/* WUSPER CAR — Motorsport Glassmorphism UI (Desktop + Mobile Multi-Touch Optimized) */
:root {
  --bg: #050816;
  --panel: rgba(12, 18, 36, 0.8);
  --border: rgba(148, 163, 184, 0.24);
  --cyan: #06b6d4;
  --sky: #38bdf8;
  --pink: #f43f5e;
  --amber: #f59e0b;
  --green: #22c55e;
  --text: #f8fafc;
  --muted: #94a3b8;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Noto Sans TC', 'PingFang TC', sans-serif;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

#game-canvas {
  position: fixed; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none;
}

.hidden { display: none !important; }

/* Speed lines radial overlay */
#speed-lines {
  position: fixed; inset: 0; pointer-events: none; opacity: 0;
  transition: opacity 0.15s ease;
  background: radial-gradient(circle at center, transparent 42%, rgba(56, 189, 248, 0.18) 84%, rgba(244, 63, 94, 0.28) 100%);
  box-shadow: inset 0 0 90px rgba(6, 182, 212, 0.35);
}

/* Active Drift Banner */
#drift-banner {
  position: fixed; top: 126px; left: 50%; transform: translateX(-50%);
  pointer-events: none; z-index: 35;
  background: rgba(245, 158, 11, 0.2);
  border: 1.5px solid #f59e0b;
  color: #fde047;
  padding: 5px 18px; border-radius: 999px;
  font-weight: 900; font-size: 16px; letter-spacing: 0.08em;
  box-shadow: 0 0 22px rgba(245, 158, 11, 0.35);
  backdrop-filter: blur(8px);
}

/* Floating toasts */
#toast-container {
  position: fixed; top: 76px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: none; z-index: 40;
}
.toast-msg {
  background: rgba(9, 13, 28, 0.88);
  border: 1.5px solid var(--sky);
  padding: 6px 16px; border-radius: 999px;
  font-weight: 800; font-size: 13.5px; letter-spacing: 0.04em;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  animation: toastPop 1.45s ease forwards;
  white-space: nowrap;
}
@keyframes toastPop {
  0% { opacity: 0; transform: translateY(12px) scale(0.9); }
  15% { opacity: 1; transform: translateY(0) scale(1); }
  80% { opacity: 1; transform: translateY(-6px) scale(1); }
  100% { opacity: 0; transform: translateY(-18px) scale(0.95); }
}

/* Main Menu / Garage Overlay — scrollable on mobile */
#menu-overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: linear-gradient(90deg, rgba(5, 8, 22, 0.84) 0%, rgba(5, 8, 22, 0.28) 52%, rgba(5, 8, 22, 0.82) 100%);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.top-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.brand-block h1 {
  margin: 0; font-size: 26px; font-weight: 900; letter-spacing: 0.08em;
  background: linear-gradient(90deg, #38bdf8, #f43f5e);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-block p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase; }

.top-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.coin-pill {
  background: rgba(245, 158, 11, 0.16); border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fde047; padding: 6px 13px; border-radius: 999px; font-weight: 800; font-size: 13.5px;
}
.icon-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; backdrop-filter: blur(12px); transition: 0.15s;
}
.icon-btn:hover { border-color: var(--sky); background: rgba(56, 189, 248, 0.16); }

.menu-grid {
  display: grid; grid-template-columns: 310px 1fr 310px; gap: 18px;
  align-items: center; flex: 1; margin: 14px 0;
}

.glass-panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 15px;
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.42);
}
.panel-title {
  font-size: 11.5px; font-weight: 800; letter-spacing: 0.12em;
  color: var(--sky); text-transform: uppercase; margin: 0 0 10px;
}

