/* --- Base & Fonts --- */

:root {
    --dark-bg: #121212; /* 更纯粹的黑 */
    --glass-bg: rgba(255, 255, 255, 0.08); /* 更轻盈的玻璃态 */
    --border-color: rgba(255, 255, 255, 0.1);
    --primary-accent: #b39ddb; /* 柔和的紫色 */
    --text-primary: #f5f5f5;
    --text-secondary: #aaaaaa;
    --radius-md: 12px;
    --radius-lg: 24px;
}

body {
    margin: 0;
    background-color: var(--dark-bg);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    transition: background-color 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* --- Category Tabs --- */
#source-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    justify-content: center;
}

.source-tab-btn {
    padding: 8px 16px;
    border: none;
    background-color: var(--glass-bg);
    color: var(--text-secondary);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
    font-weight: 500;
}

.source-tab-btn.active, .source-tab-btn:hover {
    background-color: var(--text-primary);
    color: var(--dark-bg);
}

#category-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 30px;
    justify-content: center;
    /* border-bottom: 1px solid var(--border-color); Remove border for minimalism */
    padding-bottom: 10px;
}

.tab-btn {
    padding: 6px 14px;
    border: 1px solid transparent;
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--glass-bg);
}

.tab-btn.active {
    background-color: var(--glass-bg);
    color: var(--primary-accent);
    border-color: var(--border-color);
}

#album-list-info {
    color: var(--text-secondary);
    margin: 0 0 20px 0;
    font-size: 0.85em;
    text-align: center;
    opacity: 0.7;
}

/* --- Main Layout --- */
.container {
    max-width: 1200px;
    margin: 40px auto;
    padding: 20px;
    transition: all 0.3s ease;
}

.container.reader-mode {
    max-width: 100%;
    padding: 0;
    margin: 0;
}

.container.reader-mode .bookshelf-header,
.container.reader-mode #album-list-info,
.container.reader-mode #source-tabs,
.container.reader-mode #category-tabs,
.container.reader-mode #main-title,
.container.reader-mode p {
    display: none !important;
}

/* --- Bookshelf / Album List --- */
.bookshelf-header {
    margin-bottom: 30px;
    position: relative;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.bookshelf-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

#search-input {
    width: 100%;
    flex: 1;
    min-width: 0;
    padding: 12px 20px;
    box-sizing: border-box;
    background: var(--glass-bg);
    border: 1px solid transparent;
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 16px;
    transition: all 0.2s ease;
}

#search-input:focus {
    outline: none;
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--border-color);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%; /* Circular buttons */
    border: none;
    background: var(--glass-bg);
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.05);
}

.local-menu {
    position: absolute;
    right: 0;
    top: 56px;
    display: none;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    background: #1e1e1e;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    z-index: 50;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.local-menu.is-open {
    display: flex;
}

.menu-btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.menu-btn:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.05);
}

#local-folder-input,
#local-zip-input {
    display: none;
}

.album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
}

.album-item {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0;
    aspect-ratio: 3 / 4; /* Card aspect ratio */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    transition: transform 0.2s ease, border-color 0.2s ease;
    color: var(--text-secondary);
}

