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

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

body {
  min-height: 100dvh;
  font-family: var(--ak-font-body);
  font-size: 16px;
  font-weight: 600;
  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);
}

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

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.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: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  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-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::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--ak-accent) 42%, transparent), transparent 58%);
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(6px, env(safe-area-inset-right, 0px));
  z-index: 9;
  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);
  cursor: pointer;
}

.mute-icon {
  width: 22px;
  height: 22px;
}

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

.mute.is-muted::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 3px;
  background: var(--ak-accent-2);
}

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

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

.turn {
  min-width: 0;
  padding: 4px 8px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.turn-who,
.turn-sub {
  margin: 0;
}

.turn-who {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
  line-height: 0.9;
  letter-spacing: 0.02em;
}

.turn-sub {
  font-size: 13px;
  line-height: 1.2;
  color: var(--ak-btn-ink);
}

.goal,
.voice,
.why,
.result-card,
.dock,
.drop,
.invite {
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.goal,
.voice {
  position: relative;
  z-index: 2;
  margin: 0;
  padding: 6px 8px;
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.goal {
  padding: 3px 8px;
  font-size: 14px;
  line-height: 1.15;
}

.voice {
  min-height: 0;
  font-size: 16px;
  line-height: 1.2;
  padding: 4px 8px;
}

.board {
  position: relative;
  z-index: 1;
  min-height: 0;
}

.stage {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 6px);
  width: 112px;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: 52px minmax(48px, 1fr);
  column-gap: 4px;
  padding-top: 46px;
  z-index: 2;
  touch-action: none;
}

.stage.is-empty {
  grid-template-columns: 1fr;
}

.stage.is-empty .ends {
  display: none;
}

.rail {
  position: absolute;
  top: 0;
  left: 56px;
  right: 0;
  height: 46px;
  display: grid;
  place-items: end center;
  pointer-events: none;
}

.stage.is-empty .rail {
  left: 0;
}

.rail::before {
  content: "";
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 4px;
  height: 8px;
  background: var(--ak-btn-fill);
  border: 2px solid var(--ak-outline);
  box-shadow: var(--ak-shadow);
}

.star {
  position: relative;
  z-index: 1;
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: brightness(0.42) saturate(0.55);
}

.star:not([data-keyed="1"]) {
  opacity: 0;
}

.star.is-spent {
  filter: grayscale(0.65) brightness(0.28);
}

.star.is-lit {
  filter: brightness(1.12) saturate(1.15);
}

.sparks {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 0;
  height: 0;
  z-index: 2;
}

.spark {
  position: absolute;
  left: 0;
  top: 0;
  width: 8px;
  height: 8px;
  margin: -4px;
  background: var(--ak-accent);
  border: 1px solid var(--ak-outline);
}

.spark-b {
  background: var(--ak-btn-ink);
  border-radius: 50%;
}

.ends {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 0;
  min-width: 0;
}

.line > .drop {
  position: absolute;
  z-index: 5;
  left: -56px;
  width: calc(100% + 56px);
  min-width: 48px;
  min-height: 48px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0;
  padding: 4px 2px;
  pointer-events: none;
  text-align: center;
  color: var(--ak-ink);
  background: color-mix(in srgb, var(--ak-surface) 90%, var(--ak-accent));
  border: 3px dashed var(--ak-accent);
  box-shadow: 0 0 0 2px var(--ak-outline);
}

.drop-k {
  font-size: 11px;
  line-height: 1;
  font-weight: 600;
}

.drop-n {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 26px;
  line-height: 0.85;
}

.drop.is-bad {
  background: var(--ak-accent-2);
  color: var(--ak-surface);
}

.line {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 1px;
  touch-action: none;
}

.line::before {
  content: "";
  position: absolute;
  z-index: 0;
  top: 4px;
  bottom: 4px;
  left: 50%;
  width: 16px;
  transform: translateX(-50%);
  border-radius: 10px;
  background: var(--ak-accent);
  box-shadow: 0 0 0 2px var(--ak-outline), var(--ak-shadow);
  pointer-events: none;
}

.stage.is-lit .line::before {
  box-shadow: 0 0 0 2px var(--ak-outline), 0 0 18px var(--ak-accent), 0 0 18px var(--ak-glow);
}

.invite {
  position: relative;
  z-index: 1;
  margin: auto 0;
  padding: 10px 8px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 26px;
  line-height: 0.92;
  text-align: center;
}

.line .tile {
  position: relative;
  z-index: 1;
  flex: 1 1 0;
  width: 100%;
  min-width: 48px;
  min-height: 0;
  max-height: 120px;
  display: grid;
  place-items: center;
  container-type: size;
}

.line .tile .body {
  width: min(100cqw, calc(100cqh * 0.734));
  height: auto;
  max-height: 100cqh;
  aspect-ratio: 282 / 384;
}

.tile {
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
}

.tile .body {
  position: relative;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 282 / 384;
}

.shell {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.face {
  position: absolute;
  z-index: 1;
  left: 10%;
  right: 10%;
  top: 8%;
  bottom: 13%;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

.half {
  flex: 1 1 0;
  min-height: 0;
  margin: 0;
  background: var(--ak-bg);
  display: grid;
  place-items: center;
}

.bar {
  flex: 0 0 9%;
  margin: 0 4%;
  background: var(--ak-ink);
}

.pips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 92%;
  height: 92%;
}

.pips i {
  width: min(9px, 70%);
  aspect-ratio: 1;
  margin: auto;
  border-radius: 50%;
  background: transparent;
}

.pips i.on {
  background: var(--ak-ink);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ak-surface) 70%, transparent);
}

.dock {
  position: absolute;
  z-index: 3;
  top: 0;
  right: 0;
  bottom: 0;
  width: calc(50% - 52px);
  min-width: 120px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  overflow: hidden;
  background: color-mix(in srgb, var(--ak-surface) 86%, transparent);
}

.tray-art {
  position: absolute;
  z-index: 0;
  left: 4px;
  right: 4px;
  bottom: 4px;
  width: calc(100% - 8px);
  height: 38%;
  object-fit: contain;
  object-position: center bottom;
  pointer-events: none;
}

.dock-bar,
.tiles,
.end-line,
.hint {
  position: relative;
  z-index: 1;
}

.dock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-height: 48px;
}

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

