* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --hud-font: 'Oswald', 'Arial Narrow', system-ui, sans-serif;
  --big-font: 'Anton', 'Impact', 'Oswald', sans-serif;
  --gold: #f5c542;
  --pink: #ff3fb4;
  --cyan: #3fd8ff;
  --panel: rgba(8, 9, 12, 0.55);
}
html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #0b0b0d; color: #f2f2f2;
  font-family: var(--hud-font);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
/* Readable on any background: dark outline like GTA's HUD text. */
.outline, #clock, .score-value, .score-ico, #stars, .speed-num, #banner, #bigbanner, #radio-name, #drift-meter, #combo, .trick, #wrecked {
  text-shadow: -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000, 0 3px 10px rgba(0, 0, 0, 0.6);
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

/* Radar + bars (bottom left) */
#radar {
  position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: 18px;
  width: 232px; padding: 4px; background: rgba(0, 0, 0, 0.55); border-radius: 6px;
}
#minimap { display: block; width: 224px; height: 137px; border-radius: 3px; }
.bars { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 3px; margin-top: 4px; }
.bar { height: 7px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; transition: width 0.15s linear; }
.bar.hp i { background: linear-gradient(#5fd35a, #2f9a35); }
.bar.air i { background: linear-gradient(#5fb6ff, #2a7fd6); }
.bar.combo i { background: linear-gradient(#ffd34a, #d9a01a); width: 0; }

/* Top-right block */
#topinfo { position: absolute; right: max(22px, env(safe-area-inset-right)); top: 16px; text-align: right; }
#clock { font-size: 22px; font-weight: 600; letter-spacing: 0.04em; }
#score { font-family: var(--big-font); font-size: 40px; line-height: 1.05; letter-spacing: 0.02em; pointer-events: auto; cursor: pointer; }
.score-ico { color: var(--gold); font-size: 30px; margin-right: 6px; vertical-align: 3px; }
#stars { font-size: 22px; letter-spacing: 2px; margin-top: 2px; }
#stars span { color: rgba(255, 255, 255, 0.16); transition: color 0.2s, transform 0.2s; display: inline-block; }
#stars span.on { color: #fff; }
#stars.flash span.on { animation: starflash 0.5s ease-in-out 2; }
@keyframes starflash { 50% { color: var(--gold); transform: scale(1.25); } }
.score-best { font-size: 12px; color: #d6d6d6; letter-spacing: 0.08em; text-shadow: 0 1px 4px #000; }
#toasts { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; margin-top: 10px; }
.toast {
  font-family: var(--big-font); font-size: 20px; letter-spacing: 0.02em; color: #9cff7a;
  text-shadow: -1.5px -1.5px 0 #000, 1.5px -1.5px 0 #000, -1.5px 1.5px 0 #000, 1.5px 1.5px 0 #000;
  animation: toastin 0.25s ease-out; transition: opacity 0.8s, transform 0.8s;
}
.toast small { font-family: var(--hud-font); font-size: 14px; color: #fff; margin-left: 6px; }
.toast.task { color: var(--gold); }
.toast.fade { opacity: 0; transform: translateY(-8px); }
@keyframes toastin { from { opacity: 0; transform: translateX(20px); } }

#drift-meter {
  position: absolute; left: 50%; top: 30%; transform: translateX(-50%);
  font-family: var(--big-font); font-size: 30px; color: #ffb02f; letter-spacing: 0.04em;
}

#telemetry {
  position: absolute; right: 22px; top: 50%; transform: translateY(-50%); text-align: right;
  font: 600 13px/1.6 var(--hud-font); color: #c8c8c8; letter-spacing: 0.08em;
  background: var(--panel); padding: 8px 12px; border-right: 3px solid var(--cyan);
}
#telemetry b { color: #fff; font-weight: 600; margin-left: 8px; }

/* Banners */
#banner {
  position: absolute; left: 50%; top: 20%; transform: translateX(-50%);
  text-align: center; font-family: var(--big-font); font-size: 40px; letter-spacing: 0.04em;
  text-transform: uppercase; opacity: 0; transition: opacity 0.25s; white-space: nowrap;
}
#banner.show { opacity: 1; animation: pop 0.35s ease-out; }
#banner small { display: block; font-family: var(--hud-font); font-size: 17px; letter-spacing: 0.06em; color: #f0f0f0; margin-top: 4px; text-transform: none; }
@keyframes pop { from { transform: translateX(-50%) scale(1.25); opacity: 0; } }
#bigbanner {
  position: absolute; left: 0; right: 0; top: 34%; text-align: center; opacity: 0; transition: opacity 0.4s;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.55) 20%, rgba(0, 0, 0, 0.55) 80%, transparent); padding: 14px 0;
}
#bigbanner.show { opacity: 1; }
#bigbanner.show .big-title { animation: slam 0.45s cubic-bezier(.2, 1.4, .5, 1); }
.big-title { font-family: var(--big-font); font-size: 62px; color: var(--gold); letter-spacing: 0.03em; line-height: 1; }
.big-sub { font-size: 20px; letter-spacing: 0.08em; margin-top: 6px; text-transform: uppercase; }
.big-bonus { font-family: var(--big-font); font-size: 26px; color: #9cff7a; margin-top: 4px; }
@keyframes slam { from { transform: scale(2.2); opacity: 0; } }
#radio-name {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); text-align: center;
  font-family: var(--big-font); font-size: 28px; letter-spacing: 0.06em; opacity: 0; transition: opacity 0.4s;
}
#radio-name small { display: block; font-family: var(--hud-font); font-size: 14px; color: #ddd; letter-spacing: 0.1em; }
#radio-name.show { opacity: 1; }

/* Speedometer (bottom right) */
#speedo { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: 12px; width: 190px; height: 190px; }
#speedo svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#arc-bg { fill: none; stroke: rgba(0, 0, 0, 0.5); stroke-width: 12; stroke-linecap: round; }
#arc-fg { fill: none; stroke: #fff; stroke-width: 8; stroke-linecap: round; filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.6)); }
#ticks line { stroke: rgba(255, 255, 255, 0.75); stroke-width: 2; }
#ticks text { fill: #ddd; font: 600 11px var(--hud-font); text-anchor: middle; dominant-baseline: middle; }
.speed-num { position: absolute; left: 0; right: 0; top: 64px; text-align: center; font-family: var(--big-font); font-size: 46px; font-variant-numeric: tabular-nums; }
.speed-unit { position: absolute; left: 0; right: 0; top: 118px; text-align: center; font-size: 12px; letter-spacing: 0.2em; color: #ddd; text-shadow: 0 1px 4px #000; }
.mode-badge {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); padding: 2px 10px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.16em; background: #fff; color: #111; border-radius: 3px;
}
.mode-badge.rocket { background: var(--gold); }
.mode-badge.road { background: #9ad0ff; }
#airtext { position: absolute; right: 2px; bottom: -2px; font-size: 11px; letter-spacing: 0.1em; color: #bfe3ff; text-shadow: 0 1px 3px #000; }
#fps { position: absolute; left: 2px; bottom: -2px; font-size: 10px; color: #888; }

/* Mode switch + camera (bottom right, above the speedometer) */
#quickbar {
  position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: 214px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; pointer-events: auto;
}
#quickbar .modes { display: flex; background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 255, 255, 0.25); }
#quickbar .mode {
  background: transparent; border: 0; padding: 7px 12px; font-size: 13px; font-weight: 600; letter-spacing: 0.12em; color: #bbb;
}
#quickbar .mode.active { background: #fff; color: #111; }
#quickbar .mode[data-mode="rocket"].active { background: var(--gold); }
.cam-btn {
  display: flex; align-items: center; gap: 6px; background: rgba(0, 0, 0, 0.6); border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 5px 12px; font-size: 13px; font-weight: 600; letter-spacing: 0.12em;
}
.cam-btn svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linejoin: round; }

