/* Public sector and education entry page: two pop-up books (Paul's mock-up
   "Public et éducation pop-up", 2026-11-18). Loaded after space.css, whose
   type scale, buttons and palette this page reuses: only the books and the
   scroll choreography live here. Class names carry the sp-pop- prefix so
   Tailwind never reads them as utilities (same rule as space.css).

   Book 1 (the territory) opens on a town, then stands up the collège with
   its half-board terminal (Cantoche) and the lycée with its delivery lorry
   (Allegro), the copy changing beside it. Book 2 builds ÉVIDENCE's office
   wall by wall, and its printer throws sheets that fade away.

   Static first: everything below is written for the page WITHOUT the
   driver, so no JS, a failed script, reduced motion or a crawler all get
   the complete picture (books open, every piece standing, the three texts
   stacked, no pinning). public-sector-popup.js puts .sp-pop-live on <html>
   when it can drive the scroll, and only then does the page pin and
   animate. Same contract as .sp-ie.is-live in space.css. */

.sp-pop-act {
  position: relative;
  /* The spread of book 2 runs wider than its page; clip (not hidden) keeps
     the sticky stage anchored to the viewport's scrollport. */
  overflow-x: clip;
}
.sp-pop-act--territory { background: linear-gradient(100deg, var(--sp-bg-a) 0%, var(--sp-bg-b) 100%); }
.sp-pop-act--evidence { background: #ffffff; }
/* The base layer colours h1/h2/p from --color-primary, which flips with the
   site's dark theme; these sections stay light, so their text takes the
   space's ink instead. Same guard space.css puts on .sp-hero and
   .sp-product, and the reason: a dark --color-primary on the pastel
   gradient leaves the title all but invisible. */
:where(.sp-pop-act) :where(h1, h2, p) { color: inherit; margin: 0; }

/* The site bar lies over the first book (hero view), about 85px tall, so
   the opening section leaves room for it instead of running under it. Only
   the still needs it: once the page is driven the section is a pinned
   screen with its copy centred, far below the bar. */
.sp-pop-pin {
  display: grid;
  gap: 32px;
  width: 100%;
  max-width: 1240px;
  margin-inline: auto;
  padding: 56px 20px;
}
html:not(.sp-pop-live) .sp-pop-act--territory .sp-pop-pin { padding-top: 112px; }
@media (min-width: 768px) { .sp-pop-pin { padding-inline: 40px; } }
@media (min-width: 1024px) {
  .sp-pop-pin { grid-template-columns: minmax(0, 5fr) minmax(0, 8fr); align-items: center; gap: clamp(16px, 4vw, 56px); }
  /* ÉVIDENCE answers the first book: its text sits on the right. */
  .sp-pop-act--evidence .sp-pop-pin { grid-template-columns: minmax(0, 8fr) minmax(0, 5fr); }
  .sp-pop-act--evidence .sp-pop-copy { order: 2; }
}

/* ---------- The copy column ---------- */

.sp-pop-copy { display: grid; gap: 48px; min-width: 0; }
.sp-pop-products { display: grid; gap: 48px; min-width: 0; }
.sp-pop-step, .sp-pop-product { display: grid; gap: 14px; align-content: center; }
/* space.css spaces these with margins; here the grid's gap does it. */
:where(.sp-pop-step, .sp-pop-product) :where(.sp-lead, .sp-body, .sp-actions) { margin-top: 0; }
.sp-pop-eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sp-steel);
}
/* Reads as an instruction, not decoration: the book only opens on scroll.
   So it belongs to the driven page alone; in the still the book is already
   open and the line would promise something that has happened. */
.sp-pop-cue { display: none; align-items: center; gap: 10px; font-size: 0.875rem; color: var(--sp-steel); }
.sp-pop-live .sp-pop-cue { display: flex; }
.sp-pop-cue::before {
  content: "";
  flex: none;
  width: 15px;
  height: 24px;
  border: 1.5px solid currentColor;
  border-radius: 8px;
  background: radial-gradient(circle at 50% 30%, currentColor 2px, transparent 2.5px);
}

