/* ─── /academics/courses/ — the library ───────────────────────────────
   One continuous bookcase. courses.js packs the books into shelves and
   puts a library label under every run of a section. Exams are matched
   sets; self-chosen courses are odd sizes; a gold ribbon marks a course
   still in progress. On phones each section becomes a stack.           */

:root {
  --bg: #000000;
  --surface: #111111;
  --surface-soft: #181818;
  --text: #F4F1E8;
  --text-sec: #E8E4DA;
  --text-muted: #CFC9BC;
  --gold: #C9A44C;
  --gold-hi: #E0BE67;
  --line: rgba(201, 164, 76, 0.18);
  --line-soft: rgba(201, 164, 76, 0.12);
  --line-strong: rgba(201, 164, 76, 0.42);
  --ink-line: rgba(244, 241, 232, 0.22);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-serif: 'Cinzel Decorative', serif;
  --font-sans: 'DM Sans', sans-serif;
  --font-tech: 'Space Grotesk', sans-serif;
}

html { scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); font-family: var(--font-sans); overflow-x: hidden; margin: 0; }
.sk-main { margin-top: 0; }
.sk-container { max-width: 1180px; margin: 0 auto; padding: clamp(3rem, 7vw, 6rem) clamp(1rem, 4vw, 3rem); box-sizing: border-box; }

.sk-eyebrow { display: block; font-family: var(--font-tech); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.18em; color: var(--gold); margin-bottom: 0.75rem; }
.sk-sec-title { font-family: var(--font-serif); font-size: clamp(2rem, 4vw, 3.25rem); font-weight: 700; color: var(--text); margin: 0 0 1.5rem; letter-spacing: -0.01em; line-height: 1.15; }
.sk-hero__subtitle { font-family: var(--font-tech); font-size: clamp(0.85rem, 1.8vw, 1.2rem); text-transform: uppercase; letter-spacing: 0.15em; color: var(--gold); margin-bottom: 1.5rem; }
.sk-sec-lead { font-size: clamp(1.05rem, 2vw, 1.25rem); line-height: 1.65; color: var(--text-sec); max-width: 800px; margin: 0 0 1.75rem; }

/* ─── Hero ─────────────────────────────────────────────────────────── */
.sk-hero { position: relative; min-height: 100vh; overflow: hidden; background: var(--bg); border-bottom: 1px solid var(--line-soft); }
.sk-hero__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; filter: grayscale(20%) contrast(110%); }
.sk-hero__overlay { position: absolute; inset: 0; z-index: 1; }

/* ─── Shared ───────────────────────────────────────────────────────── */
.lib-section { position: relative; background: var(--bg); border-top: 1px solid var(--line-soft); }
.lib-body { font-size: 1.02rem; line-height: 1.75; color: var(--text-sec); max-width: 620px; margin: 0 0 2rem; }
.lib-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

kbd {
  display: inline-block; min-width: 1.4em; padding: 0.05em 0.4em; box-sizing: border-box; text-align: center;
  font: 600 0.78em/1.4 var(--font-tech); color: var(--gold); border: 1px solid var(--line-strong);
}

.lib-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.6rem; cursor: pointer; text-decoration: none;
  font: 600 0.78rem/1.2 var(--font-sans); letter-spacing: 0.1em; text-transform: uppercase;
  padding: 0.9rem 1.35rem; border-radius: 0; border: 1px solid transparent; background: transparent; transition: all 220ms ease;
}
.lib-btn--gold { background: var(--gold); color: #080808; border-color: var(--gold); }
.lib-btn--gold:hover { background: var(--gold-hi); border-color: var(--gold-hi); transform: translateY(-2px); }
.lib-btn--ghost { color: var(--text); border-color: var(--ink-line); }
.lib-btn--ghost:hover { color: var(--gold); border-color: var(--gold); }
.lib-btn:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }

