/* 공통 스타일: 바탕, 윗줄, 버튼, 카드·칩·배지, 고정 버튼 줄, 대화상자·선택지 시트, 토스트, 디버그, 움직임.
   화면마다의 스타일은 screens.css에 있다. 색은 tokens.css의 변수만 쓴다(라이트/다크가 저절로 바뀐다).
   모바일 우선: 360~480px은 한 열, 넓은 화면은 가운데 720px(spec 22.4). 탭 타깃은 44px 이상. */

/* ── 바탕 ─────────────────────────────────────── */
* { box-sizing: border-box; }
html {
  font-size: calc(100% * var(--font-scale)); -webkit-text-size-adjust: 100%;
  /* Tab으로 옮긴 포커스가 위 고정 줄(topbar)이나 아래 고정 버튼(cta-bar)에 가려지지 않게 */
  scroll-padding-top: calc(56px + env(safe-area-inset-top) + 8px);
  scroll-padding-bottom: calc(120px + env(safe-area-inset-bottom));
}
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
  min-width: 320px;
}
body.is-locked { overflow: hidden; }
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 2px; }
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }
/* 가운데 정렬한 제목·문구는 줄 길이를 고르게(마지막 줄에 낱말 하나만 남지 않게). 지원하지 않는 브라우저는 무시한다 */
.page-title, .home-title, .dialog-title, .memo-title, .ending-name, .ending-lines p, .work-title, .dogam-hint, .dogam-line { text-wrap: balance; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--ink-soft); }
.small { font-size: 0.8rem; }
[hidden] { display: none !important; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  min-height: 100dvh;
}
.app:focus { outline: none; }
.screen { padding-bottom: calc(132px + env(safe-area-inset-bottom)); }
.screen--boot, .screen--fatal { display: grid; place-items: center; align-content: center; gap: 16px; min-height: 80dvh; text-align: center; padding: 24px 0; }
.boot-text { color: var(--ink-soft); }
.noscript { margin: 24px 16px; padding: 16px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn-ink); }

