:root { --grad-delta: 10%; } /* lower = flatter */

/* Container and Layout */
.bookshelf-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding-top: 2rem;
    padding-bottom: 2rem;
}

/* Header with View Switcher */
.bookshelf-header {
    display: flex;
    justify-content: center;
    margin-bottom: 30px;
}

.view-switcher {
    display: inline-flex;
    background: #f5f5f5;
    border-radius: 25px;
    padding: 4px;
    gap: 8px;
}

.view-btn {
    padding: 8px 20px;
    border: none;
    background: transparent;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.view-btn.active {
    background: #2563EB;
    color: white;
}

.view-btn:hover:not(.active) {
    background: #e0e0e0;
}

/* Controls Section */
.bookshelf-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    margin-bottom: 2rem;
    gap: 20px;
}

.search-container {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 12px 15px 12px 45px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.3s;
    background: white;
}

.search-input:focus {
    border-color: #2563EB;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.list-selector {
    display: flex;
    align-items: center;
}

.list-dropdown {
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    outline: none;
    min-width: 120px;
}

/* Alphabet Navigation */
.alphabet-nav {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.letter-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #999;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.letter-btn:hover {
    background: #f0f0f0;
    color: #2563EB;
}

.letter-btn.active {
    background: #2563EB;
    color: white;
}

.letter-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Books Grid */
.books-grid-wrapper {
    max-height: calc(var(--max-rows, 3) * 280px);
    overflow-y: auto;
    padding-right: 10px;
}

.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 30px 25px;
}

/* 3D Book Effect */
.book-item {
    cursor: pointer;
    transition: transform 0.3s ease;
}

.book-item:hover {
    transform: translateY(-5px);
}

.book-item.hidden {
    display: none !important;
}

.book-cover-3d {
    position: relative;
    width: 100%;
    height: 240px;
}

/* Book spine - CORRECTED STYLE */
.book-spine {
    position: absolute;
    left: 0;
    top: 0;
    width: 14px; /* Default spine width */
    height: 100%;
    background: #7e7e7e; /* Dark base color for spine */
    border-radius: 4px 0 0 4px;
    box-shadow:
        inset 1px 0 2px rgba(255, 255, 255, 0.4), /* Highlight on the left edge */
        inset -1px 0 2px rgba(0, 0, 0, 0.8), /* Shadow on the right edge */
        -2px 0 4px rgba(0, 0, 0, 0.25); /* External shadow */
    z-index: 1;
}

/* HIDE SPINE for full-cover books */
.book-item.full-cover-book .book-spine {
    display: none;
}

/* Book spine for full cover books - removed from original (was .book-spine-full) */
.book-spine-full {
    display: none;
}

/* Book Cover for non-full cover books */
.book-cover:not(.has-full-cover) {
    position: absolute; /* Use absolute positioning for placement */
    left: 14px; /* Starts after the 14px spine */
    top: 0;
    width: calc(100% - 14px); /* Width adjusted to fill the remaining space */
    height: 100%;
    border-radius: 0 6px 6px 0;
    overflow: hidden;
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.12),
        0 1px 2px rgba(0, 0, 0, 0.24);
    background: transparent;
    z-index: 2; /* Ensures cover is on top of the spine */
}

/* Book Cover for full cover books - CORRECTED LAYOUT */
.book-cover.has-full-cover {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 100%; /* Takes up the whole 3D container */
    border-radius: 6px;
    overflow: hidden;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.15),
        0 4px 16px rgba(0, 0, 0, 0.1);
    background: transparent;
    z-index: 3;
}

/* Cover Content (used for non-full cover books with text/logo) */
.book-cover-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 15px;
    box-sizing: border-box;
}

/* Full cover image */
.cover-image-full {
    height: 100%;
    width: 100%;
    object-fit: cover;
    display: block;
}

.book-cover-image-container {
    position: absolute;
    width: 70%;
    height: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cover-image-logo {
    object-fit: contain;
    display: block;
}

/* Text on Book Cover - Title at top */
.book-cover-title-top {
    color: var(--text-color, white);
    font-size: 16px;
    font-weight: 400;
    line-height: 1.3;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    word-wrap: break-word;
    text-align: center;
    margin-bottom: auto;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    z-index: 2;
    position: relative;
}

/* Authors at bottom */
.book-cover-authors-bottom {
    color: var(--text-color, white);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.2;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.4);
    text-align: center;
    margin-top: auto;
    word-wrap: break-word;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    z-index: 2;
    position: relative;
}


