/* library.css — Library + Bibliography page components, plus the
   epistemic-filter UI that now lives on /search.html. */

/* ============================================================
   LIBRARY PALETTE — scoped warm "candlelight" accent
   Only loaded on /library.html (via $if(library)$) and /search.html,
   so defining at :root here is effectively page-scoped. Consumed by
   section headings, the divider, the intro blockquote, and the
   "more on this shelf" link to give the library page a fine-press
   feel without touching global colors.
   ============================================================ */

:root {
    --library-accent:        #524638;   /* muted warm-gray — reads as "warm" only if you look */
    --library-accent-muted:  #7c7164;   /* dusty taupe */
    --library-intro-ink:     #3c3328;
}

[data-theme="dark"] {
    --library-accent:        #b5a890;   /* soft oat */
    --library-accent-muted:  #897f6e;
    --library-intro-ink:     #c8beac;
}

[data-theme="cappuccino"] {
    --library-accent:        #d0b888;   /* foam — matches text-muted */
    --library-accent-muted:  #957a5a;
    --library-intro-ink:     #dcc296;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --library-accent:        #b5a890;
        --library-accent-muted:  #897f6e;
        --library-intro-ink:     #c8beac;
    }
}

/* ============================================================
   FILTER UI
   Originally the Library's sort+filter panel; the sort panel
   and numeric filter were dropped in Phase 4 when the Library
   unified onto item-cards. The filter panel itself remains in
   use on /search.html, which reuses the same classes and
   filter-panel markup.
   ============================================================ */

.library-filter-toggle {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 0.15em 0.55em;
    cursor: pointer;
    margin-left: auto;
    transition: border-color 0.1s, color 0.1s;
}

.library-filter-toggle:hover,
.library-filter-toggle[aria-expanded="true"] {
    border-color: var(--text-muted);
    color: var(--text);
}

.filter-toggle-badge {
    font-weight: 600;
}

.library-filters {
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    margin-top: 0.75rem;
}

.library-filters[hidden] {
    display: none;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.45rem;
}

.filter-label {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--text-faint);
    width: 5.5rem;
    flex-shrink: 0;
}

.filter-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
}

.filter-prefix {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--text-faint);
}

.filter-btn {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border);
    border-radius: 2px;
    padding: 0.1em 0.45em;
    cursor: pointer;
    transition: border-color 0.1s, color 0.1s;
}

.filter-btn:hover {
    border-color: var(--border-muted);
    color: var(--text);
}

.filter-btn.is-active {
    border-color: var(--text-muted);
    color: var(--text);
    font-weight: 600;
}

.filter-number {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    width: 3rem;
    padding: 0.1em 0.3em;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: transparent;
    color: var(--text);
}

.filter-number:focus {
    outline: none;
    border-color: var(--text-muted);
}

.filter-row-actions {
    justify-content: flex-end;
    margin-top: 0.25rem;
}

.filter-clear-btn {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    color: var(--text-faint);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.filter-clear-btn:hover {
    color: var(--text);
}

/* Search-page result filtering (applied via search-filters.js) */

.search-filtered {
    display: none !important;
}

/* Search page filter controls — just the toggle, no sort buttons */

.search-filter-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 0.5rem;
}

/* ============================================================
   PORTAL SECTIONS
   Shared by the Library and by /bibliography/<keyword>/ pages
   for the Writings + References section headers.
   ============================================================ */

.library-section {
    margin-bottom: 3rem;
}

/* Section heading — fine-press chapter marker. Spectral small-caps in
   walnut ink, letterspaced for a traditional printer's-ornament look.
   The ornament span inherits currentColor and picks up the same accent. */
.library-section h2 {
    font-family: var(--font-serif);
    font-size: 1.2rem;
    font-variant: all-small-caps;
    font-feature-settings: "smcp" 1;
    letter-spacing: 0.09em;
    color: var(--library-accent);
    text-transform: none;
    font-weight: 400;
    margin: 0 0 0.9rem 0;
}

/* Per-shelf ornament sitting before the heading text. SVGs in
   /images/dingbats/ painted via mask-image so they inherit
   currentColor (→ the same muted tone as the heading). */
.library-section-ornament {
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.5em;
    background-color: currentColor;
    mask-repeat: no-repeat;
    mask-position: center;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    -webkit-mask-size: contain;
    vertical-align: -0.12em;
}

.library-section-ornament[data-ornament="research"] {
    mask-image: url('/images/dingbats/research.svg');
    -webkit-mask-image: url('/images/dingbats/research.svg');
}
.library-section-ornament[data-ornament="nonfiction"] {
    mask-image: url('/images/dingbats/nonfiction.svg');
    -webkit-mask-image: url('/images/dingbats/nonfiction.svg');
}
.library-section-ornament[data-ornament="fiction"] {
    mask-image: url('/images/dingbats/fiction.svg');
    -webkit-mask-image: url('/images/dingbats/fiction.svg');
}
.library-section-ornament[data-ornament="poetry"] {
    mask-image: url('/images/dingbats/poetry.svg');
    -webkit-mask-image: url('/images/dingbats/poetry.svg');
}
.library-section-ornament[data-ornament="music"] {
    mask-image: url('/images/dingbats/clef.svg');
    -webkit-mask-image: url('/images/dingbats/clef.svg');
}
.library-section-ornament[data-ornament="ai"] {
    mask-image: url('/images/dingbats/ai.svg');
    -webkit-mask-image: url('/images/dingbats/ai.svg');
}
.library-section-ornament[data-ornament="tech"] {
    mask-image: url('/images/dingbats/tech.svg');
    -webkit-mask-image: url('/images/dingbats/tech.svg');
}
.library-section-ornament[data-ornament="miscellany"] {
    mask-image: url('/images/dingbats/trefoil.svg');
    -webkit-mask-image: url('/images/dingbats/trefoil.svg');
}

