:root {
  --neon-orange: #ff9500;
  --neon-orange-bright: #ffb347;
  --neon-cyan: #23e6ff;
  --neon-magenta: #ff2fd0;
  --bg-dark: #05060a;
  --panel-bg: rgba(10, 12, 20, 0.88);
  --font-display: 'Orbitron', 'Segoe UI', sans-serif;
  --font-body: 'Rajdhani', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --bracket: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-dark);
  overflow: hidden;
  font-family: var(--font-body);
  color: #eaf6ff;
  user-select: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.hidden { display: none !important; }

/* ---------- CRT scanline / vignette overlay ---------- */
#scanlines {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.04) 0px,
    rgba(255, 255, 255, 0.04) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}
#scanlines::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.6) 100%);
}

/* ---------- Shared corner-bracket frame (menu/finish panels + HUD boxes) ----------
   Drawn as background gradients on ::before rather than a clip-path border, so it
   layers on top of the panel without clipping away the outer glow box-shadow. */
.panel, #hud-lap, #hud-time, .boot-frame {
  position: relative;
}
#hud-lap, #hud-time { --bracket: 10px; }
.panel::before,
#hud-lap::before,
#hud-time::before,
.boot-frame::before {
  content: '';
  position: absolute;
  inset: -1px;
  pointer-events: none;
  background:
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) top    left  / var(--bracket) 2px no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) top    left  / 2px var(--bracket) no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) top    right / var(--bracket) 2px no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) top    right / 2px var(--bracket) no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) bottom left  / var(--bracket) 2px no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) bottom left  / 2px var(--bracket) no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) bottom right / var(--bracket) 2px no-repeat,
    linear-gradient(var(--neon-cyan), var(--neon-cyan)) bottom right / 2px var(--bracket) no-repeat;
  filter: drop-shadow(0 0 4px var(--neon-cyan));
  opacity: 0.85;
}

/* Orbitron has no tabular figures, so digits keep their natural (unequal)
   advance widths and any live-updating number visibly jitters. Swapping in
   a monospace font "fixed" that but lost Orbitron's look entirely. Instead,
   game.js wraps each digit of a live readout in one of these spans and
   sizes it (per element, via JS) to the widest digit in that same font -
   forcing every digit into an equal-width slot while keeping the real
   Orbitron glyphs untouched. */
.tnum-digit { display: inline-block; text-align: center; }

/* ---------- Boot screen ---------- */
#boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #101425 0%, #05060a 75%);
}

.boot-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 44px 64px;
  background: rgba(10, 12, 20, 0.5);
}

#boot-logo {
  font-family: var(--font-display);
  font-size: 3.2rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--neon-orange);
  text-shadow: 0 0 12px var(--neon-orange), 0 0 40px rgba(255, 149, 0, 0.6);
}
#boot-logo span { color: #fff; text-shadow: 0 0 12px #fff, 0 0 30px var(--neon-orange); }
#boot-sub {
  font-family: var(--font-display);
  letter-spacing: 0.6em;
  color: var(--neon-cyan);
  margin-top: 4px;
  font-size: 0.9rem;
  text-shadow: 0 0 10px var(--neon-cyan);
}
#boot-bar {
  width: 280px;
  height: 6px;
  margin-top: 34px;
  background:
    repeating-linear-gradient(to right, rgba(0, 0, 0, 0.45) 0 2px, transparent 2px 22px),
    rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 149, 0, 0.4);
  border-radius: 3px;
  overflow: hidden;
}
#boot-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--neon-orange), var(--neon-orange-bright));
  box-shadow: 0 0 10px var(--neon-orange);
  transition: width 0.2s ease-out;
}
#boot-pct {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  color: var(--neon-orange-bright);
}
#boot-tip {
  margin-top: 10px;
  font-size: 0.8rem;
  color: #8aa;
}

/* ---------- Menu / Finish overlays ---------- */
#menu, #finish {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 3, 6, 0.55);
  backdrop-filter: blur(2px);
}

.panel {
  background: var(--panel-bg);
  border: 1px solid rgba(255, 149, 0, 0.35);
  box-shadow: 0 0 40px rgba(255, 149, 0, 0.15), inset 0 0 60px rgba(35, 230, 255, 0.03);
  border-radius: 4px;
  padding: 34px 44px;
  min-width: 340px;
  max-width: 92vw;
  text-align: center;
  overflow: hidden;
}

/* thin light sweeping across the top edge - "system online" flavor */
.panel::after {
  content: '';
  position: absolute;
  top: 0;
  left: -30%;
  width: 30%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--neon-cyan), transparent);
  filter: drop-shadow(0 0 6px var(--neon-cyan));
  animation: panel-scan 3.2s linear infinite;
}
@keyframes panel-scan {
  from { left: -30%; }
  to   { left: 130%; }
}

/* Finish screen reads as a "confirmed" state: cyan-dominant chrome instead of orange */
#finish .panel {
  border-color: rgba(35, 230, 255, 0.4);
  box-shadow: 0 0 40px rgba(35, 230, 255, 0.18), inset 0 0 60px rgba(35, 230, 255, 0.05);
}
#finish .panel::after { background: linear-gradient(90deg, transparent, var(--neon-orange-bright), transparent); }

.panel h1 {
  font-family: var(--font-display);
  margin: 0 0 4px;
  font-size: 2rem;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 0 0 10px var(--neon-orange);
}
.panel h1 span { color: var(--neon-orange); }
.tagline { margin: 0 0 22px; color: var(--neon-cyan); font-size: 0.85rem; letter-spacing: 0.15em; }