/* ─── Bindings (spines and legend minis) ───────────────────────────── */
.bind-ivory { --bind: linear-gradient(90deg, #cfc9bc 0%, #F4F1E8 38%, #e8e4da 100%); --ink: #0b0b0b; --foil: #0b0b0b; --edge: rgba(0, 0, 0, 0); }
.bind-black { --bind: #070707; --ink: #C9A44C; --foil: #C9A44C; --edge: rgba(201, 164, 76, 0.28); }
.bind-char  { --bind: #1f1f1f; --ink: #F4F1E8; --foil: #C9A44C; --edge: rgba(244, 241, 232, 0.06); }
.bind-noir  { --bind: #0e0e0e; --ink: #F4F1E8; --foil: #E8E4DA; --edge: rgba(244, 241, 232, 0.16); }

/* ─── 01 · Guide (kept short) ─────────────────────────────────────── */
.lib-section--tight > .sk-container { padding-top: clamp(2.5rem, 5vw, 4rem); padding-bottom: clamp(2rem, 4vw, 3rem); }
.lib-section--tight-top > .sk-container { padding-top: clamp(2.5rem, 5vw, 4rem); }
.lib-guide { display: grid; grid-template-columns: 1fr auto; gap: clamp(1.5rem, 4vw, 4rem); align-items: end; }
.lib-guide .sk-sec-title { margin-bottom: 0.9rem; }
.lib-guide .lib-body { margin: 0; max-width: 560px; }
.lib-body a { color: var(--gold); text-underline-offset: 3px; }
.lib-body a:hover { color: var(--gold-hi); }
.lib-legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 1.75rem; }
.lib-legend__item { display: flex; flex-direction: column; align-items: flex-start; gap: 0.7rem; }
.lib-legend__item p { margin: 0; font-size: 0.85rem; line-height: 1.35; color: var(--text-sec); white-space: nowrap; }
.lib-legend__item strong { color: var(--text); font-weight: 600; }
.lib-legend__books {
  display: flex; align-items: flex-end; gap: 2px; padding: 0 0.4rem; height: 62px;
  border-bottom: 5px solid #141414; box-shadow: 0 1px 0 rgba(201, 164, 76, 0.5);
}
.lib-mini { position: relative; isolation: isolate; display: block; width: var(--w); height: var(--h); background: var(--bind); box-shadow: inset 0 0 0 1px var(--edge), 2px 0 5px rgba(0, 0, 0, 0.6); }
.lib-mini::before { content: ""; position: absolute; left: 18%; right: 18%; top: 7px; height: 3px; border-top: 1px solid var(--foil); border-bottom: 1px solid var(--foil); }
.lib-mini.is-progress::after {
  content: ""; position: absolute; right: 24%; top: -14px; width: 6px; height: 18px; background: var(--gold); z-index: -1;
  clip-path: polygon(0 0, 50% 22%, 100% 0, 100% 100%, 0 100%);
}

/* ─── 02 · Directory board (one row) ──────────────────────────────── */
.lib-head .sk-sec-title { margin-bottom: 0.6rem; }
.lib-head .lib-body { margin: 0 0 1.5rem; }
.lib-dir { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); margin: 0 0 1.25rem; border: 1px solid var(--line); }
.lib-dir__item {
  display: grid; grid-template-columns: auto 1fr; grid-template-areas: "num name" "num count";
  gap: 0.2rem 0.7rem; align-items: center; text-align: left; cursor: pointer;
  padding: 0.8rem 0.9rem; background: #000; color: inherit; font: inherit; border: 0; border-radius: 0;
  border-right: 1px solid var(--line-soft); transition: background 220ms ease, box-shadow 220ms ease;
}
.lib-dir__item:last-child { border-right: 0; }
.lib-dir__item:hover { background: var(--surface); }
.lib-dir__item:focus-visible { outline: 1px solid var(--gold); outline-offset: -4px; }
.lib-dir__item.is-active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--gold); }
.lib-dir__num { grid-area: num; min-width: 1.6ch; font: 400 1.3rem/1 var(--font-serif); color: var(--gold); }
.lib-dir__name { grid-area: name; hyphens: none; font: 400 0.84rem/1.25 var(--font-serif); color: var(--text); letter-spacing: 0.02em; }
.lib-dir__count { grid-area: count; font: 600 0.58rem/1 var(--font-tech); letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }

/* ─── Toolbar + catalogue search ───────────────────────────────────── */
.lib-toolbar {
  position: sticky; top: 72px; z-index: 30;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "search count" "try try";
  gap: 0.75rem 1.25rem; align-items: center; padding: 0.9rem; margin-bottom: 2rem;
  background: rgba(0, 0, 0, 0.9); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line);
}
.lib-toolbar.is-stuck { border-color: var(--line-strong); }
.lib-search { grid-area: search; position: relative; display: flex; align-items: center; }
.lib-search__icon { position: absolute; left: 0.95rem; width: 18px; height: 18px; fill: none; stroke: var(--gold); stroke-width: 1.5; pointer-events: none; }
.lib-search input {
  width: 100%; box-sizing: border-box; padding: 0.85rem 3rem 0.85rem 2.85rem; border-radius: 0;
  font: 400 1rem/1.3 var(--font-sans); color: var(--text); background: #000; border: 1px solid var(--ink-line);
  transition: border-color 220ms ease; -webkit-appearance: none; appearance: none;
}
.lib-search input::placeholder { color: var(--text-muted); opacity: 1; }
.lib-search input::-webkit-search-cancel-button { display: none; }
.lib-search input:focus { outline: none; border-color: var(--gold); }
.lib-search__key { position: absolute; right: 0.9rem; pointer-events: none; transition: opacity 200ms ease; }
.lib-search input:focus ~ .lib-search__key, .lib-search.has-q .lib-search__key { opacity: 0; }
.lib-search__clear {
  position: absolute; right: 0.4rem; width: 2.2rem; height: 2.2rem; display: grid; place-items: center;
  background: none; border: 0; color: var(--text); font-size: 1.35rem; line-height: 1; cursor: pointer;
}
.lib-search__clear[hidden] { display: none; }
.lib-search__clear:hover { color: var(--gold); }
@media (hover: none) { .lib-search__key { display: none; } }

