/* Books: the "Reliée" galleries and the PDF readers (Goupil: editor/blocks/flipbook.js, editor/blocks/pdf-reader.js).
     <figure class="gallery flipbook"><ul class="gallery-grid"><li class="gallery-item">…   (book-no-cover: no cover)
     <figure class="flipbook pdf-reader"><a class="pdf-reader-file" href="….pdf">Title</a>  (pdf-download: a download link)
   src/assets/flipbook.js turns them into a book whose pages turn (.flipbook-ready). Without it (and in Goupil's
   preview), a gallery shows its images as double pages one under the other, and a PDF reader a link to the file.
   Loaded only on the pages that have one (layouts/base.njk). */

/* ---- Without the script: double pages ---------------------------------------------------------------------- */
.gallery.flipbook {
  display: block;
}
.gallery.flipbook .gallery-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  row-gap: 1.5rem;
}
.gallery.flipbook .gallery-grid > .gallery-item {
  display: block;
  width: auto;
  margin: 0;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}
/* The cover, alone on the right, as a closed book. */
.gallery.flipbook:not(.book-no-cover):not(.book-single) .gallery-grid > .gallery-item:first-child {
  grid-column: 2;
}
/* One page at a time ("book-single"): the images one under the other, as wide as the block. */
.gallery.flipbook.book-single .gallery-grid {
  grid-template-columns: 1fr;
}
.gallery.flipbook.book-single .gallery-item::after {
  display: none;
}
.gallery.flipbook .gallery-item figure {
  display: block;
  height: auto;
}
.gallery.flipbook .gallery-item img,
.gallery.flipbook .gallery-item video {
  display: block;
  width: 100%;
  height: auto;
}
.gallery.flipbook .gallery-item figcaption {
  display: none;
}
/* The fold in the middle of a double page: the left pages are the even ones (the odd ones without a cover). */
.gallery.flipbook .gallery-item::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 12%;
  pointer-events: none;
}
.gallery.flipbook:not(.book-no-cover) .gallery-item:nth-child(2n)::after,
.gallery.flipbook.book-no-cover .gallery-item:nth-child(2n + 1)::after {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.16), transparent);
}
.gallery.flipbook:not(.book-no-cover) .gallery-item:nth-child(2n + 1)::after,
.gallery.flipbook.book-no-cover .gallery-item:nth-child(2n)::after {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.16), transparent);
}

.pdf-reader {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}
.pdf-reader-file {
  display: inline-block;
  padding: 2.5rem 2rem 1.25rem;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 0.5rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  background: #fff;
}
.pdf-reader-file::before {
  content: "PDF";
  display: block;
  width: 3rem;
  margin: 0 auto 1rem;
  padding: 1.1rem 0;
  border-radius: 0.25rem;
  background: #18606b;
  color: #fff;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
}

/* ---- With the script: a book ---------------------------------------------------------------------------- */
.gallery.flipbook.flipbook-ready .gallery-grid,
.flipbook-ready .pdf-reader-file {
  display: none;
}
.flipbook-viewer {
  position: relative;
  -webkit-user-select: none;
  user-select: none;
}
/* Two pages side by side, with the proportions of the first one, as high as the window at most. */
.flipbook-stage {
  --flipbook-ratio: 0.7071;
  position: relative;
  width: min(100%, calc(78vh * 2 * var(--flipbook-ratio)));
  margin: 0 auto;
  aspect-ratio: calc(2 * var(--flipbook-ratio));
  perspective: 2600px;
  touch-action: pan-y;
  outline: none;
}
/* Full width ("width-full"): the book takes all the height of the window it can, its buttons still in view. */
.flipbook.width-full .flipbook-stage {
  width: min(calc(100% - 2rem), calc((100vh - 6rem) * 2 * var(--flipbook-ratio)));
  width: min(calc(100% - 2rem), calc((100svh - 6rem) * 2 * var(--flipbook-ratio)));
}
/* One page at a time ("book-single"): the stage has the proportions of one page, as wide as the block (a
   presentation), as high as the window at most; the page slides to the next one (flipbook.js), hidden past the sides. */
.book-single .flipbook-stage {
  width: min(100%, calc(78vh * var(--flipbook-ratio)));
  aspect-ratio: var(--flipbook-ratio);
  overflow: hidden;
}
.flipbook.width-full.book-single .flipbook-stage {
  width: min(calc(100% - 2rem), calc((100vh - 6rem) * var(--flipbook-ratio)));
  width: min(calc(100% - 2rem), calc((100svh - 6rem) * var(--flipbook-ratio)));
}
.book-single .flipbook-book.only-right {
  transform: none;
}
.book-single .flipbook-side.right {
  width: 100%;
}
.book-single .flipbook-side.left,
.book-single .flipbook-side::after {
  display: none;
}

/* The links of a PDF page (flipbook.js): invisible areas over the page, as in the PDF. */
.flipbook-links {
  position: absolute;
  z-index: 1;
}
.flipbook-links a {
  position: absolute;
  cursor: pointer;
}
.flipbook-links a:hover,
.flipbook-links a:focus-visible {
  background: rgba(24, 96, 107, 0.15);
  outline: 1px solid rgba(24, 96, 107, 0.5);
}
.flipbook-face .flipbook-links {
  display: none;
}

