:root {
  --s: 1;
  --dark-a: rgba(12, 19, 28, .78);
  --muted: #8FA3B4;
  --white: #F3F6EF;
  --accent: #FFD05A;
  --ink: #1B2526;
  --line: rgba(255, 255, 255, .12);
  --nitro: #38E1FF;
  --bg: #0A0F15;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  font-weight: 700; color: var(--white);
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
small { display: block; font-size: 12px; color: var(--muted); letter-spacing: .04em; }
button { font: inherit; color: inherit; border: 0; background: none; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.touch-help { display: none; }

.panel {
  background: var(--dark-a); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .3), 0 10px 24px rgba(0, 0, 0, .25);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.btn { font-size: 22px; color: var(--ink); border-radius: 16px; cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .3); transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); }
.btn.accent { background: var(--accent); }
.btn.light { background: #DDE5DE; }
.btn.icon { width: 54px; height: 54px; background: rgba(221, 229, 222, .92); }
.btn.icon.accent { background: var(--accent); }
.btn.icon.off { opacity: .45; text-decoration: line-through; }


/* ---------- HUD: 1280x720 design pixels, each group scales from the corner it is pinned to ---------- */
#hud, #tags { position: fixed; inset: 0; pointer-events: none; }
.anchor { position: absolute; transform: scale(var(--s)); }
.anchor button { pointer-events: auto; }
.tl { left: calc(26px * var(--s)); top: calc(20px * var(--s)); transform-origin: 0 0; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.tr { right: calc(26px * var(--s)); top: calc(20px * var(--s)); transform-origin: 100% 0; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.tc { left: 50%; top: calc(24px * var(--s)); transform: translateX(-50%) scale(var(--s)); transform-origin: 50% 0; display: flex; flex-direction: column; align-items: center; gap: 64px; }
.bc { left: 50%; bottom: calc(10px * var(--s)); transform: translateX(-50%) scale(var(--s)); transform-origin: 50% 100%; }
.bl { left: calc(24px * var(--s)); bottom: calc(24px * var(--s)); transform-origin: 0 100%; display: flex; gap: 16px; align-items: flex-end; }
.br { right: calc(18px * var(--s)); bottom: calc(14px * var(--s)); transform-origin: 100% 100%; }
kbd { position: absolute; bottom: 9px; left: 50%; transform: translateX(-50%); font: 700 10px/1 "Microsoft YaHei", sans-serif;
  padding: 3px 6px; border-radius: 5px; background: rgba(255, 255, 255, .14); color: rgba(255, 255, 255, .85); display: none; }
body.kb kbd { display: block; }

/* Position badge, lap strip, standings: slanted racing panels. */
.pos-badge { display: flex; align-items: baseline; gap: 4px; height: 82px; padding: 0 40px 0 16px; color: #14191B;
  background: linear-gradient(100deg, #FFE07A, #FFB23A 70%, #FF8A2A); clip-path: polygon(0 0, 100% 0, 86% 100%, 0 100%);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .45)); }
.pos-badge .pos-p { font: 900 12px/1 "Microsoft YaHei"; letter-spacing: .12em; align-self: center; writing-mode: vertical-rl; transform: rotate(180deg); opacity: .75; }
.pos-badge b { font: italic 900 78px/82px Impact, "Arial Black", sans-serif; }
.pos-badge .pos-of { font: italic 900 26px Impact, "Arial Black", sans-serif; opacity: .65; }
.lap-strip { display: flex; gap: 20px; padding: 6px 30px 6px 14px; border-left: 4px solid var(--accent);
  background: rgba(8, 12, 18, .72); clip-path: polygon(0 0, 100% 0, 95% 100%, 0 100%); }
.lap-strip div { display: flex; flex-direction: column; }
.lap-strip small { font-size: 10px; letter-spacing: .1em; }
.lap-strip b { font: italic 900 22px/26px Impact, "Arial Black", sans-serif; font-variant-numeric: tabular-nums; }
#time { color: var(--accent); }
#gap.ahead { color: #FF8A5C; }
#gap.lead { color: #5DFF9A; }
.board { list-style: none; display: flex; flex-direction: column; gap: 3px; margin-top: 2px; }
.board li { display: flex; align-items: center; width: 196px; height: 26px; padding-right: 16px; font-size: 13px; white-space: nowrap;
  background: rgba(8, 12, 18, .62); clip-path: polygon(0 0, 100% 0, 93% 100%, 0 100%); transition: background .2s; }
.board li em { align-self: stretch; width: 28px; display: grid; place-items: center; margin-right: 8px; background: rgba(255, 255, 255, .1);
  font: italic 900 16px Impact, "Arial Black", sans-serif; }
.board li i { width: 4px; align-self: stretch; margin-right: 8px; }
.board li.me { background: rgba(255, 208, 90, .24); }
.board li.me em { background: var(--accent); color: var(--ink); }

/* Whole-race progress strip: every car as a dot between start and the flag. */
.race-track { position: relative; width: 470px; height: 28px; }
.rt-line { position: absolute; left: 0; right: 26px; top: 12px; height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, .12)); box-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
.rt-lap { position: absolute; left: calc((100% - 26px) / 2); top: 5px; width: 2px; height: 18px; background: rgba(255, 255, 255, .45); }
.rt-flag { position: absolute; right: 0; top: 1px; font-size: 18px; }
.rt-dot { position: absolute; top: 7px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, .65); }
.rt-dot.me { top: 3px; width: 22px; height: 22px; margin-left: -11px; border: 3px solid #fff; z-index: 2; box-shadow: 0 0 12px rgba(255, 208, 90, .9); }

/* System buttons, minimap, combat feed. */
.sys { display: flex; gap: 8px; }
.sys-btn { width: 46px; height: 46px; border-radius: 12px; font-size: 19px; cursor: pointer; color: var(--white);
  background: rgba(8, 12, 18, .65); border: 1px solid rgba(255, 255, 255, .16); transition: background .15s; }
.sys-btn:hover { background: rgba(40, 52, 66, .85); }
.sys-btn.off { opacity: .4; }
.map { width: 222px; height: 152px; padding: 6px; border-radius: 14px; background: rgba(8, 12, 18, .58); border: 1px solid rgba(255, 255, 255, .1); }
#minimap { width: 210px; height: 140px; }
#feed { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; width: 280px; }
.feed-line { padding: 3px 12px 3px 34px; font-size: 13px; animation: slidein .3s ease-out both;
  background: linear-gradient(90deg, transparent, rgba(8, 12, 18, .78) 26%); }
.feed-line span { color: #FF8A5C; margin: 0 6px; }

/* Announcements. */
#popups { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pop { font: italic 900 30px "Microsoft YaHei", sans-serif; white-space: nowrap; padding: 4px 48px;
  background: linear-gradient(90deg, transparent, rgba(8, 12, 18, .72) 18%, rgba(8, 12, 18, .72) 82%, transparent);
  text-shadow: 0 3px 0 rgba(0, 0, 0, .6); animation: pop 1.7s ease-out both; }
.pop.big { font-size: 42px; color: var(--accent); }
.pop.blue { color: var(--nitro); }
.pop.orange { color: #FF9A3A; }
.pop.red { color: #FF5A45; }
.pop.green { color: #5DFF9A; }
.pop small { display: inline; font-size: 20px; color: var(--white); margin-left: 10px; font-style: normal; }

/* LED tachometer with four nitro charges. */
.tacho { position: relative; width: 300px; height: 170px; }
.tacho-bars { position: absolute; left: 50%; top: 142px; }
.tacho-bars i { position: absolute; width: 9px; height: 24px; margin: -12px 0 0 -4.5px; border-radius: 2px;
  background: rgba(255, 255, 255, .1); transition: background .08s, box-shadow .08s; }
.tacho-bars i.on { background: var(--c); box-shadow: 0 0 10px var(--c); }
.tacho.boost .tacho-bars i.on { background: var(--nitro); box-shadow: 0 0 12px var(--nitro); }
.tacho-read { position: absolute; left: 0; right: 0; top: 52px; text-align: center; }
#speed { display: block; font: italic 900 66px/66px Impact, "Arial Black", sans-serif; letter-spacing: .02em;
  text-shadow: 0 4px 0 rgba(0, 0, 0, .5), 0 0 20px rgba(0, 0, 0, .4); }
.tacho.boost #speed { color: var(--nitro); }
.tacho-read small { font-size: 11px; letter-spacing: .2em; }
.nitro-cells { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%) skewX(-18deg); display: flex; gap: 5px; }
.nitro-cells i { width: 44px; height: 10px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.nitro-cells s { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #1A8CFF, var(--nitro)); }
.nitro-cells i.full s { box-shadow: 0 0 10px var(--nitro); }

/* Steering: two big chevron pads under the left thumb. */
.steer { position: relative; width: 132px; height: 150px; border-radius: 24px; cursor: pointer; touch-action: none;
  background: linear-gradient(180deg, rgba(30, 40, 52, .55), rgba(8, 12, 18, .6)); border: 2px solid rgba(255, 255, 255, .16);
  display: grid; place-items: center; transition: background .12s, border-color .12s, opacity .3s; }
#btn-left { transform: skewX(8deg); }
#btn-right { transform: skewX(-8deg); }
.steer svg { width: 54px; height: 72px; fill: none; stroke: rgba(255, 255, 255, .92); stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; }
.steer.down { background: rgba(255, 208, 90, .28); border-color: var(--accent); }
.steer.down svg { stroke: var(--accent); }
body.kb .steer { opacity: .3; }

/* Action cluster: nitro biggest under the thumb, drift beside it, bucket above. */
/* Buttons sit on a 185px arc around the nitro centre (trick 180deg, bucket 130deg, item 80deg), 30px+ apart. */
.cluster { position: relative; width: 430px; height: 340px; }
.act { position: absolute; border-radius: 50%; cursor: pointer; touch-action: none; color: var(--white);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: radial-gradient(circle at 50% 30%, rgba(46, 58, 72, .9), rgba(8, 12, 18, .88) 70%);
  border: 2px solid rgba(255, 255, 255, .14); box-shadow: 0 8px 20px rgba(0, 0, 0, .45);
  transition: transform .07s, box-shadow .2s, opacity .2s, color .2s; }
.act .ring, .act .ticks { position: absolute; inset: -8px; border-radius: 50%; pointer-events: none;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 7px), #000 calc(100% - 6px)); }
.act .ring { background: conic-gradient(var(--rc, #fff) calc(var(--p, 0) * 1%), rgba(255, 255, 255, .1) 0); }
.act .ico { width: 44%; height: 44%; fill: none; stroke: currentColor; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round; }
.act b { font: italic 900 17px "Microsoft YaHei", sans-serif; letter-spacing: .06em; }
body.kb .act b { margin-bottom: 10px; }
.act.down { transform: scale(.92); }
.act.nitro { right: 4px; bottom: 4px; width: 164px; height: 164px; color: var(--nitro); --rc: var(--nitro); }
.act.nitro .ico { fill: currentColor; stroke: none; width: 40%; height: 40%; }
.act.nitro .ticks { background: repeating-conic-gradient(rgba(8, 12, 18, 1) 0 3deg, transparent 3deg 90deg); }
.act.nitro.ready { box-shadow: 0 0 0 2px var(--nitro), 0 0 38px rgba(56, 225, 255, .55); }
.act.nitro.empty { opacity: .5; }
.act.nitro.firing { background: radial-gradient(circle, rgba(56, 225, 255, .55), rgba(6, 40, 60, .92) 70%); color: #fff; }
.act.trick { right: 216px; bottom: 31px; width: 110px; height: 110px; color: rgba(255, 255, 255, .55); --rc: var(--accent); }
.act.trick.air { color: var(--accent); --p: 100; box-shadow: 0 0 0 2px var(--accent), 0 0 30px rgba(255, 208, 90, .65); animation: throb .45s ease-in-out infinite alternate; }
.act.nitro.drifting { color: #7FD0FF; --rc: #4AB8FF; }
.act.nitro.drifting.l2 { color: #FFB26B; --rc: #FF9A3A; box-shadow: 0 0 0 2px #FF9A3A, 0 0 38px rgba(255, 154, 58, .6); }
.act.nitro.drifting .ticks { opacity: 0; }
/* Item slot: empty and dim until a box is collected, then it glows with the item's icon. */
.act.item { right: 6px; bottom: 220px; width: 96px; height: 96px; color: rgba(255, 255, 255, .45); --rc: #FFE45A; }
.act.item .item-ico { font-size: 30px; line-height: 34px; filter: grayscale(1); opacity: .5; }
.act.item b { font-size: 13px; }
.act.item.has { color: #FFE45A; --p: 100; box-shadow: 0 0 0 2px #FFE45A, 0 0 30px rgba(255, 228, 90, .55);
  background: radial-gradient(circle at 50% 30%, rgba(90, 70, 20, .9), rgba(20, 14, 6, .9) 70%); animation: throb .7s ease-in-out infinite alternate; }
.act.item.has .item-ico { filter: none; opacity: 1; }
.act.arm { right: 150px; bottom: 173px; width: 110px; height: 110px; color: #FF8A5C; --rc: #FF8A5C; }
.act.arm.cool { opacity: .55; }
.act.arm.ready { box-shadow: 0 0 0 2px #FF5A3A, 0 0 32px rgba(255, 90, 58, .7); animation: throb .6s ease-in-out infinite alternate; }

#countdown { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: calc(140px * var(--s));
  font-style: italic; color: var(--accent); pointer-events: none; white-space: nowrap;
  text-shadow: 0 8px 0 rgba(0, 0, 0, .5), 0 0 50px rgba(255, 208, 90, .35); }
#countdown.go { color: #5DFF9A; text-shadow: 0 8px 0 rgba(0, 0, 0, .5), 0 0 60px rgba(93, 255, 154, .5); }
#countdown.pop { animation: count .9s ease-out both; }

#overlay, #paused { position: fixed; inset: 0; display: grid; place-items: center; grid-template: 100% / 100%; overflow: hidden;
  background: radial-gradient(ellipse at center, rgba(8, 12, 18, .1), rgba(8, 12, 18, .55)); }
/* The menu is scaled by main.js (fitMenu) from its measured size, so it always fits phones. Keyframes never touch the scale. */
.menu-fit { transform: scale(var(--ms, 1)); transform-origin: center; }
#overlay.menu-mode .menu-fit { transform-origin: right center; }
.pause-card { transform: scale(var(--s)); }
.keyart { position: absolute; inset: 0; background: url(assets/keyart.jpg) center / cover no-repeat; opacity: 0; transition: opacity .6s; }
#overlay.menu-mode .keyart { opacity: 1; }
#overlay.menu-mode { background: linear-gradient(90deg, rgba(6, 9, 14, .2), rgba(6, 9, 14, .05) 40%, rgba(6, 9, 14, .55)); }
#overlay.menu-mode { place-items: center end; padding-right: 4vw; }
#overlay.menu-mode .menu { width: 560px; }
#overlay.menu-mode .guide { grid-template-columns: repeat(2, 1fr); }
#overlay.menu-mode .guide .hot { grid-column: span 2; }
#overlay.menu-mode .guide div { height: 62px; }
.emblem { width: 92px; height: 92px; border-radius: 22px; margin: -66px 0 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 0 0 2px rgba(255, 208, 90, .5); }
.menu { width: 760px; border-radius: 30px; padding: 26px 36px 18px; text-align: center; position: relative;
  display: flex; flex-direction: column; align-items: center; animation: rise .45s cubic-bezier(.2, .9, .3, 1.2) both; }
.marker { background: rgba(255, 208, 90, .12); color: var(--accent); font-size: 12px; border-radius: 14px; padding: 5px 20px; letter-spacing: .1em; }
.menu h1 { font-size: 56px; margin: 14px 0 6px; font-style: italic; letter-spacing: .04em;
  background: linear-gradient(180deg, #FFF6D6, #FFD05A 60%, #FF9A3A); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .45)); }
#details { color: var(--muted); font-size: 19px; line-height: 30px; }
#results { list-style: none; width: 520px; margin: 6px 0 4px; }
#results li { display: flex; align-items: center; gap: 12px; font-size: 18px; line-height: 36px; padding: 0 14px; border-radius: 10px; animation: fadeup .4s both; }
#results li.me { background: rgba(255, 208, 90, .14); }
#results li i { width: 12px; height: 12px; border-radius: 4px; flex: none; }
#results li span { flex: 1; text-align: left; }
#results li em { font-style: normal; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats { display: flex; gap: 14px; margin: 6px 0 2px; }
.stats div { background: rgba(255, 255, 255, .06); border-radius: 12px; padding: 8px 16px; font-size: 13px; color: var(--muted); }
.stats b { display: block; font-size: 22px; color: var(--white); }
.guide { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 20px 0 22px; width: 100%; }
.guide .hot { background: rgba(255, 90, 60, .14); box-shadow: inset 0 0 0 1px rgba(255, 120, 80, .35); }
.guide .hot b { color: #FF8A5C; }
.guide .drift { background: rgba(56, 225, 255, .12); box-shadow: inset 0 0 0 1px rgba(56, 225, 255, .35); }
.guide .drift b { color: var(--nitro); }
.guide div { height: 76px; border-radius: 15px; background: rgba(255, 255, 255, .06); display: flex;
  flex-direction: column; justify-content: center; gap: 4px; padding: 0 8px; }
.guide b { color: var(--accent); font-size: 18px; }
.guide span { font-size: 13px; color: var(--white); }
.start { width: 100%; height: 66px; font-size: 26px; margin-top: 10px; }
#footer { margin-top: 12px; font-size: 13px; }
.settings { display: flex; align-items: center; justify-content: space-between; width: 100%; margin: -8px 0 14px;
  padding: 8px 10px 8px 16px; border-radius: 14px; background: rgba(255, 255, 255, .05); font-size: 14px; color: var(--muted); }
.seg { display: flex; padding: 3px; gap: 3px; border-radius: 11px; background: rgba(0, 0, 0, .35); }
.seg button { padding: 7px 16px; border-radius: 9px; font-size: 14px; cursor: pointer; color: var(--muted); transition: background .15s, color .15s; }
.seg button.on { background: var(--accent); color: var(--ink); }
#overlay:not(.menu-mode) .settings { display: none; }

.pause-card { width: 380px; padding: 30px; border-radius: 26px; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.pause-card b { font-size: 36px; }
.pause-card .btn { width: 260px; height: 56px; }

.tag { position: absolute; left: 0; top: 0; padding: 3px 10px 3px 8px; border-radius: 10px; font-size: 13px;
  background: rgba(12, 19, 28, .78); white-space: nowrap; display: flex; align-items: center; gap: 6px; will-change: transform; }
.tag i { width: 9px; height: 9px; border-radius: 3px; }


/* Cinematic letterbox for highlight shots. */
#letterbox { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#letterbox i { position: absolute; left: 0; right: 0; height: 0; background: #000; transition: height .35s cubic-bezier(.2, .8, .2, 1); }
#letterbox i:first-child { top: 0; }
#letterbox i:nth-child(2) { bottom: 0; }
body.cine #letterbox i { height: 11vh; }
#cine-label, #letterbox em { position: absolute; opacity: 0; transition: opacity .3s .15s; white-space: nowrap; }
#cine-label { left: 5vw; bottom: 3.2vh; font: italic 900 calc(30px * var(--s)) "Microsoft YaHei", sans-serif; color: var(--accent); letter-spacing: .08em; }
#letterbox em { right: 5vw; bottom: 3.8vh; font: italic 700 calc(15px * var(--s)) "Microsoft YaHei", sans-serif; color: rgba(255, 255, 255, .7); letter-spacing: .3em; }
#letterbox em::before { content: ''; display: inline-block; width: .7em; height: .7em; margin-right: .6em; border-radius: 50%; background: #FF4A3A; animation: blinkdot 1s steps(2) infinite; }
body.cine #cine-label, body.cine #letterbox em { opacity: 1; }
body.cine #hud { opacity: .28; transition: opacity .3s; }
#hud { transition: opacity .3s; }
@keyframes blinkdot { 50% { opacity: 0; } }

/* Lock-on reticle. */
#reticle { position: fixed; left: 0; top: 0; width: 96px; height: 96px; pointer-events: none; will-change: transform; }
#reticle svg { width: 100%; height: 100%; fill: none; stroke: #FF5A3A; stroke-width: 5; animation: spin 2.4s linear infinite; filter: drop-shadow(0 0 6px rgba(255, 90, 58, .8)); }
#reticle span { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); white-space: nowrap; font-size: 15px;
  background: #FF5A3A; color: #fff; padding: 2px 10px; border-radius: 8px; font-style: italic; }
#reticle.obstacle svg { stroke: var(--accent); filter: drop-shadow(0 0 6px rgba(255, 208, 90, .8)); }
#reticle.obstacle span { background: var(--accent); color: var(--ink); }
@keyframes throb { to { transform: scale(1.05); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }

#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(237, 70, 50, .55)); }
#flash.on { animation: flash .7s ease-out; }
#boostglow { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .25s;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(56, 180, 255, .28)); }
#boostglow.on { opacity: 1; }

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 700px) {
  #rotate { display: grid; place-items: center; position: fixed; inset: 0; z-index: 10; background: var(--bg); font-size: 22px; }
}

@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 12% { transform: scale(1); opacity: 1; }
  75% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-18px); } }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } }
@keyframes fadeup { from { transform: translateY(10px); opacity: 0; } }
@keyframes count { 0% { transform: translate(-50%, -50%) scale(2); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  80% { opacity: 1; } 100% { transform: translate(-50%, -50%) scale(.8); opacity: 0; } }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Short landscape phones: drop the control cards (the HUD buttons explain themselves) so the menu can be larger. */
@media (max-height: 500px) {
  #overlay.menu-mode .guide { display: none; }
  #overlay.menu-mode #details { margin-bottom: 18px; }
}

/* Touch controls use real CSS pixels, independently of the scaled racing HUD. */
@media (pointer: coarse), (max-width: 1000px) and (max-height: 600px) {
  :root {
    --pad: clamp(80px, 12vw, 96px);
    --skill: clamp(68px, 18vh, 80px);
    --boost-size: clamp(96px, 25vh, 112px);
    --touch-bottom: max(18px, env(safe-area-inset-bottom));
  }
  .bl, .br { transform: none; bottom: var(--touch-bottom); z-index: 4; }
  .bl { left: max(18px, env(safe-area-inset-left)); gap: 20px; }
  .br { right: max(18px, env(safe-area-inset-right)); }
  .steer { width: var(--pad); height: calc(var(--pad) + 12px); }
  .steer svg { width: 41%; height: 48%; }
  body.kb .steer { opacity: 1; }
  .cluster {
    width: auto; height: auto; display: grid;
    grid-template-columns: var(--skill) var(--boost-size);
    grid-template-rows: var(--skill) var(--boost-size);
    gap: 16px; align-items: center; justify-items: center;
  }
  .cluster .act { position: relative; inset: auto; width: var(--skill); height: var(--skill); }
  .cluster .arm { grid-area: 1 / 2; }
  .cluster .trick { grid-area: 1 / 1; }
  .cluster .item { grid-area: 2 / 1; }
  .cluster .nitro { grid-area: 2 / 2; width: var(--boost-size); height: var(--boost-size); }
  .act b, .act.item b { font-size: 13px; }
  .act.nitro b { font-size: 17px; }
  .act .item-ico { font-size: 25px; line-height: 29px; }
  body.kb .act b { margin-bottom: 0; }
  body.kb kbd { display: none; }
  .tr { transform: none; top: max(10px, env(safe-area-inset-top)); right: max(18px, env(safe-area-inset-right)); gap: 8px; }
  .sys { gap: 12px; }
  .sys-btn { width: 48px; height: 48px; }
  .map { width: 110px; height: 76px; padding: 4px; border-radius: 10px; }
  #minimap { width: 100px; height: 66px; }
  #feed { display: none; }
  .tl { left: max(14px, env(safe-area-inset-left)); top: max(10px, env(safe-area-inset-top)); }
  .bc { bottom: var(--touch-bottom); }
  body.cine #hud { opacity: 1; }
  body.cine #cine-label, body.cine #letterbox em { opacity: 0; }
  #paused { z-index: 5; }
  .pause-card { transform: none; width: min(360px, calc(100vw - 40px)); padding: 22px; }
  .pause-card b { font-size: 28px; }
  .pause-card .btn { width: 100%; min-height: 52px; }

  /* Menus also retain finger-sized targets instead of shrinking the whole card. */
  #overlay { padding: max(10px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
  #overlay.menu-mode { padding-right: max(18px, env(safe-area-inset-right)); }
  #overlay .menu-fit { transform: none; max-width: 100%; max-height: 100%; overflow-y: auto; touch-action: pan-y; border-radius: 22px; }
  #overlay .menu { width: min(440px, calc(100vw - 60px)); padding: 16px 20px; border-radius: 22px; animation: none; }
  #overlay.menu-mode .menu { width: min(360px, calc(100vw - 60px)); }
  .menu .emblem, .menu .marker, #overlay.menu-mode .guide { display: none; }
  .menu h1 { font-size: 30px; margin: 0 0 6px; }
  #overlay.menu-mode #details { font-size: 12px; line-height: 20px; margin-bottom: 6px; }
  #overlay.menu-mode .touch-help { display: block; font-size: 12px; line-height: 20px; color: #D7E4ED; margin-bottom: 12px; }
  .settings { margin: 0 0 8px; padding: 4px 6px 4px 12px; font-size: 12px; }
  .seg { gap: 6px; }
  .seg button { min-width: 76px; min-height: 44px; padding: 6px 10px; }
  .start { height: 52px; min-height: 52px; margin-top: 0; font-size: 20px; }
  #footer { font-size: 10px; line-height: 16px; margin-top: 8px; }
  #results { width: 100%; }
  #results li { font-size: 13px; line-height: 30px; gap: 8px; padding: 0 8px; }
  .stats { flex-wrap: wrap; justify-content: center; gap: 6px; margin-bottom: 10px; }
  .stats div { padding: 6px 10px; font-size: 10px; }
  .stats b { font-size: 18px; }
}

@media (max-height: 400px) and (orientation: landscape) {
  .map { display: none; }
}

/* Clearer race information; the established arrow pads and action faces stay intact. */
.menu-intro { display: none; }
#overlay.menu-mode .menu-intro { display: block; position: absolute; left: 6vw; top: 50%; transform: translateY(-50%); text-align: left; }
.menu-intro > span { font-size: 12px; letter-spacing: .32em; color: var(--accent); }
.menu-intro strong { display: block; margin: 22px 0; font-size: clamp(42px, 5vw, 76px); line-height: 1.18; font-style: italic; letter-spacing: -.04em; text-shadow: 0 4px 30px #000; }
.menu-intro p { color: #D7E0E7; font-size: 15px; letter-spacing: .06em; }
.menu-intro > div { display: flex; align-items: center; gap: 10px; margin-top: 42px; font-size: 12px; color: #DBE2E6; }
.menu-intro > div span { color: #9EAFBD; font-size: 10px; letter-spacing: .1em; margin-left: 10px; }
.menu-intro i { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; }
#overlay.menu-mode .keyart { background-position: 37% center; }
#overlay.menu-mode .keyart::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(5,10,17,.77), rgba(5,10,17,.2) 55%, rgba(5,10,17,.65)); }
#overlay.menu-mode .menu { width: 480px; }
.menu { background: rgba(10,18,27,.91); border: 1px solid rgba(185,208,227,.18); box-shadow: 0 24px 80px #0006; padding: 28px; border-radius: 24px; }
.menu .emblem { display: none; }
.menu .marker { background: none; padding: 0; border-radius: 0; font-size: 10px; letter-spacing: .15em; }
.menu h1 { font-size: 42px; margin: 12px 0 8px; }
#details { font-size: 14px; line-height: 24px; color: #BDCAD4; }
.race-facts { display: flex; width: 100%; justify-content: center; gap: 24px; padding: 14px 0; margin: 8px 0 0; border-bottom: 1px solid var(--line); }
.race-facts span { font-size: 12px; color: #ADBEC9; white-space: nowrap; }
.race-facts b { color: var(--white); font: 900 22px Impact, sans-serif; padding-right: 4px; }
#overlay:not(.menu-mode) .race-facts, #overlay.menu-mode .result-menu { display: none; }
.guide { gap: 8px; margin: 16px 0; }
#overlay.menu-mode .guide div { height: 52px; border-radius: 10px; }
.guide b { font-size: 14px; }
.guide span { font-size: 11px; color: #BCCAD6; }
.settings { margin: 0 0 12px; border: 1px solid var(--line); background: #ffffff04; }
.start { font-size: 22px; height: 58px; }
.start:disabled { cursor: wait; opacity: .65; }
#footer { color: #A9BAC7; font-size: 11px; line-height: 18px; }
.result-menu { min-height: 44px; padding: 10px 22px; margin-top: 8px; color: #BDCAD4; cursor: pointer; }
.result-menu:hover { color: var(--accent); }
.menu-actions { display: contents; }
#overlay:not(.menu-mode) .menu-actions { display: flex; gap: 12px; align-items: center; width: 100%; margin-top: 10px; }
#overlay:not(.menu-mode) .menu-actions .start { flex: 1; margin-top: 0; }
#overlay:not(.menu-mode) .result-menu { margin: 0; border: 1px solid var(--line); border-radius: 14px; }
#overlay:not(.menu-mode) .menu { width: 660px; }
#results { width: 100%; margin: 16px 0; }
#results li { min-height: 44px; border-bottom: 1px solid #ffffff08; }
#results li > b { width: 28px; font: italic 900 26px Impact,sans-serif; color: #B1C2CD; }
#results li.me > b { color: var(--accent); }
.stats { width: 100%; gap: 6px; }
.stats > div { flex: 1; padding: 12px 6px; font-size: 11px; }
.pause-eyebrow { color: var(--accent); font-size: 11px; letter-spacing: .14em; }
.pause-card b { font-size: 30px; }
#pause-summary { color: #B8C8D2; font-size: 13px; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.lap-strip b, #speed, #results em { font-variant-numeric: tabular-nums; }
#rotate > div { text-align: center; padding: 30px; }
#rotate svg { width: 92px; height: 92px; fill: none; stroke: var(--accent); stroke-width: 3; margin-bottom: 28px; }
#rotate b { display: block; font-size: 25px; }
#rotate p { margin-top: 14px; font-size: 14px; color: #A5B6C3; }
#rotate span { display: block; margin-top: 50px; font-size: 10px; letter-spacing: .3em; color: #657C8C; }

@media (pointer: coarse), (max-width: 1000px) and (max-height: 600px) {
  #overlay.menu-mode .menu-intro { left: max(30px, env(safe-area-inset-left)); max-width: calc(100vw - 410px); }
  .menu-intro > span { font-size: 9px; letter-spacing: .18em; }
  .menu-intro strong { font-size: clamp(28px, 5vw, 48px); margin: 14px 0; }
  .menu-intro p { font-size: 11px; line-height: 20px; }
  .menu-intro > div { margin-top: 20px; font-size: 10px; }
  .menu-intro > div span { display: none; }
  #overlay .menu { padding: 18px 20px; width: min(440px, calc(100vw - 48px)); }
  #overlay.menu-mode .menu { width: 340px; }
  #overlay:not(.menu-mode) .menu { width: min(500px, calc(100vw - 48px)); }
  .menu h1 { font-size: 28px; margin: 0 0 6px; }
  #overlay.menu-mode #details { font-size: 11px; margin: 0; }
  .race-facts { gap: 22px; padding: 9px 0; margin: 0 0 8px; }
  .race-facts span { font-size: 11px; }
  .race-facts b { font-size: 19px; }
  #overlay.menu-mode .touch-help { font-size: 11px; line-height: 18px; margin-bottom: 10px; color: #B8C9D6; }
  .settings { margin-bottom: 8px; }
  .start { height: 52px; font-size: 20px; }
  #footer { font-size: 10px; line-height: 16px; }
  .tl { transform: none; display: grid; grid-template-columns: 66px auto; gap: 0 8px; align-items: start; }
  .pos-badge { height: 58px; padding: 0 12px 0 6px; gap: 2px; grid-row: 1 / 3; }
  .pos-badge .pos-p { font-size: 8px; letter-spacing: 0; }
  .pos-badge b { font-size: 44px; line-height: 58px; }
  .pos-badge .pos-of { font-size: 14px; }
  .lap-strip { gap: 12px; padding: 6px 12px 6px 8px; border-left-width: 2px; min-height: 58px; }
  .lap-strip small { font-size: 10px; line-height: 16px; }
  .lap-strip b { font-size: 19px; line-height: 24px; }
  .lap-strip > div:last-child { display: none; }
  .board { display: none; }
  .tc { transform: translateX(-50%); top: max(15px, env(safe-area-inset-top)); gap: 56px; }
  .race-track { width: clamp(150px, 26vw, 280px); }
  .rt-dot { width: 9px; height: 9px; top: 10px; margin-left: -4px; }
  .rt-dot.me { width: 16px; height: 16px; top: 6px; margin-left: -8px; border-width: 2px; }
  .rt-lap { height: 10px; top: 9px; opacity: .6; }
  .rt-flag { font-size: 14px; top: 5px; }
  .bc { transform: translateX(-50%); bottom: max(12px, env(safe-area-inset-bottom)); }
  .tacho { width: 130px; height: 82px; }
  .tacho-bars { display: none; }
  .tacho-read { top: 0; }
  #speed { font-size: 40px; line-height: 44px; }
  .tacho-read small { font-size: 9px; color: #D2DFE7; text-shadow: 0 1px 4px #000; }
  .nitro-cells { gap: 4px; bottom: 5px; }
  .nitro-cells i { width: 24px; height: 6px; }
  .pop { font-size: 20px; padding: 4px 20px; }
  .pop.big { font-size: 26px; }
  .pop small { font-size: 12px; }
  #popups > :nth-child(n+3) { display: none; }
  body.cine #letterbox i { height: 0; }
  #results { margin: 8px 0; }
  #results li { min-height: 34px; }
  #results li > b { font-size: 21px; }
  .stats { display: grid; grid-template-columns: repeat(5,1fr); }
  .stats > div { padding: 8px 4px; font-size: 9px; }
  .stats b { font-size: 16px; }
  .result-menu { min-height: 44px; font-size: 12px; margin-top: 2px; }
}
@media (max-width: 720px) and (orientation: landscape) {
  #overlay.menu-mode .menu-intro { left: max(22px, env(safe-area-inset-left)); max-width: calc(100vw - 380px); }
  .menu-intro strong { font-size: 30px; }
  .menu-intro p, .menu-intro > div { display: none; }
  .tl { grid-template-columns: 58px auto; gap: 0 5px; }
  .pos-badge { height: 52px; }
  .pos-badge b { font-size: 39px; line-height: 52px; }
  .lap-strip { gap: 8px; min-height: 52px; padding: 4px 10px 4px 6px; }
  .lap-strip b { font-size: 17px; }
  .race-track { width: 144px; }
  .tacho { width: 110px; height: 74px; }
  #speed { font-size: 35px; line-height: 40px; }
  .nitro-cells i { width: 20px; }
}
@media (max-height: 350px) and (orientation: landscape) {
  #overlay .menu { padding: 12px 18px; }
  #overlay.menu-mode .touch-help { display: none; }
  #overlay.menu-mode .race-facts { margin-bottom: 6px; }
  #overlay:not(.menu-mode) .menu { padding: 12px 18px; }
  #overlay:not(.menu-mode) .menu h1 { font-size: 26px; }
  #overlay:not(.menu-mode) #results li { min-height: 28px; line-height: 28px; }
  #overlay:not(.menu-mode) #results { margin: 6px 0; }
  #overlay:not(.menu-mode) #footer { display: none; }
  #overlay:not(.menu-mode) .menu-actions { margin-top: 2px; }
}