.lib-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 5; margin: 0; padding: 0; list-style: none;
  max-height: min(430px, 60vh); overflow: auto; overscroll-behavior: contain;
  background: #050505; border: 1px solid var(--line-strong); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.85);
}
.lib-results[hidden] { display: none; }
.lib-result {
  display: grid; grid-template-columns: 2.6rem 1fr auto; gap: 0.25rem 0.85rem; align-items: center;
  padding: 0.75rem 1rem; cursor: pointer; border-bottom: 1px solid var(--line-soft);
}
.lib-result__num { grid-row: span 2; font: 400 1.05rem/1 var(--font-serif); color: var(--gold); text-align: center; }
.lib-result__title { font: 400 0.98rem/1.3 var(--font-serif); color: var(--text); }
.lib-result__title mark, .lib-result__why mark { background: none; color: var(--gold); }
.lib-result__meta { grid-column: 2; font: 600 0.62rem/1.3 var(--font-tech); letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-sec); }
.lib-result__why { grid-column: 2; font-size: 0.82rem; line-height: 1.4; color: var(--text-sec); }
.lib-result__grade { grid-row: 1 / span 2; grid-column: 3; font: 700 1rem/1 var(--font-serif); color: var(--gold); white-space: nowrap; }
.lib-result__grade.is-word { font: 600 0.6rem/1 var(--font-tech); letter-spacing: 0.14em; text-transform: uppercase; }
.lib-result.is-active, .lib-result:hover { background: var(--surface); }
.lib-result.is-active { box-shadow: inset 2px 0 0 var(--gold); }
.lib-results__foot { padding: 0.8rem 1rem; cursor: pointer; font: 600 0.66rem/1.2 var(--font-tech); letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
.lib-results__foot.is-active, .lib-results__foot:hover { background: var(--surface); }
.lib-results__none { padding: 1rem; font-size: 0.95rem; color: var(--text-sec); }

.lib-count { grid-area: count; margin: 0; font: 600 0.68rem/1 var(--font-tech); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-sec); white-space: nowrap; }
.lib-count strong { color: var(--gold); font-weight: 600; font-variant-numeric: tabular-nums; }
.lib-count button { margin-left: 0.6rem; padding: 0; background: none; border: 0; cursor: pointer; font: inherit; letter-spacing: inherit; text-transform: inherit; color: var(--gold); text-decoration: underline; text-underline-offset: 3px; }

.lib-try { grid-area: try; display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.lib-try__label { margin-right: 0.35rem; font: 600 0.62rem/1 var(--font-tech); letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }
.lib-try button {
  padding: 0.42rem 0.65rem; cursor: pointer; border-radius: 0; background: transparent; color: var(--text-sec);
  border: 1px solid rgba(244, 241, 232, 0.16); font: 600 0.66rem/1 var(--font-tech); letter-spacing: 0.08em; text-transform: uppercase;
  transition: color 200ms ease, border-color 200ms ease;
}
.lib-try button:hover, .lib-try button.is-active { color: var(--gold); border-color: var(--gold); }
.lib-try button:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }

