:root {
  --bg-dark: rgba(11, 15, 23, 0.84);
  --bg-card: rgba(14, 19, 30, 0.92);
  --border-subtle: rgba(255, 255, 255, 0.12);
  --accent: #ef233c;
  --accent-hover: #ff3850;
  --gold: #f5b700;
  --cyan: #38bdf8;
  --green: #22c55e;
  --purple: #c084fc;
  --purple-strong: #a855f7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-main: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0f17;
  color: var(--text-main);
  font-family: var(--font-main);
}

#canvas-container {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* Overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(10, 14, 24, 0.55) 0%, rgba(7, 10, 18, 0.86) 100%);
  backdrop-filter: blur(6px);
  padding: 20px;
}

.menu-card, .modal-card, .finish-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  padding: 28px 32px;
  width: 100%;
}

.menu-card {
  max-width: 680px;
  max-height: 94vh;
  overflow-y: auto;
}

.menu-row-2 {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 14px;
}

.text-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 10px 12px;
  color: #fff;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 700;
  outline: none;
  user-select: text;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.text-input:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.1);
}

.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.diff-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.diff-btn.selected {
  background: rgba(239, 35, 60, 0.18);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(239, 35, 60, 0.35);
}

.modal-card {
  max-width: 380px;
  text-align: center;
}

.finish-card {
  max-width: 720px;
}

.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(239, 35, 60, 0.18);
  color: #ff5c72;
  border: 1px solid rgba(239, 35, 60, 0.45);
  margin-bottom: 10px;
}

h1 {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 1px;
  line-height: 1.1;
}

h2 {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 6px;
}

.accent {
  color: var(--accent);
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 6px;
  margin-bottom: 22px;
}

.form-group {
  margin-bottom: 20px;
}

.section-label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 10px;
}

/* Track cards */
.track-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.track-option {
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.18s ease;
  text-align: left;
}

.track-option:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.25);
}

.track-option.selected {
  background: rgba(239, 35, 60, 0.14);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(239, 35, 60, 0.35), 0 8px 24px rgba(239, 35, 60, 0.18);
}

.track-option-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.track-option-title {
  font-size: 15px;
  font-weight: 800;
  color: #fff;
}

.track-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--cyan);
}

.track-option-meta {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Slider */
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.slider-header .section-label {
  margin-bottom: 0;
}

.count-pill {
  font-size: 13px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.09);
  padding: 3px 10px;
  border-radius: 8px;
  color: #fff;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 6px;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 2px;
}

.start-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--gold);
  font-weight: 600;
}

.start-hint.muted-hint {
  color: var(--cyan);
}

/* Controls hint */
.controls-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: 22px;
  font-size: 12px;
  color: var(--text-muted);
}

.ctrl-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  border-radius: 5px;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 2px;
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-ghost {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.btn-primary {
  background: linear-gradient(135deg, #ef233c, #d90429);
  color: #fff;
  box-shadow: 0 10px 24px rgba(239, 35, 60, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #ff3850, #ef233c);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.16);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-ghost:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.28);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions.horizontal {
  flex-direction: row;
}

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

.hud-panel {
  background: var(--bg-dark);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

/* Leaderboard (Top-left) */
#leaderboard-panel {
  position: fixed;
  top: 16px;
  left: 16px;
  width: 245px;
  padding: 10px 12px;
}

.hud-panel-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 6px;
}

#leaderboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lb-row {
  display: grid;
  grid-template-columns: 24px 10px 1fr auto;
  align-items: center;
  gap: 7px;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.03);
}

.lb-row.is-player {
  background: linear-gradient(90deg, rgba(239, 35, 60, 0.38), rgba(239, 35, 60, 0.14));
  border: 1px solid rgba(239, 35, 60, 0.75);
  color: #fff;
  font-weight: 800;
}

.lb-pos {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--text-muted);
}

.lb-row.is-player .lb-pos {
  color: #ffd166;
}

.lb-swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.lb-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-name-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.fl-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 4px;
  background: linear-gradient(135deg, #a855f7, #7e22ce);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.78);
  border: 1px solid rgba(233, 213, 255, 0.7);
}

.fl-badge svg {
  width: 12px;
  height: 12px;
  display: block;
}

.lb-lap {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.lb-row.is-player .lb-lap {
  color: #fff;
}

/* Timer (Top-center) */
#timer-panel {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 22px;
}

.timer-block {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.timer-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.3px;
  color: var(--text-muted);
}

.timer-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fff;
  margin-top: 2px;
}

.timer-value.secondary {
  color: var(--cyan);
  font-size: 19px;
}

.timer-label.fastest-label {
  color: var(--purple);
}

.timer-value.fastest {
  color: var(--purple);
  font-size: 18px;
  text-shadow: 0 0 12px rgba(168, 85, 247, 0.45);
}

