/* ==========================================================================
   Google Material Design 3 (Material You) Design System & Tokens
   ========================================================================== */

:root {
  /* Dynamic Palette: Indigo / Violet accessible primary */
  --md-sys-color-primary: #3b5bdb;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #dbe4ff;
  --md-sys-color-on-primary-container: #102a71;

  --md-sys-color-secondary: #495057;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #e9ecef;
  --md-sys-color-on-secondary-container: #212529;

  --md-sys-color-tertiary: #0c8599;
  --md-sys-color-on-tertiary: #ffffff;
  --md-sys-color-tertiary-container: #c5f6fa;
  --md-sys-color-on-tertiary-container: #0b4953;

  --md-sys-color-error: #e03131;
  --md-sys-color-on-error: #ffffff;
  --md-sys-color-error-container: #ffe3e3;
  --md-sys-color-on-error-container: #911818;

  --md-sys-color-background: #f8f9fa;
  --md-sys-color-on-background: #1a1b1e;

  --md-sys-color-surface: #ffffff;
  --md-sys-color-on-surface: #1a1b1e;
  --md-sys-color-surface-variant: #f1f3f5;
  --md-sys-color-on-surface-variant: #495057;

  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f8f9fa;
  --md-sys-color-surface-container: #f1f3f5;
  --md-sys-color-surface-container-high: #e9ecef;
  --md-sys-color-surface-container-highest: #dee2e6;

  --md-sys-color-outline: #ced4da;
  --md-sys-color-outline-variant: #e9ecef;
  --md-sys-color-inverse-surface: #212529;
  --md-sys-color-inverse-on-surface: #f8f9fa;
  --md-sys-color-inverse-primary: #91a7ff;

  /* Elevation Shadows */
  --md-sys-elevation-1: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --md-sys-elevation-2: 0 3px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
  --md-sys-elevation-3: 0 10px 20px rgba(0, 0, 0, 0.1), 0 3px 6px rgba(0, 0, 0, 0.06);
  --md-sys-elevation-4: 0 14px 28px rgba(0, 0, 0, 0.12), 0 10px 10px rgba(0, 0, 0, 0.08);

  /* Corner Radius */
  --md-sys-shape-corner-none: 0px;
  --md-sys-shape-corner-xs: 4px;
  --md-sys-shape-corner-sm: 8px;
  --md-sys-shape-corner-md: 12px;
  --md-sys-shape-corner-lg: 16px;
  --md-sys-shape-corner-xl: 24px;
  --md-sys-shape-corner-2xl: 32px;
  --md-sys-shape-corner-full: 9999px;

  /* Reader Dynamic Typography */
  --reader-font-size: 18px;
  --reader-line-height: 1.7;
  --reader-letter-spacing: 0.02em;
  --reader-font-family: 'Lexend', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Active Word Glow for Speech */
  --word-highlight-bg: #fff3bf;
  --word-highlight-border: #fab005;
  --word-highlight-color: #000000;
}

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

html {
  font-family: var(--reader-font-family);
  font-size: 16px;
  color: var(--md-sys-color-on-background);
  background-color: var(--md-sys-color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Accessibility Focus States */
:focus-visible {
  outline: 3px solid var(--md-sys-color-primary);
  outline-offset: 3px;
  border-radius: var(--md-sys-shape-corner-xs);
}

/* Top App Bar */
.m3-top-app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--md-sys-color-surface);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: var(--md-sys-elevation-1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.m3-top-app-bar .brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--md-sys-color-on-surface);
}

.m3-top-app-bar .brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--md-sys-shape-corner-md);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.m3-top-app-bar .brand-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.m3-top-app-bar .brand-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border-radius: var(--md-sys-shape-corner-full);
}

.m3-actions-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Layout container */
.app-container {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem 1rem;
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
  }
}

/* M3 Cards */
.m3-card {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-xl);
  padding: 1.5rem;
  box-shadow: var(--md-sys-elevation-1);
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.m3-card-elevated {
  box-shadow: var(--md-sys-elevation-2);
}

.m3-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.m3-card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
}

/* M3 Buttons */
.m3-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--md-sys-shape-corner-full);
  border: none;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.2, 0, 0, 1);
  text-decoration: none;
}

.m3-btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-sys-elevation-1);
}

.m3-btn-filled:hover {
  filter: brightness(1.08);
  box-shadow: var(--md-sys-elevation-2);
}

.m3-btn-filled:active {
  filter: brightness(0.95);
}

.m3-btn-tonal {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-btn-tonal:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.m3-btn-outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1.5px solid var(--md-sys-color-outline);
}

.m3-btn-outlined:hover {
  background: var(--md-sys-color-primary-container);
  border-color: var(--md-sys-color-primary);
}

.m3-btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 0.5rem 0.75rem;
}

.m3-btn-text:hover {
  background: var(--md-sys-color-surface-container);
}

.m3-icon-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--md-sys-shape-corner-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  font-size: 1.25rem;
  transition: background-color 0.15s ease;
}

.m3-icon-btn:hover {
  background: var(--md-sys-color-surface-container-high);
}

.m3-icon-btn.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

