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

:root {
  --bg: #eef3df;
  --bg-warm: #f7f1e1;
  --green-deep: #4f6330;
  --green-main: #647e3a;
  --green-soft: #9cad73;
  --card: rgba(248, 251, 241, 0.7);
  --text: #2b1d11;
  --subtext: #6c5a40;
  --button-0: #dfe7b7;
  --button-1: #9cad73;
  --button-2: #647e3a;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(100, 126, 58, 0.18), transparent 24%),
    radial-gradient(circle at top right, rgba(157, 173, 115, 0.16), transparent 22%),
    radial-gradient(circle at bottom right, rgba(217, 163, 84, 0.12), transparent 30%),
    linear-gradient(180deg, var(--bg) 0%, #f2f5e6 56%, var(--bg-warm) 100%);
}

img,
video {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
}

.hidden {
  display: none !important;
}

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

.machine-card {
  width: min(100%, 760px);
  display: grid;
  gap: 18px;
  justify-items: center;
  padding: 18px;
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(251, 253, 246, 0.82), rgba(239, 245, 225, 0.78));
  border: 1px solid rgba(100, 126, 58, 0.18);
  box-shadow: 0 24px 50px rgba(71, 47, 20, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.28) inset;
  backdrop-filter: blur(12px);
}

.machine-stage {
  position: relative;
  width: 100%;
  border-radius: 26px;
  overflow: hidden;
  border: 1px solid rgba(79, 99, 48, 0.26);
  box-shadow:
    0 16px 28px rgba(69, 44, 18, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.2) inset;
  aspect-ratio: 0.69;
  background: linear-gradient(180deg, #f5e7b8, #e0d5a9);
}

.machine-poster,
.machine-gif,
.machine-video,
.stage-glow {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  background: #d8c98d;
}

.machine-poster {
  z-index: 1;
}

.machine-gif {
  z-index: 2;
  opacity: 0;
  transition: opacity 0.18s ease;
  will-change: opacity;
}

.machine-video {
  z-index: 2;
  opacity: 0;
  transition: opacity 0.18s ease;
  will-change: opacity;
}

.machine-stage.playing .machine-video.ready {
  opacity: 1;
}

.machine-stage.fallback .machine-gif {
  opacity: 1;
}

.machine-stage.fallback .machine-video {
  opacity: 0 !important;
}

.machine-stage.fallback .machine-poster {
  animation: posterPulse 1.6s ease-in-out infinite;
  filter: saturate(1.08) brightness(1.03);
}

.machine-stage.fallback::after {
  content: "抽奖进行中";
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 4;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  color: #fdfcf2;
  background: rgba(79, 99, 48, 0.82);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.12em;
  box-shadow: 0 8px 18px rgba(34, 23, 11, 0.18);
  animation: labelFloat 1.6s ease-in-out infinite;
}

.stage-glow {
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at center, rgba(157, 173, 115, 0.18), transparent 36%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.2), transparent 60%);
  transition: opacity 0.18s ease;
}

.machine-stage.playing .stage-glow {
  opacity: 1;
}

.draw-btn {
  width: min(100%, 420px);
  height: 66px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--button-0), var(--button-1) 54%, var(--button-2));
  color: #f8f6ea;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.12em;
  box-shadow: 0 10px 0 #40501f, 0 18px 24px rgba(72, 41, 14, 0.16);
}

.draw-btn:active {
  transform: translateY(4px);
  box-shadow: 0 6px 0 #40501f, 0 12px 18px rgba(72, 41, 14, 0.16);
}

.draw-btn:disabled {
  opacity: 0.58;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(18px);
  min-width: min(92vw, 420px);
  max-width: calc(100vw - 24px);
  padding: 12px 16px;
  border-radius: 999px;
  background: rgba(48, 61, 25, 0.86);
  color: #fff8e7;
  text-align: center;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(25, 31, 13, 0.58);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: min(100%, 520px);
  padding: 28px 22px 22px;
  border-radius: 32px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(253, 255, 247, 0.98), rgba(240, 245, 228, 0.98));
  box-shadow: 0 30px 70px rgba(34, 23, 11, 0.36);
  overflow: hidden;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: rgba(122, 77, 31, 0.12);
  color: var(--green-deep);
  font-size: 24px;
}

.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(100, 126, 58, 0.14);
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.result-emoji {
  font-size: 56px;
  margin-bottom: 10px;
}

.modal-card h3 {
  margin: 0;
  font-size: 26px;
}

.modal-card p {
  margin: 10px 0 0;
  color: var(--subtext);
  line-height: 1.7;
}

.result-prize,
.result-code {
  margin: 16px auto 0;
  width: fit-content;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 18px;
  background: rgba(100, 126, 58, 0.12);
  color: var(--green-deep);
  font-weight: 800;
}

.modal-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.share-btn,
.again-btn {
  height: 48px;
  border: 0;
  border-radius: 999px;
  font-weight: 800;
}

.share-btn {
  background: linear-gradient(180deg, #9cad73, #647e3a);
  color: #fff;
}

.again-btn {
  background: rgba(100, 126, 58, 0.1);
  color: var(--green-deep);
}

@media (max-width: 640px) {
  .page {
    padding: 12px;
  }

  .machine-card {
    padding: 14px;
    border-radius: 24px;
  }

  .draw-btn {
    height: 60px;
    font-size: 17px;
  }

  .result-emoji {
    font-size: 50px;
  }
}

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

@keyframes labelFloat {
  0%, 100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-4px);
  }
}