.album-item:hover {
    transform: translateY(-4px);
    border-color: var(--primary-accent);
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

.album-item::before {
    /* SVG Icon Placeholder */
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    width: 64px;
    height: 64px;
    opacity: 0.1;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 19.5A2.5 2.5 0 0 1 6.5 17H20'/%3E%3Cpath d='M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.album-item:hover::before {
    opacity: 0.2;
}

/* --- Cover Image Styles --- */
.album-item.cover-loading {
    background: rgba(255, 255, 255, 0.03);
}

.album-item.cover-loaded {
    border-color: transparent;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.album-item.cover-loaded::before {
    opacity: 0;
}

.album-item.cover-loaded span {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 40px 15px 44px;
    background: linear-gradient(transparent, rgba(0,0,0,0.85));
    color: #f5f5f5;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    box-sizing: border-box;
    z-index: 3;
    font-weight: 500;
}

.album-item.cover-error {
    /* Falls back to default placeholder icon */
}

.album-item span {
    padding: 15px;
    z-index: 2;
    display: block; /* Ensure text flows correctly */
    padding-bottom: 40px; /* Space for button */
}

.album-download-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 10;
    transition: all 0.2s;
    overflow: hidden;
}

.album-download-btn:hover {
    background: var(--primary-accent);
    color: #000;
    border-color: transparent;
}

.album-download-btn.downloading {
    background: rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.progress-ring {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.progress-ring-circle {
    stroke: var(--primary-accent);
    stroke-width: 4;
    fill: transparent;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    transition: stroke-dashoffset 0.1s linear;
}

/* --- Album Progress Bar --- */
.album-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: var(--primary-accent);
    z-index: 4;
    border-radius: 0 2px 0 0;
    transition: width 0.3s ease;
    pointer-events: none;
}

.album-item.album-read {
    border-color: rgba(187, 134, 252, 0.3);
}

.album-item.album-read .album-progress-bar {
    background: #4caf50;
    border-radius: 0;
}

/* --- Reader View --- */
.reader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

.reader-image-item {
    position: relative;
    line-height: 0;
    width: 100%;
    max-width: 800px; /* Limit max width for better reading on desktop */
    margin: 0 auto;
    min-height: 300px; /* Prevent collapse when empty to ensure correct scrolling */
    display: flex; /* Center content */
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02); /* Slight bg for placeholder */
}

.reader-image-item img {
    width: 100%;
    height: auto;
    display: block;
    min-height: 50px; /* Ensure image has some height */
}

.reader-video {
    width: 100%;
    max-width: 1200px;
    max-height: 80vh;
    background: #000;
    border-radius: var(--radius-md);
}

.reader-text {
    width: min(900px, 92vw);
    max-height: 82vh;
    overflow: auto;
    white-space: pre-wrap;
    line-height: 1.85;
    font-size: 17px;
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
}

.reader-text.no-wrap {
    white-space: pre;
    overflow-x: auto;
    overflow-y: auto;
}

/* Error & Loading States */
.image-error {
    padding: 20px;
    background: rgba(255, 77, 77, 0.1);
    border-radius: var(--radius-md);
    margin: 20px auto;
    text-align: center;
    color: #ff6b6b;
}

.image-error-retry {
    background: transparent;
    border: 1px solid #ff6b6b;
    color: #ff6b6b;
    padding: 4px 12px;
    border-radius: 20px;
    margin-top: 8px;
    cursor: pointer;
}

.spinner {
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-accent);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 0.8s linear infinite;
    margin: 20px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Single Page Mode */
.reader-image-item.single-page-mode {
    max-width: none;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.reader-image-item.single-page-mode.text-page-mode {
    align-items: flex-start;
    padding-top: 24px;
    overflow: auto;
}

.reader-image-item.single-page-mode img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    width: auto;
    height: auto;
}

.reader-image-item.single-page-mode.zoomed {
    display: block;
    overflow: auto;
}

.reader-image-item.single-page-mode.zoomed img {
    width: 100%;
    max-width: none;
    max-height: none;
    cursor: zoom-out;
}

/* --- Selection Mode --- */
.album-item.selecting {
    cursor: pointer;
    border: 2px solid transparent;
}

.album-item.selected {
    border-color: var(--primary-accent);
    background: rgba(187, 134, 252, 0.1);
}

.selection-checkbox {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.album-item.selecting .selection-checkbox {
    display: flex;
}

.album-item.selected .selection-checkbox {
    background: var(--primary-accent);
    border-color: var(--primary-accent);
}

.album-item.selected .selection-checkbox::after {
    content: '';
    display: block;
    width: 5px;
    height: 9px;
    border: solid #000;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    position: absolute;
    top: 3px;
    left: 6px;
}

.selection-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--surface-bg);
    border-top: 1px solid var(--border-color);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.selection-bar.visible {
    transform: translateY(0);
}

.selection-info {
    font-weight: 500;
}

.selection-actions {
    display: flex;
    gap: 12px;
}

.selection-btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 500;
    cursor: pointer;
}

.selection-btn.cancel {
    background: transparent;
    color: var(--text-secondary);
}

.selection-btn.action {
    background: var(--primary-accent);
    color: #000;
}

.selection-btn.action.danger {
    background: #ff4444;
    color: #fff;
}

.batch-select-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 0.8em;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s;
}

.batch-select-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* --- Toast Notification --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4000; /* Ensure toast is above modal (z-index: 3000) */
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}

.toast {
    background: var(--surface-light);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-left: 4px solid var(--primary-accent);
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: toast-slide-up 0.3s ease-out;
    pointer-events: auto;
}

