/* ==========================================================================
   Zone-Maths — Zone Optimale d'Apprentissage (Cycle 4 : 5e, 4e, 3e)
   Design System & Feuille de style principale
   ========================================================================== */

:root {
  /* Palette de couleurs (Mode Clair) */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border: var(--border-color);
  --border-focus: #3b82f6;
  --bg-hover: var(--bg-subtle);

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;

  /* Couleurs sémantiques */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;

  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;
  --success-text: #065f46;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;

  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #991b1b;

  --info: #0ea5e9;
  --info-bg: #f0f9ff;
  --info-border: #bae6fd;
  --info-text: #0369a1;

  /* Paliers ZPD */
  --tier-1-color: #10b981;
  --tier-2-color: #0284c7;
  --tier-3-color: #6366f1;
  --tier-4-color: #8b5cf6;

  /* Typographie & Rayons */
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Menlo, Consolas, Monaco, monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --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);

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  /* Palette d'arrière-plans harmonieuse (Slate 900 / 800) */
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-elevated: #283548;
  --bg-card: #1e293b;
  --bg-subtle: #243044;
  --border-color: #334155;
  --border: var(--border-color);
  --border-focus: #60a5fa;
  --bg-hover: var(--bg-subtle);

  /* Typographie haute lisibilité (WCAG AAA) */
  --text-main: #f8fafc;
  --text-muted: #cbd5e1;
  --text-subtle: #94a3b8;

  /* Couleur d'accentuation Primaire accessible en mode sombre */
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-subtle: rgba(59, 130, 246, 0.16);
  --primary-border: rgba(96, 165, 250, 0.35);

  /* Couleurs sémantiques équilibrées & lisibles */
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --success-border: #10b981;
  --success-text: #6ee7b7;

  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --warning-border: #f59e0b;
  --warning-text: #fde68a;

  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);
  --danger-border: #ef4444;
  --danger-text: #fca5a5;

  --info: #38bdf8;
  --info-bg: rgba(56, 189, 248, 0.15);
  --info-border: #38bdf8;
  --info-text: #7dd3fc;

  /* Paliers ZPD vibrants & contrastés */
  --tier-1-color: #34d399;
  --tier-2-color: #38bdf8;
  --tier-3-color: #818cf8;
  --tier-4-color: #c084fc;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.brand-logo-img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  flex-shrink: 0;
}

.brand-container:hover .brand-logo-img {
  transform: scale(1.05) rotate(-2deg);
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.35);
}

.brand-logo {
  font-size: 1.8rem;
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-level-tag {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #3b82f6, #10b981);
  color: #ffffff;
  font-weight: 600;
  letter-spacing: 0.3px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}

.app-badge-zpd {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: white;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.brand-tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Sélecteur de Niveau Cycle 4 (5e, 4e, 3e) */
.cycle4-level-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg-subtle);
  padding: 3px 6px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
}

.cycle4-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-left: 6px;
}

.level-pills {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.level-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
}

.level-pill:hover {
  color: var(--text-main);
  background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .level-pill:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.level-pill.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

.header-user-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 4px 12px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-icon-text {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 6px 14px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon-text:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-focus);
}

/* Grille 2x2 des 4 outils pédagogiques du Header */
.header-actions-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-tools-grid-2x2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.35rem 0.5rem;
}

.header-tools-grid-2x2 .btn-icon-text {
  justify-content: center;
  padding: 5px 12px;
  font-size: 0.82rem;
  white-space: nowrap;
}

.header-utility-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  justify-content: center;
}

.header-utility-actions .btn-utility-action {
  padding: 4px 10px;
  font-size: 0.78rem;
  justify-content: center;
  white-space: nowrap;
}

.btn-flashcards-glow {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(234, 88, 12, 0.16));
  border-color: rgba(245, 158, 11, 0.45);
  font-weight: 600;
}

.btn-flashcards-glow:hover {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(234, 88, 12, 0.28));
  border-color: rgba(245, 158, 11, 0.8);
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
  transform: translateY(-1px);
}

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

/* Déclencheur Mobile du Volet Chapitres */
.mobile-chapter-trigger-bar {
  display: none;
}

.mobile-chapter-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  cursor: pointer;
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
  transition: var(--transition);
  text-align: left;
}

.mobile-chapter-btn:hover {
  background-color: var(--bg-subtle);
  border-color: var(--primary);
}

.m-chap-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  flex: 1;
}

.m-chap-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.m-chap-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  background-color: var(--primary-subtle);
  color: var(--primary);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  letter-spacing: 0.3px;
  flex-shrink: 0;
}

.m-chap-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
  font-weight: 600;
}

.m-chap-mastery-pill {
  font-size: 0.72rem;
  font-weight: 700;
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
}

.m-chap-mastery-pill.mid {
  background-color: rgba(59, 130, 246, 0.12);
  color: #2563eb;
  border-color: rgba(59, 130, 246, 0.3);
}

.m-chap-mastery-pill.high {
  background-color: rgba(16, 185, 129, 0.12);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.3);
}

.m-chap-arrow {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: transform 0.25s ease;
  flex-shrink: 0;
}

/* Barre latérale / Grille des Chapitres */
.sidebar-chapters {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: fit-content;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

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

.sidebar-title-row h2 {
  font-size: 1rem;
  font-weight: 700;
}

.chapters-count {
  font-size: 0.75rem;
  background-color: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  color: var(--text-muted);
}

.domain-filters-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.domain-filter-btn {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.domain-filter-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.domain-filter-btn.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
}

.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chapter-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.chapter-card:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-focus);
}

.chapter-card.active {
  border-color: var(--primary);
  background-color: var(--primary-subtle);
  box-shadow: 0 0 0 1px var(--primary);
}

