/* 공통 토큰. 테마별 값은 [data-theme] 에서 덮어쓴다. */
:root {
  --bg: #141311;
  --surface: #1d1b18;
  --ink: #ebe7df;
  --ink-2: #b7b0a4;
  --accent: #c9a96e;
  --accent-ink: #141311;
  --paper: #e8e2d4;
  --paper-ink: #1b1815;
  --paper-ink-2: #5b5349;
  --field: #22201c;
  --wall: #26292a;
  --seg-on: #e8c27a;
  --seg-off: #2a2620;
  --danger: #d2463c;

  --font-ui: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --font-display: 'Nanum Myeongjo', 'AppleMyungjo', 'Batang', serif;
  --font-doc: var(--font-display);

  --step--1: 14.5px;
  --step-0: 17px;
  --step-1: clamp(19px, 0.6vw + 15px, 22px);
  --step-2: clamp(30px, 2.4vw + 18px, 48px);
  --step-3: clamp(52px, 8vw, 128px);

  --gutter: clamp(16px, 4vw, 48px);
  --max: 1240px;
  --gap-section: clamp(96px, 12vw, 200px);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  color-scheme: dark;
}

[data-theme='room404'] {
  --bg: #16100e;
  --surface: #211915;
  --ink: #eee5d6;
  --ink-2: #bcae9b;
  --accent: #c0262d;
  --accent-ink: #fbf3ea;
  --brass: #c59d5d;
  --paper: #ece4d3;
  --paper-ink: #1f1915;
  --paper-ink-2: #5e5246;
  --field: #3b1519;
  --wall: #2a2f2b;
  --seg-on: #ff3b30;
  --seg-off: #2c0f0d;
  --font-display: 'Nanum Myeongjo', 'AppleMyungjo', 'Batang', serif;
  --font-doc: 'Nanum Myeongjo', 'AppleMyungjo', 'Batang', serif;
}

[data-theme='mayor'] {
  --bg: #111315;
  --surface: #1a1d20;
  --ink: #e4e6e4;
  --ink-2: #a8afb1;
  --accent: #e3a33c;
  --accent-ink: #15130f;
  --rust: #93421f;
  --paper: #dddbd3;
  --paper-ink: #16181b;
  --paper-ink-2: #555a5e;
  --field: #2b2e30;
  --wall: #2d322f;
  --seg-on: #ffb23e;
  --seg-off: #2b2210;
  --stamp: #b3201f;
  --font-display: 'Black Han Sans', 'IBM Plex Sans KR', sans-serif;
  --font-doc: 'IBM Plex Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh; min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: break-word;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  transition: background-color 600ms ease;
}

