/* ==========================================================
   TULMS EBOOK READER - MODERN MINIMALIST THEME
   Tối ưu không gian hiển thị, thanh thoát, nút nhỏ gọn tinh tế
   ========================================================== */

.tulms-ebook-app-container {
    --eb-bg-app: #15171c;
    --eb-page-bg: #f9f4ec; /* Giấy ngà tự nhiên */
    --eb-page-text: #2c323f;
    --eb-border-subtle: rgba(255, 255, 255, 0.08);
    --eb-font-serif: 'Merriweather', Georgia, serif;
    --eb-font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
    --eb-primary: #2563eb;

    position: relative;
    width: 100%;
    height: 100%;
    min-height: 620px;
    background: var(--eb-bg-app);
    color: #e2e8f0;
    font-family: var(--eb-font-sans);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    box-sizing: border-box;
}

/* Các chế độ màu giấy */
.tulms-ebook-app-container.theme-sepia {
    --eb-page-bg: #f5eedc;
    --eb-page-text: #32251a;
}
.tulms-ebook-app-container.theme-white {
    --eb-page-bg: #ffffff;
    --eb-page-text: #1a202c;
}
.tulms-ebook-app-container.theme-dark {
    --eb-bg-app: #0d1117;
    --eb-page-bg: #1e2430;
    --eb-page-text: #e6edf3;
    --eb-border-subtle: rgba(255, 255, 255, 0.12);
}

/* HEADER TOOLBAR TINH GỌN (44px, luôn cố định ở trên cùng) */
.tulms-reader-header {
    height: 44px;
    flex-shrink: 0;
    background: rgba(21, 23, 28, 0.96);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--eb-border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    position: relative;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ebook-heading {
    font-size: 13.5px;
    font-weight: 600;
    color: #f1f5f9;
    letter-spacing: -0.2px;
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Cụm điều khiển Zoom (In / Out / Reset) */
.zoom-controls-group {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 2px;
    gap: 2px;
}
.zoom-controls-group .btn-ctrl {
    border: none;
    background: transparent;
    padding: 0 6px;
    height: 26px;
    min-width: 26px;
    justify-content: center;
}
.zoom-controls-group .btn-ctrl:hover {
    background: rgba(255, 255, 255, 0.12);
}
.zoom-controls-group .btn-ctrl:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.zoom-label {
    font-size: 11px;
    font-weight: 600;
    font-family: monospace;
    min-width: 36px;
    text-align: center;
    color: #38bdf8;
}

/* Nút bấm tinh gọn (compact button, viền 1px thanh mảnh) */
.btn-ctrl {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
    height: 30px;
    padding: 0 10px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.15s ease;
    text-decoration: none;
}
.btn-ctrl:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.2);
}
.btn-cta-highlight {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    border: none;
    color: #fff !important;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.btn-cta-highlight:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
}

/* SÂN KHẤU SÁCH LẬT (STAGE) - TỐI ƯU TOÀN MÀN HÌNH CHUẨN HEYZINE */
.tulms-book-stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 6px 12px;
    perspective: 2500px;
    overflow: hidden;
    width: 100%;
    height: calc(100vh - 44px - 36px);
    box-sizing: border-box;
    touch-action: none;
}

/* VỎ BỌC ZOOM & PAN TƯƠNG TÁC (TẦNG VIEWPORT ĐỘC LẬP) */
.tulms-zoom-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    transform-origin: center center;
    transition: transform 0.12s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: transform;
}

/* Khi đang phóng to (zoom > 1.0x), chuyển chuột sang grab để kéo rê */
.tulms-book-stage.is-zoomed {
    cursor: grab;
}
.tulms-book-stage.is-zoomed.is-panning {
    cursor: grabbing;
    user-select: none;
}
.tulms-book-stage.is-zoomed.is-panning .tulms-zoom-container {
    transition: none !important; /* Kéo rê tức thì không delay */
}

/* KHÓA HOÀN TOÀN TƯƠNG TÁC LẬT TRANG 3D KHI ĐANG ZOOM IN - CHO PHÉP RÊ TAY TỰ DO KHÔNG LẬT */
.tulms-book-stage.is-zoomed .tulms-flipbook-host,
.tulms-book-stage.is-zoomed .tulms-flipbook-host *,
.tulms-book-stage.is-zoomed .stf__parent,
.tulms-book-stage.is-zoomed .stf__wrapper,
.tulms-book-stage.is-zoomed .stf__block,
.tulms-book-stage.is-zoomed .stf__item,
.tulms-book-stage.is-zoomed canvas {
    pointer-events: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    touch-action: none !important;
}

