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

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

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 {
  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(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;
  grid-template-areas:
    "top"
    "say"
    "board"
    "dock"
    "result";
  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;
  background-repeat: no-repeat;
}

.top { grid-area: top; }
.say,
.why { grid-area: say; }
.stage { grid-area: board; }
.dock { grid-area: dock; }
.result { grid-area: result; }

.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);
  transform: rotate(-35deg);
}

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

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

.turn {
  min-width: 0;
  padding: 2px 8px 3px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

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

.turn-sub {
  margin: 1px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ak-ink-muted);
}

.say,
.why {
  margin: 0;
  padding: 5px 8px 6px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.rule {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ak-ink-muted);
}

.voice,
.why {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ak-ink);
}

.voice.is-invite {
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-weight: var(--ak-title-weight);
  line-height: 1.05;
}

.voice.is-fault {
  color: var(--ak-ink);
}

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

.stage {
  position: relative;
  min-height: 0;
  height: 100%;
}

.board {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.board.is-example {
  grid-template-rows: minmax(0, 1fr);
  padding: 4% 1%;
}

.card {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  touch-action: manipulation;
}

.card.is-empty {
  cursor: default;
  opacity: 0.35;
}

.plaque {
  position: absolute;
  inset: 0;
  background-image: url("./art/card.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
  pointer-events: none;
}

.marks {
  position: absolute;
  inset: 12% 11% 11%;
  display: grid;
  justify-items: center;
  align-items: stretch;
  gap: 1px;
  min-height: 0;
  pointer-events: none;
}

.marks.count-1 { grid-template-rows: minmax(0, 1fr); }
.marks.count-2 { grid-template-rows: repeat(2, minmax(0, 1fr)); }
.marks.count-3 { grid-template-rows: repeat(3, minmax(0, 1fr)); }

.marks img {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.fallback {
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  color: var(--ak-ink);
}

.board.is-example .marks {
  inset: 12% 10% 28%;
}

.cap {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 7%;
  margin: 0;
  padding: 2px 0;
  text-align: center;
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-ink);
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
}

.flare {
  position: absolute;
  top: 7%;
  right: 8%;
  width: 16%;
  height: 11%;
  border-radius: 3px;
  background: var(--ak-accent-2);
  opacity: 0;
  pointer-events: none;
  box-shadow: 0 0 8px var(--ak-accent-2), 0 0 2px var(--ak-glow);
}

.card.is-picked {
  z-index: 2;
  box-shadow: inset 0 0 0 3px var(--ak-accent-2);
}

.card.is-picked .flare {
  opacity: 0.95;
}

.card.is-hint,
.card.is-coach {
  z-index: 2;
  box-shadow: 0 0 0 3px var(--ak-accent-2), 0 0 10px var(--ak-glow);
}

.card.is-picked.is-hint,
.card.is-picked.is-coach {
  box-shadow:
    inset 0 0 0 3px var(--ak-accent-2),
    0 0 0 3px var(--ak-accent-2),
    0 0 10px var(--ak-glow);
}

.dock {
  display: grid;
  grid-template-columns: 78px minmax(48px, 1fr) 78px;
  align-items: end;
  gap: 6px;
  min-height: 64px;
}

.stack {
  position: relative;
  width: 78px;
  height: 64px;
  justify-self: start;
}

.stack img {
  width: 78px;
  height: 58px;
  object-fit: contain;
  object-position: left bottom;
}

.stack.is-empty img {
  opacity: 0.38;
}

.score {
  position: absolute;
  right: 0;
  bottom: 0;
  min-width: 28px;
  margin: 0;
  padding: 1px 4px 0;
  background: var(--ak-surface);
  color: var(--ak-accent);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  font-family: var(--ak-font-display);
  font-size: 22px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
  text-align: center;
}

.hint,
.btn-go,
.btn-alt {
  min-height: 48px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  cursor: pointer;
  touch-action: manipulation;
}

.hint {
  justify-self: center;
  align-self: center;
  min-width: 88px;
  padding: 8px 14px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: 24px;
  font-weight: var(--ak-title-weight);
}

.hint:disabled {
  opacity: 0.45;
  cursor: default;
}

.timer {
  position: relative;
  width: 72px;
  height: 64px;
  justify-self: end;
}

.timer-disc {
  position: relative;
  width: 64px;
  height: 64px;
  margin-left: auto;
  overflow: hidden;
  border: 2px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.timer-disc img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 46%;
}

.cover {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: var(--ak-choice-bg);
  transform: translate(-50%, -50%);
}

.hand {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 4px;
  height: 30%;
  margin-left: -2px;
  border-radius: 3px;
  background: var(--ak-accent);
  transform-origin: 50% 100%;
}

.hub {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 9px;
  height: 9px;
  margin: -4px 0 0 -4px;
  border: 1px solid var(--ak-outline);
  border-radius: 50%;
  background: var(--ak-accent-2);
}

.clock {
  position: absolute;
  left: 50%;
  bottom: 0;
  margin: 0;
  padding: 0 4px;
  transform: translateX(-50%);
  background: var(--ak-surface);
  color: var(--ak-ink);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  line-height: 1.1;
}

.is-urgent .clock,
.is-stopped .clock {
  color: var(--ak-accent);
}

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

.result-card {
  padding: 8px 8px 6px;
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

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

.result-count {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ak-ink-muted);
}

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

.btn-go,
.btn-alt {
  padding: 8px 6px;
}

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

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

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

.card:focus-visible {
  outline-offset: -4px;
  z-index: 3;
}

.card:active,
.hint:active,
.mute:active,
.btn-go:active,
.btn-alt:active {
  filter: brightness(1.08);
}

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

.drop,
.bit {
  position: absolute;
  opacity: 0;
}

.drop {
  width: 8px;
  height: 11px;
  margin: -5px 0 0 -4px;
  border-radius: 40% 40% 50% 50%;
}

.drop-a { background: var(--ak-accent); }
.drop-b { background: var(--ak-accent-2); }
.drop-c { background: var(--ak-ink); }

.bit {
  width: 8px;
  height: 12px;
  border-radius: 2px;
}

@media (hover: hover) {
  .card:hover {
    filter: brightness(1.05);
  }

  .hint:hover:not(:disabled),
  .btn-go:hover,
  .btn-alt:hover,
  .mute:hover {
    transform: translateY(-1px);
  }
}

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

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

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

  .card.is-idle {
    animation: float 3.2s ease-in-out infinite;
  }

  .card.is-idle:nth-child(3n + 2) { animation-delay: 0.4s; }
  .card.is-idle:nth-child(3n) { animation-delay: 0.8s; }

  .card.is-picked {
    transform: translateY(-7px) scale(1.03, 0.98);
    animation: hop 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .card.is-shake {
    animation: shake 420ms ease-in-out;
  }

  .card.is-leaving {
    z-index: 3;
    animation: slide-off 420ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

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

  .card.is-hint::after,
  .card.is-coach::after {
    content: "";
    position: absolute;
    inset: 3px;
    border: 2px solid var(--ak-accent-2);
    border-radius: 6px;
    pointer-events: none;
    animation: ring 1.1s ease-in-out infinite;
  }

  .fault-word {
    animation: oxblood 640ms ease-in-out 2;
  }

  .hint.is-offer {
    animation: offer 1.15s ease-in-out infinite;
  }

  .hint:active:not(:disabled),
  .btn-go:active,
  .btn-alt:active,
  .mute:active {
    transform: translateY(2px) scale(0.98, 1.02);
  }

  .card:active:not(.is-picked):not(.is-empty) {
    transform: scale(0.97, 1.03);
  }

  .stack img {
    animation: float 3.6s ease-in-out infinite;
  }

  .stack.is-tick .score {
    animation: pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .hand {
    animation: glint 1.35s ease-in-out infinite;
  }

  .is-urgent .hand {
    animation-duration: 0.32s;
  }

  .is-urgent .card.is-idle {
    animation: edge 0.65s ease-in-out infinite;
  }

  .is-stopped .hand,
  .is-stopped .card,
  .is-stopped .stack img,
  .is-stopped .play-logo {
    animation: none;
  }

  .board.is-dealing::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    z-index: 3;
    width: 42%;
    height: 28%;
    pointer-events: none;
    background: radial-gradient(circle at 80% 0%, color-mix(in srgb, var(--ak-accent-2) 75%, transparent), transparent 68%);
    animation: porthole 520ms ease-out;
  }

  .stack.is-hot,
  .result.is-sharp .result-card {
    animation: chase 1.15s linear infinite;
  }

  .drop {
    animation: splash 620ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .bit {
    animation: burst 920ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }
}

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

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

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

@keyframes shake {
  0%, 100% { transform: translateY(-7px) translateX(0); }
  25% { transform: translateY(-7px) translateX(-6px) rotate(-1.5deg); }
  75% { transform: translateY(-7px) translateX(6px) rotate(1.5deg); }
}

@keyframes slide-off {
  0% { transform: translateY(-7px) scale(1.03); opacity: 1; }
  100% { transform: translate(-18%, 120%) rotate(-10deg) scale(0.86); opacity: 0.15; }
}

@keyframes glide {
  0% { transform: translate(28px, -70px) rotate(7deg) scale(0.84); opacity: 0; }
  68% { transform: translate(0, 5px) rotate(0) scale(1.05, 0.92); opacity: 1; }
  100% { transform: translate(0, 0) scale(1); opacity: 1; }
}

@keyframes ring {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--ak-accent-2); }
  50% { opacity: 0.55; box-shadow: 0 0 0 6px transparent; }
}

@keyframes oxblood {
  0%, 100% { color: var(--ak-accent); }
  50% { color: var(--ak-ink); }
}

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

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

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.2) rotate(-4deg); }
  100% { transform: scale(1); }
}

@keyframes glint {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.7); }
}

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

@keyframes porthole {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes chase {
  0% { box-shadow: var(--ak-shadow), 0 0 0 0 var(--ak-accent-2); }
  35% { box-shadow: var(--ak-shadow), 0 0 16px var(--ak-accent); }
  70% { box-shadow: var(--ak-shadow), 0 0 14px var(--ak-accent-2); }
  100% { box-shadow: var(--ak-shadow), 0 0 0 0 var(--ak-accent-2); }
}

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

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