:root {
  color-scheme: dark;
  --bg: #000000;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.48);
  --faint: rgba(255, 255, 255, 0.28);
  --line: rgba(255, 255, 255, 0.12);
  --orb: #ffffff;
  --orb-ink: #000000;
  --font: "Inter", system-ui, -apple-system, "SF Pro Text", "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100svh;
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 20;
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus { top: calc(12px + var(--safe-t)); }

.ally-chrome {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(18px + var(--safe-t)) 22px 0;
  pointer-events: none;
}

.wordmark {
  font-size: 17px;
  font-weight: 400;
  letter-spacing: -0.03em;
  text-transform: lowercase;
  pointer-events: none;
}

.chrome-brand {
  pointer-events: none;
  display: grid;
  gap: 2px;
}

.chrome-kicker {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--faint);
}

.back-link {
  pointer-events: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.back-link:hover { color: var(--text); }

body.ally-miss {
  overflow: auto;
}

.ally-miss-main {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 14px;
  padding: calc(96px + var(--safe-t)) 24px calc(40px + var(--safe-b));
}

.ally-miss-main .eyebrow {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.ally-miss-main h1 {
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 500;
  letter-spacing: -0.04em;
}

.miss-copy {
  max-width: 26rem;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.miss-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 10px;
}

.miss-btn {
  pointer-events: auto;
  color: var(--bg);
  background: var(--text);
  text-decoration: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
}

.miss-btn.ghost {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
}

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

.stage {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(72px + var(--safe-t)) 24px calc(28px + var(--safe-b));
}

.presence {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.face-wrap {
  width: min(42vw, 280px);
  min-width: 196px;
  color: var(--text);
}

.ally-face {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.eye {
  transform-box: fill-box;
  transform-origin: center;
}

.face-wrap[data-state="idle"] .ally-face {
  animation: idleBreath 5.6s var(--ease) infinite;
}

.face-wrap[data-state="idle"] .eye,
.face-wrap[data-state="listening"] .eye {
  animation: blink 5.4s var(--ease) infinite;
}

.face-wrap[data-state="listening"] .eye-left { animation-delay: 0s, 0s; }
.face-wrap[data-state="listening"] .eye-right { animation-delay: 0.04s; }

.face-wrap[data-state="listening"] .ally-face {
  animation: listenHold 1.6s var(--ease) infinite;
}

.mouth-wrap {
  transform-box: fill-box;
  transform-origin: center;
}

.mouth {
  transform-box: fill-box;
  transform-origin: center;
}

.face-wrap[data-state="speaking"] .mouth {
  animation: mouthSpeak 0.26s ease-in-out infinite;
}

.face-wrap[data-state="speaking"] .eye {
  animation: blinkSpeak 2.4s var(--ease) infinite;
}

.tagline {
  color: var(--faint);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  transition: opacity 220ms var(--ease);
}

.presence:has(.caption.is-on) .tagline {
  opacity: 0;
}

.caption {
  min-height: 3.2em;
  max-width: 22rem;
  text-align: center;
  font-size: 16px;
  line-height: 1.45;
  letter-spacing: -0.02em;
  color: var(--muted);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 280ms var(--ease), transform 280ms var(--ease);
}

.caption.is-on {
  opacity: 1;
  transform: none;
  color: var(--text);
}

.dock {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding-top: 8px;
}

.demo-note {
  max-width: 22rem;
  text-align: center;
  font-size: 12px;
  line-height: 1.45;
  color: var(--faint);
  font-weight: 500;
}

.talk {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 22px 6px 6px;
  border-radius: 999px;
  transition: background 180ms var(--ease);
}

.talk.is-listening,
.talk.is-speaking {
  background: rgba(255, 255, 255, 0.06);
}

.talk:disabled { cursor: default; }

.talk-orb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--orb);
  color: var(--orb-ink);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 180ms var(--ease);
}

.talk:hover .talk-orb { transform: scale(1.03); }
.talk:active .talk-orb { transform: scale(0.97); }

.mic-icon {
  width: 26px;
  height: 26px;
  position: relative;
  z-index: 1;
}

.pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--orb);
  opacity: 0;
  transform: scale(1);
}

.talk.is-listening .pulse {
  animation: listenPulse 1.2s var(--ease) infinite;
}

.talk.is-listening .talk-orb,
.talk.is-speaking .talk-orb {
  box-shadow: 0 0 0 1px var(--line);
}

.talk-copy {
  display: grid;
  gap: 2px;
  text-align: left;
}

.talk-label {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.talk-hint {
  font-size: 12px;
  color: var(--faint);
  font-weight: 500;
}

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

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

@keyframes blink {
  0%, 88%, 94%, 100% { transform: scaleY(1); }
  91% { transform: scaleY(0.08); }
}

@keyframes blinkSpeak {
  0%, 72%, 80%, 100% { transform: scaleY(1); }
  76% { transform: scaleY(0.08); }
}

@keyframes mouthSpeak {
  0%, 100% { transform: scaleY(1) scaleX(1); }
  28% { transform: scaleY(5.2) scaleX(0.84); }
  52% { transform: scaleY(1.8) scaleX(0.96); }
  74% { transform: scaleY(4.1) scaleX(0.88); }
}

@keyframes listenPulse {
  0% { opacity: 0.45; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.55); }
}

@media (max-width: 520px) {
  .face-wrap {
    width: min(64vw, 240px);
    min-width: 168px;
  }
  .talk {
    flex-direction: column;
    gap: 12px;
  }
  .talk-copy { text-align: center; }
  .caption { font-size: 15px; padding: 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .face-wrap[data-state="idle"] .ally-face,
  .face-wrap[data-state="idle"] .eye,
  .face-wrap[data-state="listening"] .eye,
  .face-wrap[data-state="listening"] .ally-face,
  .face-wrap[data-state="speaking"] .eye,
  .talk.is-listening .pulse {
    animation: none;
  }
  .face-wrap[data-state="speaking"] .mouth {
    animation: none;
    transform: scaleY(2.4) scaleX(0.92);
  }
  .caption { transition: none; }
}
