/* The one look of the UI: the game's ink, gold and cream over dark navy, every panel and
   button a sticker with an ink border and a hard shadow (the same outline the karts and props
   carry in 3D), one heavy display face for titles and numbers, every text 15 px or more. The
   colour values are the shared look palette (shared/palette.js); a test keeps them equal. */
:root {
  --ink: #14101f; --ink-soft: #2a2440; --navy: #1c1a33; --gold: #ffc21a; --gold-deep: #d08a00; --gold-pale: #ffe066; --cream: #fff4d6;
  --up: #3dff8a; --up-deep: #14a85a; --down: #ff4a3d; --down-deep: #b0241a; --blue: #3fa9ff; --violet: #8e5cff; --pink: #ff5fb8; --steel: #5c6478; --cyan: #29e0e6; --orange: #ff7a1a;
  --panel: rgba(28, 26, 51, 0.94); --glass: rgba(20, 16, 31, 0.8); --edge: var(--ink); --text: var(--cream);
  --display: "Segoe UI Black", "Arial Black", "Helvetica Neue", Arial, system-ui, sans-serif;
  --shadow-hard: 0 4px 0 var(--ink); --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.45);
  --green: var(--up); --red: var(--down); --purple: var(--violet);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--navy); color: var(--text); font-family: var(--display); font-weight: 800; overflow: hidden; }
