/* Minimalist Design System */
:root {
  /* Monochromatic Palette - Better contrast */
  --bg-primary: #09090b;
  --bg-secondary: #131316;
  --bg-elevated: #1c1c21;
  --bg-surface: #26262c;
  --bg-hover: #32323a;
  --bg-content: #1a1a1f;

  /* Text - High contrast hierarchy */
  --text-primary: #fafafa;
  --text-secondary: #b4b4bc;
  --text-muted: #8a8a96;

  /* Single Accent */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-muted: rgba(99, 102, 241, 0.15);

  /* Functional */
  --danger: #ef4444;
  --success: #22c55e;

  /* Spacing Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", monospace;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration: 200ms;
}

/* Reset */
*, *::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: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

/* App Container - Fixed height layout with sticky footer */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-5);
  gap: var(--space-5);
  overflow: hidden;
}

/* ========================================
   HEADER - Bold, minimal
   ======================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  background: var(--bg-secondary);
  border: 1px solid var(--bg-surface);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
}

.app-title {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.settings-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.settings-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.settings-btn svg {
  transition: transform var(--duration) var(--ease-out);
}

.settings-btn:hover svg {
  transform: rotate(30deg);
}

.cta-library-btn {
  height: 44px;
  padding: 0 var(--space-5);
  background: var(--bg-surface);
  border: none;
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background var(--duration) var(--ease-out);
}

.cta-library-btn:hover {
  background: var(--bg-hover);
}

/* ========================================
   MAIN CONTENT - Text is the hero
   ======================================== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; /* Allow flex child to shrink below content size */
  overflow: hidden;
}

.text-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0; /* Allow flex child to shrink */
  overflow: hidden;
}

/* Action Buttons - Visible, icon-forward */
.text-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.action-btn {
  height: 40px;
  padding: 0 var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-surface);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.action-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.action-btn.danger:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.action-btn.optional {
  opacity: 0.5;
}

.action-btn.optional:hover {
  opacity: 1;
}

.action-btn.premium {
  color: var(--accent);
}

.action-btn.premium:hover {
  background: var(--accent-muted);
}

/* Text Input - Clean, spacious, readable */
.text-input {
  flex: 1;
  min-height: 120px;
  padding: var(--space-5);
  background: var(--bg-content);
  border: 1px solid var(--bg-surface);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.75;
  resize: none;
  overflow-y: auto; /* Enable internal scrolling */
  transition: border-color var(--duration) var(--ease-out),
              box-shadow var(--duration) var(--ease-out);
}

.text-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

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

/* Text Display (during playback) */
.text-display {
  flex: 1;
  min-height: 120px;
  padding: var(--space-5);
  background: var(--bg-content);
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-size: 1.0625rem;
  line-height: 1.85;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.text-display .current-word,
.text-display mark.current-word {
  background: var(--accent);
  color: white;
  padding: 1px 4px;
  border-radius: 3px;
  margin: 0 -2px;
}

/* Text Stats - Subtle footer */
.text-stats {
  display: flex;
  gap: var(--space-5);
  padding: var(--space-3) 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* ========================================
   FOOTER / PLAYBACK CONTROLS - Always visible
   ======================================== */
.app-footer {
  flex-shrink: 0; /* Never shrink - always visible */
  background: var(--bg-secondary);
  border: 1px solid var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

/* Progress Bar */
.progress-container {
  margin-bottom: var(--space-5);
}

.progress-bar {
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  overflow: hidden;
  cursor: pointer;
  margin-bottom: var(--space-3);
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 0.1s linear;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Controls Layout */
.controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

@media (min-width: 640px) {
  .controls {
    flex-direction: row;
    align-items: center;
  }
}

/* Control Group - Play/Stop */
.control-group {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
}

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-hover);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: transform var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out),
              border-color var(--duration) var(--ease-out);
}

.control-btn:hover {
  background: var(--bg-surface);
  border-color: rgba(255, 255, 255, 0.2);
}

.control-btn:active {
  transform: scale(0.95);
}

.control-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Play Button - The star */
.control-btn.primary {
  width: 72px;
  height: 72px;
  background: var(--accent);
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.3);
}

.control-btn.primary:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.control-btn.primary:active {
  transform: scale(0.98);
}

/* Stop Button */
.control-btn.secondary {
  width: 56px;
  height: 56px;
}

.control-btn.secondary:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* Speed Control */
.speed-control {
  flex: 1;
  min-width: 0;
}

.speed-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.speed-label span {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.speed-slider {
  width: 100%;
  height: 32px;
  -webkit-appearance: none;
  background: transparent;
  margin-bottom: var(--space-3);
}

.speed-slider::-webkit-slider-track {
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--text-primary);
  border-radius: 50%;
  cursor: pointer;
  margin-top: -7px;
  transition: transform var(--duration) var(--ease-out);
}

.speed-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.speed-slider::-moz-range-track {
  height: 4px;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  border: none;
}

.speed-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--text-primary);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

