:root {
  --bg: #080c11;
  --glass: rgba(8, 13, 19, .72);
  --glass-strong: rgba(8, 13, 19, .90);
  --line: rgba(255,255,255,.15);
  --line-strong: rgba(255,255,255,.28);
  --text: #f7fbff;
  --muted: #99a7b6;
  --soft: #dce6f0;
  --accent: #ff2f87;
  --accent-warm: #ff704d;
  --cyan: #2bdcff;
  --good: #61f5b1;
}
* { box-sizing: border-box; }
html, body, #app { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { touch-action: none; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }


/* ---------- global audio ---------- */
.audio-toggle {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 30;
  min-width: 72px;
  height: 36px;
  padding: 0 11px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 8px;
  background: rgba(7,12,18,.72);
  color: #dbe8f2;
  cursor: pointer;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .10em;
  text-transform: uppercase;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.audio-toggle[aria-pressed="true"] {
  color: #ffb8cf;
  border-color: rgba(255,47,135,.35);
  background: rgba(55,10,28,.72);
}

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; z-index: 10; display: none; padding: clamp(20px, 4vw, 64px); background: linear-gradient(90deg, rgba(3,7,11,.84) 0%, rgba(3,7,11,.55) 40%, rgba(3,7,11,.16) 72%, rgba(3,7,11,.34) 100%); }
.overlay.visible { display: flex; align-items: center; }
.menu-shell { width: min(680px, 92vw); margin-left: clamp(0px, 5vw, 70px); animation: menuIn .45s cubic-bezier(.2,.78,.28,1) both; }
.menu-copy { max-width: 650px; }
.eyebrow { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; color: #dce6f0; font-size: 11px; line-height: 1; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.eyebrow-dot { width: 22px; height: 3px; display: inline-block; background: linear-gradient(90deg, var(--accent), var(--cyan)); }
h1, h2 { margin: 0; text-transform: uppercase; font-style: italic; font-weight: 950; letter-spacing: -.055em; line-height: .91; text-shadow: 0 7px 30px rgba(0,0,0,.38); }
h1 { font-size: clamp(48px, 6.5vw, 90px); }
h1 span { color: transparent; background: linear-gradient(90deg, #fff 0%, #fff 15%, #ff619f 47%, #ff8050 68%, #57e4ff 100%); -webkit-background-clip: text; background-clip: text; }
h2 { font-size: clamp(38px, 5vw, 66px); }
.tagline, .info-panel p { max-width: 58ch; margin: 20px 0 0; color: #b4c0cc; font-size: 14px; line-height: 1.65; }
.menu-actions { width: min(530px, 100%); margin-top: 30px; }
.menu-primary-actions { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, .85fr); gap: 10px; }
.menu-primary-actions .primary, .menu-primary-actions .secondary-button { min-width: 0; min-height: 62px; }
.paired-primary-actions { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, .85fr); gap: 10px; margin-top: 24px; }
.paired-primary-actions .primary, .paired-primary-actions .secondary-button { min-width: 0; min-height: 54px; }
.paired-primary-actions .compact-primary { margin-top: 0; }
.menu-top-more { background: rgba(10,16,23,.78); border-color: rgba(255,255,255,.20); }
.primary { width: 100%; min-height: 62px; border: 0; cursor: pointer; color: white; background: linear-gradient(100deg, var(--accent) 0%, #f84f62 52%, var(--accent-warm) 100%); box-shadow: 0 16px 42px rgba(255,47,135,.22), inset 0 1px rgba(255,255,255,.28); font-size: 14px; font-weight: 950; letter-spacing: .13em; text-transform: uppercase; transition: transform .16s ease, filter .16s ease; }
.primary:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.08); }
.primary:active:not(:disabled) { transform: translateY(0); }
.primary:disabled { cursor: default; filter: saturate(.25); opacity: .72; }
.compact-primary { margin-top: 24px; min-height: 54px; }
.secondary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.secondary-button { min-height: 46px; display: grid; place-items: center; border: 1px solid var(--line); background: rgba(10,16,23,.62); color: #eaf2fa; cursor: pointer; text-decoration: none; font-size: 11px; font-weight: 850; letter-spacing: .1em; transition: background .16s ease, border-color .16s ease; }
.secondary-button:hover { background: rgba(255,255,255,.09); border-color: var(--line-strong); }
.menu-meta { display: flex; justify-content: space-between; gap: 20px; margin-top: 15px; color: #8292a2; font-size: 10px; font-weight: 850; letter-spacing: .11em; }
#bestScore { color: #bdefff; }
.panel { width: min(680px, 94vw); margin-left: clamp(0px, 5vw, 70px); border: 1px solid var(--line); background: rgba(7,12,18,.88); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); padding: clamp(28px, 4vw, 48px); box-shadow: 0 28px 90px rgba(0,0,0,.42); animation: menuIn .3s ease-out both; }
.info-panel p { max-width: 62ch; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 24px 0 4px; }
.keys > div { min-height: 54px; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.035); color: #acbac7; font-size: 12px; }
.key-pair { min-width: 82px; display: flex; gap: 5px; }
.key-pair.wide { min-width: 82px; }
kbd { min-width: 34px; padding: 7px 8px; border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.07); color: #fff; text-align: center; font-size: 10px; font-weight: 900; box-shadow: inset 0 -2px rgba(0,0,0,.28); }
.result-panel { width: min(500px, 92vw); }
.result-badge { display: inline-flex; padding: 7px 10px; margin-bottom: 18px; border: 1px solid rgba(43,220,255,.30); background: rgba(43,220,255,.08); color: #bcefff; font-size: 10px; font-weight: 900; letter-spacing: .14em; }
.result-badge.new-best { border-color: rgba(255,47,135,.45); background: rgba(255,47,135,.12); color: #ffd5e6; }
.final-score { margin: 4px 0 4px; font-size: clamp(62px, 10vw, 104px); font-weight: 950; font-style: italic; letter-spacing: -.06em; line-height: 1; }
.final-stats { margin-bottom: 22px; color: var(--muted); font-size: 12px; font-weight: 750; }
.result-primary-actions { margin-top: 0; }
.result-actions { margin-top: 10px; }
.retry-hint { margin-top: 15px; color: #788796; font-size: 9px; font-weight: 850; letter-spacing: .14em; text-align: center; }
@keyframes menuIn { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: translateX(0); } }


/* ---------- pause ---------- */
.pause-overlay { background: rgba(3,7,11,.64); }
.pause-panel { width: min(470px, 92vw); }
.pause-copy { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.pause-primary-actions { margin-top: 24px; }
.pause-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.pause-menu-button { grid-column: 1 / -1; }

/* ---------- driving HUD ---------- */
#hud { position: absolute; inset: 0; z-index: 5; pointer-events: none; padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); text-shadow: 0 2px 10px rgba(0,0,0,.62); }
.hud-glass { border: 1px solid rgba(255,255,255,.10); background: linear-gradient(135deg, rgba(7,12,18,.72), rgba(7,12,18,.45)); box-shadow: 0 10px 28px rgba(0,0,0,.16); }
.hud-top-left { position: absolute; top: max(18px, env(safe-area-inset-top)); left: max(18px, env(safe-area-inset-left)); width: 188px; padding: 12px 14px 11px; }
.hud-kicker { color: #a9b6c3; font-size: 9px; font-weight: 900; letter-spacing: .18em; }
.score-value { margin-top: 2px; font-size: 31px; line-height: 1; font-weight: 950; font-style: italic; letter-spacing: -.045em; }
.combo-row { display: flex; align-items: baseline; gap: 7px; margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(255,255,255,.09); }
.combo-value { color: #7be9ff; font-size: 17px; font-weight: 950; font-style: italic; }
.combo-caption { color: #7d8d9d; font-size: 8px; font-weight: 900; letter-spacing: .13em; }
.hud-route { position: absolute; top: max(18px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: grid; justify-items: center; gap: 7px; }
.route-card { min-height: 32px; display: flex; align-items: center; gap: 11px; padding: 7px 11px; white-space: nowrap; }
.location-value { color: #f3f8fc; font-size: 9px; font-weight: 900; letter-spacing: .13em; }
.route-divider { width: 1px; height: 12px; background: rgba(255,255,255,.17); }
.distance-value, .time-value { color: #a7b5c2; font-size: 9px; font-weight: 850; letter-spacing: .09em; }
.event-value { min-width: 190px; padding: 8px 14px; border: 1px solid rgba(255,111,76,.30); background: rgba(15,15,20,.70); color: #fff1e9; text-align: center; font-size: 9px; font-weight: 950; letter-spacing: .14em; opacity: 0; transform: translateY(-7px); transition: opacity .18s ease, transform .18s ease; }
.event-value.show { opacity: 1; transform: translateY(0); }
.message { position: absolute; left: 50%; top: 22%; transform: translate(-50%,-50%) scale(.96); max-width: 80vw; color: white; font-size: clamp(25px, 4vw, 48px); font-weight: 950; font-style: italic; letter-spacing: -.045em; text-align: center; opacity: 0; transition: opacity .16s ease, transform .16s ease; }
.message.show { opacity: 1; transform: translate(-50%,-50%) scale(1); }
.hud-bottom-left { position: absolute; bottom: max(18px, env(safe-area-inset-bottom)); left: max(18px, env(safe-area-inset-left)); padding: 10px 12px 11px; }
.health-segments { display: flex; gap: 5px; margin-top: 7px; }
.health-segments span { width: clamp(18px, 3vw, 30px); height: 7px; background: linear-gradient(90deg, #79f7bd, #3edb9d); box-shadow: 0 0 12px rgba(97,245,177,.22); transition: opacity .15s ease, background .15s ease; }
.health-segments span.lost { background: rgba(255,255,255,.11); box-shadow: none; opacity: .65; }
.health-segments span.unused { display: none; }
.speed-cluster { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); width: min(300px, 42vw); text-align: right; transition: transform .15s ease; }
.speed-cluster.boosting { transform: scale(1.025); }
.speed-readout { position: relative; z-index: 2; display: flex; align-items: flex-end; justify-content: flex-end; gap: 9px; padding-right: 5px; }
#speedValue { font-size: clamp(58px, 9vw, 96px); line-height: .82; font-weight: 950; font-style: italic; letter-spacing: -.075em; text-shadow: 0 4px 20px rgba(0,0,0,.55); }
.speed-unit { padding-bottom: 6px; color: #afbdca; font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.speed-arc { position: absolute; right: -3px; bottom: 37px; width: 210px; height: 76px; overflow: hidden; opacity: .58; }
.speed-arc::before { content: ""; position: absolute; inset: 18px 0 -110px 0; border: 2px solid rgba(255,255,255,.15); border-bottom-color: transparent; border-left-color: rgba(255,255,255,.05); border-radius: 50%; transform: rotate(-4deg); }
.speed-arc span { position: absolute; right: 18px; bottom: 18px; width: 5px; height: 5px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 16px rgba(43,220,255,.7); }
.nitro-meter { position: relative; z-index: 2; margin-top: 14px; padding: 9px 10px 10px; }
.nitro-head { display: flex; justify-content: space-between; margin-bottom: 6px; color: #b8c6d2; font-size: 9px; font-weight: 900; letter-spacing: .14em; }
.nitro-meter.ready .nitro-head { color: #c8f7ff; }
.nitro-meter.active { border-color: rgba(43,220,255,.35); box-shadow: 0 0 28px rgba(43,220,255,.13); }
.meter-track { height: 6px; overflow: hidden; background: rgba(255,255,255,.12); }
.meter-fill { width: 100%; height: 100%; transform-origin: left center; background: linear-gradient(90deg, #2bdcff 0%, #4ce7ff 45%, #ff4a9a 100%); box-shadow: 0 0 15px rgba(43,220,255,.34); }

/* ---------- touch controls ---------- */
.touch-controls { display: none; position: absolute; inset: 0; z-index: 6; pointer-events: none; align-items: flex-end; justify-content: space-between; padding: max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
.touch-controls button { pointer-events: auto; border: 1px solid rgba(255,255,255,.16); background: rgba(7,12,18,.70); color: #fff; font-weight: 900; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.touch-left, .touch-right { display: flex; gap: 10px; align-items: flex-end; }
.touch-utility { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); display: flex; gap: 8px; pointer-events: none; }
.utility-touch-button { pointer-events: auto; min-width: 46px; height: 44px; padding: 0 11px; border-radius: 10px; font-size: 9px; line-height: 1; letter-spacing: .08em; }
#touchPause { min-width: 44px; padding: 0; font-size: 17px; letter-spacing: 0; }
.steer-button { width: 62px; height: 62px; border-radius: 50%; font-size: 36px; line-height: 1; }
.brake-button, .nitro-button { min-width: 78px; height: 58px; padding: 0 16px; font-size: 10px; letter-spacing: .08em; }
.nitro-button { background: linear-gradient(135deg, rgba(43,220,255,.76), rgba(255,47,135,.72)) !important; }

.crash-flash { position: absolute; inset: 0; z-index: 20; pointer-events: none; background: rgba(255,255,255,.72); opacity: 0; }
.crash-flash.show { animation: crashFlash .24s ease-out; }
@keyframes crashFlash { 0% { opacity: .7; } 30% { opacity: .28; } 100% { opacity: 0; } }

@media (pointer: coarse), (max-width: 850px) {
  .touch-controls:not(.hidden) { display: flex; }
  .overlay { justify-content: center; background: rgba(4,8,12,.58); }
  .menu-shell, .panel { margin-left: 0; }
  .desktop-controls { display: none; }
  .hud-top-left { width: 152px; padding: 9px 11px; }
  .score-value { font-size: 25px; }
  .hud-route { top: 86px; }
  .route-card { gap: 7px; padding: 6px 8px; }
  .location-value { max-width: 105px; overflow: hidden; text-overflow: ellipsis; }
  .speed-cluster { width: 215px; bottom: 90px; }
  #speedValue { font-size: 64px; }
  .hud-bottom-left { bottom: 94px; }
  
}
@media (max-width: 560px) {
  .pause-actions { grid-template-columns: 1fr; }
  .pause-menu-button { grid-column: 1 / -1; }
  h1 { font-size: clamp(42px, 13vw, 62px); }
  .tagline { font-size: 13px; }
  .menu-meta { justify-content: center; }
  .keys { grid-template-columns: 1fr; }
  .secondary-actions { grid-template-columns: 1fr; }
  .hud-route { top: 78px; }
  .route-card { min-width: 0; }
  .route-divider, .time-value { display: none; }
  .message { top: 27%; }
}
@media (max-height: 650px) {
  .overlay { padding-top: 18px; padding-bottom: 18px; }
  h1 { font-size: clamp(40px, 9vh, 62px); }
  .tagline { margin-top: 12px; line-height: 1.45; }
  .menu-actions { margin-top: 16px; }
  .primary { min-height: 50px; }
  .panel { padding: 22px 28px; }
}

/* ---------- garage / permanent upgrades ---------- */
.menu-secondary-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.result-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pause-menu-button { grid-column: 1 / -1; }

.garage-overlay { background: rgba(3,7,11,.72); }
.garage-panel { width: min(760px, 94vw); max-height: min(92vh, 900px); overflow: hidden; margin-left: clamp(0px, 4vw, 56px); padding: clamp(24px, 3vw, 38px); }
.garage-header { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: start; }
.garage-header h2 { font-size: clamp(34px, 4.4vw, 58px); }
.garage-copy { max-width: 58ch; margin: 12px 0 0; color: #8f9dac; font-size: 12px; line-height: 1.55; }
.garage-points-box { min-width: 126px; padding: 13px 14px 12px; border: 1px solid rgba(97,245,177,.30); background: rgba(97,245,177,.075); text-align: right; }
.garage-points-box span { display: block; color: #82a997; font-size: 8px; font-weight: 900; letter-spacing: .14em; }
.garage-points-box strong { display: block; margin-top: 3px; color: #8ef2c2; font-size: 30px; line-height: 1; font-weight: 950; font-style: italic; }
.garage-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 18px 0 10px; }
.garage-summary > div { padding: 9px 11px; border: 1px solid rgba(255,255,255,.075); background: rgba(255,255,255,.025); }
.garage-summary span { display: block; color: #718090; font-size: 7px; font-weight: 900; letter-spacing: .13em; }
.garage-summary strong { display: block; margin-top: 3px; color: #eaf3fb; font-size: 13px; font-weight: 950; letter-spacing: .04em; }

.upgrade-list { display: grid; gap: 7px; }
.upgrade-row { display: grid; grid-template-columns: minmax(0,1fr) 150px; align-items: center; gap: 16px; min-height: 88px; padding: 12px 13px; border: 1px solid rgba(255,255,255,.08); background: linear-gradient(90deg, rgba(255,255,255,.032), rgba(255,255,255,.012)); transition: border-color .16s ease, background .16s ease, transform .16s ease; }
.upgrade-row.affordable { border-color: rgba(43,220,255,.24); background: linear-gradient(90deg, rgba(43,220,255,.065), rgba(255,255,255,.012)); }
.upgrade-row.maxed { border-color: rgba(97,245,177,.14); }
.upgrade-name-line { display: flex; align-items: baseline; gap: 10px; }
.upgrade-name-line strong { color: #f5f9fc; font-size: 12px; font-weight: 950; letter-spacing: .11em; }
.upgrade-name-line span { color: #67dff7; font-size: 9px; font-weight: 950; letter-spacing: .08em; }
.upgrade-effect { margin-top: 4px; color: #c4d0db; font-size: 10px; font-weight: 800; }
.upgrade-next { margin-top: 3px; color: #6f8191; font-size: 8px; font-weight: 850; letter-spacing: .04em; }
.upgrade-row.maxed .upgrade-next { color: #70d7a5; }
.upgrade-pips { display: grid; grid-template-columns: repeat(5, minmax(22px, 52px)); gap: 4px; margin-top: 8px; }
.upgrade-pips i { display: block; height: 5px; background: rgba(255,255,255,.08); box-shadow: inset 0 0 0 1px rgba(255,255,255,.025); }
.upgrade-pips i.active { background: linear-gradient(90deg, #2bdcff, #ff4a9a); box-shadow: 0 0 9px rgba(43,220,255,.12); }
.upgrade-button { width: 100%; min-height: 42px; border: 1px solid rgba(43,220,255,.28); background: rgba(43,220,255,.08); color: #d4f8ff; cursor: pointer; font-size: 9px; font-weight: 950; letter-spacing: .10em; transition: background .15s ease, border-color .15s ease, opacity .15s ease, transform .15s ease; }
.upgrade-button:hover:not(:disabled) { transform: translateY(-1px); background: rgba(43,220,255,.15); border-color: rgba(43,220,255,.50); }
.upgrade-button:disabled { cursor: default; opacity: .38; }
.upgrade-button.maxed { border-color: rgba(97,245,177,.24); background: rgba(97,245,177,.06); color: #8ef2c2; opacity: .82; }
.upgrade-flash { animation: upgradeFlash .42s ease-out; }
@keyframes upgradeFlash { 0% { transform: scale(1); } 35% { transform: scale(1.012); border-color: rgba(97,245,177,.65); background: rgba(97,245,177,.08); } 100% { transform: scale(1); } }
.garage-actions { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 12px; }
.garage-primary-actions { margin-top: 0; }
.garage-actions .compact-primary { margin-top: 0; }
.garage-back-button { min-height: 42px; }

@media (max-width: 700px) {
  .menu-secondary-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .garage-panel { margin-left: 0; }
  .garage-header { grid-template-columns: 1fr; gap: 12px; }
  .garage-points-box { width: 100%; display: flex; align-items: center; justify-content: space-between; text-align: left; }
  .garage-points-box strong { margin-top: 0; }
  .garage-summary { grid-template-columns: 1fr 1fr 1fr; }
  .upgrade-row { grid-template-columns: 1fr; gap: 10px; }
  .upgrade-button { min-height: 38px; }
}
@media (max-width: 480px) {
  .garage-panel { padding: 20px; }
  .garage-summary { grid-template-columns: 1fr; gap: 5px; }
  .upgrade-row { min-height: 0; padding: 10px; }
  .upgrade-next { display: none; }
}
@media (max-height: 700px) and (min-width: 701px) {
  .garage-panel { padding-top: 20px; padding-bottom: 20px; }
  .garage-copy { display: none; }
  .garage-summary { margin-top: 12px; }
  .upgrade-row { min-height: 74px; padding-top: 9px; padding-bottom: 9px; }
  .garage-actions { margin-top: 8px; }
}


/* ---------- locked responsive UI: fit viewport, never scroll ---------- */
html, body, #app {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden !important;
  overscroll-behavior: none;
}

.overlay {
  width: 100%;
  height: 100%;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden !important;
  padding:
    max(clamp(10px, 2.4vh, 28px), env(safe-area-inset-top))
    max(clamp(10px, 2.4vw, 36px), env(safe-area-inset-right))
    max(clamp(10px, 2.4vh, 28px), env(safe-area-inset-bottom))
    max(clamp(10px, 2.4vw, 36px), env(safe-area-inset-left));
}

.overlay.visible {
  align-items: center;
  justify-content: flex-start;
}

.menu-shell,
.panel {
  min-width: 0;
  min-height: 0;
  max-width: calc(100vw - max(20px, env(safe-area-inset-left)) - max(20px, env(safe-area-inset-right)));
  max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  overflow: hidden !important;
}

.menu-shell {
  width: min(680px, 100%);
}

.panel {
  width: min(680px, 100%);
  padding: clamp(18px, 3.2vmin, 42px);
}

/* Fluid type/controls use both width and height so short landscape screens fit. */
h1 { font-size: clamp(34px, min(6.2vw, 11vh), 84px); }
h2 { font-size: clamp(29px, min(4.7vw, 8.4vh), 60px); }
.eyebrow { margin-bottom: clamp(7px, 1.6vh, 14px); font-size: clamp(8px, min(.85vw, 1.65vh), 11px); }
.tagline, .info-panel p { margin-top: clamp(8px, 1.8vh, 20px); font-size: clamp(11px, min(1.05vw, 2vh), 14px); line-height: 1.48; }
.menu-actions { margin-top: clamp(11px, 2.6vh, 30px); }
.menu-primary-actions { gap: clamp(5px, 1vmin, 10px); }
.menu-primary-actions .primary, .menu-primary-actions .secondary-button { min-height: clamp(42px, 7.4vh, 62px); }
.paired-primary-actions { gap: clamp(5px, 1vmin, 10px); margin-top: clamp(8px, 2vh, 24px); }
.paired-primary-actions .primary, .paired-primary-actions .secondary-button { min-height: clamp(38px, 6.5vh, 54px); }
.primary { min-height: clamp(42px, 7.4vh, 62px); font-size: clamp(10px, min(1vw, 1.9vh), 14px); }
.compact-primary { margin-top: clamp(10px, 2vh, 24px); min-height: clamp(40px, 6.5vh, 54px); }
.secondary-button { min-height: clamp(36px, 5.8vh, 46px); font-size: clamp(8px, min(.82vw, 1.5vh), 11px); }
.menu-meta { margin-top: clamp(7px, 1.7vh, 15px); font-size: clamp(7px, min(.7vw, 1.35vh), 10px); }

/* Briefing always compacts instead of scrolling. */
.info-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 0;
}
.keys {
  min-height: 0;
  margin: clamp(8px, 2vh, 24px) 0 2px;
  gap: clamp(4px, .8vmin, 8px);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.keys > div {
  min-width: 0;
  min-height: clamp(38px, 7vh, 54px);
  gap: clamp(6px, 1.3vmin, 12px);
  padding: clamp(5px, 1vmin, 8px) clamp(7px, 1.4vmin, 12px);
  font-size: clamp(9px, min(.9vw, 1.7vh), 12px);
  overflow: hidden;
}
.key-pair, .key-pair.wide { min-width: clamp(56px, 10vw, 82px); flex: 0 0 auto; }
kbd { min-width: clamp(27px, 4vw, 34px); padding: clamp(4px, .8vmin, 7px) clamp(5px, 1vmin, 8px); font-size: clamp(8px, min(.72vw, 1.45vh), 10px); }

/* Pause/results: compact grids, no overflow. */
.pause-panel, .result-panel { width: min(500px, 100%); }
.pause-copy { margin-top: clamp(7px, 1.7vh, 14px); font-size: clamp(10px, min(.9vw, 1.7vh), 13px); }
.pause-actions, .secondary-actions { gap: clamp(5px, 1vmin, 10px); margin-top: clamp(5px, 1.2vh, 10px); }
.final-score { font-size: clamp(48px, min(10vw, 16vh), 98px); }
.final-stats { margin-bottom: clamp(10px, 2vh, 22px); font-size: clamp(9px, min(.9vw, 1.7vh), 12px); }
.result-badge { margin-bottom: clamp(8px, 1.7vh, 18px); }
.retry-hint { margin-top: clamp(6px, 1.4vh, 15px); }

/* Garage is a fitted dashboard, never a scroll container. */
.garage-panel {
  width: min(800px, 100%);
  height: min(92dvh, 900px);
  max-height: calc(100dvh - max(20px, env(safe-area-inset-top)) - max(20px, env(safe-area-inset-bottom)));
  overflow: hidden !important;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(5px, 1.15vh, 12px);
  margin-left: clamp(0px, 4vw, 56px);
  padding: clamp(14px, 2.6vmin, 34px);
}
.garage-header { gap: clamp(10px, 2vw, 24px); }
.garage-header h2 { font-size: clamp(27px, min(4.1vw, 7.5vh), 54px); }
.garage-copy { margin-top: clamp(5px, 1.2vh, 12px); font-size: clamp(9px, min(.82vw, 1.45vh), 12px); line-height: 1.4; }
.garage-points-box { min-width: clamp(105px, 14vw, 126px); padding: clamp(8px, 1.4vmin, 13px); }
.garage-points-box strong { font-size: clamp(22px, min(2.4vw, 4.8vh), 30px); }
.garage-summary { margin: 0; gap: clamp(4px, .8vmin, 8px); }
.garage-summary > div { padding: clamp(5px, 1vmin, 9px) clamp(7px, 1.2vmin, 11px); min-width: 0; }
.garage-summary strong { font-size: clamp(10px, min(1vw, 1.8vh), 13px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.paint-customizer { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: clamp(8px, 1.4vw, 16px); min-height: clamp(30px, 5.2vh, 42px); padding: clamp(4px, .8vmin, 7px) clamp(7px, 1.2vmin, 11px); border: 1px solid rgba(255,255,255,.075); background: rgba(255,255,255,.022); overflow: hidden; }
.paint-meta { min-width: 76px; display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.paint-meta strong { color: #f5f9fc; font-size: clamp(8px, min(.82vw, 1.45vh), 10px); font-weight: 950; letter-spacing: .12em; }
.paint-meta span { color: #7f91a3; font-size: clamp(7px, min(.68vw, 1.2vh), 8px); font-weight: 900; letter-spacing: .05em; }
.paint-swatches { justify-self: end; width: min(100%, 430px); display: grid; grid-template-columns: repeat(8, minmax(22px, 1fr)); gap: clamp(3px, .6vw, 6px); }
.paint-swatch { position: relative; min-width: 0; height: clamp(24px, 4.2vh, 32px); border: 1px solid rgba(255,255,255,.18); background: var(--paint, #f41d7b); cursor: pointer; overflow: hidden; transition: transform .14s ease, border-color .14s ease, box-shadow .14s ease; }
.paint-swatch:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.62); }
.paint-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(43,220,255,.38), inset 0 0 0 2px rgba(0,0,0,.18); }
.paint-swatch.active::after { content: '✓'; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 950; text-shadow: 0 1px 3px rgba(0,0,0,.9); }
.paint-custom { display: block; background: conic-gradient(#f33, #fc3, #4d6, #2cf, #85f, #f3a, #f33); }
.paint-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.paint-custom span { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 950; text-shadow: 0 1px 4px #000; pointer-events: none; }
.upgrade-list {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: clamp(4px, .8vh, 7px);
  overflow: hidden;
}
.upgrade-row {
  min-height: 0;
  height: 100%;
  grid-template-columns: minmax(0,1fr) clamp(112px, 20vw, 150px);
  gap: clamp(8px, 1.7vw, 16px);
  padding: clamp(6px, 1.2vmin, 12px) clamp(8px, 1.4vmin, 13px);
  overflow: hidden;
}
.upgrade-row-main { min-width: 0; align-self: center; }
.upgrade-name-line strong { font-size: clamp(9px, min(.92vw, 1.65vh), 12px); }
.upgrade-name-line span { font-size: clamp(7px, min(.72vw, 1.35vh), 9px); }
.upgrade-effect { margin-top: clamp(2px, .5vh, 4px); font-size: clamp(8px, min(.78vw, 1.42vh), 10px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upgrade-next { margin-top: 2px; font-size: clamp(7px, min(.65vw, 1.18vh), 8px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upgrade-pips { margin-top: clamp(4px, .9vh, 8px); grid-template-columns: repeat(5, minmax(14px, 52px)); gap: 3px; }
.upgrade-pips i { height: clamp(3px, .7vh, 5px); }
.upgrade-button { min-height: clamp(32px, 5.6vh, 42px); font-size: clamp(7px, min(.7vw, 1.25vh), 9px); align-self: center; }
.garage-actions { margin-top: 0; gap: clamp(4px, .8vmin, 8px); }
.garage-primary-actions { margin-top: 0; }
.garage-actions .primary, .garage-primary-actions .secondary-button { min-height: clamp(36px, 5.8vh, 52px); }
.garage-back-button { min-height: clamp(30px, 4.8vh, 42px); }

/* HUD scales down as both width and height tighten. */
#hud { overflow: hidden; }
.hud-top-left { top: max(clamp(8px, 2vh, 18px), env(safe-area-inset-top)); left: max(clamp(8px, 2vw, 18px), env(safe-area-inset-left)); width: clamp(132px, 17vw, 188px); padding: clamp(7px, 1.2vmin, 12px); }
.score-value { font-size: clamp(21px, min(2.5vw, 4.5vh), 31px); }
.combo-value { font-size: clamp(12px, min(1.4vw, 2.8vh), 17px); }
.hud-route { top: max(clamp(8px, 2vh, 18px), env(safe-area-inset-top)); max-width: min(54vw, 520px); }
.route-card { max-width: 100%; min-width: 0; }
.location-value { max-width: min(18vw, 170px); overflow: hidden; text-overflow: ellipsis; }
.speed-cluster { right: max(clamp(8px, 2vw, 18px), env(safe-area-inset-right)); bottom: max(clamp(8px, 2vh, 18px), env(safe-area-inset-bottom)); width: clamp(170px, 27vw, 300px); }
#speedValue { font-size: clamp(46px, min(8vw, 14vh), 92px); }
.speed-arc { width: clamp(150px, 19vw, 210px); height: clamp(54px, 9vh, 76px); }
.hud-bottom-left { bottom: max(clamp(8px, 2vh, 18px), env(safe-area-inset-bottom)); left: max(clamp(8px, 2vw, 18px), env(safe-area-inset-left)); }

/* Wide/short screens: aggressively compact secondary copy rather than scroll. */
@media (max-height: 620px) {
  .overlay { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .menu-shell, .panel { max-height: calc(100dvh - 16px); }
  .menu-shell { width: min(610px, 88vw); }
  .tagline { max-width: 54ch; }
  .panel { padding: clamp(12px, 2.3vmin, 22px); }
  .info-panel p { margin-top: 7px; line-height: 1.35; }
  .keys { margin-top: 8px; }
  .keys > div { min-height: 34px; }
  .garage-panel { height: calc(100dvh - 16px); padding: 10px 14px; gap: 4px; }
  .garage-copy { display: none; }
  .garage-summary > div { padding-top: 4px; padding-bottom: 4px; }
  .paint-customizer { min-height: 27px; padding-top: 2px; padding-bottom: 2px; }
  .paint-swatch { height: 22px; }
  .upgrade-next { display: none; }
  .upgrade-row { padding-top: 4px; padding-bottom: 4px; }
  .upgrade-pips { margin-top: 4px; }
  .garage-actions .primary, .garage-primary-actions .secondary-button, .garage-back-button { min-height: 34px; }
  .paired-primary-actions .primary, .paired-primary-actions .secondary-button { min-height: 34px; }
  .pause-copy { display: none; }
  .result-badge { margin-bottom: 5px; }
  .retry-hint { display: none; }
}

@media (max-height: 480px) {
  .tagline, .info-panel p, .garage-copy { display: none; }
  .menu-actions { margin-top: 8px; }
  .menu-meta { margin-top: 5px; }
  .eyebrow { margin-bottom: 5px; }
  .secondary-actions { margin-top: 5px; }
  .keys { margin-top: 5px; }
  .keys > div { min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
  .compact-primary { margin-top: 7px; }
  .paired-primary-actions .compact-primary { margin-top: 0; }
  .garage-header { grid-template-columns: minmax(0,1fr) auto; align-items: center; }
  .garage-summary { display: none; }
  .garage-panel { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .garage-panel .garage-summary { display: none; }
  .paint-meta span { display: none; }
  .paint-customizer { min-height: 24px; padding-top: 1px; padding-bottom: 1px; }
  .paint-swatch { height: 20px; }
  .upgrade-effect { margin-top: 1px; }
  .upgrade-pips { margin-top: 2px; }
  .upgrade-button { min-height: 28px; }
  .hud-route { top: 6px; }
}

/* Narrow screens reflow controls/panels but still never scroll. */
@media (max-width: 700px) {
  .overlay.visible { justify-content: center; }
  .menu-shell, .panel, .garage-panel { margin-left: 0; }
  .menu-shell { width: 100%; }
  .menu-secondary-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .secondary-button { letter-spacing: .055em; }
  .garage-header { grid-template-columns: minmax(0,1fr) auto; gap: 8px; }
  .garage-points-box { width: auto; min-width: 96px; display: block; text-align: right; }
  .garage-summary { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .paint-customizer { grid-template-columns: auto minmax(0,1fr); gap: 6px; }
  .paint-meta { min-width: 58px; }
  .paint-meta span { display: none; }
  .upgrade-row { grid-template-columns: minmax(0,1fr) minmax(92px, 27vw); gap: 7px; }
  .keys { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .overlay { padding-left: max(9px, env(safe-area-inset-left)); padding-right: max(9px, env(safe-area-inset-right)); }
  .menu-secondary-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .menu-meta { justify-content: center; }
  .panel { padding: clamp(12px, 4vw, 20px); }
  .garage-panel { padding: 10px; }
  .garage-header { grid-template-columns: minmax(0,1fr) auto; }
  .garage-header h2 { font-size: clamp(23px, 7.5vw, 34px); }
  .garage-points-box { min-width: 84px; padding: 7px 8px; }
  .garage-summary { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 3px; }
  .garage-summary span { font-size: 6px; letter-spacing: .07em; }
  .upgrade-row { grid-template-columns: minmax(0,1fr) 88px; gap: 5px; padding-left: 7px; padding-right: 7px; }
  .upgrade-next { display: none; }
  .keys { grid-template-columns: 1fr; }
  .keys > div { min-height: 34px; }
}

/* Very small portrait phones: remove nonessential copy, preserve all actions. */
@media (max-width: 380px) and (max-height: 700px) {
  .tagline, .info-panel p { display: none; }
  .menu-actions { margin-top: 10px; }
  .menu-secondary-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keys { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .keys > div { min-height: 32px; }
  .key-pair, .key-pair.wide { min-width: 47px; }
  kbd { min-width: 22px; padding: 4px; }
  .garage-summary { display: none; }
  .garage-panel { grid-template-rows: auto minmax(0,1fr) auto; }
  .upgrade-effect { font-size: 7px; }
  .upgrade-row { grid-template-columns: minmax(0,1fr) 78px; }
}

/* Touch layout leaves the road center clear and respects safe areas. */
@media (pointer: coarse), (max-width: 850px) {
  .touch-controls {
    padding:
      0
      max(clamp(10px, 2.5vw, 18px), env(safe-area-inset-right))
      max(clamp(10px, 2.5vh, 18px), env(safe-area-inset-bottom))
      max(clamp(10px, 2.5vw, 18px), env(safe-area-inset-left));
  }
  .steer-button { width: clamp(48px, 13vw, 62px); height: clamp(48px, 13vw, 62px); }
  .brake-button, .nitro-button { min-width: clamp(66px, 18vw, 78px); height: clamp(46px, 12vw, 58px); padding: 0 clamp(9px, 2.5vw, 16px); }
  .touch-utility { top: max(clamp(8px, 2vh, 14px), env(safe-area-inset-top)); right: max(clamp(8px, 2vw, 14px), env(safe-area-inset-right)); }
  .utility-touch-button { min-width: 44px; height: 44px; padding: 0 10px; }
  .speed-cluster { bottom: max(clamp(72px, 16vh, 90px), calc(env(safe-area-inset-bottom) + 68px)); }
  .hud-bottom-left { bottom: max(clamp(76px, 16vh, 94px), calc(env(safe-area-inset-bottom) + 72px)); }
}

@media (pointer: coarse), (max-width: 850px) {
  .audio-toggle { min-width: 58px; height: 40px; padding: 0 8px; font-size: 8px; }
  .touch-utility { top: max(calc(58px + env(safe-area-inset-top)), 58px); }
}
@media (max-height: 480px) and (pointer: coarse), (max-height: 480px) and (max-width: 850px) {
  .audio-toggle { top: max(6px, env(safe-area-inset-top)); height: 34px; }
  .touch-utility { top: max(calc(46px + env(safe-area-inset-top)), 46px); }
}


/* V28: More Games stays beside the primary action in every menu. */
@media (max-width: 480px) {
  .paired-primary-actions { grid-template-columns: minmax(0, 1.35fr) minmax(0, .9fr); gap: 5px; }
  .paired-primary-actions .secondary-button { font-size: 8px; letter-spacing: .045em; }
}

/* ---------- real asset preload state ---------- */
html.preloading .menu-secondary-actions,
html.preloading .menu-meta {
  display: none !important;
}
html.preloading .menu-primary-actions {
  grid-template-columns: minmax(0, 1.45fr) minmax(0, .85fr);
}

/* V28 menu action hierarchy */
@media (max-width: 420px) {
  .menu-primary-actions { grid-template-columns: minmax(0, 1.35fr) minmax(0, .9fr); gap: 5px; }
  .menu-primary-actions .primary { letter-spacing: .08em; }
  .menu-top-more { font-size: 8px; letter-spacing: .045em; }
  .menu-secondary-actions { gap: 5px; }
}
