:root {
  color-scheme: dark;
  --ink: #09090d;
  --black: #121217;
  --surface: #1b1b23;
  --surface-2: #262631;
  --paper: #fffaf4;
  --soft: #d8d1cb;
  --red: #e21d35;
  --pink: #ff8da1;
  --pink-light: #ffd3dc;
  --gold: #ffd84d;
  --line: rgba(255, 250, 244, 0.18);
  --focus: #fff36d;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--ink);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--paper);
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(255, 141, 161, 0.035) 50%, transparent 50.2%) 0 0 / 40px 40px,
    linear-gradient(rgba(255, 250, 244, 0.025) 1px, transparent 1px) 0 0 / 100% 5px,
    var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible, canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  min-height: 48px;
  padding: 0.7rem 1rem;
  color: var(--ink);
  background: var(--focus);
  font-weight: 900;
  text-decoration: none;
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.site-header, .hero, footer { width: min(1320px, calc(100% - 3rem)); margin-inline: auto; }

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 78px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 0.7rem;
  min-height: 52px;
  color: var(--paper);
  text-decoration: none;
}

.brand img { width: 48px; height: 48px; border: 1px solid var(--paper); background: white; object-fit: contain; }
.brand span { display: grid; line-height: 1; }
.brand strong { color: var(--pink); font-size: 1.02rem; font-weight: 950; letter-spacing: 0.2em; }
.brand small { margin-top: 0.28rem; font-size: 0.58rem; font-weight: 900; letter-spacing: 0.22em; }

.chapter, .mini-goal {
  margin: 0;
  color: var(--soft);
  font-size: 0.66rem;
  font-weight: 850;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.chapter { display: flex; align-items: center; gap: 0.65rem; }
.chapter span { width: 22px; height: 2px; background: var(--red); }
.mini-goal { display: grid; justify-self: end; gap: 0.12rem; text-align: right; }
.mini-goal strong { color: var(--paper); font-size: 0.76rem; }

.hero {
  display: grid;
  grid-template-columns: minmax(320px, 0.7fr) minmax(410px, 0.95fr);
  gap: clamp(2rem, 4vw, 4.5rem);
  align-items: center;
  padding-block: clamp(2rem, 4vw, 4rem);
}

.story-panel { min-width: 0; order: -1; }
.eyebrow { margin: 0 0 0.8rem; color: var(--pink); font-size: 0.67rem; font-weight: 950; letter-spacing: 0.18em; text-transform: uppercase; }

h1 {
  max-width: 9ch;
  margin: 0;
  color: var(--paper);
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(3.8rem, 7vw, 7rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 0.79;
  text-transform: uppercase;
  text-wrap: balance;
}

h1 span { display: block; color: var(--red); font-size: 0.56em; letter-spacing: 0.06em; text-shadow: 3px 3px 0 var(--paper); }
.lead { max-width: 35rem; margin: 1.5rem 0 0; color: var(--soft); font-size: clamp(0.92rem, 1.1vw, 1.02rem); line-height: 1.7; }

.mission-card {
  position: relative;
  margin-top: 1.6rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(255, 141, 161, 0.55);
  background: var(--surface);
  box-shadow: 5px 5px 0 rgba(226, 29, 53, 0.55);
}

.mission-card::before { position: absolute; top: -5px; left: 1rem; width: 52px; height: 9px; background: var(--pink); content: ""; transform: rotate(-3deg); }
.mission-heading { display: flex; justify-content: space-between; margin-bottom: 0.5rem; font-size: 0.65rem; font-weight: 950; letter-spacing: 0.12em; text-transform: uppercase; }
.mission-heading > span, .mission-card p { color: var(--soft); }
.mission-heading strong, .mission-card p strong { color: var(--pink); }
.mission-card p { margin: 0.65rem 0 0; font-size: 0.73rem; line-height: 1.55; }

.key-guide { display: grid; margin: 1.2rem 0 0; }
.key-guide div { display: flex; justify-content: space-between; padding: 0.55rem 0; border-bottom: 1px solid var(--line); font-size: 0.65rem; letter-spacing: 0.07em; text-transform: uppercase; }
.key-guide dt { color: var(--pink); font-weight: 950; }
.key-guide dd { margin: 0; color: var(--soft); text-align: right; }

.game-frame {
  position: relative;
  width: min(100%, 610px);
  min-width: 0;
  justify-self: end;
  padding: 6px;
  border: 2px solid var(--paper);
  background: var(--black);
  box-shadow: 10px 10px 0 var(--red), 0 0 34px rgba(255, 49, 94, 0.14);
}

.game-frame::after { position: absolute; inset: 3px; z-index: 8; border: 1px solid rgba(255, 141, 161, 0.35); content: ""; pointer-events: none; }
.frame-topbar { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--line); background: var(--black); }
.frame-topbar p { margin: 0; color: var(--soft); font-size: 0.57rem; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; }
.live-dot { display: inline-block; width: 7px; height: 7px; margin-right: 0.35rem; border-radius: 50%; background: var(--red); animation: pulse 1.5s ease-in-out infinite; }

.game-play-area { display: grid; }
.stage-wrap, .game-messages { grid-area: 1 / 1; }
.stage-wrap { position: relative; overflow: hidden; aspect-ratio: 4 / 5; background: #090912; isolation: isolate; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.hud {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  display: grid;
  grid-template-columns: 0.75fr 1fr 1fr;
  border-bottom: 1px solid rgba(255, 250, 244, 0.26);
  background: rgba(9, 9, 13, 0.9);
  pointer-events: none;
}

.hud-cell { display: grid; align-content: center; gap: 0.08rem; min-width: 0; padding: 0.45rem 0.6rem; }
.hud-cell:nth-child(2), .hud-cell:nth-child(3), .hud-cell:nth-child(5) { border-left: 1px solid rgba(255, 250, 244, 0.18); }
.hud-cell span { overflow: hidden; color: var(--pink-light); font-size: 0.49rem; font-weight: 900; letter-spacing: 0.1em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.hud-cell strong { color: var(--paper); font-size: clamp(0.8rem, 2.4vw, 1.25rem); font-weight: 950; letter-spacing: 0.03em; white-space: nowrap; }
.hud-time strong { color: var(--focus); }
.hud-time.is-urgent strong { color: var(--paper); animation: urgent 500ms steps(2) infinite; }
.hud-hearts strong { color: var(--red); letter-spacing: 0.06em; }
.hud-nitro { grid-column: span 2; border-top: 1px solid rgba(255, 250, 244, 0.18); }
.hud-cell:nth-child(5) { border-top: 1px solid rgba(255, 250, 244, 0.18); }

progress { display: block; width: 100%; height: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 0; background: var(--surface-2); }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--red), var(--gold)); }
progress::-moz-progress-bar { background: var(--gold); }

