/* Keystorm — a night-time neon race. Desktop 1280x720 and phone 390x844. */
:root {
  --bg: #0b0d1f;
  --panel: #151935;
  --panel2: #1d2246;
  --ink: #e8ebff;
  --muted: #9aa3d6;
  --accent: #7cf3ff;
  --accent2: #ff5cad;
  --good: #69f0ae;
  --bad: #ff5370;
  --gold: #ffd166;
  --vvh: 100vh;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
.muted { color: var(--muted); }

/* ── game screen ─────────────────────────────────────────────────────── */
#game {
  position: fixed; left: 0; right: 0; top: 0; height: var(--vvh);
  display: flex; flex-direction: column; overflow: hidden;
  background:
    radial-gradient(900px 400px at 15% -10%, rgba(124, 243, 255, .12), transparent 60%),
    radial-gradient(800px 420px at 100% 110%, rgba(255, 92, 173, .12), transparent 60%),
    var(--bg);
}
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(10, 12, 30, .8); border-bottom: 1px solid rgba(124, 243, 255, .15);
}
.tb-mode { font-weight: 800; letter-spacing: .04em; color: var(--accent); min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tb-stats { display: flex; gap: 14px; }
.stat { display: flex; align-items: baseline; gap: 3px; }
.stat b { font: 800 22px ui-monospace, Menlo, Consolas, monospace; color: #fff; }
.stat small { color: var(--muted); font-size: 11px; }
.tb-right { display: flex; gap: 8px; align-items: center; }
.tb-btn, .help-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(124, 243, 255, .35);
  background: var(--panel2); color: var(--ink); font-weight: 700;
}
/* anchored to the lobby PANE, not the card: the card's top row is the audio
   strip, and on a phone the "?" sat on top of its skip-track button */
#lobbyPane { position: relative; }
.help-btn.corner { position: absolute; top: 4px; right: 0; }
.hud-gear { position: relative; }
.hud-gear summary {
  list-style: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  background: var(--panel2); border: 1px solid rgba(124, 243, 255, .35);
}
.hud-gear summary::-webkit-details-marker { display: none; }
/* site_audio.css pins #hudAudio fixed bottom-centre; inside the gear it sits
   under the button instead, so restate ALL four placement properties. */
#hudAudio {
  position: absolute; top: 42px; right: 0; left: auto; bottom: auto; transform: none;
  z-index: 30; width: max-content; max-width: 92vw;
}
/* web/style.css pins .volume-slider position:fixed top:12px — undo it here
   (CLAUDE.md item 5). */
.volume-slider { position: static !important; top: auto !important; }

.stage {
  flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px;
  padding: 12px 16px 12px; max-width: 1180px; width: 100%; margin: 0 auto;
}
.track-wrap { position: relative; flex: 0 0 auto; border-radius: 12px; overflow: hidden;
  border: 1px solid rgba(124, 243, 255, .2); box-shadow: 0 6px 30px rgba(0,0,0,.35); }
#track, #sky { display: block; width: 100%; }
.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font: 900 72px system-ui, sans-serif; color: #fff; text-shadow: 0 0 24px var(--accent);
  background: rgba(5, 6, 18, .35); pointer-events: none;
}
.countdown.go { color: var(--good); text-shadow: 0 0 30px var(--good); }

.type-col { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.passage {
  flex: 0 1 auto; min-height: 3.4em; max-height: 40vh; overflow-y: auto;
  padding: 14px 16px; border-radius: 12px; background: var(--panel);
  border: 1px solid rgba(124, 243, 255, .15);
  font: 500 22px/1.55 ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; color: #c3c9f5;
}
#pDone { color: var(--good); opacity: .75; }
#pErr { background: var(--bad); color: #fff; border-radius: 3px; }
#pWord { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; color: #fff; }
.passage.has-err #pWord { text-decoration-color: var(--bad); }
.caret { display: inline-block; width: 2px; height: 1.15em; margin: 0 -1px; vertical-align: text-bottom;
  background: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.passage.survival { display: none; }

.input-row { position: relative; }
#typeInput {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 2px solid rgba(124, 243, 255, .35);
  background: #0f1230; color: #fff; outline: none;
  font: 600 20px ui-monospace, Menlo, Consolas, monospace;
}
#typeInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 243, 255, .15); }
#typeInput.err { border-color: var(--bad); background: #2a0f1c; animation: shake .18s; }
#typeInput:disabled { opacity: .55; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.refused {
  position: absolute; left: 8px; right: 8px; top: calc(100% + 6px); z-index: 6; padding: 6px 10px; border-radius: 8px;
  background: var(--bad); color: #fff; font-weight: 700; font-size: 14px; text-align: center;
}