.chap-badge-id {
  font-size: 0.85rem;
  font-weight: 700;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.chap-title {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chap-desc {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chap-progress-pill {
  width: 44px;
  height: 18px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-full);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pill-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background-color: var(--success);
  opacity: 0.3;
  transition: width 0.4s ease;
}

.pill-text {
  font-size: 0.65rem;
  font-weight: 700;
  z-index: 1;
}

/* Zone Principale de Travail */
.main-workspace {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Hero Bannière du Chapitre */
.chapter-hero-banner {
  background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-subtle) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.domain-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

.chapter-hero-banner h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 0.3rem;
}

.chapter-hero-banner p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.hero-mastery-gauge {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  text-align: center;
  min-width: 140px;
}

.gauge-header {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.gauge-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
}

.gauge-track {
  width: 100%;
  height: 6px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-full);
  margin-top: 0.5rem;
  overflow: hidden;
}

.gauge-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--success));
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* Barre d'onglets du chapitre */
.tabs-navigation-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 8px 16px;
  background: none;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.tab-btn.active {
  background-color: var(--primary-subtle);
  color: var(--primary);
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* =========================================================================
   1. STYLES DE L'ENTRAÎNEMENT ADAPTATIF (ZPD)
   ========================================================================= */

.adaptive-control-panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.tier-selector-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tier-selector-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.tier-pills-group {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tier-pill-btn {
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background-color: var(--bg-subtle);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.tier-pill-btn[data-tier="1"].active { background-color: var(--tier-1-color); color: white; border-color: var(--tier-1-color); }
.tier-pill-btn[data-tier="2"].active { background-color: var(--tier-2-color); color: white; border-color: var(--tier-2-color); }
.tier-pill-btn[data-tier="3"].active { background-color: var(--tier-3-color); color: white; border-color: var(--tier-3-color); }
.tier-pill-btn[data-tier="4"].active { background-color: var(--tier-4-color); color: white; border-color: var(--tier-4-color); }

/* Paliers d'entraînement verrouillés et validés */
.tier-pill-btn.tier-locked {
  opacity: 0.65;
  background-color: var(--bg-hover, #f1f5f9) !important;
  color: var(--text-muted, #64748b) !important;
  border: 1px dashed var(--border-color, #cbd5e1) !important;
  cursor: not-allowed !important;
  user-select: none;
}

.tier-pill-btn.tier-locked:hover {
  opacity: 0.9;
  border-color: #f59e0b !important;
  color: var(--text-main, #0f172a) !important;
}

.tier-pill-btn.tier-validated:not(.active) {
  border-color: rgba(16, 185, 129, 0.45);
  background-color: rgba(16, 185, 129, 0.08);
  color: var(--text-main, #0f172a);
}

.tier-pill-btn .tier-check-icon {
  color: #10b981;
  font-weight: 800;
  margin-right: 3px;
}

.tier-pill-btn.active .tier-check-icon {
  color: #ffffff;
}

.tier-pill-btn .tier-lock-icon {
  font-size: 0.85em;
  margin-right: 3px;
  opacity: 0.85;
}

[data-theme="dark"] .tier-pill-btn.tier-locked {
  background-color: #1e293b !important;
  color: #64748b !important;
  border-color: #334155 !important;
}

[data-theme="dark"] .tier-pill-btn.tier-validated:not(.active) {
  border-color: rgba(16, 185, 129, 0.5);
  background-color: rgba(16, 185, 129, 0.15);
  color: #f1f5f9;
}

/* Jauge Visuelle ZPD */
.zpd-gauge-widget {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
}

.zpd-gauge-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.zpd-label {
  font-size: 0.85rem;
  font-weight: 700;
}

.zpd-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.zpd-meter-bar {
  position: relative;
  height: 10px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, #3b82f6 0%, #10b981 50%, #f59e0b 100%);
  margin: 0.5rem 0;
}

.zpd-pointer {
  position: absolute;
  top: -4px;
  width: 18px;
  height: 18px;
  background-color: white;
  border: 3px solid var(--text-main);
  border-radius: 50%;
  transform: translateX(-50%);
  transition: left 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-sm);
}

.zpd-pointer.badge-comfort { border-color: #3b82f6; }
.zpd-pointer.badge-flow { border-color: #10b981; }
.zpd-pointer.badge-frustration { border-color: #f59e0b; }

.zpd-meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Boîte de l'exercice */
.exercise-workspace-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.exo-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.exo-tier-tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  color: white;
}

.exo-tier-tag.tier-1 { background-color: var(--tier-1-color); }
.exo-tier-tag.tier-2 { background-color: var(--tier-2-color); }
.exo-tier-tag.tier-3 { background-color: var(--tier-3-color); }
.exo-tier-tag.tier-4 { background-color: var(--tier-4-color); }

.exo-skill-tag {
  font-size: 0.75rem;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.exo-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.exo-body {
  font-size: 1.05rem;
  line-height: 1.8;
}

/* Zone d'interaction */
.exercise-input-zone {
  border-top: 1px solid var(--border-color);
  padding-top: 1.25rem;
}

/* Saisie QCM */
.mcq-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .mcq-options-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.mcq-opt-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.95rem;
}

.mcq-opt-btn:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-focus);
}

.mcq-opt-btn.selected {
  border-color: var(--primary);
  background-color: var(--primary-subtle);
  box-shadow: 0 0 0 1px var(--primary);
}

.mcq-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-color: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.mcq-opt-btn.selected .mcq-letter {
  background-color: var(--primary);
  color: white;
}

/* Saisie Exacte */
.exact-input-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.math-text-input {
  flex: 1;
  font-size: 1.15rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-family: var(--font-mono);
  outline: none;
  transition: var(--transition);
}

.math-text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.math-preview-badge {
  padding: 0.5rem 1rem;
  background-color: var(--primary-subtle);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-md);
  font-size: 1.1rem;
  display: inline-flex;
  align-items: center;
}

.input-tip {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Clavier Mathématique Virtuel */
.virtual-keyboard-section {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  background-color: var(--bg-subtle);
}

.keyboard-toggle-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.virtual-math-keyboard {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
}

@media (max-width: 600px) {
  .virtual-math-keyboard {
    grid-template-columns: repeat(6, 1fr);
    gap: 0.3rem;
  }
}

.key-btn {
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.key-btn:hover {
  background-color: var(--bg-subtle);
  border-color: var(--primary);
}

.key-btn.action-key {
  background-color: var(--primary-subtle);
  color: var(--primary);
}

/* Boutons d'action */
.exo-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-top: 1px solid var(--border-color);
  padding-top: 1.25rem;
}

.help-buttons-group {
  display: flex;
  gap: 0.5rem;
}

.btn-primary {
  padding: 0.75rem 1.75rem;
  border-radius: var(--radius-md);
  border: none;
  background-color: var(--primary);
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-focus);
}

.btn-danger {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--danger-border);
  background-color: var(--danger-bg);
  color: var(--danger-text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

/* Cartes de Feedback */
.feedback-card {
  padding: 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  animation: fadeIn 0.3s ease;
}

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

.feedback-success {
  background-color: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success-text);
}

.feedback-warning {
  background-color: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.feedback-danger {
  background-color: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.feedback-info {
  background-color: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info-text);
}

.feedback-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.feedback-header h4 {
  font-size: 1.1rem;
  font-weight: 700;
}

.xp-badge {
  background-color: #10b981;
  color: white;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
}

.level-up-banner {
  background: linear-gradient(135deg, #10b981, #06b6d4);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-weight: 700;
  margin: 0.75rem 0;
  box-shadow: var(--shadow-sm);
}

.feedback-solution {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.feedback-solution-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.feedback-solution-body {
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--text-main);
}

.feedback-solution-body .katex-display {
  margin: 0.75rem 0;
  padding: 0.25rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.feedback-solution-body p.math-p:last-child {
  margin-bottom: 0;
}

.hint-content {
  margin-top: 0.75rem;
  padding: 0.9rem 1.15rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1rem;
  line-height: 1.65;
  box-shadow: var(--shadow-sm);
}

.hint-content .katex-display {
  margin: 0.6rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.hint-content p.math-p:last-child {
  margin-bottom: 0;
}

.retry-text {
  margin-top: 0.75rem;
  font-size: 0.92rem;
  font-weight: 600;
  opacity: 0.95;
}

.step-down-box {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px dashed var(--danger-border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}

[data-theme="dark"] .feedback-solution,
[data-theme="dark"] .hint-content {
  background-color: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: var(--text-main);
}

[data-theme="dark"] .feedback-solution-title {
  color: var(--text-subtle);
}

[data-theme="dark"] .step-down-box {
  background: rgba(239, 68, 68, 0.15);
}

/* =========================================================================
   2. STYLES FICHE DE COURS
   ========================================================================= */

.course-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.course-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.course-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--primary);
}

.course-traps h3 {
  color: var(--warning-text);
}

.course-card-body {
  line-height: 1.8;
}

.course-method {
  border-left: 4px solid var(--primary);
}

.method-example {
  background-color: var(--bg-subtle);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin: 0.75rem 0;
}

.method-step-item {
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border-color);
}

.method-step-item:last-child {
  border-bottom: none;
}

.course-cta-box {
  text-align: center;
  padding: 2rem;
  background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-subtle) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-top: 2rem;
}

.course-cta-box p {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

/* =========================================================================
   3. STYLES FICHES D'EXERCICES COMPLÈTES & IMPRESSION
   ========================================================================= */

.sheets-nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.sheets-tabs-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sheet-select-btn {
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.sheet-select-btn:hover {
  background-color: var(--bg-subtle);
}

.sheet-select-btn.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
}

.printable-worksheet {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  line-height: 1.8;
}

.sheet-statement-content {
  margin-bottom: 2rem;
}

.sheet-solution-accordion {
  margin-top: 2rem;
  border-top: 2px solid var(--border-color);
  padding-top: 1rem;
}

.accordion-toggle-btn {
  width: 100%;
  padding: 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--primary-border);
  background-color: var(--primary-subtle);
  color: var(--primary);
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.solution-content {
  padding: 1.5rem;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  margin-top: 1rem;
}

.print-only {
  display: none;
}

/* Impression (@media print) */
@media print {
  body {
    background-color: white !important;
    color: black !important;
  }
  .app-header, .sidebar-chapters, .tabs-navigation-bar, .no-print, .chapter-hero-banner {
    display: none !important;
  }
  
  /* Si une modale est ouverte, on masque totalement le conteneur principal */
  body.modal-open .app-container {
    display: none !important;
  }

  .app-container {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  
  /* En dehors des modales, on imprime proprement l'onglet actif */
  body:not(.modal-open) .tab-pane {
    display: none !important;
  }
  body:not(.modal-open) .tab-pane.active {
    display: block !important;
  }

  .printable-worksheet, .course-card {
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
    background: white !important;
    color: black !important;
  }
  .sheet-print-header,
  .printable-worksheet .print-only {
    display: block !important;
    margin-bottom: 2rem;
    border-bottom: 2px solid black;
    padding-bottom: 1rem;
  }
  .sheet-print-header h1, .print-only h1 { font-size: 1.4rem; }
  .sheet-print-header h2, .print-only h2 { font-size: 1.2rem; }
  .print-meta { margin-top: 1rem; font-size: 0.9rem; }
}

/* =========================================================================
   4. STYLES BILAN & STATISTIQUES
   ========================================================================= */

.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.25rem;
}

.stat-icon { font-size: 2rem; margin-bottom: 0.25rem; }
.stat-val { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.stat-lbl { font-size: 0.8rem; color: var(--text-muted); }

.stats-section {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.stats-section h3 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.badge-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.badge-item.unlocked {
  background-color: var(--success-bg);
  border-color: var(--success-border);
}

.badge-item.locked {
  opacity: 0.4;
  filter: grayscale(100%);
}

.badge-emoji { font-size: 2rem; }
.badge-info strong { display: block; font-size: 0.9rem; }
.badge-info small { font-size: 0.75rem; color: var(--text-muted); }

/* Grille des Trophées par Chapitre */
.chapter-trophies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.1rem;
}

.chapter-trophy-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
  min-width: 0;
  box-sizing: border-box;
}

.chapter-trophy-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.07);
}

.chapter-trophy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 0;
}

.chapter-trophy-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  overflow: hidden;
  flex: 1;
}

.chapter-trophy-code {
  font-weight: 800;
  font-family: monospace;
  font-size: 0.8rem;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid currentColor;
  flex-shrink: 0;
}

.chapter-trophy-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chapter-trophy-mastery {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-subtle);
  padding: 2px 8px;
  border-radius: 9999px;
  flex-shrink: 0;
}

/* Bannière du titre unique le plus élevé */
.chapter-single-rank-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
  min-width: 0;
}

.chapter-trophy-card.unlocked .chapter-single-rank-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(234, 179, 8, 0.1));
  border-color: rgba(234, 179, 8, 0.45);
}

.chapter-trophy-card.unlocked.tier-4 .chapter-single-rank-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(6, 182, 212, 0.14));
  border-color: rgba(16, 185, 129, 0.6);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.15);
}

.chapter-trophy-card.locked .chapter-single-rank-banner {
  background: var(--bg-subtle);
  border: 1px dashed var(--border-color);
  opacity: 0.75;
}

.rank-single-medal {
  font-size: 1.8rem;
  line-height: 1;
  flex-shrink: 0;
}

.rank-single-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  flex: 1;
}

.rank-single-status {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.2;
  margin-bottom: 2px;
}

.chapter-trophy-card.unlocked .rank-single-status {
  color: #b45309;
}

.chapter-trophy-card.unlocked.tier-4 .rank-single-status {
  color: #059669;
}

