/* Noah Presence Layer — UX-04.3 micro continuidade natural */

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

:root {
  --bg-deep: #0b1020;
  --bg-mid: #111827;
  --bg-soft: #1a2238;
  --light-soft: #dbe4ff;
  --light-mid: #9fb4ff;
  --light-core: #7c93ff;
  --aura-1: rgba(124, 147, 255, 0.03);
  --aura-2: rgba(124, 147, 255, 0.055);
  --aura-3: rgba(124, 147, 255, 0.095);
  --breath: 7s;
  --text-memory: rgba(219, 228, 255, 0.78);
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body.scene {
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--light-soft);
  background: radial-gradient(
      ellipse 120% 80% at 50% 45%,
      var(--bg-soft) 0%,
      var(--bg-deep) 55%,
      #070a14 100%
    ),
    var(--bg-deep);
}

.breath-field {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(
      ellipse 90% 70% at 48% 42%,
      rgba(124, 147, 255, 0.07) 0%,
      transparent 52%
    ),
    radial-gradient(
      ellipse 70% 55% at 58% 58%,
      rgba(17, 24, 39, 0.85) 0%,
      transparent 50%
    ),
    linear-gradient(165deg, var(--bg-deep) 0%, var(--bg-mid) 45%, var(--bg-soft) 100%);
  animation: field-breathe var(--breath) ease-in-out infinite;
}

@keyframes field-breathe {
  0%,
  100% {
    opacity: 0.92;
    filter: saturate(1) brightness(0.97);
  }
  50% {
    opacity: 1;
    filter: saturate(1.06) brightness(1.03);
  }
}

.presence {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: clamp(1.5rem, 5vw, 3rem);
}

.nucleus {
  position: relative;
  width: clamp(7rem, 22vw, 9.5rem);
  height: clamp(7rem, 22vw, 9.5rem);
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.nucleus:focus-visible {
  outline: 1px solid rgba(159, 180, 255, 0.28);
  outline-offset: 12px;
}

.nucleus::before,
.nucleus::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid transparent;
  pointer-events: none;
  opacity: 0;
}

.aura {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
  transition: transform 0.35s ease, opacity 0.35s ease;
}

.aura--outer {
  inset: -38%;
  background: radial-gradient(
    circle,
    var(--aura-1) 0%,
    transparent 68%
  );
  animation: aura-pulse var(--breath) ease-in-out infinite;
  animation-delay: 0s;
}

.aura--mid {
  inset: -22%;
  background: radial-gradient(
    circle,
    var(--aura-2) 0%,
    transparent 70%
  );
  animation: aura-pulse var(--breath) ease-in-out infinite;
  animation-delay: -2.3s;
}

.aura--inner {
  inset: -10%;
  background: radial-gradient(
    circle,
    var(--aura-3) 0%,
    transparent 72%
  );
  animation: aura-pulse var(--breath) ease-in-out infinite;
  animation-delay: -4.6s;
}

@keyframes aura-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.55;
  }
  50% {
    transform: scale(1.045);
    opacity: 0.85;
  }
}

.core {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 35%,
    rgba(219, 228, 255, 0.22) 0%,
    rgba(124, 147, 255, 0.14) 42%,
    rgba(26, 34, 56, 0.55) 100%
  );
  box-shadow:
    0 0 28px rgba(124, 147, 255, 0.12),
    inset 0 0 24px rgba(11, 16, 32, 0.65);
  animation: core-breathe var(--breath) ease-in-out infinite;
  transition:
    transform 0.22s ease,
    box-shadow 0.28s ease,
    filter 0.28s ease,
    opacity 0.35s ease;
}

@keyframes core-breathe {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 28px rgba(124, 147, 255, 0.12),
      inset 0 0 24px rgba(11, 16, 32, 0.65);
  }
  50% {
    transform: scale(1.028);
    box-shadow:
      0 0 36px rgba(124, 147, 255, 0.16),
      inset 0 0 22px rgba(11, 16, 32, 0.58);
  }
}

