:root {
    color-scheme: dark;

    --app-bg: #10131b;
    --text: #f5f7fb;
    --muted: #aab2c2;
    --accent: #35c6b0;
    --panel-border: rgba(255, 255, 255, .10);
    --page-ratio: .70654296875;

    font-family: Poppins, Inter, system-ui, -apple-system,
                 BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--app-bg);
}

body {
    color: var(--text);
}

button,
a,
input {
    font: inherit;
}

button {
    color: inherit;
}

#flipbookApp {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;

    background:
        radial-gradient(
            ellipse at 50% 35%,
            #252b3b 0%,
            #151923 52%,
            #0d1016 100%
        );
}

/* TOP TOOLBAR */

.toolbar {
    z-index: 50;
    flex: 0 0 62px;
    width: 100%;

    display: flex;
    align-items: center;
    gap: 12px;

    padding: 8px 18px;

    border-bottom: 1px solid var(--panel-border);
    background: rgba(13, 16, 23, .88);

    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.toolbar-navigation {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-spacer {
    flex: 1;
}

.toolbar-btn {
    width: 42px;
    height: 42px;
    flex: 0 0 auto;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 12px;

    background: rgba(255, 255, 255, .07);
    color: var(--text);

    text-decoration: none;
    font-size: 25px;
    line-height: 1;

    cursor: pointer;

    transition:
        background .18s ease,
        border-color .18s ease,
        transform .18s ease;
}

.toolbar-btn:hover:not(:disabled) {
    background: rgba(53, 198, 176, .18);
    border-color: rgba(53, 198, 176, .6);
}

.toolbar-btn:active:not(:disabled) {
    transform: scale(.96);
}

.toolbar-btn:disabled,
.bottom-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
}

.home-btn {
    font-size: 27px;
}

.page-counter {
    min-width: 70px;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    color: #fff;
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.counter-divider {
    color: #758093;
    font-weight: 400;
}

/* BOOK AREA */

#book-area {
    position: relative;
    isolation: isolate;

    flex: 1 1 auto;
    min-height: 0;
    width: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 8px 12px;
    overflow: hidden;

    touch-action: none;
}

#book {
    --page-ratio: .70654296875;

    position: relative;
    flex: 0 0 auto;

    display: block;

    height: min(calc(100dvh - 145px), 78vh);

    width: calc(
        min(calc(100dvh - 145px), 78vh)
        * 2
        * var(--page-ratio)
    );

    max-width: calc(100vw - 24px);

    aspect-ratio: calc(2 * var(--page-ratio)) / 1;

    margin: 0 auto;
    background: transparent;

    box-shadow: 0 24px 60px rgba(0, 0, 0, .45);

    transform: translate3d(0, 0, 0) scale(1);
    transform-origin: center center;

    will-change: transform;
    z-index: 2;
}

/* PAGE IMAGES */

.flip-page {
    position: relative;
    overflow: hidden;

    background: #fff;

    margin: 0;
    padding: 0;
    border: 0;
}

.flip-page img {
    display: block;

    width: 100%;
    height: 100%;
    max-width: none;

    margin: 0;
    padding: 0;
    border: 0;

    object-fit: fill;

    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;

    pointer-events: none;

    image-rendering: auto;
}

#book .stf__parent {
    margin: 0 !important;
    background: transparent !important;
}

#book .stf__block {
    background: transparent !important;
}

#book .stf__item {
    background: #fff;
}

#book canvas {
    display: block !important;
    background: transparent !important;
}

/* ZOOM GESTURE LAYER */

#gestureLayer {
    display: none;

    position: absolute;
    inset: 0;

    z-index: 20;

    background: transparent;
    touch-action: none;

    cursor: grab;

    user-select: none;
    -webkit-user-select: none;
}

#gestureLayer:active {
    cursor: grabbing;
}

#book-area.is-zoomed #gestureLayer {
    display: block;
}

#book-area.is-zoomed #book {
    box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}

/* ZOOM CONTROLS */

#zoomControls {
    position: absolute;
    z-index: 35;

    right: 20px;
    bottom: 18px;

    display: flex;
    align-items: center;
    gap: 5px;

    padding: 6px;

    border: 1px solid var(--panel-border);
    border-radius: 14px;

    background: rgba(17, 21, 30, .92);

    box-shadow: 0 8px 28px rgba(0, 0, 0, .25);

    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}

