:root {
  --bg: #16130f;
  --surface: #221d17;
  --surface-2: #2d261e;
  --line: #3a3128;
  --text: #f3ece2;
  --muted: #b3a795;
  --accent: #e0a060;
  --accent-ink: #1d140b;
  --red: #c4553a;
  --ok: #8cc771;
  --warn: #f2c14e;
  --c-geology: #e0a060;
  --c-railroad: #86b2e0;
  --c-history: #f2c14e;
  --c-people: #ec97a8;
  --c-nature: #8cc771;
  --c-fun: #bf98ea;
  --c-story: #5fa3dc;
  --radius: 16px;
  --top: calc(env(safe-area-inset-top) + 40px);
  --bottom: calc(env(safe-area-inset-bottom) + 62px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.15; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

/* status bar */
#status {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  padding: env(safe-area-inset-top) 16px 0;
  height: var(--top);
  display: flex; align-items: center; gap: 8px;
  background: rgba(22, 19, 15, 0.94);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
#status-where { margin-left: auto; color: var(--text); font-weight: 600; }
.gps-dot { width: 10px; height: 10px; border-radius: 50%; background: #6b6258; flex: none; }
#status[data-state="good"] .gps-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
#status[data-state="weak"] .gps-dot, #status[data-state="waiting"] .gps-dot { background: var(--warn); }
#status[data-state="error"] .gps-dot { background: var(--red); }
#status[data-state="sim"] .gps-dot { background: var(--c-fun); box-shadow: 0 0 8px var(--c-fun); }

main {
  padding: calc(var(--top) + 14px) 16px calc(var(--bottom) + 24px);
  max-width: 640px; margin: 0 auto;
}
.tab { display: none; }
.tab.active { display: block; }
.tab-title { font-size: 28px; margin: 4px 0 6px; }

/* bottom tabs */
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex; height: var(--bottom);
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(22, 19, 15, 0.96);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
#tabs button {
  flex: 1; border: 0; background: none; color: var(--muted);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#tabs button .ti { font-size: 20px; line-height: 1; }
#tabs button.active { color: var(--accent); }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 20px; font-size: 22px; border-radius: 18px; }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.icon { width: 56px; height: 56px; padding: 0; font-size: 22px; border-radius: 50%; }
.btn.icon.primary { width: 72px; height: 72px; font-size: 24px; }
.btn:disabled { opacity: 0.5; }
.link { background: none; border: 0; color: var(--accent); padding: 6px 0; text-align: left; display: block; font-weight: 600; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row-btns .btn { flex: 1; }

/* hero */
.hero { text-align: center; padding: 24px 4px; }
.hero-kicker { color: var(--accent); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 14px; }
.hero h1 { font-size: 38px; margin: 8px 0 12px; }
.hero p { margin: 0 0 22px; }
.hero .hint { font-size: 14px; color: var(--muted); margin: 14px 0; }
.hero .btn.ghost { margin-top: 18px; width: 100%; }
.offline-badge { font-size: 15px; margin-top: 8px; }
.offline-badge .link { display: inline; }

/* tags */
.tag {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  padding: 4px 9px; border-radius: 999px; color: #15110c; background: var(--c-geology);
}
.tag.railroad { background: var(--c-railroad); }
.tag.history { background: var(--c-history); }
.tag.people { background: var(--c-people); }
.tag.nature { background: var(--c-nature); }
.tag.fun { background: var(--c-fun); }
.tag.story { background: var(--c-story); }
.tag.mini { font-size: 10px; padding: 3px 7px; }

/* now playing */
.now { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.now-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.now-phase { color: var(--muted); font-size: 14px; }
.now h2, #sheet-body h2 { font-size: 30px; }
.subtitle { color: var(--muted); margin-top: 4px; }
.pointer { display: flex; align-items: center; gap: 16px; margin: 16px 0 8px; }
.arrow { width: 96px; height: 96px; flex: none; fill: var(--accent); transition: transform 0.6s ease, opacity 0.3s; }
.pointer.small .arrow { width: 64px; height: 64px; }
.arrow.sm { width: 48px; height: 48px; }
.clock { font-size: 26px; font-weight: 700; }
.lookfor {
  font-size: 21px; font-weight: 600; margin: 10px 0 14px; padding: 12px 14px;
  border-left: 4px solid var(--accent); background: var(--surface-2); border-radius: 0 12px 12px 0;
}
.lookfor span { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin: 12px 0; }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }
.controls { display: flex; justify-content: center; align-items: center; gap: 22px; margin: 6px 0 12px; }
.media figure { margin: 14px 0 0; }
.media img { width: 100%; border-radius: 12px; display: block; }
.media figcaption { font-size: 11px; color: var(--muted); margin-top: 4px; }
.media .diagram svg { width: 100%; height: auto; display: block; border-radius: 12px; }
.facts { padding-left: 20px; margin: 16px 0; }
.facts li { margin: 6px 0; }
.quiz { background: var(--surface-2); border-radius: 12px; padding: 14px; margin: 14px 0; }
.quiz-label { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--c-fun); }
.quiz-q { font-size: 19px; font-weight: 600; margin: 4px 0 10px; }
.quiz-a { font-size: 17px; color: var(--ok); }
.transcript, .sources { margin-top: 14px; }
.transcript summary, .sources summary { color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 0; }
.transcript p { white-space: pre-wrap; color: #e6ddcf; }
.sources div { font-size: 12px; color: var(--muted); word-break: break-all; margin: 4px 0; }

/* idle */
.idle { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 18px; text-align: center; }
.idle-label { color: var(--muted); font-size: 15px; }
.next-title { font-size: 28px; font-weight: 700; margin-top: 10px; }
.next-dist { font-size: 22px; color: var(--accent); font-weight: 600; margin-top: 4px; }

/* lists */
.section { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 22px 0 6px; }
.row {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line); padding: 13px 2px; cursor: pointer;
}
.row-mi { width: 52px; flex: none; color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; }
.row-title { flex: 1; font-weight: 600; }
.row.heard .row-title { color: var(--muted); }
.check { color: var(--ok); }
.here {
  margin: 8px 0; padding: 8px 12px; border-radius: 10px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 14px; text-align: center;
}
.mapbox { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); padding: 6px; margin-bottom: 8px; }
.map { width: 100%; height: auto; display: block; }
.mroute { fill: none; stroke: #6d5d4b; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.mdot { fill: var(--c-geology); stroke: var(--bg); stroke-width: 2; }
.mdot.railroad { fill: var(--c-railroad); } .mdot.history { fill: var(--c-history); } .mdot.people { fill: var(--c-people); }
.mdot.nature { fill: var(--c-nature); } .mdot.fun { fill: var(--c-fun); }
.mdot.heard { opacity: 0.45; }
.mtown { fill: var(--text); }
.mlabel { fill: var(--text); font-size: 24px; font-weight: 600; paint-order: stroke; stroke: var(--bg); stroke-width: 5px; }
.mme { fill: #fff; stroke: var(--red); stroke-width: 6; }

/* around */
.arow {
  width: 100%; display: flex; gap: 14px; align-items: center; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 10px 0; cursor: pointer;
}
.arow-text { display: flex; flex-direction: column; gap: 2px; }
#btn-compass { width: 100%; margin: 6px 0 4px; }

/* rocks */
.column { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); margin-top: 12px; }
.layer { background: var(--surface); border-bottom: 1px solid var(--line); }
.layer summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 12px; cursor: pointer; }
.layer summary::-webkit-details-marker { display: none; }
.swatch { width: 34px; height: 34px; border-radius: 8px; background: var(--c); flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15); }
.layer-name { flex: 1; font-weight: 600; }
.layer-age { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.layer-body { padding: 0 14px 14px 58px; font-size: 15px; }
.layer-body p { margin: 8px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 2px solid var(--c); }
.diagram-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* setup */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 14px 0; }
.card h3 { font-size: 19px; margin-bottom: 8px; }
.card .btn { margin-top: 8px; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; }
.radio input { margin-top: 5px; }
input[type="range"] { width: 100%; margin: 10px 0; accent-color: var(--accent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 8px 0; }
.seg button { flex: 1; padding: 10px; border: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--accent); color: var(--accent-ink); }

/* sheet */
#sheet {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
}
#sheet-body {
  width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
  padding: 16px 18px calc(env(safe-area-inset-bottom) + 28px);
}
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.sheet-head .close { margin-left: auto; width: 40px; height: 40px; font-size: 16px; }
#sheet-play { width: 100%; margin: 14px 0 4px; padding: 15px; font-size: 18px; }

