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

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

body {
  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,
input {
  font-family: inherit;
  touch-action: manipulation;
}

[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: min(6px, 0.8dvh);
  width: min(100%, 430px);
  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-tap-highlight-color: transparent;
  background-image: var(--ak-backdrop-layer);
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}

.mute {
  position: absolute;
  top: var(--pad-top);
  right: max(6px, 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: 18px;
  height: 18px;
  border: 3px solid var(--ak-ink);
  border-left: 0;
  border-radius: 0 10px 10px 0;
  box-shadow: -7px 0 0 -3px var(--ak-ink);
}

.mute.is-muted .mute-icon {
  opacity: 0.35;
}

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

.play-logo {
  display: block;
  width: auto;
  height: min(46px, 6.5dvh);
  max-width: 46%;
  object-fit: contain;
  filter: drop-shadow(0 0 6px var(--ak-glow));
}

.turn {
  min-width: 0;
}

.turn-who {
  margin: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(20px, 5.6vw, 30px);
  font-weight: var(--ak-title-weight);
  letter-spacing: 0.02em;
  color: var(--ak-accent);
  text-shadow: 0 0 10px var(--ak-glow);
}

.turn-meta {
  margin: 0;
  color: var(--ak-ink);
  font-size: 13px;
}

.stage {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: min(22%, 78px) minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 4px;
  align-items: end;
  height: min(22dvh, 176px);
  min-height: 112px;
  flex: 0 0 auto;
}

.host {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(3px 3px 0 var(--ak-outline));
}

.envelope {
  position: relative;
  height: 100%;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.envelope:disabled {
  cursor: default;
}

.env-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.envelope:not(.is-open) .ghost {
  visibility: hidden;
}

.envelope.is-open .env-img {
  clip-path: inset(0 46% 0 0);
  transform: translateX(-10%) rotate(-7deg);
}

.envelope.is-open .ghost {
  clip-path: inset(0 0 0 46%);
  transform: translateX(10%) rotate(7deg);
}

.secret {
  position: absolute;
  left: 50%;
  bottom: 8%;
  z-index: 3;
  margin: 0;
  padding: 2px 8px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-surface);
  box-shadow: var(--ak-shadow);
  opacity: 0;
  font-family: var(--ak-font-display);
  font-size: clamp(13px, 3.6vw, 18px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  color: var(--ak-ink);
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
}

.envelope.is-open .secret {
  opacity: 1;
}

.dial {
  height: 100%;
  min-height: 48px;
  display: grid;
  place-items: end center;
}

.dial-frame {
  position: relative;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1;
}

.dial-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.dial-cover {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 1;
  width: 34%;
  height: 26%;
  transform: translate(-50%, -30%);
  border-radius: 50%;
  background: var(--ak-surface);
}

.needle {
  position: absolute;
  left: 50%;
  top: 46%;
  z-index: 2;
  width: 8px;
  height: 20%;
  border: 2px solid var(--ak-outline);
  border-radius: 8px 8px 2px 2px;
  background: var(--ak-bg);
  transform-origin: 50% 100%;
  transform: translate(-50%, -100%) rotate(var(--ang, -60deg));
}

.dial-num {
  position: absolute;
  left: 50%;
  top: 28%;
  z-index: 3;
  transform: translate(-50%, 0);
  font-family: var(--ak-font-display);
  font-size: clamp(16px, 4.6vw, 26px);
  font-weight: var(--ak-title-weight);
  color: var(--ak-ink);
}

.monitor {
  position: relative;
  z-index: 2;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.monitor-frame {
  position: relative;
  width: min(100cqw, calc(100cqh * 384 / 360));
  aspect-ratio: 384 / 360;
}

.monitor-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.glass {
  position: absolute;
  left: 9%;
  right: 16%;
  top: 9%;
  bottom: 29%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  overflow: hidden;
}

.timer {
  position: absolute;
  top: 8%;
  left: 10%;
  width: 80%;
  height: 8px;
  border: 2px solid var(--ak-outline);
  border-radius: 99px;
  background: var(--ak-surface);
  overflow: hidden;
}

.timer span {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(var(--left, 1));
  background: var(--ak-accent-2);
}

.clue {
  margin: 0;
  max-width: 100%;
  font-family: var(--ak-font-display);
  font-size: clamp(18px, 6vw, 34px);
  font-weight: var(--ak-title-weight);
  line-height: 1.05;
  text-align: center;
  color: var(--ak-ink);
  word-break: break-word;
}

.cursor {
  display: inline-block;
  width: 3px;
  height: 0.85em;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--ak-ink);
}

.badge {
  margin: 0;
  padding: 6px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: var(--ak-accent-2);
  color: var(--ak-btn-ink);
  box-shadow: var(--ak-shadow);
  font-family: var(--ak-font-display);
  font-size: clamp(14px, 4vw, 20px);
  text-align: center;
}

.voice,
.why {
  z-index: 4;
  flex: 0 0 auto;
  min-height: 36px;
  margin: 0;
  padding: 8px 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 90%, transparent);
  box-shadow: var(--ak-shadow);
  font-size: 14px;
}

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

.dock {
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 6px;
  flex: 0 0 auto;
}

.guess,
.send,
.next,
.btn-go,
.btn-alt {
  min-height: 48px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  box-shadow: var(--ak-shadow);
  font-weight: 700;
}

.guess {
  width: 100%;
  min-width: 0;
  padding: 0 10px;
  background: var(--ak-surface);
  color: var(--ak-ink);
  font-size: 16px;
}

.send,
.btn-go {
  padding: 0 12px;
  background: var(--ak-btn-fill);
  color: var(--ak-btn-ink);
  cursor: pointer;
}

.next,
.btn-alt {
  padding: 0 10px;
  background: var(--ak-accent-2);
  color: var(--ak-btn-ink);
  cursor: pointer;
}

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

.send:disabled,
.next:disabled,
.guess:disabled {
  opacity: 0.55;
}

.guess:focus-visible,
.send:focus-visible,
.next:focus-visible,
.btn-go:focus-visible,
.btn-alt:focus-visible,
.mute:focus-visible,
.envelope:focus-visible {
  outline: 3px solid var(--ak-focus);
  outline-offset: 3px;
}

.result {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
}

.result-card {
  padding: 10px;
  border: 2px solid var(--ak-outline);
  border-radius: var(--ak-radius);
  background: color-mix(in srgb, var(--ak-surface) 94%, transparent);
  box-shadow: var(--ak-shadow);
}

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

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

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

.beaker {
  position: absolute;
  z-index: 1;
  width: 28px;
  height: 52px;
  border: 2px solid var(--ak-outline);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: color-mix(in srgb, var(--ak-surface) 70%, transparent);
  overflow: hidden;
  pointer-events: none;
}

.beaker::before {
  content: '';
  position: absolute;
  left: -4px;
  right: -4px;
  top: -8px;
  height: 10px;
  border: 2px solid var(--ak-outline);
  border-radius: 4px;
  background: var(--ak-surface);
}

.beaker-left {
  left: max(2px, env(safe-area-inset-left, 0px));
  bottom: 28%;
}

.beaker-right {
  right: max(2px, env(safe-area-inset-right, 0px));
  bottom: 34%;
}

.liquid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 58%;
  background: var(--ak-accent);
}

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

.burst i {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 10px;
  height: 14px;
  border: 2px solid var(--ak-outline);
  border-radius: 2px;
  background: var(--ak-accent);
}

.burst i:nth-child(odd) {
  background: var(--ak-accent-2);
}

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

.play.is-ended .stage {
  height: min(16dvh, 128px);
  min-height: 96px;
}

.play.is-ended .monitor {
  flex: 0 1 min(24dvh, 180px);
  min-height: 100px;
}

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

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

  .liquid {
    animation: bob 1.8s ease-in-out infinite;
  }

  .beaker-right .liquid {
    animation-delay: 0.4s;
  }

  .cursor {
    animation: blink 0.7s steps(1, end) infinite;
  }

  .envelope.is-ready {
    animation: ready 0.9s cubic-bezier(0.34, 1.4, 0.64, 1) infinite;
  }

  .envelope.is-hop .env-img {
    animation: hop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .envelope.is-open .env-img {
    animation: tear-left 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .envelope.is-open .ghost {
    animation: tear-right 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .envelope.is-open .secret {
    animation: popword 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  .needle.is-wobble {
    animation: wobble 0.45s ease-in-out;
  }

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

  .play.is-slosh .beaker {
    animation: slosh 0.5s ease-in-out;
  }

  .play.is-flash .glass {
    animation: flash 0.45s ease-out;
  }

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

  .play.is-ended .monitor {
    animation: glowchase 1.1s linear 3;
  }

  .send:active,
  .next:active,
  .btn-go:active,
  .btn-alt:active,
  .mute:active,
  .envelope:not(:disabled):active {
    transform: translateY(2px) scale(0.97);
  }

  .burst i {
    animation: burst 0.85s ease-out forwards;
  }
}

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

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

@keyframes blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes ready {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-4px) scale(1.03); }
}

@keyframes hop {
  0% { transform: translateY(0) scale(1, 1); }
  40% { transform: translateY(-10px) scale(0.94, 1.08); }
  100% { transform: translateY(0) scale(1, 1); }
}

@keyframes tear-left {
  0% { clip-path: inset(0 0 0 0); transform: translateX(0) rotate(0); }
  100% { clip-path: inset(0 46% 0 0); transform: translateX(-10%) rotate(-7deg); }
}

@keyframes tear-right {
  0% { clip-path: inset(0 0 0 0); transform: translateX(0) rotate(0); }
  100% { clip-path: inset(0 0 0 46%); transform: translateX(10%) rotate(7deg); }
}

@keyframes popword {
  0% { opacity: 0; transform: translateX(-50%) scale(0.4); }
  60% { opacity: 1; transform: translateX(-50%) scale(1.12); }
  100% { opacity: 1; transform: translateX(-50%) scale(1); }
}

@keyframes wobble {
  0% { transform: translate(-50%, -100%) rotate(var(--ang, 0deg)); }
  35% { transform: translate(-50%, -100%) rotate(calc(var(--ang, 0deg) + 16deg)); }
  70% { transform: translate(-50%, -100%) rotate(calc(var(--ang, 0deg) - 8deg)); }
  100% { transform: translate(-50%, -100%) rotate(var(--ang, 0deg)); }
}

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

@keyframes slosh {
  0% { transform: rotate(0); }
  30% { transform: rotate(-12deg); }
  70% { transform: rotate(10deg); }
  100% { transform: rotate(0); }
}

@keyframes flash {
  0% { background: color-mix(in srgb, var(--ak-accent) 70%, transparent); }
  100% { background: transparent; }
}

@keyframes stamp {
  0% { transform: scale(1.6) rotate(-8deg); opacity: 0; }
  55% { transform: scale(0.92) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes glowchase {
  0% { filter: drop-shadow(-8px 0 8px var(--ak-accent)); }
  50% { filter: drop-shadow(8px 0 10px var(--ak-accent-2)); }
  100% { filter: drop-shadow(-8px 0 8px var(--ak-accent)); }
}

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