/* ==========================================================================
   lc3d — 404 easter-egg light cycle game
   Part 1: the innocent 404 shell (respects light/dark browser theme)
   Part 2: the neon game UI (always dark — it's a light-cycle grid)
   ========================================================================== */

:root {
  --ui-scale: 1;
  --cyan: #00e5ff;
  --cyan-dim: rgba(0, 229, 255, .35);
  --orange: #ff9a00;
  --bg: #05070d;
  --panel: rgba(8, 14, 24, .88);
  --text: #d7f4ff;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "Courier New", monospace;
  --tc-btn: 76px; /* on-screen steer/throttle button diameter — also used to
                      keep the minimap clear of the throttle buttons, see below */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: #f4f6f9; color: #1c2430; }

@media (prefers-color-scheme: dark) {
  body { background: #0d1117; color: #dbe4ee; }
}

/* ==========================================================================
   Part 1 — 404 shell
   ========================================================================== */

#page404 {
  min-height: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.err-card { text-align: center; max-width: 540px; }
.err-code {
  font-size: clamp(90px, 22vw, 180px);
  font-weight: 200; letter-spacing: .04em; line-height: 1;
  display: flex; justify-content: center; align-items: center; gap: .02em;
}
.err-code span { opacity: .92; }
#egg-zero {
  font: inherit; color: inherit; background: none; border: none; cursor: default;
  padding: 0 .02em; border-radius: 12px; transition: color .4s, text-shadow .4s;
}
#egg-zero:hover, #egg-zero.beckon {
  color: var(--cyan); cursor: pointer;
  text-shadow: 0 0 18px var(--cyan-dim), 0 0 40px var(--cyan-dim);
}
#egg-zero.beckon { animation: beckon 2.6s ease-in-out infinite; }
@keyframes beckon { 0%, 100% { text-shadow: none; } 50% { text-shadow: 0 0 22px var(--cyan-dim); } }
/* Flynn's hello: flickers on whenever the zero lights up — on hover, and
   for good once it starts beckoning (.greet, see main.js). Its space is
   always reserved, so the 404 doesn't shift when it appears. */
.err-greet {
  font-family: var(--mono); font-size: clamp(15px, 3.6vw, 24px); letter-spacing: .12em;
  color: var(--cyan); text-shadow: 0 0 18px var(--cyan-dim);   /* lit like the zero */
  margin-bottom: 6px; visibility: hidden; opacity: 0; transition: opacity .5s, visibility .5s;
}
.err-card.greet .err-greet { visibility: visible; opacity: 1; animation: greet-on 1.1s linear both; }
.err-card:has(#egg-zero:hover) .err-greet { visibility: visible; opacity: 1; animation: greet-on 1.1s linear both; }
@keyframes greet-on {
  0% { opacity: 0; } 8% { opacity: 1; } 14% { opacity: .15; } 22% { opacity: 1; }
  30% { opacity: .35; } 38%, 100% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .err-greet { animation: none !important; } }
.err-card h2 { font-weight: 600; font-size: 26px; margin: 10px 0 8px; }
.err-card p { opacity: .75; line-height: 1.55; }
.err-actions { margin: 22px 0 14px; }
.err-btn {
  display: inline-block; padding: 10px 22px; border-radius: 8px;
  background: #2563eb; color: #fff; text-decoration: none; font-weight: 600;
}
.err-btn:hover { filter: brightness(1.1); }
.err-fine { font-size: 12px; opacity: .45 !important; }

/* Glitch-out when the egg opens */
#page404.derez { animation: derez .6s steps(8) forwards; }
@keyframes derez {
  0% { filter: none; transform: none; opacity: 1; }
  30% { filter: hue-rotate(90deg) contrast(3); transform: translateX(-6px) skewX(3deg); }
  60% { filter: invert(1); transform: translateX(8px) scaleY(1.04); }
  100% { filter: contrast(6) brightness(3); transform: scale(1.06); opacity: 0; }
}

/* ==========================================================================
   Part 2 — Game overlay
   ========================================================================== */

#game { position: fixed; inset: 0; background: var(--bg); color: var(--text); }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#pre-loader {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--cyan); letter-spacing: .5em; font-size: 14px; z-index: 40;
  background: var(--bg);
}
/* The UI layer must not steal touches/clicks aimed at the canvas: the layer
   itself is transparent to input, individual widgets opt back in. */
