/* ==========================================================================
   HERO COVER 3D · the printed book, turning, in the hero's top right
   --------------------------------------------------------------------------
   The one photographic object allowed above the fold: the real printed cover
   assembled as a box in CSS 3D (front, spine, back plus the three paper
   edges) and turning slowly on its own clock. It stands in the empty top
   right of the hero, beside — never over — the title block, and it is the
   warm object of the page, so it is allowed the amber pool the wireframe rig
   also carries (The One Warm Thing Rule).

   Loaded AFTER css/libro.css and css/hero-book.css, from which it borrows the
   tokens (--pad, --cyan, --magenta, --amber, --ease) and nothing else.

   Contract
   - every selector is scoped to `.cover3d` or to a `c3d-` class, and every
     custom property and keyframe carries the same prefix;
   - the component is decorative: `aria-hidden`, no text, no focusable node,
     `pointer-events: none` so it can never take a click from the hero. The
     real cover with its alt text lives in the editions panel further down;
   - the content is static HTML and the motion is pure CSS: with scripting off
     the book is there and still turning. There is no JS file for this
     component on purpose — the rig's own pointer handler already reads the
     pointer over the whole `.hero`, so a second reaction here would move two
     objects at once;
   - the geometry is derived, never hard-coded: the trim is 7 x 10 in, so the
     cover height is the width over 0.7, and the thickness is the width times
     the edition's own spine ratio — 50/520 for the Italian edition, 64/520
     for the English one, exactly the pixel ratios of the sliced art;
   - below 1100px the component is removed: the room it needs does not exist
     there and the wireframe rig is the hero's object on those widths;
   - under prefers-reduced-motion nothing moves and the book is parked at a
     three-quarter view with the front and the spine both readable.

   Layer map (outside in)
     .cover3d              absolute in .hero, anchored to the page margin
       .c3d-stage          the perspective camera
         .c3d-seat         the black offset shadow it is seated on
         .c3d-pool         the warm pool of light it stands in
         .c3d-tilt         the slow nod, off the turn's clock
           .c3d-spin       the turn: front, spine, back, fore-edge, front
             .c3d-face     six planes; the three printed ones carry an <img>
   ========================================================================== */

.cover3d {
  /* --- geometry --------------------------------------------------------- */
  --c3d-box:    clamp(170px, 16vw, 250px); /* the component's own footprint  */
  --c3d-w:      calc(var(--c3d-box) * 0.88);   /* front cover width          */
  --c3d-trim:   0.7;                       /* 7 x 10 in: width over height   */
  --c3d-h:      calc(var(--c3d-w) / var(--c3d-trim));
  --c3d-spine-ratio: 0.09615;              /* 50 / 520, Italian edition      */
  --c3d-t:      calc(var(--c3d-w) * var(--c3d-spine-ratio));
  --c3d-ht:     calc(var(--c3d-t) / 2);    /* half the thickness             */
  --c3d-r:      2.5px;                     /* the printed corner, at this scale */
  --c3d-floor:  calc(var(--c3d-h) * 0.15); /* the room under it for the pool */

  /* --- clocks ----------------------------------------------------------- */
  --c3d-turn:   26s;                       /* one full revolution            */
  --c3d-nod:    13s;                       /* the slow nod, deliberately coprime */
  --c3d-breath: 9.5s;                      /* the chromatic fringe           */

  /* --- light ------------------------------------------------------------ */
  --c3d-paper:  #c6ccde;                   /* the cut page block             */
  --c3d-ink:    rgba(2, 4, 12, 0.92);      /* the shading over a cover       */

  position: absolute;
  top: clamp(12px, 2.4vh, 28px);
  right: var(--pad);
  z-index: 1;                 /* under .hero-head (2): the title always wins */
  width: var(--c3d-box);
  pointer-events: none;
}

/* the English edition is the thicker book: 64 / 520 of the cover width */
.cover3d--en { --c3d-spine-ratio: 0.12308; }

/* --- the camera ---------------------------------------------------------- */
/* Flat on purpose: the seat and the pool are painted in DOM order under the
   book, and only .c3d-tilt opens a 3D context. */
