/* ============================================================
   CODEX - refonte complète, mobile d'abord.
   Aucune dépendance à Tailwind. Une seule feuille.
   ============================================================ */

@font-face {
  font-family: 'EB Garamond';
  src: url('/fonts/ebgaramond-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('/fonts/ebgaramond-italic-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url('/fonts/imfell-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url('/fonts/imfell-italic-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #f4ead7;
  --paper-2: #eadcc0;
  --paper-3: #fbf5e6;
  --ink: #1f1a15;
  --ink-2: #4c4033;
  --ink-3: #6d5d4b;
  --rubric: #8b2f23;
  --rubric-2: #6d2119;
  --verdigris: #3d5847;
  --gold: #a17f39;
  --rule: rgba(52, 38, 22, 0.30);
  --rule-2: rgba(52, 38, 22, 0.14);
  --serif: 'EB Garamond', Garamond, Georgia, serif;
  --display: 'IM Fell English', 'EB Garamond', Georgia, serif;
  --measure: 68ch;
  --head-h: 56px;
  --bar-h: 60px;
}

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

html {
  background: #c9b78f;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom));
  font: 400 19px/1.72 var(--serif);
  color: #241c14;
  background-color: #d5be8c;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Fond sur un calque fixe : composé une fois, aucun repaint au scroll.
   (background-attachment: fixed provoque un saut de l'image en défilement rapide.) */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-color: #d5be8c;
  background-image:
    radial-gradient(ellipse at 50% 35%, rgba(60, 40, 18, 0) 35%, rgba(60, 40, 18, 0.22) 100%),
    url('/images/parchment-dark.webp?v=2');
  background-size: cover, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  transform: translateZ(0);
  backface-visibility: hidden;
}

@media (min-width: 960px) {
  body { padding-bottom: 0; }
}

img { max-width: 100%; height: auto; }

a {
  color: var(--rubric);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { color: var(--rubric-2); }

:focus-visible {
  outline: 2px solid var(--rubric);
  outline-offset: 3px;
}

.hidden { display: none !important; }

::selection { background: rgba(139, 47, 35, 0.18); }

/* ---------- En-tête ---------- */

.site-head {
  position: sticky;
  top: 0;
  z-index: 40;
  background: linear-gradient(180deg, rgba(250, 243, 228, 0.95), rgba(240, 228, 205, 0.92));
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(3px);
}

.head-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0.5rem 0.9rem;
  min-height: var(--head-h);
}

.sigil {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  padding: 2px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
}
.sigil img { display: block; width: 100%; height: 100%; object-fit: cover; }

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.02;
  margin-right: auto;
  min-width: 0;
}
.brand b {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.02rem;
  letter-spacing: 0.12em;
  white-space: nowrap;
}
.brand span {
  font-size: 0.58rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}

.head-actions { display: flex; align-items: center; gap: 0.15rem; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  background: none;
  color: var(--ink);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { border-color: var(--rule); background: rgba(255, 250, 238, 0.55); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .count {
  position: absolute;
  transform: translate(14px, -12px);
  font-size: 0.6rem;
  color: var(--rubric);
}


.menu-btn { display: grid; }
@media (min-width: 960px) { .menu-btn { display: none; } }

/* Barre de progression de lecture */
.progress {
  position: absolute;
  left: 0;
  bottom: -1px;
  height: 2px;
  width: 0;
  background: var(--rubric);
  transition: width 0.1s linear;
}

/* ---------- Panneaux (recherche, musique, tiroir) ---------- */

.panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0.9rem;
  z-index: 45;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  box-shadow: 0 18px 30px -26px rgba(40, 25, 8, 0.9);
  padding: 0.7rem;
  width: min(22rem, calc(100vw - 1.8rem));
}

.search-form { display: flex; border: 1px solid var(--rule); background: #fffaf0; }
.search-form input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 0.6rem 0.7rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
}
.search-form input:focus { outline: none; }
.search-form button {
  border: 0;
  border-left: 1px solid var(--rule);
  background: var(--rubric);
  color: var(--paper-3);
  padding: 0 0.9rem;
  font-family: var(--display);
  letter-spacing: 0.08em;
  cursor: pointer;
}

.search-results { margin-top: 0.5rem; max-height: 14rem; overflow-y: auto; }
.search-results a {
  display: block;
  padding: 0.5rem 0.35rem;
  border-bottom: 1px dotted var(--rule);
  text-decoration: none;
  color: var(--ink);
  font-size: 0.92rem;
}
.search-results a:hover { color: var(--rubric); background: rgba(255, 250, 238, 0.6); }
.search-results .empty { padding: 0.5rem 0.35rem; color: var(--ink-3); font-style: italic; }

.music-panel { width: min(19rem, calc(100vw - 1.8rem)); }
.music-row { display: flex; align-items: center; gap: 0.4rem; }
.music-row button {
  border: 1px solid var(--rule);
  background: none;
  color: var(--rubric);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-family: var(--display);
  font-size: 0.9rem;
}
.music-row button:hover { background: rgba(255, 250, 238, 0.7); }
.music-range { width: 100%; margin-top: 0.6rem; accent-color: var(--rubric); }
.music-label {
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
}

/* Tiroir mobile */
.drawer {
  position: fixed;
  inset: var(--head-h) 0 0 0;
  z-index: 55;
  background: rgba(244, 234, 215, 0.98);
  padding: 1.4rem 1.2rem calc(2rem + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.drawer h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 1rem;
}
.drawer ol { list-style: none; margin: 0; padding: 0; }
.drawer a {
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--rule-2);
  color: var(--ink);
  text-decoration: none;
  font-size: 1.1rem;
}
.drawer a[aria-current='page'] { color: var(--rubric); }
.drawer .n { font-family: var(--display); color: var(--gold); min-width: 2rem; font-size: 0.9rem; }

/* ---------- Structure ---------- */

.shell {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  background: rgba(252, 246, 232, 0.80);
}

@media (min-width: 960px) {
  .shell {
    grid-template-columns: 14rem minmax(0, 1fr) 15rem;
    gap: 2.2rem;
    padding: 0 2.4rem 0 2rem;
    margin: 1.4rem auto;
    border: 1px solid rgba(52, 38, 22, 0.35);
    box-shadow: 0 30px 70px -50px rgba(30, 18, 6, 0.9);
    align-items: start;
  }
}

.rail, .marginalia { display: none; }

.rail h2, .marginalia h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.68rem;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 0.9rem;
}

@media (min-width: 960px) {
  .rail {
    display: block;
    position: sticky;
    top: calc(var(--head-h) + 2rem);
    padding: 2.6rem 0 2rem;
  }
  .rail ol { list-style: none; margin: 0; padding: 0; }
  .rail a {
    display: flex;
    gap: 0.55rem;
    padding: 0.42rem 0;
    border-bottom: 1px solid var(--rule-2);
    color: var(--ink-2);
    text-decoration: none;
    font-size: 0.9rem;
    line-height: 1.3;
  }
  .rail a:hover { color: var(--rubric); }
  .rail a[aria-current='page'] { color: var(--rubric); }
  .rail .n { font-family: var(--display); color: var(--gold); min-width: 1.5rem; font-size: 0.8rem; }
}

@media (min-width: 1200px) {
  .marginalia {
    display: block;
    position: sticky;
    top: calc(var(--head-h) + 2rem);
    padding: 2.6rem 0 2rem;
    font-size: 0.88rem;
    color: var(--ink-2);
  }
}

.marginalia dl { margin: 0 0 1.6rem; }
.marginalia dt {
  font-size: 0.6rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 0.7rem;
}
.marginalia dd { margin: 0.1rem 0 0; }
.marginalia .note {
  border-top: 1px solid var(--rule-2);
  padding-top: 0.8rem;
  font-style: italic;
  color: var(--ink-3);
}

/* ---------- Feuillet ---------- */

.leaf {
  min-width: 0;
  padding: 2rem 1.15rem 3rem;
}

@media (min-width: 960px) {
  .leaf {
    padding: 3.2rem 0 4rem;
    max-width: var(--measure);
  }
}

.kicker {
  margin: 0 0 0.5rem;
  font-size: 0.68rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--rubric);
}

.leaf h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.1rem, 1.4rem + 3.4vw, 3.4rem);
  line-height: 1.04;
  letter-spacing: 0.005em;
  margin: 0 0 0.7rem;
}

