*,
*::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.25;
  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: 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-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  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,
.brief,
.log,
.why,
.actions,
.result {
  position: relative;
  z-index: 7;
  flex: 0 0 auto;
}

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

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

.turn {
  min-width: 0;
  transform-origin: left center;
}

.turn-who {
  display: inline-block;
  margin: 0;
  border-bottom: 3px solid var(--ak-accent-2);
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 5.4vw, 28px);
  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: 13px;
  font-weight: 700;
}

.voice,
.brief,
.log,
.why,
.result-card {
  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);
}

.voice,
.why {
  margin: 0;
  padding: 6px 8px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.voice.is-invite {
  border-color: var(--ak-accent);
  box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent-2);
}

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

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

.brief {
  padding: 4px 8px 5px;
}

.goal,
.clue {
  margin: 0;
}

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

.clue {
  margin-top: 2px;
  color: var(--ak-accent);
  font-size: 14px;
  font-weight: 700;
}

.log {
  margin: 0;
  padding: 4px 8px;
  list-style: none;
}

.log li {
  margin: 0;
  color: var(--ak-ink-muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
}

.log .is-left,
.log .is-right,
.log .is-watch {
  color: var(--ak-ink);
}

.log .is-left,
.log .is-right {
  color: var(--ak-accent);
}

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

.stage {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  touch-action: manipulation;
}

.scale-bay {
  container-type: size;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: end center;
}

.scale {
  position: relative;
  width: min(100cqw, calc(100cqh * 384 / 315));
  max-width: 100%;
  aspect-ratio: 384 / 315;
}

.halo,
.base,
.dust {
  position: absolute;
  pointer-events: none;
}

.halo {
  inset: 6% 4% 10%;
  border-radius: 46%;
  opacity: 0;
}

.base {
  left: 28%;
  right: 28%;
  bottom: 1%;
  height: 8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ak-outline) 35%, transparent);
}

.tilt {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: 50% 18%;
}

.tilt.is-left {
  transform: rotate(-8deg);
}

.tilt.is-right {
  transform: rotate(8deg);
}

.tilt.is-still,
.tilt.is-rest,
.tilt.is-level {
  transform: none;
}

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

.pan-zone {
  position: absolute;
  bottom: 7%;
  width: 40%;
  height: 44%;
  min-width: 48px;
  min-height: 48px;
}

.pan-zone.is-left {
  left: 1%;
}

.pan-zone.is-right {
  right: 1%;
}

.stack {
  position: absolute;
  z-index: 2;
  inset: 0 0 16px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-end;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}

.pan-hit {
  position: absolute;
  z-index: 1;
  inset: 0;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 2px dashed transparent;
  border-radius: 42% 42% 48% 48%;
  background: transparent;
}

.pan-zone.is-fault .pan-hit,
.pan-zone.is-coach .pan-hit {
  border-color: var(--ak-accent);
  background: color-mix(in srgb, var(--ak-accent) 22%, transparent);
}

.pan-name {
  position: absolute;
  z-index: 3;
  bottom: 10%;
  left: 50%;
  width: max-content;
  max-width: 92%;
  padding: 2px 6px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
  box-shadow: var(--ak-shadow);
}

.pan-zone.is-coach::before,
.coin.is-coach::before {
  content: "";
  position: absolute;
  z-index: 4;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-accent);
  box-shadow: var(--ak-shadow);
}

.pan-zone.is-coach::before {
  top: -8px;
  left: 50%;
  margin-left: -7px;
}

.coin.is-coach::before {
  top: -12px;
  left: 50%;
  margin-left: -7px;
}

.bench {
  display: grid;
  grid-template-columns: repeat(4, 48px);
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 6px 6px 28px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 84%, transparent);
  box-shadow: var(--ak-shadow);
}

.bench.is-fault {
  border-color: var(--ak-accent);
  box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent);
}

.coin {
  position: relative;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-accent-2);
  box-shadow: var(--ak-shadow);
  overflow: visible;
}

.coin img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  pointer-events: none;
}

.coin .num {
  position: absolute;
  bottom: 1px;
  left: 50%;
  padding: 0 3px;
  border-radius: 4px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  transform: translateX(-50%);
  pointer-events: none;
}

.stack .coin {
  pointer-events: auto;
}

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

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

.coin.is-shake {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.coin.is-sink {
  z-index: 3;
  transform: translateY(22px);
}

.dust {
  inset: 8% 18% 40%;
  z-index: 3;
}

.speck {
  position: absolute;
  bottom: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ak-accent-2);
  opacity: 0.45;
}

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

.btn-go,
.btn-check,
.btn-alt {
  flex: 1 1 auto;
  min-width: 48px;
  min-height: 48px;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

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

.btn-check {
  background: var(--ak-accent-2);
  color: var(--ak-ink);
  box-shadow: var(--ak-shadow);
}

.btn-alt {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border-color: var(--ak-choice-border);
  box-shadow: var(--ak-shadow);
}

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

.coin:active,
.pan-hit:active,
.btn-go:active,
.btn-check:active,
.btn-alt:active,
.mute:active {
  box-shadow: 0 0 0 var(--ak-outline);
}

.result-card {
  padding: 10px;
  background: var(--ak-surface);
}

.result-says {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 4.8vw, 26px);
  font-weight: var(--ak-title-weight);
  line-height: 1.15;
  color: var(--ak-ink);
}

