/* ===== CSS Variables & Reset ===== */
:root {
    --color-bg: #faf9f7;
    --color-surface: #ffffff;
    --color-surface-hover: #f5f4f1;
    --color-border: #e5e2dc;
    --color-border-light: #f0ede8;
    --color-text: #1a1a1a;
    --color-text-secondary: #5c5c5c;
    --color-text-muted: #6b6b6b;
    --color-accent: #2563eb;
    --color-accent-hover: #1d4ed8;
    --color-accent-light: #eff6ff;
    --color-paper: #7c3aed;
    --color-book: #047857;
    --color-grey: #9a5405;
    --color-tag-bg: #f3f4f6;
    --color-tag-text: #374151;
    /* Badge fills. These were literals in four rules and had no dark value,
       so in dark mode a pale mint chip carried #34d399 text at 1.7:1. A
       literal is invisible to any check that reads the token block, which is
       why they are tokens now. */
    --badge-paper-bg: #f3f0ff;
    --badge-book-bg:  #ecfdf5;
    --badge-grey-bg:  #fffbeb;
    --badge-free-bg:  #eff6ff;
    --color-on-accent: #ffffff; /* see FILLS in check_contrast.py */
    --badge-bad-bg:   #fef2f2;
    --color-bad:      #b42318;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
    --max-width: 1120px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 24px;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===== Header ===== */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 24px 0;
}

.site-header .container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
}

.header-content {
    flex: 1;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    text-decoration: none;
}

.brand-link:hover {
    color: var(--color-accent);
    text-decoration: none;
}

.brand-icon {
    font-size: 1.2rem;
    color: var(--color-accent);
}

.brand-separator {
    color: var(--color-text-muted);
    font-weight: 300;
}

.site-title {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
}

.site-tagline {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.header-nav {
    display: flex;
    gap: 16px;
    align-items: center;
    padding-top: 6px;
}

.nav-link {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    padding: 4px 0;
}

.nav-link:hover {
    color: var(--color-accent);
    text-decoration: none;
}

/* ===== Stats Bar ===== */
.stats-bar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 16px 0;
}

.stats-grid {
    display: flex;
    gap: 32px;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.stat-number {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

/* ===== The library layout =====
 *
 * Before 2026-09-23 the search box and five filter groups ran the full width
 * above the results, and the whole block was `position: sticky`. Measured at
 * 1280x900: 620px of controls before the first resource, so exactly one card
 * was on the first screen and it was cut by the fold. Scrolling then pinned
 * the 500px of filters to the top of the viewport.
 *
 * The filters are a rail now, and the results start at the top of the page.
 * The sticky is on the rail, which is short enough to justify one.
 */
.library {
    display: block;
}

@media (min-width: 1024px) {
    .library {
        display: grid;
        grid-template-columns: 286px minmax(0, 1fr);
        gap: 40px;
        align-items: start;
    }
    .library > .search-section,
    .library > .results-section {
        min-width: 0;
    }
    .library .rail {
        position: sticky;
        top: 16px;
        max-height: calc(100vh - 32px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-right: 4px;
    }
}

.search-section {
    padding: 24px 0 0;
    background: var(--color-bg);
}

/* Below the rail breakpoint the filters are behind a disclosure. Five filter
 * groups is 500px on a phone, which is the whole screen and then some. */
.filter-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 9px 16px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    cursor: pointer;
}

.filter-toggle:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

/* `display` on the element beats the hidden attribute's UA rule, so an empty
 * badge would render as a 0 that means "no filters" and reads as "no results". */
.filter-toggle-count[hidden] {
    display: none;
}

.filter-toggle-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.7rem;
    border-radius: 10px;
    background: var(--color-accent);
    color: var(--color-on-accent);
}

.filter-toggle[aria-expanded="false"] + .filter-bar {
    display: none;
}

@media (min-width: 1024px) {
    .filter-toggle {
        display: none;
    }
    .filter-toggle[aria-expanded="false"] + .filter-bar {
        display: block;
    }
}

.search-box {
    position: relative;
    margin-bottom: 16px;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 14px 44px 14px 48px;
    font-size: 1rem;
    font-family: var(--font-sans);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.2s, box-shadow 0.2s;
}

#searchInput:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#searchInput::placeholder {
    color: var(--color-text-muted);
}

.clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    display: none;
}

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

.clear-btn.visible {
    display: block;
}

.filter-bar {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--color-border-light);
}

.filter-group {
    margin-bottom: 8px;
}

.filter-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
    display: block;
}

.filter-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.pill {
    padding: 6px 14px;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.pill:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.pill.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-on-accent);
}

.filter-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
}

@media (min-width: 1024px) {
    .filter-row {
        display: block;
    }
    .filter-group {
        margin-bottom: 16px;
    }
    .filter-bar {
        border-bottom: none;
        padding-bottom: 0;
    }
    .sort-select {
        width: 100%;
    }
}

.filter-row .filter-group:first-child {
    flex: 1;
}

/* Pill counts */
.pill-count {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-tag-bg);
    border-radius: 10px;
    padding: 0 6px;
    margin-left: 4px;
    vertical-align: middle;
}

.pill.active .pill-count {
    color: var(--color-on-accent);
    background: color-mix(in srgb, var(--color-on-accent) 22%, transparent);
}

/* Active filter chips */
.active-filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 12px;
    align-items: center;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-family: var(--font-sans);
    font-weight: 500;
    padding: 4px 10px;
    border: 1px solid var(--color-accent);
    border-radius: 16px;
    background: var(--color-accent-light);
    color: var(--color-accent);
    cursor: pointer;
    transition: all 0.15s;
}

.filter-chip:hover {
    background: var(--color-accent);
    color: var(--color-on-accent);
}

.filter-chip span {
    font-size: 1rem;
    line-height: 1;
}

.filter-chip-clear {
    border-style: dashed;
    background: transparent;
    color: var(--color-text-secondary);
    border-color: var(--color-border);
}

.filter-chip-clear:hover {
    background: var(--color-surface-hover);
    color: var(--color-text);
    border-color: var(--color-text-muted);
}

.sort-select {
    padding: 6px 12px;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
}

/* ===== Results ===== */
.results-section {
    padding: 16px 0 48px;
}

@media (min-width: 1024px) {
    .results-section {
        padding-top: 24px;
    }
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.results-count {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.results-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.tool-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.export-menu {
    position: relative;
}

.export-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 120;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    padding: 4px;
    display: flex;
    flex-direction: column;
}

.export-dropdown button {
    text-align: left;
    padding: 8px 12px;
    font-size: 0.82rem;
    font-family: var(--font-sans);
    border: none;
    background: none;
    color: var(--color-text);
    cursor: pointer;
    border-radius: 4px;
}

.export-dropdown button:hover {
    background: var(--color-surface-hover);
    color: var(--color-accent);
}

.view-toggle {
    display: flex;
    gap: 4px;
}

/* Search highlight */
mark {
    background: rgba(250, 204, 21, 0.4);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

[data-theme="dark"] mark {
    background: rgba(250, 204, 21, 0.28);
    color: #fde68a;
}

/* Access indicator on cards */
.resource-access {
    font-size: 0.72rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.resource-access::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
    background: var(--color-text-muted);
}

.resource-access.access-dot-open_access { color: var(--color-book); }
.resource-access.access-dot-open_access::before { background: var(--color-book); }
.resource-access.access-dot-free_to_read { color: var(--color-accent); }
.resource-access.access-dot-free_to_read::before { background: var(--color-accent); }
.resource-access.access-dot-check_access { color: var(--color-grey); }
.resource-access.access-dot-check_access::before { background: var(--color-grey); }

/* Back to top */
.back-to-top {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s, visibility 0.2s, color 0.15s, border-color 0.15s;
    z-index: 200;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    color: var(--color-accent);
    border-color: var(--color-accent);
}

@media (max-width: 480px) {
    .back-to-top { right: 16px; bottom: 16px; }
    .results-tools .tool-btn span { display: none; }
    .results-tools .tool-btn { padding: 6px 8px; }
}

.view-btn {
    padding: 6px 8px;
    background: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

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

.view-btn.active {
    color: var(--color-accent);
    border-color: var(--color-border);
    background: var(--color-surface);
}

/* ===== Resource Cards ===== */
.resources-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.resources-list.grid-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 12px;
}

.resource-card {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    transition: all 0.15s;
    text-decoration: none;
    color: inherit;
}

.resource-card:hover {
    border-color: var(--color-border);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    background: var(--color-surface-hover);
}

.resource-card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 6px;
}

.resource-type-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 3px;
}