.game-messages { position: relative; z-index: 4; pointer-events: none; }
.game-overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: clamp(0.75rem, 4vw, 2rem); background: radial-gradient(circle at 50% 35%, rgba(226, 29, 53, 0.18), rgba(9, 9, 13, 0.82) 62%); pointer-events: auto; }
.overlay-card { width: min(470px, 100%); padding: clamp(0.85rem, 3vw, 1.4rem); border: 2px solid var(--red); background: linear-gradient(145deg, rgba(36, 29, 41, 0.98), rgba(17, 17, 23, 0.99)); box-shadow: 6px 6px 0 var(--paper); }
.overlay-card.compact { max-width: 340px; text-align: center; }
.overlay-kicker { color: var(--pink); font-size: 0.56rem; font-weight: 950; letter-spacing: 0.16em; text-transform: uppercase; }
.overlay-card h2 { margin: 0.35rem 0 0.65rem; color: var(--paper); font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: clamp(1.75rem, 6vw, 2.8rem); font-weight: 900; letter-spacing: 0.04em; line-height: 0.95; text-transform: uppercase; }
.overlay-card p { margin: 0 0 0.9rem; color: var(--soft); font-size: 0.75rem; line-height: 1.5; }

.rider-options { display: grid; gap: 0.45rem; margin-bottom: 0.7rem; }
.rider-card { position: relative; display: grid; grid-template-columns: 58px minmax(0, 1fr); align-items: center; gap: 0.6rem; min-width: 0; min-height: 68px; padding: 0.3rem; border: 1px solid var(--line); color: var(--paper); background: var(--black); text-align: left; cursor: pointer; transition: border-color 150ms ease, background 150ms ease, transform 150ms ease; }
.rider-card:hover { border-color: var(--pink); transform: translateX(2px); }
.rider-card.is-selected { border: 2px solid var(--pink); background: linear-gradient(135deg, rgba(49, 21, 27, 0.98), rgba(19, 19, 25, 0.98)); box-shadow: inset 5px 0 var(--red), 0 0 0 1px rgba(255, 141, 161, 0.18); }
.rider-card.is-selected::after { position: absolute; top: 0.35rem; right: 0.4rem; display: grid; place-items: center; width: 18px; height: 18px; color: var(--ink); background: var(--focus); content: "✓"; font-size: 0.7rem; font-weight: 950; }
.rider-card.is-selected img { filter: saturate(1.08) contrast(1.08); }
.rider-card img { width: 58px; height: 58px; border: 1px solid var(--paper); object-fit: cover; object-position: center 22%; filter: saturate(0.95) contrast(1.05); }
.rider-card span { display: grid; min-width: 0; }
.rider-card strong { font-size: 0.77rem; letter-spacing: 0.06em; }
.rider-card small { margin-top: 0.15rem; color: var(--pink-light); font-size: 0.57rem; line-height: 1.25; }
.rider-card em { margin-top: 0.15rem; color: var(--soft); font-size: 0.48rem; font-style: normal; letter-spacing: 0.05em; text-transform: uppercase; }
.rider-card em b { color: var(--focus); }

