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

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

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  font-family: var(--ak-font-body);
  font-size: 16px;
  line-height: 1.2;
  color: var(--ak-ink);
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
}

body.is-playing {
  background-image: var(--ak-backdrop-layer), var(--ak-bg-art);
  background-size: cover, var(--ak-bg-size);
  background-position: center top, 0 0;
  background-repeat: no-repeat, repeat;
}

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

img {
  display: block;
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

[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(10px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: min(100%, 440px);
  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-user-select: none;
  -webkit-tap-highlight-color: transparent;
  background-color: transparent;
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.motes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.motes i {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ak-ink);
  opacity: 0.55;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ak-accent) 55%, transparent);
}

.motes i:nth-child(1) { left: 6%; top: 18%; width: 7px; height: 7px; }
.motes i:nth-child(2) { left: 12%; bottom: 14%; width: 11px; height: 11px; }
.motes i:nth-child(3) { right: 8%; top: 22%; }
.motes i:nth-child(4) { right: 14%; bottom: 10%; width: 6px; height: 6px; }
.motes i:nth-child(5) { left: 46%; top: 8%; width: 5px; height: 5px; background: var(--ak-accent); }

.top,
.voice,
.hint,
.stage,
.result {
  position: relative;
  z-index: 1;
}

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

.play-logo {
  width: auto;
  height: 48px;
  max-width: 38%;
  object-fit: contain;
  flex: 0 0 auto;
}

.turn {
  flex: 1 1 auto;
  min-width: 0;
}

.turn-who,
.turn-sub,
.voice,
.clock,
.result-says {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-size: 26px;
  line-height: 1;
  color: var(--ak-ink);
}

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

.clock {
  flex: 0 0 auto;
  min-width: 48px;
  font-family: var(--ak-font-display);
  font-size: 32px;
  line-height: 1;
  color: var(--ak-ink);
  text-align: right;
  text-shadow: 2px 2px 0 var(--ak-bg);
}

.clock .unit {
  font-size: 16px;
  color: var(--ak-ink-muted);
}

.clock.is-low {
  color: var(--ak-accent);
}

