:root {
  --blue: #1596e8;
  --red: #e8202a;
  --gold: #f5c451;
  --ink: #08080a;
  --size: min(88vw, 52vh);
  --size: min(88vw, 52dvh);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: #fff;
  font-family: "Helvetica Neue", Arial, system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100vh;
  height: 100dvh;
  padding: max(env(safe-area-inset-top), 8px) 16px max(env(safe-area-inset-bottom), 14px);
  position: relative;
}

/* ---------- Background ---------- */
.bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    radial-gradient(55% 38% at 12% 18%, rgba(21, 150, 232, 0.32), transparent 70%),
    radial-gradient(55% 38% at 88% 82%, rgba(232, 32, 42, 0.3), transparent 70%),
    radial-gradient(90% 60% at 50% 48%, #1a1c22 0%, #08080a 72%);
}

.grid-floor {
  position: fixed;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 42%;
  z-index: -2;
  overflow: hidden;
  transform: perspective(380px) rotateX(62deg);
  transform-origin: 50% 100%;
  opacity: 0.45;
}
.grid-floor::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -38px;
  bottom: 0;
  background:
    linear-gradient(rgba(21, 150, 232, 0.35) 1px, transparent 1px) 0 0 / 100% 38px,
    linear-gradient(90deg, rgba(21, 150, 232, 0.35) 1px, transparent 1px) 0 0 / 60px 100%;
  will-change: transform;
  animation: floor 2.4s linear infinite;
}
.grid-floor::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, #08080a 0%, transparent 80%);
}
@keyframes floor { to { transform: translateY(38px); } }

.vignette {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(circle at 50% 45%, transparent 22%, rgba(0, 0, 0, 0.94) 82%);
  opacity: 0;
  transition: opacity 0.7s ease;
}
.vignette.on { opacity: 1; }

/* ---------- Header ---------- */
.brand { flex: 0 0 auto; text-align: center; position: relative; }
.brand img {
  display: block;
  height: clamp(68px, 13vh, 120px);
  height: clamp(68px, 13dvh, 120px);
  width: auto;
  filter: drop-shadow(0 6px 22px rgba(21, 150, 232, 0.35));
}
.intro .brand { animation: dropIn 0.9s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-24px) scale(0.92); } to { opacity: 1; transform: none; } }

.mute {
  position: fixed;
  top: max(env(safe-area-inset-top), 10px);
  right: 12px;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.mute .cross[hidden] { display: none; }
.mute.off .wave { display: none; }

/* ---------- Stage / wheel ---------- */
.stage-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.stage {
  position: relative;
  width: var(--size);
  height: var(--size);
  margin-bottom: calc(var(--size) * 0.12);
  isolation: isolate;
}
.intro .stage { animation: wheelIn 1.3s cubic-bezier(.2, 1.1, .3, 1) 0.15s both; }
@keyframes wheelIn { from { opacity: 0; transform: scale(0.6) rotate(-40deg); } to { opacity: 1; transform: none; } }

/* slow rotating light rays behind the wheel */
.stage::before {
  content: "";
  position: absolute;
  inset: -34%;
  z-index: -1;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(21, 150, 232, 0.2) 0 7deg, transparent 7deg 20deg, rgba(232, 32, 42, 0.17) 20deg 27deg, transparent 27deg 40deg);
  mask-image: radial-gradient(circle, #000 30%, transparent 68%);
  -webkit-mask-image: radial-gradient(circle, #000 30%, transparent 68%);
  will-change: transform;
  animation: spinSlow 60s linear infinite;
}
@keyframes spinSlow { to { transform: rotate(360deg); } }

.stage.spinning .bulbs i { animation-duration: 0.5s; }
.stage.shake { animation: shake 0.4s ease-in-out infinite; }
.halo {
  position: absolute;
  inset: -12%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 196, 81, 0.75), rgba(245, 196, 81, 0.25) 45%, transparent 68%);
  opacity: 0;
  will-change: opacity;
}
.stage.win .halo { animation: haloPulse 1.1s ease-in-out infinite alternate; }

@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  25% { transform: translateX(-3px) rotate(-0.5deg); }
  75% { transform: translateX(3px) rotate(0.5deg); }
}
@keyframes haloPulse { from { opacity: 0.35; } to { opacity: 1; } }

