/* In-race HUD v2 (glass + gold). Loaded after style.css and overrides their race UI.
   Sizes follow one design unit: --u = 1/1920 of a 1920×1080 landscape screen, or 1/430 of a
   430×932 portrait screen, with pixel minimums so buttons stay easy to hit on phones. */
#game-shell {
  --u: min(calc(100vw / 1920), calc(100dvh / 1080));
  --gold: linear-gradient(123deg, #fbe9bd 0%, #ecc989 61%, #dcab73 100%);
  --gold-ball: radial-gradient(circle at 35% 28%, #fff6dc, #f1cf8d 40%, #d9a25e 85%);
  --glass: linear-gradient(150deg, #2b3d54c8, #15243acc);
  --glass-line: #d6e4f04d;
  --cream: #fff4dc;
  --muted: #9fb1c2;
  --hud-font: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --num-font: "Bahnschrift", "DIN Alternate", "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --edge-l: max(calc(36 * var(--u)), env(safe-area-inset-left), 12px);
  --edge-r: max(calc(36 * var(--u)), env(safe-area-inset-right), 12px);
  --edge-t: max(calc(26 * var(--u)), env(safe-area-inset-top), 8px);
  --edge-b: max(calc(24 * var(--u)), env(safe-area-inset-bottom), 10px);
  --tb: max(42px, calc(76 * var(--u)));
  --logo-w: calc(var(--tb) * 2.01);
  --tool: max(38px, calc(54 * var(--u)));
  --steer: max(64px, calc(184 * var(--u)));
  --steer-gap: max(10px, calc(28 * var(--u)));
  --steer-l: max(calc(50 * var(--u)), env(safe-area-inset-left), 14px);
  --steer-b: max(calc(89 * var(--u)), env(safe-area-inset-bottom), 22px);
  --ring: max(54px, calc(96 * var(--u)));
  --slap: max(90px, calc(180 * var(--u)));
  --fan-gap: max(8px, calc(30 * var(--u)));
  --fan-r: max(calc(30 * var(--u)), env(safe-area-inset-right), 12px);
  --fan-b: max(calc(30 * var(--u)), env(safe-area-inset-bottom), 12px);
  --R: calc(var(--slap) / 2 + var(--ring) / 2 + var(--fan-gap));
  --B: calc(var(--slap) / 2 + var(--R) + var(--ring) / 2);
  --prog-l: calc(var(--edge-l) + var(--logo-w) + max(14px, calc(24 * var(--u))));
  --prog-w: clamp(150px, calc(620 * var(--u)), 38vw);
  font-family: var(--hud-font);
}
@media (orientation: portrait) {
  #game-shell {
    --u: min(calc(100vw / 430), calc(100dvh / 932));
    --edge-l: max(calc(12 * var(--u)), env(safe-area-inset-left), 10px);
    --edge-r: max(calc(12 * var(--u)), env(safe-area-inset-right), 10px);
    --edge-t: max(calc(12 * var(--u)), env(safe-area-inset-top), 8px);
    --tb: max(40px, calc(44 * var(--u)));
    --tool: max(34px, calc(36 * var(--u)));
    --steer: max(62px, calc(80 * var(--u)));
    --steer-gap: max(10px, calc(18 * var(--u)));
    --steer-l: max(calc(12 * var(--u)), env(safe-area-inset-left), 10px);
    --steer-b: max(calc(54 * var(--u)), env(safe-area-inset-bottom), 20px);
    --ring: max(50px, calc(52 * var(--u)));
    --slap: max(84px, calc(92 * var(--u)));
    --fan-gap: max(6px, calc(8 * var(--u)));
    --fan-r: max(calc(12 * var(--u)), env(safe-area-inset-right), 10px);
    --fan-b: max(calc(20 * var(--u)), env(safe-area-inset-bottom), 14px);
  }
}
#game-shell .hud-ico { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; pointer-events: none; }
#game-shell .vignette { background: radial-gradient(120% 90% at 50% 45%, transparent 62%, #06101f40 100%), linear-gradient(180deg, #06101f40 0%, transparent 14%, transparent 80%, #06101f55 100%); }

/* ---------- Top bar: logo, tools ---------- */
#game-shell .topbar { position: absolute !important; inset: var(--edge-t) var(--edge-r) auto var(--edge-l) !important; height: var(--tb); display: flex !important; align-items: center !important; justify-content: space-between !important; gap: 10px !important; z-index: 7; pointer-events: none; }
#game-shell .brand { transform: none !important; filter: none !important; flex: none; width: auto !important; height: var(--tb); display: block !important; }
#game-shell .brand .race-logo { display: block; height: var(--tb); width: auto; filter: drop-shadow(0 4px 8px #0008); }
#game-shell .brand-main, #game-shell .brand-sub { position: absolute !important; width: 1px !important; height: 1px !important; overflow: hidden !important; clip-path: inset(50%) !important; white-space: nowrap; margin: 0 !important; padding: 0 !important; }
#game-shell .toolbar { display: flex !important; align-items: center !important; gap: max(6px, calc(10 * var(--u))) !important; margin: 0 !important; pointer-events: auto; flex-wrap: nowrap !important; }
#game-shell .toolbar .icon-button,
#game-shell .toolbar :is(#tilt, #quality, #sound, #pause, #race-ui-toggle, #tilt-center) {
  transform: none !important; margin: 0 !important; display: inline-grid !important; place-items: center !important; place-content: center !important; flex: 0 0 var(--tool) !important;
  width: var(--tool) !important; min-width: var(--tool) !important; max-width: var(--tool) !important; height: var(--tool) !important; padding: 0 !important;
  border-radius: 50% !important; border: 1px solid var(--glass-line) !important; background: var(--glass) !important; color: #eef3f7 !important;
  box-shadow: inset 0 1px 0 #ffffff26, 0 8px 20px #06101f59 !important; -webkit-backdrop-filter: blur(12px) saturate(1.2); backdrop-filter: blur(12px) saturate(1.2);
  font-size: calc(var(--tool) * .44) !important; line-height: 1 !important; text-shadow: none !important; letter-spacing: 0 !important;
}
#game-shell .toolbar [hidden] { display: none !important; }
#game-shell .toolbar #sound { display: none !important; }
#game-shell .toolbar .quality-control { order: 1; position: relative; display: block; }
#game-shell .toolbar #tilt-center { order: 2; }
#game-shell .toolbar #tilt { order: 3; }
#game-shell .toolbar #race-ui-toggle { order: 4; }
#game-shell .toolbar #pause { order: 5; }
#game-shell .toolbar #quality { color: #ffdda0 !important; }
#game-shell .toolbar #quality[aria-expanded="true"] { border-color: #ecc989 !important; box-shadow: inset 0 1px 0 #ffffff26, 0 0 0 4px #ecc98944, 0 8px 20px #06101f59 !important; }
#game-shell .toolbar #tilt[aria-pressed="true"] { color: #ffdda0 !important; border-color: #ecc989 !important; box-shadow: inset 0 1px 0 #ffffff26, 0 0 0 4px #ecc98933, 0 8px 20px #06101f59 !important; }
#game-shell .toolbar #tilt[aria-pressed="true"]::after { content: ""; position: absolute; right: 14%; top: 14%; width: 18%; height: 18%; border-radius: 50%; background: #7fe0a6; box-shadow: 0 0 6px #7fe0a6; }
#game-shell .toolbar #tilt { position: relative; }
#game-shell .toolbar #race-ui-toggle .eye-slash { opacity: 1; }
#game-shell .toolbar #race-ui-toggle[aria-pressed="true"] { color: #ffdda0 !important; border-color: #ecc989 !important; }
#game-shell .toolbar :is(button):hover { filter: brightness(1.12); }
#game-shell .toolbar #pause:active { background: var(--glass) !important; color: #fff !important; }