/* Input Drop Zone (Strictly zero sample files) */
.m3-dropzone {
  border: 2px dashed var(--md-sys-color-primary);
  background: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-sys-shape-corner-xl);
  padding: 2.25rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.m3-dropzone:hover, .m3-dropzone.drag-over {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary-container);
}

.m3-dropzone-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  color: var(--md-sys-color-primary);
}

.m3-dropzone-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: var(--md-sys-color-on-surface);
}

.m3-dropzone-subtitle {
  font-size: 0.85rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 1.25rem;
}

.m3-input-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
}

/* Image Preview & Preprocessing Toolbar */
.image-preview-wrapper {
  position: relative;
  background: #000000;
  border-radius: var(--md-sys-shape-corner-lg);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  max-height: 420px;
  margin-top: 1rem;
}

.image-preview-wrapper img {
  max-width: 100%;
  max-height: 420px;
  object-fit: contain;
  display: block;
}

.preprocess-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 0.5rem 0.75rem;
  margin-top: 0.75rem;
}

.preprocess-bar span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  margin-right: 0.25rem;
}

/* Camera Stream Container */
.camera-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.camera-modal.hidden {
  display: none;
}

.camera-card {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-2xl);
  overflow: hidden;
  max-width: 680px;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.camera-view-box {
  position: relative;
  background: #000;
  height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.camera-view-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-crosshair {
  position: absolute;
  inset: 30px;
  border: 2px dashed rgba(255, 255, 255, 0.75);
  border-radius: var(--md-sys-shape-corner-lg);
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 1rem;
  background: var(--md-sys-color-surface-container);
}

/* Segmented Tabs */
.m3-tabs-container {
  display: flex;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-full);
  padding: 0.25rem;
  margin-bottom: 1.25rem;
  gap: 0.25rem;
  overflow-x: auto;
}

.m3-tab-btn {
  flex: 1;
  min-width: 120px;
  padding: 0.6rem 0.9rem;
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-full);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
}

.m3-tab-btn.active {
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-primary);
  box-shadow: var(--md-sys-elevation-1);
}

/* Reading Display & Word-by-Word Container */
.reader-content-box {
  background: var(--md-sys-color-surface-container-low);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-xl);
  padding: 1.5rem;
  min-height: 260px;
  max-height: 480px;
  overflow-y: auto;
  font-size: var(--reader-font-size);
  line-height: var(--reader-line-height);
  letter-spacing: var(--reader-letter-spacing);
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  position: relative;
}

/* Speech Audio Player Bar */
.audio-player-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  background: var(--md-sys-color-surface-container);
  border-radius: var(--md-sys-shape-corner-xl);
  padding: 0.85rem 1.25rem;
  margin-top: 1rem;
}

.audio-controls-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.audio-settings-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.audio-slider-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
}

/* M3 Sliders */
input[type="range"].m3-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 6px;
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  outline: none;
}

input[type="range"].m3-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-primary);
  cursor: pointer;
  transition: transform 0.1s ease;
}

input[type="range"].m3-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Select Dropdown */
.m3-select {
  padding: 0.45rem 0.85rem;
  border-radius: var(--md-sys-shape-corner-md);
  border: 1px solid var(--md-sys-color-outline);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

/* Readability Score Banner */
.readability-pill-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.readability-metric {
  background: rgba(255, 255, 255, 0.45);
  padding: 0.2rem 0.5rem;
  border-radius: var(--md-sys-shape-corner-sm);
}

/* Key Action Points Bullet List */
.key-takeaways-card {
  margin-top: 1rem;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: var(--md-sys-shape-corner-lg);
  padding: 1rem 1.25rem;
}

.key-takeaways-card h4 {
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.key-takeaways-card ul {
  padding-left: 1.2rem;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

/* Floating Action Button (FAB) */
.m3-fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1.5rem;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-radius: var(--md-sys-shape-corner-xl);
  box-shadow: var(--md-sys-elevation-3);
  font-size: 1rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  z-index: 90;
  transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s ease;
}

.m3-fab:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: var(--md-sys-elevation-4);
}

/* Progress bar */
.m3-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--md-sys-color-surface-container-highest);
  border-radius: var(--md-sys-shape-corner-full);
  overflow: hidden;
  margin: 0.75rem 0;
  position: relative;
}

.m3-progress-bar-fill {
  height: 100%;
  background: var(--md-sys-color-primary);
  width: 0%;
  transition: width 0.2s ease;
}

/* Modal Dialog */
.m3-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.m3-dialog-overlay.hidden {
  display: none;
}

.m3-dialog {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-sys-shape-corner-2xl);
  max-width: 580px;
  width: 100%;
  box-shadow: var(--md-sys-elevation-4);
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.m3-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.m3-dialog-title {
  font-size: 1.35rem;
  font-weight: 700;
}

.m3-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 65vh;
  overflow-y: auto;
}

.m3-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

/* Snackbar Alert */
.m3-snackbar {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  padding: 0.85rem 1.5rem;
  border-radius: var(--md-sys-shape-corner-md);
  box-shadow: var(--md-sys-elevation-3);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1100;
  transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1), opacity 0.25s ease;
  opacity: 0;
  pointer-events: none;
}

.m3-snackbar.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
