/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Baloo 2', cursive, sans-serif;
    color: #2d3436;
    background: #f8f9fa;
    overflow-x: hidden;
}

h1, h2, h3 {
    font-family: 'Fredoka', sans-serif;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ---- Hero ---- */
.books-hero {
    position: relative;
    min-height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe, #74b9ff);
    overflow: hidden;
    text-align: center;
}

.hero-bg {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.floating-emoji {
    position: absolute;
    font-size: 2.5rem;
    opacity: 0.25;
    animation: float 6s ease-in-out infinite;
}

.emoji-1 { top: 10%; left: 8%; animation-delay: 0s; }
.emoji-2 { top: 20%; right: 12%; animation-delay: 1s; }
.emoji-3 { bottom: 20%; left: 20%; animation-delay: 2s; }
.emoji-4 { top: 15%; right: 25%; animation-delay: 0.5s; }
.emoji-5 { bottom: 15%; right: 10%; animation-delay: 3s; }
.emoji-6 { bottom: 30%; left: 5%; animation-delay: 1.5s; }

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-18px) rotate(8deg); }
}

.hero-content {
    position: relative;
    z-index: 2;
    padding: 40px 24px 36px;
}

.back-link {
    display: inline-block;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    padding: 6px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
    transition: background 0.2s, transform 0.2s;
}

.back-link:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateX(-4px);
}

.books-hero h1 {
    font-size: 2.8rem;
    color: #fff;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    margin-bottom: 4px;
}

.books-hero .tagline {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
    font-weight: 500;
}

/* ---- Search ---- */
.search-section {
    margin-top: -28px;
    position: relative;
    z-index: 10;
}

.search-bar-wrapper {
    display: flex;
    align-items: center;
    background: #fff;
    border-radius: 50px;
    box-shadow: 0 8px 32px rgba(108, 92, 231, 0.18);
    padding: 6px 8px 6px 20px;
    max-width: 620px;
    margin: 0 auto;
    transition: box-shadow 0.3s;
}

.search-bar-wrapper:focus-within {
    box-shadow: 0 8px 40px rgba(108, 92, 231, 0.32);
}

.search-icon {
    font-size: 1.3rem;
    margin-right: 8px;
    flex-shrink: 0;
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    font-family: 'Baloo 2', sans-serif;
    font-size: 1.1rem;
    color: #2d3436;
    background: transparent;
    padding: 10px 4px;
}

.search-input::placeholder {
    color: #b2bec3;
}

.clear-btn {
    display: none;
    background: #dfe6e9;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    color: #636e72;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}

.clear-btn.visible {
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    background: #b2bec3;
    color: #fff;
}

/* ---- Filters ---- */
.filters-section {
    padding: 28px 0 8px;
}

.filter-group {
    margin-bottom: 16px;
}

.filter-group h3 {
    font-size: 1rem;
    color: #6c5ce7;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pill {
    font-family: 'Baloo 2', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 7px 18px;
    border: 2px solid #dfe6e9;
    border-radius: 50px;
    background: #fff;
    color: #636e72;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.pill:hover {
    border-color: #a29bfe;
    color: #6c5ce7;
    transform: translateY(-1px);
}

.pill.active {
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(108, 92, 231, 0.3);
}

/* ---- Results ---- */
.results-section {
    padding: 16px 0 60px;
    min-height: 400px;
}

.results-info {
    font-size: 0.95rem;
    color: #636e72;
    margin-bottom: 16px;
}

/* Loading */
.loading-state {
    text-align: center;
    padding: 60px 20px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 5px solid #dfe6e9;
    border-top-color: #6c5ce7;
    border-radius: 50%;
    margin: 0 auto 16px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-state p {
    color: #6c5ce7;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Error */
.error-state {
    text-align: center;
    padding: 60px 20px;
}

.error-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
}

.error-state p {
    font-size: 1.1rem;
    color: #636e72;
    margin-bottom: 20px;
}

.retry-btn {
    font-family: 'Baloo 2', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    padding: 10px 28px;
    border: none;
    border-radius: 50px;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.retry-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
}

/* Empty */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 1.1rem;
    color: #636e72;
}

/* ---- Book Grid ---- */
.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 24px;
}

/* Book Card */
.book-card {
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
    transition: transform 0.25s, box-shadow 0.25s;
    display: flex;
    flex-direction: column;
    animation: fadeInUp 0.4s ease both;
}

.book-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 32px rgba(108, 92, 231, 0.18);
}

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

.book-cover-wrapper {
    position: relative;
    width: 100%;
    padding-top: 140%;
    background: linear-gradient(135deg, #dfe6e9, #b2bec3);
    overflow: hidden;
}

.book-cover-wrapper img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.book-card:hover .book-cover-wrapper img {
    transform: scale(1.05);
}

.no-cover-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #636e72;
    font-size: 0.85rem;
    text-align: center;
    padding: 16px;
}

.no-cover-placeholder span {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.book-info {
    padding: 14px 16px 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: #2d3436;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.85rem;
    color: #6c5ce7;
    font-weight: 600;
    margin-bottom: 6px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-year {
    font-size: 0.8rem;
    color: #b2bec3;
    margin-bottom: 8px;
}

.book-subjects {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.subject-tag {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 50px;
    background: #f0efff;
    color: #6c5ce7;
    white-space: nowrap;
}

.book-link {
    display: inline-block;
    margin-top: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #a29bfe;
    text-decoration: none;
    transition: color 0.2s;
}

.book-link:hover {
    color: #6c5ce7;
}

/* ---- Load More ---- */
.load-more-wrapper {
    text-align: center;
    padding: 36px 0 20px;
}

.load-more-btn {
    font-family: 'Baloo 2', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    padding: 14px 40px;
    border: none;
    border-radius: 50px;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.25);
}

.load-more-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(108, 92, 231, 0.4);
}

.load-more-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ---- Footer ---- */
.books-footer {
    text-align: center;
    padding: 24px;
    font-size: 0.9rem;
    color: #b2bec3;
    border-top: 1px solid #eee;
}

.books-footer a {
    color: #6c5ce7;
    text-decoration: none;
    font-weight: 600;
}

.books-footer a:hover {
    text-decoration: underline;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .books-hero h1 {
        font-size: 2rem;
    }

    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 16px;
    }

    .pill {
        font-size: 0.85rem;
        padding: 6px 14px;
    }

    .search-input {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .books-hero {
        min-height: 200px;
    }

    .books-hero h1 {
        font-size: 1.7rem;
    }

    .book-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .book-info {
        padding: 10px 12px 14px;
    }

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

    .container {
        padding: 0 16px;
    }
}
