@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Noto+Nastaliq+Urdu&display=swap');

/* =========================================================
   ORIGINAL / STABLE FLIPBOOK CSS
   Deliberately avoids styling .page/.turn-page because
   Turn.js owns those elements and must control their geometry.
========================================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Poppins", sans-serif;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    width: 100vw;
    overflow-x: hidden;
    background: #fef6e4;
}

#main-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex-grow: 1;
    width: 100%;
    padding: 20px;
}

#magazine-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-grow: 1;
}

.flipbook {
    width: 1488px !important;
    height: 2105px !important;
    max-width: 50vw;
    max-height: 70vh;

    /* Let Turn.js receive normal pointer/touch input. */
    touch-action: auto;
    -webkit-user-select: none;
    user-select: none;
}

.button-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    position: relative;
    z-index: 9999;
    pointer-events: auto;
}

.icon {
    position: relative;
    z-index: 10000;
    pointer-events: auto;
    font-size: 24px;
    color: #172c66;
    cursor: pointer;
    transition: transform 0.3s;
}

.icon:hover {
    transform: scale(1.2);
}

.icon:active {
    transform: scale(0.9);
}

.home-button {
    position: fixed;
    top: 20px;
    left: 20px;

    width: 48px;
    height: 48px;

    font-size: 24px;
    color: #ffffff;
    background-color: #172c66;

    border-radius: 8px;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;
    z-index: 2147483647 !important;

    transition:
        background-color 0.3s,
        transform 0.3s;
}

.home-button:hover {
    background-color: #ffffff;
    color: #172c66;
    transform: scale(1.05);
}

/* =========================================================
   MOBILE
   JS/Turn.js remains responsible for the actual A4 size.
========================================================= */

@media (max-width: 968px) {
    /* Mobile dimensions are set by the working template's JavaScript.
       Do not override Turn.js with a viewport-height rule here. */
    .flipbook {
        max-width: none;
        max-height: none;
        touch-action: auto;
    }
}

/* =========================================================
   PROGRESS
========================================================= */

.progress-container {
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    position: relative;
    z-index: 20;
}

progress {
    width: 200px;
    height: 10px;
}

/* =========================================================
   CREDIT
========================================================= */

.credit {
    margin-top: 12px;
    margin-left: auto;
    margin-right: auto;

    font-size: 20px;
    font-family: 'Noto Nastaliq Urdu', serif;

    direction: rtl;
    text-align: center;

    background: linear-gradient(
        90deg,
        #000000,
        #555555,
        #000000
    );

    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;

    background-size: 200% auto;

    animation:
        typing 3s steps(30, end) forwards,
        fadeScale 3s ease forwards,
        shine 3s linear infinite;

    animation-delay: 0s, 0s, 3s;

    white-space: nowrap;
    overflow: hidden;

    width: 0;
    opacity: 0;

    display: block;
    max-width: 120vw;
}

@keyframes typing {
    from {
        width: 0;
    }

    to {
        width: 20em;
    }
}

@keyframes fadeScale {
    0% {
        opacity: 0;
        transform: scale(0.95);
    }

    50% {
        opacity: 1;
        transform: scale(1.05);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes shine {
    0% {
        background-position: 0% center;
    }

    100% {
        background-position: 200% center;
    }
}

/* =========================================================
   ZOOM
========================================================= */

.zoomed {
    cursor: grab;
}

.zoomed:active {
    cursor: grabbing;
}

#zoom-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;

    transform: translateX(-50%);

    background: rgba(0, 0, 0, 0.75);
    color: white;

    padding: 10px 16px;
    border-radius: 8px;

    font-size: 14px;

    opacity: 0;
    pointer-events: none;

    transition: opacity 0.5s ease;

    z-index: 9999;
}

#zoom-toast.show {
    opacity: 1;
}

/* =========================================================
   PHONE
========================================================= */

@media (max-width: 768px) {
    #main-container {
        padding: 0;
        margin: 0 auto;
    }

    #magazine-container {
        width: 100%;
        max-width: 95vw;
        margin: 0 auto;
    }

    /* Do not impose the final height here.
       The working HTML calculates true A4 dimensions in JS. */
    .flipbook {
        width: min(92vw, 380px) !important;
        height: auto !important;
        max-width: none;
        max-height: none;
        aspect-ratio: 210 / 297;
    }

    /* Hide only the visual loading bar on phones.
       Image preloading still happens in JavaScript. */
    .progress-container {
        display: none !important;
    }

    .button-container {
        gap: 10px;
        margin-top: 5px;
    }

    .icon {
        font-size: 20px;
    }

    .home-button {
        width: 44px;
        height: 44px;
        font-size: 20px;

        top: max(15px, env(safe-area-inset-top));
        left: 15px;
    }

    .credit {
        font-size: 16px;
        margin-top: 5px;
        margin-bottom: 6px;
    }

    @keyframes typing {
        from {
            width: 0;
        }

        to {
            width: 16em;
        }
    }
}

@media (max-width: 380px) {
    .button-container {
        gap: 8px;
    }

    .icon {
        font-size: 18px;
    }

    .credit {
        font-size: 14px;
    }
}
