:root {
    /* Light mode variables */
    --bg-color: #ffffff;
    --text-color: #333333;
    --title-color: #000000;
    --overlay-text-color: rgba(0, 0, 0, 0.05);
    --shelf-bg: linear-gradient(to bottom, #f0f0f0, #e0e0e0);
    --shelf-edge-top: rgba(255, 255, 255, 0.02);
    --shelf-edge-bottom: rgba(0, 0, 0, 0.12);
    --book-back-cover: #111111;
    --book-page: #ffffff;
    --book-page-border: rgba(0, 0, 0, 0.2);
    --book-shadow: rgba(0, 0, 0, 0.15);
    --book-shadow-strong: rgba(0, 0, 0, 0.35);
    --side-book-bg: linear-gradient(to right, #444 0%, #666 50%, #444 100%);
    --side-book-text: #f0f0f0;
    --side-book-decoration: rgba(255, 255, 255, 0.3);
    --book-spine-bg: linear-gradient(to right, #333 0%, #555 50%, #333 100%);
    --book-spine-text: #ffffff;
    --toggle-dot: #333333;
    --glow-color: rgba(255, 255, 255, 0.5);
}

body.dark {
    /* Dark mode variables */
    --bg-color: #121212;
    --text-color: #e0e0e0;
    --title-color: #ffffff;
    --overlay-text-color: rgba(255, 255, 255, 0.05);
    --shelf-bg: linear-gradient(to bottom, #2a2a2a, #1a1a1a);
    --shelf-edge-top: rgba(255, 255, 255, 0.04);
    --shelf-edge-bottom: rgba(0, 0, 0, 0.3);
    --book-back-cover: #ffffff;
    --book-page: #ffffff;
    --book-page-border: rgba(0, 0, 0, 0.2);
    --book-shadow: rgba(0, 0, 0, 0.3);
    --book-shadow-strong: rgba(0, 0, 0, 0.5);
    --side-book-bg: linear-gradient(to right, #222 0%, #444 50%, #222 100%);
    --side-book-text: #ffffff;
    --side-book-decoration: rgba(255, 255, 255, 0.25);
    --book-spine-bg: linear-gradient(to right, #222 0%, #444 50%, #222 100%);
    --book-spine-text: #e0e0e0;
    --toggle-dot: #ffffff;
    --glow-color: rgba(255, 255, 255, 0.35);
}

@font-face {
    font-family: "Cabinet Grotesk";
    font-style: normal;
    font-weight: 800;
    src: local("Cabinet Grotesk"),
        url("https://fonts.cdnfonts.com/s/85514/CabinetGrotesk-Extrabold.woff") format("woff");
}

@font-face {
    font-family: "Cabinet Grotesk";
    font-style: normal;
    font-weight: 400;
    src: local("Cabinet Grotesk"),
        url("https://fonts.cdnfonts.com/s/85514/CabinetGrotesk-Medium.woff") format("woff");
}

.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--toggle-dot);
    cursor: pointer;
    z-index: 100;
    transition: background-color 0.3s ease;
}

.book-title-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: -1;
    opacity: 1;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.book-title-text {
    font-family: "Cabinet Grotesk", sans-serif;
    font-weight: 800;
    font-size: clamp(5rem, 14vw, 15rem);
    color: var(--overlay-text-color);
    text-transform: uppercase;
    text-align: center;
    line-height: 1;
    max-width: 90vw;
    transition: color 0.5s ease;
}

.shelf-container {
    position: relative;
    width: 100%;
    height: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    z-index: 1;
    perspective: 1000px;
}

.shelf {
    display: block;
    position: absolute;
    bottom: 270px;
    width: 100%;
    max-width: 800px;
    height: 15px;
    background: var(--shelf-bg);
    border-radius: 2px;
    z-index: 20;
    box-shadow:
        0px -1px 1px rgba(255, 255, 255, 0.15),
        0px 2px 3px rgba(0, 0, 0, 0.12),
        0px 5px 10px rgba(0, 0, 0, 0.08),
        0px 15px 20px rgba(0, 0, 0, 0.06);
    transition: background 0.5s ease, box-shadow 0.5s ease;
    transform-style: preserve-3d;
}

.shelf:after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: var(--shelf-edge-bottom);
    transition: background-color 0.5s ease;
}

.shelf:before {
    content: "";
    position: absolute;
    top: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: var(--shelf-edge-top);
    transition: background-color 0.5s ease;
}

.books-wrapper {
    position: absolute;
    bottom: 287px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 1.8rem; /* Increased gap for consistent spacing */
    z-index: 10;
}

.books__item {
    text-align: center;
    cursor: default;
    height: 220px;
    width: 160px; /* Fixed width to prevent overlap */
    position: relative;
    transition: filter 0.3s ease;
}

.books__item:hover {
    filter: drop-shadow(0 0 10px var(--glow-color));
}

.books__container {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0;
}

.books__cover {
    position: relative;
    will-change: transform;
    height: 100%;
    transform-style: preserve-3d;
}

.books__hitbox {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: 5;
    cursor: pointer;
}

.books__back-cover {
    position: absolute;
    width: 96%;
    height: 96%;
    top: 2%;
    left: 2%;
    background: var(--book-back-cover);
    border-radius: 0 6px 6px 0;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    z-index: -10;
    transition: background 0.5s ease;
}

.books__inside {
    position: absolute;
    width: 90%;
    height: 94%;
    top: 3%;
    left: 5%;
    z-index: 0;
}

.books__page {
    position: absolute;
    top: 0;
    right: 0;
    width: 98%;
    height: 100%;
    background: var(--book-page);
    border: 1px solid var(--book-page-border);
    border-radius: 0 6px 6px 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    transform-origin: right center;
    z-index: -5;
    transition: background 0.5s ease, border-color 0.5s ease;
    transform-style: preserve-3d;
}

.books__spine {
    position: absolute;
    width: 20px;
    height: 100%;
    top: 0;
    left: -20px;
    background: var(--book-spine-bg);
    color: var(--book-spine-text);
    font-size: 10px;
    text-align: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotateY(-90deg);
    transform-origin: right center;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0;
    z-index: 2;
    transition: opacity 0.3s ease;
    transform-style: preserve-3d;
}

.books__image {
    line-height: 0;
    position: relative;
    border-radius: 2px 6px 6px 2px;
    height: 100%;
    box-shadow: var(--book-shadow) 10px -5px 15px, var(--book-shadow) 20px 0px 25px;
    transform-origin: left center;
    cursor: pointer;
    will-change: transform, box-shadow;
    transition: box-shadow 0.4s ease, filter 0.3s ease;
    transform-style: preserve-3d;
}

.books__image:hover {
    filter: drop-shadow(0 0 10px var(--glow-color));
}

.books__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 2px 6px 6px 2px;
}

.books__effect {
    position: absolute;
    width: 24px;
    height: 100%;
    margin-left: 12px;
    top: 0;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 255, 255, 0) 100%);
    transform-origin: left center;
    z-index: 5;
    pointer-events: none;
    will-change: margin-left, opacity;
    transition: opacity 0.3s ease;
}

