:root { --h: 64px; --gold: #f5c542; --red: #c0262d; }
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(circle at top, #3a0d12, #120305);
  font-family: system-ui, sans-serif; color: #fff;
  overflow-x: hidden;
}
.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 42%, #3a0d1288 0%, #120305c8 58%, #080103e0 100%);
}
.bg__pic {
  position: absolute;
  object-fit: cover;
  border-radius: 18px;
  opacity: 0.78;
  filter: saturate(1.05) contrast(1.08);
  box-shadow: 0 12px 40px #000a;
  transform-origin: center center;
  will-change: transform;
  content-visibility: auto;
  contain: layout paint;
}
.bg__pic--1 {
  width: 220px; height: 220px; left: 4%; top: 8%;
  animation: bgPulse 5.5s ease-in-out infinite;
}
.bg__pic--2 {
  width: 280px; height: 160px; right: 3%; top: 10%;
  animation: bgSquash 4.2s ease-in-out infinite;
}
.bg__pic--3 {
  width: 170px; height: 220px; left: 8%; bottom: 12%;
  animation: bgWobble 6s ease-in-out infinite;
}
.bg__pic--4 {
  width: 160px; height: 240px; right: 7%; bottom: 8%;
  animation: bgStretch 4.8s ease-in-out infinite;
}
.bg__pic--5 {
  width: 140px; height: 180px; left: 22%; top: 42%; opacity: 0.62;
  animation: bgDrift 7s ease-in-out infinite;
}
.bg__pic--6 {
  width: 150px; height: 150px; right: 18%; top: 36%; opacity: 0.62;
  animation: bgPulse 3.8s ease-in-out infinite reverse;
}
.bg__pic--7 {
  width: 180px; height: 180px; left: 40%; bottom: 4%; opacity: 0.58;
  animation: bgSpinBob 8s ease-in-out infinite;
}
.music {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 6;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 3px solid var(--gold);
  border-radius: 50%;
  background: linear-gradient(#d33, var(--red));
  color: var(--gold);
  cursor: pointer;
  box-shadow: 0 0 18px #f5c54266;
  transition: transform .15s, box-shadow .2s, filter .2s;
}
.music:hover { transform: scale(1.06); box-shadow: 0 0 28px #f5c54299; }
.music:active { transform: scale(0.96); }
.music__icon { width: 26px; height: 26px; display: none; }
.music[aria-pressed="true"] .music__icon--on { display: block; }
.music[aria-pressed="false"] .music__icon--off { display: block; }
.music.is-on {
  filter: saturate(1.15) brightness(1.08);
  animation: musicPulse 1.4s ease-in-out infinite alternate;
}
@keyframes musicPulse {
  from { box-shadow: 0 0 14px #f5c54255; }
  to { box-shadow: 0 0 30px #ffe08acc; }
}
@keyframes bgPulse {
  0%, 100% { transform: rotate(-8deg) scale(1); }
  50% { transform: rotate(-4deg) scale(1.14); }
}
@keyframes bgSquash {
  0%, 100% { transform: rotate(6deg) scaleX(1) scaleY(1); }
  25% { transform: rotate(8deg) scaleX(1.12) scaleY(0.88); }
  75% { transform: rotate(3deg) scaleX(0.88) scaleY(1.14); }
}
@keyframes bgStretch {
  0%, 100% { transform: rotate(-12deg) scaleX(1) scaleY(1); }
  50% { transform: rotate(-8deg) scaleX(0.82) scaleY(1.18); }
}
@keyframes bgWobble {
  0%, 100% { transform: rotate(10deg) translate(0, 0) scale(1); }
  33% { transform: rotate(16deg) translate(10px, -12px) scale(1.08); }
  66% { transform: rotate(4deg) translate(-8px, 8px) scale(0.94); }
}
@keyframes bgDrift {
  0%, 100% { transform: rotate(-4deg) translate(0, 0) scale(1); }
  50% { transform: rotate(2deg) translate(18px, -22px) scale(1.1); }
}
@keyframes bgSpinBob {
  0%, 100% { transform: rotate(3deg) translateY(0) scale(1); }
  50% { transform: rotate(-6deg) translateY(-18px) scale(1.12); }
}
.machine {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
  padding: 16px;
  max-width: 100%;
  overflow: visible;
}
h1 {
  margin: 0;
  color: var(--gold);
  text-shadow: 0 0 12px #f5c54288;
  letter-spacing: 2px;
}
.stage {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  overflow: visible;
}
.cabinet {
  padding: 20px 24px;
  background: linear-gradient(#d33, var(--red));
  border: 6px solid var(--gold);
  border-radius: 24px;
  box-shadow: 0 0 40px #f5c54255;
  transition: box-shadow .3s, filter .3s;
  transform-origin: center center;
}
.cabinet.spinning {
  animation: cabinetShake 0.12s linear infinite, cabinetPulse 0.55s ease-in-out infinite alternate;
  filter: saturate(1.2) brightness(1.08);
}
.cabinet.spinning .reel {
  animation: reelJitter 0.09s linear infinite;
}
.cabinet.spinning .reel:nth-child(2) { animation-delay: -0.03s; }
.cabinet.spinning .reel:nth-child(3) { animation-delay: -0.06s; }
.cabinet.spinning .reel:nth-child(4) { animation-delay: -0.02s; }
@keyframes cabinetPulse {
  from { box-shadow: 0 0 28px #f5c54266, 0 0 8px #ff8a3a55; }
  to { box-shadow: 0 0 56px #ffe08a99, 0 0 18px #ff5a3a77; }
}
@keyframes cabinetShake {
  0% { transform: translate(0, 0) rotate(0deg); }
  15% { transform: translate(-3px, 2px) rotate(-0.6deg); }
  30% { transform: translate(4px, -2px) rotate(0.7deg); }
  45% { transform: translate(-2px, -3px) rotate(-0.4deg); }
  60% { transform: translate(3px, 1px) rotate(0.5deg); }
  75% { transform: translate(-4px, 2px) rotate(-0.7deg); }
  90% { transform: translate(2px, -1px) rotate(0.4deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes reelJitter {
  0% { transform: translate(0, 0); }
  25% { transform: translate(1px, -1px); }
  50% { transform: translate(-1px, 1px); }
  75% { transform: translate(1px, 1px); }
  100% { transform: translate(0, 0); }
}
.fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 5;
}
.reels { display: flex; gap: 8px; }
.reel {
  width: 140px; height: calc(var(--h) * 3); overflow: hidden;
  background: #fff; border-radius: 10px; position: relative;
  box-shadow: inset 0 12px 16px #0006, inset 0 -12px 16px #0006;
  contain: layout style paint;
  content-visibility: auto;
}
.strip { will-change: transform; contain: layout paint; }
.reel::after {
  content: ""; position: absolute; left: 0; right: 0; top: var(--h); height: var(--h);
  border-top: 2px solid var(--red); border-bottom: 2px solid var(--red); pointer-events: none;
}
.cell {
  height: var(--h); display: flex; align-items: center; justify-content: center;
  padding: 0 6px; color: #222; font-size: 18px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: clip;
}
.lever {
  position: relative;
  flex: 0 0 40px;
  width: 40px;
  height: 160px;
  margin-top: 20px;
  padding: 0;
  background: none;
  border: 0;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform .25s;
}
.lever .stick {
  position: absolute; left: 17px; top: 30px;
  width: 6px; height: 130px; background: #aaa;
}
.lever .knob {
  position: absolute; left: 4px; top: 0;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--red); border: 3px solid var(--gold);
}
.lever.pulled { transform: scaleY(-1); }
.spin {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0;
  padding: 14px 28px;
  font-size: 18px;
  font-weight: 700;
  color: #120305;
  background: var(--gold);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.spin:disabled, .lever:disabled { opacity: .5; cursor: default; }
.result {
  margin: 0;
  min-height: 48px;
  font-size: 32px;
  font-weight: 800;
  color: var(--gold);
}
.result.show { animation: pop .5s ease-out; }
@keyframes pop {
  from { transform: scale(.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@media (max-width: 640px) {
  :root { --h: 48px; }
  .reel { width: 72px; }
  .cell { font-size: 13px; }
  .lever { display: none; }
  .stage { gap: 0; }
  .bg__pic--5, .bg__pic--6, .bg__pic--7 { display: none; }
  .bg__pic { opacity: 0.35; width: 120px !important; height: 120px !important; }
  .music { top: 12px; right: 12px; width: 44px; height: 44px; }
  .music__icon { width: 22px; height: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  .bg__pic,
  .cabinet.spinning,
  .cabinet.spinning .reel,
  .music.is-on {
    animation: none !important;
  }
  .strip { transition-duration: 0.01ms !important; }
}