.toast.error {
    border-left-color: #ff4444;
}

.toast.success {
    border-left-color: #00C851;
}

@keyframes toast-slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-fade-out {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

/* --- Modal Dialog --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    backdrop-filter: blur(8px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Helper Classes */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.image-error-title {
    font-weight: bold;
    margin-bottom: 4px;
    color: var(--text-primary);
}

/* Dragging State */
#scroll-indicator.dragging {
    cursor: grabbing;
    transform: translateY(-50%) scale(1.1);
    background: #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.modal {
    background: var(--surface-bg);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 400px;
    padding: 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-title {
    font-size: 1.2em;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-content {
    margin-bottom: 24px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin: 20px 0;
}

.input-group input {
    width: 80px;
    margin: 0;
    text-align: center;
}

.input-group span {
    color: var(--text-secondary);
    font-size: 1.1em;
}

.modal-btn, .primary-btn, .secondary-btn {
    padding: 8px 16px;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    font-size: 0.95em;
    transition: background 0.2s;
}

.modal-btn.secondary, .secondary-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.modal-btn.secondary:hover, .secondary-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-secondary);
}

.modal-btn.primary, .primary-btn {
    background: var(--primary-accent);
    color: #000;
    font-weight: 500;
}

.modal-btn.primary:hover, .primary-btn:hover {
    filter: brightness(1.1);
}

.modal-btn.danger {
    background: rgba(255, 68, 68, 0.2);
    color: #ff4444;
}

.modal-btn.danger:hover {
    background: rgba(255, 68, 68, 0.3);
}

/* --- Storage Manager --- */
.storage-manager {
    background: var(--glass-bg);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
}

.storage-stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.storage-bar-container {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 16px;
}

.storage-bar-fill {
    height: 100%;
    background: var(--primary-accent);
    width: 0%;
    transition: width 0.5s ease;
}

.storage-actions {
    display: flex;
    gap: 12px;
}

.storage-btn {
    flex: 1;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

.storage-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-accent);
}

.storage-btn.danger {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}

.storage-btn.danger:hover {
    background: rgba(255, 107, 107, 0.1);
}

/* --- Reader Controls (Mobile Optimized) --- */
#reader-controls {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(120px); /* Start off-screen */
    
    display: none; /* Default hidden */
    flex-direction: column;
    gap: 16px;
    
    padding: 16px 24px;
    background: rgba(18, 18, 18, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    backdrop-filter: blur(20px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    
    width: auto;
    min-width: 320px;
    max-width: 90vw;
}

#reader-controls.active-context {
    display: flex; /* Show in reader context */
}

#reader-controls.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Control Row Layout */
.controls-bottom-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
}

.controls-left {
    justify-self: start;
}

.controls-right {
    justify-self: end;
    display: flex;
    gap: 8px;
    position: relative; /* Context for dropdown */
}

.controls-center {
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 12px; /* Soft square */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.control-btn:active {
    transform: translateY(0);
}

.control-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 2px;
}

#page-display {
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0 12px;
    white-space: nowrap;
    cursor: pointer;
    background: transparent;
    border-radius: 8px;
    min-width: 120px;
    text-align: center;
    user-select: none;
}

#page-display:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

/* Settings Panel */
#reader-settings-panel {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 12px;
    background: rgba(18, 18, 18, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 16px;
    min-width: 240px;
    backdrop-filter: blur(20px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 101; /* Above buttons */
}

#reader-settings-panel.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#chapter-panel {
    position: absolute;
    bottom: 100%;
    right: 50px;
    margin-bottom: 12px;
    width: min(460px, 80vw);
    max-height: min(65vh, 560px);
    background: rgba(18, 18, 18, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    backdrop-filter: blur(20px);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 101;
    overflow: hidden;
}

#chapter-panel.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chapter-panel-header {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chapter-list {
    max-height: min(55vh, 500px);
    overflow: auto;
    padding: 8px;
}

.chapter-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text-secondary);
    text-align: left;
    font-size: 13px;
    line-height: 1.45;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.chapter-item.active {
    background: rgba(187, 134, 252, 0.2);
    color: var(--text-primary);
}

/* Slider Styling */
.page-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    cursor: pointer;
    transition: background 0.2s;
    margin: 0;
}
/* ... rest of slider styling ... */

.page-slider:hover {
    background: rgba(255, 255, 255, 0.2);
}

