/* ==========================================================================
   Audia - Custom Styles
   E-reader typography and enhanced UI styling
   ========================================================================== */

/* Typography & Reading Experience */
.prose {
    font-family: Georgia, Cambria, 'Times New Roman', serif;
    font-size: 1.125rem;
    line-height: 1.8;
    letter-spacing: 0.01em;
}

.prose p {
    margin-bottom: 1.5em;
    text-align: justify;
    hyphens: auto;
}

.prose h1,
.prose h2,
.prose h3 {
    font-family: system-ui, -apple-system, sans-serif;
    font-weight: 700;
    margin-top: 2em;
    margin-bottom: 0.75em;
}

/* Dark mode prose adjustments */
.dark .prose {
    color: #e5e7eb;
}

.dark .prose h1,
.dark .prose h2,
.dark .prose h3 {
    color: #fbbf24;
}

/* Segment highlighting */
.segment {
    cursor: pointer;
    transition: background-color 0.2s ease, padding 0.2s ease;
    border-radius: 4px;
    padding: 4px 6px;
    margin: 4px 0;
    display: block;
}

.segment:hover {
    background-color: rgba(251, 191, 36, 0.15);
}

.segment.active {
    background-color: rgba(251, 191, 36, 0.4);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.5);
}

.dark .segment:hover {
    background-color: rgba(251, 191, 36, 0.1);
}

.dark .segment.active {
    background-color: rgba(251, 191, 36, 0.25);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3);
}

.segment.played {
    color: #9ca3af;
}

.dark .segment.played {
    color: #6b7280;
}

/* Book Container (ebook style) */
.book-container {
    position: relative;
    background: linear-gradient(to right, #f5f0e1 0%, #fffbf0 5%, #fffbf0 95%, #f5f0e1 100%);
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.15),
        inset 0 0 100px rgba(0, 0, 0, 0.02);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.dark .book-container {
    background: linear-gradient(to right, #1f2937 0%, #374151 5%, #374151 95%, #1f2937 100%);
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.4),
        inset 0 0 100px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Page navigation buttons */
.page-nav-btn {
    opacity: 0.5;
    transition: all 0.3s ease;
}

.book-container:hover .page-nav-btn {
    opacity: 1;
}

.page-nav-btn:hover {
    transform: translateY(-50%) scale(1.1);
}

#pageContent {
    animation: fadeIn 0.3s ease-out;
    min-height: 50vh;
}

/* Drop Zone animations */
#dropZone>div {
    transition: all 0.3s ease;
}

#dropZone.dragover>div {
    border-color: #f59e0b;
    background-color: rgba(251, 191, 36, 0.1);
    transform: scale(1.02);
}

.dark #dropZone.dragover>div {
    background-color: rgba(251, 191, 36, 0.05);
}

/* Playback button pulse animation */
@keyframes pulse-ring {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

#playPause.playing::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 9999px;
    background-color: #f59e0b;
    animation: pulse-ring 1.5s ease-out infinite;
    z-index: -1;
}

#playPause {
    position: relative;
}

/* Smooth scrolling for reader content */
#readerView {
    scroll-behavior: smooth;
}

/* Progress bar glow effect */
#progressBar {
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.4);
}

.dark #progressBar {
    box-shadow: 0 0 8px rgba(217, 119, 6, 0.4);
}

/* Modal backdrop blur */
#settingsModal>div:first-child {
    backdrop-filter: blur(4px);
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

.dark ::-webkit-scrollbar-thumb {
    background: #4b5563;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Loading spinner */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.animate-spin {
    animation: spin 1s linear infinite;
}

/* Voice status indicator */
#voiceStatus .animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* Button hover effects */
button {
    transition: all 0.2s ease;
}

button:active {
    transform: scale(0.97);
}

/* Chapter select styling */
#chapterSelect {
    max-width: 200px;
    text-overflow: ellipsis;
}

/* Reader content fade-in */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#textContent {
    animation: fadeIn 0.3s ease-out;
}

/* Recent book cards */
.book-card {
    transition: all 0.2s ease;
}

.book-card:hover {
    transform: translateX(4px);
    background-color: rgba(251, 191, 36, 0.1);
}

/* Model card in settings */
.model-card {
    transition: all 0.2s ease;
}

.model-card.active {
    border-color: #f59e0b;
    background-color: rgba(251, 191, 36, 0.1);
}