.resource-type-badge.paper {
    background: var(--badge-paper-bg);
    color: var(--color-paper);
}

.resource-type-badge.book {
    background: var(--badge-book-bg);
    color: var(--color-book);
}

.resource-type-badge.grey_literature {
    background: var(--badge-grey-bg);
    color: var(--color-grey);
}

.resource-title {
    font-family: var(--font-serif);
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-text);
    flex: 1;
}

.resource-meta {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.resource-authors {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.resource-year {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.resource-description {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    line-height: 1.5;
    margin-bottom: 8px;
}

.resource-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* A resource can carry more than one topic, so the left side of the footer
   wraps rather than pushing the card sideways. min-width:0 is load-bearing:
   without it a flex item's min-content keeps the row at its natural width and
   the card overflows on a phone instead of wrapping. */
.resource-topics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

.resource-topic-tag {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    font-weight: 500;
}

.resource-footer-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: none;
}

.resource-tag-count {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.resource-link-icon {
    font-size: 0.8rem;
    color: var(--color-accent);
    opacity: 0;
    transition: opacity 0.15s;
}

.resource-card:hover .resource-link-icon {
    opacity: 1;
}

/* ===== Load More ===== */
.load-more-container {
    text-align: center;
    padding: 24px 0;
}

.load-more-btn {
    padding: 10px 32px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.15s;
}

.load-more-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

/* ===== No Results ===== */
.no-results {
    text-align: center;
    padding: 64px 24px;
    color: var(--color-text-muted);
}

.no-results svg {
    margin-bottom: 16px;
    opacity: 0.4;
}

.no-results p {
    margin-bottom: 16px;
    font-size: 1rem;
}

.reset-btn {
    padding: 8px 20px;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-accent);
    cursor: pointer;
}

.reset-btn:hover {
    background: var(--color-accent-light);
}

/* ===== About Section ===== */
.about-section {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 48px 0;
}

.about-section h2 {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    margin-bottom: 20px;
}

.about-content {
    max-width: 720px;
}

.about-content p {
    margin-bottom: 14px;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
    line-height: 1.7;
}

.about-topics {
    margin-top: 24px;
}

.about-topics h3,
.about-contribute h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.topic-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.topic-tag {
    font-size: 0.82rem;
    padding: 5px 14px;
    border-radius: 20px;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    font-weight: 500;
}

.about-contribute {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--color-border-light);
}

.about-contribute p {
    font-size: 0.9rem;
}

/* ===== Footer ===== */
.site-footer {
    border-top: 1px solid var(--color-border);
    padding: 20px 0;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.footer-content p {
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.footer-links {
    display: flex;
    gap: 16px;
}

.footer-links a {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    text-decoration: none;
}

.footer-links a:hover {
    color: var(--color-accent);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .site-header .container {
        flex-direction: column;
        gap: 12px;
    }

    .header-nav {
        padding-top: 0;
    }

    .site-title {
        font-size: 1.3rem;
    }

    .stats-grid {
        gap: 20px;
    }

    .stat-number {
        font-size: 1.1rem;
    }

    .search-section {
        position: static;
    }

    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .resources-list.grid-view {
        grid-template-columns: 1fr;
    }

    .resource-card {
        padding: 14px 16px;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .brand {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    .brand-separator {
        display: none;
    }

    .stats-grid {
        gap: 12px 20px;
    }

    .resource-card-header {
        flex-direction: column;
        gap: 6px;
    }
}

/* ===== Breadcrumb ===== */
.breadcrumb-section {
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-surface);
}

.breadcrumb {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.breadcrumb a {
    color: var(--color-text-secondary);
    text-decoration: none;
}

.breadcrumb a:hover {
    color: var(--color-accent);
}

.breadcrumb-sep {
    color: var(--color-border);
}

.breadcrumb-current {
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 400px;
}

/* ===== Detail Page ===== */
.detail-section {
    padding: 32px 0 64px;
}

.detail-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 40px;
    align-items: start;
}

.detail-main {
    min-width: 0;
}

.site-title-link {
    text-decoration: none;
    color: inherit;
}

.site-title-link:hover {
    text-decoration: none;
}

/* Detail Header */
.detail-header {
    margin-bottom: 24px;
}

.detail-badges {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.access-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 10px;
    border-radius: 4px;
    white-space: nowrap;
}

.access-badge.access-open_access {
    background: var(--badge-book-bg);
    color: var(--color-book);
}

.access-badge.access-free_to_read {
    background: var(--badge-free-bg);
    color: var(--color-accent);
}

.access-badge.access-check_access {
    background: var(--badge-grey-bg);
    color: var(--color-grey);
}

.verified-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 10px;
    border-radius: 4px;
    background: var(--badge-book-bg);
    color: var(--color-book);
}

.detail-title {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text);
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.detail-authors {
    font-size: 1rem;
    color: var(--color-text-secondary);
    margin-bottom: 8px;
    line-height: 1.5;
}

.detail-meta-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.detail-year {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
}

.detail-topic-tag {
    font-size: 0.78rem;
    padding: 3px 12px;
    border-radius: 12px;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    font-weight: 500;
}

/* Action Bar */
.detail-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    font-size: 0.85rem;
    font-family: var(--font-sans);
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}

.action-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    text-decoration: none;
}

.action-btn.action-primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-on-accent);
}