.c3d-stage {
  position: relative;
  width: 100%;
  height: calc(var(--c3d-h) + var(--c3d-floor));
  perspective: calc(var(--c3d-w) * 7);
  /* the camera sits level with the head of the book and the book leans a few
     degrees toward it, the way a book is photographed. Without that pair the
     top edge is a zero-height line and the object loses the one paper edge
     that reads as thickness while the front is facing the reader. Seven cover
     widths of distance keeps the near edge from swelling as it swings round;
     the little swell that is left is what the seat below tracks. */
  perspective-origin: 50% 3%;
}

/* ==========================================================================
   THE GROUND · a pool of light with the book's own shadow dropped into it
   The Shadow-Under-Every-Glow Rule: the pool is the light, the seat is the
   body. A black shadow on a near-black ground says nothing, so the seat is
   painted *over* the pool (it is second in the markup) and reads as the dark
   contact patch inside the lit floor. The seat narrows and lightens with the
   turn, because an edge-on book occludes a narrower strip of floor: its
   keyframes are the projected silhouette, |cos| plus the thickness times
   |sin|, on the turn's own clock.
   ========================================================================== */
.c3d-pool {
  position: absolute;
  left: 50%;
  top: var(--c3d-h);
  width: calc(var(--c3d-w) * 1.34);
  height: calc(var(--c3d-floor) * 1.8);
  transform: translate(-50%, -38%);
  background:
    radial-gradient(closest-side at 50% 50%,
      rgba(255, 138, 61, 0.32), rgba(255, 138, 61, 0.08) 42%, rgba(255, 138, 61, 0) 70%),
    radial-gradient(closest-side,
      rgba(34, 227, 255, 0.18), rgba(34, 227, 255, 0.05) 54%, rgba(34, 227, 255, 0) 76%);
  animation: c3d-pool 7.5s ease-in-out infinite alternate;
}

.c3d-seat {
  position: absolute;
  left: 50%;
  top: var(--c3d-h);
  width: calc(var(--c3d-w) * 0.98);
  height: calc(var(--c3d-floor) * 0.64);
  transform: translate(-50%, -34%);
  border-radius: 50%;
  background: radial-gradient(closest-side,
    rgba(1, 2, 8, 0.95), rgba(1, 2, 8, 0.55) 52%, rgba(1, 2, 8, 0) 80%);
  animation: c3d-seat var(--c3d-turn) linear infinite;
}
@keyframes c3d-pool {
  from { opacity: 0.68; }
  to   { opacity: 1; }
}

/* ==========================================================================
   THE NOD · a slow lean on its own 13s clock, coprime with the 26s turn, so
   the two never line up and the object never reads as a lazy susan. It also
   holds the book tipped toward the camera, which is what keeps the head a
   visible sliver of paper the whole way round.
   ========================================================================== */
.c3d-tilt {
  position: absolute;
  left: 50%;
  top: 0;
  width: var(--c3d-w);
  height: var(--c3d-h);
  margin-left: calc(var(--c3d-w) / -2);
  transform-style: preserve-3d;
  animation: c3d-nod var(--c3d-nod) ease-in-out infinite alternate;
}
/* rotateX is negative: it tips the head *toward* the camera. The head sliver
   breathes between roughly 2px and 4px of paper as the nod runs. */
@keyframes c3d-nod {
  from { transform: translate3d(0, 5px, 0)  rotateX(-6deg)  rotateZ(-0.8deg); }
  to   { transform: translate3d(0, -5px, 0) rotateX(-12deg) rotateZ(0.9deg); }
}

/* ==========================================================================
   THE TURN
   Front, round past the spine, back, past the fore-edge, front again, in 26s.
   The schedule is not linear: the time spent per degree is 1 + 0.5cos(a) +
   0.3cos(2a), so the front holds the view for 51% of the cycle, the back for
   24%, and the two edge-on poses are the quickest part of the pass. Sampling
   that at a constant 15 degrees gives keyframes whose *percentages* are
   uneven and whose angles are even, which is a smooth, continuously varying
   speed rather than a few eased segments bumping into each other.
   ========================================================================== */
