:root {
  --bg: #04060a;
  --fg: #e8fffb;
  --cyan: #5cf0ff;
  --amber: #ffb14b;
  --rose: #ff5c4b;
  --dim: #3a8e95;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "JetBrains Mono", "Courier New", ui-monospace, monospace;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: crosshair;
  touch-action: none;
}

/* CRT vignette — was a per-frame radial-gradient fillRect in JS; moved
   here so the compositor handles it without touching frame budget. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  background: radial-gradient(
    ellipse at center,
    transparent 35%,
    rgba(0, 0, 0, 0.55) 92%
  );
}

/* CRT scanlines — was the worst offender (67% of frame time on Firefox)
   when done as a per-frame "overlay" blend fillRect. As a fixed CSS
   pseudo-element it's effectively free. */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.04) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: overlay;
}

/* Top display — stacked TIME (big), stage pips, score (medium below) */
#top-display {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 11;
  user-select: none;
  text-align: center;
}

#timer {
  font-family: "Press Start 2P", "VT323", "Courier New", monospace;
  font-size: clamp(32px, 6vw, 64px);
  letter-spacing: 0.04em;
  color: var(--cyan);
  text-shadow:
    0 0 12px var(--cyan),
    0 0 28px var(--cyan),
    0 0 56px rgba(92, 240, 255, 0.55);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1;
}
#timer.warn {
  color: var(--amber);
  text-shadow: 0 0 12px var(--amber), 0 0 28px var(--amber);
}
#timer.crit {
  color: var(--rose);
  text-shadow: 0 0 12px var(--rose), 0 0 28px var(--rose), 0 0 48px var(--rose);
  animation: timer-blink 0.4s step-end infinite;
}
@keyframes timer-blink { 50% { opacity: 0.35; } }

#stage-pips {
  font-family: "Press Start 2P", monospace;
  font-size: 11px;
  letter-spacing: 0.4em;
  color: rgba(92, 240, 255, 0.4);
}
#stage-pips .pip {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid rgba(92, 240, 255, 0.25);
  margin: 0 2px;
  transition: color 0.18s, border-color 0.18s, text-shadow 0.18s;
}
#stage-pips .pip.active {
  color: var(--amber);
  border-color: var(--amber);
  text-shadow: 0 0 8px var(--amber);
}
#stage-pips .pip.done {
  color: var(--cyan);
  border-color: var(--cyan);
  opacity: 0.7;
}
#stage-pips .pip-sep {
  opacity: 0.45;
}

#score {
  font-family: "Press Start 2P", "VT323", "Courier New", monospace;
  font-size: clamp(18px, 2.6vw, 32px);
  letter-spacing: 0.10em;
  color: var(--fg);
  text-shadow:
    0 0 10px var(--cyan),
    0 0 24px var(--cyan);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1;
  margin-top: 4px;
}

/* HUD */
#hud {
  position: fixed;
  top: 18px;
  left: 18px;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-shadow: 0 0 8px var(--cyan), 0 0 16px rgba(92, 240, 255, 0.4);
  pointer-events: none;
  z-index: 10;
  user-select: none;
}
#hud .row {
  display: flex;
  gap: 14px;
  padding: 3px 0;
  font-variant-numeric: tabular-nums;
}
#hud .lbl {
  color: var(--cyan);
  opacity: 0.65;
}
#hud .bar {
  margin-top: 8px;
  width: 132px;
  height: 5px;
  border: 1px solid var(--cyan);
  box-shadow: 0 0 8px rgba(92, 240, 255, 0.5);
  padding: 1px;
}
#hud #speedbar {
  height: 100%;
  width: 0%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
  transition: width 60ms linear;
}

/* Start overlay */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at center, rgba(4, 6, 10, 0.65) 0%, rgba(4, 6, 10, 0.95) 75%);
  z-index: 20;
  text-align: center;
}
.overlay.hidden { display: none; }

