/* NEON STREAK: OVERDRIVE - CSS Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&family=Orbitron:wght@400;700;900&display=swap');

:root {
  --bg-color: #0c0214;
  --panel-bg: rgba(15, 2, 28, 0.75);
  --panel-border: rgba(255, 0, 127, 0.3);
  --cyan: #00f0ff;
  --pink: #ff007f;
  --yellow: #ffff00;
  --white: #ffffff;
  --font-hud: 'Orbitron', monospace;
  --font-ui: 'Inter', sans-serif;
  --glow-cyan: 0 0 10px rgba(0, 240, 255, 0.5), 0 0 20px rgba(0, 240, 255, 0.3);
  --glow-pink: 0 0 10px rgba(255, 0, 127, 0.5), 0 0 20px rgba(255, 0, 127, 0.3);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background-color: var(--bg-color);
  color: var(--white);
  font-family: var(--font-ui);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: radial-gradient(circle at center, #23083b 0%, #0c0214 100%);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Main Container */
#game-container {
  position: relative;
  width: 1024px;
  height: 768px;
  background: #000;
  border: 4px solid var(--pink);
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(255, 0, 127, 0.4), inset 0 0 20px rgba(0, 240, 255, 0.2);
  overflow: hidden;
}

/* Fill the whole viewport when the desktop frame doesn't fit (phones/tablets) */
@media (max-width: 1080px), (max-height: 820px) {
  #game-container {
    width: 100vw;
    width: 100dvw;
    height: 100vh;
    height: 100dvh;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
}

/* Aspect-ratio fallback / canvas styles */
#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  object-fit: contain; /* letterboxes when canvas aspect is clamped (extreme portrait) */
  touch-action: none;
}

/* UI Overlay Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(12, 2, 20, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  z-index: 10;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  padding: clamp(12px, 4vw, 40px);
  padding-top: max(clamp(12px, 4vw, 40px), env(safe-area-inset-top));
  padding-bottom: max(clamp(12px, 4vw, 40px), env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#hud-overlay.hidden {
  display: none;
}

/* CRT Scanline overlay */
#crt-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.15) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  background-size: 100% 4px, 6px 100%;
  z-index: 99;
  pointer-events: none;
  border-radius: 4px;
}

#crt-overlay.disabled {
  display: none;
}

/* Glassmorphism Panels */
.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: clamp(14px, 3.5vw, 30px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(255, 0, 127, 0.1);
  max-width: 900px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: auto; /* centers when shorter than the screen, scrolls when taller */
  flex-shrink: 0;
}

/* Typography & Neon Text Glows */
h1 {
  font-family: var(--font-hud);
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  letter-spacing: 4px;
  color: var(--white);
  text-align: center;
  margin-bottom: 30px;
  text-transform: uppercase;
  text-shadow: 0 0 10px var(--pink), 0 0 20px var(--pink);
  animation: neon-flicker 4s infinite alternate;
}

h2 {
  font-family: var(--font-hud);
  color: var(--cyan);
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  margin-bottom: 20px;
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
}

h3 {
  font-family: var(--font-hud);
  color: var(--pink);
  margin-bottom: 10px;
}

/* Buttons */
.btn {
  font-family: var(--font-hud);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 12px 30px;
  margin: 10px;
  background: transparent;
  border: 2px solid var(--cyan);
  color: var(--cyan);
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  box-shadow: 0 0 5px rgba(0, 240, 255, 0.2);
}

.btn:hover:not(:disabled) {
  background: var(--cyan);
  color: #000;
  box-shadow: var(--glow-cyan);
  transform: scale(1.05);
}

.btn-secondary {
  border-color: var(--pink);
  color: var(--pink);
  box-shadow: 0 0 5px rgba(255, 0, 127, 0.2);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--pink);
  color: var(--white);
  box-shadow: var(--glow-pink);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: #555;
  color: #555;
  box-shadow: none;
}

/* Horizontal flex rows */
.row {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 20px;
}

/* CAR SELECT & TRACK SELECT VIEWS */
.selector-container {
  display: flex;
  gap: 20px;
  width: 100%;
  margin-bottom: 25px;
  justify-content: center;
}

.card {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.25s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.card:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 0, 127, 0.5);
  box-shadow: 0 0 15px rgba(255, 0, 127, 0.15);
  transform: translateY(-5px);
}