/* Quality dropdown (the game's #quality-options) */
#game-shell .quality-options { position: absolute !important; top: calc(100% + 10px) !important; right: 0 !important; left: auto !important; width: max(232px, calc(300 * var(--u))) !important; min-width: 0 !important; padding: max(6px, calc(10 * var(--u))) !important; display: grid !important; gap: 2px !important; border-radius: max(14px, calc(22 * var(--u))) !important; border: 1px solid var(--glass-line) !important; background: linear-gradient(150deg, #2b3d54f0, #15243af0) !important; box-shadow: inset 0 1px 0 #ffffff26, 0 14px 32px #06101f80 !important; z-index: 9; transform: none !important; }
#game-shell .quality-options[hidden] { display: none !important; }
#game-shell .quality-options::before { content: '画质'; display: block; margin: 0; padding: 4px 10px 6px; font-size: max(10px, calc(13 * var(--u))); font-weight: 800; letter-spacing: .3em; color: #aebfce; }
#game-shell .quality-options button { display: flex !important; align-items: center; gap: max(10px, calc(14 * var(--u))); width: 100%; min-height: max(44px, calc(60 * var(--u))) !important; padding: 6px max(10px, calc(14 * var(--u))) !important; border-radius: max(10px, calc(14 * var(--u))) !important; background: none !important; color: #eef3f7 !important; text-align: left; font-size: inherit !important; white-space: nowrap; }
#game-shell .quality-options button .hud-ico { font-size: max(20px, calc(28 * var(--u))); color: #c9d6e2; stroke-width: 1.8; }
#game-shell .quality-options .q-text { display: grid; gap: 2px; }
#game-shell .quality-options .q-text b { font-size: max(14px, calc(19 * var(--u))); font-weight: 900; }
#game-shell .quality-options .q-text small { font-size: max(10px, calc(12 * var(--u))); color: var(--muted); font-weight: 700; }
#game-shell .quality-options .q-check { margin-left: auto; width: max(16px, calc(22 * var(--u))); height: max(16px, calc(22 * var(--u))); border-radius: 50%; background: var(--gold); position: relative; display: none; }
#game-shell .quality-options .q-check::after { content: ""; position: absolute; left: 33%; top: 20%; width: 24%; height: 44%; border: solid #3c2e1e; border-width: 0 2px 2px 0; rotate: 45deg; }
#game-shell .quality-options button.current { background: linear-gradient(90deg, #ecc98933, #ecc98910) !important; box-shadow: inset 0 0 0 1px #ecc98980; }
#game-shell .quality-options button.current :is(.hud-ico, b) { color: #ffdda0; }
#game-shell .quality-options button.current .q-check { display: block; }
#game-shell .quality-options button:is(:hover, :focus-visible):not(.current) { background: #ffffff12 !important; color: #fff !important; }
#game-shell .quality-options button:disabled { opacity: .4; }

