/* ═══════════════════════════════════════════════════════════
   APP4 Audition/Vestibule — Feuille de style
   Manuel visuel sobre : ardoise, teal, papier ivoire. Typographie système
   locale (titres à empattements, texte en sans-serif), aucune dépendance distante.
   Les couleurs des figures scientifiques (bleu/orange) sont un code à part :
   elles ne servent ici à aucun décor.
   ═══════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────── */
:root {
  color-scheme: light;
  --ink:        #172630;
  --muted:      #4b5b66;
  --accent:     #0a6a72;
  --accent-dk:  #07525a;
  --line:       #cbd8dc;
  --paper:      #fffefb;
  --tint:       #e8f3f2;
  --tint-2:     #f1f7f7;
  --surface:    #e9eeef;
  --corr-bg:    #fdf8ef;
  --corr-bdr:   #7d5a12;
  --measure:    39rem;       /* colonne de lecture : environ 75 caractères */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: 4.5rem;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
  font: 18px/1.72 var(--sans);
  -webkit-text-size-adjust: 100%;
}

/* ── Skip link ─────────────────────────────────────────── */
.skip-link {
  position: absolute;
  left: -10000px;
  top: 0;
  white-space: nowrap;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  background: white;
  z-index: 200;
  padding: .6rem 1.2rem;
  border-radius: 5px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}

/* ── Barre de progression lecture ──────────────────────── */
#read-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0%;
  background: var(--accent);
  z-index: 300;
  pointer-events: none;
  transition: width .12s linear;
}

/* ── Barre du haut ─────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding: .7rem 2rem;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar a {
  flex: none;
  text-decoration: none;
  font-weight: 650;
  color: var(--ink);
  font-size: .88rem;
  letter-spacing: .01em;
}
.topbar a:hover { color: var(--accent); }
/* Section en cours (ajoutée par cours.js, purement indicative) */
#topbar-section {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: .84rem;
  color: var(--muted);
}

/* ── Mise en page principale ───────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 16.5rem minmax(0, 1fr);
  max-width: 1380px;
  margin: 0 auto;
  gap: 2.5rem;
  padding: 2.25rem 2rem 3rem;
  align-items: start;
  counter-reset: chap nav;
}

/* ── Sommaire latéral ──────────────────────────────────── */
nav#sommaire {
  align-self: start;
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 5.25rem);
  overflow-y: auto;
  font-size: .83rem;
  line-height: 1.42;
  padding: 1.2rem .9rem 1.2rem 1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  scrollbar-width: thin;
}
nav#sommaire h2 {
  font: 650 .85rem/1.2 var(--sans);
  letter-spacing: .01em;
  color: var(--muted);
  margin: 0 0 .8rem;
  padding: 0 .5rem;
}
nav#sommaire a {
  display: block;
  padding: .32rem .5rem;
  text-decoration: none;
  color: var(--muted);
  border-radius: 4px;
  border-left: 3px solid transparent;
  transition: color .15s, background .15s, border-color .15s;
}
nav#sommaire a:hover {
  color: var(--ink);
  background: var(--tint-2);
}
nav#sommaire a.active {
  color: var(--accent-dk);
  background: var(--tint);
  border-left-color: var(--accent);
  font-weight: 650;
}
/* Les 11 sections du parcours sont numérotées ; le cas initial et les références ne le sont pas */
nav#sommaire a:not([href="#depart"]):not([href="#objectifs-sources"]) { counter-increment: nav; }
nav#sommaire a:not([href="#depart"]):not([href="#objectifs-sources"])::before {
  content: counter(nav) ". ";
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--accent);
}

/* Bouton de bascule du sommaire mobile (injecté par JS) */
#nav-toggle {
  display: none;
  width: 100%;
  background: none;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .6rem 1rem;
  text-align: left;
  font-weight: 650;
  font-size: .88rem;
  cursor: pointer;
  margin-bottom: .5rem;
}
#nav-toggle:hover { background: var(--tint-2); }
#nav-toggle::after {
  content: ' ▾';
  float: right;
  font-weight: 400;
}
#nav-toggle[aria-expanded="true"]::after { content: ' ▴'; }

/* ── Contenu principal ─────────────────────────────────── */
main#contenu {
  min-width: 0;
  max-width: 940px;
}

