/* ===== VOICE MODE (upgraded) ===== */
.voice-mode-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: #000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 40px 24px;
  padding-top: calc(40px + env(safe-area-inset-top));
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
  font-family: 'DM Sans', system-ui, sans-serif;
}
.voice-mode-overlay.visible { display: flex; }

.voice-close-btn {
  position: absolute; top: calc(20px + env(safe-area-inset-top)); right: 20px;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.08);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .2s;
}
.voice-close-btn:hover, .voice-close-btn:focus-visible { background: rgba(255,255,255,.16); }
.voice-close-btn:focus-visible { outline: 2px solid rgba(255,255,255,.6); outline-offset: 2px; }
.voice-close-btn svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; }

/* NEW: connection status pill, top-left */
.voice-status-pill {
  position: absolute; top: calc(20px + env(safe-area-inset-top)); left: 20px;
  display: flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 100px;
  background: rgba(255,255,255,.08);
  font-size: 11.5px; color: rgba(255,255,255,.6); letter-spacing: .3px;
}
.voice-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,.4);
  transition: background .3s;
}
.voice-mode-overlay[data-state="listening"] .voice-status-dot { background: #4285f4; }
.voice-mode-overlay[data-state="thinking"] .voice-status-dot { background: #ffd000; }
.voice-mode-overlay[data-state="speaking"] .voice-status-dot { background: #b100cd; }
.voice-mode-overlay[data-state="error"] .voice-status-dot { background: #ff5a5a; animation: none; }
.voice-mode-overlay[data-state="connecting"] .voice-status-dot { background: rgba(255,255,255,.4); animation: dotBlink 1s ease-in-out infinite; }
@keyframes dotBlink { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.voice-orb-wrap {
  position: relative;
  width: 200px; height: 200px;
  display: flex; align-items: center; justify-content: center;
}
.voice-nebula {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from var(--angle), #4285f4, #b100cd, #ff3d00, #ffd000, #4285f4);
  filter: blur(22px); opacity: .6; z-index: 0; pointer-events: none;
  animation: flowFade 3s ease-out forwards;
  /* NEW: scale reacts to live mic amplitude, set via --amp custom prop in JS */
  transform: scale(calc(1 + var(--amp, 0) * 0.18));
  transition: transform .08s linear;
}
.voice-nebula.active { animation: flowLoop 6s linear infinite; opacity: .6; }
.voice-mode-overlay[data-state="listening"] .voice-nebula.active { animation: flowLoop 3.2s linear infinite; opacity: .7; }
.voice-mode-overlay[data-state="thinking"] .voice-nebula.active { animation: flowLoop 1s linear infinite; opacity: .85; }
.voice-mode-overlay[data-state="speaking"] .voice-nebula.active { animation: flowLoop 2.2s linear infinite; opacity: .8; }
.voice-mode-overlay[data-state="error"] .voice-nebula.active { animation: none; opacity: .35; filter: blur(22px) grayscale(1); }

.voice-orb {
  width: 170px; height: 170px; border-radius: 50%;
  position: relative; z-index: 1;
  background: transparent;
  cursor: pointer;
  transition: transform .35s ease;
}
.voice-orb::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.16);
}
.voice-orb::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%; padding: 2px;
  background: conic-gradient(from var(--angle), rgba(255,255,255,0) 0%, rgba(255,255,255,.9) 50%, rgba(255,255,255,0) 100%);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: destination-out; mask-composite: exclude;
  animation: flowLoop 6s linear infinite; opacity: .55;
}
.voice-mode-overlay[data-state="listening"] .voice-orb::before { animation: flowLoop 3.2s linear infinite, voiceOrbPulse 1.7s ease-in-out infinite; opacity: 1; }
.voice-mode-overlay[data-state="thinking"] .voice-orb { transform: scale(.88); }
.voice-mode-overlay[data-state="thinking"] .voice-orb::before { animation: flowLoop 1s linear infinite; opacity: 1; }
.voice-mode-overlay[data-state="speaking"] .voice-orb::before { animation: flowLoop 2.2s linear infinite, voiceOrbPulse 0.85s ease-in-out infinite; opacity: 1; }
.voice-mode-overlay[data-state="error"] .voice-orb::before { animation: none; opacity: .3; }
/* NEW: live amplitude drives real orb scale, layered on top of state transforms */
.voice-mode-overlay[data-state="listening"] .voice-orb { transform: scale(calc(1 + var(--amp, 0) * 0.12)); }

/* NEW: reactive waveform bars beneath the orb */
.voice-waveform {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  height: 28px; opacity: 0; transition: opacity .3s;
}
.voice-mode-overlay[data-state="listening"] .voice-waveform,
.voice-mode-overlay[data-state="speaking"] .voice-waveform { opacity: 1; }
.voice-waveform span {
  display: block; width: 3px; border-radius: 2px;
  background: rgba(255,255,255,.55);
  height: 6px;
  transition: height .09s ease-out;
}

.voice-status { font-size: 13px; color: rgba(255,255,255,.5); letter-spacing: .4px; text-transform: uppercase; }
.voice-caption { max-width: 520px; text-align: center; min-height: 50px; font-size: 18px; color: #fff; line-height: 1.55; }
/* NEW: word-by-word reveal for captions */
.voice-caption .word { opacity: 0; animation: wordIn .35s ease forwards; }
@keyframes wordIn { to { opacity: 1; } }

.voice-controls { display: flex; align-items: center; gap: 14px; margin-top: 6px; }

/* NEW: mute toggle button */
.voice-mute-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .2s, border-color .2s;
}
.voice-mute-btn:hover, .voice-mute-btn:focus-visible { background: rgba(255,255,255,.12); }
.voice-mute-btn:focus-visible { outline: 2px solid rgba(255,255,255,.6); outline-offset: 2px; }
.voice-mute-btn.muted { background: rgba(255,90,90,.16); border-color: rgba(255,90,90,.3); }
.voice-mute-btn svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.voice-end-btn {
  padding: 13px 26px; border-radius: 100px; border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06); color: rgba(255,255,255,.85);
  font-family: 'DM Sans', system-ui, sans-serif; font-size: 13px;
  letter-spacing: .3px; cursor: pointer; transition: background .2s;
}
.voice-end-btn:hover, .voice-end-btn:focus-visible { background: rgba(255,90,90,.18); color: #fff; }
.voice-end-btn:focus-visible { outline: 2px solid rgba(255,255,255,.6); outline-offset: 2px; }

.voice-hint { position: absolute; bottom: calc(28px + env(safe-area-inset-bottom)); font-size: 11.5px; color: rgba(255,255,255,.3); }

/* NEW: error state banner */
.voice-error-banner {
  display: none;
  max-width: 420px; text-align: center;
  font-size: 13px; color: rgba(255,120,120,.9);
  padding: 10px 16px; border-radius: 10px;
  background: rgba(255,90,90,.08); border: 1px solid rgba(255,90,90,.2);
}
.voice-mode-overlay[data-state="error"] .voice-error-banner { display: block; }

@keyframes flowLoop { to { --angle: 360deg; } }
@keyframes flowFade { from { opacity: 0; } to { opacity: .6; } }
@keyframes voiceOrbPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@property --angle { syntax: '<angle>'; inherits: false; initial-value: 0deg; }

/* NEW: respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .voice-nebula, .voice-orb::before, .voice-nebula.active { animation: none !important; }
  .voice-caption .word { animation: none; opacity: 1; }
}