/* ---------- HUD ---------- */
#game-shell .hud { font-family: var(--hud-font); text-shadow: none; }
#game-shell .hud :is(.position, .speed, .stamina, .hit-count) { transform: none !important; margin: 0 !important; height: auto !important; min-height: 0 !important; }
#game-shell .hud :is(.race-progress, .clock) { transform: none !important; margin: 0 !important; }
/* Progress line next to the logo */
#game-shell .race-progress { position: absolute !important; top: var(--edge-t) !important; left: var(--prog-l) !important; right: auto !important; width: var(--prog-w) !important; max-width: none !important; height: var(--tb) !important; display: flex !important; align-items: center; }
#game-shell .race-progress { gap: max(8px, calc(14 * var(--u))); }
#game-shell .race-progress .progress-copy { display: contents !important; }
#game-shell .race-progress .progress-copy span:not(#distance) { display: none; }
#game-shell #distance { order: 2; flex: none; padding: max(4px, calc(6 * var(--u))) max(9px, calc(13 * var(--u))); border-radius: 99px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--glass-line); color: #fff; font: 800 max(11px, calc(15 * var(--u)))/1 var(--hud-font); text-shadow: none; white-space: nowrap; }
#game-shell .progress-track { order: 1; position: relative !important; flex: 1; min-width: 40px; height: max(5px, calc(8 * var(--u))) !important; border: 0 !important; border-radius: 99px !important; background: #0b1626b3 !important; box-shadow: inset 0 0 0 1px #ffffff1f; }
#game-shell .progress-track > div { background: var(--gold) !important; box-shadow: 0 0 10px #ecc989aa; border-radius: 99px !important; }
#game-shell #progress-bike { position: absolute !important; top: 50% !important; translate: 0 -50%; transform: translateX(-50%) !important; width: max(26px, calc(46 * var(--u))); height: max(26px, calc(46 * var(--u))); padding: max(2px, calc(3 * var(--u))); border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 3px #0b162680, 0 0 14px #ecc989aa; font-size: 0 !important; z-index: 2; }
#game-shell #progress-avatar { display: block; width: 100%; height: 100%; border-radius: 50%; background: #f5f3e9; object-fit: cover; }
/* Time chip */
#game-shell .clock { position: absolute !important; top: var(--edge-t) !important; left: calc(var(--prog-l) + var(--prog-w) + max(28px, calc(40 * var(--u)))) !important; right: auto !important; height: var(--tb); display: flex !important; align-items: center; }
#game-shell .clock > * { position: relative; }
#game-shell .clock { gap: 0; }
#game-shell .clock small, #game-shell .clock strong { text-shadow: none !important; }
#game-shell .clock::before { content: ""; position: absolute; inset: 10% -14px; border-radius: 99px; background: var(--glass); box-shadow: inset 0 0 0 1px var(--glass-line), 0 8px 20px #06101f59; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
#game-shell .clock small { display: inline !important; margin-right: 8px; font-size: max(10px, calc(13 * var(--u))) !important; color: #ffffffa8 !important; letter-spacing: .05em !important; font-weight: 800 !important; }
#game-shell .clock strong { font: 800 max(16px, calc(26 * var(--u)))/1 var(--num-font) !important; color: #fff !important; font-variant-numeric: tabular-nums; }
/* Rank: text only */
#game-shell .position { position: absolute !important; top: calc(var(--edge-t) + var(--tb) + max(8px, calc(22 * var(--u)))) !important; left: var(--edge-l) !important; right: auto !important; display: flex !important; align-items: flex-end !important; gap: max(6px, calc(10 * var(--u))) !important; }
#game-shell .position small { width: auto !important; font-size: max(10px, calc(13 * var(--u))) !important; line-height: 1.15 !important; font-weight: 900 !important; color: #ffdda0 !important; letter-spacing: .08em; width: 2.2em !important; align-self: center; text-shadow: 0 1px 3px #000c; }
#game-shell #rank { font: italic 900 max(30px, calc(52 * var(--u)))/.9 var(--num-font) !important; -webkit-text-stroke: 0 !important; color: #ffe27a !important; background: linear-gradient(#fff6c8, #ffd84a 55%, #f0a93a); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; filter: drop-shadow(0 2px 0 #3a2614) drop-shadow(0 3px 6px #0007); text-shadow: none !important; padding-right: .06em; }
#game-shell #rank em { font: italic 900 max(13px, calc(21 * var(--u)))/1 var(--num-font) !important; -webkit-text-fill-color: #fff; color: #fff !important; margin-left: .2em !important; -webkit-text-stroke: 0 !important; }
/* Speed + riding tip */
#game-shell .speed { position: absolute !important; left: calc(var(--edge-l) + max(4px, calc(8 * var(--u)))) !important; right: auto !important; top: auto !important; bottom: calc(var(--steer-b) + var(--steer) + max(24px, calc(70 * var(--u)))) !important; color: #fff; line-height: 1; }
#game-shell #speed { font: italic 900 max(38px, calc(84 * var(--u)))/1 var(--num-font) !important; letter-spacing: -.02em; -webkit-text-stroke: 0 !important; color: #fff !important; text-shadow: 0 3px 0 #15243a, 0 6px 16px #000a !important; }
#game-shell .speed > span { font: 800 max(11px, calc(20 * var(--u)))/1 var(--hud-font) !important; color: #eef3f7 !important; margin-left: .35em !important; text-shadow: 0 2px 4px #000c !important; }
#game-shell #riding-label { display: flex !important; align-items: center; gap: max(6px, calc(10 * var(--u))); margin-top: max(5px, calc(10 * var(--u))) !important; font: 900 max(11px, calc(19 * var(--u)))/1.2 var(--hud-font) !important; color: #fff !important; text-shadow: 0 1px 3px #000c, 0 0 2px #000a !important; white-space: nowrap; }
#game-shell #riding-label::before { content: ""; width: max(3px, calc(6 * var(--u))); height: 1.25em; border-radius: 99px; background: var(--gold); flex: none; }
/* Stamina: separate bar, bottom centre */
#game-shell .stamina { position: absolute !important; left: 50% !important; right: auto !important; top: auto !important; bottom: max(calc(40 * var(--u)), env(safe-area-inset-bottom), 14px) !important; translate: -50% 0; transform: none !important; width: clamp(180px, calc(440 * var(--u)), 44vw) !important; display: flex !important; flex-direction: column; }
#game-shell .stamina > div:first-child { display: flex !important; justify-content: space-between !important; align-items: baseline !important; margin: 0 0 max(4px, calc(8 * var(--u))) !important; padding: 0 6px; color: #fff; text-shadow: 0 2px 5px #000c; }
#game-shell #boost-label { font: 900 max(11px, calc(16 * var(--u)))/1.2 var(--hud-font) !important; letter-spacing: .12em; color: #fff !important; }
#game-shell #stamina-number { font: 800 max(12px, calc(20 * var(--u)))/1 var(--num-font) !important; color: #fff !important; }
#game-shell .stamina-track { position: relative; height: max(12px, calc(18 * var(--u))) !important; padding: max(2px, calc(3 * var(--u))) !important; border-radius: 99px !important; border: 1px solid #d6e4f066 !important; background: var(--glass) !important; box-shadow: inset 0 1px 0 #ffffff26, 0 8px 20px #06101f66 !important; overflow: hidden; }
#game-shell .stamina-track::before { content: ""; position: absolute; inset: max(2px, calc(3 * var(--u))); border-radius: 99px; background: linear-gradient(90deg, #ff6b5a 0%, #ffad47 22%, #ffe27a 45%, #a8ec8e 70%, #3fd0b8 100%); }
#game-shell #stamina-fill { position: relative; height: 100% !important; background: transparent !important; border-radius: 99px 0 0 99px !important; box-shadow: 0 0 0 100vmax #0b1626e0; clip-path: inset(-100vmax -100vmax -100vmax 0); }
#game-shell .stamina-track::after { content: ""; position: absolute; inset: max(2px, calc(3 * var(--u))); border-radius: 99px; background: linear-gradient(#ffffff50, transparent 55%); pointer-events: none; }
#game-shell #boost-tip { display: block !important; margin-top: max(4px, calc(7 * var(--u))) !important; text-align: center !important; font: 800 max(10px, calc(13 * var(--u)))/1.3 var(--hud-font) !important; color: #ffffffd0 !important; text-shadow: 0 1px 3px #000c !important; }
/* Hits, near the slap button */
#game-shell .hit-count { position: absolute !important; left: auto !important; right: var(--fan-r) !important; top: auto !important; bottom: calc(var(--fan-b) + var(--B) + max(6px, calc(14 * var(--u)))) !important; display: flex !important; align-items: baseline; gap: 6px; text-align: right !important; }
#game-shell #hits { font: italic 900 max(22px, calc(40 * var(--u)))/1 var(--num-font) !important; -webkit-text-stroke: 0 !important; color: #ffe27a !important; text-shadow: 0 2px 0 #3a2614, 0 4px 10px #0008 !important; }
#game-shell #hits::before { content: "×"; font-size: .7em; margin-right: .05em; }
#game-shell .hit-count span { margin: 0 !important; font: 800 max(10px, calc(13 * var(--u)))/1 var(--hud-font) !important; color: #fff !important; text-shadow: 0 1px 3px #000c !important; }
@media (pointer: fine) and (orientation: landscape) {
  #game-shell:not(.layout-editing) .hit-count { bottom: max(calc(50 * var(--u)), 40px) !important; }
}

/* Portrait arrangement */
@media (orientation: portrait) {
  #game-shell { --prog-l: var(--edge-l); }
  #game-shell .race-progress, #game-shell .clock { top: calc(var(--edge-t) + var(--tb) + 8px) !important; height: max(28px, calc(30 * var(--u))) !important; }
  #game-shell .race-progress { width: auto !important; right: calc(var(--edge-r) + max(132px, calc(140 * var(--u)))) !important; }
  #game-shell .clock { left: auto !important; right: calc(var(--edge-r) + 12px) !important; }
  #game-shell .position { top: calc(var(--edge-t) + var(--tb) + max(48px, calc(52 * var(--u)))) !important; }
  #game-shell .stamina { left: var(--steer-l) !important; translate: none; width: calc(var(--steer) * 2 + var(--steer-gap)) !important; bottom: calc(var(--steer-b) + var(--steer) + 14px) !important; }
  #game-shell #boost-tip { order: -1; text-align: left !important; margin: 0 0 6px !important; }
  #game-shell .speed { left: var(--steer-l) !important; bottom: calc(var(--steer-b) + var(--steer) + max(92px, calc(96 * var(--u)))) !important; }
}

