*,
*::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: 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;
  background-color: var(--ak-bg);
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.heat,
.clock,
.giant,
.clip-ring {
  pointer-events: none;
}

.heat {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  height: 34%;
  background-image: linear-gradient(
    to top,
    color-mix(in srgb, var(--ak-accent) 46%, transparent),
    transparent 68%
  );
  opacity: 0.55;
}

.clock {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 1;
  width: 92px;
  height: 40px;
  transform: translateX(-50%);
}

.clock-arc {
  fill: color-mix(in srgb, var(--ak-surface) 88%, transparent);
  stroke: var(--ak-accent-2);
  stroke-width: 4;
}

.clock-hand {
  stroke: var(--ak-accent-2);
  stroke-width: 3;
  stroke-linecap: round;
}

.clock-tick {
  fill: var(--ak-accent);
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: var(--pad-x);
  z-index: 6;
  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 .slash {
  opacity: 0;
}

.mute.is-muted .wave {
  opacity: 0;
}

.mute.is-muted .slash {
  opacity: 1;
}

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

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

.turn {
  min-width: 0;
  flex: 1 1 auto;
}

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

.turn-who {
  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-top: 2px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ak-ink-muted);
}

.prompt {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-height: 36px;
}

.prompt-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.bubble {
  position: relative;
  margin: 0 8px 12px 0;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
}

.bubble p {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: 18px;
  font-weight: var(--ak-title-weight);
  line-height: 1.2;
  color: var(--ak-ink);
}

.bubble::after {
  content: '';
  position: absolute;
  left: 22px;
  bottom: -9px;
  width: 14px;
  height: 14px;
  background: var(--ak-surface);
  border-right: 2px solid var(--ak-outline);
  border-bottom: 2px solid var(--ak-outline);
  transform: rotate(45deg);
}

.voice {
  margin: 0;
  min-height: 22px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  color: var(--ak-ink);
}

.hint,
.check,
.btn {
  min-height: 48px;
  min-width: 48px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: 16px;
  font-weight: var(--ak-title-weight);
  cursor: pointer;
  touch-action: manipulation;
}

.hint {
  flex: 0 0 auto;
  padding: 0 12px;
  background: var(--ak-surface);
  color: var(--ak-accent-2);
}

.stage {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  overflow: hidden;
}

.giant {
  position: absolute;
  z-index: 0;
  right: -38%;
  bottom: 16%;
  width: min(62vw, 240px);
  transform: rotate(8deg);
  filter: drop-shadow(0 10px 0 color-mix(in srgb, var(--ak-accent-2) 40%, transparent));
}

.hang {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1 1 auto;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
}

.ticket {
  position: relative;
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  width: min(78%, 280px);
  height: 100%;
  min-height: 0;
  max-height: 100%;
  padding: 42px 8px 8px 18px;
  filter: drop-shadow(0 8px 0 color-mix(in srgb, var(--ak-accent-2) 38%, transparent));
}

.ticket-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: left top;
}

.clip-ring {
  position: absolute;
  top: 8px;
  left: 46%;
  z-index: 2;
  width: 18px;
  height: 18px;
  border: 2px solid var(--ak-accent);
  border-radius: 50%;
  opacity: 0;
}

.ticket-kicker {
  position: relative;
  z-index: 1;
  margin: 0 0 4px;
  font-family: var(--ak-font-display);
  font-size: 14px;
  font-weight: var(--ak-title-weight);
  line-height: 1;
  color: var(--ak-ink);
}

.slots {
  position: relative;
  z-index: 1;
  display: grid;
  flex: 1 1 auto;
  align-content: start;
  gap: 4px;
  min-height: 0;
  grid-template-rows: repeat(var(--slot-count, 2), 56px);
  padding: 4px;
  background: var(--ak-surface);
}

.slot {
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.chip,
.groove {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 48px;
  height: 100%;
  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);
}