/* Inter-shelf divider. Adjacent-sibling selector renders between
   actually-emitted sections — a section hidden by its $if$ gate
   leaves no orphan divider because it never hits the DOM. */
.library-section + .library-section::before {
    content: "";
    display: block;
    width: 240px;
    max-width: 60%;
    height: 24px;
    margin: 2.5rem auto;
    color: var(--library-accent-muted);
    background-color: currentColor;
    mask-image: url('/images/dingbats/library-divider.svg');
    -webkit-mask-image: url('/images/dingbats/library-divider.svg');
    mask-repeat: no-repeat;
    mask-position: center;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    -webkit-mask-size: contain;
}

/* "More on this shelf →" link, shown when the portal has more
   items than the shelf's cap. Right-aligned, italic, subdued. */
.library-more {
    text-align: right;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 0.95rem;
    color: var(--library-accent-muted);
    margin: 0.75rem 0 0;
}

.library-more a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-fast), color var(--transition-fast);
}

.library-more a:hover {
    color: var(--library-accent);
    border-bottom-color: var(--library-accent-muted);
}

/* Leading blockquote above the shelves, lifted from content/library.md.
   Set as an epigraph: narrower measure, italic serif, warm ink, no
   left-bar decoration. */
.library-intro {
    max-width: 32rem;
    margin: 1.5rem 0 2.75rem;
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 0.95rem;
    line-height: 1.55;
    color: var(--library-intro-ink);
}

.library-intro blockquote {
    border: none;
    margin: 0;
    padding: 0;
}

.library-intro blockquote p {
    margin: 0 0 0.4rem 0;
}

.library-intro blockquote p:last-of-type {
    margin: 0;
    font-style: normal;
    font-size: 0.9rem;
    color: var(--library-accent-muted);
}

.library-intro a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--library-accent-muted);
    text-decoration-thickness: 0.05em;
    text-underline-offset: 0.2em;
}

.library-intro a:hover {
    text-decoration-color: var(--library-accent);
}

/* Card-level typography refinements scoped to the library page.
   Oldstyle figures on dates read as book-typesetting rather than
   tabular UI; small-caps on the item-kind badge keeps it in the
   same fine-press register as the section heading. Scoped via
   `.library-section` so /new.html and tag pages keep their
   current treatment (lining figures, uppercase badges). */
.library-section .item-card-date {
    font-variant-numeric: oldstyle-nums proportional-nums;
    font-feature-settings: "onum" 1, "pnum" 1;
}

.library-section .item-card-kind {
    font-variant: all-small-caps;
    font-feature-settings: "smcp" 1;
    letter-spacing: 0.06em;
}

.library-section h2 a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.library-section h2 a:hover {
    border-bottom-color: var(--library-accent-muted);
}

/* ============================================================
   SEE ALSO — compact chain (Phase 4)
   Secondary navigation above the portal sections: New,
   Commonplace, Colophon, Bibliography. Single-line `·`-separated
   list, sans-serif, muted, reads as a utility row rather than
   content.
   ============================================================ */

.library-see-also {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0.25rem 0 2rem;
}

.library-see-also a {
    color: var(--text-muted);
    text-decoration: underline;
    text-decoration-color: var(--border);
    text-decoration-thickness: 0.08em;
    text-underline-offset: 0.2em;
    transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

.library-see-also a:hover {
    color: var(--text);
    text-decoration-color: var(--border-muted);
}

.library-see-also-sep {
    color: var(--text-faint);
    padding: 0 0.35em;
    user-select: none;
}

/* ============================================================
   BIBLIOGRAPHY INDEX — alphabet jump strip + letter headers
   Complete A–Z row at top of /bibliography/ so the page reads
   as a scannable reference. Absent letters render as muted
   non-links so the strip stays visually complete without gaps.
   ============================================================ */

.bibliography-alphabet {
    display: flex;
    flex-wrap: wrap;
    gap: 0.15em;
    margin: 0.25rem 0 1.5rem;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    line-height: 1.4;
}

.bibliography-alphabet .alpha {
    display: inline-block;
    min-width: 1.2em;
    padding: 0.05em 0.2em;
    text-align: center;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}

.bibliography-alphabet a.alpha:hover {
    color: var(--text);
    border-bottom-color: var(--border-muted);
}

.bibliography-alphabet .alpha-empty {
    color: var(--text-faint);
    opacity: 0.45;
    cursor: default;
}

.bibliography-letter {
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-variant: small-caps;
    text-transform: lowercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 500;
    margin: 1.5rem 0 0.5rem;
    scroll-margin-top: 1rem;
}
