/* same self-hosted variable font as the blog theme (served by the blog at /fonts/) */
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin-ext.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #291d38;
  --bg-deep: #140c22;
  --card: rgba(30, 21, 44, .93);
  --line: hsl(0 0% 50% / .16);
  --brand: #ff4f8b;
  --brand-light: #f7b5c8;
  --cyan: #46c8d8;
  --purple: #8a8af0;
  --orange: #f6894b;
  --yellow: #f7c948;
  --light: #d9ecec;
  --font: "JetBrains Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-deep);
  color: var(--light);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  height: var(--app-h, 100svh);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* no panning or zooming over the road and the HUD; the text screens must still scroll, and Safari
   applies touch-action from every ancestor, so it is not set on #game */
#cv, #glcv, #hud { touch-action: none; }

#cv, #glcv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
#glcv { pointer-events: none; }
/* the WebGL pass draws its own scanlines and vignette */
body.glfx .fx { display: none; }

/* scanlines + vignette */
.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, .13) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(10, 4, 20, .6) 100%);
}

[hidden] { display: none !important; }

/* ------------------------------------------------------------------ HUD */
/* OutRun layout: TIME / SCORE / LAP on top, speed + tacho bottom-left, STAGE bottom-right */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(10, 4, 20, .6);
}

.hud-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.hud-row.bottom { align-items: flex-end; }

