*,
*::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.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;
}

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

.play {
  --pad-top: max(8px, 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%, 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 top;
  background-repeat: no-repeat;
}

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

.drop {
  position: absolute;
  width: 16px;
  height: 20px;
  border: 2px solid var(--ak-outline);
  border-radius: 46% 46% 50% 50%;
  background: var(--ak-accent);
  opacity: 0.8;
}

.drop-a { left: 8%; top: 18%; background: var(--ak-accent); }
.drop-b { right: 10%; top: 28%; width: 12px; height: 16px; background: var(--ak-accent-2); }
.drop-c { left: 14%; bottom: 16%; background: var(--ak-accent-2); }
.drop-d { right: 18%; bottom: 22%; width: 18px; height: 22px; background: var(--ak-accent); }

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

.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;
  touch-action: manipulation;
}

.mute-icon {
  width: 22px;
  height: 22px;
  background: currentColor;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M4 9v6h4l5 4V5L8 9H4zm12.5 3a4.5 4.5 0 0 0-2.5-4v8a4.5 4.5 0 0 0 2.5-4z'/></svg>") center / contain no-repeat;
}

.mute.is-muted .mute-icon {
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path fill='black' d='M4 9v6h4l5 4V5L8 9H4zm11.6 1.1 1.4-1.4 1.4 1.4 1.4-1.4 1.4 1.4-1.4 1.4 1.4 1.4-1.4 1.4-1.4-1.4-1.4 1.4-1.4-1.4 1.4-1.4-1.4-1.4z'/></svg>") center / contain no-repeat;
}

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

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

.turn {
  margin-left: auto;
  max-width: 52%;
  padding: 4px 8px;
  text-align: right;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.turn-who,
.round-pip {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.4vw, 22px);
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-ink);
  white-space: nowrap;
}

.round-pip {
  margin-top: 2px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ak-ink-muted);
}

.voice {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  min-height: 44px;
  margin: 0;
  padding: 6px 12px;
  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);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ak-ink);
}

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

.scores.is-solo {
  grid-template-columns: 1fr;
}

.score {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name now" "saved now";
  align-items: center;
  column-gap: 8px;
  min-height: 48px;
  padding: 4px 10px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.score.is-live {
  box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent);
}

.score.is-winner {
  box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent-2);
}

.score-name {
  grid-area: name;
  font-family: var(--ak-font-display);
  font-size: 13px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-ink);
}

.score-saved {
  grid-area: saved;
  font-size: 12px;
  font-weight: 700;
  color: var(--ak-ink-muted);
}

.score-now {
  grid-area: now;
  font-family: var(--ak-font-display);
  font-size: clamp(22px, 6vw, 32px);
  font-weight: var(--ak-title-weight);
  line-height: 0.9;
  color: var(--ak-accent);
  text-shadow: 2px 2px 0 var(--ak-outline);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.board-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 13% 7% 5%;
  background: url("./art/letter-board.png") center / 100% 100% no-repeat;
}

.category {
  align-self: center;
  max-width: 92%;
  margin: 0;
  padding: 2px 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: clamp(13px, 3.5vw, 18px);
  font-weight: var(--ak-title-weight);
  line-height: 1.3;
  color: var(--ak-ink);
}

.board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 6px 8px;
  padding: 4px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--ak-surface) 90%, var(--ak-accent-2));
  perspective: 640px;
}

.word {
  display: flex;
  gap: 3px;
  max-width: 100%;
}

.tile {
  display: grid;
  place-items: center;
  width: clamp(18px, min(8vw, 5.2dvh), 36px);
  height: clamp(22px, min(9vw, 6dvh), 42px);
  border: 2px solid var(--ak-outline);
  border-radius: 42% 42% 48% 48%;
  background: var(--ak-surface);
  box-shadow: 0 2px 0 var(--ak-outline);
}

.tile.is-open {
  border-color: transparent;
  background: url("./art/letter-tile.png") center / 100% 100% no-repeat;
  box-shadow: none;
}

.glyph {
  display: grid;
  place-items: center;
  width: 62%;
  height: 58%;
  border-radius: 34%;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(12px, 3.5vw, 18px);
  font-weight: var(--ak-title-weight);
  line-height: 1;
}

.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 0;
}

.wheel {
  position: relative;
  display: block;
  width: min(46vw, 30dvh, 210px);
  aspect-ratio: 384 / 370;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.wheel-bob {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
}

.wheel-tilt,
.wheel-spin {
  position: absolute;
  inset: 0;
}

.wheel-spin {
  transform-origin: 48% 50%;
}

.wheel-art,
.pointer-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.wheel-art {
  clip-path: circle(45% at 48% 50%);
}

.pointer-art {
  position: absolute;
  inset: 0;
  z-index: 2;
  clip-path: polygon(88% 50%, 100% 38%, 100% 62%);
}

.wedge-badge {
  margin: 0;
  padding: 2px 12px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: clamp(14px, 4vw, 20px);
  font-weight: var(--ak-title-weight);
  line-height: 1.2;
  color: var(--ak-accent);
  text-align: center;
}

.wedge-badge.is-sour {
  color: var(--ak-ink);
  background: color-mix(in srgb, var(--ak-accent-2) 55%, var(--ak-surface));
}

.letters,
.vowels {
  display: grid;
  width: 100%;
  gap: 4px;
}

.letters {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.vowels {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.actions,
.solve-actions,
.result-actions {
  display: flex;
  width: 100%;
  gap: 8px;
}

.btn-go,
.btn-alt,
.key,
.solve-input {
  min-height: 48px;
  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);
  touch-action: manipulation;
  cursor: pointer;
}

.btn-go,
.btn-alt {
  flex: 1 1 0;
  padding: 0 10px;
  font-size: clamp(14px, 3.8vw, 17px);
}

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

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

.buy {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding-left: 4px;
}

.buy img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  pointer-events: none;
}

.buy span {
  font-size: clamp(13px, 3.4vw, 16px);
  line-height: 1.05;
}

.key {
  padding: 0;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 18px;
}

.key.is-used,
.buy.is-used {
  opacity: 0.45;
}

.solve-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 6px;
}