/* Escuta: atenção imediata (<~60ms perceptivos — sem esperar STT) */
.scene[data-state="listening"] {
  --breath: 4.9s;
}

.scene[data-state="listening"] .aura {
  transition: transform 0.05s ease-out, opacity 0.05s ease-out;
}

.scene[data-state="listening"] .aura--inner {
  opacity: 0.99;
}

.scene[data-state="listening"] .aura--mid {
  opacity: 0.96;
}

.scene[data-state="listening"] .aura--outer {
  opacity: 0.96;
}

/* Pulsação ativa do core durante escuta */
.scene[data-state="listening"] .core {
  animation: core-listening 1.9s ease-in-out infinite;
  transition:
    box-shadow 0.045s ease-out,
    filter 0.045s ease-out,
    opacity 0.055s ease-out;
}

/* Anéis de ripple expandindo a partir da orb */
.scene[data-state="listening"] .nucleus::before {
  animation: listening-ring 2.1s ease-out infinite;
}

.scene[data-state="listening"] .nucleus::after {
  animation: listening-ring 2.1s ease-out infinite 1.05s;
}

@keyframes listening-ring {
  0% {
    transform: scale(0.92);
    border-color: rgba(124, 147, 255, 0.52);
    opacity: 1;
  }
  55% {
    opacity: 0.14;
  }
  100% {
    transform: scale(1.72);
    border-color: rgba(124, 147, 255, 0);
    opacity: 0;
  }
}

@keyframes core-listening {
  0%, 100% {
    filter: brightness(1.06);
    box-shadow:
      0 0 44px rgba(124, 147, 255, 0.22),
      inset 0 0 17px rgba(11, 16, 32, 0.51);
  }
  50% {
    filter: brightness(1.20);
    box-shadow:
      0 0 70px rgba(124, 147, 255, 0.42),
      0 0 28px rgba(159, 180, 255, 0.16),
      inset 0 0 10px rgba(11, 16, 32, 0.37);
  }
}

.scene[data-state="listening"] .breath-field {
  transition: opacity 0.08s ease-out;
  opacity: 0.96;
}

.scene[data-state="listening"] .listen-whisper.is-visible {
  transition: opacity 0.12s ease-out;
}

/* Feedback breve após STT final — sem parecer "processando" */
.scene.stt-captured .core {
  filter: brightness(1.06);
  box-shadow:
    0 0 34px rgba(124, 147, 255, 0.15),
    inset 0 0 23px rgba(11, 16, 32, 0.61);
}

/* Thinking: contemplação curta, presença ativa — não loading */
.scene[data-state="thinking"] {
  --breath: 6.6s;
}

.scene[data-state="thinking"] .breath-field {
  opacity: 0.88;
}

.scene[data-state="thinking"] .core {
  animation: thinking-inner 8.2s ease-in-out infinite;
  transform-origin: center center;
}

.scene[data-state="thinking"] .aura--outer {
  opacity: 0.9;
}

@keyframes thinking-inner {
  0%,
  100% {
    transform: scale(1.04);
    filter: brightness(0.93);
    opacity: 1;
    box-shadow:
      0 0 26px rgba(124, 147, 255, 0.09),
      inset 0 0 30px rgba(11, 16, 32, 0.76);
  }
  50% {
    transform: scale(1.07);
    filter: brightness(0.97);
    opacity: 0.94;
    box-shadow:
      0 0 30px rgba(124, 147, 255, 0.11),
      inset 0 0 26px rgba(11, 16, 32, 0.7);
  }
}

/* Speaking: estável, calmo, sem "aceso" */
.scene[data-state="speaking"] .core {
  filter: brightness(0.98);
  box-shadow:
    0 0 24px rgba(124, 147, 255, 0.09),
    inset 0 0 27px rgba(11, 16, 32, 0.63);
  animation-duration: calc(var(--breath) * 1.04);
}

.scene[data-state="speaking"] .aura--outer {
  opacity: 0.87;
}

