:root {
  color-scheme: light dark;
  --fond: #f7f3ea;
  --surface: #fffdf8;
  --surface-2: #efe9dc;
  --trait: #d9d1c0;
  --texte: #1f2a29;
  --texte-doux: #5c6663;
  --accent: #0f5f55;
  --accent-fort: #0a4a42;
  --sur-accent: #ffffff;
  --accent-doux: #d9ece7;
  --ambre: #8a5a00;
  --ambre-doux: #f8ecd0;
  --erreur: #a3331f;
  --erreur-doux: #f9e2db;
  --mot-cle: #0f5f55;
  --chaine: #a3501f;
  --nombre: #7a3f9a;
  --commentaire: #7b8480;
  --ombre: 0 8px 24px rgb(40 30 10 / 12%);
  --serif: ui-serif, 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #121817;
    --surface: #1a2221;
    --surface-2: #232d2b;
    --trait: #35413e;
    --texte: #e8e5dc;
    --texte-doux: #a2aca8;
    --accent: #5fcab6;
    --accent-fort: #86dccb;
    --sur-accent: #0c211e;
    --accent-doux: #1c3a35;
    --ambre: #f2c063;
    --ambre-doux: #3a2f17;
    --erreur: #f29b85;
    --erreur-doux: #41241d;
    --mot-cle: #5fcab6;
    --chaine: #f0a877;
    --nombre: #cfa6ec;
    --commentaire: #8a948f;
    --ombre: 0 8px 24px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.6 var(--sans);
}
main:focus { outline: none; }
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; font-weight: 600; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: .08em .32em; border-radius: 4px; }
pre code { background: none; padding: 0; font-size: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* En-tête */
.entete {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--trait);
  position: sticky; top: 0; z-index: 10;
}
.marque { font: 600 19px var(--serif); color: var(--texte); text-decoration: none; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.marque-signe { font: 700 14px var(--mono); color: var(--sur-accent); background: var(--accent); padding: 2px 6px; border-radius: 5px; }
.entete nav { display: flex; gap: 16px; }
.entete nav a { color: var(--texte-doux); text-decoration: none; font-size: 15px; white-space: nowrap; }
.entete nav a:hover, .entete nav a[aria-current] { color: var(--texte); }
.progression-globale { margin-left: auto; font-size: 14px; color: var(--texte-doux); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Accueil */
.accueil { max-width: 980px; margin: 0 auto; padding: 48px 24px 72px; }
.accueil h1 { font-size: clamp(34px, 6vw, 50px); margin: 0 0 14px; letter-spacing: -.01em; }
.accroche { font-size: 19px; color: var(--texte-doux); max-width: 620px; margin: 0 0 24px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.module { margin-top: 44px; }
.module h2 { font-size: 24px; margin: 0 0 10px; }
.liste-lecons { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--trait); }
.liste-lecons li { border-bottom: 1px solid var(--trait); }
.liste-lecons a {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center;
  padding: 11px 6px; color: var(--texte); text-decoration: none;
}
.liste-lecons a:hover { background: var(--surface-2); }
.liste-lecons .numero { color: var(--texte-doux); font: 13px var(--mono); }
.liste-lecons .etat { color: var(--texte-doux); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.liste-lecons .fini .etat { color: var(--accent); font-weight: 600; }
.bloc-base { margin-top: 52px; }
.bloc-base h2 { font-size: 24px; margin: 0 0 6px; }
.bloc-base > p { color: var(--texte-doux); margin: 0 0 16px; }
.reinitialiser-progres { margin-top: 40px; }

/* Schéma */
.schema { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 12px; }
.table-schema { background: var(--surface); border: 1px solid var(--trait); border-radius: 8px; overflow: hidden; }
.table-schema header { display: flex; justify-content: space-between; gap: 8px; padding: 6px 10px; background: var(--surface-2); font: 600 13.5px var(--mono); }
.table-schema header span { font-weight: 400; color: var(--texte-doux); }
.table-schema ul { list-style: none; margin: 0; padding: 6px 10px; font: 12.5px/1.7 var(--mono); }
.table-schema li { display: flex; justify-content: space-between; gap: 8px; }
.table-schema .type { color: var(--texte-doux); text-align: right; }
.table-schema .cle { color: var(--ambre); }

/* Page de leçon */
.lecon { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
.cours { padding: 32px clamp(20px, 3vw, 44px) 56px; min-width: 0; }
.fil { font-size: 14px; color: var(--texte-doux); margin: 0 0 4px; }
.cours h1 { font-size: clamp(27px, 3vw, 34px); margin: 0 0 18px; }
.cours p, .cours li { max-width: 62ch; }
.cours .etapes { display: flex; flex-wrap: wrap; gap: 6px 26px; padding-left: 22px; }
.note { background: var(--ambre-doux); padding: 10px 14px; border-radius: 8px; font-size: 15px; }
.note code { background: rgb(128 128 128 / 16%); }
.exemple-bloc { margin: 14px 0; border: 1px solid var(--trait); border-radius: 8px; background: var(--surface); overflow: hidden; }
.exemple-bloc pre { margin: 0; padding: 10px 12px; overflow-x: auto; font: 13.5px/1.55 var(--mono); }
.exemple-pied { display: flex; justify-content: flex-end; padding: 4px 6px; border-top: 1px solid var(--trait); background: var(--surface-2); }
.exemple-resultat { padding: 8px; border-top: 1px solid var(--trait); }
pre.modele { margin: 14px 0; padding: 10px 12px; overflow-x: auto; border: 1px solid var(--trait); border-radius: 8px; background: var(--surface); font: 13.5px/1.55 var(--mono); }
.navigation-lecons { display: flex; justify-content: space-between; gap: 12px; margin-top: 34px; font-size: 15px; }

/* Atelier */
.atelier {
  position: sticky; top: 53px;
  height: calc(100vh - 53px); height: calc(100dvh - 53px);
  overflow-y: auto;
  padding: 22px clamp(16px, 2.5vw, 32px) 40px;
  background: var(--surface);
  border-left: 1px solid var(--trait);
  min-width: 0;
}
.exercices-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.pastille {
  min-width: 34px; height: 34px; padding: 0 6px;
  border: 1px solid var(--trait); border-radius: 8px;
  background: var(--surface); color: var(--texte);
  font: 600 14px var(--sans); cursor: pointer;
}
.pastille:hover { border-color: var(--accent); }
.pastille.fait { background: var(--accent-doux); border-color: var(--accent); color: var(--accent-fort); }
.pastille[aria-current] { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); }
.consigne { margin: 0 0 12px; font-size: 16.5px; min-height: 3.2em; }

.editeur { border: 1px solid var(--trait); border-radius: 8px; overflow: hidden; background: var(--fond); }
.editeur:focus-within { border-color: var(--accent); }
.CodeMirror { height: 150px; font: 14.5px/1.55 var(--mono); background: transparent; color: var(--texte); }
.grand .CodeMirror { height: 230px; }
.CodeMirror-cursor { border-left-color: var(--texte); }
.CodeMirror-selected, .CodeMirror-focused .CodeMirror-selected { background: var(--accent-doux); }
.CodeMirror-matchingbracket { color: inherit !important; background: var(--accent-doux); }
.cm-s-default .cm-keyword { color: var(--mot-cle); font-weight: 600; }
.cm-s-default .cm-string { color: var(--chaine); }
.cm-s-default .cm-number { color: var(--nombre); }
.cm-s-default .cm-comment { color: var(--commentaire); }
.cm-s-default .cm-builtin, .cm-s-default .cm-atom, .cm-s-default .cm-variable-2 { color: var(--nombre); }
.cm-s-default .cm-operator, .cm-s-default .cm-bracket { color: inherit; }
.CodeMirror-hints { background: var(--surface); border-color: var(--trait); font-family: var(--mono); box-shadow: var(--ombre); }
.CodeMirror-hint { color: var(--texte); }
li.CodeMirror-hint-active { background: var(--accent); color: var(--sur-accent); }

.barre { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
.bouton {
  border: 1px solid var(--trait); border-radius: 8px;
  background: var(--surface); color: var(--texte);
  font: 500 14.5px var(--sans); padding: 7px 13px; cursor: pointer;
  text-decoration: none; display: inline-block;
}
.bouton:hover { border-color: var(--accent); }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); font-weight: 600; }
.bouton.principal:hover { background: var(--accent-fort); }
.bouton.petit { font-size: 13px; padding: 3px 9px; }
.bouton.discret { border-color: transparent; background: none; color: var(--texte-doux); }
.bouton.discret:hover { color: var(--texte); border-color: var(--trait); }
.bouton:disabled { opacity: .55; cursor: wait; }
.raccourci { font-size: 12.5px; color: var(--texte-doux); margin-left: 2px; }

.verdict { padding: 9px 13px; border-radius: 8px; margin: 10px 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.verdict.ok { background: var(--accent-doux); color: var(--accent-fort); }
.verdict.ko { background: var(--ambre-doux); color: var(--ambre); }
.verdict.erreur { background: var(--erreur-doux); color: var(--erreur); }
.verdict.info { background: var(--surface-2); }
.aide { background: var(--surface-2); padding: 9px 13px; border-radius: 8px; margin: 10px 0; font-size: 15px; }
.aide > strong { display: block; font-size: 13px; color: var(--texte-doux); font-weight: 600; }
.aide pre { margin: 4px 0 0; white-space: pre-wrap; word-break: break-word; font: 13.5px/1.55 var(--mono); }

.resultat { overflow: auto; max-height: 46vh; border: 1px solid var(--trait); border-radius: 8px; background: var(--surface); }
.resultat table { border-collapse: collapse; width: 100%; font: 13.5px/1.45 var(--mono); }
.resultat th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 600; white-space: nowrap; }
.resultat th, .resultat td { padding: 4px 10px; border-bottom: 1px solid var(--trait); }
.resultat td { white-space: nowrap; }
.resultat td.long { white-space: normal; min-width: min(420px, 70vw); }
.resultat tr:last-child td { border-bottom: 0; }
.resultat .nombre { text-align: right; font-variant-numeric: tabular-nums; }
.resultat td.nul { color: var(--texte-doux); font-style: italic; }
.compte { font-size: 13px; color: var(--texte-doux); margin: 5px 0 0; }
details.tables { margin-top: 18px; }
details.tables summary { cursor: pointer; font-weight: 600; font-size: 15px; padding: 3px 0; }
details.tables .schema { margin-top: 10px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }

.bac-a-sable { max-width: 1120px; margin: 0 auto; padding: 32px 24px 64px; }
.bac-a-sable h1 { font-size: 32px; margin: 0 0 6px; }
.bac-a-sable > p { color: var(--texte-doux); margin: 0 0 16px; }

.choix { margin: 0 0 12px; }
.choix select { font: 15px var(--sans); color: var(--texte); background: var(--surface); border: 1px solid var(--trait); border-radius: 6px; padding: 4px 8px; }
.texte-section { color: var(--texte-doux); margin: 0 0 12px; max-width: 620px; }
.onglets { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.onglet { border: 1px solid var(--trait); border-radius: 8px; background: var(--surface); color: var(--texte); font: 500 13.5px var(--mono); padding: 6px 12px; cursor: pointer; }
.onglet:hover { border-color: var(--accent); }
.onglet[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); }
.projet .CodeMirror { height: 340px; }
.grille { list-style: none; margin: 10px 0 24px; padding: 0; }
.grille li { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--trait); }
.marque-controle { font-weight: 700; width: 1em; flex: none; }
.grille .reussi .marque-controle { color: var(--accent); }
.grille .manque .marque-controle { color: var(--erreur); }
.detail { color: var(--texte-doux); font-size: 14px; }
.bac-a-sable h2 { font-size: 22px; margin: 26px 0 10px; }

.chargement, .noscript, .introuvable { padding: 48px 24px; text-align: center; color: var(--texte-doux); }

@media (max-width: 920px) {
  .lecon { grid-template-columns: minmax(0, 1fr); }
  .atelier { position: static; height: auto; overflow: visible; border-left: 0; border-top: 1px solid var(--trait); }
  .resultat { max-height: 60vh; }
}
@media (max-width: 560px) {
  .entete { gap: 12px; padding: 9px 16px; flex-wrap: wrap; position: static; }
  .progression-globale { font-size: 13px; }
  .accueil { padding: 32px 16px 56px; }
  .cours { padding: 24px 16px 36px; }
  .atelier { padding: 18px 16px 32px; }
  .bac-a-sable { padding: 24px 16px 48px; }
  .raccourci { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
