/* 刹车挑战 — portrait-first UI over a full-bleed three.js canvas.
   Layout decision (enforced below): on phones the PEDAL ZONE owns the bottom
   ~34% of the screen at full usable width minus the handbrake column; the 3D
   road owns everything above. On short screens (≤680px tall) the chips and gap
   meter shrink first; the pedal never drops below 180px tall. */
:root {
  --bg: #0b0e12;
  --ink: #eef3f8;
  --muted: #93a1b3;
  --dim: #5d6a7a;
  --cyan: #3fe0ff;
  --orange: #ff5a1f;
  --yellow: #ffc21a;
  --red: #ff2d3d;
  --green: #3ddc84;
  --panel: rgba(13, 17, 23, 0.8);
  --panel-solid: #12171e;
  --line: rgba(255, 255, 255, 0.09);
  --glass: linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  --radius: 18px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'HarmonyOS Sans SC', 'MiSans', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
img { -webkit-user-drag: none; pointer-events: none; }
[hidden] { display: none !important; }
b, .num { font-variant-numeric: tabular-nums; }

#app { position: fixed; inset: 0; overflow: hidden; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.12s; box-shadow: inset 0 0 70px 6px rgba(255, 30, 40, 0.8); }
#vignette.on { opacity: 1; animation: vig 0.5s ease-in-out infinite alternate; }
@keyframes vig { from { opacity: 1; } to { opacity: 0.45; } }
#flash { position: absolute; inset: 0; pointer-events: none; background: #fff; opacity: 0; }
#flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.7; } to { opacity: 0; } }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.screen.overlay { background: radial-gradient(120% 80% at 50% 100%, rgba(5, 7, 10, 0.92), rgba(5, 7, 10, 0.55)); justify-content: flex-end; align-items: center; padding: calc(16px + var(--sat)) 14px calc(14px + var(--sab)); z-index: 30; animation: fadein 0.18s ease-out; }
@keyframes fadein { from { opacity: 0; } }

/* ---------- buttons ---------- */
.icon-btn { width: 48px; height: 48px; flex: 0 0 auto; border-radius: 14px; display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform 0.12s ease-out, background 0.15s; }
.icon-btn img { width: 30px; height: 30px; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.labeled { width: auto; min-width: 0; height: 52px; padding: 0 12px 0 10px; display: flex; gap: 6px; font-weight: 600; font-size: 15px; white-space: nowrap; }
.icon-btn.labeled img { width: 28px; height: 28px; flex: 0 0 auto; }
.flip { transform: scaleX(-1); }
.btn { min-height: 52px; padding: 0 12px; white-space: nowrap; border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: 0.02em; transition: transform 0.12s ease-out, filter 0.15s; flex: 1 1 0; }
.btn img { width: 26px; height: 26px; flex: 0 0 auto; }
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(180deg, #ff7a3d, var(--orange) 55%, #e2430c); color: #fff; box-shadow: 0 8px 24px -8px rgba(255, 90, 31, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.35); text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); }
.btn.ghost { background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); }
.btn.slim { min-height: 44px; font-size: 14px; font-weight: 600; flex: 0 0 auto; align-self: center; padding: 0 16px; }
.btn:disabled { filter: grayscale(1) brightness(0.6); }
.row { display: flex; gap: 10px; width: 100%; }
.col { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px 0 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 14px; font-weight: 700; }
.chip img { width: 22px; height: 22px; }

/* ---------- sheets ---------- */
.sheet { width: min(100%, 460px); background: linear-gradient(180deg, rgba(28, 34, 43, 0.96), rgba(14, 18, 24, 0.98)), url(assets/img/panel.jpg); background-blend-mode: normal; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 26px; padding: 20px 18px 18px; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.08); animation: sheetin 0.32s cubic-bezier(0.2, 0.9, 0.25, 1.05); max-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; position: relative; }
.sheet::before { content: ''; position: absolute; inset: 0; border-radius: inherit; background: url(assets/img/panel.jpg); opacity: 0.18; pointer-events: none; mix-blend-mode: screen; }
.sheet > * { position: relative; }
.sheet.small { width: min(100%, 360px); align-self: center; margin-bottom: auto; margin-top: auto; }
.sheet h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: 0.02em; }
@keyframes sheetin { from { transform: translateY(40px) scale(0.98); opacity: 0; } }

