/* ==========================================================================
   TOUT MON BREVET 2027 — Style Studyfiches (Inspiré Hatier Studyfiches)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Kalam:wght@400;700&family=Nunito:wght@600;700;800&family=Barlow:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  /* Papier blanc pur + bureau neutre doux */
  --desk: #f1f3f6;
  --paper: #ffffff;
  --ink: #1e2d44;
  --ink-soft: #4e5d73;
  --rule: #e4e8ef;

  /* Accents Studyfiches universels */
  --yellow-tab: #f6cb52;
  --yellow-hi: #ffea78;
  --ok: #38a169;
  --ok-soft: #e9f7ef;
  --warn: #e05a47;
  --warn-soft: #fff1ee;

  /* Défaut (Accueil) */
  --p1: #3b7ea1;         /* couleur principale (macaron, onglet, définitions) */
  --p1-soft: #eaf4f9;
  --on-p1: #ffffff;      /* texte sur fond --p1 (contraste ≥ 4,5:1) */
  --p2: #eb8a44;         /* couleur secondaire (titres h3, mémo, flèches) */
  --p2-soft: #fef2e8;
  --on-p2: var(--ink);   /* encre foncée sur fond --p2 lumineux */

  /* Typographie Studygram / Hatier */
  --font-hand: "Kalam", "Marker Felt", "Comic Sans MS", cursive;
  --font-head: "Nunito", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: "Barlow", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --shadow-sheet: 0 2px 6px rgba(30, 45, 68, .05), 0 14px 36px rgba(30, 45, 68, .08);
  --shadow-soft: 0 2px 10px rgba(30, 45, 68, .05);
}

/* Codes couleur exacts par matière (façon Studyfiches Hatier) */
body.maths {
  --p1: #f08a38;         /* Orange vif Hatier Maths */
  --p1-soft: #fff2e6;
  --on-p1: var(--ink);
  --p2: #2b9e97;         /* Turquoise / sarcelle */
  --p2-soft: #e6f6f5;
  --on-p2: var(--ink);
}
body.francais {
  --p1: #de5468;         /* Rouge framboise Hatier Français */
  --p1-soft: #fdeef0;
  --on-p1: #ffffff;
  --p2: #4a6fa5;         /* Bleu ardoise doux */
  --p2-soft: #edf2fa;
  --on-p2: #ffffff;
}
body.histoire {
  --p1: #63b995;         /* Vert menthe Hatier Histoire-Géo EMC */
  --p1-soft: #e8f6f0;
  --on-p1: var(--ink);
  --p2: #eb8a44;         /* Orange abricot / corail */
  --p2-soft: #fdf0e5;
  --on-p2: var(--ink);
}
body.sciences {
  --p1: #2a9d8f;         /* Sarcelle Hatier Sciences */
  --p1-soft: #e6f5f3;
  --on-p1: var(--ink);
  --p2: #7e63b8;         /* Violet lavande */
  --p2-soft: #f2eefb;
  --on-p2: #ffffff;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16.5px;
  line-height: 1.62;
  color: var(--ink);
  background: var(--desk);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--p1); text-underline-offset: 3px; }
b, strong { font-weight: 700; color: var(--ink); }

/* ==========================================================================
   BARRE SUPÉRIEURE ÉPURÉE
   ========================================================================== */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .9rem; flex-wrap: wrap;
  padding: .6rem 1.5rem;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--rule);
}
.topbar .brand {
  font-family: var(--font-hand);
  font-weight: 700; font-size: 1.32rem;
  text-decoration: none; color: var(--ink);
  display: inline-flex; align-items: center; gap: .5rem;
}
.topbar .brand::before {
  content: "STUDY";
  font-family: var(--font-head);
  font-size: .65rem; font-weight: 800; letter-spacing: .08em;
  background: var(--p1); color: var(--on-p1);
  padding: .18rem .5rem; border-radius: 999px;
}
.topbar nav { display: flex; gap: .3rem; flex-wrap: wrap; }
.topbar nav a {
  text-decoration: none; color: var(--ink-soft); font-family: var(--font-head);
  font-weight: 700; font-size: .88rem;
  padding: .36rem .82rem; border-radius: 999px;
  transition: all .15s;
}
.topbar nav a:hover { background: var(--p1-soft); color: var(--ink); }
.topbar nav a.active { background: var(--p1); color: var(--on-p1); }
.topbar .actions { margin-left: auto; display: flex; gap: .4rem; flex-wrap: wrap; }
.btn {
  border: 1.5px solid var(--rule); background: #fff; color: var(--ink);
  font-family: var(--font-head); font-size: .8rem; font-weight: 700;
  padding: .34rem .72rem; border-radius: 999px; cursor: pointer;
  transition: all .15s;
}
.btn:hover { border-color: var(--p1); color: var(--p1); background: var(--p1-soft); }