.leaf .lead {
  font-size: 1.1em;
  font-style: italic;
  color: var(--ink-2);
  max-width: 50ch;
  margin: 0 0 0.5rem;
}

.ornament {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin: 1.4rem 0 2rem;
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.35em;
}
.ornament::before,
.ornament::after {
  content: '';
  height: 1px;
  flex: 1;
  background: var(--rule);
}

/* Titre + portrait (accueil) */
.title-page { margin-bottom: 2.2rem; }
.title-page .sub {
  font-size: 0.72rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 1rem;
}

.plate { margin: 0 0 1rem; }
.plate .frame {
  border: 1px solid var(--rule);
  background: var(--paper-3);
  padding: 6px;
}
.plate img { display: block; width: 100%; height: auto; filter: sepia(0.1); }
.plate figcaption {
  margin-top: 0.45rem;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.plate .no { color: var(--rubric); margin-right: 0.45rem; }

@media (min-width: 640px) {
  .title-page { display: grid; grid-template-columns: 1fr 15rem; gap: 2rem; align-items: end; }
  .title-page .plate { margin: 0; }
}

/* Sommaire */
.toc { margin: 0 0 3rem; }
.toc h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 0.7rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 0.6rem;
}
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc a {
  display: flex;
  gap: 0.9rem;
  align-items: baseline;
  padding: 0.48rem 0;
  border-bottom: 1px dotted var(--rule);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.98rem;
}
.toc a:hover { color: var(--rubric); }
.toc .n { font-family: var(--display); color: var(--rubric); min-width: 2rem; font-size: 0.88rem; }

