/* Affichage à l'écran des livres de la bibliothèque (demande de Pierre, 2026-11-08).
   Chaque partie du livre (couverture, liminaires, chapitres, annexes) devient une page Lettre en portrait,
   blanche, avec marges, posée sur un fond coloré. L'impression n'est pas touchée (@media screen seulement).
   Fond : <html data-bibliotheque="immobiliere"> gris-bleu ; <html data-bibliotheque="la-machine"> bleu royal semi-transparent. */
@media screen {
  html { background: #5E6E85; min-height: 100%; }                       /* gris-bleu : Bibliothèque Immobilière */
  html[data-bibliotheque="la-machine"] { background: rgba(65, 105, 225, 0.55); } /* bleu royal semi-transparent */
  body { background: transparent !important; padding: 40px 16px 64px; }
  main.book { max-width: none; margin: 0; padding: 0; }
  .cover-page,
  section.chapter {
    box-sizing: border-box;
    width: 100%;
    max-width: 8.5in;                     /* largeur d'une page Lettre */
    min-height: 11in;                     /* au moins une page de haut */
    margin: 0 auto 32px;
    padding: 0.9in 1in;                   /* marges intérieures, le texte ne touche pas le bord */
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 2px 6px rgba(16, 27, 61, 0.18), 0 12px 32px rgba(16, 27, 61, 0.22);
    overflow-wrap: break-word;
  }
  .cover-page { height: auto; aspect-ratio: 5 / 8; background: #0B0C23; min-height: 0; padding: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
  .cover-page img { width: 100%; height: 100%; object-fit: cover; display: block; }
  html[data-bibliotheque="la-machine"] .cover-page { background: #000201; }  /* couverture 1600 x 2560 : pleine page, sans bandes */
  img, svg, table { max-width: 100%; }
  table { display: table; }
  .cbreak { display: none; }
}
@media screen and (max-width: 720px) {
  body { padding: 16px 8px 40px; }
  .cover-page, section.chapter { padding: 28px 20px; min-height: 0; margin-bottom: 16px; }
  .cover-page { padding: 0; }
  table { display: block; overflow-x: auto; }
}

/* ======================================================================================
   Lecteur en ligne : barre, tiroir, themes, taille du texte (lecture-livre.js).
   Tout est reserve a l'ecran ; a l'impression, seuls les elements ajoutes par le lecteur sont masques.
   ====================================================================================== */
@media print { .lecteur { display: none !important; } }

@media screen {
  html {
    --lc-bar-h: 52px; --lc-z: 1;
    --lc-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --lc-accent: #4169E1; --lc-on-accent: #fff;
    --lc-bg: rgba(255,255,255,.97); --lc-fg: #1c2430; --lc-mut: #5b6472; --lc-line: #dfe3ea; --lc-hov: #eef1f6; --lc-sel: #e4eafc;
    --lc-page: #fff;
  }
  html[data-bibliotheque="la-machine"] { --lc-accent: #5252E8; --lc-sel: #e9e9ff; }

  /* themes : fond de la page, interface, couleurs du texte du livre */
  html[data-lecteur-theme="sepia"] {
    --lc-bg: rgba(244,236,216,.97); --lc-fg: #3a3025; --lc-mut: #7a6a52; --lc-line: #ddd0b3; --lc-hov: #eadfc6; --lc-sel: #e6d9b8;
    --lc-page: #f5edd9; color-scheme: light;
    --color-text-primary: #3a3025; --color-text-secondary: #5c4e3b; --color-bg-secondary: #efe3c8;
    --color-border: #dccfae; --color-border-subtle: #e6dbbf; --color-bg-card: #f5edd9;
  }
  html.lecteur-actif .cover-page,
  html.lecteur-actif section.chapter { background: var(--lc-page); }

  /* taille du texte : zoom des pages, largeur et marges visuelles inchangees */
  html[data-lecteur-taille="0"] { --lc-z: .9; }
  html[data-lecteur-taille="2"] { --lc-z: 1.15; }
  html[data-lecteur-taille="3"] { --lc-z: 1.3; }
  html[data-lecteur-taille="4"] { --lc-z: 1.5; }
  html.lecteur-actif section.chapter {
    zoom: var(--lc-z);
    max-width: calc(8.5in / var(--lc-z));
    min-height: calc(11in / var(--lc-z));
    padding: calc(.9in / var(--lc-z)) calc(1in / var(--lc-z));
    margin-bottom: calc(32px / var(--lc-z));
    scroll-margin-top: calc((var(--lc-bar-h) + 10px) / var(--lc-z));
  }
  html.lecteur-actif body { padding-top: calc(var(--lc-bar-h) + 22px); }
  html.lecteur-actif main.book [id] { scroll-margin-top: calc((var(--lc-bar-h) + 16px) / var(--lc-z)); }
  @media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

  .lc-toc:hover { text-decoration: underline; }

  /* ---- composants ---- */
  .lecteur { font: 14px/1.4 var(--lc-ui); color: var(--lc-fg); hyphens: manual; letter-spacing: 0; text-align: left; text-transform: none; word-break: normal; }
  .lecteur *, .lecteur *::before, .lecteur *::after { box-sizing: border-box; }
  .lecteur a { color: inherit; text-decoration: none; word-break: normal; }
  .lecteur button, .lecteur input { font: inherit; color: inherit; }
  .lc-ic { flex: none; display: block; }

  .lc-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
    min-width: 36px; height: 36px; padding: 0 8px; border: 0; border-radius: 8px; margin: 0;
    background: transparent; color: var(--lc-fg); cursor: pointer; white-space: nowrap; text-decoration: none;
  }
  .lc-btn:hover { background: var(--lc-hov); }
  .lc-btn[disabled] { opacity: .35; cursor: default; background: transparent; }
  .lecteur :focus-visible { outline: 2px solid var(--lc-accent); outline-offset: 2px; }

  .lc-bar {
    position: fixed; top: 0; left: 0; right: 0; height: var(--lc-bar-h); z-index: 1000;
    display: flex; align-items: center; gap: 4px; padding: 0 12px;
    background: var(--lc-bg); border-bottom: 1px solid var(--lc-line); box-shadow: 0 1px 10px rgba(16,27,61,.08);
    transition: transform .25s ease;
  }
  .lc-bar.lc-hidden { transform: translateY(-100%); }
  .lc-back { margin-right: 4px; }
  .lc-id { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; justify-content: center; padding: 0 8px; border-left: 1px solid var(--lc-line); }
  .lc-title, .lc-chap, .lc-posm { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lc-title { font-size: 11.5px; line-height: 1.3; color: var(--lc-mut); }
  .lc-chap { font-size: 14px; line-height: 1.35; font-weight: 600; }
  .lc-posm { display: none; font-size: 11.5px; line-height: 1.3; color: var(--lc-mut); font-variant-numeric: tabular-nums; }
  .lc-pos { flex: none; margin: 0 8px; font-size: 12.5px; color: var(--lc-mut); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .lc-aa { font-family: Georgia, "Times New Roman", serif; font-size: 16px; font-weight: 600; letter-spacing: -.02em; }
  .lc-aa[aria-expanded="true"], .lc-contents[aria-expanded="true"] { background: var(--lc-sel); }

  .lc-progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 1001; pointer-events: none; }
  .lc-progress i { display: block; height: 100%; background: var(--lc-accent); transform: scaleX(0); transform-origin: 0 50%; }

  /* fenetre d'affichage */
  .lc-pop {
    position: fixed; top: calc(var(--lc-bar-h) + 6px); right: 12px; z-index: 1002; width: 300px; padding: 14px;
    background: var(--lc-bg); border: 1px solid var(--lc-line); border-radius: 12px; box-shadow: 0 10px 34px rgba(16,27,61,.22);
    visibility: hidden; opacity: 0; transform: translateY(-6px); transition: opacity .15s, transform .15s, visibility .15s;
  }
  .lc-pop.lc-open { visibility: visible; opacity: 1; transform: none; }
  .lc-row + .lc-row { margin-top: 14px; }
  .lc-cap { display: block; margin-bottom: 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--lc-mut); }
  .lc-seg { display: flex; align-items: stretch; gap: 6px; }
  .lc-seg .lc-btn { border: 1px solid var(--lc-line); }
  .lc-sm, .lc-lg { flex: 1; font-weight: 600; }
  .lc-val { flex: 0 0 64px; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; color: var(--lc-mut); }
  .lc-th { flex: 1; flex-direction: column; height: auto; padding: 8px 4px; gap: 6px; font-size: 12.5px; }
  .lc-th i { display: block; width: 26px; height: 26px; border-radius: 50%; border: 1px solid #b9c0cc; }
  .lc-th-light i { background: #fff; } .lc-th-sepia i { background: #f5edd9; border-color: #c9b88f; } .lc-th-dark i { background: #1a1e25; border-color: #596172; }
  .lc-th[aria-pressed="true"] { border-color: var(--lc-accent); box-shadow: inset 0 0 0 1px var(--lc-accent); background: var(--lc-sel); }
  .lc-row-mob { display: none; }
  .lc-row-mob .lc-btn { flex: 1; border: 1px solid var(--lc-line); }

  /* tiroir */
  .lc-scrim { position: fixed; inset: 0; z-index: 1090; background: rgba(10,16,32,.45); opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; }
  .lc-scrim.lc-open { opacity: 1; visibility: visible; }
  .lc-drawer {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 1100; width: min(400px, 100vw); display: flex; flex-direction: column;
    background: var(--lc-bg); border-right: 1px solid var(--lc-line); box-shadow: 8px 0 34px rgba(16,27,61,.25);
    transform: translateX(-102%); visibility: hidden; transition: transform .25s ease, visibility 0s linear .25s;
  }
  .lc-drawer.lc-open { transform: none; visibility: visible; transition: transform .25s ease, visibility 0s; }
  .lc-dhead { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 6px 18px; }
  .lc-dtitle { font-size: 17px; font-weight: 700; color: var(--lc-fg); }
  .lc-dsearch { flex: none; position: relative; margin: 4px 14px 10px; color: var(--lc-mut); }
  .lc-dsearch .lc-ic { position: absolute; left: 10px; top: 10px; width: 18px; height: 18px; pointer-events: none; }
  .lc-input { width: 100%; height: 38px; padding: 0 12px 0 36px; border: 1px solid var(--lc-line); border-radius: 8px; background: transparent; color: var(--lc-fg); -webkit-appearance: none; appearance: none; }
  .lc-input::placeholder { color: var(--lc-mut); opacity: 1; }
  .lc-dlist { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 24px; position: relative; }
  .lc-g { margin-bottom: 6px; }
  .lc-i { display: block; border-radius: 6px; padding: 7px 10px; line-height: 1.35; color: var(--lc-fg); }
  .lc-i:hover { background: var(--lc-hov); }
  .lc-i[hidden], .lc-g[hidden] { display: none; }
  .lc-ch { font-weight: 600; margin-top: 4px; }
  .lc-su { font-size: 13px; padding-left: 24px; color: var(--lc-mut); }
  .lc-cur { background: var(--lc-sel); color: var(--lc-fg); box-shadow: inset 3px 0 0 var(--lc-accent); }
  .lc-su.lc-cur { color: var(--lc-fg); font-weight: 600; }
  .lc-empty { margin: 8px 18px; color: var(--lc-mut); }

  /* retour en haut, reprise de lecture */
  .lc-top {
    position: fixed; right: 20px; bottom: 20px; z-index: 900; width: 44px; height: 44px; padding: 0; display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--lc-line); border-radius: 50%; background: var(--lc-bg); color: var(--lc-fg); cursor: pointer; box-shadow: 0 4px 16px rgba(16,27,61,.25);
    opacity: 0; visibility: hidden; transform: translateY(8px); transition: opacity .2s, transform .2s, visibility .2s;
  }
  .lc-top.lc-show { opacity: 1; visibility: visible; transform: none; }
  .lc-top:hover { background: var(--lc-hov); }
  .lc-toast {
    position: fixed; left: 50%; bottom: 20px; z-index: 950; width: min(440px, calc(100vw - 24px)); padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
    background: var(--lc-bg); border: 1px solid var(--lc-line); border-radius: 12px; box-shadow: 0 10px 34px rgba(16,27,61,.28);
    opacity: 0; visibility: hidden; transform: translate(-50%, 10px); transition: opacity .2s, transform .2s, visibility .2s;
  }
  .lc-toast.lc-show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
  .lc-tmsg { flex: 1 0 100%; font-weight: 600; }
  .lc-tsub { flex: 1 1 0; min-width: 0; color: var(--lc-mut); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lc-tact { display: flex; gap: 6px; margin-left: auto; }
  .lc-tbtn { height: 34px; padding: 0 12px; border: 1px solid var(--lc-line); border-radius: 8px; background: transparent; cursor: pointer; }
  .lc-tbtn:hover { background: var(--lc-hov); }
  .lc-tgo { background: var(--lc-accent); border-color: var(--lc-accent); color: var(--lc-on-accent); font-weight: 600; }
  .lc-tgo:hover { background: var(--lc-accent); filter: brightness(1.08); }

  @media (max-width: 1100px) { .lc-contents .lc-lbl, .lc-posc { display: none; } }
  @media (max-width: 900px) { .lc-back .lc-lbl { display: none; } }
  @media (prefers-reduced-motion: reduce) {
    .lc-bar, .lc-pop, .lc-scrim, .lc-drawer, .lc-top, .lc-toast { transition: none; }
  }
}

@media screen and (max-width: 720px) {
  html { --lc-bar-h: 46px; }
  html.lecteur-actif body { padding-top: calc(var(--lc-bar-h) + 10px); }
  html.lecteur-actif section.chapter {
    max-width: none; min-height: 0; margin-bottom: calc(16px / var(--lc-z));
    padding: calc(28px / var(--lc-z)) calc(20px / var(--lc-z));
  }
  .lc-bar, .lc-bar.lc-hidden { transform: none; padding: 0 6px; gap: 2px; }   /* toujours accessible */
  .lc-title, .lc-pos { display: none; } .lc-posm { display: block; }
  .lc-id { padding: 0 6px; }
  .lc-chap { font-size: 13.5px; }
  .lc-pdf, .lc-print { display: none; }
  .lc-row-mob { display: flex; gap: 6px; }
  .lc-pop { left: 8px; right: 8px; width: auto; }
  .lc-drawer { width: 100vw; border-right: 0; }
  .lc-top { right: 14px; bottom: 14px; }
}
