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

:root {
  --bg-deep: #0f172a;
  --card-bg: rgba(17, 24, 39, 0.92);
  --accent-gold: #facc15;
  --accent-orange: #f97316;
  --accent-blue: #38bdf8;
  --accent-red: #ef4444;
  --text-light: #f8fafc;
  --text-muted: #94a3b8;
}

body {
  background: radial-gradient(circle at top, #1e293b 0%, #090d16 100%);
  color: var(--text-light);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-shell {
  position: relative;
  width: min(96vw, 1200px);
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7), 0 0 0 3px rgba(255, 255, 255, 0.14);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;
}

.hidden {
  display: none !important;
}

/* --- HUD --- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hud-panel {
  position: absolute;
  inset: 0;
}

#game-shell.split-screen #hud-p1 {
  bottom: 50%;
}

#game-shell.split-screen #hud-p2 {
  top: 50%;
}

.hud-top-left {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.pos-badge {
  background: linear-gradient(180deg, #fde047 0%, #f59e0b 100%);
  color: #1e1b4b;
  font-weight: 900;
  font-size: 28px;
  line-height: 1;
  padding: 8px 14px;
  border-radius: 12px;
  border: 3px solid #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.pos-badge.second {
  background: linear-gradient(180deg, #cbd5e1 0%, #64748b 100%);
  color: #0f172a;
}

.lap-badge {
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.35);
  padding: 7px 14px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.hud-top-center {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
}

.item-box {
  width: 72px;
  height: 72px;
  border-radius: 14px;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.95));
  border: 3px solid #38bdf8;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5), inset 0 0 14px rgba(56, 189, 248, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.item-box.active {
  border-color: #facc15;
  box-shadow: 0 0 18px rgba(250, 204, 21, 0.55);
}

.item-label {
  position: absolute;
  bottom: -18px;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #fef08a;
  text-shadow: 0 2px 4px #000;
}

.hud-bottom-left {
  position: absolute;
  bottom: 14px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer-pill,
.speed-pill {
  background: rgba(15, 23, 42, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.25);
  padding: 6px 12px;
  border-radius: 10px;
  font-weight: 800;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.speed-pill {
  color: #38bdf8;
}

.drift-meter {
  width: 96px;
  height: 14px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.45);
  overflow: hidden;
}

.drift-fill {
  height: 100%;
  width: 0%;
  background: #38bdf8;
  transition: width 0.05s linear;
}

.drift-fill.super {
  background: linear-gradient(90deg, #f97316, #facc15);
}

#minimap-wrap {
  position: absolute;
  bottom: 14px;
  right: 16px;
  background: rgba(15, 23, 42, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

.track-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.9px;
  color: #cbd5e1;
}

#hud-controls {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
}

.icon-btn:hover {
  transform: scale(1.07);
  background: rgba(30, 41, 59, 0.95);
}

#center-banner {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(42px, 6vw, 76px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 2px;
  color: #fde047;
  -webkit-text-stroke: 3px #1e1b4b;
  text-shadow: 0 8px 20px rgba(0, 0, 0, 0.7);
  text-align: center;
  animation: popIn 0.25s ease-out;
}

.wrong-way {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 38, 38, 0.92);
  border: 3px solid #fff;
  border-radius: 12px;
  padding: 6px 18px;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
  animation: pulseWarn 0.55s infinite alternate;
}

#game-shell.split-screen #wrong-way-p1 {
  top: 20%;
}

#game-shell.split-screen #wrong-way-p2 {
  top: 70%;
}

@keyframes popIn {
  from { transform: translate(-50%, -50%) scale(1.45); opacity: 0.2; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes pulseWarn {
  from { transform: translateX(-50%) scale(1); }
  to { transform: translateX(-50%) scale(1.08); }
}

/* --- Overlays & Menu --- */
.overlay-screen {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.78), rgba(2, 6, 23, 0.92));
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 20;
}

.menu-card {
  width: min(94%, 860px);
  background: var(--card-bg);
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-radius: 22px;
  padding: 18px 24px;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.title-banner {
  text-align: center;
}

.badge-pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.4px;
  color: #1e1b4b;
  background: linear-gradient(90deg, #fde047, #fb923c);
  padding: 3px 12px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.title-banner h1 {
  font-size: clamp(32px, 4.5vw, 48px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 2px;
  background: linear-gradient(180deg, #ffffff 10%, #fde047 65%, #f97316 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgba(15, 23, 42, 0.9));
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.mode-toggle {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.mode-btn {
  padding: 7px 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(30, 41, 59, 0.8);
  color: #cbd5e1;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn.active {
  background: #38bdf8;
  border-color: #fff;
  color: #0f172a;
}

.char-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.char-card {
  position: relative;
  background: linear-gradient(160deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  border: 3px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  padding: 12px 16px;
  color: var(--text-light);
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.char-card:hover {
  transform: translateY(-2px);
  border-color: rgba(250, 204, 21, 0.65);
}

.char-card.selected {
  border-color: #facc15;
  box-shadow: 0 0 24px rgba(250, 204, 21, 0.3), inset 0 0 20px rgba(250, 204, 21, 0.1);
}

.char-tag {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 12px;
  font-weight: 900;
  padding: 3px 10px;
  border-radius: 8px;
}

.p1-tag {
  background: #facc15;
  color: #0f172a;
}

.p2-tag {
  background: #38bdf8;
  color: #0f172a;
}

.cpu-tag {
  background: #475569;
  color: #f8fafc;
}

.char-card h2 {
  font-size: 22px;
  font-weight: 900;
}

.breed {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #38bdf8;
  margin-bottom: 4px;
}

.stats {
  width: 100%;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 4px 0;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #cbd5e1;
}

.stat-row span {
  width: 44px;
  text-align: left;
}

.bar {
  flex: 1;
  height: 7px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #facc15);
  border-radius: 999px;
}

.blurb {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

.track-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(15, 23, 42, 0.72);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 8px 14px;
}

.track-thumb-wrap {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  background: #14532d;
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#track-preview-canvas {
  width: 64px;
  height: 64px;
}

.track-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.track-info strong {
  font-size: 15px;
  color: #fde047;
}

.track-info span {
  font-size: 12px;
  color: var(--text-muted);
}

.start-btn {
  background: linear-gradient(180deg, #fde047 0%, #f97316 100%);
  color: #1e1b4b;
  border: 3px solid #fff;
  border-radius: 12px;
  padding: 11px 24px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.8px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(249, 115, 22, 0.45);
  transition: transform 0.12s, filter 0.12s;
}

.start-btn:hover {
  transform: scale(1.04);
  filter: brightness(1.06);
}

.secondary-btn {
  background: rgba(30, 41, 59, 0.95);
  color: #f8fafc;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.12s;
}

.secondary-btn:hover {
  background: rgba(51, 65, 85, 0.95);
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  font-size: 12px;
  color: #cbd5e1;
}

.controls-hint b {
  color: #fde047;
}

/* --- Modal (Pause / Finish) --- */
.modal-box {
  background: var(--card-bg);
  border: 3px solid rgba(255, 255, 255, 0.22);
  border-radius: 20px;
  padding: 28px 34px;
  text-align: center;
  min-width: 340px;
  max-width: 480px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
}

.modal-box h2 {
  font-size: 32px;
  font-weight: 900;
  color: #fde047;
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 18px;
}

.trophy-icon {
  font-size: 52px;
  margin-bottom: 4px;
}

#finish-subline {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 14px;
}

.results-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(30, 41, 59, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 800;
}

.result-row.winner {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.14);
}
