/* 조회수 공장 — 모바일 우선, 다크 기본 */

/*
 * 편집실 계기판 — 새벽 3시 뉴스룸의 계측 화면.
 * 순흑 대신 따뜻한 다크로 눕히고, 수치는 백라이트 호박색으로 읽힌다.
 */
:root {
  --point: #ff7a45; /* 브랜드 코랄 — 수집기·강조 */
  --point-dim: #7a3520;
  --gold: #ffc453; /* 계기판 백라이트 — 모든 수치 */
  --mint: #7ddc7d;
  --sky: #5ac8fa;

  --bg: #0c0a09;
  --surface: #16120f;
  --surface-2: #201a16;
  --surface-3: #2a221d;
  --line: #2e2620;

  --text: #f7f3f0;
  --text-dim: #a1938a;

  /* 숫자는 모노, 한글은 Pretendard로 흘러간다 */
  --font-num: 'JetBrains Mono', 'Pretendard Variable', Pretendard, ui-monospace, monospace;

  /* 타이포 스케일 — 임의 px 대신 단계로 고정 */
  --t-hero: 46px;
  --t-lg: 22px;
  --t-md: 15px;
  --t-sm: 13px;
  --t-xs: 11px;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 10px;
}

/* 계기판 패널의 재질 — 상단에 백라이트가 걸린 얇은 하이라이트 */
.panel,
.stage,
.tabs,
.modal {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* 수치는 전부 모노 — 자리가 흔들리지 않고 계기판처럼 읽힌다 */
.views,
.rate,
.chip strong,
.stage-power strong,
.combo-mult,
.row-rate,
.row-cost,
.row-count,
.pub-gain,
.prestige-stat strong,
.progress-top,
.stats dd,
.pulse figcaption {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* 품질 하한 — 키보드 초점이 반드시 보여야 한다 */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

* {
  box-sizing: border-box;
}

/* display가 지정된 요소는 hidden 속성만으로 숨겨지지 않는다 (명시도에서 밀림) */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
    'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 16px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── 헤더 ─────────────────────────── */
.series {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
}

.series .bar {
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: var(--point);
}

.head {
  text-align: center;
}

.head .series {
  justify-content: flex-start;
}

.views {
  margin: 14px 0 2px;
  font-size: var(--t-hero);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.rate {
  margin: 0;
  color: var(--point);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── 생산 리듬 (시그니처) ───────────── */
.pulse {
  margin: 12px 0 0;
  padding: 0;
}

#pulse {
  display: block;
  width: 100%;
  height: 46px;
}

.pulse figcaption {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 4px;
  color: var(--text-dim);
  font-size: var(--t-xs);
  font-weight: 700;
}

/* ── 헤더 스탯 칩 ───────────────────── */
.stat-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
  min-height: 24px;
}

.chip {
  padding: 3px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
}

.chip strong {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* ── 탭 ─────────────────────────────── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.tabs button {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 38px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
}

.tabs button.is-active {
  background: var(--surface-2);
  color: var(--point);
}

/* 할 일이 생긴 탭에 점을 찍는다 — 어디를 봐야 하는지 알려준다 */
.tabs .dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
}

/* ── 수집 필드 ─────────────────────── */
.stage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
}

.stage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.stage-title {
  font-size: 15px;
  font-weight: 800;
}

.stage-power {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
}

.stage-power strong {
  color: var(--gold);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.field-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #221b18 0%, #14100e 100%);
}

#field {
  display: block;
  width: 100%;
  height: 240px;
  /* 필드 위 드래그가 페이지 스크롤로 새지 않게 한다 */
  touch-action: none;
  cursor: crosshair;
}

/* 소재를 주울 때 떠오르는 숫자.
   필드 좌표를 화면 좌표로 옮겨 쓰므로 뷰포트 고정이어야 하고,
   조상의 overflow에 잘리지 않도록 최상위에 둔다. */
.floaters {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

/* ── 콤보 ─────────────────────────── */
.combo {
  margin-top: 10px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  transition: border-color 0.2s;
}

.combo.is-active {
  border-color: var(--gold);
}

.combo-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}

.combo-count {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
}

.combo.is-active .combo-count {
  color: var(--text);
}

.combo-mult {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.combo.is-active .combo-mult {
  color: var(--gold);
}

.combo-track {
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

/* 남은 시간을 scaleX로 줄인다 — width 애니메이션보다 리플로우가 없다 */
.combo-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--gold);
  transform-origin: left center;
  transform: scaleX(0);
}

/* ── 조작 ─────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.controls-hint {
  margin: 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}

/* 십자 배치 — 위 / 좌·하·우 */
.dpad {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(2, 40px);
  gap: 4px;
}

.dpad button {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.dpad button:active {
  background: var(--point);
  border-color: transparent;
  color: #2b0d02;
}

.dpad button[data-dir='up'] {
  grid-column: 2;
  grid-row: 1;
}
.dpad button[data-dir='left'] {
  grid-column: 1;
  grid-row: 2;
}
.dpad button[data-dir='down'] {
  grid-column: 2;
  grid-row: 2;
}
.dpad button[data-dir='right'] {
  grid-column: 3;
  grid-row: 2;
}

.floater {
  position: absolute;
  color: var(--gold);
  font-size: 17px;
  font-weight: 800;
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  animation: float-up 0.9s ease-out forwards;
}

@keyframes float-up {
  from {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
  to {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 42px));
  }
}

