/* CENSENSE — product experience layer.
   Loaded after site.css on the home pages and the publication pages only.
   It adds exactly two things and overrides nothing else:
   (1) MODIFICATION 1 — the Gumroad mark inside the "Obtenir le livre numérique" / "Get the digital book" buttons;
   (2) MODIFICATION 2 — the 3D book that progressively enhances the existing cover preview. */

/* ===== MODIFICATION 1 — Gumroad mark inside the purchase buttons ===== */
.button[data-purchase] { position: relative; }
.button-gumroad {
  position: absolute;
  top: 7px;
  right: 11px;
  width: 20px;
  height: 20px;
  display: block;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== MODIFICATION 2 — 3D book (progressive enhancement of the existing cover preview) ===== */
/* The original cover button stays in the page as the layout reference and as the fallback; once the 3D book is
   ready it is only made invisible (visibility), so nothing around it moves. */
.book-scene.is-3d > .book-image-toggle { visibility: hidden; }
.book-scene.is-3d { padding-bottom: 12px; }
.book-scene.is-3d > .book-interaction-hint { position: relative; z-index: 2; }
.book-scene:not(.is-3d) > .book3d-hit { display: none; }
.book-scene > .book3d { opacity: 0; transition: opacity calc(.5s / 1.7) ease; }
.book-scene.is-3d > .book3d { opacity: 1; }

.book3d {
  --bw: 300px;                       /* book width, set from the real preview size by the script */
  --w: var(--bw);
  --h: calc(var(--bw) * 1.5);       /* the cover asset is 1024 x 1536 */
  --t: calc(var(--bw) * .118);      /* thickness of the closed book */
  --ct: calc(var(--bw) * .013);     /* thickness of a hard cover board */
  --oh: calc(var(--bw) * .022);     /* cover overhang at the fore-edge */
  --ohy: calc(var(--bw) * .014);    /* cover overhang at head and tail */
  --tx: 0px; --ty: 0px; --tz: 0px; --rx: -6deg; --ry: 20deg; --open: 0;
  --dur: 1800ms; --odur: 1800ms; --ease: cubic-bezier(.45, 0, .2, 1); --oease: cubic-bezier(.45, 0, .2, 1);
  --sweep: -120%; --sweep-dur: 0ms; --gutter: 0; --pv: 0; --ps: 0; --sh: 1; --cv: 1; --cvt: 0ms; --cvd: 0ms;
  --leather: #0a2d86;
  position: absolute;
  z-index: 1;
  pointer-events: none;
  contain: layout style;
}
.book3d-view {
  position: absolute;
  inset: 0;
  perspective: calc(var(--bw) * 4.4);
  perspective-origin: 50% 50%;
}
.book3d-cam {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transform: translate3d(var(--tx), var(--ty), var(--tz)) rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform var(--dur) var(--ease);
  will-change: transform;
}
.book3d-obj {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--w);
  height: var(--h);
  margin: calc(var(--h) / -2) 0 0 calc(var(--w) / -2);
  transform-style: preserve-3d;
}
.book3d-obj > *, .b-cover > * { position: absolute; display: block; margin: 0; }
.b-cover > img, .b-pages > img { display: block; width: 100%; height: 100%; max-width: none; }

/* contact shadow on the surface the book rests on */
.b-shadow {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--w) * 1.55); height: calc(var(--w) * .62);
  margin: calc(var(--w) * -.31) 0 0 calc(var(--w) * -.775);
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 4, 20, .62) 0%, rgba(0, 4, 20, .34) 38%, rgba(0, 4, 20, 0) 70%);
  transform: translateY(calc(var(--h) / 2 + 1px)) rotateX(90deg);
  opacity: var(--sh); transition: opacity var(--dur) var(--ease);
}

