/* Mi Biblioteca */
.library-page .library-shelf-panel {
    margin-bottom: var(--space-4);
}
.library-shelf-card .library-shelf-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
    width: 100%;
}
.library-shelf-cta {
    display: block;
    text-align: center;
    width: 100%;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--line);
    text-decoration: none;
    font-size: var(--text-sm);
}
.library-shelf-cta.cta-read {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border-color: transparent;
    color: #fff;
    font-weight: 600;
}
.library-shelf-remove {
    margin: 0;
    text-align: center;
}
.library-shelf-remove button {
    font-size: var(--text-xs);
    padding: 4px 8px;
}
.library-shelf-progress {
    position: absolute;
    right: 6px;
    top: 6px;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(7, 8, 15, 0.82);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    z-index: 4;
}
.library-shelf-progress-bar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    z-index: 4;
    background: rgba(0, 0, 0, 0.4);
    pointer-events: none;
}
.library-shelf-progress-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #a78bfa);
}
.library-shelf-card .shelf-cover-badges {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 4;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: calc(100% - 52px);
    pointer-events: none;
}
.library-shelf-card .shelf-cover-badges .format-badge {
    font-size: 10px;
    padding: 2px 7px;
    box-shadow: 0 4px 12px rgba(2, 6, 23, 0.35);
}
.library-shelf-card .shelf-cover-overlay.library-shelf-actions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    margin-top: 0;
    padding: 26px 8px 8px;
    background: linear-gradient(180deg, transparent 0%, rgba(7, 8, 15, 0.5) 38%, rgba(7, 8, 15, 0.94) 100%);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.library-shelf-card .shelf-cover-overlay .shelf-form {
    margin-top: 0;
    padding-top: 0;
}
@media (hover: hover) and (pointer: fine) {
    .library-shelf-card .shelf-cover-overlay.library-shelf-actions {
        opacity: 0;
        transform: translateY(8px);
        pointer-events: none;
    }
    .library-shelf-card:hover .shelf-cover-overlay.library-shelf-actions,
    .library-shelf-card:focus-within .shelf-cover-overlay.library-shelf-actions {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }
}
@media (hover: none), (pointer: coarse) {
    .library-shelf-card .shelf-cover-overlay.library-shelf-actions {
        opacity: 1;
        transform: none;
        pointer-events: auto;
        padding: 18px 6px 6px;
    }
}
.library-collections-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-3);
}
.library-collection-card {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--card);
    overflow: hidden;
    transition: border-color 0.15s ease, transform 0.15s ease;
}
.library-collection-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}
.library-collection-card__link {
    display: block;
    padding: var(--space-3);
    color: inherit;
    text-decoration: none;
}
.library-collection-card__covers {
    display: flex;
    gap: 4px;
    min-height: 88px;
    margin-bottom: var(--space-2);
}
.library-collection-card__cover {
    flex: 1;
    aspect-ratio: 2/3;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--card-2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.library-collection-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.library-collection-card__fallback {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--sub);
}
.library-collection-card__title {
    margin: 0;
    font-size: 0.98rem;
    font-weight: 700;
}
.library-collection-card__meta {
    margin: 4px 0 0;
    color: var(--sub);
}

/* Biblioteca: blindaje de layout para estanterías (evita compresión por overrides globales) */
body.library-page .library-shelf-panel .shelf-track {
    display: flex !important;
    grid-auto-flow: unset !important;
    grid-auto-columns: unset !important;
    width: 100%;
    max-width: 100%;
    gap: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 8px;
    scroll-snap-type: x proximity;
}
body.library-page .library-shelf-panel .shelf-card:not(.library-shelf-card--spine) {
    flex: 0 0 220px !important;
    min-width: 220px !important;
    max-width: 220px !important;
}
body.library-page .library-shelf-panel .shelf-track.single,
body.library-page .library-shelf-panel .shelf-track.few {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    overflow: visible;
    padding-bottom: 0;
}

@media (max-width: 900px) {
    body.library-page .library-shelf-panel .shelf-card:not(.library-shelf-card--spine) {
        flex: 0 0 168px !important;
        min-width: 168px !important;
        max-width: 168px !important;
    }
}

