/* ---------- Thème clair (par défaut) ---------- */
:root {
  --largeur: 64rem;

  --fond: #F6F7F9;
  --surface: #FFFFFF;
  --encre: #1B2533;
  --encre-douce: #4A5566;
  --trait: #D5DAE1;
  --code-fond: #E1E6EE;
  --code-trait: #C2CAD6;
  --lien: #1F5FAD;

  --cours: #1F5FAD;
  --td: #8A5A00;
  --tp: #1D7A6B;
  --eval: #B3261E;

  --brouillon-fond: #FFF4D6;
  --brouillon-trait: #E0B84C;

  --syn-mot: #A626A4;
  --syn-type: #986801;
  --syn-chaine: #3E8A3D;
  --syn-nombre: #0B6FA4;
  --syn-comm: #6B7482;
  --syn-fonction: #2F63C8;

  --texte: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

/* ---------- Thème sombre : système, sauf choix « clair » ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #15191F;
    --surface: #1E232B;
    --encre: #D7DCE3;
    --encre-douce: #9AA4B2;
    --trait: #323A46;
    --code-fond: #2A313C;
    --code-trait: #45505F;
    --lien: #7FB0F0;
    --cours: #7FB0F0;
    --td: #E0B060;
    --tp: #5CC4B0;
    --eval: #F08A80;
    --brouillon-fond: #3A2F10;
    --brouillon-trait: #8A6D1F;
    --syn-mot: #C792EA;
    --syn-type: #FFCB6B;
    --syn-chaine: #C3E88D;
    --syn-nombre: #F78C6C;
    --syn-comm: #7F8A99;
    --syn-fonction: #82AAFF;
    color-scheme: dark;
  }
}

/* ---------- Thème sombre : choix explicite ---------- */
:root[data-theme="dark"] {
  --fond: #15191F;
  --surface: #1E232B;
  --encre: #D7DCE3;
  --encre-douce: #9AA4B2;
  --trait: #323A46;
  --code-fond: #2A313C;
  --code-trait: #45505F;
  --lien: #7FB0F0;
  --cours: #7FB0F0;
  --td: #E0B060;
  --tp: #5CC4B0;
  --eval: #F08A80;
  --brouillon-fond: #3A2F10;
  --brouillon-trait: #8A6D1F;
  --syn-mot: #C792EA;
  --syn-type: #FFCB6B;
  --syn-chaine: #C3E88D;
  --syn-nombre: #F78C6C;
  --syn-comm: #7F8A99;
  --syn-fonction: #82AAFF;
  color-scheme: dark;
}

/* ---------- Mise en page : pied collé en bas ---------- */
* { box-sizing: border-box; }
html { font-size: 112.5%; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--fond);
  color: var(--encre);
  font-family: var(--texte);
  line-height: 1.55;
}
.interieur { max-width: var(--largeur); margin: 0 auto; padding: .7rem 1.5rem; }
main { flex: 1; width: 100%; max-width: var(--largeur); margin: 0 auto; padding: 2rem 1.5rem 3rem; }

/* En-tête */
.site-entete { background: var(--surface); border-bottom: 1px solid var(--trait); }
.site-entete .interieur { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.site-titre { font-weight: 700; font-size: 1.1rem; color: var(--encre); text-decoration: none; }
.theme {
  display: grid; place-items: center;
  width: 2.25rem; height: 2.25rem;
  color: var(--encre-douce); background: none;
  border: 1px solid var(--trait); border-radius: 6px; cursor: pointer;
}
.theme:hover { color: var(--encre); border-color: var(--encre-douce); }
.icone-soleil { display: none; }
:root[data-theme="dark"] .icone-lune { display: none; }
:root[data-theme="dark"] .icone-soleil { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icone-lune { display: none; }
  :root:not([data-theme="light"]) .icone-soleil { display: block; }
}

/* Pied de page */
.site-pied { border-top: 1px solid var(--trait); color: var(--encre-douce); font-size: .9rem; }
.site-pied p { margin: .3rem 0; }

/* ---------- Texte ---------- */
h1 { font-size: 2rem; line-height: 1.2; margin: .25rem 0 1rem; }
h2 { font-size: 1.45rem; line-height: 1.3; margin: 2.5rem 0 .75rem; }
h3 { font-size: 1.15rem; margin: 1.75rem 0 .5rem; }
a { color: var(--lien); }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 3px solid var(--lien); outline-offset: 2px; }
img { max-width: 100%; height: auto; }

/* ---------- Code ---------- */
code {
  font-family: var(--mono);
  font-size: .88em;
  color: var(--encre);
  background: var(--code-fond);
  border: 1px solid var(--code-trait);
  border-radius: 4px;
  padding: .05em .35em;
}
pre {
  position: relative;
  margin: 1rem 0;
  font-family: var(--mono);
  font-size: .85rem;
  line-height: 1.45;
  background: var(--surface);
  border: 1px solid var(--code-trait);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }
div.highlight { margin: 1rem 0; }
div.highlight pre { margin: 0; }
.copier {
  position: absolute; top: .5rem; right: .5rem;
  font-family: var(--texte); font-size: .8rem;
  padding: .2rem .6rem;
  color: var(--encre-douce); background: var(--fond);
  border: 1px solid var(--trait); border-radius: 4px; cursor: pointer;
}

/* Coloration syntaxique (Rouge) */
.highlight :is(.k, .kd, .kn, .kr, .kc, .kp) { color: var(--syn-mot); }
.highlight .kt { color: var(--syn-type); }
.highlight :is(.s, .s1, .s2, .sc, .se, .sb, .sd, .sh, .si, .sx) { color: var(--syn-chaine); }
.highlight :is(.m, .mi, .mf, .mh, .mo, .il) { color: var(--syn-nombre); }
.highlight :is(.c, .c1, .cm, .cs, .cp) { color: var(--syn-comm); font-style: italic; }
.highlight :is(.nf, .nb, .fm) { color: var(--syn-fonction); }

