/* ========================================
   DRIFT PURSUIT - Optimized Stylesheet
   2D Endless Car Escape Game
   ======================================== */

/* CSS Custom Properties - Unified Theme System */
:root {
  /* Color Palette */
  --primary-blue: #1e3a8a;
  --royal-blue: #3730a3;
  --electric-blue: #2563eb;
  --accent-blue: #60a5fa;
  --light-blue: #93c5fd;
  
  --dark-bg: #0a0a0f;
  --darker-bg: #050507;
  --card-bg: rgba(255, 255, 255, 0.95);
  --card-border: rgba(59, 130, 246, 0.2);
  --glass-bg: rgba(255, 255, 255, 0.06);
  --border-color: rgba(255, 255, 255, 0.08);
  
  --text-primary: #ffffff;
  --text-secondary: #e2e8f0;
  --text-muted: #94a3b8;
  
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  
  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #1e3a8a 0%, #3730a3 50%, #2563eb 100%);
  --gradient-glass: linear-gradient(135deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.02) 100%);
  --gradient-overlay: linear-gradient(135deg, rgba(10, 10, 15, 0.95) 0%, rgba(30, 58, 138, 0.75) 100%);
  --gradient-button: linear-gradient(135deg, #2563eb 0%, #3730a3 50%, #1e3a8a 100%);
  --gradient-accent: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
  --gradient-card: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(37, 99, 235, 0.1) 100%);
  
  /* Shadows */
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.12);
  --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-medium: 0 8px 25px rgba(0, 0, 0, 0.15);
  --shadow-strong: 0 20px 40px rgba(30, 58, 138, 0.2);
  --shadow-glow: 0 0 30px rgba(37, 99, 235, 0.3);
  --shadow-elevated: 0 12px 40px rgba(59, 130, 246, 0.3);
  
  /* Day Theme */
  --theme-bg: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  --theme-canvas-bg: #ffffff;
  --theme-grid: #e2e8f0;
  --theme-text: #1e293b;
  --theme-border: #cbd5e1;
  --theme-shadow: rgba(0, 0, 0, 0.1);
  --theme-card-bg: rgba(255, 255, 255, 0.98);
  --theme-card-border: rgba(59, 130, 246, 0.4);
  
  /* Grid Colors */
  --day-grid: #e2e8f0;
  --day-canvas-bg: #ffffff;
  
  /* Arrow Direction Indicator Colors */
  --day-arrow-fuel-color: #ef4444;
  --day-arrow-repair-color: #10b981;
  
  /* Item Pickup Colors */
  --day-item-pickup-particle: #3b82f6;
  --day-dollar-color: #fbbf24;
  --day-dollar-bg-color: rgba(251, 191, 36, 0.2);
  
  /* Gaming Colors */
  --neon-glow: #60a5fa;
  --neon-green: #10b981;
  --neon-blue: #3b82f6;
  --neon-cyan: #06b6d4;
  --neon-purple: #a78bfa;
  --accent-glow: #3b82f6;
}

/* Night Mode Theme Variables */
body.night-mode {
  --theme-bg: linear-gradient(135deg, #000000 0%, #0a0a0f 50%, #000000 100%);
  --theme-canvas-bg: #000000;
  --theme-grid: #1a1a1a;
  --theme-text: var(--text-primary);
  --theme-border: rgba(255, 255, 255, 0.15);
  --theme-shadow: rgba(0, 0, 0, 0.5);
  --theme-card-bg: rgba(0, 0, 0, 0.85);
  --theme-card-border: rgba(96, 165, 250, 0.4);
  
  /* Grid Colors - Visible gray for night mode */
  --night-grid: #4a4a4a;
  --night-canvas-bg: #000000;
  
  /* Arrow Direction Indicator Colors - Night Mode */
  --night-arrow-fuel-color: #ff0055;
  --night-arrow-repair-color: #00ff88;
  
  /* Item Pickup Colors - Night Mode */
  --night-item-pickup-particle: #60a5fa;
  --night-dollar-color: #fde047;
  --night-dollar-bg-color: rgba(253, 224, 71, 0.2);
}

/* ========================================
   BASE STYLES
   ======================================== */

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

html, body {
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--theme-bg);
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  color: var(--theme-text);
  -webkit-tap-highlight-color: transparent;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  font-weight: 400;
  letter-spacing: -0.025em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: none;
  overscroll-behavior: none;
  width: 100vw;
}

