/* site.css — presentation for the public exercise site.
   All visual choices live here (html.py emits markup only). Organised as:
   tokens · base · header/footer · catalog · exercise · parts · source · assets. */

/* ---- tokens ---------------------------------------------------------- */
/* Theming — every colour token is written ONCE as light-dark(light, dark).
   Which side applies is driven by `color-scheme`: default `light dark` follows
   the OS (works without JS); the header toggle forces it by setting data-theme
   on <html> (persisted). Requires light-dark() (baseline 2024). */
:root {
  color-scheme: light dark;
  --fg: light-dark(#1a1a1a, #e6e6e6);
  --muted: light-dark(#666, #9aa0a6);
  --bg: light-dark(#fdfdfc, #16181d);
  --card: light-dark(#fff, #1f2228);
  --line: light-dark(#e3e3e0, #33373f);
  --accent: light-dark(#34506b, #8fb3d9);
  --relu: light-dark(#2f7d43, #4bbf67);
  --arelire: light-dark(#b06a12, #d99a3c);
  --code-bg: light-dark(#f6f6f4, #23262d);
  --shadow: light-dark(rgba(0, 0, 0, .14), rgba(0, 0, 0, .55));
  --radius: 8px;
  --maxw: 52rem;
  --gap: 1rem;
  --font: "New Computer Modern", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

/* Non-colour dark switch (light-dark() only produces colours): --dark = 0|1,
   set by the SAME condition as color-scheme (forced theme, else OS). Rendered
   exercise SVGs are plain black-on-white; in dark we invert the <img> (light
   text + figures; hue-rotate keeps colours roughly true). */
:root { --dark: 0; }
:root[data-theme="dark"] { --dark: 1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --dark: 1; }
}
.render img, .apercu {
  filter: invert(var(--dark)) hue-rotate(calc(var(--dark) * 180deg));
}

/* ---- base ------------------------------------------------------------ */
* { box-sizing: border-box; }
body {
  margin: 0; color: var(--fg); background: var(--bg);
  font-family: var(--font); line-height: 1.5;
}
main { max-width: var(--maxw); margin: 0 auto; padding: var(--gap); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; }
.muted { color: var(--muted); font-size: .9em; }

/* ---- header / footer ------------------------------------------------- */
.site-header, .site-footer {
  padding: .75rem var(--gap); border-bottom: 1px solid var(--line);
  display: flex; gap: 1rem; align-items: baseline;
}
.site-footer { border: 0; border-top: 1px solid var(--line); color: var(--muted);
  font-size: .9rem; justify-content: center; margin-top: 3rem; }
.brand { font-weight: bold; text-decoration: none; color: var(--fg); }
.site-header nav { margin-left: auto; display: flex; flex-wrap: wrap; gap: .9rem; }
.site-header nav a.active { font-weight: bold; color: var(--fg); }
.theme-toggle { font: inherit; cursor: pointer; line-height: 1; padding: .2rem .55rem;
  background: var(--card); color: var(--fg); border: 1px solid var(--line);
  border-radius: var(--radius); }
.theme-toggle:hover { border-color: var(--accent); }

/* ---- icons (inline SVG sprite in _icons.html; currentColor -> dark-mode free) - */
.icon { width: 1em; height: 1em; vertical-align: -0.125em; }

/* ---- chips ----------------------------------------------------------- */
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem;
  padding: 0; margin: .6rem 0 0; }
.chip { font-size: .75rem; padding: .1rem .5rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--card); color: var(--muted);
  vertical-align: middle; }
.chip-duree, .chip-importance { color: var(--fg); }
.chip-indic { color: var(--arelire); border-color: var(--arelire); }
.chip-solu { color: var(--relu); border-color: var(--relu); }
/* « vu » : vraie checkbox + label, discrète ; l'état coché teinte le chip en
   vert (couleur de succès), lisible en clair comme en sombre (variable partagée). */
.chip-vu label { display: inline-flex; align-items: center; gap: .3rem;
  cursor: pointer; }
.chip-vu input { margin: 0; cursor: pointer; }
.chip-vu.is-vu { color: var(--relu); border-color: var(--relu); }

/* ---- catalog --------------------------------------------------------- */
/* The toolbar sticks while scrolling the (long) list; it needs an opaque
   background and a hairline to read as a layer over the rows. */
.catalog-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  margin: .5rem 0 1rem; position: sticky; top: 0; z-index: 20;
  background: var(--bg); padding: .6rem 0; border-bottom: 1px solid var(--line); }
.filter { flex: 1 1 12rem; padding: .5rem .75rem; font: inherit;
  background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); }
/* facet = a <details> dropdown chip whose panel holds the checkboxes
   (OR within a facet, AND across facets). Chips keep the toolbar one tidy row. */
details.facet { position: relative; }
details.facet > summary { list-style: none; cursor: pointer; user-select: none;
  padding: .45rem .7rem; font-size: .9rem; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); white-space: nowrap; }
details.facet > summary::-webkit-details-marker { display: none; }
details.facet > summary::after { content: " ▾"; color: var(--muted); font-size: .8em; }
details.facet[open] > summary, details.facet > summary:hover {
  border-color: var(--accent); }
.facet-count { color: var(--accent); font-weight: 600; }
.facet-panel { position: absolute; z-index: 10; top: calc(100% + .3rem); left: 0;
  min-width: 10rem; max-height: 14rem; overflow-y: auto;
  display: flex; flex-direction: column; gap: .15rem; padding: .5rem .75rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 6px 22px var(--shadow); }
.facet-panel label { display: flex; align-items: center; gap: .4rem;
  font-size: .9rem; white-space: nowrap; }
.facet-panel input { margin: 0; }
.facet-panel-tall { max-height: 18rem; }  /* the 31-chapter list scrolls */
/* chips near the toolbar's right end would overflow the viewport with a
   left-anchored panel: anchor the last two to the right instead */
details.facet:nth-last-of-type(-n+2) .facet-panel { left: auto; right: 0; }
/* sort stays a single-choice dropdown, inline like the chips */
.sort-ctl { display: inline-flex; align-items: center; gap: .35rem;
  font-size: .85rem; color: var(--muted); }
.sort-ctl select { font: inherit; padding: .42rem .5rem; background: var(--card);
  color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius); }
/* "Au hasard" / "Sélectionner" — same chip look as the facets */
.random, .select-toggle { font: inherit; font-size: .9rem; cursor: pointer;
  padding: .45rem .7rem; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); white-space: nowrap; }
.random:hover, .select-toggle:hover { border-color: var(--accent); }
.select-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.select-badge { color: var(--accent); font-weight: 600; }

/* selection mode: per-row checkbox, hidden until the mode is on (.selecting).
   No dead control without JS — the mode can only be entered by the script. */
.sel-toggle { display: none; margin-right: .5rem; cursor: pointer;
  vertical-align: baseline; }
.catalog.selecting .sel-toggle { display: inline-block; }
/* reserve the fixed bar's height so the last rows stay reachable in the mode */
.catalog.selecting { padding-bottom: 4rem; }
/* sticky bar (bottom of the viewport), only while the mode is active */
.select-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: .6rem;
  padding: .7rem var(--gap); background: var(--card);
  border-top: 1px solid var(--line); box-shadow: 0 -6px 22px var(--shadow); }
.select-bar[hidden] { display: none; }
.select-count { font-weight: 600; margin-right: auto; }
.select-bar button { font: inherit; font-size: .9rem; cursor: pointer;
  padding: .4rem .7rem; background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); white-space: nowrap; }
