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

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

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  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);
}

[hidden] {
  display: none !important;
}

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

.play {
  --pad-top: max(6px, env(safe-area-inset-top, 0px));
  --pad-side: 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: flex;
  flex-direction: column;
  gap: 4px;
  width: min(100%, 430px);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: var(--pad-top) var(--pad-side) var(--pad-bot);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-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 top;
  background-repeat: no-repeat;
}

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

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

.mute.is-muted .wave {
  opacity: 0;
}

.top,
.line,
.ribbon,
.tray,
.kept,
.result {
  position: relative;
  z-index: 1;
}

.top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "logo timer"
    "turn timer";
  align-items: center;
  column-gap: 8px;
  min-height: 56px;
  padding-left: 52px;
}

.play-logo {
  grid-area: logo;
  display: block;
  width: auto;
  height: 34px;
  max-width: 100%;
  object-fit: contain;
  justify-self: start;
}

.turn {
  grid-area: turn;
  min-width: 0;
}

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

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

.timer {
  grid-area: timer;
  position: relative;
  width: min(58px, 16vw);
  aspect-ratio: 299 / 384;
}

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

.face {
  position: absolute;
  left: 58.5%;
  top: 56%;
  width: 54%;
  height: 46%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--ak-surface);
}

.hand {
  position: absolute;
  z-index: 1;
  left: 60.9%;
  top: 64.8%;
  width: 11%;
  height: 29%;
  border-radius: 999px;
  background: var(--ak-ink);
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(var(--hand, 0deg));
}

.line {
  min-height: 44px;
}

.voice,
.why {
  margin: 0;
  min-height: 44px;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: clamp(16px, 4.5vw, 20px);
  line-height: 1.15;
  text-align: center;
  color: var(--ak-ink);
}

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

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

