html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
}

.play,
.play * {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.play {
  --pad-top: max(6px, env(safe-area-inset-top, 0px));
  --pad-x: max(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --pad-bot: max(8px, env(safe-area-inset-bottom, 0px));
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "voice" "stage" "dock";
  gap: 6px;
  width: min(100%, 430px);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: var(--pad-top) var(--pad-x) var(--pad-bot);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(8px, env(safe-area-inset-right, 0px));
  z-index: 8;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  box-shadow: var(--ak-shadow);
  cursor: pointer;
  touch-action: manipulation;
}

.mute-icon {
  width: 22px;
  height: 22px;
}

.mute-x {
  display: none;
}

.mute.is-muted .mute-wave {
  display: none;
}

.mute.is-muted .mute-x {
  display: block;
}

.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding-right: 52px;
}

.play-logo {
  display: block;
  width: auto;
  height: 44px;
  max-width: 46%;
  object-fit: contain;
}

.turn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 48px;
  margin: 0 0 0 auto;
  padding: 4px 12px 4px 4px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
}

.turn.is-you {
  box-shadow: var(--ak-shadow), 0 0 0 2px var(--ak-accent), 0 0 12px var(--ak-glow);
}

.turn.is-cpu {
  box-shadow: var(--ak-shadow), 0 0 0 2px var(--ak-accent-2), 0 0 12px var(--ak-glow);
}

.turn-marble {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.voice,
.why {
  margin: 0;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
  font-size: 15px;
  line-height: 1.3;
}

.voice {
  grid-area: voice;
}

.why {
  position: relative;
  z-index: 6;
}

.stage {
  grid-area: stage;
  container-type: size;
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  touch-action: manipulation;
}

.board {
  position: relative;
  width: min(100cqw, calc(100cqh * 359 / 384));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 359 / 384;
  touch-action: manipulation;
  cursor: pointer;
}

.star {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
}

.holes,
.burst,
.bloom {
  position: absolute;
  inset: 0;
}

.holes {
  z-index: 4;
}

.bloom {
  z-index: 3;
  pointer-events: none;
}

.bloom img {
  position: absolute;
  left: var(--bx, 50%);
  top: var(--by, 40%);
  width: 46%;
  height: auto;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.burst {
  z-index: 6;
  overflow: hidden;
  pointer-events: none;
}

.hole {
  position: absolute;
  width: var(--hole, 7.6%);
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
  pointer-events: none;
  cursor: pointer;
}

.pit {
  position: absolute;
  left: 50%;
  top: 54%;
  width: 46%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ak-ink) 78%, var(--ak-bg));
  box-shadow:
    0 0 0 2px var(--ak-accent),
    inset 0 3px 0 color-mix(in srgb, var(--ak-ink) 45%, transparent);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 168%;
  height: auto;
  transform: translate(-50%, -50%) scale(0.92);
  opacity: 0;
  pointer-events: none;
}

.hole.is-glow .ring,
.hole.is-bloom .ring {
  opacity: 1;
}

.spark {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 80%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--ak-accent) 0%, transparent 70%);
  box-shadow: 0 0 10px var(--ak-glow);
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0;
  pointer-events: none;
}

.marble {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 128%;
  height: auto;
  transform: translate(-50%, -62%);
  pointer-events: none;
  filter: drop-shadow(0 2px 0 color-mix(in srgb, var(--ak-ink) 40%, transparent));
}

.hole.is-picked .marble {
  filter:
    drop-shadow(0 3px 0 color-mix(in srgb, var(--ak-ink) 40%, transparent))
    drop-shadow(0 0 6px var(--ak-accent));
}

.hole.is-guide::after {
  content: "";
  position: absolute;
  left: 50%;
  top: -46%;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 14px solid var(--ak-accent-2);
  transform: translateX(-50%);
  filter: drop-shadow(0 1px 0 var(--ak-outline));
}

.flyer {
  position: absolute;
  z-index: 7;
  width: var(--hole, 7.6%);
  height: auto;
  transform: translate(-50%, -62%);
  pointer-events: none;
  filter: drop-shadow(0 3px 0 color-mix(in srgb, var(--ak-ink) 40%, transparent));
}

.hole:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
  z-index: 30;
}