.solve-input {
  width: 100%;
  padding: 0 12px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  user-select: text;
}

.solve-input::placeholder {
  text-transform: none;
  color: var(--ak-ink-muted);
  font-weight: 500;
}

.play.is-letters .wheel,
.play.is-vowels .wheel,
.play.is-form .wheel {
  display: none;
}

.play.is-letters #buy,
.play.is-vowels #buy {
  display: none;
}

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

.play.is-card .dock {
  display: none;
}

.play.is-sour .wheel-art {
  filter: saturate(1.7) hue-rotate(62deg);
}

.result-card {
  padding: 12px 12px 10px;
  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);
}

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

.bubble,
.confetti {
  position: absolute;
  pointer-events: none;
}

.bubble {
  left: 50%;
  top: 36%;
  width: 58px;
  height: 58px;
  margin-left: -29px;
  border: 3px solid var(--ak-outline);
  border-radius: 50%;
  background: color-mix(in srgb, var(--ak-accent) 38%, var(--ak-surface));
  box-shadow: inset 0 0 0 6px color-mix(in srgb, var(--ak-accent-2) 35%, transparent), 0 0 12px var(--ak-glow);
}

.confetti {
  top: -8px;
  width: 9px;
  height: 13px;
  border: 1px solid var(--ak-outline);
  border-radius: 40% 40% 48% 48%;
  background: var(--ak-accent);
}

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

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

button:focus,
.solve-input:focus {
  outline: none;
}

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

.btn-go:active {
  background: var(--ak-btn-active);
}

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

  .stage,
  .dock {
    gap: 4px;
  }

  .play-logo {
    height: 36px;
  }

  .buy img {
    width: 32px;
    height: 32px;
  }
}

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

@media (hover: hover) {
  .mute:hover,
  .btn-go:hover,
  .btn-alt:hover,
  .key:hover {
    transform: translateY(-1px);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .play.is-idle .wheel-bob {
    animation: wobble 2.8s ease-in-out infinite;
  }

  .play.is-idle .board-wrap {
    animation: wobble 3.6s ease-in-out infinite;
  }

  .play-logo {
    animation: logo-idle 3.2s ease-in-out infinite;
  }

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

  .drop-b { animation-delay: -1.4s; }
  .drop-c { animation-delay: -2.6s; }
  .drop-d { animation-delay: -3.8s; }

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

  .voice.is-shake {
    animation: shake 380ms ease;
  }

  .score-now.is-bump,
  .score-saved.is-bump,
  .wedge-badge.is-pop {
    animation: bump 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .score-now.is-melt {
    animation: melt 480ms ease;
  }

  .score-now.is-pay {
    animation: pay 360ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .tile.is-flip {
    animation: flip 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .play.is-win .tile.is-open {
    animation: glow-chase 900ms linear infinite;
  }

  .play.is-win .tile.is-open.is-flip {
    animation: flip 460ms cubic-bezier(0.34, 1.56, 0.64, 1), glow-chase 900ms linear 460ms infinite;
  }

  .wheel-tilt.is-land {
    animation: land 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .wheel:active .wheel-bob,
  .key:active,
  .btn-go:active,
  .btn-alt:active,
  .mute:active {
    animation: none;
    transform: scale(0.96, 0.92);
  }

  .bubble {
    animation: bubble-pop 520ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }

  .confetti {
    animation: candy-fall 1200ms ease-in forwards;
  }
}

@keyframes wobble {
  0%, 100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg); }
}

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

@keyframes drift {
  0%, 100% { transform: translateY(0) rotate(-6deg); }
  50% { transform: translateY(-12px) rotate(8deg); }
}

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

@keyframes pay {
  0% { transform: scale(1); }
  40% { transform: scale(0.86, 1.12); }
  100% { transform: scale(1); }
}

@keyframes melt {
  0% { transform: scale(1, 1); }
  45% { transform: scale(1.2, 0.35); }
  100% { transform: scale(1, 1); }
}

@keyframes flip {
  0% { transform: rotateX(86deg) scale(0.84, 0.7); }
  58% { transform: rotateX(-10deg) scale(1.08, 0.94); }
  100% { transform: rotateX(0deg) scale(1); }
}

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

@keyframes land {
  0% { transform: scale(1); }
  40% { transform: scale(1.07, 0.9); }
  100% { transform: scale(1); }
}

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

@keyframes bubble-pop {
  0% { transform: scale(0.3); opacity: 0.2; }
  55% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

@keyframes candy-fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(68vh) rotate(var(--spin, 120deg)); opacity: 0.2; }
}
