:root {
  /* Plan : le parcours est un réseau de lignes ; chaque niveau est une ligne colorée,
     chaque cours une station. Le reste de l'interface reste sobre. */
  --papier: #F2F4F6;
  --surface: #FFFFFF;
  --encre: #14202E;
  --encre-2: #4F5D6C;
  --trait: #D7DDE4;
  --accent: #0B6E78;
  --accent-doux: #E0F0F1;
  --xp: #A8670F;
  --ok: #1B7F47;
  --ko: #B53A2C;
  --c-kw: #7A3EB1;
  --c-str: #0E7A4F;
  --c-num: #B4530E;
  --c-com: #7C8794;
  --code-fond: #F7F8FA;
  --f-titre: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-texte: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --f-code: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --rayon: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --papier: #0D131A;
    --surface: #151E28;
    --encre: #E3E9EF;
    --encre-2: #9AA7B4;
    --trait: #283542;
    --accent: #43B7C1;
    --accent-doux: #133238;
    --xp: #E3A84A;
    --ok: #4CC184;
    --ko: #EB6F61;
    --c-kw: #C59AF0;
    --c-str: #7FD3A6;
    --c-num: #F0A46A;
    --c-com: #7E8C99;
    --code-fond: #10181F;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --papier: #0D131A;
  --surface: #151E28;
  --encre: #E3E9EF;
  --encre-2: #9AA7B4;
  --trait: #283542;
  --accent: #43B7C1;
  --accent-doux: #133238;
  --xp: #E3A84A;
  --ok: #4CC184;
  --ko: #EB6F61;
  --c-kw: #C59AF0;
  --c-str: #7FD3A6;
  --c-num: #F0A46A;
  --c-com: #7E8C99;
  --code-fond: #10181F;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--papier);
  color: var(--encre);
  font-family: var(--f-texte);
  font-size: 16px;
  line-height: 1.6;
}
a { color: var(--accent); }
h1, h2, h3, h4 { font-family: var(--f-titre); line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.7rem, 3.4vw, 2.4rem); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.45rem; font-weight: 650; }
h3 { font-size: 1.12rem; font-weight: 650; }
p { margin: 0 0 0.75em; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
sub, sup { font-size: 0.72em; }

/* ---------- Structure ---------- */
.appli { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.nav {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 22px 16px;
  border-right: 1px solid var(--trait);
  background: var(--surface);
}
.marque { display: grid; gap: 2px; text-decoration: none; color: var(--encre); padding: 0 6px; }
.marque strong { font-family: var(--f-titre); font-size: 1.3rem; letter-spacing: -0.01em; }
.marque span { font-size: 0.8rem; color: var(--encre-2); }
.marque-lignes { display: flex; gap: 3px; margin-bottom: 6px; }
.marque-lignes i { display: block; width: 16px; height: 4px; border-radius: 2px; }
.liens { display: grid; gap: 2px; }
.liens a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--encre-2); text-decoration: none; font-weight: 500;
}
.liens a:hover { background: var(--papier); color: var(--encre); }
.liens a[aria-current="page"] { background: var(--accent-doux); color: var(--encre); }
.liens svg { width: 18px; height: 18px; flex: none; }
.nav-bas { margin-top: auto; display: grid; gap: 10px; font-size: 0.82rem; color: var(--encre-2); }
.pastille-xp {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 12px; border: 1px solid var(--trait); border-radius: var(--rayon);
}
.pastille-xp b { font-family: var(--f-titre); font-size: 1.25rem; color: var(--xp); font-variant-numeric: tabular-nums; }
.etat { display: flex; align-items: center; gap: 8px; }
.etat i { width: 8px; height: 8px; border-radius: 50%; background: var(--trait); flex: none; }
.etat[data-etat="pret"] i, .etat[data-etat="sync"] i { background: var(--ok); }
.etat[data-etat="chargement"] i { background: var(--xp); }
.etat[data-etat="erreur"] i { background: var(--ko); }