/* ==========================================================================
   EN-TÊTE STUDYFICHES (Fond blanc, macaron circulaire fait main, titre feutre)
   ========================================================================== */
.hero {
  position: relative;
  max-width: 1160px;
  margin: 1.4rem auto 0;
  padding: 1.6rem 2.4rem 1.4rem;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--rule);
  border-bottom: none;
  box-shadow: var(--shadow-soft);
}
body.portal .hero {
  border-radius: 18px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1.2rem;
  padding: 2rem 2.4rem;
  background:
    radial-gradient(circle at 96% 18%, var(--p1-soft) 0, var(--p1-soft) 130px, transparent 131px),
    radial-gradient(circle at 88% 92%, var(--p2-soft) 0, var(--p2-soft) 95px, transparent 96px),
    var(--paper);
}

.breadcrumb {
  font-family: var(--font-head); font-size: .78rem; font-weight: 700;
  color: var(--ink-soft); margin-bottom: .75rem;
}
.breadcrumb a { color: var(--ink-soft); text-decoration: none; }
.breadcrumb a:hover { color: var(--p1); }

/* En-tête de chapitre avec macaron "Fiche N" injecté par JS */
.sf-header {
  display: flex; align-items: center; gap: 1.3rem; flex-wrap: wrap;
}
.sf-badge {
  width: 74px; height: 74px; flex-shrink: 0;
  border-radius: 52% 48% 51% 49% / 48% 52% 48% 52%;
  border: 3.5px solid var(--p1);
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--p1-soft);
  background: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--p1);
  transform: rotate(-4deg);
}
.sf-badge span {
  font-family: var(--font-hand); font-size: .92rem; line-height: 1; font-weight: 700;
}
.sf-badge strong {
  font-family: var(--font-head); font-size: 1.65rem; line-height: 1.05; color: var(--p1); font-weight: 800;
}

.hero h1 {
  font-family: var(--font-hand);
  font-size: clamp(1.9rem, 3.6vw, 2.65rem);
  font-weight: 700;
  margin: 0 0 .35rem;
  line-height: 1.12;
  color: var(--ink);
  display: inline-block;
  position: relative;
  padding-bottom: .35rem;
}
/* Trait fin souligné façon feutre sous le titre */
.hero h1::after {
  content: "";
  display: block;
  height: 3px;
  margin-top: .25rem;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--p1) 0%, var(--p1) 70%, transparent 100%);
}
.hero h1 span { color: var(--ink); }
.sf-rays {
  display: inline-block; vertical-align: top; margin-left: .25rem;
  color: var(--p2); width: 26px; height: 26px;
}
.hero p {
  color: var(--ink-soft); margin: .45rem 0 0; max-width: 820px; font-size: .98rem;
}

/* ==========================================================================
   BARRE D'ONGLETS (Intercalaires colorés)
   ========================================================================== */