.page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-primary);
    cursor: pointer;
    transition: transform 0.1s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    margin-top: -6px; /* Center thumb */
}

.page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Progress Bar (Reading Progress) */
#progress-bar-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

#progress-bar {
    height: 100%;
    background: var(--primary-accent);
    width: 0%;
    transition: width 0.2s;
    box-shadow: 0 0 10px var(--primary-accent);
}

/* --- Scroll Indicator --- */
#scroll-indicator {
    position: fixed;
    right: 40px; /* Increased from 12px to avoid scrollbar overlap */
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary-accent);
    color: #000;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    z-index: 2000;
    cursor: grab;
    user-select: none;
    transition: opacity 0.3s, transform 0.1s;
    min-width: 48px; /* Increased min-width */
    text-align: center;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.2);
    white-space: nowrap; /* Prevent text wrapping */
    height: 32px; /* Fixed height to prevent shrinking */
    min-height: 32px; /* Ensure min height */
    max-height: 32px; /* Ensure max height */
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    bottom: auto !important; /* Force bottom to auto to prevent conflicts */
}

#scroll-indicator.fade-out {
    opacity: 0;
    pointer-events: none;
}

#scroll-indicator:active {
    cursor: grabbing;
    transform: translateY(-50%) scale(1.1);
    background: #fff;
}

/* Hide native scrollbar in reader mode */
body.reader-active {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}
body.reader-active::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
    width: 0;
    height: 0;
}
body.reader-active .container.reader-mode {
    scrollbar-width: none;
}
body.reader-active .container.reader-mode::-webkit-scrollbar {
    display: none;
}

/* --- Immersive Exit Button --- */
#immersive-exit {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.4);
    color: rgba(255, 255, 255, 0.8);
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(4px);
    font-size: 14px;
    z-index: 200;
    cursor: pointer;
    display: none;
}

body.immersive #reader-controls {
    transform: translateX(-50%) translateY(100px); /* Move out of view */
    pointer-events: none;
}

/* --- Password Modal (Simplified) --- */
/* Merged into main Modal section */

.modal-content {
    background: #1e1e1e;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    border-radius: var(--radius-lg);
    padding: 30px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.modal-content h2 {
    margin-top: 0;
    color: var(--text-primary);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    box-sizing: border-box;
    font-size: 16px;
    text-align: center;
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary-accent);
    background: rgba(255, 255, 255, 0.12);
}

.modal-content button {
    width: 100%;
    padding: 12px;
    background: var(--text-primary);
    color: var(--dark-bg);
    font-weight: bold;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 16px;
    transition: opacity 0.2s;
}

.modal-content button:hover {
    opacity: 0.9;
}

.error-message {
    color: #ff6b6b !important;
    font-size: 0.9em;
    margin-top: 10px;
    min-height: 1.2em;
}

.temp-source-form .form-group {
    margin-bottom: 12px;
    text-align: left;
}

.temp-source-form label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.temp-source-form input {
    width: 100%;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 14px;
    box-sizing: border-box;
}

.temp-source-form input:focus {
    outline: none;
    border-color: var(--primary-accent);
    background: rgba(255, 255, 255, 0.12);
}

#temp-source-modal .modal-content {
    max-width: 420px;
}

#temp-source-list {
    text-align: left;
}

.temp-source-badge {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    font-size: 0.85em;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    transition: background 0.2s, transform 0.1s;
}
.temp-source-badge:hover {
    background: rgba(179, 157, 219, 0.15) !important;
    transform: scale(1.02);
}
.temp-source-badge .temp-source-remove:hover {
    color: #ff6b6b !important;
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
    .container {
        padding: 16px;
        margin: 10px auto;
    }

    h1#main-title {
        font-size: 1.5em;
        text-align: center;
        margin-bottom: 0.5em;
    }
    
    p {
        text-align: center;
        font-size: 0.9em;
        margin-bottom: 1.5em;
    }

    .album-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .album-item {
        font-size: 0.9em;
    }

    .bookshelf-actions {
        /* On mobile, maybe stack search and buttons? Or keep them tight. */
        /* Keeping them tight for now */
    }

    #search-input {
        font-size: 14px;
        padding: 10px 16px;
    }
    
    #reader-controls {
        min-width: auto;
        max-width: 92vw;
        bottom: 12px;
        padding: 6px 12px;
        gap: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    #reader-controls::-webkit-scrollbar {
        display: none;
    }
    .controls-bottom-row {
        gap: 6px;
    }
    #page-display {
        min-width: auto;
        padding: 0 8px;
        font-size: 13px;
    }
    .controls-right {
        gap: 4px;
    }
    #download-btn, #spread-btn {
        display: none;
    }

    #chapter-panel {
        right: 0;
        width: min(88vw, 360px);
    }
}