.game-ui { position: absolute; inset: 0; font-size: calc(15px * var(--ui-scale)); pointer-events: none; }
.game-ui > * { pointer-events: auto; }
#toasts, #countdown { pointer-events: none !important; }

.hidden { display: none !important; }

/* ---------------- screens ---------------- */
.screen {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; justify-content: safe center; /* keep top reachable when content overflows */
  gap: calc(18px * var(--ui-scale));
  background: radial-gradient(ellipse at center, rgba(3, 8, 16, .45) 0%, rgba(3, 8, 16, .82) 100%);
  animation: screenIn .45s ease both;
  padding: 20px; overflow-y: auto;
}
@keyframes screenIn { from { opacity: 0; transform: scale(1.02); } to { opacity: 1; transform: none; } }

.screen h2 {
  font-weight: 300; letter-spacing: .45em; color: var(--cyan);
  font-size: calc(24px * var(--ui-scale)); text-shadow: 0 0 18px var(--cyan-dim);
}

/* loading */
#scr-loading { background: var(--bg); z-index: 35; }
.loader-ring {
  width: 84px; height: 84px; border-radius: 50%;
  border: 2px solid var(--cyan-dim); border-top-color: var(--cyan);
  animation: spin 1s linear infinite;
  box-shadow: 0 0 30px var(--cyan-dim), inset 0 0 30px rgba(0, 229, 255, .12);
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { letter-spacing: .45em; font-size: 13px; color: var(--cyan); }
.dots::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* title */
.game-title {
  font-weight: 100; letter-spacing: .18em; text-align: center; line-height: 1.05;
  font-size: clamp(42px, 9vw, 92px); color: #eafcff;
  text-shadow: 0 0 24px var(--cyan-dim), 0 0 80px rgba(0, 229, 255, .25);
}
.game-title span { color: var(--cyan); font-weight: 600; }
.game-title em {
  display: block; font-style: normal; font-size: clamp(11px, 1.6vw, 15px);
  letter-spacing: .8em; color: var(--orange); margin-top: 10px;
}

/* menus */
.menu {
  display: flex; flex-direction: column; gap: 10px; min-width: min(320px, 80vw);
  background: var(--panel); border: 1px solid rgba(0, 229, 255, .15);
  padding: 24px 30px;
}
.menu button, .row-btns button, .panel button {
  font: inherit; text-transform: uppercase; letter-spacing: .28em;
  background: rgba(0, 229, 255, .05); color: var(--text);
  border: 1px solid var(--cyan-dim); padding: 13px 26px; cursor: pointer;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
  transition: background .18s, box-shadow .18s, color .18s;
}
.menu button:hover, .row-btns button:hover, .panel button:hover {
  background: rgba(0, 229, 255, .16); box-shadow: 0 0 24px var(--cyan-dim); color: #fff;
}
button.primary { border-color: var(--cyan); color: var(--cyan); background: rgba(0, 229, 255, .1); }
button.ghost { opacity: .65; }

/* Keyboard / gamepad navigation (ui.js "Menu navigation"): the focused
   control gets a white outline — distinct from the cyan glow that marks a
   chip's current choice. Only while navigating that way (.nav-kbd). The
   angled menu buttons clip outlines, so they light up from inside instead. */
.game-ui :focus { outline: none; }
.game-ui.nav-kbd :focus { outline: 2px solid #fff; outline-offset: 2px; box-shadow: 0 0 16px var(--cyan-dim); }
.game-ui.nav-kbd :is(.menu, .row-btns, .panel) button:focus {
  background: rgba(0, 229, 255, .26); color: #fff; border-color: #fff; opacity: 1;
  text-shadow: 0 0 10px var(--cyan);
}
.game-ui.nav-kbd .opt:focus-within { background: rgba(0, 229, 255, .08); box-shadow: inset 3px 0 0 var(--cyan); }
.game-ui.nav-kbd .opt :focus { outline-offset: 1px; }
.menu-foot { font-size: 11px; letter-spacing: .3em; opacity: .35; }
.row-btns { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

/* setup */
.setup-grid {
  display: grid; grid-template-columns: minmax(260px, 380px) minmax(260px, 420px);
  gap: 26px; max-width: 900px; width: 100%; justify-content: center;
}
/* Solid backing behind each column — without it the busy 3D grid floor shows
   straight through the text/options, making the setup screen hard to read. */
.setup-grid > section {
  background: var(--panel); border: 1px solid rgba(0, 229, 255, .15);
  padding: 18px 22px;
}
@media (max-width: 720px) { .setup-grid { grid-template-columns: 1fr; } }
.setup-grid h3, #setup-opts h3 {
  font-weight: 400; letter-spacing: .3em; font-size: 12px; color: var(--orange);
  margin: 14px 0 6px;
}
.pick-list { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow-y: auto; }
.pick {
  text-align: left; font: inherit; cursor: pointer; padding: 9px 14px;
  background: rgba(255, 255, 255, .03); color: var(--text);
  border: 1px solid rgba(255, 255, 255, .12); border-left: 3px solid transparent;
}
.pick b { letter-spacing: .18em; display: block; }
.pick span { font-size: 12px; opacity: .6; }
.pick.on { border-color: var(--cyan); border-left-width: 3px; background: rgba(0, 229, 255, .09); }
.pick:hover { background: rgba(0, 229, 255, .07); }

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  font: inherit; font-size: 13px; letter-spacing: .12em; cursor: pointer;
  padding: 6px 14px; color: var(--text);
  background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .16);
}
.chip.on { border-color: var(--cyan); color: var(--cyan); background: rgba(0, 229, 255, .1); box-shadow: 0 0 12px var(--cyan-dim); }
.chip.locked { opacity: .35; cursor: not-allowed; }
.chip-row .hint { align-self: center; font-size: 11px; letter-spacing: .06em; opacity: .55; }

