/* ===========================================================================
   Public scientific library
   Minimal, editorial, calm.
   =========================================================================== */

.lib-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--es-font);
    color: var(--es-ink);
    background:
        radial-gradient(ellipse 80% 50% at 50% -10%, rgba(37, 99, 235, 0.06), transparent),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(13, 148, 136, 0.04), transparent),
        #f6f7f9;
    -webkit-font-smoothing: antialiased;
}

/* Main — content sits in shared .site-main after Knowledge tabs */
.lib-body .site-main {
    flex: 1;
    width: 100%;
    margin: 0 auto;
    padding: 0 clamp(48px, 6vw, 96px) 64px;
}

/* Hero + search stay at the original content width; cards go full-bleed. */
.lib-hero,
.lib-search {
    width: 100%;
    max-width: 1080px;
    margin-left: auto;
    margin-right: auto;
}
.lib-hero {
    margin-bottom: 36px;
}
.lib-hero__title {
    margin: 0 0 12px;
    font-size: clamp(28px, 4vw, 38px);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.1;
}
.lib-hero__lead {
    margin: 0 0 20px;
    max-width: 640px;
    font-size: 17px;
    line-height: 1.55;
    color: var(--es-ink-soft);
}
.lib-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 24px;
}
.lib-stat {
    font-size: 14px;
    color: var(--es-ink-soft);
}
.lib-stat strong {
    color: var(--es-ink);
    font-weight: 700;
}

/* Search */
.lib-search {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 28px;
}
.lib-search__field {
    flex: 1 1 220px;
    position: relative;
    min-width: 0;
}
.lib-search__icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--es-ink-faint);
    pointer-events: none;
}
.lib-search__input {
    width: 100%;
    height: 42px;
    padding: 0 14px 0 38px;
    border: 1px solid var(--es-line);
    border-radius: 999px;
    font: inherit;
    font-size: 15px;
    background: #fff;
    color: var(--es-ink);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.lib-search__input:focus {
    outline: none;
    border-color: var(--es-accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
/* Year-range filter (PubMed-style popover) */
.lib-year { position: relative; }
.lib-year__btn {
    height: 42px;
    padding: 0 36px 0 16px;
    border: 1px solid var(--es-line);
    border-radius: 999px;
    font: inherit;
    font-size: 14px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa3ad' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E") no-repeat right 10px center;
    color: var(--es-ink);
    cursor: pointer;
}
.lib-year__btn:hover { border-color: var(--es-ink-faint); }
.lib-year__pop {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 60;
    width: 340px;
    padding: 16px;
    background: var(--es-surface);
    border: 1px solid var(--es-line);
    border-radius: var(--es-r);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}
.lib-year__title {
    margin: 0 0 12px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--es-ink-soft);
}
.lib-year__bars {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    height: 64px;
    margin-bottom: 6px;
}
.lib-year__bar {
    flex: 1 1 0;
    min-width: 1px;
    background: var(--es-line);
    border-radius: 1px 1px 0 0;
}
.lib-year__bar.is-in { background: var(--es-accent); }
.lib-year__slider {
    position: relative;
    height: 20px;
    margin-bottom: 8px;
}
.lib-year__track {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    height: 4px;
    background: var(--es-line);
    border-radius: 999px;
}
.lib-year__fill {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--es-accent);
    border-radius: 999px;
}
.lib-year__slider input[type="range"] {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 100%;
    height: 20px;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
}
.lib-year__slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--es-accent);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    cursor: pointer;
    pointer-events: auto;
}
.lib-year__slider input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--es-accent);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    cursor: pointer;
    pointer-events: auto;
}
.lib-year__slider input[type="range"]::-moz-range-track { background: transparent; }
.lib-year__label {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    color: var(--es-ink);
}
.lib-year__actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.lib-btn--sm {
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
}

/* Buttons */
.lib-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    padding: 0 20px;
    border: none;
    border-radius: 999px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    color: var(--es-accent-ink);
    background: var(--es-accent);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}