/* ---------- The book ----------
   A board, a right page, and a leaf that carries the left page on its front
   and the cover on its back. The whole thing lies back on rotateX so the
   reader looks down into it; each piece then stands up around its own
   hinge, leaning ~20 degrees past upright to face the reader. */

/* The padding is the room the pieces need once they are standing: they rise
   off the book's lower edge, so the stage reserves it above the book and
   keeps the whole spread, pieces included, centred in the pinned screen. */
.sp-pop-stage { min-width: 0; padding: 13% 4% 7%; perspective: 1300px; perspective-origin: 50% 25%; }
/* The office's walls stand higher than the town's buildings and its sheets
   fly off the top of the room, so this book needs more sky above it. Its
   height is also what keeps the standing walls inside their own section
   instead of reaching up into the gradient above. */
.sp-pop-act--evidence .sp-pop-stage { padding: 20% 5% 0; }
/* Stacked under the text, the stage runs the full width: without side
   padding the closed cover, which lands on the book's right half and
   overhangs it, would be cut by the window's edge. */
@media (max-width: 1023px) {
  .sp-pop-stage { padding: 20% 8% 4%; }
  .sp-pop-act--evidence .sp-pop-stage { padding: 24% 8% 0; }
}
.sp-pop-book {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 1.25;
  transform-style: preserve-3d;
  transform: rotateX(54deg);
}
.sp-pop-board {
  position: absolute;
  inset: -2.5% -2% -2.5% 50%;
  background: #1b2a41;
  border-radius: 0 10px 10px 0;
  transform: translateZ(-3px);
  box-shadow: 0 40px 60px -20px rgba(10, 17, 28, 0.45);
}
.sp-pop-page { position: absolute; top: 0; height: 100%; width: 50%; transform-style: preserve-3d; }
.sp-pop-page--right { left: 50%; border-radius: 0 6px 6px 0; }
.sp-pop-leaf {
  position: absolute;
  left: 0;
  top: 0;
  width: 50%;
  height: 100%;
  transform-origin: 100% 50%;
  transform-style: preserve-3d;
  transform: translateZ(2px) rotateY(0deg);
}
.sp-pop-leaf::before {
  content: "";
  position: absolute;
  inset: -2.5% 0 -2.5% -4%;
  background: #1b2a41;
  border-radius: 10px 0 0 10px;
  transform: translateZ(-0.5px);
}
.sp-pop-leaf .sp-pop-page { left: 0; width: 100%; border-radius: 6px 0 0 6px; }
.sp-pop-paper { position: absolute; inset: 0; border-radius: inherit; background-color: #f5f7f9; backface-visibility: hidden; }
.sp-pop-page--left .sp-pop-paper { box-shadow: inset -30px 0 30px -24px rgba(27, 42, 65, 0.35); }
.sp-pop-page--right .sp-pop-paper { box-shadow: inset 30px 0 30px -24px rgba(27, 42, 65, 0.35); }
.sp-pop-cover {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: end;
  gap: 6px;
  padding: 9%;
  border-radius: 6px 0 0 6px;
  background: #22344f;
  color: #ffffff;
  transform: rotateY(180deg) translateZ(1px);
  backface-visibility: hidden;
}
.sp-pop-cover small { font-size: clamp(0.5625rem, 1.1vw, 0.75rem); font-weight: 600; letter-spacing: 0.14em; line-height: 1; text-transform: uppercase; color: #c7eeff; }
.sp-pop-cover strong { font-size: clamp(1.0625rem, 2.5vw, 1.875rem); font-weight: 700; line-height: 1.08; }
.sp-pop-cover img { position: absolute; top: 10%; left: 9%; width: 20%; }
.sp-pop-cover--evidence { background: #14202f; }

/* Printed decor: streets and lawns for the town, a parquet for the office. */
.sp-pop-book--town .sp-pop-paper {
  background-image:
    linear-gradient(transparent 63%, #dce2e8 63% 71%, transparent 71%),
    repeating-linear-gradient(90deg, transparent 0 22px, #f5f7f9 22px 34px),
    linear-gradient(transparent 66.6%, #c9d2db 66.6% 67.4%, transparent 67.4%),
    radial-gradient(ellipse 30% 14% at 82% 88%, #dcebd6 98%, transparent 100%),
    radial-gradient(ellipse 26% 12% at 14% 20%, #dcebd6 98%, transparent 100%);
}
.sp-pop-book--office .sp-pop-paper { background-image: repeating-linear-gradient(90deg, #efe6da 0 30px, #e8dccb 30px 31px); }

/* The pieces that stand up. --lean is the angle each one settles at, read
   by the driver too, so the still and the animation agree. --pad is the
   transparent margin the baked die-cut edge needed (scripts/bake_diecut.py):
   the piece hangs and hinges on the drawing's foot, that much above the
   file's own bottom edge, so adding the margin moved nothing. */
.sp-pop-piece {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1%);
  transform-origin: 50% calc(100% - var(--pad, 0) * 1%);
  transform: translate(-50%, calc(-100% + var(--pad, 0) * 1%)) translateZ(0.6px) rotateX(calc(var(--lean, -70) * 1deg));
}
/* The white border and the short shadow are drawn into the files, once, by
   scripts/bake_diecut.py. They were an SVG filter, which Chrome recomputed
   on every frame because a piece's 3D rotation changes its rasterisation
   scale: a tenth of the frames fell under 30fps on a throttled phone. */
.sp-pop-photo { display: block; width: 100%; height: auto; }
/* A room's layers share the floor's frame; each turns on its own hinge. */
.sp-pop-room { transform-style: preserve-3d; }
.sp-pop-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform-origin: var(--ox) var(--oy);
  transform: translateZ(calc(var(--z) * 0.2px));
}
/* Cast by the driver only (it measures each piece's angle), so the still
   carries none: a flat book is still a readable one. */
.sp-pop-shade {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--w) * 1.05%);
  aspect-ratio: 3 / 1;
  transform-origin: 50% 100%;
  /* Its own bottom already sits where the drawing's foot does, so the
     piece's --pad, a share of the piece's height, does not apply here. */
  transform: translate(-50%, -100%) translateZ(0.3px) scaleY(0);
  background: radial-gradient(closest-side, rgba(27, 42, 65, 0.36), transparent);
  opacity: 0;
  pointer-events: none;
}

/* The sheets leaving the printer. The 3D pieces clip whatever overflows
   them, so the sheets fly in a flat layer over the stage, starting from the
   output marker inside the room. */
.sp-pop-sheets { position: absolute; left: calc(var(--sx) * 1%); top: calc(var(--sy) * 1%); width: 1px; height: 1px; pointer-events: none; }
.sp-pop-flyer { position: absolute; inset: 0; z-index: 5; perspective: 700px; pointer-events: none; }
.sp-pop-sheet {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--sheet-w, 40px);
  aspect-ratio: 21 / 29.7;
  translate: -50% -70%;
  border-radius: 2px;
  background:
    linear-gradient(#1b2a41, #1b2a41) 14% 14% / 46% 5% no-repeat,
    repeating-linear-gradient(transparent 0 6px, #c9d3dc 6px 7.5px) 14% 34% / 72% 50% no-repeat,
    #ffffff;
  box-shadow: 0 6px 12px -6px rgba(27, 42, 65, 0.45);
  will-change: transform, opacity;
}

/* ---------- Driven: pinned stages, one text at a time ---------- */

.sp-pop-live .sp-pop-act--territory { height: 460vh; }
.sp-pop-live .sp-pop-act--evidence { height: 340vh; }
@media (max-width: 1023px) { .sp-pop-live .sp-pop-act--territory { height: 420vh; } }
.sp-pop-live .sp-pop-pin {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100svh;
  padding-block: 64px 24px;
}
@media (max-width: 1023px) { .sp-pop-live .sp-pop-pin { align-content: center; gap: 4px; padding-block: 64px 12px; } }
/* Two layers share one cell: the title, then the product list that takes
   its place. Inside the list the products do NOT share a cell, so Cantoche
   stays where it is and in reach once Allegro lights up beneath it. */
.sp-pop-live .sp-pop-copy { gap: 0; }
.sp-pop-live .sp-pop-step,
.sp-pop-live .sp-pop-products { grid-area: 1 / 1; align-content: center; }
.sp-pop-live :where(.sp-pop-step, .sp-pop-products, .sp-pop-product) { transition: opacity 450ms ease, transform 450ms ease; }
.sp-pop-live :where(.sp-pop-step, .sp-pop-product):not(.is-on) { opacity: 0; transform: translateY(14px); pointer-events: none; }
.sp-pop-live .sp-pop-products:not(.is-on) { opacity: 0; pointer-events: none; }
/* Hidden copy keeps its place in the layout but must leave the tab order. */
.sp-pop-live [aria-hidden="true"] a { visibility: hidden; }
.sp-pop-live .sp-pop-leaf { transform: translateZ(2px) rotateY(180deg); }
.sp-pop-live .sp-pop-piece--spread, .sp-pop-live .sp-pop-piece--act { opacity: 0; }
.sp-pop-live .sp-pop-layer { opacity: 0; }
/* The pieces answer the pointer once they are up. */
.sp-pop-live .sp-pop-piece { cursor: pointer; }

/* ---------- Below 1024: the first book is not driven ----------
   Both products must be reachable at once (Paul, 2026-11-18), and a phone
   screen cannot hold two product blocks and the spread together: measured
   at 375 the pair needs 669px and the book 257px, where a pinned screen
   offers 664px, which cut the top off Cantoche and the foot off the book.
   A block cut in half is worse than a still, so this act stops being
   driven here and serves its finished picture, both products in the flow
   and in reach. The second book's copy is one block, so it fits a pinned
   phone screen and keeps its animation at every width. The driver reads
   the pin's position, so this query alone decides it. */
@media (max-width: 1023px) {
  .sp-pop-live .sp-pop-act--territory { height: auto; }
  .sp-pop-live .sp-pop-act--territory .sp-pop-pin {
    position: static;
    height: auto;
    gap: 32px;
    padding-block: 112px 56px;
  }
  .sp-pop-live .sp-pop-act--territory .sp-pop-copy { gap: 48px; }
  /* Written out rather than wrapped in :where(), which would zero the
     specificity and lose to .sp-pop-products:not(.is-on) above. */
  .sp-pop-live .sp-pop-act--territory .sp-pop-step,
  .sp-pop-live .sp-pop-act--territory .sp-pop-products { grid-area: auto; }
  .sp-pop-live .sp-pop-act--territory .sp-pop-step,
  .sp-pop-live .sp-pop-act--territory .sp-pop-products,
  .sp-pop-live .sp-pop-act--territory .sp-pop-product {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    transition: none;
  }
  .sp-pop-live .sp-pop-act--territory [aria-hidden="true"] a { visibility: visible; }
  /* The book is already open here, so the cue would promise nothing. */
  .sp-pop-live .sp-pop-act--territory .sp-pop-cue { display: none; }
  .sp-pop-live .sp-pop-act--territory .sp-pop-leaf { transform: translateZ(2px) rotateY(0deg); }
  .sp-pop-live .sp-pop-act--territory .sp-pop-piece--spread,
  .sp-pop-live .sp-pop-act--territory .sp-pop-piece--act,
  .sp-pop-live .sp-pop-act--territory .sp-pop-layer { opacity: 1; }
  .sp-pop-live .sp-pop-act--territory .sp-pop-piece { cursor: auto; }
}
