*,
*::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);
  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 {
  --gap: 6px;
  --gutter: 28px;
  --clue-top: 32px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  width: min(100%, 440px);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding:
    max(6px, env(safe-area-inset-top, 0px))
    max(8px, env(safe-area-inset-right, 0px))
    max(6px, env(safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-left, 0px));
  overflow: hidden;
  touch-action: manipulation;
  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;
}

.mute {
  position: absolute;
  z-index: 8;
  top: max(6px, env(safe-area-inset-top, 0px));
  right: max(6px, env(safe-area-inset-right, 0px));
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-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,
.goal,
.voice,
.why,
.stage,
.dock {
  position: relative;
  z-index: 1;
}

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

.play-logo {
  display: block;
  width: auto;
  height: 40px;
  max-width: 46%;
  object-fit: contain;
  filter: drop-shadow(0 0 6px var(--ak-glow));
}

.turn {
  margin: 0;
  min-width: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(22px, 6vw, 32px);
  font-weight: var(--ak-title-weight);
  line-height: 0.95;
  color: var(--ak-accent);
}

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

.hint {
  margin-left: auto;
  padding: 0 12px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-size: 18px;
}

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

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

.voice,
.why {
  min-height: 44px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ak-ink);
}

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

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

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

.lantern {
  position: absolute;
  z-index: 0;
  top: 8%;
  right: 10%;
  width: 22px;
  height: 28px;
  border-radius: 40% 40% 28% 28%;
  background: var(--ak-accent-2);
  box-shadow: 0 0 12px var(--ak-glow), 0 0 10px var(--ak-accent-2);
  pointer-events: none;
}

.lantern::after {
  content: "";
  position: absolute;
  left: 9px;
  top: -7px;
  width: 4px;
  height: 6px;
  border-radius: 2px;
  background: var(--ak-outline);
}

.chart {
  position: relative;
  width: 100%;
  width: min(100%, 100cqw, 100cqh);
  max-width: 100%;
  max-height: 100%;
  height: auto;
  aspect-ratio: 1;
  transform: perspective(820px) rotateX(5deg);
  transform-origin: center 88%;
  touch-action: manipulation;
}

.chart-skin {
  position: absolute;
  inset: -3% -2% -6% -2%;
  width: auto;
  height: auto;
  object-fit: fill;
  pointer-events: none;
  filter: drop-shadow(0 8px 0 color-mix(in srgb, var(--ak-outline) 25%, transparent));
}

.sheet {
  position: absolute;
  inset: 2% 1% 3% 1%;
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  grid-template-rows: var(--clue-top) minmax(0, 1fr);
  padding: 4px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ak-bg) 88%, var(--ak-surface));
  box-shadow: inset 0 0 0 2px var(--ak-accent-2);
}

.corner {
  grid-column: 1;
  grid-row: 1;
}

.col-clues,
.row-clues,
.grid {
  min-width: 0;
  min-height: 0;
}

.col-clues {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 1px;
}

.row-clues {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: 1px;
}

.clue-col,
.clue-row {
  display: flex;
  min-width: 0;
  min-height: 0;
  color: var(--ak-accent-2);
}

.clue-col {
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 1px;
}

.clue-row {
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  padding-right: 2px;
}

.clue {
  display: inline-grid;
  place-items: center;
  min-width: 12px;
  font-family: var(--ak-font-display);
  font-size: clamp(10px, 2.5vw, 13px);
  font-weight: var(--ak-title-weight);
  line-height: 1;
  transform: rotate(var(--tilt, 0deg));
}

.clue.is-hot {
  padding: 1px 2px;
  border-radius: 999px;
  background: var(--ak-accent-2);
  color: var(--ak-ink);
  box-shadow: 1px 2px 0 var(--ak-outline);
}

.clue-col.is-dim .clue,
.clue-row.is-dim .clue {
  opacity: 0.38;
}

.clue-col.is-bad .clue,
.clue-row.is-bad .clue {
  padding: 0 2px;
  border-radius: 999px;
  background: var(--ak-accent);
  color: var(--ak-btn-ink);
}