.tulms-flipbook-host {
    margin: auto !important;
    box-shadow: 0 20px 60px rgba(0,0,0,0.65), 0 0 25px rgba(0,0,0,0.3);
    border-radius: 4px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Đảm bảo các wrapper nội bộ của StPageFlip luôn căn giữa */
.stf__parent {
    margin: auto !important;
}

.stage-nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 30;
    transition: all 0.2s ease;
    backdrop-filter: blur(6px);
}
.stage-nav-arrow:hover {
    background: var(--eb-primary);
    color: #fff;
    border-color: var(--eb-primary);
    transform: translateY(-50%) scale(1.06);
}
.stage-nav-arrow.btn-prev { left: 16px; }
.stage-nav-arrow.btn-next { right: 16px; }

/* TRANG SÁCH LẬT 3D */
.tulms-page-item {
    background-color: #ffffff;
    color: var(--eb-page-text);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: inset 0 0 25px rgba(0,0,0,0.02);
    position: relative;
}

.tulms-page-item.--left {
    border-right: 1px solid rgba(0,0,0,0.08);
    background-image: linear-gradient(to right, rgba(0,0,0,0) 94%, rgba(0,0,0,0.05) 100%);
}
.tulms-page-item.--right {
    border-left: 1px solid rgba(0,0,0,0.08);
    background-image: linear-gradient(to left, rgba(0,0,0,0) 94%, rgba(0,0,0,0.05) 100%);
}

