:root {
    --bg-color: #0d1b2a;
    --toolbar-bg: #1b263b;
    --text-color: #e0e1dd;
    --accent: #415a77;
    --accent-hover: #778da9;
    --page-bg: #ffffff;
}

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

body,
html {
    width: 100%;
    height: 100%;
    /* Fallback */
    height: 100dvh;
    /* Exact viewport height for mobile */
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    touch-action: none;
    /* Help prevent mobile bouncy scroll */
}

body {
    display: flex;
    flex-direction: column;
}

/* Toolbar */
.toolbar {
    flex: 0 0 60px;
    width: 100%;
    height: 60px;
    background-color: var(--toolbar-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 100;
    position: relative;
}

.title {
    font-weight: 600;
    font-size: 1.1rem;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    margin: 0 1rem;
}

.controls {
    display: flex;
    gap: 0.5rem;
}

.btn {
    background-color: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s;
    text-decoration: none;
}

.btn:hover {
    background-color: var(--accent-hover);
}

.btn-back {
    background-color: transparent;
    border: 1px solid var(--accent);
}

.btn-back:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Workspace */
.workspace {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-color);
}

#zoom-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}

#flip-book {
    transition: transform 0.4s ease;
    /* Smooth centering shift on cover pages */
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    background-color: transparent;
}

.page {
    background-color: white;
    box-shadow: 0 0 1px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* Shadows specifically for StPageFlip pages */
.page::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    box-shadow: inset -10px 0 20px -10px rgba(0, 0, 0, 0.15);
    /* Right shadow on all inner */
    pointer-events: none;
}

.page.--left::after {
    box-shadow: inset 10px 0 20px -10px rgba(0, 0, 0, 0.15);
    /* Left shadow on left pages */
}

.page img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    /* Let pageFlip handle it! Critical */
    user-select: none;
    -webkit-user-drag: none;
}

.nav-overlay {
    position: absolute;
    top: 60px;
    bottom: 0;
    width: 10%;
    min-width: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: rgba(14, 165, 233, 0.4);
    /* Faint light blue for visibility on white pages */
    cursor: pointer;
    transition: all 0.3s;
    z-index: 1001;
    /* Must be >1000 so it sits on top of the drag-overlay */
}

.nav-overlay:hover {
    color: rgba(14, 165, 233, 1);
    background-color: rgba(0, 0, 0, 0.05);
}

.nav-prev {
    left: 0;
}

.nav-next {
    right: 0;
}

.page-indicator {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    z-index: 40;
    letter-spacing: 1px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .btn-zoom {
        display: none;
    }

    .title {
        font-size: 0.9rem;
    }

    .btn {
        padding: 0.4rem 0.6rem;
    }

    .btn:not(#btn-print) span {
        display: none;
    }

    #btn-print {
        padding: 0.5rem 0.8rem;
    }

    .nav-overlay {
        width: 15vw;
        background: transparent !important;
        color: rgba(14, 165, 233, 0.8);
        /* Stronger light blue arrows clearly visible on mobile */
        /* Swipes on mobile for native stPageFlip, but these catch clicks while zoomed */
    }
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-hover);
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading-overlay p {
    font-size: 1.2rem;
    color: var(--text-color);
    text-align: center;
    line-height: 1.5;
}

/* Print Styles */
@media print {
    body {
        background-color: white !important;
        overflow: auto;
        height: auto;
        display: block;
        /* Override flex */
    }

    .no-print {
        display: none !important;
    }

    .workspace {
        display: none !important;
    }

    #print-container {
        display: block !important;
    }

    .print-page {
        page-break-after: always;
        width: 100%;
        max-height: 100vh;
        object-fit: contain;
        display: block;
        margin: 0 auto;
    }
}

#print-container {
    display: none;
}