/* Apex Lane — neon arcade */

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

:root {
  --bg: #070712;
  --panel: rgba(10, 12, 28, 0.92);
  --neon: #00f0ff;
  --neon2: #ff2bd6;
  --accent: #ffe600;
  --text: #e8f0ff;
  --muted: #7a8499;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #12122a 0%, #070712 70%);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
  background: #0a0a1a;
  image-rendering: auto;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(4, 4, 14, 0.72);
  backdrop-filter: blur(4px);
  padding: 16px;
  overflow-y: auto;
}

.overlay.hidden { display: none; }

.panel {
  text-align: center;
  background: var(--panel);
  border: 1px solid rgba(0, 240, 255, 0.35);
  box-shadow:
    0 0 40px rgba(0, 240, 255, 0.15),
    0 0 80px rgba(255, 43, 214, 0.08),
    inset 0 0 60px rgba(0, 240, 255, 0.04);
  border-radius: 16px;
  padding: 28px 32px 24px;
  max-width: 520px;
  width: 100%;
}

.panel.wide {
  max-width: 720px;
  padding: 22px 24px 20px;
}

.logo {
  font-size: clamp(2.2rem, 8vw, 3.4rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--text);
  text-shadow:
    0 0 12px rgba(0, 240, 255, 0.8),
    0 0 32px rgba(0, 240, 255, 0.4);
  line-height: 1.05;
}

.logo span {
  color: var(--neon2);
  text-shadow:
    0 0 12px rgba(255, 43, 214, 0.9),
    0 0 32px rgba(255, 43, 214, 0.45);
}

.tagline {
  margin: 10px 0 22px;
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.meta {
  margin-top: 16px;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.btn {
  display: inline-block;
  margin: 6px 4px;
  padding: 12px 28px;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
  touch-action: manipulation;
}

.btn.primary {
  background: linear-gradient(135deg, var(--neon), #0088ff);
  color: #041018;
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.45);
}

.btn.primary:hover, .btn.primary:focus-visible {
  transform: scale(1.04);
  box-shadow: 0 0 28px rgba(0, 240, 255, 0.7);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(122, 132, 153, 0.4);
}

.btn.ghost:hover { color: var(--text); border-color: var(--neon); }

.legend {
  margin-top: 22px;
  text-align: left;
  display: inline-block;
  font-size: 0.85rem;
  color: var(--muted);
}

.legend-row { margin: 5px 0; }

.legend kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 2px 6px;
  margin: 0 2px;
  background: rgba(0, 240, 255, 0.12);
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 4px;
  color: var(--neon);
  font-family: inherit;
  font-size: 0.8rem;
  text-align: center;
}

.touch-hint { margin-top: 8px; font-size: 0.8rem; opacity: 0.7; }

/* Garage */
.garage-title {
  font-size: 1.1rem;
  letter-spacing: 0.2em;
  color: var(--neon);
  margin-bottom: 14px;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.garage-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  text-align: left;
}

@media (min-width: 560px) {
  .garage-layout {
    grid-template-columns: 200px 1fr;
    align-items: start;
  }
}

.garage-preview {
  background: linear-gradient(180deg, #0e1024 0%, #1a0a28 100%);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 160px;
}

#garage-canvas {
  width: 180px;
  height: 110px;
  display: block;
}

.preview-name {
  margin-top: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  text-align: center;
}

.preview-livery {
  font-size: 0.75rem;
  color: var(--neon2);
  letter-spacing: 0.06em;
  text-align: center;
}

.car-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}

.car-slot {
  background: rgba(20, 24, 48, 0.8);
  border: 1px solid rgba(122, 132, 153, 0.3);
  border-radius: 10px;
  padding: 10px 8px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
  touch-action: manipulation;
  color: var(--text);
  font: inherit;
}

.car-slot:hover {
  border-color: rgba(0, 240, 255, 0.5);
  transform: translateY(-1px);
}

.car-slot.selected {
  border-color: var(--neon);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.35);
  background: rgba(0, 240, 255, 0.08);
}

.car-slot .slot-name {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.car-slot canvas {
  width: 72px;
  height: 40px;
  display: block;
  margin: 0 auto;
  pointer-events: none;
}

.livery-row {
  margin-top: 14px;
}

.livery-label {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.12s, box-shadow 0.12s;
  touch-action: manipulation;
  box-shadow: inset 0 -8px 12px rgba(0, 0, 0, 0.35);
}

.swatch:hover { transform: scale(1.08); }

.swatch.selected {
  border-color: #fff;
  box-shadow:
    0 0 0 2px var(--neon),
    0 0 14px rgba(0, 240, 255, 0.5),
    inset 0 -8px 12px rgba(0, 0, 0, 0.35);
}

.swatch .swatch-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #12122a;
  color: var(--text);
  font-size: 0.65rem;
  padding: 3px 7px;
  border-radius: 4px;
  white-space: nowrap;
  pointer-events: none;
  border: 1px solid rgba(0, 240, 255, 0.3);
  z-index: 2;
}

.swatch:hover .swatch-tip,
.swatch.selected .swatch-tip { display: block; }

.garage-actions {
  margin-top: 18px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Countdown */
#countdown {
  background: rgba(4, 4, 14, 0.35);
  pointer-events: none;
}

