/* ============================================================
   LIBRARY — bookshelf (/library) and flipbook reader (/library/{slug})
   Loaded only on library pages. Dark is the default theme;
   [data-theme="light"] overrides follow each block.
   ============================================================ */

.lib-page,
.lib-doc {
  --lib-stage:
    radial-gradient(900px 420px at 12% -8%, rgba(225, 29, 46, 0.20), transparent 62%),
    radial-gradient(800px 480px at 92% 110%, rgba(84, 98, 170, 0.20), transparent 60%),
    linear-gradient(180deg, #0E1122 0%, #080A14 100%);
  --lib-board-top: #F4F5F8;
  --lib-board-top-back: #DADDE5;
  --lib-board-front: #E9EBF0;
  --lib-board-front-low: #BFC4CF;
  --lib-board-shadow: rgba(0, 0, 0, 0.55);
  --lib-ink: var(--text);
  --lib-ink-muted: #9AA0B6;
  --lib-chip: rgba(255, 255, 255, 0.06);
  --lib-chip-border: rgba(255, 255, 255, 0.12);
  --lib-reader: #1B1E27;
  --lib-reader-bar: #12141B;
  --lib-reader-ink: #E8EAF0;
}

[data-theme="light"] .lib-page,
[data-theme="light"] .lib-doc {
  --lib-stage:
    radial-gradient(900px 420px at 10% -10%, rgba(225, 29, 46, 0.11), transparent 62%),
    radial-gradient(800px 480px at 95% 110%, rgba(84, 110, 190, 0.14), transparent 60%),
    linear-gradient(180deg, #EEF0F5 0%, #DDE2EC 100%);
  --lib-board-top: #FFFFFF;
  --lib-board-top-back: #E7E9EF;
  --lib-board-front: #FBFBFD;
  --lib-board-front-low: #D9DDE5;
  --lib-board-shadow: rgba(31, 41, 66, 0.22);
  --lib-ink-muted: #5B6478;
  --lib-chip: rgba(15, 23, 42, 0.04);
  --lib-chip-border: rgba(15, 23, 42, 0.12);
}

.lib-page .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ── Header ─────────────────────────────────────────────────── */
.lib-head {
  padding: calc(var(--nav-height, 110px) + 2.5rem) 0 1.75rem;
  background: var(--bg);
}
.lib-head-inner {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
  flex-wrap: wrap;
}
.lib-head-copy { max-width: 40rem; }
.lib-title {
  font-size: clamp(2rem, 4.4vw, 3.25rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-bright);
  margin: 0 0 0.85rem;
}
.lib-lede {
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 0;
}
.lib-search {
  position: relative;
  flex: 0 1 22rem;
  min-width: 15rem;
}
.lib-search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.lib-search-input {
  width: 100%;
  height: 2.9rem;
  padding: 0 1rem 0 2.6rem;
  border-radius: 999px;
  border: 1px solid var(--lib-chip-border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}
.lib-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(225, 29, 46, 0.18);
}

.lib-cats {
  display: flex;
  gap: 0.5rem;
  margin-top: 2rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.lib-cats::-webkit-scrollbar { display: none; }
.lib-cat {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--lib-chip-border);
  background: var(--lib-chip);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.lib-cat:hover { border-color: var(--primary); }
.lib-cat.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.lib-cat-count {
  font-size: 0.78rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
.lib-tags,
.lib-doc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.9rem;
}
.lib-tag {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  color: var(--lib-ink-muted);
  background: var(--lib-chip);
  text-decoration: none;
  transition: color 0.2s, background 0.2s;
}
.lib-tag::before { content: "#"; opacity: 0.55; margin-right: 1px; }
.lib-tag:hover,
.lib-tag.is-active { color: var(--primary); background: rgba(225, 29, 46, 0.1); }

/* ── Stage with shelves ─────────────────────────────────────── */
.lib-stage {
  background: var(--lib-stage);
  padding: 2.5rem 0 4rem;
}
.lib-shelf-section + .lib-shelf-section { margin-top: 2.5rem; }
.lib-shelf-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.25rem;
}
.lib-shelf-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-bright);
  margin: 0;
}
.lib-shelf-more {
  font-size: 0.875rem;
  color: var(--lib-ink-muted);
  text-decoration: none;
  white-space: nowrap;
}
a.lib-shelf-more:hover { color: var(--primary); }