/* ---------- Touch controls ---------- */
#game-shell #touch-controls { position: absolute !important; inset: 0 !important; top: 0 !important; bottom: 0 !important; left: 0 !important; right: 0 !important; width: auto !important; height: auto !important; max-height: none !important; min-height: 0 !important; padding: 0 !important; z-index: 4; pointer-events: none; --controls-fit: 1 !important; transform: none !important; }
#game-shell #touch-controls .steering, #game-shell #touch-controls .actions { position: absolute !important; display: block !important; transform: none !important; margin: 0 !important; padding: 0 !important; gap: 0 !important; pointer-events: none; }
#game-shell #touch-controls .steering { left: var(--steer-l) !important; bottom: var(--steer-b) !important; width: calc(var(--steer) * 2 + var(--steer-gap)) !important; height: var(--steer) !important; }
#game-shell #touch-controls .actions { right: var(--fan-r) !important; bottom: var(--fan-b) !important; left: auto !important; width: var(--B) !important; height: var(--B) !important; grid-template-columns: none !important; grid-template-rows: none !important; }
#game-shell #touch-controls button {
  position: absolute !important; display: grid !important; place-content: center !important; justify-items: center; gap: 1px; padding: 0 !important; margin: 0 !important;
  border-radius: 50% !important; border: 0 !important; color: #fff !important; pointer-events: auto; text-align: center;
  background: var(--glass) !important; -webkit-backdrop-filter: blur(12px) saturate(1.2); backdrop-filter: blur(12px) saturate(1.2);
  transform: translate(var(--lx, 0px), var(--ly, 0px)) scale(var(--ls, 1)) !important; opacity: var(--lo, 1); transition: filter .12s, box-shadow .12s;
  font-family: var(--hud-font) !important; line-height: 1.1 !important; flex: none !important; grid-column: auto !important; grid-row: auto !important; align-self: auto !important;
}
#game-shell #touch-controls .steering button { top: 0 !important; width: var(--steer) !important; min-width: 0 !important; max-width: none !important; height: var(--steer) !important; font-size: calc(var(--steer) * .32) !important; box-shadow: inset 0 0 0 1px var(--glass-line), inset 0 1px 0 #ffffff26, 0 10px 26px #06101f59 !important; }
#game-shell #touch-controls [data-hold="left"] { left: 0 !important; }
#game-shell #touch-controls [data-hold="right"] { left: calc(var(--steer) + var(--steer-gap)) !important; }
#game-shell #touch-controls .actions button { width: var(--ring) !important; min-width: 0 !important; max-width: none !important; height: var(--ring) !important; }
#game-shell #touch-controls :is(.jump-touch, .boost-touch, .brake-touch) { box-shadow: inset 0 0 0 max(2px, calc(var(--ring) * .03)) var(--c), inset 0 1px 0 #ffffff30, 0 10px 24px #06101f66 !important; }
#game-shell #touch-controls .boost-touch { --c: #6fc3ff; left: calc(var(--B) - var(--slap) / 2 - var(--ring) / 2) !important; top: 0 !important; }
#game-shell #touch-controls .jump-touch { --c: #7fe0a6; left: calc(var(--B) - var(--slap) / 2 - var(--R) * .7071 - var(--ring) / 2) !important; top: calc(var(--B) - var(--slap) / 2 - var(--R) * .7071 - var(--ring) / 2) !important; }
#game-shell #touch-controls .brake-touch { --c: #ff8a7a; left: 0 !important; top: calc(var(--B) - var(--slap) / 2 - var(--ring) / 2) !important; }
#game-shell #touch-controls .actions button b { font-size: calc(var(--ring) * .22) !important; font-weight: 900; letter-spacing: .04em; line-height: 1.15 !important; }
#game-shell #touch-controls .actions button small { display: block !important; margin: 0 !important; font-size: max(8px, calc(var(--ring) * .12)) !important; font-weight: 700; opacity: .78 !important; white-space: nowrap; line-height: 1.2 !important; }
#game-shell #touch-controls .actions .slap-touch { right: 0 !important; bottom: 0 !important; left: auto !important; top: auto !important; width: var(--slap) !important; height: var(--slap) !important; background: var(--gold-ball) !important; color: #3a2614 !important; box-shadow: inset 0 0 0 max(3px, calc(var(--slap) * .022)) #fff3d0, 0 0 0 max(5px, calc(var(--slap) * .055)) #ecc98933, inset 0 -6px 14px #9c6b3355, 0 14px 30px #06101f80 !important; -webkit-backdrop-filter: none; backdrop-filter: none; }
#game-shell #touch-controls .slap-touch b { font-size: calc(var(--slap) * .24) !important; font-weight: 900; }
#game-shell #touch-controls .slap-touch small { font-size: max(8px, calc(var(--slap) * .07)) !important; color: #6b4a22; opacity: 1 !important; font-weight: 700; }
#game-shell #touch-controls button.active, #game-shell #touch-controls .slap-touch:active { filter: brightness(1.25); box-shadow: inset 0 0 0 99px #ffffff22, 0 0 0 4px #ffdda055, 0 6px 14px #06101f66 !important; transform: translate(var(--lx, 0px), var(--ly, 0px)) scale(calc(var(--ls, 1) * .95)) !important; }
#game-shell #touch-controls .slap-touch:active { box-shadow: inset 0 0 0 3px #fff3d0, 0 0 0 8px #ecc98966 !important; }
#game-shell.friendly-race #touch-controls [data-brawl-only] { display: none !important; }

/* ---------- Desktop key guide ---------- */
#game-shell #desktop-controls { gap: max(12px, calc(20 * var(--u))) !important; padding: 8px 18px; border-radius: 99px; background: #0b162680; box-shadow: inset 0 0 0 1px #ffffff1c; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); bottom: max(calc(14 * var(--u)), 8px) !important; color: #eef3f7 !important; }
#game-shell #desktop-controls kbd { background: #ffffff14 !important; border-color: #ffffff55 !important; color: #fff; border-radius: 5px; }
#game-shell.key-hints-off #desktop-controls { display: none !important; }
@media (pointer: fine) and (orientation: landscape) {
  #game-shell:not(.key-hints-off) .stamina { bottom: max(calc(84 * var(--u)), 58px) !important; }
}

/* ---------- Countdown / finish ---------- */
#game-shell #countdown { font-family: var(--num-font); color: #ffe27a !important; -webkit-text-stroke: max(3px, calc(5 * var(--u))) #3a2614 !important; text-shadow: 0 8px 24px #0008 !important; }
#game-shell #finish-banner { color: #ffe27a !important; text-shadow: 0 3px 0 #3a2614, 0 6px 16px #0009 !important; }
#game-shell #finish-banner > b { -webkit-text-stroke: 0 !important; }

