/* ================================================================
   KART RACING — UI/UX Design System
   ================================================================ */

:root {
  --bg: #0a0c12;
  --surface: #11141c;
  --surface2: #181c26;
  --surface3: #202430;
  --border: rgba(255,255,255,0.06);
  --border-bright: rgba(255,255,255,0.12);
  --red: #e10600;
  --gold: #ffd700;
  --blue: #00d4ff;
  --green: #00ff41;
  --accent: var(--blue);
  --text: #ffffff;
  --text2: #8a8fa0;
  --text3: #50566a;
  --font-display: 'Orbitron', monospace, sans-serif;
  --font-hud: 'Rajdhani', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 400;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ─── Screens ─── */
.screen {
  display: none;
  width: 100%; height: 100%;
  flex-direction: column;
  position: absolute;
  inset: 0;
}
.screen.active { display: flex; }

/* ─── Main Menu ─── */
#screen-menu {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #1a1a2e 0%, #0a0c12 70%);
  overflow: hidden;
}

.menu-bg {
  position: absolute;
  inset: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(225,6,0,0.08) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(0,212,255,0.06) 0%, transparent 50%);
}

.menu-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 36px;
  z-index: 2;
}

.menu-logo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.menu-logo-rings {
  position: absolute;
  width: 140px;
  height: 140px;
  top: -30px;
}

.ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}
.ring-1 {
  border-top-color: var(--red);
  border-right-color: rgba(225,6,0,0.3);
  animation: spin 4s linear infinite;
}
.ring-2 {
  inset: 10px;
  border-bottom-color: var(--blue);
  border-left-color: rgba(0,212,255,0.3);
  animation: spin 6s linear infinite reverse;
}
.ring-3 {
  inset: 20px;
  border-top-color: var(--gold);
  border-right-color: rgba(255,215,0,0.2);
  animation: spin 8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.menu-logo-icon {
  font-size: 52px;
  filter: drop-shadow(0 0 30px rgba(225,6,0,0.5));
  display: block;
  margin-bottom: 20px;
  z-index: 1;
}

.menu-title {
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 10px;
  background: linear-gradient(180deg, #fff 20%, var(--red) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.menu-sub {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 14px;
  color: var(--text3);
  margin-top: 10px;
}

.menu-actions { display: flex; flex-direction: column; gap: 14px; align-items: center; }

.menu-btn {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 16px 44px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.25s var(--ease);
  border: none;
  min-width: 240px;
  position: relative;
  overflow: hidden;
}

.btn-icon { margin-right: 8px; }

.menu-btn-primary {
  background: linear-gradient(135deg, var(--red), #c00500);
  color: #fff;
  box-shadow: 0 4px 24px rgba(225,6,0,0.35), inset 0 1px 0 rgba(255,255,255,0.15);
}
.menu-btn-primary:hover {
  background: linear-gradient(135deg, #ff1a1a, var(--red));
  box-shadow: 0 8px 40px rgba(225,6,0,0.5), inset 0 1px 0 rgba(255,255,255,0.2);
  transform: translateY(-2px);
}
.menu-btn-primary:active { transform: translateY(0); }

.menu-btn-secondary {
  background: rgba(255,255,255,0.04);
  color: var(--text2);
  border: 1px solid var(--border);
}
.menu-btn-secondary:hover { background: rgba(255,255,255,0.08); color: var(--text); border-color: var(--border-bright); }

.menu-btn-spaced { margin-top: 8px; }

.menu-footer-text {
  font-family: var(--font-hud);
  font-size: 13px;
  color: var(--text3);
  letter-spacing: 1px;
}

/* ─── Controls Overlay ─── */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
}
.overlay.active { display: flex; }

.overlay-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
.overlay-header h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 4px;
}
.overlay-close {
  background: none;
  border: none;
  color: var(--text3);
  font-size: 28px;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.2s;
}
.overlay-close:hover { color: var(--text); }

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.control-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.key-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: var(--surface3);
  border: 1px solid var(--border-bright);
  border-radius: 6px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.key-label {
  font-size: 11px;
  color: var(--text3);
}

.control-action {
  font-family: var(--font-hud);
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 1px;
}

.controls-tips {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}
.controls-tips h3 {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--text3);
  margin-bottom: 12px;
}
.controls-tips ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.controls-tips li {
  font-family: var(--font-hud);
  font-size: 14px;
  color: var(--text2);
  padding-left: 16px;
  position: relative;
}
.controls-tips li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: var(--green);
  font-weight: 700;
}