/* ========================================
   GAME CONTAINER
   ======================================== */

#gameRootContainer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0;
  left: 0;
  overflow: hidden;
  will-change: transform;
  transform: translateZ(0);
}

#gameContainerWrapper {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  max-width: none;
  margin: 0;
  padding: 0;
}

#gameContainer {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0;
  left: 0;
  background-color: var(--theme-canvas-bg);
  border: none;
  box-shadow: none;
  overflow: hidden;
  transition: background-color 0.3s ease;
  max-width: none;
  margin: 0;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: var(--theme-canvas-bg);
  border: none;
  outline: none;
  transition: background-color 0.3s ease;
  will-change: auto;
  transform: translateZ(0);
  image-rendering: optimizeSpeed;
  image-rendering: -webkit-optimize-contrast;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background-color: transparent;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 16px;
  overflow: hidden;
  margin: 0;
  padding: 0;
  max-width: none;
  max-height: none;
}

/* ========================================
   UI OVERLAY
   ======================================== */

#uiOverlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  color: var(--theme-text);
  font-size: clamp(13px, 2.2vw, 18px);
  pointer-events: none;
  text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.3);
  z-index: 10;
  transition: color 0.5s ease, text-shadow 0.5s ease;
}

.ui-left, .ui-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ui-right {
  align-items: flex-end;
}

#highScore {
  font-weight: bold;
  color: #8b4513;
  text-shadow: 1px 1px 0px #fff;
}

body.night-mode #highScore {
  color: #f4a460;
  text-shadow: 1px 1px 0px #111;
}

#cashDisplay {
  font-weight: bold;
  color: #228b22;
}

body.night-mode #cashDisplay {
  color: #34d399;
}

/* ========================================
   STAT BARS
   ======================================== */

.ui-stat-bar-container {
  width: 120px;
  height: 20px;
  border: 2px solid var(--theme-border);
  background-color: #d8d8d8;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 5px;
  border-radius: 3px;
  transition: border-color 0.5s ease, background-color 0.5s ease;
}

body.night-mode .ui-stat-bar-container {
  background-color: #444;
}

.ui-stat-bar {
  height: 100%;
  transition: width 0.1s linear, background-color 0.3s ease;
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 1px;
}

.ui-stat-label {
  position: relative;
  z-index: 1;
  font-size: 11px;
  font-weight: bold;
  color: var(--theme-text);
  text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.8);
  transition: color 0.5s ease;
  margin-left: 24px;
}

body.night-mode .ui-stat-label {
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.8);
}

.ui-stat-icon {
  width: 20px;
  height: 20px;
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  opacity: 0.9;
}

#fuelBar {
  background-color: #ef4444;
}

#healthBar {
  background-color: #10b981;
}

#cashBar {
  background-color: #228b22;
}

body.night-mode #cashBar {
  background-color: #2d5a2d;
}

/* ========================================
   IN-GAME BUTTONS
   ======================================== */

#inGameButtons {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 11;
  pointer-events: auto;
}

.in-game-button {
  padding: 8px 16px;
  font-size: 13px;
  background: var(--glass-bg);
  color: var(--theme-text);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  cursor: pointer;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 500;
  box-shadow: var(--shadow-subtle);
  backdrop-filter: blur(8px);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  position: relative;
  overflow: hidden;
}

.in-game-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(255, 255, 255, 0.1) 50%, transparent 100%);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.in-game-button:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--primary-blue);
  box-shadow: var(--shadow-medium);
  transform: translateY(-1px);
}

.in-game-button:hover::before {
  opacity: 1;
}

.in-game-button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-subtle);
}