/* ---------- Tableaux ---------- */
table { border-collapse: collapse; margin: 1rem 0; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--trait); padding: .4rem .7rem; text-align: left; vertical-align: top; }
th { background: var(--code-fond); }

/* ---------- Couleur par type ---------- */
.type-cours { --type: var(--cours); }
.type-td    { --type: var(--td); }
.type-tp    { --type: var(--tp); }
.type-eval  { --type: var(--eval); }

/* ---------- Page d'un document ---------- */
.fil { font-size: .9rem; color: var(--encre-douce); }
.fil a { color: inherit; }
.doc-entete { border-left: 6px solid var(--type); padding: .25rem 0 .25rem 1rem; margin: 1rem 0 2rem; }
.badge { color: var(--type); font-weight: 700; margin: 0; }
.meta { color: var(--encre-douce); margin: 0; }
.fichiers { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.bouton {
  display: inline-block; padding: .35rem .8rem;
  border: 1px solid var(--type, var(--lien)); border-radius: 4px;
  color: var(--type, var(--lien)); font-weight: 700; font-size: .9rem; text-decoration: none;
}
.bouton:hover { background: var(--type, var(--lien)); color: var(--surface); }
.brouillon { background: var(--brouillon-fond); border: 1px solid var(--brouillon-trait); border-radius: 4px; padding: .6rem .9rem; }

/* ---------- Page d'une classe : chapitres repliables ---------- */
.chapitre { background: var(--surface); border: 1px solid var(--trait); border-radius: 6px; margin: .75rem 0; }
.chapitre > summary {
  display: flex; align-items: center; flex-wrap: wrap; gap: .25rem 1rem;
  padding: .9rem 1.25rem; cursor: pointer; list-style: none;
}
.chapitre > summary::-webkit-details-marker { display: none; }
.chapitre > summary::before {
  content: "";
  flex: none;
  width: .5rem; height: .5rem;
  border-right: 2px solid var(--encre-douce);
  border-bottom: 2px solid var(--encre-douce);
  transform: rotate(-45deg);
  transition: transform .15s;
}
.chapitre[open] > summary::before { transform: rotate(45deg); }
.chapitre > summary h2 { margin: 0; font-size: 1.2rem; }
.chapitre-types { color: var(--encre-douce); font-size: .9rem; margin-left: auto; }
.chapitre-contenu { padding: 0 1.25rem 1rem 2.4rem; }
.groupe { border-left: 4px solid var(--type); padding-left: 1rem; margin: 1rem 0; }
.groupe h3 { color: var(--type); font-size: 1rem; margin: 0 0 .35rem; }
.groupe ul { margin: 0; padding-left: 1.1rem; }
.duree { color: var(--encre-douce); font-size: .9rem; }

/* ---------- Accueil ---------- */
.niveaux { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; }
.niveaux a {
  display: block; padding: 1.25rem 1.5rem;
  background: var(--surface); border: 1px solid var(--trait); border-radius: 6px;
  color: var(--encre); font-size: 1.3rem; font-weight: 700; text-decoration: none;
}
.niveaux a:hover { border-color: var(--lien); }
.niveaux a span { display: block; color: var(--encre-douce); font-size: 1rem; font-weight: 400; }

@media (prefers-reduced-motion: reduce) {
  .chapitre > summary::before { transition: none; }
}

/* ---------- Impression des sujets ---------- */
@media print {
  :root { color-scheme: light; }
  .site-entete, .site-pied, .fil, .copier, .fichiers, .brouillon { display: none; }
  body { display: block; background: #FFFFFF; color: #000000; font-size: 11pt; }
  main { max-width: none; padding: 0; }
  a { color: inherit; text-decoration: none; }
  code, pre { background: #FFFFFF; border-color: #999999; color: #000000; }
  th, td { border-color: #999999; }
  h2, h3 { break-after: avoid; }
  pre, table, img { break-inside: avoid; }
}

/* ---------- Encadrés GitHub : > [!NOTE], [!TIP], [!IMPORTANT], [!WARNING], [!CAUTION] ---------- */
:root {
  --alerte-note: #1F5FAD;
  --alerte-tip: #1A7F37;
  --alerte-important: #8250DF;
  --alerte-warning: #9A6700;
  --alerte-caution: #CF222E;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --alerte-note: #4493F8;
    --alerte-tip: #3FB950;
    --alerte-important: #AB7DF8;
    --alerte-warning: #D29922;
    --alerte-caution: #F85149;
  }
}
:root[data-theme="dark"] {
  --alerte-note: #4493F8;
  --alerte-tip: #3FB950;
  --alerte-important: #AB7DF8;
  --alerte-warning: #D29922;
  --alerte-caution: #F85149;
}

.markdown-alert {
  margin: 1rem 0;
  padding: .5rem 1rem;
  background: var(--surface);
  border-left: 4px solid var(--alerte);
  border-radius: 0 6px 6px 0;
}
.markdown-alert-note      { --alerte: var(--alerte-note); }
.markdown-alert-tip       { --alerte: var(--alerte-tip); }
.markdown-alert-important { --alerte: var(--alerte-important); }
.markdown-alert-warning   { --alerte: var(--alerte-warning); }
.markdown-alert-caution   { --alerte: var(--alerte-caution); }

.markdown-alert-title {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .25rem 0;
  font-weight: 700;
  color: var(--alerte);
}
.markdown-alert-title svg { fill: currentColor; flex: none; }
.markdown-alert p { margin: .25rem 0; }

@media print {
  .markdown-alert { background: #FFFFFF; }
}