.result-says:focus {
  outline: none;
}

.result-score {
  margin: 4px 0 0;
  color: var(--ak-accent);
  font-size: 15px;
  font-weight: 700;
}

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

.result-actions button {
  flex: 1 1 140px;
}

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

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

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

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

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

.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.is-finale .halo {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--ak-accent), 0 0 18px 4px var(--ak-accent-2);
}

@media (prefers-reduced-motion: no-preference) {
  .tilt {
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .tilt.is-rest {
    animation: idle-beam 3.4s ease-in-out infinite;
  }

  .tilt.is-level {
    animation: dip 0.72s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .tilt.is-swing .stack {
    transform-origin: top center;
    animation: swing 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .pan-zone.is-catch .stack {
    animation: catch 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .pan-zone.is-coach::before,
  .coin.is-coach::before {
    animation: bob-dot 0.8s ease-in-out infinite;
  }

  .bench .coin {
    animation: bob 2.8s ease-in-out infinite;
  }

  .bench .coin:nth-child(2n) {
    animation-delay: 0.25s;
  }

  .bench .coin:nth-child(3n) {
    animation-delay: 0.45s;
  }

  .coin.is-held,
  .coin.is-drop,
  .coin.is-off,
  .coin.is-shake,
  .coin.is-hop,
  .coin.is-sink {
    animation: none;
  }

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

  .coin.is-off {
    animation: settle 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .coin.is-shake {
    animation: shake-back 0.55s ease-in-out;
  }

  .coin.is-hop {
    animation: hop-sink 0.72s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }

  .speck {
    animation: float 3.1s ease-in-out infinite;
  }

  .dust.is-kick .speck {
    animation: kick 0.75s ease-out, float 3.1s 0.75s ease-in-out infinite;
  }

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

  .play.is-finale .halo {
    animation: chase 1.05s ease-in-out infinite;
  }

  .coin:active,
  .pan-hit:active,
  .btn-go:active,
  .btn-check:active,
  .btn-alt:active,
  .mute:active {
    transform: scale(0.96);
  }

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

  @keyframes idle-beam {
    0%,
    100% { transform: rotate(-1.4deg); }
    50% { transform: rotate(1.4deg); }
  }

  @keyframes dip {
    0% { transform: rotate(0deg); }
    35% { transform: rotate(-7deg); }
    68% { transform: rotate(4deg); }
    100% { transform: rotate(0deg); }
  }

  @keyframes swing {
    0% { transform: rotate(6deg); }
    55% { transform: rotate(-4deg); }
    100% { transform: rotate(0deg); }
  }

  @keyframes catch {
    0% { transform: translateY(-6px) scale(1, 1.04); }
    60% { transform: translateY(0) scale(1.06, 0.9); }
    100% { transform: translateY(0) scale(1, 1); }
  }

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

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

  @keyframes drop-bounce {
    0% { transform: translateY(-18px) scale(0.9, 1.12); }
    55% { transform: translateY(0) scale(1.14, 0.78); }
    100% { transform: translateY(0) scale(1, 1); }
  }

  @keyframes settle {
    0% { transform: translateY(-14px) scale(1.06, 0.9); }
    100% { transform: translateY(0) scale(1, 1); }
  }

  @keyframes shake-back {
    0% { transform: translateY(-18px); }
    25% { transform: translateX(-7px) rotate(-3deg); }
    50% { transform: translateX(7px) rotate(3deg); }
    75% { transform: translateX(-3px); }
    100% { transform: translateX(0) translateY(0); }
  }

  @keyframes hop-sink {
    0% { transform: translateY(0) scale(1, 1); }
    32% { transform: translateY(-22px) scale(1.1, 0.86); }
    58% { transform: translateY(6px) scale(0.94, 1.08); }
    100% { transform: translateY(22px) scale(1, 1); }
  }

  @keyframes float {
    0%,
    100% { transform: translateY(0); opacity: 0.35; }
    50% { transform: translateY(-10px); opacity: 0.7; }
  }

  @keyframes kick {
    0% { transform: translateY(8px) scale(0.6); opacity: 0.2; }
    40% { transform: translateY(-28px) scale(1); opacity: 0.95; }
    100% { transform: translate(var(--drift, 8px), -52px) scale(0.7); opacity: 0; }
  }

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

  @keyframes chase {
    0%,
    100% { box-shadow: 0 0 0 3px var(--ak-accent), 0 0 12px 2px var(--ak-accent-2); }
    50% { box-shadow: 0 0 0 3px var(--ak-accent-2), 0 0 24px 8px var(--ak-accent); }
  }

  @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);
  }
}
