/* Turbo Drift '89 — 1989 Synthwave Arcade UI & Responsive Layout */
:root {
  --bg-deep: #09071a;
  --bg-panel: rgba(15, 12, 36, 0.9);
  --bg-card: rgba(25, 19, 56, 0.88);
  --border-neon: rgba(244, 63, 158, 0.45);
  --border-cyan: rgba(34, 211, 238, 0.45);
  --pink: #ff2e93;
  --cyan: #22d3ee;
  --gold: #fbbf24;
  --violet: #a855f7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: 'Trebuchet MS', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stage-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: #0d0a24;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Top In-Race HUD */
.hud-bar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.hud-bar.hidden {
  display: none;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  pointer-events: auto;
}

.hud-pill {
  background: rgba(11, 9, 28, 0.84);
  border: 1px solid rgba(56, 189, 248, 0.42);
  border-radius: 10px;
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 62px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
}

.hud-pill.pink { border-color: rgba(255, 46, 147, 0.55); }
.hud-pill.gold { border-color: rgba(251, 191, 36, 0.6); }

.hud-lbl {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  line-height: 1;
}

.hud-val {
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.03em;
  color: #fff;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

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

/* Nitro Gauge Pill */
.nitro-pill {
  background: rgba(11, 9, 28, 0.86);
  border: 1px solid rgba(34, 211, 238, 0.5);
  border-radius: 10px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 146px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.nitro-icon {
  width: 18px;
  height: 24px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.nitro-track-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nitro-top-row {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--cyan);
}

.nitro-bar-bg {
  width: 100%;
  height: 9px;
  border-radius: 99px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.35);
  overflow: hidden;
}

.nitro-bar-fill {
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, #06b6d4, #38bdf8, #fbbf24);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.8);
  transition: width 0.06s linear;
}

.hud-icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(11, 9, 28, 0.86);
  color: #f8fafc;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.hud-icon-btn:hover {
  border-color: var(--cyan);
  background: rgba(30, 27, 75, 0.95);
  transform: translateY(-1px);
}

/* Live Drift Chain Floating Banner */
.drift-banner {
  position: absolute;
  top: 72px;
  left: 50%;
  transform: translateX(-50%) scale(0.92);
  z-index: 19;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 46, 147, 0.9), rgba(124, 58, 237, 0.92));
  border: 2px solid #fde047;
  border-radius: 999px;
  padding: 5px 16px;
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
  box-shadow: 0 0 22px rgba(255, 46, 147, 0.65);
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s;
  white-space: nowrap;
}

.drift-banner.active {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* Countdown Center Overlay */
.countdown-pop {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

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

.countdown-text {
  font-size: clamp(54px, 12vw, 108px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  color: #fef08a;
  text-shadow: 0 0 26px #ff2e93, 0 5px 0 #1e1038;
  animation: popScale 0.45s cubic-bezier(0.22, 1.25, 0.36, 1);
}

@keyframes popScale {
  0% { transform: scale(1.65); opacity: 0.2; }
  100% { transform: scale(1); opacity: 1; }
}

/* Mobile Touch Controls */
.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  z-index: 24;
  display: none;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 12px;
  pointer-events: none;
}

.touch-controls.visible {
  display: flex;
}

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

.touch-btn {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  border: 2px solid rgba(56, 189, 248, 0.6);
  background: rgba(15, 12, 36, 0.72);
  color: #f8fafc;
  font-size: 22px;
  font-weight: 900;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  touch-action: none;
}

.touch-btn span {
  font-size: 10px;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.touch-btn.drift-btn {
  width: 72px;
  border-color: rgba(255, 46, 147, 0.78);
  background: rgba(88, 12, 58, 0.75);
}

.touch-btn.nitro-btn {
  width: 72px;
  border-color: rgba(251, 191, 36, 0.85);
  background: rgba(12, 62, 88, 0.78);
}

.touch-btn.pressed {
  transform: scale(0.93);
  filter: brightness(1.3);
}

/* Fixed Modal Overlays (Menu, Post-Race, Garage, Leaderboard) */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  padding-bottom: max(54px, calc(48px + var(--safe-bottom)));
  background: rgba(6, 4, 18, 0.68);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  overflow-y: auto;
}

.overlay.hidden {
  display: none;
}

.card {
  width: 100%;
  max-width: 680px;
  max-height: calc(100dvh - 76px);
  overflow-y: auto;
  background: linear-gradient(165deg, rgba(21, 14, 48, 0.96), rgba(10, 9, 28, 0.97));
  border: 1.5px solid var(--border-neon);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.72), 0 0 28px rgba(255, 46, 147, 0.22);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.title-hero {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(56, 189, 248, 0.45);
  min-height: 118px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px 14px;
  background: #140b2e url('assets/title_bg.jpg') center/cover no-repeat;
}

.title-hero::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 6, 28, 0.18) 0%, rgba(10, 6, 28, 0.84) 100%);
  pointer-events: none;
}

.title-hero > * {
  position: relative;
  z-index: 2;
}

.game-logo {
  margin: 0;
  font-size: clamp(26px, 6vw, 38px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 0.04em;
  line-height: 1.02;
  background: linear-gradient(180deg, #fff7ed 0%, #fde047 45%, #ff2e93 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #1e1038);
}

.game-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: #cbd5e1;
  font-weight: 600;
}

.top-meta-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 11px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(148, 163, 184, 0.22);
  font-size: 12px;
}

.meta-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 11.5px;
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(148, 163, 184, 0.28);
}

