:root {
    --primary-light: #e0f2fe;
    --primary: #0ea5e9;
    --primary-dark: #0284c7;
    --background: #f0f9ff;
    --text: #0f172a;
    --card-bg: #ffffff;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background);
    color: var(--text);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* --- Floating Bubbles Animation --- */
.bubbles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.bubble {
    position: absolute;
    bottom: -150px;
    background: rgba(14, 165, 233, 0.15);
    /* Light blue bubbles */
    border-radius: 50%;
    animation: floatUp 15s infinite linear;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) scale(1);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        transform: translateY(-120vh) scale(1.5);
        opacity: 0;
    }
}

/* Randomize bubbles */
.bubble:nth-child(1) {
    left: 10%;
    width: 40px;
    height: 40px;
    animation-duration: 12s;
    animation-delay: 0s;
}

.bubble:nth-child(2) {
    left: 25%;
    width: 80px;
    height: 80px;
    animation-duration: 18s;
    animation-delay: 2s;
}

.bubble:nth-child(3) {
    left: 40%;
    width: 30px;
    height: 30px;
    animation-duration: 10s;
    animation-delay: 4s;
}

.bubble:nth-child(4) {
    left: 55%;
    width: 60px;
    height: 60px;
    animation-duration: 15s;
    animation-delay: 1s;
}

.bubble:nth-child(5) {
    left: 70%;
    width: 50px;
    height: 50px;
    animation-duration: 14s;
    animation-delay: 3s;
}

.bubble:nth-child(6) {
    left: 85%;
    width: 90px;
    height: 90px;
    animation-duration: 20s;
    animation-delay: 6s;
}

.bubble:nth-child(7) {
    left: 15%;
    width: 35px;
    height: 35px;
    animation-duration: 11s;
    animation-delay: 5s;
}

.bubble:nth-child(8) {
    left: 50%;
    width: 75px;
    height: 75px;
    animation-duration: 17s;
    animation-delay: 8s;
}

.bubble:nth-child(9) {
    left: 80%;
    width: 45px;
    height: 45px;
    animation-duration: 13s;
    animation-delay: 7s;
}

.bubble:nth-child(10) {
    left: 30%;
    width: 65px;
    height: 65px;
    animation-duration: 16s;
    animation-delay: 9s;
}

/* ---------------------------------- */

.header {
    background: linear-gradient(to right, #0369a1, #38bdf8);
    /* Deep sea blue to light sky blue */
    color: white;
    padding: 2rem 1rem;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 2rem;
    font-weight: 600;
}

.bookshelf-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 2.5rem;
}

.book-card {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.book-cover-container {
    width: 100%;
    aspect-ratio: 1 / 1.414;
    display: flex;
    flex-direction: column;
    background-color: #f1f5f9;
    border-bottom: 2px solid var(--primary-light);
    overflow: hidden;
}

.cover-page {
    width: 100%;
    /* Let images dictate their own natural height */
    height: auto;
    object-fit: cover;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

/* Ensure Page 1 and Page 2 take their natural exact height and do NOT stretch/shrink to share space */
.cover-page:nth-child(1),
.cover-page:nth-child(2) {
    flex: 0 0 auto;
}

/* Let Page 3 take whatever vertical space remains (and get cut off visually by the container's overflow: hidden) */
.cover-page:nth-child(3) {
    flex: 1 1 auto;
    /* ensure it stretches to fill the bottom if needed, though it will naturally be cut off by container */
    object-position: top;
    /* Since it cuts off at bottom, ensure top of page 3 is visible */
}

.cover-page:last-child {
    border-bottom: none;
}

.book-info {
    padding: 1.25rem 1rem;
    text-align: center;
}

.book-title {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    word-break: break-word;
}

.book-pages {
    font-size: 0.875rem;
    color: #64748b;
}

.loading,
.error {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem;
    font-size: 1.25rem;
    color: var(--primary-dark);
}

.error {
    color: #ef4444;
}

/* Responsive adjustments for Mobile */
@media (max-width: 600px) {
    .bookshelf-container {
        /* Force 3 columns on mobile so covers are roughly 33% width */
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
        padding: 1.5rem 0.5rem;
    }

    .book-info {
        padding: 0.5rem;
    }

    .book-title {
        font-size: 0.8rem;
        margin-bottom: 0.2rem;
    }

    .book-pages {
        font-size: 0.7rem;
    }
}