/* ---------- Dialog cards: pause, settings, result ---------- */
#game-shell .overlay.dim { background: radial-gradient(ellipse at 50% 50%, #0b162699, #06101fd9) !important; -webkit-backdrop-filter: blur(10px) saturate(.9) !important; backdrop-filter: blur(10px) saturate(.9) !important; }
#game-shell :is(#paused, #result, #race-settings) .dialog {
  max-width: none; width: min(calc(100vw - 32px), max(340px, calc(560 * var(--u)))); padding: max(18px, calc(30 * var(--u))) max(18px, calc(34 * var(--u))) max(18px, calc(28 * var(--u)));
  border: 0 !important; border-radius: max(20px, calc(32 * var(--u))) !important; color: var(--cream) !important; text-align: center;
  background: linear-gradient(160deg, #2b3d54ee, #13213aee) !important; box-shadow: inset 0 1px 0 #ffffff2a, 0 0 0 1px #d6e4f040, 0 30px 70px #000a !important;
  font-family: var(--hud-font); max-height: calc(100dvh - 24px); overflow: auto;
}
#game-shell :is(#paused, #result) .dialog-tag { display: block; font-size: max(11px, calc(14 * var(--u))) !important; font-weight: 800 !important; letter-spacing: .2em; color: #aebfce !important; }
#game-shell :is(#paused, #result) h2 { margin: max(4px, calc(6 * var(--u))) 0 0 !important; font-size: max(28px, calc(46 * var(--u))) !important; font-weight: 900; letter-spacing: .12em !important; background: var(--gold); -webkit-background-clip: text; background-clip: text; color: transparent !important; }
#game-shell .pause-stats, #game-shell #result .result-stats { display: grid !important; grid-template-columns: repeat(3, 1fr); margin: max(14px, calc(22 * var(--u))) 0 max(16px, calc(24 * var(--u))) !important; padding: max(10px, calc(14 * var(--u))) 0 !important; border-block: 1px solid #ffffff1c !important; }
#game-shell #result .result-stats { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
#game-shell .pause-stats div + div, #game-shell #result .result-stats div + div { border-left: 1px solid #ffffff1c; }
#game-shell .pause-stats small, #game-shell #result .result-stats small { display: block; font-size: max(10px, calc(12 * var(--u))) !important; font-weight: 800; letter-spacing: .12em; color: var(--muted) !important; }
#game-shell .pause-stats b, #game-shell #result .result-stats strong { display: block; margin-top: 4px; font: 800 max(18px, calc(30 * var(--u)))/1.1 var(--num-font) !important; color: #fff; order: -1; }
#game-shell #result .result-stats div { display: flex; flex-direction: column-reverse; gap: 4px; }
#game-shell .pause-stats b span { font-size: .55em; color: var(--muted); }
#game-shell :is(#paused, #result, #race-settings) .primary-button,
#game-shell :is(#paused, #result, #race-settings) .secondary-button {
  display: flex; align-items: center; justify-content: center; gap: max(8px, calc(12 * var(--u))); width: 100%; min-width: 0 !important; margin: 0 !important;
  height: max(46px, calc(68 * var(--u))); padding: 0 16px !important; border-radius: max(14px, calc(20 * var(--u))) !important; transform: none !important;
  font: 900 max(14px, calc(21 * var(--u)))/1 var(--hud-font) !important; letter-spacing: .08em !important; text-decoration: none !important;
  color: #eef3f7 !important; background: #ffffff10 !important; border: 0 !important; box-shadow: inset 0 0 0 1px #ffffff26 !important;
}
#game-shell :is(#paused, #result, #race-settings) .primary-button { height: max(52px, calc(80 * var(--u))); font-size: max(16px, calc(26 * var(--u))) !important; color: #3a2614 !important; background: radial-gradient(circle at 30% 20%, #fff6dc, #f1cf8d 45%, #d9a25e 100%) !important; box-shadow: inset 0 0 0 max(2px, calc(3 * var(--u))) #fff3d0, 0 0 0 max(4px, calc(6 * var(--u))) #ecc98926, 0 12px 26px #06101f80 !important; }
#game-shell :is(#paused, #result, #race-settings) :is(.primary-button, .secondary-button):hover { filter: brightness(1.08); }
#game-shell :is(#paused, #result, #race-settings) .hud-ico { font-size: 1.15em; }
#game-shell .pause-grid { display: grid; grid-template-columns: 1fr 1fr; gap: max(8px, calc(12 * var(--u))); margin: max(10px, calc(14 * var(--u))) 0; }
#game-shell #result .result-place { margin-top: max(8px, calc(12 * var(--u))); font-size: max(16px, calc(22 * var(--u))) !important; color: #fff; font-weight: 900; }
#game-shell #result .result-place b { font: italic 900 max(54px, calc(84 * var(--u)))/1 var(--num-font) !important; color: #ffe27a !important; background: linear-gradient(#fff6c8, #ffd84a 55%, #f0a93a); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; filter: drop-shadow(0 3px 0 #3a2614); padding: 0 .06em; }
#game-shell #result-line { color: #c9d6e2 !important; font-size: max(12px, calc(15 * var(--u))) !important; }
#game-shell #result .result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: max(8px, calc(12 * var(--u))); }
#game-shell #result .result-actions #back { color: #eef3f7 !important; background: #ffffff10 !important; box-shadow: inset 0 0 0 1px #ffffff26 !important; height: max(52px, calc(80 * var(--u))); }