/* ── 윗줄 ─────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto; align-items: center; gap: 8px;
  margin: 0 -16px; padding: env(safe-area-inset-top) 8px 0 16px; min-height: 56px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); text-decoration: none; font-weight: 800; }
.brand-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--accent-strong); color: var(--accent-ink); font-size: 0.95rem; font-weight: 900;
}
.brand-name { font-size: 1.05rem; letter-spacing: -0.01em; }
.topbar-back { display: inline-flex; align-items: center; gap: 2px; min-height: var(--tap); padding-right: 8px; margin-left: -6px; text-decoration: none; font-weight: 600; }
.topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; font-size: 0.95rem; text-align: center; }
.icon-btn { display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); padding: 0; border: 0; border-radius: 12px; background: transparent; color: var(--ink-soft); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn-space { width: var(--tap); }
.icon { display: block; flex-shrink: 0; }

/* ── 버튼 ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 700; font-size: 1rem; text-decoration: none; cursor: pointer; text-align: center;
  transition: transform 0.08s ease, background-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent-strong); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
/* 보라(--meta): 특별 엔딩·작가 회귀(2회차) 전용. 금색은 투베·BEST·금색 엔딩·6단계에만 쓴다(spec 22.4) */
.btn-meta { background: color-mix(in srgb, var(--meta) 12%, var(--surface)); color: var(--meta); border-color: var(--meta); }
.btn-danger { background: var(--bad); color: var(--on-bad); }
.btn-block { display: flex; width: 100%; }
.btn-lg { min-height: 52px; font-size: 1.05rem; border-radius: 14px; }
.btn-sm { padding: 0 12px; font-size: 0.9rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }
.link { display: inline-flex; align-items: center; min-height: var(--tap); color: var(--accent-strong); font-weight: 700; text-decoration: none; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ── 카드·칩·배지 ─────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; box-shadow: var(--shadow);
}
.card--flush { padding: 0; overflow: hidden; }
.section-title { font-size: 1rem; font-weight: 800; margin: 0 0 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card--flush .section-head { padding: 6px 12px 0 16px; }
.card--flush .section-title { margin: 8px 0; }
.page-title { font-size: 1.5rem; font-weight: 800; line-height: 1.3; margin: 18px 0 8px; }
.page-kicker { margin-top: 18px; font-size: 0.82rem; font-weight: 700; color: var(--accent-strong); }
.page-kicker + .page-title { margin-top: 2px; }
.notice { margin: 12px 0; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); font-size: 0.92rem; }
.notice--good { background: var(--good-soft); color: var(--good); font-weight: 700; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips--row { margin: 12px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 2px 10px;
  border-radius: 999px; background: var(--surface-2); color: var(--ink); font-size: 0.82rem; font-weight: 600; line-height: 1.3;
}
.chip-kicker { color: var(--ink-soft); font-weight: 500; }
.chip--trend { background: var(--surface); border: 1px solid var(--line); font-weight: 800; }
.chip--live { background: var(--accent-soft); color: var(--ink); }
.chip--done { background: var(--good-soft); color: var(--good); }
.chip--prep { background: var(--surface-2); color: var(--ink-soft); }
.chip--stop, .chip--rest { background: var(--surface-2); color: var(--ink-soft); }
.chip--paid, .chip--gold { background: var(--gold-soft); color: var(--gold-ink); }
.chip--meta { background: color-mix(in srgb, var(--meta) 12%, var(--surface)); color: var(--meta); }
.chip--good, .chip--up { background: var(--good-soft); color: var(--good); }
.chip--bad, .chip--down { background: var(--bad-soft); color: var(--bad); }
.chip--warn { background: var(--warn-soft); color: var(--warn-ink); }

.badge { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 6px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em; white-space: nowrap; }
.badge--tube { background: var(--gold-soft); color: var(--gold-ink); border: 1px solid var(--gold); }
.badge--best { background: var(--gold); color: #1f1d1a; }
.badge--regular { background: var(--accent-soft); color: var(--ink); border: 1px solid var(--accent); }
.badge--new { background: var(--accent-strong); color: var(--accent-ink); } /* 새로 열린 장르(새 작품 화면) */
.badge--rest { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line); }

/* ── 고정 버튼 줄 ─────────────────────────────── */
.cta-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 20px max(16px, env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(to top, var(--paper) 72%, color-mix(in srgb, var(--paper) 0%, transparent));
  pointer-events: none;
}
.cta-inner { max-width: 688px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 10px; pointer-events: auto; }
/* 버튼 글자는 한 줄로 둔다. 두 버튼이 한 줄에 다 안 들어가면(좁은 화면 + 큰 글자) 글자를 꺾지 않고 버튼째 아래 줄로 내린다 */
.cta-inner > * { flex: 1 1 0; min-width: max-content; white-space: nowrap; }

/* ── 대화상자·선택지 시트 ──────────────────────── */
.backdrop { position: fixed; inset: 0; z-index: 50; display: flex; background: rgb(0 0 0 / 0.45); animation: fade 0.18s ease both; }
.backdrop--sheet { align-items: flex-end; justify-content: center; }
.backdrop--modal { align-items: center; justify-content: center; padding: 16px; }
/* 닫힐 때: 들어올 때의 fade(채우기 both)가 opacity를 붙잡고 있어서 transition 대신 나가는 애니메이션으로 덮어쓴다 */
.backdrop.is-leaving { animation: fade-out 0.18s ease both; pointer-events: none; }
.dialog { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); }
.dialog:focus { outline: none; }
.dialog--sheet {
  width: 100%; max-width: 720px; max-height: 88dvh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); animation: slide-up 0.24s ease both;
}
.dialog--modal { width: min(420px, 100%); border-radius: 16px; padding: 20px; animation: pop 0.18s ease both; }
.dialog-title { font-size: 1.15rem; font-weight: 800; margin-bottom: 8px; }
.dialog-body { color: var(--ink-soft); }
.dialog-desc { display: grid; gap: 8px; margin-bottom: 16px; }
/* 확인 창의 경고 한 줄(예: 연재 중인 작품이 사라진다). 본문과 따로 떼어 강조한다 */
.dialog-note { font-weight: 700; color: var(--ink); }
.dialog-note--danger { color: var(--bad); }
/* 열린 직후(ARM_DELAY_MS)에는 버튼을 누를 수 없다. 빠른 두 번째 탭이 막 뜬 버튼을 누르지 않게(dom.js armDelay) */
.dialog.is-arming :is(button, a, input, label, textarea) { pointer-events: none; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.sheet-head-text { min-width: 0; }
.sheet-close { margin: -6px -8px 0 0; }
.sheet-kicker { font-size: 0.8rem; font-weight: 700; color: var(--accent-strong); }
.sheet-title { font-size: 1.25rem; font-weight: 800; margin: 2px 0; }
/* 열린 직후(시트가 올라오는 동안)에는 카드를 누를 수 없다. 빠른 두 번째 탭이 카드를 고르지 않게(dom.js armDelay) */
.sheet.is-arming .choice { pointer-events: none; }
.sheet-sub { color: var(--ink-soft); margin-bottom: 14px; font-size: 0.92rem; }
.choices { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 10px; }
.choice {
  display: flex; flex-direction: column; justify-content: center; gap: 4px; width: 100%; min-height: 64px; padding: 14px 16px; text-align: left;
  border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  font-size: 1.02rem; font-weight: 600; line-height: 1.45; cursor: pointer;
}
@media (hover: hover) {
  .choice:hover { border-color: var(--accent); background: var(--accent-soft); }
  .choice--hidden:hover { border-color: var(--gold-ink); background: var(--gold-soft); }
}
.choice.is-picked { border-color: var(--accent-strong); background: var(--accent-soft); }
.choice[aria-disabled="true"] { pointer-events: none; }
.choice[aria-disabled="true"]:not(.is-picked) { opacity: 0.5; }
.choice--hidden { border: 2px dashed var(--gold); background: var(--gold-soft); }
.choice-label { font-size: 0.72rem; font-weight: 800; color: var(--gold-ink); }
.choice-label--past { color: var(--accent-strong); }
.choice--past { border-color: var(--accent); }

/* ── 토스트 ──────────────────────────────────── */
/* 토스트는 아래 고정 버튼 바로 위에 뜬다(위쪽에 뜨면 읽고 있는 제목·본문을 가린다) */
.toasts {
  position: fixed; z-index: 60; bottom: calc(env(safe-area-inset-bottom) + 92px); left: 50%; transform: translateX(-50%);
  width: min(440px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; flex-direction: column; gap: 0; padding: 9px 14px; border-radius: 12px; pointer-events: auto; cursor: pointer;
  background: #242220; color: #fbf8f2; border: 1px solid rgb(255 255 255 / 0.1); box-shadow: var(--shadow-lg); font-size: 0.88rem; line-height: 1.45;
  animation: toast-in 0.22s ease both;
}
.toast-title { color: #f2c14e; font-size: 0.8rem; }
.toast--error .toast-title, .toast--error { color: #ffb3a9; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.25s ease, transform 0.25s ease; }

/* ── 디버그 오버레이(?debug=1) ──────────────────── */
.debug-toggle { position: fixed; left: 8px; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 70; min-height: 32px; padding: 0 10px; border: 0; border-radius: 8px; background: #111; color: #9fe39f; font: 700 0.7rem/1 ui-monospace, monospace; cursor: pointer; opacity: 0.85; }
.debug { position: fixed; left: 8px; right: 8px; bottom: calc(134px + env(safe-area-inset-bottom)); z-index: 70; max-height: 50dvh; overflow: auto; padding: 10px; border-radius: 10px; background: rgb(17 17 17 / 0.94); color: #e6f5e6; font: 0.72rem/1.5 ui-monospace, monospace; word-break: break-all; }
.debug-row { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 6px; padding: 2px 0; border-bottom: 1px solid rgb(255 255 255 / 0.06); }
.debug-row b { color: #9fe39f; font-weight: 700; }
.debug summary { cursor: pointer; color: #9fe39f; margin-top: 6px; }
.debug ul { margin: 4px 0 0; padding-left: 16px; }
.debug li.no { color: #b9b9b9; }

/* ── 움직임 ──────────────────────────────────── */
.fade-in { animation: fade-in 0.35s ease both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes pulse { 50% { opacity: 0.45; } }

/* 모션 줄이기: 시스템 설정과 게임 설정(<html data-reduce-motion>) 둘 다 따른다(spec 22.7) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
:root[data-reduce-motion] *, :root[data-reduce-motion] *::before, :root[data-reduce-motion] *::after {
  animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important;
}
.notice--gold { background: var(--gold-soft); color: var(--gold-ink); font-weight: 700; }