/* Every grid row is one shelf: the board is painted by a background that
   repeats once per row, so a shelf spans the full width however many
   books stand on it. */
.lib-shelf {
  --cover-h: 232px;
  --cover-w: calc(var(--cover-h) * 0.7071);
  --lift: 30px;                           /* space above the covers */
  --caption: 78px;
  --row: calc(var(--lift) + var(--cover-h) + 18px + var(--caption));
  --floor: calc(var(--lift) + var(--cover-h));
  list-style: none;
  margin: 0 -0.75rem;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--cover-w) + 2.25rem), 1fr));
  grid-auto-rows: var(--row);
  background-image: linear-gradient(to bottom,
    transparent 0,
    transparent calc(var(--floor) - 12px),
    var(--lib-board-top-back) calc(var(--floor) - 12px),
    var(--lib-board-top) calc(var(--floor) + 3px),
    var(--lib-board-front) calc(var(--floor) + 3px),
    var(--lib-board-front-low) calc(var(--floor) + 18px),
    var(--lib-board-shadow) calc(var(--floor) + 18px),
    transparent calc(var(--floor) + 40px),
    transparent 100%);
  background-size: 100% var(--row);
  background-repeat: repeat-y;
  border-radius: 3px;
}
.lib-book {
  display: flex;
  justify-content: center;
  min-width: 0;
}
.lib-book-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: calc(var(--cover-w) + 1.5rem);
  padding-top: var(--lift);
  text-decoration: none;
  color: inherit;
  outline: none;
}
.lib-book-cover {
  width: var(--cover-w);
  height: var(--cover-h);
  flex: none;
  transform-origin: 50% 100%;
  transition: transform 0.45s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.45s;
}
.lib-book-link:hover .lib-book-cover,
.lib-book-link:focus-visible .lib-book-cover {
  transform: translateY(-10px) rotate(-1.2deg);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 14px 26px 30px -12px rgba(0, 0, 0, 0.55);
}
.lib-book-link:focus-visible .lib-book-cover { outline: 2px solid var(--primary); outline-offset: 4px; }
.lib-book-caption {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  width: 100%;
  margin-top: 26px;
  text-align: center;
}
.lib-book-title {
  font-size: 0.875rem;
  line-height: 1.35;
  font-weight: 600;
  color: var(--text-bright);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-book-link:hover .lib-book-title { color: var(--primary); }
.lib-book-meta {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.5rem;
  font-size: 0.75rem;
  color: var(--lib-ink-muted);
}
.lib-access {
  padding: 0.05rem 0.45rem;
  border-radius: 4px;
  border: 1px solid var(--lib-chip-border);
}
.lib-access--preview { border-color: rgba(225, 29, 46, 0.45); color: var(--text); }

/* ── Covers ─────────────────────────────────────────────────── */
.lib-cover {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 2px 5px 5px 2px;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.22), 8px 14px 22px -10px rgba(0, 0, 0, 0.5);
}
.lib-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* spine crease and a soft sheen, as on a bound cover */
.lib-cover::before,
.lib-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.lib-cover::before {
  width: 12px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.22), rgba(255, 255, 255, 0.28) 35%, rgba(0, 0, 0, 0.12) 60%, transparent);
  z-index: 2;
}
.lib-cover::after {
  background: linear-gradient(110deg, rgba(255, 255, 255, 0.16) 0%, transparent 38%, transparent 70%, rgba(0, 0, 0, 0.06) 100%);
  z-index: 2;
}

