:root {
    --fb-ink: #222;
    --fb-muted: rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #e8e8e8;
    color: var(--fb-ink);
    font-family: Arial, Helvetica, sans-serif;
}

.fb-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-color: #e8e8e8;
    background-image: url("../img/bg.png");
    background-repeat: repeat;
    background-position: center;
    background-size: 456px 487px;
}

.fb-vignette {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: radial-gradient(
        ellipse 75% 65% at 50% 48%,
        transparent 40%,
        rgba(0, 0, 0, 0.08) 100%
    );
}

.app {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
}

.stage {
    position: relative;
    width: 100%;
    height: calc(100% - 54px);
    overflow: hidden;
}

.loader {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(380px, 90vw);
    text-align: center;
    z-index: 3;
}

.loader-logo {
    display: block;
    width: min(320px, 80vw);
    height: auto;
    margin: 0 auto 16px;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
}

.loader-text,
.loader-meta {
    margin: 0;
    color: var(--fb-muted);
    font-size: 12px;
}

.loader-meta {
    margin-top: 12px;
    font-size: 11px;
    letter-spacing: 0.04em;
}

.progress {
    margin-top: 14px;
    height: 4px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.14);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: #333;
    transition: width 0.2s ease;
}

.book-wrap {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.book {
    position: relative;
    pointer-events: auto;
    transition: transform 0.35s ease;
    will-change: transform;
}

.book .stf__parent {
    margin: 0 auto !important;
}

.book .stf__wrapper,
.book .stf__block {
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28), 0 2px 8px rgba(0, 0, 0, 0.12);
}

.book .page {
    background: #fff;
    overflow: hidden;
}

.book .page img,
.book .page canvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.book .stf__outerShadow,
.book .stf__innerShadow,
.book .stf__hardOuterShadow,
.book .stf__hardInnerShadow {
    opacity: 1 !important;
}

.book .stf__item.--left {
    box-shadow: inset -18px 0 28px -18px rgba(0, 0, 0, 0.28);
}

.book .stf__item.--right {
    box-shadow: inset 18px 0 28px -18px rgba(0, 0, 0, 0.28);
}

.book .spine {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 28px;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 5;
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.07) 35%,
        rgba(0, 0, 0, 0.16) 50%,
        rgba(0, 0, 0, 0.07) 65%,
        rgba(0, 0, 0, 0) 100%
    );
    opacity: 0;
    transition: opacity 0.25s ease;
}

.book.is-spread .spine {
    opacity: 0.9;
}

.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 6;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.18);
    color: rgba(255, 255, 255, 0.95);
    display: grid;
    place-items: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.25s ease, background 0.2s ease;
}

.stage:hover .nav-arrow,
.nav-arrow:focus-visible {
    opacity: 1;
}

.nav-arrow:hover {
    background: rgba(0, 0, 0, 0.35);
}

.nav-prev { left: 14px; }
.nav-next { right: 14px; }

.page-badge {
    position: absolute;
    left: 50%;
    bottom: 66px;
    transform: translateX(-50%);
    z-index: 6;
    font-size: 12px;
    letter-spacing: 0.04em;
    color: rgba(0, 0, 0, 0.55);
    background: rgba(255, 255, 255, 0.55);
    border-radius: 999px;
    padding: 5px 12px;
    user-select: none;
    opacity: 0;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(4px);
}

.bottom-toolbar {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    z-index: 8;
    height: 38px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

.tool-btn {
    appearance: none;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #777;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.18s ease, color 0.18s ease;
}

.tool-btn:hover {
    background: rgba(0, 0, 0, 0.07);
    color: #444;
}

.tool-btn.active {
    background: rgba(0, 0, 0, 0.12);
    color: #2f2f2f;
}

.thumbs-panel {
    position: absolute;
    left: 10px;
    top: 10px;
    bottom: 58px;
    width: min(340px, calc(100vw - 20px));
    z-index: 8;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
    padding: 10px 8px 8px;
    overflow: hidden;
}

.thumbs-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.thumbs-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 30px;
    color: #2d3742;
    font-weight: 700;
}

.thumbs-title span {
    font-size: 30px;
}

.thumbs-close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #b6bcc4;
    font-size: 34px;
    line-height: 1;
    cursor: pointer;
}

.thumbs-close:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #8f97a1;
}

.thumbs-grid {
    height: calc(100% - 44px);
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-right: 4px;
}

.thumb-btn {
    border: 1px solid rgba(0, 0, 0, 0.14);
    border-radius: 0;
    background: #fff;
    padding: 3px;
    cursor: pointer;
    width: 100%;
}

.thumb-btn img {
    width: calc(100% - 2px);
    display: block;
    margin: 0 auto;
    border-radius: 0;
}

.thumb-num {
    display: block;
    margin-top: 6px;
    font-size: 33px;
    color: #5b6572;
    text-align: center;
}

.stage:hover .page-badge {
    opacity: 1;
}

.page-badge .slash {
    margin: 0 3px;
    opacity: 0.7;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 720px) {
    .stage {
        height: calc(100% - 48px);
    }

    .bottom-toolbar {
        bottom: 6px;
        height: 34px;
        gap: 4px;
        padding: 0 5px;
    }

    .tool-btn {
        width: 26px;
        height: 26px;
    }

    .thumbs-panel {
        left: 6px;
        top: 6px;
        bottom: 44px;
        width: calc(100vw - 12px);
        padding: 8px 6px;
    }

    .thumbs-title,
    .thumbs-title span {
        font-size: 21px;
    }

    .thumb-num {
        font-size: 24px;
    }

    .nav-arrow {
        opacity: 0.75;
        width: 38px;
        height: 38px;
    }

    .nav-prev { left: 4px; }
    .nav-next { right: 4px; }

    .page-badge {
        opacity: 0.9;
        bottom: 52px;
    }

    .book .spine {
        width: 16px;
    }
}