.select-bar button:hover:not([disabled]) { border-color: var(--accent); }
.select-bar button[disabled] { opacity: .5; cursor: default; }
/* active-filter recap: removable chips + clear-all + live count */
.active-filters { flex-basis: 100%; display: flex; flex-wrap: wrap; gap: .35rem;
  align-items: center; margin: 0; font-size: .85rem; }
.active-filters[hidden] { display: none; }
.chips-live { display: contents; }
.chip-active { font: inherit; font-size: .78rem; cursor: pointer;
  padding: .12rem .55rem; color: var(--accent); background: var(--card);
  border: 1px solid var(--accent); border-radius: var(--radius); }
.chip-active:hover { background: var(--accent); color: var(--bg); }
.clear-all { font: inherit; font-size: .78rem; cursor: pointer;
  padding: .12rem .55rem; color: var(--muted); background: none;
  border: none; text-decoration: underline; }
.clear-all:hover { color: var(--fg); }
.fcount { margin-left: auto; }

/* theme sections: collapsed <details>, heading + count on the summary line */
details.theme > summary { list-style: none; cursor: pointer; user-select: none;
  display: flex; align-items: baseline; gap: .6rem; padding: .55rem 0;
  border-bottom: 1px solid var(--line); }
details.theme > summary::-webkit-details-marker { display: none; }
details.theme > summary::before { content: "▸"; color: var(--muted);
  font-size: .8em; transition: transform .12s; }