.grid {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(10, minmax(0, 1fr));
  gap: 1px;
  touch-action: manipulation;
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 28% 34% 30% 36% / 32% 28% 36% 30%;
  background: color-mix(in srgb, var(--ak-bg) 62%, var(--ak-surface));
  box-shadow: 1px 2px 0 color-mix(in srgb, var(--ak-outline) 28%, transparent);
  touch-action: manipulation;
}

.mark {
  position: absolute;
  pointer-events: none;
  opacity: 0;
}

.mark-fill {
  inset: -30% -18% -22%;
  width: 146%;
  height: 158%;
  object-fit: contain;
}

.mark-cross {
  inset: -6%;
  width: 112%;
  height: 112%;
  object-fit: contain;
}

.cell.is-fill {
  z-index: 1;
  background: transparent;
  box-shadow: none;
}

.cell.is-fill .mark-fill {
  opacity: 1;
}

.cell.is-cross {
  background: color-mix(in srgb, var(--ak-bg) 70%, var(--ak-surface));
  box-shadow: none;
}

.cell.is-cross .mark-cross {
  opacity: 1;
}

.cell.is-hot {
  box-shadow: inset 0 0 0 2px var(--ak-accent-2), 0 0 8px var(--ak-glow);
}

.cell.is-open {
  box-shadow: inset 0 0 0 2px var(--ak-accent-2);
}

.cell.is-bad {
  box-shadow: inset 0 0 0 2px var(--ak-accent);
}

.cell.is-flag {
  box-shadow: inset 0 0 0 2px var(--ak-accent-2), 0 0 8px var(--ak-accent-2);
}

.cell.is-on {
  outline: 2px solid var(--ak-focus);
  outline-offset: 1px;
}

.cell:disabled {
  cursor: default;
}

.bird-wrap {
  position: absolute;
  z-index: 3;
  left: 16%;
  top: 6%;
  width: 70%;
  aspect-ratio: 384 / 383;
  opacity: 0;
  pointer-events: none;
}

.bird {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 8px 0 color-mix(in srgb, var(--ak-outline) 35%, transparent));
}

.lid {
  position: absolute;
  left: 45%;
  top: 21%;
  width: 9%;
  height: 7%;
  border-radius: 50%;
  background: var(--ak-ink);
  transform: scaleY(0);
  transform-origin: center;
}

.caption {
  position: absolute;
  z-index: 5;
  left: 8%;
  right: 8%;
  bottom: 2%;
  margin: 0;
  padding: 4px 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.4vw, 24px);
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
  text-align: center;
  opacity: 0;
}

.chart.is-solved .caption {
  opacity: 1;
}

.chart.is-solved .bird-wrap {
  opacity: 1;
}

.chart.is-solved .sheet {
  opacity: 0;
  pointer-events: none;
}

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

.bit {
  position: absolute;
  top: 42%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
}

.bit.is-0 { background: var(--ak-accent); }
.bit.is-1 { background: var(--ak-accent-2); }
.bit.is-2 { background: var(--ak-ink); }

.dock {
  flex: 0 0 auto;
  z-index: 2;
}

.check {
  width: 100%;
  padding: 0 12px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-size: clamp(16px, 4.2vw, 20px);
}

.check:disabled {
  opacity: 0.55;
}

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

.result-card {
  padding: 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow), 0 0 16px var(--ak-glow);
}

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

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

.btn-go,
.btn-alt {
  flex: 1 1 140px;
  padding: 0 12px;
  font-size: 16px;
}

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

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

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

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

.boot-error {
  margin: 24px;
  color: var(--ak-ink);
  font-family: var(--ak-font-body);
}

