/* Layout and motion. Colour and ornament live in neon.css. */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg, #111);
  color: var(--ink, #fff);
  font-family: var(--font-body, system-ui, sans-serif);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus, #ffd84a); outline-offset: 3px; }

:root {
  --gut: 16px;
  --lever-w: clamp(56px, 14vw, 92px);
  --cab-pad: clamp(10px, 2.6vw, 20px);
  --frame: clamp(6px, 1.4vw, 10px);
  --reel-gap: clamp(4px, 1vw, 8px);
  --machine-w: min(calc(100vw - 2 * var(--gut)), 620px);
  --reel-w: calc((var(--machine-w) - var(--lever-w) - 2 * var(--cab-pad) - 2 * var(--frame) - 2 * var(--reel-gap)) / 3);
  --cell: clamp(60px, min(calc(var(--reel-w) * 0.94), calc((100vh - 340px) / 3)), 138px);
}
@supports (height: 100svh) {
  :root { --cell: clamp(60px, min(calc(var(--reel-w) * 0.94), calc((100svh - 340px) / 3)), 138px); }
}
/* ---------- stage ---------- */
.stage {
  min-height: 100%;
  display: grid; place-items: center;
  padding: 14px var(--gut) 22px;
}
.machine {
  position: relative;
  width: var(--machine-w);
  padding-right: var(--lever-w);
  display: flex; flex-direction: column; gap: 12px;
}
.marquee { position: relative; text-align: center; }
.marquee-title { margin: 0; font-weight: 400; line-height: 1; text-wrap: balance; }
.marquee-title span { display: inline-block; }
.marquee-sub { margin: 6px 0 0; }
.bulbs { display: flex; justify-content: space-between; align-items: center; }
.bulbs:empty { display: none; }
.bulb { width: var(--bulb, 8px); aspect-ratio: 1; border-radius: 50%; flex: none; }

.cabinet { position: relative; padding: var(--cab-pad); }
.reels-row { position: relative; }
.reels-frame { position: relative; padding: var(--frame); }
.reels { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--reel-gap); }
.reel { position: relative; height: calc(var(--cell) * 3); overflow: hidden; contain: paint; }
.reel::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.strip { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }
.cell {
  height: var(--cell);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: 5% 4%;
}
.icon { height: 64%; aspect-ratio: 1; flex: none; max-width: 100%; }
.icon svg, .icon img { width: 100%; height: 100%; display: block; }
.icon img { image-rendering: pixelated; image-rendering: crisp-edges; }
.cap {
  font-size: clamp(9px, calc(var(--cell) * 0.105), 14px);
  line-height: 1.05; text-align: center; text-wrap: balance; max-width: 100%;
  overflow-wrap: anywhere;
}
.reel.fast .strip { filter: blur(1.3px); }
.reel.fast .icon { transform: scaleY(1.12); }

.payline {
  position: absolute; left: 0; right: 0; pointer-events: none; z-index: 3;
  top: calc(var(--frame) + var(--cell)); height: var(--cell);
}
.payline::before, .payline::after { content: ""; position: absolute; top: 50%; transform: translateY(-50%); }

.cell.win { animation: win-pop 0.5s ease-in-out infinite alternate; }
@keyframes win-pop { from { transform: scale(1); } to { transform: scale(1.08); } }

/* ---------- banner ---------- */
.banner {
  position: absolute; left: 50%; top: 50%; z-index: 6;
  width: max-content; max-width: 112%;
  text-align: center; line-height: 1; pointer-events: none;
  transform: translate(-50%, -50%) scale(0); opacity: 0;
  text-wrap: balance;
}
.banner.show { animation: banner 2.1s cubic-bezier(0.2, 1.5, 0.4, 1) forwards; }
.banner.show.jackpot { animation-duration: 2.6s; }
@keyframes banner {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(-8deg); opacity: 0; }
  14% { transform: translate(-50%, -50%) scale(1.12) rotate(2deg); opacity: 1; }
  24% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
  80% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(0.9) rotate(-2deg); opacity: 0; }
}

