:root {
  --fond: #f2efe9;
  --carte: #ffffff;
  --encre: #17171a;
  --encre-douce: #6b6862;
  --trait: #e4e0d8;
  --action: #17171a;
  --terme: #b7273b;          /* le rouge du site d'origine */
  --terme-actif: #e08300;    /* l'orange du survol */
  --rayon: 22px;
  --barre-h: 60px;
  --pied-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  /* pas de 100vh : la barre d adresse des navigateurs mobiles change la
     hauteur visible en plein geste et fait sauter la mise en page */
  height: 100dvh;
  margin: 0;
}

body {
  background: var(--fond);
  color: var(--encre);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.i {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex: none;
}

/* ——— barre du haut ——————————————————————————————————— */

.barre {
  height: var(--barre-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--fond);
  border-bottom: 1px solid var(--trait);
}

.titre-barre {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.chapitre {
  font-weight: 650;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ecran {
  font-size: 12.5px;
  color: var(--encre-douce);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recherche {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--carte);
  border: 1px solid var(--trait);
  border-radius: 999px;
  padding: 0 14px;
  height: 38px;
  color: var(--encre-douce);
  flex: none;
  width: 260px;
}

.recherche input {
  border: 0;
  outline: 0;
  background: none;
  font: inherit;
  color: var(--encre);
  width: 100%;
  min-width: 0;
}

.bouton-icone {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  border: 1px solid var(--trait);
  border-radius: 12px;
  background: var(--carte);
  color: var(--encre);
  cursor: pointer;
  flex: none;
}

.bouton-icone:hover { background: #fbfaf8; }

/* ——— corps ————————————————————————————————————————— */

.corps {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 14px;
  padding: 14px;
}

.plan {
  width: 250px;
  flex: none;
  overflow-y: auto;
  background: var(--carte);
  border-radius: var(--rayon);
  padding: 16px 8px 16px 16px;
}

.plan a {
  display: block;
  padding: 6px 10px;
  border-radius: 10px;
  color: var(--encre);
  text-decoration: none;
  font-size: 13.5px;
  line-height: 1.35;
}

.plan a:hover { background: #f4f2ee; }

.plan a.actif {
  background: var(--action);
  color: #fff;
}

.plan .niveau-1 { font-weight: 650; margin-top: 10px; }
.plan .niveau-2 { padding-left: 20px; }
.plan .niveau-3 { padding-left: 32px; font-size: 13px; color: var(--encre-douce); }
.plan a.actif.niveau-3 { color: #fff; }

.scene {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 14px;
}

.carte {
  background: var(--carte);
  border-radius: var(--rayon);
  overflow: hidden;
}

.schema {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 18px;
  position: relative;
}

.schema img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  /* le remplacement d'image est instantané dans l'original : on garde ce
     franc-parler, juste adouci pour ne pas clignoter */
  transition: opacity .12s ease;
}

.legende {
  position: absolute;
  left: 18px; bottom: 14px; right: 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--terme-actif);
  text-align: center;
  pointer-events: none;
}

.texte {
  overflow-y: auto;
  padding: 26px 30px 32px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.62;
  text-align: justify;
  hyphens: auto;
}

.texte h2 {
  font-size: 17px;
  margin: 0 0 14px;
  letter-spacing: .01em;
}

.texte h3 {
  font-size: 15.5px;
  margin: 22px 0 8px;
  color: var(--encre-douce);
}

.texte p { margin: 0 0 14px; }
.texte ul { margin: 0 0 14px; padding-left: 20px; }
.texte li { margin-bottom: 4px; }
.texte strong { color: var(--terme); font-weight: 700; }

/* le cœur de l'affaire : le terme qui change le schéma */
.terme {
  color: var(--terme);
  font-weight: 700;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(183, 39, 59, .28);
  text-underline-offset: 3px;
  transition: color .12s ease;
}

.terme:hover,
.terme:focus-visible,
.terme.actif {
  color: var(--terme-actif);
  text-decoration-color: currentColor;
  outline: none;
}

/* ——— pied ————————————————————————————————————————— */

.pied {
  height: var(--pied-h);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px;
  border-top: 1px solid var(--trait);
}

.bouton {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--action);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  flex: none;
}

.bouton:disabled {
  background: #ded9d0;
  color: #9a958c;
  cursor: default;
}

.avancee {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
}

.pas {
  width: 100%;
  max-width: 13px;
  height: 7px;
  border-radius: 999px;
  border: 0;
  padding: 0;
  background: #ddd8cf;
  cursor: pointer;
  flex: 1 1 5px;
}

.pas.vu { background: #b3aca0; }
.pas.actif { background: var(--action); }

/* ——— recherche ————————————————————————————————————— */

.resultats {
  position: fixed;
  top: calc(var(--barre-h) + 6px);
  right: 14px;
  width: 380px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--carte);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .16);
  padding: 8px;
  z-index: 30;
}

.resultat {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  font: inherit;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}

.resultat:hover { background: #f4f2ee; }
.resultat b { display: block; font-size: 13px; margin-bottom: 2px; }
.resultat span { font-size: 13px; color: var(--encre-douce); }
.resultat mark { background: #ffe8b0; color: inherit; border-radius: 3px; }
.rien { padding: 14px; color: var(--encre-douce); font-size: 13.5px; }

.voile { display: none; }

/* ——— petit écran ——————————————————————————————————— */

@media (max-width: 900px) {
  .recherche { width: 44px; padding: 0 11px; }
  .recherche input { display: none; }
  .recherche.ouverte {
    position: absolute;
    left: 14px; right: 14px;
    width: auto;
    z-index: 40;
  }
  .recherche.ouverte input { display: block; }

  .corps { padding: 10px; gap: 10px; }

  .plan {
    position: fixed;
    top: var(--barre-h); bottom: 0; left: 0;
    width: 280px;
    z-index: 50;
    border-radius: 0 var(--rayon) var(--rayon) 0;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .plan.ouvert { transform: none; }

  .voile {
    display: block;
    position: fixed;
    inset: var(--barre-h) 0 0 0;
    background: rgba(0, 0, 0, .3);
    z-index: 45;
  }
  .voile[hidden] { display: none; }

  .scene {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 38%) 1fr;
  }

  .texte { padding: 20px 20px 26px; font-size: 16.5px; }

  .resultats { left: 10px; right: 10px; width: auto; }

  .bouton span { display: none; }
  .bouton { padding: 0 14px; }
}

@media (max-width: 520px) {
  .chapitre { font-size: 13px; }
}

/* groupes du plan : un intitulé, puis une pastille par écran */
.plan a.section {
  background: #f0ede7;
  font-weight: 650;
}

.pages {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 2px 0 6px 10px;
}

.plan .pages a {
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  padding: 0;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--encre-douce);
  background: #f4f2ee;
}

.plan .pages a:hover { background: #e8e4dc; color: var(--encre); }
.plan .pages a.actif { background: var(--action); color: #fff; }

/* ——— digicode ————————————————————————————————————————— */

#application {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#application[hidden] { display: none; }

.connexion {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

.connexion[hidden] { display: none; }

.carte-connexion {
  background: var(--carte);
  border-radius: var(--rayon);
  padding: 34px 30px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  position: relative;
}

.carte-connexion h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 650;
}

.doux {
  color: var(--encre-douce);
  font-size: 14px;
  margin: 0 0 18px;
}

.points-code {
  display: flex;
  gap: 14px;
  margin-bottom: 8px;
}

.points-code span {
  width: 13px; height: 13px;
  border-radius: 50%;
  background: #e2ded6;
  transition: background .15s, transform .15s;
}

.points-code span.plein {
  background: var(--action);
  transform: scale(1.12);
}

.points-code.refuse { animation: secousse .4s; }

@keyframes secousse {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.erreur {
  color: var(--terme);
  font-size: 13px;
  margin: 0 0 4px;
  min-height: 18px;
}

.erreur[hidden] { display: none; }

.pave-numerique {
  display: grid;
  grid-template-columns: repeat(3, 74px);
  gap: 11px;
  margin-top: 10px;
}

.pave-numerique button {
  height: 74px;
  border-radius: 50%;
  border: 0;
  font: inherit;
  font-size: 21px;
  font-weight: 500;
  background: #f4f2ee;
  color: var(--encre);
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
}

.pave-numerique button:hover { background: #ebe7df; }
.pave-numerique button:active { background: #e0dbd1; }
.pave-numerique button.vide { visibility: hidden; }

/* Invisible mais présent : display:none priverait les gestionnaires de mots
   de passe du champ. */
.carte-connexion #code {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  border: 0;
}

@media (max-width: 900px) {
  /* Sur petit écran l'image occupe toute la carte : la légende posée par
     dessus retombe dans le dessin. On la remet dans le flux. */
  .schema { padding: 12px; }
  .legende {
    position: static;
    margin-top: 8px;
    order: 2;
  }
  .schema img { min-height: 0; }
}

/* ═══ Téléphone : deux volets qui glissent ═══════════════════════
   Le côte à côte ne tient pas sous 900 px — la planche y devient
   illisible. On la met en plein cadre, à côté du texte, et on passe de
   l'un à l'autre par un glissement horizontal.
   Conséquence à ne pas oublier : le glissement horizontal sert donc à
   changer de volet, jamais à tourner la page. Celle-ci se tourne par les
   boutons du pied. */

.retour { display: none; }

@media (max-width: 900px) {
  .scene {
    display: flex;
    grid-template-columns: none;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    scrollbar-width: none;
    overscroll-behavior-x: contain;
  }

  .scene::-webkit-scrollbar { display: none; }

  .scene > * {
    flex: 0 0 100%;
    scroll-snap-align: start;
    min-width: 0;
  }

  /* Le texte est le volet d'accueil ; la planche vient à sa droite. */
  .texte { order: 1; overflow-y: auto; }
  .schema { order: 2; justify-content: flex-start; padding: 0 0 14px; }

  .schema img {
    flex: 1;
    min-height: 0;
    padding: 0 14px;
  }

  .retour {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    align-self: flex-start;
    margin: 0;
    padding: 12px 14px 10px;
    border: 0;
    background: none;
    font: inherit;
    font-size: 13px;
    color: var(--encre-douce);
    cursor: pointer;
  }

  .retour:hover, .retour:focus-visible { color: var(--encre); outline: none; }
  .retour .i { width: 16px; height: 16px; }

  .legende { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .scene { scroll-behavior: auto; }
}

/* ——— liste des chapitres ——————————————————————————————— */

.colonne-gauche {
  width: 250px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.colonne-gauche .plan { width: auto; flex: 1; min-height: 0; }

.liste-chapitres {
  background: var(--carte);
  border-radius: var(--rayon);
  flex: none;
  max-height: 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.liste-chapitres summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 16px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  list-style: none;
  flex: none;
}

.liste-chapitres summary::-webkit-details-marker { display: none; }
.liste-chapitres summary span { flex: 1; }
.liste-chapitres .chevron { transition: transform .18s ease; width: 16px; height: 16px; color: var(--encre-douce); }
.liste-chapitres[open] .chevron { transform: rotate(180deg); }
.liste-chapitres[open] summary { border-bottom: 1px solid var(--trait); }

#chapitres { overflow-y: auto; padding: 8px; }

.section-titre {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--encre-douce);
  padding: 10px 8px 5px;
}

.chap {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 10px;
  color: var(--encre);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.3;
}

.chap:hover { background: #f4f2ee; }
.chap.actif { background: var(--action); color: #fff; }

.chap .num {
  flex: none;
  width: 20px;
  text-align: right;
  color: var(--encre-douce);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.chap.actif .num, .chap.actif .compte { color: rgba(255, 255, 255, .7); }
.chap .nom { flex: 1; }

.chap .compte {
  flex: none;
  color: var(--encre-douce);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 900px) {
  .colonne-gauche {
    position: fixed;
    top: var(--barre-h); bottom: 0; left: 0;
    width: 290px;
    z-index: 50;
    padding: 10px;
    background: var(--fond);
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .colonne-gauche.ouvert { transform: none; }
  .colonne-gauche .plan { position: static; transform: none; width: auto; border-radius: var(--rayon); }
}
