/*
 * reader-ui.css — V8.0
 * Styles de l'interface de lecture EPUB : reader screen, zones de nav,
 * TOC overlay, barre de progression, boutons, mobile/desktop adaptations.
 * Requiert base.css chargé en premier.
 */

/* ── Reader screen ───────────────────────────────────────────────────────── */
#readerScreen {
  position: relative;
  width: 100%;
  height: 100%;
  background: #ddd;
  overflow: hidden;
  touch-action: pan-y;
  overscroll-behavior: contain;
}
#viewer {
  width: 100%;
  height: 100%;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}

/* Boutons navigation gauche/droite */
.nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 30;
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  font-size: 16px;
  background: rgba(14,15,17,.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, opacity .15s;
}
.nav-btn:hover { background: var(--accent); }
#prevBtn { left: 10px; }
#nextBtn { right: 10px; }

/* ── Zones de clic/tap navigation (invisible, toute hauteur) ─────────────── */
.nav-zone {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 72px;
  z-index: 9999;
  cursor: pointer;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
}
#prevZone { left: 0; top: 50px; }
#nextZone { right: 0; }
/* Zone centrale — toggle UI (barre infos + TOC) */
#centerZone {
  left: 72px;
  right: 72px;
  width: auto;
  top: 50px;
  touch-action: manipulation;
  cursor: default;
  z-index: 10001;
}

/* TOC ouverte → neutraliser toutes les zones de nav pour laisser défiler le panel */
body.toc-open .nav-zone {
  pointer-events: none;
}

/* ── Overlay de synchronisation (recalage cross-device) ─────────────────── */
#syncOverlay {
  position: fixed;
  inset: 0;
  background: rgba(14,15,17,.72);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 30;
  backdrop-filter: blur(3px);
  pointer-events: none;
}
#syncOverlay.hidden { display: none !important; }

/* ── Barre info lecture en haut (% + chapitre) ───────────────────────────── */
#readerTopInfo {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10002;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 16px;
  font-size: 11px;
  font-family: var(--font-mono, monospace);
  color: rgba(60,100,180,.85);
  pointer-events: none;
  user-select: none;
  letter-spacing: .02em;
  transition: opacity .2s, transform .2s;
}
.reader-top-sep { opacity: .3; }

/* ── Bouton TOC (haut gauche) ────────────────────────────────────────────── */
#tocToggleBtn {
  display: none; /* affiché uniquement en reading-mode (ci-dessous) */
  position: fixed;
  top: 6px;
  left: 0;
  z-index: 10003;
  background: rgba(255,255,255,.08);
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  width: 34px;
  height: 34px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, opacity .2s;
  pointer-events: auto;
}
#tocToggleBtn:hover { background: rgba(255,255,255,.16); color: var(--text); }
body.reading-mode #tocToggleBtn { display: flex; }

/* ── Bouton retour fiche (haut droit) ────────────────────────────────────── */
#readerCloseBtn {
  display: none;
  position: fixed;
  top: 6px;
  right: 8px;
  z-index: 10010;
  background: rgba(255,255,255,.08);
  border: none;
  border-radius: 6px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  width: 34px;
  height: 34px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s, opacity .2s;
  pointer-events: auto;
}
#readerCloseBtn:hover { background: rgba(255,255,255,.16); color: var(--text); }

/* ── readerCloseBtn visible aussi sur la fiche couverture ──────────────────
   En cover-mode, la topbar est visible (~44px) + coverBackBar (44px).
   On positionne le bouton centré verticalement dans la coverBackBar.
   top = hauteur topbar (44px) + (44px backbar - 34px bouton) / 2 = 49px
   Sur mobile (max-width:960px) la topbar est cachée → top: 5px
── */
body.cover-mode #readerCloseBtn {
  display: flex;
  top: 49px;
  opacity: 1;
  pointer-events: auto;
}

