* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Libre Baskerville', serif;
    line-height: 1.6;
    color: #2d2d2d;
    background-color: #f9ece6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Color Palette */
:root {
    --primary: #a66f7d; /* Dusty rose */
    --secondary: #f4a261; /* Warm orange */
    --hover: #e76f51; /* Darker orange */
    --accent: #d4af37; /* Gold for Best Seller */
    --text-light: #666;
    --text-dark: #2d2d2d;
}

.books {
    max-width: 1200px;
    margin: 4rem auto;
    padding: 0 2rem;
}

.books h1 {
    color: var(--primary);
    margin-bottom: 2.5rem;
    text-align: center;
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.books h1::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 3px;
    background: linear-gradient(to right, var(--secondary), var(--primary));
    border-radius: 2px;
}

.filter-search {
    margin-bottom: 2.5rem;
    text-align: center;
}

#searchBar {
    padding: 0.9rem 1.5rem;
    width: 320px;
    max-width: 100%;
    border: 2px solid var(--primary);
    border-radius: 25px;
    margin-bottom: 1.5rem;
    font-family: 'Libre Baskerville', serif;
    font-size: 1rem;
    background-color: #fff;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

#searchBar:focus {
    border-color: var(--secondary);
    box-shadow: 0 0 8px rgba(244, 162, 97, 0.5);
    outline: none;
}

.filters {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.filters button {
    padding: 0.6rem 1.2rem;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.filters button:hover {
    background-color: #8c5d68;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.filters button.active {
    background-color: var(--secondary);
    color: var(--text-dark);
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 2.5rem;
    padding: 1.5rem;
}

.book-item {
    position: relative;
    background: linear-gradient(135deg, #fff 50%, #f9ece6 50%);
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid rgba(244, 162, 97, 0.2);
}

.book-item.hidden {
    display: none;
}

.book-item:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.book-item img {
    width: auto;
    max-width: 180px;
    border-radius: 8px;
    margin-bottom: 1.2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease;
}

.book-item:hover img {
    transform: scale(1.05);
}

.book-item h3 {
    color: var(--primary);
    font-size: 1.3rem;
    margin-bottom: 0.6rem;
    text-align: center;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0 0.5rem;
    font-weight: 600;
}

.book-item p {
    color: var(--text-light);
    font-size: 0.95rem;
    margin-bottom: 1.2rem;
    text-align: center;
    flex-grow: 1;
    min-height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    line-height: 1.6;
}

.purchase-button {
    display: inline-block;
    padding: 0.9rem 1.8rem;
    background-color: var(--secondary);
    color: var(--text-dark);
    text-decoration: none;
    border-radius: 25px;
    font-weight: 700;
    transition: background-color 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
    margin-top: auto;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.purchase-button:hover {
    background-color: var(--hover);
    transform: scale(1.05);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.15);
}

/* Best Seller Badge */
.best-seller .badge {
    position: absolute;
    top: -25px;
    left: -25px;
    width: 90px; /* Increased for more space */
    height: 90px;
    background: linear-gradient(135deg, var(--accent), #b8860b); /* Gradient for premium look */
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.3); /* Outer shadow + inner shine */
    z-index: 10;
    animation: pulseGlow 2s infinite ease-in-out; /* Retained animation */
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden; /* Prevents overflow */
}

.best-seller .badge-front {
    color: var(--text-dark);
    font-size: 0.85rem; /* Slightly smaller to fit */
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    padding: 0.2rem 0.5rem; /* Padding for spacing */
    line-height: 1.2; /* Tighter line height for two lines */
    width: 100%;
    white-space: normal; /* Allows wrapping */
    overflow: hidden; /* Ensures no overflow */
}

.best-seller .badge-back {
    display: none; /* Still removed */
}

@keyframes pulseGlow {
    0% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 0 10px rgba(212, 175, 55, 0.5);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25), 0 0 20px rgba(212, 175, 55, 0.8);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 0 10px rgba(212, 175, 55, 0.5);
    }
}

footer {
    background-color: var(--primary);
    color: white;
    text-align: center;
    padding: 1.5rem;
    width: 100%;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .books h1 {
        font-size: 2.2rem;
    }

    .book-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 2rem;
    }

    #searchBar {
        width: 100%;
    }

    .filters {
        gap: 0.5rem;
    }

    .filters button {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }

    .book-item h3 {
        min-height: 4rem;
    }

    .best-seller .badge {
        width: 75px; /* Adjusted for mobile */
        height: 75px;
        top: -20px;
        left: -20px;
    }

    .best-seller .badge-front {
        font-size: 0.7rem; /* Smaller to fit full text */
    }
}

@media (max-width: 480px) {
    .books h1 {
        font-size: 1.8rem;
    }

    .books h1::after {
        width: 80px;
    }

    .book-grid {
        grid-template-columns: 1fr;
    }

    .book-item {
        padding: 1.5rem;
    }

    .book-item img {
        max-width: 150px;
    }

    .book-item h3 {
        font-size: 1.2rem;
        min-height: 3rem;
    }

    .book-item p {
        font-size: 0.9rem;
        min-height: 2rem;
    }

    .purchase-button {
        padding: 0.8rem 1.5rem;
        font-size: 0.9rem;
    }

    .best-seller .badge {
        width: 60px; /* Smaller for very small screens */
        height: 60px;
        top: -15px;
        left: -15px;
    }

    .best-seller .badge-front {
        font-size: 0.6rem; /* Smallest size to ensure fit */
        padding: 0.2rem 0.3rem; /* Adjusted padding */
    }
}