/* ---------- Flip book viewer (flip_book_view.php) ---------- */

.flipbook, .flipbook *, .flipbook *::before, .flipbook *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

.viewer-body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: radial-gradient(ellipse at 50% 38%, #fbf6ea 0%, #efe4cf 55%, #e3d5b8 100%);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

.flipbook {
    -webkit-user-select: none;
    user-select: none;
}

.controls button {
    touch-action: manipulation;
}

.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    color: #2b2620;
    background: #fffaf1;
    width: 100%;
    gap: 12px;
    box-sizing: border-box;
    box-shadow: 0 2px 10px rgba(43, 38, 32, 0.08);
    position: relative;
    z-index: 5;
}

.viewer-header h1 {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
}

.viewer-header-actions {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
}

.new-book-link {
    color: #6b6255;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid #d8cdb8;
    padding: 7px 16px;
    border-radius: 20px;
    background: #fff;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}

.new-book-link:hover {
    background: #2b2620;
    color: #f4f1ea;
    border-color: #2b2620;
}

.viewer-status-banner {
    width: 100%;
    max-width: 1040px;
    background: #fdeaea;
    color: #8a1f1f;
    padding: 10px 16px;
    box-sizing: border-box;
    text-align: center;
    font-size: 14px;
    margin-top: 12px;
    border-radius: 8px;
}

.flipbook-container {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    min-height: 0; /* allow flex child to shrink instead of overflowing */

    margin: 0 auto;
    overflow: hidden; /* never scroll, in either direction */

    border-radius: 0px;
    box-sizing: border-box;
    padding: 10px 10px 96px; /* reserve room for the floating controls + shadow */
}

.flipbook-container::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 100px;
    transform: translateX(-50%);
    width: min(70%, 620px);
    height: 40px;
    background: radial-gradient(ellipse at center, rgba(43, 38, 32, 0.30) 0%, rgba(43, 38, 32, 0) 72%);
    filter: blur(2px);
    pointer-events: none;
}

.flipbook {
    max-width: 100%;
    max-height: 100%;
    margin: 0 auto;
    position: relative;
    box-shadow: 0 18px 34px rgba(43, 38, 32, 0.35);
}

.flipbook .page {
    background: #fdfbf6;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.flipbook .page-cover {
    background: #2b2620;
    color: #f4f1ea;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    box-shadow: inset 0 0 0 6px rgba(244, 241, 234, 0.06);
}

.flipbook .page-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cover-content h2 {
    font-size: 22px;
    margin-bottom: 6px;
}

.flipbook .image-page {
    padding: 0;
}

.flipbook .image-page img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.flipbook .image-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e7e1d3;
    color: #948b7c;
    font-size: 14px;
    text-align: center;
    padding: 12px;
}

.flipbook .text-page {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 30px 26px 24px;
    position: relative;
    min-height: 100%;
    height: 100%;
    background: #fdfbf6 linear-gradient(90deg, rgba(43,38,32,0.05), rgba(43,38,32,0) 18px);
}

.flipbook .page-content {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 15px;
    line-height: 1.8;
    color: #362f27;
    overflow-wrap: break-word;
    word-break: break-word;
    max-height: calc(100% - 20px);    
    /*overflow-y: auto;*/
    width: 100%;
    padding-right: 6px;
}

.flipbook .page-number {
    position: absolute;
    bottom: 12px;
    right: 18px;
    font-size: 11px;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: #a89a80;
    background: #f4efe3;
    padding: 2px 9px;
    border-radius: 10px;
}

.controls {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    background: #2b2620;
    padding: 6px;
    border-radius: 30px;
    box-shadow: 0 8px 20px rgba(43, 38, 32, 0.35);
    z-index: 10;
}

.controls button {
    padding: 9px 18px;
    background: transparent;
    color: #f4f1ea;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s ease;
}

.controls button:hover {
    background: rgba(244, 241, 234, 0.14);
}

.controls button:active {
    background: rgba(244, 241, 234, 0.22);
}

#pageIndicator {
    color: #cfc4ad;
    font-size: 13px;
    font-weight: 600;
    padding: 0 8px;
    min-width: 44px;
    text-align: center;
}

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
    .viewer-header {
        padding: 10px 12px;
        gap: 8px;
    }

    .viewer-header h1 {
        font-size: 16px;
    }

    .new-book-link {
        font-size: 12px;
        padding: 6px 12px;
    }

    .viewer-status-banner {
        font-size: 13px;
        padding: 8px 12px;
        margin: 8px 10px 0;
        width: auto;
    }

    .flipbook-container {
        padding: 6px 4px 88px;
    }

    .flipbook-container::before {
        bottom: 90px;
        width: 60%;
        height: 26px;
    }

    .flipbook .text-page {
        padding: 20px 16px 20px;
    }

    .flipbook .page-content {
        font-size: 14px;
        line-height: 1.65;
        max-height: calc(100% - 30px);
    }

    .flipbook .page-number {
        bottom: 8px;
        right: 12px;
    }

    .controls {
        bottom: 14px;
        gap: 2px;
        padding: 5px;
    }

    .controls button {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 44px; /* comfortable touch target */
    }

    #pageIndicator {
        font-size: 12px;
        min-width: 36px;
        padding: 0 4px;
    }
}

@media (max-width: 360px) {
    .viewer-header h1 {
        font-size: 14px;
    }

    .new-book-link span.full-label {
        display: none;
    }
}
