/* ==========================================================================
   Knowledge: a book taken off the shelf opens into a reading sheet.
   Loaded by the Knowledge page only, after style.css (which keeps the shelves,
   the spines and the small cards). Behaviour: assets/js/library.js.
   The book is three boards (spine, front cover, back board with its pages) in
   one 3D context; the sheet is an ordinary flat element laid over the page.
   Everything that moves is a transform or an opacity, driven by library.js
   through the Web Animations API; nothing here animates on its own.
   ========================================================================== */

/* Without JavaScript: a book reached by its address shows its card, and on narrow screens (where the card is a panel
   at the foot of the screen that style.css opens on a tap) hovering or focusing a spine opens it */
.library .book { scroll-margin-top: clamp(15rem, 42vh, 24rem); }   /* room above a book reached by its address, for its card */
.no-js .book:target .spine { transform: translateY(-1.1rem); }
.no-js .book:target .book-card { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.no-js .book:is(:first-child, :nth-child(2), :last-child, :nth-last-child(2)):target .book-card { transform: translate(0, 0); }
@media (max-width: 1100px) {
  .no-js .library .books .book:is(:hover, :focus-within, :target):not(.is-open) .book-card { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
}

/* While a sheet is open the page behind keeps still (the gutter is kept, so nothing shifts sideways) and shows no card */
html.lib-on { overflow: hidden; scrollbar-gutter: stable; }
html.lib-on .library .books .book .book-card, .library .books .book.is-out .book-card { opacity: 0; pointer-events: none; }
/* the book that is out leaves its place empty, held at the height of a pulled spine; it comes back down when it returns */
.library .book.is-out .spine { opacity: 0; transform: translateY(-1.1rem); transition: none; }

/* The overlay ------------------------------------------------------------------ */
.lib-layer { position: fixed; inset: 0; z-index: 250; --lib-page: #EFE6D6; --lib-ink: #1D1617; --lib-ox: #522623; --lib-gilt: #D9B45A; --lib-rule: rgba(82, 38, 35, 0.22);
  --lib-leather: linear-gradient(90deg, color-mix(in srgb, var(--spine, #5A2A26) 58%, #000) 0, var(--spine, #5A2A26) 7%, color-mix(in srgb, var(--spine, #5A2A26) 90%, #fff) 48%, var(--spine, #5A2A26) 82%, color-mix(in srgb, var(--spine, #5A2A26) 70%, #000) 100%); }
.lib-layer.is-closing, .lib-layer.is-leaving { pointer-events: none; }
.lib-scrim { position: absolute; inset: 0; background: rgba(15, 10, 11, 0.8); opacity: 0; touch-action: none; }
.lib-layer.is-leaving .lib-scrim { visibility: hidden; }
.lib-stage { position: absolute; inset: 0; perspective: 2200px; perspective-origin: 50% 50%; pointer-events: none; }

/* The book: its box is the front cover's place when the book is open (left edge = the hinge); library.js writes the box
   (--lib-x, --lib-y, --lib-w, --lib-h) and the height of the spine on its shelf (--lib-sh) */
.lib-settle, .lib-fly, .lib-book, .lib-cover { position: absolute; inset: 0; transform-style: preserve-3d; transform-origin: 0 50%; }
.lib-settle { inset: auto; left: var(--lib-x); top: var(--lib-y); width: var(--lib-w); height: var(--lib-h); }
.lib-book { transform: rotateY(90deg); }
.lib-cover { transform: translateZ(1px) rotateY(0deg); }
.lib-back, .lib-page, .lib-cover-out, .lib-cover-in { position: absolute; inset: 0; opacity: 0; }
.lib-back { transform: translateZ(-1px); border-radius: 2px 7px 7px 2px; background: var(--lib-leather); box-shadow: 0 28px 60px rgba(0, 0, 0, 0.55); }
.lib-page, .lib-sheet { background: linear-gradient(90deg, rgba(29, 22, 23, 0.2) 0, rgba(29, 22, 23, 0.06) 1.1rem, rgba(29, 22, 23, 0) 3rem), var(--lib-page); border-radius: 0 3px 3px 0; }
.lib-page { inset: 8px 8px 8px 0; -webkit-backface-visibility: hidden; backface-visibility: hidden; }
/* the spine as it stood on the shelf (a copy of the button, at its own size), hinged on its right edge */
.lib-spine { position: absolute; right: 100%; top: 50%; margin-top: calc(var(--lib-sh) / -2); transform-origin: 100% 50%; -webkit-backface-visibility: hidden; backface-visibility: hidden; }
.lib-spine .spine { display: grid; pointer-events: none; transition: none; box-shadow: inset -3px 0 0 rgba(0, 0, 0, 0.22), 0 14px 22px rgba(0, 0, 0, 0.35); }
.lib-cover-out, .lib-cover-in { -webkit-backface-visibility: hidden; backface-visibility: hidden; }
/* the front cover: leather in the spine's tone, a gilt double rule, the short title on its panel, the year at the foot */
.lib-cover-out { border-radius: 2px 7px 7px 2px; background: var(--lib-leather); display: grid; grid-template-rows: 1fr auto 1fr; justify-items: center; padding: 3.4rem 2.6rem 2.4rem; color: #E9D2A6; text-align: center; }
.lib-cover-out::before, .lib-cover-out::after { content: ""; position: absolute; border: 1px solid rgba(217, 180, 90, 0.75); border-radius: 2px; pointer-events: none; }
.lib-cover-out::before { inset: 1rem; } .lib-cover-out::after { inset: 1.35rem; border-color: rgba(217, 180, 90, 0.4); }
.lib-cover-title { grid-row: 2; margin: 0; max-width: 100%; padding: 1.1rem 1.3rem; border-radius: 3px; background: color-mix(in srgb, var(--spine, #5A2A26) 55%, #000); box-shadow: inset 0 0 0 1px rgba(217, 180, 90, 0.55); font-family: var(--font-serif); font-weight: 600; font-variation-settings: "opsz" 72, "SOFT" 40; font-size: clamp(1.4rem, 1rem + 1.6vw, 2.1rem); line-height: 1.1; letter-spacing: 0.01em; overflow-wrap: anywhere; }
.lib-cover-year { grid-row: 3; align-self: end; margin: 0; font-family: var(--font-mono); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.14em; color: var(--lib-gilt); }
/* inside the front cover: the marbled endpaper (the space's own pattern) within the leather turn-in, and the shelf's plate */
.lib-cover-in { transform: rotateY(180deg); border-radius: 7px 2px 2px 7px; background: var(--lib-leather); box-shadow: 0 28px 60px rgba(0, 0, 0, 0.55); display: grid; place-items: center; padding: 2.6rem; }
.lib-cover-in::before { content: ""; position: absolute; inset: 8px 0 8px 8px; border-radius: 3px 0 0 3px; background: #2A1D1C url("/assets/img/pattern-knowledge.webp?v=9d1687b164") center / cover; box-shadow: inset -1.4rem 0 1.6rem -1rem rgba(0, 0, 0, 0.6); }
.lib-plate { position: relative; max-width: 100%; padding: 1.1rem 1.3rem 1.2rem; text-align: center; background: var(--lib-page); color: var(--lib-ink); border-radius: 2px; box-shadow: inset 0 0 0 1px var(--lib-page), inset 0 0 0 2px rgba(82, 38, 35, 0.55), inset 0 0 0 5px var(--lib-page), inset 0 0 0 6px rgba(82, 38, 35, 0.3), 0 6px 16px rgba(0, 0, 0, 0.4); }
.lib-plate-span { margin: 0 0 0.45rem; font-family: var(--font-mono); font-size: 0.6rem; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--lib-ox); }
.lib-plate-name { margin: 0; font-family: var(--font-serif); font-weight: 600; font-variation-settings: "opsz" 36, "SOFT" 40; font-size: 1.05rem; line-height: 1.15; }
.lib-layer:not(.is-spread) .lib-plate { display: none; }

/* The sheet: the book's first page, with what the registry records --------------- */
.lib-sheet { position: absolute; left: var(--lib-x); top: calc(var(--lib-y) + 8px); width: calc(var(--lib-w) - 8px); height: calc(var(--lib-h) - 16px); display: flex; flex-direction: column; color: var(--lib-ink); opacity: 0; pointer-events: none; outline: none; }
.lib-layer.is-open .lib-sheet { pointer-events: auto; }
.lib-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 2rem 1.7rem 0.6rem 2.3rem; }
.lib-kicker { margin: 0 3.2rem 1.1rem 0; font-family: var(--font-mono); font-size: 0.64rem; font-weight: 600; letter-spacing: 0.12em; line-height: 1.5; text-transform: uppercase; color: var(--lib-ox); }
.lib-title { margin: 0 0 0.7rem; font-family: var(--font-serif); font-weight: 600; font-variation-settings: "opsz" 72, "SOFT" 40; font-size: clamp(1.3rem, 1.05rem + 0.9vw, 1.8rem); line-height: 1.14; letter-spacing: -0.01em; text-transform: none; text-wrap: balance; overflow-wrap: anywhere; }
.lib-with { margin: 0 0 0.4rem; font-size: 0.92rem; font-style: italic; color: #5C5450; }
.lib-facts { margin: 1.1rem 0 1.3rem; border-top: 1px solid var(--lib-rule); }
.lib-facts > div { display: grid; grid-template-columns: 5.4rem minmax(0, 1fr); gap: 0.8rem; padding: 0.55rem 0; border-bottom: 1px solid var(--lib-rule); }
.lib-facts dt { padding-top: 0.2rem; font-family: var(--font-mono); font-size: 0.62rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--lib-ox); }
.lib-facts dd { margin: 0; font-size: 0.92rem; line-height: 1.38; }
.lib-go { margin: 0; }
.lib-go .book-link { display: inline-flex; align-items: center; gap: 0.5em; min-height: 2.75rem; padding: 0.55rem 1rem; border-radius: 0.5rem; background: var(--lib-ox); color: var(--lib-page); font-size: 0.74rem; font-weight: 600; text-decoration: none; }
.lib-go .book-link:hover { background: #3B1A18; }
.lib-go .book-link.none { padding: 0; min-height: 0; background: none; color: #5C5450; }
.lib-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.7rem 1.2rem 0.9rem 1.8rem; font-family: var(--font-mono); font-size: 0.64rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--lib-ox); }
.lib-step { display: inline-flex; align-items: center; gap: 0.5em; height: 2.75rem; padding: 0 0.95rem; border: 1px solid rgba(82, 38, 35, 0.4); border-radius: 999px; background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; transition: background-color 0.25s ease, color 0.25s ease; }
.lib-step:not(:disabled):hover { background: var(--lib-ox); color: var(--lib-page); }
.lib-step:disabled { opacity: 0.32; cursor: default; }
.lib-close { position: absolute; top: 0.7rem; right: 0.7rem; z-index: 1; width: 2.75rem; height: 2.75rem; padding: 0; border: 1px solid rgba(82, 38, 35, 0.4); border-radius: 50%; background: var(--lib-page); color: var(--lib-ox); transition: background-color 0.25s ease, color 0.25s ease; }
.lib-close::before, .lib-close::after { content: ""; position: absolute; left: 50%; top: 50%; width: 1rem; height: 2px; margin: -1px 0 0 -0.5rem; border-radius: 2px; background: currentColor; transform: rotate(45deg); }
.lib-close::after { transform: rotate(-45deg); }
.lib-close:hover { background: var(--lib-ox); color: var(--lib-page); }
.lib-sheet :is(a, button):focus-visible { outline: 2px solid var(--lib-ox); outline-offset: 2px; }
.lib-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
@media (max-width: 640px) {
  .lib-body { padding: 1.7rem 1.2rem 0.5rem 1.6rem; }
  .lib-foot { padding: 0.6rem 0.8rem 0.8rem 1.3rem; }
  .lib-cover-out { padding: 3rem 1.9rem 2.1rem; }
}
