:root {
  --ink: #f4efe6;
  --ink-dim: rgba(244, 239, 230, 0.86);
  --glass: rgba(14, 18, 32, 0.8);
  --glass-border: rgba(255, 255, 255, 0.14);
  --accent: #f2c46d;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --serif: ui-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: #0b1020;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: block;
  touch-action: manipulation;
}

a { color: var(--accent); text-underline-offset: 3px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 6px; }

/* ---------- top bar ---------- */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) 12px calc(14px + var(--safe-l));
  background: linear-gradient(to bottom, rgba(5, 8, 18, 0.55), rgba(5, 8, 18, 0));
  transition: opacity 1.2s ease;
  z-index: 5;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--ink); text-decoration: none;
  font-family: var(--serif); font-size: 1.15rem; letter-spacing: 0.04em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
  min-height: 44px;
}
.actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 44px; min-height: 44px; padding: 0 12px;
  color: var(--ink); background: var(--glass);
  border: 1px solid var(--glass-border); border-radius: 999px;
  font: 500 0.85rem var(--sans);
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: background 0.2s, transform 0.1s;
}
.btn:hover { background: rgba(30, 38, 66, 0.7); }
.btn:active { transform: scale(0.97); }
.btn[aria-pressed="true"] { border-color: var(--accent); }
.btn[aria-disabled="true"] { opacity: 0.5; }
.btn[hidden] { display: none; }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  left: calc(14px + var(--safe-l));
  bottom: calc(max(50px, 7.5vh) + 14px + var(--safe-b));
  max-width: min(420px, calc(100vw - 28px - var(--safe-l) - var(--safe-r)));
  padding: 12px 16px;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  transition: opacity 1.2s ease;
}
.hud p { margin: 0; font-size: 0.9rem; color: var(--ink-dim); }
.hud strong { color: var(--ink); font-weight: 600; }
.hud .hud-place { font-family: var(--serif); font-size: 1.1rem; color: var(--ink); margin-bottom: 4px; }
.hud-weather { font: 0.8rem var(--sans); color: var(--ink-dim); margin-left: 6px; }
.hud .hud-riders { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--ink); }
.hud .hud-riders[hidden] { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #7ee2a0; box-shadow: 0 0 0 0 rgba(126, 226, 160, 0.6); animation: pulse 2.4s ease-out infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(126, 226, 160, 0); } 100% { box-shadow: 0 0 0 0 rgba(126, 226, 160, 0); } }
.hud time { font-variant-numeric: tabular-nums; color: var(--ink); }

body.idle .top, body.idle .hud { opacity: 0; }
body.idle { cursor: none; }
.top:focus-within, .hud:focus-within { opacity: 1 !important; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%; top: calc(64px + var(--safe-t));
  transform: translate(-50%, -12px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 999px;
  background: rgba(20, 26, 48, 0.82); border: 1px solid var(--accent);
  font-size: 0.9rem; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- dialogs ---------- */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px - var(--safe-t) - var(--safe-b));
  padding: 0; border: 1px solid var(--glass-border); border-radius: 20px;
  color: var(--ink); background: rgba(14, 18, 34, 0.94);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}
dialog::backdrop { background: rgba(3, 5, 12, 0.6); }
.sheet { position: relative; padding: 24px 22px 22px; overflow: auto; max-height: calc(100dvh - 26px - var(--safe-t) - var(--safe-b)); }
.sheet h2 { margin: 0 36px 8px 0; font: 600 1.35rem var(--serif); }
.sheet p { margin: 0 0 12px; }
.muted { color: var(--ink-dim); }
.small { font-size: 0.85rem; }
.close {
  position: absolute; top: 10px; right: 10px;
  width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: transparent; color: var(--ink); font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.close:hover { background: rgba(255, 255, 255, 0.08); }
.plain { margin: 0 0 14px; padding-left: 1.1em; }
.plain li { margin-bottom: 8px; }

.stats { display: flex; gap: 12px; margin: 14px 0; }
.stats div {
  flex: 1; padding: 12px; text-align: center;
  background: rgba(255, 255, 255, 0.05); border-radius: 14px;
}
.stats strong { display: block; font: 600 1.8rem var(--serif); color: var(--accent); }
.stats span { font-size: 0.8rem; color: var(--ink-dim); }

.stamps {
  list-style: none; margin: 0 0 14px; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px;
}
.stamp a {
  display: block; padding: 10px 12px; text-decoration: none; color: var(--ink);
  border: 1.5px dashed rgba(242, 196, 109, 0.6); border-radius: 12px;
  background: rgba(242, 196, 109, 0.06);
}
.stamp a:hover { background: rgba(242, 196, 109, 0.14); }
.stamp-no { display: block; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.stamp-name { display: block; font: 600 1.05rem var(--serif); }
.stamp-date { display: block; font-size: 0.78rem; color: var(--ink-dim); }
.empty { grid-column: 1 / -1; color: var(--ink-dim); }

.noscript { position: fixed; inset: auto 0 20% 0; text-align: center; padding: 0 20px; }

/* ---------- small screens & landscape phones ---------- */
@media (max-width: 560px) {
  .btn .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .btn { padding: 0; width: 44px; }
  .brand span { font-size: 1.05rem; }
  .hud { right: calc(14px + var(--safe-r)); max-width: none; }
}
@media (max-height: 460px) {
  .hud { padding: 8px 12px; bottom: calc(46px + var(--safe-b)); }
  .hud p { font-size: 0.8rem; }
  .hud .hud-place { font-size: 0.95rem; margin-bottom: 2px; }
  .hud .hud-left { display: none; }
  .top { padding-top: calc(6px + var(--safe-t)); padding-bottom: 6px; }
}
@media (min-width: 1100px) {
  .hud { left: 28px; padding: 16px 20px; }
  .hud p { font-size: 1rem; }
  .hud .hud-place { font-size: 1.3rem; }
}
@media (prefers-reduced-motion: reduce) {
  .top, .hud, .toast, .btn { transition: none; }
  .dot { animation: none; }
}

/* ---------- station pages & archive ---------- */
body.page { overflow: auto; background: #0b1020; }
.page-hero { position: relative; height: min(56vh, 520px); min-height: 280px; background: linear-gradient(#26345c, #f0a77a); }
.page-hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.page-wrap { max-width: 720px; margin: 0 auto; padding: 24px calc(20px + var(--safe-r)) 56px calc(20px + var(--safe-l)); }
.page-wrap h1 { font: 600 clamp(1.8rem, 6vw, 2.8rem) var(--serif); margin: 0 0 6px; line-height: 1.15; }
.eyebrow { font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin: 0 0 8px; }
.lede { font: 1.15rem/1.6 var(--serif); color: var(--ink); margin: 14px 0 22px; }
.meta { color: var(--ink-dim); margin: 0 0 22px; }
.cta { display: inline-flex; align-items: center; min-height: 48px; padding: 0 22px; border-radius: 999px; background: var(--accent); color: #1a1408; font-weight: 600; text-decoration: none; }
.cta:hover { filter: brightness(1.08); }
.pager { display: flex; justify-content: space-between; gap: 12px; margin: 28px 0 0; padding-top: 18px; border-top: 1px solid var(--glass-border); }
.pager a { min-height: 44px; display: inline-flex; align-items: center; }
.page-top { position: absolute; z-index: 2; }
.archive { list-style: none; margin: 18px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.archive a { display: block; padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); color: var(--ink); text-decoration: none; border: 1px solid var(--glass-border); }
.archive a:hover { background: rgba(242, 196, 109, 0.12); }
.archive .no { display: block; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.archive .nm { display: block; font: 600 1.05rem var(--serif); }
.archive .dt { display: block; font-size: 0.8rem; color: var(--ink-dim); }
.legal h2 { font: 600 1.2rem var(--serif); margin-top: 28px; }

/* ---------- journey dialog: tabs, title, backup, milestones, mosaic ---------- */
.hud button.hud-riders {
  display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 0;
  background: none; border: 0; color: var(--ink); font: 0.9rem var(--sans); text-align: left; cursor: pointer;
}
.hud button.hud-riders[hidden] { display: none; }
.hud-mosaic { color: var(--accent); }
.tabs { display: flex; gap: 6px; margin: 10px 0 14px; border-bottom: 1px solid var(--glass-border); }
.tab {
  padding: 9px 14px; min-height: 44px; border: 0; border-bottom: 2px solid transparent; background: none;
  color: var(--ink-dim); font: 500 0.9rem var(--sans); cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.panel[hidden] { display: none; }
.title-badge {
  display: inline-block; margin: 0 0 4px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--accent); color: var(--accent); font: 600 0.95rem var(--serif);
}
.small { font-size: 0.82rem; }
.stats { flex-wrap: wrap; }
.stats div { flex: 1 1 90px; }
.backup { margin: 14px 0 0; font-size: 0.88rem; }
.backup summary { cursor: pointer; color: var(--accent); min-height: 32px; }
.code-row { display: flex; gap: 8px; margin: 8px 0; }
.code-row input {
  flex: 1; min-width: 0; padding: 10px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.06); color: var(--ink); font: 0.8rem ui-monospace, Menlo, Consolas, monospace;
}
.small-btn {
  padding: 9px 14px; min-height: 40px; border-radius: 10px; border: 1px solid var(--glass-border);
  background: var(--glass); color: var(--ink); font: 500 0.85rem var(--sans); cursor: pointer;
}
.milestones { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }
.milestone { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--glass-border); background: rgba(255, 255, 255, 0.04); }
.milestone.locked { opacity: 0.8; }
.milestone.done { border-color: var(--accent); }
.milestone p { margin: 4px 0 0; }
.ms-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; }
.ms-head span { color: var(--ink-dim); font-size: 0.8rem; white-space: nowrap; }
.meter { height: 8px; margin: 10px 0 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width 0.6s ease; }
.meter.open i { background: #7ee2a0; }
.mosaic-card { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.mosaic-card canvas { width: min(200px, 100%); height: auto; aspect-ratio: 1; border-radius: 12px; background: rgba(255, 255, 255, 0.05); flex: none; }
.mosaic-info { flex: 1 1 200px; min-width: 0; }
.mosaic-status { margin: 0 0 6px; font: 600 1.1rem var(--serif); }

/* ---------- link a screen, tour, TV mode ---------- */
button.cta { border: 0; cursor: pointer; font: inherit; font-weight: 600; }
button.cta:disabled { opacity: 0.6; cursor: default; }
.link-card { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--glass-border); border-radius: 12px; background: rgba(255, 255, 255, 0.04); }
.link-card p { margin: 4px 0 10px; }
.pair-sheet { text-align: center; }
.pair-sheet h2 { margin-right: 36px; text-align: left; }
.pair-sheet p { text-align: left; }
.pair-qr { width: min(280px, 100%); height: auto; aspect-ratio: 1; border-radius: 12px; background: #fff; margin: 6px auto 10px; display: block; }
.tour-sheet h2 { margin-right: 0; font-size: 1.6rem; }
.tour-body { font: 1.05rem/1.6 var(--serif); margin: 10px 0 18px; min-height: 7.5em; }
.tour-dots { display: flex; gap: 8px; justify-content: center; margin: 0 0 16px; }
.tour-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.25); }
.tour-dots i.on { background: var(--accent); }
.tour-actions { display: flex; align-items: center; gap: 8px; }
.tour-actions .spacer { flex: 1; }
.tour-actions .cta { min-height: 40px; padding: 0 18px; }
.about-actions { display: flex; gap: 8px; flex-wrap: wrap; }
body.tv { cursor: none; }
body.tv .btn { min-height: 56px; font-size: 1.1rem; padding: 0 22px; }
body.tv .btn .label { position: static; width: auto; height: auto; clip: auto; }
body.tv .hud { left: 48px; bottom: 90px; padding: 22px 28px; max-width: 640px; }
body.tv .hud p { font-size: 1.35rem; }
body.tv .hud .hud-place { font-size: 1.9rem; }
@media (max-width: 560px) { .tour-actions .small-btn { padding: 0 12px; } }
.tour-actions .small-btn { white-space: nowrap; }

.stream-cap { display: none; }
body.stream .top, body.stream .hud, body.stream .toast { display: none !important; }
body.stream { cursor: none; }
body.stream .stream-cap { display: block; position: fixed; left: 24px; bottom: 18px; margin: 0; padding: 8px 14px; border-radius: 999px; background: var(--glass); color: var(--ink); font: 500 1.05rem var(--sans); z-index: 3; }

/* Text buttons inside dialogs must not inherit the icon-only sizing of the top bar on phones. */
.btn.small-btn { width: auto; min-height: 44px; padding: 0 16px; white-space: normal; text-align: center; line-height: 1.2; }
.link-card .small-btn { width: 100%; }
.tour-actions .btn.small-btn { white-space: nowrap; }
.about-actions .small-btn { flex: 1 1 auto; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; color: var(--ink); }
.btn[hidden], .small-btn[hidden] { display: none !important; }

/* ---------- rider reactions ---------- */
.hud-say { margin: 8px 0 2px; padding: 0; background: none; border: 0; color: var(--accent); font: 500 0.88rem var(--sans); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; min-height: 32px; }
.say-panel {
  position: fixed; z-index: 4; left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r)); bottom: calc(max(50px, 7.5vh) + 14px + var(--safe-b));
  max-width: 460px; padding: 14px; border-radius: 16px; background: #0e1222; border: 1px solid var(--glass-border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.say-panel[hidden] { display: none; }
.say-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.say-grid button { min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--glass-border); background: var(--glass); color: var(--ink); font: 500 0.92rem var(--sans); cursor: pointer; }
.say-grid button[data-emoji] { font-size: 1.3rem; padding: 0 12px; }
.say-grid button:disabled { opacity: 0.45; cursor: default; }
.say-mute { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; font-size: 0.85rem; color: var(--ink-dim); min-height: 32px; }
.say-note { min-height: 1.2em; margin: 4px 0 0; }
.bubbles { position: fixed; z-index: 3; right: calc(14px + var(--safe-r)); bottom: calc(max(50px, 7.5vh) + 14px + var(--safe-b)); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; max-width: min(320px, 70vw); }
.bubble { padding: 9px 14px; border-radius: 16px 16px 4px 16px; background: rgba(14, 18, 34, 0.78); border: 1px solid var(--glass-border); color: var(--ink); font: 0.95rem var(--sans); animation: bubble-in 0.35s ease-out; transition: opacity 0.8s; }
.bubble.emoji { font-size: 1.7rem; padding: 4px 12px; }
.bubble.mine { border-color: var(--accent); }
.bubble.out { opacity: 0; }
@keyframes bubble-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
body.stream .say-panel, body.stream #hud-say { display: none !important; }
body.tv .say-panel, body.tv #hud-say { display: none !important; }
@media (prefers-reduced-motion: reduce) { .bubble { animation: none; } }
@media (max-height: 460px) { .hud-say { display: none; } }

.small-h { font: 600 1rem var(--sans); margin: 26px 0 8px; color: var(--ink-dim); }
.nearby { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.nearby a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--glass-border); color: var(--ink); text-decoration: none; background: rgba(255,255,255,0.05); }
.keep-safe { border-color: var(--accent); }

/* ---------- accessibility ---------- */
.hud, .toast, .top .btn { -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
@media (pointer: coarse) { .hud-say, .say-mute, .backup summary { min-height: 44px; display: inline-flex; align-items: center; } }
@media (prefers-contrast: more) {
  :root { --glass: rgba(6, 8, 18, 0.95); --glass-border: rgba(255, 255, 255, 0.5); --ink-dim: #f4efe6; }
}
.skip { position: absolute; left: -9999px; top: 8px; z-index: 10; padding: 10px 14px; background: #fff; color: #10141f; border-radius: 8px; }
.skip:focus { left: 8px; }
