:root {
  --fond: #f4f1ea;
  --papier: #fffdf8;
  --encre: #1f1d1a;
  --discret: #6b665d;
  --trait: #ddd6c8;
  --accent: #1f4e79;
  --rouge: #c00000;
  --ombre: 0 1px 2px rgba(31, 29, 26, .06), 0 4px 16px rgba(31, 29, 26, .06);
  --rayon: 10px;
  --entete: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--encre);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fond); }
button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

/* En-tête */
.entete { position: sticky; top: 0; z-index: 20; height: var(--entete); display: flex; align-items: center; gap: 16px;
  padding: 0 20px; background: var(--papier); border-bottom: 1px solid var(--trait); }
.entete .marque { font-weight: 700; letter-spacing: .02em; text-decoration: none; color: var(--encre); white-space: nowrap; }
.entete .marque small { display: block; font-weight: 400; font-size: 12px; color: var(--discret); letter-spacing: 0; }
.entete h1 { font-size: 16px; font-weight: 600; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bouton { border: 1px solid var(--trait); background: var(--papier); color: var(--encre); border-radius: 8px; padding: 8px 14px; font-size: 14px; }
.bouton:hover { border-color: var(--discret); }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: #fff; }
.bouton.principal:hover { filter: brightness(1.1); }
.bouton:focus-visible, .page-btn:focus-visible { outline: 3px solid #8ab4e8; outline-offset: 1px; }

/* Barre de navigation du document */
.barre { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 12px 20px; }
.pages { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--discret); }
.page-btn { min-width: 34px; height: 34px; border: 1px solid var(--trait); background: var(--papier); border-radius: 8px; color: var(--encre); }
.page-btn[aria-current="true"] { background: var(--encre); color: #fff; border-color: var(--encre); }
.page-btn:disabled { opacity: .35; cursor: default; }
.legende { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--discret); }
.legende span { display: inline-flex; align-items: center; gap: 6px; }
.pastille { width: 13px; height: 13px; border-radius: 3px; display: inline-block; flex: none; }
.pastille.incertain { border: 2px dashed var(--rouge); }

/* Fiche de synthèse */
.synthese { margin: 0 20px 12px; background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre); }
.synthese summary { padding: 12px 16px; font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.synthese summary::after { content: "Replier"; font-weight: 400; font-size: 13px; color: var(--discret); }
.synthese:not([open]) summary::after { content: "Déplier"; }
.synthese summary::-webkit-details-marker { display: none; }
.synthese dl { margin: 0; padding: 0 16px 12px; display: grid; grid-template-columns: minmax(150px, max-content) 1fr; gap: 6px 16px; font-size: 14px; }
.synthese dt { display: flex; align-items: flex-start; gap: 8px; color: var(--discret); padding-top: 3px; }
.synthese dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; }
.ligne-synthese { border: 0; background: transparent; padding: 3px 6px; border-radius: 6px; text-align: left; color: var(--encre); }
button.ligne-synthese:hover { background: #efe9dc; }
.ligne-synthese.doute { color: var(--rouge); text-decoration: underline wavy var(--rouge); text-underline-offset: 4px; }
.ligne-synthese.vide { color: var(--discret); font-style: italic; cursor: default; }
.ligne-synthese + .ligne-synthese::before { content: ""; }

/* Côte à côte */
.cote-a-cote { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 0 20px 20px; }
.volet { background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre);
  height: calc(100vh - var(--entete) - 24px); overflow: auto; position: sticky; top: calc(var(--entete) + 12px); }