.action-btn.action-primary:hover {
    background: var(--color-accent-hover);
}

/* Citation Panel */
.citation-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 24px;
}

.citation-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.citation-tab {
    padding: 6px 14px;
    font-size: 0.8rem;
    font-family: var(--font-sans);
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.citation-tab.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--color-on-accent);
}

.citation-content {
    font-family: 'Source Code Pro', 'Menlo', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--color-text-secondary);
    background: var(--color-bg);
    padding: 12px;
    border-radius: var(--radius-sm);
    word-break: break-word;
    white-space: pre-wrap;
    margin-bottom: 8px;
}

.citation-copy {
    font-size: 0.8rem;
    font-family: var(--font-sans);
    font-weight: 500;
    padding: 6px 14px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: none;
    color: var(--color-accent);
    cursor: pointer;
    transition: all 0.15s;
}

.citation-copy:hover {
    background: var(--color-accent-light);
}

/* Description */
.detail-description {
    margin-bottom: 24px;
}

.detail-description h2,
.detail-tags h2,
.detail-notes h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--color-text);
}

.detail-description p {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--color-text-secondary);
}

/* Tags */
.detail-tags {
    margin-bottom: 24px;
}

.tag-list {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.detail-tag {
    font-size: 0.78rem;
    padding: 4px 12px;
    border-radius: 14px;
    background: var(--color-tag-bg);
    color: var(--color-tag-text);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.15s;
}

.detail-tag:hover {
    background: var(--color-accent-light);
    color: var(--color-accent);
    text-decoration: none;
}

/* Community Notes */
.detail-notes {
    margin-bottom: 24px;
    padding: 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
}

.notes-empty {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    margin-bottom: 12px;
}

.notes-contribute {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-accent);
    text-decoration: none;
}

.notes-contribute:hover {
    text-decoration: underline;
}

/* Sidebar */
.detail-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 24px;
}

.sidebar-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: 20px;
}

.sidebar-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 14px;
}

/* Metadata List */
.meta-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.meta-item dt {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.meta-item dd {
    font-size: 0.88rem;
    color: var(--color-text);
    word-break: break-word;
}

.meta-item dd a {
    color: var(--color-accent);
}

/* Related Resources */
.related-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.related-item {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: background 0.15s;
}

.related-item:hover {
    background: var(--color-surface-hover);
    text-decoration: none;
}

.related-title {
    display: block;
    font-family: var(--font-serif);
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--color-text);
    line-height: 1.4;
    margin-bottom: 2px;
}

.related-meta {
    font-size: 0.78rem;
    color: var(--color-text-muted);
}

.related-empty,
.related-loading {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    padding: 8px 0;
}

