:root {
  --bg-top: #effcff;
  --bg-bottom: #83d7f7;
  --stage-glow: rgba(255, 255, 255, 0.55);
  --machine-purple-dark: #6e34b6;
  --machine-purple: #8a46d2;
  --machine-purple-light: #b36fff;
  --machine-shadow: rgba(95, 54, 164, 0.32);
  --glass-shadow: rgba(54, 95, 122, 0.18);
  --glass-highlight: rgba(255, 255, 255, 0.82);
  --ticket-yellow: #ffd64c;
  --ticket-orange: #ff9f22;
  --text-main: #11314b;
  --text-soft: rgba(17, 49, 75, 0.72);
  --white: #ffffff;
  --button-core: #f6f7fb;
  --button-ring: #d2d5df;
  --button-shadow: rgba(131, 93, 193, 0.34);
  --capsule-size: 58px;
  --dispense-top: #ffe36a;
  --dispense-bottom: #ffaf21;
  --result-top: #ffde59;
  --result-bottom: #f7c324;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 255, 255, 0.88), transparent 28%),
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.34), transparent 24%),
    linear-gradient(180deg, var(--bg-top) 0%, #c8f2ff 16%, var(--bg-bottom) 100%);
}

body.show-result .machine-stage {
  filter: blur(8px) saturate(0.78) brightness(0.76);
  transform: scale(1.01);
}

button {
  font: inherit;
}

.page-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.hero {
  width: min(100%, 1120px);
  text-align: center;
}

.machine-stage {
  position: relative;
  margin: 0 auto;
  width: min(100%, 900px);
  min-height: 920px;
  display: grid;
  justify-items: center;
  align-items: start;
  isolation: isolate;
  transition: filter 220ms ease, transform 220ms ease;
}

.machine-aura {
  position: absolute;
  top: 94px;
  width: min(88vw, 760px);
  height: 720px;
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.74) 0%, rgba(255, 255, 255, 0.24) 42%, rgba(255, 255, 255, 0) 74%);
  filter: blur(8px);
  z-index: -2;
}

.machine {
  position: relative;
  width: min(100%, 620px);
  padding-top: 94px;
}

.globe-shell {
  position: relative;
  width: 500px;
  height: 500px;
  margin: -16px auto 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.98), rgba(241, 248, 252, 0.96) 58%, rgba(211, 229, 240, 0.98) 100%);
  border: 18px solid rgba(255, 255, 255, 0.94);
  box-shadow:
    inset 0 8px 28px rgba(255, 255, 255, 0.9),
    inset 0 -28px 36px rgba(139, 174, 193, 0.2),
    0 30px 55px var(--glass-shadow);
  overflow: hidden;
}

.globe-highlight,
.globe-shadow {
  position: absolute;
  pointer-events: none;
}

.globe-highlight {
  inset: 18px 150px 176px 44px;
  border-radius: 50%;
  background: linear-gradient(130deg, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0.12));
  filter: blur(2px);
}

.globe-shadow {
  inset: auto 62px 56px 62px;
  height: 78px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(137, 163, 176, 0.28), rgba(137, 163, 176, 0) 72%);
}

.capsule-field {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0) 26%),
    radial-gradient(circle at 50% 80%, rgba(108, 147, 171, 0.16), rgba(108, 147, 171, 0) 44%);
}

.capsule-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.capsule {
  position: absolute;
  width: var(--capsule-size);
  height: var(--capsule-size);
  border-radius: 50%;
  left: var(--x);
  top: var(--y);
  transform: rotate(var(--rot));
  transform-origin: center center;
  animation: bob var(--bob-duration) ease-in-out infinite;
  animation-delay: var(--delay);
}

.capsule::before,
.capsule::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.capsule::before {
  background:
    linear-gradient(180deg, var(--capsule-top) 0 50%, var(--capsule-bottom) 50% 100%);
  box-shadow:
    inset 0 5px 8px rgba(255, 255, 255, 0.45),
    inset 0 -5px 10px rgba(0, 0, 0, 0.12),
    0 12px 18px rgba(26, 72, 98, 0.16);
}