/* ─── The bookcase ─────────────────────────────────────────────────── */
.lib-case {
  --case-pad: 12px; --row-pad: 18px; --board: 40px; --seg-gap: 16px;
  position: relative; padding: 0 var(--case-pad);
  background: #030303; border: 1px solid rgba(201, 164, 76, 0.22);
  box-shadow: inset 0 24px 40px -24px rgba(0, 0, 0, 0.9);
  /* without JS the books simply wrap */
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 3px;
}
.lib-case.is-packed { display: block; }
.lib-case::before {
  content: ""; display: block; position: absolute; left: -1px; right: -1px; top: -9px; height: 8px;
  background: linear-gradient(#1c1c1c, #0c0c0c); border: 1px solid rgba(201, 164, 76, 0.32); border-bottom: 0;
}
.lib-case.is-switching .lib-row { opacity: 0; }

.lib-row {
  position: relative; display: flex; align-items: flex-end; gap: 0 var(--seg-gap);
  padding: 34px var(--row-pad) 0; transition: opacity 240ms ease;
  background:
    linear-gradient(to top, #0b0b0b 0, #191919 calc(var(--board) - 1px), rgba(201, 164, 76, 0.6) calc(var(--board) - 1px), rgba(201, 164, 76, 0.6) var(--board), transparent var(--board)),
    radial-gradient(ellipse 70% 90% at 50% 100%, rgba(244, 241, 232, 0.035), transparent 70%);
}
.lib-row + .lib-row { border-top: 6px solid #0a0a0a; }
.lib-seg { display: flex; flex-direction: column; align-items: stretch; flex: none; }
.lib-seg__books { display: flex; align-items: flex-end; gap: 3px; }
.lib-seg__label { height: var(--board); display: flex; align-items: center; justify-content: center; min-width: 0; padding: 0 2px; }
.lib-tag {
  max-width: 100%; box-sizing: border-box; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  padding: 5px 10px; background: #F4F1E8; color: #0a0a0a;
  font: 700 0.62rem/1.1 var(--font-tech); letter-spacing: 0.12em; text-transform: uppercase;
  box-shadow: 0 0 0 2px #0c0c0c, 0 0 0 3px rgba(201, 164, 76, 0.75);
  transition: opacity 260ms ease;
}
.lib-tag b { margin-right: 0.5em; font-family: var(--font-serif); letter-spacing: 0.02em; }
.lib-seg.is-dim .lib-tag { opacity: 0.3; }

.lib-end {
  flex: none; align-self: flex-end; width: 14px; height: 150px; margin-bottom: var(--board);
  background: linear-gradient(90deg, #1d1d1d, #0c0c0c); border-left: 1px solid rgba(201, 164, 76, 0.5);
  box-shadow: -4px 0 10px rgba(0, 0, 0, 0.6);
}

/* ─── A book ───────────────────────────────────────────────────────── */
.bk { position: relative; display: flex; align-items: flex-end; }
.bk.is-out { display: none; }
.bk__spine {
  --i: 0;
  position: relative; width: var(--ww, var(--w)); height: var(--h); box-sizing: border-box; margin: 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 16px 0 13px;
  border: 0; border-radius: 0; cursor: pointer; font: inherit; color: var(--ink); background: var(--bind);
  box-shadow: inset 0 0 0 1px var(--edge), 3px 0 9px rgba(0, 0, 0, 0.6);
  transform-origin: 50% 100%; isolation: isolate;
  transition: transform 480ms var(--ease), box-shadow 300ms ease, opacity 320ms ease, filter 320ms ease;
}
.bk__spine::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.38) 0%, rgba(255, 255, 255, 0.08) 14%, transparent 34%, transparent 70%, rgba(0, 0, 0, 0.34) 100%);
}
.bk__spine:hover, .bk__spine:focus-visible { transform: translateY(-16px); box-shadow: inset 0 0 0 1px var(--edge), 3px 12px 24px rgba(0, 0, 0, 0.75); }
.bk__spine:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }
.bk__spine > * { position: relative; }

