/* Дополнительные оптимизации для мобильных устройств */

/* Улучшение отзывчивости изображений */
img {
    max-width: 100%;
    height: auto;
    display: block;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Отключение анимаций только по системному запросу */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Улучшение рендеринга шрифтов на мобильных */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-tap-highlight-color: transparent;
}

/* Улучшение отображения на устройствах с вырезом */
@supports (padding: max(0px)) {
    body, header, .section {
        padding-left: min(0vmin, env(safe-area-inset-left));
        padding-right: min(0vmin, env(safe-area-inset-right));
        padding-top: min(0vmin, env(safe-area-inset-top));
        padding-bottom: min(0vmin, env(safe-area-inset-bottom));
    }
}

/* Оптимизация для iOS и мобильных устройств */
input,
textarea,
select,
button {
    font-size: 16px; /* Предотвращает масштабирование iOS */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0;
}

/* Улучшение нажатий на мобильных */
.btn,
.nav-link,
.nav-shop-btn,
.shop-drawer-close,
.shop-product-buy,
.slider-prev,
.slider-next,
.testimonial-prev,
.testimonial-next,
.faq-question {
    -webkit-tap-highlight-color: rgba(128, 0, 32, 0.2);
    tap-highlight-color: rgba(128, 0, 32, 0.2);
    min-height: 44px; /* Минимальный размер для нажатия */
    min-width: 44px;
}
/* Мобильные: изображения и фоны слайдера не выходят за экран */
@media (max-width: 768px) {
    #main {
        min-width: 0;
        max-width: 100%;
        overflow-x: hidden;
    }

    .slider-container,
    .slide {
        overflow: hidden;
    }

    /* Герой: на мобильном — contain (весь кадр), на ПК правила в style.css (cover для 2–3 слайдов) */
    .hero-slider .slide-background {
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background-size: contain !important;
        background-position: center center !important;
        background-repeat: no-repeat !important;
        background-color: #140a0d !important;
    }

    .hero-slider .slide-hero-primary {
        background-image: var(--hero-bg-mobile) !important;
    }

    .slide.active .slide-background {
        transform: scale(1) !important;
    }

    /* Контентные <img>: вписываются в контейнер, по центру, пропорции сохраняются */
    main img {
        max-width: 100%;
        width: auto;
        height: auto;
        display: block;
        margin-left: auto;
        margin-right: auto;
        object-fit: contain;
        box-sizing: border-box;
    }

    .expert-image img,
    .circles-image img,
    .gallery-item img {
        width: 100%;
        height: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
        object-fit: cover;
        object-position: center;
    }

    .expert-image img {
        object-position: center top;
    }

    .experts-grid,
    .gallery-grid,
    .circles-content {
        min-width: 0;
        max-width: 100%;
    }

    .experts-grid > *,
    .gallery-grid > *,
    .circles-content > * {
        min-width: 0;
        max-width: 100%;
    }

    .expert-card,
    .expert-image,
    .gallery-item,
    .circles-image {
        max-width: 100%;
    }
}
/* Улучшение читаемости на мобильных */
@media (max-width: 768px) {
    .section-description,
    .slide-description,
    .expert-bio,
    .help-card p,
    .level-content p,
    .testimonial-text,
    .faq-answer p,
    .contact-description {
        line-height: 1.6;
        font-size: 1rem;
        letter-spacing: 0.2px;
        text-align: center;
    }
    
    h1, h2, h3, h4 {
        text-align: center;
    }

    /* Панель магазина: левое выравнивание, как в боковой колонке */
    .shop-drawer h2,
    .shop-drawer h3 {
        text-align: left;
    }
}

/* Улучшение контраста на ярком экране */
@media (prefers-color-scheme: light) {
    body {
        background: #0a0a0a;
    }
    
    .slide-title,
    .section-title {
        color: #ffffff;
        text-shadow: 0 2px 15px rgba(0, 0, 0, 0.9);
    }
}

/* Оптимизация загрузки для мобильных */
.lazy-load {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-load.loaded {
    opacity: 1;
}

/* Улучшение производительности на мобильных */
@media (max-width: 768px) {
    .parallax-layer {
        transform: none !important;
        display: none;
    }
    
    .cinematic-elements,
    .light-ray {
        display: none;
    }
    
    .slider-controls,
    .slider-indicators {
        opacity: 0.7;
    }
    
    /* Оптимизация для слайдера на мобильных */
    .slide-content {
        padding: 20px 15px;
    }
    
    .luxury-title {
        font-size: 1.8rem;
        line-height: 1.1;
        margin-bottom: 15px;
    }
    
    .slide-buttons {
        flex-direction: column;
        gap: 10px;
    }
    
    .slide-buttons .btn {
        width: 100%;
        justify-content: center;
        padding: 14px 20px;
    }
}

/* Предотвращение зума при фокусе на iOS */
@media (max-width: 768px) {
    input[type="text"],
    input[type="tel"],
    input[type="email"],
    textarea {
        font-size: 16px !important;
    }
    
    select {
        font-size: 16px !important;
    }
}

/* Улучшение для очень маленьких экранов */
@media (max-width: 360px) {
    .container {
        padding: 0 12px;
    }
    
    .section {
        padding: 40px 0;
    }
    
    .luxury-title {
        font-size: 1.5rem;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
    
    .btn {
        padding: 12px 16px;
        font-size: 14px;
    }
}

/* Оптимизация для планшетов */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 0 30px;
    }
    
    .luxury-title {
        font-size: 2.5rem;
    }
    
    .section-title {
        font-size: 2rem;
    }
    
    .experts-grid {
        gap: 30px;
    }
    
    .levels-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
    
    .level-featured {
        grid-column: span 2;
    }
}

