html,
body {
  height: 100%;
  margin: 0;
  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(8px, env(safe-area-inset-top, 0px));
  --pad-x: max(10px, 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 auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "ribbon" "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;
}

.slash {
  display: none;
}

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

.mute.is-muted .slash {
  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: 16px;
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
}

.turn-mark {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  object-fit: contain;
}

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

.ribbon {
  grid-area: ribbon;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.bench {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 48px;
  padding: 4px 6px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.pip {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.bench-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bench-name {
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 13px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
}

.slips {
  display: flex;
  gap: 3px;
}

.slip {
  width: 14px;
  height: 18px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-choice-bg);
  box-shadow: var(--ak-shadow);
}

.slip:nth-child(1) {
  transform: rotate(-7deg);
}

.slip:nth-child(2) {
  transform: rotate(4deg);
}

.slip:nth-child(3) {
  transform: rotate(-2deg);
}

.bench:not(.is-cpu) .slip.is-on {
  background: var(--ak-ink);
}

.bench.is-cpu .slip.is-on {
  background: var(--ak-accent);
}

.bar {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 4px 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background-color: var(--ak-accent-2);
  background-image: linear-gradient(100deg, var(--ak-accent-2), var(--ak-bg) 42%, var(--ak-accent-2) 70%);
  background-size: 220% 100%;
  box-shadow: var(--ak-shadow), 0 0 12px var(--ak-glow);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(13px, 3.4vw, 18px);
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
  text-align: center;
}

.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;
}

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

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

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

.cells {
  position: absolute;
  inset: 0;
}

.cell {
  position: absolute;
  width: 20%;
  height: 18%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
  touch-action: manipulation;
}

.cell.is-down {
  background: color-mix(in srgb, var(--ak-ink) 28%, transparent);
}

.mark-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.mark {
  width: 112%;
  height: 112%;
  object-fit: contain;
  pointer-events: none;
}

.cell.is-invite .mark-wrap::after,
.cell.is-heart .mark-wrap::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  border: 3px solid var(--ak-accent-2);
  border-radius: 50%;
  box-shadow: 0 0 10px var(--ak-glow);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cell.is-heart .mark-wrap::after {
  border-color: var(--ak-accent);
}

.seal {
  position: absolute;
  z-index: 12;
  width: 20%;
  aspect-ratio: 1;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 42%, var(--ak-bg) 0 38%, transparent 39%),
    radial-gradient(circle at 50% 50%, var(--ak-accent-2) 0 46%, var(--ak-accent) 47% 64%, var(--ak-accent-2) 65% 100%);
  box-shadow: var(--ak-shadow), 0 0 14px var(--ak-glow);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.seal-face {
  position: absolute;
  left: 28%;
  top: 30%;
  width: 44%;
  height: 40%;
  border: 2px solid var(--ak-accent);
  border-radius: 50%;
}

.burst,
.wipe {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.burst {
  z-index: 13;
  overflow: hidden;
}

.wipe {
  z-index: 20;
  background: linear-gradient(90deg, transparent, var(--ak-bg) 42%, var(--ak-bg) 58%, transparent);
  transform: translateX(-130%);
  opacity: 0;
}

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

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

.result-card {
  padding: 10px;
  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.8vw, 24px);
  font-weight: var(--ak-title-weight);
  line-height: 1.2;
}

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

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

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

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

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

.bit {
  position: absolute;
  top: 46%;
  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: 14px;
  }

  .play-logo {
    height: 34px;
  }

  .pip {
    width: 24px;
    height: 24px;
  }

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

@media (max-height: 700px) {
  .play {
    gap: 4px;
  }

  .play-logo {
    height: 32px;
  }

  .bench,
  .bar,
  .turn {
    min-height: 44px;
  }

  .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;
  }

  .bar {
    animation: sheen 3.6s ease-in-out infinite;
  }

  .mark.is-dry {
    animation: dry-idle 2.6s ease-in-out infinite;
  }

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

  .cell.is-invite .mark-wrap::after,
  .cell.is-heart .mark-wrap::after {
    animation: invite 1.25s ease-in-out infinite;
  }

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

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

  .mark.is-peel {
    animation: peel 460ms ease forwards;
  }

  .mark.is-win {
    animation: win-bounce 900ms cubic-bezier(0.34, 1.45, 0.64, 1) both, glow-chase 700ms ease-in-out 900ms 2;
  }

  .seal.is-stamp {
    animation: stamp 560ms cubic-bezier(0.34, 1.56, 0.64, 1) 720ms both;
  }

  .slip.is-new {
    animation: slip-pop 380ms 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);
  }

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

  .board.is-wipe .wipe {
    opacity: 1;
    animation: swipe 380ms ease-in forwards;
  }

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

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

@keyframes sheen {
  0%,
  100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes dry-idle {
  0%,
  100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-6%) rotate(3deg); }
}

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

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

@keyframes pop {
  0% { transform: scale(1.25, 0.45); }
  55% { transform: scale(0.82, 1.22); }
  78% { transform: scale(1.08, 0.9); }
  100% { transform: scale(1); }
}

@keyframes peel {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  35% { transform: scale(1.08, 0.86) translateY(-8%) rotate(-4deg); opacity: 1; }
  100% { transform: scale(0.7, 1.15) translateY(-80%) rotate(10deg); opacity: 0; }
}

@keyframes win-bounce {
  0%,
  100% { transform: translateY(0) scale(1); }
  16% { transform: translateY(-16%) scale(1.1, 0.84); }
  32% { transform: translateY(0) scale(0.94, 1.08); }
  52% { transform: translateY(-12%) scale(1.06, 0.9); }
  72% { transform: translateY(0) scale(1); }
}

@keyframes glow-chase {
  0%,
  100% { filter: drop-shadow(0 0 0 var(--ak-glow)); }
  50% { filter: drop-shadow(0 0 8px var(--ak-glow)) drop-shadow(0 0 6px var(--ak-accent-2)); }
}

@keyframes stamp {
  0% { transform: translate(-50%, -220%) scale(0.45) rotate(-12deg); opacity: 0; }
  62% { transform: translate(-50%, -50%) scale(1.16, 0.78); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes slip-pop {
  0% { transform: translateY(6px) scale(0.6); }
  60% { transform: translateY(-4px) scale(1.08); }
  100% { transform: none; }
}

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

@keyframes swipe {
  0% { transform: translateX(-130%); }
  100% { transform: translateX(130%); }
}

@keyframes bit-burst {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate3d(var(--dx), var(--dy), 0) rotate(160deg); opacity: 0; }
}