.c3d-spin {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: rotateY(-16deg);
  animation: c3d-turn var(--c3d-turn) linear infinite;
}

@keyframes c3d-turn {
    0.000% { transform: rotateY(-16deg); }
    7.403% { transform: rotateY(-1deg); }
   14.838% { transform: rotateY(14deg); }
   21.841% { transform: rotateY(29deg); }
   28.039% { transform: rotateY(44deg); }
   33.221% { transform: rotateY(59deg); }
   37.373% { transform: rotateY(74deg); }
   40.665% { transform: rotateY(89deg); }
   43.392% { transform: rotateY(104deg); }
   45.894% { transform: rotateY(119deg); }
   48.464% { transform: rotateY(134deg); }
   51.283% { transform: rotateY(149deg); }
   54.387% { transform: rotateY(164deg); }
   57.681% { transform: rotateY(179deg); }
   60.988% { transform: rotateY(194deg); }
   64.125% { transform: rotateY(209deg); }
   66.983% { transform: rotateY(224deg); }
   69.579% { transform: rotateY(239deg); }
   72.074% { transform: rotateY(254deg); }
   74.752% { transform: rotateY(269deg); }
   77.950% { transform: rotateY(284deg); }
   81.974% { transform: rotateY(299deg); }
   87.015% { transform: rotateY(314deg); }
   93.085% { transform: rotateY(329deg); }
  100.000% { transform: rotateY(344deg); }
}

/* the seat follows the same clock: the silhouette of a book seen edge-on is
   half as wide as the one seen face-on, and so is what it occludes */
@keyframes c3d-seat {
    0.000% { transform: translate(-50%, calc(-34% + 0.0194 * var(--c3d-h))) scaleX(1.004); opacity: 1.000; }
    7.403% { transform: translate(-50%, calc(-34% + 0.0012 * var(--c3d-h))) scaleX(1.002); opacity: 1.000; }
   14.838% { transform: translate(-50%, calc(-34% + 0.0170 * var(--c3d-h))) scaleX(1.006); opacity: 1.000; }
   21.841% { transform: translate(-50%, calc(-34% + 0.0347 * var(--c3d-h))) scaleX(0.974); opacity: 0.977; }
   28.039% { transform: translate(-50%, calc(-34% + 0.0504 * var(--c3d-h))) scaleX(0.903); opacity: 0.914; }
   33.221% { transform: translate(-50%, calc(-34% + 0.0630 * var(--c3d-h))) scaleX(0.796); opacity: 0.818; }
   37.373% { transform: translate(-50%, calc(-34% + 0.0712 * var(--c3d-h))) scaleX(0.661); opacity: 0.698; }
   40.665% { transform: translate(-50%, calc(-34% + 0.0743 * var(--c3d-h))) scaleX(0.508); opacity: 0.561; }
   43.392% { transform: translate(-50%, calc(-34% + 0.0719 * var(--c3d-h))) scaleX(0.642); opacity: 0.680; }
   45.894% { transform: translate(-50%, calc(-34% + 0.0644 * var(--c3d-h))) scaleX(0.780); opacity: 0.803; }
   48.464% { transform: translate(-50%, calc(-34% + 0.0523 * var(--c3d-h))) scaleX(0.891); opacity: 0.903; }
   51.283% { transform: translate(-50%, calc(-34% + 0.0369 * var(--c3d-h))) scaleX(0.967); opacity: 0.971; }
   54.387% { transform: translate(-50%, calc(-34% + 0.0194 * var(--c3d-h))) scaleX(1.004); opacity: 1.000; }
   57.681% { transform: translate(-50%, calc(-34% + 0.0012 * var(--c3d-h))) scaleX(1.002); opacity: 1.000; }
   60.988% { transform: translate(-50%, calc(-34% + 0.0170 * var(--c3d-h))) scaleX(1.006); opacity: 1.000; }
   64.125% { transform: translate(-50%, calc(-34% + 0.0347 * var(--c3d-h))) scaleX(0.974); opacity: 0.977; }
   66.983% { transform: translate(-50%, calc(-34% + 0.0504 * var(--c3d-h))) scaleX(0.903); opacity: 0.914; }
   69.579% { transform: translate(-50%, calc(-34% + 0.0630 * var(--c3d-h))) scaleX(0.796); opacity: 0.818; }
   72.074% { transform: translate(-50%, calc(-34% + 0.0712 * var(--c3d-h))) scaleX(0.661); opacity: 0.698; }
   74.752% { transform: translate(-50%, calc(-34% + 0.0743 * var(--c3d-h))) scaleX(0.508); opacity: 0.561; }
   77.950% { transform: translate(-50%, calc(-34% + 0.0719 * var(--c3d-h))) scaleX(0.642); opacity: 0.680; }
   81.974% { transform: translate(-50%, calc(-34% + 0.0644 * var(--c3d-h))) scaleX(0.780); opacity: 0.803; }
   87.015% { transform: translate(-50%, calc(-34% + 0.0523 * var(--c3d-h))) scaleX(0.891); opacity: 0.903; }
   93.085% { transform: translate(-50%, calc(-34% + 0.0369 * var(--c3d-h))) scaleX(0.967); opacity: 0.971; }
  100.000% { transform: translate(-50%, calc(-34% + 0.0194 * var(--c3d-h))) scaleX(1.004); opacity: 1.000; }
}