/* Chapitres de l'accueil */
.chapter {
  margin-top: 2.6rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule-2);
}
.chapter:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.chapter-head {
  display: flex;
  align-items: baseline;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}
.chapter-num {
  font-family: var(--display);
  color: var(--rubric);
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  min-width: 2.2rem;
}
.chapter h2 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.45rem;
  letter-spacing: 0;
  margin: 0;
  line-height: 1.2;
}

/* ---------- Texte courant ---------- */

.prose { font-size: 1.05em; line-height: 1.75; }
.prose > p { margin: 0 0 1.05rem; }

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
  margin: 2rem 0 0.7rem;
}
.prose h2 { font-size: 1.85rem; }
.prose h3 { font-size: 1.5rem; border-bottom: 1px solid var(--rule-2); padding-bottom: 0.3rem; }
.prose h4 { font-size: 1.2rem; }

.prose ul, .prose ol { padding-left: 1.2rem; margin: 0 0 1rem; }
.prose li { margin-bottom: 0.35rem; }
.prose li::marker { color: var(--gold); }

.prose blockquote {
  margin: 1.4rem 0;
  padding: 0.2rem 0 0.2rem 1.1rem;
  border-left: 2px solid var(--rubric);
  font-style: italic;
  color: var(--ink-2);
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.6rem auto;
  padding: 5px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  filter: sepia(0.1);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.94rem;
}
.prose th, .prose td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--rule-2);
  vertical-align: top;
}
.prose th {
  font-family: var(--display);
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  border-bottom-color: var(--rule);
}

.prose hr {
  border: 0;
  text-align: center;
  margin: 2.2rem 0;
  color: var(--gold);
}
.prose hr::before { content: '❧'; font-size: 1.2rem; }

.prose a { text-decoration-style: dotted; }

