:root {
  --bg: #111214;
  --accent: #ffffff;
  --btn-bg: rgba(255, 255, 255, 0.08);
  --btn-bg-hover: rgba(255, 255, 255, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

#flipbook-container {
  position: relative;
  width: 100vw;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
  padding-top: 16px;
  padding-bottom: 16px;
  /* overflow reste cache par defaut : centrer (align-items/justify-content) un
     conteneur en overflow:auto cree un vide fantome des que le contenu depasse.
     Le defilement n'est active qu'en zoom actif, voir .is-zoomed ci-dessous. */
  overflow: hidden;
}

#flipbook-container.is-zoomed {
  overflow: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

#flipbook {
  --zoom: 1;
  max-height: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  transform: scale(var(--zoom));
  /* Anime le redimensionnement du bloc (couverture unique -> double page)
     et le zoom, pour eviter tout saut brusque. */
  transition: width 0.5s ease, height 0.5s ease, margin 0.5s ease, transform 0.3s ease;
}

/* Avec showCover, le bloc reserve toujours la largeur d'une double page :
   ces classes recentrent la page unique (couverture/dos) visible a l'ecran. */
#flipbook.shift-left {
  transform: translateX(-25%) scale(var(--zoom));
}

#flipbook.shift-right {
  transform: translateX(25%) scale(var(--zoom));
}

.page {
  position: relative;
  background: #fff;
  overflow: hidden;
}

.page img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.page-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: rgba(255, 255, 255, 0.85);
  background: #1a1b1e;
  font-size: 14px;
  line-height: 1.5;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.offline-banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 16px;
  background: #b3261e;
  color: #fff;
  font-size: 13px;
  text-align: center;
  z-index: 30;
}

/* Barre d'outils unique : navigation, pagination, telechargement, zoom, plein ecran.
   Dans le flux normal, sous le livret, pour ne jamais chevaucher son contenu. */
#toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.03);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.12);
}

.toolbar-btn {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--btn-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, opacity 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.toolbar-btn:hover {
  background: var(--btn-bg-hover);
}

.toolbar-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.toolbar-btn-wide {
  width: auto;
  border-radius: 20px;
  padding: 0 14px;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

#page-indicator {
  min-width: 52px;
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  letter-spacing: 0.05em;
  user-select: none;
}

/* Desktop : taille fixe raisonnable */
@media (min-width: 769px) {
  #flipbook-container {
    padding: 20px 40px;
  }
}

/* Mobile : plein ecran */
@media (max-width: 768px) {
  #flipbook-container {
    padding: 10px 0;
  }

  #toolbar {
    gap: 6px;
    padding: 8px;
  }

  .toolbar-btn {
    width: 34px;
    height: 34px;
  }

  .toolbar-btn-wide span {
    display: none;
  }
}