/* ==========================================================================
   THE SIX FACES
   Flat inside: each face paints its two chromatic ghosts, then the printed
   art over them, then its own shading. Nothing inside a face is in 3D, so
   the paint order is the DOM order and no plane can z-fight with another.
   ========================================================================== */
.c3d-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--c3d-r);
}
/* positioned on purpose: an in-flow image would paint *under* the positioned
   ghosts beside it, and the whole board would come up magenta */
.c3d-face > img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

/* the two boards */
.c3d-front { transform: translateZ(var(--c3d-ht)); }
.c3d-back  { transform: translateZ(calc(var(--c3d-ht) * -1)) rotateY(180deg); }

/* the spine, on the left of the front board, facing -X */
.c3d-spineface {
  left: 50%;
  right: auto;
  width: var(--c3d-t);
  margin-left: calc(var(--c3d-t) / -2);
  border-radius: 1px;
  transform: translateX(calc(var(--c3d-w) / -2)) rotateY(-90deg);
}

/* ==========================================================================
   THE PAPER · fore-edge, head and tail
   The three faces that are not printed are the cut block of 384 pages, and
   they are what gives the object its mass: a book whose edges are missing
   reads as three pictures taped together. They are the light edge of the
   object, so they are kept just off white and very slightly cool, and each
   one is darkened where the cover folds over it.
   ========================================================================== */
.c3d-edge {
  background-color: var(--c3d-paper);
  box-shadow: inset 0 0 0 0.5px rgba(10, 16, 36, 0.35);
}

/* the fore-edge: local left is the front of the book, local right the back */
.c3d-fore {
  left: 50%;
  right: auto;
  width: var(--c3d-t);
  margin-left: calc(var(--c3d-t) / -2);
  border-radius: 1px;
  transform: translateX(calc(var(--c3d-w) / 2)) rotateY(90deg);
  background-image:
    repeating-linear-gradient(to right,
      rgba(14, 20, 44, 0.26) 0 0.6px, rgba(14, 20, 44, 0) 0.6px 2.1px),
    linear-gradient(to right,
      rgba(8, 12, 30, 0.80) 0%, rgba(8, 12, 30, 0.12) 20%,
      rgba(255, 255, 255, 0.10) 48%, rgba(8, 12, 30, 0.20) 76%,
      rgba(8, 12, 30, 0.78) 100%);
}