.capsule::after {
  inset: 11px 11px auto 11px;
  height: 15px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0));
}

.capsule-band {
  position: absolute;
  inset: 25px 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

.machine-body {
  position: relative;
  width: 460px;
  margin: -12px auto 0;
  padding: 26px 30px 42px;
  border-radius: 34px 34px 46px 46px;
  background:
    linear-gradient(90deg, rgba(88, 40, 150, 0.9), rgba(150, 83, 223, 0.95) 38%, rgba(196, 119, 255, 0.95) 50%, rgba(140, 74, 210, 0.96) 65%, rgba(90, 44, 156, 0.92));
  box-shadow:
    0 26px 40px rgba(90, 45, 153, 0.26),
    inset 0 2px 0 rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.machine-body::before {
  content: "";
  position: absolute;
  inset: 18px 18px auto;
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.08));
}

.machine-panel {
  position: relative;
  min-height: 190px;
  border-radius: 22px 22px 32px 32px;
  background:
    linear-gradient(90deg, rgba(96, 46, 164, 0.8), rgba(190, 120, 255, 0.72), rgba(94, 42, 164, 0.8));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2);
}

.machine-panel::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -12px;
  width: 112px;
  height: 124px;
  transform: translateX(-50%);
  border-radius: 0 0 38px 38px;
  background:
    linear-gradient(180deg, rgba(216, 232, 246, 0.46), rgba(144, 107, 219, 0.08) 24%, rgba(77, 38, 136, 0.02) 100%);
  box-shadow:
    inset 0 0 0 3px rgba(255, 255, 255, 0.24),
    inset 0 14px 18px rgba(255, 255, 255, 0.22);
  opacity: 0.36;
  pointer-events: none;
}

.start-button {
  position: absolute;
  left: 50%;
  top: 68px;
  width: 150px;
  height: 150px;
  padding: 0;
  border: none;
  background: transparent;
  transform: translateX(-50%);
  cursor: pointer;
}

.start-button:focus-visible,
.ghost-button:focus-visible {
  outline: 3px solid rgba(255, 224, 128, 0.88);
  outline-offset: 4px;
}

.start-button-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.35rem;
  font-weight: 700;
  color: #595b68;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.98), rgba(240, 242, 247, 0.94) 58%, rgba(205, 210, 222, 0.98) 100%);
  box-shadow:
    0 14px 20px var(--button-shadow),
    inset 0 0 0 10px rgba(255, 255, 255, 0.82),
    inset 0 0 0 16px var(--button-ring);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.start-button:hover .start-button-face {
  transform: translateY(-2px);
}

.start-button:active .start-button-face,
.machine-stage[data-state="shaking"] .start-button-face {
  transform: translateY(5px) scale(0.98);
  box-shadow:
    0 7px 14px rgba(131, 93, 193, 0.22),
    inset 0 0 0 10px rgba(255, 255, 255, 0.82),
    inset 0 0 0 16px var(--button-ring);
}

.speaker {
  position: absolute;
  bottom: 28px;
  width: 32px;
  height: 18px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(45, 16, 84, 0.46), rgba(42, 11, 85, 0.82));
}

.speaker::before,
.speaker::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.36);
}

.speaker::before {
  top: 4px;
}

.speaker::after {
  bottom: 4px;
}

.speaker-left {
  left: 28px;
}

.speaker-right {
  right: 28px;
}

.chute {
  position: relative;
  margin: -10px auto 0;
  width: 142px;
  height: 158px;
}

.chute-mouth {
  width: 62px;
  height: 18px;
  margin: 0 auto;
  border-radius: 999px;
  background: linear-gradient(180deg, #3f176f, #251047);
  box-shadow: 0 10px 14px rgba(62, 20, 110, 0.22);
}

.dispense-capsule {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 78px;
  height: 78px;
  margin-left: -39px;
  opacity: 0;
  transform: translate3d(0, 0, 0) scale(0.64) rotate(0deg);
  filter: drop-shadow(0 14px 18px rgba(79, 60, 110, 0.18));
}

.dispense-capsule::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    linear-gradient(180deg, var(--dispense-top) 0 48%, var(--dispense-bottom) 48% 100%);
  box-shadow:
    inset 0 6px 10px rgba(255, 255, 255, 0.34),
    inset 0 -8px 12px rgba(190, 102, 12, 0.14),
    0 15px 24px rgba(51, 64, 84, 0.18);
}