/* toast */
#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--bottom) + 14px); z-index: 50;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 16px; border-radius: 12px; font-weight: 600; text-align: center;
  opacity: 0; transform: translateY(10px); transition: all 0.25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: none; }

/* detail level + topic toggles */
.level-label { font-size: 14px; color: var(--muted); margin: 6px 0 2px; }
.seg.level button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 6px; color: var(--text); }
.seg.level button small { font-size: 11px; font-weight: 500; color: var(--muted); }
.seg.level button.active small { color: var(--accent-ink); }
.hero .seg.level { margin: 8px 0 18px; }
.toggles { gap: 8px; }
.chip-btn {
  border: 2px solid var(--line); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-weight: 600; font-size: 14px;
}
.chip-btn.on { border-color: var(--accent); color: var(--text); background: var(--surface-2); }
.row.off { opacity: 0.45; }
.tier {
  margin-left: 8px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; vertical-align: 2px;
}
.seg.level button.active { color: var(--accent-ink); }

/* tap-to-enlarge */
.media figure { cursor: zoom-in; }
#zoom {
  position: fixed; inset: 0; z-index: 60; background: #000; overflow: auto; -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 56px) 0 calc(env(safe-area-inset-bottom) + 40px);
}
#zoom-body { width: max(100vw, 820px); }
#zoom-body svg, #zoom-body img { width: 100%; height: auto; display: block; }
#zoom-close { position: fixed; top: calc(env(safe-area-inset-top) + 8px); right: 12px; z-index: 61; width: 44px; height: 44px; font-size: 16px; }
.zoom-hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 12px; position: sticky; left: 0; width: 100vw; }
@media (orientation: landscape) { #zoom-body { width: 100vw; } .zoom-hint { display: none; } }

/* ---- mini player (now playing while browsing) ---- */
:root { --mini: 64px; }
#mini {
  position: fixed; left: 0; right: 0; bottom: var(--bottom); z-index: 45;
  height: var(--mini); display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--surface-2); border-top: 1px solid var(--line);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.35);
}
.mini-prog { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: transparent; }
.mini-prog > div { height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }
.mini-arrow { width: 40px; height: 40px; flex: none; }
.mini-text {
  flex: 1; min-width: 0; background: none; border: 0; text-align: left; padding: 0;
  display: flex; flex-direction: column; cursor: pointer;
}
#mini-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#mini-sub { font-size: 13px; color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.icon.mini-btn { width: 44px; height: 44px; font-size: 17px; flex: none; }
body.has-mini main { padding-bottom: calc(var(--bottom) + var(--mini) + 24px); }
body.has-mini #toast { bottom: calc(var(--bottom) + var(--mini) + 14px); }
/* keep the sheet above the mini player so you can read while it plays */
body.has-mini #sheet { bottom: calc(var(--bottom) + var(--mini)); }
body.has-mini #sheet-body { padding-bottom: 28px; max-height: calc(100vh - var(--bottom) - var(--mini) - 40px); }

