.rf {
  position: relative;
  width: 540px;
  height: 540px;
  overflow: hidden;
  background: #dde1e4;
  color: #17181c;
  font-family: "Bodoni Moda", serif;
  user-select: none;
  touch-action: none;
  --paper: #f6f1e3;
  --ink: #17181c;
  --spot: #2438b8;
}

.rf * { box-sizing: border-box; }

/* The book lies open on the ground, seen from the front at 21 degrees. */
.rf-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 540px;
  height: 450px;
  perspective: 2200px;
  perspective-origin: 270px 255px;
  pointer-events: none;
}

.rf-book {
  position: absolute;
  left: 45px;
  top: 99px;
  width: 450px;
  height: 312px;
  transform-style: preserve-3d;
  transform: rotateX(21deg);
}

/* Laid out at twice the size and scaled back, so the pages are drawn at full
   resolution under the perspective. */
.rf-x2 {
  position: absolute;
  left: 0;
  top: 0;
  width: 450px;
  height: 312px;
  zoom: 2;
  transform-style: preserve-3d;
  transform-origin: 0 0;
  transform: scale3d(0.5, 0.5, 0.5);
}

/* Every sheet in the scene is a bare element that keeps the 3D context
   (no children, clipping or opacity), so none of them needs a surface of
   its own to be drawn, and nothing is repainted while the leaves move. */
.rf-shadow {
  position: absolute;
  inset: 8px 2px -4px;
  background: #1c243357;
  box-shadow: 0 0 22px 12px #1c243357;
  transform-style: preserve-3d;
  transform: translateZ(-4px);
}

.rf-board {
  position: absolute;
  inset: -6px -14px;
  border-radius: 2px;
  background: linear-gradient(90deg, #1b274c 0%, #22305c 49%, #141d3b 50%, #22305c 51%, #1b274c 100%);
  transform-style: preserve-3d;
  transform: translateZ(-2px);
}

/* The bottom page of each stack is the widest: 23 leaves of 0.35 px. */
.rf-base {
  position: absolute;
  top: 0;
  width: 225px;
  height: 312px;
  background-color: var(--paper);
  transform-style: preserve-3d;
  transform: scaleX(1.03578);
}

.rf-base-l { left: 0; transform-origin: 100% 50%; }
.rf-base-r { left: 225px; transform-origin: 0 50%; }

.rf-leaf {
  position: absolute;
  left: 225px;
  top: 0;
  width: 0;
  height: 312px;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  will-change: transform;
}

.rf-strip {
  position: absolute;
  left: 0;
  top: 0;
  width: 45px;
  height: 312px;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  will-change: transform;
}

/* A leaf lying on a stack is flat, so it does not need its five hinged strips
   and two faces: while it is settled it is one sheet carrying the same print,
   and the strips (and their layers) are not laid out at all. A leaf unfolds
   back into strips the moment it starts to turn. */
.rf-flat { display: none; }

.rf-leaf[data-flat] > .rf-strip { display: none; }

.rf-leaf[data-flat] > .rf-flat {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 225px;
  height: 312px;
  background-color: var(--paper);
  background-size: 225px 312px;
  background-repeat: no-repeat;
}

.rf-leaf[data-flat="front"] > .rf-flat { background-image: var(--front); }

/* The turned leaf itself is a half-turn around the spine, onto the left side,
   so its print is turned back to face the reader. */
.rf-leaf[data-flat="back"] > .rf-flat {
  background-image: var(--back);
  transform: rotateY(180deg);
}

.rf-strip .rf-strip { left: 45px; }

/* A strip face runs 2 px over the next strip, so the soft edges of the sheets
   never leave a hairline at the joint. A face carries its paper and its print
   on one sheet: the print is transparent, so there is nothing to keep in the
   same plane as it. */
.rf-face {
  position: absolute;
  left: 0;
  top: 0;
  width: 47px;
  height: 312px;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  /* the print is transparent, so the sheet's colour is the paper under it */
  background-color: var(--paper);
  background-size: 225px 312px;
  background-repeat: no-repeat;
}

.rf-strip[data-end] > .rf-face { width: 45px; }

/* Each face has a transform of its own, so each is its own layer and is
   culled by its own facing. */
.rf-face.rf-front { background-image: var(--front); transform: translateZ(0); }
.rf-face.rf-back { background-image: var(--back); transform: rotateY(180deg); }

/* The pages of the covers are paper and print in two sheets. */
.rf-ink {
  background-color: transparent;
  background-size: 225px 312px;
  background-repeat: no-repeat;
}

.rf-ink.rf-base { transform: scaleX(1.03578); }

/* Pointer surface over the book. */
.rf-hit {
  position: absolute;
  left: 24px;
  top: 84px;
  width: 492px;
  height: 344px;
  cursor: grab;
}

.rf-hit[data-held] { cursor: grabbing; }

/* Pagination: a line of figures, the current one printed in the spot ink. */
.rf-nav {
  position: absolute;
  left: 0;
  right: 0;
  top: 460px;
  display: flex;
  justify-content: center;
}

.rf-list {
  display: flex;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rf-item { display: block; }

.rf-link,
.rf-step,
.rf-gap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 1px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 25px;
  font-weight: 500;
  line-height: 48px;
  font-variant-numeric: lining-nums tabular-nums;
  outline: none;
  cursor: pointer;
}

.rf-gap { cursor: default; color: #17181c99; }

.rf-link[data-current] {
  background: var(--spot);
  color: var(--paper);
  font-weight: 700;
}

.rf-step svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}

.rf-step[data-disabled] { color: #17181c4d; cursor: default; }

.rf-link:focus-visible,
.rf-step:focus-visible { box-shadow: 0 0 0 2px #dde1e4, 0 0 0 4px var(--ink); }