.tabs-bar {
  position: sticky; top: 53px; z-index: 20;
  max-width: 1160px; margin: 0 auto;
  background: #fff;
  border-left: 1px solid var(--rule);
  border-right: 1px solid var(--rule);
  border-bottom: 2.5px solid var(--p1);
  padding: .45rem 1.8rem 0;
}
.tabs-inner { display: flex; gap: .4rem; flex-wrap: wrap; align-items: flex-end; }
.tab-btn {
  border: 2px solid transparent; border-bottom: none;
  background: var(--p1-soft); color: var(--ink-soft);
  font-family: var(--font-head); font-size: .88rem; font-weight: 800;
  padding: .55rem 1.1rem .6rem;
  border-radius: 12px 12px 0 0;
  cursor: pointer; transition: all .15s;
  position: relative; top: 2px;
}
.tab-btn:hover { color: var(--p1); }
.tab-btn.active {
  background: var(--p1); color: var(--on-p1); border-color: var(--p1);
}
.tab-btn[data-tab="all"] {
  margin-left: auto; background: transparent; font-size: .82rem; font-weight: 700;
}
.tab-btn[data-tab="all"].active { background: var(--ink); color: #fff; border-color: var(--ink); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: sfFade .18s ease-out; }
body.show-all-tabs .tab-panel { display: block; }
@keyframes sfFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   MISE EN PAGE (Sommaire + Page blanche Studyfiches avec onglet vertical)
   ========================================================================== */
.layout {
  display: grid; grid-template-columns: 250px 1fr; gap: 1.6rem;
  max-width: 1160px; margin: 0 auto; padding: 1.4rem 0 4rem;
}

.toc {
  position: sticky; top: 7.4rem; align-self: start;
  max-height: calc(100vh - 8.5rem); overflow: auto;
  background: #fff; border: 1px solid var(--rule); border-radius: 16px;
  padding: 1.1rem .95rem; box-shadow: var(--shadow-soft);
}
.toc h2 {
  font-family: var(--font-hand); font-size: 1.15rem; font-weight: 700;
  color: var(--p1); margin: 0 0 .6rem; padding-bottom: .35rem;
  border-bottom: 2px dashed var(--p1-soft);
}
.toc ol { margin: 0; padding: 0; list-style: none; counter-reset: ch; }
.toc li { counter-increment: ch; margin: .18rem 0; font-size: .88rem; line-height: 1.32; }
.toc a {
  display: flex; align-items: baseline; gap: .5rem;
  text-decoration: none; color: var(--ink-soft);
  padding: .34rem .5rem; border-radius: 10px; transition: all .12s;
}
.toc a::before {
  content: counter(ch);
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 21px; height: 21px; border-radius: 50%;
  background: var(--p1-soft); color: var(--p1);
  font-family: var(--font-head); font-size: .72rem; font-weight: 800; flex-shrink: 0;
}
.toc a:hover { background: var(--p1-soft); color: var(--ink); }
.toc a.current { background: var(--p1); color: var(--on-p1); font-weight: 700; }
.toc a.current::before { background: #fff; color: var(--ink); }
.toc a.is-done::after { content: "✓"; margin-left: auto; color: var(--ok); font-weight: 800; }
.toc a.current.is-done::after { color: var(--on-p1); }

main { min-width: 0; }

/* ==========================================================================
   FEUILLE STUDYFICHES (Blanc pur, onglet matière vertical à droite !)
   ========================================================================== */
.fiche {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 16px;
  box-shadow: var(--shadow-sheet);
  padding: 2rem 2.8rem 2.2rem 2.4rem;
  margin-bottom: 1.8rem;
  scroll-margin-top: 8rem;
  overflow: visible;
}

/* Onglet vertical coloré collé sur la tranche droite (signature Hatier !) */
.sf-side-tab {
  position: absolute;
  right: 0; top: 90px;
  background: var(--p1); color: var(--on-p1);
  font-family: var(--font-head); font-size: .72rem; font-weight: 800;
  letter-spacing: .12em; text-transform: uppercase;
  padding: .75rem .36rem;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  border-radius: 0 10px 10px 0;
  box-shadow: -2px 2px 8px rgba(30, 45, 68, .1);
  user-select: none;
}

.fiche > header { margin-bottom: 1.3rem; }
.fiche .tag {
  display: inline-block;
  font-family: var(--font-head); font-size: .72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--p1); background: var(--p1-soft);
  padding: .2rem .75rem; border-radius: 999px;
}
.fiche h2 {
  font-family: var(--font-hand);
  font-size: 1.85rem; font-weight: 700;
  margin: .3rem 0 0; line-height: 1.15; color: var(--ink);
}

/* ==========================================================================
   TITRES DE RUBRIQUES (Marque-page jaune moutarde à gauche + titre couleur 2)
   ========================================================================== */
.fiche { counter-reset: sec; }
.fiche h3 {
  counter-increment: sec;
  position: relative;
  font-family: var(--font-head);
  font-size: 1.2rem; font-weight: 800;
  color: var(--p2);
  margin: 2rem 0 .8rem;
  padding: .15rem 0 .15rem 2.3rem;
  line-height: 1.3;
}
/* Marque-page rectangulaire jaune moutarde avec numéro encre foncée (contraste 9,4:1) */
.fiche h3::before {
  content: counter(sec);
  position: absolute; left: -2.4rem; top: 0;
  width: 3.9rem; height: 1.85rem;
  padding-right: .65rem;
  background: var(--yellow-tab); color: var(--ink);
  font-family: var(--font-head); font-size: 1rem; font-weight: 800;
  display: flex; align-items: center; justify-content: flex-end;
  border-radius: 0 8px 8px 0;
  box-shadow: 0 2px 5px rgba(246, 203, 82, .35);
}

.fiche h4 {
  font-family: var(--font-hand);
  font-size: 1.22rem; font-weight: 700;
  color: var(--ink); margin: 1.1rem 0 .3rem;
}

.fiche p { margin: .55rem 0; }

/* Puces Studyfiches : ronds colorés niveau 1, petits carrés inclinés niveau 2 */
.fiche ul { list-style: none; padding-left: 1.35rem; margin: .5rem 0; }
.fiche ul > li { position: relative; margin: .34rem 0; }
.fiche ul > li::before {
  content: "";
  position: absolute; left: -1.15rem; top: .52em;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--p1);
}
.fiche ul ul > li::before {
  width: 7px; height: 7px; border-radius: 2px;
  background: var(--p2); transform: rotate(12deg);
}
.fiche ol { padding-left: 1.4rem; margin: .5rem 0; }
.fiche ol > li { margin: .3rem 0; }
.fiche ol > li::marker { color: var(--p2); font-weight: 800; font-family: var(--font-head); }

