*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ak-ink);
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
}

[hidden] {
  display: none !important;
}

button {
  font-family: inherit;
  touch-action: manipulation;
}

.play {
  --pad-top: max(6px, env(safe-area-inset-top, 0px));
  --pad-bot: max(6px, env(safe-area-inset-bottom, 0px));
  --pad-x: max(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --hud: 148px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  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;
  background-repeat: no-repeat;
}

.motes {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.mote {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ak-accent-2);
  box-shadow: 0 0 10px var(--ak-glow);
  opacity: 0.7;
}

.mote-a { left: 8%; top: 22%; }
.mote-b { right: 12%; top: 16%; width: 6px; height: 6px; }
.mote-c { left: 16%; bottom: 18%; width: 5px; height: 5px; }
.mote-d { right: 18%; bottom: 28%; }
.mote-e { left: 42%; top: 8%; width: 4px; height: 4px; opacity: 0.5; }

.mute,
.top,
.voice,
.scores,
.stage,
.result {
  position: relative;
  z-index: 1;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(8px, env(safe-area-inset-right, 0px));
  z-index: 6;
  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;
}

.mute-icon {
  width: 18px;
  height: 18px;
  border: 3px solid var(--ak-ink);
  border-left: 0;
  border-radius: 0 10px 10px 0;
  box-shadow: -7px 0 0 -3px var(--ak-ink);
}

.mute.is-muted .mute-icon {
  opacity: 0.45;
  transform: rotate(25deg);
}

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

.play-logo {
  display: block;
  width: auto;
  height: 46px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px var(--ak-glow));
}

.turn {
  min-width: 0;
}

.turn-who {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 5vw, 26px);
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.02em;
  color: var(--ak-accent-2);
  text-shadow: 0 0 12px var(--ak-glow);
}

.round-pip {
  margin: 0;
  color: var(--ak-ink-muted);
  font-size: 13px;
}

.voice {
  min-height: 40px;
  margin: 0;
  padding: 6px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 88%, transparent);
  box-shadow: var(--ak-shadow);
  font-size: 15px;
}

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

.score {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ak-surface) 80%, transparent);
  border: 2px solid color-mix(in srgb, var(--ak-accent-2) 55%, transparent);
  color: var(--ak-ink);
}