@keyframes blink { 50% { opacity: .45; } }

/* Play Nearby (offline P2P) */
.nearby-body {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  max-width: min(420px, 90vw); text-align: center;
  background: var(--panel); border: 1px solid rgba(0, 229, 255, .15);
  padding: 22px 26px;
}
#nb-canvas { background: #fff; border-radius: 4px; }
#nb-video {
  /* Rear ("environment") camera, aimed at the other device's screen — not
     mirrored, unlike a front-facing selfie view. */
  width: min(300px, 80vw); height: min(300px, 80vw); object-fit: cover;
  background: #000; border: 1px solid var(--cyan-dim);
}
.dim { opacity: .55; font-size: 13px; }
code { font-family: var(--mono); color: var(--cyan); }

/* settings / records */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tabs button {
  font: inherit; font-size: 12px; letter-spacing: .25em; cursor: pointer; padding: 8px 16px;
  background: none; color: var(--text); border: none; border-bottom: 2px solid transparent; opacity: .55;
}
.tabs button.on { opacity: 1; color: var(--cyan); border-bottom-color: var(--cyan); }
.tab-body {
  width: min(560px, 92vw); display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid rgba(0, 229, 255, .15); padding: 20px 24px;
}
.opt { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.opt span { letter-spacing: .2em; font-size: 12px; opacity: .8; }
.opt input[type="range"] { width: 46%; accent-color: var(--cyan); }
.opt input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--cyan); }
.opt select, .opt input[type="text"] {
  font: inherit; background: #0a1220; color: var(--text);
  border: 1px solid var(--cyan-dim); padding: 6px 10px;
}
.bind-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bind-row b { width: 34px; color: var(--orange); }
.bind {
  flex: 1; font: inherit; font-size: 13px; cursor: pointer; padding: 8px;
  background: rgba(255, 255, 255, .04); color: var(--text); border: 1px solid rgba(255, 255, 255, .18);
}
.bind:hover { border-color: var(--cyan); }

.tbl { border-collapse: collapse; width: 100%; }
.tbl th, .tbl td { padding: 7px 12px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, .09); }
.tbl th { font-size: 11px; letter-spacing: .25em; color: var(--orange); font-weight: 400; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; }

.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ach { border: 1px solid rgba(255, 255, 255, .12); padding: 12px 14px; opacity: .45; }
.ach.got { opacity: 1; border-color: rgba(255, 213, 28, .55); box-shadow: 0 0 16px rgba(255, 213, 28, .12); }
.ach b { display: block; letter-spacing: .12em; margin-bottom: 4px; }
.ach span { font-size: 12px; opacity: .7; }

.help-body { max-width: 620px; line-height: 1.7; background: var(--panel); padding: 22px 28px; border: 1px solid rgba(0, 229, 255, .15); }
.help-body ul { margin: 12px 0 0 20px; }
.help-body b { color: var(--cyan); }

