:root {
  --navy: #0d1b3d;
  --navy-2: #13275a;
  --gold: #f2b632;
  --gold-hi: #ffe7a0;
  --gold-lo: #9a6a12;
  --green: #119944;
  --yellow: #ffd500;
  --white: #ffffff;
  --panel: rgba(9, 18, 42, 0.78);
  --font: 'Baloo 2', 'Arial Rounded MT Bold', 'Trebuchet MS', system-ui, sans-serif;
  --display: 'Lilita One', 'Baloo 2', 'Arial Black', system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; width: 100%; height: 100%; overflow: hidden;
  background: #8cc8ff; color: var(--white); font-family: var(--font);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: var(--font); cursor: pointer; touch-action: none; }

.panel {
  background: linear-gradient(180deg, rgba(19, 39, 90, 0.86), rgba(9, 18, 42, 0.86));
  border: 2px solid rgba(242, 182, 50, 0.75);
  border-radius: 18px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}

/* ------------------------------------------------------------------ HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-top {
  position: absolute; top: calc(10px + var(--safe-t)); left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r));
  display: flex; align-items: flex-start; gap: 8px;
}
.hud-race { display: flex; align-items: center; padding: 6px 14px; gap: 12px; }
.hud-item { display: flex; flex-direction: column; line-height: 1; }
.hud-item .lbl { font-size: 11px; letter-spacing: 2px; color: var(--gold); font-weight: 800; }
.hud-item .val { font-size: 24px; font-weight: 800; margin-top: 3px; }
.hud-item b { color: var(--yellow); }
.mono { font-variant-numeric: tabular-nums; }
.hud-sep { width: 2px; align-self: stretch; background: rgba(242, 182, 50, 0.4); border-radius: 2px; }
.hud-crowns { margin-left: auto; padding: 6px 14px; display: flex; align-items: center; gap: 6px; font-size: 26px; font-weight: 800; }
.hud-crowns .crown-icon { font-size: 24px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.hud-crowns .small { font-size: 15px; opacity: 0.75; }
.hud-crowns.bump { animation: bump 0.45s ease; }
@keyframes bump { 30% { transform: scale(1.25); } }
.round-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid var(--gold); background: var(--panel); color: var(--gold); font-size: 15px; font-weight: 800;
}

#speedo {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b)); width: 170px; padding: 6px 10px 8px; text-align: center;
}
.gauge { width: 100%; height: auto; display: block; }
.gauge-bg { fill: none; stroke: rgba(255,255,255,0.15); stroke-width: 9; stroke-linecap: round; }
.gauge-fill { fill: none; stroke: url(#gGold) var(--gold); stroke: var(--gold); stroke-width: 9; stroke-linecap: round; stroke-dasharray: 157; stroke-dashoffset: 157; transition: stroke 0.2s; }
.gauge-fill.turbo { stroke: #ff8a1c; }
.speed-num { margin-top: -38px; line-height: 1; }
.speed-num b { font-size: 34px; font-family: var(--display); font-weight: 400; display: block; font-variant-numeric: tabular-nums; }
.speed-num span { font-size: 11px; letter-spacing: 2px; color: var(--gold); font-weight: 800; }
.turbo-bar { position: relative; margin-top: 6px; height: 14px; border-radius: 8px; background: rgba(0,0,0,0.45); overflow: hidden; border: 1px solid rgba(242,182,50,.6); }
#turbo-fill { position: absolute; inset: 0; width: 100%; background: linear-gradient(90deg, var(--green), var(--yellow)); transform-origin: left; }
#turbo-fill.active { background: linear-gradient(90deg, #ff6a00, #ffd500); box-shadow: 0 0 12px #ff9a1c; }
.turbo-bar span { position: absolute; inset: 0; font-size: 10px; font-weight: 800; letter-spacing: 2px; line-height: 14px; color: #0d1b3d; }

.toast {
  position: absolute; top: 24%; left: 50%; transform: translate(-50%, -50%) scale(0.8);
  font-family: var(--display); font-size: clamp(26px, 6vw, 46px); color: var(--yellow);
  text-shadow: 0 3px 0 var(--navy), 0 0 18px rgba(0,0,0,.5); -webkit-text-stroke: 1.5px var(--navy);
  opacity: 0; transition: opacity 0.25s, transform 0.25s; white-space: nowrap; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.warn { color: #ff5a4a; }
.countdown {
  position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%);
  font-family: var(--display); font-size: clamp(80px, 22vw, 170px); color: var(--yellow);
  -webkit-text-stroke: 4px var(--navy); text-shadow: 0 8px 0 var(--navy), 0 0 40px rgba(0,0,0,.4);
}
.countdown.pop { animation: pop 0.9s ease-out forwards; }
.countdown.go { color: #3bff7a; }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(2); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 100% { opacity: 0.0; transform: translate(-50%, -50%) scale(0.9); } }

/* ------------------------------------------------------------------ touch controls */
#controls { display: none; }
body.touch #controls { display: block; }
.wheel {
  position: absolute; pointer-events: auto;
  left: calc(14px + var(--safe-l)); bottom: calc(14px + var(--safe-b));
  width: clamp(130px, min(40vw, 34vh), 190px); aspect-ratio: 1;
  touch-action: none;
}
.wheel-knob { width: 100%; height: 100%; filter: drop-shadow(0 6px 10px rgba(0,0,0,.45)); will-change: transform; }
.wheel-knob svg { width: 100%; height: 100%; display: block; }
.wheel-txt { font: 800 13px var(--font); fill: var(--gold); letter-spacing: 1px; }
.ctrl-lbl { position: absolute; left: 0; right: 0; bottom: -4px; text-align: center; font-size: 10px; letter-spacing: 3px; color: var(--gold); font-weight: 800; text-shadow: 0 1px 2px #000; pointer-events: none; }
#pedals {
  position: absolute; right: calc(14px + var(--safe-r)); bottom: calc(14px + var(--safe-b));
  display: flex; align-items: flex-end; gap: 10px; pointer-events: auto;
}
.pedal {
  pointer-events: auto; touch-action: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: clamp(62px, min(17vw, 15vh), 84px); height: clamp(78px, min(22vw, 19vh), 108px);
  border-radius: 20px; border: 3px solid var(--gold); color: var(--white);
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  box-shadow: 0 6px 0 #050b1c, 0 8px 18px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.2);
  transition: transform 0.05s, box-shadow 0.05s;
}
.pedal i { font-style: normal; font-size: 26px; line-height: 1; }
.pedal small { font-size: 12px; font-weight: 800; letter-spacing: 1.5px; margin-top: 4px; }
.pedal-gas { height: clamp(96px, min(27vw, 23vh), 130px); background: linear-gradient(180deg, #19b257, #0b6b31); }
.pedal-turbo { background: linear-gradient(180deg, #ffcf3a, #d4870f); color: var(--navy); }
.pedal-brake { background: linear-gradient(180deg, #2b3c6a, #121f45); }
.pedal.down { transform: translateY(5px) scale(0.97); box-shadow: 0 1px 0 #050b1c, 0 3px 8px rgba(0,0,0,.4), inset 0 2px 0 rgba(255,255,255,.2); filter: brightness(1.2); }

/* speedometer moves up on narrow portrait phones so it never overlaps the controls */
@media (max-width: 600px) and (orientation: portrait) {
  .toast { top: 34%; }
  body.touch #speedo { bottom: auto; top: calc(70px + var(--safe-t)); width: 132px; padding: 4px 8px 6px; }
  body.touch .speed-num b { font-size: 26px; }
  body.touch .speed-num { margin-top: -30px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  #speedo { width: 140px; bottom: auto; top: calc(8px + var(--safe-t)); }
  .speed-num b { font-size: 26px; }
  .speed-num { margin-top: -30px; }
  .hud-item .val { font-size: 19px; }
  .hud-crowns { font-size: 21px; }
}

#speedlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 5; opacity: 0;
  background: repeating-conic-gradient(from 0deg at 50% 45%, rgba(255,255,255,0.0) 0deg 4deg, rgba(255,255,255,0.22) 4.3deg 4.6deg, rgba(255,255,255,0) 5deg 9deg);
  -webkit-mask-image: radial-gradient(ellipse at 50% 45%, transparent 38%, #000 75%);
  mask-image: radial-gradient(ellipse at 50% 45%, transparent 38%, #000 75%);
  transition: opacity 0.3s;
}

/* ------------------------------------------------------------------ screens */
.screen { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: calc(18px + var(--safe-t)) 16px calc(18px + var(--safe-b)); }
#screen-start { background: linear-gradient(180deg, rgba(13,27,61,0.55) 0%, rgba(13,27,61,0) 30%, rgba(13,27,61,0) 55%, rgba(13,27,61,0.75) 100%); }
#screen-pause, #screen-finish, #error { justify-content: center; background: rgba(6, 12, 30, 0.6); }
.title-block { text-align: center; margin-top: 2vh; }
.badge { display: inline-block; padding: 3px 12px; border-radius: 30px; background: var(--green); color: var(--yellow); font-weight: 800; font-size: 12px; letter-spacing: 3px; border: 2px solid var(--yellow); }
h1 {
  margin: 8px 0 0; font-family: var(--display); font-weight: 400; line-height: 0.92;
  font-size: clamp(38px, 10vw, 92px); color: var(--gold);
  -webkit-text-stroke: 2px var(--navy); text-shadow: 0 5px 0 var(--navy), 0 10px 26px rgba(0,0,0,.45);
  background: linear-gradient(180deg, #fff3c2 10%, #f2b632 55%, #b9811c 100%); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
h1 span { display: block; font-size: 0.62em; -webkit-text-fill-color: var(--white); color: var(--white); }
.subtitle { margin-top: 10px; font-family: var(--display); font-size: clamp(18px, 4.4vw, 30px); color: var(--white); letter-spacing: 3px; text-shadow: 0 3px 0 var(--navy); }
.menu-card { width: min(440px, 100%); padding: 18px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.menu-card h2 { margin: 0; font-family: var(--display); font-weight: 400; color: var(--gold); font-size: 34px; letter-spacing: 2px; }
.btn-primary {
  border: 3px solid var(--gold-hi); border-radius: 18px; padding: 14px 20px;
  font-family: var(--display); font-size: 28px; letter-spacing: 2px; color: var(--navy);
  background: linear-gradient(180deg, #ffe58a, var(--gold) 55%, #c98a1b);
  box-shadow: 0 6px 0 #7a5208, 0 10px 24px rgba(0,0,0,.35);
  animation: glow 2s ease-in-out infinite;
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #7a5208; }
@keyframes glow { 50% { box-shadow: 0 6px 0 #7a5208, 0 0 28px rgba(255, 213, 0, .6); } }
.btn-secondary { border: 2px solid var(--gold); border-radius: 14px; padding: 11px; font-size: 18px; font-weight: 800; color: var(--white); background: var(--green); }
.btn-ghost { border: 2px solid rgba(242,182,50,.6); border-radius: 12px; padding: 8px 12px; font-size: 14px; font-weight: 800; color: var(--white); background: rgba(255,255,255,.06); }
.menu-row { display: flex; flex-direction: column; gap: 6px; }
.menu-row label { font-size: 11px; letter-spacing: 2px; color: var(--gold); font-weight: 800; }
.small-row { flex-direction: row; align-items: center; justify-content: space-between; }
.seg { display: flex; border: 2px solid rgba(242,182,50,.6); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; padding: 8px 0; background: transparent; color: #cfd8ef; font-weight: 800; font-size: 13px; letter-spacing: 1px; }
.seg button.on { background: var(--gold); color: var(--navy); }
.best { font-size: 13px; color: var(--yellow); font-weight: 800; }
.help { margin: 0; font-size: 12.5px; color: #cfd8ef; line-height: 1.4; }
.touch-only { display: none; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stats div { background: rgba(255,255,255,.06); border-radius: 12px; padding: 8px; display: flex; flex-direction: column; }
.stats span { font-size: 10px; letter-spacing: 2px; color: var(--gold); font-weight: 800; }
.stats b { font-size: 22px; font-variant-numeric: tabular-nums; }
.record { font-family: var(--display); color: var(--yellow); font-size: 22px; animation: bump 1s ease infinite; }

#loading { background: linear-gradient(180deg, rgba(13,27,61,0) 45%, rgba(13,27,61,0.92) 88%), url(../img/menu-bg.jpg) center 30% / contain no-repeat, radial-gradient(circle at 50% 40%, #1d3a7a, var(--navy)); justify-content: flex-end; z-index: 50; }
/* poster (thumbnail art) next to the title on the start screen */
#screen-start .title-block .poster { display: block; width: clamp(84px, 18vh, 200px); height: auto; aspect-ratio: 1; margin: 0 auto 8px; border-radius: 18px; border: 3px solid var(--gold, #ffd500); box-shadow: 0 10px 30px rgba(0,0,0,0.45); transform: rotate(-3deg); object-fit: cover; }
.loader { display: flex; flex-direction: column; align-items: center; gap: 10px; color: var(--gold); }
.loader b { font-family: var(--display); font-weight: 400; font-size: 26px; letter-spacing: 2px; }
.loader span { color: #cfd8ef; font-size: 14px; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 6px solid rgba(242,182,50,.25); border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-height: 520px) and (orientation: landscape) {
  .screen { flex-direction: row; justify-content: space-around; align-items: center; }
  .title-block { margin: 0; }
  h1 { font-size: clamp(30px, 7vw, 60px); }
  .menu-card { width: min(360px, 48vw); padding: 12px; gap: 8px; }
  .btn-primary { font-size: 22px; padding: 10px; }
  #screen-pause, #screen-finish { justify-content: center; }
}

/* start screen layout on wide screens: title top-left, menu bottom-right, kart visible in between */
@media (min-aspect-ratio: 5/4) {
  #screen-start {
    display: grid; grid-template-columns: 1fr minmax(300px, 400px); grid-template-rows: auto 1fr;
    align-items: start; padding-left: calc(28px + var(--safe-l)); padding-right: calc(24px + var(--safe-r));
    background: linear-gradient(90deg, rgba(13,27,61,0.55) 0%, rgba(13,27,61,0) 38%, rgba(13,27,61,0) 60%, rgba(13,27,61,0.55) 100%);
  }
  #screen-start .title-block { grid-column: 1; grid-row: 1; text-align: left; margin-top: 0; }
  #screen-start .title-block .poster { margin-left: 0; }
  #screen-start .menu-card { grid-column: 2; grid-row: 1 / span 2; align-self: end; width: 100%; }
  #screen-start h1 { font-size: clamp(34px, 6.2vw, 84px); }
}
@media (max-aspect-ratio: 5/4) {
  #screen-start .menu-card { padding: 14px; gap: 10px; }
  #screen-start h1 { font-size: clamp(34px, 11vw, 70px); }
}

/* ------------------------------------------------------------------ levels */
.levels-head { font-size: 11px; letter-spacing: 2px; color: var(--gold); font-weight: 800; text-align: left; margin-bottom: -4px; }
.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.level-card {
  display: flex; align-items: center; gap: 8px; text-align: left; padding: 7px 9px; min-height: 58px;
  border: 2px solid rgba(242,182,50,.35); border-radius: 14px; color: var(--white);
  background: rgba(255,255,255,.06); touch-action: manipulation;
}
.level-card.on { border-color: var(--gold); background: linear-gradient(180deg, rgba(242,182,50,.32), rgba(242,182,50,.12)); box-shadow: 0 0 14px rgba(242,182,50,.35); }
.lv-icon { font-size: 26px; line-height: 1; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }
.lv-txt { display: flex; flex-direction: column; line-height: 1.12; min-width: 0; }
.lv-txt b { font-size: 14px; font-weight: 800; }
.lv-txt small { font-size: 9.5px; letter-spacing: 1px; color: var(--gold); font-weight: 800; }
.lv-best { font-style: normal; font-size: 10.5px; color: var(--yellow); font-weight: 800; }
.lv-best:empty { display: none; }
.level-desc { margin: 0; font-size: 13px; color: #e4eaf8; line-height: 1.35; min-height: 2.7em; }
#screen-start .menu-card { max-height: 100%; overflow-y: auto; touch-action: pan-y; }

/* ------------------------------------------------------------------ mode panel (police / kart health) */
#hud-pos-item { border-left: 2px solid rgba(242, 182, 50, 0.4); padding-left: 12px; }
#hud-pos-item .val { color: var(--yellow); }
.hud-mode {
  position: absolute; top: calc(72px + var(--safe-t)); left: calc(10px + var(--safe-l));
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; row-gap: 2px;
  padding: 6px 12px; width: min(230px, 46vw); align-items: center;
}
.hud-mode .lbl { font-size: 11px; letter-spacing: 2px; color: var(--gold); font-weight: 800; }
.mode-txt { grid-column: 1 / span 2; font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
.mode-bar { height: 12px; border-radius: 7px; background: rgba(0,0,0,.45); border: 1px solid rgba(242,182,50,.6); overflow: hidden; }
#hud-mode-fill { height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); background: linear-gradient(90deg, #2a6bff, #ff2a2a); }
.hud-mode[data-state="good"] #hud-mode-fill { background: linear-gradient(90deg, var(--green), var(--yellow)); }
.hud-mode[data-state="danger"] { border-color: #ff4a3a; animation: alarm 0.5s ease-in-out infinite alternate; }
.hud-mode[data-state="danger"] .mode-txt { color: #ff7a6a; }
@keyframes alarm { to { box-shadow: 0 0 18px rgba(255, 60, 40, .8); } }
@media (max-width: 600px) and (orientation: portrait) {
  .hud-race { gap: 8px; padding: 6px 10px; }
  .hud-item .val { font-size: 20px; }
  #hud-pos-item { padding-left: 8px; }
  body.touch .hud-mode { top: calc(188px + var(--safe-t)); width: 44vw; }
  .lv-txt b { font-size: 13px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .hud-mode { top: calc(60px + var(--safe-t)); width: 200px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .level-card { min-height: 46px; padding: 5px 7px; }
  .lv-icon { font-size: 20px; }
  .level-desc { display: none; }
  #screen-start .menu-card { width: min(420px, 56vw); }
}

/* finale: keep the cheering pigs visible behind a compact card */
#screen-finish.finale { background: linear-gradient(180deg, rgba(6,12,30,0) 45%, rgba(6,12,30,.5) 100%); justify-content: flex-end; }
#screen-finish.finale .menu-card { width: min(560px, 100%); gap: 6px; padding: 10px 14px; }
#screen-finish.finale h2 { font-size: clamp(17px, 4.2vw, 22px); }
#screen-finish.finale .stats { grid-template-columns: repeat(3, 1fr); gap: 5px; }
#screen-finish.finale .stats div { padding: 4px 6px; }
#screen-finish.finale .stats b { font-size: 15px; }
#screen-finish.finale .record { font-size: 16px; }
#screen-finish.finale .btn-primary, #screen-finish.finale .btn-secondary { padding: 8px; font-size: 18px; }
@media (max-height: 520px) and (orientation: landscape) {
  #screen-finish.finale { flex-direction: column; }
  #screen-finish.finale .stats { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 600px) and (orientation: portrait) {
  #screen-start .help { display: none; }
  #screen-start .btn-primary { font-size: 22px; padding: 10px 14px; }
  #screen-start .subtitle { font-size: 16px; }
  #screen-finish.finale .stats div:nth-child(n+4) { display: none; }
  #screen-finish.finale .record { display: none; }
}

/* ------------------------------------------------------------------ score, combo, mirror, horn (Demolition Karts 2.0) */
.hud-score {
  position: absolute; top: calc(66px + var(--safe-t)); right: calc(10px + var(--safe-r));
  display: flex; align-items: baseline; gap: 8px; padding: 5px 12px;
}
.hud-score .lbl { font-size: 11px; letter-spacing: 2px; color: var(--gold); font-weight: 800; }
.hud-score b { font-family: var(--display); font-weight: 400; font-size: 24px; font-variant-numeric: tabular-nums; color: #fff; }
.hud-score .combo { font-family: var(--display); font-size: 20px; color: #ff8a1c; -webkit-text-stroke: 1px var(--navy); }
.hud-score .combo.bump { animation: bump 0.35s ease; }
.score-pop {
  position: absolute; top: calc(112px + var(--safe-t)); right: calc(14px + var(--safe-r)); text-align: right;
  font-family: var(--display); font-size: clamp(18px, 4vw, 26px); color: var(--yellow); -webkit-text-stroke: 1px var(--navy);
  text-shadow: 0 2px 0 var(--navy); opacity: 0; transition: opacity .2s, transform .2s; transform: translateY(6px); white-space: nowrap;
}
.score-pop.show { opacity: 1; transform: none; }
.mirror {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(8px + var(--safe-t));
  width: clamp(170px, 30vw, 330px); aspect-ratio: 3 / 1; border-radius: 14px;
  border: 4px solid #1b1c20; box-shadow: 0 0 0 2px rgba(242,182,50,.7), 0 6px 16px rgba(0,0,0,.45);
  background: transparent;
}
.mirror-lbl { position: absolute; bottom: -15px; left: 0; right: 0; text-align: center; font-size: 9px; letter-spacing: 3px; color: var(--gold); font-weight: 800; text-shadow: 0 1px 2px #000; }
.horn-btn {
  position: absolute; pointer-events: auto; touch-action: none;
  left: calc(14px + var(--safe-l) + clamp(130px, min(40vw, 34vh), 190px) + 8px); bottom: calc(18px + var(--safe-b));
  width: 54px; height: 54px; border-radius: 50%; border: 3px solid var(--gold);
  background: linear-gradient(180deg, #ff6aa8, #c2306f); color: #fff; font-size: 22px; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: 0 4px 0 #050b1c, 0 6px 14px rgba(0,0,0,.4);
}
.horn-btn small { font-size: 9px; font-weight: 800; letter-spacing: 1px; margin-top: 1px; }
.horn-btn.down { transform: translateY(3px) scale(.96); filter: brightness(1.2); }
.pedal small.sub { font-size: 8.5px; letter-spacing: 0.5px; margin-top: 1px; opacity: .85; }
.fin-score { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.fin-score span { font-size: 12px; letter-spacing: 3px; color: var(--gold); font-weight: 800; }
.fin-score b { font-family: var(--display); font-weight: 400; font-size: clamp(30px, 7vw, 44px); color: var(--yellow); -webkit-text-stroke: 1.5px var(--navy); }
.board { display: flex; flex-direction: column; gap: 6px; }
.board-save { display: flex; gap: 6px; }
.board-save input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 12px; border: 2px solid rgba(242,182,50,.7);
  background: rgba(0,0,0,.35); color: #fff; font: 800 16px var(--font);
}
.board-save .btn-secondary { padding: 8px 12px; font-size: 16px; }
.board-list { margin: 0; padding: 0 0 0 24px; font-size: 13px; max-height: 128px; overflow-y: auto; columns: 2; column-gap: 18px; }
.board-list li { padding: 1px 0; break-inside: avoid; }
.board-list li b { color: var(--yellow); float: right; font-variant-numeric: tabular-nums; }
.board-list li.me { color: #3bff7a; }
.board-note { font-size: 11px; opacity: .7; text-align: center; min-height: 1em; }
@media (max-width: 600px) and (orientation: portrait) {
  .mirror { top: calc(64px + var(--safe-t)); width: 46vw; }
  body.touch.has-mirror #speedo { top: calc(64px + 15.3vw + 18px + var(--safe-t)); }
  body.touch.has-mirror .hud-mode { top: calc(64px + 15.3vw + 112px + var(--safe-t)); }
  .hud-score { top: calc(64px + var(--safe-t)); padding: 4px 9px; }
  .has-mirror .hud-score { top: calc(64px + 15.3vw + 22px + var(--safe-t)); }
  .hud-score b { font-size: 19px; }
  .score-pop { top: calc(150px + 15.3vw + var(--safe-t)); }
  .horn-btn { width: 46px; height: 46px; font-size: 18px; bottom: calc(clamp(130px, min(40vw, 34vh), 190px) + 24px + var(--safe-b)); left: calc(18px + var(--safe-l)); }
  .board-list { columns: 1; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .hud-score { top: calc(56px + var(--safe-t)); }
  .mirror { width: clamp(150px, 24vw, 230px); top: calc(6px + var(--safe-t)); }
  .has-mirror #speedo { left: auto; right: calc(70px + var(--safe-r)); transform: none; top: calc(98px + var(--safe-t)); }
}
#screen-finish.finale .fin-score b { font-size: 28px; }
#screen-finish.finale .board-list { max-height: 70px; }

/* first runtime error, shown so it can be screenshotted */
#errbar { position: fixed; left: 8px; right: 8px; top: calc(8px + var(--safe-t, 0px)); z-index: 200; background: #b3122e; color: #fff; font: 600 12px/1.35 system-ui, sans-serif; padding: 8px 10px; border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,0.4); word-break: break-word; }

/* the START button must always be reachable: keep it pinned at the bottom of the scrolling menu card,
   and drop the poster on short portrait screens */
#screen-start #btn-start { position: sticky; bottom: 0; z-index: 2; box-shadow: 0 -10px 18px rgba(13,27,61,0.85), 0 6px 0 var(--gold-lo); }
@media (max-aspect-ratio: 5/4) and (max-height: 760px) { #screen-start .title-block .poster { display: none; } }
@media (min-aspect-ratio: 5/4) and (max-height: 430px) { #screen-start .title-block .poster { width: 72px; } }

/* the menu card never grows past the screen: it scrolls inside itself, START stays pinned at its bottom */
@media (min-aspect-ratio: 5/4) {
  #screen-start { grid-template-rows: minmax(0, 1fr); }
  #screen-start .title-block { min-height: 0; overflow: hidden; }
  #screen-start .menu-card { grid-row: 1; min-height: 0; max-height: 100%; align-self: end; }
}
@media (max-aspect-ratio: 5/4) {
  #screen-start .menu-card { min-height: 0; flex: 0 1 auto; }
}
@media (max-height: 520px) {
  #screen-start .level-desc, #screen-start .help { display: none; }
  #screen-start .levels-head { display: none; }
}
@media (min-aspect-ratio: 5/4) and (max-height: 520px) {
  #screen-start h1 { font-size: clamp(26px, 9vh, 48px); }
  #screen-start .subtitle { font-size: 13px; }
  #screen-start .badge { display: none; }
}

/* police helicopter has you in its searchlight */
.hud-mode .heli-txt { display: block; margin-top: 3px; font-size: 11px; font-weight: 800; letter-spacing: 1px; color: #dfe9ff; text-shadow: 0 0 8px #8fb4ff; animation: alarm 0.5s ease-in-out infinite alternate; }
.hud-mode .heli-txt.hidden { display: none; }

/* ------------------------------------------------------------------ class (50/100/150cc), Champions League, camera */
.race-opts { display: flex; gap: 8px; align-items: stretch; }
.race-opts .seg { flex: 1.2; }
.race-opts .seg button { padding: 7px 0; font-size: 12px; }
.cl-toggle {
  flex: 1; border: 2px solid rgba(242,182,50,.6); border-radius: 12px; padding: 6px 8px;
  background: rgba(255,255,255,.06); color: #cfd8ef; font-weight: 800; font-size: 11px; letter-spacing: .5px; line-height: 1.15;
}
.cl-toggle.on { background: linear-gradient(180deg, #2a4cc0, #12266e); color: #fff; border-color: #fff; box-shadow: 0 0 12px rgba(120,170,255,.75), inset 0 0 0 1px rgba(255,255,255,.4); }
#btn-cam { font-size: 19px; }
@media (max-width: 380px) { .race-opts { flex-direction: column; } }
#btn-cam { filter: grayscale(1) brightness(2.4); }
/* phones in portrait: make room so the class / Champions League row sits above the pinned START button */
@media (orientation: portrait) and (max-height: 880px) {
  #screen-start .title-block .badge { display: none; }
  #screen-start .title-block .poster { width: clamp(84px, 13vh, 200px); }
}
/* sound on/off: round icon top right of the start screen, always in view (the arcade's back link sits top left) */
.sound-fab {
  position: fixed; top: calc(10px + var(--safe-t)); right: calc(10px + var(--safe-r)); z-index: 30;
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--gold);
  background: rgba(10,20,48,.82); font-size: 20px; line-height: 1; padding: 0;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 10px rgba(0,0,0,.4);
}
/* phones in portrait: the top bar has no room for a third button, the camera button sits above the horn */
@media (max-width: 600px) and (orientation: portrait) {
  #btn-cam { position: fixed; left: calc(18px + var(--safe-l)); top: auto; width: 46px; height: 46px;
    bottom: calc(clamp(130px, min(40vw, 34vh), 190px) + 24px + 46px + 12px + var(--safe-b)); }
}
/* phones in portrait: compact top bar so the pause button stays on screen */
@media (max-width: 600px) and (orientation: portrait) {
  .hud-top { gap: 6px; }
  .hud-race { gap: 6px; padding: 5px 8px; }
  .hud-item .lbl { font-size: 9px; letter-spacing: 1px; }
  .hud-item .val { font-size: 17px; }
  #hud-pos-item { padding-left: 6px; }
  .hud-crowns { padding: 5px 9px; font-size: 19px; gap: 4px; }
  .hud-crowns .crown-icon { font-size: 18px; }
  .hud-crowns .small { font-size: 12px; }
  #btn-pause { width: 40px; height: 40px; flex: none; }
}