/* ─── Screen Header ─── */
.screen-header {
  display: flex;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.screen-back {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text2);
  font-family: var(--font-hud);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}
.screen-back:hover { background: rgba(255,255,255,0.08); color: var(--text); }
.screen-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 4px;
  text-align: center;
  flex: 1;
}
.screen-spacer { width: 80px; }

/* ─── Screen Footer ─── */
.screen-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

/* ─── Car Select ─── */
#screen-car-select { background: var(--bg); }

.car-select-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px;
}

.car-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

#car-preview {
  width: 420px;
  height: 310px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.car-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--text);
}

.car-desc {
  font-family: var(--font-hud);
  font-size: 14px;
  color: var(--text3);
  margin-top: -8px;
}

.car-stats {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-row span {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text3);
  width: 85px;
  flex-shrink: 0;
}
.stat-bar {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.06);
  border-radius: 5px;
  overflow: hidden;
}
.stat-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s var(--ease);
}
.stat-fill.speed  { background: linear-gradient(90deg, var(--red), #ff6b35); }
.stat-fill.accel  { background: linear-gradient(90deg, var(--gold), #ffaa00); }
.stat-fill.handling { background: linear-gradient(90deg, var(--green), #00ff88); }
.stat-fill.boost  { background: linear-gradient(90deg, var(--blue), #00aaff); }

.car-counter {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 3px;
  color: var(--text3);
}

.car-arrow {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  color: var(--text2);
  font-size: 28px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.car-arrow:hover { background: rgba(255,255,255,0.1); color: var(--text); border-color: var(--border-bright); }
.car-arrow:active { transform: scale(0.95); }

/* ─── Track Select ─── */
#screen-track-select { background: var(--bg); }

.track-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 18px;
  padding: 24px;
  overflow-y: auto;
  align-content: start;
}

.track-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.25s var(--ease);
}
.track-card:hover { border-color: var(--border-bright); transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.track-card.selected { border-color: var(--blue); box-shadow: 0 0 24px rgba(0,212,255,0.2); }

.track-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.track-thumb canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.track-card-name {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 12px 14px 4px;
  color: var(--text);
}

.track-card-desc {
  font-size: 12px;
  color: var(--text3);
  padding: 0 14px 14px;
  line-height: 1.4;
  font-family: var(--font-hud);
}

/* ─── Race Screen ─── */
#screen-race { background: #000; }

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

/* HUD */
.race-hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: 16px 20px;
}

.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
}

.hud-left { display: flex; flex-direction: column; }

.hud-position {
  font-family: var(--font-display);
  font-size: 40px;
  font-weight: 900;
  color: var(--text);
  text-shadow: 0 2px 16px rgba(0,0,0,0.6);
  line-height: 1;
}

.hud-lap {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  margin-top: 4px;
}

.hud-center-top { text-align: center; }

.hud-time {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 2px 12px rgba(0,0,0,0.6);
  font-variant-numeric: tabular-nums;
}

.hud-right { display: flex; align-items: center; }

.hud-pause-btn {
  pointer-events: auto;
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  font-size: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  backdrop-filter: blur(4px);
}
.hud-pause-btn:hover { background: rgba(255,255,255,0.1); }

.hud-bottom {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
}

.hud-speed {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(6px);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.08);
}

.speed-val {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 900;
  color: var(--text);
  text-shadow: 0 0 20px rgba(0,212,255,0.3);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.speed-unit {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 2px;
  color: var(--text3);
}

/* Minimap */
.hud-minimap {
  position: absolute;
  bottom: 80px;
  right: 16px;
  z-index: 10;
  pointer-events: none;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
#minimap-canvas { display: block; }

/* Race Overlays */
.race-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
}
.race-overlay.active { display: flex; }

.countdown-num {
  font-family: var(--font-display);
  font-size: 140px;
  font-weight: 900;
  color: var(--text);
  text-shadow: 0 0 80px rgba(225,6,0,0.5), 0 0 160px rgba(225,6,0,0.2);
  animation: countPop 0.8s var(--ease) forwards;
}
.countdown-num.go {
  font-size: 90px;
  color: var(--green);
  text-shadow: 0 0 80px rgba(0,255,65,0.5);
  letter-spacing: 20px;
}

@keyframes countPop {
  0% { transform: scale(2.5); opacity: 0; }
  20% { transform: scale(0.85); opacity: 1; }
  100% { transform: scale(1); opacity: 0; }
}

.finish-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(12px);
  padding: 40px 56px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.1);
}

.finish-icon { font-size: 56px; filter: drop-shadow(0 0 24px rgba(255,215,0,0.4)); }
.finish-title { font-family: var(--font-display); font-size: 32px; font-weight: 900; letter-spacing: 6px; color: var(--gold); }
.finish-pos { font-family: var(--font-display); font-size: 42px; font-weight: 900; color: var(--text); }
.finish-time { font-family: var(--font-display); font-size: 18px; font-weight: 600; color: var(--text2); font-variant-numeric: tabular-nums; }

/* Pause overlay */
.pause-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(12px);
  padding: 40px 56px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.1);
  pointer-events: auto;
}
.pause-title {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--text);
  margin-bottom: 8px;
}

/* ─── Results Screen ─── */
#screen-results { background: var(--bg); }

.results-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
  overflow-y: auto;
}

