/* ============================================================
   LIBRARY SHELF — the shared look of the Library's book pages: The
   Reading Room (paid-book.html), Business Books and Playbooks
   (playbooks.html) and Recommended Business Books
   (recommended-books.html). library-shelf.js renders the markup.

   Modelled on how online bookshops and libraries present books: the
   cover is the interface. Every title is a portrait cover with a spine,
   page edges and its ribbon; without an uploaded cover image, a typeset
   Elowen cover is drawn from the title. Clicking a cover opens its book
   page (a side sheet): large cover, title, author, price, the main
   action, description, details and more from the shelf.

   Uses the pages' own tokens (--dark-green, --gold-dark, ...).
   ============================================================ */

/* ---------- The cover ---------- */
.lib-cover {
  --c: var(--dark-green, #0C1E14);
  position: relative; display: block; container-type: inline-size; aspect-ratio: 2 / 3; width: 100%;
  border-radius: 3px 7px 7px 3px; background: var(--c); color: #FAF9F6; isolation: isolate;
  /* The page block behind the cover, and its shadow on the shelf. */
  box-shadow:
    3px 3px 0 -1px #F6F1E7, 3px 3px 0 0 rgba(12, 30, 20, 0.1),
    6px 6px 0 -1px #EFE8DA, 6px 6px 0 0 rgba(12, 30, 20, 0.08),
    0 28px 40px -22px rgba(12, 30, 20, 0.6);
  transition: transform 500ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 500ms cubic-bezier(0.16, 1, 0.3, 1);
}
.lib-cover-face { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; }
.lib-cover-face img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
/* Spine fold, edge light and a soft sheen, over photo covers too. */
.lib-cover-face::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.32) 0%, rgba(255, 255, 255, 0.16) 2.4%, rgba(0, 0, 0, 0.12) 4.6%, rgba(0, 0, 0, 0) 9%),
    linear-gradient(160deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, 0.12) 100%);
}