.chip {
  width: 100%;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.groove {
  border-style: dashed;
  background: color-mix(in srgb, var(--ak-surface) 70%, transparent);
  box-shadow: none;
}

.chip-main,
.change-bit {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 48px;
  min-height: 48px;
  height: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.chip-main {
  flex: 1 1 auto;
  padding: 0;
  text-align: left;
}

.change-bit {
  flex: 0 1 auto;
  max-width: 46%;
  padding: 0 4px;
  border-left: 2px solid var(--ak-outline);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.05;
}

.mini {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
}

.chip-name,
.stamp-name,
.tile-name {
  color: var(--ak-ink);
  font-weight: 700;
  line-height: 1.05;
}

.chip-name {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
}

.rail span {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: var(--ak-accent-2);
  box-shadow: var(--ak-shadow);
}

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

.menu {
  grid-template-columns: repeat(3, minmax(48px, 1fr));
}

.changes {
  grid-template-columns: repeat(4, minmax(48px, 1fr));
}

.tile,
.stamp {
  position: relative;
  display: flex;
  min-width: 0;
  min-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;
  touch-action: manipulation;
  overflow: hidden;
}

.tile {
  height: min(9dvh, 68px);
  flex-direction: column;
}

.stamp {
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 48px;
  padding: 2px 4px;
}

.tile-body,
.piece {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.tile-body img,
.piece img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.piece-mask {
  position: absolute;
  inset: 12% 8% 24%;
  display: flex;
  background: var(--ak-surface);
  border-radius: var(--ak-radius);
}

.piece-mask svg,
.mini svg {
  width: 100%;
  height: 100%;
}

.tile-name {
  position: absolute;
  right: 3px;
  bottom: 3px;
  left: 3px;
  padding: 2px;
  background: var(--ak-surface);
  font-size: 13px;
  text-align: center;
}

.stamp-window {
  position: relative;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border-radius: 50%;
  border: 2px solid var(--ak-outline);
}

.stamp-window img {
  position: absolute;
  width: 278%;
  height: 276%;
  max-width: none;
}

.stamp-no-sugar img { left: -36%; top: -58%; }
.stamp-extra-hot img { left: -138%; top: -58%; }
.stamp-iced img { left: -36%; top: -149%; }
.stamp-no-butter img { left: -138%; top: -156%; }

.stamp-name {
  min-width: 0;
  font-family: var(--ak-font-body);
  font-size: 11px;
  text-align: left;
}

.change-bit .stamp-window {
  width: 22px;
  height: 22px;
}

.check {
  position: relative;
  z-index: 2;
  width: 100%;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
}

.tile.is-coach,
.stamp.is-coach,
.check.is-coach,
.chip.is-coach {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
}

.is-miss {
  outline: 3px solid var(--ak-accent);
  outline-offset: 1px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ak-accent) 35%, transparent);
}

.tile:focus-visible,
.stamp:focus-visible,
.chip:focus-visible,
.chip-main:focus-visible,
.change-bit:focus-visible,
.hint:focus-visible,
.check:focus-visible,
.btn:focus-visible,
.mute:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 2px;
}

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

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

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

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

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

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

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

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

.play.is-ended .prompt,
.play.is-ended .rail,
.play.is-ended .menu,
.play.is-ended .changes,
.play.is-ended .check,
.play.is-ended .giant {
  display: none;
}

.play.is-ended .hang {
  gap: 6px;
  justify-content: stretch;
}

.play.is-ended .ticket {
  flex: 1 1 0;
  width: 0;
  min-width: 0;
  padding-top: 36px;
}

.play.is-ended .slots {
  grid-template-rows: repeat(var(--slot-count, 2), minmax(28px, 52px));
}

.play.is-ended .chip,
.play.is-ended .groove,
.play.is-ended .chip-main,
.play.is-ended .change-bit {
  min-height: 0;
  cursor: default;
}