#zoomControls button {
    min-width: 34px;
    height: 32px;

    padding: 0 9px;

    border: 0;
    border-radius: 8px;

    background: rgba(255, 255, 255, .08);
    color: #fff;

    font-size: 17px;
    cursor: pointer;
}

#zoomControls button:hover:not(:disabled) {
    background: rgba(53, 198, 176, .22);
}

#zoomControls button:disabled {
    opacity: .35;
    cursor: not-allowed;
}

#zoomControls #zoomReset {
    font-size: 12px;
    font-weight: 600;
}

#zoomLevel {
    min-width: 46px;
    text-align: center;

    color: #e3e8f0;
    font-size: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* LOADING AND ERROR MESSAGES */

#loading,
#loadError {
    position: absolute;
    z-index: 40;

    left: 50%;
    top: 50%;

    transform: translate(-50%, -50%);

    padding: 14px 20px;

    border: 1px solid var(--panel-border);
    border-radius: 14px;

    background: rgba(13, 16, 23, .94);
    color: #fff;

    text-align: center;

    box-shadow: 0 12px 36px rgba(0, 0, 0, .3);
}

#loadError {
    max-width: min(90vw, 440px);

    display: flex;
    flex-direction: column;
    gap: 7px;
}

#loadError[hidden] {
    display: none;
}

#loadError span {
    color: var(--muted);
    font-size: 13px;
}

/* BOTTOM NAVIGATION */

.bottom-bar {
    z-index: 50;
    flex: 0 0 64px;

    display: flex;
    align-items: center;
    gap: 14px;

    padding: 9px 18px;

    border-top: 1px solid var(--panel-border);
    background: rgba(13, 16, 23, .90);

    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.bottom-btn {
    flex: 0 0 auto;

    min-width: 90px;
    height: 38px;

    padding: 0 14px;

    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 10px;

    background: rgba(255, 255, 255, .06);
    color: #f4f6fa;

    font-size: 13px;
    font-weight: 600;

    cursor: pointer;
}

.bottom-btn:hover:not(:disabled) {
    border-color: rgba(53, 198, 176, .6);
    background: rgba(53, 198, 176, .14);
}

#pageSlider {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;

    accent-color: var(--accent);
    cursor: pointer;
}

/* MOBILE */

@media (max-width: 767px) {
    .toolbar {
        flex-basis: 54px;
        gap: 8px;
        padding: 6px 10px;
    }

    .toolbar-btn {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        font-size: 22px;
    }

    .home-btn {
        font-size: 24px;
    }

    .toolbar-navigation {
        gap: 6px;
    }

    .page-counter {
        min-width: 52px;
        gap: 5px;
        font-size: 12px;
    }

    #book-area {
        padding: 4px 8px 54px;
    }

    #book {
        height: min(calc(100dvh - 132px), 82vh);

        width: calc(
            min(calc(100dvh - 132px), 82vh)
            * var(--page-ratio)
        );

        max-width: calc(100vw - 16px);

        aspect-ratio: var(--page-ratio) / 1;

        box-shadow: 0 15px 40px rgba(0, 0, 0, .45);
    }

    .bottom-bar {
        flex-basis: 58px;
        gap: 8px;
        padding: 7px 9px;
    }

    .bottom-btn {
        min-width: 70px;
        height: 35px;
        padding: 0 8px;
        font-size: 12px;
    }

    #zoomControls {
        right: 10px;
        bottom: 9px;
        gap: 4px;
        padding: 5px;
        border-radius: 12px;
    }

    #zoomControls button {
        min-width: 32px;
        height: 30px;
        padding: 0 7px;
    }

    #zoomControls #zoomReset {
        font-size: 11px;
    }

    #zoomLevel {
        min-width: 40px;
        font-size: 11px;
    }
}

@media (max-width: 360px) {
    .toolbar {
        gap: 5px;
        padding-inline: 7px;
    }

    .toolbar-btn {
        width: 32px;
        height: 32px;
    }

    .bottom-btn {
        min-width: 60px;
        font-size: 11px;
    }

    #zoomControls {
        right: 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
    }
}