/* 平安夜郵差：深藍夜空＋暖黃窗光的平面插畫風；紅綠只用在禮物與狀態。 */
:root {
  --sky-0: #0b1530;
  --sky-1: #16264d;
  --panel: #1a2b52;
  --panel-2: #233866;
  --line: #34507f;
  --ink: #f4f1e8;
  --ink-2: #b9c4dc;
  --warm: #ffd36b;
  --warm-2: #ffb347;
  --red: #e0524a;
  --green: #4fb36b;
  --focus: #9fd3ff;
  --font: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sky-0);
  background-image: linear-gradient(180deg, var(--sky-0), var(--sky-1));
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

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

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

/* ---------- 版面：手機直向為主 ---------- */
.app { min-height: 100%; }
.screen { display: flex; flex-direction: column; min-height: 100dvh; max-width: 1200px; margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

.statusbar { padding: 10px 12px 4px; }
.screen > .topbar { padding: 10px 12px; }
.topbar { display: flex; align-items: center; gap: 8px; }
.topbar-spacer { width: 44px; flex: none; }
.level-title { flex: 1; margin: 0; font-size: 18px; font-weight: 700; text-align: center; letter-spacing: .5px; }
.icon-btn {
  min-width: 44px; min-height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; min-width: 0; }
.stat dt { font-size: 12px; color: var(--ink-2); }
.stat dd { margin: 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { display: block; font-size: 12px; font-weight: 400; color: var(--ink-2); }
.stat.bad dd, .stat dd.bad { color: #ff8a80; }

.warning { min-height: 1.45em; margin: 6px 0 0; font-size: 14px; color: #ff9b93; font-weight: 600; }
.warning::before { content: ""; }
.warning.has::before { content: "⚠ "; }

.board { flex: 1; display: flex; flex-direction: column; gap: 8px; padding: 4px 12px; min-height: 0; }
.map-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; max-height: 70dvh; align-self: center; }
.map {
  width: 100%; height: 100%; display: block; border-radius: var(--radius);
  touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

.side { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hint { margin: 0; font-size: 14px; color: var(--ink-2); min-height: 1.45em; }
.side-title { margin: 6px 0 0; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.station-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.station-list button {
  width: 100%; min-height: 44px; text-align: left; padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 14px;
}
.station-list button[aria-pressed="true"] { border-color: var(--warm); background: var(--panel-2); }
.station-list .order { display: inline-block; min-width: 1.6em; color: var(--warm); font-weight: 700; }
.station-list .warn { color: #ff9b93; font-weight: 700; }

.actions {
  position: sticky; bottom: 0; display: grid; grid-template-columns: 1fr 1fr 1fr 1.3fr; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, transparent, var(--sky-0) 30%);
}
.btn {
  min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-weight: 600; font-size: 15px;
}
.btn:hover:not(:disabled) { background: var(--panel-2); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--warm); color: #3a2400; border-color: var(--warm-2); }
.btn.primary:hover:not(:disabled) { background: #ffe08f; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  max-width: min(92vw, 420px); padding: 10px 16px; border-radius: 999px;
  background: rgba(10, 18, 40, .92); border: 1px solid var(--line); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

/* ---------- 底部滑出面板 ---------- */
.sheet { position: fixed; inset: 0; background: rgba(4, 8, 20, .55); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-card {
  width: min(100%, 520px); background: var(--panel); border: 1px solid var(--line); border-bottom: 0;
  border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; animation: sheet-in .2s ease-out;
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-title { margin: 0; font-size: 19px; }
.sheet-body { color: var(--ink-2); }
.sheet-body p { margin: 4px 0; }
.sheet .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stars { font-size: 30px; color: var(--warm); letter-spacing: 4px; }
.stars .off { color: #3e5179; }

/* ---------- 錯誤畫面 ---------- */
.fatal { max-width: 640px; margin: 10vh auto; padding: 20px; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--red); }
.fatal h1 { font-size: 20px; margin-top: 0; }
.fatal li { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; margin: 4px 0; }

/* ---------- 寬螢幕：左地圖、右資訊列 ---------- */
@media (min-width: 900px) {
  .board { flex-direction: row; align-items: flex-start; }
  .map-wrap { width: min(62vw, calc(100dvh - 210px)); max-height: none; flex: none; align-self: flex-start; }
  .side { flex: 1; }
  .station-list { grid-template-columns: 1fr 1fr; }
  .actions { position: static; background: none; max-width: 640px; }
  .toast { bottom: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 通知列 ---------- */
.notice {
  margin: 0; padding: 8px 12px; text-align: center; font-size: 14px;
  background: #4a3a10; color: #ffe7a8; border-bottom: 1px solid #7a6020;
}

/* ---------- 共用按鈕 ---------- */
.btn.big { min-height: 54px; font-size: 17px; }
.btn.danger { background: #5a1f24; border-color: var(--red); color: #ffd9d5; }
.btn.danger:hover:not(:disabled) { background: #742a30; }
.btn[aria-pressed="true"] { background: var(--panel-2); border-color: var(--warm); color: var(--warm); }

/* ---------- 標題畫面 ---------- */
.title-screen { align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 24px 20px; }
.title-art canvas { display: block; width: min(60vw, 240px); height: min(60vw, 240px); }
.game-title { margin: 0; font-size: clamp(34px, 9vw, 52px); letter-spacing: 4px; color: var(--warm); text-shadow: 0 2px 18px rgba(255, 211, 107, .35); }
.tagline { margin: 0; color: var(--ink-2); font-size: 16px; }
.menu { display: grid; gap: 10px; width: min(100%, 340px); margin-top: 10px; }

/* ---------- 關卡選擇 ---------- */
.chapters { display: grid; gap: 16px; padding: 4px 12px 24px; }
.chapter h2 { margin: 0 0 8px; font-size: 16px; color: var(--warm); }
.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.level-btn {
  min-height: 84px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 8px 4px; cursor: pointer;
}
.level-btn:hover:not(:disabled) { background: var(--panel-2); }
.level-btn:disabled { opacity: .45; cursor: default; }
.level-btn .num { font-size: 20px; font-weight: 800; }
.level-btn .name { font-size: 13px; color: var(--ink-2); }
.level-btn .lv-stars { font-size: 15px; color: var(--warm); letter-spacing: 2px; }
.level-btn .lv-stars .off { color: #3e5179; }

/* ---------- 飛行播放 ---------- */
.clock {
  position: absolute; top: 10px; right: 10px; padding: 4px 10px; border-radius: 10px;
  background: rgba(8, 14, 32, .82); border: 1px solid var(--line);
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--warm);
}
.fly-actions { grid-template-columns: 3fr 1.3fr; }
.speed { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

/* ---------- 結算 ---------- */
.result-screen { align-items: center; justify-content: center; padding: 20px 16px; }
.result-card { width: min(100%, 460px); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px 18px; text-align: center; display: flex; flex-direction: column; gap: 8px; }
.result-level { margin: 0; color: var(--ink-2); font-size: 14px; }
.result-title { margin: 0; font-size: 24px; }
.result-body p { margin: 4px 0; color: var(--ink-2); }
.result-body .fail-reason { color: #ff9b93; font-weight: 600; }
.result-body .record { color: var(--warm); font-weight: 700; }
.result-actions { display: grid; gap: 8px; margin-top: 8px; }

/* ---------- 設定 ---------- */
.settings { display: grid; gap: 12px; padding: 8px 16px 24px; max-width: 560px; width: 100%; margin: 0 auto; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.setting input[type="checkbox"] { width: 28px; height: 28px; accent-color: var(--warm); }
.setting .speed { min-width: 180px; }
.fineprint { color: var(--ink-2); font-size: 13px; margin: 0; }

/* 換畫面時程式把焦點移到標題，不顯示外框 */
h1[tabindex="-1"]:focus { outline: none; }

/* ---------- 新機制說明卡 ---------- */
.sheet.center { align-items: center; padding: 16px; }
.sheet.center .sheet-card { border-radius: 18px; border-bottom: 1px solid var(--line); }
.card { text-align: center; }
.card-art { width: 100%; height: auto; display: block; border-radius: 12px; }
.setting.column { flex-direction: column; align-items: stretch; }
.card-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

/* ---------- 第 1 關引導 ---------- */
.hint.coach {
  color: #3a2400; background: var(--warm); border-radius: 12px; padding: 10px 12px; font-weight: 700; font-size: 15px;
}
.hint.coach::before { content: "👴 面試官："; }
.btn.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 211, 107, .7); } 50% { box-shadow: 0 0 0 8px rgba(255, 211, 107, 0); } }

/* ---------- 信件面板 ---------- */
.sheet-card { max-height: 88dvh; overflow-y: auto; }
.letter-intro { color: var(--ink); margin: 0; }
.adjs { list-style: none; margin: 6px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.adjs li { background: #fff7e0; color: #3a2400; border-radius: 999px; padding: 4px 12px; font-weight: 700; font-size: 15px; }
.letter-sign { text-align: right; margin: 0; color: var(--ink-2); }
.pool-title { font-size: 14px; margin: 10px 0 4px; color: var(--ink-2); font-weight: 600; }
.gift-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.gift-btn {
  min-height: 72px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px;
}
.gift-btn[aria-pressed="true"] { border: 2px solid var(--warm); background: #3a3520; }
.gift-name { font-size: 14px; font-weight: 600; color: var(--ink); }
.gift-owner { font-size: 11px; color: var(--ink-2); }
.bag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bag-row { width: 100%; text-align: left; font-weight: 500; }
.station-list .assigned { color: var(--warm); font-size: 13px; }

/* ---------- 結算揭曉 ---------- */
.reveal { text-align: left; margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.reveal h2 { font-size: 17px; margin: 0 0 6px; text-align: center; }
.reveal .badge { text-align: center; color: var(--warm); font-weight: 800; }
.reveal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 40dvh; overflow-y: auto; }
.reveal-list li { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; border-left: 4px solid #3e5179; }
.reveal-list li.ok { border-left-color: var(--warm); }
.reveal-list .who { font-weight: 700; color: var(--ink); }
.reveal-list .adj-line { font-size: 13px; color: var(--ink-2); }
.reveal-list .answer { font-size: 14px; color: var(--warm); }

/* ---------- 關卡選擇的讀心徽章、標題稱號 ---------- */
.level-btn .mind { font-size: 11px; color: var(--warm); }
.title-badge { margin: 0; color: var(--warm); font-weight: 800; }

/* ---------- 反應圖鑑 ---------- */
.gallery-count { text-align: center; color: var(--ink-2); margin: 0 0 8px; }
.gallery { display: grid; gap: 14px; padding: 0 12px 24px; }
.gallery-group h2 { font-size: 16px; color: var(--warm); margin: 0 0 6px; }
.gallery-group ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px; }
.gallery-group li { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.gallery-group li.right { border-color: var(--warm); }
.gallery-group li.locked { opacity: .55; }
.g-head { font-size: 13px; color: var(--ink-2); }
.g-text { font-size: 15px; }

.letter-ps { margin: 4px 0 0; color: var(--ink); font-style: italic; font-size: 14px; }
.letter-facts { margin: 2px 0 0; color: var(--warm); font-size: 13px; }
.ending { margin-top: 12px; padding: 12px; border-radius: 12px; background: #3a3520; border: 1px solid var(--warm); text-align: left; }
.ending h2 { margin: 0 0 6px; font-size: 18px; color: var(--warm); text-align: center; }
.ending p { color: var(--ink); }

/* ---------- 英雄榜 ---------- */
.hero-box { margin-top: 12px; padding: 12px; border-radius: 12px; background: #2a2f1c; border: 1px solid var(--warm); text-align: left; display: grid; gap: 8px; }
.hero-box h2 { margin: 0; font-size: 17px; color: var(--warm); }
.hero-box p { margin: 0; color: var(--ink-2); font-size: 14px; }
.hero-box label { display: grid; gap: 4px; font-size: 14px; color: var(--ink); }
.hero-box input {
  font: inherit; color: var(--ink); background: var(--sky-0); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
.hero-box .count { font-size: 12px; color: var(--ink-2); justify-self: end; }
.hero-box .err { color: #ff9b93; font-weight: 700; }
.hero-box .ok { color: var(--warm); font-weight: 700; }
.heroes { display: grid; gap: 10px; padding: 0 16px 24px; max-width: 640px; width: 100%; margin: 0 auto; }
.board-pick { display: flex; align-items: center; gap: 10px; }
.board-pick select { flex: 1; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-height: 44px; }
.board-status { margin: 0; color: var(--ink-2); }
.board-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.board-list li { display: grid; grid-template-columns: 3em 1fr auto; gap: 4px 10px; align-items: baseline; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.board-list .rank { font-weight: 800; color: var(--warm); }
.board-list .nick { font-weight: 700; overflow-wrap: anywhere; }
.board-list .date { font-size: 12px; color: var(--ink-2); }
.board-list .msg { grid-column: 2 / 4; color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }

.preview-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.preview-row select { font: inherit; color: var(--ink); background: var(--sky-0); border: 1px solid var(--line); border-radius: 10px; padding: 10px; min-height: 44px; }