/* ==========================================================================
   ENCADRÉS "FAITS MAIN" STUDYFICHES (Contour organique + cartouche au-dessus)
   ========================================================================== */
.box {
  position: relative;
  margin: 1.6rem 0 1.2rem;
  padding: 0 1.3rem 1.05rem;
  background: #fff;
  border: 2.5px solid var(--p1);
  border-radius: 18px 24px 20px 22px / 22px 18px 24px 19px;
}
.box > :last-child { margin-bottom: 0; }

/* Cartouche plein posé à cheval sur la bordure supérieure (supporte multi-lignes et <sup> sans chevauchement) */
.box .box-title {
  display: block;
  width: fit-content;
  margin: -15px 0 .7rem 0;
  max-width: 100%;
  font-family: var(--font-head);
  font-size: .76rem; font-weight: 800; line-height: 1.35;
  text-transform: uppercase; letter-spacing: .06em;
  padding: .3rem .85rem;
  border-radius: 10px 12px 9px 11px;
  background: var(--p1); color: var(--on-p1);
  box-shadow: 0 2px 6px rgba(30, 45, 68, .12);
}
.box .box-title svg { width: 15px; height: 15px; vertical-align: -2px; margin-right: .4rem; display: inline-block; }

.box.definition { border-color: var(--p1); }
.box.definition .box-title { background: var(--p1); color: var(--on-p1); }

