/* Emotion Aware — voice-first / assistant UI */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #07080c;
  --surface: rgba(18, 20, 28, 0.92);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f4f4f8;
  --muted: #8b8c9a;
  --accent: #a78bfa;
  --accent2: #6366f1;
  --glow: rgba(167, 139, 250, 0.35);
  --success: #34d399;
  --warning: #fbbf24;
  --error: #f87171;
  --radius: 16px;
}

html, body {
  height: 100%;
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% -20%, rgba(99, 102, 241, 0.22), transparent),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(167, 139, 250, 0.12), transparent);
  pointer-events: none;
  z-index: 0;
}

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

#app {
  display: flex;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ── Settings toggle & sidebar ── */
.settings-toggle {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 40;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(12px);
}
.settings-toggle:hover { border-color: var(--accent); }

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(300px, 88vw);
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(20px);
  padding: 72px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  transform: translateX(-100%);
  transition: transform 0.28s ease;
  z-index: 30;
  overflow-y: auto;
}
#sidebar.open { transform: translateX(0); }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 25;
  border: 0;
  cursor: pointer;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 20px var(--glow);
}
.logo-text {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.sidebar-section { display: flex; flex-direction: column; gap: 8px; }
.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.sidebar-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  margin: -4px 0 2px;
}
.muted-block p {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.select-control {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font-size: 14px;
}

.gender-toggle { display: flex; gap: 8px; }
.gender-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.2);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.gender-btn.active {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border-color: transparent;
  color: #fff;
}

#connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 10px 14px;
  background: rgba(0,0,0,0.2);
  border-radius: 999px;
  border: 1px solid var(--border);
}
#status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
#status-dot.connected { background: var(--success); box-shadow: 0 0 10px var(--success); }
#status-dot.connecting { background: var(--warning); animation: pulse 1.2s infinite; }
#status-dot.error { background: var(--error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ── Main voice stage ── */
.voice-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 56px 20px 12px;
  align-items: center;
  justify-content: space-between;
}

.sound-hint {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 320px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  z-index: 20;
  line-height: 1.4;
}
.sound-hint.hidden { display: none; }

.stage-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 560px;
  text-align: center;
  gap: 1.25rem;
}

#pulse-wrap { position: relative; width: min(200px, 45vw); aspect-ratio: 1; }
.pulse-orb {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.25), transparent 50%),
    linear-gradient(145deg, var(--accent2), #4c1d95);
  box-shadow: 0 0 60px var(--glow), inset 0 0 40px rgba(255,255,255,0.15);
  transition: transform 0.4s ease, filter 0.4s ease;
}
.pulse-orb.state-ready { transform: scale(1); filter: brightness(1); animation: breathe 4s ease-in-out infinite; }
.pulse-orb.state-listening { transform: scale(1.05); animation: breathe 2s ease-in-out infinite; }
.pulse-orb.state-processing { transform: scale(0.96); animation: spin-glow 2.2s linear infinite; }
.pulse-orb.state-speaking { transform: scale(1.08); animation: speak-pulse 0.6s ease-in-out infinite; }

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 50px var(--glow); }
  50% { box-shadow: 0 0 80px rgba(167, 139, 250, 0.5); }
}
@keyframes spin-glow {
  from { filter: hue-rotate(0deg) brightness(1.1); }
  to { filter: hue-rotate(360deg) brightness(1.1); }
}
@keyframes speak-pulse {
  0%, 100% { transform: scale(1.06); }
  50% { transform: scale(1.12); }
}

.stage-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.user-echo {
  font-size: 14px;
  color: var(--muted);
  max-width: 100%;
  line-height: 1.5;
}
.user-echo::before { content: 'You · '; opacity: 0.6; }

#live-caption-wrap { width: 100%; min-height: 4.5rem; }
.live-caption {
  font-size: clamp(1.05rem, 3.8vw, 1.35rem);
  font-weight: 500;
  line-height: 1.55;
  color: var(--text);
}
.live-caption.streaming::after {
  content: '▍';
  display: inline-block;
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

.emotion-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(167, 139, 250, 0.15);
  border: 1px solid rgba(167, 139, 250, 0.35);
  color: var(--accent);
}
.emotion-pill.hidden { display: none; }

.thinking-inline {
  display: flex;
  gap: 6px;
  justify-content: center;
}
.thinking-inline span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: dot 1.2s infinite ease-in-out;
}
.thinking-inline span:nth-child(2) { animation-delay: 0.15s; }
.thinking-inline span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 80%, 100% { transform: scale(0.85); opacity: 0.25; }
  40% { transform: scale(1.15); opacity: 1; }
}
.thinking-inline.hidden { display: none; }

.media-strip {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: rgba(0,0,0,0.25);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.media-strip.hidden { display: none; }

.main-play-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.main-play-btn:disabled { opacity: 0.4; cursor: default; }

.waveform-bars {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 36px;
}
.waveform-bars .bar {
  width: 5px;
  height: 10px;
  border-radius: 3px;
  background: var(--muted);
  opacity: 0.45;
  transition: height 0.12s ease, opacity 0.12s ease;
}
.waveform-bars.playing .bar {
  animation: bar-dance 0.5s ease-in-out infinite;
  opacity: 1;
  background: var(--accent);
}
.waveform-bars.playing .bar:nth-child(1) { animation-delay: 0s; }
.waveform-bars.playing .bar:nth-child(2) { animation-delay: 0.05s; }
.waveform-bars.playing .bar:nth-child(3) { animation-delay: 0.1s; }
.waveform-bars.playing .bar:nth-child(4) { animation-delay: 0.15s; }
.waveform-bars.playing .bar:nth-child(5) { animation-delay: 0.2s; }
.waveform-bars.playing .bar:nth-child(6) { animation-delay: 0.25s; }
.waveform-bars.playing .bar:nth-child(7) { animation-delay: 0.3s; }
@keyframes bar-dance {
  0%, 100% { height: 8px; }
  50% { height: 26px; }
}

.audio-progress {
  font-size: 12px;
  color: var(--muted);
  min-width: 3.5rem;
  text-align: right;
}

/* Voice bar */
.voice-state-bar {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 13px;
}
.voice-state-bar.hidden { display: none; }
.volume-track {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
}
.volume-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 2px;
  transition: width 0.08s linear;
}

.tts-status-line {
  font-size: 11px;
  color: var(--muted);
  min-height: 1em;
  text-align: center;
}

/* Input dock */
.input-dock {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.dock-mic, .dock-send {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text);
}
.dock-mic.always-on {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.3), rgba(52, 211, 153, 0.15));
  border-color: rgba(52, 211, 153, 0.45);
}
.dock-send {
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  border: none;
  font-weight: 700;
}
.dock-send:disabled { opacity: 0.45; cursor: not-allowed; }

#msg-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.45;
  padding: 12px 4px;
  outline: none;
}
#msg-input::placeholder { color: var(--muted); }
#msg-input:disabled { opacity: 0.5; }

.dock-hint {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
  max-width: 520px;
}

/* Mic states from JS */
.mic-toggle.user-speaking { filter: brightness(1.2); }
.mic-toggle.ai-speaking { animation: none; }
