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

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

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

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

[hidden] {
  display: none !important;
}

.play {
  --pad-top: max(6px, env(safe-area-inset-top, 0px));
  --pad-bot: max(8px, env(safe-area-inset-bottom, 0px));
  --pad-x: max(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(100%, 480px);
  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-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer, none), var(--ak-bg-art);
  background-size: cover, var(--ak-bg-size);
  background-position: center top, center;
  background-repeat: no-repeat, 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);
}

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

.mute-icon .slash {
  display: none;
}

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

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

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

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

.turn {
  min-width: 0;
  flex: 1;
  padding: 4px 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.turn-who,
.turn-sub,
.voice,
.goal,
.tip,
.why,
.result-says,
.result-score {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: 15px;
  font-weight: var(--ak-title-weight);
  color: var(--ak-accent-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn.is-water .turn-who {
  color: var(--ak-accent);
}

.turn-sub {
  color: var(--ak-ink-muted);
  font-size: 13px;
  font-weight: 700;
}

.voice,
.goal,
.tip,
.why {
  min-height: 1.25em;
  padding: 4px 8px;
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
}

.voice {
  font-family: var(--ak-font-display);
  font-size: 15px;
  font-weight: var(--ak-title-weight);
  color: var(--ak-ink);
}

.voice.is-invite {
  color: var(--ak-accent-2);
  border-color: var(--ak-accent-2);
  box-shadow: 0 0 12px var(--ak-glow);
}

.goal,
.tip {
  font-size: 14px;
  font-weight: 700;
  color: var(--ak-ink);
}

.tip {
  border-color: var(--ak-accent);
  color: var(--ak-accent);
}

.why {
  font-family: var(--ak-font-display);
  font-size: 15px;
  font-weight: var(--ak-title-weight);
  color: var(--ak-accent-2);
  border-color: var(--ak-accent-2);
  box-shadow: 0 0 14px var(--ak-glow);
}

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

.hatch {
  --n: 3;
  position: relative;
  width: min(100%, calc((100dvh - 214px) * var(--n) / (var(--n) + 2)));
  max-height: 100%;
  aspect-ratio: var(--n) / calc(var(--n) + 2);
  padding: 6px;
  border: 4px solid var(--ak-accent);
  border-radius: 18px;
  background: #07111f;
  box-shadow: var(--ak-shadow), inset 0 0 0 3px #040810;
}

.grid-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.grid {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  grid-template-rows: repeat(calc(var(--n) + 2), minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  height: 100%;
}

.porthole {
  position: absolute;
  top: -26px;
  right: 8%;
  z-index: 0;
  width: 34%;
  height: 32px;
  overflow: hidden;
  border: 3px solid var(--ak-outline);
  border-radius: 40px 40px 10px 10px;
  background: #06101c;
  box-shadow: 0 0 12px var(--ak-glow);
  pointer-events: none;
}

.stars {
  position: absolute;
  inset: -30% -10%;
  background-image:
    radial-gradient(circle at 20% 40%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 62% 30%, var(--ak-accent-2) 0 1.2px, transparent 2px),
    radial-gradient(circle at 80% 70%, #fff 0 1px, transparent 2px),
    radial-gradient(circle at 40% 75%, #fff 0 1px, transparent 2px);
  background-size: 48px 36px;
}

.lamp {
  position: absolute;
  left: -12px;
  top: 26%;
  z-index: 3;
  width: 16px;
  height: 58px;
  border-radius: 8px;
  background: var(--ak-accent-2);
  box-shadow: 0 0 16px var(--ak-glow);
  pointer-events: none;
}

.pipe,
.fixture {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #10192b;
  touch-action: manipulation;
}

.pipe img,
.fixture img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.seam {
  position: absolute;
  z-index: 2;
  display: none;
  background: var(--ak-accent-2);
  box-shadow: 0 0 8px var(--ak-glow);
  pointer-events: none;
}

.seam.on {
  display: block;
}

.seam-n { top: 0; left: 22%; width: 56%; height: 5px; }
.seam-s { bottom: 0; left: 22%; width: 56%; height: 5px; }
.seam-e { right: 0; top: 22%; width: 5px; height: 56%; }
.seam-w { left: 0; top: 22%; width: 5px; height: 56%; }

.pipe.is-coach {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: 1px;
  box-shadow: 0 0 14px var(--ak-glow);
}

.pipe.is-fault,
.fixture.is-fault {
  outline: 3px solid var(--ak-accent);
  outline-offset: 1px;
}

.pipe.is-wet {
  box-shadow: inset 0 0 0 2px var(--ak-accent-2);
}

.bead {
  position: absolute;
  z-index: 4;
  width: 18px;
  height: 18px;
  border: 2px solid var(--ak-ink);
  border-radius: 50%;
  background: var(--ak-accent-2);
  box-shadow: 0 0 12px var(--ak-glow);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.spray {
  position: absolute;
  z-index: 5;
  width: 0;
  height: 0;
  pointer-events: none;
}

.spray i {
  position: absolute;
  width: 8px;
  height: 12px;
  border-radius: 8px;
  background: var(--ak-accent-2);
  box-shadow: 0 0 8px var(--ak-glow);
}

.dock {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.hint,
.btn-check,
.btn-go,
.btn-alt {
  min-height: 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: 16px;
  font-weight: var(--ak-title-weight);
  touch-action: manipulation;
}

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

.btn-check,
.btn-go {
  flex: 1 1 auto;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}

.btn-check.is-ready {
  box-shadow: var(--ak-shadow), 0 0 14px var(--ak-glow);
}

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

.bit {
  position: absolute;
  top: 28%;
  left: 50%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  background: var(--ak-accent);
}

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

.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 {
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 4.6vw, 26px);
  font-weight: var(--ak-title-weight);
  line-height: 1.15;
  color: var(--ak-ink);
}

.result-score {
  margin-top: 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--ak-accent);
}

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

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

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

.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 (hover: hover) {
  .btn-check:hover,
  .btn-go:hover {
    background: var(--ak-btn-hover);
  }

  .btn-alt:hover,
  .hint:hover,
  .mute:hover {
    background: var(--ak-choice-bg);
  }
}

@supports (width: 1cqi) {
  .stage {
    container-type: size;
  }

  .hatch {
    width: min(100cqi, calc(100cqb * var(--n) / (var(--n) + 2)));
    max-height: 100cqb;
  }
}

@media (max-width: 359px) {
  .play {
    gap: 4px;
  }

  .goal,
  .voice,
  .why {
    font-size: 13px;
  }
}

@keyframes settle {
  0% { transform: rotate(var(--turn)) scale(1.08, 0.88); }
  55% { transform: rotate(var(--turn)) scale(0.96, 1.06); }
  100% { transform: rotate(var(--turn)) scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

@keyframes hop {
  0% { transform: translate(-50%, -50%) scale(1, 1); }
  40% { transform: translate(-50%, -68%) scale(0.86, 1.16); }
  100% { transform: translate(-50%, -50%) scale(1, 1); }
}

@keyframes swirl {
  0% { transform: translate(-50%, -50%) translate(0, 0); }
  25% { transform: translate(-50%, -50%) translate(12px, -8px); }
  50% { transform: translate(-50%, -50%) translate(0, -14px); }
  75% { transform: translate(-50%, -50%) translate(-12px, -8px); }
  100% { transform: translate(-50%, -50%) translate(0, 0); }
}

@keyframes coach {
  0%, 100% { outline-color: var(--ak-accent-2); }
  50% { outline-color: var(--ak-accent); }
}

@keyframes invite {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

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

@keyframes hum {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

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

@keyframes ready {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes kick {
  0% { transform: rotate(var(--turn)) scale(1); }
  35% { transform: rotate(var(--turn)) scale(1.12, 0.88); }
  100% { transform: rotate(var(--turn)) scale(1); }
}

@keyframes spray {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.4); }
}

@keyframes burst {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.5); }
}

@keyframes chase {
  0% { box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent-2); }
  50% { box-shadow: var(--ak-shadow), 0 0 18px 4px var(--ak-glow); }
  100% { box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent); }
}

@keyframes turn-cue {
  0% { transform: translateX(0); }
  35% { transform: translateX(6px); }
  100% { transform: translateX(0); }
}

@keyframes seam-flash {
  0% { opacity: 0.2; }
  40% { opacity: 1; }
  100% { opacity: 1; }
}

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

  .stars {
    animation: drift 14s linear infinite;
  }

  .lamp {
    animation: hum 2.4s ease-in-out infinite;
  }

  .voice.is-invite {
    animation: invite 1.6s ease-in-out infinite;
  }

  .pipe.is-coach {
    animation: coach 1.1s ease-in-out infinite;
  }

  .pipe img.is-turning,
  .fixture img.is-turning {
    animation: settle 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .pipe.is-shake,
  .fixture.is-shake {
    animation: shake 0.36s ease-in-out;
  }

  .bead.is-hop {
    animation: hop 0.28s ease-out;
  }

  .bead.is-swirl {
    animation: swirl 0.9s linear infinite;
  }

  .btn-check.is-ready {
    animation: ready 1.2s ease-in-out infinite;
  }

  .turn.is-cue {
    animation: turn-cue 0.42s ease-out;
  }

  .seam.on {
    animation: seam-flash 0.4s ease;
  }

  .hatch.is-win {
    animation: chase 0.7s linear 3;
  }

  .fixture.is-pour img {
    animation: kick 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .spray i {
    animation: spray 0.7s ease-out forwards;
  }

  .bit {
    animation: burst 0.9s ease-out forwards;
  }

  .pipe:active,
  .fixture:active,
  .btn-check:active,
  .btn-go:active,
  .btn-alt:active,
  .hint:active,
  .mute:active {
    scale: 0.96;
  }
}
