/* ====================================================================
  Dulset — Premium Design System
   Dark glassmorphism theme with vibrant gradients
   ==================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Core palette */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-card: rgba(26, 26, 46, 0.6);
  --bg-glass: rgba(255, 255, 255, 0.03);
  --bg-glass-hover: rgba(255, 255, 255, 0.06);

  /* Accent gradients */
  --gradient-primary: linear-gradient(135deg, #6366f1, #8b5cf6, #a855f7);
  --gradient-accent: linear-gradient(135deg, #06b6d4, #3b82f6, #8b5cf6);
  --gradient-success: linear-gradient(135deg, #10b981, #34d399);
  --gradient-danger: linear-gradient(135deg, #ef4444, #f97316);
  --gradient-warm: linear-gradient(135deg, #f59e0b, #ef4444);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-accent: #a78bfa;

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(139, 92, 246, 0.3);

  /* Shadows */
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(139, 92, 246, 0.15);
  --shadow-glow-active: 0 0 60px rgba(139, 92, 246, 0.3);

  /* Transitions */
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Animated background mesh */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(6, 182, 212, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ---------- Layout ---------- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 24px 80px;
}

/* ---------- Header ---------- */
.app-header {
  text-align: center;
  margin-bottom: 48px;
}

.app-logo {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.app-logo-icon {
  width: 48px;
  height: 48px;
  background: var(--gradient-primary);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 8px 32px rgba(99, 102, 241, 0.3);
}

.app-title {
  font-size: 2rem;
  font-weight: 800;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.app-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 400;
  max-width: 500px;
  margin: 0 auto;
}

/* ---------- Glass Card ---------- */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 32px;
  margin-bottom: 24px;
  transition: all 0.3s var(--ease-smooth);
}

.glass-card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-glow);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.card-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.card-icon.mic { background: rgba(99, 102, 241, 0.15); }
.card-icon.answer { background: rgba(16, 185, 129, 0.15); }
.card-icon.chunks { background: rgba(6, 182, 212, 0.15); }
.card-icon.timing { background: rgba(245, 158, 11, 0.15); }

.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------- Language Toggle ---------- */
.language-toggle-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 32px;
}

.language-toggle {
  display: flex;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px;
  gap: 4px;
}

.lang-btn {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s var(--ease-smooth);
  display: flex;
  align-items: center;
  gap: 8px;
}

.lang-btn.active {
  background: var(--gradient-primary);
  color: white;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.lang-btn:hover:not(.active) {
  color: var(--text-primary);
  background: var(--bg-glass-hover);
}

.lang-flag {
  font-size: 1.1rem;
}

/* ---------- Mic Button ---------- */
.mic-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.mic-btn {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 3px solid rgba(99, 102, 241, 0.3);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s var(--ease-smooth);
  position: relative;
  z-index: 1;
}

.mic-btn:hover {
  border-color: rgba(99, 102, 241, 0.6);
  background: rgba(99, 102, 241, 0.1);
  transform: scale(1.05);
  box-shadow: var(--shadow-glow);
}

.mic-btn.recording {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
  animation: pulse-recording 1.5s ease-in-out infinite;
}

.mic-btn.recording::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(239, 68, 68, 0.2);
  animation: ripple 1.5s ease-out infinite;
}

.mic-btn.recording::after {
  content: '';
  position: absolute;
  inset: -16px;
  border-radius: 50%;
  border: 2px solid rgba(239, 68, 68, 0.1);
  animation: ripple 1.5s ease-out infinite 0.3s;
}

@keyframes pulse-recording {
  0%, 100% { transform: scale(1); box-shadow: 0 0 30px rgba(239, 68, 68, 0.2); }
  50% { transform: scale(1.05); box-shadow: 0 0 50px rgba(239, 68, 68, 0.35); }
}

@keyframes ripple {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.mic-status {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: center;
  min-height: 22px;
}

.mic-status.recording-text {
  color: #f87171;
}

/* Waveform visualization */
.waveform-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 40px;
  opacity: 0;
  transition: opacity 0.3s;
}

.waveform-container.active {
  opacity: 1;
}

.wave-bar {
  width: 4px;
  height: 8px;
  background: var(--gradient-primary);
  border-radius: 4px;
  transition: height 0.1s;
}

.waveform-container.active .wave-bar {
  animation: wave-anim 0.6s ease-in-out infinite alternate;
}

.wave-bar:nth-child(1) { animation-delay: 0s; }
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; }
.wave-bar:nth-child(6) { animation-delay: 0.3s; }
.wave-bar:nth-child(7) { animation-delay: 0.2s; }
.wave-bar:nth-child(8) { animation-delay: 0.1s; }
.wave-bar:nth-child(9) { animation-delay: 0s; }

@keyframes wave-anim {
  0% { height: 6px; }
  100% { height: 32px; }
}

/* ---------- Transcript ---------- */
.transcript-area {
  min-height: 56px;
  padding: 16px 20px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  font-size: 1rem;
  color: var(--text-primary);
  line-height: 1.7;
  margin-top: 8px;
  transition: border-color 0.3s;
  word-break: break-word;
}

.transcript-area.has-text {
  border-color: rgba(99, 102, 241, 0.3);
}

.transcript-placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.transcript-interim {
  color: var(--text-secondary);
  opacity: 0.7;
}

/* ---------- Text Input ---------- */
.text-input-wrap {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.text-input {
  flex: 1;
  padding: 14px 20px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.text-input:focus {
  border-color: rgba(99, 102, 241, 0.5);
  box-shadow: 0 0 20px rgba(99, 102, 241, 0.1);
}

.text-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  padding: 14px 28px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-lg);
  color: white;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s var(--ease-smooth);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.send-btn:active {
  transform: translateY(0);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.or-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* ---------- Answer Section ---------- */
.answer-section {
  display: none;
}

.answer-section.visible {
  display: block;
  animation: fadeSlideIn 0.5s var(--ease-smooth);
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.answer-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.answer-status.answered {
  background: rgba(16, 185, 129, 0.12);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.answer-status.refused_unsafe,
.answer-status.refused_off_topic,
.answer-status.refused_ungrounded {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.answer-status.error {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.answer-text {
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text-primary);
  padding: 20px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

/* Typing cursor animation */
.typing-cursor {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--text-accent);
  margin-left: 2px;
  animation: blink 0.8s ease-in-out infinite;
  vertical-align: text-bottom;
}

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

/* ---------- Retrieved Chunks ---------- */
.chunks-section {
  display: none;
}

.chunks-section.visible {
  display: block;
  animation: fadeSlideIn 0.5s var(--ease-smooth) 0.1s both;
}

.chunk-item {
  padding: 16px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  transition: border-color 0.3s;
}

.chunk-item:hover {
  border-color: rgba(6, 182, 212, 0.3);
}

.chunk-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.chunk-badge {
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chunk-badge.strategy {
  background: rgba(99, 102, 241, 0.12);
  color: #a78bfa;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.chunk-badge.score {
  background: rgba(6, 182, 212, 0.12);
  color: #67e8f9;
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.chunk-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ---------- Timings & Guardrails ---------- */
.timing-section {
  display: none;
}

.timing-section.visible {
  display: block;
  animation: fadeSlideIn 0.5s var(--ease-smooth) 0.2s both;
}

.timing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.timing-item {
  padding: 14px 16px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.timing-stage {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.timing-value {
  font-size: 1.2rem;
  font-weight: 700;
  background: var(--gradient-accent);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.timing-ok {
  font-size: 0.75rem;
  color: #34d399;
}

.timing-fail {
  font-size: 0.75rem;
  color: #f87171;
}

/* Guardrail verdicts */
.guardrail-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.guardrail-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 500;
}

.guardrail-badge.passed {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.guardrail-badge.failed {
  background: rgba(239, 68, 68, 0.1);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ---------- Loading State ---------- */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 15, 0.7);
  backdrop-filter: blur(8px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.loading-overlay.visible {
  display: flex;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.spinner-ring {
  width: 56px;
  height: 56px;
  border: 3px solid var(--border-subtle);
  border-top: 3px solid #8b5cf6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ---------- Error Toast ---------- */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 14px 28px;
  background: rgba(239, 68, 68, 0.9);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  color: white;
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.4s var(--ease-smooth);
  z-index: 200;
  max-width: 90%;
  text-align: center;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.app-footer a {
  color: var(--text-accent);
  text-decoration: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app-container {
    padding: 24px 16px 60px;
  }

  .app-title {
    font-size: 1.5rem;
  }

  .glass-card {
    padding: 20px;
    border-radius: var(--radius-lg);
  }

  .text-input-wrap {
    flex-direction: column;
  }

  .send-btn {
    justify-content: center;
  }

  .timing-grid {
    grid-template-columns: 1fr;
  }

  .mic-btn {
    width: 72px;
    height: 72px;
    font-size: 28px;
  }
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ---------- Browser support warning ---------- */
.browser-warning {
  display: none;
  padding: 16px 20px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.2);
  border-radius: var(--radius-md);
  color: #fbbf24;
  font-size: 0.9rem;
  margin-bottom: 16px;
  text-align: center;
}

.browser-warning.visible {
  display: block;
}

/* ====================================================================
   Top Controls Bar & Settings Button
   ==================================================================== */
.top-controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-accent);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.2);
}

.settings-icon {
  font-size: 1rem;
}

/* ====================================================================
   Speak Answer Toolbar (inside Answer Card)
   ==================================================================== */
.answer-actions-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.tts-button-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 18px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-full);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s var(--ease-smooth);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.speak-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
}

.speak-btn:active {
  transform: translateY(0);
}

.speak-btn.loading {
  opacity: 0.8;
  cursor: wait;
}

.speak-btn.playing {
  background: linear-gradient(135deg, #10b981, #06b6d4);
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
}

.stop-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-full);
  color: #fca5a5;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
}

.stop-btn:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.5);
  color: #ffffff;
}

/* TTS Playing Indicator & Mini Waveform */
.tts-playing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  border-radius: var(--radius-full);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse-glow 1.5s infinite;
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); opacity: 0.8; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
  50% { transform: scale(1.2); opacity: 1; box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

.playing-label {
  font-size: 0.8rem;
  color: #34d399;
  font-weight: 500;
}

.mini-waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 16px;
}

.mini-bar {
  width: 3px;
  background: #34d399;
  border-radius: 2px;
  animation: mini-wave 0.8s ease-in-out infinite alternate;
}

.mini-bar:nth-child(1) { height: 6px; animation-delay: 0.1s; }
.mini-bar:nth-child(2) { height: 14px; animation-delay: 0.3s; }
.mini-bar:nth-child(3) { height: 10px; animation-delay: 0.2s; }
.mini-bar:nth-child(4) { height: 16px; animation-delay: 0.4s; }

@keyframes mini-wave {
  0% { height: 4px; }
  100% { height: 16px; }
}

/* Auto-speak toggle & Voice Badge */
.tts-options-group {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-left: auto;
}

.auto-speak-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.auto-speak-checkbox {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  transition: all 0.25s var(--ease-smooth);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-radius: 50%;
  transition: all 0.25s var(--ease-bounce);
}

.auto-speak-checkbox:checked + .toggle-slider {
  background: var(--gradient-primary);
  border-color: rgba(139, 92, 246, 0.5);
}

.auto-speak-checkbox:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.voice-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: var(--radius-sm);
  color: var(--text-accent);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.voice-badge:hover {
  background: rgba(139, 92, 246, 0.22);
  border-color: rgba(139, 92, 246, 0.5);
}

/* ====================================================================
   Voice Settings Modal
   ==================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 10, 15, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease-smooth);
}

.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 90%;
  max-width: 520px;
  background: rgba(22, 22, 38, 0.95);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.7), 0 0 50px rgba(139, 92, 246, 0.15);
  padding: 28px;
  transform: translateY(20px) scale(0.96);
  transition: transform 0.25s var(--ease-bounce);
}

.modal-backdrop.open .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-icon {
  font-size: 1.3rem;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s ease;
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.setting-hint code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-accent);
}

.custom-select, .custom-input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: all 0.2s var(--ease-smooth);
}

.custom-select {
  cursor: pointer;
}

.custom-select option {
  background: #181829;
  color: var(--text-primary);
}

.custom-select:focus, .custom-input:focus {
  border-color: var(--border-accent);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15);
}

.key-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.key-input-wrap .custom-input {
  padding-right: 42px;
}

.toggle-vis-btn {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.modal-btn {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-smooth);
  border: none;
}

.modal-btn.primary {
  background: var(--gradient-primary);
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.modal-btn.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.modal-btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.modal-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

