/* Clean Modern Design System */
:root {
  /* Primary Color Palette */
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;

  /* Semantic Colors */
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --info-color: #3b82f6;

  /* Neutral Colors */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-surface: rgba(255, 255, 255, 0.04);
  --bg-surface-hover: rgba(255, 255, 255, 0.08);
  --bg-elevated: rgba(255, 255, 255, 0.06);

  /* Text Colors */
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-disabled: #64748b;

  /* Border Colors */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.2);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5);

  /* Border Radius */
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-full: 9999px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  min-height: 100vh;
  position: relative;
}

/* Subtle Background Accent */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

/* Header */
.app-header {
  backdrop-filter: blur(12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
}

.app-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: var(--space-sm);
}

/* Library Button */
.cta-library-btn {
  padding: var(--space-sm) var(--space-lg);
  background: var(--primary-color);
  border: none;
  border-radius: var(--radius-full);
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all var(--transition-base);
  box-shadow: var(--shadow-sm);
}

.cta-library-btn:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.cta-library-btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

/* Main Content Area */
.app-main {
  flex: 1;
  padding: var(--space-md) 0;
}

/* Text Container */
.text-container {
  backdrop-filter: blur(12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-height: 450px;
}

/* Action Buttons */
.text-actions {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.action-btn {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

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

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

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

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

/* Text Input */
.text-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-primary);
  resize: none;
  transition: all var(--transition-base);
  font-family: inherit;
  min-height: 280px;
}

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

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

/* Text Stats */
.text-stats {
  display: flex;
  gap: var(--space-lg);
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding: var(--space-md);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
}

.text-stats span {
  position: relative;
}

.text-stats span:not(:last-child)::after {
  content: '·';
  position: absolute;
  right: -12px;
  color: var(--text-disabled);
}

/* Footer Controls */
.app-footer {
  backdrop-filter: blur(12px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  box-shadow: var(--shadow-md);
}

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

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

.progress-fill {
  height: 100%;
  background: var(--primary-color);
  width: 0%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-muted);
}

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

.control-group {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}

.control-btn {
  width: 72px;
  height: 72px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 50%;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
  transform: scale(1.05);
}

.control-btn.primary {
  width: 88px;
  height: 88px;
  background: var(--primary-color);
  border: none;
  box-shadow: var(--shadow-md);
}

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

.control-btn.secondary {
  width: 72px;
  height: 72px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
}

.control-btn.secondary:hover {
  background: var(--danger-color);
  border-color: var(--danger-color);
  color: white;
}

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

.control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

/* Speed Control */
.speed-control {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
}

.speed-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: var(--space-md);
  display: block;
}

.speed-label span {
  color: var(--primary-light);
  font-weight: 600;
  margin-left: var(--space-sm);
}

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

.speed-slider::-webkit-slider-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  margin-top: -7px;
  transition: all var(--transition-base);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

/* Firefox support for slider */
.speed-slider::-moz-range-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
}

.speed-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  border: none;
  transition: all var(--transition-base);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.speed-slider::-moz-range-thumb:hover {
  transform: scale(1.15);
  background: var(--primary-light);
}

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

.speed-preset {
  flex: 1;
  padding: var(--space-sm);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
}

.speed-preset:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.speed-preset:active {
  transform: scale(0.95);
}

/* Voice Control */
.voice-control {
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 0;
}

.voice-select-btn {
  width: 100%;
  padding: var(--space-lg);
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  min-height: 80px;
}

.voice-select-btn:hover {
  background: var(--primary-color);
  color: white;
}

.voice-select-btn svg {
  width: 24px;
  height: 24px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  max-width: 540px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.close-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

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

/* Search Inputs */
.voice-search,
.library-search {
  width: 100%;
  padding: var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  margin-bottom: var(--space-lg);
  transition: all var(--transition-base);
}

.voice-search:focus,
.library-search:focus {
  outline: none;
  border-color: var(--primary-color);
  background: var(--bg-surface-hover);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

/* Voice List */
.voice-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.voice-item {
  padding: var(--space-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-base);
}

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

.voice-item.selected {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary-color);
}

.voice-name {
  font-weight: 500;
  margin-bottom: var(--space-xs);
  font-size: 0.9375rem;
  color: var(--text-primary);
}

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

.voice-quality {
  display: inline-block;
  padding: 3px var(--space-sm);
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  margin-left: var(--space-sm);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

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

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

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

.library-item {
  padding: var(--space-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
}

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

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

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

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

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

.library-action {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-base);
}

.library-action:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Loading Indicator */
.loading-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-medium);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  z-index: 2000;
  text-align: center;
  min-width: 220px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-surface);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  margin: 0 auto var(--space-lg);
  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 Notifications */
.toast-container {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  pointer-events: auto;
  border: 1px solid var(--border-medium);
  border-left: 3px solid var(--primary-color);
}

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

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

/* Text Highlighting */
.highlight {
  background: rgba(99, 102, 241, 0.25);
  padding: 2px 4px;
  border-radius: var(--radius-xs);
}

/* Responsive Design */
@media (min-width: 768px) {
  .app-container {
    padding: 0 var(--space-xl);
  }

  .controls {
    flex-direction: row;
    gap: var(--space-lg);
  }

  .speed-control,
  .voice-control {
    flex: 1;
  }

  .control-group {
    background: transparent;
    padding: 0;
  }
}

@media (max-width: 640px) {
  .app-container {
    padding: 0 var(--space-md);
  }

  .app-header {
    margin: var(--space-md) 0;
    padding: var(--space-md);
  }

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

  .cta-library-btn {
    font-size: 0.8125rem;
    padding: var(--space-sm) var(--space-md);
  }

  .text-container {
    padding: var(--space-md);
    min-height: 350px;
  }

  .text-input {
    min-height: 220px;
    padding: var(--space-md);
  }

  .app-footer {
    padding: var(--space-md);
    margin: var(--space-md) 0;
  }

  .control-group {
    padding: var(--space-md);
  }

  .control-btn {
    width: 60px;
    height: 60px;
  }

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

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

  .action-btn span {
    display: none;
  }

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

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

  .text-stats span:not(:last-child)::after {
    display: none;
  }

  .modal-content {
    max-width: 100%;
  }
}

/* iOS Specific Optimizations */
@supports (-webkit-touch-callout: none) {
  .text-input {
    font-size: 16px;
  }

  .app-container {
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Smooth scrolling on iOS */
  * {
    -webkit-overflow-scrolling: touch;
  }
}

/* Hover Effects for Desktop */
@media (hover: hover) {
  .action-btn:hover svg {
    transform: scale(1.05);
  }

  .control-btn:hover svg {
    transform: scale(1.05);
  }
}

/* Focus Visible for Accessibility */
*:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Print Styles */
@media print {
  body {
    background: white;
    color: black;
  }

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

  .text-input {
    border: 1px solid #ddd;
    background: white;
    color: black;
  }
}