/* Booger Kart 64 - Grand Prix & Flight Circuits Styling */
:root {
  --bg-dark: #0a0c16;
  --panel-bg: rgba(18, 22, 40, 0.82);
  --panel-border: rgba(255, 255, 255, 0.18);
  --accent-gold: #ffd166;
  --accent-cyan: #45bdd1;
  --accent-pink: #ff477e;
  --accent-green: #06d6a0;
  --accent-purple: #9d4edd;
  --accent-blue: #3a86ff;
  --text-main: #f8f9fa;
  --text-muted: #a0aab8;
  --radius-lg: 16px;
  --radius-md: 10px;
  --shadow-glow: 0 0 25px rgba(255, 209, 102, 0.4);
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-arcade: 'Space Grotesk', var(--font-family);
}

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

body.driving-body {
  background: var(--bg-dark);
  background-image: radial-gradient(circle at 50% 0%, #20133b 0%, #0a0c16 75%);
  color: var(--text-main);
  font-family: var(--font-family);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

/* Top Navigation Bar */
.driving-topbar {
  width: 100%;
  max-width: 1100px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px);
  border-bottom: 2px solid var(--panel-border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  z-index: 100;
}

.topbar-left, .topbar-right {
  display: flex;
  gap: 10px;
}

.game-logo {
  font-family: var(--font-arcade);
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 1px;
  color: #fff;
  text-shadow: 0 0 14px rgba(255, 209, 102, 0.6);
}

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

.logo-badge {
  font-size: 0.7rem;
  background: linear-gradient(135deg, var(--accent-pink), var(--accent-purple));
  color: #fff;
  padding: 2px 8px;
  border-radius: 20px;
  vertical-align: super;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.highlight-btn {
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.25), rgba(255, 71, 126, 0.3));
  border-color: var(--accent-gold);
  box-shadow: 0 0 15px rgba(255, 209, 102, 0.3);
}

.highlight-btn:hover { box-shadow: var(--shadow-glow); }

/* Shell Layout */
.driving-shell {
  width: 100%;
  max-width: 1050px;
  margin: 16px auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px;
}

/* Driver / Track Selector Bar */
.driving-picker-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  flex-wrap: wrap;
  gap: 12px;
}

.picker-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: 100%;
}

.picker-group label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
}

.btn-toggle-group {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.4);
  padding: 4px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  min-width: 0;
  max-width: 100%;
}

.driver-btn, .track-btn, .cc-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.driver-badge-img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.5);
}

.driver-btn.active, .track-btn.active, .cc-btn.active {
  background: var(--accent-gold);
  color: #0b1329;
  font-weight: 800;
  box-shadow: 0 2px 10px rgba(255, 209, 102, 0.5);
}

.special-track-btn {
  border: 1px solid rgba(69, 189, 209, 0.4);
  background: rgba(69, 189, 209, 0.1);
}

.special-track-btn.active {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #fff;
  box-shadow: 0 0 15px rgba(69, 189, 209, 0.6);
}

/* Main Canvas Stage */
.driving-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), var(--shadow-glow);
  border: 2px solid var(--panel-border);
}

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

/* Countdown Overlay */
.countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.12);
  z-index: 40;
  pointer-events: none;
}

.countdown-overlay.hidden { display: none; }

.countdown-number {
  font-size: 6rem;
  font-weight: 900;
  color: var(--accent-gold);
  text-shadow: 0 0 30px rgba(255, 209, 102, 0.9), 0 0 10px #000;
  animation: zoom-count 0.8s ease-out;
}

