/* RESET */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* VARIABLES */
:root {
    --book-width: 576px;
    --book-height: 432px;
    --page-inset-top: 10px;
    --page-inset-right: 9px;
    --page-inset-left: 1px;
    --page-width: calc(var(--book-width) - var(--page-inset-left) - var(--page-inset-right));
    --page-height: calc(var(--book-height) - var(--page-inset-top) * 2);
    --cover-color: #b8b0a8;
    --flip-duration: 0.35s;
    --cover-flip-duration: 1.2s;
    --perspective: 2000px;
    --bg-color: #f0ece8;
}

/* GENERAL */
body {
    width: 100%;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-color);
    font-family: 'Mynerve', cursive;
    overflow: hidden;
}

main {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

/* ========================
   CONTROLS
   ======================== */
.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.nav-buttons {
    display: flex;
    align-items: center;
    gap: 16px;
}

.nav-btn {
    width: 36px;
    height: 36px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: rgba(60, 50, 45, 0.35);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s, background-color 0.2s;
    font-family: 'Mynerve', cursive;
}

.nav-btn:hover {
    color: rgba(60, 50, 45, 0.7);
    background-color: rgba(60, 50, 45, 0.06);
}

.nav-btn:active {
    background-color: rgba(60, 50, 45, 0.1);
}

.nav-btn-reset {
    font-size: 20px;
}

.hint {
    font-size: 12px;
    color: rgba(60, 50, 45, 0.35);
    text-align: center;
}

.divider {
    width: 60px;
    border: none;
    border-top: 1px solid rgba(60, 50, 45, 0.15);
}

.back-link {
    font-family: 'Mynerve', cursive;
    font-size: 14px;
    color: rgba(60, 50, 45, 0.5);
    text-decoration: none;
    transition: color 0.2s;
}

.back-link:hover {
    color: rgba(60, 50, 45, 0.8);
}

/* ========================
   FLIP BOOK
   ======================== */
#flip-book {
    width: var(--book-width);
    height: var(--book-height);
    position: relative;
    perspective: var(--perspective);
    transition: transform 0.8s ease;
}

#flip-book.opened {
    transform: translateX(calc(var(--book-width) / 2));
}

/* ========================
   COVERS (shared)
   ======================== */
.front-cover,
.back-cover {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    border-radius: 2.5px 5px 5px 2.5px;
    box-shadow: 0 0 5px 0 rgba(25, 25, 25, 0.25);
}

/* ========================
   FRONT COVER (double-sided)
   ======================== */
.front-cover {
    transform-origin: center left;
    transform-style: preserve-3d;
    transition: transform var(--cover-flip-duration) ease;
    z-index: 200;
    cursor: pointer;
}

.front-cover.flipped {
    transform: rotateY(-180deg);
}

/* Cover faces (shared) */
.cover-face {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    backface-visibility: hidden;
    border-radius: 2.5px 5px 5px 2.5px;
    background-color: var(--cover-color);
}

/* Front face of cover (visible when closed) */
.cover-face-front {
    background-image:
        linear-gradient(to left, rgba(0, 0, 0, 0.08) 0px, transparent 25px),
        linear-gradient(to right,
            rgba(0, 0, 0, 0.5) 0px,
            rgba(0, 0, 0, 0.25) 3px,
            rgba(255, 255, 255, 0.15) 5px,
            rgba(0, 0, 0, 0.12) 8px,
            transparent 25px
        );
}

/* Back face of cover (visible when opened — inside of cover on the left) */
.cover-face-back {
    transform: rotateY(180deg);
    background-image:
        linear-gradient(to right, rgba(0, 0, 0, 0.08) 0px, transparent 25px),
        linear-gradient(to left,
            rgba(0, 0, 0, 0.5) 0px,
            rgba(0, 0, 0, 0.25) 3px,
            rgba(255, 255, 255, 0.15) 5px,
            rgba(0, 0, 0, 0.12) 8px,
            transparent 25px
        );
    border-radius: 5px 2.5px 2.5px 5px;
}