.bk__band { flex: none; width: 70%; height: 8px; border-top: 1px solid var(--foil); border-bottom: 1px solid var(--foil); }
.bk__mono { flex: none; font: 700 0.6rem/1 var(--font-tech); letter-spacing: 0.14em; color: var(--foil); }
.bk__title {
  flex: 1; min-height: 0; overflow: hidden; padding: 4px 0;
  writing-mode: vertical-rl; text-orientation: mixed; text-align: center;
  font: 400 0.98rem/1.22 var(--font-serif); letter-spacing: 0.05em; color: var(--ink);
}
.bk__title mark { background: var(--gold); color: #000; }
.bk__plate {
  flex: none; min-width: 62%; box-sizing: border-box; padding: 5px 3px; text-align: center;
  border: 1px solid var(--foil); font: 700 0.6rem/1 var(--font-tech); letter-spacing: 0.08em; text-transform: uppercase; color: var(--foil);
}
.bk__plate--grade { font: 700 1.05rem/1 var(--font-serif); letter-spacing: 0; text-transform: none; }

/* Bookmark ribbon: sticks up out of the top of the book */
.bk.is-progress .bk__spine::after {
  content: ""; position: absolute; right: 22%; top: -24px; width: 11px; height: 30px; background: var(--gold); z-index: -1;
  clip-path: polygon(0 0, 50% 22%, 100% 0, 100% 100%, 0 100%);
  transition: top 480ms var(--ease), height 480ms var(--ease);
}
.bk.is-progress .bk__spine:hover::after { top: -32px; height: 38px; }

/* Search: matches stay lit, the rest of the library dims */
.bk.is-dim .bk__spine { opacity: 0.16; filter: grayscale(1); }
.bk.is-hit .bk__spine { transform: translateY(-10px); box-shadow: inset 0 0 0 1px var(--edge), 0 0 0 1px var(--gold), 0 14px 30px rgba(0, 0, 0, 0.8); }
.bk.is-hit .bk__spine:hover { transform: translateY(-18px); }
.bk.is-flash .bk__spine { animation: lib-flash 1.4s ease 2; }
@keyframes lib-flash { 50% { box-shadow: inset 0 0 0 1px var(--edge), 0 0 0 2px var(--gold-hi), 0 0 34px rgba(201, 164, 76, 0.45); } }

/* Rise-in when a shelf scrolls into view (class set by courses.js) */
.lib-anim .lib-row .bk__spine {
  opacity: 0; translate: 0 36px;
  transition: transform 480ms var(--ease), box-shadow 300ms ease, filter 320ms ease,
    translate 900ms var(--ease) calc(var(--i) * 40ms), opacity 700ms ease calc(var(--i) * 40ms);
}
.lib-anim .lib-row.is-in .bk__spine { opacity: 1; translate: 0 0; }
.lib-anim .lib-row.is-in .bk.is-dim .bk__spine { opacity: 0.16; }

.lib-empty { padding: 4rem 1rem; text-align: center; border: 1px solid var(--line-soft); }
.lib-empty__title { margin: 0 0 0.5rem; font: 400 1.5rem/1.3 var(--font-serif); color: var(--text); }
.lib-empty p { margin: 0 0 1.75rem; color: var(--text-sec); }

/* ─── 03 · The card catalogue (every course as plain text) ─────────── */
.lib-catalogue { border-top: 1px solid var(--line); }
.lib-drawer { border-bottom: 1px solid var(--line-soft); }
.lib-drawer > summary {
  list-style: none; display: grid; grid-template-columns: 3rem 1fr auto 1.5rem; align-items: center; gap: 1rem;
  padding: 1.15rem 0.25rem; cursor: pointer; transition: background 200ms ease;
}
.lib-drawer > summary::-webkit-details-marker { display: none; }
.lib-drawer > summary::after { content: "+"; justify-self: end; font: 400 1.4rem/1 var(--font-tech); color: var(--gold); }
.lib-drawer[open] > summary::after { content: "3"; }
.lib-drawer > summary:hover { background: var(--surface); }
.lib-drawer > summary:focus-visible { outline: 1px solid var(--gold); outline-offset: -2px; }
.lib-drawer h3 { margin: 0; font: 400 clamp(1.05rem, 1.8vw, 1.25rem)/1.3 var(--font-serif); color: var(--text); letter-spacing: 0.02em; }
.lib-drawer__num { font: 400 1.45rem/1 var(--font-serif); color: var(--gold); }
.lib-drawer__count { font: 600 0.62rem/1 var(--font-tech); letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-sec); }
.lib-drawer__sub { margin: 0 0 1.1rem 4rem; font-size: 0.95rem; line-height: 1.55; color: var(--text-sec); }
.lib-cards { list-style: none; margin: 0 0 1.75rem 4rem; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.lib-card { position: relative; padding: 1.1rem 1.2rem 1.6rem; background: #0a0a0a; border: 1px solid var(--line-soft); }
.lib-card::after { content: ""; position: absolute; left: 50%; bottom: 0.45rem; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; border: 1px solid rgba(201, 164, 76, 0.4); }
.lib-card:target { border-color: var(--gold); }
.lib-card__vol { font: 600 0.6rem/1 var(--font-tech); letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); }
.lib-card h4 { margin: 0.4rem 0 0.4rem; font: 400 1.02rem/1.35 var(--font-serif); color: var(--text); letter-spacing: 0.02em; }
.lib-card__meta { margin: 0 0 0.6rem; font: 600 0.62rem/1.5 var(--font-tech); letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-sec); }
.lib-card p { margin: 0 0 0.7rem; font-size: 0.92rem; line-height: 1.6; color: var(--text-sec); }
.lib-card .lib-card__meta { font-size: 0.62rem; }
.lib-card__open { font: 600 0.62rem/1 var(--font-tech); letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); text-underline-offset: 3px; }
.lib-card__open:hover { color: var(--gold-hi); }
@media (max-width: 760px) {
  .lib-drawer > summary { grid-template-columns: 2.2rem 1fr 1.2rem; gap: 0.75rem; }
  .lib-drawer__count { display: none; }
  .lib-drawer__sub, .lib-cards { margin-left: 0; }
  .lib-cards { grid-template-columns: 1fr; }
}