.box.propriete, .box.retenir { border-color: var(--p2); background: #fffdfa; }
.box.propriete .box-title, .box.retenir .box-title { background: var(--p2); color: var(--on-p2); }

.box.methode { border-color: var(--p2); background: var(--p2-soft); border-style: dashed; }
.box.methode .box-title { background: var(--p2); color: var(--on-p2); }

.box.piege { border-color: var(--warn); background: var(--warn-soft); }
.box.piege .box-title { background: var(--warn); color: #fff; }

.box.exemple { border-color: #94a3b8; background: #fafbfd; }
.box.exemple .box-title { background: var(--ink); color: #fff; }

/* Effet surligneur jaune pastel façon stabilo à main levée */
.box.definition b, .box.definition strong,
.box.retenir b, .box.retenir strong,
.box.propriete b, .box.propriete strong {
  background: linear-gradient(104deg, transparent 1%, var(--yellow-hi) 4%, var(--yellow-hi) 96%, transparent 99%);
  padding: 0 .25em;
  border-radius: 4px;
}

/* ==========================================================================
   FORMULES, CARTES MÉMO, TABLEAUX & FRISE PASTEL ORGANIQUE
   ========================================================================== */
.formule {
  display: block; text-align: center;
  font-size: 1.18rem; font-weight: 700;
  padding: .75rem 1rem; margin: .9rem 0;
  background: var(--p1-soft);
  color: var(--ink);
  border: 2px solid var(--p1);
  border-radius: 14px 18px 15px 17px;
  font-family: "Cambria Math", "STIX Two Math", Georgia, serif;
}

.two-col {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(265px, 1fr));
  gap: 1.1rem; margin: 1rem 0;
}
.mini-card {
  background: #fff;
  border: 2.2px solid var(--p1);
  border-radius: 16px 20px 18px 19px;
  padding: 1rem 1.15rem;
  box-shadow: 3px 3px 0 var(--p1-soft);
}
.mini-card:nth-child(even) {
  border-color: var(--p2);
  box-shadow: 3px 3px 0 var(--p2-soft);
}
.mini-card h4 {
  margin: 0 0 .45rem;
  font-family: var(--font-hand); font-size: 1.25rem;
  color: var(--p1);
}
.mini-card:nth-child(even) h4 { color: var(--p2); }

/* Tableaux arrondis et colorés */
table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  margin: 1rem 0; font-size: .94rem;
  border: 2px solid var(--p1); border-radius: 14px; overflow: hidden;
}
th, td {
  padding: .55rem .75rem; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule);
}
th:last-child, td:last-child { border-right: none; }
tbody tr:last-child td { border-bottom: none; }
th {
  background: var(--p1); color: var(--on-p1);
  font-family: var(--font-head); font-weight: 800; font-size: .86rem;
}
tbody tr:nth-child(even) td { background: var(--p1-soft); }

/* Frise chronologique sur bloc pastel abricot/pêche (comme Hatier Histoire !) */
.frise {
  list-style: none !important;
  padding: 1.1rem 1.3rem 1.1rem 2.2rem !important;
  margin: 1.2rem 0;
  background: var(--p2-soft);
  border-radius: 24px 28px 22px 26px;
  position: relative;
}
.frise::before {
  content: ""; position: absolute; left: 1.2rem; top: 1.4rem; bottom: 1.4rem;
  border-left: 2.5px dashed var(--p2);
}
.frise li { position: relative; margin: .6rem 0; padding-left: .4rem; }
.frise li::before {
  content: "" !important;
  position: absolute; left: -1.38rem !important; top: .45rem !important;
  width: 11px !important; height: 11px !important; border-radius: 50% !important;
  background: var(--p2) !important; border: 2.5px solid #fff;
}
.frise b {
  font-family: var(--font-hand); font-size: 1.08rem;
  color: var(--p2); margin-right: .35rem;
}

svg { max-width: 100%; height: auto; }

/* ==========================================================================
   EXERCICES (Bandeau pastel incliné & Bloc-notes perforé pour L'EXO BREVET !)
   ========================================================================== */
.exercice {
  position: relative;
  background: var(--p1-soft);
  border-radius: 16px 20px 18px 15px;
  padding: 1.25rem 1.4rem;
  margin: 1.4rem 0;
  border: 2px solid transparent;
}
.exercice:nth-of-type(even) { background: var(--p2-soft); }

/* Effet feuille de bloc-notes perforée en haut pour l'Exercice type Brevet (comme Hatier Maths !) */
.exercice.brevet-ex {
  background: #fff;
  border: 2.5px solid var(--p1);
  border-radius: 14px;
  padding: 2.3rem 1.7rem 1.6rem;
  box-shadow: 5px 5px 0 var(--p1-soft);
  background-image: radial-gradient(circle, var(--desk) 5px, var(--p1) 5.5px, var(--p1) 7px, transparent 7.5px);
  background-size: 32px 28px;
  background-repeat: repeat-x;
  background-position: 10px 6px;
}

.exercice > .ex-title {
  display: block;
  font-family: var(--font-hand); font-weight: 700; font-size: 1.32rem;
  color: var(--p1); margin-bottom: .55rem;
}
.exercice:nth-of-type(even) > .ex-title { color: var(--p2); }
.exercice.brevet-ex > .ex-title { color: var(--ink); font-size: 1.45rem; }

.exercice .points {
  float: right;
  font-family: var(--font-head); font-size: .78rem; font-weight: 800;
  background: var(--yellow-tab); color: var(--ink);
  padding: .18rem .65rem; border-radius: 999px;
}

.diff {
  display: inline-block; font-family: var(--font-head);
  font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  padding: .14rem .55rem; border-radius: 999px; margin-left: .45rem; vertical-align: middle;
}
.diff.facile    { background: #d9f2e6; color: #1d7a4f; }
.diff.moyen     { background: #fef0c7; color: #b4690e; }
.diff.difficile { background: #fde2df; color: #c43c2b; }

/* Bouton Corrigé entouré façon stylo (comme "Corrigés page 340" chez Hatier !) */
details.correction {
  margin-top: .95rem;
  border-radius: 14px;
  background: #fff;
  border: 2px solid var(--ok);
}
details.correction > summary {
  cursor: pointer; font-family: var(--font-hand); font-weight: 700; font-size: 1.08rem;
  color: var(--ok); padding: .5rem 1rem; list-style: none;
  display: inline-flex; align-items: center; gap: .45rem;
}
details.correction > summary::-webkit-details-marker { display: none; }
details.correction > summary::before {
  content: "+"; display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--ok); color: #fff; font-family: var(--font-head); font-size: .9rem; font-weight: 800;
}
details.correction[open] > summary::before { content: "−"; }
details.correction > .corr-body {
  padding: .3rem 1.15rem 1rem;
  border-top: 2px dashed var(--ok-soft);
}

/* Checklist interactive */
.checklist-item {
  display: flex; align-items: flex-start; gap: .55rem;
  list-style: none !important; margin: .4rem 0; cursor: pointer;
}
.checklist-item::before { display: none !important; }
.checklist-item input[type="checkbox"] {
  accent-color: var(--p1); width: 17px; height: 17px; margin-top: .22rem; flex-shrink: 0; cursor: pointer;
}
.checklist-item.checked span { text-decoration: line-through; color: var(--ink-soft); opacity: .7; }

/* Barre "Marquer comme révisé" */
.done-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  background: #fff; border: 2px dashed var(--p1); border-radius: 14px;
  padding: .85rem 1.25rem; margin-bottom: 1.1rem;
}
.done-btn {
  border: 2px solid var(--ok); background: #fff; color: var(--ok);
  font-family: var(--font-head); font-size: .85rem; font-weight: 800;
  padding: .42rem 1rem; border-radius: 999px; cursor: pointer; transition: all .15s;
}
.done-btn:hover, .done-btn.is-done { background: var(--ok); color: #fff; }

.chapter-nav {
  display: flex; justify-content: space-between; gap: .8rem; flex-wrap: wrap; margin-top: 1rem;
}
.chapter-nav a {
  text-decoration: none; font-family: var(--font-head); font-weight: 800; font-size: .88rem;
  background: #fff; border: 2px solid var(--rule); padding: .62rem 1.1rem;
  border-radius: 999px; color: var(--ink); transition: all .15s;
}
.chapter-nav a:hover { border-color: var(--p1); color: var(--p1); background: var(--p1-soft); }

/* ==========================================================================
   ACCUEIL & PORTAILS MATIÈRES
   ========================================================================== */
.grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 1.25rem; max-width: 1160px; margin: 0 auto; padding: .8rem 0 2rem;
}

.card {
  display: flex; flex-direction: column; text-decoration: none; color: var(--ink);
  background: #fff; border: 2.5px solid var(--c, var(--p1));
  border-radius: 20px 24px 20px 22px;
  padding: 1.45rem;
  box-shadow: 5px 5px 0 color-mix(in srgb, var(--c, var(--p1)) 18%, transparent);
  transition: transform .16s, box-shadow .16s;
}
.card:hover { transform: translate(-2px, -3px); box-shadow: 8px 8px 0 color-mix(in srgb, var(--c, var(--p1)) 24%, transparent); }
.card .subject-kicker {
  align-self: flex-start;
  font-family: var(--font-head); font-size: .72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .07em;
  background: var(--c, var(--p1)); color: var(--on-c, var(--on-p1));
  padding: .2rem .7rem; border-radius: 999px; margin-bottom: .55rem;
}
.card h2 { font-family: var(--font-hand); margin: 0 0 .35rem; font-size: 1.65rem; color: var(--ink); line-height: 1.12; }
.card p { margin: 0 0 .75rem; color: var(--ink-soft); font-size: .92rem; }
.card ul { list-style: none; margin: 0; padding: 0; font-size: .88rem; color: var(--ink-soft); }
.card ul li { position: relative; padding-left: 1rem; margin: .25rem 0; }
.card ul li::before {
  content: ""; position: absolute; left: 0; top: .52em;
  width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--p1));
}
.card .card-meta {
  margin-top: auto; padding-top: .85rem; margin-bottom: 0;
  border-top: 2px dashed var(--rule);
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-head); font-size: .82rem; font-weight: 800; color: var(--c, var(--p1));
}