/* Recherche : surlignage */
mark.hit {
  background: rgba(161, 127, 57, 0.35);
  color: var(--ink);
  padding: 0 0.1em;
  box-shadow: 0 0 0 1px rgba(161, 127, 57, 0.5);
}
mark.hit.current { background: rgba(139, 47, 35, 0.3); box-shadow: 0 0 0 2px var(--rubric); }

/* ---------- Planches ---------- */

.plates {
  display: grid;
  gap: 1.6rem;
  grid-template-columns: minmax(0, 1fr);
  margin-top: 2rem;
}
@media (min-width: 620px) { .plates { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .plates { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.plates .plate { margin: 0; cursor: pointer; }
.plates .frame { position: relative; }
.plates img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  filter: sepia(0.1);
  transition: filter 0.2s;
}
.plates .plate:hover img { filter: sepia(0.16) brightness(1.03); }
.plates figcaption { text-transform: uppercase; font-size: 0.64rem; letter-spacing: 0.1em; }

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(24, 18, 12, 0.92);
  padding: 1.2rem;
  align-items: center;
  justify-content: center;
}
.lightbox.open { display: flex; }
.lightbox-inner { max-width: min(92vw, 900px); max-height: 90vh; }
.lightbox img {
  display: block;
  max-width: 100%;
  max-height: 78vh;
  margin: 0 auto;
  border: 1px solid rgba(244, 234, 215, 0.35);
  padding: 5px;
  background: rgba(244, 234, 215, 0.06);
}
.lightbox p {
  color: var(--paper);
  text-align: center;
  margin: 0.8rem 0 0;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.lightbox button {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  background: none;
  border: 1px solid rgba(244, 234, 215, 0.4);
  color: var(--paper);
  font-size: 1.3rem;
  cursor: pointer;
}
.lightbox .nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 64px;
  background: none;
  border: 0;
  color: var(--paper);
  font-size: 1.6rem;
  cursor: pointer;
  opacity: 0.75;
}
.lightbox .nav:hover { opacity: 1; }
.lightbox .prev { left: 0.6rem; }
.lightbox .next { right: 0.6rem; }

/* ---------- Pagination de chapitre ---------- */

.pager {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.2rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
  font-size: 0.85rem;
}
.pager a { text-decoration: none; color: var(--ink-2); }
.pager a:hover { color: var(--rubric); }
.pager .dir {
  display: block;
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.pager .next { text-align: right; margin-left: auto; }

/* ---------- Colophon ---------- */

.colophon {
  position: relative;
  z-index: 1;
  max-width: 1500px;
  margin: 0 auto;
  padding: 1.6rem 1rem 2.4rem;
  border-top: 1px solid rgba(52, 38, 22, 0.28);
  text-align: center;
  color: #33291d;
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.colophon .mark { color: var(--gold); letter-spacing: 0.4em; display: block; margin-bottom: 0.5rem; }

/* ---------- Barre mobile ---------- */

.mobilebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  background: rgba(246, 238, 221, 0.97);
  border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobilebar button,
.mobilebar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  min-height: var(--bar-h);
  padding: 0.4rem 0;
  background: none;
  border: 0;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.56rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
}
.mobilebar button[aria-current='true'],
.mobilebar a[aria-current='page'] { color: var(--rubric); }
.mobilebar svg { width: 21px; height: 21px; }

@media (min-width: 960px) { .mobilebar { display: none; } }

/* ---------- Scribe (chatbot) ---------- */

#chatPanel {
  position: fixed;
  z-index: 70;
  left: 0;
  right: 0;
  bottom: 0;
  height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  box-shadow: 0 -18px 40px -30px rgba(30, 18, 6, 0.9);
}

@media (min-width: 640px) {
  #chatPanel {
    left: auto;
    width: 420px;
    height: min(660px, 86vh);
    bottom: 1rem;
    right: 1rem;
    border: 1px solid var(--rule);
  }
}

