/* Pages « Comprendre l'implexe » et « Sources et méthode » : texte long, démonstration interactive,
   schéma des quatre nombres, tableau des populations, références. S'ajoute à base.css et site.css. */

.doc-reading { max-width: 64rem; }
.doc-reading p, .doc-reading dd, .doc-reading li { max-width: 68ch; }
.reading-head { max-width: 44rem; }
.lede { margin-top: .9rem; font-size: 1.1875rem; line-height: 1.55; color: var(--ink-soft); }
.note { font-size: .875rem; color: var(--ink-soft); margin-top: .75rem; }
.doc-reading code { background: var(--sheet); padding: 0 .25em; border-radius: 3px; }
.doc-back {
  display: inline-flex; align-items: center; min-height: 44px; margin-top: .5rem; padding: 0 1.1rem;
  border: 1px solid var(--rule-strong); border-radius: var(--radius); background: var(--sheet);
  color: var(--ink) !important; text-decoration: none; font-weight: 600;
}
.doc-back:hover { border-color: var(--ink-soft); background: #fff; }

.segmented { display: flex; flex-wrap: wrap; gap: .4rem; border: 0; padding: 0; margin: 1rem 0 1.25rem; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span {
  display: inline-flex; align-items: center; min-height: 40px; padding: .4rem .9rem;
  border: 1px solid var(--rule-strong); border-radius: 999px; background: var(--sheet); cursor: pointer;
}
.segmented input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.segmented input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }

.demo-body { display: grid; grid-template-columns: minmax(0, 1fr) 16rem; gap: 1.5rem; align-items: start; }
.demo-svg { width: 100%; height: auto; display: block; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); }
.demo-edge { fill: none; stroke-width: 1.6; }
.demo-node circle { stroke: #fff; stroke-width: 1.5; }
.demo-node.is-shared circle { stroke: var(--gold); stroke-width: 3; }
.demo-badge { font-family: var(--font-ui); font-size: 11px; font-weight: 700; fill: var(--gold-ink); text-anchor: middle; }
.demo-label { font-family: var(--font-ui); font-size: 12px; fill: var(--ink-soft); text-anchor: middle; }
.demo-sibling path { fill: none; stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 4 3; }
.demo-sibling text { font-family: var(--font-ui); font-size: 11px; fill: var(--gold-ink); text-anchor: middle; }
.demo-table { width: 100%; border-collapse: collapse; font-size: .9375rem; font-variant-numeric: tabular-nums; }
.demo-table th, .demo-table td { padding: .4rem .5rem; text-align: right; border-bottom: 1px solid var(--rule); }
.demo-table th:first-child { text-align: left; }
.demo-table thead th { font-size: .8125rem; color: var(--ink-soft); font-weight: 700; }
.demo-table tfoot th, .demo-table tfoot td { font-weight: 700; border-bottom: 0; }
.demo-table .is-collapsed td:last-child { color: var(--gold-ink); font-weight: 700; }
.demo-caption { margin-top: 1rem; font-size: .9375rem; line-height: 1.55; }

/* Des lignées qui se croisent */
.meet-zone { fill: var(--paper); stroke: var(--rule-strong); }
.meet-zone.is-b { fill: var(--accent-wash); stroke: var(--accent); stroke-opacity: .4; }
.meet-zone-label { font-family: var(--font-display); font-size: 15px; fill: var(--ink-soft); text-anchor: middle; }
.meet-gen { font-family: var(--font-ui); font-size: 10px; font-weight: 700; fill: var(--ink-faint); text-anchor: middle; }
.meet-edge { fill: none; stroke-width: 1.3; }
.meet-node circle { stroke: #fff; stroke-width: 1.2; }
.meet-node.is-shared circle { stroke: var(--gold); stroke-width: 3; }
.meet-arrow { fill: none; stroke: var(--gold-ink); stroke-width: 2; stroke-dasharray: 5 3; marker-end: url(#meet-head); }
.meet-arrow-label { font-family: var(--font-ui); font-size: 11px; font-weight: 700; fill: var(--gold-ink); text-anchor: middle; }
.meet-step-title { margin: 0; font-family: var(--font-display); font-weight: 500; font-size: 1.125rem; }
.meet-step-title + .demo-caption { margin-top: .4rem; }
.meet-scale { margin-top: .9rem; font-size: .875rem; line-height: 1.5; color: var(--ink-soft); }
.meet-note { margin-top: .6rem; font-size: .8125rem; line-height: 1.5; color: var(--ink-soft); font-style: italic; }

.four { display: grid; grid-template-columns: minmax(0, 26rem) minmax(0, 1fr); gap: 1.75rem; align-items: center; margin-top: 1rem; }
.four-fig { margin: 0; display: grid; gap: .6rem; }
.four-svg { width: 100%; height: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.four-svg text { font-family: var(--font-ui); }
.four-fig figcaption { font-weight: 600; }
.four-list > div { padding-left: .8rem; border-left: 3px solid transparent; }
.four-list > div.is-active { border-left-color: var(--accent); }
.four-num {
  display: inline-grid; place-items: center; width: 1.25rem; height: 1.25rem; margin-right: .45rem;
  border-radius: 50%; background: var(--ink-soft); color: #fff; font-size: .75rem; font-weight: 700; vertical-align: .1em;
}
.four-list div:nth-child(1) .four-num { background: var(--accent); }
.four-list div:nth-child(2) .four-num { background: var(--gold-ink); }
.four-list, .three, .keys { margin: 0; display: grid; gap: .9rem; }
.four-list dt, .three dt { font-weight: 700; }
.four-list dd, .three dd { margin: .15rem 0 0; color: var(--ink-soft); }
.four-list strong { color: var(--ink); font-family: var(--font-display); font-size: 1.125rem; font-weight: 600; }
.three { margin: 1rem 0; }

.table-wrap { overflow-x: auto; margin-top: 1rem; }
.doc .pop-table { border-collapse: collapse; font-size: .875rem; font-variant-numeric: tabular-nums; min-width: 22rem; }
.doc .pop-table th, .doc .pop-table td { padding: .3rem .8rem; text-align: right; border-bottom: 1px solid var(--rule); }
.doc .pop-table th:first-child { text-align: left; }
.refs { padding-left: 1.25rem; display: grid; gap: .6rem; }
.refs li { font-size: .9375rem; }
.refs small { display: block; color: var(--ink-soft); }
.refs a { overflow-wrap: anywhere; }
.keys div { display: grid; grid-template-columns: 10rem 1fr; gap: 1rem; }
.keys dd { margin: 0; }
kbd {
  display: inline-block; min-width: 1.6em; padding: .05rem .4rem; text-align: center;
  border: 1px solid var(--rule-strong); border-bottom-width: 2px; border-radius: 4px;
  background: var(--sheet); font-family: var(--font-ui); font-size: .8125rem;
}

/* Les tableaux génériques de .doc (site.css) prennent toute la largeur : pas ceux-ci. */
.doc .demo-table, .doc .pop-table { width: auto; margin-top: 0; }
.doc .demo-table { width: 100%; }
.doc .pop-table th { color: inherit; font-weight: 700; }

@media (max-width: 759px) {
  .demo-body, .four { grid-template-columns: 1fr; }
  .keys div { grid-template-columns: 1fr; gap: .2rem; }
}

/* ---------- Circuit : d'où l'on vient, où aller ensuite ---------- */

.journey { padding: 1.1rem 1.3rem; border: 2px solid var(--accent); border-radius: 8px; background: var(--accent-wash); }
.journey h2 { margin: 0 0 .5rem; }
.journey .journey-link, .site .journey .journey-link:hover {
  display: inline-flex; align-items: center; min-height: 44px; margin-top: .9rem; padding: .4rem 1.1rem;
  border-radius: 999px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none;
}
.journey-from { margin-top: 1rem; padding: .8rem 1rem; border: 2px solid var(--gold); border-radius: 8px; background: var(--gold-wash); }

/* ---------- Et Charlemagne ? ---------- */

.trip { display: grid; grid-template-columns: 96px minmax(0, 1.5fr) minmax(0, 1fr); gap: 1.1rem; align-items: start; margin: 1rem 0 1.5rem; scroll-margin: 5rem 0; }
.trip svg { display: block; width: 100%; height: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.trip svg text { font-family: var(--font-ui); fill: var(--ink); }
.trip-view { touch-action: none; cursor: ns-resize; user-select: none; }
.trip-map { cursor: pointer; }
.trip-card, .trip-who { display: grid; gap: .7rem; align-content: start; }
.doc .trip-card h3 { margin: 0; }
.trip-title { font-variant-numeric: tabular-nums; }
.trip-stats { display: grid; gap: .3rem; margin: 0; font-size: .9375rem; }
.trip-stats div { display: flex; justify-content: space-between; gap: 1rem; padding-top: .3rem; border-top: 1px solid var(--rule); }
.trip-stats dd { margin: 0; font-weight: 700; text-align: right; }
@media (max-width: 820px) {
  .trip { grid-template-columns: 56px minmax(0, 1fr); gap: .6rem; }
  .trip-card { grid-column: 1 / -1; }
}
.figtree-legend { list-style: none; display: grid; gap: .9rem; margin: 0; padding: 0; }
.figtree-legend li { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: .75rem; align-items: start; }
.ft-key { display: block; width: 2rem; height: 1.2rem; margin-top: .2rem; }
.ft-theory { background: repeating-linear-gradient(-45deg, var(--gold) 0 3px, var(--gold-wash) 3px 8px); }
.ft-real { background: var(--accent); }
.ft-dash { height: 0; margin-top: .8rem; border-top: 3px dashed var(--ink); }
.figcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); gap: 1.5rem 2rem; margin: 1rem 0 2rem; }
.figcard { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: .5rem 1.25rem; align-content: start; padding-top: 1.25rem; border-top: 1px solid var(--rule); scroll-margin-top: 6rem; }
.figcard figure { margin: 0; }
.figcard img { display: block; width: 100%; height: auto; border-radius: 8px; }
.figcard figcaption { margin-top: .4rem; font-size: .75rem; line-height: 1.35; color: var(--ink-soft); }
.figcard h3 { margin: 0; }
.fig-verdict { font-size: 1.2rem; font-weight: 700; line-height: 1.25; text-wrap: balance; }
.fig-verdict[data-level="tres-probable"] { color: var(--distinct); }
.fig-verdict[data-level="vraisemblable"] { color: var(--accent-strong); }
.fig-verdict[data-level="conditionnel"], .fig-verdict[data-level="peu-vraisemblable"] { color: var(--gold-ink); }
.figcard dl { display: grid; gap: .3rem; margin: .7rem 0; font-size: .9375rem; }
.figcard dl div { display: flex; justify-content: space-between; gap: 1rem; }
.figcard > div, .fig-sources { min-width: 0; overflow-wrap: anywhere; }
.figcard dd { margin: 0; font-weight: 700; text-align: right; }
.fig-sources { font-size: .8125rem; }
@media (max-width: 479px) { .figcard { grid-template-columns: minmax(0, 1fr); } .figcard figure { max-width: 9rem; } }
.site .trip-who p + p { margin-top: 0; }

/* Adam et Ève génétiques */
.lineages { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2rem; align-items: center; margin-top: 1rem; }
.lineages svg { width: 100%; height: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.lineages svg text { font-family: var(--font-ui); }
@media (max-width: 759px) { .lineages { grid-template-columns: minmax(0, 1fr); } }

/* Implexe, exemple réel */
.example-body { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.75rem; align-items: start; margin-top: 1rem; }
.example-body > svg { width: 100%; height: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.example-body svg text { font-family: var(--font-ui); }
.example-photo { display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: 1rem; align-items: center; margin: 1rem 0; }
.example-photo img { display: block; width: 100%; height: auto; border-radius: 8px; }
.example-photo figcaption { font-size: .75rem; line-height: 1.35; color: var(--ink-soft); }
@media (max-width: 759px) { .example-body { grid-template-columns: minmax(0, 1fr); } }

/* Arbre entier de Louis de Bourbon jusqu'à Louis XIV : défile en largeur sur petit écran plutôt que de devenir illisible. */
.example-full-scroll { overflow-x: auto; margin: 1rem 0; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.example-full-scroll svg { display: block; width: 100%; min-width: 640px; height: auto; }
.example-full-scroll svg text { font-family: var(--font-ui); }
.example-full-scroll svg a:hover rect, .example-full-scroll svg a:focus rect { stroke: var(--accent); stroke-width: 3; }
.sources-list { margin-top: 1rem; }
.sources-list summary { cursor: pointer; font-weight: 700; }
.sources-list > div, .sources-list table { display: block; overflow-x: auto; }
.doc .sources-list .data-table { border-collapse: collapse; font-size: .875rem; margin-top: .75rem; }
.doc .sources-list .data-table th, .doc .sources-list .data-table td { padding: .3rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--rule); }
.doc .sources-list .data-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-hint { display: none; font-size: .8125rem; color: var(--ink-soft); }
@media (max-width: 699px) { .scroll-hint { display: block; } }
.example-fig { margin: 0; min-width: 0; }
.example-fig > svg { display: block; width: 100%; height: auto; background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.example-fig svg text { font-family: var(--font-ui); }
.example-fig .example-steps { margin: .6rem 0 0; }

/* ---------- Pages longues : plan de lecture et pleine largeur (js/reading-nav.js) ---------- */

/* Trait de lecture sous l'en-tête. */
.reading-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; pointer-events: none; }
.reading-progress span { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; }

.doc-wide h2 { scroll-margin-top: calc(var(--header-h, 60px) + 4rem); }
.doc-wide { scroll-margin-top: var(--header-h, 60px); }
@media (prefers-reduced-motion: no-preference) { html:has(.reading-layout) { scroll-behavior: smooth; } }

.toc-box > summary { list-style: none; cursor: pointer; }
.toc-box > summary::-webkit-details-marker { display: none; }
.toc-trail { display: flex; align-items: baseline; gap: .4rem; min-width: 0; }
.toc-page { color: var(--ink-soft); white-space: nowrap; }
.toc-sep { color: var(--ink-faint); }
.toc-current { font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-title { margin: 0 0 .5rem; font-size: .75rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); }
/* Le fil : un trait à gauche, en couleur jusqu'à la section en cours. */
.toc-list { list-style: none; margin: 0; padding: 0; font-size: .9375rem; line-height: 1.35; }
.toc-list li + li { margin-top: 0; }
.toc-list a {
  display: block; padding: .45rem .5rem .45rem .9rem; border-left: 3px solid var(--rule);
  color: var(--ink-soft); text-decoration: none;
}
.toc-list a:hover { color: var(--ink); background: var(--sheet); }
.toc-list a.is-read { border-left-color: var(--accent); color: var(--ink-soft); }
.toc-list a[aria-current] { border-left-color: var(--accent); color: var(--accent-strong); font-weight: 700; background: var(--accent-wash); }

/* Petit et moyen écran : une barre collée sous l'en-tête, le plan se déroule par-dessus le texte. */
@media (max-width: 1099px) {
  .reading-toc { position: sticky; top: var(--header-h, 60px); z-index: 650; background: var(--paper); border-bottom: 1px solid var(--rule); }
  .toc-box > summary {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem; min-height: 44px;
    padding: .35rem max(20px, env(safe-area-inset-right)) .35rem max(20px, env(safe-area-inset-left)); font-size: .9375rem;
  }
  .toc-box > summary::after { content: ""; flex: none; width: .5rem; height: .5rem; margin: 0 .2rem .2rem 0; border: solid var(--ink-soft); border-width: 0 2px 2px 0; transform: rotate(45deg); }
  .toc-box[open] > summary::after { transform: rotate(-135deg); margin-bottom: -.2rem; }
  .toc-panel {
    position: absolute; top: 100%; left: 0; right: 0; padding: .75rem 20px 1rem;
    max-height: calc(100vh - var(--header-h, 60px) - 6rem); overflow-y: auto;
    background: var(--paper); border-bottom: 1px solid var(--rule); box-shadow: 0 12px 16px -12px rgb(0 0 0 / .25);
  }
}
@media (max-width: 559px) { .toc-page, .toc-sep { display: none; } }

/* Grand écran : le plan dans une colonne à gauche, le contenu prend le reste de la largeur. */
@media (min-width: 1100px) {
  .reading-layout {
    display: grid; grid-template-columns: 14rem minmax(0, 1fr); gap: 0 clamp(2rem, 3vw, 3.5rem);
    max-width: 96rem; margin: 0 auto; padding: 0 max(24px, env(safe-area-inset-right)) 0 max(24px, env(safe-area-inset-left));
  }
  .reading-layout > .doc-wide { max-width: none; margin: 0; padding-inline: 0; }
  .reading-toc {
    position: sticky; top: calc(var(--header-h, 60px) + 1.5rem); align-self: start;
    margin-top: 2.75rem; max-height: calc(100vh - var(--header-h, 60px) - 5rem); overflow-y: auto;
  }
  .toc-box > summary { display: none; }

  /* Le texte courant garde une longueur de ligne confortable ; les schémas et les cartes s'étalent. */
  .doc-wide p, .doc-wide dd, .doc-wide li { max-width: 72ch; }
  .doc-wide .demo-body { grid-template-columns: minmax(0, 1fr) 20rem; gap: 2.5rem; }
  .doc-wide .demo-svg { max-height: calc(100vh - var(--header-h, 60px) - 8rem); }
  .doc-wide .example-body { gap: 2.5rem; }
  .doc-wide .four { grid-template-columns: minmax(0, 30rem) minmax(0, 1fr); gap: 2.5rem; }
  .doc-wide .three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2rem; }
  .doc-wide .three > div { padding-top: .75rem; border-top: 3px solid var(--rule-strong); }
  .doc-wide .figtree-legend { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.5rem; }
  .doc-wide .figtree-legend li { max-width: none; }
  .doc-wide .trip { grid-template-columns: 96px minmax(0, 1.3fr) minmax(16rem, 1fr); gap: 1.5rem; }
  .doc-wide .lineages { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 3rem; }
  .doc-wide .figcards { gap: 2rem 3rem; }
  .doc-wide .example-full-scroll svg { max-width: 64rem; margin: 0 auto; }
  /* Notes sous l'arbre entier : côte à côte plutôt qu'une longue colonne étroite. */
  .doc-wide .example-full > .note { display: inline-block; vertical-align: top; width: calc(50% - 1.5rem); max-width: none; }
  .doc-wide .example-full > .note + .note { margin-left: 2.5rem; }
}
