*,
*::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;
  line-height: 1.3;
  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(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: 4px;
  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-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

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

.mute,
.top,
.voice,
.reason,
.goal,
.lane,
.alpha,
.actions,
.result {
  position: relative;
  z-index: 1;
}

.reason,
.result {
  z-index: 6;
}

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

.mute:active {
  transform: translateY(2px) scale(0.96);
}

.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: 44px;
  padding-right: 52px;
}

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

.turn {
  min-width: 0;
}

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

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

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

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

.goal {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 6px;
  text-align: center;
}

.goal strong {
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.08em;
  color: var(--ak-accent);
}

.goal-arrow {
  color: var(--ak-accent);
  font-family: var(--ak-font-display);
}

.lane {
  --cap: min(64px, max(48px, calc((100% - 78px) / var(--letters, 5))));
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 32%, transparent);
  box-shadow: var(--ak-shadow);
}

.ripple {
  position: absolute;
  left: 8%;
  right: 18%;
  bottom: 12%;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, var(--ak-glow), transparent 70%);
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.live-lane {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 40px 2px 8px;
}

.live-lane::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 52px;
  bottom: calc(var(--cap) + 6px);
  width: 6px;
  transform: translateX(-50%);
  border-radius: 6px;
  background: linear-gradient(to top, var(--ak-accent), transparent 80%);
  opacity: 0.45;
  pointer-events: none;
}

.end-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.end-tag {
  font-family: var(--ak-font-display);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ak-accent);
}

.end-word,
.hist-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.hist {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  overflow: hidden;
}

.hist-row {
  flex: 0 1 auto;
  max-height: 34px;
}

.mini {
  --face: 34px;
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
}

.end-word .mini {
  --face: 40px;
  width: 40px;
  height: 40px;
  flex-basis: 40px;
}

.mini .pop,
.cap .pop {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.rail {
  position: absolute;
  left: 24px;
  right: 8px;
  bottom: 0;
  height: 46%;
  width: auto;
  object-fit: cover;
  object-position: center 55%;
  pointer-events: none;
  border-radius: 10px;
}

.now {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  min-height: var(--cap);
  margin-top: 2px;
}

.caps {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 4px;
  padding-left: 22px;
}

.cap {
  --face: var(--cap, 48px);
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ak-bg);
  cursor: pointer;
}

.now-cap {
  width: var(--cap);
  height: var(--cap);
  min-width: 48px;
  min-height: 48px;
  flex: 0 0 var(--cap);
}

.cap img,
.mini img {
  width: var(--face);
  height: var(--face);
  object-fit: contain;
  pointer-events: none;
}

.face {
  position: absolute;
  left: 20%;
  top: 20%;
  width: 60%;
  height: 60%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, var(--ak-ink), color-mix(in srgb, var(--ak-ink) 70%, var(--ak-bg)));
  color: var(--ak-bg);
  font-family: var(--ak-font-display);
  font-size: calc(var(--face) * 0.38);
  line-height: 1;
  pointer-events: none;
}

.cap.is-selected img {
  filter: drop-shadow(0 0 8px var(--ak-glow));
}

.cap.is-match .face {
  box-shadow: inset 0 0 0 3px var(--ak-accent);
}

.cap.is-wrong .face {
  box-shadow: 0 0 0 3px var(--ak-accent-2);
}

.cap.is-same {
  opacity: 0.45;
}

.lamps {
  position: absolute;
  top: 8px;
  right: 4px;
  bottom: 8px;
  z-index: 3;
  display: flex;
  flex-direction: column-reverse;
  justify-content: space-between;
  width: 32px;
  pointer-events: none;
}

.lamp {
  width: 32px;
  aspect-ratio: 1;
  max-height: 32px;
  border-radius: 50%;
  overflow: hidden;
}

.lamp img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.32);
}

.lamp.is-off img {
  filter: grayscale(0.35) brightness(0.62);
}

.lamp.is-on img {
  filter: saturate(1.2) drop-shadow(0 0 4px var(--ak-glow));
}

.ball {
  position: absolute;
  z-index: 4;
  left: 6px;
  bottom: calc(var(--cap) * 0.42);
  width: 58px;
  height: 58px;
  object-fit: contain;
  pointer-events: none;
}

.alpha {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  width: min(100%, 308px);
  margin: 0 auto;
}

.key {
  --cap: 48px;
  --face: 48px;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  min-width: 48px;
  min-height: 48px;
}

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

.back,
.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);
  cursor: pointer;
}

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

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

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

.now-cap:active .pop,
.key:active .pop {
  transform: translateY(2px) scale(0.94);
}

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

.compare {
  flex: 1 1 0;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 40px 6px 8px;
  overflow: hidden;
}