.scribe-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 2px double var(--rule);
  background: rgba(234, 220, 192, 0.5);
}
.scribe-head .sigil { width: 30px; height: 30px; }
.scribe-title { display: flex; flex-direction: column; line-height: 1.1; margin-right: auto; }
.scribe-title b { font-family: var(--display); font-weight: 400; font-size: 0.95rem; letter-spacing: 0.1em; }
.scribe-title span { font-size: 0.56rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-3); }
.scribe-head .icon-btn { width: 34px; height: 34px; font-size: 1.1rem; }

#chatMessages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  font-size: 0.95rem;
}

.msg { max-width: 92%; }
.msg p { margin: 0; white-space: pre-wrap; }
.msg.assistant {
  align-self: flex-start;
  padding-left: 0.8rem;
  border-left: 2px solid var(--rule);
  color: var(--ink);
}
.msg.user {
  align-self: flex-end;
  text-align: right;
  font-style: italic;
  color: var(--ink-2);
  padding-right: 0.6rem;
  border-right: 2px solid var(--rubric);
}
.msg .who {
  display: block;
  font-size: 0.54rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 0.2rem;
  font-style: normal;
}
.msg.sources { display: flex; flex-wrap: wrap; gap: 0.35rem; border: 0; padding: 0; }
.msg.sources a {
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--rubric);
  border: 1px solid var(--rule);
  padding: 0.25rem 0.45rem;
  background: rgba(251, 245, 230, 0.7);
}
.msg.sources a:hover { background: var(--paper-3); }

.scribe-foot { border-top: 1px solid var(--rule); padding: 0.6rem; }
.scribe-form { display: flex; gap: 0.4rem; }
.scribe-form input {
  flex: 1;
  min-width: 0;
  background: #fffaf0;
  border: 1px solid var(--rule);
  padding: 0.6rem 0.7rem;
  font: inherit;
  font-size: 0.92rem;
  color: var(--ink);
}
.scribe-form input:focus { outline: none; box-shadow: inset 0 0 0 1px var(--rubric); }
.scribe-form button {
  border: 1px solid var(--rubric);
  background: var(--rubric);
  color: var(--paper-3);
  padding: 0 1rem;
  font-family: var(--display);
  letter-spacing: 0.08em;
  cursor: pointer;
}
.scribe-form button:disabled { opacity: 0.5; cursor: default; }
.scribe-hint {
  margin: 0.35rem 0 0;
  font-size: 0.56rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
}
#chatThinking { padding: 0 0.95rem 0.4rem; font-size: 0.72rem; color: var(--ink-3); font-style: italic; }

/* ---------- 404 ---------- */

.notfound { text-align: center; padding: 4rem 0; }
.notfound .code {
  font-family: var(--display);
  font-size: clamp(4rem, 12vw, 7rem);
  color: var(--rubric);
  line-height: 1;
  margin: 0;
}
.notfound h1 { margin-top: 0.5rem; }

/* ---------- Mouvement réduit ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

/* Sceau du scribe (bouton flottant) */
#chatToggle {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 65;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 0.5rem;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  box-shadow: 0 10px 22px -18px rgba(40, 25, 8, 0.9);
  cursor: pointer;
}
#chatToggle img { width: 32px; height: 32px; object-fit: cover; }
#chatToggle span {
  font-size: 0.5rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