/* Cover title */
.cover-title {
    position: relative;
    z-index: 1;
    font-family: 'Mynerve', cursive;
    font-size: 28px;
    font-weight: normal;
    line-height: 1.4;
    text-align: center;
    color: rgba(60, 50, 45, 0.75);
    letter-spacing: 1px;
    pointer-events: none;
}

/* ========================
   BACK COVER
   ======================== */
.back-cover {
    background-image:
        linear-gradient(to left, rgba(0, 0, 0, 0.08) 0px, transparent 25px),
        linear-gradient(to right,
            rgba(0, 0, 0, 0.5) 0px,
            rgba(0, 0, 0, 0.25) 3px,
            rgba(255, 255, 255, 0.15) 5px,
            rgba(0, 0, 0, 0.12) 8px,
            transparent 25px
        );
    background-color: var(--cover-color);
    z-index: -1;
}

/* ========================
   PAGES CONTAINER
   ======================== */
#pages-container {
    position: absolute;
    top: var(--page-inset-top);
    left: var(--page-inset-left);
    width: var(--page-width);
    height: var(--page-height);
    z-index: 50;
    pointer-events: none;
}

/* ========================
   INDIVIDUAL PAGE
   ======================== */
.page {
    width: var(--page-width);
    height: var(--page-height);
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: left center;
    transform-style: preserve-3d;
    transform: rotateY(0deg);
    transition: transform var(--flip-duration) ease;
    cursor: pointer;
    border-radius: 0 5px 5px 0;
    background-color: white;
    pointer-events: auto;
}

.page.flipped {
    transform: rotateY(-180deg);
}

/* ========================
   FRONT OF PAGE
   ======================== */
.page-front {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    background-color: #fff;
    border-radius: 0 5px 5px 0;
    overflow: hidden;
}

.page-front::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right,
        rgba(0, 0, 0, 0.12) 0px,
        rgba(0, 0, 0, 0.04) 8px,
        transparent 20px
    );
    pointer-events: none;
    z-index: 3;
}

.page-front::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 15px;
    height: 100%;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.04), transparent);
    pointer-events: none;
    z-index: 3;
}

.page-front img {
    width: calc(100% - 1px);
    height: calc(100% - 2px);
    position: absolute;
    top: 1px;
    left: 0;
    object-fit: cover;
    display: block;
    border-radius: 0 5px 5px 0;
    z-index: 2;
}

/* ========================
   PAGE TEXT OVERLAY
   ======================== */
.page-text {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    justify-content: center;
    align-items: center;
    font-family: 'Mynerve', cursive;
    font-size: 22px;
    color: rgba(60, 50, 45, 0.7);
    text-align: center;
    line-height: 1.5;
    z-index: 2;
    pointer-events: none;
}

/* ========================
   BACK OF PAGE
   ======================== */
.page-back {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    backface-visibility: hidden;
    transform: rotateY(180deg);
    background-color: #f5f0eb;
    border-radius: 5px 0 0 5px;
    overflow: hidden;
}

.page-back::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to left,
        rgba(0, 0, 0, 0.12) 0px,
        rgba(0, 0, 0, 0.04) 8px,
        transparent 20px
    );
    pointer-events: none;
    z-index: 3;
}

.page-back::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 15px;
    height: 100%;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.04), transparent);
    pointer-events: none;
    z-index: 3;
}

.page-back img {
    width: calc(100% - 1px);
    height: calc(100% - 2px);
    position: absolute;
    top: 1px;
    left: 1px;
    object-fit: cover;
    display: block;
    border-radius: 5px 0 0 5px;
    transform: scaleX(-1);
    opacity: 0.12;
    filter: blur(0.5px);
    z-index: 2;
}


/* ================================================================
   MOBILE — Spine at top, pages flip bottom-to-top
   ================================================================ */
