/* ==============================================================
   Bookshelf — 3D Wooden Shelf Library
   ============================================================== */

.bookshelf-section {
    background: linear-gradient(180deg, #f5f0e8 0%, #ede4d4 50%, #e5d9c6 100%);
    padding: 2rem 0 4rem;
    position: relative;
}
.bookshelf-section::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, #b8895a, #c59d5f, #b8895a);
}

/* ----------- Shelf Container ----------- */
.bookshelf {
    max-width: 1100px;
    margin: 0 auto;
}

/* ----------- Individual Shelf ----------- */
.shelf {
    margin-bottom: 4rem;   /* large gap so tooltip/hover never crowds next shelf */
}
.shelf:last-child {
    margin-bottom: 1rem;
}

/* ----------- Shelf Label ----------- */
.shelf-label {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1a365d;
    margin-bottom: 1rem;
    padding: .4rem 16px;
    display: flex;
    align-items: center;
    gap: .5rem;
    border-right: 4px solid #c59d5f;
}
.shelf-label i {
    color: #c59d5f;
    font-size: 1.1rem;
}

/* ----------- Shelf Frame (Side Supports) ----------- */
.shelf-frame {
    position: relative;
    padding: 0 14px;
}
.shelf-frame::before,
.shelf-frame::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: -20px;
    width: 14px;
    background: linear-gradient(90deg, #7d5c38 0%, #a07d52 30%, #b8895a 50%, #a07d52 70%, #7d5c38 100%);
    box-shadow: 2px 2px 8px rgba(0,0,0,.25);
    z-index: 3;
    border-radius: 2px;
}
.shelf-frame::before { left: 0; }
.shelf-frame::after  { right: 0; }

/* Raise the entire frame when any book inside is hovered
   so the tooltip appears above sibling shelves. */
.shelf-frame:has(.book:hover) {
    z-index: 50;
}

/* ----------- Books Row ----------- */
.shelf-books {
    display: flex;
    align-items: flex-end;
    gap: 0;
    padding: 12px 22px 0;
    min-height: 200px;
    position: relative;
    z-index: 1;
}
.shelf-frame:has(.book:hover) .shelf-books {
    z-index: 50;
}

/* ----------- Wooden Plank ----------- */
.shelf-plank {
    height: 22px;
    background: linear-gradient(180deg, #c9a06c 0%, #b8895a 20%, #9a7248 60%, #7d5c38 100%);
    border-radius: 0 0 4px 4px;
    box-shadow:
        0 6px 16px rgba(0,0,0,.32),
        inset 0 2px 3px rgba(255,255,255,.2);
    position: relative;
    z-index: 2;
}
.shelf-plank::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg,
        rgba(255,255,255,.05) 0%,
        rgba(255,255,255,.25) 30%,
        rgba(255,255,255,.08) 70%,
        rgba(255,255,255,.05) 100%
    );
}
.shelf-plank::after {
    content: '';
    position: absolute;
    top: 7px; left: 5%; right: 5%;
    height: 1px;
    background: rgba(255,255,255,.08);
}

/* ----------- Individual Book ----------- */
.book {
    position: relative;
    cursor: pointer;
    transition: transform .32s cubic-bezier(.34,1.56,.64,1);
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    margin: 0 2px;
    z-index: 1;
    animation: bookAppear .45s ease-out both;
}

@keyframes bookAppear {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

.book-spine {
    position: relative;
    border-radius: 4px 4px 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 14px 4px;
    overflow: hidden;
    text-align: center;
    box-shadow:
        inset -4px 0 8px rgba(0,0,0,.25),
        inset 4px 0 8px rgba(255,255,255,.08),
        3px 0 6px rgba(0,0,0,.2),
        -1px 0 3px rgba(0,0,0,.1);
    transition: box-shadow .3s;
}

/* Left edge highlight */
.book-spine::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 5px;
    background: linear-gradient(90deg, rgba(0,0,0,.2), transparent);
    z-index: 2;
}
/* Right edge highlight */
.book-spine::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 4px;
    background: linear-gradient(270deg, rgba(0,0,0,.18), transparent);
    z-index: 2;
}

/* Decorative gold lines on spine */
.book-spine-line {
    position: absolute;
    left: 15%; right: 15%;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(197,157,95,.5), transparent);
    z-index: 3;
}
.book-spine-line-top    { top: 8px; }
.book-spine-line-bottom { bottom: 8px; }