.breeze {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.leaf {
  position: absolute;
  width: 16px;
  height: 24px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px 80% 8px 80%;
  background: var(--ak-accent);
  box-shadow: var(--ak-shadow);
}

.l1 { left: 4%; top: 8%; }
.l2 { right: 6%; top: 18%; background: var(--ak-accent-2); }
.l3 { left: 8%; bottom: 6%; transform: rotate(18deg); }

.dock {
  grid-area: dock;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.tools {
  display: flex;
  gap: 8px;
}

.tool,
.btn-go,
.btn-alt {
  min-height: 48px;
  min-width: 48px;
  padding: 0 14px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  cursor: pointer;
  touch-action: manipulation;
}

.tool {
  flex: 1 1 0;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
}

.tool:active,
.btn-alt:active,
.mute:active {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
}

.tool[aria-expanded="true"] {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-choice-selected-border);
}

.result-card {
  padding: 12px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.result-says {
  margin: 0;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 4.6vw, 24px);
  font-weight: var(--ak-title-weight);
  line-height: 1.25;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.btn-go,
.btn-alt {
  flex: 1 1 140px;
}

.btn-go {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}

.btn-go:active {
  background: var(--ak-btn-active);
}

.btn-alt {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
}

.mute:focus-visible,
.tool:focus-visible,
.btn-go:focus-visible,
.btn-alt:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

.bit {
  position: absolute;
  width: 10px;
  height: 16px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px 80% 8px 80%;
}

.bit.is-a { background: var(--ak-accent); }
.bit.is-b { background: var(--ak-accent-2); }

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

@media (max-width: 360px) {
  .turn {
    font-size: 14px;
    padding-right: 8px;
  }

  .play-logo {
    height: 36px;
  }

  .voice,
  .why {
    font-size: 14px;
    padding: 6px 8px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .play-logo {
    animation: logo-bob 3.2s ease-in-out infinite;
  }

  .leaf {
    animation: leaf-sway 3.4s ease-in-out infinite;
  }

  .l2 { animation-delay: 0.4s; }
  .l3 { animation-delay: 0.8s; }

  .turn.is-pop {
    animation: turn-pop 320ms cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .hole.is-guide .pit {
    animation: guide-pit 1.1s ease-in-out infinite;
  }

  .hole.is-guide::after {
    animation: guide-bob 0.9s ease-in-out infinite;
  }

  .hole.is-glow .ring,
  .hole.is-bloom .ring {
    animation: ring-pulse 1.15s ease-in-out infinite;
  }

  .hole.is-bloom .ring {
    animation-duration: 1.6s;
  }

  .hole.is-down {
    transform: translate(-50%, -50%) scale(0.92);
  }

  .hole.is-shake {
    animation: hole-shake 320ms ease;
  }

  .play:not(.is-ended) .marble {
    animation: marble-idle 2.8s ease-in-out infinite;
  }

  .play:not(.is-ended) .marble.is-settle {
    animation: settle 520ms cubic-bezier(0.22, 1.2, 0.36, 1);
  }

  .play:not(.is-ended) .marble.is-wobble {
    animation: wobble 280ms ease-in-out;
  }

  .play:not(.is-ended) .hole.is-picked .marble {
    animation: none;
    transform: translate(-50%, -74%) scale(1.06);
  }

  .flyer.is-arc {
    animation: hop-arc 230ms cubic-bezier(0.22, 0.8, 0.3, 1);
  }

  .flyer.is-wobble {
    animation: wobble 280ms ease-in-out;
  }

  .spark.is-on {
    animation: spark 340ms ease-out;
  }

  .bloom img {
    animation: bloom-pulse 1.4s ease-in-out infinite;
  }

  .play.is-won .star {
    animation: star-glow 1.6s ease-in-out infinite;
  }

  .play.is-lost .star {
    animation: star-glow-lost 1.6s ease-in-out infinite;
  }

  .bit {
    animation: confetti 900ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  }

  .tool:active,
  .btn-go:active,
  .btn-alt:active,
  .mute:active {
    transform: translateY(2px) scale(0.98);
  }

  @keyframes logo-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(3px); }
  }

  @keyframes leaf-sway {
    0%, 100% { transform: rotate(-8deg) translateY(0); }
    50% { transform: rotate(10deg) translateY(-4px); }
  }

  @keyframes turn-pop {
    0% { transform: scale(0.92); }
    55% { transform: scale(1.06); }
    100% { transform: scale(1); }
  }

  @keyframes guide-pit {
    0%, 100% { box-shadow: 0 0 0 2px var(--ak-accent), 0 0 0 0 var(--ak-accent-2); }
    50% { box-shadow: 0 0 0 3px var(--ak-accent-2), 0 0 10px var(--ak-accent-2); }
  }

  @keyframes guide-bob {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-5px); }
  }

  @keyframes ring-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.78; }
    50% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  }

  @keyframes hole-shake {
    0%, 100% { transform: translate(-50%, -50%); }
    25% { transform: translate(calc(-50% - 4px), -50%); }
    75% { transform: translate(calc(-50% + 4px), -50%); }
  }

  @keyframes settle {
    0% { transform: translate(-50%, -62%) scale(1.14, 0.78); }
    28% { transform: translate(-50%, -88%) scale(0.92, 1.14); }
    48% { transform: translate(-50%, -62%) scale(1.08, 0.88); }
    68% { transform: translate(-50%, -78%) scale(0.98, 1.06); }
    100% { transform: translate(-50%, -62%) scale(1, 1); }
  }

  @keyframes wobble {
    0%, 100% { transform: translate(-50%, -62%) rotate(0deg); }
    30% { transform: translate(-50%, -62%) rotate(-10deg) scale(1.08, 0.92); }
    70% { transform: translate(-50%, -62%) rotate(9deg) scale(0.94, 1.08); }
  }

  @keyframes marble-idle {
    0%, 100% { transform: translate(-50%, -62%) translateY(0); }
    50% { transform: translate(-50%, -62%) translateY(-2px); }
  }

  @keyframes hop-arc {
    0% { transform: translate(-50%, -62%) scale(1, 1); }
    45% { transform: translate(-50%, -96%) scale(0.9, 1.12); }
    100% { transform: translate(-50%, -62%) scale(1.08, 0.88); }
  }

  @keyframes spark {
    0% { opacity: 0.95; transform: translate(-50%, -50%) scale(0.3); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
  }

  @keyframes bloom-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(0.86); opacity: 0.75; }
    50% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
  }

  @keyframes star-glow {
    0%, 100% { filter: drop-shadow(0 0 0 transparent); }
    50% { filter: drop-shadow(0 0 14px var(--ak-accent)); }
  }

  @keyframes star-glow-lost {
    0%, 100% { filter: drop-shadow(0 0 0 transparent); }
    50% { filter: drop-shadow(0 0 14px var(--ak-accent-2)); }
  }

  @keyframes confetti {
    0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(160deg) scale(0.7); }
  }
}