@media (max-width: 768px) {
    :root {
        --book-width: calc(100vw - 32px);
        --book-height: calc((100vw - 32px) * 144 / 192);
        --page-inset-top: 1px;
        --page-inset-right: 8px;
        --page-inset-left: 8px;
        --page-width: calc(var(--book-width) - var(--page-inset-left) - var(--page-inset-right));
        --page-height: calc(var(--book-height) - var(--page-inset-top) - 8px);
    }

    /* Book shifts DOWN when opened */
    #flip-book.opened {
        transform: translateY(calc(var(--book-height) / 2));
    }

    /* --- COVERS: spine at top --- */
    .front-cover {
        transform-origin: center top;
    }

    .front-cover.flipped {
        transform: rotateX(180deg);
    }

    .cover-face {
        border-radius: 2.5px 2.5px 5px 5px;
    }

    .cover-face-front {
        background-image:
            linear-gradient(to top, rgba(0, 0, 0, 0.08) 0px, transparent 25px),
            linear-gradient(to bottom,
                rgba(0, 0, 0, 0.5) 0px,
                rgba(0, 0, 0, 0.25) 3px,
                rgba(255, 255, 255, 0.15) 5px,
                rgba(0, 0, 0, 0.12) 8px,
                transparent 25px
            );
    }

    .cover-face-back {
        transform: rotateX(180deg);
        border-radius: 5px 5px 2.5px 2.5px;
        background-image:
            linear-gradient(to bottom, rgba(0, 0, 0, 0.08) 0px, transparent 25px),
            linear-gradient(to top,
                rgba(0, 0, 0, 0.5) 0px,
                rgba(0, 0, 0, 0.25) 3px,
                rgba(255, 255, 255, 0.15) 5px,
                rgba(0, 0, 0, 0.12) 8px,
                transparent 25px
            );
    }

    .cover-title {
        font-size: 20px;
    }

    .back-cover {
        border-radius: 2.5px 2.5px 5px 5px;
        background-image:
            linear-gradient(to top, rgba(0, 0, 0, 0.08) 0px, transparent 25px),
            linear-gradient(to bottom,
                rgba(0, 0, 0, 0.5) 0px,
                rgba(0, 0, 0, 0.25) 3px,
                rgba(255, 255, 255, 0.15) 5px,
                rgba(0, 0, 0, 0.12) 8px,
                transparent 25px
            );
    }

    /* --- PAGE: flip on X axis, hinge at top --- */
    .page {
        transform-origin: center top;
        transform: rotateX(0deg);
        border-radius: 0 0 5px 5px;
    }

    .page.flipped {
        transform: rotateX(180deg);
    }

    .page-front {
        border-radius: 0 0 5px 5px;
    }

    .page-front::before {
        background: linear-gradient(to bottom,
            rgba(0, 0, 0, 0.12) 0px,
            rgba(0, 0, 0, 0.04) 8px,
            transparent 20px
        );
    }

    .page-front::after {
        top: auto;
        bottom: 0;
        right: auto;
        left: 0;
        width: 100%;
        height: 15px;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.04), transparent);
    }

    .page-front img {
        width: calc(100% - 2px);
        height: calc(100% - 1px);
        top: 1px;
        left: 1px;
        border-radius: 0 0 5px 5px;
    }

    .page-back {
        transform: rotateX(180deg);
        border-radius: 5px 5px 0 0;
    }

    .page-back::before {
        background: linear-gradient(to top,
            rgba(0, 0, 0, 0.12) 0px,
            rgba(0, 0, 0, 0.04) 8px,
            transparent 20px
        );
    }

    .page-back::after {
        top: 0;
        bottom: auto;
        left: 0;
        right: auto;
        width: 100%;
        height: 15px;
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.04), transparent);
    }

    .page-back img {
        width: calc(100% - 2px);
        height: calc(100% - 1px);
        top: 0;
        left: 1px;
        border-radius: 5px 5px 0 0;
        transform: scaleY(-1);
    }

    .page-text {
        font-size: 16px;
    }
}