.tone {
  stroke: var(--ak-outline);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.tone-cream { fill: var(--ak-surface); }
.tone-foam { fill: var(--ak-bg); }
.tone-bg { fill: var(--ak-bg); }
.tone-ink { fill: var(--ak-ink); }
.tone-steel { fill: var(--ak-accent-2); }
.tone-red { fill: var(--ak-accent); }
.tone-warm { fill: color-mix(in srgb, var(--ak-accent) 38%, var(--ak-bg)); }
.tone-line { fill: none; stroke: var(--ak-accent-2); }

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

.fx i {
  position: absolute;
  width: 10px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  opacity: 0;
}

.fly {
  position: fixed;
  z-index: 9;
  margin: 0;
  pointer-events: none;
}

.tile:active,
.stamp:active,
.chip:active,
.check:active,
.hint:active,
.btn:active,
.mute:active {
  filter: brightness(0.94);
}

@media (max-height: 700px) {
  .play-logo {
    height: 32px;
  }

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

  .bubble p {
    font-size: 16px;
  }

  .tile {
    height: 52px;
  }

  .ticket {
    padding-top: 34px;
  }
}

@media (hover: hover) {
  .tile:hover,
  .stamp:hover,
  .check:hover,
  .hint:hover,
  .btn-go:hover {
    transform: translateY(-1px);
  }
}

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

  .heat {
    animation: heat 3.4s ease-in-out infinite;
  }

  .clock-hand {
    transform-box: view-box;
    transform-origin: 40px 34px;
    animation: tick 4.8s steps(8, end) infinite;
  }

  .ticket {
    animation: sway 3.6s ease-in-out infinite;
  }

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

  .tile:nth-child(2) .tile-body { animation-delay: 0.15s; }
  .tile:nth-child(3) .tile-body { animation-delay: 0.3s; }
  .tile:nth-child(4) .tile-body { animation-delay: 0.08s; }
  .tile:nth-child(5) .tile-body { animation-delay: 0.22s; }
  .tile:nth-child(6) .tile-body { animation-delay: 0.4s; }

  .giant {
    animation: giant-bob 4.2s ease-in-out infinite;
  }

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

  .bubble.is-in {
    animation:
      bubble-in 0.46s cubic-bezier(0.34, 1.56, 0.64, 1) both,
      bubble-wiggle 0.42s ease-in-out 0.46s 1;
  }

  .bubble.is-out {
    animation: bubble-out 0.36s ease-in forwards;
  }

  .tile:active .tile-body,
  .stamp:active {
    transform: scale(1.08, 0.88);
  }

  .tile.is-pop .tile-body,
  .stamp.is-pop {
    animation: squash 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .menu.is-shiver {
    animation: shiver 0.32s ease-in-out;
  }

  .ticket.is-slide {
    animation: slide 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .ticket.is-shake {
    animation: shake 0.42s ease-in-out;
  }

  .ticket.is-ring .clip-ring {
    animation: ring 0.6s ease-out;
  }

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

  .tile.is-coach,
  .stamp.is-coach,
  .check.is-coach {
    animation: point 0.7s ease-in-out infinite;
  }

  .check.is-ready {
    animation: invite 1.2s ease-in-out infinite;
  }

  .hint:active,
  .check:active,
  .btn:active,
  .mute:active {
    transform: translateY(2px) scale(0.98);
    box-shadow: none;
  }

  .play.is-win .result-card {
    background-image: linear-gradient(
      90deg,
      var(--ak-surface),
      color-mix(in srgb, var(--ak-accent) 42%, var(--ak-surface)),
      var(--ak-surface)
    );
    background-size: 200% 100%;
    animation: chase 0.7s linear 3;
  }

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

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

  @keyframes giant-bob {
    0%, 100% { transform: rotate(8deg) translateY(0); }
    50% { transform: rotate(8deg) translateY(-6px); }
  }

  @keyframes heat {
    0%, 100% { opacity: 0.35; transform: translateY(8px); }
    50% { opacity: 0.75; transform: translateY(0); }
  }

  @keyframes tick {
    to { transform: rotate(360deg); }
  }

  @keyframes sway {
    0%, 100% { transform: rotate(-0.8deg); }
    50% { transform: rotate(0.8deg); }
  }

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

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

  @keyframes bubble-in {
    0% { opacity: 0; transform: scale(0.62, 0.62); }
    60% { opacity: 1; transform: scale(1.06, 0.92) rotate(-2deg); }
    100% { opacity: 1; transform: scale(1, 1) rotate(0); }
  }

  @keyframes bubble-wiggle {
    0%, 100% { transform: rotate(0); }
    35% { transform: rotate(-2.5deg); }
    70% { transform: rotate(2deg); }
  }

  @keyframes bubble-out {
    0% { opacity: 1; transform: scale(1, 1); }
    100% { opacity: 0; transform: scale(0.72, 0.4); }
  }

  @keyframes squash {
    0% { transform: scale(1, 1); }
    40% { transform: scale(1.12, 0.84); }
    100% { transform: scale(1, 1); }
  }

  @keyframes shiver {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px); }
    50% { transform: translateX(3px); }
    75% { transform: translateX(-2px); }
  }

  @keyframes slide {
    0% { transform: translateX(0); }
    45% { transform: translateX(26px) rotate(1deg); }
    100% { transform: translateX(0); }
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px) rotate(-1deg); }
    45% { transform: translateX(8px) rotate(1deg); }
    70% { transform: translateX(-4px); }
  }

  @keyframes ring {
    0% { opacity: 0.9; transform: scale(0.4); }
    100% { opacity: 0; transform: scale(2.4); }
  }

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

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

  @keyframes chase {
    0% { background-position: 0 0; }
    100% { background-position: 200% 0; }
  }

  @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, 20deg)) scale(0.55); }
  }
}
