*,
*::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.3;
  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%, 420px);
  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);
  background-size: cover;
  background-position: center 18%;
  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);
}

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

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

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

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

.top,
.voice,
.goal,
.why,
.actions {
  position: relative;
  z-index: 7;
  flex: 0 0 auto;
}

.why {
  z-index: 8;
}

.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 {
  min-width: 0;
  transform-origin: left center;
}

.turn-who {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(22px, 5.6vw, 30px);
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-accent);
}

.turn-sub {
  margin: 2px 0 0;
  color: var(--ak-ink);
  font-size: 14px;
  font-weight: 700;
}

.voice,
.goal,
.why {
  margin: 0;
  padding: 7px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 92%, transparent);
  box-shadow: var(--ak-shadow);
}

.voice {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ak-ink);
}

.voice.is-invite {
  border-color: var(--ak-accent);
}

.voice.is-warn {
  border-color: var(--ak-accent);
  color: var(--ak-accent);
}

.goal,
.why {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.goal {
  color: var(--ak-ink);
}

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

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  touch-action: manipulation;
}

.row {
  position: absolute;
  z-index: 2;
  inset: 8px 0 36px;
}

.drum {
  position: absolute;
  z-index: 1;
  left: -6%;
  right: -6%;
  bottom: 0;
  height: 58px;
  border-top: 3px solid var(--ak-outline);
  background: repeating-linear-gradient(
    90deg,
    var(--ak-accent) 0 14px,
    var(--ak-bg) 14px 28px
  );
  box-shadow: var(--ak-shadow);
}

.drum::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  background: var(--ak-ink);
}

.bulbs {
  position: absolute;
  z-index: 3;
  left: 10px;
  right: 10px;
  bottom: 46px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.bulb {
  width: 14px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-accent-2);
  box-shadow: 0 0 8px var(--ak-glow), 0 0 6px var(--ak-accent-2);
}

.tube {
  position: absolute;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: manipulation;
}

.tube:focus-visible {
  outline: none;
}

.tube:focus-visible .sprite {
  box-shadow: inset 0 0 0 3px var(--ak-focus);
}

.coach {
  display: none;
  position: absolute;
  top: -18px;
  left: 50%;
  z-index: 4;
  width: 0;
  height: 0;
  margin-left: -11px;
  border-right: 11px solid transparent;
  border-left: 11px solid transparent;
  border-top: 16px solid var(--ak-accent-2);
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.tube.is-coach .coach {
  display: block;
}

.sprite {
  position: relative;
  flex: 0 0 auto;
  filter: drop-shadow(2px 3px 0 var(--ak-outline));
}

.tube-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.well {
  position: absolute;
  z-index: 2;
  left: 16%;
  right: 16%;
  top: 14.5%;
  bottom: 17%;
  overflow: visible;
  border-radius: 40% / 10%;
  background:
    linear-gradient(90deg, rgba(10, 22, 48, 0.22), rgba(255, 248, 236, 0.15) 20%, rgba(255, 255, 255, 0.55) 48%, rgba(255, 248, 236, 0.12) 74%, rgba(10, 22, 48, 0.18)),
    #f3eadc;
}

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

.ball {
  position: absolute;
  aspect-ratio: 1;
  isolation: isolate;
}

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

.ball .wash {
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  background: var(--tint);
  mix-blend-mode: color;
  pointer-events: none;
}

.ball.is-away {
  visibility: hidden;
}

.sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(to top, var(--ak-accent-2), transparent 72%);
  transform: scaleY(0);
  transform-origin: bottom center;
  opacity: 0;
  pointer-events: none;
}

.tube.is-from .sprite,
.tube.is-to .sprite {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.tube.is-to .sprite {
  outline-color: var(--ak-accent-2);
}

.play.is-finale .tube.is-pure .sprite {
  filter: drop-shadow(0 0 12px var(--done, var(--ak-accent-2))) drop-shadow(2px 3px 0 var(--ak-outline));
}

.play.is-finale .tube.is-empty .sprite {
  filter: drop-shadow(2px 3px 0 var(--ak-outline));
}

.play.is-finale .bulb {
  box-shadow: 0 0 12px 4px var(--ak-accent-2), 0 0 10px var(--ak-glow);
}

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

.actions button,
.btn-go,
.btn-alt {
  flex: 1 1 0;
  min-width: 48px;
  min-height: 48px;
  padding: 0 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-size: 16px;
  font-weight: 700;
  touch-action: manipulation;
}

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

button:disabled {
  opacity: 0.45;
}

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

.bit {
  position: absolute;
  top: 46%;
  left: 50%;
  width: 10px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-surface);
}

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

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

.bit.is-c {
  background: var(--ak-surface);
}

.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: calc(64px + var(--pad-bot));
}

.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;
  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: 6px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ak-accent);
}

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

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

.flyer {
  position: fixed;
  z-index: 30;
  margin: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
  .mute:active,
  .actions button:active,
  .btn-go:active,
  .btn-alt:active {
    transform: scale(0.96);
  }

  .tube:active .sprite {
    transform: scale(0.97);
    transform-origin: center bottom;
  }

  .turn.is-cue {
    animation: turnpop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .bulb {
    animation: idle-lamp 2.6s ease-in-out infinite;
  }

  .bulb:nth-child(odd) {
    animation-delay: 0.35s;
  }

  .bulb:nth-child(3n) {
    animation-delay: 0.7s;
  }

  .tube.is-coach .coach {
    animation: bob-dot 0.8s ease-in-out infinite;
  }

  .ball.is-up {
    animation: hover 0.75s ease-in-out infinite;
    z-index: 4;
  }

  .ball.is-pop {
    animation: squash 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .ball.is-rain {
    animation: rain 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  }

  .tube.is-shake .sprite {
    animation: shake 0.4s ease-in-out;
  }

  .tube.is-flash .sheen {
    animation: sweep 0.65s ease-out;
  }

  .play.is-finale .bulb {
    animation: lamp 0.42s ease-in-out infinite alternate;
  }

  .bit {
    animation: burst 900ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  @keyframes turnpop {
    0% { transform: scale(1); }
    40% { transform: scale(1.06, 0.94); }
    100% { transform: scale(1); }
  }

  @keyframes idle-lamp {
    0%, 100% { transform: scale(1); opacity: 0.78; }
    50% { transform: scale(1.1); opacity: 1; }
  }

  @keyframes lamp {
    from { transform: scale(0.92); }
    to { transform: scale(1.18); }
  }

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

  @keyframes hover {
    0%, 100% { transform: translateY(-62%) scale(1, 1); }
    50% { transform: translateY(-84%) scale(1.06, 0.92); }
  }

  @keyframes squash {
    0% { transform: translateY(-28%) scale(0.9, 1.14); }
    45% { transform: translateY(0) scale(1.14, 0.78); }
    100% { transform: translateY(0) scale(1, 1); }
  }

  @keyframes rain {
    0% { transform: translateY(-160%) scale(1, 0.8); }
    68% { transform: translateY(0) scale(1.1, 0.84); }
    100% { transform: translateY(0) scale(1, 1); }
  }

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

  @keyframes sweep {
    0% { transform: scaleY(0.05); opacity: 0.95; }
    100% { transform: scaleY(1); opacity: 0; }
  }

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

@media (min-width: 800px) {
  body {
    display: grid;
    place-items: center;
  }

  .play {
    height: min(100dvh, 900px);
    border-left: 2px solid var(--ak-outline);
    border-right: 2px solid var(--ak-outline);
  }
}