.prog-wrap { margin-top: .8rem; }
.prog-label { display: flex; justify-content: space-between; font-family: var(--font-head); font-size: .76rem; font-weight: 700; color: var(--ink-soft); margin-bottom: .25rem; }
.prog-track { height: 8px; border-radius: 99px; background: var(--desk); overflow: hidden; }
.prog-fill { height: 100%; border-radius: 99px; background: var(--c, var(--p1)); width: 0%; transition: width .3s; }

/* Cartes chapitres dans les portails */
.card-box {
  display: flex; flex-direction: column;
  background: #fff; border: 2px solid var(--rule); border-radius: 18px;
  padding: 1.3rem 1.35rem 1.1rem;
  box-shadow: 4px 4px 0 var(--p1-soft);
  transition: transform .15s, border-color .15s;
}
.card-box:hover { transform: translateY(-2px); border-color: var(--p1); }
.card-box .ch-num {
  align-self: flex-start;
  font-family: var(--font-head); font-size: .72rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em;
  background: var(--yellow-tab); color: var(--ink);
  padding: .16rem .65rem; border-radius: 999px;
}
.card-box h2 { font-family: var(--font-hand); margin: .45rem 0 .35rem; font-size: 1.38rem; line-height: 1.18; }
.card-box h2 a { text-decoration: none; color: var(--ink); }
.card-box h2 a:hover { color: var(--p1); }
.card-box p { margin: 0 0 .85rem; color: var(--ink-soft); font-size: .9rem; line-height: 1.5; }
.card-box .quick-links {
  margin-top: auto; padding-top: .7rem; border-top: 2px dashed var(--rule);
  display: flex; gap: .35rem; flex-wrap: wrap;
}
.card-box .quick-links a {
  text-decoration: none; font-family: var(--font-head); font-size: .76rem; font-weight: 800;
  padding: .24rem .62rem; border-radius: 999px;
  background: var(--p1-soft); color: var(--p1); transition: all .12s;
}
.card-box .quick-links a:hover { background: var(--p1); color: var(--on-p1); }
.card-box.is-done { border-color: var(--ok); }
.card-box.is-done .ch-num { background: var(--ok); color: #fff; }
.card-box.is-done .ch-num::after { content: " ✓"; }

.section { max-width: 1160px; margin: 0 auto; padding: .4rem 0 2rem; }
footer.foot { text-align: center; color: var(--ink-soft); font-size: .84rem; padding: 1.8rem 1rem 3rem; }

/* Accessibilité clavier : contour de focus bien visible */
a:focus-visible, button:focus-visible, summary:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2.5px solid var(--ink);
  outline-offset: 2px;
}