/* bracket */
#bracket-body {
  background: var(--panel); border: 1px solid rgba(0, 229, 255, .15);
  padding: 20px 24px; max-width: min(900px, 94vw);
}
.bracket { display: flex; gap: 26px; flex-wrap: wrap; justify-content: center; }
.br-col { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.br-col h4 { font-weight: 400; font-size: 11px; letter-spacing: .3em; color: var(--orange); text-align: center; }
.br-slot {
  border: 1px solid; border-left-width: 4px; padding: 7px 16px; min-width: 150px;
  background: rgba(255, 255, 255, .04); letter-spacing: .1em; font-size: 14px;
}
.br-slot.me { background: rgba(0, 229, 255, .14); box-shadow: 0 0 14px var(--cyan-dim); }

/* ---------------- HUD ---------------- */
#hud { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
#hud > * { pointer-events: none; }
#hud-players { position: absolute; top: 14px; left: 16px; display: flex; flex-direction: column; gap: 5px; }
.pl {
  display: flex; align-items: center; gap: 8px; font-size: calc(13px * var(--ui-scale));
  letter-spacing: .12em; background: rgba(3, 8, 16, .55); padding: 4px 10px;
  border-left: 3px solid rgba(255, 255, 255, .2);
}
.pl i { width: 10px; height: 10px; border-radius: 2px; box-shadow: 0 0 8px currentColor; }
.pl em { font-style: normal; font-size: 12px; }
.pl.dead { opacity: .35; text-decoration: line-through; }

#hud-topright { position: absolute; top: 14px; right: 16px; text-align: right; }
#hud-mode { font-size: calc(12px * var(--ui-scale)); letter-spacing: .3em; color: var(--orange); }
#hud-timer { font-size: calc(26px * var(--ui-scale)); font-weight: 200; letter-spacing: .12em; color: #eafcff; text-shadow: 0 0 12px var(--cyan-dim); }
#hud-speed { font-size: calc(12px * var(--ui-scale)); letter-spacing: .22em; color: var(--cyan); opacity: .85; }
#hud-boost { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 4px; }
#hud-boost span { font-size: calc(10px * var(--ui-scale)); letter-spacing: .24em; color: var(--orange); opacity: .85; }
#hud-boost .bat {
  width: calc(90px * var(--ui-scale)); height: calc(9px * var(--ui-scale));
  border: 1px solid var(--cyan-dim); background: rgba(3, 8, 16, .6); padding: 1px;
}
#hud-boost .bat i {
  display: block; height: 100%; width: 100%;
  background: linear-gradient(90deg, #ff9a00, #ffe14d); transition: width .1s linear;
}
#hud-boost.boosting .bat i { background: linear-gradient(90deg, #2bff67, #bdf6ff); box-shadow: 0 0 8px #2bff67; }
#hud-boost.empty .bat { border-color: #ff3f6c; }
#hud-boost.empty .bat i { background: #ff3f6c; animation: blink 0.6s ease infinite; }
/* Your power-ups (see ui.js _updatePowerTray): one chip each in the
   power-up's own colour, a bar for time left, ×2 for a second charge. */
#hud-powers { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-top: 8px; }
.pw {
  min-width: calc(124px * var(--ui-scale)); padding: 3px 8px 4px;
  background: rgba(3, 8, 16, .62); border-right: 3px solid var(--pw);
  font-size: calc(11px * var(--ui-scale)); letter-spacing: .2em; color: var(--pw);
  text-shadow: 0 0 8px var(--pw); animation: pwIn .25s ease both;
}
.pw b { display: block; height: 3px; margin-top: 3px; background: rgba(255, 255, 255, .12); }
.pw b i { display: block; height: 100%; margin-left: auto; background: var(--pw); box-shadow: 0 0 6px var(--pw); }
.pw.ending { animation: blink .5s ease infinite; }
.pw.bad { background: rgba(60, 4, 24, .7); }
.pw.bad span::before { content: '⚠ '; }
@keyframes pwIn { from { opacity: 0; transform: translateX(14px); } }
#hud-fps { font-family: var(--mono); font-size: 12px; color: #7fe7a0; }

#minimap {
  /* Left of the throttle buttons, which are anchored further out at the same
     corner (see #touch-controls .tc-right) — kept in sync via --tc-btn so
     they never overlap at any breakpoint. */
  position: absolute; right: calc(var(--tc-btn) + 30px); bottom: 16px;
  background: rgba(3, 8, 16, .6); border: 1px solid var(--cyan-dim);
  width: calc(176px * var(--ui-scale)); height: calc(176px * var(--ui-scale));
}
@media (max-width: 640px) { #minimap { width: 120px; height: 120px; } }

#hud-spectate {
  position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%);
  letter-spacing: .3em; font-size: 13px; color: var(--orange);
  background: rgba(3, 8, 16, .6); padding: 8px 18px;
}
#hud-spectate i { opacity: .5; font-style: normal; letter-spacing: .1em; }

