:root {
  --s: 76px;
  --night1: #1c0b33;
  --night2: #0b0518;
  --wall: #2a1240;
  --wall-dark: #160828;
  --gold: #ffcf4a;
  --gold-dark: #9a6a12;
  --neon-pink: #ff3d9a;
  --neon-cyan: #44f0ff;
  --red: #d61f35;
  --red-dark: #7a0d1c;
  --felt: #1f8a45;
  --felt-dark: #0c4422;
  --text: #fff2dc;
  --panel: rgba(20, 8, 36, .9);
  --pixel: "VT323", ui-monospace, monospace;
  --pixel-bold: "Press Start 2P", "VT323", monospace;
  --roll-time: 1.3s;
  --climb: 0px;
}

* { box-sizing: border-box; }

/* Background lives on html so the fixed tower (z-index -1) shows above it */
html { background: radial-gradient(ellipse at 50% 0%, var(--night1), var(--night2) 70%) fixed var(--night2); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--pixel);
  font-size: 20px;
  letter-spacing: .08em;
  overflow-x: hidden;
  image-rendering: pixelated;
}

/* CRT scanlines over everything */
.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 30;
  /* Plain translucent lines: a blend mode here forces full-page recompositing every frame */
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, .14) 0 1px, transparent 1px 3px);
}