body.night-mode .in-game-button {
  background: rgba(0, 0, 0, 0.6);
  border-color: var(--theme-card-border);
}

body.night-mode .in-game-button:hover {
  background: rgba(20, 20, 20, 0.8);
  border-color: var(--electric-blue);
}

/* ========================================
   OVERLAY SCREENS
   ======================================== */

.overlay-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(248, 250, 252, 0.75);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #1e293b;
  text-align: center;
  z-index: 20;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 24px;
  box-sizing: border-box;
  gap: 20px;
  overflow-y: auto;
  border: 1px solid rgba(59, 130, 246, 0.2);
  will-change: opacity, transform;
  transform: translateZ(0);
}

body.night-mode .overlay-screen {
  background: rgba(0, 0, 0, 0.75);
  color: #e2e8f0;
  border-color: rgba(96, 165, 250, 0.3);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 15px;
  max-width: 600px;
  width: 100%;
}

.overlay-content h2 {
  font-size: clamp(28px, 7vw, 40px);
  margin: 0 0 15px 0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: #1e293b;
}

body.night-mode .overlay-content h2 {
  color: #e2e8f0;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#garageOverlay h2 {
  font-size: clamp(32px, 8vw, 48px);
  margin-bottom: 16px;
  text-shadow: none;
  font-weight: 700;
  letter-spacing: -0.025em;
  background: var(--gradient-button);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0 0 20px 0;
}

body.night-mode #garageOverlay h2 {
  background: linear-gradient(135deg, #60a5fa 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ========================================
   BUTTONS
   ======================================== */

.overlay-button {
  background: rgba(255, 255, 255, 0.9);
  color: #1e293b;
  border: 2px solid #3b82f6;
  padding: 16px 32px;
  font-size: clamp(16px, 3.5vw, 20px);
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  border-radius: 16px;
  margin: 8px 0;
  min-height: 60px;
  width: 100%;
  max-width: 400px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-transform: none;
  letter-spacing: -0.025em;
  will-change: transform, box-shadow;
  transform: translateZ(0);
}

.overlay-button span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.overlay-button.primary {
  background: var(--gradient-button);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: clamp(18px, 3.5vw, 24px);
  padding: 20px 40px;
  box-shadow: var(--shadow-glow);
  max-width: 400px;
  min-height: 64px;
  font-weight: 700;
}

.overlay-button.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(37, 99, 235, 0.4), var(--shadow-glow);
  background: linear-gradient(135deg, var(--royal-blue) 0%, var(--electric-blue) 100%);
}

.overlay-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  transition: left 0.5s ease;
}

.overlay-button:hover::before {
  left: 100%;
}

.overlay-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
  border-color: var(--primary-blue);
  background: rgba(255, 255, 255, 1);
  color: #1e293b;
}

.overlay-button:active {
  transform: translateY(0);
  box-shadow: var(--shadow-medium);
}

.overlay-button.secondary {
  background: rgba(255, 255, 255, 0.98);
  color: #1e3a8a;
  border: 2px solid #3b82f6;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-size: clamp(14px, 3vw, 18px);
  min-height: 48px;
  padding: 12px 24px;
  font-weight: 600;
}

.overlay-button.secondary:hover {
  background: rgba(255, 255, 255, 1);
  border-color: #1e3a8a;
  color: #1e3a8a;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
}

body.night-mode .overlay-button {
  background: rgba(0, 0, 0, 0.75);
  color: #e2e8f0;
  border: 2px solid #60a5fa;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
}

body.night-mode .overlay-button:hover {
  background: rgba(10, 10, 15, 0.85);
  color: #60a5fa;
  border-color: #3b82f6;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(96, 165, 250, 0.3);
}