/* ── Sections ──────────────────────────────────────────── */
.chapter {
  position: relative;
  background: var(--paper);
  padding: 3rem 3.5rem 2.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 2.25rem;
  scroll-margin-top: 5rem;
}
.chapter:not(#depart):not(#objectifs-sources) { counter-increment: chap; }

/* ── Typographie ───────────────────────────────────────── */
h1, h2 {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--ink);
}
h1 {
  font-size: clamp(2rem, 4.2vw, 2.8rem);
  line-height: 1.1;
  letter-spacing: -.025em;
  margin: .25rem 0 1.4rem;
}
h2 {
  position: relative;
  font-size: clamp(1.55rem, 2.9vw, 2rem);
  line-height: 1.22;
  letter-spacing: -.018em;
  margin: 0 0 1.4rem;
  max-width: 24em;
}
/* Repère de section dans la marge de gauche */
.chapter:not(#depart):not(#objectifs-sources) > h2::before {
  content: counter(chap);
  position: absolute;
  left: -2.6rem;
  top: .1rem;
  display: grid;
  place-items: center;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--tint);
  color: var(--accent-dk);
  font: 700 .88rem/1 var(--sans);
  letter-spacing: 0;
}
h3 {
  position: relative;
  font-size: 1.22rem;
  line-height: 1.38;
  letter-spacing: -.005em;
  margin: 2.75rem 0 .75rem;
  padding-top: .85rem;
  color: var(--ink);
}
h3::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 2.25rem;
  height: 3px;
  background: var(--accent);
  border-radius: 2px;
}
.case h2 + p, .case h3 { margin-top: .8rem; }
.case h3::before, .rappel h3::before, .retenir h3::before,
.question h3::before, .mini-rappel h3::before, .key-point h3::before { display: none; }
.question h3, .rappel h3, .retenir h3, .mini-rappel h3, .key-point h3 { margin-top: 0; padding-top: 0; }
h4 {
  font-size: 1.02rem;
  line-height: 1.45;
  margin: 1.75rem 0 .45rem;
  color: var(--muted);
  font-weight: 650;
}
p { margin: .7rem 0 1.05rem; }
strong { font-weight: 650; }
li { margin: .45rem 0; }
a { color: var(--accent); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }

/* Colonne de lecture : le texte reste contenu ; figures et tableaux occupent toute la largeur */
.chapter > p, .chapter > ul, .chapter > ol, .chapter > h3, .chapter > h4,
.chapter > blockquote, .chapter > .source { max-width: var(--measure); }
.chapter > .case, .chapter > .encadre, .chapter > .repere, .chapter > .rappel,
.chapter > .mini-rappel, .chapter > .retenir, .chapter > .key-point,
.chapter > .question, .chapter > details { max-width: calc(var(--measure) + 3rem); }
.chapter > .table-wrap { max-width: 100%; }

/* ── Classes spéciales ─────────────────────────────────── */
.eyebrow {
  margin: 0 0 .5rem;
  font-size: .86rem;
  color: var(--accent-dk);
  font-weight: 650;
  letter-spacing: .01em;
}
.lead {
  font-size: 1.32rem;
  line-height: 1.5;
  color: var(--muted);
  font-family: var(--serif);
}
.source, .figure-source, .source-figure {
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.55;
}
.figure-source, .source-figure {
  display: block;
  margin-top: .4rem;
}

blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.5rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
  font-style: italic;
}

/* ── Encadrés contextuels ──────────────────────────────── */
.case, .encadre, .repere, .rappel, .mini-rappel,
.retenir, .key-point, .question {
  padding: 1.2rem 1.5rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  margin: 1.9rem 0;
}
.case, .encadre {
  background: var(--tint);
  border-left-width: 5px;
}
.rappel, .mini-rappel {
  background: var(--tint-2);
  border-left-color: #5aa5ac;
}
.retenir, .key-point {
  background: var(--tint);
  border-left-color: var(--accent);
}
.repere {
  background: var(--tint-2);
  border-left-color: var(--accent-dk);
}
.question {
  background: #f6f4fb;
  border-left-color: #6a58b5;
}
.case h2, .encadre h2 { font-size: 1.35rem; margin-top: 0; }
.case > :last-child, .question > :last-child, .rappel > :last-child,
.repere > :last-child, .retenir > :last-child { margin-bottom: 0; }

/* À retenir : une idée centrale, nettement détachée du texte courant */
.takeaway {
  margin: 1.9rem 0;
  padding: 1rem 1.3rem 1rem 1.4rem;
  background: var(--tint);
  border: 1px solid #a9cdce;
  border-left: 5px solid var(--accent);
  border-radius: 0 6px 6px 0;
  font-weight: 560;
}

/* Visuels facultatifs, repliés par défaut */
details.visual-optional {
  background: transparent;
  border-style: dashed;
  border-color: #9bb4ba;
}
details.visual-optional > summary { color: var(--muted); font-weight: 600; }

ul.capacites { padding-left: 1.25rem; }
ul.bibliographie { font-size: .92rem; line-height: 1.6; padding-left: 1.25rem; }
ul.bibliographie li { margin: .55rem 0; }