@media (max-width: 389px) {
  .play {
    --gap: 4px;
    --gutter: 26px;
    --clue-top: 30px;
  }

  .goal {
    font-size: 12px;
  }

  .play-logo {
    height: 34px;
  }

  .voice,
  .why {
    min-height: 40px;
    font-size: 15px;
  }
}

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

  .btn-alt:hover,
  .mute:hover {
    background: var(--ak-choice-bg);
  }
}

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

  .lantern {
    animation: lantern 2.6s ease-in-out infinite;
  }

  .clue {
    animation: wobble 3.6s ease-in-out infinite;
  }

  .clue-col.is-dim .clue,
  .clue-row.is-dim .clue {
    animation: none;
  }

  .clue.is-hot {
    animation: hot 1.2s ease-in-out infinite;
  }

  .cell.is-blank {
    animation: breathe 3.8s ease-in-out infinite;
    animation-delay: var(--d, 0ms);
  }

  .cell.is-squash .mark-fill {
    animation: squash 380ms cubic-bezier(0.34, 1.45, 0.64, 1);
  }

  .cell.is-flick .mark-cross {
    animation: flick 260ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .cell.is-shake {
    animation: shake 340ms ease;
  }

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

  .hint:active,
  .check:active,
  .mute:active,
  .btn-go:active,
  .btn-alt:active,
  .cell:active,
  .cell.is-blank:active {
    animation: none;
    transform: scale(0.94);
  }

  .chart.is-solved .cell.is-fill {
    animation: lift 760ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: var(--d, 0ms);
  }

  .chart.is-solved .cell.is-cross,
  .chart.is-solved .cell.is-blank {
    animation: sink 480ms ease forwards;
  }

  .chart.is-solved .sheet {
    animation: sheet-fade 1100ms ease forwards;
  }

  .chart.is-solved .bird-wrap {
    animation: bird-in 820ms cubic-bezier(0.22, 1, 0.36, 1) 240ms both;
  }

  .chart.is-solved .lid {
    animation: blink 1.7s ease-in-out 0.45s 1;
  }

  .chart.is-solved .caption.is-write {
    animation: write 900ms steps(9, end) 360ms both;
  }

  .chart.is-solved {
    animation: glow-chase 1.1s linear 3;
  }

  .bit {
    animation: confetti 900ms ease-out forwards;
    animation-delay: var(--delay, 0ms);
  }
}

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

@keyframes lantern {
  0%, 100% { transform: scale(1); filter: brightness(1); }
  50% { transform: scale(1.08); filter: brightness(1.25); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(var(--tilt, 0deg)); }
  50% { transform: rotate(calc(var(--tilt, 0deg) + 4deg)); }
}

@keyframes hot {
  0%, 100% { transform: rotate(var(--tilt, 0deg)) scale(1); }
  50% { transform: rotate(var(--tilt, 0deg)) scale(1.12); }
}

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

@keyframes squash {
  0% { transform: scale(0.35, 1.2); }
  45% { transform: scale(1.14, 0.78); }
  72% { transform: scale(0.96, 1.06); }
  100% { transform: scale(1); }
}

@keyframes flick {
  0% { transform: scale(1.35) rotate(-10deg); opacity: 0; }
  70% { transform: scale(0.92) rotate(3deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px) rotate(-2deg); }
  75% { transform: translateX(3px) rotate(2deg); }
}

@keyframes turn-pop {
  0% { transform: scale(0.84); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes lift {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  55% { transform: translateY(-14%) scale(1.06); opacity: 1; }
  100% { transform: translateY(-22%) scale(0.92); opacity: 0; }
}

@keyframes sink {
  to { opacity: 0; transform: scale(0.9); }
}

@keyframes sheet-fade {
  0%, 50% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes bird-in {
  0% { opacity: 0; transform: translateY(14%) scale(0.9); }
  62% { opacity: 1; transform: translateY(-3%) scale(1.04); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes blink {
  0%, 14%, 32%, 100% { transform: scaleY(0); }
  18%, 24% { transform: scaleY(1); }
  38%, 46% { transform: scaleY(1); }
  52% { transform: scaleY(0); }
}

@keyframes write {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

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

@keyframes confetti {
  0% { opacity: 1; transform: translate(0, 0) rotate(0); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(160deg); }
}
