/* Базовые стили документа */
html {
    scroll-behavior: smooth;
    scroll-padding-top: 80px;
    background: var(--bg-primary);
    overflow-x: clip;
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
}

body {
    font-family: var(--font-family-base);
    background: linear-gradient(135deg, 
        #0a0d1a 0%, 
        #161030 15%,
        #1a0d28 30%,
        #0d1529 45%,
        #161030 60%,
        #1a0d28 75%,
        #0a0d1a 100%);
    background-size: 400% 400%;
    background-attachment: fixed;
    animation: gradientShift 20s ease infinite;
    color: var(--color-text);
    min-height: calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));
    width: 100%;
    position: relative;
    overflow-x: clip;
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    font-weight: var(--font-weight-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    font-variant-ligatures: common-ligatures;
    font-optical-sizing: auto;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    touch-action: pan-y;
    overscroll-behavior-x: none;
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
    font-synthesis: none;
    -webkit-font-variant-ligatures: common-ligatures;
    -moz-font-variant-ligatures: common-ligatures;
}

/* Seasonal overlay support */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
}

/* Свечение фона */
body::before {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 900px;
    height: 900px;
    background: radial-gradient(circle, rgba(147, 51, 234, 0.12) 0%, rgba(102, 126, 234, 0.08) 40%, transparent 70%);
    border-radius: 50%;
    z-index: 0;
    animation: pulseGlow 8s ease-in-out infinite;
}

/* Мобильные устройства */
@media (max-width: 768px) {
    body {
        background-attachment: scroll;
        background-size: 100% 100%;
        animation: none;
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    * {
        will-change: auto;
    }
    
    body::before {
        display: none;
    }
    
    .container {
        padding-left: max(16px, var(--safe-area-inset-left));
        padding-right: max(16px, var(--safe-area-inset-right));
    }
    
    .calc-container,
    .accordion,
    .review-card {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    }
    
    .calc-container {
        max-height: 90vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    input:focus,
    textarea:focus,
    select:focus {
        scroll-margin-top: 20vh;
    }
    
    .calc-button,
    .btn-get-matrix {
        background: linear-gradient(135deg, #065f46 0%, #047857 100%);
        animation: none;
    }
    
    .calc-button::before,
    .btn-get-matrix::before {
        display: none;
    }
}

/* Отключение анимаций для пользователей с ограниченной анимацией */
@media (prefers-reduced-motion: reduce) {
    body {
        animation: none;
        background-attachment: scroll;
    }
    
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
        transition-duration: 0.01ms;
    }
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    25% { background-position: 50% 50%; }
    50% { background-position: 100% 50%; }
    75% { background-position: 50% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes pulseGlow {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.08); opacity: 0.7; }
}

/* Заголовки - Оптимизированные 2026 */
h1, h2 {
    font-family: var(--font-family-heading);
    font-weight: var(--font-weight-bold);
    line-height: 1.2;
    letter-spacing: 0.05em;
    font-feature-settings: 'kern' 1, 'liga' 1, 'dlig' 1;
    text-rendering: optimizeLegibility;
    font-optical-sizing: auto;
}

h3, h4 {
    font-family: var(--font-family-serif);
    font-weight: var(--font-weight-semibold);
    line-height: 1.3;
    letter-spacing: 0.01em;
    font-feature-settings: 'kern' 1, 'liga' 1;
    text-rendering: optimizeLegibility;
}

h5, h6 {
    font-family: var(--font-family-base);
    font-weight: var(--font-weight-bold);
    line-height: 1.4;
    letter-spacing: -0.01em;
    font-feature-settings: 'kern' 1;
}

/* Контейнер контента */
.container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    position: relative;
    z-index: var(--z-base);
    box-sizing: border-box;
}

/* Скроллбар */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.4) rgba(26, 13, 40, 0.3);
    -webkit-tap-highlight-color: rgba(139, 92, 246, 0.3);
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(26, 13, 40, 0.3);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, 
        rgba(139, 92, 246, 0.6) 0%, 
        rgba(236, 72, 153, 0.6) 100%);
    border-radius: 10px;
    border: 2px solid rgba(26, 13, 40, 0.3);
    transition: all 0.3s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, 
        rgba(139, 92, 246, 0.9) 0%, 
        rgba(236, 72, 153, 0.9) 100%);
    border-color: rgba(139, 92, 246, 0.2);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
}

::-webkit-scrollbar-thumb:active {
    background: linear-gradient(180deg, 
        rgba(139, 92, 246, 1) 0%, 
        rgba(236, 72, 153, 1) 100%);
}

/* Изоляция компонентов для оптимизации */
.modal-content,
.accordion-content,
.diagram-wrapper-block,
.calculator-form,
.results-section {
    contain: layout style paint;
}