/* Book title on spine */
.book-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: #fff;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: .02em;
    text-shadow: 0 1px 3px rgba(0,0,0,.5);
    max-height: calc(100% - 32px);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    z-index: 4;
}
[dir="rtl"] .book-title { writing-mode: vertical-lr; }

/* Book type badge */
.book-type {
    font-size: .48rem;
    font-weight: 800;
    color: rgba(255,255,255,.9);
    background: rgba(0,0,0,.28);
    border-radius: 3px;
    padding: 2px 5px;
    margin-top: 6px;
    letter-spacing: .06em;
    flex-shrink: 0;
    z-index: 4;
}

/* ----------- Hover: Book Lifts ----------- */
.book:hover {
    transform: translateY(-22px) scale(1.04);
    z-index: 20;
}
.book:hover .book-spine {
    box-shadow:
        inset -4px 0 8px rgba(0,0,0,.25),
        inset 4px 0 8px rgba(255,255,255,.08),
        0 14px 32px rgba(0,0,0,.38),
        0 4px 10px rgba(0,0,0,.22);
}

/* ----------- Tooltip ----------- */
.book-tooltip {
    position: absolute;
    bottom: calc(100% + 14px);
    left: 50%;
    transform: translateX(-50%) scale(.88) translateY(6px);
    background: linear-gradient(135deg, #1a365d, #0f2440);
    color: #fff;
    padding: 12px 16px;
    border-radius: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s, transform .28s cubic-bezier(.34,1.56,.64,1);
    z-index: 100;
    box-shadow: 0 10px 28px rgba(0,0,0,.45), 0 3px 8px rgba(0,0,0,.2);
    min-width: 160px;
    max-width: 260px;
    text-align: center;
    line-height: 1.5;
    white-space: normal;
}
.book-tooltip::after {
    content: '';
    position: absolute;
    top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 8px solid transparent;
    border-top-color: #0f2440;
}
.book:hover .book-tooltip {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
    pointer-events: auto;
}

.book-tooltip-title {
    font-weight: 700;
    font-size: .88rem;
    margin-bottom: 7px;
    word-break: break-word;
}
.book-tooltip-meta {
    display: flex;
    justify-content: center;
    gap: 10px;
    font-size: .74rem;
    color: rgba(255,255,255,.72);
    margin-bottom: 7px;
    flex-wrap: wrap;
}
.book-tooltip-meta i { color: #c59d5f; margin-left: 3px; }
.book-tooltip-action {
    font-size: .7rem;
    color: #c59d5f;
    font-weight: 600;
    border-top: 1px solid rgba(255,255,255,.12);
    padding-top: 6px;
    margin-top: 2px;
}

/* ----------- Download click animation ----------- */
@keyframes bookDownload {
    0%   { transform: translateY(-22px) scale(1.04); }
    30%  { transform: translateY(-22px) scale(.93); }
    65%  { transform: translateY(-22px) scale(1.06); }
    100% { transform: translateY(-22px) scale(1.04); }
}
.book.downloading { animation: bookDownload .55s ease; }

/* ----------- Empty message ----------- */
.shelf-empty {
    color: #9a7248;
    font-style: italic;
    padding: 50px 20px;
    text-align: center;
    font-size: 1rem;
}

/* ----------- Loading ----------- */
.bookshelf-loading {
    text-align: center;
    padding: 60px 20px;
    color: #9a7248;
    font-size: 1.1rem;
}
.bookshelf-loading i {
    animation: spin 1s linear infinite;
    margin-bottom: 12px;
    display: block;
    font-size: 2rem;
    color: #c59d5f;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------- Responsive ----------- */
@media (max-width: 768px) {
    .shelf { margin-bottom: 2.5rem; }
    .shelf-label { font-size: .95rem; }
    .shelf-books {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scrollbar-width: thin;
        scrollbar-color: #b8895a transparent;
    }
    .shelf-books::-webkit-scrollbar       { height: 5px; }
    .shelf-books::-webkit-scrollbar-thumb { background: #b8895a; border-radius: 5px; }
    .shelf-books::-webkit-scrollbar-track { background: transparent; }
    .book-title   { font-size: .6rem !important; }
    .book-tooltip { min-width: 130px; }
    .shelf-frame  { padding: 0 10px; }
    .shelf-frame::before, .shelf-frame::after { width: 10px; }
    .shelf-books  { padding: 10px 16px 0; }
}

/* ----------- Print ----------- */
@media print {
    .bookshelf-section { background: #fff !important; }
    .book-tooltip { display: none !important; }
}
