/* BLAZE RUSH — Arcade Nitro Racing */
:root {
  --bg: #050510;
  --bg2: #0c0c1e;
  --neon: #ff2d6a;
  --neon2: #00e5ff;
  --neon3: #ffcc00;
  --text: #f2f4ff;
  --muted: #8b90b0;
  --panel: rgba(12, 12, 32, 0.88);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#app {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
.screen.active { display: flex; }
.screen.overlay {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
  z-index: 40;
}

/* Attract */
#screen-attract {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(ellipse at 50% 20%, #1a1040 0%, #050510 70%);
  overflow: hidden;
}
.attract-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, transparent 40%, rgba(255,45,106,0.15) 100%),
    repeating-linear-gradient(90deg, transparent, transparent 80px, rgba(0,229,255,0.04) 80px, rgba(0,229,255,0.04) 81px);
  animation: roadScroll 8s linear infinite;
  pointer-events: none;
}
@keyframes roadScroll {
  from { background-position: 0 0, 0 0; }
  to { background-position: 0 0, 0 400px; }
}
.attract-content { position: relative; z-index: 1; max-width: 420px; }
.eyebrow {
  letter-spacing: 0.35em;
  font-size: 0.7rem;
  color: var(--neon2);
  margin-bottom: 8px;
  font-weight: 600;
}
.logo {
  font-size: clamp(2.8rem, 12vw, 4.2rem);
  font-weight: 900;
  letter-spacing: -0.04em;
  line-height: 0.95;
  text-shadow: 0 0 40px rgba(255,45,106,0.55);
}
.logo span { color: var(--neon); display: block; }
.logo-sm {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -0.03em;
}
.logo-sm span { color: var(--neon); }
.tagline {
  margin: 14px 0 28px;
  color: var(--muted);
  font-size: 1rem;
}
.hint-keys {
  margin-top: 20px;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.8;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto 10px;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.12s;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--neon), #ff6b3d);
  color: #fff;
  box-shadow: 0 0 24px rgba(255,45,106,0.45);
}
.btn-accent {
  background: linear-gradient(135deg, #00b8d4, var(--neon2));
  color: #041018;
  box-shadow: 0 0 20px rgba(0,229,255,0.35);
}
.btn-ghost {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
}
.btn.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 20px rgba(255,45,106,0.4); }
  50% { box-shadow: 0 0 36px rgba(255,45,106,0.75); }
}
.icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  font-size: 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn.back { font-size: 1.3rem; }

/* Menu */
#screen-menu {
  background: linear-gradient(160deg, #0e0a24 0%, #050510 50%, #120818 100%);
  justify-content: space-between;
}
.menu-header { text-align: center; padding-top: 24px; }
.subtitle { color: var(--muted); font-size: 0.85rem; margin-top: 4px; letter-spacing: 0.15em; }
.menu-nav { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.menu-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
}
.fine { font-size: 0.7rem; color: var(--muted); }

/* Screen bar */
.screen-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.screen-bar h2 {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
  letter-spacing: 0.2em;
}
.spacer { width: 44px; }

/* Garage */
#screen-garage, #screen-rankings, #screen-howto, #screen-results {
  background: linear-gradient(180deg, #0c0c1e, #050510);
}
.garage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  overflow-y: auto;
}
.car-preview {
  width: 100%;
  max-width: 320px;
  background: radial-gradient(ellipse at 50% 70%, #1a2040 0%, #080814 70%);
  border-radius: 16px;
  border: 1px solid rgba(0,229,255,0.2);
  overflow: hidden;
}
#garage-canvas { width: 100%; height: auto; display: block; }
#garage-car-name {
  font-size: 1.4rem;
  letter-spacing: 0.05em;
  margin-top: 4px;
}
.car-desc { color: var(--muted); font-size: 0.85rem; text-align: center; max-width: 300px; }
.stat-bars { width: 100%; max-width: 280px; }
.stat-row {
  display: grid;
  grid-template-columns: 70px 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.stat-track {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  overflow: hidden;
}
.stat-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--neon2), var(--neon));
  border-radius: 4px;
  transition: width 0.3s;
}
.garage-nav {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  max-width: 320px;
}
.garage-nav .btn { margin: 0; }
.garage-nav .btn-ghost { max-width: 56px; padding: 14px; }
.lock-msg { color: var(--neon3); font-size: 0.8rem; min-height: 1.2em; text-align: center; }

/* Rankings */
.rankings-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.tab {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
  min-height: 44px;
}
.tab.active {
  background: rgba(0,229,255,0.15);
  color: var(--neon2);
  border-color: rgba(0,229,255,0.4);
}
.rank-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}
.rank-list li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.06);
}
.rank-list li.you {
  border-color: rgba(255,45,106,0.5);
  background: rgba(255,45,106,0.1);
}
.rank-list .pos { color: var(--neon3); font-weight: 800; }
.rank-list .name { font-weight: 600; }
.rank-list .pts { color: var(--neon2); font-variant-numeric: tabular-nums; }

/* Howto */
.howto-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}
.howto-card {
  display: flex;
  gap: 14px;
  padding: 14px;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.08);
}
.hc-icon { font-size: 1.6rem; line-height: 1; }
.howto-card strong { display: block; margin-bottom: 4px; letter-spacing: 0.05em; }
.howto-card p { color: var(--muted); font-size: 0.88rem; line-height: 1.4; }

