:root {
  color-scheme: dark;
  --bg: #031820;
  --panel: #082a35;
  --panel-2: #0b3440;
  --line: rgba(155, 226, 235, 0.18);
  --text: #effbfc;
  --muted: #9fc0c5;
  --cyan: #68dceb;
  --cyan-2: #a8edf4;
  --wood: #c39055;
  --gold: #f2c76f;
  --danger: #ff816d;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(63, 178, 194, 0.13), transparent 34rem),
    linear-gradient(180deg, #051e27 0%, #02141b 100%);
}
button { font: inherit; }
button:focus-visible { outline: 3px solid rgba(104, 220, 235, 0.48); outline-offset: 3px; }
.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}
.site-header {
  width: min(1480px, calc(100% - 28px));
  margin: 14px auto 0;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(5, 28, 36, .8);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .22);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { border-radius: 12px; object-fit: cover; }
.brand strong, .brand span { display: block; }
.brand strong { letter-spacing: .08em; font-size: .95rem; }
.brand span { color: var(--muted); font-size: .78rem; margin-top: 2px; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.small-button, .route-button, .secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(12, 54, 66, .68);
  border-radius: 11px;
  padding: 9px 12px;
  cursor: pointer;
}
.small-button:hover, .route-button:hover, .secondary-button:hover { background: rgba(24, 80, 94, .82); }
.header-actions a.small-button { display: inline-flex; align-items: center; text-decoration: none; }
main { width: min(1480px, calc(100% - 28px)); margin: 26px auto 40px; }
.intro { display: grid; grid-template-columns: 1fr auto; gap: 32px; align-items: end; margin-bottom: 18px; }
h1 { font-size: clamp(1.85rem, 3.7vw, 3.55rem); line-height: 1.02; margin: 0 0 10px; letter-spacing: -.045em; }
.intro p { max-width: 820px; color: var(--muted); margin: 0; line-height: 1.6; }
.intro-facts { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.intro-facts span { min-width: 116px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 14px; background: rgba(6, 37, 47, .78); color: var(--muted); }
.intro-facts strong { display: block; color: var(--cyan-2); font-size: 1.3rem; }
.game-shell { border: 1px solid var(--line); background: rgba(5, 31, 40, .88); border-radius: 22px; overflow: hidden; box-shadow: 0 28px 70px rgba(0,0,0,.28); }
.top-hud { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.hud-box { min-width: 0; padding: 12px 16px; background: #072832; }
.hud-box span, .hud-box strong { display: block; }
.hud-box span { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .09em; }
.hud-box strong { font-size: clamp(1.1rem, 2vw, 1.7rem); margin-top: 3px; white-space: nowrap; }
.hud-box.accent strong { color: var(--gold); }
.stage-wrap { position: relative; min-height: 690px; background: #051f29; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; min-height: 690px; touch-action: none; }
.vignette { pointer-events: none; position: absolute; inset: 0; box-shadow: inset 0 0 80px rgba(0,0,0,.38); }
.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px;
  background: radial-gradient(circle at 50% 40%, rgba(16, 75, 87, .88), rgba(3, 20, 27, .96) 66%);
  transition: opacity .25s ease, visibility .25s ease;
}
.start-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.start-overlay img { filter: drop-shadow(0 16px 22px rgba(0,0,0,.34)); }
.start-overlay h2 { margin: 2px 0 10px; font-size: clamp(1.8rem, 4vw, 3rem); }
.start-overlay > p:not(.eyebrow) { max-width: 690px; color: var(--muted); line-height: 1.55; margin: 0 0 20px; }
.eyebrow { margin: 6px 0; color: var(--gold); letter-spacing: .18em; font-size: .73rem; font-weight: 900; }
.route-picker { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 18px; }
.route-button.active { color: #06232c; background: var(--cyan); border-color: var(--cyan); font-weight: 800; }
.primary-button {
  min-width: 190px;
  border: 0;
  border-radius: 13px;
  padding: 13px 20px;
  background: linear-gradient(180deg, #87e8f2, #4dc5d4);
  color: #06252d;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(69, 197, 212, .22);
}
.primary-button:hover { filter: brightness(1.08); }
.countdown { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; pointer-events: none; color: white; font-size: clamp(5rem, 18vw, 12rem); font-weight: 1000; text-shadow: 0 16px 50px rgba(0,0,0,.55); opacity: 0; }
.countdown.visible { animation: pop .65s ease both; }
@keyframes pop { 0% { opacity: 0; transform: scale(.55); } 35% { opacity: 1; transform: scale(1.08); } 100% { opacity: 0; transform: scale(1.35); } }
.toast { position: absolute; top: 18px; left: 50%; z-index: 6; transform: translate(-50%, -14px); opacity: 0; padding: 10px 15px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; background: rgba(3,22,29,.9); transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.bottom-panel { display: grid; grid-template-columns: 1.1fr .9fr; gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.standings, .race-info { padding: 18px; background: #072832; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.panel-heading h2 { margin: 0; font-size: 1rem; }
.panel-heading span { color: var(--muted); font-size: .8rem; }
#standingsList { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#standingsList li { display: flex; gap: 10px; align-items: center; min-width: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 12px; background: rgba(4,29,37,.7); }
#standingsList li.player { border-color: rgba(104,220,235,.48); background: rgba(26,90,102,.34); }
.place { color: var(--gold); font-weight: 950; font-size: 1.15rem; }
.driver { min-width: 0; }
.driver strong, .driver span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.driver span { color: var(--muted); font-size: .72rem; margin-top: 2px; }
.race-info p { margin: 0 0 14px; color: var(--muted); line-height: 1.55; }
.secondary-button { width: 100%; }
.mobile-controls { display: none; position: absolute; z-index: 7; inset: auto 14px 14px 14px; justify-content: space-between; align-items: end; pointer-events: none; }
.mobile-controls button { pointer-events: auto; user-select: none; -webkit-user-select: none; touch-action: none; }
.virtual-stick {
  pointer-events: auto;
  position: relative;
  width: 142px;
  height: 142px;
  border-radius: 50%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: radial-gradient(circle at 50% 50%, rgba(104,220,235,.10) 0 34%, rgba(4,29,37,.58) 35% 100%);
  border: 1px solid rgba(168,237,244,.24);
  box-shadow: inset 0 0 26px rgba(0,0,0,.28), 0 12px 30px rgba(0,0,0,.18);
  backdrop-filter: blur(7px);
}
.stick-ring {
  position: absolute;
  inset: 18px;
  border: 1px solid rgba(168,237,244,.22);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #b9f4f8, #55cad8 70%);
  border: 2px solid rgba(255,255,255,.36);
  box-shadow: 0 8px 18px rgba(0,0,0,.34), inset 0 -5px 12px rgba(0,72,84,.26);
  transform: translate3d(0,0,0);
  transition: transform 70ms linear;
  will-change: transform;
}
.virtual-stick.active .stick-knob { transition: none; }
.stick-label {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  color: rgba(239,251,252,.52);
  font-size: .58rem;
  font-weight: 900;
  letter-spacing: .13em;
}
.boost { width: 88px; height: 88px; border-radius: 50%; border: 1px solid rgba(255,255,255,.2); color: #342108; background: radial-gradient(circle at 35% 28%, #fff0aa, #efb74f 70%); font-weight: 1000; box-shadow: 0 12px 28px rgba(0,0,0,.2); }
dialog { border: 0; padding: 0; background: transparent; color: var(--text); }
dialog::backdrop { background: rgba(0, 9, 12, .78); backdrop-filter: blur(8px); }
.result-card { position: relative; width: min(520px, calc(100vw - 28px)); padding: 28px; text-align: center; border: 1px solid var(--line); border-radius: 22px; background: #072832; box-shadow: 0 28px 80px rgba(0,0,0,.46); }
.result-card h2 { margin: 0 0 18px; font-size: 2rem; }
.dialog-close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); color: white; background: rgba(255,255,255,.06); cursor: pointer; }
.result-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 18px; }
.result-grid div { padding: 13px 8px; border: 1px solid var(--line); border-radius: 12px; background: rgba(3,22,29,.68); }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: var(--muted); font-size: .75rem; }
.result-grid strong { font-size: 1.3rem; margin-top: 4px; }
footer { width: min(1480px, calc(100% - 28px)); margin: 0 auto 26px; color: #799ca1; font-size: .78rem; text-align: center; }
footer code { color: var(--cyan-2); }
footer a { color: #ffcf69; }
.reward-box { margin: 18px 0 14px; padding: 16px; border: 1px solid rgba(255,190,69,.45); border-radius: 16px; background: rgba(255,190,69,.08); text-align: left; }
.reward-box p { margin: 0 0 12px; line-height: 1.45; }
.reward-box label { display: block; margin-bottom: 6px; font-weight: 800; }
.reward-row { display: flex; gap: 8px; }
.reward-row input { min-width: 0; flex: 1; border: 1px solid rgba(255,255,255,.18); border-radius: 12px; background: #07151c; color: #fff; padding: 12px; }
.reward-row .primary-button { white-space: nowrap; }
.reward-box small { display: block; margin-top: 8px; color: var(--muted); line-height: 1.4; }
.reward-box a { color: #ffcf69; }
.reward-result { margin-top: 12px; padding: 12px; border-radius: 12px; background: #0c2b25; border: 1px solid rgba(77,231,174,.4); }
.reward-result.is-error { background: #35191d; border-color: rgba(255,105,120,.5); }
.reward-code { display: block; margin: 8px 0; color: #ffcf69; font-size: clamp(20px,5vw,28px); letter-spacing: .08em; }
.reward-result a { display: inline-block; margin-top: 8px; }

#gameShell:fullscreen { width: 100vw; height: 100vh; border-radius: 0; display: grid; grid-template-rows: auto 1fr auto; }
#gameShell:fullscreen .stage-wrap, #gameShell:fullscreen canvas { min-height: 0; height: 100%; }
#gameShell:fullscreen .bottom-panel { max-height: 170px; }

@media (max-width: 880px) {
  .intro { grid-template-columns: 1fr; }
  .intro-facts { justify-content: flex-start; }
  .top-hud { grid-template-columns: repeat(3, 1fr); }
  .hud-box:nth-child(4), .hud-box:nth-child(5) { grid-column: span 1; }
  .stage-wrap, canvas { min-height: 600px; }
  .bottom-panel { grid-template-columns: 1fr; }
  #standingsList { grid-template-columns: repeat(2, 1fr); }
  .mobile-controls { display: flex; }
}
@media (max-width: 560px) {
  .site-header, main, footer { width: min(100% - 16px, 1480px); }
  .site-header { align-items: flex-start; }
  .brand img { width: 44px; height: 44px; }
  .small-button { padding: 8px 9px; font-size: .75rem; }
  main { margin-top: 18px; }
  .intro-facts span { min-width: 96px; flex: 1; }
  .top-hud { grid-template-columns: repeat(3, 1fr); }
  .hud-box { padding: 9px 10px; }
  .hud-box:nth-child(4), .hud-box:nth-child(5) { display: none; }
  .stage-wrap, canvas { min-height: 560px; }
  #standingsList { grid-template-columns: 1fr 1fr; }
  .start-overlay { padding: 18px; }
  .start-overlay img { width: 84px; height: auto; }
  .route-picker { gap: 5px; }
  .route-button { padding: 8px 9px; font-size: .78rem; }
  .reward-row { flex-direction: column; }
  .reward-row .primary-button { width: 100%; }
}

@media (pointer: coarse) {
  .mobile-controls { display: flex; }
}