.scene[data-state="speaking"].post-speech-silence .core {
  box-shadow:
    0 0 18px rgba(124, 147, 255, 0.055),
    inset 0 0 30px rgba(11, 16, 32, 0.69);
}

.scene[data-state="speaking"].post-speech-silence .breath-field {
  opacity: 0.89;
}

.scene[data-state="open"] .aura--outer,
.scene[data-state="listening"] .aura--outer,
.scene[data-state="thinking"] .aura--outer,
.scene[data-state="speaking"] .aura--outer {
  opacity: 1;
}

.dialog {
  width: min(28rem, 88vw);
  margin-top: clamp(2.5rem, 8vh, 4rem);
  text-align: center;
}

.dialog[hidden] {
  display: none !important;
}

/* Sussurro de escuta — não parece painel técnico */
.listen-whisper {
  margin: 0 0 0.65rem;
  min-height: 1.2em;
  font-size: clamp(0.72rem, 1.85vw, 0.8rem);
  font-style: italic;
  letter-spacing: 0.12em;
  text-transform: lowercase;
  color: rgba(159, 180, 255, 0.38);
  opacity: 0;
  transition: opacity 0.7s ease;
}

.listen-whisper.is-visible {
  opacity: 1;
}

/* Transcrição fantasma — presença de escuta (throttle no JS) */
.line--ghost {
  margin: 0 0 0.75rem;
  min-height: 1.15em;
  font-size: clamp(0.8rem, 2vw, 0.9rem);
  font-style: italic;
  font-weight: normal;
  letter-spacing: 0.05em;
  line-height: 1.48;
  color: rgba(219, 228, 255, 0.55);
  opacity: 0;
  transition: opacity 0.62s ease;
  pointer-events: none;
}

.line--ghost.is-visible {
  opacity: 0.3;
}

.line {
  margin: 0;
  min-height: 1.35em;
  font-size: clamp(0.88rem, 2.35vw, 0.98rem);
  font-weight: normal;
  letter-spacing: 0.03em;
  line-height: 1.55;
  color: var(--text-memory);
  opacity: 0;
  transition: opacity 0.85s ease;
}

.line--user {
  margin-bottom: 1rem;
  color: rgba(159, 180, 255, 0.58);
}

.line--user.is-visible {
  opacity: 0.72;
}

/* PRESENCE-01: a voz conduz — o texto é legenda discreta, não protagonista. */
.line--noah {
  margin-bottom: 1.5rem;
  font-size: clamp(0.78rem, 1.95vw, 0.88rem);
  color: rgba(219, 228, 255, 0.7);
}

.line--noah.is-visible {
  opacity: 0.6;
}

.proximity-form {
  margin: 0;
}

.proximity-form input {
  width: 100%;
  padding: 0.55rem 0.35rem;
  border: none;
  border-bottom: 1px solid rgba(159, 180, 255, 0.14);
  background: transparent;
  color: rgba(219, 228, 255, 0.55);
  font-family: inherit;
  font-size: clamp(0.82rem, 2.1vw, 0.92rem);
  text-align: center;
  caret-color: var(--light-mid);
}

.proximity-form input:focus {
  outline: none;
  border-bottom-color: rgba(159, 180, 255, 0.28);
  color: rgba(219, 228, 255, 0.72);
}

.proximity-form input::placeholder {
  color: transparent;
}

.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;
}

@media (prefers-reduced-motion: reduce) {
  .breath-field,
  .aura,
  .core {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .aura,
  .core,
  .line,
  .line--ghost,
  .listen-whisper {
    transition: none;
  }

  .scene[data-state="thinking"] .core,
  .scene[data-state="listening"] .core {
    animation: none !important;
  }

  .scene[data-state="listening"] .nucleus::before,
  .scene[data-state="listening"] .nucleus::after {
    animation: none !important;
    opacity: 0;
  }

  .scene.stt-captured .core {
    transform: none;
  }
}