/* Recherche globale (modale Cmd+K / bouton loupe) */
.search-trigger {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1.5px solid var(--rule); background: var(--desk); color: var(--ink);
  font-family: var(--font-head); font-size: .8rem; font-weight: 700;
  padding: .34rem .72rem; border-radius: 999px; cursor: pointer;
  transition: all .15s;
}
.search-trigger:hover { border-color: var(--p1); background: var(--p1-soft); }
.search-trigger kbd {
  font-family: inherit; font-size: .7rem; opacity: .7;
  background: #fff; border: 1px solid var(--rule); border-radius: 5px; padding: .05rem .35rem;
}
.search-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(30, 45, 68, .48); backdrop-filter: blur(4px);
  display: none; align-items: flex-start; justify-content: center; padding: 8vh 1rem 1rem;
}
.search-overlay.open { display: flex; }
.search-modal {
  width: 100%; max-width: 600px; background: #fff; border-radius: 18px;
  border: 2px solid var(--p1); box-shadow: 0 20px 60px rgba(30, 45, 68, .25);
  overflow: hidden;
}
.search-head {
  display: flex; align-items: center; gap: .6rem; padding: .85rem 1.1rem;
  border-bottom: 1.5px solid var(--rule);
}
.search-head input {
  flex: 1; border: none; outline: none; font-family: var(--font-body);
  font-size: 1.02rem; color: var(--ink); background: transparent;
}
.search-close {
  border: none; background: var(--desk); color: var(--ink); font-family: var(--font-head);
  font-weight: 800; font-size: .78rem; padding: .28rem .65rem; border-radius: 8px; cursor: pointer;
}
.search-results { max-height: 55vh; overflow-y: auto; padding: .45rem; }
.search-item {
  display: flex; align-items: center; gap: .65rem; text-decoration: none;
  padding: .62rem .8rem; border-radius: 11px; color: var(--ink);
  transition: background .12s;
}
.search-item:hover, .search-item:focus { background: var(--p1-soft); }
.search-tag {
  font-family: var(--font-head); font-size: .7rem; font-weight: 800; text-transform: uppercase;
  padding: .16rem .52rem; border-radius: 999px; background: var(--yellow-tab); color: var(--ink);
  flex-shrink: 0;
}
.search-empty { padding: 1.4rem; text-align: center; color: var(--ink-soft); font-size: .92rem; }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 1200px) {
  .hero, .tabs-bar, .layout, .grid, .section { margin-left: 1rem; margin-right: 1rem; }
}
@media (max-width: 880px) {
  .topbar {
    position: static;
    padding: .5rem .85rem;
    gap: .45rem .6rem;
  }
  .topbar .brand { font-size: 1.15rem; }
  .topbar nav {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: .15rem;
  }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: .82rem;
    padding: .3rem .68rem;
  }
  .topbar .actions { margin-left: 0; }
  .layout { display: flex; flex-direction: column; gap: 1.2rem; }
  .layout main { order: 1; }
  .layout .toc { order: 2; position: static; max-height: none; }
  .fiche { padding: 1.35rem 1.05rem; overflow-x: hidden; }
  .fiche h3::before { left: -1.05rem; width: 2.7rem; }
  .sf-side-tab { display: none; }
  .tabs-bar { position: static; padding: .45rem .8rem 0; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .formule, pre, code { overflow-wrap: anywhere; word-break: break-word; }
}

/* ==========================================================================
   IMPRESSION (Fiches blanches ultra-propres)
   ========================================================================== */
@media print {
  body { background: #fff !important; font-size: 10.5pt; }
  .topbar, .tabs-bar, .toc, .chapter-nav, .done-bar, .no-print, footer.foot { display: none !important; }
  .hero { margin: 0 0 .6rem; padding: .8rem 1rem; border: none; box-shadow: none; }
  .layout { display: block; padding: 0; margin: 0; }
  .fiche { box-shadow: none !important; border: 1.5px solid var(--p1); padding: 1.1rem 1.6rem; }
  .fiche h3::before { left: -1.6rem; width: 3.1rem; }
  .box, .exercice, table, .formule, .mini-card { page-break-inside: avoid; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body.print-no-corr details.correction { display: none; }
}
