/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eaeaea;
    --text-secondary: #a0a0a0;
    --accent: #4a90d9;
    --accent-hover: #5ca0e9;
    --danger: #e74c3c;
    --success: #2ecc71;
    --warning: #f39c12;
    --border-color: #2d3748;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* Light Theme */
[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e8e8e8;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border-color: #ddd;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* Sepia Theme */
[data-theme="sepia"] {
    --bg-primary: #f4ecd8;
    --bg-secondary: #faf8f0;
    --bg-tertiary: #e8dfc9;
    --text-primary: #5c4b37;
    --text-secondary: #8b7355;
    --border-color: #d4c9b5;
    --shadow: 0 4px 6px rgba(92, 75, 55, 0.1);
    --shadow-lg: 0 10px 25px rgba(92, 75, 55, 0.15);
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-screen p {
    color: var(--text-secondary);
    margin: 8px 0;
}

#loading-text {
    font-weight: 500;
    color: var(--text-primary);
}

#loading-percent {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
}

/* Screens */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(20px);
}

/* Login Screen */
.login-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
}

.app-logo {
    margin-bottom: 20px;
}

.book-icon {
    width: 100px;
    height: 100px;
    margin-bottom: 16px;
}

.app-logo h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    color: var(--text-secondary);
    margin-bottom: 40px;
    font-size: 1.1rem;
}

.google-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 28px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow);
}

.google-btn:hover {
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.google-icon {
    width: 24px;
    height: 24px;
}

.info-text {
    margin-top: 30px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    max-width: 300px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
    color: var(--text-primary);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--accent);
    cursor: pointer;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Folder Selector */
.folder-selector {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.select-folder-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all var(--transition);
}

.select-folder-btn svg {
    width: 24px;
    height: 24px;
    fill: var(--accent);
}

.select-folder-btn:hover {
    border-color: var(--accent);
    background: var(--bg-secondary);
}

/* Library Content */
.library-content {
    height: calc(100vh - 140px);
    overflow-y: auto;
    padding: 20px;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
}

.empty-icon {
    width: 120px;
    height: 120px;
    margin-bottom: 20px;
    opacity: 0.5;
}

/* Book Grid */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
}

.book-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow);
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    background: linear-gradient(135deg, var(--bg-tertiary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.book-cover svg {
    width: 60px;
    height: 60px;
    fill: white;
    opacity: 0.8;
}

.book-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Cover slot — <img> sits on top of the SVG fallback. When the image has
   loaded (.cover-loaded), it covers the fallback. While a lazy cover has
   not loaded yet, the <img> is invisible so the SVG shows through. */
.book-cover .cover-img,
.row-cover .cover-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.book-cover .cover-img.cover-loaded,
.row-cover .cover-img.cover-loaded {
    opacity: 1;
}
.book-cover .cover-fallback,
.row-cover .cover-fallback {
    fill: white;
    opacity: 0.8;
}
.book-cover .cover-fallback-small {
    width: 20px;
    height: 20px;
}
.book-cover-folder {
    background: linear-gradient(135deg, #b87f1e, #f39c12);
}
.book-cover-audio {
    background: linear-gradient(135deg, var(--bg-tertiary), var(--accent));
}
.book-cover-pdf {
    background: linear-gradient(135deg, #8a3329, #e74c3c);
}

.book-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(0, 0, 0, 0.3);
}

.book-progress-bar {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}

.book-info {
    padding: 12px;
}

.book-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-type {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.book-type svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* File List View */
.file-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.file-item:hover {
    background: var(--bg-tertiary);
}

.file-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-icon.pdf {
    background: #e74c3c;
}

.file-icon.audio {
    background: var(--accent);
}

.file-icon.folder {
    background: #f39c12;
}

.file-icon svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.file-details {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Reader Header */
.reader-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.reader-title {
    flex: 1;
    min-width: 0;
}

.reader-title h2 {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reader-title span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.reader-actions {
    display: flex;
    gap: 4px;
}

/* PDF Viewer */
.viewer-container {
    height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
    background: var(--bg-tertiary);
}

.pdf-viewer {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    padding: 20px;
}

.pdf-viewer canvas {
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow-lg);
}

.page-navigation {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.nav-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--bg-tertiary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    color: var(--text-primary);
}

.nav-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.nav-btn:hover {
    background: var(--accent);
    color: white;
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#page-info {
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 80px;
    text-align: center;
}

/* Audio Player */
.player-container {
    height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, var(--bg-primary) 100%);
}

.album-art {
    width: 280px;
    height: 280px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    margin-bottom: 30px;
    position: relative;
}

/* Both the default SVG and the cover <img> fill the box; the img sits on
   top via DOM order. Toggling .hidden on the img reveals the SVG. */
.album-art .default-art,
.album-art img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.album-art img {
    object-fit: cover;
}

.audio-info {
    text-align: center;
    margin-bottom: 30px;
}

.audio-info h3 {
    font-size: 1.3rem;
    margin-bottom: 4px;
}

.audio-info p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.progress-container {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 400px;
    margin-bottom: 30px;
}

.progress-container span {
    font-size: 0.8rem;
    color: var(--text-secondary);
    min-width: 40px;
}

/* Wrapper that lets us overlay markers on top of the range input. */
.progress-track {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.progress-track > .progress-bar {
    width: 100%;
}

.progress-bar {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    cursor: pointer;
}

/* "Where was I?" marker: shows the listening position before the last
   big jump. Clicking it returns there (same target a tap on that spot
   of the bar would seek to, so it never fights the slider). */
.jump-back-marker {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1;
}

.jump-back-marker::before {
    content: '';
    width: 4px;
    height: 16px;
    border-radius: 2px;
    background: var(--warning);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

.jump-back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -18px 0 18px;
    padding: 6px 14px;
    border: 1px solid var(--warning);
    border-radius: 16px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s;
}

.jump-back-btn:hover {
    background: var(--bg-tertiary);
}

.jump-back-btn svg {
    width: 16px;
    height: 16px;
    fill: var(--warning);
    flex-shrink: 0;
}

.progress-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--text-primary);
    cursor: pointer;
    box-shadow: var(--shadow);
}

.progress-bar::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--text-primary);
    cursor: pointer;
}

.audio-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-bottom: 24px;
}