.tag-lbl {
  display: inline-block;
  font-size: clamp(11px, 1.5vw, 15px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #1a0f2a;
  background: var(--yellow);
  border-radius: 4px;
  padding: 1px 8px;
  text-shadow: none;
  box-shadow: 0 0 10px rgba(247, 201, 72, .5);
}
.tag-lbl.pink { background: var(--brand); box-shadow: 0 0 10px rgba(255, 79, 139, .5); }
.tag-lbl.cyan { background: var(--cyan); box-shadow: 0 0 10px rgba(70, 200, 216, .5); }
.tag-lbl.yellow { background: var(--yellow); }

.hud-time { display: flex; align-items: center; gap: 10px; }
.hud-left { display: grid; justify-items: start; gap: 2px; }
.time-val {
  font-size: clamp(34px, 6vw, 64px);
  font-weight: 800;
  line-height: 1;
  color: var(--yellow);
  text-shadow: 0 0 8px rgba(247, 201, 72, .8), 0 3px 0 rgba(10, 4, 20, .6);
  min-width: 2ch;
}
.time-val.low { color: var(--brand); text-shadow: 0 0 10px var(--brand); animation: blink .5s steps(2) infinite; }

.hud-score { text-align: center; display: grid; justify-items: center; gap: 2px; }
.score-val { font-size: clamp(20px, 3.4vw, 34px); font-weight: 800; color: #ffd6e6; text-shadow: 0 0 6px rgba(255, 79, 139, .8); }
.sub { font-size: 11px; color: var(--brand-light); opacity: .8; }

.hud-lap { display: grid; justify-items: end; gap: 4px; }
.ghost-delta { font-size: 13px; font-weight: 800; color: #ffb3c8; text-shadow: 0 0 6px rgba(255, 79, 139, .7); }
.ghost-delta.ahead { color: #c9f6fb; text-shadow: 0 0 6px rgba(70, 200, 216, .8); }
.lap-val { font-size: clamp(16px, 2.4vw, 24px); font-weight: 800; color: #c9f6fb; text-shadow: 0 0 6px rgba(70, 200, 216, .8); }

.fork {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  display: flex;
  gap: clamp(16px, 6vw, 80px);
  font-weight: 800;
  font-size: clamp(14px, 2.4vw, 22px);
  white-space: nowrap;
  animation: blink 1s steps(2) infinite;
}
.fork .l { color: #ffd6e6; text-shadow: 0 0 10px var(--brand); }
.fork .r { color: #c9f6fb; text-shadow: 0 0 10px var(--cyan); }

.hud-speed { display: grid; gap: 6px; }
.speed-val { font-size: clamp(28px, 4.6vw, 48px); font-weight: 800; color: var(--brand); text-shadow: 0 0 8px rgba(255, 79, 139, .8); }
.unit { margin-left: 6px; font-size: 14px; font-weight: 700; color: var(--brand-light); }
.tacho { display: flex; gap: 3px; }
.tacho b { width: clamp(6px, 1vw, 11px); height: 12px; border-radius: 2px; background: rgba(255, 255, 255, .12); transform: skewX(-20deg); }
.tacho b.on { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.tacho b.on:nth-child(n+9) { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.tacho b.on:nth-child(n+13) { background: var(--brand); box-shadow: 0 0 6px var(--brand); }

.charges { display: flex; align-items: center; gap: 8px; }
.lbl { font-size: 11px; letter-spacing: .1em; color: var(--purple); }
.lbl::before { content: "// "; opacity: .6; }
.pips { display: flex; gap: 5px; }
.pips b { width: 18px; height: 10px; border: 1px solid var(--yellow); border-radius: 2px; transform: skewX(-20deg); opacity: .55; }
.pips b.on { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); opacity: 1; }
/* the two extra charges feed the time jump: cyan, and glowing when both are full */
.pips b.x { border-color: var(--cyan); margin-left: 2px; }
.pips b.x.on { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.pips.ready b.x { animation: blink .5s steps(2) infinite; }
.power { width: 90px; height: 8px; border: 1px solid var(--cyan); border-radius: 3px; padding: 1px; }
.power i { display: block; height: 100%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.hud-stage { display: grid; justify-items: end; gap: 4px; }
.stage-line { display: flex; align-items: center; gap: 8px; }
.stage-val { font-size: clamp(24px, 3.6vw, 36px); font-weight: 800; color: var(--yellow); text-shadow: 0 0 8px rgba(247, 201, 72, .8); }
.flag {
  width: 26px;
  height: 18px;
  border: 1px solid var(--light);
  background: conic-gradient(var(--light) 25%, #1a0f2a 0 50%, var(--light) 0 75%, #1a0f2a 0) 0 0 / 9px 9px;
}
.stage-name { font-size: 12px; color: var(--brand-light); }

.buttons { display: flex; gap: 8px; pointer-events: auto; margin-top: 6px; }

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--brand-light);
  background: rgba(20, 12, 34, .7);
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: .5rem .75rem;
  cursor: pointer;
  transition: color .2s, border-color .2s, box-shadow .2s;
  touch-action: none;
}
.btn:hover { color: var(--brand); border-color: var(--brand); box-shadow: 0 0 .5rem rgba(255, 79, 139, .5); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn.nitro { color: var(--yellow); border-color: rgba(247, 201, 72, .5); padding: .8rem 1rem; }
.btn.jump { color: var(--cyan); border-color: rgba(70, 200, 216, .5); padding: .8rem 1rem; }
.btn.jump:disabled { opacity: .3; }
.btn.jump:not(:disabled) { box-shadow: 0 0 .8rem rgba(70, 200, 216, .7); animation: blink .5s steps(2) infinite; }
.btn.brake { color: var(--brand); border-color: rgba(255, 79, 139, .5); padding: .8rem 1rem; }

.btn.audio {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
}
body.playing .btn.audio { top: max(64px, calc(env(safe-area-inset-top) + 56px)); left: auto; right: max(16px, env(safe-area-inset-right)); transform: none; }

/* ------------------------------------------------------------ toasts */
/* high up in the sky, never over the road ahead */
#toasts {
  position: absolute;
  left: 0;
  right: 0;
  top: max(13%, 62px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.toast {
  font-weight: 800;
  font-size: clamp(13px, 2vw, 20px);
  color: var(--yellow);
  text-shadow: 0 0 4px var(--yellow), 0 0 14px rgba(247, 201, 72, .6);
  animation: rise 1.2s ease-out forwards;
  white-space: nowrap;
}
.toast.pink { color: #ffd6e6; text-shadow: 0 0 4px var(--brand), 0 0 14px var(--brand); }
.toast.cyan { color: #c9f6fb; text-shadow: 0 0 4px var(--cyan), 0 0 14px var(--cyan); }
.toast.bad { color: #ffd6e6; text-shadow: 0 0 4px #d6186a, 0 0 18px #d6186a; }

#countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-weight: 800;
  font-size: clamp(64px, 16vw, 160px);
  color: #ffd6e6;
  text-shadow: 0 0 4px var(--brand), 0 0 18px var(--brand), 0 0 50px rgba(255, 79, 139, .6);
}
#countdown span { animation: pop .9s ease-out forwards; }

/* ----------------------------------------------------------- screens */
.screen {
  position: absolute;
  inset: 0;
  /* centred with auto margins: a panel taller than the screen (a phone held sideways) scrolls from its top */
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20, 12, 34, .25), rgba(20, 12, 34, .7));
  overflow-y: auto;
}
.screen > * { margin-block: auto; flex: none; }
.screen { touch-action: pan-y; -webkit-overflow-scrolling: touch; }

/* a phone held sideways is short: the start buttons come right under the logo so they are in view */
@media (max-height: 500px) {
  #scrTitle .term-body { display: flex; flex-direction: column; }
  #scrTitle .logo, #scrTitle .tag, #scrTitle .actions, #scrTitle .opts, #scrTitle .tilt-msg { order: -1; }
  #scrTitle .opts { margin: -6px 0 14px; }
  #scrTitle .logo { font-size: 40px; }
  #scrTitle .tag { margin-bottom: 12px; font-size: 13px; }
  #scrTitle .term-body { padding-top: 14px; }
  #scrTitle .actions { margin: 0 0 16px; }
  #scrTitle .tilt-msg { margin: 0 0 14px; }
}

.term {
  width: min(560px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: .5rem;
  box-shadow: 0 0 .5rem rgba(255, 79, 139, .25), 0 24px 60px rgba(0, 0, 0, .5);
  overflow: hidden;
  animation: boot .35s ease-out;
}
.term.small { width: min(380px, 100%); }

.term-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--brand-light);
}
.term-bar i { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); flex: none; }
.term-bar i:nth-child(2) { background: var(--yellow); }
.term-bar i:nth-child(3) { background: var(--cyan); }
.term-bar span { flex: 1; text-align: center; margin-right: 46px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.term-body { padding: 20px 22px 22px; }

.logo {
  margin: 0 0 8px;
  font-size: clamp(38px, 9vw, 68px);
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.05;
  color: #ffd6e6;
  text-shadow: 0 0 2px var(--brand), 0 0 6px var(--brand), 0 0 14px var(--brand), 0 0 30px rgba(255, 79, 139, .6);
  animation: flicker 7s infinite;
}
.logo .eyes { color: #c9f6fb; text-shadow: 0 0 2px var(--cyan), 0 0 8px var(--cyan), 0 0 18px var(--cyan); }

.tag { margin: 0 0 18px; color: var(--cyan); font-size: 14px; line-height: 1.5; }
.tag span { color: var(--brand); }

.help {
  list-style: none;
  padding: 0;
  margin: 0 0 14px;
  display: grid;
  gap: 7px;
  font-size: 13px;
  line-height: 1.5;
}
.help li::before { content: "❯ "; color: var(--brand); }
.help.legend { color: var(--brand-light); opacity: .9; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }
.dot.fuel { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.dot.nitro { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.dot.tape { background: var(--brand); box-shadow: 0 0 6px var(--brand); }

kbd {
  display: inline-block;
  min-width: 22px;
  margin-right: 3px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #2a1f3b;
  color: var(--brand-light);
  font: inherit;
  font-size: 12px;
  text-align: center;
}

.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }

.cta {
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  color: #1a0f2a;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: .5rem;
  padding: 11px 20px;
  cursor: pointer;
  box-shadow: 0 0 .5rem var(--brand), 0 0 1.5rem rgba(255, 79, 139, .35);
  transition: transform .15s, box-shadow .15s, color .2s, border-color .2s;
}
.cta:hover { transform: translateY(-1px); box-shadow: 0 0 .8rem var(--brand), 0 0 2rem rgba(255, 79, 139, .6); }
.cta:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.cta.ghost { background: transparent; color: var(--cyan); border-color: var(--line); box-shadow: none; }
.cta.ghost:hover { border-color: var(--cyan); box-shadow: 0 0 .5rem rgba(70, 200, 216, .5); }

.tilt-msg { margin: 14px 0 0; padding: 10px 12px; border: 1px solid var(--brand); border-radius: .5rem; font-size: 13px; color: #ffd6e6; }

/* a phone held upright: the game waits for it to be turned */
.rotate {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: rgba(10, 4, 20, .94);
}
.rot-ico { margin: 0; font-size: 64px; color: var(--cyan); text-shadow: 0 0 14px var(--cyan); animation: blink 1.2s steps(2) infinite; }
.rot-t { margin: 10px 0 6px; font-size: 20px; font-weight: 800; color: #ffd6e6; text-shadow: 0 0 10px var(--brand); }
.rot-s { margin: 0; font-size: 13px; line-height: 1.6; color: var(--brand-light); }
.best { margin: 16px 0 0; font-size: 12px; color: var(--purple); }
.best b { color: var(--brand-light); }

.title { margin: 0 0 6px; font-size: 22px; color: var(--cyan); }
.reason { margin: 0 0 14px; color: var(--brand-light); font-size: 14px; }

.score-big {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 12px;
  font-weight: 800;
  font-size: clamp(40px, 9vw, 60px);
  color: #ffd6e6;
  text-shadow: 0 0 4px var(--brand), 0 0 16px var(--brand);
  font-variant-numeric: tabular-nums;
}
.score-big em {
  font-style: normal;
  font-size: 14px;
  color: #1a0f2a;
  background: var(--yellow);
  border-radius: 4px;
  padding: 2px 8px;
  text-shadow: none;
  box-shadow: 0 0 12px var(--yellow);
  animation: blink .6s steps(2) infinite;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 18px;
  margin: 16px 0 0;
  font-size: 13px;
}
.stats div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--line); padding-bottom: 4px; }
.stats dt { color: var(--purple); }
.stats dd { margin: 0; color: var(--light); font-weight: 700; }

/* pyramid of the route taken, on the end screen */
.pyr { display: grid; gap: 6px; justify-items: center; margin: 4px 0 8px; }
.pyr div { display: flex; gap: 14px; }
.pyr .node { width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--c); opacity: .45; transform: rotate(45deg); }
.pyr .node.on { background: var(--c); box-shadow: 0 0 8px var(--c); opacity: 1; }
.pyr .node.here { animation: blink .6s steps(2) infinite; }
.route { margin: 0 0 6px; font-size: 12px; color: var(--purple); text-align: center; }

/* -------------------------------------------------------- leaderboard */
.board-block { margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.title.sm { font-size: 15px; margin-bottom: 10px; }
.title span { color: var(--brand-light); }

.submit { display: flex; align-items: center; gap: 8px; }
.submit label { color: var(--brand); font-weight: 800; }
.submit input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 15px;
  color: var(--light);
  background: #1a1228;
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: 9px 12px;
  caret-color: var(--brand);
}
.submit input::placeholder { color: var(--purple); opacity: .7; }
.submit input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 .5rem rgba(255, 79, 139, .45); }
.cta.sm { font-size: 14px; padding: 9px 14px; }
.cta:disabled { opacity: .5; cursor: wait; transform: none; }

.msg { min-height: 1.2em; margin: 8px 0; font-size: 13px; color: var(--cyan); }
.msg:empty { display: none; }
.msg.bad { color: var(--brand); }

.board {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  gap: 2px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.board li { display: flex; gap: 12px; padding: 5px 8px; border-radius: 4px; }
.board li:nth-child(odd) { background: rgba(255, 255, 255, .03); }
.board li.gap { justify-content: center; color: var(--purple); background: none; padding: 0; }
.board li.empty { color: var(--purple); }
.board .pos { color: var(--purple); width: 3ch; }
.board .tag { color: var(--yellow); font-size: 11px; }
.board .nick { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { color: var(--brand-light); font-weight: 700; }
.board li:nth-child(1):not(.empty) .pos { color: var(--yellow); text-shadow: 0 0 6px var(--yellow); }
.board li.me { background: rgba(255, 79, 139, .16); box-shadow: inset 2px 0 0 var(--brand); }
.board li.me .nick { color: #ffd6e6; font-weight: 700; }
#bList { max-height: min(52vh, 560px); overflow-y: auto; }
.board-tabs { display: flex; gap: 8px; margin: 0 0 10px; }
.board-tabs .btn.on { color: var(--brand); border-color: var(--brand); box-shadow: 0 0 .5rem rgba(255, 79, 139, .4); }

/* device-specific hints */
.touch-only { display: none; }
@media (pointer: coarse) {
  .touch-only { display: grid; }
  .btn.touch-only { display: inline-block; }
  .kb-only { display: none; }
}

/* very short screens (a phone held sideways, under the browser bars): a slimmer HUD */
@media (max-height: 420px) {
  .tacho, .hud-score .sub { display: none; }
  .time-val { font-size: 30px; }
  .score-val { font-size: 20px; }
  .lap-val { font-size: 15px; }
  .speed-val { font-size: 26px; }
  .stage-val { font-size: 22px; }
  .hud-speed { gap: 4px; }
}

/* a phone held sideways: compact touch buttons so they stay clear of the car */
/* touch: the phone is held like a wheel, so the thumbs rest on its sides a little above the middle.
   Brake under the left thumb, transformation and time jump under the right one, big and round;
   only the pause stays in the corner */
@media (pointer: coarse) {
  .btn.brake, .btn.nitro, .btn.jump {
    --bs: min(76px, 23vh);
    position: absolute;
    width: var(--bs);
    height: var(--bs);
    padding: 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    border-width: 2px;
    font-size: 24px;
    background: rgba(20, 12, 34, .45);
    -webkit-user-select: none;
    user-select: none;
  }
  .btn.brake { left: max(10px, env(safe-area-inset-left)); top: calc(45% - var(--bs) / 2); }
  .btn.brake .bt { display: none; }
  .btn.jump { right: max(10px, env(safe-area-inset-right)); top: calc(45% - var(--bs) - 4px); }
  .btn.nitro { right: max(10px, env(safe-area-inset-right)); top: calc(45% + 4px); }
  /* the audio toggle leaves the right edge to the thumb buttons: it sits next to the pause */
  body.playing .btn.audio {
    top: auto;
    bottom: max(14px, env(safe-area-inset-bottom));
    right: calc(max(16px, env(safe-area-inset-right)) + 52px);
  }
  .btn.brake:active { background: rgba(255, 79, 139, .4); }
  .btn.nitro:active { background: rgba(247, 201, 72, .35); }
  .btn.jump:active { background: rgba(70, 200, 216, .35); }
}

/* touch layouts (body[data-ctl]): "left" / "right" turn half of the screen into the brake, Real Racing
   style, with big transformation and time-jump buttons on the other edge; "buttons" keeps the round brake */
.brake-zone { display: none; }
.opts { gap: 8px; margin-top: 12px; }
@media (pointer: coarse) {
  .opts.touch-only { display: flex; flex-wrap: wrap; }
  body[data-ctl="left"] .brake-zone, body[data-ctl="right"] .brake-zone {
    display: block;
    position: absolute;
    top: 22%;
    bottom: 0;
    width: 50%;
    pointer-events: auto;
    touch-action: none;
  }
  body[data-ctl="left"] .brake-zone { left: 0; }
  body[data-ctl="right"] .brake-zone { right: 0; }
  .brake-zone span {
    position: absolute;
    top: 30%;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .12em;
    color: var(--brand);
    opacity: .45;
  }
  body[data-ctl="left"] .brake-zone span { left: max(14px, env(safe-area-inset-left)); }
  body[data-ctl="right"] .brake-zone span { right: max(14px, env(safe-area-inset-right)); }
  /* the red glow follows how hard the car is braking (--bk, 0..1, set by the game) */
  body[data-ctl="left"] .brake-zone.on { background: linear-gradient(to right, rgba(255, 79, 139, calc(.12 + .3 * var(--bk, 1))), transparent 70%); }
  body[data-ctl="right"] .brake-zone.on { background: linear-gradient(to left, rgba(255, 79, 139, calc(.12 + .3 * var(--bk, 1))), transparent 70%); }
  body[data-ctl="left"] .btn.brake, body[data-ctl="right"] .btn.brake { display: none; }
  body[data-ctl="left"] .btn.nitro, body[data-ctl="left"] .btn.jump,
  body[data-ctl="right"] .btn.nitro, body[data-ctl="right"] .btn.jump { --bs: min(88px, 24vh); font-size: 30px; top: auto; }
  body[data-ctl="left"] .btn.jump, body[data-ctl="right"] .btn.jump { top: calc(43% - var(--bs) - 4px); }
  body[data-ctl="left"] .btn.nitro, body[data-ctl="right"] .btn.nitro { top: calc(43% + 4px); }
  /* freno a destra: the buttons move to the left edge */
  body[data-ctl="right"] .btn.nitro, body[data-ctl="right"] .btn.jump { right: auto; left: max(10px, env(safe-area-inset-left)); }
}

@media (max-width: 520px) {
  .term-body { padding: 16px; }
  .stats { grid-template-columns: 1fr; }
  .hud-score .sub, .hud-lap { display: none; }
  /* the car sits just above the bottom strip on an upright phone: keep the buttons in that strip, under the stage */
  .hud-stage .buttons { margin-top: 8px; gap: 6px; }
  /* four touch buttons and five charges have to share a phone's width */
  .hud-row.bottom { gap: 8px; }
  .hud-speed { flex: none; }
  .pips b { width: 13px; }
  .hud-stage .stage-name { display: none; }
  body.playing .btn.audio { top: max(56px, calc(env(safe-area-inset-top) + 48px)); }
  .fork { flex-direction: column; align-items: center; gap: 4px; }
}

@keyframes rise {
  0% { opacity: 0; transform: translateY(12px) scale(.9); }
  15% { opacity: 1; transform: translateY(0) scale(1.05); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-36px) scale(1); }
}
@keyframes pop {
  0% { opacity: 0; transform: scale(1.8); }
  25% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(.8); }
}
@keyframes blink { 50% { opacity: .35; } }
@keyframes boot { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: .55; }
  94% { opacity: 1; }
  96% { opacity: .7; }
  97% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .logo, .bar.low, .score-big em { animation: none; }
  .fx { background: radial-gradient(ellipse at center, transparent 55%, rgba(10, 4, 20, .6) 100%); }
}