.mode-list { display: flex; flex-direction: column; gap: 7px; }
.mode-card {
  width: 100%; text-align: left; background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px;
  color: var(--text); cursor: pointer; transition: 0.15s;
}
.mode-card:hover { border-color: rgba(56, 189, 248, 0.55); }
.mode-card.active {
  border-color: var(--sky); background: rgba(6, 182, 212, 0.18);
  box-shadow: 0 0 18px rgba(6, 182, 212, 0.22);
}
.mode-top { display: flex; justify-content: space-between; font-weight: 700; font-size: 13.5px; }
.mode-best { color: #fde047; font-size: 12px; }
.mode-desc { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.theme-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 8px; }
.pill-btn {
  background: rgba(15, 23, 42, 0.7); border: 1px solid var(--border);
  color: var(--muted); padding: 7px 8px; border-radius: 9px;
  font-size: 12px; font-weight: 600; cursor: pointer; transition: 0.15s;
}
.pill-btn.active { border-color: var(--pink); color: #fff; background: rgba(244, 63, 94, 0.22); }

.car-list { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 11px; }
.car-card {
  text-align: left; background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border); border-radius: 11px; padding: 8px 10px;
  color: var(--text); cursor: pointer; transition: 0.15s;
}
.car-card.active { border-color: var(--sky); background: rgba(56, 189, 248, 0.18); }
.car-card.locked { opacity: 0.82; }
.car-name { font-weight: 800; font-size: 12.5px; }
.car-tag { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.car-badge { font-size: 11px; font-weight: 700; color: #fde047; margin-top: 5px; }

.stat-row { display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-bottom: 6px; }
.bar { height: 7px; background: rgba(148, 163, 184, 0.18); border-radius: 999px; overflow: hidden; }
.bar > div { height: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); border-radius: 999px; transition: width 0.25s; }

.unlock-btn {
  width: 100%; margin-top: 8px; padding: 9px; border-radius: 10px; border: none;
  background: linear-gradient(90deg, #f59e0b, #f97316); color: #0b1120;
  font-weight: 800; font-size: 13px; cursor: pointer;
}

.swatch-group { margin-top: 9px; }
.swatch-label { font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.swatches { display: flex; gap: 8px; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: transform 0.15s;
}
.swatch.active { border-color: #fff; transform: scale(1.16); box-shadow: 0 0 10px rgba(255, 255, 255, 0.5); }

.bottom-cta {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding-bottom: 6px;
}
#btn-play {
  padding: 14px 52px; border-radius: 999px; border: none;
  background: linear-gradient(90deg, #06b6d4, #3b82f6, #f43f5e);
  color: #fff; font-size: 18px; font-weight: 900; letter-spacing: 0.12em;
  cursor: pointer; box-shadow: 0 0 32px rgba(6, 182, 212, 0.48);
  transition: transform 0.15s, box-shadow 0.15s;
}
#btn-play:hover { transform: translateY(-2px) scale(1.03); box-shadow: 0 0 42px rgba(244, 63, 94, 0.55); }
.controls-hint { font-size: 11.5px; color: var(--muted); text-align: center; }

/* In-Game HUD */
#hud {
  position: fixed; inset: 0; pointer-events: none; z-index: 15;
  padding: max(12px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}
.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hud-metrics { display: flex; gap: 8px; flex-wrap: wrap; }
.hud-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px 12px; backdrop-filter: blur(10px);
  min-width: 82px;
}
.hud-label { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.hud-val { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
#hud-combo {
  display: inline-block; margin-left: 5px; padding: 2px 7px; border-radius: 999px;
  background: rgba(244, 63, 94, 0.26); color: #fb7185; font-size: 12px; font-weight: 900;
}

.shield-pips { display: flex; gap: 4px; margin-top: 4px; }
.shield-pip { width: 16px; height: 7px; border-radius: 4px; background: rgba(148, 163, 184, 0.2); }
.shield-pip.active { background: #22c55e; box-shadow: 0 0 8px rgba(34, 197, 94, 0.65); }

.hud-tools { display: flex; gap: 6px; pointer-events: auto; flex-wrap: wrap; justify-content: flex-end; }
.hud-btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  padding: 7px 10px; border-radius: 10px; font-size: 12px; font-weight: 700;
  cursor: pointer; backdrop-filter: blur(10px); touch-action: manipulation;
}
.hud-btn:hover, .hud-btn.active { border-color: var(--sky); background: rgba(56, 189, 248, 0.2); }

/* Mini Radar */
#radar-wrap {
  position: fixed;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 7px; backdrop-filter: blur(10px);
}
#radar-canvas { display: block; border-radius: 8px; background: rgba(2, 6, 23, 0.65); }

/* Digital Speedometer Cluster */
.speedo-cluster {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 13px 16px; width: 220px;
  backdrop-filter: blur(12px);
}
.speedo-top { display: flex; align-items: baseline; justify-content: space-between; }
#hud-speed { font-size: 44px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
#hud-unit { font-size: 11.5px; color: var(--muted); font-weight: 700; margin-left: 4px; }
#hud-gear {
  background: rgba(56, 189, 248, 0.2); border: 1px solid var(--sky);
  color: var(--sky); padding: 3px 9px; border-radius: 8px; font-weight: 900; font-size: 14px;
}
.gauge-label { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--muted); margin-top: 8px; letter-spacing: 0.08em; }
.gauge-track { height: 7px; background: rgba(148, 163, 184, 0.18); border-radius: 999px; overflow: hidden; margin-top: 3px; }
#hud-rpm-fill { height: 100%; width: 20%; background: linear-gradient(90deg, #22c55e, #f59e0b, #f43f5e); transition: width 0.06s; }
#hud-nitro-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #06b6d4, #38bdf8, #a855f7); transition: width 0.06s; }

/* Multi-Touch Controls Overlay (controlled cleanly by .touch-enabled on body) */
#touch-controls {
  position: fixed; inset: 0; pointer-events: none; z-index: 18;
  display: none;
  touch-action: none;
}
body.touch-enabled #touch-controls { display: block; }

.tc-left-pad {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex; gap: 12px;
  pointer-events: auto;
  touch-action: none;
  padding: 6px;
  border-radius: 22px;
  background: rgba(5, 8, 22, 0.26);
}
.tc-right-pad {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  pointer-events: auto;
  touch-action: none;
  padding: 6px;
  border-radius: 22px;
  background: rgba(5, 8, 22, 0.26);
}
.tc-btn {
  width: 72px; height: 72px; border-radius: 18px;
  background: rgba(15, 23, 42, 0.76);
  border: 2px solid rgba(148, 163, 184, 0.42);
  color: #fff; font-size: 20px; font-weight: 900;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1;
  backdrop-filter: blur(8px);
  touch-action: none;
  transition: transform 0.06s, background 0.06s, border-color 0.06s;
}
.tc-btn small { font-size: 9.5px; font-weight: 700; opacity: 0.78; margin-top: 2px; letter-spacing: 0.05em; }
.tc-btn.pressed {
  background: rgba(56, 189, 248, 0.45);
  border-color: var(--sky);
  transform: scale(0.93);
  box-shadow: 0 0 18px rgba(56, 189, 248, 0.5);
}
.tc-nitro { border-color: rgba(6, 182, 212, 0.75); color: var(--sky); }
.tc-nitro.pressed { background: rgba(6, 182, 212, 0.45); border-color: #67e8f9; }
.tc-drift { border-color: rgba(245, 158, 11, 0.75); color: var(--amber); }
.tc-drift.pressed { background: rgba(245, 158, 11, 0.42); border-color: #fde047; }
.tc-gas { border-color: rgba(34, 197, 94, 0.75); color: #4ade80; }
.tc-gas.pressed { background: rgba(34, 197, 94, 0.42); border-color: #86efac; }
.tc-brake { border-color: rgba(244, 63, 94, 0.75); color: #fb7185; }
.tc-brake.pressed { background: rgba(244, 63, 94, 0.42); border-color: #fda4af; }

/* When touch controls are active, position radar & speedo cleanly so nothing overlaps */
body.touch-enabled #radar-wrap {
  bottom: calc(116px + env(safe-area-inset-bottom));
  transform: scale(0.76);
  transform-origin: bottom left;
}
body.touch-enabled .speedo-cluster {
  bottom: calc(184px + env(safe-area-inset-bottom));
  width: 168px;
  padding: 9px 12px;
}
body.touch-enabled #hud-speed { font-size: 30px; }

/* Landscape mobile phones (short viewport height) */
@media (max-height: 500px) {
  body.touch-enabled #radar-wrap { display: none; }
  body.touch-enabled .speedo-cluster {
    left: 50%; right: auto; transform: translateX(-50%);
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 176px; padding: 7px 12px;
  }
  body.touch-enabled #hud-speed { font-size: 26px; }
  .tc-btn { width: 64px; height: 64px; font-size: 18px; }
}

/* Modals (Pause, Game Over, Records, Settings) */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(3, 7, 18, 0.76); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 460px; max-height: 88dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y;
  background: rgba(15, 23, 42, 0.95); border: 1px solid var(--border);
  border-radius: 20px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
}
.modal-card h2 { margin: 0 0 14px; font-size: 21px; font-weight: 900; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.btn-primary {
  padding: 12px; border-radius: 12px; border: none; font-weight: 800; font-size: 15px;
  background: linear-gradient(90deg, var(--cyan), #3b82f6); color: #fff; cursor: pointer;
}
.btn-secondary {
  padding: 11px; border-radius: 12px; border: 1px solid var(--border);
  background: rgba(30, 41, 59, 0.7); color: var(--text); font-weight: 700; font-size: 14px; cursor: pointer;
}

.go-score-big { font-size: 44px; font-weight: 900; color: var(--sky); line-height: 1.1; }
.go-newbest {
  display: inline-block; margin: 6px 0; padding: 3px 10px; border-radius: 999px;
  background: rgba(250, 204, 21, 0.22); color: #fde047; font-size: 12px; font-weight: 800;
}
.go-stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px;
}
.go-stat {
  background: rgba(30, 41, 59, 0.6); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; font-size: 12px; color: var(--muted);
}
.go-stat strong { display: block; font-size: 17px; color: var(--text); margin-top: 2px; }

.ach-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.ach-pill {
  background: rgba(34, 197, 94, 0.2); border: 1px solid var(--green);
  color: #86efac; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
}

/* Records & Settings */
.rec-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.rec-kpi { background: rgba(30, 41, 59, 0.6); border-radius: 10px; padding: 8px; text-align: center; }
.rec-kpi strong { display: block; font-size: 15px; color: var(--sky); }
.rec-kpi span { font-size: 10.5px; color: var(--muted); }
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.ach-card {
  display: flex; gap: 8px; align-items: center; padding: 8px;
  border-radius: 10px; border: 1px solid var(--border); background: rgba(15, 23, 42, 0.6); opacity: 0.48;
}
.ach-card.done { opacity: 1; border-color: rgba(34, 197, 94, 0.55); background: rgba(34, 197, 94, 0.12); }
.ach-icon { font-size: 20px; }
.ach-title { font-size: 12px; font-weight: 800; }
.ach-desc { font-size: 10.5px; color: var(--muted); }
.lb-row { display: flex; justify-content: space-between; padding: 7px 10px; border-bottom: 1px solid rgba(148, 163, 184, 0.12); font-size: 12.5px; }
.lb-empty { font-size: 12.5px; color: var(--muted); text-align: center; padding: 12px; }

.set-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid rgba(148, 163, 184, 0.12); font-size: 14px; }
.set-row select { background: #1e293b; color: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; }

/* Responsive Menu */
@media (max-width: 960px) {
  .menu-grid { grid-template-columns: 1fr; gap: 12px; }
  .menu-spacer { display: none; }
}
@media (max-width: 520px) {
  .hud-card { padding: 5px 9px; min-width: 68px; }
  .hud-val { font-size: 15px; }
  .hud-btn { padding: 6px 8px; font-size: 11px; }
  .rec-kpis { grid-template-columns: repeat(2, 1fr); }
}
