*,
*::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.3;
  background-color: var(--ak-bg);
  background-image: var(--ak-bg-art);
  background-size: var(--ak-bg-size);
  overscroll-behavior: none;
}

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: 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-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.play.is-card {
  padding-bottom: calc(var(--pad-bot) + 220px);
}

.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,
.why,
.goal,
.time-line,
.actions {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
}

.why {
  z-index: 5;
}

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

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

.turn {
  min-width: 0;
}

.turn-who {
  margin: 0;
  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: 14px;
  font-weight: 700;
}

.voice,
.why,
.goal {
  margin: 0;
  padding: 7px 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);
}

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

.voice.is-invite {
  border-color: var(--ak-accent);
  background: color-mix(in srgb, var(--ak-accent) 12%, var(--ak-surface));
}

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

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

.why {
  color: var(--ak-accent);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

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

.why {
  z-index: 8;
}

.stage {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  container-type: size;
  touch-action: manipulation;
}

.board {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 92%;
  width: min(100cqi, calc(100cqh * 384 / 261), 100%);
  aspect-ratio: 384 / 261;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.board-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.well {
  position: absolute;
  left: 30.21%;
  top: 23.75%;
  width: 41.41%;
  height: 40.61%;
}

.ghost,
.photo-full,
.marks {
  position: absolute;
  inset: 0;
}

.ghost,
.photo-full {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  pointer-events: none;
  opacity: 0;
}

.play.is-ghost .ghost {
  opacity: 0.38;
}

.play.is-whole .photo-full {
  opacity: 1;
}

.marks {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  z-index: 2;
  pointer-events: none;
}

.mark.is-home {
  background: color-mix(in srgb, var(--ak-accent-2) 46%, transparent);
  box-shadow: inset 0 0 0 3px var(--ak-accent-2);
}

.mark.is-miss {
  background: color-mix(in srgb, var(--ak-accent) 42%, transparent);
  box-shadow: inset 0 0 0 3px var(--ak-accent);
}

.mark.is-hot {
  box-shadow: inset 0 0 0 4px var(--ak-accent);
}

.glow {
  position: absolute;
  left: 26%;
  top: 18%;
  width: 50%;
  height: 52%;
  border-radius: var(--ak-radius);
  pointer-events: none;
  opacity: 0;
}

.play.is-win .glow {
  opacity: 1;
}

.cherry {
  position: absolute;
  right: 10%;
  top: 8%;
  width: 22px;
  height: 22px;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--ak-surface), var(--ak-accent) 42%, var(--ak-btn-active));
  z-index: 3;
}

.cherry::before {
  content: '';
  position: absolute;
  left: 46%;
  bottom: 78%;
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--ak-accent-2);
  transform: rotate(18deg);
  transform-origin: bottom center;
}

.pieces,
.fx {
  position: absolute;
  inset: 0;
}

.pieces {
  z-index: 4;
  touch-action: manipulation;
}

.pointer {
  position: absolute;
  z-index: 5;
  width: 36px;
  height: 36px;
  color: var(--ak-accent);
  pointer-events: none;
}

.pointer svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 0 var(--ak-surface));
}

.pointer.is-flip {
  transform: rotate(180deg);
}

.fx {
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}

.piece {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  touch-action: none;
  transform-origin: center center;
}

.piece.is-locked {
  z-index: 2;
}

.piece.is-loose {
  z-index: 3;
}

.piece.is-loose:not(.is-held) {
  filter: drop-shadow(0 3px 0 color-mix(in srgb, var(--ak-outline) 28%, transparent));
}

.piece.is-away {
  opacity: 0;
  pointer-events: none;
}

.cookie,
.scrap,
.crust {
  position: absolute;
  pointer-events: none;
}

.cookie {
  inset: 0;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  transform: rotate(calc(var(--turn, 0) * 90deg));
}

.piece.is-edge .cookie {
  background-image: url('./art/edge-piece.png');
}

.piece.is-middle .cookie {
  background-image: url('./art/puzzle-piece.png');
}

.scrap {
  left: 50%;
  top: 48%;
  z-index: 2;
  width: 58%;
  height: 46%;
  border-radius: 4px;
  background-image: var(--photo);
  background-repeat: no-repeat;
  box-shadow: 0 0 0 2px var(--ak-surface);
  transform: translate(-50%, -50%);
}

.piece.is-locked .cookie,
.piece.is-locked .crust {
  opacity: 0;
}

.piece.is-locked .scrap {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  box-shadow: none;
  transform: none;
}

.play.is-whole .piece.is-locked {
  opacity: 0;
}

.crust {
  z-index: 3;
  background: var(--ak-ink);
  border-radius: 4px;
}

.crust.is-left {
  left: 6%;
  top: 24%;
  bottom: 24%;
  width: 10%;
}

.crust.is-right {
  right: 6%;
  top: 24%;
  bottom: 24%;
  width: 10%;
}

.crust.is-top {
  top: 8%;
  left: 22%;
  right: 22%;
  height: 12%;
}

.crust.is-bottom {
  bottom: 8%;
  left: 22%;
  right: 22%;
  height: 12%;
}

.time-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  margin: 0;
}

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

.time-value {
  font-family: var(--ak-font-display);
  font-size: clamp(22px, 6vw, 32px);
  font-weight: var(--ak-title-weight);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--ak-ink);
}

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

.act,
.btn-go,
.btn-alt {
  min-height: 48px;
  min-width: 48px;
  padding: 0 12px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  touch-action: manipulation;
}

.act {
  flex: 1 1 0;
  min-width: 0;
  padding: 4px 8px;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  font-size: 15px;
  line-height: 1.05;
}

.act[aria-pressed='true'] {
  background: var(--ak-choice-selected-bg);
  color: var(--ak-choice-selected-ink);
  border-color: var(--ak-choice-selected-border);
}

