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

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

body {
  min-height: 100vh;
  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%;
  user-select: none;
  -webkit-user-drag: none;
}

[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(6px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto auto auto;
  grid-template-areas:
    "top"
    "voice"
    "brief"
    "readout"
    "stage"
    "marks"
    "actions"
    "end";
  gap: 4px;
  width: min(100%, 420px);
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  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 42%;
  background-repeat: no-repeat;
}

.top { grid-area: top; }
.voice { grid-area: voice; }
.brief { grid-area: brief; }
.readout { grid-area: readout; }
.stage { grid-area: stage; }
.marks { grid-area: marks; }
.actions { grid-area: actions; }
.end { grid-area: end; }

.top,
.voice,
.brief,
.readout,
.stage,
.marks,
.actions,
.end,
.row {
  min-width: 0;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(4px, 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);
  transform: rotate(-35deg);
}

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

.play-logo {
  height: 40px;
  width: auto;
  max-width: 38%;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.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: 18px;
  line-height: 0.9;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

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

.voice,
.brief,
.readout,
.row,
.why,
.result-card,
.btn-check,
.btn-done,
.hint,
.btn-go,
.btn-alt,
.chip {
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.voice,
.brief,
.why {
  position: relative;
  z-index: 2;
  margin: 0;
  background: var(--ak-surface);
  color: var(--ak-ink);
}

.voice {
  padding: 6px 8px;
  font-size: 15px;
  line-height: 1.2;
}

.voice.is-invite {
  background: var(--ak-choice-bg);
  border-color: var(--ak-accent);
}

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

.brief {
  padding: 4px 8px;
}

.goal,
.tip {
  margin: 0;
}

.goal {
  font-size: 13px;
  line-height: 1.2;
}

.tip {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.2;
  color: var(--ak-ink-muted);
}

.readout {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 48px;
  padding: 4px 8px 4px 6px;
  background: var(--ak-ink);
  color: var(--ak-accent-2);
}

.readout-copy,
.target {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
}

.readout-kicker,
.target-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ak-surface);
}

.sum,
.target strong {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 28px;
  line-height: 0.85;
  font-variant-numeric: tabular-nums;
}

.sum {
  color: var(--ak-surface);
}

.sum.is-under {
  color: var(--ak-accent-2);
}

.sum.is-hit {
  color: var(--ak-accent-2);
}

.sum.is-over {
  color: var(--ak-accent);
}

.target strong {
  color: var(--ak-accent-2);
}

.cloth {
  flex: none;
  width: 36px;
  height: 22px;
  border: 2px solid var(--ak-outline);
  background:
    linear-gradient(var(--ak-accent-2), var(--ak-accent-2)) 0 0 / 5px 100% no-repeat,
    repeating-conic-gradient(var(--ak-ink) 0% 25%, var(--ak-surface) 0% 50%) 6px 0 / 10px 10px;
  transform-origin: left center;
}

.stage {
  position: relative;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.play.is-finish .stage {
  overflow: hidden;
}

.flag {
  position: absolute;
  z-index: 4;
  left: 8%;
  top: 0;
  width: min(48%, 190px);
  height: 64px;
  border: 2px solid var(--ak-outline);
  background:
    linear-gradient(var(--ak-accent-2), var(--ak-accent-2)) 0 0 / 7px 100% no-repeat,
    repeating-conic-gradient(var(--ak-ink) 0% 25%, var(--ak-surface) 0% 50%) 8px 0 / 14px 14px;
  transform: translateY(-100vh) rotate(-8deg);
  transform-origin: top left;
  pointer-events: none;
}

.loop {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.loop img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  mask-image: radial-gradient(circle at 50% 50%, transparent 0 62%, #000 74%);
  -webkit-mask-image: radial-gradient(circle at 50% 50%, transparent 0 62%, #000 74%);
}

.row {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 3px;
  align-items: end;
  width: 100%;
  max-height: 100%;
  padding: 14px 4px 6px;
  background: var(--ak-surface);
}

.card {
  --tilt: 0deg;
  --nudge: 0px;
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  max-height: 100%;
  aspect-ratio: 275 / 384;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  filter: drop-shadow(0 3px 0 var(--ak-outline));
}

.card:nth-child(1) { --tilt: -2.2deg; }
.card:nth-child(2) { --tilt: 1.6deg; }
.card:nth-child(3) { --tilt: -1.1deg; }
.card:nth-child(4) { --tilt: 2deg; }
.card:nth-child(5) { --tilt: -1.7deg; }
.card:nth-child(6) { --tilt: 1.2deg; }

.card.is-up,
.card.is-open {
  z-index: 3;
  transform: translateY(-10px);
}

.card-bob {
  position: absolute;
  inset: 0;
  transform: rotate(var(--tilt));
}

.card-art,
.art-rest,
.art-pick {
  position: absolute;
  display: block;
}

.card-art {
  inset: 0;
}

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

.art-pick {
  left: 50%;
  top: 0;
  width: 139%;
  height: 100%;
  transform: translateX(-50%);
  object-fit: fill;
  opacity: 0;
}

.card.is-up .art-rest {
  opacity: 0;
}

.card.is-up .art-pick {
  opacity: 1;
}

.plate {
  position: absolute;
  z-index: 2;
  left: 16%;
  right: 16%;
  top: 26%;
  bottom: 16%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--ak-ink);
  color: var(--ak-accent-2);
  border-radius: var(--ak-radius);
}

.rank {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
  line-height: 0.8;
}

.card.is-ten .rank {
  font-size: 16px;
}

.worth {
  margin-top: 1px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: var(--ak-surface);
}

.pip {
  position: absolute;
  z-index: 3;
  top: 7%;
  left: 8%;
  width: 24%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: var(--ak-ink);
  border-radius: 50%;
}

.suit {
  width: 72%;
  height: 72%;
}

.suit path {
  stroke: var(--ak-outline);
  stroke-width: 1.5;
}

.suit.is-hearts path,
.suit.is-diamonds path {
  fill: var(--ak-accent);
}

.suit.is-clubs path,
.suit.is-spades path {
  fill: var(--ak-accent-2);
}

.badge {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: -12px;
  transform: translateX(-50%);
  padding: 1px 4px;
  background: var(--ak-accent-2);
  color: var(--ak-ink);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.stamp {
  position: absolute;
  z-index: 5;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  background: var(--ak-accent);
  color: var(--ak-btn-ink);
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  box-shadow: var(--ak-shadow);
  pointer-events: none;
}

.marks {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 4px;
}

.mark-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.mark-label {
  flex: none;
  width: 58px;
  margin: 0;
  padding-top: 6px;
  font-size: 12px;
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
}

.chip,
.empty {
  margin: 0;
  padding: 3px 6px;
  background: var(--ak-surface);
  font-size: 13px;
  line-height: 1.1;
  font-weight: 700;
}

.empty {
  border: 0;
  box-shadow: none;
  padding-left: 0;
  color: var(--ak-ink-muted);
}

.chip.is-miss {
  border-color: var(--ak-accent);
  background: var(--ak-choice-bg);
}

.chip.is-on {
  outline: 3px solid var(--ak-accent-2);
  outline-offset: 1px;
}

.tick {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-right: 4px;
  background: var(--ak-accent);
  color: var(--ak-btn-ink);
  border-radius: 50%;
  font-size: 11px;
  vertical-align: middle;
}

.bit.is-hearts,
.bit.is-diamonds {
  color: var(--ak-accent);
}

.bit.is-clubs,
.bit.is-spades {
  color: var(--ak-ink);
}

.plus {
  margin: 0 1px;
}

.actions {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.btn-check,
.btn-done,
.hint,
.btn-go,
.btn-alt {
  min-height: 48px;
  padding: 8px 6px;
  cursor: pointer;
}

.btn-check {
  grid-column: 1 / -1;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: clamp(16px, 4.6vw, 22px);
  letter-spacing: 0.02em;
}

.btn-done {
  grid-column: 1 / -1;
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border-color: var(--ak-choice-border);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 22px;
}

.btn-done.is-next {
  background: var(--ak-accent-2);
  color: var(--ak-ink);
  border-color: var(--ak-outline);
  font-size: 20px;
}

.actions.has-hint .btn-done {
  grid-column: auto;
}

.hint {
  background: var(--ak-accent-2);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 20px;
}

.why {
  padding: 8px;
  font-size: 15px;
  line-height: 1.25;
  background: var(--ak-choice-bg);
}

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

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

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

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn-go {
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 20px;
}

.btn-alt {
  background: var(--ak-choice-bg);
  color: var(--ak-choice-ink);
  border-color: var(--ak-choice-border);
  font-size: 14px;
  font-weight: 700;
}

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

.btn-check:disabled,
.btn-done:disabled {
  cursor: default;
  opacity: 0.55;
}

.card:disabled {
  cursor: default;
}

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

.fx i {
  position: absolute;
  width: 8px;
  height: 14px;
  opacity: 0;
}

@media (min-width: 480px) {
  .play {
    border-left: 3px solid var(--ak-outline);
    border-right: 3px solid var(--ak-outline);
  }
}

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

  .cloth {
    animation: snap 1.6s ease-in-out infinite;
  }

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

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

  .card {
    transition: transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .card-bob {
    animation: card-idle 3.2s ease-in-out infinite;
    animation-delay: calc(var(--i) * 120ms);
  }

  .row.is-dealing .card-bob {
    animation: deal-in 480ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
    animation-delay: calc(var(--i) * 50ms);
  }

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

  .card.is-bunch {
    animation: bunch 520ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .card.is-wobble,
  .btn-check.is-wobble,
  .btn-done.is-wobble {
    animation: wobble 420ms ease;
  }

  .card.is-point:not(.is-up) {
    animation: point-bob 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) infinite;
  }

  .btn-check.is-ready,
  .btn-done.is-point {
    animation: ready 0.9s ease-in-out infinite;
  }

  .sum.is-hit {
    animation: sum-pop 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .art-rest,
  .art-pick {
    transition: opacity 160ms ease;
  }

  .chip.is-new .tick {
    animation: stamp 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .stamp.is-on {
    animation: stamp 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .loop.is-on img {
    animation: loop-in 700ms ease;
  }

  .play.is-finish .row {
    animation: slide-down 800ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .play.is-finish .flag {
    animation: flag-fall 700ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .play.is-finish .result-card {
    animation: chase 0.7s linear 3;
  }

  .fx i {
    animation: burst 900ms cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  }

  .card:active,
  .mute:active,
  .btn-check:active,
  .btn-done:active,
  .hint:active,
  .btn-go:active,
  .btn-alt:active {
    scale: 0.96;
  }
}

@keyframes logo-idle {
  0%,
  100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-2px) rotate(1deg); }
}

@keyframes snap {
  0%,
  100% { transform: skewX(0deg) scaleX(1); }
  40% { transform: skewX(-10deg) scaleX(0.92); }
  70% { transform: skewX(7deg) scaleX(1.05); }
}

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

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

@keyframes card-idle {
  0%,
  100% { transform: rotate(var(--tilt)) translateY(0); }
  50% { transform: rotate(calc(var(--tilt) * -0.35)) translateY(-2px); }
}

@keyframes deal-in {
  0% { transform: translateY(-28px) rotate(calc(var(--tilt) + 8deg)) scale(0.9, 1.08); opacity: 0; }
  100% { transform: translateY(0) rotate(var(--tilt)) scale(1); opacity: 1; }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  45% { transform: translateY(-16px) scale(1.08, 0.88); }
  100% { transform: translateY(-10px) scale(1.04, 0.97); }
}

@keyframes bunch {
  0% { transform: translate(0, 0) scale(1); }
  35% { transform: translate(var(--nudge), -18px) scale(1.08, 0.86); }
  68% { transform: translate(calc(var(--nudge) * 0.35), -4px) scale(0.96, 1.06); }
  100% { transform: translate(0, 0) scale(1); }
}

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

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

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

@keyframes sum-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18, 0.9); }
  100% { transform: scale(1); }
}

@keyframes stamp {
  0% { transform: scale(1.8) rotate(-14deg); opacity: 0; }
  100% { transform: scale(1) rotate(-6deg); opacity: 1; }
}

@keyframes loop-in {
  0% { opacity: 0; transform: scale(1.18); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes slide-down {
  to { transform: translateY(120%); }
}

@keyframes flag-fall {
  0% { transform: translateY(-100vh) rotate(-8deg); }
  68% { transform: translateY(8px) rotate(5deg) scaleY(1.04); }
  100% { transform: translateY(0) rotate(-2deg); }
}

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

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