body.night-mode .overlay-button.primary {
  background: linear-gradient(135deg, #10b981 0%, #06b6d4 100%);
  color: #0a0a0a;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 32px rgba(16, 185, 129, 0.3);
  font-weight: 700;
}

body.night-mode .overlay-button.primary:hover {
  background: linear-gradient(135deg, #059669 0%, #0891b2 100%);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(16, 185, 129, 0.4);
}

body.night-mode .overlay-button.secondary {
  background: rgba(0, 0, 0, 0.75);
  color: #e2e8f0;
  border: 2px solid #60a5fa;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

body.night-mode .overlay-button.secondary:hover {
  background: rgba(10, 10, 15, 0.85);
  border-color: #3b82f6;
  color: #60a5fa;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(96, 165, 250, 0.3);
}

/* ========================================
   MODE BUTTONS
   ======================================== */

.mode-button {
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid #3b82f6;
  border-radius: 12px;
  color: #1e293b;
  padding: 8px 16px;
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(8px);
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.mode-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
  border-color: #1e3a8a;
  background: rgba(255, 255, 255, 1);
  color: #1e3a8a;
}

.mode-button.active {
  background: var(--gradient-button) !important;
  color: white !important;
  border-color: #60a5fa !important;
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6) !important;
  transform: scale(1.05) !important;
  font-weight: 900 !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5) !important;
}

body.night-mode .mode-button {
  background: rgba(10, 10, 15, 0.95);
  color: #e2e8f0;
  border: 2px solid #60a5fa;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

body.night-mode .mode-button:hover {
  border-color: #3b82f6;
  background: rgba(20, 20, 25, 0.95);
  color: #60a5fa;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(96, 165, 250, 0.3);
}

body.night-mode .mode-button.active {
  background: var(--gradient-button) !important;
  color: #ffffff !important;
  border-color: #60a5fa !important;
  box-shadow: 0 6px 20px rgba(96, 165, 250, 0.6) !important;
  transform: scale(1.05) !important;
  font-weight: 900 !important;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7) !important;
}

.mode-buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  align-items: center;
}

.game-mode-selection {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 15px 0;
  gap: 10px;
}

.game-mode-selection h3 {
  margin: 0 0 10px 0;
  font-size: clamp(16px, 3vw, 20px);
  color: #1e293b;
  font-weight: 700;
  font-family: 'Orbitron', monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

body.night-mode .game-mode-selection h3 {
  color: #e2e8f0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.button-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 420px;
  padding: 0 20px;
}

.secondary-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}

.secondary-buttons .overlay-button {
  width: 100%;
  max-width: 100%;
  min-height: 56px;
  font-size: clamp(14px, 3vw, 18px);
  padding: 14px 20px;
}

/* ========================================
   CAR CARDS & CAROUSEL
   ======================================== */

.car-carousel-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 25px 0;
  width: 100%;
  max-width: 900px;
  position: relative;
}

.car-selection-wrapper {
  flex: 1;
  overflow: hidden;
  border-radius: 16px;
  border: 2px solid var(--theme-card-border);
  background: var(--theme-card-bg);
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.15);
  backdrop-filter: blur(16px);
  padding: 12px;
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.night-mode .car-selection-wrapper {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.car-selection,
.dedicated-car-selection {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 15px;
  padding: 20px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.car-selection::-webkit-scrollbar,
.dedicated-car-selection::-webkit-scrollbar {
  display: none;
}

.car-card {
  border: 2px solid var(--theme-card-border);
  background: var(--theme-card-bg);
  padding: 14px;
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(59, 130, 246, 0.15);
  backdrop-filter: blur(16px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  min-height: 200px;
  margin: 0 auto;
}

.car-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(59, 130, 246, 0.05) 50%, transparent 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.car-card:hover::before {
  opacity: 1;
}

.car-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 16px 48px rgba(59, 130, 246, 0.25);
  border-color: var(--primary-blue);
  background: rgba(255, 255, 255, 0.15);
}

.car-card.selected {
  border-color: var(--royal-blue);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(147, 51, 234, 0.1) 100%);
  box-shadow: 0 12px 40px rgba(59, 130, 246, 0.3);
}

body.night-mode .car-card {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body.night-mode .car-card:hover {
  border-color: var(--electric-blue);
  box-shadow: 0 16px 48px rgba(37, 99, 235, 0.3);
  background: rgba(59, 130, 246, 0.15);
}

body.night-mode .car-card.selected {
  border-color: var(--neon-green);
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.2) 0%, rgba(168, 85, 247, 0.15) 100%);
  box-shadow: 0 12px 40px rgba(87, 255, 20, 0.3);
}