/* ── 패널 ─────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.buy-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--bg);
  border-radius: 10px;
}

.buy-toggle button {
  padding: 5px 11px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.buy-toggle button.is-active {
  background: var(--surface-2);
  color: var(--point);
}

.panel-note {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── 발행 기록 ─────────────────────── */
.published {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pub {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 11px;
  background: var(--surface-2);
  border-radius: 10px;
  animation: pub-in 0.25s ease-out;
}

@keyframes pub-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.pub-tag {
  flex-shrink: 0;
  padding: 2px 7px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.5;
}

.pub-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.pub-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
}

.pub-sub {
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.4;
}

.pub-gain {
  flex-shrink: 0;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ── 목록 행 ───────────────────────── */
.rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

/* 기여도 — 전체 생산량 중 이 직원의 비율. 행 아래쪽에 얇게 깔린다. */
.row-share {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
}

.row-share-bar {
  display: block;
  height: 100%;
  background: var(--point);
  opacity: 0.55;
  transform-origin: left center;
  transform: scaleX(0);
}

/* 업그레이드 종류 배지 */
.kind {
  display: inline-block;
  margin-right: 2px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  vertical-align: 1px;
}

.row:disabled {
  opacity: 0.42;
  cursor: default;
}

.row.is-affordable {
  border-color: var(--point-dim);
}

.row.is-affordable:active {
  transform: scale(0.99);
}

.row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.row-name {
  font-size: 15px;
  font-weight: 800;
}

.row-desc {
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
}

.row-rate {
  color: var(--point);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.row-buy {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.row-cost {
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.row.is-affordable .row-cost {
  color: var(--gold);
}

.row-count {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
}

/* ── 개편 ─────────────────────────── */
.prestige-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.prestige-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
}

.prestige-stat .label {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
}

.prestige-stat strong {
  font-size: 24px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.prestige-stat .sub {
  color: var(--text-dim);
  font-size: 11px;
}

.hint {
  margin: 10px 0 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

/* 개편 패널 설명 — 무엇을 잃고 무엇을 얻는지 먼저 알려준다 */
.lead {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.6;
}

.lead strong {
  color: var(--gold);
}

/* ── 진행 바 ────────────────────────── */
.progress {
  margin: 14px 0;
}

.progress-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--gold);
  transform-origin: left center;
  transform: scaleX(0);
}

/* ── 기록 ───────────────────────────── */
.sub-head {
  margin: 20px 0 10px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text-dim);
}

.stats {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin: 0 0 16px;
  font-size: 13px;
}

.stats dt {
  color: var(--text-dim);
}

.stats dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── 버튼 ─────────────────────────── */
button {
  cursor: pointer;
}

#prestige-btn,
#offline-close {
  width: 100%;
  height: 48px;
  background: var(--gold);
  border: 0;
  border-radius: 12px;
  color: #33210a;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
}

#prestige-btn:disabled {
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: default;
}

/* ── 토스트 ───────────────────────── */
.toast {
  margin: -6px 0 0;
  min-height: 18px;
  text-align: center;
  color: var(--gold);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s;
}

.toast.is-visible {
  opacity: 1;
}

/* ── 오프라인 모달 ─────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.6);
  z-index: 10;
}

.modal {
  width: 100%;
  max-width: 340px;
  padding: 24px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  text-align: center;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 19px;
}

.modal p {
  margin: 0 0 18px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

/* ── 푸터 ─────────────────────────── */
footer {
  padding-top: 6px;
  border-top: 1px solid var(--line);
  text-align: center;
  font-size: 12px;
  font-weight: 600;
}

footer a {
  display: inline-block;
  padding: 6px 10px;
  color: var(--text-dim);
  text-decoration: none;
  opacity: 0.75;
}

footer a:hover,
footer a:focus-visible {
  color: var(--point);
  opacity: 1;
}

button.danger {
  width: 100%;
  height: 38px;
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
}

button.danger:hover {
  border-color: #7a3b3b;
  color: #e08c8c;
}

/*
 * 모바일에서는 열 래퍼가 레이아웃에 없어야 한다.
 * display: contents가 래퍼를 통과시켜 자식이 그대로 .app의 flex 아이템이 된다.
 */
.col {
  display: contents;
}

/*
 * 데스크톱 2단 — 넓은 화면에서 가운데 520px만 쓰고 양옆이 텅 비는 걸 막는다.
 *
 * Grid만으로 열을 나누면 행 높이가 열끼리 공유돼, 왼쪽의 큰 필드가 오른쪽 패널을
 * 아래로 밀어낸다. 각 열을 독립 flex 컨테이너로 세워야 서로 간섭하지 않는다.
 */
@media (min-width: 900px) {
  .app {
    max-width: 960px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
    gap: 20px;
  }

  .col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
  }

  /* 목록을 스크롤하면서도 필드를 계속 조작할 수 있어야 한다 */
  .col-left {
    position: sticky;
    top: 20px;
  }

  #field {
    height: 300px;
  }
}

/*
 * 마우스·키보드가 있는 기기에서는 D-패드가 군더더기다.
 * 방향키와 드래그로 충분하므로 치우고, 안내 문구가 그 자리를 쓴다.
 * (Chanel: 나가기 전에 액세서리 하나를 빼라)
 */
@media (hover: hover) and (pointer: fine) {
  .dpad {
    display: none;
  }

  .controls {
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
