/* Mobile Navigation Enhancements */

/* Global Touch Optimizations for Mobile Devices */
* {
    /* Remove 300ms tap delay on mobile */
    touch-action: manipulation;
}

/* Disable text selection on interactive elements */
button, .btn, .book-item, .chapter-item, [role="button"] {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

/* Books Modal Overlay */
.books-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.books-modal {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: modalSlideIn 0.3s ease-out;
}

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

.books-modal-header {
    margin-bottom: 20px;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 16px;
}

.books-modal-header h2 {
    margin: 0 0 8px 0;
    color: #1f2937;
    font-size: 24px;
    font-weight: 600;
}

.books-modal-header p {
    margin: 0;
    color: #6b7280;
    font-size: 14px;
}

.close-modal {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #6b7280;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.close-modal:hover {
    background: #f3f4f6;
    color: #374151;
}

.close-modal:active {
    transform: scale(0.95);
    background: #e5e7eb;
}

#books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.book-tile {
    padding: 16px 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    /* Enhanced touch support */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

.book-tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.6s ease;
}

.book-tile:hover::before {
    left: 100%;
}

.book-tile:hover {
    border-color: #4CAF50;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.15);
}

.book-tile:active {
    transform: translateY(0px) scale(0.98);
}

.book-name {
    font-weight: 500;
    font-size: 14px;
    color: #1f2937;
    z-index: 1;
    position: relative;
}

/* Mobile Navigator Panel Improvements */
.mobile-nav-panel {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    box-shadow: 4px 0 8px rgba(0, 0, 0, 0.1);
}

.mobile-nav-panel.active {
    transform: translateX(0);
}

/* Enhanced Mobile Navigation Controls */
.mobile-nav-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #f8fafc;
    border-radius: 8px;
    margin: 16px 0;
}

.mobile-nav-current {
    flex: 1;
    text-align: center;
    font-weight: 500;
    color: #1f2937;
}

.mobile-nav-arrow {
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 16px;
}

.mobile-nav-arrow:hover {
    background: #45a049;
    transform: scale(1.05);
}

.mobile-nav-arrow:active {
    transform: scale(0.95);
}

.mobile-nav-arrow:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

/* Button Loading States */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #ffffff;
    border-right-color: transparent;
    border-radius: 50%;
    animation: button-spin 0.8s linear infinite;
}

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

/* Select Book Button Enhancements with Optimized Touch Support */
#select-book-btn {
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    /* Optimize for touch devices */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    /* Ensure adequate touch target size (minimum 44px) */
    min-height: 44px;
    min-width: 44px;
    cursor: pointer;
}

#select-book-btn:active,
#select-book-btn.touch-active {
    transform: scale(0.95);
}

/* Enhanced touch feedback */
#select-book-btn.touch-active::before {
    width: 300px;
    height: 300px;
    background: rgba(255, 255, 255, 0.4);
}

#select-book-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
    pointer-events: none;
}

#select-book-btn:active::before {
    width: 300px;
    height: 300px;
}

/* Chapter Select Dropdown Improvements */
#chapter-select {
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 8px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 32px;
}

#chapter-select:focus {
    box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.1);
    border-color: #4CAF50;
}

/* Touch Feedback for All Interactive Elements */
.touch-feedback {
    transition: all 0.15s ease;
}

.touch-feedback:active {
    transform: scale(0.95);
    opacity: 0.7;
}

/* Dark Theme Support */
[data-theme="dark"] .books-modal {
    background: #1f2937;
    color: #f9fafb;
}

[data-theme="dark"] .books-modal-header {
    border-bottom-color: #374151;
}

[data-theme="dark"] .books-modal-header h2 {
    color: #f9fafb;
}

[data-theme="dark"] .books-modal-header p {
    color: #9ca3af;
}

[data-theme="dark"] .close-modal {
    color: #9ca3af;
}

[data-theme="dark"] .close-modal:hover {
    background: #374151;
    color: #f3f4f6;
}

[data-theme="dark"] .book-tile {
    background: #374151;
    border-color: #4b5563;
    color: #f9fafb;
}

[data-theme="dark"] .book-tile:hover {
    border-color: #4CAF50;
    background: #4b5563;
}

[data-theme="dark"] .book-name {
    color: #f9fafb;
}

[data-theme="dark"] .mobile-nav-controls {
    background: #374151;
}

[data-theme="dark"] .mobile-nav-current {
    color: #f9fafb;
}

/* Loading States */
#books-loading {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

[data-theme="dark"] #books-loading {
    color: #9ca3af;
}