.car-card h3 {
  margin: 8px 0 6px 0;
  font-size: clamp(14px, 3vw, 18px);
  color: #0f172a;
  font-weight: 700;
  font-family: 'Orbitron', monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-shadow: none;
}

.car-card p {
  margin: 3px 0;
  font-size: clamp(10px, 2vw, 13px);
  color: #334155;
  opacity: 1;
  font-weight: 600;
  line-height: 1.2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

body.night-mode .car-card h3 {
  color: var(--theme-text);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

body.night-mode .car-card p {
  color: var(--theme-text);
  opacity: 0.9;
}

.car-preview {
  width: 80px;
  height: 45px;
  margin: 10px auto 15px;
  border: 2px solid var(--theme-card-border);
  border-radius: 8px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(59, 130, 246, 0.08);
  transition: all 0.3s ease;
}

body.night-mode .car-preview {
  background: rgba(37, 99, 235, 0.1);
}

.car-card:hover .car-preview {
  border-color: var(--primary-blue);
  background: rgba(59, 130, 246, 0.15);
}

body.night-mode .car-card:hover .car-preview {
  border-color: var(--electric-blue);
  background: rgba(37, 99, 235, 0.15);
}

.car-preview-png {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.car-card:hover .car-preview-png {
  transform: rotate(90deg) scale(1.1);
}

body.night-mode .car-preview-png {
  filter: drop-shadow(0 2px 4px rgba(255, 255, 255, 0.1)) brightness(1.1);
}

.car-card button {
  width: 100%;
  max-width: 280px;
  padding: 12px 20px;
  border: 2px solid var(--primary-blue);
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-blue) 0%, var(--royal-blue) 100%);
  color: white;
  font-size: clamp(12px, 2.5vw, 16px);
  font-weight: 700;
  font-family: 'Orbitron', monospace;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin-top: 12px;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

.car-card button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
  background: linear-gradient(135deg, var(--royal-blue) 0%, var(--electric-blue) 100%);
}

.car-card button:disabled {
  background: rgba(100, 116, 139, 0.6);
  border-color: rgba(100, 116, 139, 0.4);
  color: rgba(255, 255, 255, 0.6);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

body.night-mode .car-card button {
  background: linear-gradient(135deg, var(--neon-green) 0%, var(--electric-blue) 100%);
  border-color: var(--neon-green);
  color: #0a0a0a;
  box-shadow: 0 4px 16px rgba(87, 255, 20, 0.3);
}

body.night-mode .car-card button:hover {
  background: linear-gradient(135deg, #2aff00 0%, var(--neon-cyan) 100%);
  box-shadow: 0 8px 24px rgba(87, 255, 20, 0.4);
}

body.night-mode .car-card button:disabled {
  background: rgba(71, 85, 105, 0.6);
  border-color: rgba(71, 85, 105, 0.4);
  color: rgba(148, 163, 184, 0.7);
}

/* Carousel Navigation Buttons */
.carousel-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border: 3px solid var(--card-border);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-blue) 0%, var(--royal-blue) 100%);
  color: white;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.carousel-nav-btn::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
  transform: rotate(45deg);
  transition: transform 0.5s ease;
  opacity: 0;
}

.carousel-nav-btn:hover::before {
  transform: rotate(45deg) translateX(100%);
  opacity: 1;
}

.carousel-nav-btn:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 32px rgba(59, 130, 246, 0.4);
  border-color: var(--electric-blue);
}

.carousel-nav-btn:active {
  transform: translateY(-1px) scale(0.98);
}

.carousel-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