/* ─── 04 · Still reading ───────────────────────────────────────────── */
.lib-next { display: grid; grid-template-columns: 1.15fr 0.85fr; gap: clamp(2.5rem, 6vw, 5rem); align-items: center; }
.lib-next .lib-body { margin-bottom: 0; }
.lib-next__nav { display: flex; flex-direction: column; gap: 0.75rem; }
.lib-navcard {
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "label arrow" "title arrow"; gap: 0.35rem 1rem; align-items: center;
  padding: 1.35rem 1.5rem; text-decoration: none; background: var(--surface); border: 1px solid var(--line);
  transition: border-color 220ms ease, transform 220ms var(--ease), background 220ms ease;
}
.lib-navcard:hover { border-color: var(--line-strong); transform: translateY(-3px); background: var(--surface-soft); }
.lib-navcard__label { grid-area: label; font: 600 0.64rem/1 var(--font-tech); letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); }
.lib-navcard__title { grid-area: title; font: 400 1.15rem/1.25 var(--font-serif); color: var(--text); }
.lib-navcard__arrow { grid-area: arrow; font-size: 1.25rem; color: var(--gold); transition: transform 220ms var(--ease); }
.lib-navcard:hover .lib-navcard__arrow { transform: translateX(4px); }
.lib-navcard--back:hover .lib-navcard__arrow { transform: translateX(-4px); }

