:root {
  --ink: #0a0814;
  --night: #141029;
  --night-2: #1f1940;
  --night-3: #2a2352;
  --edge: rgba(255, 255, 255, 0.12);
  --orange: #ff7a1a;
  --orange-hi: #ffa53d;
  --purple: #8b5cff;
  --blue: #2e6cf0;
  --cyan: #00c3f1;
  --money: #2bd576;
  --danger: #ff4d5e;
  --text: #f4f1ff;
  --text-soft: rgba(244, 241, 255, 0.68);
  --line: 3px;
  --radius: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: Montserrat, ui-sans-serif, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

/* Night sky + moon live behind the transparent WebGL canvas. */
body {
  background:
    /* Moon sits low and to the right, clear of the screen titles. */
    radial-gradient(circle at 85% 31%, #fff4d6 0 24px, rgba(255, 228, 170, 0.35) 26px, rgba(255, 190, 110, 0.12) 54px, transparent 100px),
    radial-gradient(1.6px 1.6px at 12% 22%, #fff 60%, transparent),
    radial-gradient(1.2px 1.2px at 28% 9%, #fff 60%, transparent),
    radial-gradient(1.4px 1.4px at 44% 26%, #fff 60%, transparent),
    radial-gradient(1.1px 1.1px at 58% 12%, #fff 60%, transparent),
    radial-gradient(1.5px 1.5px at 68% 32%, #fff 60%, transparent),
    radial-gradient(1.2px 1.2px at 92% 8%, #fff 60%, transparent),
    radial-gradient(1.3px 1.3px at 6% 40%, #fff 60%, transparent),
    radial-gradient(1.1px 1.1px at 36% 38%, #fff 60%, transparent),
    linear-gradient(180deg, #08081c 0%, #171236 42%, #33204f 72%, #2a1f48 100%);
}

#scene { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* ---------- floating nav bar ---------- */
.topbar {
  position: fixed; z-index: 5;
  top: calc(10px + var(--safe-t)); left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 10px 11px 16px;
  border-radius: 20px;
  background: rgba(20, 16, 41, 0.82);
  border: 1.5px solid var(--edge);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.brand { width: 70px; color: #fff; flex: none; }
.brand svg { display: block; width: 100%; height: auto; }
.steps { display: flex; gap: 4px; list-style: none; }
.steps li {
  font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
  padding: 9px 10px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.06); color: var(--text-soft);
  transition: background .3s, color .3s, box-shadow .3s;
}
.steps li.on { background: var(--orange); color: var(--ink); box-shadow: 0 0 18px rgba(255, 122, 26, 0.55); }
.steps li.done { background: rgba(139, 92, 255, 0.32); color: #fff; }
.steps li.done::before { content: "✓ "; }
body[data-screen="play"] .topbar,
body[data-screen="over"] .topbar { opacity: 0; transform: translateY(-24px); }

/* ---------- sound toggle ---------- */
.sound-btn {
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  color: #fff; background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2);
  pointer-events: auto;
}
.sound-btn svg { width: 18px; height: 18px; }
.sound-btn .ico-off, .sound-btn.muted .ico-on { display: none; }
.sound-btn.muted .ico-off { display: block; }
.sound-btn.muted { color: var(--text-soft); }
.topbar .sound-btn { margin-left: auto; }
.topbar { gap: 8px; }
.sound-btn.play {
  position: absolute; left: 16px; bottom: calc(18px + var(--safe-b));
  width: 42px; height: 42px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  background: rgba(20, 16, 41, .55);
}

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 4;
  pointer-events: none;
  opacity: 0; visibility: hidden;
  transition: opacity .35s ease, visibility 0s linear .35s;
}
.screen.active { opacity: 1; visibility: visible; transition: opacity .35s ease; }
.screen.active > * { pointer-events: auto; }
.screen.active > .head, .screen.active > #pops, .screen.active > .countdown, .screen.active > .howto { pointer-events: none; }

.head {
  position: absolute; left: 0; right: 0; top: calc(88px + var(--safe-t));
  text-align: center; padding: 0 16px;
}
.eyebrow {
  display: inline-block;
  font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase;
  color: #fff; background: var(--purple); padding: 5px 12px; border-radius: 99px;
  border: 2px solid var(--ink);
}
.eyebrow.danger { background: var(--danger); }
h1 {
  margin-top: 10px;
  font-size: clamp(30px, 9vw, 48px); font-weight: 900; line-height: 1; letter-spacing: -.02em;
  color: var(--orange-hi);
  text-shadow:
    0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink),
    2px 3px 0 var(--ink), -2px 3px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink),
    0 7px 0 var(--ink), 0 0 34px rgba(255, 122, 26, 0.55);
}
.sub {
  display: inline-block; margin-top: 12px; padding: 6px 14px; border-radius: 99px;
  font-size: 14px; font-weight: 700; color: var(--text);
  background: rgba(20, 16, 41, 0.8); border: 1.5px solid var(--edge);
}
.sub b { color: var(--money); }

.screen .head { transform: translateY(-12px); transition: transform .45s cubic-bezier(.2, 1.4, .4, 1); }
.screen.active .head { transform: none; }

/* ---------- Stic or Treat lockup ---------- */
.game-logo {
  display: block; width: min(214px, 57vw); height: auto; aspect-ratio: 1100 / 552; margin: 0 auto;
  filter: drop-shadow(0 0 18px rgba(255, 122, 26, .45));
}
.game-logo + .sub { margin-top: 10px; }
.game-logo.small { width: 170px; margin-bottom: 2px; }
#s-garage .sub b { color: var(--orange-hi); }

/* ---------- garage labels ---------- */
#labels { position: absolute; inset: 0; pointer-events: none !important; }
.car-label {
  position: absolute; left: 0; top: 0;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 99px;
  background: var(--night-2); color: var(--text);
  border: 2px solid var(--edge); box-shadow: 0 4px 0 var(--ink);
  font-size: 13px; font-weight: 800; white-space: nowrap;
  pointer-events: auto;
  will-change: transform;
}
.car-label:active { box-shadow: 0 1px 0 var(--ink); margin-top: 3px; }
.car-label i {
  font-style: normal; font-size: 10px; font-weight: 900; letter-spacing: .08em;
  color: var(--ink); padding: 3px 7px; border-radius: 99px;
  background: linear-gradient(135deg, var(--orange-hi), var(--orange));
}

/* ---------- sticker step ---------- */
.target {
  position: absolute; left: 0; top: 0;
  border: 3px dashed var(--orange-hi); border-radius: 10px;
  background: rgba(255, 122, 26, 0.2);
  box-shadow: 0 0 18px rgba(255, 122, 26, 0.45);
  display: grid; place-items: center;
  pointer-events: none !important;
  animation: pulse 1.2s ease-in-out infinite;
  transition: background .15s, border-color .15s, opacity .2s;
  will-change: transform;
}
.target span {
  font-size: 9px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; white-space: nowrap;
  color: #fff; text-shadow: 0 1px 0 var(--ink);
}
.target.hot { background: rgba(43, 213, 118, .45); border-color: var(--money); box-shadow: 0 0 22px rgba(43, 213, 118, .6); animation: none; }
.target.done { opacity: 0; animation: none; }
@keyframes pulse { 50% { background: rgba(255, 122, 26, 0.4); } }

.tray {
  width: 100%;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 12px; border-radius: 26px;
  background: var(--night); border: 1.5px solid var(--edge); box-shadow: 0 6px 0 var(--ink), 0 18px 40px rgba(0, 0, 0, .45);
}
/* Bottom stack on the sticker screen: glass "Change car" pill above the tray. */
.sticker-bottom {
  position: absolute; left: 50%; bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.btn-glass {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 18px 0 14px; border-radius: 99px;
  font-size: 14px; font-weight: 800; color: #fff;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 8px 24px rgba(0, 0, 0, .35);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  transition: background .15s, transform .1s;
}
.btn-glass svg { width: 18px; height: 18px; }
/* Sits just under the car; main.js keeps it pinned below the car's wheels. */
#btn-change { position: absolute; left: 50%; top: 0; transform: translate(-50%, -200px); will-change: transform; }
.btn-glass:active { transform: scale(.96); background: rgba(255, 255, 255, .2); }

.sticker-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 8px 8px; border-radius: 16px;
  background: var(--night-2);
  touch-action: none; cursor: grab;
  will-change: transform;
}
.sticker-card img { width: 100%; max-width: 150px; aspect-ratio: 4 / 3; display: block; filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .45)); pointer-events: none; }
.sticker-card span { font-size: 11px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; color: var(--text-soft); }
.sticker-card.dragging { z-index: 10; cursor: grabbing; background: transparent; }
.sticker-card.dragging img { filter: drop-shadow(0 14px 12px rgba(0, 0, 0, .55)); }
.sticker-card.dragging span { opacity: 0; }
.sticker-card.used { pointer-events: none; }
.sticker-card.used img { opacity: .18; filter: grayscale(1); }
.sticker-card.used::after {
  content: "✓"; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -62%);
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--money); color: var(--ink); font-weight: 900; font-size: 20px;
  border: var(--line) solid var(--ink);
  animation: popin .35s cubic-bezier(.3, 1.6, .5, 1);
}
@keyframes popin { from { transform: translate(-50%, -62%) scale(0); } }

#hand {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  pointer-events: none !important; opacity: 0;
}
#hand.on { opacity: 1; }
#hand .mover { position: absolute; left: 0; top: 0; width: 0; height: 0; will-change: transform; }
#hand .ghost {
  position: absolute; left: 0; top: 0; aspect-ratio: 4 / 3; border-radius: 8px;
  transform-origin: 50% 50%; filter: drop-shadow(0 10px 10px rgba(0, 0, 0, .45)); will-change: transform, opacity;
}
#hand .hand-icon { position: absolute; width: 56px; height: 56px; left: -6px; top: -20px; will-change: opacity; }
#hand .hand-icon svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .4)); }
.finger {
  position: absolute; left: -6px; top: 4px; width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255, 255, 255, .92); border: var(--line) solid var(--ink);
  box-shadow: 0 0 0 8px rgba(255, 165, 61, .35);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 52px; padding: 0 28px; border-radius: 99px;
  font-weight: 900; font-size: 16px; letter-spacing: .04em; text-transform: uppercase;
  border: var(--line) solid var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn-primary {
  background: linear-gradient(180deg, var(--orange-hi), var(--orange)); color: var(--ink);
  box-shadow: 0 6px 0 var(--ink), 0 0 30px rgba(255, 122, 26, .45);
}
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink), 0 0 20px rgba(255, 122, 26, .4); }
.btn-ghost { background: var(--night-2); color: var(--text); border-color: var(--edge); box-shadow: 0 4px 0 var(--ink); }
.btn-ghost:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- HUD: no box, the top of the game view is blurred and darkened ---------- */
.hud {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(18px + var(--safe-t)) 14px 44px;
  pointer-events: none !important;
}
.hud-blur {
  position: absolute; inset: 0;
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  backdrop-filter: blur(10px) saturate(1.2);
  background: linear-gradient(180deg, rgba(8, 6, 20, .8) 0%, rgba(8, 6, 20, .5) 55%, rgba(8, 6, 20, 0) 100%);
  -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 55%, transparent 100%);
}
/* Distance hugs the left edge, Rate the right; Earnings sits in a glass pill in the middle
   whose width eases out whenever the number gets a digit longer (set from main.js). */
.hud-row {
  position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  max-width: 560px; margin: 0 auto;
}
.hud-row > div { display: flex; flex-direction: column; gap: 3px; }
.hud-stat { align-items: flex-start; text-align: left; }
.hud-stat.end { align-items: flex-end; text-align: right; }
.hud-money {
  align-items: center; text-align: center;
  min-width: 128px; padding: 9px 20px 10px; border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .14), rgba(255, 255, 255, .05));
  border: 1px solid rgba(255, 255, 255, .2);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25), 0 12px 30px rgba(0, 0, 0, .35);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  backdrop-filter: blur(12px) saturate(1.3);
  transition: width .5s cubic-bezier(.2, .9, .3, 1.15);
  overflow: hidden;
}
.hud .lbl {
  display: block; line-height: 14px;
  font-size: 10px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--text-soft);
}
#money {
  display: inline-block; white-space: nowrap;
  font-size: clamp(28px, 8.6vw, 36px); font-weight: 900; line-height: 40px; letter-spacing: -.02em;
  color: var(--money); font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55), 0 0 22px rgba(43, 213, 118, .5);
}
.hud-money.bump #money { animation: bump .3s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes bump { 40% { transform: scale(1.12); } }
.hud-stat b {
  display: block; line-height: 26px;
  font-size: 17px; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .5);
}
.hud-stat b span { color: var(--orange-hi); }