/* ---------- Car selection (menu) ---------- */
.car-select {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 20px;
}
.car-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
#car-preview {
  width: 220px;
  height: 140px;
  display: block;
  background: radial-gradient(ellipse at center, rgba(35, 230, 255, 0.1), transparent 70%);
  border: 1px solid rgba(35, 230, 255, 0.25);
  border-radius: 4px;
}
#car-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  color: #fff;
  text-shadow: 0 0 8px var(--neon-cyan);
}
.car-arrow {
  padding: 10px 15px;
  margin: 0;
  font-size: 1.1rem;
  line-height: 1;
  border-color: var(--neon-cyan);
  background: linear-gradient(180deg, rgba(35, 230, 255, 0.2), rgba(35, 230, 255, 0.05));
  box-shadow: 0 0 12px rgba(35, 230, 255, 0.3);
}
.car-arrow:hover { box-shadow: 0 0 20px rgba(35, 230, 255, 0.6); }
.car-dots { display: flex; gap: 6px; justify-content: center; }
.car-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.car-dots span.active { background: var(--neon-orange-bright); box-shadow: 0 0 6px var(--neon-orange-bright); }

button {
  position: relative;
  overflow: hidden;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  padding: 13px 30px;
  margin: 6px 6px;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  border-radius: 0;
  border: 1px solid var(--neon-orange);
  background: linear-gradient(180deg, rgba(255, 149, 0, 0.25), rgba(255, 149, 0, 0.08));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(255, 149, 0, 0.35);
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}
button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: skewX(-20deg);
  transition: left 0.5s ease;
}
button:hover { box-shadow: 0 0 24px rgba(255, 149, 0, 0.7); transform: translateY(-1px); }
button:hover::before { left: 120%; }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: default; box-shadow: none; }
button:disabled::before { display: none; }

.controls-help {
  margin: 18px 0 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #bcd;
  text-align: left;
}
.controls-help b { font-family: var(--font-display); color: var(--neon-cyan); }

.board { margin-top: 18px; border-top: 1px solid rgba(255, 255, 255, 0.1); padding-top: 14px; }
.board h2 {
  font-family: var(--font-display);
  margin: 0 0 8px;
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  color: var(--neon-cyan);
}
#highscore-list { list-style: none; margin: 0; padding: 0; font-size: 0.85rem; }
#highscore-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.08);
}
#highscore-list li.empty { justify-content: center; color: #667; }
#highscore-list li span.rank {
  font-family: var(--font-display);
  font-weight: 900;
  width: 1.4em;
  color: #789;
}
#highscore-list li span.name { flex: 1; text-align: left; color: #fff; font-weight: 600; }
#highscore-list li span.time {
  font-family: var(--font-display);
  color: var(--neon-orange-bright);
  font-weight: 700;
}
#highscore-list li.top1 span.rank { color: #ffd54a; text-shadow: 0 0 8px #ffd54a; }
#highscore-list li.top2 span.rank { color: #d7e2ee; text-shadow: 0 0 6px #d7e2ee; }
#highscore-list li.top3 span.rank { color: #e0995c; text-shadow: 0 0 6px #e0995c; }

#finish-name {
  display: block;
  margin: 14px auto;
  width: 80%;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  border-radius: 4px;
  border: 1px solid var(--neon-cyan);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  text-align: center;
}
#finish-time { font-family: var(--font-display); font-size: 1.2rem; color: var(--neon-orange-bright); margin: 4px 0 8px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

#hud-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
#hud-lap {
  font-family: var(--font-display);
  background: rgba(5, 6, 10, 0.6);
  border: 1px solid rgba(255, 149, 0, 0.4);
  padding: 8px 18px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 8px var(--neon-orange);
}
#hud-time {
  font-family: var(--font-display);
  background: rgba(5, 6, 10, 0.6);
  border: 1px solid rgba(35, 230, 255, 0.35);
  padding: 8px 18px;
  text-align: right;
  font-size: 0.95rem;
  color: var(--neon-cyan);
}
#hud-time .best { font-size: 0.75rem; color: #7cc; margin-top: 2px; }

#hud-speed {
  position: absolute;
  bottom: 26px;
  right: 30px;
  width: 132px;
  height: 132px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.speed-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.speed-ring .ring-bg {
  fill: none;
  stroke: rgba(255, 149, 0, 0.15);
  stroke-width: 6;
}
.speed-ring .ring-fg {
  fill: none;
  stroke: var(--neon-orange-bright);
  stroke-width: 6;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px var(--neon-orange));
  transition: stroke-dashoffset 0.12s linear, stroke 0.2s ease;
}
#hud-speed.redline .ring-fg { stroke: var(--neon-magenta); filter: drop-shadow(0 0 10px var(--neon-magenta)); }
#hud-speed.redline #speed-value { color: var(--neon-magenta); text-shadow: 0 0 16px var(--neon-magenta); }

.speed-readout {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}
#speed-value {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--neon-orange-bright);
  text-shadow: 0 0 16px var(--neon-orange);
  transition: color 0.2s ease, text-shadow 0.2s ease;
}
.speed-readout .unit { font-size: 0.7rem; letter-spacing: 0.1em; margin-top: 2px; color: #ffd9a8; }

#hud-msg {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px var(--neon-orange), 0 0 50px var(--neon-orange);
  letter-spacing: 0.1em;
  opacity: 0;
}
#hud-msg.show { animation: hud-msg-in 1.2s ease forwards; }
@keyframes hud-msg-in {
  0%   { opacity: 0; letter-spacing: 0.6em; }
  15%  { opacity: 1; letter-spacing: 0.1em; }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}