@keyframes zoom-count {
  0% { transform: scale(2.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* Glassmorphism HUD */
.driving-hud-glass {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 170px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 10;
}

.hud-card {
  background: rgba(10, 14, 28, 0.72);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.hud-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.hud-value {
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
  line-height: 1.1;
}

.hud-value-large {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent-gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.6);
}

.hud-value-large small { font-size: 1rem; }

.hud-subvalue {
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 700;
}

.item-card { min-width: 110px; }

.item-box-slot {
  width: 44px;
  height: 44px;
  background: radial-gradient(circle, rgba(255, 209, 102, 0.35) 0%, rgba(0, 0, 0, 0.6) 100%);
  border: 2px solid var(--accent-gold);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  box-shadow: 0 0 14px rgba(255, 209, 102, 0.4);
}

.item-icon {
  font-size: 1.5rem;
  animation: pulse-item 1.5s infinite alternate;
}

@keyframes pulse-item {
  0% { transform: scale(0.9); }
  100% { transform: scale(1.1); }
}

/* MK64 Minimap Overlay Container */
.mk64-minimap-container {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 140px;
  height: 140px;
  background: rgba(10, 14, 28, 0.75);
  backdrop-filter: blur(10px);
  border: 2px solid var(--accent-gold);
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.35);
  z-index: 20;
  pointer-events: none;
}

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

/* Glider Badge */
.glider-badge {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(58, 134, 255, 0.9), rgba(69, 189, 209, 0.9));
  color: #fff;
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 800;
  box-shadow: 0 0 15px rgba(58, 134, 255, 0.6);
  z-index: 25;
  pointer-events: none;
  animation: pulse-glider 1s infinite alternate;
}

.glider-badge.hidden { display: none; }

@keyframes pulse-glider {
  0% { transform: translateX(-50%) scale(0.95); }
  100% { transform: translateX(-50%) scale(1.05); }
}

.speed-gauge-wrap {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.hud-unit {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Controller Status Pill */
.gamepad-status-pill {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: rgba(10, 14, 28, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--panel-border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}

.pill-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff4757;
}

.gamepad-status-pill.connected .pill-dot {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

/* Non-Intrusive Alpha Fade-Out Toast Notifications */
.driving-toast {
  position: absolute;
  top: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 14, 28, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--accent-gold);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
  padding: 6px 18px;
  border-radius: 20px;
  box-shadow: 0 0 15px rgba(255, 209, 102, 0.4);
  z-index: 30;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.driving-toast.hidden {
  opacity: 0;
  transform: translate(-50%, -10px);
  pointer-events: none;
}

/* Reward / Victory Modal */
.driving-reward {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 15, 0.85);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.driving-reward.hidden { display: none; }

.driving-reward-card {
  background: linear-gradient(135deg, rgba(20, 26, 50, 0.95), rgba(10, 14, 28, 0.98));
  border: 2px solid var(--accent-gold);
  border-radius: var(--radius-lg);
  padding: 30px 40px;
  text-align: center;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 0 40px rgba(255, 209, 102, 0.4);
}

.trophy-header {
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--accent-gold);
  margin-bottom: 8px;
}

.driving-reward-card h2 {
  font-size: 1.8rem;
  font-weight: 900;
  color: #fff;
  margin-bottom: 12px;
}

.driving-reward-lines {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.driving-reward-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.action-btn {
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  font-weight: 800;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.primary-btn {
  background: linear-gradient(135deg, var(--accent-gold), #f39c12);
  color: #000;
  box-shadow: 0 4px 15px rgba(255, 209, 102, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 209, 102, 0.6);
}

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

/* Touch Controls */
.driving-touch-controls {
  display: none;
  justify-content: space-between;
  padding: 10px;
  gap: 10px;
}

@media (max-width: 850px), (pointer: coarse) {
  .driving-topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding-inline: 12px;
  }

  .topbar-center {
    order: -1;
    width: 100%;
    text-align: center;
  }

  .topbar-left,
  .topbar-right {
    display: grid;
    flex: 1 1 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .driving-picker-bar {
    align-items: stretch;
  }

  .picker-group {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .btn-toggle-group {
    width: 100%;
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .driver-btn,
  .track-btn,
  .cc-btn {
    flex: 1 1 92px;
    min-height: 44px;
    justify-content: center;
    white-space: normal;
  }

  .driving-touch-controls {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  }
  .mk64-minimap-container { width: 100px; height: 100px; }
  .driving-hud-glass {
    right: 120px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
  }

  .hud-card,
  .item-card {
    min-width: 0;
    padding: 4px;
  }

  .hud-value-large { font-size: 1.5rem; }

  .touch-left-cluster,
  .touch-right-cluster {
    min-width: 0;
    gap: 6px;
  }

  .touch-btn {
    min-width: 44px;
    min-height: 44px;
    flex: 1 1 0;
    padding: 10px 5px;
    font-size: 0.76rem;
  }
}

.touch-left-cluster, .touch-right-cluster {
  display: flex;
  gap: 10px;
}

.touch-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--panel-border);
  color: #fff;
  font-weight: 800;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  touch-action: manipulation;
}

.touch-btn:active {
  background: var(--accent-cyan);
  color: #000;
}

/* Steering Wheel Calibration Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal-card {
  background: linear-gradient(135deg, #12182d, #090c18);
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  padding: 24px;
  box-shadow: var(--shadow-glow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  font-size: 1.2rem;
  color: #fff;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.8rem;
  cursor: pointer;
}

.modal-intro {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.device-info-box {
  background: rgba(0, 0, 0, 0.4);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border-left: 4px solid var(--accent-cyan);
  margin-bottom: 16px;
  font-size: 0.85rem;
}

.device-info-box strong {
  display: block;
  color: var(--accent-gold);
  margin-top: 4px;
}

.cal-meters-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.cal-meter-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
  border-radius: var(--radius-md);
}

.cal-meter-box label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.meter-bar-track {
  height: 12px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.meter-bar-fill {
  height: 100%;
  transition: width 0.05s linear;
}

.steer-fill { background: var(--accent-cyan); }
.gas-fill { background: var(--accent-green); }

.meter-val {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
}
