/* Bible et commentaires : feuille de style unique.
   Parti pris : le texte est l'interface. Une colonne de lecture, des commandes discrètes, des thèmes contrastés. */

/* ---------- Jetons ---------- */
:root {
  --bg: #f6f6f3;
  --fg: #1b1a18;
  --muted: #5a5750;
  --rule: #d3d0c8;
  --rubric: #8a2222;
  --soft: #ebeae5;
  --hl: #f3e3b4;
  --focus: #1f4e9c;
  --serif: "Literata", "Georgia", "Times New Roman", serif;
  --sans: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  --font: var(--serif);
  --size: 18px;
  --lh: 1.55;
  --measure: calc(var(--size) * 34);
  --margin: 18rem;
  color-scheme: light;
}
html[data-theme="sepia"] { --bg: #f3ead8; --fg: #2d2418; --muted: #675742; --rule: #d9cbb0; --rubric: #7f2a1e; --soft: #eadfc8; --hl: #e9d49c; --focus: #1f4e9c; }
html[data-theme="sombre"], html[data-theme="auto"].dark { --bg: #17181b; --fg: #dcdad3; --muted: #a39f97; --rule: #363840; --rubric: #e08c7c; --soft: #22242a; --hl: #4a3e1c; --focus: #8ab4ff; color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] { --bg: #17181b; --fg: #dcdad3; --muted: #a39f97; --rule: #363840; --rubric: #e08c7c; --soft: #22242a; --hl: #4a3e1c; --focus: #8ab4ff; color-scheme: dark; }
}
html[data-theme="noir-sur-blanc"] { --bg: #ffffff; --fg: #000000; --muted: #2a2a2a; --rule: #7a7a7a; --rubric: #8a0000; --soft: #efefef; --hl: #fff2a8; --focus: #0000d0; }
html[data-theme="blanc-sur-noir"] { --bg: #000000; --fg: #ffffff; --muted: #d8d8d8; --rule: #8a8a8a; --rubric: #ffb0a0; --soft: #161616; --hl: #4d4200; --focus: #ffff00; color-scheme: dark; }

html[data-size="1"] { --size: 16px; } html[data-size="2"] { --size: 17px; } html[data-size="3"] { --size: 18px; } html[data-size="4"] { --size: 20px; }
html[data-size="5"] { --size: 22px; } html[data-size="6"] { --size: 24px; } html[data-size="7"] { --size: 27px; }
html[data-lh="1"] { --lh: 1.4; } html[data-lh="2"] { --lh: 1.55; } html[data-lh="3"] { --lh: 1.75; }
html[data-width="1"] { --measure: calc(var(--size) * 28); } html[data-width="2"] { --measure: calc(var(--size) * 34); } html[data-width="3"] { --measure: calc(var(--size) * 42); }
html[data-font="sans"] { --font: var(--sans); }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 1rem; line-height: 1.45;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--rubric); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font); font-weight: 500; line-height: 1.2; text-wrap: balance; margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -200vw; top: .5rem; background: var(--fg); color: var(--bg); padding: .4rem .8rem; z-index: 50; }
.skip:focus { left: 1rem; }
html:not(.js) .js-only { display: none !important; }
html.js .js-hide { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--rubric); margin: 0 0 .4rem; }
mark { background: var(--hl); color: inherit; padding: 0 .1em; }
code, kbd { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: .9em; background: var(--soft); padding: .05em .35em; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; gap: .35em; border: 1.5px solid var(--fg); background: transparent; color: var(--fg); padding: .4em .8em; border-radius: 3px; text-decoration: none; cursor: pointer; line-height: 1.2; min-height: 2.4rem; white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn-primary { background: var(--fg); color: var(--bg); }
.btn-primary:hover { background: var(--rubric); border-color: var(--rubric); color: #fff; }
.btn-quiet { border-color: var(--rule); }
.btn-danger { border-color: var(--rubric); color: var(--rubric); }
.link-btn { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; cursor: pointer; }
.link-btn:hover { text-decoration-color: var(--rubric); }
.seg { display: inline-flex; border: 1.5px solid var(--fg); border-radius: 3px; overflow: hidden; }
.seg-wrap { flex-wrap: wrap; }
.seg-btn { border: 0; background: transparent; padding: .4em .8em; min-height: 2.4rem; cursor: pointer; border-right: 1.5px solid var(--fg); }
.seg-btn:last-child { border-right: 0; }
.seg-btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.seg output { padding: .4em .6em; min-width: 4.5em; text-align: center; border-right: 1.5px solid var(--fg); font-variant-numeric: tabular-nums; }
.inline { display: inline; }

/* ---------- En-tête ---------- */
.top { border-bottom: 1px solid var(--rule); padding: .6rem 0; display: flex; flex-direction: column; gap: .5rem; }
.top-row { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.goto { display: flex; flex: 1 1 18rem; min-width: 0; gap: .4rem; }
.goto input { flex: 1 1 auto; min-width: 0; border: 1.5px solid var(--rule); background: var(--bg); padding: .45em .7em; border-radius: 3px; min-height: 2.4rem; }
.goto input:focus { border-color: var(--fg); }
.top-ref { display: none; }
.top-tools { justify-content: flex-start; }
.version-form { display: flex; gap: .4rem; }
.version-form select { border: 1.5px solid var(--fg); background: var(--bg); padding: .35em .5em; border-radius: 3px; min-height: 2.4rem; }
@media (max-width: 600px) {
  .top-tools .btn, .top-tools .seg-btn, .version-form select { padding-left: .55em; padding-right: .55em; font-size: .95rem; }
  .top-tools .btn[href$="/aide"] { display: none; }
}
@media (min-width: 900px) {
  .top { flex-direction: row; justify-content: space-between; }
  .top-row { flex: 1 1 auto; }
  .top-tools { flex: 0 0 auto; }
}

/* ---------- Page ---------- */
.page { flex: 1 0 auto; width: 100%; max-width: 46rem; margin: 0 auto; padding-block: 1.5rem 3rem; }
.foot { border-top: 1px solid var(--rule); color: var(--muted); font-size: .8rem; padding: 1rem 0 1.5rem; }
.foot p { margin: 0; max-width: 60rem; }
.narrow { max-width: 38rem; }
.narrow h1 { font-size: 1.8rem; margin-bottom: .6rem; }
.narrow h2 { font-size: 1.15rem; margin: 1.6rem 0 .5rem; }
.help li { margin-bottom: .35rem; }
.form .block { display: block; margin: .8rem 0; }
.form input[type="password"] { display: block; width: 100%; max-width: 20rem; border: 1.5px solid var(--rule); padding: .45em .7em; border-radius: 3px; background: var(--bg); margin-top: .3rem; }

/* ---------- Accueil : table des livres ---------- */
.home-title { font-size: 1.8rem; margin: 0 0 .4rem; }
.resume { border-left: 3px solid var(--rubric); background: var(--soft); padding: .8rem 1rem; margin: 0 0 1.5rem; }
.resume p { margin: 0; }
.resume-link { font-family: var(--font); font-size: 1.25rem; }
.books { display: grid; grid-template-columns: 1fr; gap: 1.5rem 3rem; margin-top: 1.2rem; }
@media (min-width: 720px) { .books { grid-template-columns: 1fr 1fr; } }
.testament h2 { font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; color: var(--rubric); font-family: var(--sans); font-weight: 600; margin: 0 0 .4rem; padding-bottom: .4rem; border-bottom: 2px solid var(--rubric); }
.book { border-bottom: 1px solid var(--rule); }
.book summary { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .55rem .2rem; cursor: pointer; list-style: none; min-height: 2.6rem; }
.book summary::-webkit-details-marker { display: none; }
.book summary::before { content: "›"; color: var(--muted); margin-right: .5rem; transition: transform .15s; display: inline-block; }
.book[open] summary::before { transform: rotate(90deg); }
.book summary:hover { background: var(--soft); }
.book-name { font-family: var(--font); font-size: 1.1rem; flex: 1 1 auto; }
.book-meta { color: var(--muted); font-size: .8rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.count { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 1em; background: var(--rubric); color: #fff; text-align: center; font-weight: 600; }
html[data-theme="blanc-sur-noir"] .count { color: #000; }
.chapters { list-style: none; margin: 0; padding: .4rem 0 .9rem; display: flex; flex-wrap: wrap; gap: .35rem; }
.chapters a { display: inline-flex; align-items: center; justify-content: center; min-width: 2.6rem; min-height: 2.6rem; border: 1px solid var(--rule); border-radius: 3px; text-decoration: none; font-variant-numeric: tabular-nums; position: relative; }
.chapters a:hover { border-color: var(--fg); background: var(--soft); }
.chapters a[aria-current="page"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chapters a.has-comments::after { content: ""; position: absolute; right: .3rem; top: .3rem; width: .4rem; height: .4rem; border-radius: 50%; background: var(--rubric); }

/* ---------- Navigation de chapitre ---------- */
.chapnav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.chapnav a { text-decoration: none; padding: .5rem 0; min-height: 2.4rem; display: inline-flex; align-items: center; }
.chapnav a:hover { text-decoration: underline; }
.chapnav-bottom { border-top: 1px solid var(--rule); margin-top: 2rem; padding-top: .5rem; }
.chapnav-pick { position: relative; }
.chapnav-pick summary { list-style: none; cursor: pointer; padding: .4rem .6rem; border: 1.5px solid transparent; border-radius: 3px; }
.chapnav-pick summary::-webkit-details-marker { display: none; }
.chapnav-pick summary:hover { border-color: var(--rule); }
.chapnav-pick[open] summary { border-color: var(--fg); }
.chapnav-pick .chapters { position: absolute; left: 50%; transform: translateX(-50%); top: 100%; z-index: 20; background: var(--bg); border: 1.5px solid var(--fg); padding: .6rem; width: min(22rem, 90vw); max-height: 60vh; overflow: auto; box-shadow: 0 6px 20px rgba(0,0,0,.15); }

/* ---------- Texte ---------- */
.chapter { position: relative; }
.chapter-head { margin: .5rem 0 1.5rem; }
.chapter-head h1 { font-size: 2.2rem; font-weight: 400; }
.text { font-family: var(--font); font-size: var(--size); line-height: var(--lh); max-width: var(--measure); hyphens: manual; }
.text p { margin: 0 0 .85em; }
.text p.q { margin: 0; padding-left: 1.5em; text-indent: -1.5em; }
.text p.q2 { padding-left: 3em; }
.text p.q + p:not(.q) { margin-top: .85em; }
.text p.li { padding-left: 1.5em; }
.text p.d { font-style: italic; color: var(--muted); margin-bottom: .6em; }
.text p.qs { text-align: right; font-style: italic; color: var(--muted); margin: 0 0 .85em; }
.text .b { height: .85em; }
.text h3.s, .text h4.s { font-family: var(--sans); font-weight: 600; font-size: .78em; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 1.6em 0 .5em; }
.text h3.ms, .text h4.ms { font-family: var(--sans); font-weight: 700; font-size: .85em; letter-spacing: .06em; text-transform: uppercase; margin: 1.8em 0 .6em; }
.text p.r { font-family: var(--sans); font-size: .72em; color: var(--muted); margin: -.3em 0 .7em; }
.text .nd { font-variant: small-caps; letter-spacing: .02em; }
.text .sc { font-variant: small-caps; }
.text .wj { }
.v { font-family: var(--sans); font-size: .62em; font-weight: 600; color: var(--rubric); text-decoration: none; vertical-align: .45em; padding: 0 .25em 0 .05em; line-height: 1; }
.v:hover { text-decoration: underline; }
.vt.hl { background: var(--hl); box-shadow: 0 0 0 3px var(--hl); border-radius: 2px; }
.fn { font-size: .62em; vertical-align: .45em; line-height: 1; }
.fn-mark { background: none; border: 0; padding: 0 .1em; color: var(--muted); cursor: pointer; font-family: var(--sans); font-weight: 600; }
.fn-mark:hover, .fn.open .fn-mark { color: var(--rubric); }
.fn-body { display: none; }
.fn.open .fn-body { display: block; font-size: .85rem; line-height: 1.4; vertical-align: baseline; font-family: var(--sans); color: var(--muted); margin: .4rem 0 .4rem 1.2rem; padding-left: .6rem; border-left: 2px solid var(--rule); }
.fn-ref { font-weight: 600; color: var(--rubric); }
.fn-ref::after { content: " ·"; }
.no-comments { font-family: var(--sans); font-size: .85rem; color: var(--muted); border-top: 1px solid var(--rule); padding-top: .8rem; margin-top: 1.5rem; max-width: var(--measure); }

/* Commentaires (en ligne, sous le passage) */
.note { font-family: var(--sans); font-size: .9rem; line-height: 1.45; border-left: 3px solid var(--rubric); background: var(--soft); padding: .7rem .9rem .5rem; margin: .6rem 0 1.1rem; max-width: var(--measure); }
.note p { margin: 0 0 .5rem; }
.note-head { font-size: .78rem; color: var(--muted); letter-spacing: .02em; }
.note-ref { color: var(--rubric); font-weight: 600; }
.note-author { color: var(--fg); font-weight: 600; }
.note-body p:last-child { margin-bottom: .3rem; }
.note-link, .note-actions { font-size: .8rem; }
.note-actions { margin: 0; }
.note:target { outline: 3px solid var(--rubric); outline-offset: 2px; }
/* Sélecteur d'auteurs : quels commentaires afficher dans ce chapitre. */
.authors { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-family: var(--sans); font-size: .82rem; margin: 0 0 1.2rem; max-width: var(--measure); }
.authors-label { color: var(--muted); letter-spacing: .06em; text-transform: uppercase; font-size: .72rem; margin-right: .2rem; }
.author-btn { border: 1.5px solid var(--rubric); color: var(--rubric); background: transparent; border-radius: 3px; padding: .25em .6em; min-height: 2rem; cursor: pointer; }
.author-btn[aria-pressed="true"] { background: var(--rubric); color: #fff; }
html[data-theme="blanc-sur-noir"] .author-btn[aria-pressed="true"] { color: #000; }
.author-btn[aria-pressed="false"] { text-decoration: line-through; opacity: .8; }
.note.author-hidden { display: none !important; }
html[data-mode="lecture"] .authors { display: none; }
/* Commentaires longs : repliés au-delà de quelques lignes, « Lire la suite » les déplie. */
.note.folded .note-body { max-height: 7.2em; overflow: hidden; position: relative; }
.note.folded .note-body::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.4em; background: linear-gradient(to bottom, transparent, var(--soft)); }
.note.in-margin.folded .note-body::after { background: linear-gradient(to bottom, transparent, var(--bg)); }
.note .note-more { font-size: .8rem; margin: 0 0 .3rem; }
.note:not(.folded):not(.unfolded) .note-more { display: none; }

/* Mode Lecture : le texte seul */
html[data-mode="lecture"] .v, html[data-mode="lecture"] .fn, html[data-mode="lecture"] .note, html[data-mode="lecture"] .no-comments, html[data-mode="lecture"] .text p.r { display: none; }
html[data-mode="lecture"][data-headings="0"] .text h3, html[data-mode="lecture"][data-headings="0"] .text h4 { display: none; }
html[data-mode="lecture"] .text p { text-align: left; }

/* Mode Étude sur grand écran : notes et commentaires dans la marge droite */
@media (min-width: 1100px) {
  html[data-mode="etude"] body.is-chapter .page { max-width: calc(var(--measure) + var(--margin) + 4rem); }
  html[data-mode="etude"] .chapter:not(.is-parallel) { width: var(--measure); }
  html[data-mode="etude"] .chapter:not(.is-parallel) .note.in-margin,
  html[data-mode="etude"] .chapter:not(.is-parallel) .fn-body.in-margin { position: absolute; left: calc(100% + 2.5rem); width: var(--margin); margin: 0; display: block; }
  html[data-mode="etude"] .chapter:not(.is-parallel) .note.in-margin { background: transparent; border-left: 2px solid var(--rubric); padding: .1rem 0 .1rem .7rem; font-size: .82rem; line-height: 1.4; }
  html[data-mode="etude"] .chapter:not(.is-parallel) .fn-body.in-margin { font-size: .78rem; line-height: 1.35; font-family: var(--sans); color: var(--muted); border-left: 2px solid var(--rule); padding-left: .6rem; vertical-align: baseline; }
  .chapnav { max-width: var(--measure); }
  html[data-mode="etude"] .chapter:not(.is-parallel) .no-comments { display: none; }
}

/* Vue en parallèle */
.chapter.is-parallel .text { max-width: none; }
.page:has(.is-parallel) { max-width: 70rem; }
.parallel { display: table; width: 100%; border-collapse: collapse; }
.prow { display: table-row; }
.pnum, .pcell { display: table-cell; vertical-align: top; padding: .35em .6em .35em 0; border-bottom: 1px solid var(--rule); }
.pnum { width: 2.5em; white-space: nowrap; }
.phead .pcell { font-family: var(--sans); font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--rubric); }
.pnote .note { margin: .4rem 0; }
.pnote { display: table-row; }
.pnote .note { display: table-cell; }
html[data-mode="lecture"] .pnum { display: none; }
.parallel .v { vertical-align: baseline; font-size: .7em; }
.prow:target .pcell, .prow:target .pnum { background: var(--hl); }
@media (max-width: 640px) {
  .parallel, .prow, .pnum, .pcell { display: block; }
  .pnum { width: auto; padding-bottom: 0; border-bottom: 0; }
  .pcell { border-bottom: 0; padding-left: 0; }
  .pcell::before { content: attr(data-version); display: block; font-family: var(--sans); font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
  .prow { border-bottom: 1px solid var(--rule); padding: .3em 0; }
  .phead { display: none; }
  .pnote .note { display: block; }
}

/* ---------- Recherche ---------- */
.search h1 { font-size: 1.8rem; margin-bottom: .4rem; }
.search-book { font-size: 1rem; font-family: var(--sans); font-weight: 600; margin: 1.6rem 0 .4rem; color: var(--rubric); }
.hits { list-style: none; padding: 0; margin: 0; }
.hits li { padding: .5rem 0; border-bottom: 1px solid var(--rule); font-family: var(--font); font-size: 1.05rem; line-height: 1.45; }
.hit-ref { font-family: var(--sans); font-size: .85rem; font-weight: 600; text-decoration: none; color: var(--rubric); margin-right: .4rem; white-space: nowrap; }
.hit-ref:hover { text-decoration: underline; }

/* ---------- Volets (dialog) ---------- */
dialog.panel { border: 1.5px solid var(--fg); padding: 0; background: var(--bg); color: var(--fg); width: min(40rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); border-radius: 4px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog.panel::backdrop { background: rgba(0,0,0,.45); }
.panel-inner { padding: 1rem 1.2rem 1.2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.panel-head h2 { font-size: 1.3rem; }
.panel fieldset { border: 0; padding: 0; margin: 0 0 .9rem; }
.panel legend { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: .35rem; padding: 0; }
.panel-foot { margin: .5rem 0 0; font-size: .85rem; }
.panel .row { display: flex; flex-wrap: wrap; gap: .6rem 1rem; margin-bottom: .8rem; }
.panel .row label { display: flex; align-items: center; gap: .4rem; white-space: nowrap; }
.panel .row .grow { flex: 1 1 10rem; }
.panel .row .grow input { flex: 1 1 auto; min-width: 0; }
.panel input[type="number"] { width: 4.5em; }
.panel input[type="number"], .panel input[type="text"], .panel input[type="url"], .panel input[type="password"], .panel textarea { border: 1.5px solid var(--rule); background: var(--bg); padding: .4em .6em; border-radius: 3px; min-height: 2.4rem; }
.panel input:focus, .panel textarea:focus { border-color: var(--fg); }
.panel .block { display: block; margin-bottom: .8rem; }
.panel .block input, .panel .block textarea { display: block; width: 100%; margin-top: .3rem; font-family: var(--font); font-size: 1rem; line-height: 1.5; }
.panel .block input { font-family: var(--sans); }
.panel-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .4rem; }
.form-error { color: var(--rubric); font-weight: 600; margin: .4rem 0; }
.login-block { border-top: 1px solid var(--rule); padding-top: .6rem; }

/* ---------- Impression ---------- */
@media print {
  .top, .foot, .chapnav, dialog, .no-comments, .note-actions, .skip { display: none !important; }
  body { padding: 0; }
  .page { max-width: none; }
  .note.in-margin, .fn-body.in-margin { position: static; width: auto; }
  .fn-body { display: block; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