/* In-race settings */
#game-shell #race-settings { z-index: 9; display: flex; align-items: center; justify-content: center; }
#game-shell #race-settings[hidden] { display: none !important; }
#game-shell #race-settings .settings-card { width: min(calc(100vw - 24px), max(560px, calc(860 * var(--u)))); padding: 0; text-align: left; display: flex; flex-direction: column; overflow: hidden; }
#game-shell .settings-head { position: relative; padding: max(14px, calc(22 * var(--u))) 20px max(10px, calc(14 * var(--u))); text-align: center; border-bottom: 1px solid #ffffff1a; }
#game-shell .settings-head h2 { margin: 0; font-size: max(18px, calc(30 * var(--u))); font-weight: 900; letter-spacing: .14em; color: var(--cream); }
#game-shell .settings-back { position: absolute; left: max(12px, calc(22 * var(--u))); top: 50%; translate: 0 -50%; width: max(34px, calc(48 * var(--u))); height: max(34px, calc(48 * var(--u))); border-radius: 50%; display: grid; place-items: center; padding: 0; font-size: max(15px, calc(22 * var(--u))); background: #ffffff12; box-shadow: inset 0 0 0 1px #ffffff2a; color: #eef3f7; }
#game-shell .settings-body { padding: 4px max(16px, calc(36 * var(--u))) 4px; overflow: auto; display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "display controls" "sound controls"; gap: 0 max(20px, calc(44 * var(--u))); align-items: start; }
#game-shell .settings-display { grid-area: display; } #game-shell .settings-controls { grid-area: controls; } #game-shell .settings-sound { grid-area: sound; }
#game-shell .settings-body h3 { margin: max(10px, calc(14 * var(--u))) 0 2px; font-size: max(10px, calc(14 * var(--u))); font-weight: 800; letter-spacing: .3em; color: #ffdda0; }
#game-shell .settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: max(48px, calc(66 * var(--u))); border-bottom: 1px solid #ffffff14; }
#game-shell .settings-row > div { display: grid; gap: 2px; }
#game-shell .settings-row > div b { font-size: max(13.5px, calc(19 * var(--u))); font-weight: 860; color: var(--cream); }
#game-shell .settings-row > div small { font-size: max(10px, calc(13 * var(--u))); color: var(--muted); font-weight: 650; }
#game-shell .settings-stack { flex-direction: column; align-items: stretch; gap: 10px; padding: 10px 0 14px; }
#game-shell .settings-highlight { margin: 4px max(-8px, calc(-14 * var(--u))) 0; padding: 0 max(8px, calc(14 * var(--u))); border-radius: max(10px, calc(16 * var(--u))); background: linear-gradient(90deg, #ecc98926, #ecc9890a); box-shadow: inset 0 0 0 1px #ecc98966; border-bottom: 0; }
#game-shell:not(.touch-device) .touch-only-row { display: none; }
#game-shell .settings-seg { display: flex; gap: 4px; padding: 4px; border-radius: 99px; background: #0b1626b3; box-shadow: inset 0 0 0 1px #ffffff1f; }
#game-shell .settings-seg button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: max(34px, calc(46 * var(--u))); padding: 0 6px; border-radius: 99px; background: none; color: #c9d6e2; font-size: max(12px, calc(17 * var(--u))); font-weight: 860; }
#game-shell .settings-seg button .hud-ico { font-size: 1.15em; }
#game-shell .settings-seg button[aria-checked="true"] { background: var(--gold); color: #3c2e1e; box-shadow: 0 4px 12px #0005; }
#game-shell .settings-seg button:disabled { opacity: .4; }
#game-shell .settings-gold { display: flex; align-items: center; gap: 6px; height: max(34px, calc(46 * var(--u))); padding: 0 max(12px, calc(20 * var(--u))); border-radius: 99px; font-size: max(12.5px, calc(17 * var(--u))); font-weight: 900; color: #3c2e1e; background: var(--gold); box-shadow: 0 4px 12px #0005; flex: none; }
#game-shell .settings-switch { position: relative; flex: none; width: max(44px, calc(64 * var(--u))); height: max(25px, calc(36 * var(--u))); padding: 0; border-radius: 99px; background: #ffffff26; transition: background .2s; }
#game-shell .settings-switch i { position: absolute; left: 3px; top: 50%; translate: 0 -50%; width: calc(max(25px, calc(36 * var(--u))) - 6px); aspect-ratio: 1; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px #0006; transition: left .2s; }
#game-shell .settings-switch[aria-checked="true"] { background: #7fe0a6; }
#game-shell .settings-switch[aria-checked="true"] i { left: calc(100% - max(25px, calc(36 * var(--u))) + 3px); }
#game-shell .settings-range { display: flex; align-items: center; gap: 10px; width: max(160px, calc(220 * var(--u))); }
#game-shell .settings-range output { width: 2.2em; text-align: right; font: 800 max(11px, calc(16 * var(--u)))/1 var(--num-font); color: #fff; }
#game-shell :is(.settings-range, .layout-slider) input[type="range"] { flex: 1; min-width: 0; height: 22px; margin: 0; appearance: none; -webkit-appearance: none; background: transparent; --fill: 50%; }
#game-shell :is(.settings-range, .layout-slider) input[type="range"]::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: linear-gradient(90deg, #ecc989 var(--fill), #ffffff26 var(--fill)); }
#game-shell :is(.settings-range, .layout-slider) input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: linear-gradient(90deg, #ecc989 var(--fill), #ffffff26 var(--fill)); }
#game-shell :is(.settings-range, .layout-slider) input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: #fff4dc; box-shadow: 0 0 0 3px #ecc989, 0 2px 6px #0007; }
#game-shell :is(.settings-range, .layout-slider) input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: 0; border-radius: 50%; background: #fff4dc; box-shadow: 0 0 0 3px #ecc989, 0 2px 6px #0007; }
#game-shell .settings-foot { display: flex; justify-content: space-between; gap: 12px; padding: max(12px, calc(16 * var(--u))) max(16px, calc(30 * var(--u))) max(14px, calc(22 * var(--u))); border-top: 1px solid #ffffff1a; }
#game-shell .settings-foot .secondary-button { width: auto !important; height: max(40px, calc(54 * var(--u))) !important; font-size: max(13px, calc(18 * var(--u))) !important; }
#game-shell .settings-foot .primary-button { width: auto !important; min-width: max(130px, calc(200 * var(--u))) !important; height: max(40px, calc(54 * var(--u))) !important; font-size: max(13px, calc(18 * var(--u))) !important; }
@media (orientation: portrait) {
  #game-shell .settings-body { grid-template-columns: 1fr; grid-template-areas: "display" "controls" "sound"; }
  #game-shell .settings-row:not(.settings-stack):not(.settings-highlight) { flex-wrap: wrap; padding: 6px 0; }
}