/* Detail Page Responsive */
@media (max-width: 900px) {
    .detail-layout {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .detail-sidebar {
        position: static;
    }

    .detail-title {
        font-size: 1.4rem;
    }
}

@media (max-width: 480px) {
    .detail-actions {
        flex-direction: column;
    }

    .action-btn {
        justify-content: center;
    }
}

/* ===== LitMap Visualization ===== */
.litmap-section {
    margin-bottom: 28px;
    background: var(--color-surface);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: 20px;
}

.litmap-section h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-text);
}

.litmap-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.litmap-legend {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.litmap-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

.litmap-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.litmap-actions {
    display: flex;
    gap: 4px;
}

.litmap-btn {
    padding: 5px 8px;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
}

.litmap-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
}

.litmap-container {
    position: relative;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-bg);
}

.litmap-container svg {
    display: block;
    width: 100%;
    height: 480px;
    user-select: none;
}

.litmap-node {
    transition: opacity 0.2s;
}

.litmap-node circle {
    transition: r 0.15s;
}

.litmap-node:hover circle:last-of-type {
    r: 16;
}

.litmap-caption {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    margin-top: 8px;
    text-align: center;
}

/* Tooltip */
.litmap-tooltip {
    position: absolute;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    box-shadow: var(--shadow-md);
    z-index: 100;
    pointer-events: none;
    max-width: 280px;
    font-size: 0.82rem;
}

.litmap-tooltip-title {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--color-text);
    margin-bottom: 4px;
    line-height: 1.3;
}

.litmap-tooltip-meta {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    margin-bottom: 4px;
}

.litmap-tooltip-topic {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.litmap-tooltip-action {
    font-size: 0.72rem;
    color: var(--color-accent);
    font-weight: 500;
}

/* Fullscreen mode */
.litmap-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    margin: 0;
    border-radius: 0;
    padding: 20px 24px;
    background: var(--color-bg);
}

.litmap-fullscreen .litmap-container svg {
    height: calc(100vh - 140px);
}

/* ===== Loading State ===== */
.loading-skeleton {
    background: linear-gradient(90deg, var(--color-surface-hover) 25%, var(--color-border-light) 50%, var(--color-surface-hover) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
    height: 80px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}


/* ===== Dark Mode ===== */
[data-theme="dark"] {
  --color-bg:              #0f1419;
  --color-surface:         #161b22;
  --color-surface-hover:   #1c2128;
  --color-border:          #30363d;
  --color-border-light:    #21262d;
  --color-text:            #e6edf3;
  --color-text-secondary:  #b0b8c1;
  --color-text-muted:      #909aa4;
  --color-accent:          #58a6ff;
  --color-accent-hover:    #79b8ff;
  --color-accent-light:    #1c2a3a;
  --color-paper:           #a78bfa;
  --color-book:            #34d399;
  --color-grey:            #fbbf24;
  --color-tag-bg:          #1c2128;
  --color-tag-text:        #c9d1d9;
  --badge-paper-bg:        #2a2140;
  --badge-book-bg:         #0d2f24;
  --badge-grey-bg:         #33260a;
  --badge-free-bg:         #12283f;
  --color-on-accent:       #0f1419;
  --badge-bad-bg:          #3a1512;
  --color-bad:             #fca5a5;
  --color-book:            #6ee7b7;
  --color-grey:            #fcd34d;
  --color-paper:           #c4b5fd;
  --shadow-sm:             0 1px 2px rgba(0,0,0,0.4);
  --shadow-md:             0 2px 8px rgba(0,0,0,0.5);
  --shadow-lg:             0 4px 16px rgba(0,0,0,0.6);
}

/* ===== Theme Selector ===== */
.theme-selector {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--color-surface-hover);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px;
  margin-left: 12px;
}
.theme-btn {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}
.theme-btn:hover { color: var(--color-text); background: var(--color-surface); }
.theme-btn.active { color: var(--color-accent); background: var(--color-accent-light); }
.theme-btn svg { stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 640px) {
  .theme-selector { margin-left: 6px; }
  .theme-btn { width: 26px; height: 26px; }
  .theme-btn svg { width: 14px; height: 14px; }
}


