/* ---------------------------------------------------------------------------
   TeachBox — wiki public, servi sur /wiki
   Feuille unique, sans dépendance externe : le wiki doit rester lisible
   même si le reste du site est indisponible.
   --------------------------------------------------------------------------- */

:root {
  --fond: #fbfbfd;
  --carte: #ffffff;
  --texte: #16181d;
  --texte-doux: #4a4f5a;
  --texte-faible: #7c828e;
  --bord: #e4e6eb;
  --accent: #2f4fd8;
  --accent-doux: #eef1fd;
  --ok: #157a4a;
  --ok-doux: #e8f6ee;
  --alerte: #b3261e;
  --alerte-doux: #fdeceb;
  --attention: #8a5a00;
  --attention-doux: #fdf3e2;

  /* Texte posé sur un aplat d'accent : en clair l'accent est sombre et porte
     du blanc ; en sombre il s'éclaircit, et du blanc dessus ne se lit plus. */
  --sur-accent: #ffffff;

  --rayon: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f1116;
    --carte: #171a21;
    --texte: #f0f2f6;
    --texte-doux: #b8bec9;
    --texte-faible: #868d9a;
    --bord: #2a2f39;
    --accent: #8ba4ff;
    --accent-doux: #1b2237;
    --ok: #6ddba0;
    --ok-doux: #13291f;
    --alerte: #ff9d95;
    --alerte-doux: #2e1917;
    --attention: #f0c274;
    --attention-doux: #2b2113;
    --sur-accent: #0f1116;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.enveloppe { max-width: 780px; margin: 0 auto; padding: 0 clamp(15px, 4.5vw, 20px) 80px; }

/* La barre de navigation, son second niveau et le pied prennent la largeur de
   la présentation — 1000 px — pour que le menu soit le même d'un bout à l'autre
   du site public. Le corps de l'article, lui, reste à 780 : c'est une mesure de
   lecture, et l'élargir rendrait les lignes trop longues à suivre. */
header.site .enveloppe,
.sous-nav .enveloppe,
footer.site .enveloppe { max-width: 1000px; }

/* --- En-tête ------------------------------------------------------------- */

header.site {
  border-bottom: 1px solid var(--bord);
  background: var(--carte);
  position: sticky; top: 0; z-index: 10;
}
header.site .enveloppe {
  padding-top: 14px; padding-bottom: 14px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit; font-weight: 650;
}
.logo .marque {
  width: 30px; height: 30px; flex: none;
}
nav.site { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
nav.site a {
  color: var(--texte-doux); text-decoration: none;
  padding: 6px 12px; border-radius: 999px; font-size: .92rem;
}
nav.site a:hover { background: var(--accent-doux); color: var(--accent); }
/* Section courante du premier niveau — le wiki, ici. */
nav.site a.actif { color: var(--accent); font-weight: 600; }

/* Bouton d'action, identique à celui de la page de présentation. */
.bouton {
  display: inline-block; text-decoration: none; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--bord);
  color: var(--texte); background: var(--carte); font-size: .9rem;
}
.bouton:hover { border-color: var(--accent); color: var(--accent); }
.bouton.primaire { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); }
.bouton.primaire:hover { filter: brightness(1.08); color: var(--sur-accent); }

/* Second niveau : les guides du wiki. Il n'apparaît que dans le wiki.
   Volontairement non collant : le caler sous l'en-tête supposerait de connaître
   sa hauteur exacte, un nombre magique qui casse dès qu'on touche au menu. */
.sous-nav {
  border-bottom: 1px solid var(--bord); background: var(--fond);
}
.sous-nav .enveloppe {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding-top: 9px; padding-bottom: 9px;
}
.sous-nav a {
  color: var(--texte-doux); text-decoration: none;
  padding: 5px 12px; border-radius: 999px; font-size: .89rem;
}
.sous-nav a:hover { background: var(--accent-doux); color: var(--accent); }
.sous-nav a[aria-current="page"] { background: var(--accent); color: var(--sur-accent); }

/* --- Texte --------------------------------------------------------------- */

h1 { font-size: 1.85rem; line-height: 1.25; margin: 32px 0 8px; letter-spacing: -.02em; }
h2 {
  font-size: 1.25rem; margin: 40px 0 10px;
  padding-top: 20px; border-top: 1px solid var(--bord);
}
h3 { font-size: 1.02rem; margin: 24px 0 6px; }
p, ul, ol { margin: 10px 0; }
li { margin: 5px 0; }
a { color: var(--accent); }
.chapeau { font-size: 1.06rem; color: var(--texte-doux); margin-bottom: 4px; }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .875em; background: var(--accent-doux); color: var(--accent);
  padding: 1px 6px; border-radius: 5px;
  overflow-wrap: anywhere;
}

/* --- Blocs --------------------------------------------------------------- */

.encart {
  border: 1px solid var(--bord); border-left-width: 4px;
  border-radius: var(--rayon); padding: 12px 16px; margin: 18px 0;
  background: var(--carte);
}
.encart p:first-child { margin-top: 0; }
.encart p:last-child { margin-bottom: 0; }
.encart.info      { border-left-color: var(--accent);    background: var(--accent-doux); }
.encart.ok        { border-left-color: var(--ok);        background: var(--ok-doux); }
.encart.attention { border-left-color: var(--attention); background: var(--attention-doux); }
.encart.alerte    { border-left-color: var(--alerte);    background: var(--alerte-doux); }
.encart .titre { font-weight: 650; }

