:root {
  color-scheme: light dark;

  --page-gap: 12px;

  /* valeurs mises à jour par JS */
  --sticky-header-h: 108px;
  --followbar-h: 0px;
  --sticky-offset-px: 120;

  /* offset réel pour scroll-margin-top (header + bandeau) */
  --sticky-offset: calc(var(--sticky-header-h) + var(--followbar-h));

  /* bandeau aligné sur le reading */
  --reading-left: 0px;
  --reading-width: 100%;

  /* tailles exactes du reading (injectées par JS) */
  --rf-h1-size: 2rem;
  --rf-h1-lh: 1.2;
  --rf-h1-fw: 800;

  --rf-h2-size: 1.5rem;
  --rf-h2-lh: 1.25;
  --rf-h2-fw: 700;

  --rf-h3-size: 1.25rem;
  --rf-h3-lh: 1.25;
  --rf-h3-fw: 650;

  /* ===== Polish (non destructif) ===== */
  --ease-out: cubic-bezier(.2,.9,.2,1);
  --ease-soft: cubic-bezier(.2,.8,.2,1);

  --focus-ring: 2px solid rgba(140,140,255,0.60);
  --focus-ring-offset: 2px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  line-height: 1.6;

  /* polish */
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Focus (accessibilité + feel premium) ===== */
:focus { outline: none; }
:focus-visible{
  outline: var(--focus-ring);
  outline-offset: var(--focus-ring-offset);
}

@media (prefers-reduced-motion: reduce){
  *{ transition: none !important; animation: none !important; }
}

/* Header sticky */
header{
  position: sticky;
  top: 0;
  z-index: 50;

  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  border-bottom: 1px solid rgba(127,127,127,0.35);
  padding: 12px 16px;
}
@media (prefers-color-scheme: dark){
  header{ background: rgba(0,0,0,.72); }
}

.site-nav { font-size: 14px; opacity: 0.9; }
main { padding: 0; }

.reading {
  max-width: 78ch;
  margin: 0 auto;

  /* polish */
  font-size: 16px;
  letter-spacing: 0.005em;
}

.reading h1 {
  line-height: 1.2;
  margin: 0 0 10px;

  /* polish */
  letter-spacing: -0.01em;
}

.reading p { margin: 0 0 12px; }

/* petits ajustements de respiration */
.reading h2 { margin-top: 18px; }
.reading h3 { margin-top: 14px; }

.edition-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(127,127,127,0.35);
  font-size: 14px;
}
/* Edition-bar: cacher des badges (non destructif) */
.edition-bar [data-badge="edition"],
.edition-bar [data-badge="status"],
.edition-bar [data-badge="version"]{
  display: none;
}

.badge {
  padding: 2px 8px;
  border: 1px solid rgba(127,127,127,0.45);
  border-radius: 999px;
}

.resume-btn{
  font-size: 15px;
  font-weight: 800;
  border: 1px solid rgba(127,127,127,0.55);
  border-radius: 999px;
  padding: 5px 12px;
  transition: transform 120ms var(--ease-out), background 120ms var(--ease-out);
}
.resume-btn:hover{
  background: rgba(127,127,127,0.10);
  transform: translateY(-1px);
}