main { min-width: 0; padding: 32px clamp(16px, 4vw, 56px) 80px; }
.page { max-width: 1060px; margin: 0 auto; display: grid; gap: 28px; }
.etroit { max-width: 780px; }

/* ---------- Éléments communs ---------- */
.carte { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--rayon); padding: 20px; }
.sur-titre { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--encre-2); }
.puce {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  border: 1px solid var(--trait); color: var(--encre-2); background: var(--surface); white-space: nowrap;
}
.puce-niveau { color: #fff; border-color: transparent; }
.puce-ok { color: var(--ok); border-color: currentColor; }
.ligne-puces { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
}
:root[data-theme="dark"] .bouton { color: #0D131A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bouton { color: #0D131A; } }
.bouton:hover { filter: brightness(1.08); }
.bouton[disabled] { opacity: 0.45; cursor: not-allowed; filter: none; }
.bouton-sec { background: transparent; color: var(--encre); border-color: var(--trait); }
:root[data-theme="dark"] .bouton-sec { color: var(--encre); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .bouton-sec { color: var(--encre); } }
.bouton-sec:hover { background: var(--papier); filter: none; }
.bouton-petit { padding: 5px 11px; font-size: 0.86rem; }
.barre { height: 6px; border-radius: 3px; background: var(--trait); overflow: hidden; }
.barre i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.discret { color: var(--encre-2); font-size: 0.9rem; }
.chiffres { font-variant-numeric: tabular-nums; }

/* ---------- Accueil ---------- */
.accueil-tete { display: grid; gap: 6px; }
.prochaine {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 18px; align-items: center;
  padding: 22px; border-radius: 14px; background: var(--surface); border: 1px solid var(--trait);
}
.prochaine .trait-ligne { align-self: stretch; border-radius: 4px; }
.prochaine h2 { margin: 4px 0 6px; }
.tuiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.tuile { padding: 16px; border: 1px solid var(--trait); border-radius: var(--rayon); background: var(--surface); }
.tuile b { display: block; font-family: var(--f-titre); font-size: 1.8rem; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tuile span { font-size: 0.85rem; color: var(--encre-2); }
.niveaux-mini { display: grid; gap: 10px; }
.niveau-mini { display: grid; grid-template-columns: 26px 1fr 64px; gap: 12px; align-items: center; text-decoration: none; color: var(--encre); }
.niveau-mini .num {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 0.8rem; font-family: var(--f-titre);
}
.niveau-mini .nom { font-weight: 600; font-size: 0.95rem; }
.niveau-mini .pct { text-align: right; font-size: 0.85rem; color: var(--encre-2); font-variant-numeric: tabular-nums; }
.deux-col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; align-items: start; }
.raccourcis { display: grid; gap: 12px; }
.raccourci { display: grid; gap: 4px; text-decoration: none; color: var(--encre); }
.raccourci:hover h3 { color: var(--accent); }

/* ---------- Plan du parcours (le réseau) ---------- */
.plan { display: grid; gap: 0; }
.plan-niveau { display: grid; grid-template-columns: 56px 1fr; }
.plan-rail { position: relative; display: flex; justify-content: center; }
.plan-rail::before {
  content: ""; position: absolute; top: 0; bottom: 0; width: 8px; border-radius: 4px;
  background: var(--couleur);
}
.plan-niveau:first-child .plan-rail::before { top: 22px; }
.plan-niveau:last-child .plan-rail::before { bottom: 32px; }
.plan-terminus {
  position: relative; z-index: 1; margin-top: 8px;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--couleur); color: #fff; font-family: var(--f-titre); font-weight: 800; font-size: 1.15rem;
  box-shadow: 0 0 0 5px var(--papier);
}
.plan-corps { padding: 12px 0 34px 8px; display: grid; gap: 14px; }
.plan-entete { display: grid; gap: 2px; }
.plan-entete p { margin: 0; color: var(--encre-2); max-width: 65ch; }
.stations { display: grid; gap: 8px; }
.station {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: center;
  padding: 12px 16px; border: 1px solid var(--trait); border-radius: var(--rayon);
  background: var(--surface); text-decoration: none; color: var(--encre);
}
.station::before {
  content: ""; position: absolute; left: -45px; top: 50%; width: 18px; height: 18px; margin-top: -9px;
  border-radius: 50%; background: var(--surface); border: 4px solid var(--couleur);
}
.station[data-etat="fini"]::before { background: var(--couleur); }
.station[data-etat="encours"]::before { background: conic-gradient(var(--couleur) var(--pct), var(--surface) 0); }
.station:hover { border-color: var(--couleur); }
.station h3 { font-size: 1.02rem; }
.station .meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.82rem; color: var(--encre-2); }
.station .avancement { font-size: 0.85rem; color: var(--encre-2); font-variant-numeric: tabular-nums; }

