:root {
  color-scheme: dark;
  --ink: #f4f1ec;
  --ink-2: rgba(244, 241, 236, 0.72);
  --ink-3: rgba(244, 241, 236, 0.5);
  --glass: rgba(14, 18, 30, 0.52);
  --glass-2: rgba(22, 27, 42, 0.68);
  --line: rgba(255, 255, 255, 0.14);
  --accent: #f3b26b;
  --good: #7ee0a1;
  --bad: #ff6b5e;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b1020; color: var(--ink); font-family: Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; touch-action: none; user-select: none; -webkit-user-select: none; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font-family: 'JetBrains Mono', monospace; font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgba(255,255,255,0.1); border: 1px solid var(--line); margin-right: 3px; }

/* ---------- loader ---------- */
.loader { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; background: radial-gradient(ellipse at 50% 40%, rgba(20,28,52,0.55), rgba(5,8,16,0.85)); opacity: 0; pointer-events: none; transition: opacity .35s; }
.loader.show { opacity: 1; pointer-events: auto; }
.loader-card { display: flex; align-items: center; gap: 14px; padding: 16px 22px; border-radius: 16px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); font-weight: 500; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid rgba(255,255,255,0.2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- menu ---------- */
.menu { position: fixed; inset: 0; z-index: 20; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding: calc(64px + var(--safe-t)) 16px calc(24px + var(--safe-b)); background: linear-gradient(90deg, rgba(6,9,18,0.82) 0%, rgba(6,9,18,0.55) 46%, rgba(6,9,18,0.0) 75%); display: none; }
.menu.show { display: block; }
.menu-inner { max-width: 640px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; color: #10131d; background: linear-gradient(135deg, var(--accent), #ffe2bf); box-shadow: 0 8px 30px rgba(0,0,0,.35); flex: none; }
.brand-mark svg { width: 34px; height: 34px; }
h1 { font-family: Fraunces, Georgia, serif; font-weight: 700; font-size: clamp(34px, 6vw, 52px); margin: 0; letter-spacing: -0.02em; line-height: 1; text-shadow: 0 4px 30px rgba(0,0,0,.4); }
.tag { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; }
.panel { background: var(--glass); border: 1px solid var(--line); border-radius: 18px; padding: 14px; backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2); }
.label { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dest-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.dest { position: relative; text-align: left; border: 1px solid var(--line); border-radius: 14px; padding: 10px; min-height: 104px; background: var(--card-bg, #223); overflow: hidden; transition: transform .15s, border-color .15s, box-shadow .15s; display: flex; flex-direction: column; justify-content: flex-end; }
.dest::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 30%, rgba(0,0,0,.55)); }
.dest > * { position: relative; z-index: 1; }
.dest:hover { transform: translateY(-2px); }
.dest.on { border-color: rgba(255,255,255,.85); box-shadow: 0 0 0 2px rgba(255,255,255,.25), 0 10px 30px rgba(0,0,0,.35); }
.dest .nm { font-weight: 700; font-size: 14px; line-height: 1.15; }
.dest .pl { font-size: 11px; color: var(--ink-2); }
.dest .pc { position: absolute; top: 8px; right: 8px; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 999px; background: rgba(0,0,0,.35); z-index: 1; }
.dest-desc { margin-top: 10px; font-size: 13px; color: var(--ink-2); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-height: 40px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); font-weight: 600; font-size: 13px; transition: background .15s, border-color .15s; }
.seg button.on { background: rgba(255,255,255,0.92); color: #11141c; border-color: transparent; }
.blurb { margin-top: 8px; font-size: 12.5px; color: var(--ink-2); min-height: 16px; }
.settings { display: grid; gap: 8px; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--ink-2); }
.set select { font: inherit; color: var(--ink); background: rgba(255,255,255,0.08); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; max-width: 62%; }
.set select option { background: #161b2a; }
.switch input { display: none; }
.switch i { width: 40px; height: 24px; border-radius: 999px; background: rgba(255,255,255,0.18); position: relative; transition: background .2s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }
.cta-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.cta { border: 0; border-radius: 14px; padding: 14px 30px; font-weight: 700; font-size: 16px; color: #14110d; background: linear-gradient(135deg, var(--accent), #ffe3c4); box-shadow: 0 10px 30px rgba(0,0,0,.35); transition: transform .12s, filter .12s; }
.cta:hover { transform: translateY(-1px); filter: brightness(1.05); }
.cta.small { padding: 9px 16px; font-size: 14px; }
.ghost { border: 1px solid var(--line); border-radius: 14px; padding: 12px 18px; font-weight: 600; background: rgba(255,255,255,0.06); }
.ghost.small { padding: 8px 14px; font-size: 14px; }
.keys-hint { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 12px; color: var(--ink-3); }
body.touch .keys-hint { display: none; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; display: none; font-variant-numeric: tabular-nums; }
.hud.show { display: block; }
body.photo-mode .hud { display: none; }
.hud-btn { pointer-events: auto; position: fixed; z-index: 30; min-width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-weight: 800; letter-spacing: -1px; }
.pause-btn { top: max(10px, var(--safe-t)); right: calc(max(12px, var(--safe-r)) + 54px); }
.hud-top { position: absolute; top: calc(64px + var(--safe-t)); left: max(12px, var(--safe-l)); right: max(12px, var(--safe-r)); display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.chip { padding: 8px 12px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 13px; font-weight: 600; white-space: nowrap; }
.chip .k { font-size: 10px; letter-spacing: .14em; color: var(--ink-3); margin-right: 8px; }
.chip.score b { font-family: 'JetBrains Mono', monospace; font-size: 15px; }
.place small { color: var(--ink-3); font-weight: 500; margin-left: 6px; }
.compass { position: relative; width: min(360px, 42vw); height: 36px; overflow: hidden; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent); }
.compass-tape { position: absolute; top: 0; left: 50%; height: 100%; white-space: nowrap; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--ink-2); }
.compass-tape span { position: absolute; top: 5px; transform: translateX(-50%); }
.compass-tape span.card { color: var(--ink); font-weight: 700; font-size: 13px; top: 4px; }
.compass-tape i { position: absolute; bottom: 0; width: 1px; height: 6px; background: rgba(255,255,255,.4); }
.compass-mark { position: absolute; left: 50%; top: 0; width: 2px; height: 8px; background: var(--accent); transform: translateX(-50%); }
.hdg-num { position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%); font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--accent); }
.race-bar { position: absolute; top: calc(110px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: none; gap: 12px; align-items: baseline; padding: 8px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 13px; white-space: nowrap; }
.race-bar.show { display: flex; }
.race-bar b { font-family: 'JetBrains Mono', monospace; font-size: 18px; }
.race-bar span:last-child { color: var(--ink-3); }
.gauge { position: absolute; top: 46%; transform: translateY(-50%); text-align: center; padding: 10px 14px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); min-width: 92px; }
.gauge.left { left: max(14px, var(--safe-l)); }
.gauge.right { right: max(14px, var(--safe-r)); }
.g-num { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 26px; line-height: 1; }
.g-unit { font-size: 11px; color: var(--ink-3); margin-top: 4px; letter-spacing: .08em; }
.vs { color: var(--ink-2); }
.warn { position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%); font-weight: 800; font-size: 22px; letter-spacing: .2em; color: var(--bad); text-shadow: 0 2px 20px rgba(0,0,0,.6); opacity: 0; transition: opacity .2s; white-space: nowrap; }
.warn.show { opacity: 1; animation: blink .6s steps(2) infinite; }
.warn.soft { color: var(--accent); animation: none; }
@keyframes blink { 50% { opacity: .35; } }
.toasts { position: absolute; top: calc(160px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(92vw, 520px); }
.toast { padding: 9px 16px; border-radius: 999px; background: var(--glass-2); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); font-weight: 600; font-size: 14px; animation: toastIn .3s ease-out, toastOut .4s ease-in forwards 2.4s; text-align: center; }
.toast b { color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px); } }
.combo { position: absolute; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-weight: 800; letter-spacing: .12em; font-size: 14px; color: var(--accent); opacity: 0; transition: opacity .25s; text-shadow: 0 2px 14px rgba(0,0,0,.6); white-space: nowrap; }
.combo.show { opacity: 1; }
.ring-arrow { position: absolute; left: 0; top: 0; width: 44px; height: 44px; margin: -22px 0 0 -22px; color: #ffd36b; display: none; filter: drop-shadow(0 2px 8px rgba(0,0,0,.6)); }
.ring-arrow.show { display: block; }
.ring-arrow svg { width: 44px; height: 44px; }
.ring-arrow span { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 700; white-space: nowrap; color: #fff; text-shadow: 0 1px 6px #000; }
.hud-bottom { position: absolute; bottom: calc(16px + var(--safe-b)); left: 50%; transform: translateX(-50%); }
.bars { display: flex; gap: 10px; padding: 9px 12px; border-radius: 14px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.bar { display: flex; align-items: center; gap: 8px; font-size: 10px; font-weight: 700; letter-spacing: .12em; color: var(--ink-3); }
.track { width: 110px; height: 6px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; }
.fill { height: 100%; width: 50%; border-radius: inherit; }
.fill.thr { background: linear-gradient(90deg, #8fd3ff, #fff); }
.fill.boost { background: linear-gradient(90deg, var(--accent), #ffe0b8); }
.minimap { position: absolute; right: max(14px, var(--safe-r)); bottom: calc(14px + var(--safe-b)); width: 150px; height: 150px; border-radius: 50%; border: 1px solid var(--line); box-shadow: 0 8px 30px rgba(0,0,0,.4); background: rgba(10,14,24,.5); }

/* touch controls */
.touch-ui { display: none; }
body.touch .touch-ui { display: block; }
body.touch .chip.place { visibility: hidden; }
body.touch .toasts { top: calc(232px + var(--safe-t)); }
body.touch .minimap { width: 112px; height: 112px; bottom: auto; top: calc(110px + var(--safe-t)); right: max(10px, var(--safe-r)); }
body.touch .gauge { top: auto; bottom: calc(196px + var(--safe-b)); padding: 6px 10px; min-width: 72px; }
body.touch .g-num { font-size: 19px; }
body.touch .hud-bottom { bottom: calc(10px + var(--safe-b)); }
body.touch .bars { padding: 6px 8px; gap: 8px; }
body.touch .track { width: 60px; }
.stick { pointer-events: auto; position: absolute; left: calc(18px + var(--safe-l)); bottom: calc(44px + var(--safe-b)); width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.22); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); touch-action: none; }
.knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: rgba(255,255,255,.85); box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.touch-right { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(44px + var(--safe-b)); display: flex; align-items: flex-end; gap: 12px; }
.t-btn { pointer-events: auto; touch-action: none; border-radius: 50%; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); font-weight: 800; font-size: 12px; letter-spacing: .08em; }
.t-btn.small { width: 52px; height: 52px; font-size: 10px; margin-bottom: 96px; }
.boost-btn { width: 84px; height: 84px; }
.boost-btn.on { background: var(--accent); color: #111; }
.throttle { pointer-events: auto; touch-action: none; position: relative; width: 52px; height: 150px; border-radius: 16px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.22); overflow: hidden; }
.throttle-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 60%; background: linear-gradient(0deg, rgba(143,211,255,.55), rgba(255,255,255,.75)); }
.throttle span { position: absolute; top: 6px; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 800; letter-spacing: .1em; color: rgba(255,255,255,.8); mix-blend-mode: difference; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 40; display: none; place-items: center; padding: 16px; background: rgba(5,8,16,.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.overlay.show { display: grid; }
.sheet { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px; border-radius: 22px; background: var(--glass-2); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.sheet h2 { font-family: Fraunces, Georgia, serif; font-size: 30px; margin: 0 0 12px; }
.sheet-btns { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); }
body.touch .help-grid { display: none; }
.postcards { display: flex; flex-wrap: wrap; gap: 6px; }
.postcards .p { font-size: 12px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-3); }
.postcards .p.got { color: #14110d; background: var(--accent); border-color: transparent; font-weight: 600; }
.res-time { font-family: 'JetBrains Mono', monospace; font-size: 46px; font-weight: 700; }
.res-best { color: var(--ink-2); margin-top: 4px; }
.res-best b { color: var(--good); }

/* photo mode */
.photo { position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-b)); z-index: 35; display: none; justify-content: center; pointer-events: none; }
body.photo-mode .photo { display: flex; }
.photo-bar { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-radius: 16px; background: var(--glass-2); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); font-size: 13px; color: var(--ink-2); flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px); }

/* postcard popup */
.postcard { position: fixed; z-index: 15; left: 50%; bottom: calc(80px + var(--safe-b)); transform: translate(-50%, 30px); width: min(420px, calc(100vw - 32px)); padding: 16px 18px; border-radius: 18px; background: linear-gradient(135deg, rgba(255,248,236,.96), rgba(255,236,214,.94)); color: #2a2118; box-shadow: 0 20px 60px rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .4s, transform .4s; }
.postcard.show { opacity: 1; transform: translate(-50%, 0); }
.pc-kicker { font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; color: #b3612e; }
.pc-name { font-family: Fraunces, Georgia, serif; font-size: 24px; font-weight: 700; margin: 4px 0; }
.pc-fact { font-size: 13.5px; line-height: 1.45; color: #4a3d30; }
body.touch .postcard { bottom: auto; top: calc(170px + var(--safe-t)); }

.cloud-fog { position: fixed; inset: 0; z-index: 5; pointer-events: none; background: radial-gradient(ellipse at center, rgba(235,240,248,.75), rgba(225,232,242,.95)); opacity: 0; }
.flash { position: fixed; inset: 0; z-index: 6; pointer-events: none; background: #fff; opacity: 0; transition: opacity .6s; }

@media (max-width: 760px) {
  .dest-grid { grid-template-columns: repeat(3, 1fr); }
  .row2 { grid-template-columns: 1fr; }
  .menu { background: linear-gradient(180deg, rgba(6,9,18,0.5), rgba(6,9,18,0.82) 40%); }
  .compass { width: 38vw; }
  .chip.place { display: none; }
}
@media (max-width: 420px) {
  .dest-grid { grid-template-columns: repeat(2, 1fr); }
  .dest { min-height: 84px; }
  .hud-top { gap: 6px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  body.touch .stick { width: 120px; height: 120px; bottom: calc(14px + var(--safe-b)); }
  body.touch .touch-right { bottom: calc(14px + var(--safe-b)); }
  body.touch .throttle { height: 120px; }
  body.touch .t-btn.small { margin-bottom: 70px; }
  body.touch .gauge { bottom: auto; top: calc(110px + var(--safe-t)); }
  body.touch .gauge.right { right: calc(max(10px, var(--safe-r)) + 124px); }
  body.touch .minimap { width: 96px; height: 96px; }
  body.touch .toasts { top: calc(104px + var(--safe-t)); width: min(60vw, 460px); }
  .race-bar { top: calc(64px + var(--safe-t)); }
}
