/* ==========================================================================
   My FlipBook - Front-end Styles
   ========================================================================== */

/* ---------- Reset & Base ---------- */
.mfb-thumbnail-wrap,
.mfb-modal-overlay,
.mfb-modal-overlay * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ==========================================================================
   1. Thumbnail Card
   ========================================================================== */
.mfb-thumbnail-wrap {
    display: inline-block;
    position: relative;
    max-width: 200px;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
    transition: transform .3s ease, box-shadow .3s ease;
    background: #f5f5f5;
}

.mfb-thumbnail-wrap:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 30px rgba(0, 0, 0, .2);
}

.mfb-thumbnail-wrap canvas,
.mfb-thumbnail-wrap img {
    display: block;
    width: 100%;
    height: auto;
}

/* "Click to open" overlay */
.mfb-thumbnail-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .45);
    opacity: 0;
    transition: opacity .3s ease;
    pointer-events: none;
}

.mfb-thumbnail-wrap:hover .mfb-thumbnail-overlay {
    opacity: 1;
}

.mfb-thumbnail-overlay span {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .5px;
    padding: 8px 18px;
    border: 2px solid #fff;
    border-radius: 6px;
    text-transform: uppercase;
}

/* Thumbnail title */
.mfb-thumbnail-title {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    line-height: 1.4;
    text-align: center;
    background: #fff;
    border-top: 1px solid #eee;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Loading placeholder */
.mfb-thumb-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 280px;
    height: 360px;
    background: linear-gradient(135deg, #e8e8e8 0%, #f5f5f5 100%);
}

.mfb-thumb-loading .mfb-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #ccc;
    border-top-color: #555;
    border-radius: 50%;
    animation: mfb-spin 0.8s linear infinite;
}

/* ==========================================================================
   2. Modal / Overlay
   ========================================================================== */
.mfb-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .88);
    opacity: 0;
    visibility: hidden;
    transition: opacity .35s ease, visibility .35s ease;
}

.mfb-modal-overlay.mfb-active {
    opacity: 1;
    visibility: visible;
}

/* Close button */
.mfb-close-btn {
    position: absolute;
    top: 16px;
    right: 20px;
    z-index: 10;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .12);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    transition: background .25s ease;
    line-height: 1;
}

.mfb-close-btn:hover {
    background: rgba(255, 255, 255, .28);
}

/* ==========================================================================
   3. FlipBook Container
   ========================================================================== */
.mfb-book-area {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    width: 100%;
    overflow: hidden;
    padding: 5px 10px;
    user-select: none;
    -webkit-user-select: none;
}

.mfb-book-wrapper {
    transform-origin: center center;
    will-change: transform;
}

.mfb-book-container {
    /* StPageFlip renders inside this element */
    display: block;
}

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

.mfb-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ==========================================================================
   4. Control Bar
   ========================================================================== */
.mfb-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.mfb-controls button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: background .2s ease;
    white-space: nowrap;
}

.mfb-controls button:hover {
    background: rgba(255, 255, 255, .28);
}

.mfb-controls button:disabled {
    opacity: .35;
    cursor: default;
}

.mfb-page-info {
    color: rgba(255, 255, 255, .75);
    font-size: 13px;
    padding: 0 10px;
    user-select: none;
}

.mfb-zoom-display {
    color: rgba(255, 255, 255, .85);
    font-size: 13px;
    font-weight: 600;
    min-width: 50px;
    text-align: center;
    padding: 0 6px;
    user-select: none;
}

/* Divider between groups */
.mfb-ctrl-divider {
    width: 1px;
    height: 22px;
    margin: 0 6px;
    background: rgba(255, 255, 255, .2);
}

/* Close button in control bar */
.mfb-btn-close-bottom {
    background: rgba(220, 60, 60, .55) !important;
}

.mfb-btn-close-bottom:hover {
    background: rgba(220, 60, 60, .85) !important;
}

/* Download button */
.mfb-btn-download {
    background: rgba(255, 255, 255, .18) !important;
}

.mfb-btn-download:hover {
    background: rgba(255, 255, 255, .32) !important;
}

/* ==========================================================================
   5. Loading Overlay (inside modal)
   ========================================================================== */
.mfb-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
    background: rgba(0, 0, 0, .6);
    transition: opacity .3s ease;
}

.mfb-loading-overlay.mfb-hidden {
    opacity: 0;
    pointer-events: none;
}

.mfb-loading-overlay .mfb-spinner-lg {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, .2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mfb-spin 0.8s linear infinite;
}

.mfb-loading-text {
    color: rgba(255, 255, 255, .8);
    font-size: 14px;
    margin-top: 14px;
}

/* ==========================================================================
   6. Animations
   ========================================================================== */
@keyframes mfb-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   7. Responsive
   ========================================================================== */

/* ── モバイル: ブラウザのデフォルトピンチズーム無効化 ── */
.mfb-modal-overlay {
    touch-action: none;
    -webkit-touch-callout: none;
}

.mfb-book-area {
    touch-action: none;
}

/* ── 768px以下: タブレット ── */
@media (max-width: 768px) {
    .mfb-thumbnail-wrap {
        max-width: 200px;
    }

    .mfb-thumb-loading {
        width: 200px;
        height: 260px;
    }

    /* 右上の閉じるボタンを非表示（下部メニューに統合） */
    .mfb-close-btn {
        display: none;
    }

    /* コントロールバー: フレックスラップに戻して柔軟に配置 */
    .mfb-controls {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: 6px 8px;
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom, 10px));
        background: rgba(0, 0, 0, .85);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    /* 区切り線を非表示 */
    .mfb-ctrl-divider {
        display: none;
    }

    /* ボタン共通: タッチターゲット 44px 以上 */
    .mfb-controls button {
        min-width: 52px;
        height: 44px;
        padding: 0 14px;
        font-size: 15px;
        border-radius: 8px;
        -webkit-tap-highlight-color: transparent;
        flex: 1 1 auto;
        /* スペースに合わせて伸びる */
    }

    .mfb-zoom-display,
    .mfb-page-info {
        font-size: 14px;
        padding: 0 4px;
    }

    /* ナビボタンは少し大きく */
    .mfb-btn-prev,
    .mfb-btn-next {
        min-width: 70px;
    }
}

/* ── 480px以下: スマートフォン ── */
@media (max-width: 480px) {
    .mfb-thumbnail-wrap {
        max-width: 160px;
    }

    .mfb-thumb-loading {
        width: 160px;
        height: 210px;
    }

    .mfb-controls {
        gap: 5px 6px;
        padding: 8px 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }

    .mfb-controls button {
        min-width: 44px;
        height: 42px;
        padding: 0 10px;
        font-size: 14px;
    }

    .mfb-btn-prev,
    .mfb-btn-next {
        min-width: 64px;
    }

    .mfb-page-info {
        font-size: 13px;
    }

    .mfb-zoom-display {
        font-size: 13px;
    }
}