/* leather surfaces that the supplied cover photograph does not show (spine, back board, board edges) */
.b-leather, .b-back, .b-spine, .b-ce-top, .b-ce-bottom, .b-ce-fore {
  background-color: var(--leather);
  background-image: url("/assets/cover-texture.webp");
  background-size: calc(var(--bw) * .46) auto;
}
.b-back { left: 0; top: 0; width: var(--w); height: var(--h); transform: translateZ(calc(var(--t) / -2)) rotateY(180deg); backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.b-spine {
  left: calc((var(--w) - var(--t)) / 2); top: 0; width: var(--t); height: var(--h);
  transform: translateX(calc(var(--w) / -2)) rotateY(-90deg);
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.b-spine::after, .b-back::after { content: ""; position: absolute; inset: 0; }
.b-spine::after { background: linear-gradient(90deg, rgba(0, 8, 40, .42), rgba(120, 170, 255, .16) 28%, rgba(0, 8, 40, .05) 55%, rgba(0, 8, 40, .46)); }
.b-back::after { background: linear-gradient(0deg, rgba(0, 6, 30, .35), rgba(0, 6, 30, .15)); }

/* page block: edges are drawn from the paper tone; the front face is the authentic prologue page */
.b-fore, .b-top, .b-bottom { background-color: #dcdcd3; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.b-fore {
  left: calc((var(--w) - (var(--t) - 2 * var(--ct))) / 2); top: var(--ohy);
  width: calc(var(--t) - 2 * var(--ct)); height: calc(var(--h) - 2 * var(--ohy));
  transform: translateX(calc(var(--w) / 2 - var(--oh))) rotateY(90deg);
  background-image: linear-gradient(90deg, rgba(8, 18, 48, .30), rgba(8, 18, 48, .06) 45%, rgba(8, 18, 48, .24)), repeating-linear-gradient(90deg, #e9e9e1 0, #e9e9e1 1px, #c4c4b9 1px, #c4c4b9 2px);
}
.b-top, .b-bottom {
  left: 0; width: calc(var(--w) - var(--oh)); height: calc(var(--t) - 2 * var(--ct));
  top: calc((var(--h) - (var(--t) - 2 * var(--ct))) / 2);
  background-image: linear-gradient(90deg, rgba(8, 18, 48, .30), rgba(8, 18, 48, .08) 40%, rgba(8, 18, 48, .18)), repeating-linear-gradient(180deg, #e9e9e1 0, #e9e9e1 1px, #c4c4b9 1px, #c4c4b9 2px);
}
.b-top { transform: translateY(calc(var(--h) / -2 + var(--ohy))) rotateX(90deg); }
.b-bottom { transform: translateY(calc(var(--h) / 2 - var(--ohy))) rotateX(-90deg); filter: brightness(.62); }
.b-pages {
  left: 0; top: var(--ohy); width: calc(var(--w) - var(--oh)); height: calc(var(--h) - 2 * var(--ohy));
  background: #fbfbf9;
  transform: translateZ(calc(var(--t) / 2 - var(--ct) - .6px));
  overflow: hidden;
  opacity: var(--pv); transition: opacity var(--odur) var(--oease);
}
.b-pages > img { object-fit: contain; clip-path: inset(0 0 .35% 0); }
.b-pages::before { content: ""; position: absolute; inset: 0; z-index: 1; opacity: var(--ps); transition: opacity var(--odur) var(--oease); background: linear-gradient(90deg, rgba(6, 16, 44, .62), rgba(6, 16, 44, .38) 55%, rgba(6, 16, 44, .16)); pointer-events: none; }
.b-pages::after { content: ""; position: absolute; inset: 0; z-index: 2; opacity: var(--gutter); transition: opacity var(--odur) var(--oease); background: linear-gradient(90deg, rgba(10, 20, 50, .24), rgba(10, 20, 50, 0) 9%); pointer-events: none; }

/* front board, hinged at the spine */
.b-cover {
  left: 0; top: 0; width: var(--w); height: var(--h);
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  transform: translateZ(calc(var(--t) / 2)) rotateY(calc(var(--open) * -1deg));
  transition: transform var(--odur) var(--oease);
  will-change: transform;
}
.b-cover-front, .b-cover-inner { left: 0; top: 0; width: 100%; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; overflow: hidden; }
.b-cover-front { border-radius: 1px calc(var(--bw) * .012) calc(var(--bw) * .012) 1px; }
.b-cover-inner { transform: translateZ(calc(var(--ct) * -1)) rotateY(180deg); background: linear-gradient(90deg, #dfe5ef, #f4f6fa 12%, #f6f8fb); }
.b-cover-inner::after { content: ""; position: absolute; inset: 0; background: linear-gradient(270deg, rgba(10, 20, 50, .16), rgba(10, 20, 50, 0) 9%); }
.b-cover-front::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(104deg, rgba(255, 255, 255, 0) 32%, rgba(255, 255, 255, .15) 46%, rgba(196, 218, 255, .1) 52%, rgba(255, 255, 255, 0) 66%);
  transform: translateX(var(--sweep)); transition: transform var(--sweep-dur) cubic-bezier(.4, 0, .25, 1);
}
.b-ce-top, .b-ce-bottom { left: 0; width: 100%; height: var(--ct); transform-origin: 50% 0; transform: rotateX(-90deg); }
.b-ce-top { top: 0; }
.b-ce-bottom { top: 100%; }
.b-ce-fore { left: 100%; top: 0; width: var(--ct); height: 100%; transform-origin: 0 50%; transform: rotateY(90deg); }
/* once open, the front board swings out of the frame instead of being cut by a window */
.b-cover > * { opacity: var(--cv); transition: opacity var(--cvt) linear var(--cvd); }

/* the control that replaces the original cover button: same footprint, same accessible behaviour */
.book3d-hit {
  position: absolute;
  z-index: 3;
  appearance: none;
  margin: 0; padding: 0; border: 0; background: transparent; color: inherit;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}
.book3d-hit:focus-visible { outline: 2px solid #e5efff; outline-offset: 6px; }

.book3d-controls { display: flex; justify-content: center; min-height: 34px; margin-top: 6px; }
.book3d-play {
  appearance: none; border: 0; border-bottom: 1px solid rgba(226, 237, 255, .5); background: transparent;
  color: #dce7fa; font: 500 10px/1.6 var(--sans); letter-spacing: .12em; text-transform: uppercase;
  padding: 7px 2px 5px; cursor: pointer; min-height: 34px; transition: color .16s ease, border-color .16s ease;
}
.book3d-play:hover { color: #fff; border-color: #fff; }
.book3d-play[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .book3d-cam, .b-cover, .b-cover > *, .b-cover-front::after, .b-pages::after { transition: none !important; }
}