/* ─── The open book ────────────────────────────────────────────────── */
.lib-open {
  width: min(1060px, calc(100% - 2rem)); max-width: none; max-height: calc(100dvh - 2rem); padding: 0; margin: auto;
  color: var(--text); background: transparent; border: 0; overflow: visible;
}
.lib-open::backdrop { background: rgba(0, 0, 0, 0.86); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.lib-open__book {
  display: grid; grid-template-columns: 1fr 1fr; perspective: 2000px;
  max-height: calc(100dvh - 2rem); overflow: auto; overscroll-behavior: contain;
  box-shadow: 0 50px 120px rgba(0, 0, 0, 0.9);
}
.lib-open__page {
  display: flex; flex-direction: column; min-height: 540px; box-sizing: border-box;
  padding: clamp(2rem, 4vw, 3.25rem); border: 1px solid rgba(201, 164, 76, 0.28); backface-visibility: hidden;
}
.lib-open__page--l { border-right: 0; transform-origin: 100% 50%; background: linear-gradient(90deg, #0e0e0e 0%, #0b0b0b 78%, #040404 100%); }
.lib-open__page--r { border-left: 1px solid #000; transform-origin: 0 50%; background: linear-gradient(90deg, #040404 0%, #0b0b0b 22%, #0e0e0e 100%); }
.lib-open[open] .lib-open__page--l { animation: lib-open-l 780ms var(--ease); }
.lib-open[open] .lib-open__page--r { animation: lib-open-r 780ms var(--ease); }
@keyframes lib-open-l { from { transform: rotateY(62deg); opacity: 0.15; } to { transform: none; opacity: 1; } }
@keyframes lib-open-r { from { transform: rotateY(-62deg); opacity: 0.15; } to { transform: none; opacity: 1; } }
.lib-open__book.is-turning .lib-open__page--r { animation: lib-turn 560ms var(--ease); }
.lib-open__book.is-turning .lib-open__page--l { animation: lib-fade 560ms ease; }
@keyframes lib-turn { from { transform: rotateY(-38deg); opacity: 0.3; } to { transform: none; opacity: 1; } }
@keyframes lib-fade { from { opacity: 0.2; } to { opacity: 1; } }

.lib-open__eyebrow { font: 600 0.68rem/1.4 var(--font-tech); letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); }
.lib-open__vol { margin: 0.5rem 0 1.75rem; font: italic 400 0.92rem/1.3 var(--font-sans); color: var(--text-sec); }
.lib-open__title { margin: 0 0 0.75rem; font: 400 clamp(1.5rem, 2.8vw, 2.15rem)/1.22 var(--font-serif); color: var(--text); text-wrap: balance; }
.lib-open__kind { margin: 0; font-style: italic; color: var(--text-sec); }
.lib-open__rule { position: relative; display: block; width: 72px; height: 1px; margin: 1.75rem 0; background: var(--gold); }
.lib-open__rule::after { content: ""; position: absolute; left: 100%; top: -3px; width: 6px; height: 6px; margin-left: 6px; border: 1px solid var(--gold); transform: rotate(45deg); }
.lib-open__result { margin-bottom: 1.75rem; }
.lib-open__result small { display: block; margin-bottom: 0.4rem; font: 600 0.6rem/1 var(--font-tech); letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); }
.lib-open__result strong { font: 400 1.15rem/1.3 var(--font-serif); color: var(--text); }
.lib-open__result.is-grade strong { font: 700 clamp(3rem, 6vw, 4.5rem)/1 var(--font-serif); color: var(--gold); }
.lib-open__meta { margin-top: auto; }

.bk-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; border-top: 1px solid var(--line-soft); }
.bk-meta div { padding: 0.8rem 0.75rem 0.8rem 0; border-bottom: 1px solid var(--line-soft); }
.bk-meta dt { font: 600 0.6rem/1 var(--font-tech); letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold); margin-bottom: 0.4rem; }
.bk-meta dd { margin: 0; font-size: 0.95rem; line-height: 1.4; color: var(--text); }

.lib-open__info p { margin: 0 0 1.5rem; font-size: 1.05rem; line-height: 1.75; color: var(--text-sec); }
.lib-open__info p::first-letter { float: left; margin: 0.08em 0.12em 0 0; font: 400 3.1em/0.8 var(--font-serif); color: var(--gold); }
.bk-tags { list-style: none; display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 2rem; padding: 0; }
.bk-tags li { font: 600 0.66rem/1 var(--font-tech); letter-spacing: 0.1em; text-transform: uppercase; color: var(--text); padding: 0.45rem 0.6rem; border: 1px solid var(--line); }
.lib-open__actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 2rem; }
.lib-open__pager { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-top: 1.1rem; border-top: 1px solid var(--line-soft); }
.lib-open__pager button {
  background: none; border: 0; padding: 0.4rem 0; cursor: pointer; color: var(--text);
  font: 600 0.7rem/1 var(--font-tech); letter-spacing: 0.14em; text-transform: uppercase; transition: color 200ms ease;
}
.lib-open__pager button:hover { color: var(--gold); }
.lib-open__pager span { font: 600 0.68rem/1 var(--font-tech); letter-spacing: 0.14em; color: var(--text-sec); font-variant-numeric: tabular-nums; }
.lib-open__close {
  position: absolute; top: 0; right: 0; width: 48px; height: 48px; display: grid; place-items: center; z-index: 3;
  background: #000; color: var(--text); border: 1px solid var(--line); font-size: 1.5rem; line-height: 1; cursor: pointer; transition: color 200ms ease;
}
.lib-open__close:hover { color: var(--gold); }
.lib-open button:focus-visible, .lib-open a:focus-visible { outline: 1px solid var(--gold); outline-offset: 3px; }
html.lib-locked, html.lib-locked body { overflow: hidden; }