/* ── Details / Summary ─────────────────────────────────── */
details {
  padding: .9rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 1rem 0;
  background: var(--paper);
}
summary {
  cursor: pointer;
  font-weight: 650;
  line-height: 1.45;
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: .55rem;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: '▸';
  color: var(--accent);
  font-size: .8em;
  flex-shrink: 0;
  transition: transform .2s ease;
  position: relative;
  top: -.05em;
}
details[open] > summary::before { transform: rotate(90deg); }
details[open] > summary { margin-bottom: .75rem; }

/* Corrections (fond chaud, fermées par défaut) */
details.correction {
  background: var(--corr-bg);
  border-color: #e2c97a;
}
details.correction > summary { color: var(--corr-bdr); }
details.correction > summary::before { color: var(--corr-bdr); }
details.correction > :last-child { margin-bottom: 0; }

/* ── Boutons ───────────────────────────────────────────── */
button {
  font: inherit;
  color: white;
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  padding: .6rem 1.2rem;
  cursor: pointer;
  font-size: .9rem;
}
button:hover { background: var(--accent-dk); }

#fermer-corrections {
  display: inline-block;
  margin: 1rem 0;
}

/* ── Tableaux ──────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  margin: 1.75rem 0;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--paper);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: .9rem;
  line-height: 1.5;
}
th, td {
  padding: .7rem 1rem;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.table-wrap th, .table-wrap td { border-top: 0; }
.table-wrap tr > :first-child { border-left: 0; }
.table-wrap tr > :last-child { border-right: 0; }
th {
  background: var(--tint);
  font-weight: 650;
}
tbody th { background: var(--tint-2); }
caption {
  text-align: left;
  font-weight: 650;
  padding: .75rem 1rem .6rem;
  font-size: .92rem;
  caption-side: top;
}

/* ── Figures ───────────────────────────────────────────── */
figure {
  margin: 2.5rem 0;
  padding: 0;
}
figure a.fig-link {
  display: block;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
}
figure img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 820px;
  object-fit: contain;
  background: white;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: zoom-in;
  transition: opacity .15s;
}
figure a.fig-link:hover img { opacity: .93; }

/* Pastille d'agrandissement */
figure a.fig-link::after {
  content: '⊕ agrandir';
  position: absolute;
  bottom: .6rem;
  right: .6rem;
  background: rgba(0,0,0,.58);
  color: white;
  font-size: .74rem;
  letter-spacing: .03em;
  padding: .24rem .6rem;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
figure a.fig-link:hover::after,
figure a.fig-link:focus-visible::after { opacity: 1; }

figcaption {
  font-size: .9rem;
  line-height: 1.65;
  margin-top: 1rem;
  padding-left: 1rem;
  border-left: 3px solid var(--line);
  color: var(--ink);
  max-width: calc(var(--measure) + 5rem);
}
figcaption strong {
  display: block;
  margin-bottom: .2rem;
  font-size: .93rem;
}

/* ── Boîte de zoom (lightbox) ──────────────────────────── */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10,16,22,.9);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem;
  overflow: hidden;
}
#lightbox[hidden] { display: none; }

#lightbox-toolbar {
  display: flex;
  gap: .6rem;
  margin-bottom: .75rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: center;
}
#lightbox-toolbar button {
  font-size: .82rem;
  padding: .45rem .95rem;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 5px;
  color: white;
}
#lightbox-toolbar button:hover {
  background: rgba(255,255,255,.28);
}

#lightbox-img-wrap {
  overflow: auto;
  max-width: 100%;
  max-height: calc(100dvh - 7rem);
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  border-radius: 3px;
  touch-action: manipulation;
  width: 100%;
}
#lightbox-img-wrap img {
  display: block;
  flex: 0 0 auto;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  border-radius: 2px;
  user-select: none;
}
#lightbox-img-wrap img.lb-real {
  max-width: none;
  width: auto;
}

#lightbox-caption {
  color: rgba(255,255,255,.65);
  font-size: .78rem;
  margin-top: .65rem;
  max-width: 680px;
  text-align: center;
  line-height: 1.5;
  flex-shrink: 0;
}

/* ── Focus visible ─────────────────────────────────────── */
:focus-visible {
  outline: 3px solid #a55a00;
  outline-offset: 3px;
}

/* ── Pied de page ──────────────────────────────────────── */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: .82rem;
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE ≤ 1100px : la marge de numérotation passe devant le titre
   ════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
  .chapter { padding: 2.5rem 2.25rem 2.25rem; }
  .chapter:not(#depart):not(#objectifs-sources) > h2::before {
    position: static;
    display: inline-grid;
    margin-right: .6rem;
    vertical-align: .12em;
    width: 1.7rem; height: 1.7rem;
    font-size: .8rem;
  }
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE ≤ 1000px
   ════════════════════════════════════════════════════════ */