.rank-single-title {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.chapters-mastery-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.mastery-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.mastery-left {
  width: 220px;
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.mastery-bar-wrapper {
  flex: 1;
  height: 8px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.mastery-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.mastery-percent {
  font-size: 0.8rem;
  font-weight: 600;
  width: 140px;
  text-align: right;
  color: var(--text-muted);
}

.stats-footer-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* Classes utilitaires Math KaTeX & Markdown */
.math-h1 { font-size: 1.45rem; font-weight: 800; margin: 1.5rem 0 0.75rem; color: var(--text-main); }
.math-h2 { font-size: 1.25rem; font-weight: 700; margin: 1.35rem 0 0.6rem; color: var(--primary); }
.math-h3 { font-size: 1.12rem; font-weight: 700; margin: 1.2rem 0 0.5rem; color: var(--text-main); }
.math-h4 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 1.35rem 0 0.5rem;
  color: var(--primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.35rem;
}
.math-h5 { font-size: 0.98rem; font-weight: 700; margin: 1rem 0 0.4rem; color: var(--text-main); }
.math-p { margin-bottom: 0.85rem; line-height: 1.75; }
.math-divider { border: 0; border-top: 1px solid var(--border-color); margin: 1.5rem 0; }
.math-list { margin: 0.5rem 0 1rem 1.5rem; padding-left: 0.5rem; }
.math-bullet { margin-bottom: 0.45rem; line-height: 1.65; }
.math-callout {
  padding: 0.85rem 1.15rem;
  border-left: 4px solid var(--primary);
  background-color: var(--primary-subtle);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 1.15rem 0;
  line-height: 1.65;
}

/* Tableaux Markdown structurés */
.math-table-container {
  overflow-x: auto;
  margin: 1.25rem 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
}

.math-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.95rem;
  background-color: var(--bg-surface);
}

.math-table th {
  padding: 0.85rem 1.15rem;
  font-weight: 700;
  background-color: var(--bg-subtle);
  border-bottom: 2px solid var(--border-color);
  color: var(--text-main);
  white-space: nowrap;
}

.math-table td {
  padding: 0.75rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

.math-table tbody tr:last-child td {
  border-bottom: none;
}

.math-table tbody tr:hover {
  background-color: var(--bg-hover);
}

/* Blocs de code préformatés (Scratch, algorithmique, tableur) */
.math-code-container {
  margin: 1.25rem 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: #1e293b;
  box-shadow: var(--shadow-sm);
}

.math-code-block {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.6;
  color: #f8fafc;
  background: transparent;
}

.math-code-block code {
  font-family: inherit;
  white-space: pre;
}

.math-inline-code {
  background-color: var(--bg-subtle);
  color: var(--primary);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.9em;
  border: 1px solid var(--border-color);
}

[data-theme="dark"] .math-table {
  background-color: var(--bg-surface);
}

[data-theme="dark"] .math-table th {
  background-color: var(--bg-surface-elevated);
  border-bottom-color: var(--border-color);
  color: var(--text-main);
}

[data-theme="dark"] .math-table td {
  border-bottom-color: var(--border-color);
  color: var(--text-main);
}

[data-theme="dark"] .math-inline-code {
  background-color: var(--bg-surface-elevated);
  border-color: var(--border-color);
  color: #93c5fd;
}

/* =========================================================================
   5. NOUVEAUX COMPOSANTS : DIAPORAMA & DEVOIR FLASH (MathsMentales)
   ========================================================================= */

.btn-accent-glow {
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: white !important;
  border: none !important;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
}

.btn-accent-glow:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.tier-left-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tier-right-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* Modales d'interaction */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-box {
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.diapo-box {
  max-width: 1000px;
  min-height: 550px;
}

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

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.modal-close-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.modal-intro {
  padding: 1rem 1.5rem 0.5rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background-color: var(--bg-subtle);
}

/* Paramètres Diaporama & Quiz */
.diapo-settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 1rem 1.5rem;
}

@media (max-width: 640px) {
  .diapo-settings-grid {
    grid-template-columns: 1fr;
  }
}

.diapo-setting-item label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.form-select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
  font-size: 0.9rem;
  outline: none;
}

.form-select:focus {
  border-color: var(--primary);
}

.diapo-chapters-select-section {
  padding: 0 1.5rem 1.5rem;
  overflow-y: auto;
  max-height: 250px;
}

.diapo-chapters-select-section label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.diapo-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.diapo-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 4px 10px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

.diapo-chip:hover {
  background-color: var(--primary-subtle);
  border-color: var(--primary-border);
}

.diapo-chip input[type="checkbox"]:checked + span {
  font-weight: 700;
  color: var(--primary);
}

/* Écran Diaporama en cours */
.diapo-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.diapo-top-hud {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background-color: var(--bg-subtle);
}

.diapo-hud-index {
  font-size: 1rem;
  font-weight: 700;
}

.diapo-timer-box {
  flex: 1;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.diapo-timer-bar {
  flex: 1;
  height: 12px;
  background-color: var(--border-color);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.diapo-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #f59e0b, #ef4444);
  border-radius: var(--radius-full);
  transition: width 1s linear;
}

.diapo-time-text {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 800;
  width: 45px;
  text-align: right;
}

.diapo-main-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 3rem 2rem;
  background: radial-gradient(circle at center, var(--bg-surface) 0%, var(--bg-subtle) 100%);
}

.diapo-stage-title {
  font-size: 1.2rem;
  color: var(--primary);
  margin-bottom: 1.5rem;
  font-weight: 700;
}

.diapo-stage-body {
  font-size: 1.7rem;
  line-height: 1.8;
  max-width: 800px;
}

.diapo-bottom-controls {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background-color: var(--bg-subtle);
}

/* Récapitulatif Diaporama */
.diapo-recap-container {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: 60vh;
}

.diapo-recap-header {
  margin-bottom: 1.5rem;
  text-align: center;
}

.diapo-recap-header h3 {
  font-size: 1.4rem;
  color: var(--success-text);
  margin-bottom: 0.25rem;
}

.diapo-recap-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

.recap-item-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  background-color: var(--bg-surface);
}

.recap-item-num {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.recap-statement {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.recap-solution {
  background-color: var(--bg-subtle);
  border-left: 3px solid var(--success);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
}

/* Toast Notification Moderne */
.app-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-main);
  color: var(--bg-surface);
  padding: 0.85rem 1.5rem;
  border-radius: 9999px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  font-weight: 600;
  font-size: 0.95rem;
  z-index: 99999;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  text-align: center;
  max-width: 90vw;
}

.app-toast.visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* =========================================================================
   6. STYLES DEVOIR FLASH IMPRIMABLE (SUJET A / SUJET B)
   ========================================================================= */

.quiz-scroll-preview {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: 75vh;
  background-color: var(--bg-subtle);
}

.printable-quiz-sheet {
  background: white;
  color: black;
  border-radius: var(--radius-md);
  padding: 2rem;
  box-shadow: var(--shadow-md);
}

.quiz-banner-notice {
  background-color: #eff6ff;
  border-left: 4px solid #2563eb;
  padding: 0.85rem 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
  color: #1e3a8a;
  border-radius: 0 4px 4px 0;
}

.quiz-single-subject {
  border: 2px solid #000;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
  border-radius: 4px;
  background: white;
}

.quiz-header-box {
  border-bottom: 2px solid #000;
  padding-bottom: 0.5rem;
  margin-bottom: 0.85rem;
}

.quiz-title-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.4rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.quiz-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.quiz-header-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.quiz-title-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.quiz-title-line h3 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 0;
}

.quiz-badge-theme {
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid #000;
  padding: 2px 7px;
  border-radius: 4px;
  background: #f8fafc;
}

.quiz-author-line {
  font-size: 0.78rem;
  color: #4b5563;
  margin: 0.25rem 0 0.45rem 0;
  font-style: italic;
}

.quiz-author-line strong {
  font-weight: 600;
  color: #111827;
  font-style: normal;
}

.quiz-footer-credit {
  font-size: 0.72rem;
  color: #6b7280;
  text-align: right;
  margin-top: 0.5rem;
  font-style: italic;
}

.quiz-student-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quiz-grade-box {
  border: 2px solid #000;
  padding: 3px 10px;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
}

/* Grille compacte des questions */
.quiz-questions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem 1rem;
}

@media (max-width: 700px) {
  .quiz-questions-grid {
    grid-template-columns: 1fr;
  }
}

.quiz-q-card {
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  background-color: #fafafa;
  display: flex;
  flex-direction: column;
}

.quiz-q-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #e5e7eb;
}

.quiz-learning-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem 0.55rem;
  margin: 0 0 0.4rem;
  color: #64748b;
  font-size: 0.72rem;
  line-height: 1.35;
}

.quiz-stage-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 700;
}

.correction-learning-meta {
  margin-top: -0.2rem;
  margin-bottom: 0.4rem;
}

.quiz-q-badge {
  font-weight: 800;
  font-size: 0.82rem;
  color: #111827;
}

.quiz-q-pts {
  font-size: 0.75rem;
  color: #4b5563;
  font-weight: 600;
}

.quiz-q-topic {
  font-size: 0.75rem;
  color: #6b7280;
  margin-left: auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.quiz-q-text {
  font-size: 0.88rem;
  line-height: 1.45;
  color: #1f2937;
}

.quiz-q-text p {
  margin-bottom: 0.25rem;
}

.quiz-q-text p:last-child {
  margin-bottom: 0;
}

/* Corrigé Enseignant / Auto-évaluation */
.quiz-solutions-teacher {
  border: 2px solid #2563eb;
  padding: 1.25rem 1.5rem;
  border-radius: 4px;
  background: white;
}

.teacher-header {
  border-bottom: 2px solid #2563eb;
  padding-bottom: 0.5rem;
  margin-bottom: 0.85rem;
}

.teacher-header h3 {
  color: #2563eb;
  font-size: 1.05rem;
  font-weight: 800;
  margin: 0;
}

.quiz-solutions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem 1rem;
}

@media (max-width: 700px) {
  .quiz-solutions-grid {
    grid-template-columns: 1fr;
  }
}

.quiz-sol-card {
  border: 1px solid #bfdbfe;
  border-radius: 4px;
  padding: 0.6rem 0.75rem;
  background-color: #f8fafc;
}

.quiz-sol-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: #1e40af;
  margin-bottom: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #dbeafe;
}

.quiz-sol-topic {
  font-size: 0.75rem;
  color: #64748b;
  margin-left: auto;
  font-weight: normal;
}

.quiz-sol-body {
  font-size: 0.85rem;
  line-height: 1.45;
  color: #1e293b;
}

.quiz-sol-body p {
  margin-bottom: 0.25rem;
}

.quiz-sol-body p:last-child {
  margin-bottom: 0;
}

.quiz-method-cues {
  margin: 0 0 0.55rem;
  padding: 0.45rem 0.55rem;
  border-left: 3px solid #60a5fa;
  background: #eff6ff;
  color: #334155;
  font-size: 0.77rem;
}

.quiz-method-cues ul {
  margin: 0.2rem 0 0 1rem;
  padding: 0;
}

.quiz-method-cues li {
  margin: 0.08rem 0;
}