.timer-divider {
  width: 1px;
  height: 32px;
  background: rgba(255, 255, 255, 0.14);
}

/* Lap Counter (Top-right) */
#lap-panel {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 10px 18px;
  text-align: right;
  min-width: 175px;
}

.lap-counter-text {
  font-size: 22px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 0.5px;
}

.track-name-sub {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}

/* Status Banner */
#status-banner {
  position: fixed;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 18px;
  border-radius: 999px;
  background: rgba(239, 35, 60, 0.9);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  box-shadow: 0 8px 24px rgba(239, 35, 60, 0.4);
}

/* Countdown */
#countdown-overlay {
  position: fixed;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.lights-bar {
  display: flex;
  gap: 16px;
  padding: 12px 22px;
  border-radius: 14px;
  background: rgba(10, 14, 22, 0.88);
  border: 2px solid rgba(255, 255, 255, 0.16);
}

.start-light {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #27272a;
  border: 2px solid #3f3f46;
  transition: all 0.12s ease;
}

.start-light.red {
  background: #ef233c;
  border-color: #ff758f;
  box-shadow: 0 0 22px #ef233c;
}

.start-light.green {
  background: #22c55e;
  border-color: #86efac;
  box-shadow: 0 0 24px #22c55e;
}

#countdown-text {
  font-size: 72px;
  font-weight: 900;
  letter-spacing: 4px;
  color: #fff;
  text-shadow: 0 6px 32px rgba(0, 0, 0, 0.85), 0 0 20px rgba(239, 35, 60, 0.55);
}

#countdown-text.go {
  color: #4ade80;
  text-shadow: 0 6px 32px rgba(0, 0, 0, 0.85), 0 0 26px rgba(34, 197, 94, 0.7);
}

/* Minimap (Bottom-left) */
#minimap-panel {
  position: fixed;
  left: 16px;
  bottom: 18px;
  width: 230px;
  padding: 10px 10px 8px 10px;
}

.minimap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.minimap-title {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.sound-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.4);
}

.sound-badge.muted {
  background: rgba(148, 163, 184, 0.16);
  color: #94a3b8;
  border-color: rgba(148, 163, 184, 0.32);
}

#minimap-canvas {
  display: block;
  width: 210px;
  height: 210px;
  border-radius: 8px;
  background: rgba(7, 11, 18, 0.72);
}

/* Speedometer (Bottom-right) */
#speedometer-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 255px;
  padding: 14px 16px;
}

.speed-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 10px;
}

.gear-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 5px 11px;
  min-width: 56px;
}

.gear-label {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 0.8px;
}

#gear-value {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 900;
  color: var(--gold);
  line-height: 1.05;
}

.speed-readout {
  text-align: right;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

#speed-value {
  font-family: var(--font-mono);
  font-size: 46px;
  font-weight: 900;
  line-height: 0.95;
  color: #fff;
}

.speed-unit {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
}

.rpm-bar-track {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin-bottom: 10px;
}

#rpm-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #22c55e 0%, #eab308 72%, #ef233c 100%);
  transition: width 0.05s linear;
}

.pedals-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pedal-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.pedal-bg {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.pedal-fill {
  height: 100%;
  width: 0%;
  transition: width 0.05s linear;
}

.pedal-fill.throttle {
  background: #22c55e;
}

.pedal-fill.brake {
  background: #ef233c;
}

/* Results table */
.results-table-wrap {
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  margin-bottom: 18px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.results-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.results-table td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.results-table tr.is-player {
  background: rgba(239, 35, 60, 0.22);
  font-weight: 800;
}

.pilot-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fastest-cell {
  color: var(--purple);
  font-weight: 800;
}

.mono {
  font-family: var(--font-mono);
}

@media (max-width: 720px) {
  .track-grid,
  .menu-row-2 {
    grid-template-columns: 1fr;
  }
  #minimap-panel {
    width: 175px;
  }
  #minimap-canvas {
    width: 155px;
    height: 155px;
  }
  #leaderboard-panel {
    width: 195px;
  }
  #timer-panel {
    padding: 8px 14px;
    gap: 10px;
  }
  .timer-value {
    font-size: 17px;
  }
  .timer-value.secondary,
  .timer-value.fastest {
    font-size: 15px;
  }
  .records-box {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 8px 12px;
  max-height: 150px;
  overflow-y: auto;
  font-size: 13px;
}
.records-empty {
  color: #94a3b8;
  text-align: center;
  padding: 8px 0;
}
.record-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}
.record-row:last-child {
  border-bottom: none;
}
.record-pos {
  color: #facc15;
  font-weight: 700;
  width: 28px;
}
.record-name {
  flex: 1;
  color: #f8fafc;
}
.record-time {
  font-family: monospace;
  color: #38bdf8;
  font-weight: 600;
}
}
