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

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: #0b0d10;
  color: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
}

/* Canvas do humanoide — pode ser o #viewport legado ou o canvas criado
   pelo HumanoidPlayer.mount(#stage). Ambos ficam no fundo, cobrindo o
   stage inteiro, atrás do HUD e do botão. */
#stage > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  z-index: 1;
}

#hud {
  position: absolute;
  top: env(safe-area-inset-top, 0);
  left: 0; right: 0;
  padding: 24px 20px 16px;
  text-align: center;
  pointer-events: none;
  z-index: 2;
  background: linear-gradient(to bottom, rgba(0,0,0,0.35), transparent);
}

#character-name {
  font-size: 20px;
  font-weight: 500;
  letter-spacing: 0.02em;
  margin: 0;
}

/* prova de deploy — identificação, não conteúdo (CLAUDE.md §2) */
#app-version {
  font-size: 9px;
  opacity: 0.35;
  margin-left: 8px;
  vertical-align: middle;
}

/* Botão de fala — o único controle do produto (CLAUDE.md §3).
   Quatro estados legíveis (idle / recording / thinking / speaking) e um flash
   de erro. O que caracteriza cada estado, além da cor, é UM sinal específico:
   idle mostra o mic, recording mostra a onda ao vivo do microfone (denuncia
   mic mudo), thinking mostra um arco girando, speaking mostra equalizer. */

/* Véu de chegada: enquanto o boot não tem o 1º idle rodando, o canvas fica
   invisível (T-pose NUNCA aparece) e o nome respira devagar — "ela está
   chegando". Revelação em fade quando .booting sai. */
#stage canvas { transition: opacity 700ms ease; }
#stage.booting canvas { opacity: 0; }
#stage.booting #character-name { animation: name-arrive 1.8s ease-in-out infinite; }
@keyframes name-arrive {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 0.9; }
}

#speak {
  --size: 128px;
  --face-size: 96px;
  --tone: #f5f5f5;
  --tone-soft: rgba(245, 245, 245, 0.14);
  --tone-strong: rgba(245, 245, 245, 0.28);
  --face-bg: rgba(11, 13, 16, 0.92);
  --icon: rgba(245, 245, 245, 0.92);

  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0) + 32px);
  transform: translateX(-50%);
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: none;
  padding: 0;
  background:
    radial-gradient(circle at 32% 30%, rgba(255,255,255,0.85), rgba(255,255,255,0.55) 45%, rgba(255,255,255,0.28) 70%, rgba(255,255,255,0.08) 100%),
    var(--tone);
  color: var(--icon);
  cursor: pointer;
  z-index: 3;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.35) inset,
    0 0 0 8px var(--tone-soft),
    0 18px 44px rgba(0, 0, 0, 0.55),
    0 2px 6px rgba(0, 0, 0, 0.4);
  transition:
    transform 140ms cubic-bezier(0.3, 0.9, 0.4, 1.2),
    box-shadow 200ms ease,
    background-color 220ms ease,
    filter 220ms ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Halo animado atrás do botão — respiração no idle, pulso rápido no rec, giro
   no thinking. Fica sob o "rosto" do botão via z-index. */
.speak-halo {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
  background:
    conic-gradient(from 0deg, transparent 0deg, var(--tone-strong) 60deg, transparent 180deg, var(--tone-strong) 240deg, transparent 360deg);
  mask: radial-gradient(circle, transparent 58%, #000 62%, #000 100%);
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 62%, #000 100%);
  animation: halo-breathe 3.6s ease-in-out infinite;
}

/* "Face" do botão: disco escuro central onde vive o ícone/onda/eq. */
.speak-face {
  position: absolute;
  left: 50%; top: 50%;
  width: var(--face-size);
  height: var(--face-size);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--face-bg);
  overflow: hidden;
  z-index: 1;
  box-shadow: 0 6px 14px rgba(0,0,0,0.5) inset;
  display: grid;
  place-items: center;
}

.speak-icon {
  position: absolute;
  width: 42%;
  height: 42%;
  color: var(--icon);
  opacity: 1;
  transition: opacity 180ms ease, transform 180ms ease;
  will-change: transform, opacity;
}

.speak-wave {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}

.speak-eq {
  position: absolute;
  display: flex;
  gap: 4px;
  align-items: center;
  height: 46%;
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
}
.speak-eq span {
  display: block;
  width: 5px;
  border-radius: 3px;
  background: currentColor;
  height: 30%;
  animation: eq-bounce 900ms ease-in-out infinite;
}
.speak-eq span:nth-child(1) { animation-delay: -.1s;  height: 45%; }
.speak-eq span:nth-child(2) { animation-delay: -.35s; height: 75%; }
.speak-eq span:nth-child(3) { animation-delay: -.55s; height: 100%; }
.speak-eq span:nth-child(4) { animation-delay: -.25s; height: 70%; }
.speak-eq span:nth-child(5) { animation-delay: -.15s; height: 40%; }

/* ---- estados ---- */

#speak:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