/* ---------- Page cours ---------- */
.cours-tete { display: grid; gap: 12px; padding-left: 18px; border-left: 8px solid var(--couleur); }
.cours-tete p { margin: 0; color: var(--encre-2); max-width: 70ch; }
.liste-lecons { display: grid; gap: 8px; counter-reset: lecon; }
.ligne-lecon {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 14px; align-items: center;
  padding: 12px 16px; border: 1px solid var(--trait); border-radius: var(--rayon);
  background: var(--surface); text-decoration: none; color: var(--encre);
}
.ligne-lecon:hover { border-color: var(--accent); }
.ligne-lecon .rond {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--trait); font-weight: 700; font-size: 0.85rem; color: var(--encre-2);
}
.ligne-lecon[data-fini="1"] .rond { background: var(--ok); border-color: var(--ok); color: #fff; }
.ligne-lecon .infos { font-size: 0.82rem; color: var(--encre-2); }
.sources li { margin-bottom: 4px; }
.prereq a { text-decoration: none; }

/* ---------- Leçon ---------- */
.lecon-tete { display: grid; gap: 10px; }
.fil { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.86rem; color: var(--encre-2); }
.fil a { color: var(--encre-2); }
.lecon { display: grid; gap: 18px; }
.bloc { max-width: 78ch; }
.bloc h3 { margin-bottom: 8px; }
.bloc ul, .bloc ol { padding-left: 1.3em; margin: 0 0 0.75em; }
.bloc li { margin-bottom: 0.3em; }
.bloc table { border-collapse: collapse; width: 100%; font-size: 0.92rem; margin: 6px 0 12px; }
.bloc th, .bloc td { border-bottom: 1px solid var(--trait); padding: 7px 10px; text-align: left; vertical-align: top; }
.bloc th { font-weight: 600; background: var(--papier); }
.tableau-defile { overflow-x: auto; }
.bloc code, .formule code { font-family: var(--f-code); font-size: 0.88em; background: var(--code-fond); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--trait); }
.bloc pre { background: var(--code-fond); border: 1px solid var(--trait); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-size: 0.86rem; line-height: 1.5; }
.bloc pre code { background: none; border: 0; padding: 0; }
.etiquette { display: block; font-size: 0.74rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; margin-bottom: 6px; }
.obj { padding: 14px 18px; border-radius: var(--rayon); background: var(--accent-doux); }
.obj .etiquette { color: var(--accent); }
.obj p { margin: 0; }
.rappel { padding: 16px 18px; border-radius: var(--rayon); border: 1px dashed var(--encre-2); background: var(--surface); }
.rappel .etiquette { color: var(--encre-2); }
.rappel p:last-child, .ex p:last-child, .txt p:last-child { margin-bottom: 0; }
.ex { padding: 16px 18px; border-radius: var(--rayon); background: var(--surface); border: 1px solid var(--trait); border-left: 5px solid var(--couleur); }
.ex .etiquette { color: var(--encre-2); }
.formule { padding: 14px 18px; border-radius: var(--rayon); background: var(--surface); border: 1px solid var(--trait); font-size: 1.02rem; display: grid; gap: 6px; font-variant-numeric: tabular-nums; }
.f-ligne { font-family: var(--f-texte); }
.encart { padding: 12px 16px; border-radius: var(--rayon); font-size: 0.95rem; }
.encart p:last-child { margin: 0; }
.astuce { background: var(--accent-doux); }
.attention { background: color-mix(in srgb, var(--ko) 10%, var(--surface)); border-left: 4px solid var(--ko); }