/* Responsive Adjustments */
@media (max-width: 480px) {
    .books-modal {
        padding: 16px;
        max-width: 95vw;
        margin: 10px;
        max-height: 85vh;
    }
    
    #books-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }
    
    .book-tile {
        padding: 12px 8px;
        min-height: 50px;
        font-size: 13px;
    }
    
    .books-modal-header h2 {
        font-size: 20px;
    }
}

/* Animation for content loading */
@keyframes fadeInContent {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.content-loading {
    animation: fadeInContent 0.3s ease-out;
}

/* Success feedback */
.selection-success {
    background: #4CAF50 !important;
    color: white !important;
    transform: scale(0.95);
}

/* Error states */
.selection-error {
    background: #ef4444 !important;
    color: white !important;
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Mobile Reader Mode Styles */
.mobile-reader-mode-indicator {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-bg, #fff);
    color: var(--primary-text, #333);
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
    transition: all 0.3s ease;
    pointer-events: none;
}

.mobile-reader-mode-indicator.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.mobile-reader-mode-indicator.reader-mode {
    background: linear-gradient(135deg, #3B82F6, #2563EB);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.mobile-reader-mode-indicator.ai-mode {
    background: linear-gradient(135deg, #3B82F6, #1D4ED8);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

/* Mobile Navigation Active States */
.mobile-nav-item.active {
    background: var(--accent-color, #007AFF) !important;
    color: white !important;
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.mobile-nav-item.active .nav-icon {
    stroke: white;
    filter: drop-shadow(0 2px 4px rgba(255, 255, 255, 0.2));
}

.mobile-nav-item.active .nav-text {
    color: white;
    font-weight: 600;
}

/* Reader Mode Button Specific Styling */
#mobile-nav-reader-mode.active {
    background: linear-gradient(135deg, #8B5CF6, #A855F7) !important;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#mobile-nav-reader-mode.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: inherit;
    background: linear-gradient(135deg, #8B5CF6, #A855F7);
    z-index: -1;
    filter: blur(8px);
    opacity: 0.6;
}

/* AI Button Specific Styling */
#mobile-nav-ai.active {
    background: linear-gradient(135deg, #3B82F6, #1D4ED8) !important;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

#mobile-nav-ai.active::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border-radius: inherit;
    background: linear-gradient(135deg, #3B82F6, #1D4ED8);
    z-index: -1;
    filter: blur(8px);
    opacity: 0.6;
}

/* Mutually Exclusive Mode States */
/* When reader mode is active, AI button should be clearly inactive */
#mobile-nav-reader-mode.active ~ #mobile-nav-ai:not(.active),
body.reader-mode-active #mobile-nav-ai:not(.active) {
    opacity: 0.6;
    transform: scale(1);
    background: var(--nav-bg, rgba(255, 255, 255, 0.1)) !important;
    box-shadow: none !important;
}

#mobile-nav-reader-mode.active ~ #mobile-nav-ai:not(.active)::before,
body.reader-mode-active #mobile-nav-ai:not(.active)::before {
    display: none;
}

/* When AI mode is active, reader button should be clearly inactive ONLY if reader mode is not being activated */
#mobile-nav-ai.active ~ #mobile-nav-reader-mode:not(.active),
body.ai-mode-active #mobile-nav-reader-mode:not(.active) {
    opacity: 0.6;
    transform: scale(1);
    background: var(--nav-bg, rgba(255, 255, 255, 0.1)) !important;
    box-shadow: none !important;
}

#mobile-nav-ai.active ~ #mobile-nav-reader-mode:not(.active)::before,
body.ai-mode-active #mobile-nav-reader-mode:not(.active)::before {
    display: none;
}

/* Ensure active buttons always display properly regardless of body classes */
#mobile-nav-reader-mode.active {
    background: linear-gradient(135deg, #8B5CF6, #A855F7) !important;
    border: 2px solid rgba(255, 255, 255, 0.2) !important;
    opacity: 1 !important;
    transform: scale(1.05) !important;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3) !important;
}

#mobile-nav-ai.active {
    background: linear-gradient(135deg, #3B82F6, #1D4ED8) !important;
    border: 2px solid rgba(255, 255, 255, 0.2) !important;
    opacity: 1 !important;
    transform: scale(1.05) !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3) !important;
}

/* Dark Theme Support */
@media (prefers-color-scheme: dark) {
    .mobile-reader-mode-indicator {
        background: var(--dark-bg, #1a1a1a);
        color: var(--dark-text, #fff);
    }
}

html[data-theme="dark"] .mobile-reader-mode-indicator {
    background: var(--dark-bg, #1a1a1a);
    color: var(--dark-text, #fff);
}
