/**
 * Audiobook Player Styles
 *
 * Provides styling for the full-document audiobook player including:
 * - Fixed bottom player bar
 * - Chapter list drawer
 * - Edition selector modal
 * - Playback controls
 */

/* CSS Variables */
:root {
    --audiobook-bg: #1a1a2e;
    --audiobook-bg-secondary: #16213e;
    --audiobook-accent: #4a90d9;
    --audiobook-accent-hover: #5ba3f0;
    --audiobook-text: #ffffff;
    --audiobook-text-secondary: #a0a0b0;
    --audiobook-border: #2a2a4a;
    --audiobook-progress-bg: #3a3a5a;
    --audiobook-progress-fill: #4a90d9;
    --audiobook-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

/* Light mode adjustments */
@media (prefers-color-scheme: light) {
    :root {
        --audiobook-bg: #ffffff;
        --audiobook-bg-secondary: #f5f5f7;
        --audiobook-accent: #2563eb;
        --audiobook-accent-hover: #1d4ed8;
        --audiobook-text: #1f2937;
        --audiobook-text-secondary: #6b7280;
        --audiobook-border: #e5e7eb;
        --audiobook-progress-bg: #e5e7eb;
        --audiobook-progress-fill: #2563eb;
        --audiobook-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    }
}

/* Main Container */
.audiobook-player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.audiobook-player.hidden {
    display: none;
}

/* Player Bar */
.audiobook-player-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    background: var(--audiobook-bg);
    border-top: 1px solid var(--audiobook-border);
    box-shadow: var(--audiobook-shadow);
}

/* Loading Overlay */
.audiobook-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(26, 26, 46, 0.9);
    z-index: 10;
}

.audiobook-loading.hidden {
    display: none;
}

.audiobook-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--audiobook-text-secondary);
    border-top-color: var(--audiobook-accent);
    border-radius: 50%;
    animation: audiobook-spin 0.8s linear infinite;
}

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

/* Now Playing */
.audiobook-now-playing {
    flex: 0 0 200px;
    min-width: 0;
}

.audiobook-chapter-title {
    display: block;
    color: var(--audiobook-text);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Controls */
.audiobook-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.audiobook-controls button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--audiobook-text);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.audiobook-controls button:hover {
    background: var(--audiobook-bg-secondary);
}

.audiobook-controls button:active {
    transform: scale(0.95);
}

.audiobook-play-btn {
    width: 48px !important;
    height: 48px !important;
    background: var(--audiobook-accent) !important;
}

.audiobook-play-btn:hover {
    background: var(--audiobook-accent-hover) !important;
}

.audiobook-play-btn .hidden {
    display: none;
}

/* Skip buttons text */
.audiobook-skip-back text,
.audiobook-skip-forward text {
    font-family: inherit;
    font-weight: 600;
}

/* Progress Bar */
.audiobook-progress {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
}

.audiobook-current-time,
.audiobook-total-time {
    font-size: 12px;
    color: var(--audiobook-text-secondary);
    font-variant-numeric: tabular-nums;
    min-width: 40px;
}

.audiobook-current-time {
    text-align: right;
}

.audiobook-progress-bar {
    flex: 1;
    height: 4px;
    background: var(--audiobook-progress-bg);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.audiobook-progress-bar:hover {
    height: 6px;
    margin: -1px 0;
}

.audiobook-progress-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: var(--audiobook-progress-fill);
    border-radius: 2px;
    transition: width 0.1s linear;
}

/* Actions */
.audiobook-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.audiobook-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--audiobook-text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.audiobook-actions button:hover {
    background: var(--audiobook-bg-secondary);
    color: var(--audiobook-text);
}

/* Speed Control */
.audiobook-speed-control {
    position: relative;
}

.audiobook-speed-btn {
    min-width: 44px !important;
    font-size: 12px;
    font-weight: 600;
}