/* The loading screen's backdrop stays under the title until the stage's first frame, which fades in over it. */
body { background: radial-gradient(circle at 50% 30%, #342e62, var(--navy) 70%); }
/* A finger on the page never scrolls, zooms, selects or opens a callout. */
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
#game { display: block; width: 100vw; height: 100vh; height: 100dvh; opacity: 0; transition: opacity 0.4s ease-out; }
body.staged #game { opacity: 1; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
/* One button style everywhere: a sticker slab with an ink border and a hard shadow it sinks into when pressed. */
button { font: inherit; font-size: 17px; font-weight: 900; cursor: pointer; color: var(--text); background: var(--ink-soft); border: 3px solid var(--ink); border-radius: 14px; padding: 10px 20px; letter-spacing: 0.3px; min-height: 46px; box-shadow: var(--shadow-hard); transition: transform 0.08s ease-out, box-shadow 0.08s ease-out, background 0.12s, border-color 0.12s; }
button:hover { background: #3a3458; }
button:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
button:disabled { cursor: default; }
button.primary { background: var(--gold); color: var(--ink); font-size: 24px; padding: 12px 44px; box-shadow: 0 5px 0 var(--ink), var(--shadow-soft); }
button.primary:hover { background: var(--gold-pale); }
button.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
button.big-btn { font-size: 30px; padding: 14px 64px; border-radius: 18px; }
button.small { padding: 6px 14px; font-size: 15px; min-height: 36px; box-shadow: 0 3px 0 var(--ink); }
button.small:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
[hidden] { display: none !important; }
/* Screens slide and fade in (under a quarter of a second); reduce motion skips the slide. */
.screen .panel, .card { --rest: translate(0, 0); animation: panel-in 0.22s ease-out both; }
@keyframes panel-in { from { opacity: 0; transform: var(--rest) translateY(16px) scale(0.97); } to { opacity: 1; transform: var(--rest); } }
body.reduce-motion .screen .panel, body.reduce-motion .card { animation: fade-in 0.15s ease-out both; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
/* The cheap presets: no blur behind the cards. */
body.lowfx .panel { backdrop-filter: none; -webkit-backdrop-filter: none; }
a { color: var(--gold); }

/* ---- screens ---- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10; padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0); }
.panel { background: var(--panel); border: 3px solid var(--ink); border-radius: 22px; padding: 20px 28px; width: 460px; max-width: 94vw; max-height: 94vh; max-height: 94dvh; overflow: auto; text-align: center; box-shadow: 0 0 0 2px rgba(255, 194, 26, 0.35), 0 10px 0 rgba(0, 0, 0, 0.35), var(--shadow-soft); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); touch-action: pan-y; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.logo { width: 320px; max-width: 80vw; height: auto; aspect-ratio: 470 / 170; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.5)); }
.logo.big { width: 440px; }
.tagline { margin: 0; font-size: 15px; font-weight: 900; color: var(--gold-pale); text-shadow: 0 2px 0 var(--ink); text-wrap: balance; line-height: 1.2; }
/* The title: a narrow panel kept to the left of every frame, so the hero kart behind it (the
   player's own, in the title's close shot) has the right part of the frame to itself. */
.title-panel { width: 400px; gap: 10px; padding: 18px 24px; }
#title { justify-content: flex-start; padding-left: max(4vw, env(safe-area-inset-left, 0)); }
@media (max-width: 860px) { .title-panel { width: 360px; padding: 12px 18px; gap: 8px; } }
/* One main group, evenly spaced: Play big, solo play under it (a match against the bots is
   always one press away, server or no server), the mode pick under that. */
.main-group { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.main-group button.solo { font-size: 16px; min-height: 34px; padding: 5px 18px; }
.main-group .modes { box-shadow: 0 3px 0 var(--ink); border-radius: 12px; }
.main-group .modes button.mode { min-width: 96px; min-height: 32px; padding: 4px 14px; font-size: 15px; }
/* The quiet row: icon-and-label buttons for the garage, the settings and the other ways in
   (More opens a private room and a room code). */
.quiet-row { display: flex; justify-content: center; gap: 8px; width: 100%; }
button.quiet { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 86px; min-height: 0; padding: 6px 10px 4px; font-size: 15px; background: rgba(0, 0, 0, 0.25); box-shadow: 0 3px 0 var(--ink); border-radius: 12px; }
button.quiet:hover { background: #3a3458; }
button.quiet:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button.quiet .quiet-icon { width: 24px; height: 24px; display: block; }
button.more[aria-expanded="true"] { background: var(--gold); color: var(--ink); }
/* Play is the one big thing on the title: the biggest button, breathing a few times as the screen opens. */
button.play-btn { position: relative; font-size: 34px; padding: 14px 84px; min-width: 300px; border-radius: 20px; }
button.play-btn .ring { border-radius: 26px; outline-color: var(--gold-pale); opacity: 0.6; animation: again-ring 1.4s ease-in-out 6 alternate; }
body.reduce-motion button.play-btn .ring { animation: none; opacity: 0.5; }
/* The player strip, set apart and smaller: the name with its new-name die, the level bar,
   the next unlock with its kind's icon. */
.player-strip { display: flex; flex-direction: column; align-items: stretch; gap: 4px; width: 100%; padding: 8px 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.22); }
.who-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.who-row .name { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.icon-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 0; width: 30px; height: 30px; padding: 0; border-radius: 9px; box-shadow: 0 2px 0 var(--ink); flex: none; }
button.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
button.icon-btn .quiet-icon { width: 20px; height: 20px; display: block; }
.title-panel .level-row { font-size: 15px; gap: 8px; }
.title-panel .level-bar { height: 10px; }
.next-row { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px; color: var(--cream); }
.next-row .next-icon { width: 20px; height: 20px; display: block; }
.next-row .level-next { min-width: 0; text-align: center; }
.title-panel .fine { font-size: 15px; opacity: 0.75; margin: -4px 0 0; }
/* On the wide frames the strip is two lines where the name and the next unlock fit side by
   side (the level bar under them), three where a long name needs the line to itself. */
@media (min-width: 861px) {
  .title-panel .player-strip { flex-direction: row; flex-wrap: wrap; justify-content: space-between; align-items: center; column-gap: 10px; row-gap: 3px; }
  .title-panel .who-row { flex: 0 0 auto; justify-content: flex-start; }
  .title-panel .next-row { flex: 0 0 auto; justify-content: flex-end; }
  .title-panel .level-row { flex: 1 0 100%; order: 3; }
}
/* The backdrop dims a little behind the panel, so the round behind reads as the backdrop it is. */
/* A soft vignette besides: the frame's edges and far corners darken, the hero's spot (right of centre) stays bright, so the round behind reads as depth, not as a second subject. */
#title::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 8, 20, 0.85) 0, rgba(10, 8, 20, 0.35) 9%, rgba(10, 8, 20, 0) 18%), linear-gradient(90deg, rgba(10, 8, 20, 0.5) 0, rgba(10, 8, 20, 0.32) 400px, rgba(10, 8, 20, 0) 620px), radial-gradient(ellipse 64% 78% at 70% 58%, rgba(10, 8, 20, 0) 38%, rgba(10, 8, 20, 0.5) 100%); pointer-events: none; }
@media (max-width: 860px) { #title::before { background: linear-gradient(180deg, rgba(10, 8, 20, 0.7) 0, rgba(10, 8, 20, 0) 16%), linear-gradient(90deg, rgba(10, 8, 20, 0.5) 0, rgba(10, 8, 20, 0.3) 340px, rgba(10, 8, 20, 0) 520px), radial-gradient(ellipse 70% 82% at 72% 56%, rgba(10, 8, 20, 0) 38%, rgba(10, 8, 20, 0.45) 100%); } }
#title .panel { position: relative; }
.more-rows { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.more-rows[hidden] { display: none; }
.name { font-size: 24px; font-weight: 900; color: var(--gold); text-shadow: 0 2px 0 var(--ink); }
.level-row, .xp-row { display: flex; align-items: center; gap: 10px; width: 100%; font-size: 16px; }
.level-label { font-weight: 900; color: var(--gold); white-space: nowrap; min-width: 66px; text-align: left; }
.level-bar { flex: 1; height: 16px; border-radius: 8px; background: rgba(0, 0, 0, 0.35); border: 2px solid var(--ink); overflow: hidden; }
.level-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-deep), var(--gold)); border-radius: 6px; transition: width 0.6s ease-out; }
.level-next, .xp-gain { opacity: 1; white-space: nowrap; min-width: 70px; text-align: right; }
.xp-gain { color: var(--up); font-weight: 900; }
.toggle { font-size: 16px; opacity: 0.95; display: flex; align-items: center; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; width: 100%; font-size: 16px; }
.row > span:first-child { min-width: 84px; text-align: left; }
.row input[type="range"] { flex: 1; accent-color: var(--gold); }
.row .value { min-width: 48px; text-align: right; opacity: 0.85; }
.row select { font: inherit; font-size: 15px; padding: 6px 10px; border-radius: 10px; background: rgba(0, 0, 0, 0.35); color: var(--text); border: 2px solid var(--ink); }
.controls { margin: 0; font-size: 15px; opacity: 0.8; font-weight: 700; }
.fine { margin: 0; font-size: 16px; opacity: 0.95; font-weight: 800; }
h2 { margin: 0; font-size: 32px; font-weight: 900; color: var(--gold); text-shadow: 0 3px 0 var(--ink); letter-spacing: 0.5px; }
/* Toggles are switches: a pill that slides gold when on. */
.toggle { justify-content: space-between; width: 100%; cursor: pointer; }
.toggle input[type="checkbox"] { appearance: none; -webkit-appearance: none; margin: 0; width: 50px; height: 28px; border-radius: 14px; background: rgba(0, 0, 0, 0.35); border: 2px solid var(--ink); position: relative; cursor: pointer; transition: background 0.15s, border-color 0.15s; flex: none; }
.toggle input[type="checkbox"]::before { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--cream); box-shadow: 0 2px 0 var(--ink); transition: transform 0.15s ease-out, background 0.15s; }
.toggle input[type="checkbox"]:checked { background: var(--gold); }
.toggle input[type="checkbox"]:checked::before { transform: translateX(22px); background: var(--ink); }
.toggle input[type="checkbox"]:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.setting-note { margin: 0; font-size: 15px; opacity: 0.75; text-align: left; width: 100%; margin-top: -8px; font-weight: 700; }
.buttons { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.stats { margin: 0; font-size: 16px; font-weight: 700; }

/* ---- loading ---- */
.loading { background: radial-gradient(circle at 50% 30%, #342e62, var(--navy) 70%); z-index: 20; }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 480px; max-width: 92vw; }
.tip { margin: 0; font-size: 17px; opacity: 0.9; text-align: center; min-height: 22px; font-weight: 700; }
.token-box { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.token-art { width: 96px; height: 96px; border-radius: 50%; border: 3px solid var(--ink); box-shadow: 0 0 0 3px var(--gold); }
.ca-row { display: flex; align-items: center; gap: 8px; max-width: 92vw; }
.ca { font-size: 15px; font-weight: 700; background: rgba(0, 0, 0, 0.4); padding: 6px 10px; border-radius: 8px; border: 2px solid var(--ink); word-break: break-all; }
.load-bar { width: 260px; height: 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.35); border: 2px solid var(--ink); overflow: hidden; }
.load-fill { height: 100%; width: 0; background: var(--gold); transition: width 0.3s; }

/* ---- garage ---- */
.garage { justify-content: flex-start; padding-left: calc(24px + env(safe-area-inset-left, 0)); }
.garage-panel { width: 440px; max-height: 92vh; max-height: 92dvh; overflow: hidden; }
/* The options list is the part that scrolls on a short screen; the tabs, the note and Done stay put. */
.garage-panel .options { flex: 1 1 auto; min-height: 0; overflow-y: auto; touch-action: pan-y; padding: 6px; }
.garage-panel .tabs, .garage-panel h2, .garage-panel .fine, .garage-panel button.primary { flex: none; }
.garage-panel .fine { font-size: 17px; opacity: 0.95; }
/* The seven garage tabs: two rows of icons with the kind's name under each, never cramped. */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 100%; padding: 6px; }
.tabs button { position: relative; min-width: 0; padding: 6px 4px 5px; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tabs button canvas { width: 26px; height: 26px; display: block; }
.tabs button .tab-name { font-size: 15px; line-height: 1; }
/* Four cards a row: the longest list (eight looks) is two whole rows, so no frame the game
   ships into cuts a row of cards in half at the grid's edge. */
.options { display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 1fr; gap: 8px; width: 100%; }
.option { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 6px 4px; font-size: 15px; min-width: 0; min-height: 56px; line-height: 1.15; }
.option .swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--ink); }
/* One selection style for tabs and options: a gold border with a check mark badge on the corner. */
.tabs button.on, .option.picked { border-color: var(--gold); box-shadow: 0 4px 0 var(--ink), 0 0 0 3px rgba(255, 194, 26, 0.45); }
/* The check badge sits mostly outside its card's corner; on an option card it takes the
   bottom corner, where a two-line name's shorter second line leaves room, so a long name's
   last letters are never under it. */
.tabs button.on::after, .option.picked::after { content: "\2713"; position: absolute; top: -13px; right: -13px; width: 22px; height: 22px; border-radius: 50%; background: var(--gold); color: var(--ink); border: 2px solid var(--ink); font-size: 15px; font-weight: 900; line-height: 18px; text-align: center; }
.option.picked::after { top: auto; bottom: -11px; right: -11px; }
.option.locked { background: rgba(10, 8, 20, 0.55); color: rgba(255, 244, 214, 0.75); cursor: default; }
.option.locked .swatch { opacity: 0.55; }
.option .lock { display: flex; align-items: center; gap: 4px; font-size: 15px; color: var(--cream); font-weight: 800; white-space: nowrap; }
.option .lock-icon { width: 16px; height: 16px; display: block; }

/* ---- end screen ---- */
.end { align-items: flex-end; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0)); }
.end-panel { width: 580px; max-height: 78vh; max-height: 78dvh; padding: 14px 24px; gap: 8px; }
/* The next-round countdown and the private room's invite share one row when both show. */
.round-row { display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; width: 100%; }
.round-row:empty { display: none; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; height: 122px; width: 100%; }
.podium .step { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 30%; }
.podium .who { font-weight: 900; font-size: 15px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.podium .block { width: 100%; border-radius: 10px 10px 0 0; background: var(--steel); display: flex; align-items: flex-start; justify-content: center; font-weight: 900; font-size: 22px; padding-top: 4px; color: var(--ink); border: 3px solid var(--ink); border-bottom: 0; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.2); }
.podium .p1 .block { height: 70px; background: var(--gold); }
.podium .p2 .block { height: 50px; background: #cfd3dc; }
.podium .p3 .block { height: 36px; background: #d08a4a; }
.podium .score { font-size: 15px; opacity: 0.85; font-weight: 700; }
.podium .step.me .who { color: var(--gold); }
.podium .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--ink); margin-bottom: 2px; }
.unlocks { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
/* The unlock cards and the new-best card share one row (an empty list takes no room). */
.rewards { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; width: 100%; }
.rewards > :empty { display: none; }
.unlock-card { background: linear-gradient(180deg, var(--violet), #4a1a8a); border: 3px solid var(--ink); border-radius: 12px; padding: 6px 12px; font-size: 15px; animation: pop 0.5s ease-out; box-shadow: 0 3px 0 var(--ink); }
.unlock-card .title { display: block; font-weight: 900; color: var(--gold); font-size: 15px; letter-spacing: 1px; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* The next unlock under the XP bar, the "New best!" card, and Play again as the biggest thing on the screen. */
.xp-next { margin: -4px 0 0; font-size: 15px; opacity: 0.9; font-weight: 700; }
.best-card { background: linear-gradient(180deg, var(--gold), var(--gold-deep)); border: 3px solid var(--ink); color: var(--ink); border-radius: 12px; padding: 6px 14px; font-size: 15px; font-weight: 900; animation: pop 0.5s ease-out; text-shadow: none; box-shadow: 0 3px 0 var(--ink); }
.best-card .title { display: block; font-weight: 900; font-size: 15px; letter-spacing: 1px; color: #5a1fa8; }
.end-buttons { align-items: center; gap: 18px; }
body.touch #end button { min-height: 44px; }
/* Play again breathes a few times as the screen opens, then its ring holds. */
.end-buttons #again { min-width: 260px; position: relative; }
.end-buttons #again .ring { border-radius: 24px; outline-color: var(--gold-pale); opacity: 0.6; animation: again-ring 1.4s ease-in-out 6 alternate; }
@keyframes again-ring { from { opacity: 0.1; } to { opacity: 0.9; } }
body.reduce-motion .end-buttons #again .ring { animation: none; opacity: 0.5; }
body.reduce-motion .best-card { animation: none; }
.lobby-btn { opacity: 0.9; }

/* ---- HUD ---- */
/* Every HUD panel shares one look: dark glass, an ink border, a hard shadow, the same radius. */
#hud { --hud-panel: var(--glass); --hud-edge: var(--ink); --hud-radius: 14px; --hud-shadow: 0 3px 0 var(--ink); position: fixed; inset: 0; pointer-events: none; z-index: 5; contain: layout; padding: calc(10px + env(safe-area-inset-top, 0)) calc(12px + env(safe-area-inset-right, 0)) calc(10px + env(safe-area-inset-bottom, 0)) calc(12px + env(safe-area-inset-left, 0)); font-weight: 800; color: var(--cream); text-shadow: 0 2px 0 var(--ink); }
#top-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px; }
#top-left { justify-self: start; }
#clock { display: flex; flex-direction: column; align-items: center; gap: 4px; }
#top-left { display: flex; align-items: stretch; gap: 8px; }
/* The bag's one-line lesson under the counters, the first time the bag fills in a first match. */
#bag-hint { position: absolute; left: calc(12px + env(safe-area-inset-left, 0)); top: calc(70px + env(safe-area-inset-top, 0)); display: none; align-items: center; gap: 6px; font-size: 15px; font-weight: 900; color: var(--cream); background: var(--hud-panel); border: 2px solid var(--gold); box-shadow: var(--hud-shadow); border-radius: 10px; padding: 4px 12px 4px 8px; white-space: nowrap; pointer-events: none; }
#bag-hint.show { display: flex; transform-origin: left center; animation: hint-in 0.35s ease-out; }
/* The hint grows in where it stands (the card's keyframes carry the centring shift the hint has no use for). */
@keyframes hint-in { 0% { transform: scale(0.6); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
#bag-hint canvas { width: 22px; height: 22px; display: block; flex: none; }
body.reduce-motion #bag-hint.show { animation: none; }
#score-box, #bag-box { display: flex; align-items: center; gap: 6px; font-size: 32px; font-weight: 900; color: var(--gold); background: var(--hud-panel); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 0 12px 0 6px; border-radius: var(--hud-radius); justify-self: start; }
#score-box .label, #bag-box .label { font-size: 15px; color: var(--cream); font-weight: 900; align-self: flex-end; padding-bottom: 8px; }
#bag-box { color: var(--gold-pale); }
#bank-icon, #bag-icon { width: 34px; height: 34px; }
#bag-box.grew #bag { animation: bag-pop 0.35s ease-out; }
#bag-box.rich { border-color: var(--gold); box-shadow: var(--hud-shadow), 0 0 14px rgba(255, 194, 26, 0.45); }
@keyframes bag-pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
/* The bag at risk (a threat arrow up with coins in it) pulses red; the banked box pops a little with each tick of its tally. */
#bag-box.risk { border-color: var(--down); animation: risk-pulse 0.5s infinite alternate; }
@keyframes risk-pulse { from { box-shadow: var(--hud-shadow); } to { box-shadow: var(--hud-shadow), 0 0 16px rgba(255, 74, 61, 0.85); } }
#score-box.tally #banked { animation: bag-pop 0.2s ease-out; }
body.reduce-motion #bag-box.risk { animation: none; box-shadow: var(--hud-shadow), 0 0 12px rgba(255, 74, 61, 0.7); }
#timer.bull { color: var(--gold-pale); border-color: var(--gold); animation: bull-pulse 0.6s infinite alternate; }
@keyframes bull-pulse { from { box-shadow: var(--hud-shadow); } to { box-shadow: var(--hud-shadow), 0 0 18px rgba(255, 224, 102, 0.8); } }
#bank-ring { position: absolute; left: 50%; top: 58%; transform: translate(-50%, -50%); display: none; flex-direction: column; align-items: center; gap: 2px; }
#bank-ring.show { display: flex; }
#bank-ring-canvas { width: 96px; height: 96px; }
#bank-text { font-size: 16px; font-weight: 900; letter-spacing: 2px; color: var(--cream); }
#bank-ring.bull #bank-text { color: var(--gold-pale); }
#pending { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); padding: 8px 18px; border-radius: 12px; background: var(--glass); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); color: var(--cream); font-size: 18px; font-weight: 900; opacity: 0; white-space: nowrap; }
#pending.show { opacity: 1; }
#pending.show::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 10px; border: 3px solid var(--cream); border-right-color: transparent; border-radius: 50%; vertical-align: middle; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#timer { font-size: 34px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: 1px; background: var(--hud-panel); padding: 2px 18px; border-radius: var(--hud-radius); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); }
#timer.late { color: var(--down); border-color: var(--down); }
/* The race: the position box, the lap under the clock, the wrong-way banner and the minimap. */
#race-box { display: flex; align-items: baseline; gap: 8px; background: var(--hud-panel); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 0 14px; border-radius: var(--hud-radius); }
#race-place { font-size: 36px; color: var(--cream); font-weight: 900; }
#race-box.gained { animation: race-gain 0.6s ease-out; }
#race-box.final-lap #race-lap { color: #45efc4; }
@keyframes race-gain { 25% { transform: scale(1.09); border-color: #45efc4; } }
@media (prefers-reduced-motion: reduce) { #race-box.gained { animation: none; } }
#race-of { font-size: 16px; opacity: 0.9; }
#race-lap { font-size: 16px; font-weight: 900; margin-left: 6px; padding-left: 10px; border-left: 2px solid rgba(255, 244, 214, 0.35); }
#lap-best { font-size: 15px; font-weight: 900; background: var(--hud-panel); border: 2px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 2px 12px; border-radius: 10px; font-variant-numeric: tabular-nums; }
#wrong-way { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); padding: 8px 22px; border-radius: 12px; background: var(--down); color: var(--cream); font-size: 26px; font-weight: 900; letter-spacing: 2px; opacity: 0; border: 3px solid var(--ink); box-shadow: var(--hud-shadow); }
#wrong-way.show { opacity: 1; animation: pulse 0.5s infinite alternate; }
#minimap { position: absolute; right: calc(12px + env(safe-area-inset-right, 0)); top: calc(104px + env(safe-area-inset-top, 0)); width: 150px; height: 150px; background: var(--glass); border: 3px solid var(--hud-edge); border-radius: var(--hud-radius); box-shadow: var(--hud-shadow); }
body.touch #minimap { right: auto; left: calc(12px + env(safe-area-inset-left, 0)); top: calc(72px + env(safe-area-inset-top, 0)); width: 110px; height: 110px; }
#board { justify-self: end; min-width: 190px; background: var(--hud-panel); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); border-radius: var(--hud-radius); padding: 2px 0 4px; }
#board-cap { font-size: 15px; font-weight: 900; letter-spacing: 1px; color: var(--cream); opacity: 0.85; padding: 2px 10px 0; text-align: right; line-height: 1.1; }
#top3 { list-style: none; margin: 0; padding: 0; font-size: 15px; }
#top3 li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 10px; border-radius: 6px; font-weight: 900; }
#top3 li.me { background: rgba(255, 244, 214, 0.22); }
#top3 li .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 168px; }
#banner { position: absolute; left: 0; right: 0; top: 24%; text-align: center; font-size: 50px; font-weight: 900; color: var(--cream); opacity: 0; letter-spacing: 3px; text-shadow: 0 4px 0 var(--ink), 0 8px 24px rgba(0, 0, 0, 0.7); pointer-events: none; }
/* An arena event's banner: the hazard orange, slid in from above and shrunk away toward the
   timer, where its chip takes over. */
#banner.event { color: var(--orange); }
#banner.event.show { animation: banner-event 1.2s ease-in-out forwards; }
@keyframes banner-event { 0% { opacity: 0; transform: translateY(-36px) scale(0.9); } 12% { opacity: 1; transform: translateY(0) scale(1.05); } 22% { transform: translateY(0) scale(1); } 76% { opacity: 1; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-70px) scale(0.3); } }
body.reduce-motion #banner.event.show { animation: banner-fade 1.2s ease-out forwards; }
/* The event chip under the timer: a small plate in the hazard colours that stays while the event runs. */
.chip { font-size: 16px; font-weight: 900; letter-spacing: 1px; padding: 3px 14px; border-radius: 10px; background: var(--hud-panel); border: 2px solid var(--orange); color: var(--orange); box-shadow: var(--hud-shadow); white-space: nowrap; animation: chip-in 0.25s ease-out; }
/* The one event notice: outlined and pulsing through the warning's countdown, filled and popped in while the event runs (the hazard orange both ways). */
.chip.warn { border-color: var(--orange); color: var(--orange); animation: chip-in 0.25s ease-out, pulse 0.5s 0.25s infinite alternate; }
.chip.on { background: var(--orange); color: var(--ink); border-color: var(--ink); animation: chip-pop 0.4s ease-out; }
@keyframes chip-in { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
@keyframes chip-pop { 0% { transform: scale(0.7); } 55% { transform: scale(1.25); } 100% { transform: scale(1); } }
body.reduce-motion .chip, body.reduce-motion .chip.warn, body.reduce-motion .chip.on { animation: none; }
/* The small feedback pops: a short stack in the upper middle, above the kart, each line in
   and out in under a second so the play space stays clear. */
#pops { position: absolute; left: 0; right: 0; top: 13%; display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; }
#pops .pop { font-size: 24px; font-weight: 900; letter-spacing: 1.5px; color: var(--cream); text-shadow: 0 3px 0 var(--ink), 0 6px 16px rgba(0, 0, 0, 0.6); animation: pop-line 0.9s ease-out forwards; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
/* The coin pops say whose coins moved: red for a spill taken, green for coins taken, each with the coin. */
#pops .pop.spill { color: var(--down); }
#pops .pop.gain { color: var(--up); }
#pops .pop .pop-icon { width: 26px; height: 26px; display: block; order: -1; }
@keyframes pop-line { 0% { opacity: 0; transform: translateY(8px) scale(0.7); } 15% { opacity: 1; transform: translateY(0) scale(1.1); } 30% { transform: scale(1); } 70% { opacity: 1; } 100% { opacity: 0; transform: translateY(-10px); } }
body.reduce-motion #pops .pop { animation: banner-fade 0.9s ease-out forwards; }
/* A banner pops in large, settles, holds and fades: each new text restarts it. */
#banner.show { animation: banner-pop 1s ease-out forwards; }
#banner.bank { color: var(--up); text-shadow: 0 4px 0 var(--ink), 0 8px 28px rgba(61, 255, 138, 0.55); }
/* The bank ring keeps the Exchange's gold through the Bull Run; the plate's alarm is the hazard orange. */
#banner.bank.show { animation: banner-bank 1.3s ease-out forwards; }
@keyframes banner-bank { 0% { opacity: 0; transform: scale(0.2); } 14% { opacity: 1; transform: scale(1.32); } 28% { transform: scale(0.96); } 40% { transform: scale(1.04); } 75% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.1); } }
@keyframes banner-pop { 0% { opacity: 0; transform: scale(0.3); } 18% { opacity: 1; transform: scale(1.18); } 32% { transform: scale(1); } 72% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.08); } }
#warn { position: absolute; left: 50%; top: 16%; transform: translateX(-50%); padding: 6px 18px; border-radius: 10px; background: var(--down); color: var(--cream); font-size: 20px; font-weight: 900; letter-spacing: 1px; opacity: 0; border: 3px solid var(--ink); box-shadow: var(--hud-shadow); }
#warn.show { opacity: 1; animation: pulse 0.5s infinite alternate; }
/* An arena event's warning takes the same plate in amber. */
@keyframes pulse { from { transform: translateX(-50%) scale(1); } to { transform: translateX(-50%) scale(1.08); } }
#feed { position: absolute; right: calc(12px + env(safe-area-inset-right, 0)); top: calc(110px + env(safe-area-inset-top, 0)); max-width: calc(50% - 150px); list-style: none; margin: 0; padding: 0; font-size: 15px; text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
#feed li { background: var(--hud-panel); border: 2px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 3px 10px; border-radius: 10px; font-weight: 900; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: feed-line 4s ease-in forwards; }
/* A line slides in and fades out over its last second (the HUD drops it at four seconds). */
@keyframes feed-line { 0% { opacity: 0; transform: translateX(12px); } 6% { opacity: 1; transform: translateX(0); } 75% { opacity: 1; } 100% { opacity: 0; } }
body.reduce-motion #feed li { animation: feed-fade 4s ease-in forwards; }
@keyframes feed-fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
/* Under touch the feed keeps clear of the buttons on the right and shows fewer, shorter lines. */
body.touch #feed { right: calc(150px + env(safe-area-inset-right, 0)); max-width: 42vw; }
body.touch #feed li:nth-child(n+4) { display: none; }
#feed .who { color: var(--cream); }
#feed .victim { color: #ff8a7a; }
#feed .coins { color: var(--gold-pale); }
#feed .feed-icon { width: 22px; height: 22px; margin-right: 6px; vertical-align: -6px; }
#feed li { min-width: 0; }
/* A narrow frame: the feed's lines wrap inside the right third, and the big banner sits a
   little lower and smaller, under the feed's lines and clear of its column. */
@media (max-width: 1100px) {
  #feed { max-width: calc(50% - 110px); }
  #feed li { white-space: normal; }
  #banner { top: 40%; font-size: 40px; letter-spacing: 2px; }
  #pending { top: 52%; }
  /* A wrapped feed line, a pop or the pending line can share the banner's row here: the small
     notices step back while a big word is up and come back with it. */
  #hud.big-up #feed, #hud.big-up #pops, #hud.big-up #pending, #hud.big-up #exchange, #hud.big-up #weapon-marker { opacity: 0.2; }
}
#feed, #pops, #exchange, #weapon-marker { transition: opacity 0.2s ease-out; }
body.touch #hud.big-up #feed, body.touch #hud.big-up #pops, body.touch #hud.big-up #pending, body.touch #hud.big-up #exchange, body.touch #hud.big-up #weapon-marker { opacity: 0.2; }
#bottom-left { position: absolute; left: calc(12px + env(safe-area-inset-left, 0)); bottom: calc(12px + env(safe-area-inset-bottom, 0)); display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
#weapon { display: flex; align-items: center; gap: 10px; background: var(--hud-panel); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); border-radius: var(--hud-radius); padding: 6px 14px 6px 6px; min-width: 200px; }
#weapon.armed { border-color: var(--cream); box-shadow: var(--hud-shadow), 0 0 14px rgba(255, 244, 214, 0.35); }
#weapon.teach #weapon-uses { color: var(--cream); opacity: 1; animation: teach-pulse 0.9s infinite alternate; }
@keyframes teach-pulse { from { opacity: 0.6; } to { opacity: 1; } }
body.reduce-motion #weapon.teach #weapon-uses { animation: none; }
#weapon-icon { width: 56px; height: 56px; border-radius: 12px; background: rgba(255, 255, 255, 0.1); }
#weapon-text { display: flex; flex-direction: column; }
#weapon-name { font-size: 16px; font-weight: 900; }
#weapon-uses { font-size: 15px; color: var(--cream); opacity: 0.85; font-weight: 900; }
/* The Exchange marker: a badge with the bank icon over the pad while it is on screen (with the
   distance under it), slid to the frame's edge as an arrow pointing the way when it is not;
   placed by the HUD each frame through its transform, centred on its point. */
#exchange { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none; will-change: transform; }
#exchange-icon { width: 44px; height: 44px; border-radius: 50%; background: var(--hud-panel); border: 3px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 4px; }
#exchange.edge #exchange-icon { display: none; }
#exchange:not(.edge) #exchange-arrow { display: none; }
#exchange-text { background: var(--hud-panel); border: 2px solid var(--hud-edge); box-shadow: var(--hud-shadow); border-radius: 10px; padding: 2px 10px; }
#exchange.near { display: none; }
/* The hint shows only with coins to bank and a way to go (the HUD sets the class). */
#exchange.off { display: none; }
/* The weapon pointer's marker: a small box badge over the nearest armed pedestal with the
   distance under it, or the arrow at the frame's edge toward it; smaller than the Exchange's. */
#weapon-marker { position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; pointer-events: none; will-change: transform; }
#weapon-marker-icon { width: 34px; height: 34px; border-radius: 50%; background: var(--hud-panel); border: 2px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 3px; }
#weapon-marker.edge #weapon-marker-icon { display: none; }
#weapon-marker:not(.edge) #weapon-marker-arrow { display: none; }
#weapon-marker-arrow { width: 30px; height: 30px; filter: drop-shadow(0 2px 0 var(--ink)); }
#weapon-marker .marker-dist { font-size: 15px; font-weight: 900; color: var(--cream); background: var(--hud-panel); border: 2px solid var(--hud-edge); box-shadow: var(--hud-shadow); border-radius: 9px; padding: 0 8px; line-height: 1.2; font-variant-numeric: tabular-nums; }
#weapon-marker.off { display: none; }
#exchange-arrow { width: 36px; height: 36px; filter: drop-shadow(0 2px 0 var(--ink)); }
#exchange-text { display: flex; flex-direction: row; align-items: baseline; gap: 6px; line-height: 1.1; white-space: nowrap; }
#exchange-label { font-size: 15px; font-weight: 900; letter-spacing: 0.5px; }
#exchange-dist { font-size: 15px; color: var(--cream); opacity: 0.85; font-weight: 900; font-variant-numeric: tabular-nums; }
#hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom, 0)); font-size: 15px; font-weight: 800; background: var(--hud-panel); border: 2px solid var(--hud-edge); box-shadow: var(--hud-shadow); padding: 4px 14px; border-radius: 10px; white-space: nowrap; }
/* Once the strip has done its job it collapses to a question mark (the menu's Settings keep the keys). */
#hint.short { font-size: 18px; padding: 0; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--cream); opacity: 0.85; }
/* The mark takes a click or a hover to bring the line back (the HUD itself takes none). */
#hint { pointer-events: auto; cursor: default; }
/* The coach's one-line prompt: a gold sticker above the hint, in and out on a fade. */
#coach { position: absolute; left: 50%; bottom: calc(58px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%) translateY(6px); font-size: 20px; font-weight: 900; letter-spacing: 0.5px; color: var(--cream); background: rgba(20, 16, 31, 0.92); border: 3px solid var(--cream); box-shadow: 0 4px 0 var(--ink), 0 8px 20px rgba(0, 0, 0, 0.5); padding: 7px 20px; border-radius: 14px; white-space: nowrap; text-shadow: 0 2px 0 var(--ink); opacity: 0; pointer-events: none; transition: opacity 0.25s ease-out, transform 0.25s ease-out; }
#coach.show { opacity: 1; transform: translateX(-50%) translateY(0); animation: coach-in 0.35s ease-out; }
/* The guided round's prompt: an icon before the words and a Skip after them (the one HUD
   control that takes a click); the icon and the button hide outside the guide. */
#coach { display: flex; align-items: center; gap: 10px; }
#coach .coach-icon { width: 32px; height: 32px; display: block; flex: none; }
#coach .coach-skip { pointer-events: auto; margin-left: 6px; font-size: 15px; min-height: 28px; padding: 2px 10px; background: var(--cream); color: var(--ink); text-shadow: none; }
#coach.show .coach-skip:not([hidden]) { display: inline-block; }
@keyframes coach-in { 0% { transform: translateX(-50%) scale(0.6); } 60% { transform: translateX(-50%) scale(1.08); } 100% { transform: translateX(-50%) scale(1); } }
/* Guided instructions keep their reserved place beneath the timer. The ordinary weapon
   hint belongs beside its slot, outside the road's vanishing point. */
body.touch #coach { top: calc(78px + env(safe-area-inset-top, 0)); bottom: auto; font-size: 18px; }
body.touch #coach.route-hint { top: auto; bottom: calc(66px + env(safe-area-inset-bottom, 0)); font-size: 15px; padding: 4px 10px; gap: 6px; border-width: 2px; max-width: 45vw; white-space: normal; text-align: center; }
body.touch #coach.route-hint .coach-icon { width: 22px; height: 22px; }
/* The Airdrop warning stacks under the prompt, and the banner and the wrong-way sign sit lower
   than on a desktop, so none of the four ever meet. */
body.touch #warn { top: calc(142px + env(safe-area-inset-top, 0)); }
body.touch #wrong-way { top: calc(172px + env(safe-area-inset-top, 0)); }
body.touch #banner { top: 46%; }
/* On a phone the pops sit just above the kart, under the prompt and the warning. */
body.touch #pops { top: 38%; }
body.touch #feed { top: calc(124px + env(safe-area-inset-top, 0)); }
body.reduce-motion #coach.show { animation: none; }
/* The FIRE button pulses while the coach asks for the first shot: a ring (its own element,
   transform and opacity only) that rings out four times and then holds as a steady gold fill. */
/* The halo round a button is an outline set off from its box: ink outside the box, never scrollable overflow (a text-spill check reads scrollWidth). */
.ring { position: absolute; inset: 0; border-radius: 50%; outline: 3px solid var(--cream); outline-offset: 6px; pointer-events: none; opacity: 0; }
.tb.pulse { background: rgba(255, 244, 214, 0.75); color: var(--ink); }
.tb.pulse .ring { animation: tb-ring 0.9s ease-out 4; }
@keyframes tb-ring { from { transform: scale(0.9); opacity: 0.95; } to { transform: scale(1.45); opacity: 0; } }
body.reduce-motion .tb.pulse .ring { animation: none; opacity: 0.8; transform: scale(1.1); }
/* The FUD fog: a dark vignette closing in, with two drifting cloud layers over it. */
#fog { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: radial-gradient(circle at center, rgba(30, 20, 40, 0.25) 18%, rgba(20, 10, 30, 0.96) 72%); opacity: 0; transition: opacity 0.3s; }
#fog::before, #fog::after { content: ""; position: absolute; inset: -40%; background: radial-gradient(circle at 30% 40%, rgba(90, 70, 130, 0.55) 0, rgba(90, 70, 130, 0) 28%), radial-gradient(circle at 70% 65%, rgba(60, 40, 100, 0.6) 0, rgba(60, 40, 100, 0) 30%); }
#fog::after { opacity: 0.7; }
/* The drift runs only while the fog shows: an animation on a hidden layer would still cost a style pass every frame. */
#fog.on { opacity: 1; }
#fog.on::before { animation: fog-drift 9s linear infinite; }
#fog.on::after { animation: fog-drift 13s linear infinite reverse; }
@keyframes fog-drift { from { transform: translate(-6%, -4%) rotate(0deg); } to { transform: translate(6%, 4%) rotate(360deg); } }
/* The rocket lock-on: a red reticle in the middle of the view and a word under it. */
/* The threat arrows: a small triangle at the frame's edge toward a kart about to hit the
   player or a rocket coming in, red and blinking for a rocket. */
#threats { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#threats .threat { position: absolute; left: 0; top: 0; width: 0; height: 0; margin: -11px 0 0 -12px; border-left: 12px solid transparent; border-right: 12px solid transparent; border-bottom: 22px solid var(--cream); filter: drop-shadow(0 2px 0 var(--ink)) drop-shadow(0 0 6px rgba(0, 0, 0, 0.6)); opacity: 0.95; }
#threats .threat.rocket { border-bottom-color: var(--down); animation: threat-blink 0.3s infinite alternate; }
/* The nearest rival's arrow: its kart's colour (set from the match), a little smaller and calmer than a threat's. */
#threats .threat.rival { opacity: 0.8; border-left-width: 10px; border-right-width: 10px; border-bottom-width: 18px; margin: -9px 0 0 -10px; }
#threats .threat.off { display: none; }
@keyframes threat-blink { from { opacity: 0.5; } to { opacity: 1; } }
body.reduce-motion #threats .threat.rocket { animation: none; }
#lock { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 6px; opacity: 0; }
#lock.show { opacity: 1; animation: lock-pulse 0.4s infinite alternate; }
#lock .reticle { width: 120px; height: 120px; border: 4px solid var(--down); border-radius: 50%; box-shadow: 0 0 18px rgba(255, 74, 61, 0.7), inset 0 0 18px rgba(255, 74, 61, 0.5); position: relative; }
#lock .reticle::before, #lock .reticle::after { content: ""; position: absolute; background: var(--down); }
#lock .reticle::before { left: 50%; top: -14px; width: 4px; height: 24px; margin-left: -2px; box-shadow: 0 110px 0 var(--down); }
#lock .reticle::after { top: 50%; left: -14px; height: 4px; width: 24px; margin-top: -2px; box-shadow: 110px 0 0 var(--down); }
#lock .lock-text { color: var(--down); font-size: 18px; font-weight: 900; letter-spacing: 2px; background: var(--glass); padding: 2px 12px; border-radius: 8px; border: 2px solid var(--down); }
@keyframes lock-pulse { from { transform: translate(-50%, -50%) scale(1); } to { transform: translate(-50%, -50%) scale(1.08); } }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 4; background: rgba(255, 60, 40, 0.35); opacity: 0; }
#flash.hit { animation: flash 0.25s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
/* Reduce motion: softer flashes, no pulses, plain fades for the banner and the warnings. */
body.reduce-motion #flash.hit { animation: flash-soft 0.25s ease-out; }
@keyframes flash-soft { from { opacity: 0.35; } to { opacity: 0; } }
body.reduce-motion #banner.show, body.reduce-motion #banner.bank.show { animation: banner-fade 1s ease-out forwards; }
@keyframes banner-fade { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
body.reduce-motion #warn.show, body.reduce-motion #lock.show, body.reduce-motion #timer.bull, body.reduce-motion #wrong-way.show { animation: none; }
body.reduce-motion #fog::before, body.reduce-motion #fog::after { animation: none; }
body.reduce-motion .unlock-card { animation: none; }
body.reduce-motion button, body.reduce-motion .toggle input[type="checkbox"], body.reduce-motion .toggle input[type="checkbox"]::before { transition: none; }

/* ---- touch play ---- */
#touch { position: fixed; inset: 0; z-index: 6; touch-action: none; }
#touch-area { position: absolute; top: env(safe-area-inset-top, 0px); right: env(safe-area-inset-right, 0px); bottom: env(safe-area-inset-bottom, 0px); left: env(safe-area-inset-left, 0px); }
#stick { position: absolute; display: none; width: 120px; height: 120px; margin: -60px 0 0 -60px; pointer-events: none; }
#stick-base { width: 120px; height: 120px; border-radius: 50%; border: 3px solid var(--ink); background: rgba(20, 16, 31, 0.4); display: flex; align-items: center; justify-content: center; }
#stick-knob { width: 54px; height: 54px; border-radius: 50%; background: var(--cream); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); }
.tb { position: absolute; border-radius: 50%; border: 3px solid var(--ink); background: rgba(20, 16, 31, 0.55); color: var(--cream); font-size: 15px; font-weight: 900; letter-spacing: 1px; padding: 0; touch-action: none; min-height: 0; box-shadow: 0 3px 0 var(--ink); }
.tb.down { background: var(--cream); color: var(--ink); }
.tb:active { transform: none; }
/* The right thumb's cluster, in the bottom-right corner: FIRE in the corner, HOP left of it,
   BRAKE above it, LOOK (a race) above HOP; CHAT is small and up by the pause button, out of the play view. */
#tb-fire { width: 84px; height: 84px; right: 22px; bottom: 28px; border-color: var(--cream); }
#tb-fire.idle { opacity: 0.45; border-color: var(--ink); }
#tb-hop { width: 62px; height: 62px; right: 116px; bottom: 24px; }
#tb-brake { width: 58px; height: 58px; right: 36px; bottom: 124px; font-size: 15px; }
#tb-look { width: 56px; height: 56px; right: 122px; bottom: 98px; font-size: 15px; }
.tb-top { position: absolute; top: 8px; left: calc(50% + 70px); width: 44px; height: 44px; border-radius: 50%; padding: 0; font-weight: 900; font-size: 15px; background: rgba(20, 16, 31, 0.55); border: 3px solid var(--ink); min-height: 0; box-shadow: 0 3px 0 var(--ink); }
body.touch #hint { display: none; }
/* Under touch the weapon slot and the Exchange arrow share one low row in the middle, under the
   player's kart rather than over it (the stick owns the left, the buttons the right). */
body.touch #bottom-left { left: 50%; transform: translateX(-50%); bottom: calc(8px + env(safe-area-inset-bottom, 0)); flex-direction: row; align-items: center; gap: 16px; }
body.touch #weapon { min-width: 150px; padding: 4px 12px 4px 4px; }
body.touch #weapon-icon { width: 44px; height: 44px; }
body.touch #weapon-name { font-size: 15px; }
.card { position: fixed; left: 50%; top: 12px; --rest: translateX(-50%); transform: var(--rest); z-index: 12; width: 300px; max-width: 92vw; padding: 12px 16px; text-align: center; background: var(--panel); border: 3px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow-hard); }
/* The turn-sideways card is a hint, never a wall: taps go through it to what it covers. */
#rotate.card { pointer-events: none; display: flex; align-items: center; justify-content: center; gap: 12px; width: auto; max-width: 92vw; padding: 10px 18px; }
.card .phone { width: 18px; height: 32px; margin: 0; border: 3px solid var(--gold); border-radius: 4px; animation: rotate-hint 2.4s ease-in-out infinite; flex: none; }
@keyframes rotate-hint { 0%, 30% { transform: rotate(0deg); } 60%, 100% { transform: rotate(90deg); } }
.rotate-text { font-size: 16px; font-weight: 900; color: var(--gold); }

/* Frames a little under 640 px tall (1077x606, 1080x607): the settings and end panels would scroll
   by a few pixels, so their padding tightens and the end panel may stand taller. */
@media (max-height: 640px) {
  .panel { padding: 14px 24px; gap: 9px; }
  .end-panel { max-height: 86vh; max-height: 86dvh; }
  .controls, .setting-note { font-size: 15px; }
}

@media (max-height: 560px) {
  #coach { font-size: 16px; padding: 5px 14px; bottom: calc(54px + env(safe-area-inset-bottom, 0)); }
  .panel { padding: 10px 18px; gap: 7px; }
  /* The garage on a short frame: a tighter grid and a smaller note, so both rows of cards stand whole. */
  .garage-panel .options { padding: 4px; }
  .garage-panel .fine { font-size: 15px; }
  .logo { width: 220px; }
  .logo.big { width: 300px; }
  .controls { display: none; }
  .tagline { font-size: 15px; }
  /* The panel's rows never squeeze: a frame too short for them scrolls the panel instead. */
  .panel > * { flex-shrink: 0; }
  .title-panel { gap: 5px; padding: 8px 18px; }
  .title-panel .logo { width: 190px; }
  .title-panel .main-group { gap: 5px; }
  .title-panel .player-strip { padding: 4px 8px; gap: 2px; }
  .title-panel button.quiet { padding: 3px 8px 2px; min-width: 80px; }
  .title-panel button.quiet .quiet-icon { width: 20px; height: 20px; }
  .title-panel button.play-btn { min-height: 44px; padding: 6px 60px; font-size: 26px; }
  #coach { font-size: 15px; padding: 5px 12px; }
  #weapon { padding: 4px 10px 4px 4px; }
  #weapon-icon { width: 44px; height: 44px; }
  .modes button.mode { min-height: 32px; padding: 5px 18px; }
  button.primary.big-btn { font-size: 22px; padding: 8px 44px; }
  button { min-height: 40px; padding: 8px 16px; }
  /* Three unlock cards and a new-best card can share the end panel on a short frame: the
     podium, the title and the panel's own padding give the room, so Play again stays inside. */
  .podium { height: 96px; }
  .podium .p1 .block { height: 44px; }
  .podium .p2 .block { height: 34px; }
  .podium .p3 .block { height: 24px; }
  .end { align-items: center; padding-bottom: 0; }
  .end-panel { max-height: 94vh; max-height: 94dvh; padding: 10px 20px; gap: 6px; }
  .end-panel h2 { font-size: 26px; }
  /* Four unlock cards (a race can pay several levels at once) fit on one row, so Play again stays inside the frame. */
  .unlocks { gap: 6px; }
  .unlock-card, .best-card { padding: 3px 8px; }
  .xp-next { margin-top: -2px; }
  .end-buttons #again { min-width: 220px; }
  #timer { font-size: 26px; }
  #score-box { font-size: 24px; }
  #race-place { font-size: 28px; }
  /* The banner sits under the feed's two lines (a third is dropped on a short frame) and over the
     pending line, the pops under the race HUD's best-lap box. */
  #banner { font-size: 38px; top: 34%; }
  #pending { top: 44%; }
  #feed li:nth-child(n+3) { display: none; }
  #pops { top: 21%; }
  #pops .pop { font-size: 20px; }
  #minimap { width: 110px; height: 110px; top: calc(96px + env(safe-area-inset-top, 0)); }
  body.touch #minimap { width: 96px; height: 96px; top: calc(64px + env(safe-area-inset-top, 0)); }
  #wrong-way { font-size: 20px; }
  .garage-panel { width: 400px; }
  .options { gap: 6px; }
  .option { min-height: 50px; padding: 5px 4px; }
  .tabs { gap: 6px; padding: 4px; }
  .tabs button { min-height: 50px; padding: 4px 2px 3px; gap: 2px; }
  .tabs button canvas { width: 22px; height: 22px; }
}

/* Narrow desktop frames: the hint pill would run under the weapon slot, so the slot and the
   Exchange arrow sit above it. */
/* Frames up to 1100 px wide (1077x606 and 1080x607 among the platform's): the centred controls
   strip would reach the weapon slot's corner, so the slot stands above it. */
@media (max-width: 1100px) {
  body:not(.touch) #bottom-left { bottom: calc(46px + env(safe-area-inset-bottom, 0)); }
  /* The slot sizes to its words, so the prompt beside it has its room; its line wraps rather than widening the slot under a centred prompt. */
  #weapon { min-width: 0; }
  #weapon-uses { max-width: 132px; white-space: normal; line-height: 1.15; }
}

/* Phones (under 440 px tall): tighter panels, the settings note gone, the end panel centred and compact
   so Done, Play again and Lobby sit inside the screen without scrolling. */
@media (max-height: 440px) {
  /* A phone held sideways: two feed lines, wide enough for a whole line, over the banner's line. */
  body.touch #feed { max-width: 60vw; }
  body.touch #banner { top: 47%; }
  body.touch #pops { top: 56%; }
  .panel { padding: 8px 16px; gap: 4px; }
  h2 { font-size: 24px; }
  /* The title's rows never shrink into each other (the logo would overlap the mode pick): the
     logo and the buttons are smaller instead, so the whole panel fits a 390 px frame. */
  .panel { gap: 3px; }
  .panel > * { flex-shrink: 0; }
  .logo, .logo.big { width: 170px; }
  .panel .modes button.mode { padding: 5px 20px; font-size: 16px; min-height: 34px; }
  /* A phone held sideways: the player strip steps aside while the More rows are open, so the panel never scrolls. */
  .title-panel:has(#more-rows:not([hidden])) .player-strip { display: none; }
  .level-row { font-size: 15px; }
  .title-panel .logo { width: 180px; }
  .main-group button.solo { min-height: 30px; padding: 3px 14px; font-size: 15px; }
  .title-panel { gap: 2px; padding: 5px 16px; }
  .title-panel .logo { width: 150px; }
  .title-panel .main-group { gap: 3px; }
  .title-panel button.quiet { padding: 2px 8px 1px; gap: 0; }
  .title-panel button.quiet .quiet-icon { width: 18px; height: 18px; }
  .title-panel .player-strip { padding: 2px 8px; gap: 0; }
  .title-panel .who-row { gap: 6px; }
  .title-panel button.icon-btn { width: 26px; height: 26px; }
  .title-panel .level-bar { height: 8px; }
  .title-panel .next-row .next-icon { width: 16px; height: 16px; }
  .panel .buttons button, .panel .code-row button, .panel .code-row input { min-height: 36px; padding: 4px 14px; }
  .panel button.primary.big-btn { font-size: 20px; padding: 4px 40px; min-height: 38px; }
  .title-panel button.play-btn { font-size: 24px; padding: 4px 50px; min-height: 40px; min-width: 240px; }
  .who-row .name { font-size: 16px; }
  /* The podium's names behind the panel would read through it on a short frame. */
  .end-panel { background: rgba(28, 26, 51, 0.98); }
  .setting-note { display: none; }
  .end { align-items: center; padding-bottom: 0; }
  .end-panel { max-height: 96vh; max-height: 96dvh; padding: 6px 16px; gap: 2px; }
  /* The names and scores over the blocks need their own room, or they run up into the title. */
  /* The place word is smaller on a short frame, so the third block (the lowest) holds it whole over the stats line. */
  .podium { height: 104px; }
  .podium .block { font-size: 16px; padding-top: 3px; }
  .podium .p1 .block { height: 42px; }
  .podium .p2 .block { height: 34px; }
  .podium .p3 .block { height: 26px; }
  .podium .who, .podium .score { line-height: 1.1; }
  /* A locked garage card on a phone says its level alone: the lock icon would push the words past the card's edge. */
  .option .lock-icon { display: none; }
  /* The tabs and the cards tighter, so two rows of each and the note fit a 390 px frame without the list scrolling a card's last line away. */
  .tabs button { min-height: 42px; padding: 3px 2px 2px; gap: 1px; }
  .tabs button canvas { width: 22px; height: 22px; }
  .options { gap: 5px; }
  .option { min-height: 50px; }
  .unlock-card, .best-card { padding: 3px 10px; }
  button.primary { font-size: 20px; padding: 8px 36px; }
  .end-buttons #again { min-width: 200px; font-size: 22px; }
  .xp-next { display: none; }
  .garage-panel { width: 380px; }
  .tabs button { min-height: 44px; }
  .tabs button canvas { width: 20px; height: 20px; }
}

/* ---- the mode pick: two slabs, the chosen one gold ---- */
.modes { display: flex; gap: 0; border: 3px solid var(--ink); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-hard); }
.modes button.mode { border: 0; border-radius: 0; box-shadow: none; min-width: 120px; padding: 9px 24px; font-size: 18px; }
.modes button.mode:active { transform: none; }
.modes button.mode.on { background: var(--gold); color: var(--ink); }
.modes button.mode.on:hover { background: var(--gold-pale); }

/* ---- online: title extras, the waiting card, emotes, invite, reports ---- */
.code-row { display: flex; gap: 8px; align-items: center; justify-content: center; }
#code { width: 160px; font: inherit; font-size: 16px; font-weight: 900; letter-spacing: 3px; text-transform: uppercase; text-align: center; padding: 8px 10px; border-radius: 10px; border: 3px solid var(--ink); background: rgba(0, 0, 0, 0.35); color: var(--text); }
#code:focus { outline: none; border-color: var(--gold); }
#code::placeholder { letter-spacing: 0; text-transform: none; font-weight: 700; opacity: 0.6; }
.status { margin: 0; font-size: 15px; color: #ffb3a7; min-height: 18px; font-weight: 700; }
.status.ok { color: var(--up); }
/* The line under Play while the game server is away: information, not an error. It takes the
   controls preview's place (that line hides meanwhile) and the panel widens a little so the
   line fits whole, so the panel's height does not change; a frame too narrow for that width
   gets the line balanced over two. */
.status.offline { color: var(--gold); font-size: 15px; text-align: center; line-height: 1.2; text-wrap: balance; max-width: 100%; }
.title-panel:has(#offline:not([hidden])) { width: 440px; }
.wait-text { font-size: 19px; font-weight: 900; color: var(--gold); }
.wait-sub { font-size: 15px; opacity: 0.85; margin-top: 4px; font-weight: 700; }
#waiting { top: 40%; width: 360px; padding: 18px 20px; }
.next-round { margin: 0; font-size: 15px; color: var(--gold); font-weight: 900; }
.invite { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap; }
.invite-code { font-size: 22px; font-weight: 900; letter-spacing: 4px; color: var(--gold); background: rgba(0, 0, 0, 0.35); padding: 4px 12px; border-radius: 10px; border: 2px solid var(--ink); }
.reports { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.report-row { display: flex; align-items: center; gap: 8px; justify-content: center; font-size: 15px; }
.report-row .who { font-weight: 900; min-width: 110px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.report-row select { font: inherit; font-size: 15px; padding: 4px 6px; border-radius: 8px; background: rgba(0, 0, 0, 0.35); color: var(--text); border: 2px solid var(--ink); }
.report-row .done { color: var(--up); font-weight: 900; }
.emotes { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%); z-index: 7; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 8px; background: var(--panel); border: 3px solid var(--ink); border-radius: 14px; box-shadow: var(--shadow-hard); }
.emotes button { padding: 8px 10px; font-size: 15px; min-width: 80px; min-height: 42px; }
body.touch .emotes button { min-height: 56px; }
#tb-chat { width: 56px; height: 56px; top: 4px; bottom: auto; right: auto; left: calc(50% + 122px); font-size: 15px; }
@media (max-height: 560px) {
  #waiting { top: 34%; }
}

/* ---- portrait on a phone: the turn-sideways card in the middle, the HUD narrower, the
   weapon slot at the left so the touch buttons keep the right ---- */
@media (orientation: portrait) and (max-width: 600px) {
  /* The hint sits under the lobby's panels, and in the middle of the view while the touch controls are up. */
  #rotate.card { top: auto; bottom: calc(14px + env(safe-area-inset-bottom, 0)); left: auto; right: calc(12px + env(safe-area-inset-right, 0)); --rest: translate(0, 0); transform: var(--rest); max-width: 58vw; }
  #touch:not([hidden]) ~ #rotate.card { top: 50%; bottom: auto; left: 50%; right: auto; --rest: translate(-50%, -50%); transform: var(--rest); }
  #banner { font-size: 30px; }
  #pops .pop { font-size: 18px; }
  #tb-look { right: 130px; bottom: 170px; }
  #top-bar { gap: 6px; grid-template-columns: auto auto auto; justify-content: space-between; }
  /* The prompt sits under the pause button, wrapping to two lines inside the narrow frame. */
  body.touch #coach { top: calc(102px + env(safe-area-inset-top, 0)); font-size: 16px; white-space: normal; text-align: center; max-width: 88vw; padding: 6px 14px; }
  body.touch #warn { top: calc(176px + env(safe-area-inset-top, 0)); }
  body.touch #wrong-way { top: calc(218px + env(safe-area-inset-top, 0)); }
  #race-box { padding: 0 8px; gap: 5px; white-space: nowrap; }
  #top3 li { white-space: nowrap; }
  #score-box { font-size: 22px; padding: 0 8px; }
  #timer { font-size: 22px; padding: 2px 10px; }
  /* The top three would be clipped at the frame's edge: upright, the score boxes and the clock carry the bar. */
  #board { display: none; }
  /* The pause button under the score or position box; the minimap under it; the slot under
     the weapon, clear of the HOP button; the end panel in the middle, clear of the
     turn-sideways card at the bottom. */
  .tb-top { left: calc(12px + env(safe-area-inset-left, 0)); transform: none; top: calc(52px + env(safe-area-inset-top, 0)); }
  body.touch #minimap { top: calc(104px + env(safe-area-inset-top, 0)); }
  .end { align-items: center; padding-bottom: 0; }
  /* A garage card's lock line wraps in the narrow columns of an upright phone. */
  .option .lock { white-space: normal; text-align: center; }
  /* The feed sits under the prompt, the warning and the wrong-way sign, which take the top of a portrait frame. */
  #feed { max-width: 58vw; font-size: 15px; top: calc(262px + env(safe-area-inset-top, 0)); }
  body.touch #bottom-left { left: calc(8px + env(safe-area-inset-left, 0)); transform: none; flex-direction: column; align-items: flex-start; gap: 6px; bottom: calc(8px + env(safe-area-inset-bottom, 0)); }
  body.touch #weapon { min-width: 140px; padding: 4px 10px 4px 4px; }
  body.touch #weapon-icon { width: 44px; height: 44px; }
  body.touch #weapon-name { font-size: 15px; }
  #race-place { font-size: 24px; }
  #race-of { font-size: 15px; }
  #race-lap { font-size: 15px; }
  body.touch #minimap { width: 80px; height: 80px; }
  .garage-panel { width: 94vw; }
}

/* ---- the privacy page ---- */
body.page { overflow: auto; touch-action: auto; -webkit-user-select: text; user-select: text; font-weight: 500; }
.prose { max-width: 640px; margin: 0 auto; padding: 24px 20px 60px; line-height: 1.5; font-size: 16px; }
.prose h1 { color: var(--gold); }
.prose h2 { font-size: 22px; margin-top: 24px; text-shadow: none; }
.prose ul { padding-left: 20px; }
