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[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:active {
  transform: translateY(2px) scale(0.96);
}

.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: 40px;
  max-width: 46%;
  object-fit: contain;
}

.turn {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin: 0 0 0 auto;
  padding: 4px 10px 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: 15px;
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
}

.turn-stone {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  object-fit: cover;
  object-position: center 100%;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-surface);
}

#turn-who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice {
  grid-area: voice;
}

.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: 14px;
  line-height: 1.3;
}

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

.stage {
  grid-area: stage;
  container-type: size;
  min-height: 0;
  display: grid;
  place-items: center;
}

.board {
  position: relative;
  width: min(100cqw, calc(100cqh * 384 / 303));
  aspect-ratio: 384 / 303;
  touch-action: manipulation;
}

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

.board::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: transparent;
}

.play.is-draw .board::after {
  background: color-mix(in srgb, var(--ak-ink) 28%, transparent);
}

.crumbs,
.spots,
.burst {
  position: absolute;
  inset: 0;
}

.crumbs {
  z-index: 4;
  pointer-events: none;
}

.spots {
  z-index: 2;
}

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

.crumb {
  position: absolute;
  width: 7px;
  height: 5px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ak-ink) 62%, var(--ak-bg));
}

.c1 { left: 28%; top: 91%; }
.c2 { left: 42%; top: 94%; }
.c3 { left: 57%; top: 92%; }
.c4 { left: 71%; top: 90%; }
.c5 { left: 82%; top: 86%; }

.spot {
  position: absolute;
  width: 7.4%;
  height: 9.4%;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  touch-action: manipulation;
  cursor: pointer;
}

.spot .glow {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: transparent;
  pointer-events: none;
}

.spot:active .glow,
.spot.is-down .glow,
.spot:focus-visible .glow {
  background: color-mix(in srgb, var(--ak-accent-2) 72%, transparent);
  box-shadow: 0 0 10px var(--ak-accent-2);
}

.spot.is-invite .glow {
  inset: 28%;
  background: transparent;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ak-accent-2) 75%, transparent);
}

.spot.is-heart .glow {
  inset: 16%;
  background: transparent;
  box-shadow:
    0 0 0 3px var(--ak-accent-2),
    0 0 12px var(--ak-accent-2);
}

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

.stone {
  position: absolute;
  left: 50%;
  top: 46%;
  height: 118%;
  width: auto;
  max-width: none;
  transform: translate(-50%, -72%);
  pointer-events: none;
  z-index: 1;
}

.stone.is-win {
  filter: drop-shadow(0 0 6px var(--ak-accent-2));
  z-index: 2;
}

.cherry {
  position: absolute;
  left: 50%;
  top: 2%;
  z-index: 3;
  width: 34%;
  aspect-ratio: 1;
  border: 2px solid var(--ak-outline);
  border-radius: 50% 50% 46% 54%;
  background: var(--ak-accent);
  transform: translate(-50%, -10%);
  pointer-events: none;
}

.cherry::before {
  content: '';
  position: absolute;
  left: 46%;
  top: -46%;
  width: 3px;
  height: 55%;
  border-radius: 2px;
  background: var(--ak-ink);
  transform: rotate(20deg);
}

.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-go:active,
.btn-alt:active {
  transform: translateY(2px) scale(0.98);
}

.result[hidden],
.why[hidden],
.tool[hidden] {
  display: none !important;
}

.result {
  position: relative;
  z-index: 4;
}

.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;
  top: 42%;
  width: 8px;
  height: 12px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px;
}

.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: 13px;
    padding-right: 8px;
  }

  .play-logo {
    height: 34px;
  }

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

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

  .crumb {
    animation: crumb-idle 2.8s ease-in-out infinite;
  }

  .c2 { animation-delay: 0.2s; }
  .c3 { animation-delay: 0.45s; }
  .c4 { animation-delay: 0.15s; }
  .c5 { animation-delay: 0.6s; }

  .play.is-draw .crumb {
    animation: crumb-settle 700ms ease forwards;
  }

  .play.is-crumb .crumb {
    animation: crumb-jump 420ms cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .spot.is-invite .glow,
  .spot.is-heart .glow {
    animation: invite 1.3s ease-in-out infinite;
  }

  .spot.is-heart .glow {
    animation-duration: 0.9s;
  }

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

  .spot.is-puff::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 58%;
    width: 80%;
    height: 46%;
    border-radius: 50%;
    background: color-mix(in srgb, var(--ak-ink) 40%, transparent);
    transform: translate(-50%, -50%) scale(0.3);
    animation: puff 480ms ease-out forwards;
    pointer-events: none;
  }

  .stone.is-drop {
    animation: stone-drop 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .stone.is-reply {
    animation: stone-drop 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .stone.is-lift {
    animation: stone-lift 380ms ease forwards;
  }

  .stone.is-win {
    animation: mint-pulse 900ms ease-in-out infinite;
  }

  .cherry {
    animation: cherry-pop 520ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

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

  .bit {
    animation: bit-burst 1100ms ease-in forwards;
  }

  .play.is-draw .board::after {
    animation: lamp-down 800ms ease forwards;
  }
}

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

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

@keyframes crumb-jump {
  0% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-10px) scale(0.9, 1.15); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes crumb-settle {
  to { transform: translateY(2px) scale(1.05, 0.7); }
}

@keyframes invite {
  0%, 100% { transform: scale(0.86); opacity: 0.7; }
  50% { transform: scale(1.08); opacity: 1; }
}

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

@keyframes puff {
  0% { opacity: 0.8; transform: translate(-50%, -40%) scale(0.3); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(1.4); }
}

@keyframes stone-drop {
  0% { transform: translate(-50%, -130%) scale(0.7, 1.25); }
  55% { transform: translate(-50%, -64%) scale(1.12, 0.82); }
  78% { transform: translate(-50%, -78%) scale(0.94, 1.08); }
  100% { transform: translate(-50%, -72%) scale(1, 1); }
}

@keyframes stone-lift {
  0% { transform: translate(-50%, -72%) scale(1, 1); opacity: 1; }
  40% { transform: translate(-50%, -96%) scale(0.9, 1.25); opacity: 1; }
  100% { transform: translate(-50%, -140%) scale(0.7, 1.1); opacity: 0; }
}

@keyframes mint-pulse {
  0%, 100% { filter: drop-shadow(0 0 2px var(--ak-accent-2)); }
  50% { filter: drop-shadow(0 0 10px var(--ak-accent-2)); }
}

@keyframes cherry-pop {
  0% { transform: translate(-50%, 20%) scale(0.2); }
  60% { transform: translate(-50%, -18%) scale(1.18); }
  100% { transform: translate(-50%, -10%) scale(1); }
}

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

@keyframes bit-burst {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(160px) rotate(180deg); opacity: 0; }
}

@keyframes lamp-down {
  from { background: transparent; }
  to { background: color-mix(in srgb, var(--ak-ink) 28%, transparent); }
}