.hud-board { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); }
.hud-row { display: inline-flex; align-items: baseline; gap: 6px; padding: 3px 9px; border-radius: 999px;
  background: rgba(255,255,255,.05); }
.hud-row.me { background: rgba(124, 243, 255, .12); color: var(--ink); }
.hud-row .sw { width: 9px; height: 9px; border-radius: 50%; align-self: center; }
.hud-row .who { font-weight: 700; color: var(--ink); }
.hud-row .v { font-family: ui-monospace, monospace; }
.hud-row.out { opacity: .5; }
.watch-bar { display: flex; align-items: center; gap: 10px; justify-content: center; color: var(--muted); }

.coach {
  background: rgba(15, 18, 48, .95); border: 1px solid var(--gold); border-radius: 12px;
  padding: 10px 12px; display: flex; gap: 10px; align-items: center;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}
.coach-text { flex: 1; font-size: 15px; line-height: 1.4; }
.coach-text b { color: var(--gold); }
.coach-nav { display: flex; gap: 6px; }

.toast-box { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: rgba(20, 24, 60, .95); border: 1px solid var(--accent); color: #fff;
  padding: 7px 14px; border-radius: 999px; font-size: 14px; animation: pop .25s; }
.toast.bad { border-color: var(--bad); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }

.spectator-flag {
  position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 12px; z-index: 9;
  padding: 4px 12px; background: var(--panel2); color: var(--ink); border-radius: 999px; font-size: 12px;
  border: 1px solid var(--accent);
}

/* ── lobby card ─────────────────────────────────────────────────────── */
#lobbyOverlay {
  position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center;
  z-index: 10; overflow-y: auto; padding: 22px 0;
  background:
    radial-gradient(900px 520px at 18% 8%, rgba(124, 243, 255, .14), transparent 60%),
    radial-gradient(800px 520px at 85% 92%, rgba(255, 92, 173, .16), transparent 60%),
    var(--bg);
}
.card {
  width: min(500px, 94vw); padding: 20px 20px 16px; margin: auto 0; position: relative;
  border-radius: 16px; text-align: center; background: var(--panel);
  border: 1px solid rgba(124, 243, 255, .22); box-shadow: 0 10px 50px rgba(0,0,0,.5);
}
.card.results-wide { width: min(820px, 96vw); }
.lobby-audio { margin-bottom: 8px; }
.ks-title { margin: 6px 0 2px; font-size: 46px; font-weight: 900; letter-spacing: -.02em; color: #fff;
  text-shadow: 0 0 22px rgba(124, 243, 255, .5); }
.ks-title span { color: var(--accent2); text-shadow: 0 0 22px rgba(255, 92, 173, .55); }
.ks-title.small { font-size: 32px; }
.tagline { color: var(--muted); margin: 0 0 14px; }
#nameInput { width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid rgba(124,243,255,.3);
  background: #0f1230; color: #fff; font-size: 16px; margin-bottom: 10px; }
.primary, .secondary { display: block; width: 100%; padding: 12px; margin: 8px 0; border-radius: 12px;
  font-weight: 800; font-size: 16px; border: 0; }