.act-hint {
  flex: 1 1 0;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}

.act:disabled {
  opacity: 0.55;
}

.result {
  position: absolute;
  z-index: 7;
  left: max(8px, env(safe-area-inset-left, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
  bottom: max(8px, env(safe-area-inset-bottom, 0px));
}

.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-size: clamp(18px, 4.6vw, 26px);
  font-weight: var(--ak-title-weight);
  line-height: 1.15;
  color: var(--ak-ink);
}

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

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

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

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

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

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

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

.crumb,
.bit {
  position: absolute;
  border-radius: 50%;
}

.crumb {
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  background: var(--ak-ink);
}

.crumb.is-cream {
  background: var(--ak-surface);
  box-shadow: 0 0 0 2px var(--ak-ink);
}

.bit {
  top: 42%;
  left: 50%;
  width: 10px;
  height: 14px;
  margin-left: -5px;
  border-radius: 3px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
}

.bit.is-mint {
  background: var(--ak-accent-2);
  border-color: var(--ak-ink);
}

.bit.is-cherry {
  background: var(--ak-accent);
  border-color: var(--ak-ink);
}

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

  .act:hover,
  .btn-alt:hover,
  .mute:hover {
    border-color: var(--ak-accent-2);
  }

  .act[aria-pressed='true']:hover {
    background: var(--ak-btn-hover);
  }
}

@media (max-width: 359px) {
  .play {
    --pad-x: 6px;
    gap: 4px;
  }

  .goal,
  .voice {
    font-size: 14px;
  }
}

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

@keyframes pop {
  0% { transform: scale(1.16) rotate(-6deg); }
  45% { transform: scale(0.94, 1.08) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes shake {
  0%,
  100% { transform: translateX(0) rotate(0deg); }
  30% { transform: translateX(-6px) rotate(-3deg); }
  70% { transform: translateX(6px) rotate(3deg); }
}

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

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

@keyframes turn-cue {
  0% { transform: translateX(0) scale(1); }
  40% { transform: translateX(4px) scale(1.04); }
  100% { transform: translateX(0) scale(1); }
}

@keyframes breathe {
  0%,
  100% { opacity: 0.26; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.02); }
}

@keyframes hop {
  0%,
  100% { transform: translateY(0) scale(1, 1); }
  35% { transform: translateY(-16px) scale(0.94, 1.08); }
  55% { transform: translateY(-4px) scale(1.06, 0.92); }
}

@keyframes point {
  0%,
  100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

@keyframes point-flip {
  0%,
  100% { transform: rotate(180deg) translateY(0); }
  50% { transform: rotate(180deg) translateY(5px); }
}

@keyframes chase {
  0% { box-shadow: 6px 0 0 var(--ak-accent), 0 0 14px var(--ak-glow); }
  25% { box-shadow: 0 6px 0 var(--ak-accent-2), 0 0 14px var(--ak-glow); }
  50% { box-shadow: -6px 0 0 var(--ak-accent), 0 0 14px var(--ak-glow); }
  75% { box-shadow: 0 -6px 0 var(--ak-accent-2), 0 0 14px var(--ak-glow); }
  100% { box-shadow: 6px 0 0 var(--ak-accent), 0 0 14px var(--ak-glow); }
}

@keyframes puff {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.4); }
}

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

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

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

  .piece {
    transition: opacity 280ms ease, transform 160ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .piece.is-loose:not(.is-held):not(.is-shake):not(.is-pop):not(.is-away):not(.is-coach):not(.is-glide) {
    animation: bob 2.8s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * -0.17s);
  }

  .piece.is-glide {
    transition:
      left 240ms cubic-bezier(0.22, 1, 0.36, 1),
      top 240ms cubic-bezier(0.22, 1, 0.36, 1),
      width 240ms ease,
      height 240ms ease,
      opacity 280ms ease;
  }

  .piece.is-held {
    z-index: 6;
    transform: rotate(-8deg) scale(var(--grow, 1.14));
    filter: drop-shadow(0 10px 0 color-mix(in srgb, var(--ak-outline) 45%, transparent));
  }

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

  .piece.is-shake {
    animation: shake 0.36s ease-in-out;
  }

  .piece.is-coach:not(.is-held) {
    animation: invite 1.05s ease-in-out infinite;
  }

  .play.is-ghost .ghost {
    animation: breathe 3.2s ease-in-out infinite;
  }

  .hint-live.is-offer,
  .act-hint:not([hidden]) {
    animation: offer 1.15s ease-in-out infinite;
  }

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

  .play.is-win .glow {
    animation: chase 0.7s linear 4;
  }

  .cherry:not([hidden]) {
    animation: hop 0.85s cubic-bezier(0.34, 1.4, 0.64, 1) infinite;
  }

  .pointer:not(.is-flip) {
    animation: point 0.9s ease-in-out infinite;
  }

  .pointer.is-flip {
    animation: point-flip 0.9s ease-in-out infinite;
  }

  .crumb {
    animation: puff 0.55s ease-out forwards;
  }

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

  .play.is-whole .photo-full,
  .play.is-whole .piece.is-locked {
    transition: opacity 360ms ease;
  }

  .piece:active:not(.is-locked):not(.is-held),
  .act:active,
  .mute:active,
  .btn-go:active,
  .btn-alt:active {
    transform: scale(0.96);
  }
}

@media (prefers-reduced-motion: reduce) {
  .piece,
  .ghost,
  .cherry,
  .turn,
  .pointer,
  .glow,
  .crumb,
  .bit,
  .play-logo {
    animation: none !important;
    transition: none !important;
  }

  .piece.is-held {
    z-index: 6;
    transform: rotate(-8deg) scale(var(--grow, 1.14));
  }
}