/* Jump by paragraph id */
.jump-form{
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.jump-input{
  border: 1px solid rgba(127,127,127,0.55);
  background: transparent;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  width: 320px;
  transition: border-color 120ms var(--ease-out), box-shadow 120ms var(--ease-out);
}
.jump-input:focus-visible{
  border-color: rgba(140,140,255,0.65);
  box-shadow: 0 0 0 3px rgba(140,140,255,0.18);
}
.jump-input.is-error{
  outline: 2px solid rgba(127,127,127,0.55);
  outline-offset: 2px;
}
.jump-btn{
  border: 1px solid rgba(127,127,127,0.55);
  background: transparent;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: transform 120ms var(--ease-out), background 120ms var(--ease-out);
}
.jump-btn:hover{
  background: rgba(127,127,127,0.10);
  transform: translateY(-1px);
}

/* Toggle niveaux (legacy, non bloquant) */
.level-toggle { display: inline-flex; gap: 6px; }
.lvl-btn {
  border: 1px solid rgba(127,127,127,0.55);
  background: transparent;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  transition: transform 120ms var(--ease-out), background 120ms var(--ease-out), border-color 120ms var(--ease-out);
}
.lvl-btn:hover{
  background: rgba(127,127,127,0.10);
  transform: translateY(-1px);
}
.lvl-btn[aria-pressed="true"] {
  border-color: rgba(127,127,127,0.9);
  font-weight: 650;
}

/* Règles niveaux */
body[data-reading-level="1"] .level-2,
body[data-reading-level="1"] .level-3,
body[data-reading-level="1"] .level-4 { display: none; }

body[data-reading-level="2"] .level-3,
body[data-reading-level="2"] .level-4 { display: none; }

body[data-reading-level="3"] .level-2,
body[data-reading-level="3"] .level-4 { display: none; }

body[data-reading-level="4"] .level-2,
body[data-reading-level="4"] .level-3 { display: none; }

/* ==========================
   Scroll offset (anchors / headings / paras)
   ========================== */

.reading p[id]{
  position: relative;
  padding-right: 14rem;
  scroll-margin-top: var(--sticky-offset);
}

/* Anchres + titres */
.para-alias,
.details-anchor{
  display: block;
  height: 0;
  scroll-margin-top: var(--sticky-offset);
}

.reading h1,
.reading h2[id],
.reading h3[id]{
  scroll-margin-top: var(--sticky-offset);
}

.para-tools{
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  opacity: 0;
  transition: opacity 120ms ease-in-out;
}

.para-tools-row{
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.reading p[id]:hover .para-tools,
.reading p[id]:focus-within .para-tools { opacity: 1; }

.para-anchor,
.para-propose,
.para-cite{
  font-size: 12px;
  border: 1px solid rgba(127,127,127,0.45);
  border-radius: 999px;
  padding: 2px 8px;
  background: transparent;
  transition: transform 120ms var(--ease-out), background 120ms var(--ease-out);
}
.para-anchor:hover,
.para-propose:hover,
.para-cite:hover{
  background: rgba(127,127,127,0.10);
  transform: translateY(-1px);
}
.para-cite{ cursor: pointer; }

.para-bookmark{
  font-size: 13px;
  border: 1px solid rgba(127,127,127,0.65);
  border-radius: 999px;
  padding: 4px 12px;
  background: transparent;
  cursor: pointer;
  transition: transform 120ms var(--ease-out), background 120ms var(--ease-out);
}
.para-bookmark:hover{
  background: rgba(127,127,127,0.10);
  transform: translateY(-1px);
  text-decoration: underline;
}

/* Highlight (jump / resume / arrivée hash) */
.para-highlight{
  background: rgba(127,127,127,0.10);
  border-radius: 10px;
  box-shadow: 0 0 0 2px rgba(127,127,127,0.35);
  transition: box-shadow 160ms ease;
}

.build-stamp {
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid rgba(127,127,127,0.25);
  opacity: 0.85;
}

/* Accordéon */
.details-section {
  border: 1px solid rgba(127,127,127,.25);
  border-radius: 16px;
  padding: 10px 12px;
  margin: 14px 0;
  position: relative;
}

/* ✅ Handle minimal pour sections fermées : pas de titre visible, mais ouvrable */
.details-summary{
  list-style: none;
  cursor: pointer;
  user-select: none;

  border: 1px dashed rgba(127,127,127,.25);
  border-radius: 999px;
  padding: 6px 10px;
  margin: 10px 0;

  background: rgba(127,127,127,0.06);
  position: relative;

  /* cache le texte réel (souvent le titre), sans casser l’accessibilité */
  color: transparent;
}
.details-summary::-webkit-details-marker { display: none; }

.details-summary::before{
  content: "▸ Ouvrir la section";
  color: rgba(127,127,127,0.85);
  font-size: 12px;
  font-weight: 850;
}
@media (prefers-color-scheme: dark){
  .details-summary::before{ color: rgba(220,220,220,0.82); }
}

details[open] > .details-summary{
  /* une fois ouvert, on le rend “SR-only” pour éviter le doublon visuel */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.details-body { margin-top: 10px; }

/* Smooth scroll */
html{ scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce){
  html{ scroll-behavior: auto; }
}

/* ==========================
   Reading-follow (H1/H2/H3 only)
   ========================== */

.reading-follow{
  position: fixed;

  left: var(--reading-left);
  width: var(--reading-width);
  right: auto;

  top: var(--sticky-header-h);

  z-index: 60;
  pointer-events: none;

  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.reading-follow.is-on{
  opacity: 1;
  transform: translateY(0);
}

.reading-follow__inner{
  pointer-events: auto;

  width: 100%;
  box-sizing: border-box;

  padding: 8px 12px;
  padding-right: 84px;

  border: 1px solid rgba(127,127,127,.20);
  border-top: 0;
  border-radius: 0 0 14px 14px;

  background: rgba(255,255,255,.86);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  box-shadow: 0 10px 22px rgba(0,0,0,.06);

  position: relative;
}

@media (prefers-color-scheme: dark){
  .reading-follow__inner{
    background: rgba(0,0,0,.58);
    box-shadow: 0 10px 22px rgba(0,0,0,.18);
  }
}

.rf-line{
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  margin: 0;
}
.rf-line[hidden]{ display: none !important; }

.rf-h1{
  font-size: var(--rf-h1-size);
  line-height: var(--rf-h1-lh);
  font-weight: var(--rf-h1-fw);
}
.rf-h2{
  font-size: var(--rf-h2-size);
  line-height: var(--rf-h2-lh);
  font-weight: var(--rf-h2-fw);
  opacity: .96;
}
.rf-h3{
  font-size: calc(var(--rf-h2-size, 1.5rem) * 0.72);
  line-height: calc(var(--rf-h2-lh, 1.25) * 0.9);
  font-weight: var(--rf-h3-fw, 650);
  opacity: .86;
}
.rf-line:hover{ text-decoration: underline; }

/* Actions */
.rf-actions{
  position: absolute;
  right: 10px;
  bottom: 8px;
  display: inline-flex;
  gap: 6px;
}

.rf-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid rgba(127,127,127,0.35);
  background: rgba(127,127,127,0.10);
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
}

.rf-btn:hover{
  background: rgba(127,127,127,0.16);
  transform: translateY(-1px);
}

/* ==========================
   PATCH CRUCIAL : éviter les “rectangles vides”
   (details fermés + summary handle minimal)
   ========================== */

.reading details.details-section:not([open]){
  border: 0;
  padding: 0;
  background: transparent;
}

/* ==========================
   Landscape boost (mobile/tablet)
   CSS-only, non destructif
   - iOS + Android
   - élargit la lecture en paysage sur petits écrans
   - ne touche pas au desktop
   ========================== */

/* 1) Quand on est en paysage sur “petits” devices,
      on évite une colonne unique trop “étroite” et on retire le max-width 78ch. */
      @media (orientation: landscape) and (max-width: 1024px){
        /* La grille (EditionLayout) utilise .page-shell ; on la rend plus “fluide” */
        .page-shell{
          max-width: calc(100vw - 16px) !important; /* respire mais exploite la largeur */
        }
      
        /* La lecture ne doit pas rester “bridée” à 78ch en paysage */
        .reading{
          max-width: none !important;
          width: 100% !important;
        }
      }
      
      /* 2) Cas extrême : petits téléphones en paysage (hauteur faible).
            On réduit légèrement les paddings pour gagner de la place utile. */
      @media (orientation: landscape) and (max-width: 820px) and (max-height: 520px){
        header{
          padding-top: 10px;
          padding-bottom: 10px;
        }
      
        /* allège un peu la barre d’édition (sans la casser) */
        .edition-bar{
          margin-top: 8px;
          padding-top: 8px;
          gap: 8px 12px;
        }
      
        /* champ jump un peu moins large, pour éviter de “manger” la nav */
        .jump-input{
          width: min(260px, 48vw);
        }
      }
      
      /* 3) iOS Safari : le viewport peut être “bizarre” en paysage (barres).
            Cette règle aide à éviter des layouts coincés quand l’UI Safari bouge. */
      @supports (height: 100dvh){
        @media (orientation: landscape) and (max-width: 1024px){
          .page-shell{
            min-height: 100dvh;
          }
        }
      }

/* ==========================
   Glossaire
   ========================== */

   .glossary-intro{
    margin-bottom: 14px;
  }
  
  .glossary-section{
    margin: 24px 0;
  }
  
  .glossary-section-nav{
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 18px 0 12px;
  }
  
  .glossary-section-nav a,
  .glossary-alpha-nav a{
    border: 1px solid rgba(127,127,127,0.35);
    border-radius: 999px;
    padding: 4px 10px;
    transition: background 120ms ease, transform 120ms ease;
  }
  
  .glossary-section-nav a:hover,
  .glossary-alpha-nav a:hover{
    background: rgba(127,127,127,0.10);
    transform: translateY(-1px);
    text-decoration: none;
  }
  
  .glossary-grid{
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    margin-top: 14px;
  }
  
  .glossary-card{
    border: 1px solid rgba(127,127,127,0.22);
    border-radius: 16px;
    padding: 14px;
    background: rgba(127,127,127,0.05);
  }
  
  .glossary-card h3{
    margin-top: 0;
    margin-bottom: 8px;
    line-height: 1.25;
  }
  
  .glossary-card__def{
    margin-bottom: 10px;
  }
  
  .glossary-meta{
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    opacity: .85;
  }
  
  .glossary-meta span{
    border: 1px solid rgba(127,127,127,0.28);
    border-radius: 999px;
    padding: 2px 8px;
  }
  
  .glossary-alpha-nav{
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 18px;
  }
  
  .glossary-alpha-group{
    margin: 20px 0;
  }
  
  .glossary-alpha-group h3{
    margin-bottom: 8px;
  }