/* ---------- Touch layout editor ---------- */
#game-shell #layout-editor { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
#game-shell #layout-editor[hidden] { display: none; }
#game-shell.layout-editing::after { content: ""; position: absolute; inset: 0; z-index: 2; background: #06101fa8; pointer-events: none; }
#game-shell.layout-editing #touch-controls, #game-shell.layout-editing #touch-controls[hidden] { display: block !important; z-index: 4; }
#game-shell.layout-editing #touch-controls [data-brawl-only] { display: grid !important; }
#game-shell.layout-editing :is(#hud, .topbar, #desktop-controls, #cb-menu-host, #paused, #result, #countdown, #speech-layer) { visibility: hidden; }
#game-shell.layout-editing #touch-controls button { outline: max(2px, calc(2 * var(--u))) dashed #ffffffb0; outline-offset: max(5px, calc(8 * var(--u))); cursor: grab; touch-action: none; }
#game-shell.layout-editing #touch-controls button.layout-selected { outline-color: #ecc989; outline-width: max(3px, calc(3 * var(--u))); }
#game-shell #layout-editor .layout-bar { position: absolute; z-index: 6; left: 50%; top: var(--edge-t); translate: -50% 0; pointer-events: auto; display: flex; align-items: center; gap: max(8px, calc(12 * var(--u))); padding: max(8px, calc(10 * var(--u))) max(8px, calc(12 * var(--u))) max(8px, calc(10 * var(--u))) max(16px, calc(26 * var(--u))); border-radius: 99px; background: linear-gradient(150deg, #2b3d54f0, #15243af0); box-shadow: inset 0 1px 0 #ffffff26, 0 0 0 1px #d6e4f040, 0 14px 32px #06101f80; white-space: nowrap; color: var(--cream); }
#game-shell #layout-editor .layout-bar > div { display: grid; margin-right: max(8px, calc(18 * var(--u))); }
#game-shell #layout-editor .layout-bar b { font-size: max(14px, calc(20 * var(--u))); font-weight: 900; }
#game-shell #layout-editor .layout-bar small { font-size: max(10px, calc(13 * var(--u))); color: #aebfce; font-weight: 700; }
#game-shell #layout-editor :is(.primary-button, .secondary-button) { display: flex; align-items: center; justify-content: center; height: max(38px, calc(50 * var(--u))); padding: 0 max(14px, calc(26 * var(--u))) !important; margin: 0 !important; min-width: 0 !important; border-radius: 99px !important; border: 0 !important; transform: none !important; font: 900 max(13px, calc(17 * var(--u)))/1 var(--hud-font) !important; letter-spacing: .06em; text-decoration: none !important; color: #eef3f7 !important; background: #ffffff12 !important; box-shadow: inset 0 0 0 1px #ffffff2a !important; }
#game-shell #layout-editor .primary-button { min-width: max(90px, calc(170 * var(--u))) !important; color: #3a2614 !important; background: var(--gold) !important; box-shadow: 0 6px 16px #0006 !important; }
#game-shell #layout-editor .layout-panel { position: absolute; z-index: 6; left: 50%; top: 50%; translate: -50% -50%; width: max(240px, calc(330 * var(--u))); padding: max(10px, calc(16 * var(--u))) max(14px, calc(22 * var(--u))); border-radius: max(16px, calc(22 * var(--u))); display: grid; gap: max(8px, calc(12 * var(--u))); pointer-events: auto; background: linear-gradient(150deg, #2b3d54f0, #15243af0); box-shadow: inset 0 1px 0 #ffffff26, 0 0 0 1px #d6e4f040, 0 14px 32px #06101f80; color: var(--cream); }
#game-shell #layout-editor .layout-panel[hidden] { display: none; }
#game-shell .layout-panel-title { display: flex; align-items: baseline; justify-content: space-between; }
#game-shell .layout-panel-title b { font-size: max(14px, calc(20 * var(--u))); font-weight: 900; color: #ffdda0; }
#game-shell .layout-panel-title small { font-size: max(10px, calc(13 * var(--u))); color: var(--muted); font-weight: 700; }
#game-shell .layout-slider { display: grid; grid-template-columns: 3.2em 1fr 3.2em; align-items: center; gap: 8px; font-size: max(11px, calc(15 * var(--u))); font-weight: 800; color: #c9d6e2; }
#game-shell .layout-slider output { text-align: right; color: #fff; font-family: var(--num-font); }
@media (orientation: portrait) {
  #game-shell #layout-editor .layout-bar { flex-wrap: wrap; justify-content: flex-end; width: calc(100vw - 24px); border-radius: 18px; white-space: normal; }
  #game-shell #layout-editor .layout-bar > div { flex-basis: 100%; margin: 0 0 2px; }
  #game-shell #layout-editor .layout-panel { top: 38%; }
}

/* ---------- Menu host, race loading card, exited screen ---------- */
#game-shell #cb-menu-host { position: absolute; inset: 0; z-index: 10; }
#game-shell #cb-menu-host[hidden] { display: none; }
#game-shell #cb-menu-host > .cb-menu { block-size: 100%; }
#game-shell .cb-race-loading, #game-shell .cb-exited { position: absolute; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 50%, #0b1626b3, #06101fe6); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); font-family: var(--hud-font); color: var(--cream); }
#game-shell .cb-race-loading[hidden], #game-shell .cb-exited[hidden] { display: none; }
#game-shell .cb-race-loading-card, #game-shell .cb-exited-card { width: min(calc(100vw - 32px), max(320px, calc(520 * var(--u)))); padding: max(16px, calc(24 * var(--u))); border-radius: max(20px, calc(28 * var(--u))); text-align: center; background: linear-gradient(160deg, #2b3d54ee, #13213aee); box-shadow: inset 0 1px 0 #ffffff2a, 0 0 0 1px #d6e4f040, 0 30px 70px #000a; }
#game-shell .cb-race-loading-cover { display: block; width: 100%; aspect-ratio: 16 / 8; object-fit: cover; border-radius: max(12px, calc(18 * var(--u))); box-shadow: inset 0 0 0 1px #ffffff2a; background: #15243a; }
#game-shell .cb-race-loading-card h2 { margin: max(12px, calc(18 * var(--u))) 0 4px; font-size: max(20px, calc(32 * var(--u))); font-weight: 900; letter-spacing: .1em; background: var(--gold); -webkit-background-clip: text; background-clip: text; color: transparent; }
#game-shell .cb-race-loading-card p { margin: 0 0 max(12px, calc(16 * var(--u))); min-height: 1.4em; font-size: max(12px, calc(16 * var(--u))); color: #c9d6e2; font-weight: 700; }
#game-shell .cb-race-loading-bar { height: 10px; padding: 2px; border-radius: 99px; background: #0b1626b3; box-shadow: inset 0 0 0 1px #ffffff26; overflow: hidden; }
#game-shell .cb-race-loading-bar i { display: block; height: 100%; border-radius: 99px; background: var(--gold); transform-origin: left; transform: scaleX(0); transition: transform .25s ease; box-shadow: 0 0 10px #ecc989aa; }
#game-shell .cb-race-loading-percent { display: block; margin-top: 8px; font: 800 max(13px, calc(18 * var(--u)))/1 var(--num-font); color: #fff; }
#game-shell .cb-race-loading-actions { display: flex; justify-content: center; gap: 10px; margin-top: max(12px, calc(18 * var(--u))); }
#game-shell .cb-race-loading-actions button, #game-shell .cb-exited-back { height: max(40px, calc(52 * var(--u))); padding: 0 max(20px, calc(32 * var(--u))); border: 0; border-radius: 99px; font: 900 max(13px, calc(17 * var(--u)))/1 var(--hud-font); letter-spacing: .08em; color: #eef3f7; background: #ffffff12; box-shadow: inset 0 0 0 1px #ffffff2a; cursor: pointer; }
#game-shell .cb-race-loading-retry, #game-shell .cb-exited-back { color: #3a2614 !important; background: var(--gold) !important; box-shadow: 0 6px 16px #0006 !important; }
#game-shell .cb-race-loading-retry[hidden] { display: none; }
#game-shell .cb-exited-card img { width: min(60%, 260px); filter: drop-shadow(0 6px 14px #0008); }
#game-shell .cb-exited-card h2 { margin: 10px 0 4px; font-size: max(22px, calc(34 * var(--u))); font-weight: 900; letter-spacing: .12em; }
#game-shell .cb-exited-card p { margin: 0 0 18px; color: #c9d6e2; font-weight: 700; }