/* ==========================================================================
   IMPACTMOJO BRAND UNIFICATION LAYER
   Aligns Development Discourses with the shared library design system.
   Brand VALUES live in the vendored ImpactMojo Kit (css/impactmojo-kit.css,
   linked before this stylesheet); here we alias them onto this site's own
   token names so the kit is the single source of truth.
   ========================================================================== */

:root {
  --color-accent:        var(--imx-accent);
  --color-accent-hover:  var(--imx-accent-hover);
  --color-accent-light:  var(--imx-accent-light);
  --color-accent-2:      var(--imx-accent-2);
  --brand-grad:          var(--imx-brand-grad);
  --brand-ring:          var(--imx-ring);
}
[data-theme="dark"] {
  /* Dark values come from the kit's [data-theme="dark"] block; re-alias so
     this site's token names resolve to them in dark mode. */
  --color-accent:        var(--imx-accent);
  --color-accent-hover:  var(--imx-accent-hover);
  --color-accent-light:  var(--imx-accent-light);
  --color-accent-2:      var(--imx-accent-2);
  --brand-grad:          var(--imx-brand-grad);
  --brand-ring:          var(--imx-ring);
}

/* Brand mark → gradient chip (matches Dev Case Studies logo) */
.brand-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--brand-grad); color: #fff !important;
  font-size: 1rem; box-shadow: var(--shadow-sm);
}

/* Ecosystem cross-links in the header nav */
.eco-nav { display: inline-flex; align-items: center; gap: 14px; }
.eco-link {
  font-size: 0.85rem; font-weight: 600; color: var(--color-text-secondary);
  border-bottom: 2px solid transparent; padding-bottom: 2px; white-space: nowrap;
}
.eco-link:hover { color: var(--color-accent); text-decoration: none; }
.eco-link.current { color: var(--color-accent); border-bottom-color: var(--color-accent); }

/* Stat numbers pick up the brand */
.stat-number { color: var(--color-accent); }

/* Cards: subtle lift + gradient accent strip on hover */
.resource-card { position: relative; transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease; }
.resource-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--brand-grad); opacity: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; transition: opacity 0.18s ease;
}
.resource-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.resource-card:hover::before { opacity: 1; }

/* Bookmark button on cards */
.rc-bookmark {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--color-surface) 82%, transparent);
  border: 1px solid var(--color-border-light); border-radius: 8px;
  color: var(--color-text-muted); cursor: pointer;
  opacity: 0; transform: translateY(-2px); transition: all 0.15s;
}
.resource-card:hover .rc-bookmark,
.rc-bookmark.saved,
.rc-bookmark:focus-visible { opacity: 1; transform: translateY(0); }
.rc-bookmark:hover { color: var(--color-accent); border-color: var(--color-accent); }
.rc-bookmark.saved { color: var(--color-accent); border-color: var(--color-accent); background: var(--color-accent-light); }
.rc-bookmark svg { width: 15px; height: 15px; }

/* Saved toggle in the results tools */
.tool-btn.active { background: var(--color-accent); border-color: var(--color-accent); color: var(--color-on-accent); }
.tool-btn .saved-count {
  display: none; margin-left: 6px; font-size: 0.66rem; font-weight: 700; line-height: 15px;
  min-width: 15px; text-align: center; padding: 0 4px; border-radius: 8px;
  background: var(--color-accent); color: var(--color-on-accent);
}
.tool-btn.active .saved-count { background: color-mix(in srgb, var(--color-on-accent) 25%, transparent); }
.tool-btn .saved-count.visible { display: inline-block; }

/* Footer: brand gradient top edge (matches Dev Case Studies) */
.site-footer { border-top: 3px solid transparent; border-image: var(--brand-grad) 1; }

/* Focus rings on the brand */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--color-accent); outline-offset: 2px; border-radius: 4px;
}

/* ---------- Reading progress bar (resource pages) ---------- */
.reading-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 200; background: transparent; opacity: 0;
  transition: opacity 0.25s; pointer-events: none;
}
.reading-progress.visible { opacity: 1; }
.reading-progress > span {
  display: block; height: 100%; width: 0%;
  background: var(--brand-grad); box-shadow: 0 0 8px rgba(42,157,143,0.4);
  transition: width 0.1s linear;
}