/* ---------- Night sky & the tower ---------- */
.stars {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(2px 2px at 10% 20%, #fff, transparent),
    radial-gradient(2px 2px at 80% 12%, #fff, transparent),
    radial-gradient(2px 2px at 30% 70%, #ffd, transparent),
    radial-gradient(2px 2px at 65% 45%, #fff, transparent),
    radial-gradient(2px 2px at 90% 80%, #cff, transparent),
    radial-gradient(2px 2px at 15% 90%, #fff, transparent),
    radial-gradient(2px 2px at 50% 30%, #fdf, transparent);
  animation: twinkle 3s steps(2) infinite;
}
@keyframes twinkle { 50% { opacity: .5; } }

/* An endless facade of lit windows; --climb slides it down as you go up */
.tower {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  width: min(720px, 94vw);
  transform: translateX(-50%);
  z-index: -1;
  background:
    /* lit windows */
    repeating-linear-gradient(90deg, transparent 0 22px, rgba(255, 207, 74, .55) 22px 46px, transparent 46px 70px) 0 var(--climb) / 70px 120px,
    /* window rows */
    repeating-linear-gradient(to bottom, transparent 0 30px, var(--wall) 30px 120px) 0 var(--climb) / 100% 120px,
    /* floor slabs */
    repeating-linear-gradient(to bottom, var(--wall-dark) 0 8px, transparent 8px 120px) 0 var(--climb) / 100% 120px,
    linear-gradient(90deg, var(--wall-dark), var(--wall) 12%, var(--wall) 88%, var(--wall-dark));
  box-shadow: 0 0 80px rgba(255, 61, 154, .25);
  opacity: .55;
  transition: background-position 1s steps(10);
}
.tower::before,
.tower::after {
  /* neon trim running up the sides */
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--neon-pink);
  box-shadow: 0 0 12px var(--neon-pink), 0 0 24px var(--neon-pink);
}
.tower::before { left: 0; background: var(--floor-color, var(--neon-pink)); box-shadow: 0 0 12px var(--floor-color, var(--neon-pink)), 0 0 24px var(--floor-color, var(--neon-pink)); transition: background .6s; }
.tower::after { right: 0; background: var(--neon-cyan); box-shadow: 0 0 12px var(--neon-cyan), 0 0 24px var(--neon-cyan); }

/* ---------- Neon sign ---------- */
header {
  text-align: center;
  padding: 28px 16px 8px;
}
.sign {
  position: relative;
  display: inline-block;
  padding: 22px 30px 18px;
  background: rgba(12, 4, 24, .85);
  border: 4px solid var(--gold);
  box-shadow: 0 0 0 4px var(--night2), 0 0 30px rgba(255, 207, 74, .35);
}
/* Chasing marquee bulbs around the sign */
.sign::before {
  content: "";
  position: absolute;
  inset: -12px;
  border: 6px dotted var(--gold);
  animation: marquee 2.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes marquee {
  0%   { border-color: var(--gold); }
  50%  { border-color: #fff6c9; }
}
h1 {
  margin: 0;
  font-family: var(--pixel-bold);
  font-size: clamp(2rem, 9vw, 4rem);
  letter-spacing: .1em;
  color: #fff;
  text-shadow:
    0 0 6px var(--neon-pink),
    0 0 14px var(--neon-pink),
    0 0 28px var(--neon-pink),
    4px 4px 0 var(--red-dark);
}
@keyframes flicker {
  0%, 89%, 92%, 95%, 100% { opacity: 1; }
  90%, 94% { opacity: .35; }
}
.subtitle {
  margin: 14px 0 0;
  font-size: 1.35rem;
  letter-spacing: .3em;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px var(--neon-cyan);
}
.rules {
  margin: 22px 0 0;
  color: #c7a8e8;
  font-size: 1.15rem;
}

/* ---------- Main floor ---------- */
.drift {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}
.floor {
  position: relative;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 40px;
}
.floor .panel,
.floor .roll-btn { pointer-events: auto; }

.panel {
  background: var(--panel);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 3px var(--night2), 0 0 14px rgba(255, 207, 74, .3), inset 0 0 12px rgba(255, 207, 74, .12);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 640px;
}
.stat {
  padding: 8px 6px 6px;
  text-align: center;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stat .label { font-size: .95rem; letter-spacing: .25em; color: var(--gold); text-transform: uppercase; }
.stat .value {
  font-family: var(--pixel-bold);
  font-size: 1.2rem;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bump { animation: bump .35s steps(3); }
@keyframes bump { 50% { transform: scale(1.35); color: var(--gold); } }

/* ---------- Felt table ---------- */
.table {
  width: 100%;
  max-width: 760px;
  margin-top: 18px;
  padding: 0 12px 14px;
  background: radial-gradient(ellipse at center, var(--felt), var(--felt-dark) 85%);
  border: 8px solid var(--gold-dark);
  outline: 3px solid var(--gold);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .6), 0 12px 40px rgba(0, 0, 0, .6);
  border-radius: 60px;
}
.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 26px;
  min-height: 220px;
  padding: 46px 0 26px;
  perspective: 900px;
}
@keyframes shake {
  25% { transform: translate(-4px, 4px); }
  50% { transform: translate(4px, -4px); }
  75% { transform: translate(-2px, 2px); }
}

.log {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
}
.chip {
  background: rgba(0, 0, 0, .45);
  border: 2px solid rgba(255, 207, 74, .6);
  padding: 2px 10px;
  font-size: 1rem;
  animation: pop-in .3s steps(3);
}
.chip b { color: #fff; font-weight: normal; }
.chip i { color: var(--gold); font-style: normal; }
@keyframes pop-in { from { transform: scale(0); } }

/* ---------- Casino dice ---------- */
.slot {
  width: var(--s);
  height: var(--s);
  position: relative;
}
.shadow {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -18px;
  height: 10px;
  background: rgba(0, 0, 0, .45);
  animation: shadow var(--roll-time) ease-out both;
}
.toss {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
  animation: toss var(--roll-time) cubic-bezier(.3, .7, .4, 1) both;
}
/* Dice get flung onto the felt and bounce */
@keyframes toss {
  0%   { transform: translate3d(0, -220px, 160px) scale(.5); opacity: 0; }
  12%  { opacity: 1; }
  45%  { transform: translate3d(0, 0, 0) scale(1); }
  58%  { transform: translate3d(0, -36px, 0); }
  72%  { transform: translate3d(0, 0, 0) scale(1.05, .95); }
  84%  { transform: translate3d(0, -8px, 0); }
  94%, 100% { transform: translate3d(0, 0, 0) scale(1); opacity: 1; }
}
@keyframes shadow {
  0%  { transform: scaleX(.2); opacity: 0; }
  45% { transform: scaleX(1); opacity: 1; }
  58% { transform: scaleX(.7); opacity: .6; }
  72%, 100% { transform: scaleX(1); opacity: 1; }
}
.die {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  will-change: transform;
  transition: transform var(--roll-time) cubic-bezier(.15, .75, .25, 1);
}
.face {
  position: absolute;
  inset: 0;
  background: var(--red);
  border: 4px solid var(--red-dark);
  box-shadow: inset -6px -6px 0 #9e1426, inset 6px 6px 0 #ff5d6e;
  backface-visibility: hidden;
}

/* Pips are one masked pseudo-element per face instead of a grid of spans:
   far fewer DOM nodes and no layout work while dice are flying */
.face::before,
.mini::before {
  content: "";
  position: absolute;
  inset: 12%;
  background: var(--pip, #fff);
  -webkit-mask: var(--pips) center / 100% 100% no-repeat;
  mask: var(--pips) center / 100% 100% no-repeat;
}
.v1 { --pips: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 3'%3E%3Crect x='.85' y='.85' width='1.3' height='1.3'/%3E%3C/svg%3E"); }
.v2 { --pips: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 3'%3E%3Crect x='.18' y='.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='2.18' width='.64' height='.64'/%3E%3C/svg%3E"); }
.v3 { --pips: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 3'%3E%3Crect x='.18' y='.18' width='.64' height='.64'/%3E%3Crect x='1.18' y='1.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='2.18' width='.64' height='.64'/%3E%3C/svg%3E"); }
.v4 { --pips: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 3'%3E%3Crect x='.18' y='.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='.18' width='.64' height='.64'/%3E%3Crect x='.18' y='2.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='2.18' width='.64' height='.64'/%3E%3C/svg%3E"); }
.v5 { --pips: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 3'%3E%3Crect x='.18' y='.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='.18' width='.64' height='.64'/%3E%3Crect x='1.18' y='1.18' width='.64' height='.64'/%3E%3Crect x='.18' y='2.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='2.18' width='.64' height='.64'/%3E%3C/svg%3E"); }
.v6 { --pips: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 3'%3E%3Crect x='.18' y='.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='.18' width='.64' height='.64'/%3E%3Crect x='.18' y='1.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='1.18' width='.64' height='.64'/%3E%3Crect x='.18' y='2.18' width='.64' height='.64'/%3E%3Crect x='2.18' y='2.18' width='.64' height='.64'/%3E%3C/svg%3E"); }
.f1 { transform: translateZ(calc(var(--s) / 2)); }
.f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.f2 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.f5 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.f3 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.f4 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }

.slot.six .face {
  --pip: var(--red-dark);
  background: var(--gold);
  border-color: var(--gold-dark);
  box-shadow: inset -6px -6px 0 #d49a1a, inset 6px 6px 0 #fff2b0;
}
.slot.six::before {
  content: "";
  position: absolute;
  inset: -12px;
  border: 3px solid var(--gold);
  box-shadow: 0 0 14px var(--gold);
  animation: ring 1s steps(5) infinite;
  pointer-events: none;
}
@keyframes ring {
  from { transform: scale(.85); opacity: 1; }
  to   { transform: scale(1.45); opacity: 0; }
}

.message {
  min-height: 1.6em;
  font-size: 1.4rem;
  text-align: center;
  margin: 18px 0 18px;
  color: #d8c2f2;
}
.message::after { content: "_"; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.message.win { color: var(--gold); text-shadow: 0 0 10px rgba(255, 207, 74, .6); }

/* ---------- Big casino button ---------- */
.roll-btn {
  width: 100%;
  max-width: 520px;
  padding: 22px 16px;
  font-family: var(--pixel-bold);
  font-size: 1.3rem;
  letter-spacing: .2em;
  color: #fff;
  text-shadow: 3px 3px 0 var(--red-dark);
  background: linear-gradient(var(--red) 0 50%, #b5182b 50%);
  border: 4px solid var(--gold);
  box-shadow: 0 0 0 4px var(--night2), 0 8px 0 var(--red-dark), 0 0 24px rgba(214, 31, 53, .6);
  cursor: pointer;
  transition: transform .1s steps(2);
  animation: glow 1.6s steps(4) infinite;
}
@keyframes glow {
  50% { box-shadow: 0 0 0 4px var(--night2), 0 8px 0 var(--red-dark), 0 0 44px rgba(255, 207, 74, .7); }
}
.roll-btn:hover { transform: translateY(-2px); }
.roll-btn:active { transform: translateY(6px); box-shadow: 0 0 0 4px var(--night2), 0 2px 0 var(--red-dark); }
.roll-btn.again {
  background: linear-gradient(var(--gold) 0 50%, #e6b22e 50%);
  color: var(--red-dark);
  text-shadow: 2px 2px 0 #fff2b0;
  animation: again 1.6s ease-in-out infinite;
}
@keyframes again {
  50% { box-shadow: 0 0 0 4px var(--night2), 0 8px 0 var(--gold-dark), 0 0 50px var(--gold); transform: scale(1.03); }
}
.roll-btn .auto {
  display: block;
  margin-top: 8px;
  font-family: var(--pixel);
  font-size: 1.1rem;
  letter-spacing: .2em;
  text-shadow: none;
  opacity: .8;
}
.roll-btn:disabled {
  cursor: default;
  opacity: .45;
  transform: none;
  animation: none;
}

.insta-btn {
  margin-top: 14px;
  padding: 8px 16px 6px;
  font-family: var(--pixel);
  font-size: 1.15rem;
  letter-spacing: .15em;
  color: #8e72b0;
  border-color: #4a3466;
  cursor: pointer;
}
.insta-btn.on { color: var(--neon-cyan); border-color: var(--neon-cyan); text-shadow: 0 0 8px var(--neon-cyan); }
.footer {
  margin: 22px 0 0;
  font-size: 1rem;
  letter-spacing: .2em;
  color: #8e72b0;
  text-align: center;
}
.joke {
  margin: 8px 0 0;
  min-height: 1.4em;
  max-width: 600px;
  text-align: center;
  font-size: 1.1rem;
  color: var(--neon-cyan);
  text-shadow: 0 0 6px rgba(68, 240, 255, .5);
}

.super-chance { font-size: .85rem; letter-spacing: .1em; color: var(--neon-cyan); }

/* ---------- Superbonus die ---------- */
.super-stage {
  --s: min(170px, 36vw);
  position: fixed;
  inset: 0;
  z-index: 16;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 60px;
  background: radial-gradient(circle, rgba(255, 207, 74, .18), rgba(8, 3, 16, .7) 60%);
  pointer-events: none;
  perspective: 1000px;
}
.super-roll {
  width: var(--s);
  height: var(--s);
  transform-style: preserve-3d;
}
.super-die { will-change: transform; }
.super-die .face {
  background: var(--gold);
  border: 6px solid var(--gold-dark);
  box-shadow: inset -10px -10px 0 #d49a1a, inset 10px 10px 0 #fff2b0, 0 0 40px rgba(255, 207, 74, .6);
}
.super-die .face { --pip: var(--red); }
.super-label {
  margin: 0;
  font-family: var(--pixel-bold);
  font-size: clamp(.8rem, 3.5vw, 1.4rem);
  color: var(--gold);
  text-shadow: 0 0 12px var(--gold), 3px 3px 0 var(--red-dark);
}
.super-stage.won .super-label { animation: rainbow 2s linear infinite; }
.super-stage.won .super-label::after { content: " \2714"; }
.super-stage.lost .super-roll { filter: grayscale(.7) brightness(.7); transition: filter .4s; }
.super-stage.lost .super-label { animation: none; opacity: .5; }

/* ---------- Crazy stuff ---------- */
.flash {
  position: fixed;
  inset: 0;
  z-index: 17;
  pointer-events: none;
  opacity: 0;
}
.float.oof { color: #b9a6cf; font-size: .8rem; text-shadow: 2px 2px 0 #160828; }

/* 6x6: the whole page goes haywire */
/* Calm version by default: slow sway, no strobing */
html.mayhem .floor { animation: mayhem-tilt 1.4s ease-in-out infinite alternate; }
html.mayhem .tower { animation: mayhem-zoom 2s ease-in-out infinite alternate; }
html.mayhem h1 { animation: mayhem-spin 2.4s linear infinite; }
/* Flashy version: color cycling, hard shake, strobing marquee */
html.flashy.mayhem { animation: mayhem-hue .8s linear infinite; }
html.flashy.mayhem body { animation: mayhem-shake .1s steps(2) infinite; }
html.flashy.mayhem .floor { animation: mayhem-tilt .4s steps(4) infinite alternate; }
html.flashy.mayhem h1 { animation: mayhem-spin .6s steps(8) infinite; }
html.flashy.mayhem .sign::before { animation: marquee .1s steps(2) infinite; }

/* ---------- Flashy animations toggle (off by default) ---------- */
html.flashy h1 { animation: flicker 6s steps(1) infinite; }
html.flashy .wheel-title { animation: flicker 3s steps(1) infinite; }
html.flashy .sign::before { animation: marquee .6s steps(2) infinite; }
html.flashy .wheel-wrap::before { animation: marquee .4s steps(2) infinite; }
html.flashy .roll-btn.again { animation: again .5s steps(2) infinite; }
html.flashy .super-label { animation: blink .5s steps(1) infinite; }
html.flashy .jackpot.mult-value, html.flashy .mult.jackpot .mult-value, html.flashy .value.jackpot,
html.flashy .hub-value.jackpot, html.flashy .toast.jackpot, html.flashy .go-score.jackpot {
  animation: rainbow .6s steps(6) infinite;
}
html.flashy .toast.jackpot.show { animation: toast 1.1s steps(10) both, rainbow .6s steps(6) infinite; }

.flashy-btn {
  position: fixed;
  top: 12px;
  right: 70px;
  z-index: 15;
  width: 48px;
  height: 48px;
  color: #6b5687;
  font-size: 1.4rem;
  font-family: var(--pixel);
  cursor: pointer;
}
html.flashy .flashy-btn { color: var(--gold); text-shadow: 0 0 8px var(--gold); }

/* ---------- Splash (click to enter) ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 16px;
  text-align: center;
  background: radial-gradient(circle, rgba(40, 10, 60, .9), rgba(8, 3, 16, .98));
  cursor: pointer;
}
.splash .roll-btn { max-width: 420px; }
.splash-hint { margin: 0; color: #c7a8e8; font-size: 1.2rem; }

/* ---------- Game over card ---------- */
.gameover {
  position: fixed;
  inset: 0;
  z-index: 16;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 3, 16, .7);
  opacity: 0;
  visibility: hidden;
  transition: opacity .4s, visibility .4s;
}
.gameover.show { opacity: 1; visibility: visible; }
.go-card {
  width: 100%;
  max-width: 480px;
  padding: 26px 22px 22px;
  text-align: center;
  border-color: var(--tc, var(--gold));
  transform: scale(.3) rotate(-6deg);
  transition: transform .6s cubic-bezier(.3, 1.6, .5, 1);
}
.gameover.show .go-card { transform: none; }
.go-title { margin: 0; font-family: var(--pixel-bold); font-size: 1rem; color: var(--gold); letter-spacing: .2em; }
.go-score {
  display: block;
  margin: 18px 0 4px;
  font-family: var(--pixel-bold);
  font-size: clamp(1.8rem, 9vw, 3rem);
  color: var(--tc, var(--text));
  text-shadow: 0 0 18px var(--tc, transparent), 4px 4px 0 var(--red-dark);
  font-variant-numeric: tabular-nums;
}
.go-tier { font-size: 1.6rem; letter-spacing: .4em; color: var(--tc, var(--gold)); }
/* Ten pips light up as the score climbs through the tiers */
.go-ladder { display: flex; justify-content: center; gap: 6px; margin: 14px 0; }
.go-ladder span {
  width: 22px;
  height: 22px;
  background: rgba(255, 255, 255, .08);
  border: 2px solid rgba(255, 255, 255, .15);
  transition: background .2s, box-shadow .2s, transform .2s;
}
.go-ladder span.on { background: var(--c); border-color: var(--c); box-shadow: 0 0 10px var(--c); transform: translateY(-4px); }
.go-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 12px 0 6px; font-size: 1.15rem; text-align: left; }
.go-stats b { color: var(--gold); font-weight: normal; float: right; }
.go-odds {
  margin: 14px 0 18px;
  padding: 10px;
  border: 2px dashed rgba(68, 240, 255, .5);
  color: var(--neon-cyan);
  font-size: 1.2rem;
}
.go-odds strong { display: block; font-family: var(--pixel-bold); font-size: 1rem; margin-top: 6px; color: #fff; }
.go-card .roll-btn { max-width: none; }

/* ---------- Elevator doors every 5 floors ---------- */
.doors {
  position: fixed;
  inset: 0;
  z-index: 21;
  pointer-events: none;
  overflow: hidden;
}
.door {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .06) 0 2px, transparent 2px 18px),
    linear-gradient(90deg, #6d6680, #b9b2c9 45%, #8a829c);
  border: 6px solid var(--gold-dark);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .5);
}
.door.left { left: 0; transform: translateX(-100%); border-right-color: var(--gold); }
.door.right { right: 0; transform: translateX(100%); border-left-color: var(--gold); }
.door-sign {
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -110px 0 0 -150px;
  width: 300px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 4px solid var(--gold);
  box-shadow: 0 0 0 4px var(--night2), 0 0 40px rgba(255, 207, 74, .5);
  opacity: 0;
  text-align: center;
}
.door-floor { font-family: var(--pixel-bold); font-size: 1.5rem; color: var(--gold); text-shadow: 3px 3px 0 var(--red-dark); }
.door-gift { font-size: 1.3rem; letter-spacing: .15em; color: var(--neon-cyan); }
/* Extra specificity: the drifting-die .mini rule comes later in this file */
.door-sign .door-die { width: 72px; height: 72px; padding: 8px; animation: none; opacity: 1; }

/* ---------- Dramatic last die ---------- */
.tray .slot { transition: opacity .4s, transform .4s; }
.tray.spotlight .slot:not(.last) { opacity: .3; }
.tray.spotlight .slot.last { transform: scale(1.35); z-index: 2; }
.tray.spotlight .slot.last::after {
  content: "";
  position: absolute;
  inset: -40px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 242, 176, .35), transparent 70%);
  pointer-events: none;
  z-index: -1;
}
@keyframes mayhem-hue { to { filter: hue-rotate(360deg) saturate(1.8); } }
@keyframes mayhem-shake {
  0% { transform: translate(-6px, 4px); }
  100% { transform: translate(6px, -4px); }
}
@keyframes mayhem-tilt {
  from { transform: rotate(-3deg) scale(.97); }
  to   { transform: rotate(3deg) scale(1.04); }
}
@keyframes mayhem-spin { to { transform: rotateY(360deg); } }
@keyframes mayhem-zoom { to { transform: translateX(-50%) scale(1.15); } }

/* ---------- Corner widgets ---------- */
.mult {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 12px;
  perspective: 300px;
}
.d100 {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #fff2b0, var(--gold) 50%, var(--gold-dark));
  clip-path: polygon(50% 0, 100% 38%, 82% 100%, 18% 100%, 0 38%);
  color: var(--red-dark);
  font-family: var(--pixel-bold);
  font-size: .9rem;
}
.d100 span { margin-top: 8px; }
.mult-text { display: flex; flex-direction: column; }
.mult .label { font-size: .9rem; letter-spacing: .25em; color: var(--gold); text-transform: uppercase; }
.mult { border-color: var(--tc, var(--gold)); }
.mult-value {
  font-family: var(--pixel-bold);
  font-size: 1.5rem;
  min-width: 4.5ch;
  margin-top: 4px;
  color: var(--tc, var(--text));
  text-shadow: 0 0 10px var(--tc, transparent);
}

/* ---------- Ten tier colors (set as --tc from script.js) ---------- */
.stat .value { color: var(--tc, var(--text)); text-shadow: 0 0 8px var(--tc, transparent); }
.jackpot.mult-value, .mult.jackpot .mult-value, .value.jackpot, .hub-value.jackpot, .toast.jackpot, .go-score.jackpot {
  animation: rainbow 4s linear infinite;
}
@keyframes rainbow {
  0%   { color: var(--neon-pink); text-shadow: 0 0 12px var(--neon-pink), 4px 4px 0 var(--red-dark); }
  33%  { color: var(--gold); text-shadow: 0 0 12px var(--gold), 4px 4px 0 var(--red-dark); }
  66%  { color: var(--neon-cyan); text-shadow: 0 0 12px var(--neon-cyan), 4px 4px 0 var(--red-dark); }
}
.toast.jackpot.show { animation: toast 1.1s steps(10) both, rainbow 4s linear infinite; }
.chip { border-color: var(--tc, rgba(255, 207, 74, .6)); }
.chip u { color: var(--neon-cyan); text-decoration: none; }

/* ---------- The big d100 wheel ---------- */
.wheel-overlay {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 16px;
  background: radial-gradient(circle, rgba(40, 10, 60, .75), rgba(8, 3, 16, .92));
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.wheel-overlay.show { opacity: 1; visibility: visible; }
.wheel-title {
  margin: 0;
  font-family: var(--pixel-bold);
  font-size: clamp(.9rem, 3.5vw, 1.6rem);
  text-align: center;
  color: var(--gold);
  text-shadow: 0 0 12px var(--gold), 3px 3px 0 var(--red-dark);
}
.wheel-wrap {
  position: relative;
  /* Leave room for the title, pointer and marquee bulbs. Explicit height instead of
     aspect-ratio, which older mobile browsers ignore (the wheel collapsed to 0px) */
  width: 84vw;
  height: 84vw;
  max-width: 620px;
  max-height: 620px;
  flex-shrink: 0;
  margin-top: 20px;
}
/* Also fit short screens; only where min() works, so older phones keep the plain size */
@supports (width: min(1px, 2px)) {
  .wheel-wrap {
    width: min(84vw, calc(100vh - 170px), 620px);
    height: min(84vw, calc(100vh - 170px), 620px);
  }
}
/* Marquee bulbs around the rim */
.wheel-wrap::before {
  content: "";
  position: absolute;
  inset: -26px;
  border-radius: 50%;
  border: 10px dotted var(--gold);
  animation: marquee 2s ease-in-out infinite;
}
.wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 0 8px var(--gold-dark), 0 0 0 12px var(--gold), 0 0 80px rgba(255, 207, 74, .5);
  /* Rotation is set every frame from script.js; a transition here would fight it */
  will-change: transform;
}
.pointer {
  position: absolute;
  top: -34px;
  left: 50%;
  z-index: 2;
  width: 44px;
  height: 56px;
  margin-left: -22px;
  background: linear-gradient(90deg, #fff2b0, var(--gold) 50%, var(--gold-dark));
  clip-path: polygon(0 0, 100% 0, 100% 40%, 50% 100%, 0 40%);
  filter: drop-shadow(0 4px 0 var(--red-dark));
  transform-origin: 50% 20%;
}
.pointer.tick { animation: tick .12s steps(2); }
@keyframes tick { 50% { transform: rotate(-14deg); } }
.hub {
  position: absolute;
  inset: 34%;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, #2a1240, #0b0518);
  border: 6px solid var(--gold);
  box-shadow: 0 0 30px rgba(0, 0, 0, .8), inset 0 0 20px rgba(255, 207, 74, .3);
}
.hub-label { font-size: clamp(.8rem, 2.4vmin, 1.1rem); letter-spacing: .3em; color: var(--gold); }
.hub-value {
  font-family: var(--pixel-bold);
  font-size: clamp(1.6rem, 7vmin, 3.4rem);
  color: var(--tc, var(--text));
  text-shadow: 0 0 16px var(--tc, transparent), 4px 4px 0 var(--red-dark);
}

/* ---------- The big d20 end die ---------- */
.d20-stage {
  position: fixed;
  inset: 0;
  z-index: 16;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px;
  opacity: 0;
  background: radial-gradient(circle, rgba(40, 10, 60, .55), rgba(8, 3, 16, .9) 65%);
  pointer-events: none;
}
.d20-roll { position: relative; width: min(64vw, 340px); height: min(64vw, 340px); }
.d20 {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 0 rgba(0, 0, 0, .45));
}
.d20-shadow {
  position: absolute;
  left: 20%;
  right: 20%;
  bottom: -6%;
  height: 8%;
  border-radius: 50%;
  background: radial-gradient(rgba(0, 0, 0, .6), transparent 70%);
  z-index: -1;
}
.d20-title, .d20-label {
  margin: 0;
  font-family: var(--pixel-bold);
  text-align: center;
  color: var(--tc, var(--gold));
  text-shadow: 0 0 14px var(--tc, var(--gold)), 3px 3px 0 var(--red-dark);
}
.d20-title { font-size: clamp(.9rem, 4vw, 1.5rem); color: var(--gold); letter-spacing: .2em; }
.d20-label { font-size: clamp(1.4rem, 7vw, 2.6rem); }
.d20-stage.landed .d20 { filter: drop-shadow(0 10px 0 rgba(0, 0, 0, .45)) drop-shadow(0 0 24px var(--gold)); }

/* ---------- Cinematic final score ---------- */
.cine {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 16px;
  overflow: hidden;
  pointer-events: none;
  background: radial-gradient(circle, rgba(30, 8, 50, .92), rgba(4, 1, 10, .98) 70%);
}
.cine-bar {
  position: absolute;
  left: 0;
  right: 0;
  height: 11vh;
  background: #000;
  z-index: 3;
}
.cine-bar.top { top: 0; }
.cine-bar.bottom { bottom: 0; }
/* Slowly turning light rays behind the score, tinted by tier */
.cine-rays {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 180vmax;
  height: 180vmax;
  margin: -90vmax 0 0 -90vmax;
  background: repeating-conic-gradient(from 0deg, var(--tc, var(--gold)) 0deg 6deg, transparent 6deg 18deg);
  -webkit-mask: radial-gradient(circle, #000 0, transparent 55%);
  mask: radial-gradient(circle, #000 0, transparent 55%);
  opacity: 0;
  animation: rays 24s linear infinite;
  z-index: 0;
}
@keyframes rays { to { transform: rotate(360deg); } }
.cine > *:not(.cine-bar):not(.cine-rays) { position: relative; z-index: 2; }
.cine-eq {
  display: flex;
  align-items: center;
  gap: 18px;
  font-family: var(--pixel-bold);
  font-size: clamp(1.1rem, 5vw, 2.2rem);
  color: var(--text);
  text-shadow: 3px 3px 0 var(--red-dark);
}
.cine-eq .x { color: var(--gold); font-size: 1.4em; }
.cine-eq .m { color: var(--tc, var(--gold)); text-shadow: 0 0 12px var(--tc, var(--gold)), 3px 3px 0 var(--red-dark); }
.cine-score {
  display: flex;
  font-family: var(--pixel-bold);
  font-size: clamp(2.2rem, 12vw, 6rem);
  color: var(--tc, var(--text));
  text-shadow: 0 0 24px var(--tc, transparent), 6px 6px 0 var(--red-dark);
  min-height: 1.2em;
}
.cine-score span { display: inline-block; min-width: .9em; text-align: center; }
.cine-score span.locked { animation: digit-lock .25s ease-out; }
@keyframes digit-lock { from { transform: scale(1.8); } }
.cine-score span.comma { min-width: .4em; }
.cine-tier {
  font-family: var(--pixel-bold);
  font-size: clamp(1.2rem, 6vw, 2.6rem);
  letter-spacing: .3em;
  color: var(--tc, var(--gold));
  text-shadow: 0 0 18px var(--tc, var(--gold)), 4px 4px 0 var(--red-dark);
  opacity: 0;
}
.cine-rank { font-size: 1.4rem; color: var(--neon-cyan); letter-spacing: .1em; opacity: 0; }

/* ---------- End die token: d(total sixes) ---------- */
.end-die {
  --grow: 1;
  width: calc(var(--s) * 1.9);
  height: calc(var(--s) * 1.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--tc);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  color: #160828;
  transform: scale(var(--grow));
  transition: background .15s;
}
.end-die .bd-value { font-size: calc(var(--s) * .55); }
.end-die .bd-label { font-size: 1.4rem; }
.bonus-die {
  width: calc(var(--s) * 1.1);
  height: calc(var(--s) * 1.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--tc);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  color: #160828;
  animation: drop-in .4s steps(4) both;
}
.bonus-die.rolling { animation: drop-in .4s steps(4) both, wobble .15s steps(2) infinite .4s; }
.bonus-die.landed { animation: bump .4s steps(3); }
.bd-value { font-family: var(--pixel-bold); font-size: calc(var(--s) * .3); }
.bd-label { font-size: 1.1rem; font-weight: bold; }
@keyframes drop-in { from { transform: translateY(-120px) scale(.3); opacity: 0; } }
@keyframes wobble { 50% { transform: rotate(12deg) scale(1.05); } }

.mute {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 15;
  width: 48px;
  height: 48px;
  color: var(--gold);
  font-size: 1.6rem;
  font-family: var(--pixel);
  cursor: pointer;
}
.mute.off { color: #6b5687; text-decoration: line-through; }

/* Elevator floor indicator: the shaft scrolls down as you climb */
.elevator {
  position: fixed;
  right: 12px;
  top: 90px;
  bottom: 24px;
  width: 64px;
  pointer-events: none;
  z-index: 3;
}
.shaft {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  border-right: 2px solid rgba(255, 207, 74, .5);
  background: repeating-linear-gradient(to bottom, rgba(255, 207, 74, .6) 0 3px, transparent 3px 24px) 0 var(--climb) / 100% 24px;
  transition: background-position 1s steps(10);
}
.marker {
  position: absolute;
  right: 18px;
  top: 50%;
  white-space: nowrap;
  font-family: var(--pixel-bold);
  font-size: .7rem;
  color: var(--floor-color, var(--gold));
  background: var(--panel);
  border: 2px solid var(--floor-color, var(--gold));
  padding: 6px 6px 4px;
  text-shadow: 0 0 6px var(--floor-color, var(--gold));
}

/* ---------- Falling dice you can tap ---------- */
.drifter {
  position: absolute;
  top: -70px;
  width: var(--ds, 34px);
  height: var(--ds, 34px);
  padding: 0;
  border: 0;
  background: none;
  pointer-events: auto;
  cursor: pointer;
  animation: fall var(--dur) linear forwards;
}
@keyframes fall {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(var(--sway), 27vh); }
  50%  { transform: translate(0, 55vh); }
  75%  { transform: translate(calc(var(--sway) * -1), 82vh); }
  100% { transform: translate(0, calc(100vh + 90px)); }
}
.mini {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--red);
  border: 3px solid var(--red-dark);
  box-shadow: inset -3px -3px 0 #9e1426, inset 3px 3px 0 #ff5d6e;
  animation: tumble var(--spin) steps(8) infinite;
  opacity: .9;
}
@keyframes tumble { to { transform: rotate(360deg); } }
.drifter.golden .mini {
  background: var(--gold);
  border-color: var(--gold-dark);
  box-shadow: 0 0 14px var(--gold), inset -3px -3px 0 #d49a1a;
}
.drifter.golden .mini { --pip: var(--red-dark); }
.drifter.popped { animation-play-state: paused; pointer-events: none; }
.drifter.popped .mini { animation: popspin .6s steps(6) forwards; }
@keyframes popspin {
  0%   { transform: scale(1) rotate(0); }
  60%  { transform: scale(1.9) rotate(540deg); opacity: 1; }
  100% { transform: scale(.2) rotate(720deg); opacity: 0; }
}

.float {
  position: fixed;
  z-index: 12;
  transform: translate(-50%, -50%);
  font-family: var(--pixel-bold);
  font-size: 1rem;
  color: #fff;
  text-shadow: 2px 2px 0 var(--red-dark), 0 0 8px var(--gold);
  pointer-events: none;
  animation: float-up 1s steps(10) forwards;
}
.float.gold { color: var(--gold); font-size: 1.2rem; }
@keyframes float-up {
  to { transform: translate(-50%, calc(-50% - 70px)); opacity: 0; }
}

/* ---------- Toast & particles ---------- */
.toast {
  position: fixed;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  max-width: 94vw;
  text-align: center;
  font-family: var(--pixel-bold);
  font-size: clamp(1.1rem, 5.5vw, 2.4rem);
  line-height: 1.4;
  white-space: pre-line;
  color: var(--tc, var(--gold));
  text-shadow: 0 0 14px var(--tc, var(--gold)), 4px 4px 0 var(--red-dark);
  pointer-events: none;
  z-index: 20;
}
.toast.show { animation: toast 1.1s steps(10) both; }
@keyframes toast {
  0%   { transform: translate(-50%, -50%) scale(0) rotate(-8deg); opacity: 0; }
  25%  { transform: translate(-50%, -50%) scale(1.2) rotate(2deg); opacity: 1; }
  40%  { transform: translate(-50%, -50%) scale(1); }
  80%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -120%) scale(1); opacity: 0; }
}

.fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 19;
}

@media (max-width: 600px) {
  :root { --s: 56px; }
  body { font-size: 18px; }
  header { padding-top: 92px; }
  .sign { padding: 16px 14px 12px; }
  .subtitle { font-size: 1rem; letter-spacing: .15em; }
  .mult { position: absolute; }
  .mute { position: absolute; }
  .elevator { display: none; }
  .scoreboard { gap: 8px; }
  .stat .label { font-size: .8rem; letter-spacing: .1em; }
  .stat .value { font-size: .8rem; }
  .tray { gap: 20px; min-height: 180px; }
  .table { border-radius: 36px; border-width: 6px; }
  .roll-btn { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --roll-time: .4s; }
  .stars, h1, .sign::before, .roll-btn, .slot.six::before, .message::after, .mini, .wheel-wrap::before, .wheel-title { animation: none; }
  .wheel { --spin-time: .8s; }
  html.mayhem, html.mayhem body, html.mayhem .floor, html.mayhem h1, html.mayhem .tower { animation: none; }
  .tower, .shaft { transition: none; }
}