details.theme[open] > summary::before { transform: rotate(90deg); }
details.theme > summary h2 { display: inline; margin: 0; font-size: 1.2rem; }
details.theme > summary:hover h2 { color: var(--accent); }
.theme-count { font-size: .85rem; }

.exo-list { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.exo-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.exo-list a { text-decoration: none; font-weight: 600; }
/* done ("vu") rows: dimmed + a ✓ before the title (state signalled by the glyph,
   not by colour alone — the ✓ carries it for colour-blind readers). */
.exo-list li.vu { opacity: .55; }
.exo-list li.vu > a::before { content: "✓ "; color: var(--relu); font-weight: 700; }
/* per-chapter done counter, on the summary line next to .theme-count */
.done-count { font-size: .85rem; }
/* "réinitialiser les vus" — a plain button inside the Vus dropdown panel */
.reset-done { font: inherit; font-size: .85rem; cursor: pointer; margin-top: .4rem;
  padding: .3rem .55rem; text-align: left; color: var(--fg); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); }
.reset-done:hover { border-color: var(--accent); }
/* per-row statement preview: the énoncé SVG. The switch sits apart at the right
   end of the toolbar and is ON by default (checked server-side); loading="lazy"
   means only rows scrolled into view fetch their SVG. */
.toggle-switch { display: inline-flex; align-items: center;
  gap: .45rem; cursor: pointer; font-size: .9rem; font-weight: 600;
  color: var(--fg); }
.toggle-group { margin-left: auto; }  /* first of the toggle pair: pushes both right */
.toggle-switch input { appearance: none; margin: 0; cursor: pointer;
  width: 2.15rem; height: 1.2rem; border-radius: 1rem;
  background: var(--line); position: relative; transition: background .15s; }
.toggle-switch input::after { content: ""; position: absolute;
  top: .13rem; left: .14rem; width: .94rem; height: .94rem; border-radius: 50%;
  background: var(--card); box-shadow: 0 1px 3px var(--shadow);
  transition: transform .15s; }
.toggle-switch input:checked { background: var(--accent); }
.toggle-switch input:checked::after { transform: translateX(.93rem); }
.apercu { display: none; }
/* No card chrome here: the énoncé SVG carries its own box/background, and a CSS
   background/border would be inverted by the dark-mode filter (a light "halo"). */
.catalog.enonces .apercu { display: block; max-width: 100%; height: auto;
  margin: .45rem 0 .2rem; }

/* ---- exercise -------------------------------------------------------- */
.exo-head { margin-bottom: 1.5rem; }
.part { margin: 1rem 0; }
.render { margin: 0; }
.render img { max-width: 100%; height: auto; display: block; }

/* Visually hidden but exposed to screen readers and crawlers: the flattened
   énoncé text alternative to the SVG (the SVG stays the visible rendering). */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

/* reveal (indication/solution) */
details.part { border: 1px solid var(--line); border-radius: var(--radius);
  padding: .25rem .75rem; background: var(--card); }
details.part > summary { cursor: pointer; font-weight: 600; padding: .5rem 0; }
details.part[open] > summary { border-bottom: 1px solid var(--line);
  margin-bottom: .75rem; }