.volet-titre { position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-size: 13px; color: var(--discret); background: var(--papier); border-bottom: 1px solid var(--trait); }
.zoom { display: flex; gap: 4px; }
.zoom button { width: 30px; height: 28px; border: 1px solid var(--trait); background: var(--papier); border-radius: 6px; }
.manuscrit { position: relative; margin: 10px; }
.manuscrit img { display: block; width: 100%; height: auto; border-radius: 4px; }
.zone { position: absolute; border-radius: 3px; border: 2px solid transparent; transition: box-shadow .15s, background-color .15s; }
.zone.categorisee { cursor: pointer; }
.zone.doute { border: 2px dashed var(--rouge) !important; }
.zone.libre.actif { background: rgba(138, 129, 112, .18); border-color: rgba(138, 129, 112, .9); }
.zone.actif { box-shadow: 0 0 0 3px var(--encre); z-index: 2; }
.transcription { padding: 18px 24px 40px; font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: 16.5px; line-height: 1.85; }
.transcription p { margin: 0 0 14px; }
.seg { border-radius: 3px; padding: 1px 1px; transition: box-shadow .15s; }
.seg.categorisee, .seg.doute, .seg.confirme, .seg.corrige, .seg.posterieur { cursor: pointer; }
.seg.doute { color: var(--rouge); text-decoration: underline wavy var(--rouge); text-underline-offset: 4px; }
.seg.posterieur { font-style: italic; color: var(--discret); }
.seg.confirme::after { content: "✓"; font-family: system-ui, sans-serif; font-size: 11px; color: #2d7a3a; vertical-align: super; margin-left: 1px; }
.seg.corrige::after { content: "corrigé"; font-family: system-ui, sans-serif; font-size: 10px; color: var(--accent);
  border: 1px solid currentColor; border-radius: 4px; padding: 0 3px; margin-left: 3px; vertical-align: super; }
.seg.actif { box-shadow: 0 0 0 2px var(--encre); }
.bulle { position: fixed; z-index: 50; max-width: 340px; padding: 8px 10px; border-radius: 8px; background: #1f1d1a; color: #fff;
  font-size: 13px; line-height: 1.45; white-space: pre-line; pointer-events: none; box-shadow: var(--ombre); }
.introuvable { max-width: 520px; margin: 80px auto; text-align: center; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: none; } }

/* Accueil */
.accueil { max-width: 880px; margin: 0 auto; padding: 40px 20px; }
.accueil h1 { font-size: 26px; margin: 0 0 8px; }
.accueil .intro { color: var(--discret); margin: 0 0 28px; line-height: 1.6; }
.cartes { display: grid; gap: 14px; }
.carte { display: flex; align-items: center; gap: 18px; padding: 16px; background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre); }
.carte img { width: 84px; height: 112px; object-fit: cover; border-radius: 6px; border: 1px solid var(--trait); }
.carte h3 { margin: 0 0 4px; font-size: 17px; }
.carte p { margin: 0; color: var(--discret); font-size: 14px; }
.carte .bouton { margin-left: auto; text-decoration: none; }

@media (max-width: 860px) {
  .cote-a-cote { grid-template-columns: 1fr; }
  .volet { position: static; height: auto; max-height: none; }
  .entete { padding: 0 16px; gap: 10px; }
  .entete .marque small { display: none; }
  .barre, .cote-a-cote { padding-left: 16px; padding-right: 16px; }
  .synthese { margin: 0 16px 12px; }
  .synthese dl { grid-template-columns: 1fr; }
  .carte { flex-wrap: wrap; }
  .carte .bouton { margin-left: 0; }
}
@media (max-width: 520px) {
  .entete h1 { display: none; }
  .entete .marque { flex: 1; }
  .long { display: none; }
}

/* Panneau de grille */
.panneau-grille { margin: 0 20px 12px; padding: 16px; background: var(--papier); border: 1px solid var(--trait); border-radius: var(--rayon); box-shadow: var(--ombre); }
.panneau-entete h2 { margin: 0 0 4px; font-size: 16px; }
.panneau-entete p { margin: 0 0 12px; color: var(--discret); font-size: 14px; }
.categories { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.categories li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.categories input[type=text], .ajout input[type=text] { flex: 1; min-width: 180px; padding: 7px 10px; border: 1px solid var(--trait); border-radius: 8px; font: inherit; font-size: 14px; background: #fff; }
.categories input[type=color], .ajout input[type=color] { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--trait); border-radius: 8px; background: #fff; cursor: pointer; }
.afficher { font-size: 14px; color: var(--discret); display: inline-flex; gap: 6px; align-items: center; }
.categories .bouton { padding: 6px 10px; font-size: 13px; }
.ajout { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 10px; border-top: 1px solid var(--trait); }
.aide-surlignage { margin: 12px 0 0; padding: 10px 12px; background: #eef3fa; border-radius: 8px; font-size: 14px; }
.panneau-grille:has(.compacte) { position: sticky; top: calc(var(--entete) + 4px); z-index: 10; padding: 0; }
.aide-surlignage.compacte { margin: 0; display: flex; align-items: center; gap: 10px; }
.aide-surlignage.compacte span { flex: 1; }
.pied-panneau { margin-top: 12px; display: flex; justify-content: flex-end; }
body.mode-surlignage .transcription { cursor: text; }
body.mode-surlignage .transcription .seg { cursor: pointer; }
body.mode-surlignage .transcription .seg:hover { outline: 2px dashed var(--accent); }
@media (max-width: 860px) { .panneau-grille { margin: 0 16px 12px; } }
body.mode-surlignage .volet { top: calc(var(--entete) + 66px); height: calc(100vh - var(--entete) - 78px); }
@media (max-width: 860px) { body.mode-surlignage .volet { height: auto; } }