#hud-touch-pause {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  pointer-events: auto !important; cursor: pointer;
  border: 1px solid var(--cyan-dim); color: var(--cyan);
  padding: 6px 16px; letter-spacing: 4px; background: rgba(3, 8, 16, .5);
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}

/* on-screen steer/throttle buttons (touch/tablet play) */
#touch-controls { position: absolute; inset: 0; }
#touch-controls .tc-side {
  position: absolute; bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 16px; pointer-events: auto !important;
}
#touch-controls .tc-left { left: calc(22px + env(safe-area-inset-left, 0px)); }
#touch-controls .tc-right {
  /* Anchored to the same corner as the minimap, but further out — to its
     right — rather than sandwiched between it and the steer buttons. */
  right: calc(16px + env(safe-area-inset-right, 0px));
  flex-direction: column;
}
.tc-btn {
  width: var(--tc-btn); height: var(--tc-btn); border-radius: 50%;
  background: rgba(0, 229, 255, .08); border: 2px solid var(--cyan-dim); color: var(--cyan);
  font: inherit; font-size: 26px; display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent; touch-action: none; user-select: none;
  /* Without these, a held press is caught by iOS's own long-press gesture
     (text-selection / "Copy…" callout) instead of just registering as a held
     button — the callout doesn't cancel the game's own pointer handling, so
     the button reads as stuck/"selected" after ~a second of holding. */
  -webkit-touch-callout: none; -webkit-user-select: none;
  transition: background .1s, transform .1s, box-shadow .1s;
}
.tc-btn.active {
  background: rgba(0, 229, 255, .34); transform: scale(0.92); box-shadow: 0 0 22px var(--cyan-dim);
}
@media (max-width: 640px) { :root { --tc-btn: 58px; } .tc-btn { font-size: 20px; } }

/* iPhone landscape (the real play orientation on a phone — see the rotate
   prompt above): buttons and minimap at full/iPad size eat a big share of a
   ~390px-tall screen. Shrink both, matching the same landscape-short cutoff
   used for the menus. */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --tc-btn: 54px; }
  .tc-btn { font-size: 18px; }
  #touch-controls .tc-side { bottom: calc(10px + env(safe-area-inset-bottom, 0px)); gap: 10px; }
  #touch-controls .tc-left { left: calc(10px + env(safe-area-inset-left, 0px)); }
  #minimap { right: calc(var(--tc-btn) + 20px); bottom: 8px; width: 96px !important; height: 96px !important; }
}

/* countdown */
#countdown {
  position: absolute; inset: 0; z-index: 18; display: flex; align-items: center; justify-content: center;
  font-size: clamp(90px, 20vw, 200px); font-weight: 100; color: #fff; pointer-events: none;
  text-shadow: 0 0 40px var(--cyan), 0 0 120px var(--cyan-dim);
}
#countdown.pop { animation: pop .9s ease both; }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 20% { transform: scale(1); opacity: 1; } 100% { opacity: .9; } }