body.night-mode .carousel-nav-btn {
  background: linear-gradient(135deg, var(--neon-green) 0%, var(--electric-blue) 100%);
  border-color: var(--theme-card-border);
  color: #0a0a0a;
  box-shadow: 0 6px 20px rgba(87, 255, 20, 0.3);
}

body.night-mode .carousel-nav-btn:hover {
  box-shadow: 0 12px 32px rgba(87, 255, 20, 0.4);
  border-color: var(--neon-green);
}

/* ========================================
   MOBILE CONTROLS
   ======================================== */

#touchControls {
  width: 100%;
  max-width: 500px;
  margin: 5px auto 2px auto;
  padding: 5px;
  box-sizing: border-box;
  display: none;
  justify-content: space-between;
  align-items: center;
  z-index: 15;
  pointer-events: none;
  flex-shrink: 0;
}

.touch-control-group {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.touch-button {
  width: 60px;
  height: 60px;
  background-color: rgba(120, 120, 120, 0.55);
  border: 2px solid rgba(30, 30, 30, 0.6);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 30px;
  color: rgba(10, 10, 10, 0.75);
  user-select: none;
  cursor: pointer;
  box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.15);
  transition: background-color 0.15s, border-color 0.15s;
}

.touch-button:active {
  background-color: rgba(100, 100, 100, 0.65);
  box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.15);
  transform: translate(2px, 2px);
}

body.night-mode .touch-button {
  background-color: rgba(80, 80, 80, 0.6);
  border-color: rgba(150, 150, 150, 0.6);
  color: rgba(230, 230, 230, 0.8);
}

body.night-mode .touch-button:active {
  background-color: rgba(60, 60, 60, 0.7);
}

#mobileScreenControls {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 12;
  pointer-events: none;
  display: none;
}

.mobile-control-zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(48px, 12vw, 96px);
  color: rgba(255, 255, 255, 0.1);
  transition: background-color 0.15s, color 0.15s;
  font-family: 'Courier New', Courier, monospace;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
  min-height: 100vh;
  min-height: 100dvh;
}

#leftControlZone {
  left: 0;
}

#rightControlZone {
  right: 0;
}

.mobile-control-zone:active {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.2);
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

body.night-mode .mobile-control-zone:active {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.25);
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

#mobileControlGuide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 15;
  pointer-events: none;
  display: none;
  background: rgba(0, 0, 0, 0.7);
}

.control-guide-zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  color: white;
  font-family: 'Courier New', Courier, monospace;
  font-weight: bold;
  text-align: center;
}

#leftGuideZone {
  left: 0;
  border-right: 2px dashed rgba(255, 255, 255, 0.5);
}

#rightGuideZone {
  right: 0;
  border-left: 2px dashed rgba(255, 255, 255, 0.5);
}

.guide-icon {
  font-size: clamp(48px, 15vw, 96px);
  margin-bottom: 20px;
  animation: pulseGuide 1.5s ease-in-out infinite;
}

.guide-text {
  font-size: clamp(14px, 4vw, 20px);
  margin-bottom: 10px;
}

.guide-instruction {
  font-size: clamp(12px, 3vw, 16px);
  opacity: 0.8;
  animation: fadeInstruction 2s ease-in-out infinite;
}

.direction-arrow {
  position: absolute;
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  z-index: 5;
  transform-origin: center bottom;
  pointer-events: none;
  opacity: 0.9;
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.6));
  transition: border-bottom-color 0.5s ease, opacity 0.5s ease;
}

body.night-mode .direction-arrow {
  filter: drop-shadow(0 0 5px var(--neon-blue));
  opacity: 1;
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes pulseGuide {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.1);
    opacity: 0.7;
  }
}