/* ── Comportement mobile (≤960px) : header masqué par défaut ─────────────
   Sur mobile en mode lecture, topInfo + TOC btn + close btn sont invisibles.
   Ils apparaissent uniquement quand body a la classe reader-ui-visible
   (déclenché par tap au centre de l'écran).
   Sur desktop (>960px) : toujours visibles, sauf quand TOC est ouverte.
   ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  body.reading-mode #readerTopInfo {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
  }
  body.reading-mode #tocToggleBtn {
    opacity: 0;
    pointer-events: none;
  }
  body.cover-mode #readerCloseBtn { top: 5px; }
  body.reading-mode #readerCloseBtn {
    display: flex;
    top: 6px;
    opacity: 0;
    pointer-events: none;
  }
  /* Visible après tap centre */
  body.reading-mode.reader-ui-visible #readerTopInfo {
    opacity: 1;
    pointer-events: none;
    transform: translateY(0);
    /* Fond couvrant toute la top bar (étendu avec box-shadow pour couvrir les boutons latéraux) */
    background: rgba(10, 11, 14, 0.88);
    box-shadow: 0 23px 0 0 rgba(10, 11, 14, 0.88);
  }
  body.reading-mode.reader-ui-visible #tocToggleBtn {
    opacity: 1;
    pointer-events: auto;
  }
  body.reading-mode.reader-ui-visible #readerCloseBtn {
    opacity: 1;
    pointer-events: auto;
  }
}
@media (min-width: 961px) {
  /* PC : header toujours visible */
  body.reading-mode #readerTopInfo  { opacity: 1; pointer-events: none; }
  body.reading-mode #tocToggleBtn   { opacity: 1; pointer-events: auto; }
  body.reading-mode #readerCloseBtn {
    display: flex;
    top: 6px;
    opacity: 1;
    pointer-events: auto;
  }
  /* TOC ouverte sur PC → masquer la top bar pour éviter superposition */
  body.reading-mode.toc-open #readerTopInfo  { opacity: 0; pointer-events: none; }
  body.reading-mode.toc-open #tocToggleBtn   { opacity: 0; pointer-events: none; }
  body.reading-mode.toc-open #readerCloseBtn { opacity: 0; pointer-events: none; }
}

/* ── TOC Overlay (panneau glissant, mobile + desktop) ────────────────────── */
#tocOverlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  pointer-events: none;
}
#tocOverlay:not(.hidden) { pointer-events: auto; }

/* Backdrop : déclenche fermeture au clic, commence après le panel */
#tocOverlayBackdrop {
  position: fixed;
  top: 0;
  left: min(320px, 85vw); /* commence exactement après le panel */
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,.55);
  opacity: 0;
  transition: opacity .22s ease;
  cursor: pointer;
}
#tocOverlay:not(.hidden) #tocOverlayBackdrop { opacity: 1; }

/* Panel TOC (glisse depuis la gauche) */
#tocOverlayPanel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 85vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform .24s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,.35);
  pointer-events: auto;
  touch-action: pan-y;
}
#tocOverlay:not(.hidden) #tocOverlayPanel { transform: translateX(0); }

#tocOverlayHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#tocOverlayTitle {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
#tocOverlayClose {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: background .12s, color .12s;
}
#tocOverlayClose:hover { background: var(--surface2); color: var(--text); }

/* Liste des entrées TOC */
#tocOverlayList {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  padding: 10px 0;
  overscroll-behavior: contain;
}
#tocOverlayList a {
  display: block;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.5;
  padding: 7px 18px;
  border-radius: 0;
  transition: background .12s;
  border-left: 3px solid transparent;
}
#tocOverlayList a:hover { background: var(--surface2); }
#tocOverlayList a.toc-active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(91,142,240,.08);
  font-weight: 500;
}
/* Indentation niveaux TOC */
#tocOverlayList a.toc-indent-1 { padding-left: 32px; font-size: 12px; }
#tocOverlayList a.toc-indent-2 { padding-left: 46px; font-size: 11px; }

/* ── Curseur de progression vertical (à droite de l'écran) ──────────────── */
#readerProgressCursor {
  position: fixed;
  right: 0;
  left: auto;
  top: 0;
  width: 4px;
  height: 48px;
  border-radius: 3px 0 0 3px;
  z-index: 25;
  pointer-events: none;
  user-select: none;
  transition: top .4s ease, background-color .6s ease;
  background-color: #22c55e; /* vert → rouge selon avancement */
  box-shadow: -1px 0 6px rgba(0,0,0,.18);
}