.card.active {
  background: rgba(255, 0, 127, 0.08);
  border-color: var(--pink);
  box-shadow: 0 0 20px rgba(255, 0, 127, 0.25);
}

.card-title {
  font-family: var(--font-hud);
  font-size: 1.3rem;
  margin-bottom: 10px;
  color: var(--white);
}

.card-title.cyan-text {
  color: var(--cyan);
}

.card-desc {
  font-size: 0.85rem;
  color: #aaa;
  margin-bottom: 15px;
  line-height: 1.4;
  height: 60px;
  overflow: hidden;
}

.card-specs {
  width: 100%;
  margin-top: auto;
}

.spec-bar-wrapper {
  margin-bottom: 8px;
  text-align: left;
}

.spec-label {
  font-size: 0.75rem;
  color: #ccc;
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.spec-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
  overflow: hidden;
}

.spec-bar-fill {
  height: 100%;
  background: var(--cyan);
  border-radius: 3px;
}

.card.active .spec-bar-fill {
  background: var(--pink);
}

/* GARAGE / UPGRADES PANEL */
.garage-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  width: 100%;
  margin-bottom: 25px;
}

.garage-car-preview {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  padding-right: 20px;
}

.garage-upgrades-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.upgrade-item {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
}

.upgrade-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.upgrade-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.upgrade-cost {
  color: var(--yellow);
  font-family: var(--font-hud);
  font-size: 0.9rem;
}

.upgrade-bar {
  display: flex;
  gap: 4px;
}

.upgrade-pip {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
}

.upgrade-pip.filled {
  background: var(--cyan);
  box-shadow: 0 0 5px rgba(0, 240, 255, 0.4);
}

.upgrade-item button {
  margin-top: 8px;
  align-self: flex-end;
  padding: 4px 12px;
  font-size: 0.8rem;
}

/* SCOREBOARD / LEADERBOARD */
.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 15px;
  margin-bottom: 25px;
}

.leaderboard-table th, .leaderboard-table td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.leaderboard-table th {
  font-family: var(--font-hud);
  color: var(--pink);
  font-size: 0.9rem;
}

.leaderboard-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.leaderboard-table td.rank-1 { color: var(--yellow); font-weight: bold; }
.leaderboard-table td.rank-2 { color: #d1d1d1; }
.leaderboard-table td.rank-3 { color: #cd7f32; }

/* CREDITS HUD IN SELECTOR */
.credits-counter {
  font-family: var(--font-hud);
  color: var(--yellow);
  font-size: 1.4rem;
  text-shadow: 0 0 8px rgba(255, 230, 0, 0.4);
  margin-bottom: 15px;
}

/* SETTINGS OPTIONS */
.options-list {
  width: 100%;
  margin-bottom: 25px;
}

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

.option-label {
  font-weight: 600;
}

.option-desc {
  font-size: 0.8rem;
  color: #888;
  margin-top: 3px;
}

/* Switch styling */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: .4s;
  border-radius: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: var(--white);
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--cyan);
  border-color: var(--cyan);
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

input:checked + .slider:before {
  transform: translateX(24px);
  background-color: #000;
}

/* IN-GAME HUD LAYOUT */
#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 5;
  padding: 25px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: var(--font-hud);
}

.hud-top {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding-right: 56px; /* clear the pause button */
}

.hud-panel {
  background: rgba(12, 2, 20, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.2);
  border-radius: 6px;
  padding: 8px 15px;
  backdrop-filter: blur(5px);
}

.hud-label {
  font-size: 0.7rem;
  color: #888;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.hud-val {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--white);
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

.hud-val.cyan-text {
  color: var(--cyan);
}

.hud-val.pink-text {
  color: var(--pink);
}

/* Speedometer circular/bottom panel */
.hud-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
}

.speedometer-panel {
  display: flex;
  gap: 15px;
  align-items: flex-end;
}

.hud-boost-bar {
  width: 120px;
  background: rgba(12, 2, 20, 0.7);
  border: 1px solid rgba(255, 0, 127, 0.2);
  border-radius: 6px;
  padding: 8px 12px;
  backdrop-filter: blur(5px);
}

.boost-gauge-bg {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
  margin-top: 4px;
}