#chatToggle:hover { background: #fffaf0; }
@media (min-width: 960px) { #chatToggle { display: flex; } }

/* Navigation de recherche */
.search-nav {
  position: fixed;
  right: 1rem;
  bottom: calc(var(--bar-h) + 1rem);
  z-index: 45;
  display: flex;
  gap: 0.35rem;
}
@media (min-width: 960px) { .search-nav { bottom: 1.5rem; } }
.search-nav button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--rule);
  background: var(--paper-3);
  color: var(--rubric);
  font-family: var(--display);
  font-size: 1.2rem;
  cursor: pointer;
}
.search-nav button:hover { background: #fffaf0; }

/* Très petits écrans : on libère de la place dans l'en-tête
   (la musique reste accessible depuis la barre du bas). */
@media (max-width: 520px) {
  #musicToggle, #visitorCountBtn { display: none; }
  .brand span { display: none; }
  .head-inner { gap: 0.45rem; }
}

/* ---------- Sommaire de page ---------- */

.prose h1[id], .prose h2[id], .prose h3[id], .prose h4[id] {
  scroll-margin-top: calc(var(--head-h) + 1rem);
}

.page-toc {
  margin: 0 0 1.8rem;
  border-top: 1px solid var(--rule-2);
  border-bottom: 1px solid var(--rule-2);
  padding: 0.5rem 0;
}
.page-toc summary {
  cursor: pointer;
  font-size: 0.66rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--ink-3);
  list-style: none;
}
.page-toc summary::-webkit-details-marker { display: none; }
.page-toc summary::after {
  content: '+';
  float: right;
  color: var(--rubric);
}
.page-toc[open] summary::after { content: '−'; }
.page-toc ol, .page-toc-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}
.page-toc li, .page-toc-list li { margin: 0; }
.page-toc a, .page-toc-list a {
  display: block;
  padding: 0.32rem 0;
  border-bottom: 1px dotted var(--rule-2);
  color: var(--ink-2);
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.3;
}
.page-toc a:hover, .page-toc-list a:hover { color: var(--rubric); }
.page-toc-list a.current, .page-toc a.current {
  color: var(--rubric);
  border-bottom-color: var(--rubric);
}
.page-toc .lvl-2 a, .page-toc-list .lvl-2 a {
  font-weight: 600;
  color: var(--ink);
}
.page-toc .lvl-4 a, .page-toc-list .lvl-4 a {
  padding-left: 0.9rem;
  font-size: 0.84rem;
  color: var(--ink-3);
}

@media (min-width: 1200px) {
  .page-toc { display: none; }
}

/* ---------- Ancre de section ---------- */

.anchor-copy {
  margin-left: 0.4rem;
  border: 0;
  background: none;
  color: var(--gold);
  font-family: var(--serif);
  font-size: 0.8em;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0 0.15rem;
  vertical-align: middle;
}
h2:hover .anchor-copy,
h3:hover .anchor-copy,
.anchor-copy:focus-visible { opacity: 1; }
.anchor-copy:hover { color: var(--rubric); }
.anchor-copy.copied {
  opacity: 1;
  color: var(--verdigris);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
@media (hover: none) {
  .anchor-copy { opacity: 1; }
}

/* Lien d'évitement (clavier) */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
}
.skip-link:focus {
  left: 0.8rem;
  top: 0.8rem;
  z-index: 100;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  padding: 0.55rem 0.9rem;
  color: var(--ink);
  text-decoration: none;
}

/* Surlignage des passages cités par le scribe (?hl=) */
mark.chat-hl {
  background: rgba(161, 127, 57, 0.30);
  color: var(--ink);
  padding: 0 0.12em;
  box-shadow: 0 0 0 1px rgba(161, 127, 57, 0.55);
  scroll-margin-top: calc(var(--head-h) + 2rem);
  animation: chatHlPulse 1.6s ease-out 2;
}
@keyframes chatHlPulse {
  0% { box-shadow: 0 0 0 5px rgba(161, 127, 57, 0.45); }
  100% { box-shadow: 0 0 0 1px rgba(161, 127, 57, 0.55); }
}
@media (prefers-reduced-motion: reduce) {
  mark.chat-hl { animation: none; }
}

/* Tableaux markdown : défilement horizontal sans casser la page */
.table-scroll {
  overflow-x: auto;
  margin: 1.2rem 0;
  -webkit-overflow-scrolling: touch;
}
.table-scroll table { margin: 0; }

.prose p, .prose li, .prose dd { overflow-wrap: break-word; }

/* Vidéos et iframes intégrés au markdown (les classes Tailwind ont disparu) */
.prose video,
.prose iframe {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1.6rem auto;
  border: 1px solid var(--rule);
  padding: 4px;
  background: var(--paper-3);
}

/* Titre de la piste en cours */
.music-title {
  margin: 0 0 0.6rem;
  font-family: var(--serif);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  text-align: center;
}
