body {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 50%, #90caf9 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    color: #1a237e;
    margin: 0;
    font-family: sans-serif;
}

.book-wrapper {
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
}

.my-page {
    position: relative;
    overflow: visible;
}


/* Căn giữa trang bìa khi sách chưa mở */
.stf__wrapper {
    justify-content: center !important;
}

/* Ẩn trang bên trái khi đang ở chế độ bìa (cover-mode) */
#my-book.cover-mode .stf__wrapper {
    justify-content: center !important;
}

/* Ẩn block bên trái khi ở chế độ bìa */
#my-book.cover-mode .stf__block.stf__item--left {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Giới hạn kích thước container sách */
#my-book {
    flex: 1;
    max-width: calc(95vw - 160px);
    /* Trừ đi khoảng trống cho 2 nút */
    max-height: 85vh;
    min-width: 70vw;
    min-height: 60vh;
}

#my-book.hidden {
    display: none;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

.loading .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(25, 118, 210, 0.2);
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading .loading-text {
    font-size: 14px;
    color: #1565c0;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading.hidden {
    display: none;
}

.error-msg {
    color: #ff4444;
    background: #330000;
    padding: 15px;
    border-radius: 5px;
    display: none;
    margin-top: 10px;
    border: 1px solid red;
}

/* Trang bìa và trang cuối có màu xanh */
.my-page.cover-page {
    background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
}

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

.page-number {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* Container chính chứa sách và nút điều hướng */
.flipbook-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    position: relative;
    width: 95vw;
    height: 85vh;
}

/* Nút điều hướng prev/next */
.nav-btn {
    background: rgba(25, 118, 210, 0.2);
    border: none;
    color: #1565c0;
    font-size: 40px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-btn:hover {
    background: rgba(25, 118, 210, 0.4);
    color: #0d47a1;
    transform: scale(1.1);
}

.nav-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.nav-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.nav-btn.hidden {
    display: none;
}

/* Hiệu ứng bóng mờ ở giữa sách (book spine) */
#my-book::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 100%;
    background: linear-gradient(to right,
            rgba(0, 0, 0, 0.15) 0%,
            rgba(0, 0, 0, 0.05) 30%,
            rgba(0, 0, 0, 0) 50%,
            rgba(0, 0, 0, 0.05) 70%,
            rgba(0, 0, 0, 0.15) 100%);
    pointer-events: none;
    z-index: 100;
}

/* Ẩn hiệu ứng spine khi ở trang bìa */
#my-book.cover-mode::after {
    display: none;
}

/* Đảm bảo sách có position relative */
#my-book {
    position: relative;
}

/* ==================== RESPONSIVE MOBILE ==================== */

/* Tablet (max-width: 1024px) */
@media (max-width: 1024px) {
    .flipbook-container {
        width: 98vw;
        height: 80vh;
        gap: 10px;
    }

    #my-book {
        min-width: 60vw;
        max-width: calc(98vw - 140px);
    }

    .nav-btn {
        width: 50px;
        height: 50px;
    }

    .nav-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* Mobile (max-width: 768px) */
@media (max-width: 768px) {
    .flipbook-container {
        flex-direction: column;
        width: 100vw;
        height: auto;
        min-height: 85vh;
        gap: 15px;
        padding: 10px;
        box-sizing: border-box;
    }

    #my-book {
        min-width: 90vw;
        max-width: 90vw;
        /* Giảm chiều cao xuống ~60% so với trước để sách nằm ngang hơn trên mobile */
        min-height: 36vh;
        max-height: 45vh;
        order: 1;
        flex: none;
    }

    .nav-btn {
        width: 45px;
        height: 45px;
    }

    /* Di chuyển nút sang container riêng ở dưới */
    #prev-btn {
        order: 2;
        position: fixed;
        bottom: 20px;
        left: 20px;
    }

    #next-btn {
        order: 3;
        position: fixed;
        bottom: 20px;
        right: 20px;
    }

    .loading .spinner {
        width: 40px;
        height: 40px;
    }

    /* Trên mobile luôn 1 trang nên ẩn hiệu ứng spine */
    #my-book::after {
        display: none;
    }

    /* Trên mobile luôn căn giữa vì 1 trang */
    #my-book .stf__wrapper {
        justify-content: center !important;
    }
}

/* Small Mobile (max-width: 480px) */
@media (max-width: 480px) {
    .flipbook-container {
        padding: 5px;
    }

    #my-book {
        min-height: 45vh;
        max-height: 65vh;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
        bottom: 15px;
    }

    #prev-btn {
        left: 15px;
    }

    #next-btn {
        right: 15px;
    }

    .nav-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Ẩn hiệu ứng spine trên mobile nhỏ */
    #my-book::after {
        display: none;
    }
}