.boost-gauge-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--pink), var(--cyan));
  box-shadow: 0 0 5px var(--pink);
  border-radius: 5px;
  transition: width 0.1s linear;
}

/* BIG NOTIFICATIONS IN-GAME (Countdown, Lap clear, Checkpoint) */
.hud-center-alert {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.alert-text {
  font-size: clamp(2.4rem, 10vw, 5rem);
  font-weight: 900;
  text-transform: uppercase;
  color: var(--white);
  text-shadow: 0 0 20px var(--pink), 0 0 40px var(--pink);
  animation: scale-up 0.5s ease forwards;
}

.alert-subtext {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
  text-transform: uppercase;
  margin-top: 10px;
}

/* Screen animations */
@keyframes neon-flicker {
  0%, 19%, 21%, 23%, 25%, 54%, 56%, 100% {
    text-shadow: 0 0 4px #fff, 0 0 10px var(--pink), 0 0 20px var(--pink), 0 0 30px var(--pink);
  }
  20%, 24%, 55% {
    text-shadow: 0 0 2px rgba(255, 0, 127, 0.4);
  }
}

@keyframes scale-up {
  0% {
    transform: scale(0.2);
    opacity: 0;
  }
  70% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Touch controls for mobile devices - Hidden by default */
#touch-controls {
  position: absolute;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 0;
  width: 100%;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
  z-index: 6;
  pointer-events: none;
}

.touch-btn {
  width: 78px;
  height: 78px;
  background: rgba(12, 2, 20, 0.55);
  border: 2px solid var(--cyan);
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--cyan);
  font-family: var(--font-hud);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#touch-left, #touch-right {
  font-size: 1.8rem;
}

#touch-gas {
  width: 96px;
  height: 96px;
}

.touch-btn:active, .touch-btn.pressed {
  background: var(--cyan);
  color: #000;
  box-shadow: var(--glow-cyan);
}

/* Pause button visible during races (mainly for touch players with no ESC key) */
#btn-hud-pause {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  background: rgba(12, 2, 20, 0.7);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 6px;
  color: var(--cyan);
  font-size: 1.1rem;
  cursor: pointer;
  pointer-events: auto;
  z-index: 7;
  touch-action: manipulation;
}

/* Compact layout for phone screens */
@media (max-width: 700px) {
  .selector-container {
    flex-direction: column;
    gap: 12px;
  }

  .card-desc {
    height: auto;
  }

  .garage-container {
    grid-template-columns: 1fr;
  }

  .garage-car-preview {
    border-right: none;
    padding-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 15px;
  }

  .btn {
    font-size: 0.95rem;
    padding: 12px 18px;
    margin: 6px;
  }

  .row {
    gap: 10px;
  }

  /* Slimmer in-race HUD */
  #hud-overlay {
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .hud-panel {
    padding: 5px 9px;
    border-radius: 4px;
  }

  .hud-label {
    font-size: 0.55rem;
  }

  .hud-val {
    font-size: 1rem;
  }

  .hud-top {
    gap: 6px;
    padding-right: 52px; /* keep clear of the pause button */
  }

  .hud-top .hud-panel {
    min-width: 0 !important;
  }

  .hud-boost-bar {
    width: 100px;
  }
}

/* Keep the bottom HUD clear of the touch buttons while racing */
body.touch-device #hud-overlay {
  padding-bottom: calc(120px + env(safe-area-inset-bottom));
}

/* Very narrow screens: drop the least useful HUD panels, shrink touch buttons */
@media (max-width: 480px) {
  #hud-credits-live {
    display: none;
  }

  .hud-top .hud-panel:has(#hud-credits-live) {
    display: none;
  }

  #touch-controls {
    padding: 0 10px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #touch-controls > div {
    gap: 8px !important;
  }

  .touch-btn {
    width: 60px;
    height: 60px;
    font-size: 0.8rem;
  }

  #touch-left, #touch-right {
    font-size: 1.4rem;
  }

  #touch-gas {
    width: 80px;
    height: 80px;
  }

  body.touch-device #hud-overlay {
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }
}

/* Instructions card on HUD start */
.keyboard-tip {
  font-size: 0.8rem;
  color: #777;
  text-align: center;
  margin-top: 15px;
}