.round-btn {
  position: absolute; left: max(18px, env(safe-area-inset-left)); top: 16px; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); border: 2px solid rgba(255, 255, 255, 0.7); display: flex; align-items: center; justify-content: center;
}
.round-btn svg, .tb svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  font-size: 13px; letter-spacing: 0.06em; color: #e8e8e8; background: var(--panel);
  padding: 6px 14px; white-space: nowrap; transition: opacity 1s;
}

/* ---------- Pause menu ---------- */
#menu {
  position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column;
  background: linear-gradient(180deg, rgba(8, 8, 12, 0.92), rgba(18, 8, 26, 0.92));
}
.menu-top { padding: 22px 36px 0; }
.menu-title { font-family: var(--big-font); font-size: 40px; letter-spacing: 0.04em; background: linear-gradient(90deg, #ff9a3c, #ff3fb4 55%, #8a5cff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.menu-tabs { display: flex; gap: 2px; margin-top: 10px; border-bottom: 2px solid rgba(255, 255, 255, 0.15); }
.menu-tabs button { background: transparent; border: 0; padding: 10px 22px; font-size: 16px; font-weight: 600; letter-spacing: 0.12em; color: #aaa; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.menu-tabs button.active { color: #fff; border-color: var(--pink); background: rgba(255, 255, 255, 0.06); }
.menu-body { flex: 1; overflow: auto; padding: 18px 36px; }
.menu-body section { display: none; }
.menu-body section.active { display: flex; gap: 22px; flex-wrap: wrap; }
#menu-map { width: min(900px, 100%); height: auto; aspect-ratio: 900 / 580; background: #0c3446; border: 2px solid rgba(255, 255, 255, 0.2); }
.warp-list { display: flex; flex-direction: column; gap: 8px; min-width: 220px; }
.warp-list button, .set-row button {
  background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.18); padding: 10px 14px; text-align: left;
  font-size: 15px; letter-spacing: 0.06em; display: flex; align-items: center; gap: 10px;
}
.warp-list button:hover, .set-row button:hover { background: rgba(255, 63, 180, 0.25); border-color: var(--pink); }
.warp-list .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
#menu-tasks { width: min(640px, 100%); }
.task { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 17px; letter-spacing: 0.03em; }
.task .box { width: 22px; height: 22px; border: 2px solid rgba(255, 255, 255, 0.45); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; }
.task.ok { color: #9cff7a; }
.task.ok .box { border-color: #9cff7a; background: rgba(156, 255, 122, 0.15); }
.task .bonus { margin-left: auto; color: var(--gold); font-family: var(--big-font); font-size: 18px; }
.task .prog { color: #aaa; font-size: 13px; }
.tasks-total { margin-top: 14px; color: #ccc; letter-spacing: 0.08em; }
#menu-settings { width: min(640px, 100%); }
.set-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.set-row .label { width: 160px; font-size: 15px; letter-spacing: 0.1em; color: #ccc; }
.set-row button { padding: 7px 14px; font-size: 13px; }
.set-row button.active { background: #fff; color: #111; border-color: #fff; }
table.controls { border-collapse: collapse; font-size: 15px; width: min(720px, 100%); }
table.controls td { padding: 8px 14px 8px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
table.controls td:not(:first-child) { color: var(--cyan); letter-spacing: 0.06em; }
.menu-foot { padding: 14px 36px 20px; color: #bbb; letter-spacing: 0.1em; }
.menu-foot span { background: #fff; color: #111; padding: 1px 8px; margin-right: 6px; font-weight: 600; }

/* ---------- Start screen ---------- */
#start {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 60%, rgba(60, 20, 70, 0.55), rgba(5, 5, 8, 0.94));
  padding: 16px;
}
.start-card { max-width: 520px; text-align: center; }
.logo { font-family: var(--big-font); line-height: 0.9; letter-spacing: 0.02em; }
.logo span { display: block; }
.logo span:first-child { font-size: 76px; background: linear-gradient(180deg, #ffe2a8, #ff9a3c 45%, #ff3fb4); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 #2a0a2e); }
.logo span:last-child { font-size: 62px; color: #3fd8ff; text-shadow: 0 0 18px rgba(63, 216, 255, 0.6), 0 4px 0 #0a1a2e; font-style: italic; }
.start-card .sub { margin: 18px 0 26px; color: #d0d0d0; line-height: 1.5; font-size: 16px; letter-spacing: 0.02em; }
#btn-play {
  padding: 14px 54px; border: 0; background: linear-gradient(90deg, #ff9a3c, #ff3fb4); color: #fff;
  font-family: var(--big-font); font-size: 24px; letter-spacing: 0.08em; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  clip-path: polygon(6% 0, 100% 0, 94% 100%, 0 100%);
}
#btn-play:disabled { opacity: 0.5; cursor: wait; }
.quality { margin-top: 18px; font-size: 14px; color: #aaa; display: flex; gap: 14px; justify-content: center; letter-spacing: 0.06em; }
.quality label { cursor: pointer; }
.disclaimer { margin-top: 28px; font-size: 12px; color: #777; }

/* Shown on the start screen inside X's (or another app's) built-in browser. */
#inapp-hint { margin: 14px auto 0; max-width: 340px; font-size: 13px; line-height: 1.4; color: #ffd27a; letter-spacing: 0.02em; }
#inapp-hint b { color: #fff; }
#inapp-hint .dots { font-family: system-ui, sans-serif; font-weight: 700; padding: 0 2px; }

/* ---------- Tricks, combo, crash ---------- */
#combo {
  position: absolute; left: 50%; top: 29%; transform: translateX(-50%); opacity: 0; transition: opacity 0.2s;
  font-family: var(--big-font); font-size: 34px; letter-spacing: 0.03em; white-space: nowrap;
}
#combo.on { opacity: 1; }
#combo-mult { color: var(--gold); margin-left: 10px; font-size: 28px; }
#trick-feed {
  position: absolute; left: 50%; top: calc(29% + 46px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.trick {
  font-family: var(--big-font); font-size: 22px; letter-spacing: 0.04em; white-space: nowrap;
  animation: trickin 0.25s cubic-bezier(.2, 1.4, .5, 1); transition: opacity 0.6s, transform 0.6s;
}
.trick b { color: #9cff7a; font-weight: 400; margin-left: 8px; }
.trick.banked { color: var(--gold); font-size: 26px; }
.trick.lost { color: #ff4a3c; }
.trick.out { opacity: 0; transform: translateY(-10px); }
@keyframes trickin { from { opacity: 0; transform: scale(1.6); } }
#wrecked {
  position: absolute; left: 0; right: 0; top: 40%; text-align: center; opacity: 0; transition: opacity 0.3s;
}
#wrecked.show { opacity: 1; }
#wrecked.show .w-title { animation: slam 0.45s cubic-bezier(.2, 1.4, .5, 1); }
.w-title { font-family: var(--big-font); font-size: 72px; color: #e8261c; letter-spacing: 0.04em; line-height: 1; }
.w-sub { font-size: 18px; letter-spacing: 0.12em; text-transform: uppercase; margin-top: 4px; }
body.wrecked #game { filter: grayscale(0.85) contrast(1.1); transition: filter 0.3s; }
#game { transition: filter 0.6s; }
/* Thruster indicators under the speedometer */
#speedo .thr { position: absolute; left: -62px; bottom: 22px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
#speedo .thr span {
  font: 600 10px var(--hud-font); letter-spacing: 0.14em; padding: 1px 6px; color: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.35);
}
#ind-lift.on { color: #fff; background: #2a7fd6; border-color: #5fb6ff; }
#ind-boost.on { color: #fff; background: #d65a2a; border-color: #ff9a6a; }
/* Start screen key list */
.start-card .keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin-top: 18px; font-size: 13px; color: #bbb; letter-spacing: 0.04em; }
.start-card .keys b { color: #fff; font-weight: 600; border: 1px solid rgba(255, 255, 255, 0.35); padding: 0 5px; margin-right: 4px; border-radius: 3px; }
body.touch .start-card .keys { display: none; }

/* Share on X */
.share-x {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 16px; padding: 8px 16px; border-radius: 999px;
  background: #000; border: 1px solid rgba(255, 255, 255, 0.35); color: #fff; font: 600 14px var(--hud-font); letter-spacing: 0.06em;
}
.share-x svg { width: 15px; height: 15px; fill: #fff; }
.share-x:hover { border-color: #fff; }
.menu-foot .share-x { margin: 0 0 0 18px; padding: 5px 12px; font-size: 12px; vertical-align: middle; }

/* ---------- Phone layout ----------
   Left thumb: a stick that appears wherever it touches. Right thumb: GAS with an arc of
   BRAKE / DRIFT / LIFT / BOOST around it. Radar top left, a small speedometer at the
   bottom centre, score top right with three small buttons next to it. Sizes follow the
   screen height (--u), so the same layout fits an iPhone SE and a big Android. */
body.touch {
  --u: clamp(44px, 13.5vmin, 62px); /* the short side of the screen, in landscape or portrait */
  touch-action: none; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
body.touch #hint, body.touch #quickbar, body.touch #telemetry, body.touch #speedo .thr,
body.touch #fps, body.touch #airtext { display: none !important; }

#touch { position: fixed; inset: 0; pointer-events: none; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 46%; height: 74%; pointer-events: auto; touch-action: none; }
#stick {
  position: absolute; left: calc(env(safe-area-inset-left) + 26px); bottom: 22px;
  width: calc(var(--u) * 2); height: calc(var(--u) * 2); border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.03) 45%, rgba(255, 255, 255, 0.1));
  border: 1.5px solid rgba(255, 255, 255, 0.35); opacity: 0.5; transition: opacity 0.2s;
}
#stick.active { opacity: 1; transition: none; }
#knob {
  position: absolute; left: 50%; top: 50%; border-radius: 50%;
  width: calc(var(--u) * 0.86); height: calc(var(--u) * 0.86); margin: calc(var(--u) * -0.43) 0 0 calc(var(--u) * -0.43);
  background: rgba(255, 255, 255, 0.88); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.tb {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 0;
  border-radius: 50%; background: rgba(10, 10, 14, 0.36); border: 1.5px solid rgba(255, 255, 255, 0.5); color: #fff;
  font: 600 calc(var(--u) * 0.15) / 1 var(--hud-font); letter-spacing: 0.08em; touch-action: none;
  -webkit-tap-highlight-color: transparent; transition: transform 0.06s, background 0.1s, box-shadow 0.15s;
}
.tb svg { width: calc(var(--u) * 0.34); height: calc(var(--u) * 0.34); fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tb.pressed { background: rgba(255, 255, 255, 0.32); transform: scale(0.93); }

/* Right-thumb cluster: GAS in the corner, the rest on an arc around it. */
#touch-buttons {
  position: absolute; right: calc(env(safe-area-inset-right) + 14px); bottom: 14px;
  width: calc(var(--u) * 2.75); height: calc(var(--u) * 2.75); pointer-events: auto;
}
.tb.act { position: absolute; width: calc(var(--u) * 0.88); height: calc(var(--u) * 0.88); }
.tb.gas {
  right: 0; bottom: 0; width: calc(var(--u) * 1.45); height: calc(var(--u) * 1.45); font-size: calc(var(--u) * 0.2);
  background: rgba(40, 190, 110, 0.3); border-color: rgba(150, 255, 190, 0.85);
}
.tb.gas svg { width: calc(var(--u) * 0.48); height: calc(var(--u) * 0.48); fill: #fff; }
.tb.brake { right: calc(var(--u) * 1.87); bottom: calc(var(--u) * 0.06); background: rgba(220, 50, 50, 0.24); border-color: rgba(255, 140, 140, 0.8); }
.tb.brake svg { fill: #fff; stroke: none; }
.tb.drift { right: calc(var(--u) * 1.7); bottom: calc(var(--u) * 1.04); }
.tb.lift { right: calc(var(--u) * 0.99); bottom: calc(var(--u) * 1.72); background: rgba(60, 150, 255, 0.28); border-color: rgba(140, 200, 255, 0.85); }
.tb.boost { right: calc(var(--u) * 0.01); bottom: calc(var(--u) * 1.86); background: rgba(255, 110, 50, 0.28); border-color: rgba(255, 180, 130, 0.85); }
.tb.lift.firing { box-shadow: 0 0 14px rgba(90, 170, 255, 0.9); background: rgba(60, 150, 255, 0.55); }
.tb.boost.firing { box-shadow: 0 0 14px rgba(255, 130, 60, 0.9); background: rgba(255, 110, 50, 0.55); }

/* Mode, camera, horn: small, next to the score. */
#touch-top {
  position: absolute; top: 10px; right: calc(env(safe-area-inset-right) + 138px);
  display: flex; gap: 8px; pointer-events: auto;
}
.tb.tiny { width: calc(var(--u) * 0.74); height: calc(var(--u) * 0.74); background: rgba(0, 0, 0, 0.4); border-color: rgba(255, 255, 255, 0.4); }
.tb.tiny svg { width: calc(var(--u) * 0.32); height: calc(var(--u) * 0.32); }
#tb-mode-label { font-size: calc(var(--u) * 0.14); letter-spacing: 0.04em; }

/* HUD on phones */
body.touch .round-btn { left: calc(env(safe-area-inset-left) + 12px); top: 10px; width: 36px; height: 36px; border-width: 1.5px; }
body.touch .round-btn svg { width: 18px; height: 18px; }
body.touch #radar { left: calc(env(safe-area-inset-left) + 56px); top: 8px; bottom: auto; width: 146px; padding: 3px; }
body.touch #minimap { width: 140px; height: 86px; }
body.touch .bars { margin-top: 3px; gap: 2px; }
body.touch .bar { height: 5px; }
body.touch #speedo { left: 50%; right: auto; bottom: 2px; transform: translateX(-50%); width: calc(var(--u) * 2.1); height: calc(var(--u) * 2.1); }
body.touch #ticks text { display: none; }
body.touch .speed-num { top: 27%; font-size: calc(var(--u) * 0.6); }
body.touch .speed-unit { top: 61%; font-size: 9px; letter-spacing: 0.16em; }
body.touch .mode-badge { bottom: 4%; font-size: 9px; padding: 1px 6px; }
body.touch #topinfo { top: 8px; right: calc(env(safe-area-inset-right) + 12px); }
body.touch #clock { font-size: 14px; }
body.touch #score { font-size: 26px; }
body.touch .score-ico { font-size: 18px; }
body.touch #stars { font-size: 13px; letter-spacing: 1px; }
body.touch .score-best { font-size: 10px; }
body.touch #toasts { margin-top: 4px; }
body.touch #toasts .toast:nth-child(n + 3) { display: none; }
body.touch .toast { font-size: 15px; }
body.touch .toast small { font-size: 11px; }
body.touch #radio-name { top: 6px; font-size: 18px; }
body.touch #banner { font-size: 24px; top: 19%; }
body.touch #banner small { font-size: 13px; }
body.touch #drift-meter { font-size: 22px; top: 27%; }
body.touch .big-title { font-size: 38px; }
body.touch .big-sub { font-size: 14px; }
body.touch #combo { top: 34%; font-size: 24px; }
body.touch #combo-mult { font-size: 20px; }
body.touch #trick-feed { top: calc(34% + 30px); }
body.touch .trick { font-size: 16px; }
body.touch .trick.banked { font-size: 19px; }
body.touch .w-title { font-size: 46px; }
body.touch .w-sub { font-size: 13px; }

/* Pause menu: a Resume button on phones, the Esc hint on desktops. */
.menu-foot .resume { display: none; }
.menu-foot em { font-style: normal; }
body.touch .menu-foot .resume {
  display: inline-block; padding: 8px 18px; border: 0; background: linear-gradient(90deg, #ff9a3c, #ff3fb4);
  font: 400 16px var(--big-font); letter-spacing: 0.08em; color: #fff;
}
body.touch .menu-foot .esc, body.touch .menu-foot .esc-text { display: none; }

/* Short screens (phones in landscape): compact start screen and menu. */
@media (max-height: 500px) {
  .logo span:first-child { font-size: 46px; }
  .logo span:last-child { font-size: 36px; }
  .start-card .sub { margin: 8px 0 12px; font-size: 13px; line-height: 1.35; }
  #btn-play { padding: 9px 44px; font-size: 20px; }
  .quality { margin-top: 10px; font-size: 12px; }
  .share-x { margin-top: 10px; padding: 6px 14px; font-size: 12px; }
  .disclaimer { margin-top: 10px; font-size: 10px; }
  .menu-top { padding: 8px 16px 0; display: flex; align-items: flex-end; gap: 18px; }
  .menu-title { font-size: 22px; padding-bottom: 6px; }
  .menu-tabs { margin-top: 0; flex: 1; }
  .menu-tabs button { padding: 7px 12px; font-size: 12px; }
  .menu-body { padding: 10px 16px; }
  .menu-body section.active { flex-wrap: nowrap; gap: 14px; }
  #menu-map { width: auto; height: calc(100vh - 112px); max-width: 64vw; }
  .warp-list { min-width: 0; flex: 1; gap: 5px; }
  .warp-list button { padding: 6px 10px; font-size: 12px; }
  .task { padding: 6px 0; font-size: 13px; }
  .task .bonus { font-size: 14px; }
  .set-row { padding: 5px 0; }
  .set-row .label { width: 120px; font-size: 12px; }
  .set-row button { padding: 5px 10px; font-size: 12px; }
  table.controls { font-size: 12px; }
  table.controls td { padding: 5px 10px 5px 0; }
  .menu-foot { padding: 6px 16px 10px; font-size: 12px; }
}

/* Portrait phones (X's built-in browser does not rotate): controls along the bottom,
   HUD along the top, the speedometer above the buttons on the right. */
@media (orientation: portrait) {
  body.touch #stick-zone { height: 58%; width: 50%; }
  body.touch #stick { bottom: 26px; }
  body.touch #touch-buttons { bottom: 22px; }
  body.touch #speedo {
    left: auto; right: calc(env(safe-area-inset-right) + 10px); transform: none;
    bottom: calc(22px + var(--u) * 2.9); width: calc(var(--u) * 1.7); height: calc(var(--u) * 1.7);
  }
  body.touch #touch-top { top: 100px; right: calc(env(safe-area-inset-right) + 12px); }
  body.touch #toasts { margin-top: 52px; }
  body.touch #radio-name { top: 122px; }
  body.touch #banner { top: 24%; font-size: 22px; white-space: normal; width: 90%; }
  body.touch #combo { top: 36%; }
  body.touch #trick-feed { top: calc(36% + 30px); }
  body.touch #drift-meter { top: 31%; }
  body.touch .big-title { font-size: 32px; }
  .menu-top { padding: 14px 16px 0; }
  .menu-title { font-size: 26px; }
  .menu-tabs button { padding: 8px 10px; font-size: 12px; }
  .menu-body { padding: 12px 16px; }
  .menu-body section.active { flex-direction: column; }
  .warp-list { min-width: 0; }
  .set-row { flex-wrap: wrap; }
  .set-row .label { width: 100%; }
  .menu-foot { padding: 10px 16px 18px; }
}

/* Slow-motion moments: cinema bars slide in, the edges darken. */
#cine { position: fixed; inset: 0; pointer-events: none; }
#cine::before, #cine::after {
  content: ''; position: absolute; left: 0; right: 0; height: 0; background: #000; transition: height 0.35s ease;
}
#cine::before { top: 0; }
#cine::after { bottom: 0; }
body.cine #cine::before, body.cine #cine::after { height: 9vh; }
#cine { background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0)); transition: background 0.4s; }
body.cine #cine { background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.45)); }

/* Nitro speed lines (drawn by src/speedfx.js) */
#speedfx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Leaderboard: rank under the score, nickname on the start screen, RANKING tab */
#rank { margin-top: 3px; font-size: 13px; letter-spacing: 0.06em; color: var(--gold); text-shadow: 0 1px 4px #000; }
body.touch #rank { font-size: 11px; }
.nick-start {
  display: block; margin: 0 auto 14px; width: min(320px, 90%); padding: 9px 12px; border-radius: 6px; text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(0, 0, 0, 0.45); color: #fff; font: 500 14px var(--hud-font); letter-spacing: 0.04em; outline: none;
}
.nick-start:focus { border-color: #3fd8ff; }
#menu-rank { width: min(640px, 100%); }
.board-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.board-head .you { font-size: 15px; letter-spacing: 0.08em; color: #ccc; }
.board-head .you b { font-family: var(--big-font); font-size: 30px; color: var(--gold); font-weight: 400; margin: 0 6px; }
.board-head .nick { margin-left: auto; display: flex; gap: 6px; }
.board-head .nick input { width: 170px; padding: 7px 10px; border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.06); color: #fff; font: 500 14px var(--hud-font); outline: none; }
.board-head .nick button { padding: 7px 14px; border: 0; background: #fff; color: #111; font-weight: 600; letter-spacing: 0.1em; }
ol.board { list-style: none; margin: 0; padding: 0; }
ol.board li { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; padding: 7px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 16px; }
ol.board .r { color: #999; font-variant-numeric: tabular-nums; }
ol.board .s { font-family: var(--big-font); font-size: 19px; letter-spacing: 0.02em; }
ol.board li.p1 .s, ol.board li.p1 .r { color: var(--gold); }
ol.board li.p2 .s, ol.board li.p2 .r { color: #d6dbe4; }
ol.board li.p3 .s, ol.board li.p3 .r { color: #e3a46b; }
ol.board li.me { background: rgba(255, 63, 180, 0.16); outline: 1px solid rgba(255, 63, 180, 0.6); }
ol.board li.me em { font-style: normal; font-size: 11px; letter-spacing: 0.14em; color: #ff8fd4; margin-left: 6px; }
ol.board li.gap { display: block; text-align: center; color: #777; border: 0; padding: 2px; }
.board-empty { color: #999; padding: 10px 0; }
@media (max-height: 500px) {
  .nick-start { margin-bottom: 8px; padding: 6px 10px; font-size: 12px; }
  .board-head .you b { font-size: 22px; }
  ol.board li { padding: 4px; font-size: 13px; }
  ol.board .s { font-size: 15px; }
}

/* Leaderboard moments: top-10 celebration and the overtaken warning */
#rankfx { position: fixed; inset: 0; pointer-events: none; z-index: 4; opacity: 0; transition: opacity 0.5s; --rf: #3fd8ff; --rf2: #ff3fb4; }
#rankfx.show { opacity: 1; transition: opacity 0.15s; }
#rankfx.gold { --rf: #f5c542; --rf2: #fff2b8; }
#rankfx.silver { --rf: #dfe6f0; --rf2: #9fb2c9; }
#rankfx.bronze { --rf: #e3a46b; --rf2: #ffd2a8; }
#rankfx.warn { --rf: #ff5a4a; --rf2: #ffb0a8; }
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; }
#rankfx.show { box-shadow: inset 0 0 90px 10px color-mix(in srgb, var(--rf) 55%, transparent); animation: rfedge 1.2s ease-in-out 2; }
@keyframes rfedge { 50% { box-shadow: inset 0 0 140px 24px color-mix(in srgb, var(--rf) 75%, transparent); } }
.rf-flash { position: absolute; inset: 0; opacity: 0; background: radial-gradient(circle at 50% 38%, color-mix(in srgb, var(--rf) 70%, transparent), transparent 60%); }
#rankfx.show .rf-flash { animation: rfflash 0.9s ease-out; }
@keyframes rfflash { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
.rf-card {
  position: absolute; left: 50%; top: 20%; transform: translateX(-50%); text-align: center; white-space: nowrap; padding: 12px 90px 16px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.35) 55%, transparent 72%);
}
.rf-card.go { animation: rfslam 0.6s cubic-bezier(.2, 1.5, .45, 1); }
@keyframes rfslam { from { transform: translateX(-50%) scale(2.6) rotate(-8deg); opacity: 0; } to { transform: translateX(-50%) scale(1) rotate(0); opacity: 1; } }
.rf-kicker { font: 600 18px var(--hud-font); letter-spacing: 0.3em; color: #fff; text-shadow: 0 0 12px var(--rf), 0 2px 4px #000; }
.rf-rank {
  font-family: var(--big-font); font-size: 120px; line-height: 1; letter-spacing: 0.02em; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, var(--rf2), var(--rf) 60%); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--rf) 70%, transparent)) drop-shadow(0 5px 0 #000);
}
.rf-sub { font: 500 18px var(--hud-font); letter-spacing: 0.06em; color: #fff; text-shadow: 0 2px 6px #000; }
body.touch .rf-rank { font-size: 76px; }
body.touch .rf-kicker { font-size: 13px; }
body.touch .rf-sub { font-size: 13px; }
body.touch .rf-card { top: 16%; }
#rank.bump { animation: rankbump 0.9s ease-out; }
@keyframes rankbump { 30% { transform: scale(1.35); color: #fff; text-shadow: 0 0 10px var(--gold); } }