.primary { background: linear-gradient(90deg, var(--accent), #8f7cff); color: #0b0d1f; }
.primary:disabled { opacity: .45; cursor: default; }
.secondary { background: var(--panel2); color: var(--ink); border: 1px solid rgba(124,243,255,.3); }
.link-row { display: flex; justify-content: center; gap: 4px 14px; flex-wrap: wrap; margin: 8px 0; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 6px; }
.back-link { display: inline-block; margin-top: 10px; color: var(--muted); font-size: 14px; }

.setup { text-align: left; margin: 6px 0 4px; }
.settings-row { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.settings-label { width: 82px; flex: 0 0 82px; font-size: 13px; color: var(--muted); }
.seg { display: flex; gap: 4px; flex: 1; }
.seg.wrap { flex-wrap: wrap; }
.seg button { flex: 1; padding: 7px 6px; border-radius: 8px; border: 1px solid rgba(124,243,255,.25);
  background: #0f1230; color: var(--ink); font-size: 13px; white-space: nowrap; }
.seg button.on { background: var(--accent); color: #0b0d1f; font-weight: 800; border-color: var(--accent); }
.seg.locked button { cursor: default; }
.seg.locked button:not(.on) { opacity: .5; }
.setup.mode-survival .race-only { display: none; }
.setup.no-bots .bots-only { display: none; }

.squad-count { color: var(--muted); margin-bottom: 6px; }
.player-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; text-align: left; }
.player-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #0f1230; }
.player-row .dot { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-weight: 800; color: #0b0d1f; }
.player-row .player-name { font-weight: 700; flex: 1; min-width: 0; }
.player-row .tag { font-size: 12px; color: var(--muted); }
.leaderboard { margin-top: 12px; text-align: left; }

/* results */
.result-note { margin: 4px 0 10px; font-weight: 700; color: var(--gold); }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 8px 0 14px; }
.pod { display: flex; flex-direction: column; align-items: center; min-width: 96px; max-width: 170px; }
.pod .pname { font-weight: 700; font-size: 14px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }
.pod .ppts { color: var(--muted); font-size: 13px; margin: 2px 0 4px; }
.pod .block { width: 100%; border-radius: 8px 8px 0 0; display: flex; align-items: flex-start;
  justify-content: center; padding-top: 6px; font-weight: 900; color: #0b0d1f; }
.pod.p1 .block { height: 70px; background: var(--gold); }
.pod.p2 .block { height: 50px; background: #c9d3ff; }
.pod.p3 .block { height: 36px; background: #f0a37a; }
.passage-source { color: var(--muted); font-size: 13px; margin: 10px 0; font-style: italic; }
.result-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.result-btns button[style*="none"] + button { grid-column: auto; }

/* how-to */
.howto { position: fixed; inset: 0; z-index: 50; background: rgba(4, 5, 16, .75);
  display: flex; align-items: center; justify-content: center; padding: 12px; }
.howto-card { width: min(520px, 100%); background: var(--panel); border-radius: 16px; padding: 18px;
  position: relative; border: 1px solid var(--accent); }
.howto-x { position: absolute; top: 10px; right: 10px; background: none; border: 0; color: var(--muted); font-size: 18px; }
.howto-card h2 { margin: 0 0 10px; }
.hstep { display: none; }
.hstep.on { display: block; }
.hstep h3 { margin: 10px 0 4px; color: var(--accent); }
.hstep p { margin: 0; line-height: 1.5; color: #d5d9ff; }
.hart { min-height: 70px; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #0f1230; border-radius: 12px; padding: 10px; flex-wrap: wrap; }
.demo { font: 600 20px ui-monospace, monospace; color: #c3c9f5; }
.d-done { color: var(--good); }
.d-err { background: var(--bad); color: #fff; }
.d-word { text-decoration: underline; color: #fff; }
.fake-key { border: 1px solid var(--muted); border-radius: 6px; padding: 4px 10px; }
.pill-stat { background: var(--panel2); padding: 6px 12px; border-radius: 999px; }
.pill-stat b { font-size: 22px; color: #fff; }
.meteor { font: 700 16px ui-monospace, monospace; border: 1px solid #748ffc; border-radius: 8px; padding: 4px 10px; }
.meteor.hot { border-color: var(--gold); color: var(--gold); }
.ghost-car { opacity: .7; border: 1px dashed #c0c8ff; padding: 6px 12px; border-radius: 999px; }
.howto-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.howto-dots { display: flex; gap: 6px; }
.howto-dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--panel2); }
.howto-dots i.on { background: var(--accent); }
.mini-btn { padding: 7px 12px; border-radius: 8px; border: 1px solid rgba(124,243,255,.3);
  background: var(--panel2); color: var(--ink); font-size: 13px; }
.mini-btn:disabled { opacity: .4; }
.primary-mini { background: var(--accent); color: #0b0d1f; font-weight: 800; border-color: var(--accent); }
.warm-link { display: block; margin: 10px auto 0; }

/* ── phone ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .stage { padding: 8px 8px 8px; gap: 6px; }
  .topbar { padding: 6px 8px; padding-top: calc(6px + env(safe-area-inset-top)); gap: 6px; }
  .tb-stats { gap: 8px; }
  .stat b { font-size: 17px; }
  #statTimeBox { display: none; }
  .tb-btn, .help-btn, .hud-gear summary { width: 30px; height: 30px; }
  .passage { font-size: 17px; padding: 9px 10px; line-height: 1.45; }
  #typeInput { font-size: 17px; padding: 9px 10px; }
  .hud-board { font-size: 12px; gap: 4px 6px; max-height: 3.6em; overflow: hidden; }
  .countdown { font-size: 54px; }
  .result-btns { grid-template-columns: 1fr; }
  .ks-title { font-size: 38px; }
  .card { padding: 16px 14px 12px; }
  .settings-label { width: 64px; flex-basis: 64px; }
}
/* the on-screen keyboard is up: give the passage the room */
body.kb-open .hud-board { display: none; }
body.kb-open .stage { gap: 4px; padding-top: 4px; }