.control-btn {
    width: 50px;
    height: 50px;
    border: none;
    background: var(--bg-secondary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    color: var(--text-primary);
    position: relative;
}

.control-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.control-btn:hover {
    background: var(--bg-tertiary);
    transform: scale(1.05);
}

.control-btn.play-btn {
    width: 70px;
    height: 70px;
    background: var(--accent);
    color: white;
}

.control-btn.play-btn:hover {
    background: var(--accent-hover);
}

.control-btn.play-btn svg {
    width: 32px;
    height: 32px;
}

.control-btn.small {
    width: 44px;
    height: 44px;
    flex-direction: column;
}

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

.control-btn.small span {
    font-size: 0.6rem;
    font-weight: 600;
    position: absolute;
    bottom: 6px;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.speed-control select {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    transition: opacity 0.2s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-content.large {
    max-width: 600px;
    max-height: 90vh;
}

.modal-content.compact {
    max-width: 350px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 140px);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* Settings */
.setting-group {
    margin-bottom: 24px;
}

.setting-group:last-child {
    margin-bottom: 0;
}

.setting-group h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.theme-options, .display-options {
    display: flex;
    gap: 8px;
}

.theme-btn, .display-btn {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 0.85rem;
}

.theme-btn:hover, .display-btn:hover {
    border-color: var(--accent);
}

.theme-btn.active, .display-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.theme-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.theme-preview {
    width: 100%;
    height: 24px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.light-preview {
    background: #ffffff;
    border-color: #ccc;
}

.dark-preview {
    background: #1a1a2e;
}

.sepia-preview {
    background: #f4ecd8;
    border-color: #d4c4a8;
}

.font-size-control, .zoom-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.font-size-control span, .zoom-control span {
    min-width: 50px;
    text-align: center;
}

.account-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.account-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* Buttons */
.primary-btn {
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.secondary-btn {
    padding: 10px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
}

.secondary-btn:hover {
    background: var(--bg-primary);
}

.danger-btn {
    padding: 10px 20px;
    background: var(--danger);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
}

.danger-btn:hover {
    opacity: 0.9;
}

/* File Picker */
.picker-content {
    min-height: 300px;
}

.picker-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 300px;
}

.picker-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.picker-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
}

.picker-item:hover {
    background: var(--bg-tertiary);
}

.picker-item.selected {
    background: var(--accent);
    color: white;
}

.picker-item svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    animation: slideUp 0.3s ease;
}

.toast.success {
    border-left: 4px solid var(--success);
}

.toast.error {
    border-left: 4px solid var(--danger);
}

.toast.warning {
    border-left: 4px solid var(--warning);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chapter List */
.chapter-list {
    position: absolute;
    bottom: 80px;
    left: 20px;
    right: 20px;
    max-height: 300px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.chapter-list h3 {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.chapter-list ul {
    list-style: none;
    max-height: 240px;
    overflow-y: auto;
}

.chapter-list li {
    padding: 12px 16px;
    cursor: pointer;
    transition: background var(--transition);
    display: flex;
    align-items: center;
    gap: 10px;
}

.chapter-list li:hover {
    background: var(--bg-tertiary);
}

.chapter-list li.active {
    background: var(--accent);
    color: white;
}

.chapter-list li svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Mobile Optimizations */
@media (max-width: 600px) {
    .app-header h1 {
        font-size: 1.2rem;
    }

    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 12px;
    }

    .album-art {
        width: 220px;
        height: 220px;
    }

    .audio-controls {
        gap: 12px;
    }

    .control-btn {
        width: 44px;
        height: 44px;
    }

    .control-btn.play-btn {
        width: 60px;
        height: 60px;
    }

    .modal-content {
        margin: 10px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* EPUB Viewer */
.epub-viewer {
    flex: 1;
    width: 100%;
    height: 100%;
    background: var(--bg-secondary);
}

#epub-location {
    font-size: 0.9rem;
    color: var(--text-secondary);
    min-width: 60px;
    text-align: center;
}

/* Chapter list improvements */
.chapter-list {
    position: absolute;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.chapter-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.chapter-list-header h3 {
    font-size: 1rem;
}

.chapter-list ul {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.chapter-list li {
    padding: 14px 16px;
    cursor: pointer;
    transition: background var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.chapter-list li:hover {
    background: var(--bg-tertiary);
}

.chapter-list li.active {
    background: var(--accent);
    color: white;
}

.chapter-list li .chapter-progress {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.chapter-list li.active .chapter-progress {
    color: rgba(255, 255, 255, 0.8);
}

/* Parts button for multi-file books */
.parts-btn {
    position: fixed;
    bottom: 100px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--accent);
    border: none;
    border-radius: 30px;
    color: white;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    transition: all var(--transition);
}

.parts-btn:hover {
    transform: scale(1.05);
    background: var(--accent-hover);
}

.parts-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Audio loading overlay */
.audio-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.audio-loading p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin: 8px 0;
}

#audio-loading-text {
    font-weight: 500;
    color: var(--text-primary);
}

#audio-loading-size {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent);
}

.progress-bar-container {
    width: 80%;
    max-width: 300px;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin: 12px 0;
}

.progress-bar-container > .progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #6bb5ff);
    border-radius: 4px;
    transition: width 0.1s ease-out;
}

/* Book card with type badge */
.book-card .book-type-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 4px 8px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 4px;
    font-size: 0.7rem;
    color: white;
    text-transform: uppercase;
}

/* Multi-part book indicator */
.book-card .parts-indicator {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 4px 8px;
    background: var(--accent);
    border-radius: 4px;
    font-size: 0.7rem;
    color: white;
}

/* Book grid view */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 20px;
    padding: 10px 0;
}

.book-card {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: var(--shadow);
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    background: linear-gradient(135deg, var(--bg-tertiary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.book-cover svg {
    width: 50px;
    height: 50px;
    fill: white;
    opacity: 0.8;
}

.book-cover .book-icon-text {
    position: absolute;
    bottom: 10px;
    left: 10px;
    right: 10px;
    font-size: 0.8rem;
    color: white;
    text-shadow: 0 1px 3px rgba(0,0,0,0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(0, 0, 0, 0.3);
}

.book-progress-bar {
    height: 100%;
    background: var(--success);
    transition: width 0.3s ease;
}

.book-info {
    padding: 12px;
}

.book-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.book-meta svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Section headers in library */
.library-section {
    margin-bottom: 24px;
}

.library-section h3 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    padding-left: 4px;
}

/* Continue reading card */
.continue-reading {
    background: linear-gradient(135deg, var(--accent), #6366f1);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
    color: white;
}

.continue-reading h3 {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.continue-reading .book-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.continue-reading .book-chapter {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 12px;
}

.continue-reading .continue-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 20px;
    color: white;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--transition);
}

.continue-reading .continue-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.continue-reading .continue-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Library toolbar (sort dropdown + view toggle).
   Lives at the top of the library content area; both controls share a row. */
.library-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 4px 16px;
    flex-wrap: wrap;
}
.library-toolbar-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.library-sort-select {
    flex: 1;
    max-width: 320px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
}
.library-toolbar-spacer {
    flex: 1;
}

/* View toggle — segmented control with two icon buttons. */
.view-toggle {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}
.view-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}
.view-toggle-btn + .view-toggle-btn {
    border-left: 1px solid var(--border-color);
}
.view-toggle-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.view-toggle-btn.active {
    background: var(--accent);
    color: white;
}
.view-toggle-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Row thumbnail — small 2:3 cover box used by file-item rows and book-rows
   in Details view. Mirrors .book-cover layering. */
.row-cover {
    position: relative;
    width: 40px;
    height: 60px;
    flex: 0 0 auto;
    border-radius: 4px;
    overflow: hidden;
    background: linear-gradient(135deg, var(--bg-tertiary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Book as a list row (Details view). Shares .book-card so click handlers
   pick it up, but flexes horizontally instead of stacking. */
.book-card.book-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: background var(--transition);
}
.book-card.book-row:hover {
    background: var(--bg-tertiary);
    transform: none;
    box-shadow: var(--shadow);
}

/* Slim inline progress bar used by row variants. */
.row-progress {
    width: 60px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    flex: 0 0 auto;
}
.row-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
}

/* Folder-as-card (Icons view) — book-card sized, but with a flat folder
   gradient instead of a cover image. */
.book-card.folder-card .book-cover {
    background: linear-gradient(135deg, #b87f1e, #f39c12);
}
