* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: #ffffff;
  color: #111111;
  font-family: Arial, sans-serif;
}

a,
button {
  font: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.library-page {
  padding: 24px;
}

.edition-list {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.edition-link {
  width: 180px;
  color: inherit;
  text-decoration: none;
}

.edition-link img {
  width: 100%;
  height: auto;
  border: 1px solid #cccccc;
}

.edition-title {
  margin-top: 8px;
  font-size: 14px;
}

.message {
  margin: 16px 0 0;
  font-size: 14px;
}

.book-page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

.book-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid #dddddd;
}

.book-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  line-height: 1.28;
}

.book-title .book-title__line {
  display: block;
  line-height: 1.28;
}

/* Un peu d’air entre les deux lignes (sans revenir au 1.4 initial) */
.book-title .book-title__line + br + .book-title__line {
  margin-top: 0.12em;
}

.book-title br {
  display: none;
}

.book-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.book-button {
  display: inline-block;
  padding: 8px 12px;
  border: 1px solid #cccccc;
  background: #ffffff;
  color: #111111;
  text-decoration: none;
  cursor: pointer;
}

.book-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.page-label {
  min-width: 110px;
  text-align: center;
  font-size: 14px;
}

.book-content {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.book-content > .message {
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
}

.book-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 400;
  max-width: min(92vw, 22rem);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid #e3e3e3;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  text-align: center;
}

/* La classe ci-dessus gagne sur la règle UA de [hidden] : sans ceci, hidden="" ne masque pas le loader. */
.book-loading[hidden] {
  display: none !important;
}

.book-loading__spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #d8d8d8;
  border-top-color: #111111;
  animation: book-spin 0.85s linear infinite;
  flex: 0 0 auto;
}

.book-loading__text {
  text-wrap: balance;
  animation: book-pulse 1.4s ease-in-out infinite;
}

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

@keyframes book-pulse {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

.book-host,
.book-root,
.image-fallback {
  width: 100%;
  height: 100%;
}

.book-host,
.image-fallback {
  margin: 0 auto;
  overflow: visible;
  box-sizing: border-box;
  flex-shrink: 0;
}

.book-root {
  display: block;
}

.image-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
}

.fallback-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.stf__parent {
  width: 100%;
  height: 100%;
}

.stf__wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  box-sizing: border-box;
}

/* Écrans larges : bandeau à gauche, zone livre sans marge verticale */
@media (min-width: 901px) {
  .book-page {
    flex-direction: row;
    align-items: stretch;
  }

  .book-bar {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 14px;
    width: min(220px, 20vw);
    min-width: 168px;
    max-width: 260px;
    flex-shrink: 0;
    border-bottom: none;
    border-right: 1px solid #dddddd;
    padding: 14px 12px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .book-title {
    flex: 0 0 auto;
    width: 100%;
    text-align: center;
    font-size: 15px;
    line-height: 1.28;
    word-break: normal;
    overflow-wrap: break-word;
    hyphens: none;
  }

  .book-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 10px;
    margin-top: auto;
  }

  .book-bar .book-button {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  .page-label {
    min-width: 0;
    padding: 4px 0;
  }

  .book-content {
    padding: 0 10px;
    min-width: 0;
  }

  .book-content > .message {
    margin: 6px 0 4px;
  }
}

@media (max-width: 900px) {
  .library-page {
    padding: 16px;
  }

  .edition-list {
    gap: 16px;
  }

  .edition-link {
    width: calc(50vw - 24px);
    max-width: 180px;
  }

  .book-page {
    min-height: 100vh;
    min-height: 100dvh;
  }

  .book-bar {
    flex-shrink: 0;
    flex-wrap: wrap;
  }

  .book-title {
    order: -1;
    width: 100%;
    text-align: left;
  }

  .book-actions {
    width: 100%;
    justify-content: space-between;
  }

  /* Zone livre : bord gauche aligné écran (pas de padding gauche), max largeur = viewport ; zoom pincer + scroll H/V */
  .book-page {
    touch-action: auto;
  }

  .book-content {
    width: 100%;
    align-items: flex-start;
    justify-content: flex-start;
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    padding-left: 0;
    gap: 8px;
    touch-action: auto;
    overflow: auto;
    overflow-x: auto;
    overflow-y: auto;
  }

  .book-content > .message {
    flex-shrink: 0;
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: 0;
    box-sizing: border-box;
  }

  .book-host,
  .image-fallback {
    margin-left: 0;
    margin-right: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .book-host,
  .book-root,
  .image-fallback {
    height: auto;
    min-height: 0;
  }

  /* StPageFlip : laisser le pinch-zoom / scroll au navigateur sur mobile */
  .book-host .stf__parent,
  .book-host .stf__wrapper,
  .book-host .stf__block,
  .book-host .stf__canvas,
  .book-host canvas {
    touch-action: auto !important;
  }

  .fallback-image {
    width: 100%;
    height: auto;
    max-width: none;
    max-height: none;
    object-fit: contain;
  }
}
