:root {
  --scene-bg: #0e0d0c;
  --surface: rgba(250, 246, 238, 0.94);
  --surface-strong: #fbf8f1;
  --text: #1f1b17;
  --muted: #6b6257;
  --accent: #a5372a;
  --accent-text: #fff8f0;
  --gold: #b88a2c;
  --line: rgba(31, 27, 23, 0.14);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --serif: "Noto Serif TC", "Songti TC", serif;
  --sans: "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  --gutter: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: rgba(28, 25, 22, 0.92);
    --surface-strong: #1f1c19;
    --text: #efe8dd;
    --muted: #a99f92;
    --accent: #d8644f;
    --accent-text: #1a1310;
    --gold: #d9b25a;
    --line: rgba(239, 232, 221, 0.16);
  }
}
:root[data-theme="dark"] {
  --surface: rgba(28, 25, 22, 0.92);
  --surface-strong: #1f1c19;
  --text: #efe8dd;
  --muted: #a99f92;
  --accent: #d8644f;
  --accent-text: #1a1310;
  --gold: #d9b25a;
  --line: rgba(239, 232, 221, 0.16);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--scene-bg); color: var(--text); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#scene:active { cursor: grabbing; }

.primary { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px; padding: 12px 26px; font-weight: 700; letter-spacing: .05em; }
.primary:disabled { opacity: .55; cursor: wait; }
.primary.small { padding: 8px 18px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.intro { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: var(--gutter); background: radial-gradient(ellipse at 50% 40%, rgba(60, 30, 22, .82), rgba(8, 7, 6, .96)); }
.intro-box { max-width: 520px; width: 100%; background: var(--surface); border-radius: 18px; padding: 28px 26px; box-shadow: var(--shadow); max-height: calc(100vh - 32px); overflow: auto; }
.kicker { margin: 0; color: var(--gold); font-size: 14px; letter-spacing: .12em; }
.intro h1 { font-family: var(--serif); font-weight: 900; font-size: clamp(24px, 7.4vw, 46px); margin: 6px 0 10px; letter-spacing: .08em; }
.lead { font-family: var(--serif); line-height: 1.8; margin: 0 0 14px; }
.howto { margin: 0 0 14px; padding-left: 1.1em; line-height: 1.9; font-size: 15px; }
.note { font-size: 13px; color: var(--muted); margin: 0 0 18px; }

.topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) var(--gutter) 10px; pointer-events: none; }
.brand { display: flex; flex-direction: column; color: #f4efe4; text-shadow: 0 1px 6px rgba(0, 0, 0, .7); }
.brand b { font-family: var(--serif); font-size: 20px; letter-spacing: .1em; }
.brand span { font-size: 12px; opacity: .8; }
.tools { display: flex; gap: 6px; pointer-events: auto; }
.icon { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.icon[aria-pressed="false"] { opacity: .65; }

.styles { position: fixed; top: calc(60px + env(safe-area-inset-top)); left: var(--gutter); right: var(--gutter); z-index: 10; display: flex; align-items: center; gap: 8px; pointer-events: none; }
.styles-label { color: #f4efe4; font-size: 12px; text-shadow: 0 1px 6px rgba(0, 0, 0, .8); white-space: nowrap; }
.chips { display: flex; gap: 6px; overflow-x: auto; pointer-events: auto; scrollbar-width: none; padding: 2px; }
.venues { top: calc(96px + env(safe-area-inset-top)); }
.switches { top: calc(132px + env(safe-area-inset-top)); }
.stand-styles { top: calc(168px + env(safe-area-inset-top)); }
.drape-layouts { top: calc(204px + env(safe-area-inset-top)); }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip[aria-checked="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
.chip .count { font-size: 11px; opacity: .7; margin-left: 4px; }

.card { position: fixed; left: var(--gutter); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 10; width: min(400px, calc(100vw - 2 * var(--gutter))); background: var(--surface); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card h2 { font-family: var(--serif); font-size: 18px; margin: 0; }
.card p { margin: 8px 0 0; font-size: 14px; line-height: 1.75; max-height: 30vh; overflow: auto; }
.card .primary { margin-top: 10px; }
.badge { flex: none; min-width: 28px; height: 28px; border-radius: 999px; display: grid; place-items: center; background: #2c4a7a; color: #f4efe4; font-weight: 900; font-size: 14px; padding: 0 6px; }
.badge.stop { background: var(--accent); color: var(--accent-text); }

.tour { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 11; display: flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 999px; padding: 6px; box-shadow: var(--shadow); max-width: calc(100vw - 2 * var(--gutter)); }
.nav { width: 44px; height: 44px; border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-text); font-size: 16px; flex: none; }
.nav:disabled { opacity: .35; cursor: default; }
.stop-label { border: 0; background: transparent; padding: 0 10px; min-width: 0; max-width: 56vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--serif); font-weight: 700; font-size: 15px; }
.stop-list { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 12; width: min(360px, calc(100vw - 2 * var(--gutter))); max-height: 60vh; overflow: auto; background: var(--surface-strong); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; }
.stop-list button { display: flex; width: 100%; align-items: center; gap: 10px; text-align: left; border: 0; background: transparent; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.stop-list button:hover, .stop-list button[aria-current="true"] { background: var(--line); }

.minimap { position: fixed; right: var(--gutter); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 10; width: 190px; height: auto; aspect-ratio: 700 / 1000; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.minimap.wide { width: 300px; aspect-ratio: 960 / 570; }
.minimap .stop-dot { cursor: pointer; }

.caption { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); z-index: 9; max-width: calc(100vw - 2 * var(--gutter)); text-align: center; color: #f4efe4; font-size: 14px; text-shadow: 0 1px 6px rgba(0, 0, 0, .9); pointer-events: none; transition: opacity .4s; opacity: 0; }
.caption.show { opacity: 1; }
.caption.quote { font-family: var(--serif); font-size: clamp(17px, 2.4vw, 24px); bottom: 45%; }
.toast { position: fixed; left: 50%; top: calc(104px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 20; background: var(--surface-strong); border-radius: 999px; padding: 8px 16px; font-size: 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .3s; max-width: calc(100vw - 2 * var(--gutter)); }
.toast.show { opacity: 1; }
.fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 8; transition: opacity .35s; }
.fade.on { opacity: 1; }

.modal { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; padding: var(--gutter); background: rgba(0, 0, 0, .6); }
.modal-box { position: relative; background: var(--surface-strong); border-radius: 16px; box-shadow: var(--shadow); width: min(880px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; }
.modal-box.narrow { width: min(460px, 100%); }
.modal-box h2 { font-family: var(--serif); margin: 0 0 8px; }
.close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); }
.modal-body { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 22px; }
.modal-body.text-only { grid-template-columns: 1fr; }
.modal-body.board-view { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); }
.modal-body img.board { aspect-ratio: auto; height: auto; object-fit: contain; border-radius: 4px; background: none; }
.modal-body img, .modal-body .pending { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 10px; background: #2b2520; }
.modal-body .pending { display: grid; place-items: center; color: #d8d0c4; font-size: 14px; }
.modal-body .section { color: var(--muted); font-size: 13px; letter-spacing: .08em; margin: 4px 0 6px; }
.modal-body .section.stop { color: var(--accent); }
.modal-body h3 { font-family: var(--serif); font-size: 26px; margin: 0 0 4px; line-height: 1.35; }
.modal-body .sub { color: var(--muted); margin: 0 0 14px; }
.modal-body blockquote { margin: 0 0 16px; padding: 0 0 0 14px; border-left: 3px solid var(--accent); font-family: var(--serif); font-size: 19px; line-height: 1.8; color: var(--accent); }
.modal-body dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 0 0 12px; }
.modal-body dt { color: var(--muted); }
.modal-body dd { margin: 0; }
.modal-body .stop-text { font-size: 15px; line-height: 1.8; background: var(--line); border-radius: 10px; padding: 10px 12px; }
.modal-body ol { padding-left: 1.2em; line-height: 1.9; }
textarea { width: 100%; font: inherit; font-family: "LXGW WenKai TC", var(--serif); font-size: 20px; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: #fbf2bf; color: #3b3530; resize: vertical; margin: 6px 0; }
.fatal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: var(--gutter); background: var(--scene-bg); color: #f4efe4; text-align: center; line-height: 1.8; }

@media (max-width: 720px) {
  .brand span { display: none; }
  .brand b { font-size: 14px; letter-spacing: .04em; white-space: nowrap; }
  .icon { white-space: nowrap; }
  .styles { top: calc(52px + env(safe-area-inset-top)); }
  .venues { top: calc(86px + env(safe-area-inset-top)); right: calc(var(--gutter) + 126px); }
  .switches { top: calc(120px + env(safe-area-inset-top)); right: calc(var(--gutter) + 126px); }
  .stand-styles { top: calc(154px + env(safe-area-inset-top)); right: calc(var(--gutter) + 126px); }
  .drape-layouts { top: calc(188px + env(safe-area-inset-top)); right: calc(var(--gutter) + 126px); }
  .styles-label { display: none; }
  .card { bottom: calc(76px + env(safe-area-inset-bottom)); padding: 12px 14px; }
  .card p { max-height: 22vh; font-size: 13px; }
  .minimap { width: 118px; top: calc(96px + env(safe-area-inset-top)); bottom: auto; }
  .minimap.wide { width: 200px; top: calc(192px + env(safe-area-inset-top)); }
  .modal-body { grid-template-columns: 1fr; }
  .modal-body.board-view { grid-template-columns: 1fr; }
  .modal-body img, .modal-body .pending { max-width: 260px; margin: 0 auto; }
  .modal-body img.board { max-width: 100%; }
  .caption { bottom: calc(40vh); }
}