/* =============================================
   Novel Reader
   ============================================= */

:root {
    --novel-bg: #121212;
    --novel-text: #e0e0e0;
    --novel-accent: #b39ddb;
    --novel-border: rgba(255,255,255,0.06);
    --novel-font-size: 18px;
    --novel-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --novel-line-height: 1.8;
}

body[data-novel-theme="sepia"] {
    --novel-bg: #f5e6c8;
    --novel-text: #5b4636;
    --novel-accent: #8b6914;
    --novel-border: rgba(0,0,0,0.08);
}

body[data-novel-theme="light"] {
    --novel-bg: #ffffff;
    --novel-text: #333333;
    --novel-accent: #7c4dff;
    --novel-border: rgba(0,0,0,0.08);
}

body[data-novel-theme="green"] {
    --novel-bg: #c7edcc;
    --novel-text: #3a5a3a;
    --novel-accent: #2e7d32;
    --novel-border: rgba(0,0,0,0.06);
}

body[data-reader-mode="novel"] {
    background-color: var(--novel-bg);
}

.novel-container {
    background: var(--novel-bg);
    color: var(--novel-text);
    min-height: 100vh;
    width: 100%;
    box-sizing: border-box;
}

/* Scroll Mode */
.novel-scroll {
    padding: 24px 16px 80px;
    max-width: 780px;
    margin: 0 auto;
}

.novel-chapter {
    content-visibility: auto;
    contain-intrinsic-size: 0px 200px;
    margin-bottom: 48px;
    border-bottom: 1px solid var(--novel-border);
    padding-bottom: 32px;
}

.novel-chapter:last-child {
    border-bottom: none;
}

.novel-chapter-title {
    font-size: calc(var(--novel-font-size) * 1.4);
    font-weight: 600;
    font-family: var(--novel-font-family);
    color: var(--novel-text);
    margin: 0 0 20px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--novel-accent);
    letter-spacing: 0.02em;
}

.novel-content {
    font-size: var(--novel-font-size);
    font-family: var(--novel-font-family);
    line-height: var(--novel-line-height);
    color: var(--novel-text);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    letter-spacing: 0.01em;
}

.novel-content.paged {
    padding: 40px 32px;
    min-height: 70vh;
    max-width: 700px;
    margin: 0 auto;
    background: var(--novel-bg);
}

/* Paged Mode */
.novel-paged {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    user-select: none;
    position: relative;
}

.novel-paged-nav {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.6);
    color: var(--novel-text);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 14px;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.1);
    z-index: 50;
}

/* Show/hide settings per reader mode */
body[data-reader-mode="novel"] .settings-group-comic { display: none; }
body[data-reader-mode="novel"] #comic-controls { display: none; }
body[data-reader-mode="comic"] .novel-controls-group { display: none; }
body[data-reader-mode="comic"] #download-btn { display: flex; }
body:not([data-reader-mode="comic"]) #download-btn { display: none; }

/* Comic reader direction & zoom buttons */
.comic-dir-btn, .comic-zoom-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.comic-dir-btn.active, .comic-zoom-btn.active {
    background: var(--primary-accent);
    color: var(--dark-bg);
    border-color: var(--primary-accent);
}

/* Novel reader controls in settings */
.novel-controls-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.novel-controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.novel-controls-row label {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 56px;
}

.novel-theme-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.novel-theme-btn.active {
    border-color: var(--primary-accent);
    box-shadow: 0 0 8px rgba(179, 157, 219, 0.5);
}

.novel-theme-btn[data-theme="dark"] { background: #121212; border-color: #555; }
.novel-theme-btn[data-theme="sepia"] { background: #f5e6c8; border-color: #c4a97d; }
.novel-theme-btn[data-theme="light"] { background: #ffffff; border-color: #ccc; }
.novel-theme-btn[data-theme="green"] { background: #c7edcc; border-color: #81c784; }

.novel-font-btn, .novel-pagemode-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.novel-font-btn.active, .novel-pagemode-btn.active {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary);
    border-color: var(--primary-accent);
}

.novel-font-size-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.15);
    outline: none;
    cursor: pointer;
}

.novel-font-size-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary-accent);
    cursor: pointer;
}

