/* ==========================================================================
   Lecteur des livres en ligne — bribes-en-ligne.fr
   Couleurs et typographie reprises du catalogue /flipbooks/.
   La mise en page n'est appliquée qu'une fois le lecteur lancé (classe
   .lecteur posée par lecteur.js) : sans JavaScript, la page reste une simple
   suite d'images lisible (bloc <noscript> de index.html).
   ========================================================================== */

:root {
  --bg: #f7f7f7;
  --ink: #333;
  --muted: #6b6b6b;
  --line: #ddd;
  --accent: #8b0000;
  --scene: #e4e4e4;
  --barre: 52px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Trebuchet MS", Helvetica, Arial, sans-serif;
}

/* --- Sans JavaScript -------------------------------------------------------- */
.sans-js { max-width: 900px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.sans-js h1 { color: var(--accent); font-variant: small-caps; margin: .2rem 0 1rem; }
.sans-js img { display: block; width: 100%; height: auto; margin: 0 0 1.5rem;
               background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.sans-js a { color: var(--accent); }

/* --- Ossature du lecteur ---------------------------------------------------- */
html.lecteur, html.lecteur body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
html.lecteur body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

.haut, .bas {
  flex: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  height: var(--barre);
  padding: 0 .5rem;
  background: var(--bg);
}
.haut { border-bottom: 1px solid var(--line); }
.bas  { border-top: 1px solid var(--line); justify-content: center; gap: .75rem; }

.retour {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: .15rem;
  min-height: 44px;
  padding: 0 .6rem 0 .25rem;
  color: var(--ink);
  font-size: .8rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .08em;
  text-decoration: none;
  border-radius: 6px;
}
.retour:hover { color: var(--accent); }

.titre {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: bold;
  font-variant: small-caps;
  letter-spacing: .02em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.outils { flex: none; display: flex; gap: .25rem; }

/* Boutons à icône : 44 px, la taille minimale confortable au doigt. */
.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
}
.bouton:hover:not(:disabled) { color: var(--accent); background: rgba(0,0,0,.05); }
.bouton:disabled { opacity: .3; cursor: default; }
.bouton svg, .retour svg, .fleche svg {
  width: 24px; height: 24px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

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

/* --- Scène et livre ----------------------------------------------------------- */
.scene {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 18px 76px;
  background: radial-gradient(ellipse at center, #f1f1f1 0%, var(--scene) 75%);
}

/* StPageFlip pose des tailles minimales en style en ligne : on les neutralise,
   c'est lecteur.js qui décide du nombre de pages affichées. */
#livre {
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
}
#livre .stf__wrapper {
  width: 100%;
  height: 100%;
  padding-bottom: 0 !important;
}

.page {
  background: #fff;
  overflow: hidden;
}
.page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
/* Ombre du pli entre deux pages en vis-à-vis (StPageFlip marque --left / --right). */
.--landscape .page::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.--landscape .page.--left::before {
  background: linear-gradient(to left, rgba(0,0,0,.13), rgba(0,0,0,.04) 2.5%, transparent 7%);
}
.--landscape .page.--right::before {
  background: linear-gradient(to right, rgba(0,0,0,.13), rgba(0,0,0,.04) 2.5%, transparent 7%);
}

/* Petit indicateur de chargement tant que l'image de la page n'est pas arrivée. */
.page:not(.prete)::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 28px; height: 28px;
  margin: -14px 0 0 -14px;
  border: 3px solid #e2e2e2;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: tourne .9s linear infinite;
}
.page.erreur::after {
  content: "Page indisponible";
  width: auto; height: auto; margin: 0;
  transform: translate(-50%, -50%);
  border: 0;
  animation: none;
  color: var(--muted);
  font-size: .9rem;
  white-space: nowrap;
}
@keyframes tourne { to { transform: rotate(360deg); } }

.fleche {
  position: absolute;
  top: 50%;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 112px;
  margin-top: -56px;
  padding: 0;
  color: #777;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.fleche svg { width: 40px; height: 40px; stroke-width: 1.4; }
.fleche:hover:not(:disabled) { color: var(--accent); background: rgba(255,255,255,.55); }
.fleche:disabled { opacity: 0; pointer-events: none; }
.fleche.prec { left: 10px; }
.fleche.suiv { right: 10px; }

/* --- Barre du bas : curseur et numéro de page ------------------------------- */
.curseur {
  flex: 1;
  max-width: 560px;
  min-width: 0;
  height: 44px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.compteur {
  flex: none;
  min-width: 7.5ch;
  color: var(--muted);
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

/* --- Zoom (loupe) ------------------------------------------------------------- */
.loupe {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow: hidden;
  background: rgba(24, 24, 24, .96);
  touch-action: none;
  cursor: grab;
  -webkit-user-select: none;
  user-select: none;
}
.loupe.saisie { cursor: grabbing; }
.loupe-contenu {
  position: absolute;
  left: 0; top: 0;
  display: flex;
  transform-origin: 0 0;
}
.loupe-contenu img {
  display: block;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  object-fit: contain;
  background: #fff;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.loupe-barre {
  position: absolute;
  top: 10px; right: 10px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0,0,0,.55);
  border-radius: 10px;
}
.loupe .bouton { color: #eee; }
.loupe .bouton:hover:not(:disabled) { color: #fff; background: rgba(255,255,255,.12); }
.loupe-aide {
  position: absolute;
  left: 50%; bottom: 18px;
  max-width: calc(100% - 32px);
  transform: translateX(-50%);
  padding: .45rem .9rem;
  color: #eee;
  background: rgba(0,0,0,.6);
  border-radius: 999px;
  font-size: .85rem;
  text-align: center;
  pointer-events: none;
  transition: opacity .6s ease;
}
.loupe-aide.cachee { opacity: 0; }

/* --- Petits écrans ------------------------------------------------------------ */
@media (max-width: 700px) {
  .scene { padding: 10px; }
  .fleche { display: none; }
  .titre { font-size: 1rem; text-align: left; }
  .retour span { display: none; }
  .bas { gap: .25rem; }
}

@media (prefers-reduced-motion: reduce) {
  .page:not(.prete)::after { animation-duration: 2.5s; }
  .loupe-aide { transition: none; }
}