.lib-btn:hover { background: #1d4ed8; text-decoration: none; color: var(--es-accent-ink); }
.lib-btn--ghost {
    background: transparent;
    color: var(--es-ink-soft);
    border: 1px solid var(--es-line);
}
.lib-btn--ghost:hover { background: var(--es-bg); color: var(--es-ink); }
.lib-btn--outline {
    background: transparent;
    color: var(--es-accent);
    border: 1px solid var(--es-accent);
    margin-top: 16px;
}
.lib-btn--outline:hover { background: var(--es-accent-soft); color: var(--es-accent); }

/* Results */
.lib-empty {
    text-align: center;
    padding: 64px 24px;
    color: var(--es-ink-soft);
}
.lib-empty p { margin: 0 0 16px; font-size: 16px; }

/* Grid */
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}
.lib-card {
    display: flex;
    flex-direction: column;
    background: var(--es-surface);
    border: 1px solid var(--es-line);
    border-radius: var(--es-r);
    overflow: hidden;
    box-shadow: var(--es-shadow);
    transition: box-shadow 0.2s, transform 0.2s;
}
.lib-card:hover {
    box-shadow: 0 4px 24px rgba(16, 21, 27, 0.08);
    transform: translateY(-2px);
}
.lib-card__cover {
    display: block;
    aspect-ratio: 3 / 4;
    background: linear-gradient(145deg, #eef2f7 0%, #e5eaf0 100%);
    overflow: hidden;
    text-decoration: none;
}
.lib-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}
.lib-card:hover .lib-card__cover img { transform: scale(1.03); }
.lib-card__placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--es-ink-faint);
}
.lib-card__body {
    padding: 16px 18px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.lib-card__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.lib-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.lib-tag--article { background: #eff6ff; color: #2563eb; }
.lib-tag--book { background: #f0fdf4; color: #15803d; }
.lib-tag--web { background: #faf5ff; color: #7c3aed; }
.lib-tag--year { background: var(--es-bg); color: var(--es-ink-soft); text-transform: none; letter-spacing: 0; font-weight: 600; }
.lib-tag--muted { background: var(--es-bg); color: var(--es-ink-faint); text-transform: none; letter-spacing: 0; font-weight: 600; }
.lib-card__title {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.01em;
}
.lib-card__title a {
    color: var(--es-ink);
    text-decoration: none;
}
.lib-card__title a:hover { color: var(--es-accent); }
.lib-card__meta {
    margin: 0;
    font-size: 13px;
    color: var(--es-ink-soft);
    line-height: 1.4;
}
.lib-card__excerpt {
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--es-ink-faint);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Pagination */
.lib-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-top: 40px;
}
.lib-pagination__label {
    font-size: 13px;
    color: var(--es-ink-faint);
    font-variant-numeric: tabular-nums;
}

/* Detail page */
.lib-back {
    display: inline-block;
    margin-bottom: 24px;
    font-size: 14px;
    font-weight: 600;
    color: var(--es-ink-soft);
    text-decoration: none;
    transition: color 0.15s;
}
.lib-back:hover { color: var(--es-accent); text-decoration: none; }

.lib-detail {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 36px;
    max-width: 1080px;
    margin: 0 auto 40px;
}
.lib-detail__cover {
    aspect-ratio: 3 / 4;
    border-radius: var(--es-r);
    overflow: hidden;
    background: linear-gradient(145deg, #eef2f7 0%, #e5eaf0 100%);
    border: 1px solid var(--es-line);
    box-shadow: 0 8px 32px rgba(16, 21, 27, 0.1);
}
.lib-detail__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.lib-detail__cover .lib-card__placeholder { min-height: 100%; }
.lib-detail__title {
    margin: 10px 0 8px;
    font-size: clamp(22px, 3vw, 30px);
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.lib-detail__authors {
    margin: 0 0 20px;
    font-size: 16px;
    color: var(--es-ink-soft);
    line-height: 1.5;
}
.lib-detail__meta {
    margin: 0;
    display: grid;
    gap: 0;
}
.lib-detail__field {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--es-line);
    font-size: 14px;
}
.lib-detail__field dt {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--es-ink-faint);
}
.lib-detail__field dd {
    margin: 0;
    color: var(--es-ink);
    overflow-wrap: anywhere;
}

.lib-section {
    margin-bottom: 32px;
    padding-top: 8px;
}
.lib-section__title {
    margin: 0 0 14px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--es-ink-faint);
}
.lib-prose {
    font-size: 16px;
    line-height: 1.7;
    color: var(--es-ink-soft);
}
.lib-prose p { margin: 0; }

@media (max-width: 720px) {
    .lib-body .site-main { padding: 0 24px 48px; }
    .lib-search { flex-direction: column; align-items: stretch; }
    .lib-search__field,
    .lib-year,
    .lib-year__btn,
    .lib-btn { width: 100%; }
    .lib-year__pop { left: 0; right: 0; width: auto; }
    .lib-detail { grid-template-columns: 1fr; gap: 24px; }
    .lib-detail__cover { max-width: 200px; }
    .lib-detail__field { grid-template-columns: 1fr; gap: 2px; }
    .lib-grid { grid-template-columns: 1fr; }
}

/* Mobile: 2px less vertical padding on pill controls. */
@media (max-width: 860px) {
    .lib-search__input,
    .lib-year__btn,
    .lib-btn {
        height: 38px;
    }
    .lib-btn--sm {
        height: 30px;
    }
}