#pops { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, 0);
  font-weight: 900; font-size: 18px; color: var(--money);
  text-shadow: 0 2px 0 var(--ink), 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 -1px 0 var(--ink);
  animation: floatup 1s ease-out forwards;
}
.pop.mile { font-size: 16px; animation-name: floatdown; }
@keyframes floatdown {
  0% { opacity: 0; transform: translate(-50%, -6px) scale(.7); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, 22px) scale(1); }
}
.pop.logo { font-size: 24px; color: #7fe0ff; text-shadow: 0 2px 0 var(--ink), 1px 0 0 var(--ink), -1px 0 0 var(--ink), 0 0 16px rgba(0, 195, 241, .8); }
@keyframes floatup {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.6); }
  20% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -44px) scale(1); }
}

.howto {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9);
  width: min(300px, calc(100% - 32px));
  padding: 16px 18px; border-radius: var(--radius);
  background: rgba(20, 16, 41, .94); border: 1.5px solid var(--edge); box-shadow: 0 6px 0 var(--ink);
  text-align: center; opacity: 0; transition: opacity .3s, transform .3s;
}
.howto.on { opacity: 1; transform: translate(-50%, -50%); }
.howto p { font-size: 14px; font-weight: 700; color: var(--text-soft); }
.howto p + p { margin-top: 4px; }
.howto p b { color: var(--text); }
.howto .logo-hint b { color: #7fe0ff; }
.swipe { position: relative; height: 44px; margin-bottom: 8px; }
.swipe .finger { left: calc(50% - 15px); top: 6px; animation: swipe 1.4s ease-in-out infinite; }
.swipe::before {
  content: ""; position: absolute; left: 22%; right: 22%; top: 20px; height: 4px; border-radius: 4px;
  background: repeating-linear-gradient(90deg, var(--orange) 0 10px, transparent 10px 18px);
}
@keyframes swipe { 0%, 100% { transform: translateX(-60px); } 50% { transform: translateX(60px); } }

.countdown {
  position: absolute; left: 0; right: 0; top: 22%; text-align: center;
  font-size: 96px; font-weight: 900; color: var(--orange-hi); opacity: 0;
  text-shadow: 0 5px 0 var(--ink), 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 -3px 0 var(--ink), 3px 5px 0 var(--ink), -3px 5px 0 var(--ink), 0 9px 0 var(--ink), 0 0 40px rgba(255, 122, 26, .6);
}
.countdown.tick { animation: tick .6s cubic-bezier(.3, 1.6, .5, 1) forwards; }
@keyframes tick {
  0% { opacity: 0; transform: scale(.3); }
  30% { opacity: 1; transform: scale(1.1); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.3); }
}