.speed-presets {
  display: flex;
  gap: var(--space-2);
}

.speed-preset {
  flex: 1;
  height: 36px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.speed-preset:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

.speed-preset:active {
  background: var(--bg-hover);
}

/* Voice Control */
.voice-control {
  flex: 1;
  min-width: 0;
}

.voice-select-btn {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  background: var(--bg-surface);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration) var(--ease-out);
}

.voice-select-btn:hover {
  background: var(--bg-hover);
}

.voice-select-btn svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.voice-select-btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========================================
   MODALS - Clean overlays
   ======================================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.close-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.close-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
}

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  flex: 1;
}

/* Search Inputs */
.voice-search,
.library-search {
  width: 100%;
  height: 48px;
  padding: 0 var(--space-4);
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  margin-bottom: var(--space-4);
  transition: box-shadow var(--duration) var(--ease-out);
}

.voice-search:focus,
.library-search:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent);
}

.voice-search::placeholder,
.library-search::placeholder {
  color: var(--text-muted);
}

/* Voice List */
.voice-list-header {
  margin-bottom: var(--space-3);
}

.voice-count {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}

.voice-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.voice-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration) var(--ease-out);
}

.voice-item:hover {
  background: var(--bg-surface);
}

.voice-item.selected {
  background: var(--accent-muted);
}

.voice-info {
  flex: 1;
  min-width: 0;
}

.voice-name {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

.voice-lang {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.voice-quality {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.voice-quality.premium {
  background: var(--success);
  color: white;
}

.voice-quality.enhanced {
  background: var(--accent);
  color: white;
}

.voice-quality.good {
  background: #f59e0b;
  color: #1a1a1a;
}

.voice-quality.standard {
  background: var(--bg-surface);
  color: var(--text-muted);
}

.voice-source {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-muted);
}

.voice-source.google {
  color: #4285f4;
}

.voice-source.premium {
  color: var(--accent);
  font-weight: 600;
}

.voice-preview {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.voice-preview:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.voice-empty {
  text-align: center;
  padding: var(--space-7);
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Library List */
.library-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.library-item {
  padding: var(--space-4);
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  transition: background var(--duration) var(--ease-out);
}

.library-item:hover {
  background: var(--bg-surface);
}

.library-title {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.library-preview {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: var(--space-3);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.library-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.library-actions {
  display: flex;
  gap: var(--space-2);
}

.library-action {
  height: 32px;
  padding: 0 var(--space-3);
  background: var(--bg-surface);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.library-action:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ========================================
   SETTINGS
   ======================================== */
.settings-section {
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--bg-surface);
}

.settings-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.settings-title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.settings-description {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: var(--space-4);
}

.settings-description a {
  color: var(--accent);
  text-decoration: none;
}

.settings-description a:hover {
  text-decoration: underline;
}

/* Engine Toggle */
.engine-toggle {
  display: flex;
  gap: var(--space-2);
}

.engine-btn {
  flex: 1;
  padding: var(--space-4);
  background: var(--bg-elevated);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--duration) var(--ease-out),
              background var(--duration) var(--ease-out);
}

.engine-btn:hover {
  background: var(--bg-surface);
}

.engine-btn.active {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.engine-name {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.engine-detail {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Quality Info */
.quality-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.quality-tier {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.quality-tier .voice-quality {
  min-width: 72px;
  text-align: center;
}

/* ========================================
   LOADING & TOASTS
   ======================================== */
.loading-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
  z-index: 2000;
  text-align: center;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--bg-surface);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto var(--space-4);
  animation: spin 0.8s linear infinite;
}

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

#loadingMessage {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

.toast-container {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  border-left: 3px solid var(--accent);
}

.toast.success {
  border-left-color: var(--success);
}

.toast.error {
  border-left-color: var(--danger);
}

/* ========================================
   RESPONSIVE
   ======================================== */
@media (max-width: 640px) {
  .app-container {
    padding: var(--space-4);
    gap: var(--space-4);
  }

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

  .text-input,
  .text-display {
    min-height: 100px;
    padding: var(--space-4);
  }

  .app-footer {
    padding: var(--space-4);
  }

  .control-btn.primary {
    width: 64px;
    height: 64px;
  }

  .control-btn.secondary {
    width: 48px;
    height: 48px;
  }

  .action-btn span {
    display: none;
  }

  .action-btn {
    padding: 0 var(--space-3);
  }

  .text-stats {
    flex-wrap: wrap;
    gap: var(--space-3);
  }
}

/* iOS Safe Areas */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .app-container {
    padding-bottom: max(var(--space-5), env(safe-area-inset-bottom));
  }

  .text-input {
    font-size: 16px;
  }
}

/* Focus States */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ========================================
   PRINT
   ======================================== */
@media print {
  body {
    background: white;
    color: black;
  }

  .app-header,
  .app-footer,
  .text-actions,
  .modal {
    display: none;
  }

  .text-input {
    background: white;
    color: black;
  }
}