/* Cartes d'orientation de la page d'accueil */
.portes { display: grid; gap: 14px; margin: 26px 0; }
@media (min-width: 640px) { .portes { grid-template-columns: repeat(3, 1fr); } }
.porte {
  display: block; text-decoration: none; color: inherit;
  background: var(--carte); border: 1px solid var(--bord);
  border-radius: var(--rayon); padding: 18px;
}
.porte:hover { border-color: var(--accent); }
.porte .pour { font-size: .74rem; text-transform: uppercase; letter-spacing: .09em; color: var(--texte-faible); }
.porte .quoi { font-weight: 650; font-size: 1.1rem; margin: 4px 0 6px; }
.porte .sous { color: var(--texte-doux); font-size: .92rem; }

/* Étapes numérotées */
ol.etapes { counter-reset: e; list-style: none; padding: 0; }
ol.etapes > li {
  counter-increment: e; position: relative;
  padding: 0 0 4px 42px; margin: 16px 0;
}
ol.etapes > li::before {
  content: counter(e);
  position: absolute; left: 0; top: 1px;
  width: 28px; height: 28px; border-radius: 50%;

  display: grid; place-items: center; font-size: .85rem; font-weight: 650;
}
ol.etapes > li > strong { display: block; }

/* Tableaux */
.tableau { overflow-x: auto; margin: 16px 0; }
table {
  width: 100%; border-collapse: collapse; font-size: .94rem;
  background: var(--carte); border: 1px solid var(--bord); border-radius: var(--rayon);
}
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--bord); vertical-align: top; }
th { font-weight: 620; color: var(--texte-doux); font-size: .84rem; }
tr:last-child td { border-bottom: 0; }

/* Questions fréquentes */
details {
  border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 12px 16px; margin: 10px 0; background: var(--carte);
}
details[open] { border-color: var(--accent); }
summary { cursor: pointer; font-weight: 600; }
summary::marker { color: var(--accent); }
details > *:last-child { margin-bottom: 0; }

footer.site {
  border-top: 1px solid var(--bord); margin-top: 50px; padding: 22px 0;
  color: var(--texte-faible); font-size: .87rem;
}
footer.site .enveloppe { padding-bottom: 0; }

/* --- Téléphones et tablettes ---------------------------------------------- */

html { -webkit-text-size-adjust: 100%; }
h1, h2, h3, p, li, summary, td, th { overflow-wrap: break-word; }

@media (max-width: 640px) {
  /* Même en-tête que la page de présentation : marque et action principale sur
     la première ligne, rubriques centrées en dessous. */
  header.site .enveloppe { gap: 10px; padding-top: 11px; padding-bottom: 11px; }
  .logo { order: 1; }
  /* Deux boutons ne tiennent pas a cote de la marque : ils prennent leur
     propre ligne, en partageant la largeur. */
  header.site .enveloppe > .bouton { order: 3; flex: 1 1 auto; text-align: center; }
  nav.site {
    order: 3; width: 100%; margin-left: 0; justify-content: center; gap: 2px;
    border-top: 1px solid var(--bord); padding-top: 7px;
  }

  /* Deux barres de navigation collantes mangeraient un tiers de l'écran d'un
     téléphone, sur des pages qu'on lit d'une traite. On les laisse défiler. */
  header.site { position: static; }

  .sous-nav .enveloppe { justify-content: center; }

  h1 { font-size: 1.55rem; margin-top: 24px; }
  h2 { font-size: 1.14rem; margin-top: 30px; padding-top: 16px; }
  .chapeau { font-size: 1rem; }
  .encart { padding: 11px 13px; }
  .porte { padding: 15px; }
  ol.etapes > li { padding-left: 38px; }
  /* Un tableau plus large que l'écran défile dans son cadre, pas la page. */
  .tableau { margin-inline: calc(clamp(15px, 4.5vw, 20px) * -1); padding-inline: clamp(15px, 4.5vw, 20px); }
  th, td { padding: 8px 10px; }
  .enveloppe { padding-bottom: 56px; }
  footer.site { margin-top: 36px; }
}

@media (pointer: coarse) {
  nav.site a { padding-top: 10px; padding-bottom: 10px; }
  .sous-nav a { padding-top: 9px; padding-bottom: 9px; }
  summary { padding: 5px 0; }
}

/* --- Sommaire des guides longs -------------------------------------------- */

/* Construit par wiki.js à partir des <h2> réellement présents : une liste
   recopiée à la main finit toujours par désigner un chapitre disparu. */
.sommaire {
  margin: 18px 0 26px;
  padding: 14px 18px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--carte);
}
.sommaire-titre {
  margin: 0 0 8px;
  font-size: .78rem; font-weight: 650; letter-spacing: .06em;
  text-transform: uppercase; color: var(--texte-doux);
}
.sommaire-liste {
  margin: 0; padding: 0; list-style: none;
  display: grid; gap: 4px 22px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  counter-reset: chapitre;
}
.sommaire-liste li { counter-increment: chapitre; }
.sommaire-liste a {
  display: block; padding: 3px 0;
  font-size: .9rem; text-decoration: none;
}
.sommaire-liste a::before {
  content: counter(chapitre) '. ';
  color: var(--texte-doux); font-variant-numeric: tabular-nums;
}
.sommaire-liste a:hover { text-decoration: underline; }

/* La barre de tête est fixe : sans cette marge, une ancre place le titre
   dessous. */
main h2[id] { scroll-margin-top: 90px; }