#countdown-num {
  font-size: clamp(5rem, 22vw, 9rem);
  font-weight: 900;
  color: var(--accent);
  text-shadow:
    0 0 20px rgba(255, 230, 0, 0.9),
    0 0 60px rgba(255, 43, 214, 0.5);
  letter-spacing: 0.05em;
  animation: pulse 0.85s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.85; }
}

/* HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 14px;
  padding-left: max(14px, var(--safe-l));
  padding-right: max(14px, var(--safe-r));
}

#hud.hidden { display: none; }

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

.hud-center { align-items: center; }
.hud-right { align-items: flex-end; }

.hud-block {
  background: rgba(8, 10, 24, 0.72);
  border: 1px solid rgba(0, 240, 255, 0.22);
  border-radius: 8px;
  padding: 6px 12px;
  backdrop-filter: blur(2px);
  min-width: 72px;
}

.hud-label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.hud-value {
  font-size: 1.35rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.35);
  line-height: 1.15;
}

.hud-value.accent {
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255, 230, 0, 0.5);
  font-size: 1.8rem;
}

.pos-of { font-size: 0.85rem; color: var(--muted); font-weight: 600; }

.hud-unit {
  font-size: 0.65rem;
  color: var(--neon);
  margin-left: 2px;
}

.nitro-bar {
  width: 90px;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 4px;
}

#nitro-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--neon2), var(--neon));
  border-radius: 4px;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px rgba(255, 43, 214, 0.6);
}

/* Results */
.results-place {
  font-size: 3rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(255, 230, 0, 0.6);
  margin: 4px 0;
}

.results-time {
  color: var(--neon);
  font-size: 1.2rem;
  margin-bottom: 14px;
  font-variant-numeric: tabular-nums;
}

.results-board {
  text-align: left;
  margin: 0 auto 16px;
  max-width: 280px;
  font-size: 0.85rem;
}

.results-board .rb-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 4px;
  color: var(--muted);
}

.results-board .rb-row.you {
  background: rgba(0, 240, 255, 0.12);
  color: var(--text);
  border: 1px solid rgba(0, 240, 255, 0.3);
}

.results-board .rb-pos { width: 2em; color: var(--accent); font-weight: 700; }

/* Touch controls — side pads, road center clear */
.touch-controls {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(8px, var(--safe-l)) max(10px, calc(8px + var(--safe-b))) max(8px, var(--safe-r));
}

.touch-controls.hidden { display: none; }

.touch-col {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.touch-col.left { flex-direction: row; gap: 8px; }

.touch-btn {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  border: 1px solid rgba(0, 240, 255, 0.4);
  background: rgba(8, 12, 28, 0.55);
  color: var(--neon);
  font-size: 1.4rem;
  font-weight: 700;
  backdrop-filter: blur(3px);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.15);
}

.touch-btn:active,
.touch-btn.active {
  background: rgba(0, 240, 255, 0.28);
  color: #fff;
  box-shadow: 0 0 22px rgba(0, 240, 255, 0.45);
}

.touch-btn.boost {
  width: 64px;
  height: 44px;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: var(--neon2);
  border-color: rgba(255, 43, 214, 0.45);
}

.touch-btn.boost:active,
.touch-btn.boost.active {
  background: rgba(255, 43, 214, 0.3);
  color: #fff;
}

/* Show touch on coarse pointers / narrow screens */
@media (hover: none), (max-width: 700px) {
  .touch-controls:not(.hidden) { display: flex; }
}

@media (hover: hover) and (min-width: 701px) {
  .touch-controls { display: none !important; }
}

@media (max-width: 420px) {
  .touch-btn { width: 56px; height: 56px; font-size: 1.2rem; }
  .hud-value { font-size: 1.1rem; }
  .hud-value.accent { font-size: 1.4rem; }
  .panel { padding: 20px 16px; }
  .car-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Name entry */
.name-label {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--muted);
  text-transform: uppercase;
  margin: 8px 0 6px;
}

.name-input {
  width: 100%;
  max-width: 260px;
  padding: 12px 14px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  color: var(--text);
  background: rgba(0, 240, 255, 0.06);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 8px;
  outline: none;
  font-family: inherit;
}

.name-input:focus {
  border-color: var(--neon);
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.35);
}

.name-hint {
  margin-top: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

.btn.danger { color: #ff6b8a; border-color: rgba(255, 107, 138, 0.4); }
.btn.danger:hover { border-color: #ff6b8a; color: #ff9aaf; }

/* High scores list */
.scores-sub {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 12px;
  letter-spacing: 0.06em;
}

.scores-list {
  max-height: min(48vh, 360px);
  overflow-y: auto;
  text-align: left;
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 10px;
  background: rgba(8, 10, 24, 0.6);
}

.scores-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.score-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(122, 132, 153, 0.15);
  font-size: 0.85rem;
}

.score-row:last-child { border-bottom: none; }

.score-row.top3 .score-rank {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(255, 230, 0, 0.5);
}

.score-rank {
  font-weight: 800;
  color: var(--neon);
  font-variant-numeric: tabular-nums;
}

.score-name {
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.score-meta {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
  margin-top: 2px;
  text-transform: none;
}

.score-stats {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.score-time {
  font-weight: 700;
  color: var(--neon);
}

.score-extra {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 2px;
}