.compare-head {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.compare-head h2 {
  margin: 0;
  text-align: center;
  font-family: var(--ak-font-display);
  font-size: 13px;
  font-weight: var(--ak-title-weight);
  color: var(--ak-accent);
}

.compare-round {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.compare:not(.is-caps) {
  container-type: size;
}

.compare:not(.is-caps) .compare-cols {
  container-type: normal;
}

.compare:not(.is-caps) .compare-round {
  flex: var(--rows) 1 0;
}

.compare-len {
  margin: 0 0 2px;
  flex: 0 0 auto;
  text-align: center;
  font-size: 12px;
  color: var(--ak-ink-muted);
}

.compare-cols {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  container-type: size;
}

.compare ol {
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  list-style: none;
}

.compare:not(.is-caps) ol {
  gap: 2px;
}

.compare li {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1px;
}

.compare li .mini,
.compare li .mini .pop,
.compare li .mini img {
  min-width: 0;
  min-height: 0;
}

.play.is-card #goal {
  display: none;
}

.compare:not(.is-caps) li {
  width: min(100%, 8.4em);
  height: auto;
  padding: 0 6px;
  border-radius: 999px;
  border: 1px solid var(--ak-outline);
  background: var(--ak-ink);
  color: var(--ak-bg);
  font-family: var(--ak-font-display);
  font-size: max(12px, min(16px, calc(100cqh / (var(--all) + 14))));
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.08em;
  line-height: 1;
}

.compare li .mini {
  --face: min(36px, calc((100cqh - (var(--rows, 4) - 1) * 4px) / var(--rows, 4)));
  width: var(--face);
  height: var(--face);
  max-height: none;
  flex: 0 0 auto;
}

.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;
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: var(--ak-title-weight);
  line-height: 1.3;
  color: var(--ak-ink);
}

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

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

.play.is-reason .alpha,
.play.is-reason .actions,
.play.is-reveal .alpha,
.play.is-reveal .actions,
.play.is-card .alpha,
.play.is-card .actions,
.play.is-reveal .live-lane,
.play.is-card .live-lane,
.play.is-reveal .ball,
.play.is-card .ball {
  display: none;
}

.play.is-reason .now-cap,
.play.is-reveal .cap,
.play.is-card .cap {
  pointer-events: none;
}

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

.bit {
  position: absolute;
  bottom: 28%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  opacity: 0.95;
}

.bit.is-gold { background: var(--ak-accent); }
.bit.is-cream { background: var(--ak-ink); }
.bit.is-hot { background: var(--ak-accent-2); }

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

  .ball {
    animation: bob 2.6s ease-in-out infinite;
  }

  .ball.is-hop {
    animation: hop 0.48s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .ball.is-rattle {
    animation: rattle 0.42s ease-in-out;
  }

  .play.is-invite .now-cap .pop {
    animation: invite 1.25s ease-in-out infinite;
  }

  .play.is-invite .now-cap:nth-child(2) .pop { animation-delay: 0.08s; }
  .play.is-invite .now-cap:nth-child(3) .pop { animation-delay: 0.16s; }
  .play.is-invite .now-cap:nth-child(4) .pop { animation-delay: 0.24s; }
  .play.is-invite .now-cap:nth-child(5) .pop { animation-delay: 0.32s; }

  .cap.is-pop .pop,
  .play.is-invite .now-cap.is-pop .pop {
    animation: squash 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .turn.is-cue {
    animation: turn-cue 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .play.is-ready .check {
    animation: ready 1s ease-in-out infinite;
  }

  .play.is-cheer .ripple {
    animation: rise 0.95s ease-out;
  }

  .play.is-cheer .lamp.is-on img {
    animation: wink 0.55s ease-in-out 3;
    animation-delay: calc(var(--i) * 0.07s);
  }

  .lamp.is-on img {
    animation: lamp-idle 2.8s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.18s);
  }

  .play.is-wrong .end-word {
    animation: point 0.7s ease-in-out 2;
  }

  .compare li {
    animation: row-in 0.38s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

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

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

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

@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  35% { transform: translateY(-32px) scale(0.9, 1.12); }
  62% { transform: translateY(-4px) scale(1.08, 0.9); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes rattle {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  20% { transform: translate(-7px, 10px) rotate(-8deg); }
  45% { transform: translate(8px, 12px) rotate(7deg); }
  70% { transform: translate(-4px, 6px) rotate(-4deg); }
}

@keyframes invite {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.06, 0.94); }
}

@keyframes squash {
  0% { transform: scale(1, 1); }
  35% { transform: scale(1.16, 0.8); }
  70% { transform: scale(0.94, 1.1); }
  100% { transform: scale(1, 1); }
}

@keyframes turn-cue {
  0% { transform: scale(1) rotate(0); }
  40% { transform: scale(1.08) rotate(-2deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes ready {
  0%, 100% { box-shadow: var(--ak-shadow); }
  50% { box-shadow: var(--ak-shadow), 0 0 18px var(--ak-glow); }
}

@keyframes rise {
  0% { transform: translateY(10%); opacity: 0.9; }
  100% { transform: translateY(-320%); opacity: 0; }
}

@keyframes wink {
  0%, 100% { filter: saturate(1.1) drop-shadow(0 0 3px var(--ak-glow)); }
  50% { filter: saturate(1.5) brightness(1.3) drop-shadow(0 0 12px var(--ak-glow)); }
}

@keyframes lamp-idle {
  0%, 100% { filter: saturate(1.1) drop-shadow(0 0 2px var(--ak-glow)); }
  50% { filter: saturate(1.3) brightness(1.12) drop-shadow(0 0 7px var(--ak-glow)); }
}

@keyframes point {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

@keyframes row-in {
  0% { opacity: 0; transform: translateY(12px) scale(0.94, 0.9); }
  60% { opacity: 1; transform: translateY(0) scale(1.04, 1); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes burst {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.35);
    opacity: 0;
  }
}

@media (hover: hover) {
  .check:hover,
  .btn-go:hover {
    background: var(--ak-btn-hover);
  }
}
