/* ==========================================================================
   Turbo Drift - Retro Arcade Styling (Pure CSS, 0 Dependencies)
   ========================================================================== */

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

body {
  background-color: #0b0f19;
  color: #f8fafc;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  user-select: none;
}

#game-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
}

#gameCanvas {
  background-color: #1e293b;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.1);
  max-width: 96vw;
  max-height: 96vh;
  aspect-ratio: 16 / 9;
}

/* UI Overlay Layer */
#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Modals (Start & Finish) */
.overlay-modal {
  position: absolute;
  display: none;
  pointer-events: auto;
  z-index: 10;
}

.overlay-modal.active {
  display: flex;
  animation: modalFadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-content {
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  padding: 30px 36px;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.15);
  max-width: 560px;
  width: 92vw;
}

/* Titels */
.game-title {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #f8fafc;
  margin-bottom: 2px;
  text-shadow: 0 0 20px rgba(249, 115, 22, 0.5);
}

.game-title span {
  color: #f97316;
}

.victory-title {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #4ade80;
  margin-bottom: 8px;
  text-shadow: 0 0 25px rgba(74, 222, 128, 0.4);
}

.track-finish-subtitle {
  font-size: 15px;
  color: #38bdf8;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 20px;
}

.subtitle {
  font-size: 13px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 18px;
}

/* Baanselectie Section */
.track-selector-section {
  margin-bottom: 20px;
  text-align: left;
}

.track-selector-section h3 {
  font-size: 12px;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
}

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

.track-btn {
  background: rgba(30, 41, 59, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px 10px;
  color: #f8fafc;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 85px;
}

.track-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
  background: rgba(30, 41, 59, 0.9);
}

.track-btn.active {
  border-color: #f97316;
  background: rgba(249, 115, 22, 0.15);
  box-shadow: 0 0 16px rgba(249, 115, 22, 0.35);
}

.track-btn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.track-name {
  font-size: 13px;
  font-weight: 800;
  color: #f8fafc;
}

.track-badge {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(249, 115, 22, 0.2);
  color: #f97316;
}

.track-badge.green {
  background: rgba(34, 197, 94, 0.2);
  color: #4ade80;
}

.track-badge.purple {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
}

.track-desc {
  font-size: 10px;
  color: #94a3b8;
  line-height: 1.3;
  margin-bottom: 6px;
}

.track-stat {
  font-size: 10px;
  color: #64748b;
  font-family: monospace;
}

.track-stat .track-record {
  color: #38bdf8;
  font-weight: 700;
}

/* Besturingspaneel */
.controls-panel {
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 22px;
  text-align: left;
}

.controls-panel h3 {
  font-size: 11px;
  color: #38bdf8;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 4px;
}

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-row .keys {
  background: #334155;
  color: #f8fafc;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-weight: bold;
  font-size: 11px;
  border-bottom: 2px solid #1e293b;
}

.control-row .action {
  color: #cbd5e1;
}

/* Knoppen */
.arcade-btn {
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: #ffffff;
  border: none;
  border-radius: 10px;
  padding: 13px 28px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1.5px;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(249, 115, 22, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transition: all 0.2s ease;
  width: 100%;
}

.arcade-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(249, 115, 22, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
}

.arcade-btn:active {
  transform: translateY(1px);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.4);
}

.finish-btn-row {
  display: flex;
  gap: 12px;
}

.arcade-btn.secondary-btn {
  background: #334155;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.arcade-btn.secondary-btn:hover {
  background: #475569;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

/* Statistieken na de finish */
.stats-summary {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 22px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-item:last-child {
  border-bottom: none;
}

.stat-item .label {
  color: #94a3b8;
  font-size: 13px;
}

.stat-item .value {
  font-family: monospace;
  font-size: 16px;
  font-weight: bold;
  color: #f8fafc;
}

.stat-item.highlight .value {
  color: #38bdf8;
  font-size: 20px;
}

/* ==========================================================================
   Touch Controls (Mobile)
   ========================================================================== */

/* Touch overlay: standaard verborgen, pas zichtbaar op touch-apparaten als het spel gestart is (.active) */
#touch-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 50;
  pointer-events: none; /* stuurzones en knoppen zetten dit zelf aan */
}

/* Toon overlay alleen op touch devices (coarse pointer = vinger) wanneer actief */
@media (pointer: coarse) {
  #touch-overlay.active {
    display: block;
  }

  /* Verberg toetsenbord-uitleg op startscherm op mobiel */
  .controls-panel {
    display: none;
  }

  /* Canvas: voorkom scroll en zoom */
  #gameCanvas {
    touch-action: none;
    border-radius: 0;
    max-width: 100vw;
    max-height: 100vh;
    box-shadow: none;
  }

  /* Fullscreen layout op mobiel */
  body {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
  }

  #game-container {
    width: 100%;
    height: 100%;
  }
}

/* Touch stuurzones: grote transparante klikgebieden */
.touch-zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  pointer-events: auto;
  /* Subtiele visuele aanduiding — bijna transparant */
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}

#touch-left {
  left: 0;
}

#touch-right {
  right: 0;
}

/* Touch actieknop: alleen reset */
.touch-btn {
  position: absolute;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  pointer-events: auto;
  border: none;
  border-radius: 50%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.05em;
  color: #fff;
  min-width: 72px;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  /* Mooie semi-transparante achtergrond */
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: background 0.1s ease, transform 0.1s ease;
}

.touch-btn:active {
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0.93);
}

/* Reset-knop: linksonder in de hoek */
.touch-btn-reset {
  left: max(16px, env(safe-area-inset-left, 16px));
  font-size: 24px;
  min-width: 56px;
  min-height: 56px;
  background: rgba(148, 163, 184, 0.2);
  border-color: rgba(148, 163, 184, 0.35);
}

/* Landscape-specifieke aanpassingen */
@media (pointer: coarse) and (orientation: landscape) {
  .touch-btn {
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    min-width: 64px;
    min-height: 64px;
    font-size: 12px;
  }

  /* Track-grid smaller in landscape */
  .track-grid {
    gap: 8px;
  }

  .modal-content {
    padding: 16px;
    gap: 12px;
  }
}
