/* ============================================================
   Flipbook Viewer — full-viewport immersive reader
   ============================================================ */

/* Reset layout body for immersive mode */
body.flipbook-layout {
    margin: 0;
    padding: 0;
    background: #1a1a1a;
    overflow: hidden;
    font-family: inherit;
}

/* ---- Root container ---- */
#flipbook-viewer {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #1a1a1a;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
}

/* ---- Loading overlay ---- */
.flipbook-loading {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
}

.flipbook-loading__spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* ---- Error state ---- */
.flipbook-error {
    position: absolute;
    inset: 0;
    z-index: 100;
    background: #1a1a1a;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
}

.flipbook-error__content {
    padding: 2rem;
    max-width: 400px;
}

.flipbook-error__content i {
    color: rgba(255, 255, 255, 0.4);
}

/* ---- Top bar ---- */
.flipbook-topbar {
    flex-shrink: 0;
    height: 52px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 10;
}

.flipbook-topbar__back {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.flipbook-topbar__back:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.flipbook-topbar__title {
    flex: 1;
    margin: 0;
    font-size: 15px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.flipbook-topbar__actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.flipbook-topbar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    font-size: 14px;
}

.flipbook-topbar__btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* ---- Stage (scrollable page area) ---- */
.flipbook-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    padding: 16px;
    box-sizing: border-box;
}

/* ---- Flipbook container ---- */
.flipbook-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* StPageFlip canvas shadow */
.flipbook-container canvas {
    box-shadow: 0 4px 40px rgba(0, 0, 0, 0.7);
}

/* ---- Bottom navigation bar ---- */
.flipbook-navbar {
    flex-shrink: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 10;
}

.flipbook-navbar__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 14px;
    transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.flipbook-navbar__btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.flipbook-navbar__btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.flipbook-navbar__pager {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.7);
}

.flipbook-navbar__page-input {
    width: 52px;
    height: 32px;
    padding: 0 6px;
    text-align: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    -moz-appearance: textfield;
}

.flipbook-navbar__page-input::-webkit-outer-spin-button,
.flipbook-navbar__page-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.flipbook-navbar__page-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.12);
}

.flipbook-navbar__separator {
    color: rgba(255, 255, 255, 0.4);
}

.flipbook-navbar__total {
    min-width: 24px;
}

/* ---- Thumbnail strip (optional — show on hover) ---- */
.flipbook-thumbs {
    position: absolute;
    bottom: 56px;
    left: 0;
    right: 0;
    height: 80px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.flipbook-thumbs::-webkit-scrollbar { height: 4px; }
.flipbook-thumbs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.flipbook-thumbs.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.flipbook-thumb {
    flex-shrink: 0;
    width: 44px;
    height: 62px;
    border-radius: 3px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s;
}

.flipbook-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.flipbook-thumb.is-active {
    border-color: rgba(255, 255, 255, 0.6);
}

/* ---- Mobile: single-page mode ---- */
@media (max-width: 767px) {
    .flipbook-topbar {
        height: 48px;
        padding: 0 12px;
    }

    .flipbook-topbar__title {
        font-size: 13px;
    }

    .flipbook-stage {
        padding: 8px;
    }

    .flipbook-navbar {
        height: 52px;
        gap: 12px;
    }

    .flipbook-navbar__page-input {
        width: 44px;
    }
}

/* ---- Fullscreen adjustments ---- */
:-webkit-full-screen #flipbook-viewer,
:-moz-full-screen #flipbook-viewer,
:fullscreen #flipbook-viewer {
    position: fixed;
    inset: 0;
}
