:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #1e2433;
  --ink-soft: #5a6478;
  --muted: #8a93a6;
  --line: #e4e8f0;
  --brand: #2563eb;
  --brand-soft: #dbe7ff;
  --conf-1: #ef4444; /* à revoir */
  --conf-2: #f59e0b; /* fragile */
  --conf-3: #22c55e; /* acquis */
  --conf-0: #cbd2df; /* non évalué */
  --shadow: 0 1px 3px rgba(20, 30, 60, .06), 0 6px 20px rgba(20, 30, 60, .05);
  --radius: 14px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px;
  background: linear-gradient(120deg, #1e3a8a, #2563eb 60%, #3b82f6);
  color: #fff;
  position: sticky; top: 0; z-index: 20;
  box-shadow: 0 2px 10px rgba(20, 30, 60, .18);
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.brand { font-size: 1.15rem; font-weight: 700; letter-spacing: .2px; }
.brand-arrow { opacity: .85; font-weight: 600; }
.phase-badge {
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  padding: 4px 12px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 20px; }
.countdown { text-align: right; line-height: 1.05; }
.countdown-num { font-size: 1.7rem; font-weight: 800; }
.countdown-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .6px; opacity: .85; }
/* Indicateur de sauvegarde (topbar) — montre que la saisie est enregistrée automatiquement */
.topbar #syncStatus {
  font-size: .74rem; font-weight: 600; padding: 5px 12px; border-radius: 999px;
  white-space: nowrap; border: 1px solid transparent; transition: background .2s, color .2s;
}
.topbar #syncStatus[data-mode="saved"] { background: rgba(34,197,94,.28); color: #eafff0; border-color: rgba(220,252,231,.45); }
.topbar #syncStatus[data-mode="local"] { background: rgba(255,255,255,.15); color: rgba(255,255,255,.92); }
.topbar #syncStatus[data-mode="saving"] { background: rgba(255,255,255,.24); color: #fff; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 61px; z-index: 15; overflow-x: auto;
}
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 14px 16px; font-size: .95rem; font-weight: 600; color: var(--ink-soft);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Layout ---------- */
.wrap { max-width: 1100px; margin: 0 auto; padding: 26px 22px 60px; }
.panel { display: none; animation: fade .25s ease; }
.panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.intro-card { margin-bottom: 22px; }
.intro-card h1 { font-size: 1.5rem; margin: 0 0 8px; }
.intro-card p { color: var(--ink-soft); max-width: 760px; margin: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; margin: 0 0 10px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.method-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.method-grid ul { margin: 0; padding-left: 18px; }
.method-grid li { margin-bottom: 8px; color: var(--ink-soft); }
.method-grid li strong { color: var(--ink); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
a { color: var(--brand); }

/* ---------- Stat grid (avancement matières) ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.10); border-color: var(--brand); }
.stat:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* Surbrillance temporaire de la section ciblée après un clic depuis le tableau de bord. */
@keyframes subjectFlash { 0% { background: #eef3ff; } 100% { background: transparent; } }
.subject-highlight { animation: subjectFlash 1.6s ease-out; border-radius: 12px; }
.stat-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-title { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.stat-ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-size: .95rem; }
.stat-pct { font-weight: 800; font-size: 1.1rem; }
.bar { height: 9px; border-radius: 999px; background: #eef1f7; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; transition: width .4s ease; }
.stat-sub { margin-top: 8px; font-size: .78rem; color: var(--muted); display: flex; gap: 12px; }

/* ---------- Priority list ---------- */
.priority-list { margin: 6px 0 0; padding-left: 20px; }
.priority-list li { margin-bottom: 7px; }
.priority-list .pl-mat { color: var(--muted); font-size: .8rem; }
.priority-empty { color: var(--muted); font-style: italic; }

/* ---------- Timeline ---------- */
.timeline { display: flex; flex-direction: column; gap: 10px; }
.tl-step { display: flex; gap: 12px; align-items: flex-start; }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--conf-0); }
.tl-step.done .tl-dot { background: var(--conf-3); }
.tl-step.current .tl-dot { background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.tl-body { flex: 1; }
.tl-name { font-weight: 600; }
.tl-name.current { color: var(--brand); }
.tl-meta { font-size: .8rem; color: var(--muted); }

/* ---------- Matieres ---------- */
.matieres-legend {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 16px; color: var(--ink-soft); font-size: .9rem;
}
.matieres-legend .dot { width: 13px; height: 13px; border-radius: 50%; display: inline-block; }
.matieres-legend .sep { flex: 1; }
.fold-actions { display: flex; align-items: center; gap: 6px; }
.fold-divider { color: var(--line); }
.btn-link { border: 0; background: none; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600; color: var(--brand); padding: 2px 4px; }
.btn-link:hover { text-decoration: underline; }
/* Boutons-icônes plier / déplier (chevrons) */
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  border-radius: 8px; cursor: pointer; transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: #eef3ff; color: var(--brand); border-color: var(--brand); }
.icon-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.icon-btn svg { display: block; }
.dot.conf-1 { background: var(--conf-1); }
.dot.conf-2 { background: var(--conf-2); }
.dot.conf-3 { background: var(--conf-3); }

.subject { margin-bottom: 22px; }
.subject-head {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
  cursor: pointer; user-select: none; border-radius: 10px; padding: 4px 6px; margin-left: -6px;
}
.subject-head:hover { background: #eef1f7; }
.subject-head:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.chevron { color: var(--muted); font-size: .9rem; width: 14px; transition: transform .2s ease; }
.subject.collapsed .chevron { transform: rotate(-90deg); }
.subject-body { overflow: hidden; }
.subject.collapsed .subject-body { display: none; }
.subject-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-size: 1.2rem; }
.subject-head h2 { margin: 0; font-size: 1.2rem; }
.subject-head .count { color: var(--muted); font-size: .85rem; font-weight: 500; }

.chapter {
  background: var(--surface); border: 1px solid var(--line); border-left-width: 4px;
  border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
  display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: start;
}
.conf-btn {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line);
  cursor: pointer; background: var(--conf-0); margin-top: 2px; transition: background .15s, transform .1s;
}
.conf-btn:hover { transform: scale(1.12); }
.conf-btn[data-conf="1"] { background: var(--conf-1); border-color: var(--conf-1); }
.conf-btn[data-conf="2"] { background: var(--conf-2); border-color: var(--conf-2); }
.conf-btn[data-conf="3"] { background: var(--conf-3); border-color: var(--conf-3); }

.ch-titleline { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ch-main .ch-title { font-weight: 600; }
.ch-links { flex: none; display: flex; align-items: baseline; gap: 12px; }
.ch-fiche-link, .ch-exos-link {
  border: 0; background: none; cursor: pointer; font: inherit; font-size: .78rem;
  font-weight: 600; color: var(--brand); padding: 0; white-space: nowrap;
}
.ch-fiche-link:hover, .ch-exos-link:hover { text-decoration: underline; }
.ch-main .ch-note { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.ch-note-input {
  margin-top: 8px; width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font: inherit; font-size: .85rem; resize: vertical; min-height: 34px;
  color: var(--ink); background: #fafbfe;
}
.ch-checks { display: flex; flex-direction: column; gap: 6px; font-size: .82rem; color: var(--ink-soft); }
.ch-checks label { display: flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; }

/* ---------- Fiches ---------- */
.fiches-layout { display: grid; grid-template-columns: 250px 1fr; gap: 20px; align-items: start; }

.fiches-index {
  position: sticky; top: 112px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); max-height: calc(100vh - 140px); overflow-y: auto;
}
.fi-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.fi-bar-label { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.fi-group { margin-bottom: 6px; }
.fi-group-head {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; cursor: pointer;
  border: 0; background: none; font: inherit; font-weight: 700; font-size: .9rem; color: var(--ink);
  padding: 6px 6px; border-radius: 8px;
}
.fi-group-head:hover { background: #f1f4fa; }
.fi-group-head:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.fi-group-name { flex: 1; }
.fi-count { flex: none; color: var(--muted); font-weight: 600; font-size: .74rem; background: #eef1f7; border-radius: 10px; padding: 1px 8px; }
.fi-chevron { color: var(--muted); font-size: .8rem; width: 12px; flex: none; transition: transform .2s ease; }
.fi-group.collapsed .fi-chevron { transform: rotate(-90deg); }
.fi-group-body { margin: 2px 0 8px; }
.fi-group.collapsed .fi-group-body { display: none; }
.fi-ico { width: 22px; height: 22px; border-radius: 7px; display: inline-grid; place-items: center; color: #fff; font-size: .8rem; flex: none; }
.fi-item {
  display: block; width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: .88rem; color: var(--ink-soft); padding: 7px 10px; border-radius: 8px;
  border-left: 3px solid transparent; line-height: 1.3;
}
.fi-item:hover { background: #f1f4fa; color: var(--ink); }
.fi-item.active { background: #eef3ff; color: var(--ink); font-weight: 600; border-left-color: var(--accent); }
.fi-foot { padding: 6px 10px 2px; border-top: 1px solid var(--line); margin-top: 6px; }

/* ---------- Exercices ---------- */
.exos-group-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .9rem; margin: 4px 0 6px; }
.fi-item .exos-count { color: var(--muted); font-weight: 600; font-size: .74rem; background: #eef1f7; border-radius: 10px; padding: 1px 8px; }
#exosIndex .fi-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.exo-card { border: 1px solid var(--line); border-left-width: 4px; border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; background: var(--surface); }
.exo-card.done { border-left-color: var(--conf-3); background: #f4fbf6; }
.exo-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.exo-num { font-weight: 700; }
.exo-niveau { color: #f59e0b; letter-spacing: 2px; font-size: .9rem; }
.exo-titre { color: var(--muted); font-size: .9rem; }
.exo-done { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--ink-soft); cursor: pointer; white-space: nowrap; }
.exo-enonce { line-height: 1.75; color: var(--ink); }
.exo-fold { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.exo-fold > summary { cursor: pointer; font-weight: 600; font-size: .9rem; color: var(--brand); list-style: none; }
.exo-fold > summary::-webkit-details-marker { display: none; }
.exo-corrige > summary { color: var(--conf-3); }
.exo-fold-body { margin-top: 8px; line-height: 1.75; color: var(--ink-soft); }
.exo-fold-body strong { color: var(--ink); }

.fiche-detail {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 28px; box-shadow: var(--shadow); min-height: 300px;
}
.fiche-head { border-left: 4px solid; padding-left: 14px; margin-bottom: 20px; }
.fiche-mat { display: flex; align-items: center; gap: 8px; font-size: .82rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.fiche-head h2 { margin: 6px 0 0; font-size: 1.5rem; }

.fiche-section { margin-bottom: 22px; }
.fiche-section h3 {
  font-size: 1rem; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--line);
  color: var(--ink);
}
.fs-list { margin: 0; padding-left: 20px; }
.fs-list li { margin-bottom: 7px; color: var(--ink-soft); }
.fs-list li strong { color: var(--ink); }

.fs-defs { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.fs-defs dt { font-weight: 700; color: var(--ink); }
.fs-defs dd { margin: 0; color: var(--ink-soft); }

.fs-formulas { display: flex; flex-direction: column; gap: 8px; }
.formula {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: 9px 13px;
}
.formula-name { font-size: .78rem; font-weight: 700; color: var(--muted); min-width: 130px; }
.formula-body { font-family: "Cambria Math", Georgia, "Times New Roman", serif; font-size: 1.05rem; color: var(--ink); }

/* Vecteur : flèche dessinée en CSS au-dessus du symbole (rendu fiable partout,
   contrairement au caractère combinant U+20D7 qui s'affiche en « tofu »). */
.vec { position: relative; display: inline-block; }
.vec::after {
  content: "→";
  position: absolute; left: 50%; top: -0.62em;
  transform: translateX(-50%) scaleX(1.15);
  font-size: 0.6em; font-weight: 400; line-height: 1;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  pointer-events: none;
}
/* Réserve la place de la flèche pour éviter tout chevauchement de ligne. */
.fs-list li, .fs-defs dd, .formula-body { line-height: 1.75; }

/* Accent gauche par type de section */
.fs-pieges h3 { border-bottom-color: #fecaca; }
.fs-pieges .fs-list li { color: #7f1d1d; }
.fs-pieges .fs-list { list-style: "⚠ "; }
.fs-methodes .fs-list li, .fs-methodes ol li { color: var(--ink-soft); }

/* Encadré « Le réflexe » */
.fiche-reflexe {
  display: flex; gap: 12px; align-items: flex-start;
  background: linear-gradient(90deg, #fffbeb, #fff);
  border: 1px solid #fde68a; border-left: 4px solid #f59e0b; border-radius: 10px;
  padding: 12px 15px; margin: 0 0 22px;
}
.reflexe-ico { font-size: 1.1rem; line-height: 1.4; flex: none; }
.reflexe-label { display: block; font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .6px; color: #b45309; margin-bottom: 2px; }
.fiche-reflexe strong { color: var(--ink); }

/* Exercices types */
.fs-exercices .fs-list { list-style: none; padding-left: 4px; }
.fs-exercices .fs-list li { position: relative; padding-left: 22px; color: var(--ink-soft); }
.fs-exercices .fs-list li::before { content: "▸"; position: absolute; left: 4px; color: var(--brand); font-weight: 700; }

/* Teste-toi (questions flash repliables) */
.fs-flash { display: flex; flex-direction: column; gap: 8px; }
.flash-item { border: 1px solid var(--line); border-radius: 9px; background: #fafbfe; overflow: hidden; }
.flash-item summary {
  cursor: pointer; padding: 10px 13px; font-weight: 600; color: var(--ink);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
.flash-item summary::-webkit-details-marker { display: none; }
.flash-item summary::before { content: "?"; display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-size: .78rem; font-weight: 800; flex: none; }
.flash-item[open] summary { border-bottom: 1px dashed var(--line); }
.flash-item[open] summary::before { content: "✓"; background: #dcfce7; color: #16a34a; }
.flash-r { padding: 10px 13px 12px 41px; color: var(--ink-soft); }

/* Liens avec le programme */
.fs-liens { display: flex; flex-direction: column; gap: 8px; }
.lien { display: flex; gap: 10px; align-items: baseline; }
.lien-label {
  flex: none; min-width: 118px; font-size: .72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .5px; color: var(--brand); padding-top: 2px;
}
.lien-txt { color: var(--ink-soft); }

.fiche-notes { margin-top: 26px; border-top: 1px dashed var(--line); padding-top: 16px; }
.fiche-notes h3 { font-size: 1rem; margin: 0 0 8px; }
.fiche-notes textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px;
  font: inherit; font-size: .9rem; resize: vertical; min-height: 70px; color: var(--ink); background: #fafbfe;
}

@media (max-width: 760px) {
  .fiches-layout { grid-template-columns: 1fr; }
  .fiches-index { position: static; max-height: none; }
  .fs-defs { grid-template-columns: 1fr; gap: 2px 0; }
  .fs-defs dd { margin-bottom: 8px; }
}

/* ---------- Planning ---------- */
.phase-block { margin-bottom: 26px; }
.phase-title {
  display: flex; align-items: baseline; gap: 12px; margin: 0 0 4px;
  font-size: 1.15rem;
}
.phase-title .badge { font-size: .72rem; padding: 3px 9px; border-radius: 999px; font-weight: 700; color: #fff; }
.phase-1 .badge { background: #0ea5e9; }
.phase-2 .badge { background: #a855f7; }
.phase-3 .badge { background: #ef4444; }
.phase-desc { color: var(--ink-soft); margin: 0 0 12px; font-size: .92rem; }

.week {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.week.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft), var(--shadow); }
.week-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.week-name { font-weight: 700; }
.week-name .now-tag { font-size: .68rem; background: var(--brand); color: #fff; padding: 2px 7px; border-radius: 999px; margin-left: 8px; vertical-align: middle; }
.week-load { font-size: .8rem; color: var(--muted); }
.week-goals { list-style: none; margin: 0; padding: 0; }
.week-goals li { display: flex; align-items: flex-start; gap: 9px; padding: 5px 0; border-top: 1px dashed var(--line); }
.week-goals li:first-child { border-top: 0; }
.week-goals input { margin-top: 4px; }
.goal-txt { flex: 1; }
.goal-txt.done { text-decoration: line-through; color: var(--muted); }
.goal-tag { font-size: .7rem; padding: 1px 7px; border-radius: 999px; color: #fff; white-space: nowrap; }

/* ---------- Settings ---------- */
.settings-card { margin-bottom: 18px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.settings-grid label { display: flex; flex-direction: column; gap: 5px; font-size: .85rem; font-weight: 600; color: var(--ink-soft); }
.settings-grid input {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; color: var(--ink);
}
.settings-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.danger-card h2 { color: #b91c1c; }

/* ---------- Buttons ---------- */
.btn { border: 0; border-radius: 9px; padding: 9px 15px; font: inherit; font-weight: 600; cursor: pointer; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: rgba(255,255,255,.14); color: inherit; border: 1px solid rgba(255,255,255,.3); }
.tabs .btn-ghost, .settings-actions .btn-ghost { background: #eef1f7; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { filter: brightness(.97); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }

.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 24px; display: flex; flex-direction: column; gap: 4px; align-items: center; }
#syncStatus { font-size: .74rem; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
#syncStatus[data-mode="saved"] { color: #166534; background: #dcfce7; }
#syncStatus[data-mode="local"] { color: var(--muted); background: #eef1f7; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .two-col, .method-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .chapter { grid-template-columns: 24px 1fr; }
  .ch-checks { flex-direction: row; grid-column: 1 / -1; margin-top: 6px; }
  /* Topbar en colonne : le compte à rebours et l'indicateur de sauvegarde passent en pleine largeur. */
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 16px; }
  .topbar-right { width: 100%; justify-content: space-between; gap: 12px; }
  .countdown { text-align: left; }
  /* Les barres collantes (onglets, index des fiches) reposent sur des hauteurs fixes qui sautent
     quand la topbar s'empile : on les rend statiques sur mobile pour éviter les chevauchements. */
  .tabs { position: static; top: auto; padding: 0 10px; }
  .fiches-index { position: static; top: auto; max-height: none; }
  .wrap { padding: 20px 14px 48px; }
  .fiche-detail { padding: 18px 15px; }
  .intro-card h1, .fiche-head h2 { font-size: 1.3rem; }
  .exo-card { padding: 14px 15px; }
  /* Éviter les débordements horizontaux dus au code / SQL / longues formules. */
  .exo-enonce, .exo-fold-body, .fs-list li, .fs-defs dd, .formula-body { overflow-wrap: anywhere; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .brand { font-size: 1rem; }
  .countdown-num { font-size: 1.4rem; }
  /* Titre de chapitre au-dessus de ses liens Fiche / Exercices, pour ne pas serrer sur 320 px. */
  .ch-titleline { flex-direction: column; align-items: flex-start; gap: 4px; }
  .exo-done { margin-left: 0; }
  .settings-actions .btn { width: 100%; }
}

/* ---------- Impression / PDF ---------- */
@media print {
  .topbar, .tabs, .foot, .btn, .conf-btn, .settings-actions, .danger-card, .ch-note-input { display: none !important; }
  .panel { display: block !important; page-break-before: always; }
  #tab-tableau { page-break-before: avoid; }
  body { background: #fff; }
  .card, .week, .stat { box-shadow: none; }
  .subject.collapsed .subject-body { display: block !important; } /* tout imprimer, même replié */
  .fi-group.collapsed .fi-group-body { display: block !important; } /* menu fiches : tout imprimer */
  .chevron, .fold-actions, .fi-chevron, .ch-links, .fi-bar { display: none !important; }
  .exo-fold > .exo-fold-body { display: block !important; } /* exercices : imprimer indications + corrigés */
  .exo-done { display: none !important; }
}