/* ---- source (copyable, collapsible like indication/solution) -------- */
.source-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .6rem; }
.copy { font: inherit; font-size: .85rem; padding: .25rem .75rem; cursor: pointer;
  color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); }
.copy:hover { border-color: var(--accent); }
pre.src { background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem 1rem; overflow: auto; font-family: var(--mono); font-size: .82rem;
  line-height: 1.45; }

/* ---- assets (nested under the Source Typst reveal, below the code) --- */
.assets { margin-top: 1rem; }
.assets h2 { font-size: 1rem; margin: 0 0 .4rem; }
.assets ul { padding-left: 1.2rem; }

/* ---- remarque (formulaire de contact — seul composant dynamique) ----- */
/* Dépliant « Une remarque ? » sous la source : hérite du style .part/details.
   Le honeypot .hp est hors écran (bots seuls le remplissent) ; les notes
   .form-note (succès/erreur) vivent HORS du <details>, révélées par :target. */
.remarque-intro { margin: 0 0 .75rem; color: var(--muted); font-size: .9rem; }
.remarque-form { display: flex; flex-direction: column; gap: .5rem; }
.remarque-form > label { font-size: .9rem; font-weight: 600; }
.remarque-form textarea, .remarque-form input[type="email"],
.remarque-form input[name="verif"] {
  font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: .5rem .6rem; max-width: 100%; }
.remarque-form textarea { min-height: 6rem; resize: vertical; }
.remarque-form textarea:focus, .remarque-form input[type="email"]:focus,
.remarque-form input[name="verif"]:focus {
  outline: 2px solid var(--accent); outline-offset: 1px; }
.remarque-form button { align-self: flex-start; font: inherit; font-size: .9rem;
  cursor: pointer; padding: .45rem .9rem; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); }
.remarque-form button:hover { border-color: var(--accent); }
/* honeypot : hors écran mais PAS display:none (certains bots ignorent display) */
.remarque-form .hp { position: absolute; left: -9999px; width: 1px; height: 1px;
  overflow: hidden; }
/* notes de résultat : cachées par défaut, montrées quand l'URL porte leur hash */
.form-note { display: none; margin: 1rem 0; padding: .6rem .8rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); }
.form-note:target { display: block; }

/* ---- prev / next (exercise page, manifest order) --------------------- */
.exo-nav { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem;
  align-items: baseline; margin-bottom: 1.5rem; padding-bottom: .75rem;
  border-bottom: 1px solid var(--line); font-size: .9rem; }
.exo-nav a { text-decoration: none; }
.exo-nav .nav-next { text-align: right; }
.exo-nav .nav-chapter { text-align: center; white-space: nowrap; }

/* ---- planche (worksheet rebuilt client-side from the URL hash) ------- */
.planche-actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0; }
.planche-actions[hidden] { display: none; }
.planche-actions button { font: inherit; font-size: .9rem; cursor: pointer;
  padding: .45rem .7rem; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); white-space: nowrap; }
.planche-actions button:hover:not([disabled]) { border-color: var(--accent); }
.planche-actions button[disabled] { opacity: .5; cursor: default; }
.planche-summary { margin: .5rem 0 1rem; }
.planche-list { list-style: none; padding: 0; margin: 0 0 1.5rem; }
.planche-row { padding: .4rem 0; border-bottom: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .6rem; }
.planche-row a { text-decoration: none; font-weight: 600; }
/* done ("vu") rows: dimmed + a ✓ before the title (glyph carries the state,
   not colour alone — like the catalog). */
.planche-row.vu { opacity: .6; }
.planche-row.vu > a::before { content: "✓ "; color: var(--relu); font-weight: 700; }
.planche-meta { color: var(--muted); font-size: .9em; display: inline-flex;
  flex-wrap: wrap; align-items: baseline; gap: .2rem .6rem; }
/* réordonner / retirer : petits contrôles discrets, poussés à droite de la ligne */
.planche-ctrl { margin-left: auto; display: inline-flex; gap: .15rem; }
.planche-ctrl-btn { font: inherit; font-size: .85rem; line-height: 1; cursor: pointer;
  padding: .15rem .45rem; color: var(--muted); background: none;
  border: 1px solid transparent; border-radius: var(--radius); }
