:root {
  --ink: #76504c;
  --pink: #f45778;
  --pink-dark: #d83b63;
  --cream: #fff3eb;
  --stage-ratio: 0.4625813449;
}

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

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: #f8aec0;
}

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "荆南麦圆体", "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  overscroll-behavior: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.game-shell {
  width: min(100vw, calc(100dvh * var(--stage-ratio)), 426.5px);
  max-width: 100%;
  line-height: 1.35;
}

.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 853 / 1844;
  overflow: hidden;
  background: #f7a7b9;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

.game-background {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.reward-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.back-button {
  position: absolute;
  z-index: 10;
  left: 0.8%;
  top: 0.7%;
  width: 14.4%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.back-button img {
  display: block;
  width: 71%;
  height: 71%;
}

.back-button:active img {
  transform: translateY(1px) scale(0.95);
}

.music-toggle {
  position: absolute;
  z-index: 10;
  right: 2.2%;
  top: 1.5%;
  width: 9.54%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #ff7f9d;
  color: #fff;
  box-shadow: 2px 4px 0 #d96b71, 0 4px 12px rgb(126 58 74 / 24%);
  cursor: pointer;
  touch-action: manipulation;
}

.music-toggle svg {
  width: 65%;
  height: 65%;
  overflow: visible;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.music-speaker {
  stroke: #dc5774;
  stroke-width: 1.5;
}

.music-sound-waves,
.music-muted-slash {
  fill: none;
}

.music-muted-slash {
  display: none;
}

.music-toggle[aria-pressed="false"] {
  background: #b9a6a7;
  box-shadow: 2px 4px 0 #806d70, 0 4px 12px rgb(74 53 59 / 20%);
}

.music-toggle[aria-pressed="false"] .music-sound-waves {
  display: none;
}

.music-toggle[aria-pressed="false"] .music-muted-slash {
  display: block;
}

.music-toggle:active {
  transform: translateY(2px) scale(0.95);
  box-shadow: 1px 2px 0 #d96b71;
}

.reward-item {
  position: absolute;
  border-radius: 24%;
  pointer-events: none;
}

.reward-icon {
  position: absolute;
  left: 50%;
  top: var(--icon-top, 17%);
  width: var(--icon-width, 66%);
  height: var(--icon-height, 66%);
  object-fit: contain;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 2px rgb(153 73 83 / 22%));
  transition: filter 220ms ease, opacity 220ms ease, transform 220ms ease;
}

.quantity-badge {
  position: absolute;
  right: 6%;
  bottom: 6%;
  min-width: 46%;
  height: 26%;
  display: grid;
  place-items: center;
  padding: 0 5px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #e25a5c;
  color: #fff;
  font-family: "AlibabaHealthFont2.0CN", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1;
  text-shadow: 0 1px 1px rgb(128 33 42 / 45%);
  box-shadow: 0 2px 3px rgb(124 47 58 / 18%);
}

.obtained-mask {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgb(82 43 48 / 40%);
  opacity: 0;
  transition: opacity 220ms ease;
}

.obtained-mask img {
  position: absolute;
  top: 6%;
  right: 6%;
  width: 24%;
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 1px 2px rgb(35 25 28 / 45%));
}

.reward-item.is-obtained .reward-icon {
  filter: grayscale(0.35) brightness(0.82);
  opacity: 0.86;
}

.reward-item.is-obtained .obtained-mask {
  opacity: 1;
}

.reward-item.is-grand.is-ready {
  animation: grand-ready 1.2s ease-in-out infinite alternate;
}

.reward-item.is-new .reward-icon {
  animation: reward-pop 650ms cubic-bezier(.2, .9, .25, 1.35);
}

.reward-item.is-marquee-active {
  z-index: 3;
  box-shadow:
    inset 0 0 0 2px #fff,
    inset 0 0 0 5px #ffd951,
    0 0 12px 4px rgb(255 222 83 / 88%);
  transform: scale(1.035);
  transition: transform 55ms ease-out, box-shadow 55ms ease-out;
}

.reward-item.is-marquee-active .reward-icon {
  filter: brightness(1.16) drop-shadow(0 0 5px rgb(255 231 91 / 95%));
}

.reward-item.is-marquee-final {
  box-shadow:
    inset 0 0 0 3px #fff,
    inset 0 0 0 7px #ffbd2e,
    0 0 18px 7px rgb(255 207 53 / 95%);
  transform: scale(1.075);
  animation: marquee-final-pulse 260ms ease-in-out infinite alternate;
}

.stage-hotspot {
  position: absolute;
  z-index: 5;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 45%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.draw-hotspot {
  left: 23.9%;
  top: 76.2%;
  width: 52.2%;
  height: 9.9%;
  border-radius: 22% / 44%;
}

.draw-hotspot::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: url("../assets/images/bg_game.png") 50% 84.5738% / 191.5709% 1010.101% no-repeat;
  opacity: 0;
  pointer-events: none;
  transform-origin: center;
  will-change: transform, opacity;
}

.draw-hotspot.is-click-animating::before {
  animation: draw-button-press 260ms cubic-bezier(.22, .8, .28, 1) both;
}

.add-coin-hotspot {
  left: 64.1%;
  top: 86.6%;
  width: 7.8%;
  height: 4.2%;
  border-radius: 50%;
}

.stage-hotspot:active:not(:disabled) {
  background: rgb(255 255 255 / 14%);
}

.stage-hotspot:disabled {
  cursor: default;
}

.game-stage.is-complete .draw-hotspot {
  background: rgb(91 62 65 / 32%);
  box-shadow: inset 0 0 0 2px rgb(255 255 255 / 24%);
}

.completion-banner {
  position: absolute;
  z-index: 6;
  left: 29%;
  top: 49.2%;
  width: 42%;
  padding: 7px 8px;
  border: 2px solid #fff;
  border-radius: 16px;
  background: linear-gradient(#fff7cf, #ffd36d);
  color: #b84d49;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  box-shadow: 0 4px 0 #e48468, 0 7px 16px rgb(111 45 45 / 25%);
}

.completion-banner span {
  display: block;
  white-space: nowrap;
}

.machine-window {
  position: absolute;
  z-index: 3;
  left: 32.1%;
  top: 41.75%;
  width: 35.8%;
  height: 20.2%;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  clip-path: polygon(10% 6%, 88% 2%, 100% 28%, 94% 84%, 82% 100%, 14% 100%, 0 82%, 1% 25%);
}

.machine-motion {
  position: absolute;
  inset: 0;
  transform-origin: 50% 70%;
}

.machine-motion img {
  position: absolute;
  left: -89.9%;
  top: -206.8%;
  width: 279.7%;
  height: auto;
  max-width: none;
}

.machine-glow {
  position: absolute;
  z-index: 4;
  left: 35.5%;
  top: 43.6%;
  width: 29%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(255 255 219 / 85%) 0 15%, rgb(255 235 130 / 34%) 38%, transparent 70%);
  opacity: 0;
  pointer-events: none;
}

.capsule-pop {
  position: absolute;
  z-index: 6;
  left: 46.2%;
  top: 57.3%;
  width: 7.5%;
  aspect-ratio: 1;
  border: 2px solid rgb(255 255 255 / 90%);
  border-radius: 50%;
  background: linear-gradient(155deg, #fff 0 47%, #f77da1 48% 100%);
  box-shadow: 0 3px 6px rgb(102 42 51 / 30%);
  opacity: 0;
  pointer-events: none;
}

.capsule-pop span {
  position: absolute;
  left: 5%;
  right: 5%;
  top: 47%;
  height: 2px;
  background: rgb(190 73 101 / 55%);
}

.game-stage.is-drawing .machine-window {
  opacity: 1;
}

.game-stage.is-drawing .machine-motion {
  animation: machine-shake 760ms ease-in-out;
}

.game-stage.is-drawing .machine-glow {
  animation: glow-flash 850ms ease-out 240ms;
}

.game-stage.is-drawing .capsule-pop {
  animation: capsule-eject 720ms cubic-bezier(.18, .88, .28, 1.25) 540ms both;
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(0 0 0 / 79%);
  animation: fade-in 180ms ease-out;
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: 83.7%;
  min-height: 40.7%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7.5% 7% 5%;
  background: url("../assets/ui/popup-panel.svg") center / 100% 100% no-repeat;
  animation: panel-enter 340ms cubic-bezier(.18, .9, .22, 1.15);
}

.modal-panel h2 {
  max-width: 86%;
  margin: 0;
  color: #7a6362;
  font-size: 22px;
  line-height: 1.2;
  text-align: center;
  text-shadow: 1px 1px 0 #fff;
}

.modal-close {
  position: absolute;
  top: -1%;
  right: -1%;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.modal-close img {
  display: block;
  width: 100%;
  height: 100%;
}

.modal-coin {
  width: 40%;
  aspect-ratio: 1;
  margin-top: 3%;
  object-fit: contain;
  filter: drop-shadow(0 5px 5px rgb(91 61 63 / 18%));
}

.modal-question {
  margin: -1% 0 3%;
  font-size: 18px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #fff;
}

.insufficient-panel h2 {
  font-size: 18px;
}

.insufficient-panel .modal-question {
  font-size: 15px;
}

.insufficient-panel .pink-action {
  font-size: 16px;
}

.pink-action {
  position: relative;
  width: 64%;
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border: 0;
  background: url("../assets/ui/popup-button.svg") center / 100% 100% no-repeat;
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 0 2px 1px rgb(194 47 74 / 45%);
  cursor: pointer;
}

.pink-action img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.pink-action:disabled {
  filter: saturate(0.55);
  cursor: wait;
}

.ad-remaining {
  margin: 4px 0 0;
  font-size: 14px;
  font-weight: 700;
}

.reward-panel {
  justify-content: flex-start;
  min-height: 42%;
}

.reward-result-image-wrap {
  position: relative;
  width: 45%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin-top: 3%;
}

.reward-result-image-wrap img {
  position: relative;
  z-index: 1;
  max-width: 86%;
  max-height: 86%;
  object-fit: contain;
  filter: drop-shadow(0 5px 4px rgb(121 67 71 / 25%));
  animation: reward-result-enter 520ms cubic-bezier(.18, .9, .25, 1.35) 100ms both;
}

.reward-halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgb(255 226 105 / 0%) 0deg 10deg, rgb(255 226 105 / 52%) 10deg 20deg);
  mask: radial-gradient(circle, transparent 0 35%, #000 36% 70%, transparent 71%);
  opacity: 0.7;
  animation: halo-spin 6s linear infinite;
}

.reward-result-name {
  width: 92%;
  margin: 0 0 3%;
  color: #7a5050;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.reward-confirm {
  width: 54%;
  min-height: 50px;
  margin-top: auto;
}

.reward-panel.is-grand h2 {
  color: #e24d65;
  font-size: 21px;
}

.reward-panel.is-grand .reward-result-image-wrap {
  width: 51%;
}

.celebration-stars {
  position: absolute;
  inset: 8% 7% 18%;
  pointer-events: none;
  opacity: 0;
}

.reward-panel.is-grand .celebration-stars {
  opacity: 1;
}

.celebration-stars i {
  position: absolute;
  width: 12px;
  aspect-ratio: 1;
  background: #ffd768;
  clip-path: polygon(50% 0, 62% 35%, 100% 50%, 62% 65%, 50% 100%, 38% 65%, 0 50%, 38% 35%);
  animation: star-twinkle 900ms ease-in-out infinite alternate;
}

.celebration-stars i:nth-child(1) { left: 5%; top: 20%; }
.celebration-stars i:nth-child(2) { right: 8%; top: 9%; animation-delay: 180ms; }
.celebration-stars i:nth-child(3) { left: 14%; bottom: 12%; animation-delay: 320ms; }
.celebration-stars i:nth-child(4) { right: 4%; bottom: 20%; animation-delay: 450ms; }
.celebration-stars i:nth-child(5) { left: 42%; top: 1%; animation-delay: 580ms; }
.celebration-stars i:nth-child(6) { right: 32%; bottom: 2%; animation-delay: 720ms; }

.toast {
  position: absolute;
  z-index: 40;
  left: 50%;
  top: 64%;
  max-width: 78%;
  transform: translate(-50%, -50%);
  padding: 9px 15px;
  border: 2px solid rgb(255 255 255 / 75%);
  border-radius: 999px;
  background: rgb(91 60 62 / 92%);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 5px 18px rgb(0 0 0 / 22%);
  animation: toast-enter 200ms ease-out;
}

.debug-tools {
  position: fixed;
  z-index: 100;
  right: max(10px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  width: min(292px, calc(100vw - 20px));
  color: #f7f7f7;
  font-family: Consolas, "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

.debug-toggle {
  display: block;
  min-width: 68px;
  height: 34px;
  margin-left: auto;
  border: 1px solid #87f2c0;
  border-radius: 5px;
  background: #18221e;
  color: #87f2c0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: 0 3px 12px rgb(0 0 0 / 35%);
}

.debug-panel {
  margin-bottom: 7px;
  padding: 12px;
  border: 1px solid #53615b;
  border-radius: 6px;
  background: rgb(24 29 27 / 96%);
  box-shadow: 0 8px 28px rgb(0 0 0 / 42%);
  backdrop-filter: blur(7px);
}

.debug-heading {
  margin-bottom: 7px;
  color: #87f2c0;
  font-size: 13px;
  font-weight: 700;
}

.debug-status {
  margin-bottom: 10px;
  color: #d8dedb;
  font-size: 11px;
  line-height: 1.5;
}

.debug-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.debug-actions button {
  min-width: 0;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid #53615b;
  border-radius: 4px;
  background: #303a36;
  color: #fff;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: 0;
}

.debug-actions button:active {
  background: #46534d;
}

.debug-actions button.is-confirming {
  border-color: #ffc466;
  background: #5a421f;
  color: #fff1ce;
}

.debug-actions button:disabled {
  opacity: 0.45;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@keyframes reward-pop {
  0% { transform: translateX(-50%) scale(0.72); }
  55% { transform: translateX(-50%) scale(1.14); }
  100% { transform: translateX(-50%) scale(1); }
}

@keyframes grand-ready {
  from { filter: drop-shadow(0 0 2px rgb(255 224 84 / 30%)); }
  to { filter: drop-shadow(0 0 11px rgb(255 219 80 / 88%)); }
}

@keyframes marquee-final-pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.16); }
}

@keyframes draw-button-press {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  38% {
    opacity: 1;
    transform: scale(1.06);
  }
  72% {
    opacity: 1;
    transform: scale(0.985);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes machine-shake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  15% { transform: rotate(-2.4deg) translateX(-1.5%); }
  30% { transform: rotate(2.6deg) translateX(1.7%); }
  45% { transform: rotate(-2deg) translateX(-1.2%); }
  60% { transform: rotate(1.7deg) translateX(1%); }
  78% { transform: rotate(-0.8deg); }
}

@keyframes glow-flash {
  0%, 100% { opacity: 0; transform: scale(0.7); }
  45% { opacity: 1; transform: scale(1.18); }
}

@keyframes capsule-eject {
  0% { opacity: 0; transform: translateY(-45%) scale(0.3) rotate(0deg); }
  22% { opacity: 1; }
  70% { opacity: 1; transform: translateY(105%) scale(1.05) rotate(300deg); }
  100% { opacity: 0; transform: translateY(142%) scale(0.88) rotate(390deg); }
}

@keyframes fade-in { from { opacity: 0; } }

@keyframes panel-enter {
  from { opacity: 0; transform: translateY(18px) scale(0.88); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes reward-result-enter {
  from { opacity: 0; transform: scale(0.45) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes halo-spin { to { transform: rotate(360deg); } }

@keyframes star-twinkle {
  from { opacity: 0.35; transform: scale(0.65) rotate(0); }
  to { opacity: 1; transform: scale(1.25) rotate(45deg); }
}

@keyframes toast-enter {
  from { opacity: 0; transform: translate(-50%, -40%) scale(0.9); }
}

@media (max-height: 680px) and (orientation: portrait) {
  .game-shell {
    width: min(100vw, calc(100dvh * var(--stage-ratio)));
  }
}

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