.dispense-capsule::after {
  content: "";
  position: absolute;
  left: 9px;
  right: 9px;
  top: 33px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.34);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 1px 0 rgba(180, 104, 15, 0.14);
}

.capsule-top,
.capsule-bottom {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  opacity: 0;
  box-shadow:
    inset 0 6px 10px rgba(255, 255, 255, 0.34),
    0 15px 24px rgba(51, 64, 84, 0.22);
}

.capsule-top {
  clip-path: inset(0 0 50% 0 round 999px 999px 18px 18px);
  background: linear-gradient(180deg, var(--dispense-top), color-mix(in srgb, var(--dispense-top) 68%, #ffffff));
}

.capsule-bottom {
  clip-path: inset(50% 0 0 0 round 18px 18px 999px 999px);
  background: linear-gradient(180deg, color-mix(in srgb, var(--dispense-bottom) 80%, #ffffff), var(--dispense-bottom));
}

.machine-stage[data-state="shaking"] .capsule {
  animation: none;
}

.machine-stage[data-state="dispensing"] .dispense-capsule {
  opacity: 1;
  animation: dispense-roll 1100ms cubic-bezier(.23, .83, .25, 1) forwards;
}

.machine-stage[data-state="revealing"] .dispense-capsule,
.machine-stage[data-state="result"] .dispense-capsule {
  opacity: 0;
}

.machine-stage[data-state="revealing"] .dispense-capsule .capsule-top {
  opacity: 1;
  animation: split-top 600ms ease forwards;
}

.machine-stage[data-state="revealing"] .dispense-capsule .capsule-bottom {
  opacity: 1;
  animation: split-bottom 600ms ease forwards;
}

.machine-stage[data-state="revealing"] .dispense-capsule::before,
.machine-stage[data-state="revealing"] .dispense-capsule::after {
  opacity: 0;
}

@keyframes bob {
  0%, 100% {
    transform: translate(0, 0) rotate(var(--rot));
  }
  50% {
    transform: translate(0, calc(var(--bob-distance) * -1)) rotate(calc(var(--rot) + 3deg));
  }
}

@keyframes rattle {
  0%, 100% {
    transform: translate(-5px, 1px) rotate(calc(var(--rot) - 3deg));
  }
  25% {
    transform: translate(8px, -6px) rotate(calc(var(--rot) + 9deg));
  }
  50% {
    transform: translate(-9px, 5px) rotate(calc(var(--rot) - 8deg));
  }
  75% {
    transform: translate(7px, -4px) rotate(calc(var(--rot) + 7deg));
  }
}

@keyframes shake-roll {
  0% {
    transform: translate(var(--x), var(--y)) rotate(calc(var(--rot) + 0deg));
  }
  25% {
    transform: translate(calc(var(--x) + var(--tx1)), calc(var(--y) + var(--ty1))) rotate(calc(var(--rot) + 90deg));
  }
  50% {
    transform: translate(calc(var(--x) + var(--tx2)), calc(var(--y) + var(--ty2))) rotate(calc(var(--rot) + 180deg));
  }
  75% {
    transform: translate(calc(var(--x) + var(--tx3)), calc(var(--y) + var(--ty3))) rotate(calc(var(--rot) + 270deg));
  }
  100% {
    transform: translate(var(--x), var(--y)) rotate(calc(var(--rot) + 360deg));
  }
}

@keyframes dispense-roll {
  0% {
    opacity: 0;
    transform: translate3d(0, -8px, 0) scale(0.56) rotate(0deg);
  }
  18% {
    opacity: 1;
    transform: translate3d(0, 6px, 0) scale(0.7) rotate(95deg);
  }
  56% {
    opacity: 1;
    transform: translate3d(0, 52px, 0) scale(0.84) rotate(360deg);
  }
  78% {
    opacity: 1;
    transform: translate3d(20px, 78px, 0) scale(1) rotate(560deg);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 102px, 0) scale(1) rotate(720deg);
  }
}

@keyframes split-top {
  to {
    transform: translate(-20px, -38px) rotate(-20deg);
    opacity: 0;
  }
}

@keyframes split-bottom {
  to {
    transform: translate(22px, 34px) rotate(24deg);
    opacity: 0;
  }
}

@media (max-width: 900px) {
  .page-shell {
    padding: 22px 18px 36px;
  }

  .machine-stage {
    min-height: 760px;
  }

  .machine {
    transform: scale(0.82);
    transform-origin: top center;
  }

}

.result-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 220ms ease, visibility 220ms ease;
  z-index: 20;
}

.result-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.result-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 22, 30, 0.66);
  z-index: 0;
}