/* Typeset cover, when no image was uploaded. */
.lib-cover-art {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 12cqw 10cqw 10cqw 14cqw;
  background:
    radial-gradient(120% 80% at 100% 0%, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 60%),
    var(--c);
}
.lib-cover-art::before {
  content: ''; position: absolute; inset: 5cqw 5cqw 5cqw 9cqw; border: 1px solid rgba(229, 198, 151, 0.42); border-radius: 2px; pointer-events: none;
}
.lib-cover-mark { font-family: 'Montserrat', sans-serif; font-size: 4.6cqw; font-weight: 700; letter-spacing: 0.32em; text-transform: uppercase; color: var(--gold-light, #E5C697); }
.lib-cover-title {
  margin-top: auto; font-family: 'Playfair Display', serif; font-weight: 400; font-size: 11cqw; line-height: 1.12; color: #FAF9F6;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; text-wrap: balance;
}
.lib-cover-rule { width: 18cqw; height: 1px; margin: 7cqw 0 5cqw; background: var(--gold-light, #E5C697); }
.lib-cover-author { font-family: 'Montserrat', sans-serif; font-size: 4.4cqw; font-weight: 500; line-height: 1.35; color: rgba(250, 249, 246, 0.82); }
.lib-cover-edition { margin-top: 2cqw; font-family: 'Playfair Display', serif; font-style: italic; font-size: 5cqw; color: var(--gold-light, #E5C697); }

/* Playbooks: a workbook — cream paper, a coloured band, a stitched spine. */
.lib-cover--playbook { background: #F4EDE0; color: var(--dark-green, #0C1E14); }
.lib-cover--playbook .lib-cover-art { background: linear-gradient(180deg, var(--c) 0 34%, #F4EDE0 34% 100%); padding: 10cqw 10cqw 10cqw 15cqw; }
.lib-cover--playbook .lib-cover-art::before { border-color: rgba(145, 117, 81, 0.35); }
.lib-cover--playbook .lib-cover-art::after {
  content: ''; position: absolute; top: 4cqw; bottom: 4cqw; left: 6.5cqw; border-left: 1.5px dashed rgba(145, 117, 81, 0.5);
}
.lib-cover--playbook .lib-cover-mark { color: #FAF9F6; }
.lib-cover--playbook .lib-cover-kind { margin-top: 3cqw; font-family: 'Playfair Display', serif; font-style: italic; font-size: 7cqw; color: var(--gold-light, #E5C697); }
.lib-cover--playbook .lib-cover-title { margin-top: 30cqw; color: var(--dark-green, #0C1E14); font-size: 10.5cqw; }
.lib-cover--playbook .lib-cover-rule { background: var(--gold-dark, #917551); }
.lib-cover--playbook .lib-cover-author { color: var(--text-muted, #5A6D60); }

/* The ribbon marker hanging from the top edge. */
.lib-cover-ribbon {
  position: absolute; top: -3px; right: 14%; z-index: 3; width: 9%; height: 17%;
  background: var(--ribbon, var(--gold-dark, #917551)); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.25));
}
/* A shop sticker on the top-left corner: Save, Complete set, Free. */
.lib-cover-badge {
  position: absolute; z-index: 3; left: -8px; top: 10px; padding: 0.32rem 0.65rem; border-radius: 999px; transform: rotate(-4deg);
  font-family: 'Montserrat', sans-serif; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--gold-light, #E5C697); color: var(--dark-green, #0C1E14); box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.45);
}

/* ---------- Toolbar: search, categories, count ---------- */
.lib-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem 2rem; margin-bottom: 1.6rem; }
.lib-head .section-tag, .lib-kicker { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-dark, #917551); margin-bottom: 0.7rem; }
.lib-head h2 { font-family: 'Playfair Display', serif; font-weight: 400; font-size: clamp(1.7rem, 3vw, 2.4rem); line-height: 1.15; color: var(--dark-green, #0C1E14); }
.lib-head h2 em { font-style: italic; color: var(--gold-dark, #917551); }
.lib-count { font-size: 0.88rem; color: var(--text-muted, #5A6D60); }
.lib-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem 1.2rem; margin-bottom: 2.4rem; }
.lib-toolbar[hidden] { display: none; }
.lib-search { position: relative; flex: 0 1 320px; }
.lib-search svg { position: absolute; left: 1rem; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-muted, #5A6D60); pointer-events: none; }
.lib-search input {
  width: 100%; padding: 0.8rem 2.6rem 0.8rem 2.6rem; border-radius: 999px; border: 1px solid rgba(145, 117, 81, 0.28);
  background: rgba(255, 255, 255, 0.62); font: inherit; font-size: 0.9rem; color: var(--text-dark, #233027);
  transition: border-color 200ms ease, box-shadow 200ms ease, background-color 200ms ease;
}
.lib-search input:focus { outline: none; border-color: var(--gold-dark, #917551); background: #fff; box-shadow: 0 0 0 3px rgba(145, 117, 81, 0.15); }
.lib-search-clear {
  position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: none; color: var(--text-muted, #5A6D60); font-size: 1.1rem; cursor: pointer;
}
.lib-search-clear[hidden] { display: none; }
.lib-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.lib-chip {
  padding: 0.55rem 1rem; border-radius: 999px; border: 1px solid rgba(145, 117, 81, 0.28); background: rgba(255, 255, 255, 0.45);
  font: inherit; font-size: 0.84rem; font-weight: 500; color: var(--text-dark, #233027); cursor: pointer;
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease;
}
.lib-chip:hover { border-color: var(--gold-dark, #917551); }
.lib-chip[aria-pressed="true"] { background: var(--dark-green, #0C1E14); border-color: var(--dark-green, #0C1E14); color: #FAF9F6; }
.lib-chip:focus-visible, .lib-search input:focus-visible { outline: 2px solid var(--gold-dark, #917551); outline-offset: 2px; }

/* ---------- The shelf: covers first ---------- */
.lib-section { position: relative; max-width: 1240px; margin: 0 auto; padding: clamp(3rem, 6vw, 5rem) 6% clamp(2rem, 4vw, 3rem); scroll-margin-top: 90px; }
.lib-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: clamp(2.2rem, 4vw, 3.2rem) clamp(1.4rem, 3vw, 2.4rem); }
.lib-book { display: flex; flex-direction: column; min-width: 0; }
.lib-book[hidden] { display: none; }
.lib-book-cover { display: block; width: 100%; padding: 0 6px 6px 0; border: 0; background: none; cursor: pointer; perspective: 900px; }
.lib-book-cover:focus-visible { outline: 2px solid var(--gold-dark, #917551); outline-offset: 6px; border-radius: 6px; }
@media (hover: hover) and (pointer: fine) {
  .lib-book-cover:hover .lib-cover, .lib-spotlight-cover:hover .lib-cover {
    transform: translateY(-6px) rotateY(-9deg);
    box-shadow:
      3px 3px 0 -1px #F6F1E7, 3px 3px 0 0 rgba(12, 30, 20, 0.1),
      6px 6px 0 -1px #EFE8DA, 6px 6px 0 0 rgba(12, 30, 20, 0.08),
      14px 38px 46px -22px rgba(12, 30, 20, 0.62);
  }
}
.lib-book-meta { display: flex; flex-direction: column; gap: 0.3rem; padding-top: 1.2rem; flex: 1; }
.lib-book-tag { font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-dark, #917551); }
.lib-book-title { font-family: 'Playfair Display', serif; font-weight: 400; font-size: 1.12rem; line-height: 1.3; color: var(--dark-green, #0C1E14); }
.lib-book-title button { padding: 0; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.lib-book-title button:hover { text-decoration: underline; text-decoration-color: rgba(145, 117, 81, 0.6); text-underline-offset: 4px; }
.lib-book-author { font-size: 0.8rem; color: var(--text-muted, #5A6D60); }
.lib-book-desc { font-size: 0.84rem; line-height: 1.6; color: var(--text-muted, #5A6D60); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-top: 0.2rem; }
.lib-book-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; margin-top: auto; padding-top: 0.8rem; }
.lib-price { display: flex; align-items: baseline; gap: 0.45rem; font-family: 'Playfair Display', serif; font-size: 1.15rem; color: var(--dark-green, #0C1E14); }
.lib-price s { font-family: 'Montserrat', sans-serif; font-size: 0.8rem; color: var(--text-muted, #5A6D60); }
.lib-price--free { font-family: 'Montserrat', sans-serif; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold-dark, #917551); }
.lib-source { font-size: 0.78rem; color: var(--text-muted, #5A6D60); }

/* Buttons: dark-green pills, as the site's. */
.lib-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em; padding: 0.7rem 1.15rem; border-radius: 999px;
  font-family: 'Montserrat', sans-serif; font-size: 0.82rem; font-weight: 600; letter-spacing: 0.02em; text-decoration: none; white-space: nowrap; cursor: pointer;
  background: var(--dark-green, #0C1E14); color: #FAF9F6; border: 1px solid var(--dark-green, #0C1E14);
  transition: background-color 300ms ease, border-color 300ms ease, color 300ms ease, transform 160ms ease;
}
.lib-btn svg { width: 14px; height: 14px; flex: none; }
.lib-btn--ghost { background: rgba(255, 255, 255, 0.45); color: var(--dark-green, #0C1E14); border-color: rgba(12, 30, 20, 0.2); }
.lib-btn--lg { padding: 0.95rem 1.6rem; font-size: 0.92rem; }
.lib-btn--light { background: #FAF9F6; color: var(--dark-green, #0C1E14); border-color: #FAF9F6; }
.lib-btn--icon { width: 40px; height: 40px; padding: 0; }
.lib-btn--icon svg { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .lib-btn:hover { background: #163322; border-color: #163322; }
  .lib-btn--ghost:hover { background: rgba(255, 255, 255, 0.85); border-color: rgba(12, 30, 20, 0.4); }
  .lib-btn--light:hover { background: var(--gold-light, #E5C697); border-color: var(--gold-light, #E5C697); }
}
.lib-btn:active { transform: scale(0.97); }
.lib-btn:focus-visible { outline: 2px solid var(--gold-dark, #917551); outline-offset: 3px; }
.lib-btn.is-added { background: var(--gold-dark, #917551); border-color: var(--gold-dark, #917551); }
.lib-book-actions { display: flex; gap: 0.5rem; margin-top: auto; padding-top: 0.9rem; }

/* ---------- Spotlight: the featured title ---------- */
.lib-spotlight {
  position: relative; overflow: hidden; margin: 0 clamp(12px, 2vw, 28px); border-radius: 28px; color: #FAF9F6;
  background: radial-gradient(120% 140% at 100% 0%, #1C3B28 0%, var(--dark-green, #0C1E14) 60%);
}
.lib-spotlight-inner {
  display: grid; grid-template-columns: minmax(200px, 300px) minmax(0, 1fr); align-items: center; gap: clamp(2rem, 6vw, 5rem);
  max-width: 1100px; margin: 0 auto; padding: clamp(2.6rem, 6vw, 4.6rem) 6%;
}
.lib-spotlight-cover { display: block; padding: 0 6px 6px 0; border: 0; background: none; cursor: pointer; perspective: 900px; }
.lib-spotlight-cover .lib-cover { box-shadow: 3px 3px 0 -1px #F6F1E7, 6px 6px 0 -1px #EFE8DA, 0 40px 60px -26px rgba(0, 0, 0, 0.8); }
.lib-spotlight .lib-kicker { color: var(--gold-light, #E5C697); }
.lib-spotlight h2 { font-family: 'Playfair Display', serif; font-weight: 400; font-size: clamp(1.9rem, 3.6vw, 3rem); line-height: 1.12; margin-bottom: 0.7rem; }
.lib-spotlight-author { font-size: 0.9rem; color: rgba(250, 249, 246, 0.7); margin-bottom: 1.4rem; }
.lib-spotlight-desc { max-width: 36em; font-size: 1rem; line-height: 1.75; color: rgba(250, 249, 246, 0.82); margin-bottom: 1.8rem; }
.lib-spotlight .lib-price { color: #FAF9F6; font-size: 1.6rem; }
.lib-spotlight .lib-price s { color: rgba(250, 249, 246, 0.55); }
.lib-spotlight-row { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 1.4rem; }
.lib-spotlight .lib-btn--ghost { background: transparent; color: #FAF9F6; border-color: rgba(250, 249, 246, 0.35); }
@media (hover: hover) and (pointer: fine) { .lib-spotlight .lib-btn--ghost:hover { background: rgba(250, 249, 246, 0.1); border-color: rgba(250, 249, 246, 0.6); } }

/* ---------- Ambient light behind the shelf ---------- */
.lib-ambient {
  position: absolute; z-index: -1; top: 0; bottom: 0; left: calc(50% - 50vw); width: 100vw; overflow: hidden; pointer-events: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 12%, #000 88%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 12%, #000 88%, transparent 100%);
}
.lib-ambient-light { position: absolute; border-radius: 50%; will-change: transform; }
.lib-ambient-light--a { width: 62vw; height: 62vw; top: -14%; left: -18%; background: radial-gradient(closest-side, rgba(229, 198, 151, 0.4), transparent); animation: lib-drift-a 30s ease-in-out infinite alternate; }
.lib-ambient-light--b { width: 54vw; height: 54vw; bottom: -18%; right: -16%; background: radial-gradient(closest-side, rgba(255, 252, 245, 0.95), transparent); animation: lib-drift-b 36s ease-in-out infinite alternate; }
.lib-ambient-leaves { position: absolute; aspect-ratio: 1.4; background: url('/dx-leaves.webp') no-repeat center / contain; opacity: 0.12; will-change: transform; }
.lib-ambient-leaves--a { top: 2%; right: -6%; width: max(560px, 58vw); transform-origin: 100% 0; animation: lib-sway 9s ease-in-out infinite alternate; }
.lib-ambient-leaves--b { bottom: 6%; left: -8%; width: max(460px, 46vw); scale: -1 -1; opacity: 0.08; transform-origin: 0 100%; animation: lib-sway 12s ease-in-out -4s infinite alternate; }
.lib-section--ambient { isolation: isolate; }
@media (max-width: 560px) { .lib-ambient { opacity: 0.6; } }

/* ---------- Buy with confidence: a dark band with moving light and
   glass cards (paid-book.html). Gold light drifts and leaf shadows sway
   behind frosted panels; only transform and opacity animate, slowly,
   and it all pauses off screen (site-nav.js) and for reduced motion. */
.lib-assure {
  position: relative; isolation: isolate; overflow: hidden; margin-top: clamp(1rem, 3vw, 2rem); color: #FAF9F6;
  background:
    radial-gradient(120% 90% at 50% 0%, #1C3B28 0%, rgba(28, 59, 40, 0) 70%),
    linear-gradient(180deg, var(--dark-green, #0C1E14) 0%, #102116 100%);
}
/* The arc the band rises in: a cream cap over its top corners, traced
   in gold. Drawn as an SVG rather than a rounded clip, which would make
   the browser re-mask the glass panels on every frame. */
.lib-assure-cap { position: absolute; z-index: 1; top: -1px; left: 0; width: 100%; height: clamp(40px, 7vw, 110px); pointer-events: none; }
.lib-assure-cap .cap-fill { fill: var(--cream-bg, #F2EFE9); }
.lib-assure-cap .cap-line { fill: none; stroke: rgba(229, 198, 151, 0.7); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
/* Rising gold motes: a quiet sense of light in the air. */
.lib-assure-motes i {
  position: absolute; bottom: -10px; width: 4px; height: 4px; border-radius: 50%;
  background: var(--gold-light, #E5C697); box-shadow: 0 0 10px 2px rgba(229, 198, 151, 0.45); opacity: 0;
  animation: lib-mote 16s linear infinite; will-change: transform, opacity;
}
.lib-assure-motes i:nth-child(1) { left: 8%; animation-delay: 0s; }
.lib-assure-motes i:nth-child(2) { left: 21%; animation-delay: -5s; animation-duration: 19s; transform: scale(0.7); }
.lib-assure-motes i:nth-child(3) { left: 37%; animation-delay: -11s; animation-duration: 22s; }
.lib-assure-motes i:nth-child(4) { left: 52%; animation-delay: -2s; animation-duration: 18s; }
.lib-assure-motes i:nth-child(5) { left: 66%; animation-delay: -8s; animation-duration: 21s; }
.lib-assure-motes i:nth-child(6) { left: 79%; animation-delay: -14s; animation-duration: 17s; }
.lib-assure-motes i:nth-child(7) { left: 91%; animation-delay: -6s; animation-duration: 24s; }
@keyframes lib-mote {
  0% { transform: translate(0, 0); opacity: 0; }
  12% { opacity: 0.8; }
  50% { transform: translate(18px, -42vh); }
  88% { opacity: 0.5; }
  100% { transform: translate(-10px, -84vh); opacity: 0; }
}
.lib-assure-bg { position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.lib-assure-light { position: absolute; border-radius: 50%; will-change: transform; }
.lib-assure-light--a { width: 60%; aspect-ratio: 1; top: -30%; left: -12%; background: radial-gradient(closest-side, rgba(229, 198, 151, 0.38), transparent); animation: lib-drift-a 26s ease-in-out infinite alternate; }
.lib-assure-light--b { width: 54%; aspect-ratio: 1; bottom: -34%; right: -10%; background: radial-gradient(closest-side, rgba(86, 112, 90, 0.7), transparent); animation: lib-drift-b 32s ease-in-out infinite alternate; }
.lib-assure-light--c { width: 34%; aspect-ratio: 1; top: 30%; left: 42%; background: radial-gradient(closest-side, rgba(229, 198, 151, 0.18), transparent); animation: lib-drift-c 38s ease-in-out infinite alternate; }
/* The site's leaf shadow, as gold light through the leaves. */
.lib-assure-leaves {
  position: absolute; top: -12%; right: -8%; width: max(520px, 56%); aspect-ratio: 1.4; transform-origin: 100% 0;
  background: var(--gold-light, #E5C697); opacity: 0.09; will-change: transform;
  -webkit-mask: url('/dx-leaves.webp') no-repeat center / contain; mask: url('/dx-leaves.webp') no-repeat center / contain;
  animation: lib-sway 10s ease-in-out infinite alternate;
}
@keyframes lib-drift-a { to { transform: translate(18%, 14%) scale(1.12); } }
@keyframes lib-drift-b { to { transform: translate(-16%, -12%) scale(0.9); } }
@keyframes lib-drift-c { to { transform: translate(-30%, 12%) scale(1.2); } }
@keyframes lib-sway { from { transform: rotate(-2deg); } to { transform: rotate(2.4deg) translate(-14px, 10px); } }

.lib-assure-inner { max-width: 1180px; margin: 0 auto; padding: clamp(4.4rem, 9vw, 7rem) 6% clamp(2rem, 4vw, 3rem); text-align: center; }
.lib-assure-grid { text-align: left; }
.lib-assure .lib-kicker { color: var(--gold-light, #E5C697); }
.lib-assure h2 { font-family: 'Playfair Display', serif; font-weight: 400; font-size: clamp(1.8rem, 3.4vw, 2.7rem); line-height: 1.15; margin-bottom: clamp(1.8rem, 4vw, 2.6rem); }
.lib-assure h2 em { font-style: italic; color: var(--gold-light, #E5C697); }

/* Frosted glass: a translucent pane, a light top edge, blur behind. */
.lib-glass {
  background: linear-gradient(145deg, rgba(250, 249, 246, 0.13), rgba(250, 249, 246, 0.04));
  border: 1px solid rgba(250, 249, 246, 0.18); border-radius: 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 24px 50px -30px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(140%); backdrop-filter: blur(18px) saturate(140%);
}
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) { .lib-glass { background: rgba(28, 59, 40, 0.92); } }
@media (prefers-reduced-transparency: reduce) { .lib-glass { background: #1C3B28; -webkit-backdrop-filter: none; backdrop-filter: none; } }

.lib-assure-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 1rem; align-items: stretch; }
.lib-perks { display: grid; gap: 1rem; list-style: none; margin: 0; padding: 0; }
.lib-perks li { display: flex; gap: 1rem; align-items: flex-start; padding: 1.25rem 1.35rem; }
.lib-perk-icon { display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 12px; background: rgba(229, 198, 151, 0.14); border: 1px solid rgba(229, 198, 151, 0.28); color: var(--gold-light, #E5C697); }
.lib-perk-icon svg { width: 20px; height: 20px; }
.lib-perks strong { display: block; font-size: 0.96rem; font-weight: 600; color: #FAF9F6; margin-bottom: 0.25rem; }
.lib-perks span { font-size: 0.84rem; line-height: 1.55; color: rgba(250, 249, 246, 0.72); }
.lib-perks a { color: var(--gold-light, #E5C697); }

/* Ways to pay. */
.lib-pay { display: flex; flex-direction: column; padding: clamp(1.4rem, 3vw, 2rem); }
.lib-pay-title { display: flex; align-items: center; gap: 0.6rem; font-size: 11px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-light, #E5C697); margin-bottom: 1.2rem; }
.lib-pay-title svg { width: 16px; height: 16px; }
.lib-pay-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem; }
.lib-pay-option {
  position: relative; display: flex; flex-direction: column; gap: 0.8rem; padding: 1.2rem; border-radius: 16px;
  background: rgba(250, 249, 246, 0.07); border: 1px solid rgba(250, 249, 246, 0.14);
  transition: border-color 300ms ease, background-color 300ms ease, transform 400ms cubic-bezier(0.16, 1, 0.3, 1);
}
@media (hover: hover) and (pointer: fine) { .lib-pay-option:hover { transform: translateY(-3px); border-color: rgba(229, 198, 151, 0.5); background: rgba(250, 249, 246, 0.1); } }
.lib-pay-name { font-family: 'Playfair Display', serif; font-size: 1.45rem; line-height: 1; color: #FAF9F6; }
.lib-pay-name b { font-family: 'Montserrat', sans-serif; font-weight: 800; letter-spacing: -0.02em; font-size: 1.25rem; }
.lib-pay-name b i { font-style: normal; color: var(--gold-light, #E5C697); }
.lib-pay-option p { margin: 0; font-size: 0.84rem; line-height: 1.5; color: rgba(250, 249, 246, 0.74); }
.lib-pay-marks { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: auto; }
.lib-pay-mark {
  display: inline-flex; align-items: center; gap: 0.35rem; height: 28px; padding: 0 0.6rem; border-radius: 7px;
  background: #FAF9F6; color: var(--dark-green, #0C1E14); font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.lib-pay-mark--visa { font-style: italic; font-weight: 900; font-size: 12.5px; letter-spacing: 0.04em; color: #1A1F71; }
.lib-pay-mark--mc svg { width: 26px; height: 16px; }
.lib-pay-mark--paypal { gap: 0; font-weight: 800; font-style: italic; color: #003087; }
.lib-pay-mark--paypal i { color: #009CDE; }
.lib-pay-soon { position: absolute; top: 0.9rem; right: 0.9rem; padding: 0.22rem 0.55rem; border-radius: 999px; font-size: 9.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; background: rgba(229, 198, 151, 0.18); color: var(--gold-light, #E5C697); border: 1px solid rgba(229, 198, 151, 0.35); }
.lib-pay-soon[hidden] { display: none; }
.lib-pay-note { display: flex; gap: 0.6rem; align-items: flex-start; margin: 1.2rem 0 0; padding-top: 1.1rem; border-top: 1px solid rgba(250, 249, 246, 0.12); font-size: 0.8rem; line-height: 1.55; color: rgba(250, 249, 246, 0.66); }
.lib-pay-note svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--gold-light, #E5C697); }

@media (prefers-reduced-motion: reduce) {
  .lib-assure-light, .lib-assure-leaves, .lib-ambient * { animation: none; }
  .lib-assure-motes { display: none; }
  .lib-pay-option { transition: none; }
}

/* ---------- Empty shelf and no results ---------- */
.lib-empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; text-align: center; padding: clamp(1.5rem, 4vw, 3rem) 1rem; }
.lib-empty-shelf { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding: 0 22px; border-bottom: 3px solid rgba(145, 117, 81, 0.35); margin-bottom: 1.6rem; }
.lib-empty-shelf i { display: block; width: 22px; border-radius: 3px 3px 0 0; border: 1px solid rgba(145, 117, 81, 0.35); border-bottom: 0; background: rgba(255, 255, 255, 0.55); }
.lib-empty-shelf i:nth-child(1) { height: 92px; }
.lib-empty-shelf i:nth-child(2) { height: 108px; width: 26px; }
.lib-empty-shelf i:nth-child(3) { height: 84px; }
.lib-empty-shelf i:nth-child(4) { height: 100px; transform: rotate(9deg); transform-origin: bottom left; margin-left: 4px; }
.lib-empty h3 { font-family: 'Playfair Display', serif; font-weight: 400; font-size: 1.5rem; color: var(--dark-green, #0C1E14); margin-bottom: 0.5rem; }
.lib-empty p { max-width: 30em; font-size: 0.95rem; line-height: 1.7; color: var(--text-muted, #5A6D60); margin-bottom: 1.4rem; }
.lib-empty .lib-book-actions { padding: 0; justify-content: center; flex-wrap: wrap; }

/* ---------- The book page: a side sheet ---------- */
.lib-sheet-scrim { position: fixed; inset: 0; z-index: 1200; background: rgba(12, 30, 20, 0.45); opacity: 0; pointer-events: none; transition: opacity 300ms ease; }
.lib-sheet {
  position: fixed; z-index: 1201; top: 0; right: 0; bottom: 0; width: min(620px, 100%); overflow-y: auto; overscroll-behavior: contain;
  background: var(--light-cream, #FAF9F6); box-shadow: -30px 0 80px -30px rgba(12, 30, 20, 0.5);
  transform: translateX(104%); transition: transform 500ms cubic-bezier(0.16, 1, 0.3, 1); visibility: hidden;
}
.lib-sheet.is-open { transform: none; visibility: visible; }
.lib-sheet-scrim.is-open { opacity: 1; pointer-events: auto; }
/* A zero-height bar that stays at the top while the sheet scrolls,
   holding the close button over the cover backdrop. */
.lib-sheet-bar { position: sticky; top: 0; z-index: 3; height: 0; }
.lib-sheet-close {
  position: absolute; top: 0.9rem; right: 0.9rem; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid rgba(145, 117, 81, 0.28); background: rgba(250, 249, 246, 0.92); color: var(--dark-green, #0C1E14); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.lib-sheet-close:focus-visible { outline: 2px solid var(--gold-dark, #917551); outline-offset: 2px; }
.lib-sheet-stage { display: grid; place-items: center; padding: 3.4rem 2rem 2.6rem; background: radial-gradient(90% 90% at 50% 30%, #fff 0%, rgba(242, 239, 233, 1) 70%); border-bottom: 1px solid rgba(145, 117, 81, 0.18); }
.lib-sheet-stage .lib-cover { width: min(230px, 56vw); }
.lib-sheet-body { padding: 2rem clamp(1.4rem, 5vw, 2.6rem) 3rem; }
.lib-sheet-body h2 { font-family: 'Playfair Display', serif; font-weight: 400; font-size: clamp(1.6rem, 4vw, 2.1rem); line-height: 1.18; color: var(--dark-green, #0C1E14); margin: 0.5rem 0 0.5rem; }
.lib-sheet-author { font-size: 0.9rem; color: var(--text-muted, #5A6D60); }
.lib-sheet-buy { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.6rem 0 0.6rem; padding: 1.1rem 1.2rem; border-radius: 18px; background: rgba(255, 255, 255, 0.7); border: 1px solid rgba(145, 117, 81, 0.24); }
.lib-sheet-buy .lib-price { font-size: 1.5rem; }
.lib-sheet-buy small { display: block; font-family: 'Montserrat', sans-serif; font-size: 0.74rem; color: var(--text-muted, #5A6D60); margin-top: 0.15rem; }
.lib-sheet-buy .lib-book-actions { padding: 0; margin: 0; }
.lib-sheet-note { font-size: 0.8rem; color: var(--text-muted, #5A6D60); margin-bottom: 1.8rem; }
.lib-sheet h3 { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-dark, #917551); margin: 2rem 0 0.8rem; }
.lib-sheet-desc p { font-size: 0.98rem; line-height: 1.8; color: var(--text-dark, #233027); margin-bottom: 0.9rem; }
.lib-sheet-details { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem 1.4rem; font-size: 0.88rem; }
.lib-sheet-details dt { color: var(--text-muted, #5A6D60); }
.lib-sheet-details dd { margin: 0; color: var(--dark-green, #0C1E14); font-weight: 500; }
.lib-sheet-related { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.lib-sheet-related .lib-book-title { font-size: 0.92rem; }
.lib-sheet-related .lib-book-meta { padding-top: 0.8rem; }
body.lib-sheet-locked { overflow: hidden; }

/* ---------- Entrance ---------- */
@media (prefers-reduced-motion: no-preference) {
  .lib-shelf .lib-book { animation: lib-rise 700ms cubic-bezier(0.16, 1, 0.3, 1) both; animation-delay: calc(var(--i, 0) * 60ms); }
}
@keyframes lib-rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .lib-cover, .lib-sheet, .lib-sheet-scrim { transition: none; }
  .lib-book-cover:hover .lib-cover, .lib-spotlight-cover:hover .lib-cover { transform: none; }
}

/* ---------- Tablet / phone ---------- */
@media (max-width: 860px) {
  .lib-spotlight-inner { grid-template-columns: 1fr; justify-items: start; }
  .lib-spotlight-cover { width: min(220px, 60vw); }
  .lib-assure-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .lib-shelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2rem 1rem; }
  .lib-book-title { font-size: 1rem; }
  .lib-book-desc { display: none; }
  .lib-book-foot { flex-wrap: wrap; }
  .lib-book-actions { flex-wrap: wrap; }
  .lib-book-actions .lib-btn { flex: 1 1 auto; padding: 0.65rem 0.8rem; }
  .lib-search { flex: 1 1 100%; }
  .lib-spotlight { border-radius: 20px; }
  .lib-pay-options { grid-template-columns: 1fr; }
  .lib-sheet-related { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lib-sheet-related .lib-book:nth-child(3) { display: none; }
}
