/* VARIABLES - Adjust these to change the zine's size/speed */
:root {
    --p-width: 350px;
    --p-height: 500px;
    --speed: 0.8s;
    --frame-padding: 200px; /* This is the 200px background border */
}

/* 1. CORE LAYOUT */
body {
    background-color: #000; /* Outer void */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    perspective: 2000px; /* Needed for 3D depth */
    font-family: sans-serif;
    touch-action: none;
}

/* 2. THE BACKGROUND FRAME (The "Desk") */
.background-frame {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--frame-padding);
    
    /* Background Image setup */
    background-image: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.4)), 
                      url('../assets/background.png');
    background-size: cover;
    background-position: center;
    
    border-radius: 15px;
    box-shadow: 0 50px 100px rgba(0,0,0,0.7);
    transition: all var(--speed) ease-in-out;
}

/* 3. THE 3D STAGE */
.scene {
    width: var(--p-width);
    height: var(--p-height);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.book {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform var(--speed) ease-in-out;
    transform: translateX(0); /* Default: centered cover */
}

/* SHIFT LOGIC: Keeps the hinge centered when the book is open or on the last page */
.scene.open .book, 
.scene.last-page .book {
    transform: translateX(50%);
}

/* 4. PAGE STYLING */
.page {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform var(--speed) ease-in-out, z-index 0s;
    cursor: pointer;
    user-select: none;
}

.page img, .page .back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow: 0 5px 15px rgba(0,0,0,0.4);
}

/* Front of the leaf (Right side) */
.page img {
    border-radius: 0 5px 5px 0;
}

/* Back of the leaf (Left side when flipped) */
.page .back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotateY(180deg);
    backface-visibility: hidden;
}

.page .back img {
    border-radius: 5px 0 0 5px;
    /* Subtle highlight on the spine */
    border-right: 1px solid rgba(255,255,255,0.1);
}

/* THE FLIP */
.page.flipped {
    transform: rotateY(-180deg);
}

/* 5. RESPONSIVE FIXES */
@media (max-width: 1000px) {
    :root {
        --frame-padding: 100px;
    }
}

@media (max-width: 768px) {
    :root {
        --p-width: 40vw;
        --p-height: 60vw;
        --frame-padding: 40px;
    }
    
    .background-frame {
        width: 95vw;
        height: 90vh;
    }

    /* Adjust shift for smaller mobile screens */
    .scene.open .book, 
    .scene.last-page .book {
        transform: translateX(40%);
    }
}