/* ─── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .lib-next { grid-template-columns: 1fr; }
  .lib-guide { grid-template-columns: 1fr; align-items: start; }
  .lib-dir { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lib-dir__item { border-bottom: 1px solid var(--line-soft); }
  .lib-dir__item:nth-child(3n) { border-right: 0; }
  .lib-dir__item:nth-last-child(-n + 3) { border-bottom: 0; }
}

@media (max-width: 820px) {
  /* the bar would eat too much of a small screen, so it scrolls with the page */
  .lib-toolbar { position: relative; top: auto; grid-template-columns: 1fr; grid-template-areas: "search" "count" "try"; }
  .lib-open { width: 100%; max-height: 100dvh; height: 100dvh; }
  .lib-open__book { grid-template-columns: 1fr; grid-template-rows: auto 1fr; max-height: 100dvh; height: 100%; }
  .lib-open__page { min-height: auto; }
  .lib-open__page--l { border-right: 1px solid rgba(201, 164, 76, 0.28); border-bottom: 0; background: #0b0b0b; padding-top: 3.75rem; }
  .lib-open__page--r { border-left: 1px solid rgba(201, 164, 76, 0.28); border-top: 1px solid var(--line-soft); background: #0b0b0b; }
  .lib-open__meta { margin-top: 0; }
  @keyframes lib-open-l { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
  @keyframes lib-open-r { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
  @keyframes lib-turn { from { opacity: 0.2; } to { opacity: 1; } }
}

/* Phones: each section becomes a stack of books lying flat, label beneath */
@media (max-width: 640px) {
  .lib-dir { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lib-dir__item, .lib-dir__item:nth-child(n) { border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); padding: 0.7rem 0.8rem; }
  .lib-dir__item:nth-child(2n) { border-right: 0; }
  .lib-dir__item:nth-last-child(-n + 2) { border-bottom: 0; }
  .lib-legend { gap: 1rem; flex-wrap: wrap; }
  .lib-legend__item p { white-space: normal; font-size: 0.8rem; }
  .lib-case { --case-pad: 6px; --row-pad: 10px; --board: 36px; }
  .lib-row { flex-direction: column; align-items: stretch; padding-top: 22px; }
  .lib-seg__books { flex-direction: column; align-items: center; gap: 3px; }
  .bk { width: 100%; justify-content: center; }
  .bk:nth-child(3n + 1) { translate: -7px 0; }
  .bk:nth-child(3n + 2) { translate: 6px 0; }
  .bk__spine {
    width: calc(58% + var(--len) * 40%); height: auto; min-height: calc(var(--w) * 0.62);
    flex-direction: row; gap: 9px; padding: 0 11px; transform-origin: 50% 50%;
  }
  .bk__spine::before { background: linear-gradient(180deg, rgba(255, 255, 255, 0.08) 0%, transparent 30%, transparent 70%, rgba(0, 0, 0, 0.38) 100%); }
  .bk__spine:hover, .bk__spine:focus-visible { transform: translateX(6px); }
  .bk.is-hit .bk__spine, .bk.is-hit .bk__spine:hover { transform: translateX(8px); }
  .bk__band { align-self: stretch; width: 6px; height: auto; margin: 10px 0; border: 0; border-left: 1px solid var(--foil); border-right: 1px solid var(--foil); }
  .bk__title { writing-mode: horizontal-tb; text-align: left; padding: 10px 2px; font-size: 0.86rem; line-height: 1.25; }
  .bk__plate { min-width: 2.9em; }
  .bk.is-progress .bk__spine::after { left: auto; right: -20px; bottom: auto; top: 30%; width: 24px; height: 9px; z-index: 2; clip-path: polygon(0 0, 100% 0, 76% 50%, 100% 100%, 0 100%); }
  .bk.is-progress .bk__spine:hover::after { top: 30%; height: 9px; }
  .lib-anim .lib-row .bk__spine { translate: -24px 0; }
  .lib-anim .lib-row.is-in .bk__spine { translate: 0 0; }
  .lib-end { display: none; }
  .lib-try { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -0.9rem; padding: 0 0.9rem; }
  .lib-try::-webkit-scrollbar { display: none; }
  .lib-try button { flex: 0 0 auto; }
  .lib-toolbar { padding: 0.75rem 0.9rem; gap: 0.65rem; }
  .lib-result { grid-template-columns: 2rem 1fr auto; padding: 0.7rem 0.8rem; }
  .bk-meta { grid-template-columns: 1fr; }
  .lib-open__actions .lib-btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .bk__spine, .bk__spine:hover, .bk__spine:focus-visible { transition: opacity 200ms ease; transform: none; }
  .lib-anim .lib-row .bk__spine { opacity: 1; translate: none; transition: none; }
  .bk.is-flash .bk__spine { animation: none; }
  .lib-open[open] .lib-open__page--l, .lib-open[open] .lib-open__page--r, .lib-open__book.is-turning .lib-open__page--l, .lib-open__book.is-turning .lib-open__page--r { animation: none; }
}