.result-dialog {
  position: relative;
  width: min(92vw, 760px);
  min-height: 420px;
  display: grid;
  place-items: center;
  text-align: center;
  z-index: 1;
  pointer-events: none;
}

.result-dialog::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 380px;
  height: 380px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 184, 53, 0.5) 0%, transparent 25%),
    radial-gradient(circle at 70% 30%, rgba(133, 221, 111, 0.5) 0%, transparent 22%),
    radial-gradient(circle at 25% 60%, rgba(127, 203, 255, 0.5) 0%, transparent 20%),
    radial-gradient(circle at 75% 65%, rgba(250, 126, 199, 0.5) 0%, transparent 23%),
    radial-gradient(circle at 50% 45%, rgba(216, 141, 255, 0.4) 0%, transparent 30%),
    radial-gradient(circle at 40% 75%, rgba(255, 114, 114, 0.5) 0%, transparent 18%),
    radial-gradient(circle at 60% 20%, rgba(103, 224, 197, 0.5) 0%, transparent 20%),
    radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.6), rgba(241, 248, 252, 0.5) 58%, rgba(211, 229, 240, 0.3) 100%);
  border: 16px solid rgba(255, 255, 255, 0.4);
  box-shadow:
    inset 0 10px 40px rgba(255, 255, 255, 0.5),
    inset 0 -20px 40px rgba(139, 174, 193, 0.15),
    0 40px 80px rgba(54, 95, 122, 0.25);
  filter: blur(6px);
  z-index: -1;
}

.result-capsule-open {
  position: relative;
  width: 200px;
  height: 320px;
}

.result-capsule-top,
.result-capsule-bottom {
  position: absolute;
  left: 50%;
  width: 160px;
  height: 80px;
  margin-left: -80px;
  box-shadow:
    inset 0 6px 16px rgba(255, 255, 255, 0.9),
    inset 0 -4px 10px rgba(180, 120, 0, 0.2),
    0 8px 32px rgba(255, 200, 50, 0.5);
}

.result-capsule-top {
  top: 50%;
  margin-top: -130px;
  border-radius: 80px 80px 0 0;
  transform: translateX(-25px) rotate(-20deg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--result-top) 72%, #ffffff), var(--result-top));
}

.result-capsule-bottom {
  top: 50%;
  margin-top: 50px;
  border-radius: 0 0 80px 80px;
  transform: translateX(25px) rotate(20deg);
  background: linear-gradient(180deg, color-mix(in srgb, var(--result-bottom) 78%, #ffffff), var(--result-bottom));
}

.result-title {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92vw, 860px);
  margin: 0;
  padding: 0 20px;
  transform: translate(-50%, -50%);
  font-size: clamp(2.2rem, 4.2vw, 4.2rem);
  line-height: 1.2;
  font-weight: 900;
  color: #ffffff;
  text-shadow:
    0 0 20px rgba(255, 214, 76, 0.9),
    0 0 40px rgba(255, 214, 76, 0.6),
    0 0 60px rgba(255, 214, 76, 0.4),
    0 4px 12px rgba(0, 0, 0, 0.5),
    0 -1px 2px rgba(255, 255, 255, 0.3);
  z-index: 10;
  pointer-events: auto;
}

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