/* ---- two panes on wide screens (landscape phone, iPad) ---- */
body.wide main {
  max-width: 1280px; display: grid; grid-template-columns: minmax(340px, 1fr) minmax(380px, 1.25fr);
  gap: 20px; align-items: start;
}
body.wide #tab-tour {
  grid-column: 1; grid-row: 1; position: sticky; top: calc(var(--top) + 14px);
  max-height: calc(100vh - var(--top) - var(--bottom) - 28px); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
body.wide .tab.active:not(#tab-tour) { grid-column: 2; grid-row: 1; }
body.wide #tabs button[data-tab="tour"] { display: none; }
body.wide .hero { padding-top: 4px; }
body.wide .hero h1 { font-size: 30px; }

/* short landscape phones: reclaim vertical space */
@media (max-height: 500px) {
  :root { --top: calc(env(safe-area-inset-top) + 32px); --bottom: calc(env(safe-area-inset-bottom) + 46px); --mini: 56px; }
  #tabs button .ti { font-size: 16px; }
  .now h2, #sheet-body h2 { font-size: 24px; }
  .pointer { margin: 8px 0 4px; }
  .arrow { width: 64px; height: 64px; }
  .clock { font-size: 20px; }
  .lookfor { font-size: 17px; }
}
main, #status { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* ---- quiz ---- */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0 12px; }
.player { background: var(--surface); border: 2px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; }
.player.turn { border-color: var(--c-fun); box-shadow: 0 0 0 3px rgba(191, 152, 234, 0.18); }
.pname { width: 100%; background: transparent; border: 0; color: var(--text); font: inherit; font-weight: 700; text-align: center; padding: 4px; border-radius: 8px; }
.pname:focus { outline: 2px solid var(--line); }
.pscore { font-size: 40px; font-weight: 800; line-height: 1.1; color: var(--c-fun); font-variant-numeric: tabular-nums; }
.plevel { background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 600; }
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.q-meta { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 700; color: var(--c-fun); margin-bottom: 8px; }
.q-meta .muted { font-weight: 500; text-align: right; }
.q-text { font-size: 22px; font-weight: 700; line-height: 1.25; margin-bottom: 14px; }
.q-choices { display: grid; gap: 10px; }
.q-choice {
  text-align: left; background: var(--surface-2); border: 2px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 14px; font-size: 18px; font-weight: 600; cursor: pointer;
}
.q-choice.right { border-color: var(--ok); background: rgba(140, 199, 113, 0.15); }
.q-choice.wrong { border-color: var(--red); background: rgba(196, 85, 58, 0.18); }
.q-choice.dim { opacity: 0.5; }
.q-result { font-size: 22px; font-weight: 800; margin: 14px 0 4px; }
.q-why { margin: 4px 0 14px; color: #e6ddcf; }
.quiz-prompt {
  width: 100%; text-align: left; margin-top: 12px; padding: 14px 16px; border-radius: 14px; cursor: pointer;
  background: var(--surface); border: 2px solid var(--c-fun); color: var(--text); font-size: 17px;
}
.quiz-prompt .quiz-label { display: block; }
#tabs button { font-size: 10.5px; }

#update-banner {
  position: fixed; left: 12px; right: 12px; top: calc(var(--top) + 8px); z-index: 55;
  background: var(--c-story); color: #0d1620; border: 0; border-radius: 12px; padding: 12px 14px;
  font-weight: 700; font-size: 15px; box-shadow: 0 6px 18px rgba(0,0,0,0.4);
}

.joke-text { font-size: 24px; font-weight: 700; line-height: 1.3; margin: 14px 0 6px; color: var(--c-fun); }