/* press: afunda um toque, halo aperta. Sem depender do :active pra funcionar
   também em pointer-lock e no keyboard-space. */
#speak:not(:disabled):active,
#speak[data-pressed="1"] {
  transform: translateX(-50%) scale(0.94);
}

/* IDLE — convite discreto: mic à mostra, halo respira devagar. */
#speak[data-state="idle"] .speak-icon-mic { opacity: 1; }
#speak[data-state="idle"] .speak-halo { animation: halo-breathe 3.6s ease-in-out infinite; }

/* RECORDING — vermelho quente, waveform ao vivo, halo pulsa rápido.
   Aqui vive a promessa central: onda mexe = mic captando; onda parada = bug
   visível sem precisar de dev tools. */
#speak[data-state="recording"] {
  --tone: #ff5a5f;
  --tone-soft: rgba(255, 90, 95, 0.22);
  --tone-strong: rgba(255, 120, 125, 0.45);
  --icon: #ffe6e7;
  background:
    radial-gradient(circle at 32% 30%, rgba(255,255,255,0.55), rgba(255,140,140,0.45) 45%, rgba(220,60,65,0.4) 70%, rgba(160,20,25,0.35) 100%),
    var(--tone);
}
#speak[data-state="recording"] .speak-icon-mic { opacity: 0; }
#speak[data-state="recording"] .speak-wave { opacity: 1; }
#speak[data-state="recording"] .speak-halo {
  animation: halo-pulse 1.05s ease-in-out infinite;
  opacity: 1;
}

/* THINKING — arco girando (spinner desenhado), face segura o silêncio. */
#speak[data-state="thinking"] {
  --tone: #cfd6df;
  --tone-soft: rgba(207, 214, 223, 0.16);
  --tone-strong: rgba(207, 214, 223, 0.42);
  --icon: rgba(245, 245, 245, 0.55);
}
#speak[data-state="thinking"] .speak-icon-mic {
  opacity: 0.35;
  transform: scale(0.85);
}
#speak[data-state="thinking"] .speak-halo {
  animation: halo-spin 1.2s linear infinite;
  background: conic-gradient(from 0deg,
    transparent 0deg,
    rgba(255,255,255,0.15) 20deg,
    rgba(255,255,255,0.85) 55deg,
    rgba(255,255,255,0.15) 90deg,
    transparent 120deg);
  opacity: 1;
}

/* SPEAKING — âmbar quente, ESTÁTICO. Animação de som no botão é reservada
   pro som da PESSOA (waveform da gravação) — decisão do founder 2026-07-29:
   quem fala é ela na cena; o botão só sinaliza "agora não é hora de gravar"
   com o tint, sem balançar. */
#speak[data-state="speaking"] {
  --tone: #ffcf7a;
  --tone-soft: rgba(255, 207, 122, 0.28);
  --tone-strong: rgba(255, 207, 122, 0.5);
  --icon: #1a1200;
  background:
    radial-gradient(circle at 32% 30%, rgba(255,245,220,0.7), rgba(255,207,122,0.55) 50%, rgba(210,140,40,0.35) 100%),
    var(--tone);
}
#speak[data-state="speaking"] .speak-face { background: rgba(30, 18, 4, 0.9); }
#speak[data-state="speaking"] .speak-icon-mic { opacity: 0.55; }
#speak[data-state="speaking"] .speak-eq { opacity: 0; }
#speak[data-state="speaking"] .speak-eq span { animation: none; }
#speak[data-state="speaking"] .speak-halo { animation: none; opacity: 0.5; }

/* ERRO — shake curto + tint vermelho, sem texto. */
#speak[data-error="1"] {
  animation: speak-shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes halo-breathe {
  0%, 100% { transform: scale(1);    opacity: 0.55; }
  50%      { transform: scale(1.05); opacity: 0.9;  }
}
@keyframes halo-pulse {
  0%, 100% { transform: scale(1);    opacity: 0.7; }
  50%      { transform: scale(1.09); opacity: 1;   }
}
@keyframes halo-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes eq-bounce {
  0%, 100% { transform: scaleY(0.5); }
  50%      { transform: scaleY(1);   }
}
@keyframes speak-shake {
  10%, 90% { transform: translateX(calc(-50% - 2px)); }
  20%, 80% { transform: translateX(calc(-50% + 3px)); }
  30%, 50%, 70% { transform: translateX(calc(-50% - 5px)); }
  40%, 60% { transform: translateX(calc(-50% + 5px)); }
}

@media (prefers-reduced-motion: reduce) {
  .speak-halo, .speak-eq span { animation: none !important; }
  #speak { transition: background-color 200ms ease, transform 120ms ease; }
}

#status {
  position: absolute;
  bottom: calc(env(safe-area-inset-bottom, 0) + 180px);
  left: 20px; right: 20px;
  text-align: center;
  font-size: 14px;
  color: rgba(245, 245, 245, 0.7);
  min-height: 20px;
  pointer-events: none;
  z-index: 2;
}
