/* ===========================
   Library Page Specific Styles
   =========================== */

/* Library Header */
.library-header {
    background: var(--surface-primary);
    padding: calc(72px + 3rem) 0 2rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

.library-title {
    font-size: 3rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-family: var(--font-display);
}

.library-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

/* Enhanced Search */
.search-container {
    max-width: 600px;
    position: relative;
}

/* Center search in header context */
.library-header .search-container {
    margin: 0 auto;
}

/* Left-align search in main library context */
.library-search-section .search-container {
    margin: 0;
}

.search-box-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 1.5rem;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 1rem 3rem 1rem 3.5rem;
    font-size: 1.125rem;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-primary);
    transition: all 0.3s ease;
    /* Touch-friendly input */
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-clear {
    position: absolute;
    right: 1rem;
    background: none;
    border: none;
    padding: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    /* Touch-friendly button */
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.search-input:not(:placeholder-shown) ~ .search-clear {
    opacity: 1;
}

.search-clear:hover {
    color: var(--text-primary);
}

/* Search Suggestions */
.search-suggestions {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    z-index: 10;
}

.search-suggestions.active {
    display: block;
}

.suggestion-item {
    padding: 1rem 1.5rem;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.suggestion-item:hover {
    background: var(--surface-secondary);
}

.suggestion-title {
    font-weight: 500;
    color: var(--text-primary);
}

.suggestion-author {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Filter Tabs */
.filter-tabs {
    background: var(--bg-primary);
    padding: 2rem 0;
    border-bottom: 1px solid var(--border-color);
}

/* Remove default styling when inside library header section */
.library-header-section .filter-tabs {
    background: transparent;
    padding: 0;
    border: none;
}

.tabs-wrapper {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.tabs-wrapper::-webkit-scrollbar {
    height: 6px;
}

.tabs-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.tabs-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.tab-btn:hover {
    background: var(--surface-secondary);
    transform: translateY(-2px);
}

.tab-btn.active {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

.tab-icon {
    font-size: 1.25rem;
}

.results-count {
    margin-top: 1rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Featured Carousel */
.featured-section {
    padding: 3rem 0;
    background: var(--surface-primary);
    position: relative;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.section-header h2 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.carousel-controls {
    display: flex;
    gap: 0.5rem;
}

.carousel-btn {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.carousel-btn:hover {
    background: var(--surface-secondary);
    transform: translateY(-2px);
}

.carousel-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Carousel Container */
.carousel-container {
    position: relative;
    overflow: hidden;
    /* Allow vertical scrolling while enabling horizontal swipes */
    touch-action: pan-y pinch-zoom;
    -webkit-overflow-scrolling: touch;
}

.carousel-track {
    display: flex;
    gap: 1.5rem;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    /* Enable touch interactions */
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.carousel-card {
    flex: 0 0 350px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    /* Improve touch interactions */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.carousel-card:hover {
    transform: translateY(-4px) translateZ(0);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.15);
    border-color: var(--accent-primary);
    will-change: transform;
}

.carousel-image-wrapper {
    width: 100%;
    height: 200px;
    overflow: hidden;
    position: relative;
}

.carousel-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Fallback for direct img elements in carousel */
.carousel-card > img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.carousel-card-content {
    padding: 1.5rem;
}

.carousel-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.carousel-card .author {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.carousel-card .description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.carousel-indicators {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-color);
    cursor: pointer;
    transition: all 0.3s ease;
}

.indicator.active {
    width: 24px;
    border-radius: 4px;
    background: var(--accent-primary);
}

/* Scroll Indicator */
.scroll-indicator {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    animation: bounce 2s infinite;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.scroll-indicator:hover {
    opacity: 1;
}

.scroll-indicator svg {
    color: var(--text-secondary);
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateX(-50%) translateY(0);
    }
    40% {
        transform: translateX(-50%) translateY(-10px);
    }
    60% {
        transform: translateX(-50%) translateY(-5px);
    }
}

/* Library Layout */
.library-main {
    padding: 3rem 0;
    background: var(--bg-primary);
}

/* Library Header Section (Search + Filters) */
.library-header-section {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
    border-top: 1px solid var(--border-color);
}

.library-header-section .search-container {
    margin: 0 auto 2rem;
    max-width: 600px;
}

.library-header-section .tabs-wrapper {
    justify-content: center;
    flex-wrap: wrap;
}

.library-layout {
    display: grid;
    grid-template-columns: 250px 1fr;
    gap: 2rem;
}

/* Sidebar */
.library-sidebar {
    position: sticky;
    top: 100px;
    height: fit-content;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

/* Library Content Area */
.library-content {
    min-width: 0; /* Prevent grid blowout */
    width: 100%; /* Ensure full width in grid column */
}

.sidebar-section {
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.sidebar-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.sort-select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.filter-checkbox input {
    margin-right: 0.75rem;
    width: 16px;
    height: 16px;
    accent-color: var(--accent-primary);
}

.checkbox-label {
    user-select: none;
}

.clear-filters {
    width: 100%;
    padding: 0.75rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.clear-filters:hover {
    background: var(--surface-secondary);
    color: var(--text-primary);
}

/* ===========================
   SIDEBAR COLLAPSE FEATURE
   =========================== */

/* Collapse toggle button */
.sidebar-collapse-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-collapse-toggle:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.sidebar-collapse-toggle .collapse-icon {
    transition: transform 0.3s ease;
}

/* Collapsed sidebar state - only on desktop (above 1024px) */
@media (min-width: 1025px) {
    /* Sidebar transitions for smooth collapse */
    .library-sidebar {
        transition: width 0.3s ease;
    }

    .library-layout {
        transition: grid-template-columns 0.3s ease;
    }

    .library-sidebar.collapsed {
        width: 60px;
    }

    .library-layout.sidebar-collapsed {
        grid-template-columns: 60px 1fr;
    }

    /* Hide content when collapsed, show only toggle button */
    .library-sidebar.collapsed .sidebar-section,
    .library-sidebar.collapsed .clear-filters {
        opacity: 0;
        pointer-events: none;
        max-height: 0;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }

    .library-sidebar.collapsed .sidebar-collapse-toggle {
        padding: 0.75rem 0.5rem;
        margin-bottom: 0;
        flex-direction: column;
        justify-content: flex-start;
        padding-top: 1rem;
    }

    /* Rotate icon when collapsed */
    .library-sidebar.collapsed .collapse-icon {
        transform: rotate(180deg);
    }

    /* Hide text when collapsed */
    .library-sidebar.collapsed .collapse-text {
        display: none;
    }
}

/* Library Grid */
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.library-card {
    background: var(--surface-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.library-card:hover {
    transform: translateY(-4px) translateZ(0);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.15);
    border-color: var(--accent-primary);
    will-change: transform;
}

.library-card-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
}

.library-card-content {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.library-card-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.library-card-author {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.library-card-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    flex: 1;
    /* Ensure consistent height with ellipsis for overflow */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.library-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.reading-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.card-badge {
    padding: 0.25rem 0.75rem;
    background: var(--accent-gradient);
    color: white;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* Load More */
.load-more-container {
    text-align: center;
    margin-top: 3rem;
}

.load-more-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 2rem;
    background: var(--surface-primary);
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    color: var(--accent-primary);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.load-more-btn:hover {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-2px);
}

/* Browse Categories */
.browse-categories {
    padding: 4rem 0;
    background: var(--surface-primary);
}

.browse-categories h2 {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 3rem;
    color: var(--text-primary);
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
}

.category-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s ease;
}

.category-card:hover {
    transform: translateY(-4px) translateZ(0);
    box-shadow: 0 12px 32px rgba(99, 102, 241, 0.15);
    border-color: var(--accent-primary);
    will-change: transform;
}

.category-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.category-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.category-card p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Loading animations */
.fade-in {
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Skeleton Loading States */
.skeleton-carousel {
    display: flex;
    gap: 1.5rem;
}

.carousel-card.skeleton {
    background: var(--surface-secondary);
    height: 350px;
}

.skeleton-image {
    height: 200px;
    background: linear-gradient(90deg, var(--surface-secondary) 0%, var(--surface-primary) 50%, var(--surface-secondary) 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-title,
.skeleton-author,
.skeleton-description {
    height: 1rem;
    background: linear-gradient(90deg, var(--surface-secondary) 0%, var(--surface-primary) 50%, var(--surface-secondary) 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 0.75rem;
}

.skeleton-title {
    width: 70%;
}

.skeleton-author {
    width: 50%;
}

.skeleton-description {
    width: 100%;
    height: 3rem;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Prevent text flickering */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Image wrappers to prevent layout shift */
.library-card-image-wrapper {
    position: relative;
    background: var(--surface-secondary);
    overflow: hidden;
    height: 180px;
    aspect-ratio: 16/10;
}

/* Stabilize layout shifts and prevent image flicker */
.library-card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}

/* Skeleton loader for images */
.library-card-image:not([src]),
.carousel-image:not([src]) {
    background: linear-gradient(90deg, var(--surface-secondary) 0%, var(--surface-primary) 50%, var(--surface-secondary) 100%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

/* Prevent layout shift during load */
.library-grid,
.carousel-track {
    min-height: 200px;
}

/* Smooth font rendering */
body {
    text-rendering: optimizeLegibility;
}

/* Prevent hover state flicker */
.library-card,
.carousel-card,
.category-card {
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .library-layout {
        grid-template-columns: 1fr;
    }

    /* Completely hide sidebar on tablet and mobile */
    .library-sidebar {
        display: none !important;
    }

    /* Hide mobile filter toggle button - no sidebar to open */
    .mobile-filter-toggle {
        display: none !important;
    }

    .carousel-card {
        flex: 0 0 300px;
    }
}

@media (max-width: 768px) {
    /* ===========================
       MOBILE-FRIENDLY LIBRARY
       =========================== */

    /* Header - Reduce padding for mobile */
    .library-header {
        padding: calc(60px + 1.5rem) 0 1.5rem;
    }

    .library-title {
        font-size: 2rem;
        margin-bottom: 0.5rem;
    }

    .library-subtitle {
        font-size: 1rem;
        padding: 0 1rem;
    }

    /* Search - More mobile-friendly sizing */
    .search-input {
        font-size: 1rem;
        padding: 0.875rem 2.5rem 0.875rem 3rem;
    }

    .search-icon {
        left: 1rem;
    }

    .search-clear {
        right: 0.75rem;
    }

    /* Filter Tabs - Horizontal scroll */
    .filter-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .tabs-wrapper {
        display: flex;
        justify-content: flex-start;
        gap: 0.75rem;
        min-width: min-content;
        padding-bottom: 0.5rem;
    }

    .tab-btn {
        flex-shrink: 0;
        white-space: nowrap;
        min-width: fit-content;
        padding: 0.75rem 1.25rem;
        font-size: 0.9375rem;
    }

    .tab-icon {
        font-size: 1.125rem;
    }

    .results-count {
        padding: 0.75rem 0;
        font-size: 0.875rem;
    }

    /* Carousel - Better mobile touch experience */
    .carousel-card {
        flex: 0 0 280px;
        scroll-snap-align: start;
        /* Improve touch targets */
        min-height: 44px;
    }

    .carousel-card:active {
        /* Visual feedback on touch */
        opacity: 0.9;
        transform: scale(0.98);
    }

    .carousel-track {
        scroll-snap-type: x mandatory;
        scroll-padding: 1rem;
        /* Add padding for better edge visibility */
        padding: 0 1rem;
        gap: 1rem;
    }

    .carousel-container {
        /* Better touch scrolling on mobile */
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
    }

    .carousel-controls {
        display: none; /* Hide arrows on mobile, use swipe */
    }

    .carousel-indicators {
        margin-top: 1rem;
        /* Make indicators more touch-friendly */
        padding: 0.5rem;
    }

    .indicator {
        width: 12px;
        height: 12px;
        /* Larger touch targets for indicators */
        cursor: pointer;
    }

    /* Library Grid - Optimized card size */
    .library-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }

    /* Cards - Better mobile sizing */
    .library-card {
        min-height: auto;
        /* Improve touch interactions */
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    .library-card:active {
        /* Visual feedback on touch */
        transform: scale(0.98);
        opacity: 0.95;
    }

    .library-card-cover {
        height: 200px;
    }

    .library-card-content {
        padding: 1rem;
    }

    .library-card-title {
        font-size: 1.125rem;
    }

    .library-card-author {
        font-size: 0.875rem;
    }

    .library-card-description {
        -webkit-line-clamp: 2;
        font-size: 0.875rem;
        margin: 0.5rem 0;
    }

    .library-card-meta {
        font-size: 0.8125rem;
        gap: 0.75rem;
    }

    .library-card-cta {
        padding: 0.75rem 1.5rem;
        font-size: 0.9375rem;
    }

    /* Category Grid */
    .category-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    .category-card {
        padding: 1.25rem;
    }

    .category-icon {
        font-size: 2rem;
    }

    .category-name {
        font-size: 0.9375rem;
    }

    /* Featured Section - Mobile spacing */
    .featured-section {
        padding: 2rem 0;
    }

    .section-header {
        padding: 0 1rem 1rem;
    }

    .section-header h2 {
        font-size: 1.5rem;
    }

    /* Library Header Section */
    .library-header-section {
        gap: 1rem;
    }

    /* Load More Button */
    .load-more-btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
    }

    /* Modal - Mobile optimized */
    .modal-content {
        width: 95%;
        max-width: 95vw;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-description {
        max-height: 200px;
        font-size: 0.875rem;
    }

    .modal-narrative {
        grid-template-columns: 1fr;
        padding: 1.5rem 1rem;
    }

    .modal-narrative-enhanced .modal-header-section {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .modal-cover {
        max-width: 200px;
        margin: 0 auto 1rem;
    }

    .modal-narrative-enhanced .modal-description {
        max-height: 250px;
    }

    .modal-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .modal-stat {
        padding: 0.75rem;
    }

    .modal-actions {
        gap: 0.75rem;
        flex-direction: column;
    }

    .modal-btn {
        width: 100%;
        justify-content: center;
    }

    /* Touch-friendly tap targets */
    .tab-btn,
    .carousel-btn,
    .filter-checkbox,
    .library-card-cta,
    .modal-btn {
        min-height: 44px; /* iOS minimum tap target */
    }

    /* Scrollbar hiding for mobile */
    .tabs-wrapper::-webkit-scrollbar {
        display: none;
    }

    .tabs-wrapper {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.active {
    visibility: visible;
    opacity: 1;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Custom scrollbar for modal */
.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: var(--surface-secondary);
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.modal.active .modal-content {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
}

.modal-close:hover {
    background: var(--surface-primary);
    color: var(--text-primary);
    transform: scale(1.1);
}

.modal-body {
    padding: 2rem;
}

.modal-narrative {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
    align-items: start;
}

/* Enhanced modal layout with full-width description */
.modal-narrative-enhanced {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.modal-header-section {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 2rem;
    align-items: start;
}

.modal-cover {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-cover img {
    width: 100%;
    height: auto;
    display: block;
}

.modal-header-info h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-family: var(--font-display);
}

.modal-info h2 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    font-family: var(--font-display);
}

.modal-author {
    font-size: 1.125rem;
    color: var(--accent-primary);
    margin-bottom: 1.5rem;
}

.modal-meta {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.meta-item svg {
    color: var(--accent-primary);
}

.modal-description-content {
    margin-bottom: 2rem;
}

/* Full-width description section */
.modal-description-section {
    width: 100%;
}

.modal-description-section .modal-description-content {
    margin-bottom: 1rem;
}

.modal-description {
    color: var(--text-secondary);
    line-height: 1.8;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 1rem;
}

/* Enhanced modal description with more height */
.modal-narrative-enhanced .modal-description {
    max-height: 400px;
    font-size: 1rem;
    line-height: 1.9;
}

/* Paragraph formatting for modal description */
.modal-description-paragraph {
    margin: 0 0 1rem 0;
    color: var(--text-secondary);
    line-height: 1.8;
}

.modal-description-paragraph:last-child {
    margin-bottom: 0;
}

/* Ensure proper spacing in the scrollable container */
.modal-narrative-enhanced .modal-description {
    padding-bottom: 0.5rem;
}

.modal-description::-webkit-scrollbar {
    width: 6px;
}

.modal-description::-webkit-scrollbar-track {
    background: var(--surface-secondary);
    border-radius: 3px;
}

.modal-description::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.modal-actions {
    display: flex;
    gap: 1rem;
}

/* Enhanced modal actions for new layout */
.modal-narrative-enhanced .modal-actions {
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    justify-content: center;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Touch-friendly interactions */
    min-height: 44px;
    min-width: 44px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--surface-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--surface-primary);
    border-color: var(--accent-primary);
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal-narrative {
        grid-template-columns: 1fr;
    }
    
    .modal-narrative-enhanced .modal-header-section {
        grid-template-columns: 1fr;
        text-align: center;
    }
    
    .modal-cover {
        max-width: 240px;
        margin: 0 auto;
    }
    
    .modal-info h2,
    .modal-header-info h2 {
        font-size: 1.5rem;
    }
    
    .modal-narrative-enhanced .modal-description {
        max-height: 250px;
        font-size: 0.9375rem;
    }
    
    .modal-description-paragraph {
        margin-bottom: 0.75rem;
        font-size: 0.9375rem;
        line-height: 1.7;
    }
    
    .modal-narrative-enhanced .modal-actions {
        flex-direction: column;
    }
    
    .modal-narrative-enhanced .modal-actions .btn {
        width: 100%;
        text-align: center;
    }
}

/* Theme Adjustments */
[data-theme="dark"] .search-input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .carousel-card,
[data-theme="dark"] .library-card,
[data-theme="dark"] .sidebar-section,
[data-theme="dark"] .category-card {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .library-header,
[data-theme="dark"] .featured-section,
[data-theme="dark"] .browse-categories {
    background: rgba(255, 255, 255, 0.02);
}

[data-theme="light"] .library-card,
[data-theme="light"] .sidebar-section,
[data-theme="light"] .category-card {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .search-input {
    background: white;
}

[data-theme="light"] .featured-section {
    background: #f8f9fa;
}

/* Modal theme styles */
[data-theme="dark"] .modal-content {
    background: var(--bg-primary);
    border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="light"] .modal-content {
    background: white;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

/* Accessibility */
.library-card:focus,
.carousel-card:focus,
.category-card:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .carousel-track {
        transition: none;
    }
    
    .library-card:hover,
    .carousel-card:hover,
    .category-card:hover {
        transform: none;
    }
}