/* the head: local bottom is the front of the book */
.c3d-head {
  top: 50%;
  bottom: auto;
  height: var(--c3d-t);
  margin-top: calc(var(--c3d-t) / -2);
  border-radius: 1px;
  transform: translateY(calc(var(--c3d-h) / -2)) rotateX(90deg);
  background-image:
    repeating-linear-gradient(to bottom,
      rgba(14, 20, 44, 0.24) 0 0.6px, rgba(14, 20, 44, 0) 0.6px 2.1px),
    linear-gradient(to bottom,
      rgba(8, 12, 30, 0.70) 0%, rgba(8, 12, 30, 0.10) 26%,
      rgba(255, 255, 255, 0.10) 54%, rgba(8, 12, 30, 0.66) 100%);
}

/* the tail: the floor-facing edge, in its own shadow */
.c3d-tail {
  top: 50%;
  bottom: auto;
  height: var(--c3d-t);
  margin-top: calc(var(--c3d-t) / -2);
  border-radius: 1px;
  transform: translateY(calc(var(--c3d-h) / 2)) rotateX(-90deg);
  background-image: linear-gradient(to top,
    rgba(4, 6, 18, 0.88) 0%, rgba(4, 6, 18, 0.62) 60%, rgba(4, 6, 18, 0.5) 100%);
}

/* ==========================================================================
   THE CHROMATIC FRINGE
   The page's title and the wireframe rig both lose their registration; the
   printed object does too, but least of the three. Two solid ghosts of the
   board sit behind the art in the same plane and are offset a couple of
   pixels either way, so a cyan and a magenta edge stand out of the silhouette
   and foreshorten with the turn exactly as the board does. The separation
   breathes on its own 9.5s clock, and it breathes in `transform` only: a
   filter animation over three large photographs is the one thing this
   component must not do.
   ========================================================================== */
.c3d-gh {
  position: absolute;
  inset: 0;
  border-radius: inherit;
}
.c3d-gh--c {
  background: var(--cyan);
  opacity: 0.38;
  transform: translate3d(-1.6px, 0, 0);
  animation: c3d-fringe-c var(--c3d-breath) ease-in-out infinite;
}
.c3d-gh--m {
  background: var(--magenta);
  opacity: 0.38;
  transform: translate3d(1.6px, 0, 0);
  animation: c3d-fringe-m var(--c3d-breath) ease-in-out infinite;
}
@keyframes c3d-fringe-c {
  0%, 100% { transform: translate3d(-1.2px, 0, 0); }
  50%      { transform: translate3d(-2.1px, 0, 0); }
}
@keyframes c3d-fringe-m {
  0%, 100% { transform: translate3d(1.2px, 0, 0); }
  50%      { transform: translate3d(2.1px, 0, 0); }
}
/* on the spine the same separation would be a third of the face: halve it */
.c3d-spineface .c3d-gh--c { transform: translate3d(-0.9px, 0, 0); animation-name: none; }
.c3d-spineface .c3d-gh--m { transform: translate3d(0.9px, 0, 0);  animation-name: none; }

/* ==========================================================================
   THE SHADING
   A printed board that keeps its full brightness while it turns away is the
   tell of a fake 3D cover. Each printed face carries one overlay whose
   opacity runs on the turn's clock at 1 - max(0, cos) of its own angle to the
   camera, with an extra darkening along the hinge where a paperback's cover
   folds. Opacity only, over a gradient: no filter, no repaint of the art.
   ========================================================================== */
.c3d-lit {
  position: absolute;
  inset: 0;
  z-index: 2;                 /* over the art, under nothing */
  border-radius: inherit;
}
.c3d-front .c3d-lit {
  background: linear-gradient(to right,
    var(--c3d-ink) 0%, rgba(2, 4, 12, 0.3) 13%, rgba(2, 4, 12, 0.26) 100%);
  animation: c3d-lit-front var(--c3d-turn) linear infinite;
}
.c3d-back .c3d-lit {
  background: linear-gradient(to left,
    var(--c3d-ink) 0%, rgba(2, 4, 12, 0.3) 13%, rgba(2, 4, 12, 0.26) 100%);
  animation: c3d-lit-back var(--c3d-turn) linear infinite;
}
.c3d-spineface .c3d-lit {
  background: linear-gradient(to right,
    rgba(2, 4, 12, 0.5) 0%, rgba(2, 4, 12, 0.14) 42%, rgba(2, 4, 12, 0.5) 100%);
  animation: c3d-lit-spine var(--c3d-turn) linear infinite;
}

