/* Books Page Header */
.books-page-header {
    margin-bottom: var(--space-8);
    border-bottom: 1px solid var(--color-border-light);
    padding-bottom: var(--space-4);
}

.books-page-header h1 {
    margin-bottom: var(--space-2);
}

.page-header__subtitle {
    font-size: var(--text-lg);
    color: var(--color-text-secondary);
    max-width: 65ch;
}

/* Bookshelf Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--space-8) var(--space-6);
    padding: var(--space-4) 0;
}

/* Mobile: 2 columns, smaller gaps */
@media (max-width: 639px) {
    .books-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-4) var(--space-3);
    }

    .book-scene {
        width: 100px;
        height: 145px;
    }

    .book-title {
        font-size: 0.85rem;
    }

    .book-info-title {
        font-size: var(--text-sm);
    }

    .book-info-author {
        font-size: 11px;
    }

    .book-topic {
        font-size: 9px;
        padding: 2px 4px;
    }
}

/* Filter Bar Refinements */
.filter-nav-container {
    margin: 0 0 var(--space-8) 0;
    padding: var(--space-2) 0;
    background: var(--color-bg-surface);
    border-bottom: 1px solid var(--color-border-light);
}

.filter-bar {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.filter-accordion {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.filter-group {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-bg-alt);
    overflow: hidden;
}

.filter-group-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    transition: background-color 0.2s ease;
}

.filter-group-header:hover {
    background-color: var(--color-bg-surface);
}

.filter-group-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text);
}

.toggle-icon {
    font-size: 10px;
    color: var(--color-text-muted);
}

.filter-group-content {
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    border-top: 1px solid var(--color-border-light);
}

.filter-group-content.collapsed {
    display: none;
}

.filter-pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

/* Subcategories styling */
.subcategory-shelf {
    margin-top: var(--space-2);
    padding: var(--space-3);
    background: var(--color-bg-surface);
    border-radius: var(--radius-sm);
    border: 1px dashed var(--color-border);
}

.subcategory-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: var(--space-2);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pill--sub {
    font-size: 12px;
    padding: 4px 10px;
    border-style: dashed;
}

/* Mobile Adjustments */
@media (max-width: 639px) {
    .filter-nav-container {
        /* Ensure it doesn't overlap mobile sidebar or edge */
        margin-left: 0;
        margin-right: 0;
        padding: var(--space-2) 0;
    }

    .filter-pill {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 40px;
    }

    .pill--sub {
        min-height: 36px;
    }
}


.filter-scroller {
    display: flex;
    align-items: center;
    gap: var(--space-6);
    overflow-x: auto;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE */
    padding: 4px 0;
    flex-grow: 1;
}

.filter-scroller::-webkit-scrollbar {
    display: none;
}

.filter-group-horizontal {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-muted);
    margin-right: var(--space-1);
    white-space: nowrap;
}

.filter-divider {
    width: 1px;
    height: 20px;
    background: var(--color-border);
    flex-shrink: 0;
}

/* Modern Pills */
.filter-pill {
    background: transparent;
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    padding: 6px 14px;
    border-radius: 999px;
    /* Pill shape */
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease-out;
    font-family: var(--font-ui);
}

.filter-pill:hover {
    border-color: var(--color-text-secondary);
    color: var(--color-text);
    background: var(--color-bg-alt);
}

/* Enhanced active state with checkmark */
.filter-pill.active {
    background: var(--color-link);
    border-color: var(--color-link);
    color: white;
    box-shadow: 0 2px 8px rgba(51, 102, 204, 0.3);
    font-weight: 600;
}

.filter-pill.active::before {
    content: "✓ ";
    font-weight: 700;
}

.filter-clear-btn {
    font-size: 12px;
    color: var(--color-text-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
    white-space: nowrap;
    padding: 8px var(--space-3);
    display: none;
    /* Hidden by default, shown via JS when filters active */
}

.filter-clear-btn.visible {
    display: block;
}

.filter-clear-btn:hover {
    color: var(--color-link);
}

/* Filter summary / Active filters display */
.filter-summary {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border-light);
    display: none;
}

.filter-summary.visible {
    display: block;
}

/* Books stats / result count */
.books-stats {
    margin-top: var(--space-4);
    text-align: right;
    font-size: 12px;
    color: var(--color-text-muted);
    padding-bottom: var(--space-2);
}

/* Book Card */
.book-card {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    group: book;
    padding: var(--space-4);
    border-radius: var(--radius-lg);
    transition: background-color 0.2s ease;
}

.book-card:hover {
    background-color: var(--color-bg-alt);
    text-decoration: none;
}

.book-card:hover .book-object {
    transform: rotateY(-30deg) translateX(-10px);
    box-shadow: 10px 10px 30px rgba(0, 0, 0, 0.2);
}

/* 3D Book Object */
.book-scene {
    perspective: 1000px;
    width: 140px;
    height: 200px;
    margin: 0 auto;
}

.book-object {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateY(-20deg);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.4s ease;
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.1);
}

.book-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--book-color, #444);
    border-radius: 2px 4px 4px 2px;
    transform: translateZ(15px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    text-align: center;
    background-image: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(0, 0, 0, 0.1) 100%);
    box-shadow: inset 2px 0 5px rgba(0, 0, 0, 0.1);
}

.book-cover::after {
    /* Texture/Sheen */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to right, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0) 5%, rgba(255, 255, 255, 0) 100%);
}

.book-cover-content {
    color: white;
    font-family: var(--font-display, serif);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.book-title {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
}

.book-author {
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.9;
}

/* Spine */
.book-spine {
    position: absolute;
    top: 0;
    left: 0;
    width: 30px;
    height: 100%;
    background-color: var(--book-color, #444);
    filter: brightness(0.9);
    transform-origin: left;
    transform: rotateY(90deg) translateX(-30px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-spine-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 1px;
    opacity: 0.8;
    transform: rotate(180deg);
}

/* Pages */
.book-pages {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 26px;
    height: calc(100% - 6px);
    background: #fff;
    transform: translateX(110px) rotateY(90deg);
    background-image: repeating-linear-gradient(to right, #f0f0f0 0px, #f0f0f0 1px, #fff 1px, #fff 3px);
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.1);
    transform: translateZ(-13px);
}

/* Info */
.book-info {
    text-align: center;
}

.book-info-title {
    font-size: var(--text-base);
    font-weight: 700;
    margin-bottom: var(--space-1);
    line-height: 1.3;
    color: var(--color-text);
}

.book-card:hover .book-info-title {
    color: var(--color-link);
}

.book-info-author {
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
}

/* Topics */
.book-topics {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--space-1);
}

.book-topic {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-muted);
}