/* ========================================
   READER MOBILE FIXES v3 - ОКОНЧАТЕЛЬНОЕ ИСПРАВЛЕНИЕ КНОПОК ЗУМА
   ======================================== */

/* ✅ КРИТИЧНО: Кнопки зума должны быть ВЫШЕ ВСЕХ элементов */
.zoom-controls {
    position: fixed;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9998 !important; /* ✅ МАКСИМАЛЬНЫЙ z-index */
    background: rgba(255, 255, 255, 0.98);
    padding: 10px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    pointer-events: auto !important; /* ✅ КРИТИЧНО */
    isolation: isolate; /* ✅ Создает новый stacking context */
}

[data-theme="dark"] .zoom-controls {
    background: rgba(30, 30, 30, 0.98);
}

.zoom-btn {
    width: 56px !important; /* ✅ Еще больше */
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    border: none;
    background: linear-gradient(135deg, #4361ee 0%, #7209b7 100%);
    color: white;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.15s ease;
    position: relative;
    z-index: 9999 !important; /* ✅ МАКСИМАЛЬНЫЙ z-index */
    /* ✅ КРИТИЧНО: Оптимизация для тач-устройств */
    -webkit-tap-highlight-color: rgba(67, 97, 238, 0.3);
    touch-action: manipulation !important;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto !important;
    /* ✅ Убираем любые блокирующие эффекты */
    transform: translateZ(0);
    will-change: transform;
}

    /* ✅ Активное состояние для визуальной обратной связи */
    .zoom-btn:active {
        transform: scale(0.9) translateZ(0);
        background: linear-gradient(135deg, #3a52d1 0%, #6207a0 100%);
        box-shadow: 0 2px 10px rgba(67, 97, 238, 0.5);
    }

    .zoom-btn i {
        pointer-events: none !important; /* ✅ Клики только на кнопку */
        font-size: 24px;
    }

/* ✅ Мобильные кнопки действий */
.mobile-actions {
    position: fixed;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    flex-direction: column;
    gap: 10px;
    z-index: 9998 !important;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    padding: 10px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    pointer-events: auto !important;
    isolation: isolate;
}

[data-theme="dark"] .mobile-actions {
    background: rgba(30, 30, 30, 0.85);
}

.mobile-action-btn {
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    border: none;
    color: white;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.15s ease;
    position: relative;
    z-index: 9999 !important;
    -webkit-tap-highlight-color: rgba(67, 97, 238, 0.3);
    touch-action: manipulation !important;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto !important;
    transform: translateZ(0);
}

    .mobile-action-btn i {
        pointer-events: none !important;
        font-size: 24px;
    }

    .mobile-action-btn.help {
        background: linear-gradient(135deg, #06d6a0 0%, #05c090 100%);
    }

        .mobile-action-btn.help:active {
            background: linear-gradient(135deg, #05c090 0%, #04a87d 100%);
            transform: scale(0.9) translateZ(0);
        }

    .mobile-action-btn.reload {
        background: linear-gradient(135deg, #4cc9f0 0%, #3ab8d9 100%);
    }

        .mobile-action-btn.reload:active {
            background: linear-gradient(135deg, #3ab8d9 0%, #2ba7c8 100%);
            transform: scale(0.9) translateZ(0);
        }

    .mobile-action-btn.settings {
        background: linear-gradient(135deg, #f72585 0%, #d1176f 100%);
    }

        .mobile-action-btn.settings:active {
            background: linear-gradient(135deg, #d1176f 0%, #b01059 100%);
            transform: scale(0.9) translateZ(0);
        }

/* ✅ Показываем на мобильных */
@media (max-width: 768px) {
    .mobile-actions {
        display: flex !important;
    }

    /* ✅ КРИТИЧНО: Убираем конфликтующие элементы */
    .reader-container {
        pointer-events: none !important; /* ✅ Контейнер не ловит клики */
    }

    /* ✅ Область изображения — свайп и клики (анимации перелистывания работают) */
    .image-wrapper,
    .page-image {
        pointer-events: auto !important;
        touch-action: pan-y;
    }

    /* ✅ Скрываем desktop кнопки */
    .tool-actions .action-btn.reload,
    .tool-actions .action-btn.settings {
        display: none;
    }
}

/* ✅ Максимальное использование пространства */
@media (max-width: 768px) {
    .reader-container {
        padding: 0 !important;
        margin: 0 !important;
    }

    .image-wrapper {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    .page-image {
        width: 100% !important;
        height: auto !important;
        max-width: 100%;
        max-height: calc(100vh - 80px);
        object-fit: contain;
    }

    .reader-controls {
        padding: 8px 10px !important;
    }
}

/* ✅ Компактность на малых экранах */
@media (max-width: 480px) {
    .zoom-controls {
        right: 5px;
        padding: 8px;
        gap: 8px;
    }

    .mobile-actions {
        left: 5px;
        padding: 8px;
        gap: 8px;
    }

    .zoom-btn,
    .mobile-action-btn {
        width: 50px !important;
        height: 50px !important;
        min-width: 50px !important;
        min-height: 50px !important;
        font-size: 22px;
    }

        .zoom-btn i,
        .mobile-action-btn i {
            font-size: 22px;
        }
}

/* ✅ GPU: контейнер — только при полном режиме; image-wrapper и page-image — всегда */
.reader-container {
    -webkit-overflow-scrolling: touch;
}

.reader-app[data-gpu-full="true"] .reader-container {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.image-wrapper {
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.page-image {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* На мобильных перелистывание без slide-анимации: короткий fade (JS отключает slide, здесь — подстраховка) */
@media (max-width: 768px) {
    .page-image.slide-in-left,
    .page-image.slide-in-right,
    .page-image.slide-out-left,
    .page-image.slide-out-right {
        animation: none;
        -webkit-animation: none;
        transition: opacity 0.12s ease-out;
    }

    .page-image.slide-out-left,
    .page-image.slide-out-right {
        opacity: 0;
    }

    .page-image.slide-in-left,
    .page-image.slide-in-right {
        opacity: 1;
    }
}

/* Фон области изображения совпадает с фоном читалки — при смене страницы нет мелькания другого цвета */
@media (max-width: 768px) {
    .image-wrapper {
        background: var(--reader-bg, #f5f5f5);
    }

    [data-theme="dark"] .image-wrapper {
        background: var(--reader-bg, #1a1a1a);
    }
}

/* ✅ МОДАЛЬНОЕ ОКНО */
.tutorial-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    z-index: 10000; /* ✅ Выше всего */
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

    .tutorial-modal.show {
        display: flex;
        opacity: 1;
    }

.tutorial-content {
    background: white;
    border-radius: 24px;
    padding: 30px;
    max-width: 600px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.4);
    content-visibility: auto;
    contain-intrinsic-size: auto 400px;
}

[data-theme="dark"] .tutorial-content {
    background: #1a1a1a;
    color: white;
}

.tutorial-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid #e0e0e0;
}

[data-theme="dark"] .tutorial-header {
    border-bottom-color: #333;
}

.tutorial-title {
    font-size: 1.6rem;
    font-weight: 700;
    background: linear-gradient(135deg, #4361ee 0%, #7209b7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.tutorial-close {
    width: 40px;
    height: 40px;
    border: none;
    background: #f0f0f0;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

[data-theme="dark"] .tutorial-close {
    background: #333;
    color: white;
}

.tutorial-close:hover {
    background: #e74c3c;
    color: white;
    transform: rotate(90deg);
}

.tutorial-section {
    margin-bottom: 28px;
}

.tutorial-section-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}

[data-theme="dark"] .tutorial-section-title {
    color: #e0e0e0;
}

.tutorial-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

    .tutorial-list li {
        padding: 14px 16px;
        background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
        border-radius: 12px;
        margin-bottom: 10px;
        display: flex;
        align-items: flex-start;
        gap: 14px;
    }

[data-theme="dark"] .tutorial-list li {
    background: linear-gradient(135deg, #2a2a2a 0%, #333333 100%);
}

.tutorial-list li i {
    color: #4361ee;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.tutorial-text {
    flex: 1;
    line-height: 1.5;
}

.tutorial-key {
    display: inline-block;
    padding: 5px 12px;
    background: linear-gradient(135deg, #4361ee 0%, #7209b7 100%);
    color: white;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    margin: 0 4px;
}

.tutorial-footer {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
    text-align: center;
}

[data-theme="dark"] .tutorial-footer {
    border-top-color: #333;
}

.tutorial-footer button {
    padding: 14px 36px;
    background: linear-gradient(135deg, #4361ee 0%, #7209b7 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

@media (max-width: 768px) {
    .tutorial-content {
        padding: 24px 20px;
        max-height: 90vh;
    }

    .tutorial-title {
        font-size: 1.3rem;
    }
}

.action-btn.help {
    background: linear-gradient(135deg, #06d6a0 0%, #05c090 100%);
}