/* ---------- Insights dashboard ---------- */
.insights-panel {
  display: none; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); padding: 24px; margin: 0 0 20px;
}
.insights-panel.open { display: block; }
.insight-loading { padding: 24px; text-align: center; color: var(--color-text-muted); font-size: 0.85rem; }
.insight-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 24px; }
.insight-tile { display: flex; flex-direction: column; gap: 2px; padding: 16px; border-radius: var(--radius-md); background: var(--color-bg); border: 1px solid var(--color-border-light); }
.insight-tile-value { font-family: var(--font-serif); font-size: 1.55rem; font-weight: 700; color: var(--color-accent); line-height: 1; letter-spacing: -0.02em; }
.insight-tile-label { font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); }
.insight-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px 32px; }
.insight-group-title { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-text-muted); margin-bottom: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--color-border-light); }
.insight-bar { display: grid; grid-template-columns: 1fr 90px 34px; align-items: center; gap: 8px; padding: 3px 4px; border-radius: var(--radius-sm); }
.insight-bar.clickable { cursor: pointer; }
.insight-bar.clickable:hover { background: var(--color-accent-light); }
.insight-bar-label { font-size: 0.76rem; color: var(--color-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.insight-bar-track { height: 7px; background: var(--color-border-light); border-radius: 4px; overflow: hidden; }
.insight-bar-fill { display: block; height: 100%; border-radius: 4px; background: var(--brand-grad); transition: width 0.6s cubic-bezier(0.2,0.8,0.2,1); }
.insight-bar-value { font-size: 0.74rem; font-weight: 700; color: var(--color-text-secondary); text-align: right; font-variant-numeric: tabular-nums; }
.insight-note { margin-top: 20px; font-size: 0.73rem; color: var(--color-text-muted); font-style: italic; }

/* ===== Link health =====
   Added 2026-09-23 with the rewritten verify_urls.py. It replaces a "Verified"
   badge that could never appear, because enrich_data.py reset `verified` to
   false on every resource on every build. The wording is deliberately narrow:
   the checker knows whether a URL answered, not whether the work is any good,
   and a badge reading "Verified" claimed the second. */
.link-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 10px;
    border-radius: 4px;
    cursor: help;
}
.link-badge.link-ok   { background: var(--badge-book-bg); color: var(--color-book); }
.link-badge.link-warn { background: var(--badge-grey-bg); color: var(--color-grey); }
.link-badge.link-bad  { background: var(--badge-bad-bg);  color: var(--color-bad); }

.link-note {
    margin: 16px 0;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface-hover);
    font-size: 0.9rem;
    line-height: 1.55;
}
.link-note.link-bad { border-color: var(--color-bad); background: var(--badge-bad-bg); }
.link-note-actions {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}
.link-note-actions a { font-weight: 600; }

.alt-urls {
    margin: 16px 0;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    font-size: 0.9rem;
}
.alt-urls-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}
.alt-urls ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.alt-urls a { word-break: break-word; }

/* More than one topic per resource, so these wrap instead of widening the row. */
.detail-topics {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}

/* ===== Header on a phone =====
   `.header-nav` was a flex row with no wrap, holding the library links, the
   theme selector and the reading-font button. Measured at 390x844 it was
   545px wide inside a 390px viewport, so the whole page scrolled sideways by
   179px. It looks perfect on a desktop, which is why it survived. */
.site-header .container {
    flex-wrap: wrap;
}

.header-nav {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 8px;
    min-width: 0;
}

.eco-nav {
    flex-wrap: wrap;
    row-gap: 6px;
}

/* ===== Links inside prose =====
   `a { text-decoration: none }` is right for nav and cards and wrong inside a
   paragraph: a link with no underline is distinguished from the text around it
   by colour alone, which WCAG 1.4.1 does not accept and which nobody with a
   colour vision deficiency can use. axe flagged three, all in the About panel
   and the footer line. Underlined only where the link sits in running text. */
.about-content p a,
.imx-footer-tagline a,
.link-note a,
.alt-urls a {
    text-decoration: underline;
    text-underline-offset: 0.18em;
}