.audiobook-speed-menu {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    background: var(--audiobook-bg);
    border: 1px solid var(--audiobook-border);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.audiobook-speed-menu.hidden {
    display: none;
}

.audiobook-speed-menu button {
    display: block;
    width: 100%;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--audiobook-text);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.audiobook-speed-menu button:hover {
    background: var(--audiobook-bg-secondary);
}

.audiobook-speed-menu button.active {
    background: var(--audiobook-accent);
    color: white;
}

/* Chapter Drawer */
.audiobook-chapter-drawer {
    position: fixed;
    right: 0;
    bottom: 72px;
    width: 320px;
    max-height: 60vh;
    background: var(--audiobook-bg);
    border: 1px solid var(--audiobook-border);
    border-radius: 12px 0 0 0;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999;
}

.audiobook-chapter-drawer.hidden {
    display: none;
}

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

.audiobook-drawer-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--audiobook-text);
}

.audiobook-drawer-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--audiobook-text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.audiobook-drawer-close:hover {
    background: var(--audiobook-bg-secondary);
    color: var(--audiobook-text);
}

.audiobook-chapter-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.audiobook-chapter-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.audiobook-chapter-item:hover {
    background: var(--audiobook-bg-secondary);
}

.audiobook-chapter-item.active {
    background: var(--audiobook-accent);
}

.audiobook-chapter-item.active .chapter-title,
.audiobook-chapter-item.active .chapter-number,
.audiobook-chapter-item.active .chapter-duration {
    color: white;
}

.chapter-number {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--audiobook-bg-secondary);
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    color: var(--audiobook-text-secondary);
}

.audiobook-chapter-item.active .chapter-number {
    background: rgba(255, 255, 255, 0.2);
}

.chapter-title {
    flex: 1;
    font-size: 13px;
    color: var(--audiobook-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chapter-duration {
    font-size: 12px;
    color: var(--audiobook-text-secondary);
}

/* Edition Selector Modal */
.audiobook-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1100;
}

.audiobook-modal.hidden {
    display: none;
}

.audiobook-modal-content {
    background: var(--audiobook-bg);
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.audiobook-modal-content h2 {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 600;
    color: var(--audiobook-text);
}

.audiobook-modal-content p {
    margin: 0 0 20px;
    font-size: 14px;
    color: var(--audiobook-text-secondary);
}

.audiobook-edition-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.audiobook-edition-btn {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px;
    border: 1px solid var(--audiobook-border);
    border-radius: 12px;
    background: var(--audiobook-bg-secondary);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.audiobook-edition-btn:hover {
    border-color: var(--audiobook-accent);
    background: var(--audiobook-bg);
}

.audiobook-edition-btn strong {
    font-size: 15px;
    font-weight: 600;
    color: var(--audiobook-text);
}

.audiobook-edition-btn span {
    font-size: 13px;
    color: var(--audiobook-text-secondary);
}

.audiobook-no-editions {
    padding: 20px;
    text-align: center;
    color: var(--audiobook-text-secondary);
}

.audiobook-modal-cancel {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--audiobook-border);
    border-radius: 8px;
    background: transparent;
    color: var(--audiobook-text);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.audiobook-modal-cancel:hover {
    background: var(--audiobook-bg-secondary);
}

/* Toast Notifications */
.audiobook-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: var(--audiobook-bg);
    border: 1px solid var(--audiobook-border);
    border-radius: 8px;
    color: var(--audiobook-text);
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 1200;
}

.audiobook-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.audiobook-toast-success {
    border-color: #22c55e;
}

.audiobook-toast-error {
    border-color: #ef4444;
}

/* Responsive */
@media (max-width: 768px) {
    .audiobook-player-bar {
        flex-wrap: wrap;
        padding: 12px 16px;
        gap: 12px;
    }

    .audiobook-now-playing {
        flex: 1 1 100%;
        order: 1;
    }

    .audiobook-controls {
        order: 2;
    }

    .audiobook-progress {
        flex: 1 1 100%;
        order: 4;
    }

    .audiobook-actions {
        order: 3;
        margin-left: auto;
    }

    .audiobook-chapter-drawer {
        width: 100%;
        right: 0;
        left: 0;
        border-radius: 12px 12px 0 0;
    }
}

@media (max-width: 480px) {
    .audiobook-controls button {
        width: 36px;
        height: 36px;
    }

    .audiobook-play-btn {
        width: 44px !important;
        height: 44px !important;
    }

    .audiobook-skip-back,
    .audiobook-skip-forward {
        display: none;
    }
}
