
/* Free book (flip-book reader) */

.free-title {
    margin: 0 0 8px;
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--ink);
    text-align: center;
}

.free-intro {
    margin: 0 0 24px;
    color: var(--muted);
    text-align: center;
}

.flipbook {
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

/* Flipbook stage */

.fb-stage {
    width: 100%;
    max-width: 640px;
    display: flex;
    justify-content: center;
    padding: 8px 0;
    touch-action: pan-y;
    cursor: grab;
}

.fb-stage.fb-dragging {
    cursor: grabbing;
}

/* Book */

.fb-book {
    position: relative;
    perspective: 1500px;
    width: 50%;
    aspect-ratio: 320 / 440;
    transition: transform 0.6s ease;
}

.fb-paper {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transform-origin: left;
    transition: transform 0.6s ease;
}

.fb-paper.flipped {
    transform: rotateY(-180deg);
}

/* Pages */

.fb-front,
.fb-back {
    position: absolute;
    inset: 0;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
}

.fb-front {
    z-index: 1;
}

.fb-back {
    z-index: 0;
    border-radius: 8px 0 0 8px;
    transform: rotateY(180deg);
}

.fb-cover {
    background: #1e293b;
}

/* Page content */

.fb-content {
    height: 100%;
}

.fb-canvas {
    display: block;
    width: 100%;
    height: 100%;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    pointer-events: auto;
}

/* Navigation controls */

.fb-controls {
    margin-top: 20px;
    display: flex;
    gap: 16px;
}

.fb-btn {
    padding: 10px 20px;
    font-family: inherit;
    font-weight: 600;
    font-size: 16px;
    color: #fff;
    background: #2563eb;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.fb-btn:hover:not(:disabled) {
    background: #1d4ed8;
}

.fb-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}

/* =====================================
   FULLSCREEN SINGLE-PAGE LIGHTBOX
   ===================================== */

.fb-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.96);

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

    padding: 20px;
    box-sizing: border-box;
}

/* Fullscreen page container */

.fb-fullscreen-page {
    display: flex;
    align-items: center;
    justify-content: center;

    width: min(95vw, calc(90vh * 640 / 880));
    height: min(90vh, calc(95vw * 880 / 640));

    aspect-ratio: 640 / 880;

    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

/* Page content */

.fb-fullscreen-page .fb-content {
    width: 100%;
    height: 100%;
    flex-shrink: 0;
}

/* Canvas keeps its original proportions */

.fb-fullscreen-page .fb-canvas {
    display: block;

    width: 100%;
    height: 100%;

    aspect-ratio: 640 / 880;
    object-fit: contain;
}

/* Prevent fullscreen page from inheriting book styles */

.fb-lightbox .fb-stage {
    width: min(95vw, 1600px);
    height: 82vh;

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

/* Mobile adjustments */

@media (max-width: 600px) {
    .fb-book {
        width: 50%;
    }

    .fb-lightbox {
        padding: 10px;
    }

    .fb-fullscreen-page {
        width: min(96vw, calc(94vh * 640 / 880));
        height: min(94vh, calc(96vw * 880 / 640));
    }
}


/* Full-screen page navigation */
.fb-lightbox {
    touch-action: none;
    cursor: grab;
    overflow: hidden;
}

.fb-lightbox:active {
    cursor: grabbing;
}

.fb-fullscreen-page {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 260ms ease, opacity 260ms ease;
    will-change: transform;
}

.fb-lightbox-enter-left {
    transform: translateX(-100%);
}

.fb-lightbox-enter-right {
    transform: translateX(100%);
}

.fb-lightbox-enter-active {
    transform: translateX(0);
}

.fb-lightbox-exit-left {
    transform: translateX(0);
}

.fb-lightbox-exit-right {
    transform: translateX(0);
}

.fb-lightbox-exit-left.fb-lightbox-exit-active {
    transform: translateX(-100%);
    opacity: 0.5;
}

.fb-lightbox-exit-right.fb-lightbox-exit-active {
    transform: translateX(100%);
    opacity: 0.5;
}

/* Reading progress */
.fb-lightbox-progress {
    position: absolute;
    z-index: 10000;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 12px 20px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(15, 23, 42, 0.85);
}

.fb-lightbox-progress-track {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.25);
    border-radius: 10px;
    overflow: hidden;
}

.fb-lightbox-progress-fill {
    height: 100%;
    width: 0;
    background: #ffffff;
    border-radius: 10px;
    transition: width 250ms ease;
}

.fb-lightbox-progress-label {
    color: #ffffff;
    font: 13px system-ui, sans-serif;
    white-space: nowrap;
}


/* Centre page inside fullscreen lightbox */
.fb-lightbox {
    display: flex;
    align-items: center;
    justify-content: center;
}

.fb-lightbox .fb-fullscreen-page {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: auto;
}

/* Centre the actual page content */
.fb-lightbox .fb-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    margin: 0 auto;
}

/* Keep canvas proportional and centred */
.fb-lightbox .fb-canvas {
    display: block;
    width: auto;
    height: auto;
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
    margin: auto;
}