.overlay .title {
  font-size: clamp(48px, 11vw, 132px);
  letter-spacing: 0.18em;
  font-weight: 700;
  line-height: 1;
}
.overlay .title .g1 {
  color: var(--fg);
  text-shadow: 0 0 12px var(--cyan), 0 0 36px var(--cyan);
}
.overlay .title .g2 {
  margin-left: 0.18em;
  color: var(--amber);
  text-shadow: 0 0 12px var(--amber), 0 0 36px var(--amber);
}

.overlay .sub {
  margin-top: 14px;
  color: var(--cyan);
  letter-spacing: 0.5em;
  opacity: 0.7;
  font-size: 12px;
}

.overlay .ctrls {
  margin: 36px 0 18px;
  font-size: 13px;
  letter-spacing: 0.2em;
}
.overlay .ctrl-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  column-gap: 22px;
  padding: 4px 0;
}
.overlay .ctrl-row .keys {
  justify-self: end;
  display: inline-flex;
  gap: 6px;
}
.overlay .ctrl-row .action {
  justify-self: start;
  color: var(--cyan);
  text-shadow: 0 0 6px rgba(92, 240, 255, 0.55);
  opacity: 0.9;
}
.overlay .ctrls-or {
  margin-top: 18px;
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--amber);
  opacity: 0.75;
  text-shadow: 0 0 8px var(--amber);
}
.overlay kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 3px 8px;
  border: 1px solid var(--cyan);
  border-radius: 2px;
  font-family: inherit;
  font-size: 12px;
  color: var(--fg);
  box-shadow: 0 0 8px rgba(92, 240, 255, 0.5);
  background: rgba(92, 240, 255, 0.05);
}

/* Shield-pickup tutorial — small spinning hex + a one-line explanation. */
.overlay .pickup-hint {
  display: flex;
  align-items: center;
  gap: 18px;
  max-width: 460px;
  margin: 6px auto 0;
  padding: 14px 18px;
  border: 1px dashed rgba(255, 92, 255, 0.35);
  border-radius: 3px;
  background: rgba(255, 92, 255, 0.05);
  text-align: left;
}
.overlay .pickup-demo {
  width: 60px;
  height: 60px;
  flex: 0 0 60px;
  overflow: visible;
  /* Whole SVG spins around its own centre — transform-origin: center on a
     DOM element is well-behaved across browsers (the inner-<g> approach
     would orbit because of `transform-box` inconsistencies). */
  transform-origin: center;
  animation: pickup-spin 5s linear infinite;
  filter:
    drop-shadow(0 0 6px #ff5cff)
    drop-shadow(0 0 14px rgba(255, 92, 255, 0.6));
}
.overlay .pickup-hex {
  fill: none;
  stroke: #ff5cff;
  stroke-width: 1.7;
  stroke-linejoin: round;
}
.overlay .pickup-vtx circle {
  fill: #ffffff;
  filter: drop-shadow(0 0 3px #ffffff);
}
.overlay .pickup-core {
  fill: #ffffff;
  /* fill-box pins the scale origin to the circle's own bbox centre, so the
     pulse stays put even though the parent SVG is rotating. */
  transform-box: fill-box;
  transform-origin: center;
  filter: drop-shadow(0 0 4px #ffffff) drop-shadow(0 0 10px #ffffff);
  animation: pickup-pulse 0.9s ease-in-out infinite;
}
@keyframes pickup-spin { to { transform: rotate(360deg); } }
@keyframes pickup-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1.10); }
}
.overlay .pickup-label {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  letter-spacing: 0.3em;
  color: #ff5cff;
  text-shadow: 0 0 8px #ff5cff;
}
.overlay .pickup-desc {
  margin-top: 8px;
  font-family: "VT323", "Courier New", monospace;
  font-size: 16px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.35;
}

.overlay .race-rules {
  margin-top: 22px;
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  letter-spacing: 0.32em;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
  opacity: 0.85;
}

.overlay .hint {
  margin-top: 18px;
  letter-spacing: 0.4em;
  font-size: 12px;
  color: var(--amber);
  text-shadow: 0 0 10px var(--amber);
  animation: blink 1.1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0.15; } }