/* ---------- title ---------- */
#title { background: var(--bg); z-index: 20; }
.title-art { position: absolute; inset: 0 0 auto; height: 72%; overflow: hidden; }
.title-art img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 62%; animation: kenburns 24s ease-in-out infinite alternate; }
.title-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(11, 14, 18, 0.35) 0%, rgba(11, 14, 18, 0) 30%, rgba(11, 14, 18, 0.2) 62%, var(--bg) 99%); }
@keyframes kenburns { from { transform: scale(1.04); } to { transform: scale(1.14) translateY(-2%); } }
.title-head { position: relative; padding: calc(28px + var(--sat)) 20px 0; display: flex; flex-direction: column; align-items: center; text-align: center; }
.title-emblem { width: 92px; height: auto; filter: drop-shadow(0 6px 18px rgba(255, 90, 31, 0.55)); animation: emblem 3.2s ease-in-out infinite; }
@keyframes emblem { 50% { transform: rotate(-6deg) scale(1.04); } }
.title-name { margin: 2px 0 0; font-size: clamp(50px, 15vw, 72px); font-weight: 900; font-style: italic; letter-spacing: 0.06em; line-height: 1; background: linear-gradient(180deg, #ffffff 20%, #ffd2b8 55%, #ff6a2a 100%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 rgba(120, 20, 0, 0.55)) drop-shadow(0 12px 28px rgba(0, 0, 0, 0.6)); transform: skewX(-8deg); }
.title-tag { margin: 10px 0 0; font-size: 14px; letter-spacing: 0.4em; color: #ffd9c4; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7); padding-left: 0.4em; }
.title-body { position: relative; margin-top: auto; padding: 0 16px calc(12px + var(--sab)); display: flex; flex-direction: column; gap: 12px; width: min(100%, 520px); align-self: center; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { position: relative; height: clamp(96px, 15vh, 132px); border-radius: 20px; overflow: hidden; text-align: left; padding: 12px 14px; display: flex; flex-direction: column; justify-content: flex-end; background: var(--art) center / cover, #1b222b; border: 1px solid rgba(255, 255, 255, 0.14); box-shadow: 0 14px 30px -14px rgba(0, 0, 0, 0.9); transition: transform 0.14s ease-out; isolation: isolate; }
.mode::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, 0) 25%, rgba(5, 8, 12, 0.88)); z-index: -1; }
.mode::after { content: ''; position: absolute; left: 14px; top: 12px; width: 26px; height: 4px; border-radius: 2px; background: var(--orange); box-shadow: 0 0 12px var(--orange); }
.mode:active { transform: scale(0.97); }
.mode-name { font-size: 19px; font-weight: 800; letter-spacing: 0.04em; text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8); }
.mode-sub { font-size: 12.5px; color: #c7d2de; margin-top: 2px; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8); }
.title-bar { display: flex; gap: 8px; justify-content: center; }
.title-bar .icon-btn.labeled { flex: 1 1 0; justify-content: center; }
.disclaimer { margin: 0; font-size: 11px; color: var(--dim); text-align: center; line-height: 1.5; }

/* ---------- stage select ---------- */
#stages { background: linear-gradient(180deg, #121820, var(--bg)); z-index: 20; }
.screen-head { display: flex; align-items: center; gap: 12px; padding: calc(12px + var(--sat)) 16px 10px; }
.screen-head h2 { flex: 1; margin: 0; font-size: 22px; font-weight: 800; }
.screen-head.in-sheet { padding: 0; }
.head-icon { width: 36px; height: 36px; }
.stage-scroll { flex: 1; overflow-y: auto; padding: 4px 16px calc(24px + var(--sab)); display: flex; flex-direction: column; gap: 18px; -webkit-overflow-scrolling: touch; }
.venue { border-radius: 22px; overflow: hidden; border: 1px solid var(--line); background: var(--panel-solid); }
.venue-head { position: relative; height: 92px; background: var(--sky) center 40% / cover; display: flex; align-items: flex-end; padding: 12px 14px; }
.venue-head::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, 0.05), rgba(10, 13, 18, 0.9)); }
.venue-head > * { position: relative; }
.venue-head h3 { margin: 0; font-size: 20px; font-weight: 800; }
.venue-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.venue-stages { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; }
.stage { position: relative; min-height: 84px; border-radius: 16px; padding: 10px 12px; text-align: left; background: var(--glass), #19202a; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; transition: transform 0.12s; }
.stage:active { transform: scale(0.97); }
.stage .st-num { font-size: 12px; color: var(--orange); font-weight: 800; letter-spacing: 0.08em; }
.stage .st-name { font-size: 16px; font-weight: 800; }
.stage .st-meta { display: flex; gap: 4px; align-items: center; font-size: 11.5px; color: var(--muted); }
.stage .st-meta img { width: 18px; height: 18px; }
.stage .st-stars { position: absolute; right: 8px; top: 8px; display: flex; }
.stage .st-stars img { width: 18px; height: 18px; }
.stage.locked { filter: saturate(0.2) brightness(0.65); }
.stage.locked .st-lock { position: absolute; right: 10px; bottom: 10px; width: 28px; height: 28px; }
.stage.next { border-color: rgba(255, 90, 31, 0.8); box-shadow: 0 0 0 1px rgba(255, 90, 31, 0.4), 0 0 24px -6px rgba(255, 90, 31, 0.8); }
.abs-badge { font-size: 10px; font-weight: 900; padding: 1px 5px; border-radius: 5px; border: 1.5px solid currentColor; letter-spacing: 0.04em; }
.abs-badge.off { color: var(--red); text-decoration: line-through; }
.abs-badge.on { color: var(--green); }

/* ---------- briefing ---------- */
.brief-top h2 { font-size: 28px; }
.brief-kicker { font-size: 13px; color: var(--orange); font-weight: 800; letter-spacing: 0.12em; }
.cond-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.cond { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); }
.cond img { width: 34px; height: 34px; flex: 0 0 auto; }
.cond b { display: block; font-size: 16px; }
.cond small { display: block; font-size: 11.5px; color: var(--muted); }
.cond.warn { border-color: rgba(255, 45, 61, 0.5); background: rgba(255, 45, 61, 0.08); }
.brief-goal { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 14px; background: linear-gradient(90deg, rgba(61, 220, 132, 0.12), rgba(61, 220, 132, 0.02)); border: 1px solid rgba(61, 220, 132, 0.3); font-size: 14px; line-height: 1.45; }
.brief-goal img { width: 34px; height: 34px; }
.brief-tip { margin: 0; font-size: 13.5px; color: #c8d3df; line-height: 1.6; padding: 0 2px; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud .pedal-zone { pointer-events: auto; }
.hud-top { position: absolute; left: 0; right: 0; top: 0; padding: calc(10px + var(--sat)) calc(12px + var(--sar)) 0 calc(12px + var(--sal)); display: flex; gap: 8px; align-items: stretch; }
.gauge { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); min-height: 48px; }
.gauge > img { width: 32px; height: 32px; flex: 0 0 auto; }
.gauge.speed { flex: 1 1 auto; justify-content: center; }
.gauge-val { display: flex; align-items: baseline; gap: 4px; }
.gauge-val b { font-size: 30px; font-weight: 900; font-style: italic; min-width: 2.2ch; text-align: right; line-height: 1; letter-spacing: -0.02em; }
.gauge-val small { font-size: 12px; color: var(--muted); font-weight: 700; }
.gauge.bracket { flex: 0 0 auto; width: 132px; }
.gauge.bracket .bar { flex: 1; height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
.gauge.bracket .bar i { display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), #8cf0b6); transform-origin: left; transition: background 0.2s; }
.gauge.bracket small { font-size: 12px; font-weight: 800; min-width: 3.2ch; text-align: right; }
.gauge.bracket.cracked .bar i { background: linear-gradient(90deg, var(--orange), var(--yellow)); }
.gauge.bracket.danger { animation: shake 0.3s linear infinite; border-color: rgba(255, 45, 61, 0.6); }
.gauge.bracket.danger .bar i { background: var(--red); }
.gauge.bracket.broken { border-color: var(--red); background: rgba(80, 10, 14, 0.85); }
@keyframes shake { 25% { transform: translateX(-1.5px); } 75% { transform: translateX(1.5px); } }
.hud-chips { position: absolute; top: calc(66px + var(--sat)); left: 12px; right: 12px; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.hud-chips .chip { height: 28px; font-size: 12px; padding: 0 10px 0 6px; }
.hud-chips .chip img { width: 18px; height: 18px; }
.gapmeter { position: absolute; top: calc(102px + var(--sat)); left: 50%; transform: translateX(-50%); width: min(78%, 340px); display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); animation: fadein 0.2s; }
.gapmeter img { width: 26px; height: 26px; }
.gapmeter b { font-size: 18px; font-weight: 900; min-width: 4.6ch; text-align: right; font-style: italic; }
.gap-track { flex: 1; height: 10px; border-radius: 6px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.14)); position: relative; }
.gap-zone { position: absolute; right: 0; top: -3px; bottom: -3px; width: 9%; border-radius: 4px; background: rgba(61, 220, 132, 0.55); box-shadow: 0 0 10px rgba(61, 220, 132, 0.8); }
.gap-car { position: absolute; top: 50%; left: 0; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 12px var(--cyan); }
.lamps { position: absolute; top: calc(146px + var(--sat)); right: 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.lamp { height: 34px; min-width: 34px; padding: 0 8px; border-radius: 10px; display: grid; place-items: center; font-weight: 900; font-size: 13px; letter-spacing: 0.04em; background: rgba(10, 12, 16, 0.6); border: 1px solid var(--line); color: #4a5563; opacity: 0.0; transition: opacity 0.12s; }
.lamp img { width: 24px; height: 24px; }
.lamp.on { opacity: 1; }
.lamp.abs.on { color: var(--yellow); border-color: rgba(255, 194, 26, 0.6); box-shadow: 0 0 14px rgba(255, 194, 26, 0.4); }
.lamp.lock.on { border-color: rgba(255, 45, 61, 0.7); box-shadow: 0 0 14px rgba(255, 45, 61, 0.5); animation: blink 0.25s steps(2) infinite; }
.lamp.crack.on { border-color: rgba(255, 90, 31, 0.7); animation: blink 0.6s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
/* Sits in the sky band under the gap meter: the road ahead (where hazards appear) must stay visible. */
.callout { position: absolute; left: 0; right: 0; top: calc(150px + var(--sat)); text-align: center; font-size: clamp(30px, 9.5vw, 46px); pointer-events: none; font-weight: 900; font-style: italic; letter-spacing: 0.06em; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.6); opacity: 0; transform: scale(0.8); }
.callout.show { animation: callout 1.1s cubic-bezier(0.2, 1.4, 0.3, 1) forwards; }
.callout.hold { animation: calloutin 0.25s cubic-bezier(0.2, 1.4, 0.3, 1) forwards; }
.callout small { display: block; font-size: 15px; font-style: normal; letter-spacing: 0.1em; font-weight: 700; color: #dfe7ef; margin-top: 4px; }
.callout.red { color: #ff4655; }
.callout.green { color: #55f2a0; }
.callout.gold { color: var(--yellow); }
.callout.white { color: #fff; }
@keyframes callout { 0% { opacity: 0; transform: scale(0.7); } 18% { opacity: 1; transform: scale(1); } 75% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.05); } }
@keyframes calloutin { to { opacity: 1; transform: scale(1); } }
.coach { position: absolute; left: 16px; right: 16px; bottom: calc(clamp(184px, 32vh, 280px) + 18px + var(--sab)); padding: 12px 14px; border-radius: 16px; background: rgba(12, 16, 22, 0.92); border: 1px solid rgba(63, 224, 255, 0.45); font-size: 15px; line-height: 1.5; text-align: center; box-shadow: 0 0 30px -10px rgba(63, 224, 255, 0.7); animation: sheetin 0.3s; }
.coach b { color: var(--cyan); }

#hud.ending .hud-bottom, #hud.ending .lamps { opacity: 0; transform: translateY(30px); pointer-events: none; }
#hud.ending .hud-bottom * { pointer-events: none !important; }
.hud-bottom { transition: opacity 0.35s, transform 0.35s; position: absolute; left: 0; right: 0; bottom: 0; height: calc(clamp(184px, 32vh, 280px) + var(--sab)); padding: 0 calc(12px + var(--sar)) calc(12px + var(--sab)) calc(12px + var(--sal)); display: flex; gap: 10px; align-items: flex-end; }
.handbrake { flex: 0 0 auto; width: 84px; height: 108px; border-radius: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; font-weight: 800; transition: transform 0.1s; }
.handbrake img { width: 58px; height: 58px; }
.handbrake:disabled { opacity: 0.35; filter: grayscale(1); }
.handbrake:not(:disabled) { border-color: var(--red); animation: pulse 0.7s ease-in-out infinite; }
.handbrake.held { transform: scale(0.94); background: rgba(120, 10, 20, 0.85); }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 45, 61, 0.25), 0 0 30px rgba(255, 45, 61, 0.6); } }
.pedal-zone { flex: 1 1 auto; height: 100%; border-radius: 26px; display: flex; gap: 10px; padding: 12px; background: linear-gradient(180deg, rgba(12, 16, 22, 0.35), rgba(12, 16, 22, 0.85)); border: 1px solid rgba(255, 255, 255, 0.1); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); touch-action: none; position: relative; }
.pedal-zone.active { border-color: rgba(255, 90, 31, 0.7); box-shadow: inset 0 0 40px -10px rgba(255, 90, 31, 0.6); }
.pedal-zone.disabled { opacity: 0.55; }
.force { flex: 0 0 52px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.force-bar { position: relative; flex: 1; width: 16px; border-radius: 9px; background: linear-gradient(180deg, rgba(61, 220, 132, 0.28) 0%, rgba(61, 220, 132, 0.28) var(--stress, 61%), rgba(255, 45, 61, 0.35) var(--stress, 61%), rgba(255, 45, 61, 0.45) 100%); overflow: visible; }
.force-fill { position: absolute; left: 0; right: 0; top: 0; height: 0%; border-radius: 9px; background: linear-gradient(180deg, var(--green), var(--yellow) 60%, var(--red)); box-shadow: 0 0 12px rgba(255, 140, 40, 0.6); }
.mark { position: absolute; left: -8px; right: -8px; height: 3px; border-radius: 2px; }
.mark.stress { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.mark.lockline { background: var(--red); box-shadow: 0 0 6px var(--red); height: 4px; }
.mark.lockline::after { content: '抱死'; position: absolute; left: 30px; top: -8px; font-size: 10px; font-weight: 900; color: var(--red); white-space: nowrap; }
.force b { font-size: 12px; font-weight: 800; white-space: nowrap; }
.pedal-well { flex: 1; position: relative; display: flex; justify-content: center; align-items: flex-start; border-radius: 18px; background: radial-gradient(70% 60% at 50% 40%, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0)); }
.pedal-img { height: 82%; width: auto; max-width: 100%; object-fit: contain; transform-origin: 50% 0%; filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.7)); transition: filter 0.2s; }
.pedal-hint { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 13px; font-weight: 800; color: #dfe7ef; text-shadow: 0 1px 4px #000; transition: opacity 0.2s; }
.pedal-hint small { font-weight: 600; color: var(--muted); font-size: 11px; }
.pedal-zone.active .pedal-hint { opacity: 0; }

#countdown { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 15; font-size: 120px; font-weight: 900; font-style: italic; color: #fff; text-shadow: 0 8px 0 rgba(0, 0, 0, 0.3), 0 0 40px rgba(255, 90, 31, 0.8); }
#countdown span { animation: count 0.7s cubic-bezier(0.2, 1.4, 0.3, 1) forwards; }
#countdown span.go { color: var(--green); font-size: 90px; text-shadow: 0 0 40px rgba(61, 220, 132, 0.9); }
@keyframes count { from { transform: scale(1.8); opacity: 0; } 30% { transform: scale(1); opacity: 1; } to { transform: scale(0.9); opacity: 0.0; } }

/* ---------- result ---------- */
.result-banner { display: flex; gap: 12px; align-items: center; }
.result-banner img { width: 58px; height: 58px; flex: 0 0 auto; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.6)); }
.result-banner h2 { font-size: 28px; font-style: italic; }
.result-banner p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.result-banner.good h2 { color: #55f2a0; }
.result-banner.perfect h2 { color: var(--yellow); }
.result-banner.bad h2 { color: #ff5965; }
.stars { display: flex; justify-content: center; gap: 6px; margin: -4px 0; }
.stars img { width: 50px; height: 50px; opacity: 0; transform: scale(0.3) rotate(-30deg); }
.stars img.pop { animation: starpop 0.45s cubic-bezier(0.2, 1.6, 0.3, 1) forwards; }
.stars img:nth-child(2) { width: 62px; height: 62px; margin-top: -10px; }
@keyframes starpop { to { opacity: 1; transform: scale(1) rotate(0); } }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.stat { padding: 8px 6px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat img { width: 24px; height: 24px; }
.stat b { font-size: 17px; font-weight: 900; }
.stat small { font-size: 11px; color: var(--muted); }
.stat.hl { border-color: rgba(255, 194, 26, 0.6); background: rgba(255, 194, 26, 0.08); }
.stat.bad b { color: #ff6b75; }
.breakdown { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.breakdown div { display: flex; justify-content: space-between; color: #c7d2de; padding: 2px 4px; opacity: 0; animation: rowin 0.25s forwards; }
@keyframes rowin { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.breakdown div b { color: var(--ink); }
.result-tip { margin: 0; display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 14px; background: rgba(63, 224, 255, 0.07); border: 1px solid rgba(63, 224, 255, 0.3); font-size: 13.5px; line-height: 1.5; color: #d6e6f2; }
.result-tip img { width: 28px; height: 28px; flex: 0 0 auto; }
.total-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 14px; background: linear-gradient(90deg, rgba(255, 90, 31, 0.18), rgba(255, 90, 31, 0.04)); border: 1px solid rgba(255, 90, 31, 0.35); }
.total-row span { font-weight: 700; color: #ffd9c4; }
.total-row b { margin-left: auto; font-size: 30px; font-weight: 900; font-style: italic; }
.badge-new { font-style: normal; font-size: 12px; font-weight: 900; color: #1a1200; background: var(--yellow); padding: 3px 8px; border-radius: 8px; animation: emblem 1.2s ease-in-out infinite; }

/* ---------- summary ---------- */
.summary-hero { text-align: center; }
.summary-hero b { font-size: 64px; font-weight: 900; font-style: italic; line-height: 1; background: linear-gradient(180deg, #fff, #ffb48c); -webkit-background-clip: text; background-clip: text; color: transparent; }
.summary-hero small { display: block; color: var(--muted); font-size: 14px; margin-top: 4px; font-weight: 700; }
.summary-rank { text-align: center; font-size: 14px; font-weight: 700; color: var(--cyan); min-height: 1.2em; }
.summary-list { display: flex; flex-direction: column; gap: 6px; max-height: 34vh; overflow-y: auto; }
.summary-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-size: 14px; }
.summary-item img { width: 24px; height: 24px; }
.summary-item span { flex: 1; color: #c7d2de; }
.summary-item b { font-weight: 900; }
.summary-item.bad b { color: #ff6b75; }
.summary-item.best { border-color: rgba(255, 194, 26, 0.55); }

/* ---------- leaderboard ---------- */
.board-card { height: min(86vh, 720px); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; min-height: 44px; padding: 0 14px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-weight: 800; font-size: 14px; color: var(--muted); }
.tab[aria-selected='true'] { background: linear-gradient(180deg, #ff7a3d, var(--orange)); color: #fff; border-color: transparent; }
.board-note { margin: 0; font-size: 12.5px; color: var(--muted); text-align: center; min-height: 1em; }
.board-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; min-height: 120px; }
.board-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 48px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.board-row .rk { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 900; font-size: 15px; background: rgba(255, 255, 255, 0.08); flex: 0 0 auto; }
.board-row:nth-child(1) .rk { background: linear-gradient(180deg, #ffe27a, #e0a400); color: #3a2600; }
.board-row:nth-child(2) .rk { background: linear-gradient(180deg, #f1f5f9, #9aa7b6); color: #1d2530; }
.board-row:nth-child(3) .rk { background: linear-gradient(180deg, #ffc69a, #c46a2a); color: #3a1800; }
.board-row .nm { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .sc { font-weight: 900; font-style: italic; font-size: 17px; }
.board-row.me { border-color: rgba(63, 224, 255, 0.6); background: rgba(63, 224, 255, 0.08); }
.board-empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; line-height: 1.6; }
.board-empty img { width: 64px; height: 64px; display: block; margin: 0 auto 10px; opacity: 0.8; }
.board-me:empty { display: none; }
.skeleton { height: 48px; border-radius: 14px; background: linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.04)); background-size: 200% 100%; animation: sk 1.1s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- help ---------- */
.help-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.help-list li { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.help-list img { width: 34px; height: 34px; flex: 0 0 auto; }
.help-list p { margin: 0; font-size: 14px; line-height: 1.6; color: #c7d2de; }
.help-list b { color: var(--ink); }

/* ---------- rename ---------- */
#renameInput { width: 100%; height: 52px; border-radius: 14px; border: 1px solid rgba(255, 255, 255, 0.18); background: rgba(0, 0, 0, 0.35); color: var(--ink); font: inherit; font-size: 18px; padding: 0 14px; outline: none; -webkit-user-select: text; user-select: text; }
#renameInput:focus { border-color: var(--cyan); }

#toast { position: absolute; left: 50%; top: calc(14px + var(--sat)); transform: translateX(-50%); z-index: 60; padding: 10px 16px; border-radius: 14px; background: rgba(12, 16, 22, 0.95); border: 1px solid var(--line); font-size: 14px; font-weight: 700; max-width: 90%; text-align: center; animation: sheetin 0.25s; }
#rotate { position: absolute; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 18px; font-weight: 800; }
#rotate img { width: 80px; height: 80px; transform: rotate(90deg); }

/* ---------- short / narrow screens ---------- */
@media (max-height: 680px) {
  .callout { top: calc(126px + var(--sat)); font-size: 30px; }
  .gauge-val b { font-size: 24px; }
  .gauge { min-height: 44px; }
  .hud-chips { top: calc(58px + var(--sat)); }
  .hud-chips .chip { height: 24px; }
  .gapmeter { top: calc(88px + var(--sat)); }
  .lamps { top: calc(124px + var(--sat)); }
  .hud-bottom { height: calc(max(180px, 34vh) + var(--sab)); }
  .handbrake { height: 92px; width: 76px; }
  .handbrake img { width: 46px; height: 46px; }
  .title-emblem { width: 64px; }
  .title-name { font-size: 46px; }
  .title-tag { margin-top: 6px; }
  .mode { height: 86px; }
  .stat b { font-size: 15px; }
  .stars img { width: 40px; height: 40px; }
  .stars img:nth-child(2) { width: 48px; height: 48px; }
  .sheet { gap: 10px; padding: 16px 14px 14px; }
}
@media (max-width: 370px) {
  .gauge.bracket { width: 112px; }
  .gauge-val b { font-size: 24px; }
  .mode-name { font-size: 17px; }
  .icon-btn.labeled { min-width: 0; padding: 0 10px; font-size: 14px; }
}
@media (min-width: 700px) and (min-height: 600px) {
  /* Desktop / tablet: keep the HUD in a phone-width column so thumbs-math still holds. */
  .hud-bottom { left: 50%; right: auto; width: 480px; transform: translateX(-50%); }
  .title-art { height: 78%; }
}
@media (prefers-reduced-motion: reduce) {
  .title-art img, .title-emblem { animation: none; }
  #vignette.on { animation: none; }
}