/* Game */
#screen-game {
  padding: 0;
  background: #000;
}
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  display: flex;
  flex-direction: column;
}
.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.hud-score .lbl, .hud-timer .lbl {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--muted);
}
#hud-score {
  font-size: 1.6rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.hud-mode {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--neon2);
  background: rgba(0,0,0,0.35);
  padding: 6px 10px;
  border-radius: 8px;
  align-self: flex-start;
}
.hud-btn {
  pointer-events: auto;
  background: rgba(0,0,0,0.4);
}
.hud-mid {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 8px;
}
.hud-speed {
  font-size: 2.2rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 12px rgba(0,0,0,0.7);
  line-height: 1;
}
.hud-speed .unit {
  font-size: 0.75rem;
  color: var(--muted);
  margin-left: 4px;
  font-weight: 600;
}
#hud-timer {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.hud-nitro {
  margin-top: auto;
  margin-bottom: 88px;
  max-width: 220px;
}
.nitro-label {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  color: var(--neon);
  margin-bottom: 4px;
  font-weight: 700;
}
.nitro-bar {
  height: 12px;
  background: rgba(0,0,0,0.5);
  border-radius: 6px;
  border: 1px solid rgba(255,45,106,0.4);
  overflow: hidden;
}
.nitro-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff6b3d, var(--neon), #fff);
  box-shadow: 0 0 12px var(--neon);
  transition: width 0.08s linear;
}
.hud-feedback {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--neon3);
  text-shadow: 0 0 20px rgba(255,204,0,0.8);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.hud-feedback.show {
  animation: feedbackPop 0.7s ease-out forwards;
}
.hud-feedback.nitro-txt { color: var(--neon); }
.hud-feedback.near { color: var(--neon2); }
@keyframes feedbackPop {
  0% { opacity: 0; transform: translate(-50%, -40%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -70%) scale(1); }
}

/* Touch controls */
.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 120px;
  display: flex;
  z-index: 15;
  padding-bottom: var(--safe-b);
  pointer-events: none;
}
.touch-zone {
  flex: 1;
  height: 100%;
  border: none;
  background: transparent;
  pointer-events: auto;
  position: relative;
}
.touch-zone::after {
  content: "";
  position: absolute;
  bottom: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.25);
}
.touch-zone.left::after {
  left: 24px;
  content: "◀";
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  font-size: 1.2rem;
}
.touch-zone.right::after {
  right: 24px;
  left: auto;
  content: "▶";
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  font-size: 1.2rem;
}
.touch-zone:active::after {
  background: rgba(0,229,255,0.25);
  border-color: var(--neon2);
}
.touch-nitro {
  pointer-events: auto;
  align-self: flex-end;
  margin-bottom: 24px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 3px solid var(--neon);
  background: radial-gradient(circle at 40% 35%, #ff8a5c, #c01040);
  color: #fff;
  font-weight: 900;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  box-shadow: 0 0 20px rgba(255,45,106,0.5);
  flex-shrink: 0;
}
.touch-nitro:active, .touch-nitro.active {
  transform: scale(0.94);
  box-shadow: 0 0 36px rgba(255,45,106,0.9);
}
.touch-nitro sub { font-size: 0.65em; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px var(--neon);
  z-index: 20;
  background: rgba(0,0,0,0.35);
  pointer-events: none;
}
.countdown.hidden { display: none; }
.crash-flash {
  position: absolute;
  inset: 0;
  background: rgba(255,40,40,0.45);
  opacity: 0;
  pointer-events: none;
  z-index: 18;
  transition: opacity 0.15s;
}
.crash-flash.on { opacity: 1; }
.nitro-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  opacity: 0;
  box-shadow: inset 0 0 80px 30px rgba(255,45,106,0.35);
  transition: opacity 0.15s;
}
.nitro-vignette.on { opacity: 1; }

/* Pause / Results */
.panel, .results-panel {
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 28px 24px;
  width: min(340px, 92vw);
  text-align: center;
}
.panel h2, .results-panel h2 {
  margin-bottom: 20px;
  letter-spacing: 0.15em;
}
#results-score {
  font-size: 3rem;
  font-weight: 900;
  color: var(--neon2);
  text-shadow: 0 0 30px rgba(0,229,255,0.4);
  margin: 8px 0;
}
.results-sub { color: var(--muted); font-size: 0.8rem; margin-bottom: 16px; }
.results-stats {
  list-style: none;
  text-align: left;
  margin-bottom: 16px;
}
.results-stats li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.9rem;
}
.results-stats li span:last-child { color: var(--neon3); font-weight: 700; }
.unlock-toast {
  color: var(--neon);
  font-weight: 700;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.results-actions .btn { max-width: none; }

.hidden { display: none !important; }

@media (min-width: 768px) {
  .touch-controls { opacity: 0.55; }
  .touch-controls:hover { opacity: 1; }
  .hud-nitro { margin-bottom: 100px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .hud-nitro { margin-bottom: 72px; max-width: 160px; }
  .touch-controls { height: 90px; }
  .touch-nitro { width: 60px; height: 60px; margin-bottom: 12px; }
  .logo { font-size: 2.4rem; }
}
