:root {
  --bg: #070812;
  --panel: rgba(10, 12, 26, 0.78);
  --border: rgba(255, 255, 255, 0.16);
  --pink: #ff4fa3;
  --cyan: #38e8ff;
  --yellow: #ffd93d;
  --text: #f7f4ff;
  --muted: #b5b2d4;
}

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

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

#game-canvas,
#speed-lines {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#game-canvas {
  z-index: 1;
}

#speed-lines {
  z-index: 2;
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.overlay[hidden],
.hud[hidden] {
  display: none !important;
}

/* ---------- INTRO TOP-DOWN MAP OVERLAY ---------- */
.intro-overlay {
  background: radial-gradient(circle at 50% 45%, rgba(12, 16, 38, 0.25) 0%, rgba(6, 7, 16, 0.76) 100%);
  transition: opacity 0.55s ease;
}

.intro-overlay.fading {
  opacity: 0;
  pointer-events: none;
}

#intro-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.78;
}

.intro-card {
  position: relative;
  z-index: 2;
  width: min(560px, 100%);
  padding: 26px 26px 24px;
  border-radius: 26px;
  background: rgba(9, 11, 24, 0.84);
  border: 1px solid rgba(56, 232, 255, 0.35);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7), 0 0 42px rgba(255, 79, 163, 0.2);
  text-align: center;
  backdrop-filter: blur(8px);
}

.intro-kicker {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--cyan);
  text-transform: uppercase;
}

.intro-title {
  margin: 0 0 10px;
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.06;
  letter-spacing: -0.02em;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 22px rgba(255, 79, 163, 0.55);
}

.intro-title span {
  color: var(--pink);
  text-shadow: 0 0 24px rgba(255, 79, 163, 0.85), 0 0 10px rgba(56, 232, 255, 0.6);
}

.intro-sub {
  margin: 0 auto 16px;
  max-width: 44ch;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
}

.intro-route-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 20px;
}

.intro-route-pills span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(56, 232, 255, 0.25);
  color: #dff9ff;
}

.btn-primary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 28px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: transform 0.14s ease, box-shadow 0.14s ease, background 0.14s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), #ff79b9 55%, var(--yellow));
  color: #190714;
  box-shadow: 0 8px 28px rgba(255, 79, 163, 0.45);
}

.btn-play {
  min-width: 210px;
  min-height: 56px;
  font-size: 20px;
  letter-spacing: 0.12em;
}

.btn-primary:hover,
.btn-primary:focus-visible {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 34px rgba(255, 79, 163, 0.65);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: rgba(56, 232, 255, 0.16);
  border-color: var(--cyan);
  outline: none;
}

.intro-controls {
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.intro-controls b {
  color: var(--yellow);
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  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));
  transition: opacity 0.6s ease;
}

.hud.faded {
  opacity: 0;
}

.hud-left {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hud-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid rgba(255, 79, 163, 0.45);
  width: fit-content;
}

.hud-ring {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 5px solid var(--pink);
  box-shadow: 0 0 10px var(--pink), inset 0 0 4px var(--yellow);
}

.hud-brand {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: #fff;
}

.hud-brand em {
  font-style: normal;
  color: var(--cyan);
}

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

.hud-stat {
  min-width: 90px;
  padding: 7px 12px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.hud-stat small {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.hud-stat b {
  display: block;
  font-size: 20px;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.hud-stat b span {
  font-size: 11px;
  font-weight: 700;
  color: var(--cyan);
}

.hud-combo {
  border-color: rgba(255, 217, 61, 0.45);
}

.hud-combo b {
  color: var(--yellow);
}

.combo-bar {
  margin-top: 4px;
  height: 4px;
  width: 100%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.combo-bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--pink), var(--yellow));
  transition: width 0.08s linear;
}

.hud-right {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.hud-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.hud-icon-btn:hover,
.hud-icon-btn:focus-visible {
  border-color: var(--cyan);
  transform: scale(1.05);
  outline: none;
}

/* ---------- TRICK POP-UPS (BOTTOM CENTRE) ---------- */
.trick-pop {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  max-width: min(92vw, 380px);
}

.trick-item {
  padding: 7px 16px;
  border-radius: 999px;
  font-size: clamp(14px, 3vw, 20px);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(12, 14, 30, 0.86);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 22px rgba(56, 232, 255, 0.55);
  animation: trickPop 1.2s cubic-bezier(0.2, 0.9, 0.25, 1) forwards;
  white-space: nowrap;
}

.trick-item.pink {
  border-color: var(--pink);
  box-shadow: 0 0 22px rgba(255, 79, 163, 0.65);
}

.trick-item.gold {
  border-color: var(--yellow);
  color: var(--yellow);
  box-shadow: 0 0 26px rgba(255, 217, 61, 0.7);
}

@keyframes trickPop {
  0% { opacity: 0; transform: translateY(16px) scale(0.72); }
  16% { opacity: 1; transform: translateY(0) scale(1.08); }
  28% { transform: translateY(0) scale(1); }
  78% { opacity: 1; transform: translateY(-4px) scale(1); }
  100% { opacity: 0; transform: translateY(-20px) scale(0.92); }
}

/* ---------- MINIMAP (BOTTOM RIGHT) ---------- */
.minimap-wrap {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid rgba(56, 232, 255, 0.35);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

#minimap {
  width: 96px;
  height: 96px;
  border-radius: 10px;
  display: block;
}

.minimap-meta {
  text-align: center;
  line-height: 1.2;
}

.minimap-meta span {
  display: block;
  font-size: 11px;
  font-weight: 800;
  color: var(--cyan);
}

.minimap-meta small {
  font-size: 10px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- PAUSE MODAL ---------- */
.pause-overlay {
  background: rgba(5, 6, 14, 0.68);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(410px, 100%);
  padding: 24px 22px 18px;
  border-radius: 24px;
  background: rgba(11, 13, 28, 0.94);
  border: 1px solid rgba(56, 232, 255, 0.4);
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.65);
}

.modal-kicker {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--pink);
}

.modal-card h2 {
  margin: 0 0 14px;
  font-size: 25px;
}

.neon-ad-card {
  width: 100%;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 79, 163, 0.45);
  background: linear-gradient(135deg, rgba(255, 79, 163, 0.14), rgba(56, 232, 255, 0.12));
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: transform 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease;
}