.model-card:hover {
    background-color: rgba(251, 191, 36, 0.1);
}

/* Add Book Card (Dashed) */
.add-book-card {
    border: 2px dashed #d1d5db;
    background-color: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: all 0.2s ease;
    cursor: pointer;
}

.add-book-card:hover {
    border-color: #f59e0b;
    color: #f59e0b;
    background-color: rgba(245, 158, 11, 0.05);
    /* amber-50 */
    transform: translateY(-4px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.dark .add-book-card {
    border-color: #374151;
    color: #4b5563;
}

.dark .add-book-card:hover {
    border-color: #fbbf24;
    color: #fbbf24;
    background-color: rgba(251, 191, 36, 0.05);
}

/* Voice catalog cards */
.voice-card {
    transition: all 0.2s ease;
}

.voice-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dark .voice-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Voice catalog scrollbar */
#voiceCatalog::-webkit-scrollbar {
    width: 6px;
}

#voiceCatalog::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.dark #voiceCatalog::-webkit-scrollbar-thumb {
    background: #4b5563;
}

/* Hide scrollbar on touch devices for cleaner look */
@media (pointer: coarse) {
    ::-webkit-scrollbar {
        width: 4px;
    }
}

/* Responsive text sizing */
@media (max-width: 640px) {
    .prose {
        font-size: 1rem;
        line-height: 1.7;
    }

    .prose p {
        text-align: left;
    }
}

/* Print styles (hide controls when printing) */
@media print {

    header,
    footer,
    #playbackControls,
    #settingsModal,
    #loadingOverlay {
        display: none !important;
    }

    #readerView {
        max-width: 100%;
        padding: 0;
    }
}

/* ==========================================================================
   Mobile Bottom Sheet (Sidebar Transformation)
   ========================================================================== */
@media (max-width: 768px) {

    /* Transform Sidebar to Bottom Sheet */
    #sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        /* Override full height */
        width: 100%;
        height: 85vh;
        /* Max height for sheet */
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        /* Start hidden (down) */
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        border-right: none;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        z-index: 50;
        /* Above other content */
    }

    .dark #sidebar {
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    /* Active State (Slide up) */
    #sidebar.active {
        transform: translateY(0);
        /* Note: We reuse the existing toggle class logic but rely on translateY instead of X */
    }

    /* Overlay for Bottom Sheet */
    #sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 40;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        backdrop-filter: blur(2px);
    }

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

    /* Hide the "Library" button inside the sheet header if confusing, 
       or style it to look like a "Close" handle 
    */
    /* #sidebarBackBtn {
        display: none !important; 
    } */

    /* Add a visual "Handle" */
    #sidebar::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background-color: #e5e7eb;
        border-radius: 2px;
        z-index: 51;
    }

    .dark #sidebar::before {
        background-color: #4b5563;
    }
}

/* ==========================================================================
   New Mobile Layout (Split Screen)
   ========================================================================== */

/* Mobile Voice Panel Scrollbar Hide */
#mobileVoicePanel {
    -ms-overflow-style: none;
    /* IE and Edge */
    scrollbar-width: none;
    /* Firefox */
}

#mobileVoicePanel::-webkit-scrollbar {
    display: none;
}

/* Responsive Control Bar Logic
   Mobile: Part of the fixed bottom section
   Desktop: Restore Floating Look
*/
@media (min-width: 768px) {
    #mobileBottomSection {
        background-color: transparent !important;
        border-top: none !important;
        pointer-events: none;
        padding-bottom: 1.5rem;
    }

    #controlBar {
        width: 90%;
        margin-left: auto;
        margin-right: auto;
        background-color: rgba(255, 255, 255, 0.9);
        backdrop-filter: blur(8px);
        border-radius: 1rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        border: 1px solid rgba(229, 231, 235, 1);
        pointer-events: auto;
    }

    .dark #controlBar {
        background-color: rgba(31, 41, 55, 0.9);
        border: 1px solid rgba(55, 65, 81, 1);
    }
}

/* Mobile Adjustments */
@media (max-width: 767px) {
    #controlBar {
        width: 100%;
        max-width: none;
        padding-left: 1rem;
        padding-right: 1rem;
        border: none;
        background: transparent;
        box-shadow: none;
    }

    /* Hide less critical info on small screens */
    #pageCounter,
    #globalPercent {
        font-size: 0.65rem;
    }

    /* Ensure bottom padding for safe area */
    #mobileVoicePanel {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }
}