/* Cellules de code */
.cellule { border: 1px solid var(--trait); border-radius: var(--rayon); background: var(--surface); overflow: hidden; max-width: 100%; }
.cellule-tete { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--trait); }
.cellule-tete .langue { font-family: var(--f-code); font-size: 0.78rem; font-weight: 600; color: var(--encre-2); margin-right: auto; }
.editeur { position: relative; background: var(--code-fond); }
.editeur pre, .editeur textarea {
  margin: 0; padding: 12px 14px; border: 0;
  font-family: var(--f-code); font-size: 0.86rem; line-height: 1.55; tab-size: 4;
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal;
}
.editeur pre { color: var(--encre); min-height: 3.5em; pointer-events: none; }
.editeur textarea {
  position: absolute; inset: 0; width: 100%; height: 100%; resize: none; overflow: hidden;
  background: transparent; color: transparent; caret-color: var(--encre); outline: none;
}
.editeur textarea:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.editeur textarea::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); color: transparent; }
.tk-kw { color: var(--c-kw); font-weight: 600; }
.tk-str { color: var(--c-str); }
.tk-num { color: var(--c-num); }
.tk-com { color: var(--c-com); font-style: italic; }
.sortie { border-top: 1px solid var(--trait); padding: 10px 14px; display: grid; gap: 8px; }
.sortie[hidden] { display: none; }
.sortie .titre-sortie { font-size: 0.74rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--encre-2); }
.sortie pre { margin: 0; font-family: var(--f-code); font-size: 0.84rem; line-height: 1.5; white-space: pre; overflow-x: auto; }
.sortie .erreur { color: var(--ko); white-space: pre-wrap; }
.sortie img { max-width: 100%; border-radius: 6px; background: #fff; }
.table-sortie { overflow-x: auto; }
.table-sortie table { border-collapse: collapse; font-size: 0.84rem; font-variant-numeric: tabular-nums; }
.table-sortie th, .table-sortie td { padding: 5px 12px; border-bottom: 1px solid var(--trait); text-align: left; white-space: nowrap; }
.table-sortie th { font-family: var(--f-code); font-weight: 600; background: var(--papier); }

/* Quiz */
.quiz { border: 1px solid var(--trait); border-radius: var(--rayon); background: var(--surface); padding: 18px; display: grid; gap: 12px; max-width: 78ch; }
.quiz .etiquette { color: var(--xp); margin: 0; }
.quiz .question { font-weight: 600; font-size: 1.02rem; }
.options { display: grid; gap: 8px; }
.option {
  text-align: left; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--trait);
  background: var(--papier); cursor: pointer; display: flex; gap: 10px; align-items: baseline;
}
.option:hover:not([disabled]) { border-color: var(--accent); }
.option .lettre { font-weight: 700; color: var(--encre-2); font-family: var(--f-code); font-size: 0.85rem; }
.option[data-etat="bon"] { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.option[data-etat="faux"] { border-color: var(--ko); background: color-mix(in srgb, var(--ko) 10%, var(--surface)); }
.option[disabled] { cursor: default; }
.retour { padding: 10px 14px; border-radius: 8px; font-size: 0.95rem; }
.retour[data-type="ok"] { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.retour[data-type="ko"] { background: color-mix(in srgb, var(--ko) 10%, var(--surface)); }
.retour[data-type="info"] { background: var(--papier); }
.retour p:last-child { margin: 0; }

/* Exercices */
.exo { border: 2px solid var(--accent); border-radius: 12px; background: var(--surface); overflow: hidden; }
.exo-tete { padding: 14px 18px; background: var(--accent-doux); display: grid; gap: 4px; }
.exo-tete .etiquette { color: var(--accent); margin: 0; }
.exo-corps { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
.exo-consigne { padding: 16px 18px; border-right: 1px solid var(--trait); display: grid; gap: 10px; align-content: start; }
.exo-consigne p:last-child { margin: 0; }
.exo-zone { min-width: 0; display: grid; align-content: start; }
.exo-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; border-top: 1px solid var(--trait); }

/* Fin de leçon */
.fin-lecon { display: grid; gap: 12px; padding: 22px; border-radius: 14px; border: 1px solid var(--trait); background: var(--surface); }
.fin-lecon .rangee { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.fin-lecon[data-fini="1"] { border-color: var(--ok); }

/* Widgets */
.widget { border: 1px solid var(--trait); border-radius: 12px; background: var(--surface); padding: 16px 18px; display: grid; gap: 12px; }
.widget .etiquette { color: var(--accent); margin: 0; }
.widget-controles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 18px; }
.curseur { display: grid; gap: 2px; font-size: 0.88rem; }
.curseur label { display: flex; justify-content: space-between; gap: 8px; color: var(--encre-2); }
.curseur output { color: var(--encre); font-weight: 600; font-variant-numeric: tabular-nums; }
.curseur input[type="range"] { width: 100%; accent-color: var(--accent); }
.widget canvas { width: 100%; height: auto; display: block; border-radius: 8px; background: var(--papier); }
.widget-resultats { display: flex; flex-wrap: wrap; gap: 8px 22px; font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.widget-resultats b { font-family: var(--f-titre); font-size: 1.15rem; }
.legende { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; color: var(--encre-2); }
.legende i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* Recherche, fiches, positionnement */
.champ { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--trait); background: var(--surface); color: var(--encre); font: inherit; }
.resultats { display: grid; gap: 8px; }
.resultat { display: grid; gap: 2px; padding: 12px 16px; border: 1px solid var(--trait); border-radius: var(--rayon); background: var(--surface); text-decoration: none; color: var(--encre); }
.resultat:hover { border-color: var(--accent); }
.resultat span { font-size: 0.84rem; color: var(--encre-2); }
.fiche-groupe { display: grid; gap: 12px; }
.fiche-groupe > h2 { padding-left: 12px; border-left: 6px solid var(--couleur); }
.sommaire-fiches { display: flex; flex-wrap: wrap; gap: 6px; }
.confirmation { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

@media (max-width: 900px) {
  .tuiles { grid-template-columns: repeat(2, 1fr); }
  .deux-col { grid-template-columns: 1fr; }
  .exo-corps { grid-template-columns: 1fr; }
  .exo-consigne { border-right: 0; border-bottom: 1px solid var(--trait); }
}
@media (max-width: 760px) {
  .appli { grid-template-columns: 1fr; }
  .nav {
    position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 8px; gap: 0; border-right: 0; border-top: 1px solid var(--trait);
  }
  .marque, .nav-bas { display: none; }
  .liens { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .liens a { flex-direction: column; gap: 2px; font-size: 0.68rem; padding: 6px 2px; text-align: center; }
  main { padding: 20px 16px 96px; }
  .prochaine { grid-template-columns: 6px 1fr; }
  .prochaine .bouton { grid-column: 1 / -1; }
  .plan-niveau { grid-template-columns: 40px 1fr; }
  .plan-terminus { width: 34px; height: 34px; font-size: 0.95rem; }
  .station::before { left: -37px; width: 16px; height: 16px; margin-top: -8px; border-width: 3px; }
  .plan-rail::before { width: 6px; }
}
@media (prefers-reduced-motion: no-preference) {
  .station, .ligne-lecon, .option, .resultat { transition: border-color 0.15s ease, background-color 0.15s ease; }
  .apparait { animation: apparait 0.35s ease both; }
  @keyframes apparait { from { opacity: 0.4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