@keyframes fadeInstruction {
  0%, 100% {
    opacity: 0.8;
  }
  50% {
    opacity: 0.4;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes scoreReveal {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-out {
  animation: fadeOut 0.5s ease-out forwards;
}

.instructions-hidden {
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ========================================
   BUTTON GROUPS
   ======================================== */

.button-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 300px;
}

.secondary-buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  justify-content: center;
  align-items: center;
}

/* ========================================
   RESPONSIVE DESIGN - MOBILE
   ======================================== */

@media (max-width: 768px) {
  #inGameButtons {
    display: none !important;
  }

  #mobileScreenControls {
    display: block;
  }

  .ui-stat-bar-container {
    width: 110px;
    height: 20px;
  }

  .ui-stat-label {
    font-size: 11px;
  }

  .overlay-button {
    font-size: clamp(14px, 4vw, 18px);
    padding: 12px 20px;
    min-height: 48px;
    margin: 6px 0;
  }

  .overlay-button.secondary {
    min-height: 44px;
    font-size: clamp(12px, 3.5vw, 16px);
  }

  .car-carousel-container {
    width: 100%;
    max-width: none;
    margin: 15px 0;
    gap: 8px;
  }

  .car-selection-wrapper {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
  }

  .car-selection-wrapper::-webkit-scrollbar {
    display: none;
  }

  .car-selection {
    scroll-snap-type: x mandatory;
    gap: 0;
    padding: 20px 10px;
  }

  .car-selection::-webkit-scrollbar {
    display: none;
  }

  .car-card {
    min-width: calc(100vw - 100px);
    max-width: calc(100vw - 100px);
    width: calc(100vw - 100px);
    flex-shrink: 0;
    scroll-snap-align: center;
    margin: 0 15px;
    padding: 15px;
    border-radius: 8px;
  }

  .carousel-nav-btn {
    width: 35px;
    height: 35px;
    min-width: 35px;
    font-size: 14px;
  }

  .secondary-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
  }

  .secondary-buttons .overlay-button {
    flex: 0 1 auto;
    min-width: 90px;
    margin: 0;
  }
}

@media (max-width: 768px) and (orientation: portrait) {
  html, body, #gameRootContainer, #gameContainerWrapper, #gameContainer {
    height: 100vh;
    height: 100svh;
    height: 100dvh;
  }

  #gameCanvas {
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    position: fixed;
    top: 0;
    left: 0;
  }

  #gameRootContainer, #gameContainerWrapper {
    padding: 0;
  }

  #gameContainer {
    border-width: 0px;
    box-shadow: none;
    border-radius: 0;
  }

  .mobile-control-zone {
    font-size: clamp(40px, 12vw, 60px);
  }

  #uiOverlay {
    padding: 4px 6px;
    font-size: clamp(11px, 2.8vw, 15px);
  }

  .ui-stat-bar-container {
    width: 95px;
    height: 14px;
  }

  .ui-stat-label {
    font-size: 9px;
  }
}

@media (max-width: 480px), (max-height: 640px) {
  .car-card {
    min-height: 95px !important;
    padding: 12px !important;
    margin: 4px auto !important;
  }

  .car-card h3 {
    font-size: 14px !important;
    margin: 4px 0 !important;
  }

  .car-card p {
    font-size: 11px !important;
    margin: 2px 0 !important;
    line-height: 1.3 !important;
  }

  .car-preview {
    height: 40px !important;
    margin: 6px 0 !important;
  }

  .overlay-button {
    padding: 6px 12px !important;
    font-size: 11px !important;
    margin-top: 6px !important;
  }
}

@media (max-width: 400px) and (orientation: portrait) {
  .car-card {
    min-height: 85px !important;
    padding: 10px !important;
    margin: 3px auto !important;
    border-radius: 16px !important;
  }

  .car-card h3 {
    font-size: 13px !important;
    margin: 3px 0 !important;
    font-weight: 600 !important;
  }

  .car-card p {
    font-size: 10px !important;
    margin: 1px 0 !important;
    line-height: 1.2 !important;
  }

  .car-preview {
    height: 35px !important;
    margin: 4px 0 !important;
  }

  .overlay-button {
    padding: 5px 10px !important;
    font-size: 10px !important;
    margin-top: 4px !important;
    border-radius: 12px !important;
  }

  .car-selection {
    gap: 6px !important;
    padding: 8px !important;
  }

  .dedicated-car-selection {
    padding: 8px !important;
  }

  .single-car-card {
    min-height: 80px !important;
  }
}

