/* ============================================================
   CHGL Flipbook v1.2 — FlipHTML5-inspired viewer
   ============================================================ */

.chgl-flipbook-wrap {
    position: relative;
    width: 100%;
    overflow: hidden;
    background: transparent;
    user-select: none;
    -webkit-user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Background ── */
.cfb-bg {
    position: relative;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at 50% 40%, #2a2a2a 0%, #111 60%, #0a0a0a 100%);
    display: flex;
    flex-direction: column;
}

/* Light theme bg */
.chgl-flipbook-wrap[data-theme="light"] .cfb-bg {
    background: radial-gradient(ellipse at 50% 40%, #c8c0b0 0%, #9a9080 60%, #6e6558 100%);
}

/* ── Stage (book area) ── */
.cfb-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 20px 8px;
    overflow: hidden;
    position: relative;
}

/* ── Loader ── */
.cfb-loader {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: rgba(255,255,255,0.7);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    z-index: 50;
    background: inherit;
}
.chgl-flipbook-wrap[data-theme="light"] .cfb-loader { color: rgba(0,0,0,0.5); }

.cfb-spin {
    width: 32px; height: 32px;
    border: 2px solid rgba(255,255,255,0.15);
    border-top-color: #c49a4e;
    border-radius: 50%;
    animation: cfb-spin 0.8s linear infinite;
}
.chgl-flipbook-wrap[data-theme="light"] .cfb-spin {
    border-color: rgba(0,0,0,0.1);
    border-top-color: #c49a4e;
}
@keyframes cfb-spin { to { transform: rotate(360deg); } }

/* ── Book ── */
.cfb-book {
    position: relative;
    display: flex;
    align-items: stretch;
    transform-style: preserve-3d;
    /* Dropped shadow beneath book */
    filter: drop-shadow(0 20px 60px rgba(0,0,0,0.7));
}
.chgl-flipbook-wrap[data-theme="light"] .cfb-book {
    filter: drop-shadow(0 16px 40px rgba(0,0,0,0.4));
}

.cfb-book.cfb-single .cfb-page {
    box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
    border-radius: 2px;
}

/* ── Pages ── */
.cfb-page {
    position: relative;
    background: #fff;
    overflow: hidden;
    flex-shrink: 0;
}
.cfb-left  { border-radius: 2px 0 0 2px; }
.cfb-right { border-radius: 0 2px 2px 0; }

.cfb-page canvas {
    display: block;
    /* canvas sized via JS */
}

/* Inner page shadows for realism */
.cfb-shadow-l {
    position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(to right, rgba(0,0,0,0.12) 0%, transparent 30%);
}
.cfb-shadow-r {
    position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(to left, rgba(0,0,0,0.12) 0%, transparent 30%);
}

/* ── Spine ── */
.cfb-spine {
    width: 4px;
    flex-shrink: 0;
    background: linear-gradient(to right,
        rgba(0,0,0,0.25) 0%,
        rgba(0,0,0,0.08) 40%,
        rgba(255,255,255,0.06) 60%,
        rgba(0,0,0,0.2) 100%
    );
    z-index: 2;
}

/* ── Flip layer (used during animation) ── */
.cfb-flip-layer {
    position: absolute;
    pointer-events: none;
    transform-style: preserve-3d;
    z-index: 10;
    backface-visibility: hidden;
    background: #fff;
    overflow: hidden;
}
.cfb-flip-layer canvas { display: block; }

/* ── Bottom bar ── */
.cfb-bar {
    flex-shrink: 0;
    padding: 0 12px 12px;
}

.cfb-bar-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 40px;
    padding: 6px 16px;
    border: 1px solid rgba(255,255,255,0.08);
}
.chgl-flipbook-wrap[data-theme="light"] .cfb-bar-inner {
    background: rgba(20,20,20,0.82);
}

.cfb-btn {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.8);
    width: 32px; height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
    padding: 0;
}
.cfb-btn svg { width: 18px; height: 18px; fill: currentColor; }
.cfb-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
.cfb-btn:disabled { opacity: 0.25; cursor: default; pointer-events: none; }

.cfb-pager, .cfb-zoom-val {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.6);
    min-width: 56px;
    text-align: center;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.cfb-zoom-val { min-width: 38px; }

.cfb-title {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
    flex-shrink: 1;
}

.cfb-sep {
    width: 1px; height: 20px;
    background: rgba(255,255,255,0.12);
    margin: 0 6px;
    flex-shrink: 0;
}

/* ── Fullscreen ── */
.chgl-flipbook-wrap:fullscreen,
.chgl-flipbook-wrap:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
}
.chgl-flipbook-wrap:fullscreen .cfb-bg,
.chgl-flipbook-wrap:-webkit-full-screen .cfb-bg {
    height: 100vh;
}

/* ── Error ── */
.chgl-flipbook-error {
    background: #fff3f3;
    border: 1px solid #e9b4b4;
    border-radius: 4px;
    padding: 12px 16px;
    color: #a33;
    font-size: 0.85rem;
}

/* ── Mobile ── */
@media (max-width: 580px) {
    .cfb-title, .cfb-sep:last-of-type { display: none; }
    .cfb-bar-inner { padding: 6px 10px; gap: 0; }
    .cfb-btn { width: 28px; height: 28px; }
    .cfb-btn svg { width: 16px; height: 16px; }
}

/* ============================================================
   Lightbox trigger button
   ============================================================ */
.chgl-fb-trigger-wrap {
    display: inline-block;
}

.chgl-fb-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 13px 24px;
    background: #1a1a1a;
    color: #f0ece4;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.chgl-fb-trigger-btn:hover {
    background: #333;
    transform: translateY(-1px);
}
.chgl-fb-trigger-btn svg {
    width: 18px; height: 18px;
    flex-shrink: 0;
}

/* ============================================================
   Lightbox overlay
   ============================================================ */
.chgl-fb-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.chgl-fb-lightbox.is-open {
    opacity: 1;
    pointer-events: all;
}

.chgl-fb-lb-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.88);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.chgl-fb-lb-inner {
    position: relative;
    z-index: 1;
    width: 94vw;
    height: 92vh;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 32px 80px rgba(0,0,0,0.6);
    transform: scale(0.96);
    transition: transform 0.25s ease;
}
.chgl-fb-lightbox.is-open .chgl-fb-lb-inner {
    transform: scale(1);
}

/* Flipbook inside lightbox fills the inner container */
.chgl-fb-lb-inner .chgl-flipbook-wrap {
    flex: 1;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
}
.chgl-fb-lb-inner .cfb-bg {
    height: 100%;
}

.chgl-fb-lb-close {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 20;
    background: rgba(0,0,0,0.5);
    color: #fff;
    border: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.chgl-fb-lb-close:hover { background: rgba(0,0,0,0.75); }

/* Prevent body scroll when lightbox open */
body.chgl-fb-lb-open {
    overflow: hidden;
}