/* Coming Soon Ribbon */
.book-ribbon {
    position: absolute;
    top: 24px;
    right: -28px;
    background: #ff4757;
    color: white;
    padding: 3px 20px;
    font-size: 10px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transform: rotate(45deg);
    z-index: 15;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
    white-space: nowrap;
    transform-origin: center center;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.book-item:hover .book-ribbon {
    opacity: 0;
}


/* Ribbon color variants */
.book-ribbon.ribbon-blue {
    background: #0984e3;
}

.book-ribbon.ribbon-green {
    background: #00b894;
}

.book-ribbon.ribbon-orange {
    background: #fdcb6e;
    color: #2d3436;
}

.book-ribbon.ribbon-purple {
    background: #a29bfe;
}

/* Ensure ribbon is clipped to book boundaries */
.book-item {
    overflow: hidden;
    position: relative;
}

.book-cover-3d {
    overflow: hidden;
    position: relative;
}

/* Responsive ribbon sizing */
@media (max-width: 768px) {
    .book-ribbon {
        font-size: 9px;
        padding: 3px 18px;
        top: 10px;
        right: -6px;
    }
}

@media (max-width: 480px) {
    .book-ribbon {
        font-size: 8px;
        padding: 2px 15px;
        top: 8px;
        right: -5px;
    }
}

/* No Results Message */
.no-results {
    text-align: center;
    padding: 60px 20px;
    color: #666;
    grid-column: 1 / -1;
}

.no-results h3 {
    font-size: 24px;
    margin-bottom: 10px;
}

/* Scrollbar Styling */
.books-grid-wrapper::-webkit-scrollbar {
    width: 8px;
}

.books-grid-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.books-grid-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.books-grid-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Firefox Scrollbar */
.books-grid-wrapper {
    scrollbar-width: thin;
    scrollbar-color: #888 #f1f1f1;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

@media (max-width: 768px) {
    .bookshelf-title {
        font-size: 32px;
    }

    .bookshelf-subtitle {
        font-size: 16px;
    }

    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 20px 15px;
    }

    .book-cover-3d {
        height: 200px;
    }

    .book-spine {
        width: 12px;
    }

    .book-cover:not(.has-full-cover) {
        left: 12px; /* Adjusted left position */
        width: calc(100% - 12px); /* Adjusted width */
    }

    .book-cover-title-top {
        font-size: 12px;
    }

    .book-cover-authors-bottom {
        font-size: 10px;
    }

    .alphabet-nav {
        gap: 4px;
    }

    .letter-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .bookshelf-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .search-container {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    .bookshelf-title {
        font-size: 28px;
    }

    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 15px 10px;
    }

    .book-cover-3d {
        height: 160px;
    }

    .book-cover-title-top {
        font-size: 11px;
        -webkit-line-clamp: 2;
    }

    .book-cover-authors-bottom {
        font-size: 9px;
    }

    .book-cover-content {
        padding: 10px;
    }

    .view-switcher {
        flex-wrap: wrap;
        justify-content: center;
    }

    .view-btn {
        font-size: 12px;
        padding: 6px 12px;
    }

    .letter-btn {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }

    .book-spine {
        width: 10px;
    }

    .book-cover:not(.has-full-cover) {
        left: 10px; /* Adjusted left position */
        width: calc(100% - 10px); /* Adjusted width */
    }
}

/* === Minimal override patch (safe to paste at END of CSS) ================ */
/* 1) Base cover box: absolute & full-size in the 3D wrapper */
.book-cover {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  overflow: hidden;
  z-index: 2;
}

/* 2) Full-cover books: no spine, no offset, never cropped */
.book-item.full-cover-book .book-spine { display: none !important; }
.book-cover.has-full-cover { left: 0; width: 100%; border-radius: 6px; }

/* 3) Non-full-cover books: start cover after spine */
.book-cover-3d { --spine-w: 14px; }
.book-cover:not(.has-full-cover) {
  left: var(--spine-w);
  width: calc(100% - var(--spine-w));
  border-radius: 0 6px 6px 0;
}

/* 4) Spine visuals: remove bright hairline that looked like a border */
.book-spine {
  position: absolute;
  left: 0; top: 0;
  width: var(--spine-w); height: 100%;
  border-radius: 6px 0 0 6px;
  background: linear-gradient(to right,
    rgba(0,0,0,0.70) 0px,
    rgba(0,0,0,0.55) 6px,
    rgba(0,0,0,0.35) 10px,
    rgba(0,0,0,0.00) 100%
  );
  box-shadow: -2px 0 4px rgba(0,0,0,0.25);
  z-index: 1;
}

/* 5) Small screens: keep offsets in sync */
@media (max-width: 768px) { .book-cover-3d { --spine-w: 12px; } }
@media (max-width: 480px) { .book-cover-3d { --spine-w: 10px; } }
/* ======================================================================= */

/* === Spine tint (color-only books) ====================================== */
/* Use --cover-color if present; otherwise keep the neutral fallback. */
.book-item.has-spine .book-spine {
    /* base tint */
    background: var(--cover-color, #6b6b6b);

    /* subtle depth without bright hairlines (prevents 'mystery border') */
    box-shadow:
      inset -8px 0 10px rgba(255,255,255,0.06),
      inset  8px 0 14px rgba(0,0,0,0.35),
      -2px 0 4px rgba(0,0,0,0.25);
  }

  /* === Unified color source =============================================== */
/* Cover background uses --cover-color with a safe fallback. */
.book-item .book-cover-content {
    background: var(--cover-color, #6b6b6b);
    background: linear-gradient(
      135deg,
      color-mix(in srgb, var(--cover-color, #6b6b6b) calc(100% - var(--grad-delta)), white var(--grad-delta)) 0%,
      color-mix(in srgb, var(--cover-color, #6b6b6b) calc(100% - var(--grad-delta)), black var(--grad-delta)) 100%
    );
  }