:root {
  color-scheme: light;
  --ink: #684323;
  --gold: #b77939;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background: #fff4d9;
  color: var(--ink);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: min(280px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  background-color: #fff4d9;
  background-image: url("assets/background-small-gifts.webp");
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #644120; outline-offset: 5px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.app {
  width: min(100%, 440px);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(30px + env(safe-area-inset-top, 0px)) 20px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.wheel-slot { width: 100%; flex: none; }
.wheel-stage { width: 100%; position: relative; flex: none; }
.wheel-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1;
  padding: 8px;
  border: 2px solid #c99551;
  border-radius: 50%;
  background: linear-gradient(145deg, #ffeec1, #e8b862 53%, #ffe7b0);
  box-shadow: 0 7px 0 #bb8040, 0 12px 22px #7c42152b, inset 0 2px 0 #fff9df;
}
.wheel {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff8e9;
  transform-origin: 50% 50%;
  will-change: transform;
}
.pointer {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  width: 40px;
  height: 46px;
  background: #883d2b;
  clip-path: polygon(7% 0, 93% 0, 100% 12%, 54% 100%, 46% 100%, 0 12%);
}
.pointer::after {
  content: "";
  position: absolute;
  inset: 2px 3px 4px;
  background: linear-gradient(#ff9b72, #ed6749 55%, #d64736);
  clip-path: polygon(5% 0, 95% 0, 100% 9%, 50% 100%, 0 9%);
}
.wheel-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 8.5%;
  aspect-ratio: 1;
  border: 2px solid #b88243;
  border-radius: 50%;
  background: radial-gradient(circle at 33% 27%, #fffdf1, #ffd681 70%);
  box-shadow: 0 2px 4px #6d350b3b;
  pointer-events: none;
}
.result-card {
  position: relative;
  width: 100%;
  min-height: 120px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border: 2px solid #dfbe87;
  border-radius: 21px;
  background: #fffdf3;
  box-shadow: 0 4px 0 #ead3aa, 0 7px 15px #a4713020;
}
.mascot-scene {
  width: 100%;
  min-height: 172px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0 4px;
  pointer-events: none;
}
.mascot-character {
  position: relative;
  flex: none;
  width: clamp(147.2px, 46vw, 184px);
  transform: translateY(-6px);
}
.mascot {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 8px 6px #97581e24);
  pointer-events: none;
  user-select: none;
  transform-origin: 55% 88%;
  animation: mugi-sway 3.6s cubic-bezier(.45, 0, .35, 1) infinite;
}
.mascot-bubble {
  position: absolute;
  top: 14px;
  right: 82%;
  transform: translateY(-50px);
  display: block;
  width: 124px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  transform-origin: 80% 85%;
  animation: mugi-bubble-sway 3.6s cubic-bezier(.45, 0, .35, 1) infinite;
}

@keyframes mugi-sway {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  12% { transform: translate(-3px, -1px) rotate(-3deg); }
  28% { transform: translate(3px, -2px) rotate(3deg); }
  42% { transform: translate(-2px, 0) rotate(-2.5deg); }
  56% { transform: translate(3px, -2px) rotate(3.5deg); }
  64%, 78% { transform: translate(1px, -1px) rotate(2.2deg); }
  90% { transform: translate(-2px, 0) rotate(-1.8deg); }
}

@keyframes mugi-bubble-sway {
  0%, 100% { transform: translate(0, -50px) rotate(0deg); }
  12% { transform: translate(-1px, -51px) rotate(-1deg); }
  28% { transform: translate(1px, -53px) rotate(1.2deg); }
  42% { transform: translate(-1px, -50px) rotate(-.8deg); }
  56% { transform: translate(1px, -52px) rotate(1.4deg); }
  64%, 78% { transform: translate(0, -51px) rotate(.8deg); }
  90% { transform: translate(-1px, -50px) rotate(-.6deg); }
}
.result-copy { flex: 1; min-width: 0; text-align: center; }
.result-note { margin: 0 0 8px; color: #896746; font-size: 20px; font-weight: 800; line-height: 1.5; text-wrap: balance; }
.result-text { margin: 0; font-size: 32px; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; text-wrap: balance; }
.result-text span { display: inline-block; }
.result-card:has(.result-image:not([hidden])) .result-copy { padding-inline: 52px; }
.result-image { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; object-fit: contain; }
.result-card.is-winner { border-color: #dda34d; }
.play-buttons { position: relative; z-index: 2; width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 4px; }
.play-button {
  position: relative;
  min-height: 74px;
  padding: 12px 4px;
  border: 3px solid;
  border-radius: 22px;
  color: #fffef2;
  font-size: clamp(23px, 6.4vw, 28px);
  font-weight: 900;
  letter-spacing: .03em;
  text-shadow: 0 2px 0 #865123;
  transition: transform .12s, box-shadow .12s, opacity .12s;
  box-shadow: inset 0 3px 0 #fff3c59c, inset 0 -3px 0 #8d521b1f;
}
.start-button { border-color: #b77a34; background: linear-gradient(#ffd487, #ebb058); box-shadow: 0 6px 0 #ab7032, inset 0 3px 0 #fff4d3, inset 0 -3px 0 #d99940; }
.stop-button { border-color: #b5573b; background: linear-gradient(#ffa486, #f07b5e); box-shadow: 0 6px 0 #a44d32, inset 0 3px 0 #ffe0c5, inset 0 -3px 0 #d76d51; }
.play-button:not(:disabled):active { transform: translateY(4px); box-shadow: 0 2px 0 #9d6636, inset 0 2px 0 #ffffff75; }
.play-button:disabled { opacity: .44; filter: saturate(.55); text-shadow: 0 1px 0 #986f4b; }
.noscript { border-radius: 10px; padding: 12px; background: #fffaf0; }

@media (max-width: 350px) {
  .app { padding-left: 16px; padding-right: 16px; padding-top: calc(26px + env(safe-area-inset-top, 0px)); gap: 15px; }
  .wheel-frame { padding: 6px; }
  .result-card { min-height: 156px; padding: 14px; }
  .mascot-scene { min-height: 140px; }
  .mascot-bubble { top: 22px; right: 80%; width: 104px; }
  .result-image { width: 44px; height: 44px; }
  .play-buttons { gap: 12px; }
  .play-button { min-height: 64px; border-radius: 19px; }
}
@media (min-width: 650px) {
  body { background-size: auto 100%; background-repeat: no-repeat; }
  .app { width: 410px; }
}
@media (max-width: 300px) {
  .mascot-bubble { right: 75%; width: 88px; }
}

/* Reserve space for readable results, tap targets and Mugi, then size the wheel
   from the remaining small viewport height (including mobile browser bars). */
@media (max-width: 649px) {
  .app {
    --page-top: 24px;
    --page-bottom: 12px;
    --layout-gap: 12px;
    --result-space: 96px;
    --button-space: 68px;
    --mugi-size: clamp(96px, 18svh, 156px);
    width: min(100%, 440px);
    height: 100svh;
    min-height: 440px;
    padding: calc(var(--page-top) + env(safe-area-inset-top, 0px)) 16px calc(var(--page-bottom) + env(safe-area-inset-bottom, 0px));
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto var(--button-space) calc(var(--mugi-size) + 38px);
    justify-items: center;
    align-items: center;
    gap: var(--layout-gap);
  }
  .wheel-stage {
    width: min(100%, calc(100svh - var(--page-top) - var(--page-bottom) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - var(--layout-gap) * 3 - var(--result-space) - var(--button-space) - var(--mugi-size) - 38px));
    align-self: center;
  }
  .wheel-slot { height: 100%; min-height: 0; display: grid; place-items: center; container-type: size; }
  @supports (width: 1cqh) {
    .wheel-stage { width: min(100cqw, 100cqh); }
  }
  .result-card { min-height: var(--result-space); padding: 8px 10px; }
  .result-note { margin-bottom: 4px; line-height: 1.3; }
  .play-buttons { margin-bottom: 0; gap: 12px; }
  .play-button { min-height: var(--button-space); height: var(--button-space); padding: 8px 4px; }
  .mascot-scene { min-height: 0; height: 100%; padding: 36px 0 2px; flex: none; }
  .mascot-character { width: var(--mugi-size); }
  .mascot-bubble { top: 14px; right: 82%; width: clamp(84px, calc(var(--mugi-size) * .68), 108px); }
}
@media (max-width: 350px) {
  .app { --result-space: 96px; }
  .result-text { font-size: 28px; }
  .result-image { right: 10px; width: 40px; height: 40px; }
  .result-card:has(.result-image:not([hidden])) .result-copy { padding-inline: 40px; }
  .result-card:has(.result-image:not([hidden])) .result-note { font-size: 16px; }
}
@media (max-width: 649px) and (max-height: 620px) {
  .app { --page-top: 22px; --page-bottom: 8px; --layout-gap: 8px; --button-space: 64px; --mugi-size: clamp(80px, 16svh, 104px); }
}
@media (max-width: 649px) and (max-height: 500px) {
  .app { --page-top: 20px; --page-bottom: 4px; --layout-gap: 6px; --button-space: 60px; --mugi-size: 76px; }
}
@media (prefers-reduced-motion: reduce) {
  .play-button { transition: none; }
  .mascot, .mascot-bubble { animation: none; }
}

/* Result animation names are isolated from the roulette and mascot styles. */
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.result-animation-dialog { width: min(480px, 100%); max-width: none; max-height: calc(100svh - 12px); padding: 12px 18px 18px; border: 0; margin: auto; background: transparent; color: #725035; overflow: auto; font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", sans-serif; }
.result-animation-dialog::backdrop { background: #68432380; }
body:has(.result-animation-dialog[open]) { overflow: hidden; }
.result-animation-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.result-animation-close { display: grid; place-items: center; flex: none; width: 64px; height: 64px; padding: 0; border: 2px solid #c99551; border-radius: 50%; background: #fff9ed; color: #684323; }
.result-animation-close svg { display: block; }
.result-animation-navigation { padding-top: 14px; text-align: center; }
.result-animation-navigation a { display: flex; justify-content: center; align-items: center; min-height: 48px; padding: 10px 14px; border: 2px solid #b8823e; border-radius: 16px; background: linear-gradient(#ffdc92, #efb760); color: #684323; font-size: 16px; font-weight: 800; text-decoration: none; }
.result-animation-navigation a:focus-visible { outline: 3px solid #644120; outline-offset: 3px; }
.result-animation-stage { position: relative; isolation: isolate; width: 100%; height: clamp(330px, 101vw, 410px); overflow: hidden; border: 2px solid #deb975; border-radius: 28px; background: radial-gradient(ellipse at 50% 40%, #fffdf2 0%, #fff4d7 70%, #ffebbb 100%); box-shadow: 0 6px 0 #e3c99d, inset 0 2px 0 #fff; }
.result-animation-stage[data-result="miss"] { background: radial-gradient(ellipse at 50% 45%, #fffdf5, #f6eddf); }
.result-animation-stage[data-result="chocolate"], .result-animation-stage[data-result="coffee"] { min-height: 410px; }
.result-animation-win-scene, .result-animation-miss-scene { position: absolute; inset: 0; }
.result-animation-win-title, .result-animation-miss-title { position: absolute; z-index: 4; display: block; object-fit: contain; height: auto; }
.result-animation-win-title { width: 90%; left: 5%; top: 28px; }
.result-animation-miss-title { width: 68%; left: 16%; top: 30px; }
.result-animation-halo { position: absolute; width: 230px; height: 230px; left: 50%; top: 44%; transform: translate(-50%, -40%); border-radius: 50%; background: radial-gradient(circle, #ffd56c70, #ffdf8b30 55%, transparent 72%); }
.result-animation-prize-wrap { position: absolute; z-index: 3; inset: calc(37% - 10px) 0 auto; text-align: center; }
.result-animation-prize-tilt { width: clamp(128px, 40vw, 168px); height: clamp(128px, 40vw, 168px); margin: auto; }
.result-animation-stage[data-result="chocolate"] .result-animation-prize-tilt { transform: rotate(8deg); }
.result-animation-prize { display: block; width: clamp(128px, 40vw, 168px); height: clamp(128px, 40vw, 168px); object-fit: contain; margin: auto; filter: drop-shadow(0 8px 5px #aa712429); }
.result-animation-prize-label { margin: 12px 0 0; font-size: 28px; font-weight: 800; line-height: 1.1; white-space: pre-line; text-align: center; color: #9c6533; }
.result-animation-popper-wrap { position: absolute; z-index: 3; width: 24%; bottom: 28px; }
.result-animation-popper-wrap.result-animation-left { left: 10px; }
.result-animation-popper-wrap.result-animation-right { right: 10px; transform: scaleX(-1); }
.result-animation-popper { display: block; width: 100%; height: auto; transform-origin: 20% 85%; filter: drop-shadow(0 5px 3px #ab76282b); }
.result-animation-confetti { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.result-animation-skull-wrap { position: absolute; z-index: 3; width: 43%; left: 28.5%; top: 39%; transform-origin: 50% 50%; }
.result-animation-skull { width: 100%; height: auto; display: block; filter: drop-shadow(0 7px 4px #9b6a3325); }
.result-animation-tear { position: absolute; top: 53%; width: 12px; height: 18px; border-radius: 70% 35% 60% 60%; background: linear-gradient(135deg, #e6f9ff, #98c6d4 60%, #76b4c6); box-shadow: inset 2px 2px 0 #ffffff90; opacity: 0; }
.result-animation-tear.result-animation-left { left: 17%; transform: rotate(-15deg); }
.result-animation-tear.result-animation-right { right: 17%; transform: rotate(15deg); }
.result-animation-encouragement { position: absolute; bottom: 22px; width: 100%; margin: 0; text-align: center; font-size: 28px; font-weight: 800; line-height: 1.2; white-space: nowrap; color: #8d7862; }
.result-animation-playing .result-animation-win-title, .result-animation-playing .result-animation-miss-title { animation: result-animation-chocolate-title-bounce calc(.75s / var(--motion-speed, 1)) ease-out both; }
.result-animation-playing .result-animation-prize-wrap, .result-animation-playing .result-animation-skull-wrap { animation: result-animation-chocolate-prize-bounce calc(1.15s / var(--motion-speed, 1)) calc(.2s / var(--motion-speed, 1)) ease-out both; }
.result-animation-playing .result-animation-prize, .result-animation-playing .result-animation-skull { transform-origin: 50% 100%; animation: result-animation-chocolate-squash calc(1.15s / var(--motion-speed, 1)) calc(.2s / var(--motion-speed, 1)) ease-out both; }
.result-animation-playing .result-animation-popper { animation: result-animation-chocolate-popper-bounce calc(.7s / var(--motion-speed, 1)) calc(.25s / var(--motion-speed, 1)) ease-out both; }
.result-animation-playing .result-animation-tear.result-animation-left { animation: result-animation-tear-fall calc(1.15s / var(--motion-speed, 1)) calc(.65s / var(--motion-speed, 1)) ease-in 2; }
.result-animation-playing .result-animation-tear.result-animation-right { animation: result-animation-tear-fall calc(1.15s / var(--motion-speed, 1)) calc(1s / var(--motion-speed, 1)) ease-in 2; }
.result-animation-playing .result-animation-encouragement { animation: result-animation-gentle-enter calc(.7s / var(--motion-speed, 1)) calc(1.1s / var(--motion-speed, 1)) ease-out both; }
@keyframes result-animation-chocolate-title-bounce {
  0% { opacity: 0; transform: translateY(26px) scale(.6) rotate(-4deg); }
  30% { opacity: 1; transform: translateY(-10px) scale(1.1) rotate(1.5deg); }
  54% { transform: translateY(5px) scale(1.04, .96) rotate(-1deg); }
  72% { transform: translateY(-4px) scale(1.02) rotate(.5deg); }
  86% { transform: translateY(2px) scale(1, .99); }
  100% { opacity: 1; transform: none; }
}
@keyframes result-animation-chocolate-prize-bounce {
  0% { opacity: 0; transform: translateY(32px) scale(.75) rotate(-6deg); }
  18% { opacity: 1; transform: translateY(-24px) scale(1.06) rotate(3deg); }
  38% { transform: translateY(8px) rotate(-2deg); }
  56% { transform: translateY(-14px) scale(1.03) rotate(2deg); }
  72% { transform: translateY(4px) rotate(-1deg); }
  86% { transform: translateY(-5px) rotate(.5deg); }
  100% { opacity: 1; transform: none; }
}
@keyframes result-animation-chocolate-squash {
  0%, 100% { transform: scale(1); }
  18% { transform: scale(.94, 1.08); }
  38% { transform: scale(1.13, .87); }
  56% { transform: scale(.97, 1.05); }
  72% { transform: scale(1.07, .94); }
  86% { transform: scale(.99, 1.02); }
}
@keyframes result-animation-chocolate-popper-bounce {
  0% { transform: scale(.9) rotate(-8deg); }
  30% { transform: translateY(-6px) scale(1.1) rotate(8deg); }
  55% { transform: translate(-5px, 6px) scale(.91) rotate(-6deg); }
  76% { transform: translateY(-2px) scale(1.03) rotate(2deg); }
  100% { transform: none; }
}
@keyframes result-animation-tear-fall { 0% { opacity: 0; transform: translateY(-5px) scale(.5); } 20% { opacity: .85; } 85% { opacity: .75; } 100% { opacity: 0; transform: translateY(52px) scale(.7); } }
@keyframes result-animation-gentle-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (max-width: 350px) {
  .result-animation-dialog { padding-left: 12px; padding-right: 12px; }
  .result-animation-win-title { top: 26px; }
  .result-animation-encouragement { bottom: 20px; letter-spacing: -.1em; }
}
@media (prefers-reduced-motion: reduce) {
  .result-animation-playing * { animation: none !important; }
  .result-animation-confetti, .result-animation-tear { display: none; }
}
