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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

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,
input {
  font: 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(10px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: fixed;
  z-index: 1;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(100%, 420px);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0;
  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 top;
  background-repeat: no-repeat;
}

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

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

.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: 3px 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-svg {
  width: 26px;
  height: 26px;
}

.mute .slash {
  display: none;
}

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

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

.mute:active {
  transform: translateY(2px) scale(0.96);
  box-shadow: none;
}

.top,
.voice,
.reason,
.court,
.dock,
.result {
  position: relative;
  z-index: 1;
}

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

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

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

.turn {
  min-width: 0;
  padding: 4px 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);
}

.turn-who {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-ink);
}

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

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

.voice {
  min-height: 3.6em;
}

.reason {
  border-color: var(--ak-accent);
  font-weight: 800;
}

.court {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.tape {
  position: relative;
  container-type: inline-size;
  flex: 0 0 auto;
}

.tape-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
}

.sheen,
.range,
.marks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.sheen {
  background: linear-gradient(
    115deg,
    transparent 32%,
    color-mix(in srgb, var(--ak-surface) 70%, transparent) 48%,
    transparent 62%
  );
  mix-blend-mode: soft-light;
  opacity: 0.45;
}

.range {
  z-index: 1;
  overflow: visible;
}

.range polyline {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.range-all {
  stroke: var(--ak-ink);
  stroke-width: 8px;
  opacity: 0.22;
}

.range-live {
  stroke: var(--ak-accent-2);
  stroke-width: 14px;
  opacity: 0.95;
}

.marks {
  z-index: 2;
}

.gap-count {
  position: absolute;
  left: 52%;
  top: 58%;
  z-index: 6;
  width: max-content;
  max-width: 46%;
  margin: 0;
  padding: 4px 8px 6px;
  border: 3px solid var(--ak-accent);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.gap-n {
  display: block;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 8cqw, 30px);
  font-weight: var(--ak-title-weight);
  line-height: 0.9;
  color: var(--ak-ink);
}

.gap-k {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--ak-ink-muted);
}

.mark {
  position: absolute;
  z-index: 3;
  transform: translate(-50%, -50%);
}

.ball {
  width: clamp(56px, 22cqw, 72px);
  aspect-ratio: 1;
}

.ball-face,
.flop-face {
  position: relative;
  width: 100%;
}

.ball img,
.flop img,
.roll img {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
}

.letters {
  position: absolute;
  inset: 18% 6% 22%;
  display: grid;
  place-items: center;
  font-family: var(--ak-font-body);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.06em;
  color: var(--ak-link);
  text-align: center;
  pointer-events: none;
}

.splash {
  position: absolute;
  left: 50%;
  top: 62%;
  width: 86%;
  height: 34%;
  border: 3px solid var(--ak-accent-2);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
}

.flop {
  z-index: 2;
  width: clamp(34px, 13cqw, 48px);
}

.flop.is-late .flop-face img {
  transform: scaleX(-1);
}

.pin {
  position: absolute;
  left: 50%;
  top: 78%;
  min-width: 52px;
  padding: 2px 6px 3px;
  border: 2px solid var(--ak-outline);
  border-radius: 12px;
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  text-align: center;
  transform: translateX(-50%);
}

.flop.is-south .pin {
  top: auto;
  bottom: 78%;
}

.pin-k {
  display: block;
  font-style: normal;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.pin-w {
  display: block;
  font-size: 12px;
  line-height: 1.1;
  color: var(--ak-ink);
}

.pin-w:empty {
  display: none;
}

.flop.is-hot .pin {
  border-color: var(--ak-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ak-accent) 40%, transparent), var(--ak-shadow);
}

.dock {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}

.guess,
.check,
.btn-go,
.btn-alt {
  width: 100%;
  min-height: 48px;
  border-radius: var(--ak-radius);
  border: 3px solid var(--ak-outline);
  box-shadow: var(--ak-shadow);
  cursor: pointer;
}

.guess {
  display: block;
  padding: 0 12px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: lowercase;
  user-select: text;
}