/* ---------- Fixes: visibility rules that the !important sizing above must not override ---------- */
#game-shell .toolbar :is(#tilt, #tilt-center).mobile-only { display: none !important; }
@media (any-pointer: coarse), (max-width: 760px), (max-width: 900px) and (max-height: 520px), (max-width: 900px) and (orientation: portrait) {
  #game-shell .toolbar :is(#tilt, #tilt-center).mobile-only:not([hidden]) { display: inline-grid !important; }
}
#game-shell .toolbar :is(#tilt, #tilt-center).mobile-only[hidden] { display: none !important; }
#game-shell.race-ui-hidden .brand,
#game-shell.race-ui-hidden .toolbar > :not(#race-ui-toggle):not(#pause) { display: none !important; }
#game-shell .settings-row > .settings-seg { display: flex; }
#game-shell.race-ui-hidden :is(.brand, #hud, #desktop-controls, #touch-controls, #speech-layer, #countdown, #finish-banner, #result, #speed-lines, #hit-flash, .vignette) { display: none !important; }
#game-shell.race-ui-hidden .topbar { justify-content: flex-end !important; }
@media (max-height: 520px) {
  #game-shell .settings-row { min-height: 40px; }
  #game-shell .settings-body h3 { margin-top: 8px; }
  #game-shell .settings-stack { padding: 6px 0 8px; gap: 6px; }
}

#game-shell .toolbar { position: relative; }
#game-shell .toolbar .quality-control { position: static !important; }
#game-shell .position small { white-space: normal !important; }
#game-shell #riding-label { position: static !important; }
@media (orientation: portrait) {
  #game-shell .clock small { display: none !important; }
  #game-shell .race-progress { right: calc(var(--edge-r) + max(96px, calc(104 * var(--u)))) !important; }
  #game-shell :is(#paused, #result) .pause-grid .secondary-button { font-size: 15px !important; white-space: nowrap; padding: 0 8px !important; }
  #game-shell .pause-stats b { font-size: 19px !important; white-space: nowrap; }
}
@media (orientation: portrait) {
  #game-shell .speed { bottom: calc(var(--steer-b) + var(--steer) + max(124px, calc(128 * var(--u)))) !important; }
  #game-shell .race-progress { right: calc(var(--edge-r) + max(116px, calc(124 * var(--u)))) !important; }
  #game-shell #distance { font-size: 11px !important; padding: 4px 8px !important; }
}
@media (orientation: portrait) {
  #game-shell #speed { font-size: max(40px, calc(50 * var(--u))) !important; }
  #game-shell .speed > span { font-size: max(11px, calc(13 * var(--u))) !important; }
  #game-shell .speed { bottom: calc(var(--steer-b) + var(--steer) + max(112px, calc(116 * var(--u)))) !important; }
}
#game-shell .toolbar :is(#tilt, #quality, #sound, #pause, #race-ui-toggle, #tilt-center)[hidden] { display: none !important; }
#game-shell .toolbar #quality::after, #game-shell .toolbar #quality::before { display: none !important; content: none !important; }
/* The menu sits on a solid backdrop so the 3D scene never shows through during page changes. */
#game-shell #cb-menu-host { background: #0b1626; }
/* Switches match the home settings: gold when on. */
#game-shell .settings-switch[aria-checked="true"] { background: linear-gradient(123deg, #fbe9bd, #ecc989 61%, #dcab73); }
#game-shell .settings-switch[aria-checked="true"] i { background: #fff8e8; }
/* Quality button: screen icon + gold tag with the current level (no per-level icons). */
#game-shell .toolbar #quality { position: relative; overflow: visible !important; color: #eef3f7 !important; }
#game-shell .toolbar #quality .hud-ico { font-size: calc(var(--tool) * .46); }
#game-shell .toolbar #quality .q-tag { position: absolute; right: -14%; bottom: -16%; padding: 2px 6px; border-radius: 99px; background: var(--gold); color: #3c2e1e; font: 900 max(9.5px, calc(12 * var(--u)))/1.15 var(--hud-font); letter-spacing: .02em; white-space: nowrap; box-shadow: 0 3px 8px #0006; pointer-events: none; }
#game-shell .quality-options button { padding-left: max(14px, calc(18 * var(--u))) !important; }
#game-shell .settings-row:has(> .settings-switch) { flex-wrap: nowrap !important; }
/* Open eye while the race UI shows; slashed eye once it is hidden. */
#game-shell .toolbar #race-ui-toggle:not([aria-pressed="true"]) .eye-slash { display: none; }
#game-shell.race-ui-hidden .toolbar #pause:not([hidden]) { display: inline-grid !important; }
/* The menu button and its pause/settings screens still work while the race UI is hidden. */
#game-shell.race-ui-hidden #paused:not([hidden]), #game-shell.race-ui-hidden #race-settings:not([hidden]) { display: flex !important; }

/* ---------- Controller hints: replace the keyboard guide after a controller is used ---------- */
#game-shell #gamepad-controls { display: none; position: absolute; left: 50%; translate: -50% 0; bottom: max(calc(14 * var(--u)), 8px); z-index: 3; align-items: center; gap: max(12px, calc(20 * var(--u))); padding: 8px 18px; border-radius: 99px; background: #0b162680; box-shadow: inset 0 0 0 1px #ffffff1c; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); color: #eef3f7; font: 800 max(11px, calc(14 * var(--u)))/1 var(--hud-font); white-space: nowrap; pointer-events: none; }
#game-shell #gamepad-controls span { display: inline-flex; align-items: center; gap: 6px; }
#game-shell #gamepad-controls .pad-btn { display: inline-grid; place-items: center; min-width: 1.9em; height: 1.9em; padding: 0 .45em; box-sizing: border-box; border: 1px solid #ffffff55; background: #ffffff14; color: #fff; font: 900 .82em/1 var(--num-font); font-style: normal; }
#game-shell #gamepad-controls .pad-face { border-radius: 50%; padding: 0; width: 1.9em; color: #ffdda0; border-color: #ecc98999; }
#game-shell #gamepad-controls .pad-bumper { border-radius: 6px; }
#game-shell.input-gamepad #hud:not([hidden]) ~ #gamepad-controls { display: flex; }
#game-shell.input-gamepad #desktop-controls { display: none !important; }
#game-shell.input-gamepad:not(.layout-editing) #touch-controls { display: none !important; }
#game-shell.key-hints-off #gamepad-controls, #game-shell.race-ui-hidden #gamepad-controls, #game-shell.layout-editing #gamepad-controls { display: none !important; }
#game-shell.friendly-race #gamepad-controls [data-brawl-only] { display: none; }
#game-shell.input-gamepad .stamina { bottom: max(calc(84 * var(--u)), 58px) !important; }
#game-shell.input-gamepad.key-hints-off .stamina { bottom: max(calc(40 * var(--u)), 14px) !important; }
/* Controller focus ring on pages. */
.input-gamepad .pad-focus, .input-gamepad ~ * .pad-focus { outline: 3px solid #ffdda0 !important; outline-offset: 3px !important; }
#game-shell.input-gamepad #gamepad-controls { gap: max(10px, calc(16 * var(--u))); }
