.processing-library-page .page-shell { display: block; width: min(1180px, calc(100% - 60px)); }
.library-collection { display: flex; flex-direction: column; height: auto; min-height: 100%; gap: 0.6rem; }
.library-collection[hidden] { display: none; }
.library-grid { display: grid; flex: none; min-height: 0; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1.2rem 1.4rem; padding-block: 0.5rem; }
.library-book { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 2px; border: 1px solid color-mix(in srgb, var(--text) 35%, transparent); border-radius: 14px; }
.library-book[hidden] { display: none; }
.processing-library-page .library-book-cancel { position: absolute; top: 5px; right: 5px; z-index: 3; display: grid; place-items: center; width: 44px; height: 44px; min-height: 44px; padding: 0; margin: 0; border: 1px solid var(--line); border-radius: 50%; color: var(--text); background: var(--surface-gradient); box-shadow: 0 3px 10px #0004; cursor: pointer; }
.processing-library-page .library-book-cancel[hidden] { display: none; }
.processing-library-page .library-book-cancel:hover { color: var(--accent); }
.processing-library-page .library-book-cancel:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.processing-library-page .library-book-cancel:disabled { opacity: .55; cursor: wait; }
.library-book-cover { position: relative; display: block; overflow: hidden; width: 100%; flex: none; aspect-ratio: 1 / 1; min-height: 0; border: 1px solid #85858b; border-radius: 11px; background: var(--panel); box-shadow: inset 0 1px #ffffff30, 0 4px 12px #0002; }
.library-grid[hidden], .library-batch-control[hidden] { display: none; }
.library-batch-control { flex: none; padding: 1rem 0 2rem; text-align: center; color: var(--muted); font-size: .85rem; }
.library-batch-control p { min-height: 1.2em; margin: 0 0 .5rem; }
.library-batch-control button { min-height: 44px; }
.library-batch-control [hidden], .library-batch-control p:empty { display: none; }
.library-book-image { display: block; width: 100%; height: 100%; object-fit: cover; transition: opacity 180ms ease; }
.library-book-cover:hover .library-book-image { opacity: 0.88; }
.library-book-placeholder { display: block; width: 100%; height: 100%; background: linear-gradient(135deg, var(--panel-strong, var(--panel)), var(--panel)); }
.library-book-cover.is-processing::after { content: ''; position: absolute; inset: auto 0 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); animation: library-progress-line 1.8s ease-in-out infinite; }
.library-book-processing { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.4rem; padding: .75rem .65rem 3.75rem; background: color-mix(in srgb, var(--panel-solid) 78%, transparent); color: var(--text); text-align: center; font-size: 0.95rem; font-weight: 650; }
.library-book-processing .loading-spinner { flex: none; width: 22px; height: 22px; }
.library-book-processing .chapter-progress { width: 100%; max-width: 14rem; margin: 0; gap: .3rem; font-weight: 400; line-height: 1.4; }
.library-book-processing [data-chapter-progress-label] { color: var(--text); }
.library-book-processing .chapter-progress progress { height: 6px; }
.library-book-processing > span { max-width: 10rem; color: var(--muted); font-size: 0.7rem; font-weight: 400; line-height: 1.5; }
.library-book.is-colorized .library-book-cover { border-color: #d4a4d4; box-shadow: 0 0 0 1px #b883d82b, 2px 0 12px #ea835217, -2px 0 12px #749ce617; }
.library-book-colorized { position: absolute; top: 9px; left: 9px; display: flex; align-items: center; gap: 5px; max-width: calc(100% - 56px); border: 1px solid #dfadab; border-radius: 10px; padding: 3px 7px; background: var(--grain), linear-gradient(120deg, #25282bee, #101417f5); color: #f6f3f1; box-shadow: inset 0 1px #ffffff15, 0 2px 6px #0005; font-size: 11px; font-weight: 650; }
.library-book-colorized::before { content: ''; flex: none; width: 14px; height: 14px; background: #ff6655; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 0 20h2a3 3 0 0 0 2-5 2 2 0 0 1 1-3h2a3 3 0 0 0 3-3A10 10 0 0 0 12 2ZM6 11a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3Zm4-4a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3Zm5 1a1.5 1.5 0 1 1 0-3 1.5 1.5 0 0 1 0 3Z'/%3E%3C/svg%3E") center / contain no-repeat; }
.library-book-processing[hidden], .library-book-colorized[hidden], .library-book-actions[hidden] { display: none; }
.processing-library-page .library-empty-state { display: flex; min-height: min(65dvh, 34rem); flex-direction: column; align-items: center; justify-content: center; gap: 1rem; margin: 0; text-align: center; }
.processing-library-page .library-empty-state h2 { margin: 0; }
.library-book-caption { position: absolute; inset: auto 0 0; z-index: 1; padding: 3.5rem .7rem .65rem; background: linear-gradient(transparent, #101417bb 48%, #0f1316f5); color: #fff; pointer-events: none; }
.library-book-caption .library-book-meta { color: #e4e4e7; }
.library-book-cover:has(.library-book-processing:not([hidden])) .library-book-caption { padding-top: .5rem; }
.library-book-caption [data-state="processing"] { display: none; }
.library-book-caption [data-state="processing"], .library-book-caption [data-state="failed"] { color: #ffbc8c; }
.library-book-failure { margin: .5rem 0 0; color: var(--text); font-size: .8rem; line-height: 1.4; overflow-wrap: anywhere; }
.library-book-failure[hidden] { display: none; }
.library-book-title { margin: 0 0 .25rem; font-size: 0.9rem; font-weight: 650; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-book-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; color: var(--muted); font-size: 0.72rem; line-height: 1.5; }
.library-book-meta [data-state="processing"], .library-book-meta [data-state="failed"] { color: var(--accent); }
.library-book-cover:focus-visible, .library-book-title a:focus-visible { outline: 1px solid var(--accent); outline-offset: 3px; }
.library-delete-form { margin: 0; }
.library-delete-button:disabled { opacity: 0.4; cursor: not-allowed; }
.library-delete-button:focus-visible { outline: 1px solid var(--accent); outline-offset: -3px; }
.library-delete-dialog { width: min(390px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; margin: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-solid); color: var(--text); box-shadow: 0 20px 70px #0006; }
.library-delete-dialog::backdrop { background: #0008; backdrop-filter: blur(5px); }
.library-delete-content { padding: 1.5rem; }
.library-delete-content h2 { margin: 0 0 0.8rem; font-size: 1.2rem; }
.library-delete-content p { margin: 0 0 0.65rem; font-size: 0.88rem; line-height: 1.55; overflow-wrap: anywhere; }
.library-delete-content .library-delete-note { color: var(--muted); font-size: 0.78rem; }
.library-delete-actions { display: flex; justify-content: flex-end; gap: 0.65rem; margin-top: 1.25rem; }
.library-delete-actions button { min-height: 42px; padding: 0.6rem 1rem; font-size: 0.85rem; }
@keyframes library-progress-line { 0% { transform: translateX(-70%); } 100% { transform: translateX(70%); } }
@media (max-width: 1024px) {
    .processing-library-page .page-shell { display: block; -webkit-overflow-scrolling: touch; }
    .library-collection { height: auto; min-height: 100%; }
    .library-grid { flex: none; grid-template-rows: none; grid-auto-rows: auto; }
    .library-book-cover { flex: none; aspect-ratio: 1 / 1; }
}
@media (max-width: 600px) {
    .processing-library-page .page-shell { width: calc(100% - 28px); }
    .library-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.85rem; padding-block: 0.25rem; }
    .library-book-title { font-size: 0.82rem; }
    .library-book-caption { padding-inline: .55rem; }
}
@media (prefers-reduced-motion: reduce) {
    .library-book-cover.is-processing::after { animation: none; transform: none; }
    .library-book-image { transition: none; }
}

.library-book-cover { background: radial-gradient(ellipse at 25% 20%, color-mix(in srgb, var(--accent) 15%, var(--panel)), var(--panel-solid) 85%); }
.library-cover-loading, .library-cover-error { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; padding: .75rem; color: var(--muted); text-align: center; font-size: .75rem; }
.js .is-cover-loading .library-book-image { opacity: 0; filter: blur(5px); }
.js .is-cover-loading .library-cover-loading { display: flex; backdrop-filter: blur(5px); }
.is-cover-error .library-cover-error { display: flex; }
.is-cover-error .library-book-image { visibility: hidden; }
.library-book-processing { backdrop-filter: blur(5px); }
.library-book-processing b { font-weight: inherit; }
.library-book-actions { position: absolute; right: 5px; top: 5px; z-index: 3; }
.library-book-actions[open] { z-index: 5; }
.library-book-actions summary { list-style: none; display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #777d88; border-radius: 50%; cursor: pointer; color: #fff; background: var(--grain), linear-gradient(135deg, #252b32, #0c1216 65%, #202931); box-shadow: inset 0 1px 2px #ffffff18, 0 3px 10px #0004; font-size: .8rem; letter-spacing: 1px; }
.library-book-actions summary::-webkit-details-marker { display: none; }
.library-book-action-panel { position: absolute; top: 43px; right: 0; width: min(172px, calc(100vw - 32px)); padding: 5px; border: 1px solid var(--line); border-top-color: #98605c; border-radius: 14px; box-shadow: inset 0 1px #ffffff12, 0 12px 32px #0007; background: var(--surface-gradient); }
.processing-library-page .library-book-actions .library-book-action-panel button, .library-book-action-panel a { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 8px; margin: 0; border: 0; border-radius: 6px; background: transparent; color: var(--text); box-shadow: none; font-size: 13px; font-weight: 500; line-height: 20px; text-align: left; text-decoration: none; cursor: pointer; }
.library-action-icon { flex: 0 0 16px; opacity: .8; }
.processing-library-page .library-book-actions .library-book-action-panel button:hover { background: var(--panel); }
.processing-library-page .library-book-actions .library-book-action-panel .library-delete-button { color: #e65e68; }
html[data-theme="light"] .processing-library-page .library-book-actions .library-book-action-panel .library-delete-button { color: #b83347; }
.library-book-action-panel a:hover { background: var(--panel); }
.library-book-action-panel form { margin: 0; }
.library-book-action-panel .library-delete-form { margin-top: 4px; padding-top: 4px; border-top: 1px solid color-mix(in srgb, var(--text) 10%, transparent); }
.library-book-action-panel p, .library-book-action-panel small { margin: .25rem; display: block; color: var(--muted); font-size: .7rem; line-height: 1.5; overflow-wrap: anywhere; }
.processing-library-page .library-book-actions .library-book-action-panel [hidden] { display: none; }
.library-empty-state[hidden] { display: none; }
.book-export-formats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.book-export-formats button { min-width: 0; min-height: 100px; display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-start; gap: 8px; padding: 16px; border-radius: 12px; text-align: left; font-size: 17px; }
.book-export-formats small { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.4; }
[data-book-export-download][hidden] { display: none; }
.book-export-dialog .library-delete-content { padding: clamp(18px, 5vw, 26px); }
.book-export-dialog [data-book-export-title] { color: var(--muted); }
.book-export-dialog .book-export-formats small { margin: 0; }
.book-export-dialog [data-book-export-status]:empty { display: none; }
.book-export-dialog .library-delete-actions { margin-top: 16px; }
.library-guest-state p { max-width: 26rem; margin: 0; color: var(--muted); }
.processing-library-page.library-guest-page .page-shell { display: flex; flex-direction: column; align-items: stretch; }
.library-guest-space { flex: 1; min-height: 0; display: grid; place-items: center; padding-block: 20px; }
.processing-library-page .library-guest-state { width: min(100%, 460px); min-height: 0; margin: 0; padding: clamp(20px, 4vw, 32px); }

/* Reference toolbar, cover details and compact stacked cards. */
.library-toolbar { display: flex; align-items: center; gap: 7px; margin: 0 0 12px; }
.library-search { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; height: 40px; padding: 0 12px; border: 1px solid #656b74; border-radius: 99px; background: var(--surface-gradient); box-shadow: var(--surface-shadow); }
.library-search svg { width: 19px; height: 19px; flex: none; fill: none; stroke: var(--muted); stroke-width: 1.7; }
.library-search input { min-width: 0; width: 100%; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; font-weight: 400; box-shadow: none; }
.library-search input:focus { outline: none; box-shadow: none; }
.library-search:focus-within { outline: none; }
.library-search input::placeholder { color: var(--muted); opacity: .85; }
.library-search-status { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.library-book-meta [data-library-page-count] { display: inline-flex; align-items: center; gap: 5px; }
.library-book-meta [data-library-page-count]::before { content: ''; width: 13px; height: 15px; background: currentColor; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 24'%3E%3Cpath d='M3 1h9l5 5v17H3ZM12 1v6h5M6 11h8M6 15h8M6 19h8' fill='none' stroke='black' stroke-width='1.8' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat; }
.processing-library-page .library-book-actions .library-book-action-panel button { min-height: 46px; border-radius: 9px; }
.processing-library-page .library-book-actions .library-book-action-panel button:hover { background: var(--selected-surface); }
.library-book-action-panel [data-library-colorize] .library-action-icon { color: var(--accent); opacity: 1; width: 21px; height: 21px; flex-basis: 21px; }
.library-book-action-panel .library-delete-form { margin-top: 6px; padding-top: 6px; border-color: var(--line); }
@media (min-width: 601px) {
    .library-grid { grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); }
}
@media (min-width: 1025px) {
    .app-page.processing-library-page .content-frame > .page-shell { display: flex; flex-direction: column; align-items: stretch; padding-top: 72px; overflow: hidden; }
    .library-toolbar, .library-search-status { flex: none; }
    .processing-library-page .library-collection { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--muted) transparent; scrollbar-gutter: stable; padding-right: 8px; }
    .library-grid { grid-template-columns: repeat(auto-fill, minmax(225px, 1fr)); gap: 16px; }
    .library-toolbar { gap: 10px; margin-bottom: 18px; }
    .library-search { height: 44px; }
    .library-search input { font-size: 14px; }
    .library-book:nth-child(n) .library-book-action-panel { left: auto; right: 0; }
}
@media (max-width: 1024px) {
    .processing-library-page .page-shell { padding-top: 3px; }
}
@media (max-width: 600px) {
    .library-grid .library-book:nth-child(2n + 1) .library-book-action-panel { right: -28px; left: auto; }
    .processing-library-page .page-shell { width: calc(100% - 20px); }
    .library-grid { gap: 9px; }
    .library-book-title { font-size: 14px; }
    .library-book-meta { font-size: 11px; }
    .library-toolbar { gap: 6px; }
    .library-search { padding-inline: 10px; gap: 7px; }
    .library-search input { font-size: 11px; }
    .library-book-processing .chapter-progress, .library-book-processing .chapter-progress small { font-size: .65rem; }
}
@media (max-width: 360px) {
    .library-toolbar { flex-wrap: wrap; }
    .library-book-colorized { font-size: 10px; gap: 3px; left: 5px; padding-inline: 4px; }
    .library-book-colorized::before { width: 11px; height: 11px; }
}
