:root {
  --ink: #ffffff;
  --hot: #ff3d7f;
  --hot-dark: #a3164b;
  --amber: #ffb627;
  --teal: #2de2e6;
  --panel: rgba(28, 14, 52, 0.74);
  --panel-edge: rgba(255, 255, 255, 0.18);
  --display: 'Bungee', 'Impact', system-ui, sans-serif;
  --font: 'Chakra Petch', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2a1846;
  color: var(--ink);
  font: 600 15px/1.3 var(--font);
  user-select: none;
  -webkit-user-select: none;
  touch-action: auto;
}

/* Present in the initial HTML so module and model downloads are covered too. */
body.loading > :not(#loading-screen) { visibility: hidden; }
#loading-screen {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  overflow: auto; padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background: radial-gradient(ellipse at 50% 35%, #352044 0, #151321 60%, #0b1019 100%);
}
#loading-screen[hidden] { display: none; }
.loading-content { width: min(100%, 440px); text-align: center; }
.loading-kicker { margin: 0 0 20px; color: var(--teal); font-size: 12px; letter-spacing: .25em; }
#loading-title { margin: 0; font: 400 clamp(36px, 9vw, 62px)/1.05 var(--display); color: var(--amber); text-shadow: 3px 4px 0 var(--hot-dark); }
#loading-title span { display: block; color: var(--hot); text-shadow: 3px 4px 0 #4a0b26; }
.loading-road { position: relative; height: 112px; margin: 24px 0; overflow: hidden; border-bottom: 1px solid #ffffff24; }
.loading-road::after { content: ''; position: absolute; bottom: 7px; left: -60px; width: calc(100% + 120px); height: 2px; background: repeating-linear-gradient(90deg, var(--teal) 0 24px, transparent 24px 60px); animation: loading-road .65s linear infinite; }
.loading-bike { position: relative; width: 120px; height: 80px; margin-top: 12px; color: var(--amber); filter: drop-shadow(0 0 14px #ffb62730); }
.loading-details { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; text-align: left; font-size: 14px; }
#loading-status { margin: 0 0 12px; }
#loading-percent { color: var(--teal); font-variant-numeric: tabular-nums; }
#loading-progress { display: block; appearance: none; width: 100%; height: 6px; border: 0; border-radius: 8px; overflow: hidden; background: #ffffff18; accent-color: var(--hot); }
#loading-progress[hidden] { display: none; }
#loading-progress::-webkit-progress-bar { background: #ffffff18; border-radius: 8px; }
#loading-progress::-webkit-progress-value { background: linear-gradient(90deg, var(--hot), var(--amber)); border-radius: 8px; transition: width .2s; }
#loading-progress::-moz-progress-bar { background: linear-gradient(90deg, var(--hot), var(--amber)); border-radius: 8px; }
.loading-tip { margin: 20px 0 0; color: #b5adbf; font-size: 13px; }
#loading-retry { margin-top: 20px; padding: 12px 24px; border: 1px solid var(--amber); border-radius: 8px; background: #302037; color: var(--amber); font: 700 16px var(--font); cursor: pointer; }
#loading-retry:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; }
.failed .loading-road::after { animation: none; }
@keyframes loading-road { to { transform: translateX(-60px); } }
@media (prefers-reduced-motion: reduce) {
  .loading-road::after { animation: none; }
  #loading-progress::-webkit-progress-value { transition: none; }
}

#game,
#game canvas,
.labels { position: fixed; inset: 0; }
.labels { pointer-events: none; }
#speed-lines { position: fixed; inset: 0; width: 100%; height: var(--viewport-height, 100vh); z-index: 3; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { #speed-lines { display: none; } }

.label { font: 700 14px var(--font); white-space: nowrap; text-align: center; text-shadow: 0 1px 0 #000, 0 0 6px rgba(0, 0, 0, 0.7); }
.label .hp { width: 48px; height: 5px; margin: 2px auto 0; border-radius: 3px; overflow: hidden; background: rgba(0, 0, 0, 0.45); }
.label .hp i { display: block; width: 100%; height: 100%; background: #5dff9a; }
/* Riders ahead: compact tag that fades with distance (see name-tags.js). */
.label.ahead { font-size: 10px; letter-spacing: .02em; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); transition: opacity .25s; }
.label.ahead .hp { width: 26px; height: 3px; margin-top: 1px; }

kbd { display: inline-block; min-width: 20px; padding: 0 5px; border-radius: 5px; background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(255, 255, 255, 0.25); font: 700 12px var(--font); text-align: center; }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; display: none; }
body.playing #hud { display: block; }

#rankbox { position: absolute; top: 12px; left: 12px; width: 220px; }
#rank { font: 400 40px/1 var(--display); color: var(--amber); text-shadow: 3px 3px 0 var(--hot-dark); margin-bottom: 6px; }
#rank .of { margin-left: 6px; font-size: 18px; color: #fff; text-shadow: 2px 2px 0 var(--hot-dark); }
#board { list-style: none; margin: 0; padding: 4px; border-radius: 10px; background: var(--panel); border: 1px solid var(--panel-edge); }
#board li { display: flex; align-items: center; gap: 7px; padding: 2px 6px; border-radius: 6px; font-size: 14px; }
#board li.me { background: rgba(255, 182, 39, 0.22); color: var(--amber); }
#board li.down { opacity: 0.55; }
#board .pos { flex: none; width: 18px; text-align: right; opacity: 0.8; }
#board .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; }
#board .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .gap { flex: none; font-size: 12px; opacity: 0.8; }

#topbar { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: min(520px, 46vw); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#progress { width: 100%; padding: 8px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-edge); }
#ptrack { position: relative; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #6e6a80 0 19%, #93c46a 19% 43%, #3f8f4a 43% 66%, #c9733f 66% 86%, #77738a 86%); }
#ptrack .flag { position: absolute; right: -10px; top: -9px; font-size: 16px; }
#ptrack .cp { position: absolute; top: -3px; width: 2px; height: 12px; background: #fff; opacity: 0.6; }
#pmarks .pm { position: absolute; top: -5px; width: 12px; height: 16px; margin-left: -6px; border-radius: 6px 6px 6px 0; transform: rotate(-45deg) scale(0.75); border: 2px solid #1c0e34; transition: left 0.12s linear; }
#pmarks .pm.me { z-index: 2; transform: rotate(-45deg) scale(1.05); border-color: #fff; }
#timerbox { display: flex; align-items: baseline; gap: 10px; padding: 2px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-edge); }
#timer { font: 700 22px var(--font); font-variant-numeric: tabular-nums; }
#limit { font-size: 13px; color: var(--amber); }
#limit:empty { display: none; }

#mapbox { position: absolute; top: 12px; right: 66px; width: 200px; height: 200px; border-radius: 16px; background: rgba(17, 28, 42, 0.88); border: 1px solid rgba(186, 255, 255, 0.35); overflow: hidden; }
#minimap { display: block; width: 100%; height: 100%; }

.round-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.7);
  background: var(--panel);
  font-size: 19px;
  pointer-events: auto;
  cursor: pointer;
}

#feed { position: absolute; top: 224px; right: 12px; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; max-width: 320px; }
#feed div { padding: 4px 10px; border-radius: 8px; background: var(--panel); border: 1px solid var(--panel-edge); font-size: 14px; animation: slide 0.25s ease-out; }
#feed b { color: var(--amber); }
#feed .td { margin: 0 6px; padding: 0 6px; border-radius: 4px; background: var(--hot); color: #fff; font-size: 11px; }

#bars { position: absolute; left: 12px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-edge); }
.meter { display: flex; align-items: center; gap: 8px; }
.meter .lbl { width: 66px; font-size: 12px; letter-spacing: 1px; opacity: 0.85; }
.bar { width: 170px; height: 12px; border-radius: 6px; overflow: hidden; background: rgba(255, 255, 255, 0.12); }
.bar i { display: block; width: 100%; height: 100%; transition: width 0.1s; }
.bar.hp i { background: linear-gradient(90deg, #ff4d6d, #5dff9a); background-size: 170px 100%; }
.bar.hp.low i { animation: blink 0.5s steps(2) infinite; }
.bar.stab i { background: linear-gradient(90deg, #ffb627, #ffe48a); }
.bar.nitro i { background: linear-gradient(90deg, #2de2e6, #7a6bff); }
.bar.nitro.on i { box-shadow: 0 0 10px #2de2e6; }

#dash { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; align-items: flex-end; gap: 12px; }
#speedo { min-width: 140px; padding: 4px 16px; border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-edge); text-align: center; }
#speed { display: block; font: 400 44px/1 var(--display); color: #fff; text-shadow: 3px 3px 0 var(--hot-dark); font-variant-numeric: tabular-nums; }
#speedo small { font-size: 11px; letter-spacing: 2px; opacity: 0.8; }
#speedo.boost #speed { color: var(--teal); }
#power { display: flex; align-items: center; gap: 10px; padding: 6px 16px 6px 6px; border-radius: 999px; background: var(--panel); border: 2px solid var(--amber); }
#picon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--amber); color: #3a1d00; font-size: 26px; }
#pname { font: 700 17px var(--font); }
#phint { font-size: 12px; opacity: 0.8; }
#power.empty { border-color: var(--panel-edge); }
#power.empty #picon { background: rgba(255, 255, 255, 0.15); color: rgba(255, 255, 255, 0.6); }
#power.fresh { animation: bump 0.35s ease-out; }

#keys { position: absolute; right: 12px; bottom: 16px; padding: 8px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-edge); font-size: 12px; line-height: 1.9; text-align: right; opacity: 0.85; }

#popups { position: absolute; left: 50%; top: 30%; }
.pop { position: absolute; transform: translateX(-50%); white-space: nowrap; font: 400 32px var(--display); color: var(--amber); text-shadow: 3px 3px 0 var(--hot-dark), 0 6px 14px rgba(0, 0, 0, 0.4); animation: pop 1.4s ease-out forwards; }
.pop.small { font-size: 22px; color: #fff; }
.pop.teal { color: var(--teal); }

#hurt { position: fixed; inset: 0; z-index: 4; pointer-events: none; opacity: 0; box-shadow: inset 0 0 200px 50px rgba(255, 40, 80, 0.6); }
#hurt.on { animation: fade 0.5s ease-out; }
#boostfx { position: fixed; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity 0.25s; box-shadow: inset 0 0 160px 30px rgba(45, 226, 230, 0.45); }
#boostfx.on { opacity: 1; }

/* Touch controls (only on touch screens) */
#stick,
#tbtns { display: none; pointer-events: auto; position: absolute; }
#stick { left: 22px; bottom: 22px; width: 150px; height: 150px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); border: 3px solid rgba(255, 255, 255, 0.55); }
#knob { position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); }
#tbtns { right: 16px; bottom: 16px; grid-template-columns: repeat(3, 74px); grid-template-rows: 54px 74px 54px; gap: 8px; }
.tb { border: 2px solid #fff; border-radius: 16px; background: var(--panel); color: #fff; font: 700 13px var(--font); }
.tb:active, .tb.on { background: var(--hot); }
.button-icon { display: inline-block; width: 28px; height: 28px; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.kick-left { transform: scaleX(-1); }
.play .button-icon { width: 38px; height: 38px; }
.tb.big { background: var(--hot); font-size: 15px; }
.tb.small { grid-column: 3; font-size: 22px; }
.tb.nitro { grid-column: 1 / span 3; background: #1c7f8f; }
.tb.nitro.on { background: var(--teal); color: #102; }
[data-act='kickL'] { grid-column: 1; grid-row: 2; }
[data-act='punch'] { grid-column: 2; grid-row: 2; }
[data-act='kickR'] { grid-column: 3; grid-row: 2; }
[data-act='power'] { grid-row: 1; }

/* Banner (countdown, crashes, finishing) */
#banner { position: fixed; left: 0; right: 0; top: 22%; z-index: 9; display: none; text-align: center; pointer-events: none; }
#banner.on { display: block; animation: drop 0.3s ease-out; }
#btitle { font: 400 clamp(40px, 9vw, 92px)/1 var(--display); color: var(--amber); text-shadow: 4px 4px 0 var(--hot-dark), 0 10px 24px rgba(0, 0, 0, 0.35); }
#btitle b { font-weight: 400; color: var(--teal); }
#bsub { margin-top: 10px; font: 700 clamp(18px, 3.4vw, 28px) var(--font); text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6); }

/* Results */
#results { position: fixed; inset: 0; z-index: 12; display: none; place-items: center; background: rgba(20, 8, 40, 0.55); }
#results.on { display: grid; animation: fadein 0.3s ease-out; }
#results .card { width: min(560px, calc(100vw - 32px)); padding: 20px 22px; border-radius: 18px; background: rgba(28, 14, 52, 0.92); border: 2px solid var(--hot); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }
#results h2 { margin: 0 0 12px; font: 400 32px var(--display); color: var(--amber); text-align: center; text-shadow: 3px 3px 0 var(--hot-dark); }
#results table { width: 100%; border-collapse: collapse; font-size: 16px; }
#results th { padding: 4px 6px; font-size: 12px; letter-spacing: 1px; opacity: 0.7; text-align: left; }
#results td { padding: 6px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
#results td:first-child { font: 400 18px var(--display); width: 36px; }
#results tr.me td { color: var(--amber); }
#results tr.p1 td:first-child { color: #ffd84d; }
#results .dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; }
#results td.num { font-variant-numeric: tabular-nums; }
#resnext { margin: 14px 0 0; text-align: center; opacity: 0.85; }

/* Menu */
#menu { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(40, 10, 60, 0.2), rgba(20, 6, 40, 0.75)); }
body.playing #menu { display: none; }
#menu .card { width: min(460px, calc(100vw - 32px)); text-align: center; }
h1 { margin: 0; font: 400 clamp(46px, 12vw, 84px)/0.92 var(--display); color: var(--amber); text-shadow: 5px 5px 0 var(--hot-dark), 0 12px 30px rgba(0, 0, 0, 0.4); }
h1 span { color: var(--hot); text-shadow: 5px 5px 0 #4a0b26, 0 12px 30px rgba(0, 0, 0, 0.4); }
.tag { margin: 14px 0 18px; font-size: 17px; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6); }
#paints { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
#paints button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.35); cursor: pointer; }
#paints button.on { border-color: #fff; transform: translateY(-3px) scale(1.1); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
input {
  width: 100%;
  padding: 13px 16px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  outline: none;
  background: rgba(20, 8, 40, 0.75);
  color: #fff;
  font: 700 19px var(--font);
  text-align: center;
  user-select: text;
}
input:focus { border-color: var(--amber); }
.play {
  display: grid;
  place-items: center;
  line-height: 1;
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #ff5c93, var(--hot));
  box-shadow: 0 6px 0 var(--hot-dark);
  color: #fff;
  font: 400 30px var(--display);
  letter-spacing: 2px;
  cursor: pointer;
}
.play:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--hot-dark); }
.controls { margin-top: 18px; font-size: 13px; line-height: 2; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); }

#offline { position: fixed; top: 70px; left: 50%; z-index: 20; display: none; transform: translateX(-50%); padding: 10px 16px; border-radius: 10px; background: var(--hot); }
#offline.on { display: block; }
#offline.action { cursor: pointer; }

@keyframes fade { from { opacity: 1; } to { opacity: 0; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 50% { opacity: 0.4; } }
@keyframes slide { from { opacity: 0; transform: translateX(10px); } to { opacity: 1; transform: none; } }
@keyframes drop { from { opacity: 0; transform: translateY(-20px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}

/* Fit browser chrome, virtual keyboards and notched screens without scaling text. */
:root {
  --viewport-height: 100dvh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --edge: 12px;
  --map-size: 200px;
  --stick-size: 136px;
}
#game, #hud, #menu, #results { height: var(--viewport-height); bottom: auto; }
#hud { inset: var(--safe-top) var(--safe-right) auto var(--safe-left); height: calc(var(--viewport-height) - var(--safe-top) - var(--safe-bottom)); }
#game canvas { display: block; touch-action: none; }
#rankbox { left: var(--edge); top: var(--edge); }
#topbar { top: var(--edge); }
#mapbox { top: var(--edge); width: var(--map-size); height: var(--map-size); right: calc(var(--edge) + 54px); }
#mute { top: var(--edge); right: var(--edge); }
#feed { top: calc(var(--map-size) + var(--edge) + 12px); }
#power { min-width: 0; max-width: 340px; }
#power > div:last-child { min-width: 0; }
#picon { flex-shrink: 0; }
#pname, #phint { overflow-wrap: anywhere; }
#menu, #results {
  padding: calc(var(--safe-top) + 20px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 20px) calc(var(--safe-left) + 16px);
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  scroll-padding-top: calc(var(--safe-top) + 16px);
  scroll-padding-bottom: calc(var(--safe-bottom) + 16px);
}
#menu .card, #results .card { width: 100%; max-width: 460px; margin: auto; min-width: 0; }
#results .card { max-width: 560px; }
#results table { table-layout: fixed; }
#results th:first-child { width: 9%; }
#results th:nth-child(2) { width: 40%; }
#results th:nth-child(3) { width: 25%; }
#results th:nth-child(n+4) { width: 13%; }
#results td { overflow-wrap: anywhere; }
#paints button { width: 44px; height: 44px; }
#name { -webkit-user-select: text; }
.touch-help { display: none; font-size: 13px; line-height: 1.5; opacity: 0.9; }
.stick-hint { position: absolute; left: 0; right: 0; top: -22px; text-align: center; white-space: nowrap; font-size: 10px; letter-spacing: 1px; text-shadow: 0 1px 3px #000; }
#stick, .tb { touch-action: none; -webkit-tap-highlight-color: transparent; }
#knob { width: 40%; height: 40%; margin: -20% 0 0 -20%; }
#offline { max-width: calc(100vw - 32px); width: max-content; text-align: center; }
#banner { padding: 0 max(12px, var(--safe-left)); }
#btitle { overflow-wrap: anywhere; }
button:focus-visible { outline: 3px solid var(--teal); outline-offset: 3px; }

@media (max-width: 1200px) {
  :root { --map-size: 144px; }
  #rankbox { width: 180px; }
  #rank { font-size: 32px; }
  #topbar { width: min(480px, calc(100% - 440px)); }
  #keys { display: none; }
  #dash { left: auto; right: var(--edge); transform: none; }
  #speedo { min-width: 100px; }
  #speed { font-size: 36px; }
  #power { max-width: 300px; }
  .bar { width: 120px; }
}
@media (max-width: 900px), (max-height: 500px) {
  :root { --edge: 8px; --map-size: 108px; }
  #rankbox { width: 150px; }
  #rank { font-size: 28px; }
  #rank .of { font-size: 14px; }
  #board li { font-size: 12px; padding: 2px 4px; gap: 5px; }
  #board .gap { display: none; }
  #board li:nth-child(n+4):not(.me) { display: none; }
  #topbar { width: min(440px, calc(100% - 380px)); }
  #timer { font-size: 19px; }
  #timerbox { gap: 5px; padding: 2px 8px; }
  #limit { font-size: 11px; }
  #feed, #keys { display: none; }
  #bars { left: var(--edge); padding: 7px 8px; gap: 4px; }
  .meter { gap: 5px; }
  .meter .lbl { width: 58px; font-size: 10px; letter-spacing: 0.5px; }
  .bar { width: 100px; height: 9px; }
  #dash { gap: 6px; }
  #speedo { min-width: 80px; padding: 4px 8px; }
  #speed { font-size: 30px; }
  #picon { width: 34px; height: 34px; font-size: 22px; }
  #power { padding: 5px 9px 5px 5px; gap: 6px; max-width: 240px; }
  #pname { font-size: 14px; }
  #phint { font-size: 11px; }
  .pop { font-size: clamp(18px, 5vw, 28px); }
  .pop.small { font-size: clamp(14px, 4vw, 20px); }
}

/* Primary and hybrid touch devices use the same controls and input detection. */
@media (any-pointer: coarse) {
  #stick { display: block; width: var(--stick-size); height: var(--stick-size); left: 16px; bottom: 16px; }
  #tbtns { display: grid; right: 12px; bottom: 12px; width: 210px; grid-template-columns: repeat(3, minmax(44px, 1fr)); grid-template-rows: 44px 52px 44px; gap: 6px; }
  .tb { min-width: 44px; min-height: 44px; padding: 2px; font-size: 11px; border-radius: 12px; }
  .tb.big { font-size: 12px; }
  #keys, .controls { display: none; }
  .touch-help { display: block; }
  #bars { top: auto; bottom: calc(var(--stick-size) + 46px); width: 190px; padding: 7px 8px; }
  .meter .lbl { width: 58px; font-size: 10px; }
  .bar { flex: 1; width: auto; min-width: 0; height: 9px; }
  #dash { left: 50%; right: auto; transform: translateX(-50%); bottom: 16px; width: min(31vw, 300px); gap: 6px; align-items: center; }
  #speedo { min-width: 64px; padding: 5px 8px; }
  #speed { font-size: 28px; }
  #speedo small { font-size: 9px; letter-spacing: 1px; }
  #power { flex: 1; padding: 5px 8px; gap: 5px; border-radius: 12px; }
  #picon { width: 28px; height: 28px; font-size: 20px; }
  #pname { font-size: 12px; }
  #phint { display: none; }
}

@media (max-width: 600px) {
  :root { --stick-size: clamp(104px, 29vw, 136px); --map-size: clamp(90px, 27vw, 128px); }
  #topbar { left: var(--edge); right: 62px; width: auto; transform: none; gap: 5px; }
  #timerbox { align-self: center; }
  #progress { padding: 7px 12px; }
  #rankbox { top: 70px; width: min(44vw, 180px); }
  #mapbox { top: 70px; right: var(--edge); }
  #board { padding: 3px; }
  #board .pos { width: 14px; }
  #board .dot { width: 8px; height: 8px; }
  #board li { font-size: 11px; }
  #bars { width: 44%; bottom: 12px; }
  .bar { flex: 1; width: auto; min-width: 0; }
  #dash { width: 47%; right: var(--edge); left: auto; bottom: 12px; transform: none; gap: 4px; }
  #speedo { min-width: 56px; padding: 5px; }
  #speed { font-size: 25px; }
  #speedo small { font-size: 8px; letter-spacing: 1px; }
  #power { flex: 1; padding: 5px; gap: 3px; border-radius: 12px; }
  #picon { width: 24px; height: 24px; font-size: 17px; }
  #pname { font-size: 11px; }
  #phint { display: none; }
  #banner { top: 32%; }
  #btitle { font-size: clamp(28px, 9vw, 54px); }
  #bsub { font-size: 16px; }
  #popups { top: 40%; }
  #results .card { padding: 14px 10px; }
  #results h2 { font-size: 24px; }
  #results table { font-size: 13px; }
  #results th, #results td { padding: 5px 3px; }
  #results .dot { margin-right: 4px; width: 8px; height: 8px; }
  .tag { font-size: 15px; }
}
@media (any-pointer: coarse) and (max-width: 600px) {
  #bars, #dash { bottom: 190px; }
  #tbtns { width: min(54vw, 210px); right: 10px; }
  #stick { left: 12px; }
}
@media (max-height: 500px) {
  :root { --stick-size: 108px; --map-size: 88px; }
  #board li:nth-child(n+3):not(.me) { display: none; }
  #rank { font-size: 24px; }
  #btitle { font-size: clamp(28px, 7vw, 52px); }
  #bsub { margin-top: 5px; font-size: 16px; }
  #menu, #results { padding-top: calc(var(--safe-top) + 12px); padding-bottom: calc(var(--safe-bottom) + 12px); }
  #menu h1 { font-size: 44px; }
  #menu .tag { margin: 8px 0; font-size: 14px; }
  #paints { margin-bottom: 8px; }
  #name { padding: 8px 12px; font-size: 16px; }
  .play { padding: 7px; margin-top: 8px; font-size: 24px; }
  .controls, .touch-help { margin: 10px 0 0; font-size: 12px; }
  #results h2 { font-size: 24px; }
}
@media (any-pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  #bars { width: 176px; bottom: 154px; }
  #tbtns { width: 192px; grid-template-rows: 44px 44px 44px; }
}
@media (max-width: 600px) and (max-height: 500px) {
  #rankbox, #mapbox { top: 70px; }
  #board { display: none; }
  #mapbox { width: 72px; height: 72px; }
}
@media (any-pointer: coarse) and (max-width: 600px) and (max-height: 500px) and (orientation: landscape) {
  #bars { width: 150px; bottom: 154px; }
  #dash { bottom: 12px; left: 140px; right: 212px; width: auto; }
  #power { flex-direction: column; }
  #picon { display: none; }
}

/* Race outcomes: a brief celebration, then a stable, readable results table. */
#results .card { position: relative; z-index: 1; }
.result-fx { position: fixed; inset: 0; height: var(--viewport-height); overflow: hidden; pointer-events: none; }
.result-fx i { position: absolute; left: var(--x); top: -24px; width: 8px; height: 15px; border-radius: 2px; opacity: 0; }
#results.on .result-fx i { animation: result-confetti var(--duration) var(--delay) ease-in forwards; }
.result-badge { display: none; width: 88px; height: 88px; margin: 0 auto 8px; place-items: center; border-radius: 50%; }
.result-badge svg { width: 76px; height: 76px; display: none; }
.result-caption { margin: -4px 0 18px; text-align: center; font-size: 15px; color: #e0d5f4; }
.result-caption:empty { display: none; }
#results[data-outcome='win'] .result-badge { display: grid; background: radial-gradient(circle, #ffb62740, #ffb62708 70%); }
#results[data-outcome='win'] .win-badge { display: block; }
#results[data-outcome='win'] .card { border-color: var(--amber); box-shadow: 0 0 60px #ffb62722, 0 12px 40px #0008; }
#results[data-outcome='win'].on .result-badge { animation: trophy-arrive 0.85s cubic-bezier(.2,.8,.3,1.1) both; }
#results[data-outcome='win'].on .card { animation: result-rise 0.5s ease-out both; }
#results[data-outcome='loss'] .result-badge { display: grid; background: #ff3d7f12; }
#results[data-outcome='loss'] .loss-badge { display: block; }
#results[data-outcome='loss'] h2 { color: #ff90b3; }
#results[data-outcome='loss'].on .result-badge { animation: flag-settle 0.8s ease-out both; }
#results[data-outcome='loss'].on .card { animation: result-rise 0.6s ease-out both; }
#results.on .result-caption { animation: result-rise 0.45s 0.18s ease-out both; }
@keyframes result-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
@keyframes trophy-arrive {
  0% { opacity: 0; transform: translateY(24px) scale(0.35) rotate(-18deg); }
  65% { opacity: 1; transform: translateY(-5px) scale(1.12) rotate(5deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
@keyframes flag-settle {
  0% { opacity: 0; transform: translateY(-18px) rotate(12deg); }
  55% { opacity: 1; transform: translateY(3px) rotate(-7deg); }
  100% { opacity: 1; transform: translateY(0) rotate(-3deg); }
}
@keyframes result-confetti {
  0% { opacity: 0; transform: translate3d(0, -20px, 0) rotate(0); }
  8%, 80% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--drift), var(--viewport-height), 0) rotate(var(--spin)); }
}
@media (max-width: 600px), (max-height: 500px) {
  .result-badge { width: 62px; height: 62px; margin-bottom: 6px; }
  .result-badge svg { width: 56px; height: 56px; }
  .result-caption { font-size: 13px; margin-bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  #results.on, #results.on .card, #results.on .result-badge, #results.on .result-caption { animation: none !important; }
  .result-fx { display: none; }
}

/* Room selection and waiting lobby share the responsive, scrollable menu. */
[hidden] { display: none !important; }
body.in-room-lobby #menu { display: grid; }
body.in-room-lobby #hud, body.in-room-lobby #banner { display: none; }
body:not(.playing) #banner, body:not(.playing) .labels, body.in-room-lobby .labels { display: none; }
.race-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.race-actions .play { margin-top: 12px; }
.play.secondary { background: #2b2349; box-shadow: 0 6px 0 #161028; border: 1px solid #ffffff40; }
.action-caption { display: block; margin-top: 12px; font-size: 13px; color: #eee3ff; }
.room-input-label { display: block; margin: 16px 0 6px; font-size: 13px; text-align: left; color: #dcd5f0; }
.room-entry { display: flex; align-items: stretch; gap: 8px; }
.room-entry input { min-width: 0; flex: 1; font-variant-numeric: tabular-nums; letter-spacing: 4px; }
.room-icon { display: grid; place-items: center; flex-shrink: 0; width: 48px; min-height: 44px; border: 1px solid #ffffff66; border-radius: 12px; color: white; background: #342450; cursor: pointer; pointer-events: auto; touch-action: manipulation; }
.room-icon:active { background: var(--hot); }
.room-icon .button-icon { width: 24px; height: 24px; }
button:disabled { opacity: 0.5; cursor: wait; }
#room-lobby { margin-top: 22px; padding: 18px; border: 1px solid #ffffff26; border-radius: 18px; background: #17232ee8; }
#room-lobby h2 { margin: 0; font: 400 24px var(--display); color: var(--amber); }
#room-code { color: var(--teal); font-size: 24px; }
#room-invite { display: contents; }
#room-status, .room-note { font-size: 13px; line-height: 1.5; }
.room-note { color: #cec6de; }
#room-members { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 6px; }
#room-members li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 8px; background: #ffffff0d; text-align: left; }
#room-members li span { overflow-wrap: anywhere; min-width: 0; }
body.in-quick-lobby #room-status { color: var(--amber); font-size: 16px; }
#room-countdown { display:grid; grid-template-columns:1fr auto; align-items:center; gap:2px 16px; margin:14px 0; padding:12px 16px; border:1px solid var(--amber); border-radius:12px; background:#e9b97d0d; }
#room-countdown > span { color:var(--amber); font-size:12px; text-transform:uppercase; letter-spacing:.12em; }
#room-countdown-time { grid-column:2; grid-row:1 / span 2; color:var(--amber); font:700 clamp(28px, 7vw, 42px)/1 var(--font); font-variant-numeric:tabular-nums; }
#room-countdown > small { color:#b5c8d4; font-size:12px; }
body.in-quick-lobby .race-actions { grid-template-columns: 1fr; max-width: 220px; margin: 0 auto; }
#room-members li.empty-seat { background: transparent; border: 1px dashed #ffffff26; color: #b5adbf; }
#room-members li.empty-seat small { color: #b5adbf; }
#room-members small { align-self: center; flex-shrink: 0; color: var(--teal); font-size: 10px; letter-spacing: 1px; }
#room-message { margin: 12px 0 0; font-size: 14px; color: var(--amber); }
#room-message:empty { display: none; }
#room-tools { position: absolute; top: calc(var(--map-size) + var(--edge) + 8px); right: var(--edge); display: flex; align-items: center; gap: 5px; padding: 4px 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-edge); }
#room-tools .room-icon { width: 44px; }
#room-current { font-size: 12px; letter-spacing: 1px; color: var(--teal); user-select: text; -webkit-user-select: text; pointer-events: auto; }
body.in-private-room #feed { top: calc(var(--map-size) + var(--edge) + 72px); }
#room-toast { position: fixed; z-index: 25; top: 45%; left: 50%; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px; background: #241438f5; color: var(--amber); text-align: center; pointer-events: none; }
@media (max-width: 600px) {
  #room-tools { top: max(200px, calc(78px + var(--map-size))); }
  #room-lobby { padding: 12px; }
  #menu:has(#room-lobby:not([hidden])) h1 { font-size: 42px; }
}
@media (max-width: 600px) and (max-height: 500px) and (orientation: landscape) {
  #room-tools { top: 78px; right: 100px; }
}

/* Phone menus stay compact; keep every action reachable when the keyboard opens. */
@media (any-pointer: coarse) and (max-width: 700px) {
  #menu h1 { font-size: clamp(36px, 9vw, 56px); }
  #menu .tag { font-size: 14px; margin: 10px 0 12px; }
  #paints { display: grid; grid-template-columns: repeat(4, 44px); gap: 8px 12px; margin-bottom: 12px; }
  #menu .play { padding: 8px; }
  .race-actions { gap: 10px; }
  .action-caption { margin-top: 10px; }
  .room-input-label { margin-top: 12px; }
  .touch-help { margin: 12px 0 0; font-size: 12px; }
  #room-lobby { margin-top: 14px; }
}

/* Narrow portrait tablets need the same clear control area as phones. */
@media (any-pointer: coarse) and (max-width: 700px) and (orientation: portrait) {
  #bars { width: 44%; left: var(--edge); bottom: 182px; }
  #dash { width: 47%; left: auto; right: var(--edge); bottom: 182px; transform: none; gap: 4px; }
  #speedo { min-width: 56px; padding: 5px; }
  #power { min-width: 0; }
  #tbtns { width: min(54%, 224px); }
}

/* Larger touch targets and legible status panels for tablets in either orientation. */
@media (any-pointer: coarse) and (min-width: 701px) and (min-height: 501px) {
  :root { --stick-size: 160px; --map-size: clamp(128px, 14vw, 176px); }
  #rankbox { width: 180px; }
  #rank { font-size: 32px; }
  #board li { font-size: 14px; padding: 3px 5px; }
  #topbar { width: min(480px, calc(100% - 440px)); }
  #tbtns { width: 246px; grid-template-rows: 52px 64px 52px; gap: 6px; }
  .tb .button-icon { width: 32px; height: 32px; }
  #dash { width: min(32%, calc(100% - 540px), 340px); }
  #bars { width: 208px; }
  .meter .lbl { width: 66px; font-size: 12px; }
  .bar { height: 11px; }
  #pname { font-size: 14px; }
  #speed { font-size: 32px; }
}

@media (any-pointer: coarse) and (min-width: 601px) and (max-height: 500px) and (orientation: landscape) {
  #dash { width: min(31%, calc(100% - 432px)); }
  #power { min-width: 0; }
}
@media (max-width: 600px) and (max-height: 500px) and (orientation: portrait) {
  :root { --stick-size: 104px; }
  #room-tools { top: 146px; padding: 0 4px; }
}
@media (max-height: 380px) and (orientation: landscape) {
  #board li:not(.me) { display: none; }
}
@media (max-width: 600px) and (max-height: 360px) and (orientation: landscape) {
  #rankbox { top: 8px; width: 150px; }
  #topbar { left: 170px; right: 150px; }
  #mapbox { top: 8px; right: 62px; }
  #room-tools { top: 78px; left: 160px; right: auto; padding: 0 4px; }
}
@media (any-pointer: coarse) and (max-width: 600px) and (max-height: 360px) and (orientation: landscape) {
  #bars { top: 44px; bottom: auto; }
}

/* Half-screen steering leaves the road clear; only brake, power and boost need buttons. */
#room-activity { min-height: 1.3em; color: var(--teal); font-size: 13px; }
@media (any-pointer: coarse) {
  #tbtns { width: 204px; grid-template-columns: repeat(3, minmax(48px, 1fr)); grid-template-rows: 56px; gap: 6px; bottom: 12px; right: var(--edge); }
  #tbtns > .tb { grid-column: auto; grid-row: 1; }
  #bars { top: auto; bottom: 84px; width: min(40%, 208px); }
  #dash { left: auto; right: var(--edge); transform: none; bottom: 84px; width: min(47%, 340px); }
}
@media (any-pointer: coarse) and (max-height: 500px) and (orientation: landscape) {
  #tbtns { width: 180px; grid-template-rows: 48px; }
  #bars { top: auto; bottom: 12px; width: 150px; }
  #dash { bottom: 12px; left: 174px; right: 202px; width: auto; }
}

#steering-hints { display: none; position: absolute; left: 14px; right: 14px; top: 54%; justify-content: space-between; pointer-events: none; color: #ffffff70; font-size: 30px; text-shadow: 0 2px 5px #0008; }
@media (any-pointer: coarse) { #steering-hints { display: flex; } }

/* Hide menu/lobby scrollbars while preserving wheel and touch access. */
html, body, #menu, #menu *, #banner, #popups {
  scrollbar-width:none;
  -ms-overflow-style:none;
}
html::-webkit-scrollbar, body::-webkit-scrollbar,
#menu::-webkit-scrollbar, #menu *::-webkit-scrollbar,
#banner::-webkit-scrollbar, #popups::-webkit-scrollbar {
  display:none;width:0;height:0;
}
#menu {overflow-x:hidden;}
/* Results are the only screen with a visible scrollbar when content overflows. */
#results {overflow-y:auto;overflow-x:hidden;scrollbar-width:thin;scrollbar-color:var(--hot) #1c0e34;}
#results::-webkit-scrollbar {display:block;width:8px;}
#results::-webkit-scrollbar-track {background:#1c0e34;}
#results::-webkit-scrollbar-thumb {background:var(--hot);border-radius:8px;}
.room-map { color:#b6d6e5; font-size:13px; }
#race-map-name { display:block; height:20px; line-height:15px; color:#dce8ed; text-align:center; font-size:11px; padding:5px 3px 0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.member-build { display:block; color:#8ca0b0; font-size:11px; margin-top:3px; }

/* Keep information readable against every course, from dusk to snow. */
#route-status { display:flex; flex-wrap:wrap; justify-content:center; gap:2px 12px; max-width:100%; padding:5px 10px; border-radius:8px; background:#10202ef0; border:1px solid #ffffff30; font-size:12px; text-align:center; }
#route-zone { color:#fff; }
#route-next { color:#8aeeee; font-variant-numeric:tabular-nums; white-space:nowrap; }
#race-exit { top:calc(var(--edge) + 52px); color:#fff; }
.meter .bar { flex:1; min-width:12px; }
.meter .lbl { flex-shrink:0; }
.meter-value { width:23px; flex-shrink:0; font-size:11px; text-align:right; font-variant-numeric:tabular-nums; }
#rider-status { min-height:15px; max-width:260px; font-size:11px; line-height:15px; color:#c9d6df; }
#rider-status[data-kind=warning] { color:#ffd078; }
#rider-status[data-kind=good] { color:#8aeeee; }
#popups { top:130px; left:50%; transform:translateX(-50%); display:flex; flex-direction:column; align-items:center; gap:6px; width:min(410px,60vw); }
.pop, .pop.small { position:static; transform:none; white-space:normal; width:fit-content; max-width:100%; padding:7px 12px; border-radius:8px; border:1px solid #ffffff38; background:#10202ef0; font:700 15px/1.35 var(--font); text-align:center; text-shadow:none; animation:notice-in .16s ease-out; overflow-wrap:anywhere; }
.pop.danger { color:#ffb4be; border-color:#ff8da366; }
body:has(#banner.on) #popups { visibility:hidden; }
#banner.compact { top:30%; left:50%; right:auto; transform:translateX(-50%); width:max-content; max-width:calc(100% - 32px); padding:14px 20px; border:1px solid #ffffff40; border-radius:12px; background:#10202ef0; animation:none; }
#banner.compact #btitle { font-size:clamp(23px,4vw,36px); text-shadow:none; }
#banner.compact #bsub { font-size:14px; line-height:1.4; margin-top:6px; text-shadow:none; }
.garage-return { display:block; margin:14px auto 0; min-height:44px; padding:10px 18px; border:1px solid #ffffff70; border-radius:8px; color:#fff; background:#263b4c; font:700 14px var(--font); cursor:pointer; }
button:focus-visible { outline:3px solid #fff; outline-offset:3px; }
#results .card { max-width:100%; overflow-x:auto; }
#results td:nth-child(2) { max-width:180px; overflow-wrap:anywhere; }
@keyframes notice-in { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:none; } }
@media (max-width:900px), (max-height:500px) {
  #route-status { font-size:11px; padding:3px 7px; gap:2px 8px; }
  #popups { top:110px; }
  .pop, .pop.small { font-size:12px; padding:5px 9px; }
}
@media (max-width:600px) {
  #topbar { right:116px; }
  #race-exit { top:var(--edge); right:calc(var(--edge) + 52px); }
  #rankbox, #mapbox { top:104px; }
  #board li:nth-child(n+4):not(.me) { display:none; }
  #popups { top:45%; width:calc(100% - 32px); }
  #banner.compact { top:40%; }
  #bars { padding:7px; }
  .meter { gap:3px; }
  .meter .lbl { width:50px; font-size:9px; letter-spacing:0; }
  .meter-value { width:20px; font-size:10px; }
  #rider-status { font-size:10px; line-height:13px; min-height:26px; }
  #route-zone { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:100%; }
  #feed { top:calc(112px + var(--map-size)); max-width:48%; }
  #feed div { font-size:10px; }
}
@media (max-height:500px) and (min-width:601px) {
  #banner.compact { top:30%; padding:8px 14px; }
  #popups { top:110px; width:48%; }
  #rider-status { font-size:10px; }
}
#banner:not(.compact) #bsub { width:fit-content; max-width:calc(100% - 32px); margin:10px auto 0; padding:6px 12px; border-radius:8px; background:#10202ee8; font-size:clamp(14px,2vw,20px); }
#banner:not(.compact) #bsub:empty { display:none; }
@media (prefers-reduced-motion:reduce) {
  .pop, #banner.on, .bar.hp.low i, #power.fresh, #feed div, #hurt.on { animation:none; }
  .bar i, #pmarks .pm, #boostfx { transition:none; }
}

/* Takedown impact: white hit flash, radial speed burst, cinema bars and a title slam.
   Sits over the 3D view but under the HUD; runs alongside the slow-motion look-back camera. */
#takedown-fx { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; visibility: hidden; }
#takedown-fx.on { visibility: visible; }
#takedown-fx > * { position: absolute; }
.tk-flash { inset: 0; opacity: 0; mix-blend-mode: screen;
  background: radial-gradient(circle at 50% 55%, #fff 0%, rgba(255, 255, 255, 0.8) 28%, rgba(255, 61, 127, 0.35) 62%, transparent 85%); }
.tk-burst { inset: -25%; opacity: 0;
  background: repeating-conic-gradient(from 3deg at 50% 55%, transparent 0deg 6deg, rgba(255, 255, 255, 0.6) 6deg 7deg, transparent 7deg 13deg);
  -webkit-mask-image: radial-gradient(circle at 50% 55%, transparent 16%, #000 36%, transparent 70%);
  mask-image: radial-gradient(circle at 50% 55%, transparent 16%, #000 36%, transparent 70%); }
.tk-bar { left: 0; right: 0; height: 11vh; background: #000; transform: scaleY(0); }
.tk-bar.top { top: 0; transform-origin: top; }
.tk-bar.bottom { bottom: 0; transform-origin: bottom; }
.tk-title { left: 0; right: 0; top: 28%; text-align: center; opacity: 0; }
.tk-title b { display: block; padding: 0 16px; font: 400 clamp(38px, 7.2vw, 110px)/1 var(--display); font-style: italic; color: #fff; letter-spacing: 0.02em;
  text-shadow: 5px 0 0 var(--hot), -5px 0 0 var(--teal), 0 10px 34px rgba(0, 0, 0, 0.65); }
.tk-name { display: inline-block; margin-top: 10px; padding: 5px 16px; background: var(--hot); color: #fff;
  font: 700 clamp(12px, 1.5vw, 18px) var(--font); letter-spacing: 0.22em; text-transform: uppercase;
  clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%); }
.tk-name:empty { display: none; }
#takedown-fx.on .tk-flash { animation: tk-flash 0.5s ease-out forwards; }
#takedown-fx.on .tk-burst { animation: tk-burst 0.8s ease-out forwards; }
#takedown-fx.on .tk-bar { animation: tk-bars 1.6s ease-in-out forwards; }
#takedown-fx.on .tk-title { animation: tk-slam 1.6s cubic-bezier(.2, .9, .3, 1) forwards; }
@keyframes tk-flash { 0% { opacity: 0.95; } 100% { opacity: 0; } }
@keyframes tk-burst { 0% { opacity: 0.95; transform: scale(0.55) rotate(0deg); } 100% { opacity: 0; transform: scale(1.35) rotate(8deg); } }
@keyframes tk-bars { 0% { transform: scaleY(0); } 12%, 78% { transform: scaleY(1); } 100% { transform: scaleY(0); } }
@keyframes tk-slam {
  0% { opacity: 0; transform: scale(2.4) skewX(-8deg); }
  9% { opacity: 1; transform: scale(0.94) skewX(-8deg); }
  15% { transform: scale(1.03) skewX(-8deg); }
  21%, 78% { opacity: 1; transform: scale(1) skewX(-8deg); }
  100% { opacity: 0; transform: translateY(-14px) scale(1) skewX(-8deg); }
}
@media (max-width: 600px), (max-height: 500px) { .tk-bar { height: 7vh; } .tk-title { top: 24%; } }
@media (prefers-reduced-motion: reduce) {
  .tk-flash, .tk-burst, .tk-bar { display: none; }
  #takedown-fx.on .tk-title { animation: tk-fade 1.6s ease forwards; }
  @keyframes tk-fade { 0%, 100% { opacity: 0; } 15%, 80% { opacity: 1; } }
}

/* Takedown callout line above the title; streaks turn it amber and pulse. */
.tk-kicker { display: inline-block; margin-bottom: 6px; padding: 3px 12px; background: rgba(0, 0, 0, 0.55); color: var(--teal);
  font: 700 clamp(12px, 1.4vw, 17px) var(--font); letter-spacing: 0.3em; text-transform: uppercase; }
#takedown-fx.streak .tk-kicker { background: var(--amber); color: #2a1400; }
#takedown-fx.on.streak .tk-kicker { animation: tk-streak 0.5s 0.15s ease-out 2; }
@keyframes tk-streak { 50% { transform: scale(1.15); } }

/* Comic hit words that pop over the rival you strike. */
#hit-words { position: fixed; inset: 0; z-index: 6; pointer-events: none; overflow: hidden; }
body:not(.playing) #hit-words { display: none; }
.hit-word { position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  font: 400 clamp(22px, 2.8vw, 38px)/1 var(--display); font-style: italic; color: #fff; letter-spacing: 0.02em;
  -webkit-text-stroke: 2px #1a0d00; paint-order: stroke fill;
  text-shadow: 3px 3px 0 var(--hot-dark), 0 6px 18px rgba(0, 0, 0, 0.5);
  animation: hit-pop 0.85s cubic-bezier(.2, 1.4, .4, 1) forwards; }
.hit-word.punch { color: #ffe066; }
.hit-word.kick { color: #7ff3f5; text-shadow: 3px 3px 0 #0c5a63, 0 6px 18px rgba(0, 0, 0, 0.5); }
.hit-word.heavy { font-size: clamp(30px, 3.8vw, 52px); color: #fff; text-shadow: 4px 4px 0 var(--hot), 0 0 22px rgba(255, 61, 127, 0.7); }
.hit-word.calm { animation: hit-fade 0.85s ease forwards; }
@keyframes hit-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(var(--tilt)); }
  18% { opacity: 1; transform: translate(-50%, -50%) scale(1.25) rotate(var(--tilt)); }
  32% { transform: translate(-50%, -50%) scale(1) rotate(var(--tilt)); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--drift)), calc(-50% - 46px)) scale(0.95) rotate(var(--tilt)); }
}
@keyframes hit-fade { 0%, 100% { opacity: 0; transform: translate(-50%, -50%); } 20%, 70% { opacity: 1; transform: translate(-50%, -50%); } }

/* Game version: loading screen and the menu's bottom-left corner. */
.game-version { margin: 18px 0 0; color: #ffffff59; font: 700 11px var(--font); letter-spacing: 0.18em; }
.menu-version { position: absolute; left: calc(var(--safe-left) + 14px); bottom: calc(var(--safe-bottom) + 8px); z-index: 3;
  color: #ffffff52; font: 700 10px var(--font); letter-spacing: 0.18em; pointer-events: none; }
.game-version:empty, .menu-version:empty { display: none; }
@media (max-width: 760px) { .menu-version { display: none; } }


/* Console controllers: button prompts replace keyboard hints, and menu focus is easy to see from a sofa. */
#pad-keys, #menu .pad-controls { display: none; }
body.gamepad #pad-keys { display: block; }
body.gamepad #keys .kb-keys { display: none; }
body.gamepad #menu .pad-controls { display: flex; }
body.gamepad #menu .controls:not(.pad-controls), body.gamepad #menu .touch-help { display: none; }
body.pad-nav #menu button:focus, body.pad-nav #results button:focus { outline: 3px solid var(--teal); outline-offset: 3px; box-shadow: 0 0 0 6px rgba(45, 226, 230, 0.25); }

/* Race controls panel: action labels on the left of each pair, keys on the right. */
#keys { line-height: normal; text-align: left; padding: 9px 12px 8px; }
#keys .key-grid { display: grid; grid-template-columns: auto auto auto auto; align-items: center; gap: 5px 10px; }
#keys .key-grid > span:nth-child(4n + 3) { padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, 0.14); }
#keys .key-grid > span:nth-child(odd) { color: #c3b8d8; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
#keys .key-grid > span:nth-child(even) { white-space: nowrap; }
#keys .key-grid kbd + kbd { margin-left: 3px; }
#keys .keys-note { margin: 7px 0 0; padding-top: 6px; border-top: 1px solid rgba(255, 255, 255, 0.1); color: #c3b8d8; font-size: 10px; text-align: center; }