@media (max-width: 1000px) {
  #topbar-section { display: none; }
  .layout {
    grid-template-columns: 1fr;
    max-width: 900px;
    padding: 1rem;
    gap: 1rem;
  }
  nav#sommaire {
    position: static;
    max-height: none;
    top: auto;
    padding: .9rem 1rem;
  }
  #nav-toggle { display: block; }
  /* Liens masqués par défaut, visibles avec classe .open */
  nav#sommaire.nav-enhanced a { display: none; }
  nav#sommaire.open a {
    display: block;
    padding: .4rem .55rem;
    border-left: none;
    background: none;
  }
  nav#sommaire.open a.active {
    border-left: none;
    background: var(--tint);
    font-weight: 650;
  }
}

/* ════════════════════════════════════════════════════════
   RESPONSIVE ≤ 500px
   ════════════════════════════════════════════════════════ */
@media (max-width: 500px) {
  body { font-size: 16.5px; }
  .layout { padding: .5rem; }
  .topbar { padding: .65rem 1rem; font-size: .84rem; }
  .chapter {
    padding: 1.35rem 1.1rem 1.25rem;
    border-radius: 6px;
    margin-bottom: 1.5rem;
  }
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.14rem; margin-top: 2.25rem; }
  figure { margin: 1.75rem -.1rem; }
  figure img { max-height: 480px; }
  figcaption { padding-left: .75rem; }
  th, td { padding: .55rem .65rem; }
  table { min-width: 460px; }
  .case, .encadre, .question, .repere,
  .rappel, .retenir, .mini-rappel, .key-point {
    padding: 1rem 1.1rem;
  }
  .lead { font-size: 1.15rem; }
}

/* ════════════════════════════════════════════════════════
   PRÉFÉRENCE MOUVEMENT RÉDUIT
   ════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  summary::before,
  figure img,
  figure a.fig-link::after,
  nav#sommaire a,
  #read-progress { transition: none; }
}

/* ════════════════════════════════════════════════════════
   IMPRESSION
   ════════════════════════════════════════════════════════ */
@media print {
  @page { size: A4; margin: 18mm; }

  body {
    font: 10.5pt/1.45 Georgia, "Times New Roman", serif;
    background: white;
    color: #000;
  }

  .topbar,
  nav#sommaire,
  .skip-link,
  button,
  footer,
  #read-progress,
  #lightbox,
  figure a.fig-link::after { display: none !important; }

  .layout { display: block; padding: 0; max-width: none; }
  main#contenu { max-width: none; }

  .chapter {
    border: none;
    padding: 0;
    margin: 0 0 1.5rem;
    border-radius: 0;
    background: white;
  }
  .chapter > p, .chapter > ul, .chapter > ol, .chapter > h3, .chapter > h4,
  .chapter > blockquote, .chapter > .source, .chapter > .case, .chapter > .encadre,
  .chapter > .repere, .chapter > .rappel, .chapter > .mini-rappel, .chapter > .retenir,
  .chapter > .key-point, .chapter > .question, .chapter > details, h2, figcaption { max-width: none; }
  .chapter:not(#depart):not(#objectifs-sources) > h2::before { display: none; }
  h1 { font-size: 24pt; break-after: avoid; }
  h2 { font-size: 18pt; break-after: avoid; }
  h3, h4 { break-after: avoid; }
  h3::before { display: none; }
  h3 { padding-top: 0; }
  h1, h2, h3, h4 { break-inside: avoid; }
  p { orphans: 3; widows: 3; }

  figure {
    break-inside: avoid;
    max-width: 100%;
    margin: 1rem 0;
  }
  figure img {
    max-height: 200mm;
    border: 1px solid #ccc;
    cursor: auto;
    opacity: 1 !important;
  }
  figcaption { font-size: 9pt; border-left-color: #999; }

  table { min-width: 0; font-size: 9pt; }
  tr { break-inside: avoid; }
  .table-wrap { overflow: visible; border: none; }

  details { break-inside: auto; border-color: #bbb; }
  details.correction { background: #fdf8ef; }

  .source, .figure-source, .source-figure { font-size: 8pt; }

  a { color: inherit; text-decoration: none; }

  .case, .encadre, .repere, .rappel, .mini-rappel,
  .retenir, .key-point, .question, .takeaway {
    background: #f3f3f3;
    border-left-color: #999;
    border-color: #bbb;
  }
  .lead { font-size: 13pt; }
}
