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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  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,
img {
  touch-action: manipulation;
}

button {
  font-family: inherit;
}

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(8px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, 0.72fr) minmax(0, 1.12fr) auto auto auto auto;
  grid-template-areas:
    "top"
    "voice"
    "dealer"
    "player"
    "tokens"
    "actions"
    "why"
    "result";
  gap: 4px;
  width: min(100%, 420px);
  height: 100vh;
  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 18%;
  background-repeat: no-repeat;
}

.top { grid-area: top; }
.voice { grid-area: voice; }
.dealer-band { grid-area: dealer; }
.player-band { grid-area: player; }
.tokens { grid-area: tokens; }
.actions { grid-area: actions; }
.why { grid-area: why; }
.result { grid-area: result; }

.top,
.voice,
.band,
.tokens,
.actions,
.why,
.result,
.row {
  min-width: 0;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(4px, 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);
  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: 36px;
  width: auto;
  max-width: 42%;
  object-fit: contain;
  filter: drop-shadow(0 2px 0 var(--ak-outline));
}

.turn {
  min-width: 0;
  padding: 4px 10px 5px;
  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: 17px;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.turn-sub {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.15;
}

.voice,
.band-label,
.stake,
.why,
.result-card,
.token-name {
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.voice {
  margin: 0;
  padding: 6px 8px;
  font-size: 14px;
  line-height: 1.3;
  max-height: 3.9em;
  overflow: hidden;
}

.band {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  align-content: start;
  gap: 3px;
}

.dealer-band {
  align-content: end;
}

.band-label {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: max-content;
  max-width: 100%;
  margin: 0;
  padding: 2px 8px 3px;
}

.who {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
}

.total {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: clamp(22px, 6vw, 34px);
  line-height: 0.9;
  color: var(--ak-ink);
}

.dealer-band .total {
  font-size: clamp(18px, 5vw, 26px);
}

.total.is-over,
.note.is-over {
  color: var(--ak-accent-2);
}

.note {
  font-size: 12px;
  color: var(--ak-ink-muted);
}

.row {
  min-height: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  perspective: 700px;
}

.dealer-band .row {
  align-items: flex-start;
  padding-top: 2px;
}

.card {
  position: relative;
  flex: 0 0 auto;
  height: var(--card-h, min(22dvh, 128px));
  width: calc(var(--card-h, min(22dvh, 128px)) * 289 / 384);
  margin-left: calc(var(--overlap, 0px) * -1);
  filter: drop-shadow(0 3px 0 color-mix(in srgb, var(--ak-outline) 28%, transparent));
}

.dealer-band .card {
  height: var(--card-h, min(14dvh, 86px));
  width: calc(var(--card-h, min(14dvh, 86px)) * 289 / 384);
}

.row .card:first-child {
  margin-left: 0;
}

.card-art {
  width: 100%;
  height: 100%;
  object-fit: fill;
  border-radius: 8px;
  pointer-events: none;
}

.plate {
  position: absolute;
  top: 8%;
  left: 9%;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 1.35em;
  padding: 1px 4px 2px;
  background: var(--ak-surface);
  color: var(--ak-accent);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  line-height: 1;
}

.rank {
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: max(12px, calc(var(--card-h, 120px) * 0.16));
  line-height: 0.85;
}

.plate svg {
  width: max(10px, calc(var(--card-h, 120px) * 0.11));
  height: max(10px, calc(var(--card-h, 120px) * 0.11));
  display: block;
}

.tokens {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.token {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.pebble,
.chip {
  position: relative;
  width: min(18vw, 72px);
  aspect-ratio: 1;
}

.pebble img,
.chip img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.token-num {
  position: absolute;
  left: 16%;
  right: 16%;
  top: 20%;
  bottom: 16%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ak-surface) 92%, transparent);
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: clamp(16px, 4.6vw, 26px);
  line-height: 1;
}

.token-num.is-long {
  font-size: clamp(13px, 3.6vw, 18px);
}

.token-name {
  padding: 1px 6px 2px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ak-ink-muted);
  line-height: 1.2;
}

.stake {
  margin: 0 0 16px auto;
  min-height: 48px;
  padding: 0 12px;
  display: grid;
  place-items: center;
  font-family: var(--ak-font-display);
  font-weight: var(--ak-title-weight);
  font-size: 15px;
  white-space: nowrap;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  align-items: stretch;
}

.actions.has-hint {
  grid-template-columns: 1fr 1fr;
}

.btn {
  position: relative;
  min-height: 48px;
  min-width: 48px;
  padding: 0 8px;
  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: 16px;
  letter-spacing: 0.03em;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

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

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

.btn-double {
  background: var(--ak-accent-2);
  color: var(--ak-btn-ink);
}

.btn.is-dim {
  background: var(--ak-choice-bg);
  color: var(--ak-ink-muted);
  box-shadow: none;
}

.btn:disabled {
  cursor: default;
  box-shadow: none;
  background: var(--ak-choice-bg);
  color: var(--ak-ink-muted);
}

.btn.is-point::before {
  content: "Here";
  display: block;
  margin-bottom: 2px;
  font-family: var(--ak-font-body);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  line-height: 1;
}

.btn-hit:active,
.btn-go:active,
.btn-double:active {
  background: var(--ak-btn-active);
}

.btn-stand:active,
.btn-hint:active,
.btn-alt:active {
  background: var(--ak-choice-bg);
}

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

.why {
  position: relative;
  z-index: 7;
  margin: 0;
  padding: 6px 8px;
  font-size: 14px;
  line-height: 1.3;
}

.result {
  position: relative;
  z-index: 7;
}

.result-card {
  padding: 8px 10px 10px;
}

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

.result-says {
  margin: 4px 0 8px;
  font-size: 15px;
  line-height: 1.35;
}

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

.result-actions .btn {
  flex: 1 1 0;
}

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

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

.bit.is-leaf {
  width: 12px;
  height: 8px;
  border-radius: 0 80% 0 80%;
}

.player-band.is-example .card {
  outline: 3px solid var(--ak-accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  .btn:hover:not(:disabled):not(.is-dim) {
    transform: translateY(-1px);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .dealer-band {
    animation: far-idle 4.8s ease-in-out infinite;
  }

  .pebble.is-idle,
  .chip.is-idle {
    animation: token-idle 2.8s ease-in-out infinite;
  }

  .chip.is-idle {
    animation-delay: -1.1s;
  }

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

  .card.is-enter {
    animation: card-in 460ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .card.is-flip {
    animation: card-flip 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .card.is-snap {
    animation: snap 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .card.is-lift {
    animation: lift 420ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .row.is-bust {
    animation: shake 460ms ease-in-out;
  }

  .total.is-pop {
    animation: pop 380ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .total.is-chase {
    animation: chase 700ms ease-out;
  }

  .pebble.is-hop {
    animation: hop 460ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .chip.is-tick,
  .chip.is-glow {
    animation: tick 420ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .chip.is-glow {
    animation-name: glow-once;
    animation-duration: 800ms;
  }

  .turn.is-cue {
    animation: turn-cue 420ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .btn.is-point {
    animation: point-pulse 1.05s ease-in-out infinite;
  }

  .btn.is-invite:not(.is-point) {
    animation: invite 1.15s ease-in-out infinite;
  }

  .btn.is-no {
    animation: shake 380ms ease-in-out;
  }

  .btn:active:not(:disabled) {
    transform: translateY(2px) scale(0.98, 1.04);
  }

  .result.is-in .result-card {
    animation: slip 420ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .bit {
    animation: fall 980ms ease-in forwards;
  }
}

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

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

@keyframes invite-slip {
  0%,
  100% { box-shadow: var(--ak-shadow); }
  50% { box-shadow: var(--ak-shadow), 0 0 0 3px color-mix(in srgb, var(--ak-accent) 35%, transparent); }
}

@keyframes card-in {
  0% { transform: translateY(-36%) scale(1.02, 1.16); opacity: 0; }
  68% { transform: translateY(0) scale(1.05, 0.9); opacity: 1; }
  100% { transform: translateY(0) scale(1, 1); opacity: 1; }
}

@keyframes card-flip {
  0% { transform: rotateY(86deg) scale(1.06, 0.92); }
  100% { transform: rotateY(0deg) scale(1, 1); }
}

@keyframes snap {
  0% { transform: translateY(-34%) scale(1.08, 0.84); }
  70% { transform: translateY(4%) scale(0.96, 1.08); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes lift {
  0% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-12px) scale(1.03, 0.95); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes shake {
  0%,
  100% { transform: translateX(0); }
  20% { transform: translateX(-6px) rotate(-1deg); }
  40% { transform: translateX(6px) rotate(1deg); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.28); }
  100% { transform: scale(1); }
}

@keyframes chase {
  0% { text-shadow: 0 0 0 var(--ak-glow); color: var(--ak-accent); }
  100% { text-shadow: 0 0 12px var(--ak-glow); color: var(--ak-ink); }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  35% { transform: translateY(-14px) scale(0.92, 1.1); }
  62% { transform: translateY(0) scale(1.08, 0.9); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes tick {
  0% { transform: rotate(0deg) scale(1); }
  35% { transform: rotate(-8deg) scale(1.08); }
  70% { transform: rotate(6deg) scale(0.98); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes glow-once {
  0% { transform: scale(1); filter: drop-shadow(0 0 0 var(--ak-glow)); }
  45% { transform: scale(1.1); filter: drop-shadow(0 0 10px var(--ak-glow)) drop-shadow(0 0 6px var(--ak-accent)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 0 var(--ak-glow)); }
}

@keyframes turn-cue {
  0% { transform: scale(0.94); }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes point-pulse {
  0%,
  100% { transform: translateY(0); box-shadow: var(--ak-shadow); }
  50% { transform: translateY(-3px); box-shadow: var(--ak-shadow), 0 0 0 3px var(--ak-accent); }
}

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

@keyframes slip {
  0% { transform: translateY(18px) scale(0.96); opacity: 0; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes fall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(72dvh) rotate(240deg); opacity: 0; }
}