.primary-button, .secondary-button, .drive-controls button, .utility-controls button { min-height: 52px; border: 0; font-size: 0.63rem; font-weight: 950; letter-spacing: 0.08em; text-transform: uppercase; cursor: pointer; }
.primary-button { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0.65rem 0.8rem; border: 2px solid var(--paper); color: var(--paper); background: var(--red); transition: filter 150ms ease, transform 150ms ease; }
.primary-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.secondary-button { width: 100%; border: 1px solid var(--line); color: var(--paper); background: var(--black); }
.secondary-button:hover { border-color: var(--pink); }

.countdown-overlay { background: rgba(9, 9, 13, 0.72); }
.countdown-overlay > div { display: grid; justify-items: center; color: var(--paper); text-transform: uppercase; }
.countdown-overlay span { font-size: 0.65rem; font-weight: 950; letter-spacing: 0.22em; }
.countdown-overlay strong { color: var(--focus); font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: clamp(5rem, 22vw, 10rem); line-height: 0.9; text-shadow: 5px 5px 0 var(--red); animation: countdown 650ms ease-out infinite; }

.race-callout { position: absolute; top: 31%; left: 50%; z-index: 3; pointer-events: none; transform: translateX(-50%) rotate(-3deg); animation: callout-in 260ms ease-out; }
.race-callout strong { display: block; padding: 0.25rem 0.45rem; color: var(--ink); background: var(--focus); font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif; font-size: clamp(1.2rem, 4.5vw, 2rem); letter-spacing: 0.05em; white-space: nowrap; box-shadow: 4px 4px 0 var(--red); text-shadow: 0 0 12px rgba(255, 216, 77, 0.35); }

.result-card { max-width: 450px; }
.new-record { display: inline-block; margin: 0 0 0.7rem !important; padding: 0.3rem 0.55rem; color: var(--black) !important; background: var(--focus); font-weight: 950; letter-spacing: 0.12em; text-transform: uppercase; }
.result-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1px; margin: 0 0 0.75rem; background: var(--line); }
.result-stats div { display: grid; align-content: center; gap: 0.2rem; min-width: 0; padding: 0.55rem 0.25rem; background: var(--black); text-align: center; }
.result-stats dt { overflow: hidden; color: var(--soft); font-size: 0.42rem; font-weight: 850; letter-spacing: 0.05em; text-overflow: ellipsis; text-transform: uppercase; }
.result-stats dd { margin: 0; color: var(--pink); font-size: clamp(0.72rem, 3vw, 1.05rem); font-weight: 950; white-space: nowrap; }
.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }

.race-panel { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 0.65rem; padding: 0.65rem 0.7rem; border-top: 1px solid var(--line); background: var(--surface); }
.race-title { color: var(--pink); font-size: 0.55rem; font-weight: 950; letter-spacing: 0.13em; text-transform: uppercase; }
.race-track { position: relative; height: 38px; border: 1px solid var(--line); background: repeating-linear-gradient(90deg, #17171e 0 24px, #20202a 24px 48px); }
.race-track::before { position: absolute; top: 50%; right: 0; left: 0; height: 1px; background: rgba(255,255,255,.2); content: ""; }
.finish-mark { position: absolute; top: 0; right: 4px; z-index: 1; color: var(--paper); font-size: 1.8rem; line-height: 36px; }
.race-marker { position: absolute; top: 3px; left: 0; z-index: 2; display: grid; width: 30px; height: 30px; overflow: hidden; border: 2px solid var(--paper); border-radius: 50%; background: var(--red); transform: translateX(-50%); transition: left 200ms linear; }
.race-marker img { width: 100%; height: 100%; object-fit: cover; object-position: center 22%; }
.race-marker b { position: absolute; right: 0; bottom: 0; display: grid; place-items: center; width: 11px; height: 11px; color: var(--ink); background: var(--focus); font-size: 0.43rem; }
.race-marker.is-selected { border-color: var(--focus); box-shadow: 0 0 0 2px var(--red), 0 0 14px rgba(255, 216, 77, 0.35); }
.race-marker.is-gustavo { place-items: center; color: var(--paper); border-color: var(--red); background: #050508; font-weight: 950; }
.race-marker.is-gustavo b { position: static; width: auto; height: auto; color: var(--paper); background: none; font-size: 0.85rem; }

.control-bar { position: relative; z-index: 9; display: grid; grid-template-columns: 1fr auto; gap: 1px; border-top: 1px solid var(--line); background: var(--red); }
.drive-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; min-width: 0; background: var(--red); }
.drive-controls button, .utility-controls button { color: var(--paper); background: var(--black); }
.drive-controls button { display: flex; align-items: center; justify-content: center; gap: 0.4rem; min-width: 0; min-height: 56px; padding: 0.35rem; touch-action: manipulation; }
.drive-controls button:hover:not(:disabled), .drive-controls button:active:not(:disabled), .drive-controls button.is-active, .utility-controls button:hover:not(:disabled), .utility-controls button:active:not(:disabled) { background: var(--surface-2); box-shadow: inset 0 -4px var(--pink); }
.drive-controls button.is-active { color: var(--focus); box-shadow: inset 0 -4px var(--gold), 0 0 14px rgba(255, 216, 77, 0.22); }
.drive-controls button:disabled, .utility-controls button:disabled { color: #77717a; cursor: not-allowed; }
kbd { display: inline-grid; place-items: center; min-width: 26px; min-height: 26px; border: 1px solid var(--pink); color: var(--pink); background: transparent; font: inherit; white-space: nowrap; }
.utility-controls { display: grid; grid-template-columns: repeat(2, 52px); gap: 1px; }
.utility-controls button { min-width: 52px; min-height: 56px; }

body.is-turbo .game-frame { border-color: var(--focus); box-shadow: 10px 10px 0 var(--gold), 0 0 34px rgba(255, 216, 77, 0.32); }
body.is-turbo .hud { background: linear-gradient(180deg, rgba(33, 26, 12, 0.96), rgba(9, 9, 13, 0.94)); }
body.is-turbo .hud-time strong,
body.is-turbo .hud-nitro strong { color: var(--gold); text-shadow: 0 0 12px rgba(255, 216, 77, 0.4); }
body.is-turbo progress::-webkit-progress-value { background: linear-gradient(90deg, var(--gold), #fff36d); }
body.is-turbo progress::-moz-progress-bar { background: var(--gold); }
body.is-turbo .race-callout strong { background: var(--gold); color: var(--ink); }

body.is-hit .stage-wrap { animation: shake 180ms linear; }
body.is-hit .hud { animation: hit-glow 180ms ease; }
body.is-hit .race-callout strong { background: var(--red); color: var(--paper); }

footer { display: flex; justify-content: space-between; padding-block: 1rem 1.6rem; border-top: 1px solid var(--line); }
footer p { margin: 0; color: var(--soft); font-size: 0.56rem; font-weight: 850; letter-spacing: 0.14em; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes pulse { 50% { opacity: 0.3; } }
@keyframes urgent { 50% { opacity: 0.3; } }
@keyframes countdown { from { opacity: 0.4; transform: scale(1.2); } to { opacity: 1; transform: scale(1); } }
@keyframes callout-in { from { opacity: 0; transform: translateX(-50%) scale(1.45) rotate(-6deg); } }
@keyframes hit-glow {
  0% { box-shadow: inset 0 0 0 rgba(255, 29, 53, 0); }
  50% { box-shadow: inset 0 0 0 999px rgba(255, 29, 53, 0.12); }
  100% { box-shadow: inset 0 0 0 rgba(255, 29, 53, 0); }
}
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

@media (min-width: 741px) {
  .hero { padding-block: min(2rem, 1.5vh); }
  .game-frame { width: min(100%, 610px, max(390px, calc(80vh - 224px))); width: min(100%, 610px, max(390px, calc(80dvh - 224px))); }
}

@media (min-width: 741px) and (max-width: 1060px) {
  .hero { grid-template-columns: minmax(260px, 0.65fr) minmax(390px, 1fr); gap: 2rem; }
  .chapter { display: none; }
  .site-header { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 740px) {
  .site-header, .hero, footer { width: min(100% - 1.25rem, 720px); }
  .site-header { grid-template-columns: 1fr auto; min-height: 68px; }
  .chapter { display: none; }
  .mini-goal > span { display: none; }
  .brand img { width: 44px; height: 44px; }
  .hero { grid-template-columns: 1fr; gap: 1.75rem; padding-block: 1.25rem max(2.3rem, env(safe-area-inset-bottom)); }
  .game-frame { order: 0; width: 100%; margin-inline: 0; justify-self: stretch; }
  .story-panel { order: 1; }
  h1 { max-width: none; font-size: clamp(3.4rem, 18vw, 6rem); }
  .lead { margin-top: 1.2rem; line-height: 1.55; }
  .control-bar { position: sticky; bottom: 0; padding-bottom: env(safe-area-inset-bottom); }
}

@media (max-width: 430px) {
  .site-header, .hero, footer { width: calc(100% - 0.75rem); }
  .brand small { font-size: 0.52rem; }
  .mini-goal { font-size: 0.58rem; }
  .game-frame { padding: 3px; border-right: 0; border-left: 0; box-shadow: 0 8px 0 var(--red); }
  .frame-topbar { padding: 0.5rem; }
  .frame-topbar p { font-size: 0.48rem; }
  .hud-cell { padding: 0.34rem 0.38rem; }
  .hud-cell span { font-size: 0.4rem; }
  .hud-cell strong { font-size: 0.78rem; }
  .hud-nitro { padding-block: 0.3rem; }
  .game-overlay { padding: 0.65rem; }
  .overlay-card { padding: 0.7rem; box-shadow: 4px 4px 0 var(--paper); }
  .overlay-card h2 { margin-block: 0.22rem 0.5rem; }
  .overlay-kicker { font-size: 0.45rem; }
  .rider-options { gap: 0.3rem; margin-bottom: 0.45rem; }
  .rider-card { grid-template-columns: 50px minmax(0, 1fr); min-height: 57px; gap: 0.45rem; padding: 0.2rem; }
  .rider-card img { width: 50px; height: 50px; }
  .rider-card strong { font-size: 0.68rem; }
  .rider-card small { font-size: 0.5rem; }
  .rider-card em { font-size: 0.43rem; }
  .primary-button, .secondary-button { min-height: 48px; }
  .race-panel { gap: 0.4rem; padding: 0.5rem; }
  .race-title { font-size: 0.46rem; }
  .drive-controls button { min-height: 58px; padding: 0.25rem; }
  .drive-controls button span { font-size: 0.5rem; letter-spacing: 0.04em; }
  .utility-controls { grid-template-columns: repeat(2, 44px); }
  .utility-controls button { min-width: 44px; min-height: 58px; }
  .result-stats { grid-template-columns: repeat(3, 1fr); }
  .result-actions { grid-template-columns: 1fr; }
  footer { padding-inline: 0.25rem; }
}

@media (max-width: 350px) {
  .drive-controls button { flex-direction: column; gap: 0.15rem; }
  .drive-controls button kbd { min-width: 24px; min-height: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  body.is-hit .stage-wrap { transform: none; }
}