.planche-ctrl-btn:hover:not([disabled]) { color: var(--fg);
  border-color: var(--line); background: var(--card); }
.planche-ctrl-btn[disabled] { opacity: .35; cursor: default; }
/* unknown id (renamed / partial dev manifest): degraded line, never fatal */
.planche-missing { color: var(--muted); font-style: italic; }

/* ---- atelier PDF (phase 3 : Typst WASM dans le navigateur) ------------ */
.atelier { margin: 2rem 0 1rem; padding: 1rem; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); }
.atelier[hidden] { display: none; }
.atelier h2 { margin: 0 0 .75rem; font-size: 1.1rem; }
.atelier-form { display: flex; flex-wrap: wrap; gap: .75rem 1rem; margin-bottom: .75rem; }
.atelier-form label { display: flex; flex-direction: column; gap: .25rem;
  font-size: .85rem; color: var(--muted); flex: 1 1 14rem; }
.atelier-form input { font: inherit; font-size: .95rem; color: var(--fg);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .4rem .55rem; }
.atelier-form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.atelier-status { margin: .5rem 0; font-size: .9rem; min-height: 1.2em; }
.atelier-error { margin: .5rem 0; font-size: .9rem;
  color: light-dark(#b00020, #ff8a80); white-space: pre-line; }
.atelier-buttons { display: flex; flex-wrap: wrap; gap: .6rem; margin: .5rem 0 1rem; }
.atelier-buttons button { font: inherit; font-size: .9rem; cursor: pointer;
  padding: .45rem .7rem; background: var(--card); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--radius); white-space: nowrap; }
.atelier-buttons button:hover:not([disabled]) { border-color: var(--accent); }
.atelier-buttons button[disabled] { opacity: .5; cursor: default; }
/* Aperçu : le PDF compilé, affiché en lecture seule dans un iframe (blob).
   Fond blanc dans les deux thèmes (c'est un aperçu du papier). */
.atelier-preview { border: 1px solid var(--line);
  border-radius: var(--radius); background: #fff; overflow: hidden; }
.atelier-preview:empty { display: none; }
.atelier-preview-frame { display: block; width: 100%; height: 70vh; border: 0; }

/* ---- shell mode (intégration dans un site hôte) ---------------------- */
/* Monté dans le site perso (SitePerso), l'hôte injecte SA feuille de style
   (le composant « topbar » du moteur) AVANT celle-ci ; base.html rend alors le
   balisage topbar du moteur et pose `body.shell`. Ces règles ne font que
   réconcilier les retombées de nos propres tokens :root pour que la topbar soit
   une copie fidèle de celle du moteur — le corps (exercices / catalogue) garde
   le style de la banque. Hors shell, rien ne matche : rendu inchangé. */

/* La nav / les boutons de la topbar héritent de la police du corps ; le moteur
   y utilise Inter (la marque garde Spectral via .home). Notre corps est serif :
   on réaffirme Inter, et les tokens que notre :root a écrasés (valeurs claires). */
body.shell .topbar {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --accent: #1e50c8;
  --bg: #fafbfe;
  --muted: #6a6d7e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 8px 24px rgba(20, 20, 40, .05);
}
/* Sombre : on restaure les tokens sombres de la topbar du moteur (sinon nos
   overrides ci-dessus, plus spécifiques que son :root[data-theme=dark], gagnent). */
html[data-theme="dark"] body.shell .topbar {
  --accent: #6f9bf2;
  --bg: #13141b;
  --muted: #989bb2;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
}
/* La topbar de l'hôte est collante (top:0). Le catalogue a DÉJÀ sa propre barre
   d'outils collante (z-index supérieur) qui, sinon, recouvrirait la topbar : sur
   cette seule page on laisse la topbar défiler (la topbar collante reste sur
   toutes les pages d'exercice). */
body.shell:has(.catalog) .topbar { position: static; }