.guess::placeholder {
  color: var(--ak-ink-muted);
  letter-spacing: 0.12em;
}

.guess.is-invite {
  border-color: var(--ak-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ak-accent) 35%, transparent), var(--ak-shadow);
}

.guess.is-bad {
  border-color: var(--ak-accent);
}

.check,
.btn-go {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: var(--ak-title-weight);
}

.btn-alt {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border-color: var(--ak-choice-border);
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: var(--ak-title-weight);
}

.check:active,
.btn-go:active,
.btn-alt:active,
.guess:active {
  transform: translateY(3px);
  box-shadow: none;
}

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

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

.result {
  flex: 0 0 auto;
}

.result-card {
  padding: 12px;
  border: 3px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.result-says {
  margin: 0 0 10px;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
  line-height: 1.15;
  color: var(--ak-ink);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.roll {
  position: absolute;
  left: 50%;
  top: 36%;
  width: 54px;
  height: 54px;
  z-index: 2;
}

.roll .letters {
  font-size: 11px;
}

.bit {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px;
}

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

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

  .btn-alt:hover {
    border-color: var(--ak-choice-selected-border);
  }

  .mute:hover {
    transform: translateY(-1px);
  }
}

@media (max-height: 700px) {
  .play {
    gap: 4px;
  }

  .play-logo {
    height: 36px;
  }

  .voice,
  .reason {
    padding: 4px 8px;
    font-size: 14px;
  }

  .result-card {
    padding: 8px;
  }

  .result-says {
    margin-bottom: 6px;
    font-size: 18px;
  }
}

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

  .sheen {
    animation: glare 5.5s ease-in-out infinite;
  }

  .flop-face {
    animation: bob 2.8s ease-in-out infinite;
  }

  .flop.is-late .flop-face {
    animation-delay: -0.8s;
  }

  .flop-face.is-hop {
    animation: hop 0.48s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .mark {
    transition:
      left 0.45s cubic-bezier(0.34, 1.56, 0.64, 1),
      top 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

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

  .ball.is-plop .splash,
  .ball.is-pop .splash {
    animation: ring 0.6s ease-out;
  }

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

  .tape.is-reel .tape-art {
    animation: reel 0.45s ease;
  }

  .play.is-win .tape {
    animation: chase 1.1s ease-in-out 2;
  }

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

  .check.is-invite {
    animation: invite 1.05s ease-in-out infinite;
  }

  .guess.is-shake {
    animation: shake 0.4s ease;
  }

  .roll {
    animation: roll 0.65s cubic-bezier(0.45, 0, 0.8, 1) forwards;
  }

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

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

@keyframes glare {
  0%, 100% { transform: translateX(-12%); opacity: 0.25; }
  50% { transform: translateX(12%); opacity: 0.7; }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-16px) scale(0.92, 1.12); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes plop {
  0% { transform: translateY(-26px) scale(1.16, 0.78); }
  55% { transform: translateY(0) scale(1.14, 0.76); }
  78% { transform: translateY(-6px) scale(0.94, 1.08); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes ring {
  0% { opacity: 0.95; transform: translate(-50%, -50%) scale(0.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.85); }
}

@keyframes sunspin {
  0% { transform: translateY(0) scale(1) rotate(0deg); }
  35% { transform: translateY(-24px) scale(1.22, 0.82) rotate(200deg); }
  70% { transform: translateY(-6px) scale(0.92, 1.1) rotate(330deg); }
  100% { transform: translateY(0) scale(1.06) rotate(360deg); }
}

@keyframes reel {
  0% { transform: scale(1); }
  40% { transform: scale(0.96, 1.03); }
  100% { transform: scale(1); }
}

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

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

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

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

@keyframes roll {
  0% { transform: translate(-50%, -50%) rotate(0deg) scale(1); opacity: 1; }
  100% { transform: translate(-50%, 38vh) rotate(220deg) scale(0.7); opacity: 0; }
}

@keyframes fly {
  to { transform: translate(var(--dx), var(--dy)) rotate(180deg); opacity: 0; }
}