/* =============================================
   Comic Reader Improvements
   ============================================= */

/* Per-image progress bar for strip mode */
.per-image-progress-container {
    width: 80%;
    max-width: 300px;
    height: 3px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    overflow: hidden;
}

.per-image-progress-bar {
    height: 100%;
    background: var(--primary-accent);
    width: 0%;
    transition: width 0.1s;
}

/* Reader mode tag on album items */
.album-item .album-type-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    background: rgba(0,0,0,0.5);
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.1);
}

/* Smooth page transitions for single page mode */
.reader-image-item.single-page-mode {
    animation: page-enter 0.2s ease-out;
}

@keyframes page-enter {
    from { opacity: 0.6; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

/* Better zoom controls */
.zoom-controls {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 50;
    opacity: 0;
    transition: opacity 0.2s;
}

.reader-image-item.single-page-mode:hover .zoom-controls {
    opacity: 1;
}

.zoom-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.5);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: all 0.2s;
}

.zoom-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.1);
}

/* =============================================
   Settings Panel Novel Controls
   ============================================= */

.settings-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.settings-group-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

#reader-settings-panel .settings-group.compact {
    gap: 6px;
}

/* Novel chapter transition */
.novel-chapter {
    scroll-margin-top: 20px;
}

/* =============================================
   Toast improvements
   ============================================= */

.toast {
    font-size: 14px;
    backdrop-filter: blur(8px);
    background: rgba(30,30,30,0.92);
}

.toast.success {
    border-left-color: #00C851;
}

.toast.warning {
    border-left-color: #ffbb33;
}

.toast.error {
    border-left-color: #ff4444;
}

.toast.info {
    border-left-color: var(--primary-accent);
}

/* =============================================
   Scrollbar for novel content
   ============================================= */

.novel-content::-webkit-scrollbar {
    width: 6px;
}

.novel-content::-webkit-scrollbar-track {
    background: transparent;
}

.novel-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
}

body[data-novel-theme="light"] .novel-content::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
}

body[data-novel-theme="sepia"] .novel-content::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
}

body[data-novel-theme="green"] .novel-content::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.12);
}

/* =============================================
   Mobile Novel Reader
   ============================================= */

@media (max-width: 600px) {
    .novel-content.paged {
        padding: 24px 20px;
    }
    .novel-chapter-title {
        font-size: calc(var(--novel-font-size) * 1.2);
    }
    .novel-paged-nav {
        font-size: 12px;
        padding: 6px 14px;
    }
}

/* =============================================
   ============================================= */

/* =============================================
   Selection Mode bar on mobile
   ============================================= */

@media (max-width: 600px) {
    .selection-bar {
        padding: 12px 16px;
    }
    .selection-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
}

/* Reader direction for RTL comics */
#spread-btn.active {
    color: var(--primary-accent);
    background: rgba(179, 157, 219, 0.15);
}

/* Spread / Dual-page mode */
.reader-image-item.single-page-mode.spread-mode {
    flex-direction: row;
    gap: 4px;
    background: rgba(0,0,0,0.85);
    overflow: hidden;
}
.reader-image-item.single-page-mode.spread-mode .spread-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-width: 0;
    max-width: 50%;
}
.reader-image-item.single-page-mode.spread-mode .spread-page img {
    max-width: 100%;
    max-height: 100vh;
    object-fit: contain;
    width: auto;
    height: auto;
}
/* Vertical spread for wide/landscape images */
.reader-image-item.single-page-mode.spread-mode.spread-vertical {
    flex-direction: column;
    gap: 4px;
}
.reader-image-item.single-page-mode.spread-mode.spread-vertical .spread-page {
    max-width: 100%;
    max-height: 50vh;
    flex: 1;
}
.reader-image-item.single-page-mode.spread-mode.spread-vertical .spread-page img {
    max-height: 100%;
    max-width: 100vw;
}

/* Page flip animation */
.page-flip-enter {
    animation: pageFlipIn 0.35s ease-out;
}
@keyframes pageFlipIn {
    from { opacity: 0.3; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

body[data-comic-direction="rtl"] .reader-image-item.single-page-mode {
    direction: rtl;
}

body[data-comic-direction="rtl"] .novel-content {
    direction: rtl;
    text-align: right;
}