.neon-ad-card:hover,
.neon-ad-card:focus-visible {
  transform: translateY(-1px);
  border-color: var(--cyan);
  box-shadow: 0 0 20px rgba(56, 232, 255, 0.28);
  outline: none;
}

.neon-ad-card > small {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--pink);
}

.neon-ad-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.neon-ad-row img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #fff;
  object-fit: contain;
  flex: none;
}

.neon-ad-row img[hidden] {
  display: none;
}

.neon-ad-text {
  flex: 1;
  min-width: 0;
}

.neon-ad-text b {
  display: block;
  font-size: 15px;
  line-height: 1.2;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.neon-ad-text span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.neon-ad-cta {
  flex: none;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(56, 232, 255, 0.18);
  border: 1px solid rgba(56, 232, 255, 0.45);
  color: #dff9ff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pause-ad-foot {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.pause-ad-foot a {
  color: var(--cyan);
  text-decoration: none;
}

.pause-ad-foot a:hover {
  text-decoration: underline;
}

.summary-ad-card {
  margin: 4px 0 0;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- SUMMARY BAR (FINISH & CRASH) ---------- */
.summary-overlay {
  align-items: flex-end;
  background: linear-gradient(to top, rgba(6, 7, 16, 0.88) 0%, rgba(6, 7, 16, 0.28) 48%, rgba(6, 7, 16, 0) 100%);
  pointer-events: auto;
}

.summary-bar {
  width: min(860px, 100%);
  padding: 18px 22px;
  border-radius: 22px;
  background: rgba(10, 12, 26, 0.92);
  border: 1px solid rgba(255, 79, 163, 0.5);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.72), 0 0 36px rgba(56, 232, 255, 0.22);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  backdrop-filter: blur(8px);
}

.summary-head {
  display: flex;
  align-items: center;
  gap: 14px;
}

.grade-badge {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 32px;
  font-weight: 900;
  color: #160712;
  background: linear-gradient(135deg, var(--yellow), var(--pink));
  box-shadow: 0 0 24px rgba(255, 217, 61, 0.55);
  flex: none;
}

.summary-kicker {
  margin: 0 0 2px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--cyan);
}

.summary-head h2 {
  margin: 0;
  font-size: clamp(20px, 3vw, 26px);
}

.summary-metrics {
  display: flex;
  gap: 18px;
}

.metric small {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.metric b {
  font-size: clamp(18px, 2.8vw, 24px);
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.summary-actions {
  display: flex;
  gap: 10px;
}

/* ---------- PORTRAIT & LANDSCAPE PHONE TUNING ---------- */
@media (max-width: 640px) {
  .hud-logo { padding: 4px 10px 4px 6px; }
  .hud-brand { font-size: 10px; }
  .hud-stat { min-width: 74px; padding: 5px 9px; }
  .hud-stat b { font-size: 16px; }
  #minimap { width: 72px; height: 72px; }
  .minimap-wrap { padding: 6px; }
  .minimap-meta span { font-size: 10px; }
  .trick-pop { bottom: max(112px, env(safe-area-inset-bottom)); }
  .summary-bar { padding: 16px; justify-content: center; text-align: center; }
  .summary-head { width: 100%; justify-content: center; text-align: left; }
  .summary-metrics { width: 100%; justify-content: space-around; }
  .summary-actions { width: 100%; justify-content: center; }
  .summary-actions > * { flex: 1; }
}

@media (max-height: 460px) and (orientation: landscape) {
  .intro-card { padding: 14px 18px; }
  .intro-sub { display: none; }
  .intro-route-pills { margin-bottom: 10px; }
  .btn-play { min-height: 44px; font-size: 17px; }
  .hud-logo { display: none; }
  .hud-stat { padding: 4px 8px; min-width: 68px; }
  .hud-stat b { font-size: 15px; }
  #minimap { width: 64px; height: 64px; }
  .summary-bar { padding: 12px 16px; gap: 10px; }
}
