/* ===================================
   LIBRARY SIDEBAR HEADER
   =================================== */
.library-sidebar {
    position: fixed;
    top: 0;
    right: -350px;
    /* Start hidden */
    width: 350px;
    height: 100vh;
    background: #fdfaf5;
    /* Paper/Parchment color or matching site theme */
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    transition: right 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--color-divine-gold);
}

.library-sidebar.open {
    right: 0;
}

.sidebar-header {
    padding: 1.5rem;
    background: var(--color-sacred-purple);
    color: var(--color-divine-gold);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--color-divine-gold);
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-family: 'Cinzel', serif;
}

.close-sidebar-btn {
    background: none;
    border: none;
    color: var(--color-divine-gold);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.close-sidebar-btn:hover {
    color: #fff;
}

/* ===================================
   LIBRARY LIST VIEW (Compact + Preview)
   =================================== */

.books-list-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    /* Remove max-width restriction for sidebar */
    margin: 0;
    padding: 1rem 0;
    overflow-y: auto;
    /* Allow scrolling */
    flex: 1;
}

/* The Row Item */
.book-list-item {
    position: relative;
    padding: 0.8rem 1.5rem;
    border-bottom: 1px solid rgba(45, 27, 78, 0.1);
    cursor: pointer;
    transition: all 0.2s;
}

.book-list-item:hover {
    background-color: rgba(212, 175, 55, 0.15);
    padding-left: 1.8rem;
    /* Slight slide effect */
}

/* Minimalist Content */
.book-item-content {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
}

.book-item-icon {
    font-size: 0.9rem;
    color: var(--color-stone-gray);
}

.book-list-title {
    font-family: var(--font-body);
    font-weight: 600;
    color: var(--color-sacred-purple);
    text-decoration: none;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.book-list-author {
    display: none;
    /* Hide author in compact list to save space */
}

/* ===================================
   THE FLOATING PREVIEW CARD
   =================================== */
.book-hover-card {
    position: fixed;
    top: 50%;
    right: 360px;
    /* Position to the left of the sidebar (350px + 10px margin) */
    transform: translate(20px, -50%);
    /* Initial position offset for simple slide animation */
    width: 300px;
    background: #fff;
    border: 1px solid var(--color-divine-gold);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 2001;
    /* Above sidebar content but below overlays if any */
    border-radius: var(--radius-md);
    overflow: hidden;
    pointer-events: auto;

    /* Smooth fade in/out with delay for tolerance */
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s linear 0.3s, opacity 0.3s ease, transform 0.3s ease;
}

/* Invisible bridge between sidebar item and floating card so mouse can travel without losing hover */
.book-hover-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: -30px;
    /* Bridge the gap between the card and the sidebar only horizontally */
    width: 30px;
    height: 100%;
    z-index: -1;
}

.book-list-item.active .book-hover-card,
.book-list-item:hover .book-hover-card,
.book-hover-card:hover {
    visibility: visible;
    opacity: 1;
    transform: translate(0, -50%);
    transition-delay: 0s;
    /* Instantiate immediately when hovered */
}

/* Close button for mobile card (hidden on desktop) */
.mobile-close-btn {
    display: none;
}

/* Card Internals */
.book-hover-card .book-cover {
    width: 100%;
    height: 180px;
    background: #f4f4f4;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.book-hover-card .book-cover::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent);
}

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

.book-hover-card .book-info {
    padding: 1.2rem;
    background: #fff;
    text-align: left;
}

.book-hover-card .book-title {
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
    color: var(--color-sacred-purple);
    font-family: 'Cinzel', serif;
    font-weight: 700;
    line-height: 1.3;
}

.book-hover-card .book-author {
    font-size: 0.85rem;
    color: var(--color-divine-gold-dark);
    margin-bottom: 0.8rem;
    font-style: normal;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: block !important;
    /* Force show inside card */
}

.book-hover-card.expanded {
    width: 450px;
    /* Wider to accommodate text */
}

.book-hover-card .book-description {
    font-size: 0.85rem;
    color: #555;
    margin-bottom: 1rem;
    line-height: 1.5;
    transition: all 0.3s ease;
}

.book-hover-card.expanded .book-description {
    display: block;
    overflow-y: auto;
    max-height: 250px;
    /* Prevent it from growing taller than the screen */
}

.read-more-trigger:hover,
.read-less-trigger:hover {
    text-decoration: underline;
}

.book-hover-card .book-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.read-book-btn,
.download-book-btn {
    width: 100%;
    padding: 0.6rem;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    font-family: var(--font-body);
    font-weight: 600;
}

.read-book-btn {
    background: var(--color-sacred-purple);
    color: #fff;
}

.read-book-btn:hover {
    background: var(--color-onyx-black);
}

.download-book-btn {
    background: transparent;
    color: var(--color-sacred-purple);
    border: 1px solid var(--color-sacred-purple);
}

.download-book-btn:hover {
    background: rgba(45, 27, 78, 0.05);
}

/* ===================================
   RESPONSIVE
   =================================== */

@media (max-width: 1024px) {
    .library-sidebar {
        width: 300px;
    }

    .book-hover-card {
        right: 310px;
        width: 260px;
    }
}

@media (max-width: 768px) {
    .library-sidebar {
        width: 85%;
        /* Mostly full screen on mobile */
        max-width: 320px;
        right: -100%;
        box-shadow: -5px 0 20px rgba(0, 0, 0, 0.5);
    }

    .library-sidebar.open {
        right: 0;
    }

    /* Mobile: Card acts as a centered modal upon click */
    .book-hover-card {
        display: none;
        position: fixed;
        top: 50%;
        left: 50%;
        right: auto;
        transform: translate(-50%, -50%);
        width: 90%;
        max-width: 350px;
        z-index: 2200;
        /* Above everything */
        box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
        border: 2px solid var(--color-divine-gold);
        animation: fadeInMobile 0.3s ease forwards;
        transition: max-width 0.3s ease, width 0.3s ease;
    }

    .book-hover-card.expanded {
        max-width: 450px;
        width: 95%;
    }

    .mobile-close-btn {
        display: flex;
        position: absolute;
        top: 10px;
        right: 10px;
        background: rgba(0, 0, 0, 0.6);
        color: white;
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        z-index: 10;
        cursor: pointer;
    }

    @keyframes fadeInMobile {
        from {
            opacity: 0;
            transform: translate(-50%, -40%);
        }

        to {
            opacity: 1;
            transform: translate(-50%, -50%);
        }
    }

    .book-list-item.active .book-hover-card {
        display: block !important;
    }
}