/* Guardas anti-desborde en Biblioteca */
body.library-page {
    overflow-x: hidden;
}
body.library-page .container,
body.library-page .panel,
body.library-page .library-series-shelf-wrap,
body.library-page .library-shelf-panel {
    max-width: 100%;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel {
    overflow: visible;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) {
    overflow: visible;
}
body.library-page .library-shelf-panel:not(.library-shelf-panel--spine) {
    overflow: hidden;
    position: relative;
}
body.library-page .library-shelf-panel::after {
    content: "";
    position: absolute;
    top: 40px;
    right: 0;
    bottom: 4px;
    width: 36px;
    background: linear-gradient(90deg, transparent, rgba(8, 12, 24, 0.9));
    pointer-events: none;
    opacity: 0;
    z-index: 2;
}
body.library-page .library-shelf-panel:has(.shelf-track:not(.single):not(.few))::after {
    opacity: 1;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel::after {
    display: none;
}
[data-theme="light"] body.library-page .library-shelf-panel::after {
    background: linear-gradient(90deg, transparent, rgba(248, 250, 252, 0.96));
}
body.library-page .library-shelf-panel .shelf-card:not(.library-shelf-card--spine) {
    padding: 8px;
}

/* Biblioteca > Estanterías por serie: rejilla contenida (sin desborde lateral) */
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track,
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track.single,
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track.few {
    display: grid !important;
    grid-auto-flow: row !important;
    grid-auto-columns: unset !important;
    grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
    gap: 14px;
    overflow: visible;
    padding-bottom: 0;
    width: 100%;
    max-width: 100%;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-card {
    flex: initial !important;
    min-width: 0 !important;
    max-width: none !important;
    width: 100%;
    padding: 12px;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-title {
    font-size: 12.5px;
    line-height: 1.32;
    min-height: 2.64em;
    max-height: 2.64em;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-meta {
    font-size: 10.5px;
    line-height: 1.35;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel .library-shelf-actions {
    gap: 5px;
    margin-top: 7px;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel .library-shelf-cta,
body.library-page .library-series-shelf-wrap .library-shelf-panel .shelf-form button {
    min-height: 34px;
    font-size: 11.5px;
}

/* Estanterías por serie: Leer/Descargar siempre visibles bajo el título (como ficha) */
body.library-page .library-series-shelf-wrap .library-shelf-card--detail .library-shelf-actions--overlay-hidden {
    display: none;
}
body.library-page .library-series-shelf-wrap .library-shelf-detail-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    width: 100%;
}
body.library-page .library-series-shelf-wrap .library-shelf-detail-read {
    min-height: 40px;
    font-size: 12.5px;
    font-weight: 700;
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.32);
}
body.library-page .library-series-shelf-wrap .library-shelf-detail-download {
    min-height: 34px;
    font-size: 11.5px;
}
body.library-page .library-series-shelf-wrap .library-shelf-panel--has-ficha .library-series-shelf-ficha {
    min-height: 42px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    border-color: rgba(139, 92, 246, 0.55);
    background: rgba(99, 102, 241, 0.14);
}
body.library-page .library-shelf-panel--has-ficha .library-series-shelf-ficha:hover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.24);
}
body.library-series-detail-page .library-series-detail-filter.is-active {
    border-color: transparent;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    font-weight: 700;
}

@media (max-width: 900px) {
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track,
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track.single,
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track.few {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-card {
        padding: 9px;
    }
}

@media (min-width: 1500px) {
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track,
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track.single,
    body.library-page .library-series-shelf-wrap .library-shelf-panel:not(.library-shelf-panel--spine) .shelf-track.few {
        grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    }
}

/* Ficha de serie: rejilla vertical (los tomos nuevos se ven al cargar más) */
body.library-series-detail-page #library-series-volumes-track.library-series-volumes-track,
body.library-series-detail-page .library-series-volumes-track.shelf-track {
    display: grid !important;
    grid-auto-flow: row !important;
    grid-auto-columns: unset !important;
    grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
    gap: 14px;
    overflow: visible;
    padding-bottom: 0;
    width: 100%;
    max-width: 100%;
    scroll-snap-type: none;
}
body.library-series-detail-page #library-series-volumes-track .shelf-card,
body.library-series-detail-page .library-series-volumes-track .shelf-card {
    flex: initial !important;
    min-width: 0 !important;
    max-width: none !important;
    width: 100%;
}
@media (max-width: 900px) {
    body.library-series-detail-page #library-series-volumes-track.library-series-volumes-track,
    body.library-series-detail-page .library-series-volumes-track.shelf-track {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
}

/* Ficha serie: acciones de lectura siempre visibles (no solo hover) */
body.library-series-detail-page .library-shelf-card .shelf-cover-overlay.library-shelf-actions {
    opacity: 1;
    transform: none;
    pointer-events: auto;
    padding: 22px 8px 8px;
}
body.library-series-detail-page .library-shelf-card .library-shelf-cta.cta-read {
    min-height: 38px;
    font-size: 12px;
}

/* Ficha serie: botones Leer/Descargar bajo el título (siempre visibles) */
body.library-series-detail-page .library-shelf-detail-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    width: 100%;
}
body.library-series-detail-page .library-shelf-detail-read {
    min-height: 42px;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35);
}
body.library-series-detail-page .library-shelf-detail-download {
    min-height: 36px;
    font-size: 12px;
}
body.library-series-detail-page .library-shelf-card--detail .library-shelf-actions--overlay-hidden {
    display: none;
}