/* toasts */
#toasts {
  position: absolute; top: 12%; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 22; pointer-events: none;
}
.toast {
  background: rgba(3, 8, 16, .78); border: 1px solid var(--cyan-dim); color: var(--text);
  letter-spacing: .25em; font-size: calc(13px * var(--ui-scale)); padding: 9px 22px;
  animation: toastIn .25s ease both;
}
.toast.out { transition: opacity .5s, transform .5s; opacity: 0; transform: translateY(-8px); }
.toast.ach-toast { border-color: rgba(255, 213, 28, .7); color: #ffe98a; text-align: center; }
.toast.ach-toast span { font-size: 11px; letter-spacing: .1em; opacity: .8; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* overlays */
.overlay {
  position: absolute; inset: 0; z-index: 24; display: flex; align-items: center; justify-content: center;
  background: rgba(2, 5, 10, .68); backdrop-filter: blur(4px); animation: screenIn .3s ease both;
}
.panel {
  display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
  background: var(--panel); border: 1px solid rgba(0, 229, 255, .25);
  padding: 34px 44px; min-width: min(340px, 90vw);
  clip-path: polygon(22px 0, 100% 0, 100% calc(100% - 22px), calc(100% - 22px) 100%, 0 100%, 0 22px);
}
.panel.wide { min-width: min(560px, 94vw); }
.panel h2 { margin-bottom: 8px; }
#end-title .win { color: #7dffab; text-shadow: 0 0 30px rgba(60, 255, 140, .5); }
#end-title .lose { color: #ff5d6c; text-shadow: 0 0 30px rgba(255, 60, 90, .5); }
#end-title .dim { opacity: .6; font-size: .6em; letter-spacing: .3em; }
.teamscore { font-size: 30px; font-weight: 200; letter-spacing: .2em; padding: 10px 0; }
.teamscore .a { color: var(--cyan); }
.teamscore .b { color: var(--orange); }

/* replay bar */
#replay-bar {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; z-index: 22;
  background: rgba(3, 8, 16, .8); border: 1px solid var(--cyan-dim); padding: 8px 14px;
}
#replay-bar .rec { color: #ff5d6c; letter-spacing: .2em; font-size: 12px; animation: blink 1.4s infinite; }
#replay-bar .bar { width: min(300px, 40vw); height: 4px; background: rgba(255, 255, 255, .12); }
#replay-bar .bar i { display: block; height: 100%; width: 0; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
#replay-bar button {
  font: inherit; font-size: 12px; cursor: pointer; padding: 4px 10px;
  background: none; border: 1px solid rgba(255, 255, 255, .2); color: var(--text);
}
#replay-bar button.on { border-color: var(--cyan); color: var(--cyan); }

/* reduce motion where requested */
@media (prefers-reduced-motion: reduce) {
  .screen, .overlay, .toast, #countdown.pop, .pw { animation: none !important; }
}

/* ==========================================================================
   Phone landscape (iPhone landscape is ~350-430px tall — far shorter than
   the iPad/desktop sizes this UI was originally tuned for): a full-height
   title plus a boxed vertical menu overflows the viewport before the last
   button (or the footer) is even visible. Tighten everything that lives
   inside .screen so a full menu fits without needing to scroll. iPad
   landscape (768px+ tall) is comfortably above this cutoff and keeps the
   original spacious layout.
   ========================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
  .screen { gap: 6px; padding: 6px 16px; }
  .screen h2 { font-size: 14px; letter-spacing: .3em; margin-bottom: 2px; }

  .game-title { font-size: clamp(18px, 7vh, 32px); letter-spacing: .08em; }
  .game-title em { font-size: 8px; letter-spacing: .4em; margin-top: 2px; }

  .menu {
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px;
    padding: 10px 16px; min-width: min(560px, 92vw);
  }
  .menu button, .row-btns button, .panel button {
    padding: 7px 12px; letter-spacing: .14em; font-size: 12px;
  }
  /* Keep the build tag (useful for confirming an update landed) but drop the
     flavour text — that's the part actually costing vertical space. A tiny
     low-opacity label over the busy 3D grid floor is illegible on a real
     phone screen, so give it a small solid chip instead of just shrinking
     the old whisper-quiet footer text. */
  .menu-foot {
    font-size: 12px; letter-spacing: .2em; opacity: 1; color: var(--cyan);
    background: rgba(3, 8, 16, .75); border: 1px solid var(--cyan-dim);
    padding: 3px 12px; border-radius: 3px;
  }
  .menu-foot .foot-flavor { display: none; }

  .setup-grid, .nearby-body, .tab-body, .help-body, #bracket-body {
    padding: 8px 16px; gap: 6px;
  }
  .pick-list { max-height: 26vh; }
  .help-body { line-height: 1.35; font-size: 13px; }
}

/* ==========================================================================
   Portrait phones: this is a landscape-only racing game (see
   manifest.webmanifest) — a narrow tall viewport can't show the arena or HUD
   well no matter how the layout is tuned, so ask for a rotation instead of
   rendering a cramped game. iPads (768px+ wide even in portrait) are excluded
   and keep playing in portrait if they want to.
   ========================================================================== */
#rotate-prompt { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  #rotate-prompt {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 18px; position: fixed; inset: 0; z-index: 100;
    background: var(--bg); color: var(--text); text-align: center; padding: 24px;
  }
}
#rotate-prompt .icon { font-size: 56px; animation: rotateHint 1.8s ease-in-out infinite; }
#rotate-prompt p { letter-spacing: .3em; font-size: 12px; text-transform: uppercase; opacity: .7; }
@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}