.hint,
.end-line,
.btn-go,
.btn-alt {
  min-height: 48px;
  min-width: 48px;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.hint,
.btn-alt,
.end-line {
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.end-line {
  width: 100%;
  background: var(--ak-accent-2);
  color: var(--ak-surface);
}

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

.tiles {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(48px, 1fr));
  gap: 4px;
  align-content: end;
  touch-action: none;
}

.tiles .tile {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  aspect-ratio: 282 / 384;
}

.tiles .tile .body {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
}

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

.tile.is-lifted {
  opacity: 0.28;
}

.tile.is-bad .body {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: 1px;
}

.tile.is-hint .body,
.tile.is-pointed .body {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

.tile.is-pointed::after {
  content: "";
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: -2px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 10px solid var(--ak-accent);
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.ghost {
  position: fixed;
  z-index: 20;
  margin: 0;
  pointer-events: none;
  display: grid;
  place-items: center;
}

.ghost .body {
  width: 100%;
  height: 100%;
}

.drop.is-hot,
.line.is-hot,
.tiles.is-hot {
  outline: 3px solid var(--ak-btn-ink);
  outline-offset: 2px;
}

.line > .drop.is-hot {
  background: var(--ak-accent);
  border-style: solid;
  box-shadow: 0 0 0 3px var(--ak-btn-ink), 0 0 16px var(--ak-accent);
}

.line > .drop.is-over {
  box-shadow: 0 0 0 3px var(--ak-ink), 0 0 18px var(--ak-accent);
}

.drop.is-no,
.tiles.is-no {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: 2px;
}

.line > .drop.is-no {
  background: var(--ak-surface);
  border-style: dashed;
  border-color: var(--ak-accent-2);
  box-shadow: 0 0 0 2px var(--ak-accent-2);
}

.why {
  position: relative;
  z-index: 4;
  margin: 0;
  padding: 8px 10px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 16px;
  line-height: 1.25;
}

.result {
  position: relative;
  z-index: 5;
  margin: 0;
}

.result-card {
  padding: 14px 12px 12px;
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.result-says {
  margin: 0 0 12px;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 28px;
  line-height: 0.95;
}

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

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

@media (prefers-reduced-motion: no-preference) {
  .turn.is-cue {
    animation: turn-cue 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .drop.is-open {
    animation: end-pulse 1.15s ease-in-out infinite;
  }

  .tiles .tile {
    animation: idle-bob 2.8s ease-in-out infinite;
  }

  .tiles .tile:nth-child(2n) {
    animation-delay: 0.35s;
  }

  .tiles .tile:nth-child(3n) {
    animation-delay: 0.7s;
  }

  .star:not(.is-lit) {
    animation: star-idle 2.6s ease-in-out infinite;
  }

  .star.is-lit {
    animation: star-flare 700ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .tile.is-hop {
    animation: tile-hop 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .tile.is-spin {
    animation: tile-spin 480ms cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .tile.is-shake {
    animation: tile-shake 420ms cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  .tile.is-pointed {
    animation: idle-bob 1s ease-in-out infinite;
  }

  .line.is-linehop {
    animation: line-hop 520ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .line.is-celebrate .tile {
    animation: tile-chase 680ms cubic-bezier(0.34, 1.4, 0.64, 1) both;
    animation-delay: calc(var(--i, 0) * 40ms);
  }

  .spark {
    animation: spark-fly 780ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .tile:active .body,
  .hint:active,
  .end-line:active,
  .btn-go:active,
  .btn-alt:active,
  .mute:active {
    transform: scale(0.94);
  }

  .stage.is-lit .line::before {
    animation: groove-glow 900ms ease-in-out infinite;
  }
}

@keyframes turn-cue {
  0% { transform: scale(1); }
  45% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

@keyframes end-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

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

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

@keyframes star-flare {
  0% { transform: scale(0.8); filter: brightness(0.4); }
  55% { transform: scale(1.18); filter: brightness(1.35); }
  100% { transform: scale(1); filter: brightness(1.12) saturate(1.15); }
}

@keyframes tile-hop {
  0% { transform: translateY(-18px) scale(1.08, 0.86); }
  62% { transform: translateY(4px) scale(0.94, 1.08); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes tile-spin {
  0% { transform: rotate(180deg) scale(1.05); }
  68% { transform: rotate(-10deg) scale(0.96, 1.06); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes tile-shake {
  0% { transform: translateX(0); }
  30% { transform: translateX(-7px) rotate(-4deg); }
  60% { transform: translateX(7px) rotate(4deg); }
  100% { transform: translateX(0); }
}

@keyframes line-hop {
  0% { transform: translateY(0); }
  40% { transform: translateY(-12px); }
  70% { transform: translateY(3px) scale(0.98, 1.03); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes tile-chase {
  0% { transform: scale(1); }
  40% { transform: translateY(-8px) scale(1.06, 0.92); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes spark-fly {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.35);
    opacity: 0;
  }
}

@keyframes groove-glow {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.35); }
}