/* ---------- lever ---------- */
.lever {
  position: absolute; top: 0; bottom: 0;
  left: calc(100% + var(--cab-pad) + var(--lever-gap, 0px));
  width: var(--lever-w);
  touch-action: none; cursor: grab; outline: none;
  --pull: 0;
}
.lever.grabbing { cursor: grabbing; }
.lever:focus-visible .lever-knob { outline: 3px solid var(--focus, #ffd84a); outline-offset: 4px; }
.lever-mount { position: absolute; left: calc(-1 * var(--cab-pad) - 2px); top: 50%; width: calc(50% + var(--cab-pad)); height: 20%; transform: translateY(-50%); }
.lever-arm {
  position: absolute; left: 50%; bottom: 50%; width: var(--arm-w, 13%);
  transform-origin: 50% 100%; z-index: 1;
}
.lever-hub { position: absolute; left: 50%; top: 50%; width: 46%; aspect-ratio: 1; transform: translate(-50%, -50%); z-index: 2; }
.lever-knob { position: absolute; left: 50%; top: 50%; width: var(--knob-w, 66%); aspect-ratio: 1; z-index: 3; }
.lever.nope .lever-knob { animation: none; }
.lever.nope { animation: nope 0.32s ease-in-out; }
@keyframes nope { 25% { translate: 3px 0; } 50% { translate: -3px 0; } 75% { translate: 2px 0; } }

.lever-hint {
  position: absolute; left: 50%; top: calc(var(--knob-w, 66%) + 6px);
  transform: translateX(-50%);
  display: none; flex-direction: column; align-items: center; gap: 2px;
  pointer-events: none; z-index: 4;
  font-size: 11px; line-height: 1; text-transform: uppercase; letter-spacing: 0.06em; white-space: nowrap;
}
.lever-hint::after {
  content: ""; width: 10px; height: 10px; margin-top: 2px;
  border-right: 3px solid currentColor; border-bottom: 3px solid currentColor;
  transform: rotate(45deg);
}
.lever.hinting .lever-hint { display: flex; animation: hint 1.3s ease-in-out infinite; }
@keyframes hint { 0%, 100% { translate: 0 0; opacity: 1; } 50% { translate: 0 10px; opacity: 0.6; } }

/* ---------- readout ---------- */
.readout { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; margin-top: var(--cab-pad); }
.credits { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 12px; min-width: 4.6em; }
.credits .label { font-size: 11px; line-height: 1; text-transform: uppercase; letter-spacing: 0.08em; }
.credits .value { font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.credits.bump .value { animation: bump 0.25s ease-out; }
@keyframes bump { 50% { transform: scale(1.45); } }
.message {
  display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 8px 12px; min-height: 3.1em;
  font-size: clamp(13px, 3.6vw, 17px); line-height: 1.2; text-wrap: balance;
}

/* ---------- prize list ---------- */
.prizes { margin-top: var(--cab-pad); }
.prizes-head { margin: 0 0 8px; text-align: center; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; }
.paytable { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 6px 10px; }
.pay { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; line-height: 1.15; }
.pay-icon { width: 24px; height: 24px; flex: none; }
.pay-icon svg, .pay-icon img { width: 100%; height: 100%; display: block; }
.pay-icon img { image-rendering: pixelated; }
.pay-name { min-width: 0; }
.prizes[hidden] { display: none; }
@media (max-width: 380px) { .prizes { display: none; } }

/* ---------- shake ---------- */
.machine.shake { animation: shake 0.45s ease-in-out; }
.machine.shake-big { animation: shake-big 0.8s ease-in-out; }
@keyframes shake { 20% { translate: -5px 1px; } 40% { translate: 5px -1px; } 60% { translate: -3px 0; } 80% { translate: 2px 0; } }
@keyframes shake-big {
  10% { translate: -9px 2px; rotate: -0.6deg; } 20% { translate: 9px -2px; rotate: 0.6deg; }
  30% { translate: -7px 1px; rotate: -0.4deg; } 40% { translate: 7px -1px; rotate: 0.4deg; }
  55% { translate: -4px 0; rotate: 0deg; } 70% { translate: 3px 0; } 85% { translate: -1px 0; }
}

/* ---------- effects canvas + sound button ---------- */
.fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }
.sound-btn {
  position: fixed; right: 14px; bottom: 14px; z-index: 70;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  border: 2px solid currentColor; background: rgba(0, 0, 0, 0.35); color: #fff;
}
.sound-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sound-btn .spk { fill: currentColor; }
.sound-btn .mute { display: none; }
.sound-btn.off .wave { display: none; }
.sound-btn.off .mute { display: inline; }

/* ---------- birthday screen ---------- */
.party {
  position: fixed; inset: 0; z-index: 45;
  display: grid; place-items: center;
  padding: 20px 20px 28px;
  overflow: auto; opacity: 0;
}
.party[hidden] { display: none; }
.party.show { animation: party-in 0.6s ease-out forwards; }
@keyframes party-in { from { opacity: 0; } to { opacity: 1; } }
.party-bg { position: fixed; inset: 0; z-index: -1; }
.party-inner { position: relative; width: min(100%, 760px); display: flex; flex-direction: column; align-items: center; gap: 18px; text-align: center; }
.party-kicker { margin: 0; }
.party-title { margin: 0; line-height: 0.95; outline: none; display: flex; flex-wrap: wrap; justify-content: center; column-gap: 0.3em; row-gap: 0.06em; }
.party-title .word { display: inline-flex; white-space: nowrap; }
.party-title .ch { display: inline-block; }
.party.show .party-title .ch { animation: drop-in 0.8s cubic-bezier(0.2, 1.6, 0.4, 1) both, wave 2.6s ease-in-out infinite; animation-delay: calc(var(--i) * 70ms + 0.2s), calc(var(--i) * 90ms + 1.4s); }
@keyframes drop-in { from { transform: translateY(-120%) scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes wave { 0%, 100% { translate: 0 0; } 50% { translate: 0 -0.08em; } }
.party-name { margin: 0; }
.party-name[hidden] { display: none; }
.prize { display: flex; align-items: center; gap: 16px; padding: 14px 20px; text-align: left; max-width: 100%; }
.party.show .prize { animation: prize-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) 1.3s both; }
@keyframes prize-in { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.prize-icon { width: 76px; height: 76px; flex: none; }
.prize-icon svg, .prize-icon img { width: 100%; height: 100%; display: block; }
.prize-icon img { image-rendering: pixelated; }
.prize-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.prize-label { font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; }
.prize-name { font-size: clamp(20px, 5vw, 30px); line-height: 1.1; }
.prize-note { font-size: 15px; }
.prize-note[hidden] { display: none; }
.claim { display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(100%, 420px); }
.claim-prompt { margin: 0; font-size: clamp(17px, 4.6vw, 21px); line-height: 1.3; text-wrap: balance; }
.claim-fields { display: grid; gap: 10px; width: 100%; }
.claim-field { display: grid; gap: 4px; text-align: left; }
.claim-label { font-size: 12px; line-height: 1; text-transform: uppercase; letter-spacing: 0.12em; }
.claim-field input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  font: inherit; font-size: 17px; border-radius: 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
.claim.done .claim-field input { opacity: 0.6; }
.party.show .claim { animation: prize-in 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) 1.8s both; }
.claim-btn { cursor: pointer; border: 0; }
.claim-btn:disabled { cursor: default; }
.claim-status { margin: 0; min-height: 1.3em; max-width: 34ch; font-size: 15px; line-height: 1.3; text-wrap: balance; }
.party-replay { margin-top: 8px; padding: 10px 18px; cursor: pointer; background: transparent; border: 1px solid currentColor; border-radius: 99px; opacity: 0.75; font-size: 14px; }
.party-replay:hover { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .reel.fast .strip { filter: none; }
}