/* Улучшение для ландшафтной ориентации на мобильных */
@media (max-height: 500px) and (orientation: landscape) {
    .hero-slider {
        height: auto;
        min-height: 100vh;
    }
    
    .slide-content {
        padding: 40px 20px;
    }
    
    .luxury-title {
        font-size: 2rem;
        margin-bottom: 10px;
    }
    
    .slide-description {
        margin-bottom: 20px;
        font-size: 0.9rem;
    }
}

/* Предотвращение нативного перетаскивания изображений на мобильных */
img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* Оптимизация анимаций для устройств с низкой частотой обновления */
@media (max-width: 768px) {
    @keyframes slideReveal {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ===== ОПТИМИЗАЦИЯ ГАЛЕРЕИ ДЛЯ МОБИЛЬНЫХ ===== */

/* Предотвращение случайных нажатий */
.gallery-grid {
    touch-action: pan-y;
}

.gallery-item {
    touch-action: pan-y;
    -webkit-tap-highlight-color: transparent;
    min-height: 150px;
}

/* Улучшение обратной связи при нажатии */
.gallery-item:active {
    background-color: rgba(128, 0, 32, 0.1);
    transition: background-color 0.2s;
}

/* Предотвращение выделения текста при долгом нажатии */
.gallery-item img {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    pointer-events: none; /* Предотвращает перетаскивание */
}

/* Улучшение для iOS */
.gallery-item {
    -webkit-touch-callout: none;
}

/* Уменьшение чувствительности для скролла */
@media (max-width: 768px) {
    .gallery-section {
        padding: 40px 0;
    }
    
    .gallery-grid {
        margin-top: 20px;
    }
    
    /* Увеличиваем зону безопасного скролла */
    .gallery-item {
        margin: 10px 5px;
        border: 2px solid transparent;
    }
    
    .gallery-item:active {
        border-color: rgba(128, 0, 32, 0.3);
    }
}

/* Оптимизация для медленных сетей */
@media (max-width: 768px) {
    /* Чёткость мелких иконок/фото в карточках (фон слайдера без crisp-edges — иначе «ступеньки» на фото) */
    .expert-image img,
    .circles-image img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    /* Герой: фото светлее, чтобы просвечивало под текстом */
    .hero-slider .slide-background {
        filter: brightness(0.96) contrast(1.02);
    }
}

/* Оптимизация для слабых устройств */
@media (max-width: 768px) {
    /* Отключение сложных эффектов */
    .help-card:hover,
    .expert-card:hover,
    .level-card:hover,
    .testimonial-content:hover {
        transform: none !important;
    }
    
    /* Упрощение теней */
    .help-card,
    .expert-card,
    .level-card,
    .testimonial-content,
    .contact-form,
    .contact-person {
        box-shadow: var(--shadow-sm) !important;
    }
    
    /* Отключение градиентов для лучшей производительности */
    .luxury-title {
        background: var(--gold-medium);
        -webkit-background-clip: text;
        background-clip: text;
        color: transparent;
        text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.5);
    }
}

/* Оптимизация для экономии батареи */
@media (max-width: 768px) {
    /* Уменьшение частоты анимаций */
    .heart-loader {
        animation: heartBeat 3s ease-in-out infinite;
    }
    
    @keyframes textShimmer {
        0%, 100% {
            filter: brightness(1) contrast(1);
            text-shadow: 
                0px 2px 4px rgba(0, 0, 0, 0.5),
                0px 4px 20px rgba(212, 175, 55, 0.4);
        }
    }
    
    .luxury-title {
        animation: textShimmer 6s ease-in-out infinite alternate;
    }
}

/* Оптимизация для ориентации экрана */
@media (orientation: portrait) and (max-width: 768px) {
    .hero-slider {
        height: 100vh;
        height: 100dvh;
        min-height: 100svh;
        min-height: 100dvh;
    }

    .slide-content {
        padding-top: 80px;
    }
}

@media (orientation: landscape) and (max-width: 768px) {
    .hero-slider {
        min-height: 120vh;
    }
    
    .slide-content {
        padding-top: 60px;
    }
}

/* Предотвращение скролла при открытых модальных окнах */
body.modal-open,
body.menu-open {
    overflow: hidden !important;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Оптимизация для медленного интернета */
.loading-placeholder {
    background: linear-gradient(90deg, 
        rgba(255, 255, 255, 0.05) 0%, 
        rgba(255, 255, 255, 0.1) 50%, 
        rgba(255, 255, 255, 0.05) 100%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Магазин: плавная анимация панели на мобильных (поверх глобального сброса transition) */
@media (max-width: 768px) {
    .shop-drawer-root .shop-drawer-overlay,
    .shop-drawer-root .shop-drawer {
        transition-duration: 0.38s !important;
        transition-property: opacity, transform !important;
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .shop-drawer-root .shop-drawer-overlay,
    .shop-drawer-root .shop-drawer {
        transition-duration: 0.01ms !important;
    }
}