.frame {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 25deg, #fbfcfe, #7c8697, #f2f5fa, #4f586a, #fbfcfe, #7c8697, #f2f5fa, #4f586a, #fbfcfe);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.7),
    0 22px 60px rgba(0, 0, 0, 0.75),
    0 0 70px rgba(21, 150, 232, 0.3),
    0 0 110px rgba(232, 32, 42, 0.2);
}
.frame::before {
  content: "";
  position: absolute;
  inset: 3.4%;
  border-radius: 50%;
  background: linear-gradient(145deg, #1b1d24, #050507);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.9), 0 0 0 1.5px rgba(255, 255, 255, 0.25);
}
.frame::after {
  content: "";
  position: absolute;
  inset: 8.2%;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #d8dee8, 0 0 0 4px #2a2e38, 0 0 18px rgba(0, 0, 0, 0.8);
}

.bulbs { position: absolute; inset: 0; }
.bulbs i {
  position: absolute;
  width: 2.7%;
  height: 2.7%;
  margin: -1.35% 0 0 -1.35%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #ffd76a 45%, #b87a00);
  box-shadow: 0 0 9px 2px rgba(255, 215, 106, 0.95);
  animation: chase 1.4s linear infinite;
  animation-delay: calc(var(--i) * -0.05s);
}
.bulbs i:nth-child(4n+2) {
  background: radial-gradient(circle at 35% 30%, #fff, #6cc4ff 45%, #0a5ea8);
  box-shadow: 0 0 9px 2px rgba(21, 150, 232, 0.95);
}
@keyframes chase {
  0%, 38% { opacity: 1; transform: scale(1.15); }
  50%, 100% { opacity: 0.22; transform: scale(0.85); }
}

.wheel {
  position: absolute;
  inset: 10.2%;
  width: 79.6%;
  height: 79.6%;
  border-radius: 50%;
  will-change: transform;
}

.shine {
  position: absolute;
  inset: 10.2%;
  border-radius: 50%;
  pointer-events: none;
  background:
    radial-gradient(110% 60% at 35% 6%, rgba(255, 255, 255, 0.3), transparent 55%),
    radial-gradient(circle at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.4) 100%);
}

.pointer {
  position: absolute;
  top: -5.5%;
  left: 50%;
  width: 9%;
  transform: translateX(-50%);
  transform-origin: 50% 25%;
  z-index: 4;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.65));
}

