*,
*::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);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  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));
  --stack: 268px;
  --extra: 1.36;
  --heat: 0;
  --spread: 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  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;
  color: var(--ak-ink);
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.play.is-years {
  --extra: 2.2;
}

.play.is-ended {
  --stack: 448px;
  --extra: 2.2;
}

.play.is-ended .voice,
.play.is-ended .goal {
  display: none;
}

.hearth {
  position: absolute;
  z-index: 0;
  left: 4%;
  top: 0;
  width: 58%;
  height: 32%;
  pointer-events: none;
  background: radial-gradient(
    ellipse at 32% 42%,
    color-mix(in srgb, var(--ak-accent-2) 72%, transparent),
    transparent 68%
  );
  opacity: calc(0.16 + (var(--heat) * 0.07));
  mix-blend-mode: screen;
}

.play > :not(.hearth):not(.fx):not(.mute) {
  position: relative;
  z-index: 1;
}

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

.mute:active {
  background: var(--ak-choice-bg);
}

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

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

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

.turn {
  min-width: 0;
}

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

.turn-sub {
  margin: 2px 0 0;
  color: var(--ak-ink-muted);
  font-size: 14px;
}

.voice,
.goal,
.why,
.result-card,
.streak-chip {
  background: var(--ak-surface);
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
}

.voice {
  margin: 0;
  min-height: 42px;
  padding: 6px 8px;
  color: var(--ak-ink);
  font-size: 15px;
  line-height: 1.25;
}

.voice.is-invite {
  font-family: var(--ak-font-display);
  font-weight: 700;
  color: var(--ak-accent);
}

.goal {
  margin: 0;
  padding: 4px 8px;
  color: var(--ak-ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.rail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.rail {
  position: relative;
  flex: 0 1 auto;
}

.rail img {
  width: auto;
  height: min(72px, 9dvh);
}

.peg {
  position: absolute;
  right: 9%;
  top: 2%;
  width: 18%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--ak-btn-ink), var(--ak-accent-2) 46%, var(--ak-accent) 80%);
  box-shadow: 0 0 8px var(--ak-glow), 0 2px 0 var(--ak-ink);
  opacity: 0;
  pointer-events: none;
}

.streak-chip {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 76px;
  min-height: 48px;
  margin: 0;
  padding: 4px 10px;
}

.kicker {
  color: var(--ak-ink-muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.streak-num {
  font-family: var(--ak-font-display);
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--ak-accent);
}

.table {
  position: relative;
  flex: 0 0 auto;
  margin-top: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px 8px 0;
  border: 3px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background:
    radial-gradient(ellipse at 50% 100%, color-mix(in srgb, var(--ak-accent) 46%, transparent), transparent 64%),
    color-mix(in srgb, var(--ak-accent) 16%, var(--ak-surface));
  box-shadow:
    var(--ak-shadow),
    inset 0 0 0 2px color-mix(in srgb, var(--ak-accent-2) 70%, transparent);
}

.table::after {
  content: "";
  flex: 0 0 auto;
  height: 10px;
  margin: 4px 8px 0;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--ak-accent-2) 78%, var(--ak-ink)),
    var(--ak-ink)
  );
  box-shadow: var(--ak-shadow);
}

.cards {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: var(--spread);
  width: 100%;
}

.slot {
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: min(44%, 188px, calc((100dvh - var(--stack)) / var(--extra)));
  min-width: 0;
}

.slot:nth-child(1) .card {
  --tip: -8deg;
}

.slot:nth-child(2) .card {
  --tip: 8deg;
}

.card {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: rotate(var(--lean, 0deg));
  transform-origin: 50% 100%;
  touch-action: manipulation;
}

.card[aria-disabled="true"] {
  cursor: default;
}

.card-art {
  width: 100%;
  height: auto;
  pointer-events: none;
  filter: drop-shadow(0 7px 0 color-mix(in srgb, var(--ak-ink) 30%, transparent));
}

.card:active .card-art {
  filter: drop-shadow(0 2px 0 color-mix(in srgb, var(--ak-ink) 30%, transparent)) brightness(1.06);
}

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

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