@keyframes c3d-lit-front {
    0.000% { opacity: 0.166; }
    7.403% { opacity: 0.140; }
   14.838% { opacity: 0.160; }
   21.841% { opacity: 0.223; }
   28.039% { opacity: 0.325; }
   33.221% { opacity: 0.460; }
   37.373% { opacity: 0.618; }
   40.665% { opacity: 0.788; }
   43.392% { opacity: 0.800; }
   74.752% { opacity: 0.800; }
   77.950% { opacity: 0.640; }
   81.974% { opacity: 0.480; }
   87.015% { opacity: 0.342; }
   93.085% { opacity: 0.234; }
  100.000% { opacity: 0.166; }
}
@keyframes c3d-lit-back {
    0.000% { opacity: 0.800; }
   40.665% { opacity: 0.800; }
   43.392% { opacity: 0.640; }
   45.894% { opacity: 0.480; }
   48.464% { opacity: 0.342; }
   51.283% { opacity: 0.234; }
   54.387% { opacity: 0.166; }
   57.681% { opacity: 0.140; }
   60.988% { opacity: 0.160; }
   64.125% { opacity: 0.223; }
   66.983% { opacity: 0.325; }
   69.579% { opacity: 0.460; }
   72.074% { opacity: 0.618; }
   74.752% { opacity: 0.788; }
   77.950% { opacity: 0.800; }
  100.000% { opacity: 0.800; }
}
@keyframes c3d-lit-spine {
    0.000% { opacity: 0.740; }
    7.403% { opacity: 0.740; }
   14.838% { opacity: 0.585; }
   21.841% { opacity: 0.430; }
   28.039% { opacity: 0.295; }
   33.221% { opacity: 0.191; }
   37.373% { opacity: 0.125; }
   40.665% { opacity: 0.100; }
   43.392% { opacity: 0.119; }
   45.894% { opacity: 0.180; }
   48.464% { opacity: 0.280; }
   51.283% { opacity: 0.410; }
   54.387% { opacity: 0.564; }
   57.681% { opacity: 0.729; }
   60.988% { opacity: 0.740; }
  100.000% { opacity: 0.740; }
}

/* ==========================================================================
   RESPONSIVE
   One rule: below 1100px the component does not exist. The hero is already
   full at that width, the region this object fills has been eaten by the
   title block, and the wireframe rig is the hero's object from there down.
   ========================================================================== */
@media (max-width: 1100px) {
  .cover3d { display: none; }
}

/* A short viewport pushes the horizon up under the object: give the turn
   less room rather than let the book stand in the running grid. Below 1100px
   the rule above has already removed the component, so no width bound here. */
@media (max-height: 780px) {
  .cover3d { --c3d-box: clamp(150px, 13vw, 200px); }
}

/* ==========================================================================
   REDUCED MOTION
   Parked at a three-quarter view: the front and the spine are both readable,
   which is the most informative pose the object has. libro.css clamps every
   animation on `*` with !important, which would otherwise snap each loop to
   its last keyframe, so this block has to be important too.
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .cover3d,
  .cover3d *,
  .cover3d *::before,
  .cover3d *::after {
    animation: none !important;
    transition: none !important;
  }
  .c3d-tilt { transform: rotateX(-9deg) rotateZ(-0.2deg); }
  .c3d-spin { transform: rotateY(40deg); }
  /* the shading freezes at the value the turn would hold at 40 degrees */
  .c3d-front .c3d-lit     { opacity: 0.28; }
  .c3d-back  .c3d-lit     { opacity: 0.80; }
  .c3d-spineface .c3d-lit { opacity: 0.22; }
  /* and the seat at the silhouette that pose actually occludes */
  .c3d-seat { transform: translate(-50%, -34%) scaleX(0.83); opacity: 0.86; }
  .c3d-pool { opacity: 0.85; }
}
