/**
 * The Homemade Audiobook - Styles
 *
 * A modern, accessible text-to-speech web application
 *
 * Features:
 * - CSS Custom Properties for theming
 * - Dark mode support
 * - Responsive design
 * - Smooth animations
 * - Accessibility considerations
 */

/* ============================================
   CSS Custom Properties
   ============================================ */
:root {
  /* Colors - Light Mode */
  --color-primary: #6366f1;
  --color-primary-hover: #4f46e5;
  --color-primary-light: #e0e7ff;
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;

  /* Backgrounds */
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #f1f5f9;

  /* Text */
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-inverse: #ffffff;

  /* Borders */
  --border-color: #e2e8f0;
  --border-focus: var(--color-primary);

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
}

/* Dark Mode */
[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --bg-hover: #334155;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border-color: #334155;
  --color-primary-light: #312e81;

  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
}

/* ============================================
   Base Styles
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-body);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  color: var(--text-primary);
  line-height: 1.6;
  transition: background-color var(--transition-normal),
              color var(--transition-normal);
}

/* ============================================
   Layout
   ============================================ */
.app-container {
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-lg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============================================
   Header
   ============================================ */
.header {
  text-align: center;
  margin-bottom: var(--space-xl);
  position: relative;
}

.logo {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 var(--space-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
}

.logo-icon {
  font-size: 2rem;
}

.tagline {
  color: var(--text-secondary);
  margin: 0;
  font-size: 1rem;
}

.theme-toggle {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  cursor: pointer;
  font-size: 1.25rem;
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* ============================================
   Sections
   ============================================ */
section {
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
}

section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 var(--space-md);
}

/* ============================================
   Input Section
   ============================================ */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.section-header h2 {
  margin: 0;
}

.char-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.text-input {
  width: 100%;
  min-height: 200px;
  padding: var(--space-md);
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  resize: vertical;
  transition: border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}

.text-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

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

.input-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  flex-wrap: wrap;
}

/* ============================================
   Settings Section
   ============================================ */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.setting-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.setting-select {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.setting-select:focus {
  outline: none;
  border-color: var(--color-primary);
}

.setting-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border-color);
  border-radius: 3px;
  cursor: pointer;
}

.setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: transform var(--transition-fast);
}

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

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

/* ============================================
   Controls Section
   ============================================ */
.controls-section {
  text-align: center;
}

.progress-container {
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  margin-bottom: var(--space-sm);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-success));
  border-radius: 3px;
  transition: width var(--transition-fast);
}

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

.playback-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-md);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-primary {
  background: var(--color-primary);
  color: var(--text-inverse);
}

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

.btn-control {
  width: 48px;
  height: 48px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 1.25rem;
  border-radius: 50%;
}

.btn-control:hover:not(:disabled) {
  background: var(--border-color);
  color: var(--text-primary);
}

.btn-play {
  width: auto;
  height: 56px;
  padding: 0 var(--space-xl);
  font-size: 1.1rem;
  border-radius: 28px;
  gap: var(--space-sm);
}

.btn-play .play-icon {
  font-size: 1.25rem;
}

.btn-play.playing {
  background: var(--color-warning);
}

.btn-play.playing:hover {
  background: #d97706;
}

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

/* ============================================
   Status Bar
   ============================================ */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}

.status-bar.success {
  background: #dcfce7;
  color: #166534;
}

.status-bar.error {
  background: #fee2e2;
  color: #991b1b;
}

.status-bar.playing {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

[data-theme="dark"] .status-bar.success {
  background: #14532d;
  color: #86efac;
}

[data-theme="dark"] .status-bar.error {
  background: #7f1d1d;
  color: #fca5a5;
}

/* ============================================
   Footer
   ============================================ */
.footer {
  margin-top: auto;
  padding-top: var(--space-xl);
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-muted);
}

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

.footer a:hover {
  text-decoration: underline;
}

.footer-links {
  margin-top: var(--space-sm);
}

.separator {
  margin: 0 var(--space-sm);
  opacity: 0.5;
}

/* ============================================
   Browser Warning
   ============================================ */
.browser-warning {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  z-index: 1000;
}

.browser-warning[hidden] {
  display: none;
}

.warning-content {
  background: var(--bg-card);
  padding: var(--space-xl);
  border-radius: var(--radius-xl);
  max-width: 400px;
  text-align: center;
}

.warning-content h2 {
  color: var(--color-danger);
  margin-bottom: var(--space-md);
}

.warning-content ul {
  text-align: left;
  margin: var(--space-md) 0;
  padding-left: var(--space-lg);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 640px) {
  .app-container {
    padding: var(--space-md);
  }

  .logo {
    font-size: 1.5rem;
  }

  .tagline {
    font-size: 0.9rem;
  }

  .theme-toggle {
    position: static;
    margin-top: var(--space-md);
  }

  section {
    padding: var(--space-md);
  }

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

  .playback-controls {
    gap: var(--space-sm);
  }

  .btn-control {
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }

  .btn-play {
    height: 48px;
    padding: 0 var(--space-lg);
    font-size: 1rem;
  }

  .input-actions {
    justify-content: center;
  }
}

/* ============================================
   Accessibility
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

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

/* ============================================
   Animations
   ============================================ */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.playing .status-icon {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .controls-section,
  .settings-section,
  .theme-toggle,
  .input-actions,
  .status-bar,
  .footer {
    display: none !important;
  }

  body {
    background: white;
  }

  .app-container {
    max-width: none;
    padding: 0;
  }

  section {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