@media (max-width: 360px) {
  .car-card {
    min-height: 75px !important;
    padding: 8px !important;
    margin: 2px auto !important;
  }

  .car-card h3 {
    font-size: 12px !important;
    margin: 2px 0 !important;
  }

  .car-card p {
    font-size: 9px !important;
    margin: 1px 0 !important;
  }

  .car-preview {
    height: 30px !important;
    margin: 3px 0 !important;
  }

  .overlay-button {
    padding: 4px 8px !important;
    font-size: 9px !important;
    margin-top: 3px !important;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .ui-stat-bar-container {
    width: 90px;
    height: 16px;
  }

  .ui-stat-label {
    font-size: 9px;
  }

  .car-card {
    width: 30%;
    min-width: 140px;
    padding: 8px;
  }

  .car-card h3 {
    font-size: 11px;
  }

  .car-card p {
    font-size: 8px;
    margin: 2px 0;
  }

  .car-preview {
    width: 60px;
    height: 30px;
  }
}

/* ========================================
   RESPONSIVE DESIGN - DESKTOP
   ======================================== */

@media (min-width: 769px) {
  #gameRootContainer, #gameContainerWrapper, #gameContainer {
    width: 100vw !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  canvas {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }
}

/* ========================================
   VOLUME PANEL
   ======================================== */

.volume-panel {
  position: fixed;
  top: 20px;
  right: 20px;
  background: linear-gradient(135deg, var(--primary-blue) 0%, var(--neon-blue) 100%);
  border-radius: 15px;
  padding: 15px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 0 20px rgba(255, 107, 53, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  display: none;
  flex-direction: column;
  gap: 10px;
  min-width: 200px;
  z-index: 2000;
}

.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: linear-gradient(90deg, var(--neon-cyan) 0%, var(--neon-blue) 100%);
  border-radius: 3px;
  outline: none;
  transition: all 0.3s ease;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: radial-gradient(circle, #fff 0%, var(--primary-blue) 100%);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.6);
  transition: all 0.3s ease;
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.8);
}

.hud-element {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  backdrop-filter: blur(5px);
  padding: 8px 12px;
  font-family: 'Orbitron', monospace;
  font-weight: 600;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px currentColor;
  box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.1);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.show {
  display: block !important;
  animation: scoreReveal 0.8s ease-out;
}

/* ========================================
   AD CONTAINERS
   ======================================== */

.ad-container {
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.ad-container.top-ad {
  animation: slideDown 0.5s ease-out;
}

.ad-container.bottom-ad {
  animation: slideUp 0.5s ease-out;
}

.ad-container.social-bar-ad {
  animation: slideInLeft 0.5s ease-out;
}

@keyframes slideDown {
  from {
    transform: translate(-50%, -100%);
    opacity: 0;
  }
  to {
    transform: translateX(-50%);
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 100%);
    opacity: 0;
  }
  to {
    transform: translateX(-50%);
    opacity: 1;
  }
}

@keyframes slideInLeft {
  from {
    transform: translate(-100%, -50%);
    opacity: 0;
  }
  to {
    transform: translateY(-50%);
    opacity: 1;
  }
}

/* Hide ads on very small screens for better UX */
@media (max-width: 360px) {
  .ad-container.top-ad {
    top: -5px;
    font-size: 0.9em;
  }
  
  .ad-container.bottom-ad {
    bottom: -5px;
    font-size: 0.9em;
  }
}

/* Desktop ad positioning adjustments */
@media (min-width: 769px) {
  .ad-container.social-bar-ad {
    left: 15px;
  }
  
  /* Canvas is full screen - ads overlay with fixed positioning */
  #gameCanvas {
    max-height: 100vh;
  }
}

/* Mobile ad positioning adjustments */
@media (max-width: 768px) {
  .ad-container.top-ad,
  .ad-container.bottom-ad {
    max-width: 95%;
  }
}