.current {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: clamp(20px, 6vw, 28px);
  letter-spacing: 0.08em;
  line-height: 1;
  color: var(--ak-ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.current.is-empty {
  letter-spacing: 0;
  font-size: 16px;
  color: var(--ak-ink-muted);
}

.hint,
.keep,
.btn-go,
.btn-alt {
  min-width: 48px;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

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

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

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

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

.tray {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  touch-action: none;
}

.tray-wrap {
  position: relative;
  width: min(100%, calc(100dvh - 248px));
  aspect-ratio: 1;
}

.tray-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.wells,
.links,
.beads,
.board {
  position: absolute;
}

.wells {
  inset: 8%;
  touch-action: none;
}

.links,
.beads,
.board {
  inset: 0;
}

.links,
.beads {
  overflow: visible;
  pointer-events: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 2px;
  touch-action: none;
}

button.cube {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  container-type: size;
  touch-action: none;
}

.pop {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 384 / 358;
  max-height: 100%;
  transform-origin: 50% 60%;
}

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

.plate {
  position: absolute;
  left: 63%;
  top: 52%;
  width: 44%;
  height: 54%;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 2px solid var(--ak-outline);
  border-radius: 18%;
  background: var(--ak-accent-2);
  pointer-events: none;
}

.glyph {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 32cqmin;
  line-height: 0.85;
  color: var(--ak-accent);
}

.badge {
  position: absolute;
  z-index: 2;
  top: 2%;
  left: 4%;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 2px solid var(--ak-outline);
  border-radius: 999px;
  background: var(--ak-accent);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

.coach-bead {
  position: absolute;
  z-index: 4;
  top: -48%;
  left: 50%;
  width: 50%;
  height: 50%;
  margin-left: -25%;
  object-fit: contain;
  pointer-events: none;
}

.bead {
  position: absolute;
  object-fit: contain;
  pointer-events: none;
}

.cube.is-on .plate {
  background: var(--ak-accent);
}

.cube.is-on .glyph {
  color: var(--ak-accent-2);
}

.cube.is-down .pop {
  transform: scale(1.08, 0.86);
}

.cube.is-ring .pop {
  border-radius: 18%;
  outline: 3px solid var(--ak-accent);
  outline-offset: 1px;
}

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

.kept {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.kept-label,
.story-label {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: 14px;
  font-weight: var(--ak-title-weight);
  letter-spacing: 0;
  color: var(--ak-ink);
}

.kept-label {
  flex: 0 0 auto;
}

.kept-list,
.story-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.kept-list {
  flex: 1 1 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  min-height: 32px;
}

.kept-list .chip,
.kept-empty {
  flex: 0 0 auto;
  color: var(--ak-ink);
  font-weight: 800;
}

.kept-empty {
  color: var(--ak-ink-muted);
  font-weight: 700;
}

.play.is-reason .ribbon,
.play.is-card .ribbon,
.play.is-card .kept {
  display: none;
}

.play.is-card .tray {
  flex: 0 0 auto;
}

.play.is-card .tray-wrap {
  width: min(100%, 42dvh, calc(100dvh - 320px));
}

.result {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  z-index: 4;
}

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

.story {
  margin-top: 8px;
}

.story-label {
  margin: 10px 0 6px;
}

.story-list {
  padding: 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-bg);
}

.word {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  color: var(--ak-ink);
  font-weight: 800;
}

.tag {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.word.is-longest .chip {
  padding: 0 10px;
  border: 3px solid var(--ak-accent);
  border-radius: 999px;
  background: var(--ak-accent-2);
}

.result-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  background: var(--ak-surface);
}

.btn-go,
.btn-alt {
  flex: 1 1 140px;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.bit,
.floater {
  position: absolute;
  top: 38%;
  left: 50%;
  pointer-events: none;
}

.bit {
  width: 12px;
  height: 16px;
  border: 2px solid var(--ak-outline);
  border-radius: 40% 40% 50% 50%;
  background: var(--ak-accent-2);
}

.bit.is-hot {
  background: var(--ak-accent);
  border-radius: 4px;
}

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

.floater {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 28px;
  color: var(--ak-accent);
}

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

  .hint:hover,
  .btn-alt:hover,
  .mute:hover {
    transform: translateY(-1px);
  }
}

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

  .timer {
    animation: timer-idle 2.8s ease-in-out infinite;
  }

  .timer.is-low {
    animation: wobble 0.28s ease-in-out infinite;
  }

  .cube.is-coach .badge {
    animation: badge-pop 1.15s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * 0.14s);
  }

  .coach-bead {
    animation: bead-idle 0.9s ease-in-out infinite;
  }

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

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

  .cube.is-shake .pop {
    animation: shake 0.4s ease-in-out;
  }

  .cube.is-chase .pop {
    animation: chase 0.7s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * 0.12s);
  }

  .bead {
    animation: bead-in 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .links.is-snap,
  .beads.is-snap {
    animation: snap-away 0.34s ease-in forwards;
  }

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

  .word.is-miss {
    animation: slide-in 0.35s ease-out both;
    animation-delay: var(--d, 0ms);
  }

  .word.is-hop .chip {
    animation: hop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
  }

  .bit {
    animation: splash 0.75s ease-out forwards;
  }

  .floater {
    animation: rise 0.7s ease-out forwards;
  }
}

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

@keyframes timer-idle {
  0%, 100% { transform: rotate(-2deg); }
  50% { transform: rotate(3deg); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(-7deg) scale(1); }
  50% { transform: rotate(7deg) scale(1.05); }
}

@keyframes badge-pop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

@keyframes bead-idle {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-5px) scale(1.08); }
}

@keyframes squash {
  0% { transform: scale(1, 1); }
  40% { transform: scale(1.1, 0.84); }
  100% { transform: scale(1, 1); }
}

@keyframes bounce {
  0% { transform: scale(1.08, 0.86); }
  45% { transform: scale(0.92, 1.14); }
  100% { transform: scale(1, 1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-3deg); }
  40% { transform: translateX(5px) rotate(3deg); }
  60% { transform: translateX(-4px) rotate(-2deg); }
  80% { transform: translateX(3px); }
}

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

@keyframes bead-in {
  0% { transform: scale(0.4); }
  100% { transform: scale(1); }
}

@keyframes snap-away {
  to {
    opacity: 0;
    transform: scale(1.12);
  }
}

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

@keyframes slide-in {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-12px) scale(1.08); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes splash {
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) rotate(var(--rot)) scale(0.4);
  }
}

@keyframes rise {
  to {
    opacity: 0;
    transform: translateY(-36px) scale(1.1);
  }
}
