.rotopol-book {
  --book-page-ratio: 1.41421356; /* portrait page: height / width, ~A-series */
  --book-page-bg: #fff;
  --book-shadow: rgba(0, 0, 0, .18);
  --book-control: #262626;
  --book-control-hover: #444;

  width: 100%;
  max-width: 1240px;
  margin: 1.25rem auto 0;
}

.rotopol-book__header {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: .6rem;
  font-size: .95rem;
}

.rotopol-book__page-label {
  font-weight: 600;
}

.rotopol-book__page-status {
  color: #6b6b6b;
  min-width: 6rem;
  text-align: center;
}

/*
 * The viewer itself is exactly the height of a two-page portrait spread:
 * width / (2 / 1.414) = width / 1.414.
 * No additional top/bottom frame is created.
 */
.rotopol-book__scene {
  position: relative;
  width: 100%;
  aspect-ratio: 1.41421356 / 1;
  overflow: visible;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.rotopol-book__book {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  perspective: 2400px;
  transform-style: preserve-3d;
}

.rotopol-book__base,
.rotopol-book__cover,
.rotopol-book__turn {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  transform-style: preserve-3d;
}

.rotopol-book__base {
  display: flex;
  z-index: 1;
  background: var(--book-page-bg);
  box-shadow: 0 8px 24px var(--book-shadow);
  visibility: hidden; /* hidden while showing cover */
}

.rotopol-book__base.is-visible {
  visibility: visible;
}

.rotopol-book__page {
  position: relative;
  width: 50%;
  height: 100%;
  overflow: hidden;
  background: var(--book-page-bg);
}

.rotopol-book__page--left {
  border-right: 1px solid #d6d6d6;
}

.rotopol-book__page--right {
  border-left: 1px solid #d6d6d6;
}

.rotopol-book__page::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18%;
  pointer-events: none;
  opacity: .14;
}

.rotopol-book__page--left::after {
  right: 0;
  background: linear-gradient(to left, rgba(0,0,0,.24), transparent);
}

.rotopol-book__page--right::after {
  left: 0;
  background: linear-gradient(to right, rgba(0,0,0,.24), transparent);
}

.rotopol-book__page img,
.rotopol-book__cover img,
.rotopol-book__turn img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
  user-select: none;
  -webkit-user-drag: none;
}

.rotopol-book__cover {
  z-index: 10;
  width: 50%;
  transform-origin: left center;
  background: #fff;
  box-shadow: 0 8px 24px var(--book-shadow);
  overflow: hidden;
  transition: transform .78s cubic-bezier(.2, .75, .2, 1);
}

.rotopol-book__cover.is-open {
  transform: translate(-100%, -50%) rotateY(-180deg);
  visibility: hidden;
  transition:
    transform .78s cubic-bezier(.2, .75, .2, 1),
    visibility 0s linear .8s;
}

.rotopol-book__turn {
  z-index: 20;
  width: 50%;
  transform-origin: left center;
  visibility: hidden;
  pointer-events: none;
  background: transparent;
}

.rotopol-book__turn.is-active {
  visibility: visible;
}

.rotopol-book__turn-face {
  position: absolute;
  inset: 0;
  background: #fff;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 4px 0 12px rgba(0, 0, 0, .12);
}

.rotopol-book__turn-face--back {
  transform: rotateY(180deg);
}

.rotopol-book__turn.is-forward {
  animation: rotopol-turn-forward .78s cubic-bezier(.2, .75, .2, 1) forwards;
}

.rotopol-book__turn.is-backward {
  transform-origin: right center;
  animation: rotopol-turn-backward .78s cubic-bezier(.2, .75, .2, 1) forwards;
}

@keyframes rotopol-turn-forward {
  from { transform: translateY(-50%) rotateY(0deg); }
  to   { transform: translateY(-50%) rotateY(-180deg); }
}

@keyframes rotopol-turn-backward {
  from { transform: translateX(-100%) translateY(-50%) rotateY(0deg); }
  to   { transform: translateX(-100%) translateY(-50%) rotateY(180deg); }
}

/* Controls sit just inside the left/right book edge. */
.rotopol-book__nav {
  position: absolute;
  z-index: 30;
  top: 50%;
  width: 36px;
  height: 36px;
  margin-top: -18px;
  border: 0;
  border-radius: 50%;
  background: rgba(38,38,38,.86);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.12);
  transition: opacity .15s ease, background-color .15s ease, transform .15s ease;
}

.rotopol-book__nav--prev {
  left: 1.2%;
}

.rotopol-book__nav--next {
  right: 1.2%;
}

.rotopol-book__nav:hover:not(:disabled) {
  background: var(--book-control-hover);
  transform: scale(1.04);
}

.rotopol-book__nav:disabled {
  opacity: .18;
  cursor: default;
}

.rotopol-book__loading {
  position: absolute;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,.92);
  color: #333;
}

@media (max-width: 767px) {
  .rotopol-book {
    max-width: none;
  }

  .rotopol-book__nav {
    width: 32px;
    height: 32px;
    margin-top: -16px;
    font-size: 1.35rem;
  }

  .rotopol-book__nav--prev { left: .5%; }
  .rotopol-book__nav--next { right: .5%; }
}

@media (prefers-reduced-motion: reduce) {
  .rotopol-book__cover,
  .rotopol-book__turn {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}