.tulms-page-item canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* SKELETON PLACEHOLDER KHI TRANG ĐANG CHỜ RENDER */
.page-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    color: #94a3b8;
    font-size: 13px;
    gap: 8px;
}
.page-placeholder .spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* FOOTER THANH TIẾN ĐỘ & SCRUBBER */
.tulms-reader-footer {
    height: 36px;
    flex-shrink: 0;
    background: rgba(21, 23, 28, 0.96);
    border-top: 1px solid var(--eb-border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    font-size: 11.5px;
    color: #94a3b8;
    z-index: 100;
    position: relative;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.28s ease;
}

.footer-progress {
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-track {
    width: 140px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 99px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--eb-primary);
    width: 0%;
    transition: width 0.25s ease;
}

/* THANH TRƯỢT LƯỚT NHANH (PAGE SCRUBBER) CHO DI ĐỘNG */
.footer-scrubber-wrap {
    display: none;
    align-items: center;
    gap: 6px;
    flex: 1;
    max-width: 240px;
    position: relative;
}
.scrubber-track-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}
.tulms-page-scrubber {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.16);
    border-radius: 99px;
    outline: none;
    cursor: pointer;
    margin: 0;
    transition: background 0.15s ease;
}
.tulms-page-scrubber:hover, .tulms-page-scrubber:active {
    background: rgba(255, 255, 255, 0.26);
}
.tulms-page-scrubber::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #38bdf8;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45);
    cursor: pointer;
    border: 2px solid #ffffff;
    transition: transform 0.12s ease;
}
.tulms-page-scrubber::-webkit-slider-thumb:active {
    transform: scale(1.22);
    background: #0284c7;
}
.tulms-page-scrubber::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #38bdf8;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45);
    cursor: pointer;
    border: 2px solid #ffffff;
}
.scrubber-bubble {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: #0f172a;
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.4);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    box-shadow: 0 4px 14px rgba(0,0,0,0.4);
    z-index: 120;
}
.scrubber-bubble::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px;
    border-style: solid;
    border-color: #0f172a transparent transparent transparent;
}
.scrubber-track-container.is-scrubbing .scrubber-bubble {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.btn-scrub-nav {
    background: transparent;
    border: none;
    color: #94a3b8;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    transition: all 0.15s ease;
}
.btn-scrub-nav:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* BACKDROP VÀ DRAWER MỤC LỤC */
.tulms-toc-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 55;
}
.tulms-toc-backdrop.active,
.tulms-toc-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.tulms-toc-drawer {
    position: absolute;
    top: 44px;
    left: 0;
    transform: translateX(-105%);
    width: 280px;
    height: calc(100% - 44px - 36px);
    background: #181b22;
    border-right: 1px solid var(--eb-border-subtle);
    box-shadow: none;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease, visibility 0.25s;
    z-index: 60;
    display: flex;
    flex-direction: column;
    visibility: hidden;
    pointer-events: none;
}
.tulms-toc-drawer.open {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0,0,0,0.5);
    visibility: visible;
    pointer-events: auto;
}
.toc-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--eb-border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 700;
    color: #f1f5f9;
}
.btn-close-toc {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-close-toc:hover { color: #fff; }
.toc-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.toc-chapter-item {
    padding: 9px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    color: #cbd5e1;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}
.toc-chapter-item:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}
.toc-chapter-item.active {
    background: rgba(37, 99, 235, 0.18);
    color: #38bdf8;
    font-weight: 700;
    border-left: 3px solid #38bdf8;
}

/* VÙNG CẢM ỨNG CHẠM MÉP (EDGE TAP ZONES) */
.tulms-tap-zone {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 25;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.tulms-tap-zone.tap-zone-prev {
    left: 0;
    width: 18%;
    cursor: pointer;
}
.tulms-tap-zone.tap-zone-next {
    right: 0;
    width: 18%;
    cursor: pointer;
}
.tulms-tap-zone.tap-zone-center {
    left: 18%;
    right: 18%;
    z-index: 24;
    cursor: default;
}
.tulms-book-stage.is-zoomed .tulms-tap-zone {
    pointer-events: none !important;
}
@media (min-width: 769px) {
    .tulms-tap-zone {
        display: none !important;
    }
}

/* NÚT NỔI RESET ZOOM TRÊN MOBILE */
.tulms-floating-zoom-btn {
    position: absolute;
    bottom: 16px;
    right: 16px;
    z-index: 45;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(56, 189, 248, 0.4);
    color: #38bdf8;
    padding: 7px 14px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.06);
    cursor: pointer;
    opacity: 0;
    transform: translateY(12px) scale(0.92);
    pointer-events: none;
    transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.tulms-book-stage.is-zoomed .tulms-floating-zoom-btn {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.tulms-floating-zoom-btn:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #38bdf8;
    transform: translateY(-2px) scale(1.03);
}
.tulms-floating-zoom-btn:active {
    transform: translateY(0) scale(0.96);
}
.floating-zoom-val {
    font-family: monospace;
    font-weight: 700;
}
.floating-zoom-text {
    font-size: 11.5px;
    color: #e2e8f0;
}

/* CHẾ ĐỘ ĐỌC CHÌM ĐẮM (IMMERSIVE MODE) */
.tulms-reader-header {
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.28s ease;
}
.tulms-ebook-app-container.is-immersive .tulms-reader-header {
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
}
.tulms-ebook-app-container.is-immersive .tulms-reader-footer {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}
.tulms-ebook-app-container.is-immersive .tulms-book-stage {
    height: 100vh !important;
    padding: 0 !important;
}

/* CHẾ ĐỘ NHÚNG VÀO BÀI HỌC (EMBED MODE) */
.tulms-ebook-app-container.is-embedded {
    height: 100% !important;
    min-height: 520px;
    border-radius: 8px;
    border: 1px solid var(--eb-border-subtle);
}
.tulms-ebook-app-container.is-embedded .tulms-book-stage {
    height: calc(100% - 44px - 36px) !important;
}
.tulms-ebook-app-container.is-embedded .ebook-heading {
    max-width: 180px;
}

/* RESPONSIVE MOBILE TỐI ƯU CỰC ĐẠI CHO ĐIỆN THOẠI */
@media (max-width: 768px) {
    /* Ẩn nút mũi tên desktop */
    .stage-nav-arrow { display: none !important; }
    .btn-page-mode { display: none !important; }
    .zoom-controls-group { display: none !important; } /* Dùng pinch 2 ngón và double-tap */

    /* Header thanh thoát, nút touch target đạt chuẩn 40px */
    .tulms-reader-header {
        padding: 0 10px;
        gap: 6px;
        height: 44px;
    }
    .header-left {
        gap: 6px;
        flex: 1;
        min-width: 0;
    }
    .ebook-heading {
        max-width: 170px;
        font-size: 13px;
    }
    .btn-ctrl {
        height: 38px;
        min-width: 38px;
        padding: 0 8px;
        border-radius: 8px;
        justify-content: center;
    }
    .btn-ctrl span:not(.zoom-label) {
        display: none !important;
    }

    /* Sân khấu sách ôm sát viền màn hình điện thoại để trang sách to tối đa */
    .tulms-book-stage {
        padding: 2px 0 !important;
        height: calc(100vh - 44px - 40px) !important;
    }

    /* Footer chuyển sang Scrubber lướt nhanh */
    .tulms-reader-footer {
        height: 40px;
        padding: 0 10px;
        font-size: 11px;
    }
    .footer-progress {
        display: none !important;
    }
    .footer-scrubber-wrap {
        display: flex;
    }
    .footer-counter {
        font-size: 11px;
        font-weight: 600;
        white-space: nowrap;
        min-width: 70px;
    }
    .footer-counter .counter-label {
        display: none;
    }

    /* Drawer mục lục trượt toàn bộ chiều cao */
    .tulms-toc-drawer {
        width: 86vw;
        max-width: 340px;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-105%);
        box-shadow: none;
    }
    .tulms-toc-drawer.open {
        transform: translateX(0);
        box-shadow: 10px 0 30px rgba(0,0,0,0.65);
    }
    .toc-header {
        height: 44px;
    }
    .toc-chapter-item {
        padding: 11px 12px;
        font-size: 13.5px;
        min-height: 42px;
    }
}

