.folio {
  overflow: clip;
  min-height: 100svh;
  padding: var(--header-safe-space) clamp(16px, 3vw, 36px) 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.folio-book {
  position: relative;
  perspective: 1800px;
  width: min(100%, calc((100svh - 200px) * 1.4142));
}

.folio-pages {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  aspect-ratio: 1.4142;
}

.folio-pages img {
  width: 50%;
  height: 100%;
  object-fit: contain;
  box-shadow: 0 0 14px rgb(0 0 0 / .10), 0 0 2px rgb(0 0 0 / .08);
}

.folio-pages > img[data-side="right"]:only-child { margin-left: auto; }
.folio-pages > img[data-side="left"]:only-child { margin-right: auto; }

#folio-pages:has(> img:nth-of-type(2))::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 46%;
  width: 8%;
  background: linear-gradient(90deg, transparent, rgb(0 0 0 / .035) 35%, rgb(0 0 0 / .11) 50%, rgb(0 0 0 / .045) 65%, transparent);
  pointer-events: none;
}

.folio-turn-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transform-style: preserve-3d;
}

.folio-leaf {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  transform-style: preserve-3d;
  will-change: transform;
}

.folio-leaf-next { left: 50%; transform-origin: left center; }
.folio-leaf-previous { left: 0; transform-origin: right center; }

.folio-leaf-front,
.folio-leaf-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: white;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 0 18px rgb(0 0 0 / .08);
}

.folio-leaf-front { transform: translateZ(1px); }
.folio-leaf-back { transform: rotateY(180deg) translateZ(1px); }

.folio-leaf img {
  width: 100%;
  height: 100%;
  box-shadow: none;
}

.folio-leaf-front::after,
.folio-leaf-back::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(var(--shade-direction, 90deg), rgb(0 0 0 / .18), rgb(0 0 0 / .045) 28%, transparent 65%);
  pointer-events: none;
  animation: folio-page-shade 620ms ease-in-out both;
}

.folio-leaf-back::after { --shade-direction: 270deg; }
.folio-leaf-previous .folio-leaf-front::after { --shade-direction: 270deg; }
.folio-leaf-previous .folio-leaf-back::after { --shade-direction: 90deg; }

@keyframes folio-page-shade {
  0%, 100% { opacity: 0; }
  45%, 60% { opacity: 1; }
}

.folio button {
  font: inherit;
  color: inherit;
  -webkit-text-stroke: inherit;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.folio-turn {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  padding: 0;
}

.folio-turn-left { left: 0; }
.folio-turn-right { right: 0; }

.folio-controls {
  display: flex;
  width: min(100%, 540px);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.folio-controls button { padding: 10px 0; }
.folio button:disabled { opacity: .3; cursor: default; }
.folio button:focus-visible { outline: 1px solid currentColor; outline-offset: 4px; }
#folio-position { text-align: center; }
#folio-error { margin: 0; text-align: center; }

.folio-download {
  position: fixed;
  left: clamp(16px, 3vw, 36px);
  bottom: 16px;
  z-index: 20;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.folio-download::before { content: none; }

@media (max-width: 600px) {
  .folio { padding-right: 12px; padding-left: 12px; }
  .folio-controls { font-size: 14px; }
}
