/* ============================================================
   Biblioteka CRGD - bookshelf styles
   v1.2.0 - Single source of truth
   (consolidates old styles.css + book-titles.css + inline rules)
   ============================================================ */

/* ---------- Layout: shelves ---------- */

#bookshelves-container {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
}

#content-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bookshelf {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto 40px;
    padding-bottom: 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: visible;
}

.bookshelf .covers {
    position: relative;
    z-index: 2;
    width: fit-content;
    max-width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    padding: 0;
    margin: 0;
}

.bookshelf .thumb {
    position: relative;
    z-index: 1;
    width: 110px;
    flex: 0 0 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0;
    padding: 0;
    background: none;
    box-shadow: none;
}

.bookshelf .thumb:hover {
    z-index: 500;
}

.thumb.empty {
    visibility: hidden;
}

.bookshelf .shelf-img {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 1120px;
    height: auto;
    object-fit: contain;
    display: block;
    margin: -40px auto 0;
    filter: drop-shadow(0 14px 12px rgba(0, 0, 0, 0.18));
}

/* ---------- Book covers ---------- */

.book-link {
    position: relative;
    z-index: 1;
    display: block;
    text-decoration: none;
    color: inherit;
    outline: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.book-link:hover {
    z-index: 500;
}

.book-link:focus-visible {
    outline: 3px solid rgba(192, 57, 43, 0.5);
    outline-offset: 3px;
    border-radius: 8px;
}

.book-cover-container {
    width: 110px;
    height: 150px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    margin: 0 auto;
    background: #fff;
    border-radius: 6px;
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.06),
        0 2px 4px rgba(0, 0, 0, 0.08);
    position: relative;
    padding-bottom: 36px; /* room where the floating title sits */
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

/* Spine detail - makes covers read as real books */
.book-cover-container::before {
    content: '';
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 5px;
    width: 10px;
    border-radius: 3px;
    background: linear-gradient(90deg,
        rgba(0, 0, 0, 0.10) 0%,
        rgba(0, 0, 0, 0.03) 55%,
        rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.book-cover-container img {
    max-height: 128px;
    max-width: 96px;
    width: auto;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.15));
    transition: transform 0.25s ease, filter 0.25s ease;
}

.thumb a:hover .book-cover-container,
.book-cover-container:hover {
    transform: translateY(-8px);
    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.06),
        0 16px 24px rgba(0, 0, 0, 0.18),
        0 4px 10px rgba(192, 57, 43, 0.12);
}

.thumb a:hover .book-cover-container img {
    transform: scale(1.05);
    filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.25));
}

/* Skeleton shimmer while the cover loads */
.book-cover-container.loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e4e4e4 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---------- Floating title chips ---------- */

.book-title {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 10px);
    box-sizing: border-box;
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.4;
    font-weight: 500;
    letter-spacing: -0.2px;
    color: #333;
    text-align: center;
    word-break: break-word;
    background: #fff;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.04);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    z-index: 5;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    max-height: calc(2.8em + 12px);
    transition: all 0.3s ease-out;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: auto;
    cursor: pointer;
}

.book-link:hover .book-title,
.book-link:focus-visible .book-title,
.folder-link:focus-visible .book-title,
.thumb:hover .book-title,
.book-title:hover {
    -webkit-line-clamp: 5;
    max-height: calc(7em + 12px);
    min-width: 120%;
    transform: translate(-50%, -10px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.20);
    border-color: rgba(192, 57, 43, 0.15);
    z-index: 600;
    background-color: #fff;
}

/* ---------- Category folders ---------- */

.folder-link {
    position: relative;
    display: block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.folder-img {
    width: 100px;
    max-height: 120px;
    object-fit: contain;
    display: block;
    margin: 0 auto 42px;
    filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.18));
    transition: transform 0.3s ease, filter 0.3s ease;
}

.folder-link:hover .folder-img {
    transform: translateY(-6px) scale(1.04);
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, 0.22)) brightness(1.03);
}

/* ---------- Staggered entrance animation ---------- */
/* items get --animation-order set from js/books.js */

@media (prefers-reduced-motion: no-preference) {
    .thumb {
        opacity: 0;
        animation: shelf-in 0.5s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
        animation-delay: calc(var(--animation-order, 0) * 55ms);
    }

    @keyframes shelf-in {
        from { opacity: 0; transform: translateY(14px); }
        to   { opacity: 1; transform: translateY(0); }
    }
}

/* ---------- Touch devices ---------- */

@media (hover: none) {
    .folder-link:hover .folder-img,
    .thumb a:hover .book-cover-container,
    .book-cover-container:hover {
        transform: none;
    }

    .thumb a:hover .book-cover-container img {
        transform: none;
    }

    .folder-link:active .folder-img,
    .book-link:active .book-cover-container {
        transform: translateY(-3px);
        transition: transform 0.15s ease;
    }
}

/* ---------- Responsive: tablets ---------- */

@media (max-width: 840px) {
    .container {
        padding-left: 15px;
        padding-right: 15px;
    }

    .bookshelf .covers {
        gap: 12px;
    }

    .bookshelf .thumb {
        width: 95px;
        flex-basis: 95px;
    }

    .book-cover-container {
        width: 95px;
        height: 132px;
        padding-bottom: 32px;
    }

    .book-cover-container img {
        max-width: 82px;
        max-height: 112px;
    }

    .folder-img {
        width: 84px;
        max-height: 104px;
        margin-bottom: 38px;
    }

    .bookshelf .shelf-img {
        margin-top: -30px;
    }
}

/* ---------- Responsive: phones ---------- */

@media (max-width: 576px) {
    .container {
        padding-left: 10px;
        padding-right: 10px;
    }

    .bookshelf {
        margin-bottom: 24px;
    }

    .bookshelf .covers {
        gap: 8px;
        padding: 0 4px;
    }

    .bookshelf .thumb {
        width: 80px;
        flex-basis: 80px;
    }

    .book-cover-container {
        width: 80px;
        height: 112px;
        padding-bottom: 30px;
    }

    .book-cover-container img {
        max-width: 68px;
        max-height: 92px;
    }

    .book-title {
        font-size: 10px;
        line-height: 1.35;
        letter-spacing: -0.1px;
        padding: 5px 6px;
        bottom: 8px;
    }

    .book-link:hover .book-title,
    .thumb:hover .book-title,
    .book-title:hover {
        transform: translate(-50%, -8px);
        min-width: 110%;
    }

    .folder-img {
        width: 70px;
        max-height: 90px;
        margin-bottom: 34px;
    }

    .bookshelf .shelf-img {
        margin-top: -20px;
        min-width: 300px;
    }
}

/* ---------- Helpers ---------- */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
