:root {
  --yellow: #efdf00;
  --black: #000;
  --ink: #0d0f12;
  --white: #fff;
  --grey: #8a8f94;
  --font: "Outfit", "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--white);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.label {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.7);
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--yellow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 28px;
  border: 2px solid transparent;
  border-radius: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: background .15s, color .15s, transform .1s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--yellow); color: #000; }
.btn.primary:hover { background: #fff; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,0.6); color: #fff; }
.btn.ghost:hover { background: #fff; color: #000; border-color: #fff; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:hover { background: #000; color: var(--yellow); }
.btn-sound .off { display: none; }
.btn-sound[aria-pressed="true"] .on { display: none; }
.btn-sound[aria-pressed="true"] .off { display: block; }

#loader {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 28px;
  background: #000;
  transition: opacity .5s, visibility .5s;
}
#loader.done { opacity: 0; visibility: hidden; }
.loader-logo { width: 54px; height: 70px; color: #fff; }
.loader-bar { width: 160px; height: 3px; background: rgba(255,255,255,0.15); overflow: hidden; }
.loader-bar b { display: block; height: 100%; background: var(--yellow); transform: scaleX(0); transform-origin: left; transition: transform .2s; }

.screen { position: fixed; inset: 0; z-index: 10; }

#title { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; background: #000; animation: fade .5s ease both; }
#title .hero { position: absolute; inset: 0; }
#title .hero img { width: 100%; height: 100%; object-fit: cover; object-position: 60% 55%; }
#title::before {
  content: "";
  position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(90deg, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.78) 32%, rgba(0,0,0,0) 62%);
}
.title-panel {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; justify-content: center;
  padding: max(32px, var(--safe-t)) 48px 32px;
  overflow-y: auto;
  animation: rise .7s .1s cubic-bezier(.2,.8,.2,1) both;
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: auto; padding-bottom: 32px; font-size: 14px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.brand-logo { width: 30px; height: 39px; color: #fff; }
h1 { margin: 0 0 16px; font-size: clamp(36px, 4.4vw, 58px); line-height: 1.02; font-weight: 800; letter-spacing: -0.02em; }
h2 { margin: 0 0 24px; font-size: clamp(28px, 3vw, 40px); line-height: 1.05; font-weight: 800; letter-spacing: -0.01em; }
.lede { margin: 0 0 28px; font-size: 17px; line-height: 1.5; color: rgba(255,255,255,0.78); max-width: 40ch; }

.picker { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "head head" "sw photo"; align-items: center; gap: 12px 16px; padding: 18px 0; border-top: 1px solid rgba(255,255,255,0.18); border-bottom: 1px solid rgba(255,255,255,0.18); margin-bottom: 28px; }
.picker-head { grid-area: head; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.picker-name { font-weight: 700; font-size: 15px; }
.swatches { grid-area: sw; display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  width: 38px; height: 38px; padding: 0;
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.45), transparent 45%), var(--sw);
  transition: transform .15s, border-color .15s;
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-checked="true"] { border-color: var(--yellow); box-shadow: 0 0 0 3px #000, 0 0 0 5px var(--yellow); }
.picker-photo { grid-area: photo; width: 132px; aspect-ratio: 900 / 594; object-fit: cover; background: #e9e9e9; }

.title-actions { display: flex; align-items: center; gap: 24px; margin-bottom: 14px; }
.title-actions .btn { flex: 0 0 auto; min-width: 210px; }
.best { display: grid; gap: 2px; }
.best span:last-child { font-size: 22px; font-weight: 700; }
.controls-hint { margin: 0 0 auto; font-size: 13px; color: rgba(255,255,255,0.55); padding-bottom: 8px; }
.touch-only { display: none; }
.partner { display: flex; align-items: center; gap: 12px; margin: 4px 0 0; }
.partner[hidden] { display: none; }
.credit { display: inline-block; margin-top: 14px; font-size: 12px; letter-spacing: 0.04em; color: rgba(255,255,255,0.55); text-decoration: none; }
.credit b { color: #fff; font-weight: 700; }
.credit:hover b { color: var(--yellow); }
.over-main .credit { margin-top: 18px; }
.partner-label { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.6); }
.partner-badge { display: inline-flex; white-space: nowrap; align-items: center; gap: 8px; min-height: 34px; padding: 6px 12px; background: var(--partner); color: var(--partner-ink); font-size: 13px; font-weight: 700; }
.partner-mark { width: 18px; height: 18px; fill: currentColor; color: var(--partner-ink); flex: none; }
.partner-logo { height: 22px; width: auto; display: block; }
.partner.has-logo .partner-mark, .partner-logo[hidden], .partner-name[hidden] { display: none; }
.over-main .partner { margin: -12px 0 24px; }
body.touch .touch-only { display: block; }
body.touch .desktop-only { display: none; }
.title-sound { position: absolute; z-index: 3; top: max(20px, var(--safe-t)); right: 20px; }

#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: flex-start; gap: 12px;
  padding: max(16px, var(--safe-t)) 18px 0;
}
.hud-score, .hud-diamonds {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 8px 14px;
}
.hud-score { display: grid; border-left: 4px solid var(--yellow); }
.hud-score .value { font-size: 28px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.hud-diamonds { display: flex; align-items: center; gap: 8px; font-size: 22px; font-weight: 700; align-self: stretch; }
.hud-diamonds svg { width: 16px; height: 21px; color: var(--yellow); }
.hud-actions { margin-left: auto; display: flex; gap: 8px; pointer-events: auto; }

.cluster {
  position: absolute; left: 50%; bottom: calc(16px + var(--safe-b));
  transform: translateX(-50%);
  display: grid; grid-template-columns: auto 220px auto; align-items: center; gap: 22px;
  padding: 12px 22px;
  background: linear-gradient(180deg, rgba(10,14,20,0.82), rgba(0,0,0,0.88));
  border-top: 2px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.cluster-speed, .cluster-dist { display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.cluster-speed span { font-size: 40px; font-weight: 800; min-width: 2.4ch; text-align: right; line-height: 1; }
.cluster-dist span { font-size: 26px; font-weight: 700; line-height: 1; }
.cluster small { font-size: 12px; color: rgba(255,255,255,0.6); letter-spacing: 0.06em; }
.cluster-bars { display: grid; gap: 8px; }
.gauge { display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 10px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: rgba(255,255,255,0.7); }
.gauge i { display: block; height: 8px; background: rgba(255,255,255,0.12); overflow: hidden; }
.gauge b { display: block; height: 100%; transform-origin: left; transform: scaleX(0); transition: transform .2s linear; }
.gauge.fuel b { background: linear-gradient(90deg, #2fbf5a, #7fe08f); }
.gauge.fuel.low b { background: #ff4b3a; animation: blink .5s steps(2) infinite; }
.gauge.fuel.low span { color: #ff6a5a; }
.gauge.turbo b { background: linear-gradient(90deg, #1aa6e0, #7fe3ff); transition: none; }
.gauge.turbo.on span { color: #7fe3ff; }

#toast {
  position: absolute; left: 0; right: 0; top: 24%;
  text-align: center;
  font-size: clamp(40px, 7vw, 84px);
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  opacity: 0;
  text-shadow: 0 4px 24px rgba(0,0,0,0.45);
}
#toast small { display: block; margin-top: 6px; font-size: clamp(13px, 1.4vw, 16px); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #fff; text-shadow: 0 1px 6px rgba(0,0,0,0.6); }
#toast.show { animation: pop 1.1s cubic-bezier(.2,.9,.2,1) both; }
#toast.gold { color: var(--yellow); }
#toast.green { color: #6be38a; }
#toast.blue { color: #7fe3ff; }
#toast.near { color: #fff; }
#toast.near small { color: var(--yellow); }
#toast.warn { color: #ff6a5a; }
#toast.count { font-size: clamp(80px, 14vw, 160px); color: #fff; }
#toast.count.go { color: var(--yellow); }

.touch-controls { display: none; }
body.touch .touch-controls {
  position: absolute; left: 0; right: 0; bottom: calc(96px + var(--safe-b));
  display: flex; justify-content: space-between; padding: 0 14px;
  pointer-events: none;
}
.pad { display: flex; gap: 10px; pointer-events: auto; }
.pad button {
  width: 72px; height: 68px;
  border: 0; border-radius: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  font-size: 15px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
  touch-action: none;
}
.pad button svg { width: 34px; height: 34px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: square; }
.pad button.down { background: rgba(255,255,255,0.85); color: #000; }
.pad button.down svg { stroke: #000; }
.pad .gas { background: rgba(239,223,0,0.9); color: #000; width: 88px; }
.pad .gas.down { background: #fff; }

.modal { display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); animation: fade .3s ease both; }
.card { background: #000; padding: 36px 40px; width: min(440px, 100%); border-top: 4px solid var(--yellow); animation: rise .5s cubic-bezier(.2,.8,.2,1) both; }
.stack { display: grid; gap: 12px; }
.stack.row { grid-template-columns: repeat(3, auto); justify-content: start; }

.over-card { width: min(900px, 100%); padding: 0; display: grid; grid-template-columns: 1fr 320px; }
.over-main { padding: 36px 40px; }
.over-score { display: flex; align-items: baseline; gap: 12px; margin-bottom: 20px; }
.over-score #overScore { font-size: clamp(48px, 7vw, 76px); font-weight: 800; line-height: 1; color: var(--yellow); font-variant-numeric: tabular-nums; }
.over-score em { font-style: normal; color: #000; background: var(--yellow); padding: 3px 8px; margin-left: 6px; letter-spacing: 0.08em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 0 0 28px; padding: 16px 0; border-top: 1px solid rgba(255,255,255,0.18); border-bottom: 1px solid rgba(255,255,255,0.18); }
.stats dt { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: rgba(255,255,255,0.6); margin-bottom: 4px; }
.stats dd { margin: 0; font-size: 22px; font-weight: 700; }
.over-cta { display: flex; flex-direction: column; background: #f2f2f2; color: #000; text-decoration: none; }
.over-cta img { width: 100%; aspect-ratio: 900 / 594; object-fit: cover; }
.cta-text { display: grid; gap: 4px; padding: 18px 22px 22px; flex: 1; align-content: start; }
.cta-model { font-size: 20px; font-weight: 800; }
.cta-colour, .cta-spec { font-size: 14px; color: #444; }
.cta-btn { margin-top: 14px; justify-self: start; background: #000; color: #fff; padding: 12px 18px; font-weight: 700; font-size: 15px; }
.over-cta:hover .cta-btn { background: var(--yellow); color: #000; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pop {
  0% { opacity: 0; transform: scale(.6); }
  15% { opacity: 1; transform: scale(1.08); }
  25% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px); }
}
@keyframes blink { 50% { opacity: .35; } }

@media (orientation: portrait), (max-width: 820px) {
  #title { grid-template-columns: 1fr; }
  #title::before { background: linear-gradient(180deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0) 22%, rgba(0,0,0,0.35) 45%, rgba(0,0,0,0.95) 72%); }
  #title .hero img { object-position: 50% 30%; }
  .title-panel { justify-content: flex-end; padding: max(20px, var(--safe-t)) 22px calc(22px + var(--safe-b)); }
  .brand { position: absolute; top: max(20px, var(--safe-t)); left: 22px; margin: 0; padding: 0; }
  h1 { font-size: clamp(32px, 9vw, 46px); }
  .lede { font-size: 15px; margin-bottom: 18px; }
  .picker { padding: 14px 0; margin-bottom: 18px; }
  .picker-photo { width: 96px; }
  .swatch { width: 34px; height: 34px; }
  .title-actions .btn { flex: 1; min-width: 0; }
  .controls-hint { margin: 0; }

  .cluster { grid-template-columns: auto 1fr auto; width: calc(100% - 24px); gap: 14px; padding: 10px 14px; }
  .cluster-speed span { font-size: 32px; }
  .cluster-dist span { font-size: 20px; }
  .gauge { grid-template-columns: 40px 1fr; font-size: 10px; }
  .hud-score .value { font-size: 22px; }

  .over-card { grid-template-columns: 1fr; max-height: 100%; overflow-y: auto; }
  .over-main { padding: 26px 22px; }
  .stack.row { grid-template-columns: 1fr 1fr; }
  .stack.row .btn.primary { grid-column: 1 / -1; }
  .over-cta { flex-direction: row; }
  .over-cta img { width: 42%; aspect-ratio: auto; }
  .cta-text { padding: 14px 16px; }
  .cta-model { font-size: 17px; }
  .cta-btn { margin-top: 8px; padding: 10px 14px; font-size: 14px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .title-panel { padding-top: 18px; padding-bottom: 18px; }
  .brand { padding-bottom: 14px; }
  h1 { font-size: 34px; }
  .lede { display: none; }
  .picker { padding: 10px 0; margin-bottom: 14px; }
  body.touch .touch-controls { bottom: calc(84px + var(--safe-b)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