.flipbook-stage:focus-visible {
  outline: 2px solid #18606b;
  outline-offset: 6px;
}
.flipbook-book {
  position: absolute;
  inset: 0;
  transition: transform 0.7s ease;
}
/* A page alone (the cover, the last page) is in the middle. */
.flipbook-book.only-right {
  transform: translateX(-25%);
}
.flipbook-book.only-left {
  transform: translateX(25%);
}
.flipbook-side,
.flipbook-face {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  overflow: hidden;
  background: #fff;
}
.flipbook-side {
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.22);
}
.flipbook-side.left {
  left: 0;
  cursor: w-resize;
}
.flipbook-side.right {
  right: 0;
  cursor: e-resize;
}
.flipbook-side.blank {
  visibility: hidden;
}
.flipbook-side img,
.flipbook-side video,
.flipbook-face img,
.flipbook-face video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.flipbook-side picture,
.flipbook-face picture {
  display: contents;
}
/* The fold in the middle. */
.flipbook-side::after,
.flipbook-face::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 14%;
  pointer-events: none;
}
.flipbook-side.left::after,
.flipbook-face.back::after {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.18), transparent);
}
.flipbook-side.right::after,
.flipbook-face.front::after {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.18), transparent);
}
.flipbook-leaf.backward .flipbook-face.front::after {
  left: auto;
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.18), transparent);
}
.flipbook-leaf.backward .flipbook-face.back::after {
  right: auto;
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.18), transparent);
}
/* The corner of the right page, slightly lifted: it can be turned. */
.flipbook-corner {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 2.2rem;
  height: 2.2rem;
  background: linear-gradient(135deg, transparent 50%, #e9e9e9 50%, #fafafa 70%, #d0d0d0);
  box-shadow: -2px -2px 5px rgba(0, 0, 0, 0.12);
  border-top-left-radius: 0.3rem;
  pointer-events: none;
  transform-origin: 100% 100%;
  animation: flipbook-peek 2.4s ease-in-out 1s 2;
}
@keyframes flipbook-peek {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.8);
  }
}

/* The page that turns: its front, then its back. */
.flipbook-leaf {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  z-index: 2;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.45, 0.05, 0.3, 1);
}
.flipbook-leaf.forward {
  left: 50%;
  transform-origin: left center;
}
.flipbook-leaf.backward {
  left: 0;
  transform-origin: right center;
}
/* One page at a time ("book-single", flipbook.js turnSingle): the whole page turns over from its left edge. */
.flipbook-leaf.single {
  left: 0;
  width: 100%;
  transform-origin: left center;
}
/* A double page sliding ("book-slide"): what goes past the sides is hidden while it slides. */
.flipbook-stage.is-sliding {
  overflow: hidden;
}
.flipbook-leaf.forward.turned {
  transform: rotateY(-180deg);
}
.flipbook-leaf.backward.turned {
  transform: rotateY(180deg);
}
.flipbook-face {
  width: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  box-shadow: 0 3px 18px rgba(0, 0, 0, 0.25);
}
.flipbook-face.back {
  transform: rotateY(180deg);
}
.flipbook-face.blank {
  background: transparent;
  box-shadow: none;
}
/* A shadow that darkens the page while it turns. */
.flipbook-face::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease-in;
}
.flipbook-leaf.turned .flipbook-face.front::before {
  opacity: 0.25;
}

/* The buttons (beginning, previous, next, end), the page number and how to leaf through. The buttons are the site's
   round outlined icons, as in the image viewer (lightbox.css): the text's colour, lavender on hover. */
.flipbook-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}
.flipbook-nav button {
  position: relative;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
  box-shadow: none;
  transition: color 0.2s;
}
.flipbook-nav button::before {
  content: "";
  position: absolute;
  inset: 0;
  background-color: currentColor;
  -webkit-mask: url("images/btn-next.svg") center / contain no-repeat;
  mask: url("images/btn-next.svg") center / contain no-repeat;
}
.flipbook-nav .flipbook-previous::before {
  -webkit-mask-image: url("images/btn-prev.svg");
  mask-image: url("images/btn-prev.svg");
}
.flipbook-nav .flipbook-first::before {
  -webkit-mask-image: url("images/btn-first.svg");
  mask-image: url("images/btn-first.svg");
}
.flipbook-nav .flipbook-last::before {
  -webkit-mask-image: url("images/btn-last.svg");
  mask-image: url("images/btn-last.svg");
}
.flipbook-nav button:hover:not(:disabled),
.flipbook-nav button:focus-visible {
  background: none;
  color: #cbb6e7; /* lavande */
}
.flipbook-nav button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}
.flipbook-nav button:disabled {
  opacity: 0.3;
  cursor: default;
}
.flipbook-count {
  min-width: 9em;
  font-size: 0.85em;
  font-variation-settings: 'wdth' 100, 'XOPQ' 73, 'YOPQ' 72; /* stroke of the pictograms (style.css, Typography) */
  text-align: center;
}
.flipbook-hint {
  margin: 0.4rem 0 0;
  font-size: 0.8em;
  font-variation-settings: 'wdth' 100, 'XOPQ' 76, 'YOPQ' 75;
  text-align: center;
  opacity: 0.7;
  transition: opacity 0.4s;
}
.flipbook-hint.done {
  opacity: 0;
}
/* While PDF.js reads the file, its link is shown, faded. */
.flipbook-loading .pdf-reader-file {
  opacity: 0.6;
  cursor: progress;
}
.flipbook-download {
  margin: 0.6rem 0 0;
  font-size: 0.85em;
  text-align: center;
}
@media (prefers-reduced-motion: reduce) {
  .flipbook-book,
  .flipbook-leaf {
    transition: none;
  }
  .flipbook-corner {
    animation: none;
  }
}
