/* Acts 1-3: the book on the table. One pinned stage; book.js turns the act's --sc-p into hinge angles. */
.act-book { position: relative; }
.spread-mark { position: absolute; left: 0; width: 1px; height: 1px; }
:root { --W: min(23vw, 40vh); --H: calc(var(--W) * 1.22); --T: calc(var(--W) * .045); }

.scene { position: absolute; top: 4vh; bottom: 0; left: 28vw; right: 11vw; display: grid; place-items: center;
  perspective: 1500px; perspective-origin: 50% 0%; pointer-events: none; }
.zoom { transform: translateY(var(--zy, 0)) scale(var(--zoom, 1)); transform-style: preserve-3d; }
.tilt { transform-style: preserve-3d;
  transform: rotateX(calc(var(--rx, 50deg) + var(--ty, 0deg))) rotateY(var(--tx, 0deg)); }
.book { position: relative; width: calc(var(--W) * 2); height: var(--H); transform-style: preserve-3d;
  transform: translateX(calc(var(--shift, -0.5) * var(--W))) rotateZ(-4deg); }

/* contact shadow: falls away from the lamp (lamp is up-left, so the shadow goes down-right) */
.shadow { position: absolute; top: 1%; bottom: -1%; right: -1%; left: calc(50% - var(--open, 0) * 50%); transform: translateZ(-1px);
  background: rgba(8,4,2,.55); filter: blur(14px); border-radius: 6px; translate: 14px 22px; }
.shadow::after { content: ""; position: absolute; inset: 1% 0 0 0; background: rgba(5,2,1,.75); filter: blur(3px); translate: -12px -18px; }

