:root {
  --bg: #080b12;
  --panel: rgba(17, 24, 39, 0.94);
  --panel-2: #172033;
  --ink: #f8fafc;
  --muted: #9ca3af;
  --yellow: #ffd43b;
  --orange: #ff7a18;
  --red: #ef4444;
  --blue: #38bdf8;
  --green: #4ade80;
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { overflow-x: hidden; background-image: radial-gradient(circle at 10% 20%, rgba(255, 212, 59, 0.11), transparent 30%), radial-gradient(circle at 90% 75%, rgba(56, 189, 248, 0.1), transparent 28%), linear-gradient(135deg, #070a10, #111827); }
button, input, select { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

#app { min-height: 100vh; min-height: 100dvh; }
.screen { min-height: 100vh; min-height: 100dvh; }
.menu-screen { display: grid; grid-template-columns: minmax(280px, 0.9fr) minmax(340px, 1.1fr); align-items: center; gap: clamp(24px, 6vw, 84px); max-width: 1220px; margin: 0 auto; padding: clamp(24px, 5vw, 70px); }
.brand-card h1 { margin: 0; font-size: clamp(54px, 8vw, 112px); line-height: 0.82; letter-spacing: -0.07em; text-shadow: 0 7px 0 rgba(0,0,0,.3); }
.brand-card h1 span { color: var(--yellow); }
.eyebrow { margin: 0 0 12px; color: var(--yellow); font-weight: 900; letter-spacing: .16em; font-size: .78rem; }
.tagline { max-width: 540px; color: #cbd5e1; font-size: clamp(1rem, 2vw, 1.25rem); line-height: 1.55; }
.menu-card { background: linear-gradient(180deg, rgba(30,41,59,.96), rgba(15,23,42,.98)); border: 1px solid rgba(255,255,255,.1); box-shadow: 0 28px 80px rgba(0,0,0,.42); border-radius: var(--radius); padding: clamp(20px, 4vw, 36px); backdrop-filter: blur(18px); }
.menu-card.compact { width: min(440px, calc(100vw - 30px)); text-align: center; }
.menu-card label { display: grid; gap: 7px; color: #cbd5e1; font-size: .82rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 16px 0; }
input, select { width: 100%; min-height: 48px; border: 1px solid rgba(255,255,255,.12); border-radius: 10px; background: #0f172a; color: white; padding: 0 13px; outline: none; }
input:focus, select:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255,212,59,.14); }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 18px 0; }
.stat { background: rgba(255,255,255,.06); border-radius: 9px; padding: 10px 7px; text-align: center; }
.stat span { display: block; font-size: .62rem; color: var(--muted); letter-spacing: .08em; }
.stat strong { color: var(--yellow); }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
button { border: 1px solid rgba(255,255,255,.14); border-radius: 10px; background: #202b40; color: white; min-height: 46px; padding: 0 18px; font-weight: 900; letter-spacing: .04em; }
button:hover { filter: brightness(1.12); }
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(135deg, var(--yellow), var(--orange)); color: #111827; border: none; flex: 1; }
.text-button { margin-top: 14px; width: 100%; background: transparent; color: #a5b4fc; border: 0; }

.game-screen { position: fixed; inset: 0; overflow: hidden; background: black; }
#gameCanvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; }
.hud { position: absolute; top: max(12px, env(safe-area-inset-top)); display: flex; gap: 8px; pointer-events: none; }
.hud.top-left { left: max(12px, env(safe-area-inset-left)); }
.hud.top-right { right: max(56px, env(safe-area-inset-right)); }
.hud > div { min-width: 82px; border-radius: 10px; background: rgba(5,8,15,.76); border: 1px solid rgba(255,255,255,.12); padding: 7px 10px; backdrop-filter: blur(8px); }
.hud span { display: block; color: #94a3b8; font-size: .58rem; letter-spacing: .14em; font-weight: 900; }
.hud strong { font-variant-numeric: tabular-nums; }
.race-message { position: absolute; left: 50%; top: 23%; transform: translate(-50%, -50%); font-size: clamp(36px, 8vw, 88px); font-weight: 1000; font-style: italic; letter-spacing: -.06em; color: white; text-shadow: 0 5px 0 rgba(0,0,0,.5), 0 0 22px rgba(255,212,59,.5); pointer-events: none; }
.icon-button { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); min-width: 40px; min-height: 40px; padding: 0; background: rgba(5,8,15,.76); }
.reset-button { position: absolute; left: 50%; bottom: 24%; transform: translateX(-50%); min-height: 38px; font-size: .72rem; background: rgba(239,68,68,.85); }
.mobile-controls { position: absolute; inset: 0; pointer-events: none; display: none; opacity: .72; }
.mobile-controls button { pointer-events: auto; user-select: none; -webkit-user-select: none; border-radius: 999px; background: rgba(8,11,18,.72); border: 2px solid rgba(255,255,255,.35); box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.mobile-controls button.active { background: rgba(255,212,59,.86); color: #111827; transform: scale(.96); }
.steering-controls { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 12px; }
.steering-controls button { width: 72px; height: 72px; padding: 0; font-size: 24px; }
.pedal-controls { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; align-items: end; gap: 10px; }
.pedal-controls button { width: 74px; height: 74px; padding: 0 6px; font-size: .74rem; }
.pedal-controls .throttle { width: 88px; height: 88px; background: rgba(74,222,128,.72); font-size: 1.15rem; }
.pedal-controls .brake { background: rgba(239,68,68,.66); }
.pedal-controls .handbrake { width: 58px; height: 58px; font-size: .6rem; }

.panel-dialog { width: min(520px, calc(100vw - 24px)); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); color: white; background: linear-gradient(180deg, #1e293b, #0f172a); box-shadow: 0 30px 100px rgba(0,0,0,.65); padding: 26px; }
.panel-dialog::backdrop { background: rgba(2,6,23,.8); backdrop-filter: blur(8px); }
.panel-dialog h2 { margin: 0 0 18px; font-size: clamp(28px, 6vw, 50px); letter-spacing: -.05em; }
.wide-dialog { width: min(850px, calc(100vw - 24px)); max-height: min(86vh, 760px); overflow: auto; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; }
.close-dialog { min-width: 42px; min-height: 42px; padding: 0; font-size: 26px; }
.filter-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.leaderboard-content { min-height: 220px; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.leaderboard-table th, .leaderboard-table td { padding: 11px 9px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.08); }
.leaderboard-table th { color: #94a3b8; font-size: .7rem; letter-spacing: .09em; }
.leaderboard-table td:first-child { color: var(--yellow); font-weight: 1000; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.info-grid section { background: rgba(255,255,255,.05); border-radius: 12px; padding: 16px; }
.info-grid h3 { margin-top: 0; color: var(--yellow); }
.info-grid p { color: #cbd5e1; line-height: 1.55; }
.achievement-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; color: #cbd5e1; }
.achievement-row.unlocked { color: var(--green); }
.result-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 18px; }
.result-summary div { background: rgba(255,255,255,.06); border-radius: 10px; padding: 12px; }
.result-summary span { display: block; color: #94a3b8; font-size: .67rem; letter-spacing: .1em; }
.result-summary strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.achievement-pop { color: var(--green); font-weight: 900; margin-bottom: 14px; }
.pause-overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(2,6,23,.74); backdrop-filter: blur(10px); z-index: 10; }
.pause-overlay button { width: 100%; margin-top: 8px; }

@media (hover: none), (pointer: coarse) {
  .mobile-controls { display: block; }
  .reset-button { bottom: 31%; }
}

@media (max-width: 760px) {
  .menu-screen { grid-template-columns: 1fr; align-content: start; padding: 24px 16px 44px; }
  .brand-card h1 { font-size: clamp(54px, 17vw, 88px); }
  .tagline { margin-bottom: 0; }
  .menu-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .info-grid { grid-template-columns: 1fr; }
  .hud.top-right { top: 72px; right: 12px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud > div { min-width: 68px; padding: 5px 8px; }
  .steering-controls button { width: 62px; height: 62px; }
  .pedal-controls button { width: 62px; height: 62px; }
  .pedal-controls .throttle { width: 76px; height: 76px; }
  .pedal-controls .handbrake { width: 50px; height: 50px; }
}