.results-podium {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  padding: 24px 0;
}

.podium-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.podium-place {
  font-family: var(--font-display);
  font-weight: 900;
}
.podium-place.p1 { font-size: 32px; color: var(--gold); }
.podium-place.p2 { font-size: 24px; color: #c0c0c0; }
.podium-place.p3 { font-size: 20px; color: #cd7f32; }
.podium-place.p4 { font-size: 16px; color: var(--text3); }

.podium-name {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text);
  text-align: center;
  max-width: 80px;
}

.podium-time {
  font-family: var(--font-display);
  font-size: 10px;
  color: var(--text3);
  font-variant-numeric: tabular-nums;
}

.podium-bar {
  width: 64px;
  border-radius: 6px 6px 0 0;
}
.podium-bar.p1 { height: 90px; background: linear-gradient(180deg, var(--gold), #b8960f); }
.podium-bar.p2 { height: 65px; background: linear-gradient(180deg, #c0c0c0, #888); }
.podium-bar.p3 { height: 45px; background: linear-gradient(180deg, #cd7f32, #8a5720); }
.podium-bar.p4 { height: 25px; background: var(--surface3); }

.results-table {
  width: 100%;
  max-width: 520px;
  border-collapse: collapse;
}

.results-table th {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text3);
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.results-table td {
  font-family: var(--font-hud);
  font-size: 16px;
  font-weight: 500;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.results-table .player-row td { color: var(--blue); font-weight: 600; }

/* ─── Responsive ─── */
@media (max-width: 700px) {
  .menu-title { font-size: 36px; letter-spacing: 4px; }
  .menu-logo-rings { width: 100px; height: 100px; top: -20px; }
  .menu-logo-icon { font-size: 36px; }
  .car-select-body { flex-direction: column; gap: 12px; }
  #car-preview { width: 300px; height: 220px; }
  .car-arrow { width: 40px; height: 40px; font-size: 20px; }
  .car-stats { width: 280px; }
  .track-grid { grid-template-columns: repeat(2, 1fr); padding: 12px; }
  .hud-position { font-size: 28px; }
  .speed-val { font-size: 28px; }
  .hud-time { font-size: 16px; }
  .countdown-num { font-size: 90px; }
  .podium-bar { width: 44px; }
  .podium-bar.p1 { height: 65px; }
  .podium-bar.p2 { height: 48px; }
  .podium-bar.p3 { height: 32px; }

  .race-hud { padding: 10px 14px; }
  .hud-top { padding: 10px 14px; }
  .hud-position { font-size: 24px; }
  .hud-lap { font-size: 10px; }
  .speed-val { font-size: 24px; }
  .hud-time { font-size: 14px; }
  .hud-minimap { display: none; }
  .hud-speed { padding: 8px 16px; }

  .controls-grid { grid-template-columns: 1fr; }
}

@media (max-width: 500px) {
  .screen-title { font-size: 13px; letter-spacing: 2px; }
  .track-grid { grid-template-columns: 1fr; }
  #car-preview { width: 240px; height: 180px; }
  .car-name { font-size: 18px; }
  .menu-title { font-size: 28px; }
  .menu-btn { min-width: 200px; padding: 14px 32px; font-size: 10px; }
}

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