h1, h2, h3, h4, p, ol, ul, dl, dd, figure, blockquote { margin: 0; }
ol, ul { padding: 0; list-style: none; }
img, svg, canvas { display: block; max-width: 100%; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

::selection { background: var(--accent); color: var(--accent-ink); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

html { scrollbar-color: #4a443c var(--bg); }
::-webkit-scrollbar { width: 12px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #4a443c; border: 3px solid var(--bg); border-radius: 12px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.num { font-variant-numeric: tabular-nums; }

/* 버튼 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 28px;
  border: 0;
  border-radius: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  font-size: var(--step-0);
  letter-spacing: 0;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background-color 160ms ease, opacity 160ms ease;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; cursor: progress; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: color-mix(in srgb, var(--accent) 86%, white); }
}

.btn-quiet {
  background: transparent;
  color: var(--ink-2);
  padding: 0;
  min-height: 44px;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: color-mix(in srgb, currentColor 45%, transparent);
  font-weight: 500;
}
@media (hover: hover) and (pointer: fine) {
  .btn-quiet:hover { background: transparent; color: var(--ink); }
}

/* 입력 */
.field { display: grid; gap: 8px; }
.field span { font-size: var(--step--1); color: var(--ink-2); font-weight: 500; }
.field input {
  width: 100%;
  min-height: 56px;
  padding: 0 16px;
  background: var(--surface);
  border: 0;
  border-bottom: 2px solid color-mix(in srgb, var(--ink) 30%, transparent);
  border-radius: 0;
  font-size: var(--step-1);
  caret-color: var(--accent);
  transition: border-color 160ms ease;
}
.field input:focus { outline: none; border-bottom-color: var(--accent); }
.field input::placeholder { color: color-mix(in srgb, var(--ink-2) 70%, transparent); }
.field input.code-input {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 600;
}

.form-error {
  min-height: 1.6em;
  color: var(--danger);
  font-size: var(--step--1);
  font-weight: 500;
}

/* 뷰 전환 */
.view { min-height: 100vh; min-height: 100svh; }
.view.is-entering { animation: view-in 520ms var(--ease-out) both; }
@keyframes view-in { from { opacity: 0; } to { opacity: 1; } }

/* 7세그먼트 시계 */
.seg { display: block; height: 100%; width: auto; overflow: visible; }
.seg rect { fill: var(--seg-off); transition: fill 80ms linear; }
.seg rect.on { fill: var(--seg-on); }
.seg .colon { fill: var(--seg-on); }

/* 상단 바 */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: clamp(12px, 3vw, 40px);
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 70%, black);
}
.bar-case { font-size: var(--step--1); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-case strong { color: var(--ink); font-weight: 600; margin-left: 10px; }
.bar-team { font-size: var(--step--1); color: var(--ink-2); white-space: nowrap; }
.bar-team b { color: var(--ink); font-weight: 600; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; }
.bar-clock {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 48px;
  padding: 7px 12px;
  background: #050404;
  border-radius: 6px;
}
.bar-clock .seg { height: 34px; }
.bar-clock.is-final .seg { animation: final-pulse 1s steps(2, jump-none) infinite; }
@keyframes final-pulse { 50% { opacity: 0.55; } }

@media (max-width: 640px) {
  .bar { grid-template-columns: 1fr auto; }
  .bar-team { display: none; }
  .bar-clock { height: 42px; padding: 6px 10px; }
  .bar-clock .seg { height: 28px; }
}

/* 대화상자 (인물 프로필) */
.dossier {
  width: min(920px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  background: var(--paper);
  color: var(--paper-ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  overflow: auto;
}
.dossier::backdrop { background: rgba(5, 4, 3, 0.78); }
.dossier[open] { animation: dossier-in 260ms var(--ease-out); }
@keyframes dossier-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }

.dossier-inner {
  display: grid;
  grid-template-columns: minmax(220px, 340px) 1fr;
  min-height: 460px;
}
.dossier-model {
  position: relative;
  background: #0d0c0b;
  min-height: 420px;
}
.dossier-model canvas { width: 100%; height: 100%; cursor: grab; }
.dossier-model canvas:active { cursor: grabbing; }
.dossier-model .model-hint {
  position: absolute;
  left: 16px; bottom: 12px;
  color: #a9a196;
  font-size: 13px;
}
.dossier-body { padding: clamp(24px, 4vw, 44px); display: grid; align-content: start; gap: 22px; }
.dossier-role { font-size: var(--step--1); color: var(--paper-ink-2); font-weight: 600; }
.dossier-name {
  font-family: var(--font-display);
  font-size: clamp(40px, 5vw, 64px);
  line-height: 1;
  letter-spacing: -0.02em;
  font-weight: 800;
}
.dossier-facts { display: grid; grid-template-columns: max-content 1fr; gap: 10px 24px; font-size: var(--step-0); }
.dossier-facts dt { color: var(--paper-ink-2); font-weight: 500; }
.dossier-facts dd { font-weight: 500; }
.dossier-notes { display: grid; gap: 8px; font-family: var(--font-doc); font-size: var(--step-0); line-height: 1.75; max-width: 46ch; }
.dossier-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: var(--paper);
  color: var(--paper-ink);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.dossier-close:active { transform: scale(0.94); }
.dossier-wrap { position: relative; }

@media (max-width: 720px) {
  .dossier-inner { grid-template-columns: 1fr; }
  .dossier-model { min-height: 300px; height: 300px; }
}

/* 알림 */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: calc(100vw - 32px);
  padding: 14px 14px 14px 20px;
  background: var(--paper);
  color: var(--paper-ink);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, 0);
  transition: transform 320ms var(--ease-out), opacity 320ms var(--ease-out);
  font-weight: 500;
}
.toast[data-state='hidden'] { opacity: 0; transform: translate(-50%, 24px); pointer-events: none; }
.toast .btn { min-height: 40px; padding: 0 16px; font-size: var(--step--1); }

/* 시간 종료 */
.end {
  display: grid;
  place-items: center;
  padding: var(--gutter);
  text-align: center;
  background: #050404;
}
.end-inner { display: grid; justify-items: center; gap: 28px; }
.end .seg { height: clamp(80px, 16vw, 150px); }
.end .seg.blink { animation: blink 1s steps(2, jump-none) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.end h1 { font-family: var(--font-display); font-size: var(--step-2); line-height: 1.15; letter-spacing: -0.02em; }
.end p { color: var(--ink-2); max-width: 36ch; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
  .bar-clock.is-final .seg, .end .seg.blink { animation: none !important; }
}