/* Typeset cover when no image was uploaded */
.lib-cover--auto {
  display: flex;
  flex-direction: column;
  padding: 16px 14px 14px 20px;
  color: #fff;
  background: linear-gradient(160deg, #1B2340 0%, #0D1224 100%);
  text-align: left;
}
.lib-cover--auto .lib-cover-cat {
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  opacity: 0.75;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  align-self: flex-start;
}
.lib-cover--auto .lib-cover-title {
  margin-top: 14px;
  font-size: calc(var(--cover-h, 232px) * 0.07);
  line-height: 1.18;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.lib-cover--auto .lib-cover-mark {
  margin-top: auto;
  font-size: 0.66rem;
  font-weight: 700;
  opacity: 0.7;
}
.lib-cover--auto.lib-cover--case-study { background: linear-gradient(160deg, #A3162A 0%, #5E0A15 100%); }
.lib-cover--auto.lib-cover--case-study .lib-cover-cat { border-color: #fff; }
.lib-cover--auto.lib-cover--report { background: linear-gradient(160deg, #F4F5F8 0%, #DCE0E8 100%); color: #111827; }
.lib-cover--auto.lib-cover--security-research {
  background:
    linear-gradient(rgba(225, 29, 46, 0.14) 1px, transparent 1px) 0 0 / 14px 14px,
    linear-gradient(90deg, rgba(225, 29, 46, 0.14) 1px, transparent 1px) 0 0 / 14px 14px,
    #0B0C12;
}
.lib-cover--auto.lib-cover--guide { background: linear-gradient(160deg, #2D3448 0%, #171B27 100%); }

.lib-empty,
.lib-empty-inline {
  color: var(--text-muted);
}
.lib-empty {
  text-align: center;
  padding: 4rem 1rem;
}
.lib-empty p { margin: 0 0 1.25rem; font-size: 1.05rem; }
.lib-empty-inline a { color: var(--primary); }

@media (max-width: 640px) {
  .lib-shelf {
    --cover-h: 176px;
    --lift: 24px;
    --caption: 74px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0 -0.5rem;
  }
  .lib-book-link { width: 100%; padding-inline: 0.5rem; }
  .lib-head { padding-top: calc(var(--nav-height, 110px) + 1rem); }
  .lib-search { flex-basis: 100%; }
}

/* ── Document page ──────────────────────────────────────────── */
.lib-doc { background: var(--bg); }
.lib-crumbs {
  padding-top: calc(var(--nav-height, 110px) + 1.75rem);
  display: flex;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.lib-crumbs a { color: var(--text-muted); text-decoration: none; }
.lib-crumbs a:hover { color: var(--primary); }
.lib-doc-head { padding-top: 0.9rem; padding-bottom: 1.75rem; }
.lib-doc-title {
  font-size: clamp(1.75rem, 3.6vw, 2.75rem);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-bright);
  margin: 0;
  max-width: 24ch;
}
.lib-doc-summary {
  margin: 0.9rem 0 0;
  max-width: 44rem;
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--text-muted);
}
.lib-doc-cover-only { padding-bottom: 2rem; }
.lib-doc-cover-only .lib-book-cover { --cover-h: 320px; width: 226px; height: 320px; }

.lib-doc-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 3rem;
  padding-top: 3rem;
  padding-bottom: 4rem;
}
.lib-prose {
  max-width: 42rem;
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--text);
}
.lib-prose h2 { font-size: 1.4rem; margin: 2rem 0 0.75rem; color: var(--text-bright); }
.lib-prose h3 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; color: var(--text-bright); }
.lib-prose p,
.lib-prose ul,
.lib-prose ol { margin: 0 0 1rem; }
.lib-prose a { color: var(--primary); }
.lib-doc-tags { margin-top: 1.5rem; }

.lib-doc-side { display: flex; flex-direction: column; gap: 1.5rem; }
.lib-facts {
  margin: 0;
  border-top: 1px solid var(--border-subtle);
}
.lib-facts > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
}
.lib-facts dt { color: var(--text-muted); }
.lib-facts dd { margin: 0; color: var(--text); text-align: right; font-weight: 500; }
.lib-download-btn { justify-content: center; }
.lib-side-note { margin: -0.9rem 0 0; font-size: 0.8rem; color: var(--text-muted); }
.lib-share-title { font-size: 0.9rem; font-weight: 600; color: var(--text-muted); margin: 0 0 0.6rem; }
.lib-share-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.lib-share-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--lib-chip-border);
  background: var(--lib-chip);
  color: var(--text);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}
.lib-share-btn:hover { color: var(--primary); border-color: var(--primary); }
.lib-copy-done {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  white-space: nowrap;
  color: var(--text);
}
.lib-related { padding-top: 2.25rem; }

@media (max-width: 900px) {
  .lib-doc-body { grid-template-columns: 1fr; gap: 2rem; padding-top: 2rem; }
}

/* ── Reader ─────────────────────────────────────────────────── */
.lib-viewer {
  --bar-h: 52px;
  position: relative;
  scroll-margin-top: calc(var(--nav-height, 110px) - 10px);
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(70% 60% at 50% 45%, #2A2E3A 0%, var(--lib-reader) 70%);
  color: var(--lib-reader-ink);
  user-select: none;
  -webkit-user-select: none;
}
.lib-vbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  height: var(--bar-h);
  padding: 0 clamp(0.75rem, 3vw, 1.5rem);
  background: var(--lib-reader-bar);
}
.lib-vbar--top { justify-content: space-between; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.lib-vbar--bottom { justify-content: center; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.lib-vtitle {
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(232, 234, 240, 0.8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.lib-vtools { display: flex; gap: 0.15rem; flex: none; }
.lib-vbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.lib-vbtn:hover { background: rgba(255, 255, 255, 0.08); }
.lib-vbtn:focus-visible,
.lib-arrow:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.lib-vbtn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.1); }
.lib-vsep {
  width: 1px;
  height: 22px;
  margin: 0 0.35rem;
  align-self: center;
  background: rgba(255, 255, 255, 0.14);
}
.lib-vclose:hover { background: var(--primary); color: #fff; }
.lib-vbtn .lib-ico-sound-off { display: none; }
.lib-vbtn.is-off .lib-ico-sound-on { display: none; }
.lib-vbtn.is-off .lib-ico-sound-off { display: block; }
.lib-vbtn.is-off { color: rgba(232, 234, 240, 0.5); }
.lib-pageinfo {
  display: inline-flex;
  gap: 0.35rem;
  min-width: 7.5rem;
  justify-content: center;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}
.lib-pageinfo-of { color: rgba(232, 234, 240, 0.55); }

.lib-vstage {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: clamp(1rem, 3vh, 2rem) clamp(0.5rem, 2vw, 1.5rem);
}
.lib-book-area {
  position: relative;
  flex: 1;
  min-width: 0;
  height: clamp(360px, calc(100vh - 290px), 880px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.lib-flipbook { position: relative; margin: 0 auto; }
.lib-flipbook .stf__block { filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.45)); }
/* the fold between two facing pages */
.lib-viewer:not(.at-start) .lib-flipbook.is-spread::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 70px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.10) 44%, rgba(0, 0, 0, 0.22) 50%, rgba(0, 0, 0, 0.10) 56%, transparent);
  pointer-events: none;
  z-index: 5;
}
.lib-viewer.is-flipping .lib-flipbook::after { opacity: 0; }
.lib-page {
  background: #fff;
  overflow: hidden;
}
.lib-page-inner {
  width: 100%;
  height: 100%;
  background:
    linear-gradient(90deg, #f1f2f5 0 100%) center / 60% 6px no-repeat,
    #fff;
}
.lib-page-inner canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.lib-page--lock {
  background: linear-gradient(160deg, #FFFFFF 0%, #F1F2F6 100%);
}
.lib-lock {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 2rem;
  text-align: center;
  color: #111827;
}
.lib-lock svg { color: var(--primary); margin-bottom: 0.4rem; }
.lib-lock-kicker { margin: 0; font-size: 0.9rem; color: #4B5563; }
.lib-lock-title { margin: 0 0 0.9rem; font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }

.lib-arrow {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s, border-color 0.2s;
}
.lib-arrow:hover { background: var(--primary); border-color: var(--primary); }
.lib-viewer.at-start .lib-arrow--prev,
.lib-viewer.at-end .lib-arrow--next { opacity: 0.25; pointer-events: none; }

.lib-vstatus {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  font-size: 0.9rem;
  color: rgba(232, 234, 240, 0.75);
}
.lib-vstatus[hidden] { display: none; }
.lib-vstatus a,
.lib-vstatus-link { color: #fff; text-decoration: underline; }
.lib-vstatus.is-error .lib-spinner { display: none; }
.lib-spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--primary);
  animation: lib-spin 0.9s linear infinite;
}
@keyframes lib-spin { to { transform: rotate(360deg); } }

/* Share popover */
.lib-sharepop {
  position: absolute;
  top: calc(var(--bar-h) + 6px);
  right: clamp(0.75rem, 3vw, 1.5rem);
  z-index: 20;
  width: min(22rem, calc(100vw - 1.5rem));
  padding: 1rem;
  border-radius: 12px;
  background: #fff;
  color: #111827;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  user-select: text;
}
.lib-sharepop[hidden] { display: none; }
.lib-sharepop-page { display: flex; gap: 0.5rem; align-items: center; font-size: 0.875rem; margin-bottom: 0.75rem; }
.lib-sharepop-page input { accent-color: var(--primary); }
.lib-sharepop-row { display: flex; gap: 0.5rem; }
.lib-sharepop-url {
  flex: 1;
  min-width: 0;
  height: 2.4rem;
  padding: 0 0.7rem;
  border: 1px solid #D5D9E2;
  border-radius: 8px;
  font: inherit;
  font-size: 0.8rem;
  color: #374151;
  background: #F7F8FA;
}
.lib-sharepop-copy {
  height: 2.4rem;
  padding: 0 1rem;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.lib-sharepop-nets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.75rem; }
.lib-sharepop-nets a {
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  background: #F1F2F5;
  color: #111827;
  text-decoration: none;
}
.lib-sharepop-nets a:hover { background: #FDE8EA; color: var(--primary); }

/* Overview */
.lib-overview {
  position: absolute;
  inset: var(--bar-h) 0 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  background: rgba(14, 16, 22, 0.96);
}
.lib-overview[hidden] { display: none; }
.lib-overview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem clamp(0.75rem, 3vw, 1.5rem);
  font-size: 0.9rem;
  color: rgba(232, 234, 240, 0.75);
}
.lib-overview-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 1.25rem 1rem;
  padding: 0.5rem clamp(0.75rem, 3vw, 1.5rem) 2rem;
  align-content: start;
}
.lib-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  border: 0;
  padding: 0;
  background: none;
  color: rgba(232, 234, 240, 0.7);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
}
.lib-thumb-img {
  width: 100%;
  background: #fff;
  border-radius: 2px;
  overflow: hidden;
  outline: 2px solid transparent;
  outline-offset: 3px;
  transition: outline-color 0.15s, transform 0.15s;
}
.lib-thumb-img canvas { display: block; width: 100%; height: 100%; }
.lib-thumb:hover .lib-thumb-img { transform: translateY(-2px); }
.lib-thumb.is-current .lib-thumb-img,
.lib-thumb:focus-visible .lib-thumb-img { outline-color: var(--primary); }
.lib-thumb.is-current { color: #fff; }
.lib-thumb--lock .lib-thumb-img {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(225, 29, 46, 0.14);
  border: 1px dashed rgba(225, 29, 46, 0.6);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
}

/* Full screen, or "fill the window" where the API is missing */
.lib-viewer.is-fullscreen,
.lib-viewer.is-max {
  width: 100%;
  height: 100%;
}
.lib-viewer.is-max {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal, 2000) - 1);
}
/* Books open filling the window: the page behind doesn't scroll. */
html:has(.lib-viewer.is-max), body:has(.lib-viewer.is-max) { overflow: hidden; }
.lib-viewer.is-max { border-radius: 0; border: 0; }
.lib-vnotice {
  display: flex; align-items: center; gap: .75rem; justify-content: space-between;
  margin: 0; padding: .55rem 1rem; font-size: .85rem; line-height: 1.45;
  background: rgba(22, 163, 74, .16); color: #DCFCE7; border-bottom: 1px solid rgba(22, 163, 74, .35);
}
.lib-vnotice--warn { background: rgba(245, 158, 11, .16); color: #FEF3C7; border-bottom-color: rgba(245, 158, 11, .4); }
.lib-vnotice-close { flex: none; border: 0; background: none; color: inherit; font-size: 1.25rem; line-height: 1; cursor: pointer; opacity: .8; }
.lib-vnotice-close:hover { opacity: 1; }
.lib-viewer.is-fullscreen .lib-vstage,
.lib-viewer.is-max .lib-vstage { flex: 1; min-height: 0; }
.lib-viewer.is-fullscreen .lib-book-area,
.lib-viewer.is-max .lib-book-area { height: 100%; }

@media (max-width: 700px) {
  .lib-viewer { --bar-h: 48px; }
  .lib-vstage { padding: 0.75rem 0.5rem; }
  .lib-book-area { height: min(72vh, 150vw); }
  .lib-arrow {
    position: absolute;
    top: 50%;
    z-index: 5;
    width: 2.5rem;
    height: 2.5rem;
    transform: translateY(-50%);
  }
  .lib-arrow--prev { left: 0.25rem; }
  .lib-arrow--next { right: 0.25rem; }
  .lib-vtitle { display: none; }
  .lib-vbar--top { justify-content: flex-end; }
}

/* ── Unlock dialog ──────────────────────────────────────────── */
.lib-unlock {
  width: min(26rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  margin: auto; /* the site reset zeroes margins; auto centres the modal */
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}
.lib-unlock::backdrop { background: rgba(6, 8, 16, 0.6); backdrop-filter: blur(3px); }
.lib-unlock-form { position: relative; display: flex; flex-direction: column; gap: 0.9rem; padding: 1.75rem; }
.lib-unlock-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.lib-unlock-close:hover { background: var(--lib-chip); color: var(--text); }
.lib-unlock-title { margin: 0; font-size: 1.4rem; font-weight: 800; color: var(--text-bright); }
.lib-unlock-copy { margin: -0.3rem 0 0.2rem; font-size: 0.925rem; line-height: 1.55; color: var(--text-muted); }
.lib-field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; font-weight: 500; }
.lib-field input {
  height: 2.75rem;
  padding: 0 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--lib-chip-border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
}
.lib-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(225, 29, 46, 0.18); }
.lib-hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.lib-unlock-error {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  background: rgba(225, 29, 46, 0.1);
  color: var(--text);
  border-left: 3px solid var(--primary);
}
.lib-unlock-error[hidden] { display: none; }
.lib-unlock-sent {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 2rem 1.75rem 1.75rem;
  text-align: center;
  align-items: center;
}
.lib-unlock-sent[hidden],
.lib-unlock-form[hidden] { display: none; }
.lib-unlock-sent-icon { color: var(--primary); }
.lib-unlock-sent .lib-unlock-copy { margin: 0; }
.lib-unlock-sent-to { display: inline-block; max-width: 100%; color: var(--text-bright); overflow-wrap: anywhere; }
.lib-linkbtn {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--primary);
  text-decoration: underline;
  cursor: pointer;
}
.lib-lock-note { margin: 0.5rem 0 0; font-size: 0.8rem; color: #6B7280; }
.lib-notice {
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  border-left: 3px solid #16A34A;
  background: rgba(22, 163, 74, 0.1);
  color: var(--text);
  font-size: 0.925rem;
}
.lib-notice--warn { border-left-color: var(--primary); background: rgba(225, 29, 46, 0.1); }
.lib-side-note--access { margin: 0; color: var(--text); }
.lib-unlock-check {
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--lib-chip);
  color: var(--text-muted);
}
.lib-unlock-check[hidden] { display: none; }
.lib-unlock-submit { justify-content: center; margin-top: 0.25rem; }
.lib-unlock-submit:disabled { opacity: 0.6; cursor: progress; }
.lib-unlock-fine { margin: 0; font-size: 0.75rem; line-height: 1.5; color: var(--text-muted); }
.lib-unlock-fine a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  .lib-book-cover,
  .lib-thumb-img { transition: none; }
  .lib-book-link:hover .lib-book-cover,
  .lib-book-link:focus-visible .lib-book-cover { transform: none; }
  .lib-spinner { animation-duration: 2.4s; }
}