.hub {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20%;
  height: 20%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 0;
  padding: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 35% 25%, #424652, #0a0a0d 70%);
  box-shadow:
    0 0 0 calc(var(--size) * 0.012) #eef1f6,
    0 0 0 calc(var(--size) * 0.02) #4f586a,
    0 0 26px rgba(21, 150, 232, 0.35),
    0 10px 26px rgba(0, 0, 0, 0.75);
  cursor: pointer;
}
.hub svg { width: 70%; display: block; filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.6)); }
.hub:not(:disabled) { animation: hubPulse 2.2s ease-in-out infinite; }
@keyframes hubPulse {
  0%, 100% { box-shadow: 0 0 0 calc(var(--size) * 0.012) #eef1f6, 0 0 0 calc(var(--size) * 0.02) #4f586a, 0 0 18px rgba(21, 150, 232, 0.3), 0 10px 26px rgba(0, 0, 0, 0.75); }
  50% { box-shadow: 0 0 0 calc(var(--size) * 0.012) #eef1f6, 0 0 0 calc(var(--size) * 0.02) #4f586a, 0 0 42px rgba(232, 32, 42, 0.7), 0 10px 26px rgba(0, 0, 0, 0.75); }
}

/* caption pop (comic style) */
.caption {
  position: absolute;
  left: 50%;
  bottom: 106%;
  z-index: 9;
  transform: translateX(-50%);
  white-space: nowrap;
  font-style: italic;
  font-weight: 900;
  font-size: clamp(26px, 8.5vw, 40px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  -webkit-text-stroke: 1px rgba(0, 0, 0, 0.5);
  text-shadow: 0 3px 0 #a90d16, 0 0 22px rgba(232, 32, 42, 0.85);
  pointer-events: none;
}
.caption:empty { display: none; }
.caption.gold { text-shadow: 0 3px 0 #8a5a00, 0 0 26px rgba(245, 196, 81, 0.95); color: #fff3c7; }

/* ---------- Car ---------- */
/* Perf notes: no filters on the car, wheels are their own layers rotated with
   transform only, so nothing inside the body SVG is repainted while it moves. */
.car {
  position: absolute;
  left: 50%;
  bottom: -14%;
  width: 72%;
  margin-left: -36%;
  z-index: 6;
  display: none; /* display (not visibility): a fresh compositor layer on every run */
}
.car.show { display: block; will-change: transform; }
.car-flip, .car-tilt { position: relative; transform-origin: 50% 100%; }
.car-svg { display: block; width: 100%; overflow: visible; }
.car-beam {
  position: absolute;
  left: 91%;
  top: 32.5%;
  width: 31%;
  height: 47.5%;
  background: linear-gradient(90deg, rgba(255, 251, 224, 0.85), rgba(255, 251, 224, 0));
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
  opacity: 0;
  transition: opacity 0.15s;
}
.car.lights .car-beam { opacity: 1; }
.car .hl { opacity: 0.35; }
.car.lights .hl { opacity: 1; }

.cw {
  position: absolute;
  top: 46.25%;
  width: 15.45%;
  aspect-ratio: 1;
  will-change: transform;
  animation: roll 0.4s linear infinite;
}
.cw svg { display: block; width: 100%; }
.cw-r { left: 17.73%; }
.cw-f { left: 66.36%; }
.car.fast .cw { animation-duration: 0.12s; }
.car.idle .cw { animation-play-state: paused; }
@keyframes roll { to { transform: rotate(360deg); } }

.speed {
  position: absolute;
  right: 98%;
  top: 22%;
  width: 40%;
  opacity: 0;
  transition: opacity 0.15s;
}
.speed i {
  display: block;
  height: 3px;
  margin: 12px 0;
  border-radius: 3px;
  background: linear-gradient(270deg, rgba(255, 255, 255, 0.9), transparent);
}
.speed i:nth-child(2) { width: 70%; margin-left: 30%; }
.speed i:nth-child(3) { width: 90%; margin-left: 10%; }
.car.fast .speed { opacity: 1; }

/* effects spawned by JS */
.fx { position: fixed; inset: 0; z-index: 7; pointer-events: none; overflow: hidden; contain: strict; }
.fx .puff {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(225, 232, 244, 0.5), rgba(170, 182, 200, 0.18) 60%, transparent 70%);
  will-change: transform, opacity;
}
.fx .spark {
  position: absolute;
  width: 14px;
  height: 3px;
  border-radius: 3px;
  background: linear-gradient(90deg, #fff, #ffcf5a);
  box-shadow: 0 0 6px 1px rgba(255, 190, 60, 0.9);
  will-change: transform, opacity;
}
.fx .ring {
  position: absolute;
  border-radius: 50%;
  border: 4px solid #ffe08a;
  box-shadow: 0 0 22px 4px rgba(255, 190, 60, 0.8), inset 0 0 18px rgba(255, 190, 60, 0.6);
  will-change: transform, opacity;
}
.fx .flash {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 244, 200, 0.95), rgba(255, 190, 60, 0.35) 45%, transparent 70%);
  will-change: transform, opacity;
}

/* ---------- Controls ---------- */
.controls {
  flex: 0 0 auto;
  width: 100%;
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.status {
  margin: 0;
  min-height: 1.4em;
  font-size: 15px;
  font-style: italic;
  letter-spacing: 0.05em;
  color: #c9cfda;
}

.spin {
  position: relative;
  width: 100%;
  padding: 18px 24px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  font-style: italic;
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.22em;
  background: linear-gradient(180deg, #ff5159 0%, #e8202a 48%, #a90d16 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(255, 255, 255, 0.5),
    inset 0 -3px 0 rgba(0, 0, 0, 0.25),
    0 10px 30px rgba(232, 32, 42, 0.5),
    0 0 0 2px rgba(255, 255, 255, 0.1);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s ease, filter 0.2s ease, opacity 0.2s ease;
}
.spin span { position: relative; z-index: 1; text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4); }
.spin::after {
  content: "";
  position: absolute;
  top: 0;
  left: -60%;
  width: 40%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  transform: skewX(-20deg);
  animation: sweep 3s ease-in-out infinite;
}
.spin:active { transform: scale(0.97); }
.spin:disabled { filter: grayscale(0.7) brightness(0.6); opacity: 0.7; cursor: default; }
.spin:disabled::after { animation: none; }
.spin.small { font-size: 16px; padding: 15px 20px; margin-top: 8px; }

@keyframes sweep { 0%, 55% { left: -60%; } 100% { left: 130%; } }

/* ---------- Confetti / modal ---------- */
.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 30;
  pointer-events: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(4, 4, 7, 0.76);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}
.modal[hidden] { display: none; }

.rays {
  position: absolute;
  inset: -40%;
  background: repeating-conic-gradient(from 0deg, rgba(245, 196, 81, 0.2) 0 6deg, transparent 6deg 18deg);
  mask-image: radial-gradient(circle, #000 12%, transparent 55%);
  -webkit-mask-image: radial-gradient(circle, #000 12%, transparent 55%);
  animation: spinSlow 40s linear infinite;
  opacity: 0;
}
.modal.win .rays { opacity: 1; }

.card {
  position: relative;
  width: min(92vw, 380px);
  padding: 74px 24px 24px;
  margin-top: 40px;
  text-align: center;
  border-radius: 28px;
  background: linear-gradient(180deg, #20222b, #0d0e12);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 60px rgba(21, 150, 232, 0.25);
  animation: pop 0.6s cubic-bezier(.2, 1.4, .4, 1) both;
}
.card.win { box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 90px rgba(245, 196, 81, 0.45); border-color: rgba(245, 196, 81, 0.6); }

.badge {
  position: absolute;
  top: -44px;
  left: 50%;
  width: 92px;
  height: 92px;
  margin-left: -46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ffe9a6, #f5c451 55%, #a8700f);
  box-shadow: 0 0 0 5px #0d0e12, 0 0 0 7px rgba(245, 196, 81, 0.7), 0 10px 30px rgba(245, 196, 81, 0.45);
}
.card:not(.win) .badge { background: radial-gradient(circle at 35% 28%, #4a4f5c, #1a1c22 70%); box-shadow: 0 0 0 5px #0d0e12, 0 0 0 7px rgba(255, 255, 255, 0.18); }
.badge svg { width: 54px; height: 54px; }

@keyframes pop {
  from { transform: scale(0.6) translateY(30px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: 0.34em;
  color: var(--gold);
}
.card:not(.win) .eyebrow { color: #9aa4b2; }

.card h2 {
  margin: 0 0 10px;
  font-size: clamp(26px, 8vw, 34px);
  line-height: 1.1;
  font-style: italic;
  font-weight: 900;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff, #b8c2d2);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.card.win h2 { background: linear-gradient(180deg, #fff6d2, #f5c451 60%, #c8921c); -webkit-background-clip: text; background-clip: text; }

.card .detail { margin: 0 0 14px; font-size: 15px; line-height: 1.45; color: #aeb6c4; }

@media (prefers-reduced-motion: reduce) {
  .grid-floor, .bulbs i, .spin::after, .stage::before, .hub { animation: none !important; }
}

/* ---------- Debug panel ---------- */
.dbg {
  position: fixed;
  top: max(env(safe-area-inset-top), 8px);
  left: 8px;
  z-index: 60;
  width: min(300px, calc(100vw - 16px));
  max-height: 72vh;
  max-height: 72dvh;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: rgba(10, 12, 16, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  font: 12px/1.3 ui-monospace, Menlo, monospace;
  color: #dfe5ee;
}
.dbg-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.dbg-head b { color: var(--gold); letter-spacing: 0.15em; }
.dbg-fps { flex: 1; text-align: right; color: #7be495; }
.dbg-fps.bad { color: #ff7b82; }
.dbg-body { overflow-y: auto; padding: 6px 10px 10px; }
.dbg.folded .dbg-body { display: none; }
.dbg-group { margin: 10px 0 4px; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: #8d97a8; }
.dbg-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin-bottom: 2px; }
.dbg-row em { font-style: normal; color: #8d97a8; margin-right: 2px; }
.dbg button {
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.07);
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.dbg button:active { background: rgba(255, 255, 255, 0.2); }
.dbg button.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.dbg-head button { padding: 3px 8px; }
