:root {
  --background: 222 47% 96%;
  --foreground: 229 38% 12%;
  --primary: 280 91% 50%;
  --secondary: 194 89% 38%;
  --muted: 225 22% 88%;
  --destructive: 0 84% 56%;
  --border: 230 25% 82%;
  --card: 0 0% 100%;
  --shadow-sm: 0 8px 20px hsl(229 38% 12% / 0.08);
  --shadow-md: 0 18px 45px hsl(229 38% 12% / 0.13);
  --shadow-lg: 0 28px 80px hsl(229 38% 12% / 0.18);
  --transition-fast: 150ms ease;
  --transition-smooth: 260ms cubic-bezier(.2,.8,.2,1);
  --radius-sm: 0.65rem;
  --radius-md: 1rem;
  --radius-lg: 1.45rem;
}

.dark {
  --background: 229 43% 8%;
  --foreground: 222 38% 96%;
  --primary: 286 95% 64%;
  --secondary: 188 96% 46%;
  --muted: 228 22% 19%;
  --destructive: 0 78% 62%;
  --border: 229 24% 24%;
  --card: 228 36% 12%;
  --shadow-sm: 0 8px 20px hsl(0 0% 0% / 0.22);
  --shadow-md: 0 18px 45px hsl(0 0% 0% / 0.30);
  --shadow-lg: 0 28px 80px hsl(0 0% 0% / 0.42);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: hsl(var(--background));
}

body {
  min-height: 100%;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: hsl(var(--foreground));
  background:
    radial-gradient(circle at 15% 5%, hsl(var(--primary) / 0.18), transparent 28rem),
    radial-gradient(circle at 88% 18%, hsl(var(--secondary) / 0.16), transparent 24rem),
    hsl(var(--background));
}

button, a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
}

.bg-1 { background-color: hsl(var(--background)); }
.bg-2 { background-color: hsl(var(--card) / 0.88); }
.bg-3 { background-color: hsl(var(--muted) / 0.72); }
.bg-4 { background-color: hsl(var(--foreground) / 0.06); }
.text-primary { color: hsl(var(--foreground)); }
.text-secondary { color: hsl(var(--foreground) / 0.68); }
.text-tertiary { color: hsl(var(--foreground) / 0.48); }
.text-accent { color: hsl(var(--primary)); }

.safe-top {
  padding-top: env(safe-area-inset-top);
}

.safe-bottom {
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}

.focus-ring:focus-visible {
  outline: 3px solid hsl(var(--primary) / 0.42);
  outline-offset: 3px;
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: hsl(var(--muted) / 0.72);
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, hsl(var(--card) / 0.7), transparent);
  animation: shimmer 1.25s infinite;
}

@keyframes shimmer {
  100% { transform: translateX(100%); }
}

.game-stage {
  position: relative;
  height: min(62vh, 520px);
  min-height: 390px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid hsl(var(--border));
  background:
    linear-gradient(90deg, hsl(230 55% 9%), hsl(232 50% 13%) 42%, hsl(229 55% 8%)),
    hsl(229 55% 9%);
  box-shadow: inset 0 0 0 1px hsl(0 0% 100% / 0.05), inset 0 -28px 70px hsl(var(--primary) / 0.18);
}

.game-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(90deg, hsl(var(--secondary) / 0.14) 1px, transparent 1px),
    linear-gradient(0deg, hsl(var(--primary) / 0.13) 1px, transparent 1px);
  background-size: 44px 44px;
  animation: gridMove 1.1s linear infinite;
  opacity: 0.9;
}

@keyframes gridMove {
  from { background-position: 0 0, 0 0; }
  to { background-position: -44px 0, -44px 44px; }
}

.track-lane {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: repeating-linear-gradient(90deg, hsl(0 0% 100% / 0.25) 0 38px, transparent 38px 72px);
  z-index: 1;
  animation: laneSlide 520ms linear infinite;
}

@keyframes laneSlide {
  to { transform: translateX(-72px); }
}

.road-glow {
  position: absolute;
  width: 18rem;
  height: 18rem;
  border-radius: 999px;
  filter: blur(48px);
  opacity: 0.34;
  z-index: 0;
}

.road-glow.one {
  left: -6rem;
  bottom: -5rem;
  background: hsl(var(--primary));
}

.road-glow.two {
  right: -5rem;
  top: -5rem;
  background: hsl(var(--secondary));
}

.bike {
  position: absolute;
  left: 9%;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  font-size: 2.35rem;
  z-index: 8;
  filter: drop-shadow(0 0 18px hsl(var(--secondary) / 0.85));
  transition: top var(--transition-smooth), transform var(--transition-fast);
  transform: scaleX(-1);
}

.bike::after {
  content: "";
  position: absolute;
  left: -44px;
  width: 64px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, hsl(var(--secondary) / 0.85));
  z-index: -1;
}

.object-token {
  position: absolute;
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 1.9rem;
  z-index: 7;
  transition: top var(--transition-fast);
}

.object-token.bolt {
  background: hsl(var(--primary) / 0.16);
  box-shadow: 0 0 26px hsl(var(--primary) / 0.72);
}

.object-token.hazard {
  background: hsl(var(--destructive) / 0.16);
  box-shadow: 0 0 22px hsl(var(--destructive) / 0.42);
}

.stat-card {
  min-height: 78px;
  border-radius: var(--radius-md);
  background: hsl(var(--muted) / 0.58);
  border: 1px solid hsl(var(--border));
  padding: 0.8rem;
}

.stat-card span {
  display: block;
  color: hsl(var(--foreground) / 0.56);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card strong {
  display: block;
  margin-top: 0.35rem;
  color: hsl(var(--foreground));
  font-size: 1.4rem;
  line-height: 1;
}

.life-dot {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: hsl(var(--foreground) / 0.25);
  background: hsl(var(--muted) / 0.6);
  border: 1px solid hsl(var(--border));
  font-weight: 900;
  font-size: 1.25rem;
}

.life-dot.active {
  color: hsl(var(--destructive));
  background: hsl(var(--destructive) / 0.12);
  box-shadow: 0 0 20px hsl(var(--destructive) / 0.22);
}

@media (max-width: 420px) {
  .game-stage {
    min-height: 360px;
  }

  .bike {
    left: 7%;
    width: 52px;
    height: 52px;
  }

  .object-token {
    width: 46px;
    height: 46px;
  }
}