.scene {
  position: absolute;
  z-index: 1;
  left: 32%;
  top: 22%;
  width: 40%;
  height: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scene svg {
  width: 90%;
  height: 90%;
  overflow: visible;
}

.scene .a { fill: var(--ak-accent); }
.scene .g { fill: var(--ak-accent-2); }
.scene .i { fill: var(--ak-ink); }
.scene .c { fill: var(--ak-btn-ink); }
.scene .s,
.scene .sa,
.scene .sg {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.scene .s { stroke: var(--ak-ink); stroke-width: 2; }
.scene .sa { stroke: var(--ak-accent); stroke-width: 2.2; }
.scene .sg { stroke: var(--ak-accent-2); stroke-width: 2.2; }

.name {
  position: absolute;
  z-index: 2;
  left: 18%;
  top: 73.5%;
  width: 64%;
  height: 9%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(8px, 6.7cqi, 12px);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
}

.seal {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 41%;
  width: 42%;
  height: auto;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.72);
  pointer-events: none;
  filter: drop-shadow(0 3px 0 color-mix(in srgb, var(--ak-ink) 45%, transparent));
}

.seal.is-on {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.plate {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 0;
  margin-top: 0;
  overflow: hidden;
}

.plate.is-out {
  height: calc(100cqi * 308 / 384);
  margin-top: -6px;
}

.plate img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.plate-copy {
  position: absolute;
  left: 20%;
  right: 20%;
  top: 22%;
  bottom: 40%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0;
  text-align: center;
}

.year {
  color: var(--ak-btn-ink);
  font-family: var(--ak-font-display);
  font-size: clamp(12px, 14cqi, 26px);
  font-weight: 700;
  line-height: 1;
}

.source {
  margin-top: 1px;
  color: color-mix(in srgb, var(--ak-btn-ink) 86%, var(--ak-accent-2));
  font-size: clamp(8px, 6.4cqi, 12px);
  font-weight: 700;
  line-height: 1.1;
}

.end {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.why {
  margin: 0;
  padding: 8px;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.result-card {
  padding: 8px;
  border-color: var(--ak-accent);
}

.result-says {
  margin: 0 0 8px;
  color: var(--ak-ink);
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

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

.btn-go,
.btn-alt {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

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

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

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

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

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

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

.fx i {
  position: absolute;
  width: 9px;
  height: 14px;
  border-radius: 2px;
  opacity: 0;
}

.rail-row.is-hot .streak-num {
  color: var(--ak-accent);
  text-shadow: 0 0 10px var(--ak-glow), 0 0 8px var(--ak-accent-2);
}

@media (max-height: 740px) {
  .play {
    --stack: 236px;
  }

  .play.is-ended {
    --stack: 400px;
  }

  .play-logo {
    max-height: 32px;
  }

  .turn-who {
    font-size: 18px;
  }

  .rail img {
    height: 52px;
  }

  .streak-num {
    font-size: 22px;
  }

  .voice,
  .goal {
    font-size: 13px;
  }

  .goal {
    padding-block: 2px;
  }
}

@media (min-width: 700px) {
  body {
    display: flex;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .plate {
    transition: height 460ms cubic-bezier(0.22, 1, 0.36, 1), margin-top 460ms ease;
  }

  .cards {
    transition: gap 520ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .hearth {
    animation: hearth 2.8s ease-in-out infinite;
  }

  .play-logo {
    animation: float 3.2s ease-in-out infinite;
  }

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

  .card {
    animation: sway 3.5s ease-in-out infinite;
  }

  .slot:nth-child(2) .card {
    animation-delay: -1.5s;
  }

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

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

  .slot .card.is-tip {
    animation: tip 480ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .slot .card.is-wobble {
    animation: wobble 620ms ease-in-out;
  }

  .slot .card.is-hop.is-wobble {
    animation:
      hop 300ms cubic-bezier(0.34, 1.56, 0.64, 1),
      wobble 640ms ease-in-out 180ms;
  }

  .slot:nth-child(1) .card.is-deal {
    animation: deal-left 440ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .slot:nth-child(2) .card.is-deal {
    animation: deal-right 440ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .seal.is-stamp {
    animation: stamp 440ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

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

  .streak-num.is-bump {
    animation: bump 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
  }

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

  .table.is-chase {
    animation: chase 900ms linear 2;
  }

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

  .mute:active,
  .btn-go:active,
  .btn-alt:active {
    transform: scale(0.97);
  }

  @keyframes sway {
    0%,
    100% { transform: rotate(var(--lean, 0deg)) translateY(0); }
    50% { transform: rotate(calc(var(--lean, 0deg) * -0.35)) translateY(-4px); }
  }

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

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

  @keyframes hearth {
    0%,
    100% { opacity: calc(0.14 + (var(--heat) * 0.06)); }
    50% { opacity: calc(0.28 + (var(--heat) * 0.08)); }
  }

  @keyframes hop {
    0% { transform: translateY(0) rotate(var(--lean, 0deg)) scale(1, 1); }
    35% { transform: translateY(-18px) rotate(var(--lean, 0deg)) scale(0.9, 1.14); }
    68% { transform: translateY(3px) rotate(var(--lean, 0deg)) scale(1.08, 0.9); }
    100% { transform: translateY(0) rotate(var(--lean, 0deg)) scale(1, 1); }
  }

  @keyframes tip {
    0% { transform: rotate(var(--lean, 0deg)) translateY(0) scale(1, 1); }
    45% { transform: rotate(calc(var(--lean, 0deg) + var(--tip, 8deg))) translateY(8px) scale(0.96, 1.04); }
    100% { transform: rotate(var(--lean, 0deg)) translateY(0) scale(1, 1); }
  }

  @keyframes wobble {
    0% { transform: rotate(var(--lean, 0deg)); }
    18% { transform: rotate(calc(var(--lean, 0deg) + 9deg)) translateX(4px); }
    36% { transform: rotate(calc(var(--lean, 0deg) - 8deg)) translateX(-4px); }
    54% { transform: rotate(calc(var(--lean, 0deg) + 6deg)); }
    72% { transform: rotate(calc(var(--lean, 0deg) - 3deg)); }
    100% { transform: rotate(var(--lean, 0deg)); }
  }

  @keyframes deal-left {
    0% { opacity: 0; transform: translateX(-36px) translateY(18px) rotate(calc(var(--lean, 0deg) - 8deg)) scale(0.92, 1.05); }
    68% { opacity: 1; transform: translateX(3px) translateY(-6px) rotate(var(--lean, 0deg)) scale(1.05, 0.94); }
    100% { opacity: 1; transform: translateX(0) rotate(var(--lean, 0deg)) scale(1, 1); }
  }

  @keyframes deal-right {
    0% { opacity: 0; transform: translateX(36px) translateY(18px) rotate(calc(var(--lean, 0deg) + 8deg)) scale(0.92, 1.05); }
    68% { opacity: 1; transform: translateX(-3px) translateY(-6px) rotate(var(--lean, 0deg)) scale(1.05, 0.94); }
    100% { opacity: 1; transform: translateX(0) rotate(var(--lean, 0deg)) scale(1, 1); }
  }

  @keyframes stamp {
    0% { opacity: 0; transform: translate(-50%, -78%) scale(1.4) rotate(-16deg); }
    68% { opacity: 1; transform: translate(-50%, -46%) scale(0.9) rotate(5deg); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  }

  @keyframes peg-pop {
    0% { opacity: 0; transform: translateY(12px) scale(0.35); }
    42% { opacity: 1; transform: translateY(-16px) scale(1.18); }
    100% { opacity: 0; transform: translateY(-26px) scale(0.8); }
  }

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

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

  @keyframes chase {
    0% { box-shadow: var(--ak-shadow), inset 0 0 0 2px color-mix(in srgb, var(--ak-accent-2) 70%, transparent), 0 0 0 0 var(--ak-glow); }
    50% { box-shadow: var(--ak-shadow), inset 0 0 0 2px var(--ak-accent-2), 0 0 18px 3px var(--ak-accent-2), 0 0 22px var(--ak-glow); }
    100% { box-shadow: var(--ak-shadow), inset 0 0 0 2px color-mix(in srgb, var(--ak-accent-2) 70%, transparent), 0 0 0 0 var(--ak-glow); }
  }

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