.meta-chip.gold { color: var(--gold); border-color: rgba(251, 191, 36, 0.48); }
.meta-chip.cyan { color: var(--cyan); border-color: rgba(34, 211, 238, 0.48); }
.meta-chip.pink { color: #f9a8d4; border-color: rgba(255, 46, 147, 0.48); }

/* Challenge Banner */
.challenge-banner {
  padding: 9px 12px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.16), rgba(255, 46, 147, 0.18));
  border: 1px solid rgba(251, 191, 36, 0.65);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  color: #fef08a;
}

.challenge-banner.hidden { display: none; }

/* Mode Tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.mode-tab {
  border: 1px solid rgba(148, 163, 184, 0.3);
  background: rgba(20, 18, 48, 0.85);
  color: #cbd5e1;
  border-radius: 11px;
  padding: 8px 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.14s, background 0.14s, transform 0.12s;
}

.mode-tab small {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
}

.mode-tab.active {
  background: linear-gradient(135deg, rgba(255, 46, 147, 0.28), rgba(56, 189, 248, 0.24));
  border-color: var(--cyan);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.28);
}

/* Track Grid (2 Cups × 4 Tracks) */
.cup-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--cyan);
  margin: 2px 0 -4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.track-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.track-btn {
  text-align: left;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: rgba(17, 15, 42, 0.88);
  border-radius: 11px;
  padding: 8px 10px;
  color: #f8fafc;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.14s, transform 0.12s, background 0.14s;
}

.track-btn:hover {
  border-color: rgba(255, 46, 147, 0.65);
  transform: translateY(-1px);
}

.track-btn.selected {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.16), rgba(255, 46, 147, 0.16));
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.24);
}

.track-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.track-name {
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-medal {
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
}

.track-meta {
  font-size: 10.5px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

/* Daily Trial Panel */
.daily-box {
  padding: 12px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(34, 211, 238, 0.14));
  border: 1px solid rgba(168, 85, 247, 0.55);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.daily-box.hidden { display: none; }

.daily-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.daily-tag {
  font-size: 10.5px;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.2);
  color: var(--gold);
  border: 1px solid rgba(251, 191, 36, 0.5);
}

/* Action Buttons */
.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  font-family: inherit;
  border-radius: 11px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(30, 41, 59, 0.9);
  color: #f8fafc;
  font-weight: 800;
  font-size: 13.5px;
  padding: 10px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1 1 auto;
  transition: transform 0.12s, filter 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #ff2e93, #f97316);
  border-color: #fde047;
  color: #ffffff;
  font-size: 15px;
  letter-spacing: 0.03em;
  box-shadow: 0 6px 20px rgba(255, 46, 147, 0.42);
}

.btn-cyan {
  background: linear-gradient(135deg, #0284c7, #22d3ee);
  border-color: #7dd3fc;
  color: #061322;
}

.btn-gold {
  background: linear-gradient(135deg, #d97706, #fbbf24);
  border-color: #fef08a;
  color: #1c1005;
}

.controls-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* Post-Race Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
}

.stat-box {
  background: rgba(15, 23, 42, 0.84);
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}

.stat-box .s-lbl {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
}

.stat-box .s-val {
  font-size: 16px;
  font-weight: 900;
  margin-top: 2px;
  color: #fff;
}

.cliffhanger-bar {
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.4);
  font-size: 12px;
  color: #bae6fd;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Garage Modal */
.garage-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.car-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.car-card {
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.car-card.equipped {
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(251, 191, 36, 0.24);
}

.car-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.car-preview-canvas {
  width: 44px;
  height: 62px;
  border-radius: 8px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.22), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(148, 163, 184, 0.25);
  image-rendering: pixelated;
  flex-shrink: 0;
}

.car-stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  color: #cbd5e1;
}

.car-stat-bar {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: rgba(30, 41, 59, 0.95);
  overflow: hidden;
}

.car-stat-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--pink), var(--cyan));
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upgrade-row {
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 11px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pips {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.pip {
  width: 16px;
  height: 6px;
  border-radius: 99px;
  background: rgba(51, 65, 85, 0.9);
}

.pip.on {
  background: linear-gradient(90deg, var(--cyan), var(--gold));
}

/* Daily Leaderboard Table */
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 220px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid rgba(148, 163, 184, 0.18);
  font-size: 12.5px;
}

.lb-submit-row {
  display: flex;
  gap: 7px;
  align-items: center;
}

.lb-input {
  flex: 1;
  min-width: 0;
  border-radius: 9px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(10, 12, 30, 0.92);
  color: #fff;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
}

.share-preview {
  background: rgba(8, 11, 26, 0.92);
  border: 1px dashed rgba(34, 211, 238, 0.5);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
  color: #e2e8f0;
}

.share-preview.hidden { display: none; }

/* Docked Studio Footer Bar */
footer.footer-bar {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 4px 12px;
  padding-bottom: max(4px, var(--safe-bottom));
  background: #080614;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: #94a3b8;
  z-index: 30;
}

@media (max-width: 640px) {
  .hud-bar {
    top: 6px;
    left: 6px;
    right: 6px;
    gap: 5px;
  }
  .hud-pill {
    padding: 4px 7px;
    min-width: 50px;
  }
  .hud-val {
    font-size: 13.5px;
  }
  .nitro-pill {
    min-width: 114px;
    padding: 4px 7px;
  }
  .card {
    padding: 13px;
    gap: 9px;
  }
  .track-grid {
    grid-template-columns: 1fr;
  }
  .car-list {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .touch-btn {
    width: 58px;
    height: 58px;
  }
  .touch-btn.drift-btn, .touch-btn.nitro-btn {
    width: 64px;
  }
}