/* ---------- game over ---------- */
#s-over { display: grid; place-items: center; background: rgba(5, 4, 12, .55); }
.card {
  width: min(340px, calc(100% - 32px));
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
  padding: 22px 20px 18px; border-radius: 28px; text-align: center;
  background: var(--night); border: 1.5px solid var(--edge); box-shadow: 0 8px 0 var(--ink), 0 24px 60px rgba(0, 0, 0, .5);
  transform: scale(.85) translateY(20px); transition: transform .4s cubic-bezier(.3, 1.5, .5, 1);
}
#s-over.active .card { transform: none; }
.card .eyebrow { align-self: center; }
.card-title { font-size: 15px; font-weight: 800; color: var(--text-soft); margin-top: 4px; }
.big-money {
  align-self: center; font-size: 52px; font-weight: 900; line-height: 1; color: var(--money);
  background: var(--ink); padding: 10px 22px 12px; border-radius: 20px; font-variant-numeric: tabular-nums;
  border: 2px solid rgba(43, 213, 118, .35); text-shadow: 0 0 22px rgba(43, 213, 118, .45);
}
.new-best { font-size: 13px; font-weight: 900; color: var(--orange-hi); letter-spacing: .08em; text-transform: uppercase; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 6px; }
.stats div { background: var(--night-2); border-radius: 14px; padding: 10px 6px; display: flex; flex-direction: column; gap: 2px; }
.stats span { font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--text-soft); }
.stats b { font-size: 18px; font-weight: 900; }
.btn-earn { gap: 0; padding: 0 16px; white-space: nowrap; font-size: 15px; letter-spacing: .02em; text-decoration: none; }
.btn-earn .mark { display: inline-flex; width: 1.15em; height: 1.15em; margin: 0 .3em 0 .35em; }
.btn-earn .mark svg { width: 100%; height: 100%; }
.link-btn {
  align-self: center; margin-top: 2px; padding: 6px 10px;
  font-size: 13px; font-weight: 800; color: var(--text-soft);
  text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- fx ---------- */
#flash { position: fixed; inset: 0; z-index: 8; background: #ff7a1a; opacity: 0; pointer-events: none; mix-blend-mode: screen; }
.confetti {
  position: fixed; z-index: 9; width: 9px; height: 13px; border-radius: 2px; pointer-events: none;
  border: 1.5px solid var(--ink);
  animation: confetti .85s cubic-bezier(.2, .7, .3, 1) forwards;
}
@keyframes confetti {
  from { transform: translate(-50%, -50%); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 40px)) rotate(var(--r)); opacity: 0; }
}

#boot { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: #120f2a; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 5px solid rgba(255, 255, 255, .15); border-top-color: var(--orange); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 900px) {
  .topbar { left: 50%; right: auto; width: min(760px, calc(100% - 24px)); transform: translateX(-50%); }
  body[data-screen="play"] .topbar, body[data-screen="over"] .topbar { transform: translate(-50%, -24px); }
  .brand { width: 86px; }
  .head { top: calc(94px + var(--safe-t)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