.score-label {
  color: var(--ak-ink-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.score strong {
  font-family: var(--ak-font-display);
  font-size: 20px;
  font-weight: var(--ak-title-weight);
  color: var(--ak-accent-2);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
}

.slab-wrap {
  position: relative;
  width: min(100%, calc(100dvh - var(--hud) - var(--pad-top) - var(--pad-bot)));
  aspect-ratio: 1;
  max-height: 100%;
}

.tide {
  position: absolute;
  inset: -4%;
  background: url("./art/tide-ring.png") center / contain no-repeat;
  --p: 1;
  -webkit-mask-image: conic-gradient(from -90deg, transparent calc((1 - var(--p, 1)) * 1turn), #000 0);
  mask-image: conic-gradient(from -90deg, transparent calc((1 - var(--p, 1)) * 1turn), #000 0);
  pointer-events: none;
  filter: drop-shadow(0 0 10px var(--ak-glow));
}

.tide-rotor {
  position: absolute;
  inset: -4%;
  pointer-events: none;
  transform: rotate(calc((1 - var(--p, 1)) * 360deg));
}

.tide-tip {
  position: absolute;
  left: 50%;
  top: 5%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: var(--ak-accent);
  box-shadow: 0 0 12px var(--ak-accent), 0 0 4px var(--ak-ink);
}

.tide.is-urgent {
  filter: drop-shadow(0 0 14px var(--ak-accent));
}

.ripple {
  position: absolute;
  inset: 14%;
  border-radius: 18px;
  border: 3px solid var(--ak-accent-2);
  opacity: 0;
  pointer-events: none;
}

.slab {
  position: absolute;
  inset: 0;
  background: url("./art/stone-board.png") center / contain no-repeat;
  filter: drop-shadow(0 10px 18px #020c12) drop-shadow(0 0 18px color-mix(in srgb, var(--ak-glow) 45%, transparent));
}

.board {
  position: absolute;
  inset: 8% 6% 10% 6%;
  display: grid;
  gap: 1px;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: color-mix(in srgb, #041822 28%, transparent);
  cursor: pointer;
  overflow: hidden;
}

.cell:focus {
  outline: none;
}

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

.clip {
  position: absolute;
  inset: 2%;
  overflow: hidden;
  pointer-events: none;
}

.cell[data-shape="circle"] .clip { clip-path: circle(44% at 50% 50%); }
.cell[data-shape="square"] .clip { clip-path: inset(8% round 18%); }
.cell[data-shape="triangle"] .clip { clip-path: polygon(50% 10%, 90% 90%, 10% 90%); }

.fit {
  width: 100%;
  height: 100%;
  transform: rotate(var(--rot, 0deg)) scale(var(--scale, 1));
}

.sheet {
  width: calc(384 / var(--win, 112) * 100%);
  height: calc(353 / var(--win, 112) * 100%);
  background: url("./art/shape-tiles.png") 0 0 / 100% 100% no-repeat;
  transform: translate(calc(var(--sx, 0) / 384 * -100%), calc(var(--sy, 0) / 353 * -100%));
}

.sheet.is-navy-tri {
  filter: sepia(1) saturate(5) hue-rotate(186deg) brightness(0.42) contrast(1.2);
}

.cell.is-wrong .fit,
.cell.is-found .fit {
  transform: rotate(var(--rot, 0deg)) scale(var(--scale, 1));
}

.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
}

.confetti {
  position: absolute;
  top: 18%;
  width: 8px;
  height: 12px;
  border-radius: 40% 40% 50% 50%;
  background: var(--ak-accent);
}

.confetti.is-alt { background: var(--ak-accent-2); }
.confetti.is-foam { background: var(--ak-ink); }

.result {
  position: absolute;
  left: max(10px, env(safe-area-inset-left, 0px));
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: max(10px, env(safe-area-inset-bottom, 0px));
  z-index: 5;
}

.result-card {
  padding: 12px;
  text-align: center;
  background: var(--ak-surface);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  border: 3px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow), 0 0 24px color-mix(in srgb, var(--ak-glow) 35%, transparent);
}

.result-says {
  margin: 0 0 6px;
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: var(--ak-title-weight);
  line-height: 1.2;
  color: var(--ak-ink);
}

.result-score {
  margin: 0 0 10px;
  color: var(--ak-accent-2);
  font-size: 15px;
}

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

.btn-go,
.btn-alt {
  flex: 1 1 0;
  min-height: 48px;
  min-width: 48px;
  padding: 8px 10px;
  border-radius: var(--ak-radius);
  border: 2px solid var(--ak-outline);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  cursor: pointer;
}

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

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

button:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
}

.play.is-reason .voice {
  text-align: center;
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: var(--ak-title-weight);
  color: var(--ak-accent);
}

.play.is-ended .tide {
  filter: drop-shadow(0 0 16px var(--ak-accent));
}

@media (max-width: 360px) {
  .play {
    --hud: 140px;
    --pad-x: max(6px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
    gap: 2px;
  }

  .play-logo {
    height: 40px;
  }

  .voice {
    min-height: 36px;
    font-size: 14px;
  }
}

@media (min-width: 700px) {
  .play {
    width: min(100%, 430px);
  }
}

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

  .mote {
    animation: mote-drift 7s ease-in-out infinite;
  }

  .mote-b { animation-delay: -1.2s; }
  .mote-c { animation-delay: -2.4s; }
  .mote-d { animation-delay: -3.1s; }
  .mote-e { animation-delay: -4s; }

  .play.is-idle .slab {
    animation: slab-idle 4.2s ease-in-out infinite;
  }

  .turn.is-cue .turn-who {
    animation: bump 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .cell:active .fit {
    transform: rotate(var(--rot, 0deg)) scale(calc(var(--scale, 1) * 0.9));
  }

  .cell.is-in .fit {
    animation: settle 460ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: calc(var(--i, 0) * 16ms);
  }

  .cell.is-found .clip {
    animation: found-spin 720ms cubic-bezier(0.34, 1.4, 0.64, 1);
    filter: drop-shadow(0 0 10px var(--ak-accent));
  }

  .cell.is-wrong .clip {
    animation: shake 380ms ease;
  }

  .ripple.is-on {
    animation: ripple 640ms ease-out;
  }

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

  .tide.is-urgent + .tide-rotor .tide-tip {
    animation: tip-pulse 700ms ease-in-out infinite;
  }

  .play.is-ended .slab-wrap {
    animation: sink 900ms ease forwards;
  }

  .play.is-ended .cell.is-last .clip {
    animation: coral-spin 900ms cubic-bezier(0.34, 1.4, 0.64, 1);
    filter: drop-shadow(0 0 12px var(--ak-accent));
  }

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

  .mute:active,
  .btn-go:active,
  .btn-alt:active {
    transform: scale(0.96, 0.92);
  }
}

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

@keyframes mote-drift {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50% { transform: translate3d(8px, -14px, 0); }
}

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

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.16, 0.88); }
  100% { transform: scale(1); }
}

@keyframes settle {
  0% { transform: translateY(-28%) rotate(var(--rot, 0deg)) scale(calc(var(--scale, 1) * 0.7)); }
  70% { transform: translateY(4%) rotate(var(--rot, 0deg)) scale(calc(var(--scale, 1) * 1.08)); }
  100% { transform: translateY(0) rotate(var(--rot, 0deg)) scale(var(--scale, 1)); }
}

@keyframes found-spin {
  0% { transform: translateY(0) scale(1) rotate(0deg); }
  45% { transform: translateY(-16%) scale(1.18) rotate(200deg); }
  100% { transform: translateY(0) scale(1) rotate(360deg); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px) rotate(-4deg); }
  75% { transform: translateX(6px) rotate(4deg); }
}

@keyframes ripple {
  0% { opacity: 0.9; transform: scale(0.4); }
  100% { opacity: 0; transform: scale(1.15); }
}

@keyframes yank {
  0% { transform: scale(1); }
  40% { transform: scale(1.06) rotate(-6deg); }
  100% { transform: scale(1); }
}

@keyframes tip-pulse {
  0%, 100% { box-shadow: 0 0 8px var(--ak-accent); }
  50% { box-shadow: 0 0 18px var(--ak-accent); }
}

@keyframes sink {
  to { transform: translateY(14%) scale(0.94); filter: brightness(0.72); }
}

@keyframes coral-spin {
  0% { transform: scale(1) rotate(0deg); }
  60% { transform: scale(1.2) rotate(240deg); }
  100% { transform: scale(1.05) rotate(360deg); }
}

@keyframes burst {
  0% { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate3d(var(--dx, 20px), var(--dy, 80px), 0) rotate(180deg); opacity: 0; }
}