.books__light {
    width: 100%;
    height: 100%;
    position: absolute;
    border-radius: 2px 6px 6px 2px;
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.4) 100%);
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.15;
    transform-origin: left center;
    z-index: 4;
    pointer-events: none;
    mix-blend-mode: overlay;
    will-change: opacity;
}

.side-book {
    height: 220px;
    width: 30px;
    position: relative;
    cursor: pointer;
    background: var(--side-book-bg);
    border-radius: 2px;
    box-shadow: var(--book-shadow) 5px -3px 10px, var(--book-shadow) 10px 0px 15px;
    transform-origin: bottom center;
    will-change: transform, box-shadow;
    transition: background 0.5s ease, box-shadow 0.4s ease, filter 0.3s ease;
    transform-style: preserve-3d;
}

.side-book:hover {
    filter: drop-shadow(0 0 10px var(--glow-color));
}

.side-book__title {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    color: var(--side-book-text);
    font-size: 11px;
    padding: 5px 0;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: color 0.5s ease;
}

.side-book__decoration {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 1px;
    background-color: var(--side-book-decoration);
    transition: background-color 0.5s ease;
}

.side-book__decoration:nth-child(2) {
    top: auto;
    bottom: 20px;
}

.book-shadow {
    position: absolute;
    bottom: 285px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 1.8rem; /* Match books-wrapper gap */
    z-index: 15;
}

.book-shadow__item {
    width: 120px;
    height: 2px;
    background: radial-gradient(ellipse at center, var(--book-shadow) 0%, rgba(0, 0, 0, 0) 70%);
    border-radius: 50%;
    will-change: width, opacity;
    transition: background 0.5s ease;
}

.book-shadow__item.side {
    width: 25px;
}

/* Responsive design */
@media (max-width: 768px) {
    .book-title-text {
        font-size: clamp(4rem, 10vw, 9rem);
    }

    .shelf-container {
        height: 700px;
    }

    .books-wrapper {
        gap: 1.2rem;
        flex-wrap: wrap;
    }

    .books__item {
        width: 120px;
        height: 180px;
    }

    .books__container {
        width: 120px;
    }

    .books__spine {
        width: 15px;
        left: -15px;
        font-size: 9px;
    }

    .book-shadow__item {
        width: 100px;
    }

    .book-shadow__item.side {
        width: 20px;
    }
}

@media (max-width: 480px) {
    .book-title-text {
        font-size: clamp(3rem, 8vw, 6rem);
    }

    .books__item {
        width: 100px;
        height: 150px;
    }

    .books__container {
        width: 100px;
    }

    .books__spine {
        width: 12px;
        left: -12px;
        font-size: 8px;
    }

    .book-shadow__item {
        width: 80px;
    }

    .book-shadow__item.side {
        width: 18px;
    }
}