/* ==========================================================================
   Tamil to English Live Speech Translator - Premium Light Design System
   Clean, Crisp, Modern & Mobile Standalone Ergonomics
   ========================================================================== */

:root {
  /* Crisp Modern Light Palette */
  --bg-main: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.92);
  --bg-card-hover: #ffffff;

  --border: #e2e8f0;
  --border-focus: rgba(16, 185, 129, 0.5);

  --primary: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --primary-dark: #047857;

  --accent-gold: #d97706;
  --accent-cyan: #0284c7;
  --accent-indigo: #4f46e5;
  --destructive: #dc2626;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.06), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 8px 24px rgba(16, 185, 129, 0.25);

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-tamil: 'Noto Sans Tamil', 'Plus Jakarta Sans', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* Reset & Mobile Viewport */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  color-scheme: light;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

/* Soft Ambient Background Orbs */
.app-background {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(140px);
  opacity: 0.55;
  animation: floatOrb 18s ease-in-out infinite alternate;
}

.orb-1 {
  top: -120px;
  left: 10%;
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, #a7f3d0, #bae6fd);
}

.orb-2 {
  bottom: -150px;
  right: 5%;
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, #e0e7ff, #fbcfe8);
  animation-delay: -9s;
}

@keyframes floatOrb {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, 30px) scale(1.08); }
  100% { transform: translate(-25px, 50px) scale(0.96); }
}

/* Safe Area Insets for Android Notch / Home Bar */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Clean Frosted Glass Card */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: nowrap;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(6, 182, 212, 0.12));
  border: 1px solid rgba(16, 185, 129, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.15);
  flex-shrink: 0;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.gradient-arrow {
  background: linear-gradient(90deg, #059669, #0284c7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Badges */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  background: #f1f5f9;
  border: 1px solid var(--border);
}

.status-pill.active {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #059669;
}

.status-pill.warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #b45309;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Control Panel Section */
.control-card {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control-status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pulse-circle {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  transition: all 0.3s ease;
}

.pulse-circle.recording {
  background: var(--destructive);
  box-shadow: 0 0 12px var(--destructive);
  animation: pulseRecording 1.1s infinite;
}

@keyframes pulseRecording {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
  100% { transform: scale(1); opacity: 1; }
}

.live-status-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.timer-box {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: #b45309;
  background: #fef3c7;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid #fde68a;
}

/* Waveform Canvas */
.waveform-box {
  position: relative;
  width: 100%;
  height: 80px;
  background: #f8fafc;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#waveformCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.mic-guide {
  position: absolute;
  font-size: 13px;
  color: var(--text-muted);
  pointer-events: none;
  transition: opacity 0.3s ease;
  text-align: center;
  padding: 0 10px;
}

/* Action Buttons */
.controls-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.btn-primary-record {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-full);
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.3);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-primary-record:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(16, 185, 129, 0.4);
}

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

.btn-stop-record {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-full);
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.3);
  animation: pulseStop 1.5s infinite;
}

@keyframes pulseStop {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  70% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

.btn-round-ghost {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-round-ghost:hover {
  background: #f1f5f9;
  color: var(--text-primary);
  border-color: #cbd5e1;
}

/* Engine Mode Pill Toggle */
.engine-toggle-group {
  display: flex;
  justify-content: center;
  background: #f1f5f9;
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  max-width: 380px;
  margin: 0 auto;
  width: 100%;
}

.engine-tab {
  flex: 1;
  text-align: center;
  cursor: pointer;
}

.engine-tab input {
  display: none;
}

.engine-tab-label {
  display: block;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.engine-tab input:checked + .engine-tab-label {
  background: #ffffff;
  color: #059669;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border: 1px solid #d1fae5;
}

/* Mobile Tabs Switcher */
.mobile-view-tabs {
  display: none;
  background: #f1f5f9;
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  gap: 4px;
}

.view-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.view-btn.active {
  background: #ffffff;
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

@media (max-width: 720px) {
  .mobile-view-tabs {
    display: flex;
  }
}

/* Translation Feed Grid */
.translation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  flex: 1;
}

@media (max-width: 720px) {
  .translation-grid {
    grid-template-columns: 1fr;
  }
  .mobile-hide {
    display: none !important;
  }
}

.transcript-panel {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  min-height: 280px;
}

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

.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.word-count-badge {
  font-size: 11px;
  color: var(--text-secondary);
  background: #f1f5f9;
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
}

.btn-action-icon {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.btn-action-icon:hover {
  background: #f8fafc;
  color: var(--text-primary);
  border-color: #cbd5e1;
}

.btn-action-icon.tts-btn:hover {
  color: var(--accent-cyan);
  border-color: #38bdf8;
}

/* Text Containers */
.feed-content {
  flex: 1;
  overflow-y: auto;
  max-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tamil-font {
  font-family: var(--font-tamil);
}

/* Individual Sentence Bubble with Inline Copy Button */
.sentence-bubble {
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  animation: fadeInBubble 0.2s ease;
}

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

.bubble-text {
  flex: 1;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
}

.btn-bubble-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #f8fafc;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-bubble-copy:hover {
  background: #f1f5f9;
  color: var(--text-primary);
  border-color: #cbd5e1;
}

.btn-bubble-copy:active {
  transform: scale(0.92);
}

.interim-live-words {
  font-family: var(--font-tamil);
  color: #b45309;
  font-style: italic;
  font-size: 13.5px;
  padding: 4px 6px;
}

.empty-state-text {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  margin-top: 40px;
  font-style: italic;
}

.translating-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #e0f2fe;
  border: 1px solid #7dd3fc;
  border-radius: var(--radius-full);
  color: #0284c7;
  font-size: 11.5px;
  font-weight: 500;
  align-self: flex-start;
  margin-top: 6px;
}

.ping-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0284c7;
  animation: pulseRecording 1s infinite;
}

/* Bottom Toolbar */
.bottom-bar {
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bar-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-small-pill {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.btn-small-pill:hover {
  background: #f8fafc;
  color: var(--text-primary);
  border-color: #cbd5e1;
}

.latency-readout {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.latency-readout strong {
  color: var(--primary);
}

/* ==========================================================================
   SETTINGS MODAL - STRICT FIXED OVERLAY (NEVER INLINE)
   ========================================================================== */
.modal-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  width: 100dvw !important;
  height: 100vh !important;
  height: 100dvh !important;
  background: rgba(15, 23, 42, 0.45) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
  z-index: 999999 !important;
  display: none; /* Toggled to flex by JS */
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-dialog {
  width: 100%;
  max-width: 480px;
  background: #ffffff !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.15);
  animation: modalAppear 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalAppear {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

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

.modal-header-row h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

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

.guide-box {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 12px;
  color: #065f46;
  margin: 14px 0;
  line-height: 1.6;
}

.guide-box a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
}

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.hint-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-footer-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  margin-top: 14px;
}

.btn-secondary-flat {
  background: #f1f5f9;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-secondary-flat:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

.btn-primary-flat {
  background: var(--primary);
  border: none;
  color: #ffffff;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

.btn-primary-flat:hover {
  background: var(--primary-dark);
}

.feedback-alert {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-top: 10px;
}

.feedback-alert.error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.feedback-alert.success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

/* Toast */
.toast-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  border: 1px solid #334155;
  color: #ffffff;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  z-index: 1000000;
  font-size: 13px;
  font-weight: 500;
  display: none;
}