/* page blocks: the stack of paper under each half, with fore-edge and tail faces that drop to the table */
.block { position: absolute; top: 0; width: var(--W); height: var(--H); transform-style: preserve-3d; }
.block--right { left: var(--W); }
.block--left { left: 0; opacity: var(--leftOp, 0); }
.block::before, .block::after { content: ""; position: absolute; background: repeating-linear-gradient(var(--dir, 0deg), #EFE4CC 0 1px, #D9CAA8 1px 2px); }
/* tail edge (nearest the viewer) */
.block::before { left: 1.5%; right: 1.5%; top: 100%; height: var(--T); transform-origin: 50% 0; transform: translateZ(var(--T)) rotateX(-90deg);
  --dir: 0deg; filter: brightness(.82); }
/* fore-edge (the outer side) */
.block--right::after { top: 1.5%; bottom: 1.5%; left: 98.5%; width: var(--T); transform-origin: 0 50%; transform: translateZ(var(--T)) rotateY(90deg);
  --dir: 90deg; filter: brightness(.6); }
.block--left::after { top: 1.5%; bottom: 1.5%; right: 98.5%; width: var(--T); transform-origin: 100% 50%; transform: translateZ(var(--T)) rotateY(-90deg);
  --dir: 90deg; filter: brightness(1); }

/* paper pages: opaque, grained, with a gutter shadow and a slightly lighter lamp side */
.page, .leaf__front, .leaf__back, .cover__face--back { background: var(--paper); }
.page { position: absolute; top: 1.5%; width: calc(var(--W) * .985); height: 97%; overflow: hidden; transform: translateZ(var(--T)); }
.page--left { left: calc(var(--W) * .015); opacity: var(--leftOp, 0); }
.page--right { left: var(--W); }
.floor { position: absolute; inset: 0; background-size: cover; background-position: center; }
.floor::after { content: ""; position: absolute; inset: 0; background: var(--grain); mix-blend-mode: multiply; opacity: .55; }
.floor--l  { background-image: url(../assets/floor-l.webp); }
.floor--r  { background-image: url(../assets/floor-r.webp); }
.floor--l2 { background-image: url(../assets/floor-l2.webp); }
.floor--r2 { background-image: url(../assets/floor-r2.webp); }
.page--right::before, .leaf__front::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(to right, rgba(42,30,18,.5), rgba(42,30,18,.12) 9%, transparent 22%); }
.page--left::before, .leaf__back::before, .cover__face--back::before { content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(to left, rgba(42,30,18,.5), rgba(42,30,18,.12) 9%, transparent 22%); }

/* the right-hand leaf, turned over the gutter for spread 2 */
.leaf { position: absolute; top: 1.5%; left: var(--W); width: calc(var(--W) * .985); height: 97%; transform-origin: 0 50%;
  transform-style: preserve-3d; transform: translateZ(calc(var(--T) + 1px)) rotateY(var(--leaf, 0deg)); }
.leaf__front, .leaf__back { position: absolute; inset: 0; backface-visibility: hidden; transform-style: preserve-3d; }
.leaf__front > .floor { overflow: hidden; }
.leaf__back { transform: rotateY(180deg); overflow: hidden; }
/* the turning page darkens as it stands up (the lamp is behind it) */
.leaf__front::after, .leaf__back::after { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: rgba(30,20,10,var(--leafShade, 0)); }
/* the shadow the turning leaf sweeps across spread 2's right page */
.page--right::after { content: ""; position: absolute; inset: 0; z-index: 2; pointer-events: none; background: rgba(20,12,6,.55);
  transform-origin: 0 50%; transform: scaleX(var(--sweep, 0)); }

/* pop-up cards: hinged at their bottom edge, lying flat until the act lifts them */
.cards { position: absolute; inset: 0; transform-style: preserve-3d; }
.card { position: absolute; left: 50%; transform-origin: 50% 100%;
  transform: translateX(-50%) translateZ(calc(2px + var(--i, 0) * 1px)) rotateX(calc(var(--r, 0) * var(--cardMax, -76deg)));
  /* the page slot: everything below the hinge line is inside the page, so the bottom is clipped exactly at the fold;
     the art may rise past the top and sides */
  clip-path: inset(-120% -25% 0 -25%); }
/* the art inside the card rides on the engine's own parallax (data-sc-parallax), each layer at its own rate: it starts
   sunk in its slot by --sink and rises out of the page as the reader scrolls. --sink >= the layer's largest lift, so
   its foot never leaves the slot. */
.card__art { position: relative; top: var(--sink, 6px); }
.cards--2 .card img { translate: 0 calc(var(--down, 0) * 104%); }
.card img { display: block; width: 100%; height: auto; filter: drop-shadow(-8px 12px 10px rgba(20,12,6,var(--sh, 0))) brightness(var(--lit, 1)); }

/* where each card stands: a glued paper fold lying flat on the page just in front of the hinge, its crease, and the
   shadow the standing card throws onto it (lamp up-left, so the shadow falls toward the reader). Drawn on the page, in
   front of the card's foot: the page edge, never the card's cut edge, is what the eye meets. */
.slot { position: absolute; left: 50%; translate: -50% 0; height: calc(var(--H) * .045); transform: translateZ(1px); pointer-events: none;
  background: linear-gradient(to bottom, rgba(30,20,10,.75) 0 1.5px, rgba(255,246,225,.4) 1.5px 3px,
              rgba(20,12,6,calc(.12 + var(--r, 0) * .4)) 3px, rgba(20,12,6,0) 100%); }
.slot::before { content: ""; position: absolute; left: -2%; right: -2%; top: -1px; height: 3px; border-radius: 2px;
  background: rgba(20,12,6,calc(var(--r, 0) * .55)); filter: blur(1.5px); }
/* spread 1 (on the right page): far forest, then Linnea between her trunks, then the ferns, low in the middle */
/* every card is narrower than its page (94% of the leaf at most) and stands inside the page frame */
.card--back,   .slot--back   { width: 92%; bottom: 58%; --i: 0; --r: var(--r0); --sh: calc(var(--r0) * .45); --sink: 4px; }
.card--linnea, .slot--linnea { width: calc(var(--W) * .62); bottom: 30%; left: 47%; --i: 1; --r: var(--r2); --sh: calc(var(--r2) * .55); --sink: 4px; }
.card--front,  .slot--front  { width: 92%; bottom: 6%; --i: 2; --r: var(--r1); --sh: calc(var(--r1) * .5); --sink: 4px; }
.slot--back { bottom: calc(58% - var(--H) * .045); } .slot--linnea { bottom: calc(30% - var(--H) * .045); } .slot--front { bottom: calc(6% - var(--H) * .045); }
.cards--1 { left: 0; right: 0; opacity: var(--c1Op, 1); }
/* spread 2 (the peak): spans both pages */
.cards--2 { left: 0; right: 0; opacity: var(--c2Op, 0); transform: translateZ(calc(var(--T) + 6px)); } /* stands ON the paper, never through it */
.card--hollow, .slot--hollow { width: calc(var(--W) * 1.7); bottom: 61%; --i: 0; --r: var(--r3); --sh: calc(var(--r3) * .5); --sink: 30px; }
.card--trolls, .slot--trolls { width: calc(var(--W) * .95); bottom: 8%; left: 52%; --i: 1; --r: var(--r4); --sh: calc(var(--r4) * .6); --sink: 18px; }
.slot--hollow { bottom: calc(61% - var(--H) * .045); } .slot--trolls { bottom: calc(8% - var(--H) * .045); }
.card--trolls .card__art { -webkit-mask-image: linear-gradient(to right, transparent, #000 7%, #000 93%, transparent); mask-image: linear-gradient(to right, transparent, #000 7%, #000 93%, transparent); }
.card--trolls img { --lit: calc(.9 + var(--fire, 0) * .12); }

/* the blue lights: they lift off the page last and keep rising while the spread holds */
.lights { position: absolute; inset: 0; transform-style: preserve-3d; pointer-events: none; }
.lights i { position: absolute; width: calc(var(--W) * .06); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(236,246,255,1) 0 18%, rgba(150,200,255,.75) 34%, rgba(110,160,240,.22) 58%, transparent 72%);
  opacity: var(--lo, 0);
  transform: translateZ(calc(4px + var(--lz, 0) * var(--W) * var(--h, 1))) translateX(calc(var(--dx, 0) * var(--lz, 0) * var(--W))); }
.lights i:nth-child(1) { left: 38%; top: 52%; --h: .9;  --dx: .05; }
.lights i:nth-child(2) { left: 47%; top: 60%; --h: 1.3; --dx: -.04; scale: .7; }
.lights i:nth-child(3) { left: 55%; top: 48%; --h: 1.1; --dx: .03; scale: 1.15; }
.lights i:nth-child(4) { left: 62%; top: 58%; --h: .75; --dx: .07; scale: .8; }
.lights i:nth-child(5) { left: 30%; top: 44%; --h: 1.4; --dx: -.06; scale: .6; }
.lights i:nth-child(6) { left: 70%; top: 40%; --h: 1.6; --dx: .02; scale: .9; }
.lights i:nth-child(7) { left: 50%; top: 36%; --h: 1.9; --dx: -.02; scale: .55; }

/* the cover: a cloth board with thickness, its front stamped in foil with a tipped-in painted plate */
.cover { position: absolute; top: -1%; left: var(--W); width: calc(var(--W) * 1.02); height: 102%; transform-origin: 0 50%;
  transform-style: preserve-3d; transform: translateZ(calc(var(--T) + 3px)) rotateY(var(--cov, 0deg)); }
.cover__face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 1px 4px 4px 1px; }
.cover__face--front { display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 6% 0 5%; box-sizing: border-box; }
.cover__title { font-size: calc(var(--W) * .1); line-height: 1; text-align: center; padding: 0 8%; }
/* v2e: title + plate + author must fit the cover's 1.24 W height (at 70% the author fell off the bottom edge) */
.cover__plate { width: 60%; aspect-ratio: 2 / 3; box-shadow: 0 1px 2px rgba(0,0,0,.6), inset 0 0 0 1px rgba(0,0,0,.2); }
.cover__plate img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cover__author { font-size: calc(var(--W) * .066); line-height: 1; letter-spacing: .02em; }
.cover__face--back { transform: rotateY(180deg); overflow: hidden; }
.cover__face--back .floor { inset: 1.5% 0 1.5% 1.5%; }
/* the board's own edge (tail), so the cover reads as board, not a picture */
.cover__edge { position: absolute; left: 0; right: 0; top: 100%; height: 4px; background: var(--board-edge); transform-origin: 50% 0; transform: rotateX(-90deg); }

/* ---------- copy on paper ---------- */
.slip--title { left: 6vw; top: 13vh; width: min(25rem, 27vw); padding: 2rem 2.2rem 1.8rem; rotate: -1.2deg;
  opacity: var(--titleOp, 1); transform: translateX(calc(var(--titleX, 0) * -1rem)) rotate(calc(var(--titleX, 0) * -.15deg)); }
.slip--title h1, .slip--cover h2 { font-family: var(--sc-font-display); font-style: italic; font-weight: 500; font-size: clamp(2.6rem, 3.9vw, 3.9rem);
  line-height: .98; letter-spacing: -.012em; margin: 0 0 1rem; color: var(--ink); text-wrap: balance; }
.slip--title p { color: var(--ink-soft); max-width: 30ch; margin-bottom: 1.3rem; }
.slip--cover p { margin-bottom: 0; }

.slip--q1, .slip--q2 { left: 5vw; bottom: 8vh; width: min(29rem, 30vw); margin: 0; padding: 1.8rem 2.1rem 1.4rem; }
.slip--q1 { rotate: .7deg; opacity: var(--q1Op, 0); transform: translateY(calc(var(--q1Y, 1) * 105vh)); }
.slip--q2 { rotate: -.8deg; opacity: var(--q2Op, 0); transform: translateY(calc(var(--q2Y, 1) * 105vh)); }
.slip blockquote { margin: 0; }
.slip--q1 .turn { font-family: var(--sc-font-display); font-style: italic; font-size: 1.75rem; line-height: 1.15; margin: 0 0 .9rem;
}
.turn .w { transition: opacity .25s ease; }
.slip figcaption { font-size: .92rem; font-style: italic; color: var(--ink-soft); }
.slip--q2 h2 { font-family: var(--sc-font-display); font-weight: 500; font-style: italic; font-size: 2.2rem; line-height: 1; margin: 0 0 .9rem; color: var(--ink); }
.slip--q2 h2 small { display: block; font-size: 1.15rem; font-style: normal; color: var(--ink-soft); margin-top: .35rem; }

/* the stage's floor fades into the room as the pin lets go: one table, no hard edge against the next section */
.feather { position: absolute; left: 0; right: 0; bottom: 0; height: 22vh; z-index: 2; pointer-events: none; opacity: var(--featherOp, 0);
  background: linear-gradient(to bottom, rgba(26,18,12,0), var(--sc-canvas) 92%); }
.note { position: absolute; z-index: 3; right: 9vw; bottom: 2.2vh; margin: 0; max-width: 34ch; text-align: right;
  font-size: .9rem; line-height: 1.4; font-style: italic; color: #D9CBAE; opacity: var(--noteOp, 0); }

@media (prefers-reduced-motion: reduce) {
  .slip--q1, .slip--q2 { transform: none; }
}

/* ---------- phone: art-directed, LAST ---------- */
@media (max-width: 700px) {
  :root { --W: 43vw; }
  .scene { left: 0; right: 0; top: 36vh; bottom: 2vh; perspective: 1100px; }
  .book { transform: translateX(calc(var(--shift, -0.5) * var(--W))) rotateZ(-2deg); }
  .slip--title { left: 5vw; right: 14vw; top: 4vh; width: auto; padding: 1.2rem 1.4rem 1.1rem; }
  .slip--title h1, .slip--cover h2 { font-size: 2.35rem; margin-bottom: .55rem; }
  .slip--title p { margin-bottom: .8rem; }
  .find { font-size: 1.15rem; min-height: 44px; box-sizing: border-box; padding-top: .55rem; }
  .slip--q1, .slip--q2 { left: 4vw; right: 13vw; width: auto; top: 3vh; bottom: auto; padding: 1.1rem 1.3rem .9rem; }
  .slip--q1 p, .slip--q2 p { font-size: .98rem; margin-bottom: .55rem; }
  .slip--q1 { transform: translateY(calc(var(--q1Y, 1) * -70vh)); }
  .slip--q2 { transform: translateY(calc(var(--q2Y, 1) * -70vh)); }
  .slip--q1 .turn { font-size: 1.35rem; }
  .slip--q2 h2 { font-size: 1.7rem; }
  .note { right: 12vw; left: 5vw; bottom: 1.5vh; font-size: .8rem; }
}
.note .nobr { white-space: nowrap; }

/* v2e: the book's title card on a tablet (701-1000): wide enough that "Skogsflickan" stays inside the paper */
@media (min-width: 701px) and (max-width: 1000px) {
  .slip--cover { width: 17.5rem; padding: 1.7rem 1.8rem 1.6rem; }
  .slip--cover h2 { font-size: 2.3rem; }
}
