/* Compact controls and a touch-friendly filter drawer. Desktop layout stays in pages.css. */
.library-filter-count, .library-page .library-show-results { display: none; }

@media (max-width: 991px) {
    html.library-filters-scroll-lock { overflow: hidden; }
    body.library-filters-open {
        position: fixed;
        inset-inline: 0;
        top: var(--library-scroll-top, 0);
        width: 100%;
        overflow: hidden;
    }

    .library-page .library-shell { gap: 18px; }
    .library-page .library-toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px 12px;
        align-items: stretch;
    }
    .library-page .library-search {
        grid-column: 1 / -1;
        grid-row: 1;
        order: initial;
        min-width: 0;
        width: 100%;
        min-height: 50px;
        padding-inline: 14px;
        border-radius: 13px;
    }
    .library-page .library-search input {
        min-height: 48px;
        padding-block: 11px;
        font-size: 16px;
    }
    .library-page .sort-control {
        grid-column: 1;
        grid-row: 2;
        order: initial;
        width: 100%;
        min-width: 0;
    }
    .library-page .sort-control .mgn-select,
    .library-page .sort-control .mgn-select-button { width: 100%; }
    .library-page .sort-control .mgn-select-button {
        min-height: 48px;
        padding: 12px;
        gap: 8px;
        font-size: 13px;
        border-radius: 12px;
    }
    .library-page .sort-control select { width: 100%; min-width: 0; min-height: 48px; font-size: 16px; }
    .library-page .library-toolbar > .library-burger {
        grid-column: 2;
        grid-row: 2;
        order: initial;
        margin: 0;
        min-height: 48px;
        padding: 11px 14px;
        border-radius: 12px;
        justify-content: center;
        font-size: 14px;
        white-space: nowrap;
    }
    .library-page .library-filter-count:not([hidden]) {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 21px;
        height: 21px;
        margin-left: -3px;
        border-radius: 50%;
        background: #e94259;
        color: #fff;
        font-size: 11px;
        line-height: 1;
    }
    .library-page .library-count {
        grid-column: 1 / -1;
        grid-row: 3;
        order: initial;
        margin-top: 4px;
        font-size: 13px !important;
    }
    .library-page .library-count strong { font-size: 13px; }
    .library-page .library-active-filters {
        flex-wrap: nowrap;
        gap: 8px;
        max-width: 100%;
        padding-bottom: 3px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }
    .library-page .library-active-filters::-webkit-scrollbar { display: none; }
    .library-page .library-active-filters button {
        flex: 0 0 auto;
        min-height: 44px;
        padding: 8px 13px;
        font-size: 12px;
        white-space: nowrap;
    }
    .library-page .library-active-filters button span { font-size: 20px; line-height: 1; }

    .library-page .library-sidebar {
        width: min(440px, calc(100vw - 20px));
        height: 100vh;
        height: 100dvh;
        border-left: 1px solid #3b3538;
        border-radius: 22px 0 0 22px;
        box-shadow: -16px 0 56px #0008;
        background: #0b090b;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    .library-page .library-filter-clip { min-height: 100%; overflow: visible; }
    .library-page .filtering-form {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        min-height: 100dvh;
        padding: 0 20px;
        border: 0;
        background: transparent;
    }
    .library-page .filter-heading {
        position: sticky;
        top: 0;
        z-index: 2;
        margin: 0 -20px 8px;
        padding: calc(16px + env(safe-area-inset-top)) 16px 14px 20px;
        border-bottom: 1px solid #302b2e;
        background: #0b090bf5;
        backdrop-filter: blur(16px);
    }
    .library-page .filter-heading h2 { font-size: 18px; line-height: 1.35; }
    .library-page .filter-close {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        margin-left: 12px;
        border: 1px solid #40383d;
        border-radius: 50%;
        font-size: 28px;
        line-height: 1;
        background: #1a1519;
    }
    .library-page #library-filters { flex: 1; padding-bottom: 20px; }
    .library-page .accordion-button { min-height: 52px; font-size: 15px; padding-block: 16px; }
    .library-page .accordion-body,
    .library-page #filter-status .accordion-body {
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
        padding-bottom: 14px;
    }
    .library-page .filter-option {
        align-items: center;
        min-height: 48px;
        padding: 10px 12px;
        gap: 12px;
        border: 1px solid #302a2e;
        border-radius: 11px;
        background: #141014;
        font-size: 14px;
        line-height: 1.5;
    }
    .library-page .filter-option:has(input:checked) { border-color: #aa5264; background: #26161e; color: #fff; }
    .library-page input[type="checkbox"] { width: 20px; height: 20px; margin: 0; }
    .library-page .filter-actions {
        position: sticky;
        bottom: 0;
        z-index: 2;
        flex-direction: column;
        gap: 10px;
        margin: auto -20px 0;
        padding: 14px 20px calc(18px + env(safe-area-inset-bottom));
        border-top: 1px solid #302b2e;
        background: #0b090bf5;
        backdrop-filter: blur(16px);
    }
    .library-page .filter-actions > * { width: 100%; min-height: 46px; }
    .library-page .library-show-results {
        display: inline-flex;
        justify-content: center;
        max-width: none;
        min-height: 50px;
        padding: 12px 16px;
        border-radius: 12px;
        font-size: 14px;
    }
    .library-page .filter-actions .filter-reset {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        margin: 0;
        border-radius: 12px;
        font-size: 13px;
    }
    .library-page .library-row.open .library-filter-backdrop { background: #000b; cursor: pointer; }
    .library-page .library-update-status:not(.visually-hidden) { padding: 12px 14px; border: 1px solid #5e3842; border-radius: 12px; }
    .library-page .library-retry { min-height: 44px; padding: 8px; }
    .library-page .project-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 26px 16px; }
    .library-page .project-card h2 { font-size: 15px; line-height: 1.45; margin: 12px 0 5px; }
    .library-page .project-card .text-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: 13px; }
}

@media (max-width: 700px) {
    .library-page .project-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 14px; }
    .library-page .project-card .card-image-container { border-radius: 12px; }
    .library-page .library-empty { padding: 24px 20px; }
    .library-page .library-empty h2 { font-size: 22px; }
    .library-page .library-empty p { font-size: 15px; line-height: 1.65; }
}

@media (max-width: 359px) {
    .library-page .project-grid { grid-template-columns: minmax(0, 1fr); gap: 20px; }
    .library-page .project-card {
        display: grid;
        grid-template-columns: 104px minmax(0, 1fr);
        grid-template-rows: auto 1fr;
        align-items: start;
        gap: 0 14px;
    }
    .library-page .project-card .project-cover { grid-column: 1; grid-row: 1 / span 2; }
    .library-page .project-card h2 { grid-column: 2; grid-row: 1; margin: 4px 0 6px; }
    .library-page .project-card .text-link { grid-column: 2; grid-row: 2; align-self: start; }
    .library-page .project-cover > .project-card-stats {
        inset-inline: 6px;
        bottom: 6px;
        max-width: none;
        padding: 5px 6px;
        gap: 4px 6px;
        justify-content: flex-start;
        border-radius: 8px;
    }
    .library-page .library-toolbar { column-gap: 8px; }
    .library-page .library-toolbar > .library-burger { padding-inline: 11px; }
}

@media (max-width: 991px) and (prefers-reduced-motion: reduce) {
    .library-page .library-sidebar { transition: none; }
}