.mute {
  flex: 0 0 auto;
  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 svg {
  width: 26px;
  height: 26px;
  margin: 0 auto;
}

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

.voice {
  min-height: 46px;
  font-family: var(--ak-font-display);
  font-size: 22px;
  line-height: 1.15;
  text-align: center;
  color: var(--ak-accent);
  text-shadow: 0 2px 0 var(--ak-bg);
}

.hint,
.btn-go,
.btn-alt {
  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-size: 22px;
  touch-action: manipulation;
}

.hint {
  align-self: center;
  min-width: 96px;
  padding: 0 18px;
  background: var(--ak-accent);
  color: var(--ak-btn-ink);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  container-type: size;
}

.tilt {
  width: min(100%, calc((100dvh - 188px) * 384 / 334));
  width: min(90cqw, calc(82cqh * 384 / 334));
  aspect-ratio: 384 / 334;
  transform: rotate(-7deg);
  transform-origin: 50% 50%;
}

.bezel {
  position: relative;
  width: 100%;
  aspect-ratio: 384 / 334;
}

.arc {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 115%;
  object-fit: contain;
  pointer-events: none;
  z-index: 2;
  --p: 1;
  transform: translate(-50%, -50%) rotate(-16deg) scale(1.52);
  transform-origin: center center;
  -webkit-mask-image:
    radial-gradient(circle closest-side, transparent 46%, #000 52%, #000 62%, transparent 70%),
    conic-gradient(from 108deg, #000 calc(var(--p) * 268deg), transparent 0);
  mask-image:
    radial-gradient(circle closest-side, transparent 46%, #000 52%, #000 62%, transparent 70%),
    conic-gradient(from 108deg, #000 calc(var(--p) * 268deg), transparent 0);
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
}

.frame {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  background: var(--ak-surface);
  border: 3px solid var(--ak-outline);
  border-radius: 18px 30px 16px 38px;
  box-shadow: var(--ak-shadow);
}

.market,
.change,
.dust,
.spots,
.ring,
.puff,
.coach,
.swipe {
  position: absolute;
}

.market {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: inherit;
  pointer-events: none;
}

.market.is-blank {
  opacity: 0;
}

.change {
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transform-origin: center center;
}

.change.is-on {
  opacity: 1;
}

.wash,
.erase,
.chalk-shape {
  position: absolute;
  pointer-events: none;
}

.wash {
  inset: 6%;
  border-radius: 46%;
  border: 4px solid var(--ak-outline);
  box-shadow: 0 0 0 3px var(--ak-accent);
  opacity: 0.92;
}

.erase {
  inset: -12%;
  border-radius: 50%;
}

.chalk-shape {
  inset: -6%;
  width: 112%;
  height: 112%;
  overflow: visible;
}

.chalk-shape path {
  fill: var(--ak-accent);
  stroke: var(--ak-outline);
  stroke-width: 6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.dust {
  inset: 0;
  z-index: 3;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(circle at 28% 36%, rgba(238, 248, 240, 0.95), transparent 36%),
    radial-gradient(circle at 70% 62%, rgba(238, 248, 240, 0.88), transparent 40%),
    radial-gradient(circle at 48% 48%, rgba(250, 250, 88, 0.28), transparent 46%),
    rgba(238, 248, 240, 0.9);
}

.dust.is-on {
  opacity: 1;
}

.spots {
  inset: 0;
  z-index: 4;
}

.spot {
  position: absolute;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: manipulation;
}

.spot:disabled {
  opacity: 1;
}

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

.ring {
  z-index: 5;
  height: auto;
  aspect-ratio: 384 / 375;
  pointer-events: none;
  transform: translate(-50%, -50%);
  -webkit-mask-image: radial-gradient(circle closest-side, transparent 58%, #000 68%, #000 100%);
  mask-image: radial-gradient(circle closest-side, transparent 58%, #000 68%, #000 100%);
}

.puff {
  z-index: 6;
  width: 38%;
  height: auto;
  aspect-ratio: 375 / 384;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1);
  opacity: 0;
}

.puff.is-pop {
  opacity: 1;
}

.coach {
  z-index: 6;
  width: 22px;
  height: 22px;
  margin: -18px 0 0 -11px;
  border: 3px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-accent);
  box-shadow: var(--ak-shadow);
  pointer-events: none;
}

.coach::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 16px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid var(--ak-accent);
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.swipe {
  inset: 0;
  z-index: 7;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(238, 248, 240, 0.82), transparent);
  transform: translateX(-120%);
}

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

.fx .bit,
.fx .fx-puff {
  position: absolute;
  left: 50%;
  top: 46%;
}

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

.fx .fx-puff {
  width: 72px;
  height: auto;
}

.result {
  flex: 0 0 auto;
  z-index: 3;
}

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

.result-says {
  font-family: var(--ak-font-display);
  font-size: 24px;
  line-height: 1.15;
  text-align: center;
}

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

.btn-go,
.btn-alt {
  width: 100%;
  padding: 0 12px;
}

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

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

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

  .motes i {
    animation: mote-drift 4.6s ease-in-out infinite;
  }

  .motes i:nth-child(2) { animation-delay: -1.2s; }
  .motes i:nth-child(3) { animation-delay: -2s; }
  .motes i:nth-child(4) { animation-delay: -0.6s; }
  .motes i:nth-child(5) { animation-delay: -2.4s; }

  .play.is-hurry .motes i {
    animation-duration: 0.22s;
  }

  .play.is-hurry .arc {
    animation: arc-flare 0.42s ease-in-out infinite;
  }

  .play.is-hurry .clock.is-low {
    animation: arc-flare 0.42s ease-in-out infinite;
  }

  .voice.is-invite {
    animation: invite 1.5s ease-in-out infinite;
  }

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

  .frame.is-press {
    animation: press 160ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .dust.is-on {
    animation: dust-pop 150ms ease-out;
  }

  .ring.is-bounce {
    animation: ring-pop 520ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .puff.is-pop {
    animation: puff-pop 420ms ease-out forwards;
  }

  .coach {
    animation: coach-bob 0.85s ease-in-out infinite;
  }

  .swipe.is-on {
    animation: chalk-pass 460ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .arc.is-nibble {
    animation: nibble 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .play.is-win .frame {
    animation: glow-chase 0.7s ease-in-out 4;
  }

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

  .fx .fx-puff {
    animation: burst 860ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .spot:active,
  .hint:active,
  .mute:active,
  .btn-go:active,
  .btn-alt:active {
    transform: translateY(2px) scale(0.97, 1.04);
  }

  .spot.is-coach {
    animation: coach-glow 1s ease-in-out infinite;
  }
}

.spot.is-coach {
  border-radius: 14px;
  box-shadow: inset 0 0 0 3px var(--ak-accent);
}

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

@keyframes mote-drift {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

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

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

@keyframes turn-cue {
  0% { transform: scale(1); }
  40% { transform: scale(1.08, 0.9); }
  100% { transform: scale(1); }
}

@keyframes press {
  0% { transform: scale(1); }
  45% { transform: scale(0.97, 1.04); }
  100% { transform: scale(1); }
}

@keyframes dust-pop {
  0% { transform: scale(0.94); }
  100% { transform: scale(1); }
}

@keyframes ring-pop {
  0% { transform: translate(-50%, -50%) scale(0.35); }
  58% { transform: translate(-50%, -50%) scale(1.14); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes puff-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.25); }
  28% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.25); }
}

@keyframes coach-bob {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(7px) scale(0.92, 1.08); }
}

@keyframes chalk-pass {
  0% { transform: translateX(-120%) skewX(-8deg); }
  100% { transform: translateX(120%) skewX(-8deg); }
}

@keyframes nibble {
  0%, 100% { filter: brightness(1); }
  40% { filter: brightness(1.55); }
}

@keyframes glow-chase {
  0% { box-shadow: 0 0 0 3px var(--ak-accent), var(--ak-shadow); }
  50% { box-shadow: 0 0 18px 5px var(--ak-accent-2), var(--ak-shadow); }
  100% { box-shadow: 0 0 0 3px var(--ak-accent), var(--ak-shadow); }
}

@keyframes burst {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot, 18deg)) scale(1); }
}

@keyframes coach-glow {
  0%, 100% { box-shadow: inset 0 0 0 3px var(--ak-accent); }
  50% { box-shadow: inset 0 0 0 5px var(--ak-accent); }
}