/* Keep the correction preview inside its cards; print styles remain independent. */
@media screen {
  #quiz-preview-content,
  .quiz-solutions-teacher,
  .quiz-sol-card,
  .quiz-sol-body {
    min-width: 0;
    max-width: 100%;
  }

  .quiz-solutions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .quiz-sol-header {
    min-width: 0;
    flex-wrap: wrap;
  }

  .quiz-sol-topic,
  .quiz-sol-body {
    overflow-wrap: anywhere;
  }

  .quiz-sol-body .katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .quiz-sol-body pre,
  .quiz-sol-body code {
    max-width: 100%;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  @media (max-width: 700px) {
    .quiz-solutions-grid {
      grid-template-columns: minmax(0, 1fr);
    }
  }
}

/* =========================================================================
   MODALE 4 : BOÎTE DE MÉMORISATION FLASHCARDS (LEITNER / FABIEN OLICARD)
   ========================================================================= */

.flashcards-box {
  max-width: 800px;
  min-height: 520px;
}

.fc-intro-banner {
  padding: 0.85rem 1.5rem;
  background-color: var(--bg-subtle);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.fc-intro-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.fc-intro-text strong {
  color: var(--text-main);
}

.fc-stats-summary {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.fc-boxes-strip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.fc-boxes-strip.large {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.fc-box-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.76rem;
  font-weight: 500;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
}

.fc-box-pill.b1 { border-color: rgba(239, 68, 68, 0.4); color: #ef4444; background: rgba(239, 68, 68, 0.08); }
.fc-box-pill.b2 { border-color: rgba(249, 115, 22, 0.4); color: #f97316; background: rgba(249, 115, 22, 0.08); }
.fc-box-pill.b3 { border-color: rgba(234, 179, 8, 0.4); color: #eab308; background: rgba(234, 179, 8, 0.08); }
.fc-box-pill.b4 { border-color: rgba(14, 165, 233, 0.4); color: #0ea5e9; background: rgba(14, 165, 233, 0.08); }
.fc-box-pill.b5 { border-color: rgba(16, 185, 129, 0.4); color: #10b981; background: rgba(16, 185, 129, 0.08); }

.fc-total-selected {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.fc-chap-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.fc-chap-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-text-sm {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 2px 4px;
  font-weight: 500;
}

.btn-text-sm:hover {
  text-decoration: underline;
}

.fc-sep {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.fc-chap-chip {
  position: relative;
}

.fc-chip-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: normal;
}

/* Écran de Jeu / Révision active */
.fc-play-header-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.fc-pill-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

.fc-pill-box {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.fc-pill-box.b1 { background: rgba(239, 68, 68, 0.15); color: #dc2626; border-color: rgba(239, 68, 68, 0.4); }
.fc-pill-box.b2 { background: rgba(249, 115, 22, 0.15); color: #ea580c; border-color: rgba(249, 115, 22, 0.4); }
.fc-pill-box.b3 { background: rgba(234, 179, 8, 0.15); color: #ca8a04; border-color: rgba(234, 179, 8, 0.4); }
.fc-pill-box.b4 { background: rgba(14, 165, 233, 0.15); color: #0284c7; border-color: rgba(14, 165, 233, 0.4); }
.fc-pill-box.b5 { background: rgba(16, 185, 129, 0.15); color: #059669; border-color: rgba(16, 185, 129, 0.4); }

.fc-play-header-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.fc-retry-tag {
  color: #ea580c;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(249, 115, 22, 0.12);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.fc-progress-bar-container {
  height: 4px;
  background-color: var(--border-color);
  width: 100%;
}

.fc-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #10b981);
  transition: width 0.3s ease;
}

/* Stage de la Carte 3D */
.fc-card-stage {
  perspective: 1200px;
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  background: radial-gradient(circle at center, rgba(37, 99, 235, 0.03) 0%, transparent 70%);
}

.fc-flipper-container {
  position: relative;
  width: 100%;
  max-width: 650px;
  min-height: 290px;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.34, 1.3, 0.64, 1);
  cursor: pointer;
}

.fc-flipper-container.is-flipped {
  transform: rotateY(180deg);
}

.fc-card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 290px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1.5px solid var(--border-color);
  background-color: var(--bg-surface);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
}

.fc-card-front {
  background: linear-gradient(145deg, var(--bg-surface), var(--bg-subtle));
}

.fc-card-back {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, rgba(16, 185, 129, 0.04), var(--bg-surface));
  border-color: rgba(16, 185, 129, 0.35);
}

.fc-card-kind-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: rgba(37, 99, 235, 0.1);
  color: var(--primary);
}

.fc-card-kind-tag.fc-tag-answer {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
}

.fc-card-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem 0;
  text-align: center;
}

.fc-question-main,
.fc-answer-main {
  font-size: 1.15rem;
  line-height: 1.6;
  color: var(--text-main);
  max-width: 95%;
  word-break: break-word;
}

.fc-answer-main {
  font-size: 1.1rem;
}

.fc-card-hint-notice {
  display: flex;
  justify-content: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.fc-reveal-cta {
  opacity: 0.85;
  transition: opacity 0.2s;
}

.fc-flipper-container:hover .fc-reveal-cta {
  opacity: 1;
  color: var(--primary);
}

/* Zone d'action dock sous la carte */
.fc-actions-dock {
  padding: 1rem 1.5rem 1.25rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-subtle);
  display: flex;
  justify-content: center;
}

.fc-action-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  width: 100%;
}

.btn-reveal-big {
  min-width: 280px;
  padding: 0.8rem 1.75rem;
  font-size: 1rem;
  font-weight: 600;
  box-shadow: 0 3px 10px rgba(37, 99, 235, 0.25);
  cursor: pointer;
}

.btn-fc-eval {
  flex: 1;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background-color: var(--bg-surface);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  text-align: left;
}

.btn-fc-eval:hover {
  transform: translateY(-2px);
}

.btn-fc-emoji {
  font-size: 1.5rem;
}

.btn-fc-text {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.btn-fc-main {
  font-size: 0.92rem;
  font-weight: 700;
}

.btn-fc-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-fc-shortcut {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-fc-wrong {
  border-color: rgba(239, 68, 68, 0.45);
}

.btn-fc-wrong:hover {
  background: rgba(239, 68, 68, 0.08);
  border-color: #ef4444;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-fc-wrong .btn-fc-main {
  color: #dc2626;
}

.btn-fc-correct {
  border-color: rgba(16, 185, 129, 0.45);
}

.btn-fc-correct:hover {
  background: rgba(16, 185, 129, 0.08);
  border-color: #10b981;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.btn-fc-correct .btn-fc-main {
  color: #059669;
}

/* Écran 3 : Résumé et Célébration */
.fc-summary-content {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  overflow-y: auto;
}

.fc-summary-header {
  text-align: center;
}

.fc-summary-badge {
  display: inline-block;
  font-size: 1.35rem;
  font-weight: 800;
  padding: 6px 18px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(37, 99, 235, 0.15));
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.fc-summary-motivation {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.fc-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .fc-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.fc-stat-card {
  padding: 0.85rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  text-align: center;
}

.fc-stat-val {
  font-size: 1.35rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.fc-stat-val.text-green { color: #10b981; }
.fc-stat-val.text-amber { color: #f59e0b; }
.fc-stat-val.text-primary { color: var(--primary); }
.fc-stat-val.text-purple { color: #8b5cf6; }

.fc-stat-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.fc-box-distribution-section h4 {
  font-size: 0.88rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.fc-box-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.65rem 0.4rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-subtle);
  text-align: center;
}

.fc-box-col .fc-box-num {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.fc-box-col .fc-box-title {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
}

.fc-box-col.b1 { border-color: rgba(239, 68, 68, 0.4); }
.fc-box-col.b1 .fc-box-num { color: #ef4444; }

.fc-box-col.b2 { border-color: rgba(249, 115, 22, 0.4); }
.fc-box-col.b2 .fc-box-num { color: #f97316; }

.fc-box-col.b3 { border-color: rgba(234, 179, 8, 0.4); }
.fc-box-col.b3 .fc-box-num { color: #eab308; }

.fc-box-col.b4 { border-color: rgba(14, 165, 233, 0.4); }
.fc-box-col.b4 .fc-box-num { color: #0ea5e9; }

.fc-box-col.b5 { border-color: rgba(16, 185, 129, 0.4); background: rgba(16, 185, 129, 0.05); }
.fc-box-col.b5 .fc-box-num { color: #10b981; }

.btn-sm-flashcards {
  padding: 4px 10px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* Impression optimisée : SUJET BLANC & CORRIGÉ DÉTAILLÉ */
@media print {
  @page {
    size: A4 portrait;
    margin: 8mm 8mm 8mm 8mm;
  }

  html, body {
    background: white !important;
    color: black !important;
    font-size: 9pt !important;
    overflow: visible !important;
    height: auto !important;
    min-height: 0 !important;
  }

  .no-print {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  /* Déblocage de la structure en modale pour autoriser l'impression multi-pages */
  body.modal-open,
  body.modal-open html {
    overflow: visible !important;
    height: auto !important;
  }

  body.modal-open .app-container {
    display: none !important;
  }

  /* 1. TOUTES LES AUTRES MODALES SONT STRICTEMENT MASQUÉES À L'IMPRESSION */
  .modal-overlay,
  #diaporama-modal,
  #quiz-modal,
  #reward-unlock-modal,
  #flashcards-modal,
  #streak-modal,
  #level-modal {
    display: none !important;
  }

  /* 2. DÉBLOCAGE EXCLUSIF DU DEVOIR BLANC LORSQU'IL EST IMPRIMÉ */
  body.quiz-modal-open #quiz-modal,
  body.modal-open:not(.diapo-modal-open) #quiz-modal {
    position: static !important;
    display: block !important;
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    backdrop-filter: none !important;
    z-index: auto !important;
  }

  body.quiz-modal-open #quiz-modal .modal-box,
  body.modal-open:not(.diapo-modal-open) #quiz-modal .modal-box {
    display: block !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    background: white !important;
  }

  #quiz-config-screen {
    display: none !important;
  }

  body.quiz-modal-open #quiz-preview-screen,
  body.modal-open:not(.diapo-modal-open) #quiz-preview-screen {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  body.quiz-modal-open #quiz-modal .quiz-scroll-preview,
  body.modal-open:not(.diapo-modal-open) #quiz-modal .quiz-scroll-preview {
    display: block !important;
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
    margin: 0 !important;
    background: none !important;
  }

  /* Impression du Diaporama (si déclenchée depuis le récapitulatif du diaporama) */
  body.diapo-modal-open #diaporama-modal {
    position: static !important;
    display: block !important;
    background: white !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }
  body.diapo-modal-open #diaporama-modal #diapo-screen-config,
  body.diapo-modal-open #diaporama-modal #diapo-screen-play {
    display: none !important;
  }
  body.diapo-modal-open #diaporama-modal #diapo-screen-recap {
    display: block !important;
  }
  body.diapo-modal-open #quiz-modal {
    display: none !important;
  }

  .printable-quiz-sheet {
    display: block !important;
    background: white !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* 3. FEUILLE DE SUJET DU DEVOIR BLANC (PAGE 1) */
  .quiz-single-subject {
    display: block !important;
    box-shadow: none !important;
    border: 1.5px solid #000 !important;
    padding: 5mm 7mm !important;
    margin: 0 !important;
    page-break-before: auto !important;
    break-before: auto !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    box-sizing: border-box !important;
    background: white !important;
    height: auto !important;
    overflow: visible !important;
  }

  .quiz-questions-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 2mm 3.5mm !important;
  }

  .quiz-q-card {
    border: 1px solid #444 !important;
    background: white !important;
    padding: 1.8mm 2.5mm !important;
    font-size: 8pt !important;
    line-height: 1.25 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    box-sizing: border-box !important;
    border-radius: 2px !important;
  }

  .quiz-header-box {
    margin-bottom: 2mm !important;
    padding-bottom: 1.5mm !important;
    border-bottom: 1px solid #aaa !important;
  }

  .quiz-title-main h3 {
    font-size: 9.5pt !important;
    margin: 0 0 1mm 0 !important;
    font-weight: 700 !important;
    color: #000 !important;
  }

  .quiz-header-right {
    display: flex !important;
    align-items: center !important;
    gap: 2.5mm !important;
  }

  .quiz-grade-box {
    font-size: 8.5pt !important;
    font-weight: 700 !important;
    padding: 1mm 2.5mm !important;
    border: 1.5pt solid #000 !important;
    background: white !important;
    white-space: nowrap !important;
    border-radius: 2px !important;
  }

  .quiz-header-logo {
    display: block !important;
    width: 11mm !important;
    height: 11mm !important;
    object-fit: contain !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .quiz-student-meta {
    display: flex !important;
    justify-content: space-between !important;
    font-size: 7.5pt !important;
    margin-top: 1mm !important;
    color: #111 !important;
  }

  .quiz-page-break {
    display: none !important;
  }

  /* 4. FEUILLE DU CORRIGÉ DÉTAILLÉ (PAGE 2) */
  #quiz-solutions-block,
  .quiz-solutions-teacher {
    display: block !important;
    box-shadow: none !important;
    border: 1.5px solid #2563eb !important;
    padding: 5mm 7mm !important;
    margin: 0 !important;
    page-break-before: always !important;
    break-before: page !important;
    page-break-after: auto !important;
    break-after: auto !important;
    page-break-inside: auto !important;
    break-inside: auto !important;
    box-sizing: border-box !important;
    background: white !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* Masquer à l'impression UNIQUEMENT si l'élève a cliqué sur "Masquer le corrigé" */
  #quiz-solutions-block.quiz-solutions-hidden {
    display: none !important;
  }

  .teacher-header h3 {
    font-size: 9pt !important;
    color: #1e40af !important;
    margin: 0 !important;
    font-weight: 700 !important;
  }

  .quiz-solutions-grid {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 2mm 3.5mm !important;
  }

  .quiz-sol-card {
    border: 1px solid #2563eb !important;
    background: white !important;
    padding: 1.8mm 2.5mm !important;
    font-size: 7.5pt !important;
    line-height: 1.25 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    box-sizing: border-box !important;
    border-radius: 2px !important;
  }

  .quiz-sol-header {
    display: flex !important;
    align-items: center !important;
    gap: 1.5mm !important;
    margin-bottom: 0.8mm !important;
    font-size: 7.5pt !important;
    color: #1e40af !important;
    font-weight: 700 !important;
  }

  .quiz-sol-body {
    font-size: 7.5pt !important;
    line-height: 1.25 !important;
  }

  .quiz-sol-body p {
    margin: 0 0 0.8mm 0 !important;
  }

  .quiz-sol-body p:last-child {
    margin-bottom: 0 !important;
  }

  .quiz-author-line {
    font-size: 7pt !important;
    margin: 0.5mm 0 1mm 0 !important;
    color: #333 !important;
  }

  .quiz-footer-credit {
    display: block !important;
    font-size: 6.5pt !important;
    color: #444 !important;
    text-align: right !important;
    margin-top: 1.5mm !important;
    padding-top: 0.8mm !important;
    border-top: 0.5pt solid #bbb !important;
    font-style: italic !important;
  }
}

/* =========================================================================
   BARRE DE RECHERCHE DE CHAPITRES DANS LA SIDEBAR
   ========================================================================= */
.sidebar-search-box {
  display: flex;
  align-items: center;
  position: relative;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.65rem;
  transition: var(--transition);
  margin-top: 0.25rem;
}

.sidebar-search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.sidebar-search-box .search-icon {
  font-size: 0.85rem;
  margin-right: 0.4rem;
  opacity: 0.7;
}

#chapters-search-input {
  border: none;
  background: transparent;
  width: 100%;
  font-size: 0.82rem;
  color: var(--text-main);
  outline: none;
}

#chapters-search-input::placeholder {
  color: var(--text-subtle);
}

.search-clear-btn {
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 4px;
}

.search-clear-btn:hover {
  color: var(--text-main);
}

/* =========================================================================
   BOUTON DE CONTRÔLE DU SON DANS L'EN-TÊTE
   ========================================================================= */
#sound-toggle-btn {
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  font-size: 0.82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  transition: var(--transition);
  color: var(--text-main);
}

#sound-toggle-btn:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

/* =========================================================================
   CARTES FLASH & MÉMORISATION ACTIVE (ESPACE COURS)
   ========================================================================= */
.course-flashcards-section {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.flashcards-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.flashcards-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.flashcards-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.flashcards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}

.flashcard-card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
  min-height: 220px;
}

.flashcard-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.flashcard-pill {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  background-color: var(--primary-subtle);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  margin-bottom: 0.75rem;
  width: fit-content;
}

.flashcard-question-text {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-main);
  margin-bottom: 1rem;
}

.flashcard-answer-box {
  background-color: var(--bg-subtle);
  border-left: 3px solid #10b981;
  border-radius: var(--radius-sm);
  padding: 0.85rem;
  font-size: 0.9rem;
  line-height: 1.6;
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
  animation: fadeIn 0.25s ease-out;
}

.flashcard-btn-action {
  width: 100%;
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: auto;
}

.flashcard-btn-action:hover {
  background-color: var(--primary-subtle);
  border-color: var(--primary);
  color: var(--primary);
}

/* Raccourcis Clavier Badges */
.kbd-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.kbd-badge {
  display: inline-block;
  font-family: monospace;
  font-size: 0.72rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-bottom: 2px solid var(--border-color);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text-main);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

/* Boutons de réinitialisation de progression */
.btn-reset-all {
  font-size: 0.7rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  padding: 2px 7px;
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
}

.btn-reset-all:hover {
  color: #ef4444;
  border-color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

.btn-reset-chapter {
  margin-top: 0.4rem;
  font-size: 0.72rem;
  background: transparent;
  border: 1px dashed var(--border-color);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  cursor: pointer;
  transition: var(--transition);
  display: inline-block;
  text-align: center;
}

.btn-reset-chapter:hover {
  color: #ef4444;
  border-color: #ef4444;
  background-color: rgba(239, 68, 68, 0.1);
}

/* =========================================================================
   PIED DE PAGE & MENTIONS DE L'AUTEUR (LOÏC DELAPORTE)
   ========================================================================= */
.app-footer {
  margin-top: 3rem;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 1rem;
  color: var(--text-muted);
}

.app-footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

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

.footer-logo-img {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.footer-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-main);
}

.footer-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.footer-author-box {
  display: flex;
  align-items: center;
}

.footer-author-badge {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

.footer-author-badge strong {
  color: var(--primary);
}

.modal-author-badge {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 0.15rem;
}

.modal-author-badge strong {
  color: var(--text-main);
}

.course-author-sub {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.2rem;
}

.course-author-sub strong {
  color: var(--text-main);
  font-style: normal;
}

.sheet-author-tag {
  font-size: 8.5pt;
  font-style: italic;
  color: #4b5563;
  margin-bottom: 2mm;
}

.passport-author-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1.25rem;
  margin-bottom: 1.5rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.passport-author-banner strong {
  color: var(--text-main);
}

/* ==========================================================================
   RESPONSIVE DESIGN & VERSION MOBILE NATIVE (CYCLE 4)
   ========================================================================== */

/* --- TABLETTES & ÉCRANS MOYENS (<= 1024px) --- */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 1fr;
    padding: 1rem;
    gap: 1rem;
  }

  .mobile-chapter-trigger-bar {
    display: block;
    position: sticky;
    top: 0.5rem;
    z-index: 80;
    margin-bottom: 0.75rem;
  }

  .sidebar-chapters {
    display: none;
    max-height: 70vh;
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
    margin-bottom: 1rem;
  }

  .sidebar-chapters.mobile-open {
    display: flex;
    animation: mobileSlideDown 0.25s ease-out forwards;
  }

  @keyframes mobileSlideDown {
    from {
      opacity: 0;
      transform: translateY(-8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
}

/* --- SMARTPHONES & PETITS ÉCRANS (<= 768px) --- */
@media (max-width: 768px) {
  /* Dégagement pour la barre de navigation basse fixe */
  body {
    padding-bottom: calc(68px + env(safe-area-inset-bottom)) !important;
  }

  .app-container {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  /* En-tête mobile aéré et ultra-compact */
  .app-header {
    padding: max(0.5rem, env(safe-area-inset-top)) 0.75rem 0.5rem;
    position: relative;
    z-index: 50;
  }

  .header-inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0;
  }

  .brand-container {
    justify-content: center;
  }

  .brand-logo-img {
    width: 34px;
    height: 34px;
  }

  .brand-text h1 {
    font-size: 1.02rem;
  }

  .brand-tagline {
    display: none; /* Alléger le header sur mobile */
  }

  /* Sélecteur de niveau Cycle 4 centré et fluide */
  .cycle4-level-nav {
    justify-content: center;
    width: 100%;
    padding: 3px 6px;
  }

  .level-pills {
    justify-content: center;
    width: 100%;
  }

  .level-pill {
    padding: 4px 8px;
    font-size: 0.78rem;
    flex: 1;
    text-align: center;
    min-height: 32px;
  }

  /* Statut et actions utilisateur compactes */
  .header-user-status {
    flex-direction: column;
    gap: 0.4rem;
    width: 100%;
  }

  .status-pills-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
  }

  .status-pill {
    padding: 2px 7px;
    font-size: 0.75rem;
  }

  .header-actions-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    width: 100%;
  }

  .header-tools-grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.3rem 0.4rem;
  }

  .header-tools-grid-2x2 .btn-icon-text {
    padding: 5px 8px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    min-height: 32px;
  }

  .header-utility-actions {
    display: flex;
    flex-direction: row;
    gap: 0.3rem;
  }

  .header-utility-actions .btn-utility-action {
    padding: 4px 8px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    min-height: 32px;
  }

  /* Déclencheur mobile du volet chapitres */
  .mobile-chapter-trigger-bar {
    display: block;
    position: sticky;
    top: 0.35rem;
    z-index: 80;
    margin-bottom: 0.5rem;
  }

  /* MASQUER LA BANNIÈRE GÉANTE DU CHAPITRE SUR MOBILE (Informations déjà dans la barre mobile) */
  .chapter-hero-banner {
    display: none !important;
  }

  /* BARRE D'ONGLETS FIXÉE EN BAS (Bottom Navigation Bar Native) */
  .tabs-navigation-bar {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 100 !important;
    background: var(--bg-surface-elevated, #ffffff) !important;
    border-top: 1px solid var(--border-color) !important;
    box-shadow: 0 -3px 15px rgba(0, 0, 0, 0.08) !important;
    display: flex !important;
    justify-content: space-around !important;
    align-items: center !important;
    padding: 5px 0 max(6px, env(safe-area-inset-bottom)) !important;
    margin: 0 !important;
    border-bottom: none !important;
  }

  .tab-btn {
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 2px !important;
    padding: 3px 6px !important;
    font-size: 0.68rem !important;
    color: var(--text-muted) !important;
    border-radius: var(--radius-sm) !important;
    flex: 1 !important;
    text-align: center !important;
    background: none !important;
    border: none !important;
  }

  .tab-btn.active {
    background: none !important;
    color: var(--primary) !important;
    font-weight: 700 !important;
  }

  .tab-btn .tab-icon {
    font-size: 1.22rem !important;
    line-height: 1 !important;
  }

  .tab-btn .tab-label {
    font-size: 0.68rem !important;
    letter-spacing: 0.2px !important;
    white-space: nowrap !important;
  }

  /* PALIERS ZPD ÉPURÉS & COMPACTS DIRECTEMENT AU-DESSUS DE L'EXERCICE */
  .adaptive-control-panel {
    background: transparent !important;
    border: none !important;
    padding: 0 0 0.35rem 0 !important;
    margin-bottom: 0.35rem !important;
    box-shadow: none !important;
  }

  .tier-selector-row {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.35rem !important;
  }

  .tier-selector-label {
    display: none !important;
  }

  .tier-pills-group {
    display: flex !important;
    gap: 0.35rem !important;
    flex: 1 !important;
    overflow-x: auto !important;
    scrollbar-width: none !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .tier-pill-btn {
    padding: 4px 10px !important;
    font-size: 0.75rem !important;
    min-height: 32px !important;
    border-radius: var(--radius-full) !important;
    flex-shrink: 0 !important;
    white-space: nowrap !important;
  }

  .tier-right-actions {
    display: none !important;
  }

  /* =========================================================================
     L'EXERCICE EN HÉROS : MISE EN AVANT VISUELLE MAXIMALE
     ========================================================================= */
  .exercise-workspace-box {
    padding: 1.15rem 1rem !important;
    border-radius: var(--radius-lg) !important;
    border: 1px solid var(--border-color) !important;
    border-top: 4px solid var(--primary) !important;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.07) !important;
    gap: 1rem !important;
    background-color: var(--bg-surface) !important;
    margin-top: 0 !important;
  }

  .exo-header-bar {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    margin-bottom: 0.35rem !important;
  }

  .exo-tier-tag {
    font-size: 0.72rem !important;
    font-weight: 700 !important;
    padding: 3px 9px !important;
    border-radius: var(--radius-full) !important;
  }

  .exo-skill-tag {
    font-size: 0.72rem !important;
    padding: 2px 7px !important;
  }

  .exo-title {
    font-size: 1.15rem !important;
    font-weight: 800 !important;
    margin-bottom: 0.4rem !important;
    color: var(--text-main) !important;
  }

  .exo-body {
    font-size: 1.05rem !important;
    line-height: 1.65 !important;
    color: var(--text-main) !important;
    margin-bottom: 0.5rem !important;
  }

  /* Saisie QCM : Boutons tactiles généreux */
  .mcq-options-grid {
    grid-template-columns: 1fr !important;
    gap: 0.55rem !important;
  }

  .mcq-opt-btn {
    padding: 0.85rem 1rem !important;
    border-radius: var(--radius-md) !important;
    font-size: 1rem !important;
    min-height: 50px !important;
    touch-action: manipulation !important;
    border: 1.5px solid var(--border-color) !important;
  }

  .mcq-opt-btn:active {
    transform: scale(0.98) !important;
  }

  .kbd-hint {
    display: none !important;
  }

  /* Saisie exacte */
  .math-text-input {
    font-size: 1.25rem !important;
    min-height: 50px !important;
    padding: 0.75rem 1rem !important;
    border-radius: 12px !important;
    text-align: center !important;
  }

  /* Actions de l'exercice - Bouton validation pleine largeur */
  .exo-actions-bar {
    flex-direction: column-reverse !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
    padding-top: 0.75rem !important;
  }

  .exo-actions-bar .btn-primary {
    width: 100% !important;
    justify-content: center !important;
    min-height: 50px !important;
    font-size: 1.05rem !important;
    font-weight: 700 !important;
    border-radius: 12px !important;
    background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35) !important;
    letter-spacing: 0.3px !important;
  }

  .help-buttons-group {
    width: 100% !important;
    display: flex !important;
    gap: 0.4rem !important;
  }

  .help-buttons-group .btn-secondary {
    flex: 1 !important;
    justify-content: center !important;
    min-height: 40px !important;
    font-size: 0.82rem !important;
    padding: 6px !important;
    border-radius: var(--radius-md) !important;
  }

  /* Clavier mathématique virtuel tactile */
  .virtual-math-keyboard {
    grid-template-columns: repeat(6, 1fr) !important;
    gap: 0.3rem;
  }

  .key-btn {
    min-height: 42px;
    padding: 8px 2px;
    font-size: 0.95rem;
    touch-action: manipulation;
  }

  .key-btn:active {
    transform: scale(0.92);
    background-color: var(--primary-subtle);
  }

  /* KaTeX et équations mathématiques : protection anti-débordement horizontal */
  .katex-display {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
    padding: 0.35rem 0 !important;
  }

  .math-callout {
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
  }

  /* Fiches d'exercices et DS sur mobile */
  .printable-worksheet {
    padding: 1.25rem 1rem !important;
    border-radius: var(--radius-md) !important;
    line-height: 1.65 !important;
  }

  .sheet-select-btn {
    font-size: 0.8rem !important;
    padding: 6px 10px !important;
  }

  .math-table th, .math-table td {
    padding: 0.6rem 0.75rem !important;
    font-size: 0.88rem !important;
  }

  .math-code-block {
    padding: 0.85rem 1rem !important;
    font-size: 0.85rem !important;
  }

  /* Modales Diaporama et Devoir Blanc en plein écran mobile */
  .modal-overlay {
    padding: 0.5rem;
    align-items: flex-end;
  }

  .modal-box {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 94vh !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .diapo-box {
    min-height: unset;
  }

  .modal-header {
    padding: 0.85rem 1rem;
  }

  .modal-header h2 {
    font-size: 1.05rem;
  }

  .diapo-stage-title {
    font-size: 1.15rem !important;
  }

  .diapo-stage-body {
    font-size: 1.05rem !important;
    padding: 1rem 0.5rem !important;
  }

  .diapo-bottom-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .diapo-bottom-controls button {
    flex: 1;
    min-width: 80px;
    min-height: 44px;
  }

  /* Pied de page mobile */
  .app-footer {
    padding: 1.25rem 0.75rem max(1.25rem, env(safe-area-inset-bottom));
    margin-top: 1.5rem;
  }

  .app-footer-inner {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1rem;
  }

  .footer-brand {
    flex-direction: column;
    text-align: center;
  }

  .footer-author-box {
    justify-content: center;
    width: 100%;
  }

  .footer-author-badge {
    font-size: 0.8rem;
    text-align: center;
  }
}

/* --- TRÈS PETITS SMARTPHONES (<= 480px) --- */
@media (max-width: 480px) {
  .app-container {
    padding: 0.5rem;
    gap: 0.75rem;
  }

  .header-actions-row {
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
  }

  .header-tools-grid-2x2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
    gap: 0.3rem;
  }

  .header-tools-grid-2x2 .btn-icon-text {
    padding: 6px 4px;
    font-size: 0.74rem;
    min-height: 32px;
  }

  .header-tools-grid-2x2 .btn-lbl {
    display: inline !important;
  }

  .header-utility-actions {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 0.4rem;
  }

  .header-utility-actions .btn-lbl {
    display: none; /* Icon-only pour Sons et Thème sur petits smartphones */
  }

  .header-utility-actions .btn-utility-action {
    padding: 5px 12px;
    font-size: 0.88rem;
    min-height: 30px;
  }

  .virtual-math-keyboard {
    grid-template-columns: repeat(6, 1fr) !important;
    gap: 0.25rem;
  }

  .key-btn {
    min-height: 38px;
    padding: 6px 1px;
    font-size: 0.88rem;
  }

  .exercise-card {
    padding: 0.85rem;
  }

  .exo-title {
    font-size: 1.05rem;
  }

  .exo-body {
    font-size: 0.95rem;
  }

  .math-text-input {
    font-size: 1.05rem;
    padding: 0.65rem 0.75rem;
  }
}

/* ==========================================================================
   OPTIMISATIONS AVANCÉES DU MODE FONCÉ (HAUTE LISIBILITÉ & CONTRASTE OPTIMAL)
   ========================================================================== */

[data-theme="dark"] body {
  background-color: var(--bg-primary);
  color: var(--text-main);
}

/* En-tête & Sélecteur de niveau */
[data-theme="dark"] .app-header {
  background-color: #162032;
  border-bottom: 1px solid #283548;
}

[data-theme="dark"] .cycle4-level-nav {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .cycle4-label {
  color: #94a3b8;
}

[data-theme="dark"] .level-pill {
  color: #cbd5e1;
}

[data-theme="dark"] .level-pill:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

[data-theme="dark"] .level-pill.active {
  background-color: #3b82f6;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

[data-theme="dark"] .status-pill {
  background-color: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .btn-icon-text {
  background-color: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .btn-icon-text:hover {
  background-color: #283548;
  border-color: #60a5fa;
  color: #ffffff;
}

/* Barre latérale & Cartes chapitres */
[data-theme="dark"] .sidebar-chapters {
  background-color: #162032;
  border-color: #283548;
}

[data-theme="dark"] .sidebar-search-box {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .sidebar-search-box input {
  color: #f8fafc;
}

[data-theme="dark"] .sidebar-search-box input::placeholder {
  color: #64748b;
}

[data-theme="dark"] .domain-filter-btn {
  background-color: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

[data-theme="dark"] .domain-filter-btn:hover {
  border-color: #60a5fa;
  color: #60a5fa;
  background-color: #243044;
}

[data-theme="dark"] .domain-filter-btn.active {
  background-color: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
  font-weight: 700;
}

[data-theme="dark"] .chapter-card {
  background-color: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .chapter-card:hover {
  background-color: #253347;
  border-color: #475569;
}

[data-theme="dark"] .chapter-card.active {
  background-color: rgba(59, 130, 246, 0.18);
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px #60a5fa, 0 2px 10px rgba(59, 130, 246, 0.25);
}

[data-theme="dark"] .chapter-card.active .chap-title {
  color: #ffffff;
  font-weight: 700;
}

[data-theme="dark"] .chap-desc {
  color: #94a3b8;
}

[data-theme="dark"] .chap-badge-id {
  background-color: rgba(255, 255, 255, 0.08) !important;
  color: #f1f5f9 !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  font-weight: 800;
}

[data-theme="dark"] .chapter-card.active .chap-badge-id {
  background-color: #3b82f6 !important;
  color: #ffffff !important;
  border-color: #3b82f6 !important;
}

[data-theme="dark"] .domain-pill,
[data-theme="dark"] .domain-tag {
  background-color: rgba(59, 130, 246, 0.2) !important;
  color: #93c5fd !important;
  border: 1px solid rgba(147, 197, 253, 0.3) !important;
}

[data-theme="dark"] .pill-fill {
  background-color: #34d399;
  opacity: 0.55;
}

[data-theme="dark"] .pill-text {
  color: #ffffff;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .mastery-code {
  color: #93c5fd !important;
}

[data-theme="dark"] .mastery-bar-wrapper {
  background-color: #283548;
}

[data-theme="dark"] .mastery-bar-fill {
  background: linear-gradient(90deg, #3b82f6, #10b981) !important;
}

/* Hero Bannière du Chapitre */
[data-theme="dark"] .chapter-hero-banner {
  background: linear-gradient(135deg, #1e293b 0%, #172233 100%);
  border-color: #334155;
}

[data-theme="dark"] .hero-mastery-gauge {
  background-color: #162032;
  border-color: #334155;
}

[data-theme="dark"] .gauge-value {
  color: #60a5fa;
}

/* Onglets de navigation */
[data-theme="dark"] .tabs-navigation-bar {
  border-bottom-color: #334155;
}

[data-theme="dark"] .tab-btn {
  color: #94a3b8;
}

[data-theme="dark"] .tab-btn:hover {
  background-color: #243044;
  color: #f8fafc;
}

[data-theme="dark"] .tab-btn.active {
  background-color: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  font-weight: 700;
}

/* Panneau de contrôle ZPD & Boutons Paliers */
[data-theme="dark"] .adaptive-control-panel {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .tier-pill-btn {
  background-color: #162032;
  border-color: #334155;
  color: #cbd5e1;
}

[data-theme="dark"] .tier-pill-btn:hover {
  background-color: #243044;
  color: #ffffff;
}

/* Espace Exercice & Entraînement */
[data-theme="dark"] .exercise-workspace-box {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .exo-title {
  color: #f8fafc;
}

[data-theme="dark"] .exo-body {
  color: #f1f5f9;
}

[data-theme="dark"] .exo-skill-tag {
  background-color: #162032;
  color: #94a3b8;
  border: 1px solid #283548;
}

/* QCM Boutons */
[data-theme="dark"] .mcq-opt-btn {
  background-color: #162032;
  border-color: #334155;
  color: #f8fafc;
}

[data-theme="dark"] .mcq-opt-btn:hover {
  background-color: #243044;
  border-color: #60a5fa;
}

[data-theme="dark"] .mcq-opt-btn.selected {
  background-color: rgba(59, 130, 246, 0.2);
  border-color: #60a5fa;
  box-shadow: 0 0 0 1px #60a5fa;
}

[data-theme="dark"] .mcq-letter {
  background-color: #243044;
  color: #cbd5e1;
  border: 1px solid #334155;
}

[data-theme="dark"] .mcq-opt-btn.selected .mcq-letter {
  background-color: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
}

[data-theme="dark"] .mcq-opt-btn.correct {
  background-color: rgba(16, 185, 129, 0.2) !important;
  border-color: #10b981 !important;
  color: #ecfdf5 !important;
}

[data-theme="dark"] .mcq-opt-btn.wrong {
  background-color: rgba(239, 68, 68, 0.2) !important;
  border-color: #ef4444 !important;
  color: #fef2f2 !important;
}

/* Saisie Mathématique & Clavier Virtuel */
[data-theme="dark"] .math-text-input {
  background-color: #151e2e;
  border-color: #3e4c63;
  color: #f8fafc;
}

[data-theme="dark"] .math-text-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.25);
}

[data-theme="dark"] .math-preview-badge {
  background-color: rgba(59, 130, 246, 0.18);
  border-color: rgba(96, 165, 250, 0.4);
  color: #93c5fd;
}

[data-theme="dark"] .virtual-keyboard-section {
  background-color: #162032;
  border-color: #283548;
}

[data-theme="dark"] .key-btn {
  background-color: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .key-btn:hover {
  background-color: #283548;
  border-color: #60a5fa;
  color: #ffffff;
}

[data-theme="dark"] .key-btn.action-key {
  background-color: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border-color: rgba(96, 165, 250, 0.35);
}

/* Boutons secondaires & d'action */
[data-theme="dark"] .btn-secondary {
  background-color: #1e293b;
  border-color: #334155;
  color: #cbd5e1;
}

[data-theme="dark"] .btn-secondary:hover {
  background-color: #283548;
  border-color: #60a5fa;
  color: #ffffff;
}

/* Cartes de cours & fiches */
[data-theme="dark"] .course-card {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .course-card h3 {
  color: #60a5fa;
}

[data-theme="dark"] .course-method {
  border-left: 4px solid #3b82f6;
  background-color: #1e293b;
}

[data-theme="dark"] .method-example {
  background-color: #151e2e;
  border: 1px solid #283548;
  color: #f1f5f9;
}

[data-theme="dark"] .method-step-item {
  background-color: #182334;
  border-left: 3px solid #60a5fa;
  color: #cbd5e1;
}

[data-theme="dark"] .course-traps {
  border-left: 4px solid #f59e0b;
}

[data-theme="dark"] .course-traps h3 {
  color: #fde68a;
}

[data-theme="dark"] .callout-info {
  background-color: rgba(59, 130, 246, 0.12) !important;
  border-left: 4px solid #3b82f6 !important;
  color: #f1f5f9 !important;
}

[data-theme="dark"] .callout-info a {
  color: #93c5fd !important;
  text-decoration: underline;
}

/* Flashcards */
[data-theme="dark"] .flashcard-card {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .flashcard-question-box {
  background-color: #162032;
  border-color: #283548;
  color: #f8fafc;
}

[data-theme="dark"] .flashcard-answer-box {
  background-color: rgba(16, 185, 129, 0.18);
  border-color: #10b981;
  color: #a7f3d0;
}

[data-theme="dark"] .flashcard-btn-action {
  background-color: #243044;
  border-color: #3e4c63;
  color: #f1f5f9;
}

[data-theme="dark"] .flashcard-btn-action:hover {
  background-color: rgba(59, 130, 246, 0.2);
  border-color: #60a5fa;
  color: #60a5fa;
}

/* Rendu des formules KaTeX en mode sombre */
[data-theme="dark"] .katex {
  color: #f8fafc;
}

[data-theme="dark"] .katex-display {
  color: #f8fafc;
}

[data-theme="dark"] .katex .frac-line,
[data-theme="dark"] .katex .sqrt-line {
  border-color: #cbd5e1;
}

/* Fiche d'entraînement à l'écran en mode sombre */
[data-theme="dark"] .printable-worksheet {
  background-color: #1e293b;
  border-color: #334155;
  color: #f8fafc;
}

[data-theme="dark"] #sheet-solution-wrapper,
[data-theme="dark"] .solution-content,
[data-theme="dark"] .recap-solution {
  background-color: var(--bg-surface-elevated);
  color: var(--text-main);
  border-color: var(--border-color);
}

/* Modales d'interaction */
[data-theme="dark"] .modal-box {
  background-color: #1e293b;
  border-color: #334155;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
}

[data-theme="dark"] .modal-header {
  border-bottom-color: #334155;
}

[data-theme="dark"] .modal-footer {
  background-color: #162032;
  border-top-color: #334155;
}

[data-theme="dark"] .diapo-chip {
  background-color: #162032;
  border-color: #334155;
  color: #cbd5e1;
}

[data-theme="dark"] .diapo-chip:hover {
  background-color: rgba(59, 130, 246, 0.18);
  border-color: #60a5fa;
  color: #ffffff;
}

[data-theme="dark"] .diapo-chip input[type="checkbox"]:checked + span {
  color: #60a5fa;
}

[data-theme="dark"] .diapo-top-hud {
  background-color: #162032;
  border-bottom-color: #334155;
}

[data-theme="dark"] .form-select {
  background-color: #162032;
  border-color: #334155;
  color: #f8fafc;
}

/* Prévisualisation à l'écran du Devoir Blanc en mode sombre */
[data-theme="dark"] .quiz-scroll-preview {
  background-color: #0f172a;
}

[data-theme="dark"] .printable-quiz-sheet {
  background-color: #151e2e;
  color: #f8fafc;
  border: 1px solid #334155;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .quiz-single-subject,
[data-theme="dark"] .quiz-solutions-teacher {
  background-color: #1e293b;
  border: 1px solid #3e4c63;
  color: #f8fafc;
}

[data-theme="dark"] .quiz-header-box {
  border-bottom: 2px solid #3e4c63;
}

[data-theme="dark"] .quiz-q-card,
[data-theme="dark"] .quiz-sol-card {
  background-color: #162032;
  border: 1px solid #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .quiz-q-header,
[data-theme="dark"] .quiz-sol-header {
  border-bottom: 1px solid #283548;
}

[data-theme="dark"] .quiz-badge-theme {
  background-color: #283548;
  border-color: #475569;
  color: #94a3b8;
}

/* Flashcards en Mode Sombre */
[data-theme="dark"] .fc-intro-banner {
  background-color: #162032;
  border-bottom-color: #334155;
}

[data-theme="dark"] .fc-card-face {
  background-color: #1e293b;
  border-color: #334155;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .fc-card-front {
  background: linear-gradient(145deg, #1e293b, #0f172a);
}

[data-theme="dark"] .fc-card-back {
  background: linear-gradient(145deg, rgba(16, 185, 129, 0.08), #1e293b);
  border-color: rgba(16, 185, 129, 0.4);
}

[data-theme="dark"] .fc-actions-dock {
  background-color: #162032;
  border-top-color: #334155;
}

[data-theme="dark"] .btn-fc-eval {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .fc-stat-card,
[data-theme="dark"] .fc-box-col,
[data-theme="dark"] .fc-pill-badge {
  background-color: #162032;
  border-color: #334155;
}

[data-theme="dark"] .quiz-banner-notice {
  background-color: rgba(59, 130, 246, 0.15);
  border-left: 4px solid #3b82f6;
  color: #bfdbfe;
}

[data-theme="dark"] .quiz-author-line {
  color: #94a3b8;
}

[data-theme="dark"] .quiz-author-line strong {
  color: #f8fafc;
}

[data-theme="dark"] .quiz-student-meta {
  color: #cbd5e1;
}

[data-theme="dark"] .quiz-grade-box {
  background-color: #283548;
  border-color: #475569;
  color: #f8fafc;
}

[data-theme="dark"] .teacher-header p {
  color: #94a3b8 !important;
}

/* Passeport & Trophées */
[data-theme="dark"] .stats-section {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .badge-item {
  background-color: #162032;
  border-color: #334155;
}

[data-theme="dark"] .badge-item.unlocked {
  background-color: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
}

[data-theme="dark"] .chapter-trophy-card {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .chapter-single-rank-banner {
  background: #162032;
  border-color: #334155;
}

[data-theme="dark"] .chapter-trophy-card.unlocked .chapter-single-rank-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(234, 179, 8, 0.15));
  border-color: rgba(234, 179, 8, 0.45);
}

[data-theme="dark"] .chapter-trophy-card.unlocked .rank-single-status {
  color: #fbbf24;
}

[data-theme="dark"] .chapter-trophy-card.unlocked.tier-4 .chapter-single-rank-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.22), rgba(6, 182, 212, 0.22));
  border-color: rgba(52, 211, 153, 0.7);
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.25);
}

[data-theme="dark"] .chapter-trophy-card.unlocked.tier-4 .rank-single-status {
  color: #34d399;
}

[data-theme="dark"] .chapter-trophy-card.locked .chapter-single-rank-banner {
  background: #162032;
  border-color: #334155;
}

[data-theme="dark"] .passport-author-banner {
  background-color: #1e293b;
  border-color: #334155;
}

[data-theme="dark"] .app-footer {
  background-color: #162032;
  border-top-color: #283548;
}

[data-theme="dark"] .footer-author-badge {
  background-color: #1e293b;
  border-color: #334155;
  color: #f8fafc;
}

[data-theme="dark"] .brand-logo-img,
[data-theme="dark"] .footer-logo-img {
  border: 1px solid #334155;
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.15);
}

[data-theme="dark"] .brand-container:hover .brand-logo-img {
  box-shadow: 0 4px 16px rgba(56, 189, 248, 0.35);
}

[data-theme="dark"] .mobile-chapter-btn {
  background-color: #1e293b;
  border-color: #334155;
  color: #f8fafc;
}

[data-theme="dark"] .mobile-chapter-btn:hover {
  background-color: #283548;
  border-color: #38bdf8;
}

[data-theme="dark"] .m-chap-badge {
  background-color: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

[data-theme="dark"] .sidebar-chapters.mobile-open {
  border-color: #38bdf8;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  background-color: #162032;
}

[data-theme="dark"] .tabs-navigation-bar {
  background: #162032 !important;
  border-top-color: #283548 !important;
  box-shadow: 0 -3px 15px rgba(0, 0, 0, 0.4) !important;
}

[data-theme="dark"] .tab-btn.active {
  color: #38bdf8 !important;
}

[data-theme="dark"] .exercise-workspace-box {
  background-color: #1e293b !important;
  border-color: #334155 !important;
  border-top-color: #38bdf8 !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35) !important;
}

[data-theme="dark"] .m-chap-mastery-pill {
  background-color: #283548;
  border-color: #475569;
  color: #94a3b8;
}

[data-theme="dark"] .m-chap-mastery-pill.mid {
  background-color: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.4);
}

[data-theme="dark"] .m-chap-mastery-pill.high {
  background-color: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.4);
}

/* ==========================================================================
   POPUP CÉLÉBRATION PALIER & RANG DÉBLOQUÉ (10 SECONDES)
   ========================================================================== */
.reward-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100000;
  padding: 1.25rem;
  animation: rewardFadeIn 0.3s ease-out forwards;
}

@keyframes rewardFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.reward-modal-card {
  position: relative;
  background: var(--bg-surface, #ffffff);
  border: 2px solid rgba(245, 158, 11, 0.45);
  border-radius: 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45), 0 0 45px rgba(245, 158, 11, 0.28);
  width: 100%;
  max-width: 480px;
  padding: 2.25rem 1.85rem 1.65rem;
  text-align: center;
  animation: rewardPopIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  overflow: hidden;
  box-sizing: border-box;
}

@keyframes rewardPopIn {
  0% {
    opacity: 0;
    transform: scale(0.8) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.reward-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color, #e2e8f0);
  background: var(--bg-hover, #f1f5f9);
  color: var(--text-muted, #64748b);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 2;
}

.reward-modal-close:hover {
  background: var(--border-color, #cbd5e1);
  color: var(--text-main, #0f172a);
  transform: scale(1.1);
}

.reward-badge-halo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.3) 0%, rgba(245, 158, 11, 0.05) 60%, transparent 75%);
  margin: 0 auto 0.75rem;
  animation: rewardBadgePulse 2s infinite ease-in-out;
}

@keyframes rewardBadgePulse {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 0 10px rgba(245, 158, 11, 0.4));
  }
  50% {
    transform: scale(1.08);
    filter: drop-shadow(0 0 22px rgba(245, 158, 11, 0.75));
  }
}

.reward-badge-icon {
  font-size: 4rem;
  line-height: 1;
  user-select: none;
}

.reward-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d97706;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 0.35rem 0.9rem;
  border-radius: 9999px;
  margin-bottom: 0.65rem;
}

[data-theme="dark"] .reward-tag {
  color: #fbbf24;
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.4);
}

.reward-title {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-main, #0f172a);
  margin: 0 0 0.35rem;
  line-height: 1.25;
}

.reward-chap-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted, #64748b);
  margin-bottom: 1rem;
}

.reward-description-box {
  background: var(--bg-hover, #f8fafc);
  border: 1px solid var(--border-color, #e2e8f0);
  border-radius: 14px;
  padding: 0.95rem 1.15rem;
  font-size: 0.93rem;
  line-height: 1.55;
  color: var(--text-main, #1e293b);
  margin-bottom: 1.1rem;
  text-align: center;
}

[data-theme="dark"] .reward-description-box {
  background: #1e293b;
  border-color: #334155;
  color: #f1f5f9;
}

.reward-perk-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1.35rem;
}

.reward-perk-pill {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.35rem 0.8rem;
  border-radius: 9999px;
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary, #4f46e5);
  border: 1px solid rgba(99, 102, 241, 0.25);
}

[data-theme="dark"] .reward-perk-pill {
  background: rgba(99, 102, 241, 0.22);
  color: #a5b4fc;
}

.reward-timer-wrapper {
  margin-bottom: 1.35rem;
}

.reward-timer-bar {
  width: 100%;
  height: 6px;
  background: var(--border-color, #e2e8f0);
  border-radius: 9999px;
  overflow: hidden;
  margin-bottom: 0.45rem;
}

[data-theme="dark"] .reward-timer-bar {
  background: #334155;
}

.reward-timer-progress {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #f59e0b, #10b981);
  border-radius: 9999px;
  transition: width 0.1s linear;
}

.reward-timer-label {
  font-size: 0.82rem;
  color: var(--text-muted, #64748b);
  font-weight: 500;
}

.reward-timer-label strong {
  color: var(--text-main, #0f172a);
  font-weight: 700;
}

[data-theme="dark"] .reward-timer-label strong {
  color: #f8fafc;
}

.reward-action-btn {
  width: 100%;
  padding: 0.95rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
  transition: all 0.2s ease;
}

.reward-action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.5);
}

@media (max-width: 480px) {
  .reward-modal-card {
    padding: 1.6rem 1.15rem 1.35rem;
    border-radius: 20px;
  }
  .reward-badge-halo {
    width: 80px;
    height: 80px;
    margin-bottom: 0.5rem;
  }
  .reward-badge-icon {
    font-size: 3.2rem;
  }
  .reward-title {
    font-size: 1.32rem;
  }
  .reward-description-box {
    font-size: 0.86rem;
    padding: 0.8rem 0.9rem;
  }
}

/* =========================================================================
   SÉRIE QUOTIDIENNE (DAILY STREAK) & MODALE EXPLICATIVE
   ========================================================================= */
.status-pill-clickable {
  cursor: pointer;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}

.status-pill-clickable:hover {
  transform: translateY(-1px);
  background-color: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.5);
}

.streak-modal-box {
  max-width: 520px;
  width: 92%;
  border-radius: 18px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: modalPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.streak-modal-body {
  padding: 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.streak-hero-card {
  text-align: center;
  padding: 1.35rem 1rem;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(239, 68, 68, 0.08));
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 14px;
}

.streak-hero-flame {
  font-size: 3.2rem;
  animation: flamePulse 1.8s infinite ease-in-out;
  display: inline-block;
  margin-bottom: 0.2rem;
}

@keyframes flamePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.streak-hero-count {
  font-size: 2.2rem;
  font-weight: 800;
  color: #d97706;
  letter-spacing: -0.02em;
}

[data-theme="dark"] .streak-hero-count {
  color: #fbbf24;
}

.streak-hero-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  font-weight: 500;
}

.streak-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.streak-stat-card {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 0.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.streak-stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.streak-stat-val {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.streak-explanation-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text-primary);
}

.streak-explanation-box h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.streak-explanation-box ul {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@media (max-width: 480px) {
  .streak-stats-row {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
}

/* Grille des trophées de régularité dans la modale streak */
.streak-trophies-section {
  display: flex;
  flex-direction: column;
}

.streak-trophies-modal-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.55rem;
}

@media (max-width: 460px) {
  .streak-trophies-modal-grid {
    grid-template-columns: 1fr;
  }
}

.streak-trophy-modal-card {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.streak-trophy-modal-card.unlocked {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.45);
}

.streak-trophy-modal-card.locked {
  opacity: 0.72;
}

.streak-trophy-icon {
  font-size: 1.45rem;
  line-height: 1;
  flex-shrink: 0;
}

.streak-trophy-details {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.streak-trophy-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
}

.streak-trophy-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.streak-trophy-pill {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background-color: var(--border-color);
  color: var(--text-muted);
  white-space: nowrap;
}

.streak-trophy-modal-card.unlocked .streak-trophy-pill {
  background-color: rgba(245, 158, 11, 0.2);
  color: #d97706;
}

[data-theme="dark"] .streak-trophy-modal-card.unlocked .streak-trophy-pill {
  color: #fbbf24;
}

.streak-trophy-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.streak-trophy-progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.streak-trophy-bar-bg {
  flex: 1;
  height: 5px;
  background-color: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.streak-trophy-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.streak-trophy-progress-lbl {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
}

.streak-trophy-modal-card.unlocked .streak-trophy-progress-lbl {
  color: var(--success, #10b981);
}

/* =========================================================================
   MODALE : PROGRESSION DU NIVEAU & EXPÉRIENCE (XP)
   ========================================================================= */
.level-modal-box {
  max-width: 480px;
  width: 92%;
  border-radius: 18px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: modalPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

.level-modal-body {
  padding: 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.level-hero-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.15rem 1.25rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(139, 92, 246, 0.1));
  border: 1px solid rgba(59, 130, 246, 0.3);
  border-radius: 14px;
}

.level-badge-circle {
  width: 58px;
  height: 58px;
  min-width: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-badge-number {
  font-size: 1.7rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.level-hero-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.level-hero-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.level-hero-rank {
  font-size: 0.88rem;
  font-weight: 600;
  color: #2563eb;
}

[data-theme="dark"] .level-hero-rank {
  color: #60a5fa;
}

.level-xp-card {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.level-xp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
}

.level-xp-step-label {
  color: var(--text-primary);
  font-weight: 500;
}

.level-xp-values {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.level-xp-values strong {
  color: var(--text-primary);
  font-size: 0.95rem;
}

.level-progress-bar-bg {
  height: 14px;
  background-color: var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.level-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  border-radius: 8px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.level-xp-remaining-banner {
  text-align: center;
  font-size: 0.86rem;
  padding: 0.5rem 0.75rem;
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 8px;
  color: var(--text-primary);
}

.level-stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.level-stat-item {
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem 0.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.level-stat-lbl {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.level-stat-val {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.level-tips-box {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.9rem 1.1rem;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-primary);
}

.level-tips-box h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.92rem;
  color: var(--text-primary);
}

.level-tips-box ul {
  margin: 0;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
