/**
 * Только главная (body.page-home): лёгкая «живая» текстура + параллакс в hero.
 * В Telegram WebView и при prefers-reduced-motion — статично / без параллакса.
 */

body.page-home .hero,
body.page-exchange .exchange-process {
    position: relative;
    overflow: visible;
    overflow-x: visible;
}

/* Горизонтальный вылет fx ловим на body.page-exchange (см. styles.css), здесь без overflow:hidden —
   иначе обрезается hero-fx сверху и под прозрачным хедером видна «линия» шапки. */

body.page-home .hero-fx,
body.page-exchange .hero-fx {
    position: absolute;
    inset: -20% 0 -55%;
    z-index: 0;
    pointer-events: none;
    overflow: visible;

    /* Чтобы на границе hero не было резкой “линии” при скролле */
    -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 62%, rgba(0,0,0,0) 100%);
    mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 62%, rgba(0,0,0,0) 100%);
}

/* Для exchange ограничиваем вылет вниз, чтобы не появлялась лишняя прокрутка */
body.page-exchange .hero-fx {
    inset: -20% 0 -18%;
}

/* Движущийся «шлейф» поверх mesh — заметен сразу (не только при наведении мыши) */
body.page-home .hero-fx::before,
body.page-exchange .hero-fx::before {
    content: "";
    position: absolute;
    inset: -15%;
    z-index: 2;
    opacity: 0.78;
    background: linear-gradient(
        105deg,
        transparent 0%,
        rgba(93, 69, 255, 0.34) 18%,
        rgba(129, 140, 248, 0.22) 38%,
        rgba(52, 152, 219, 0.26) 52%,
        transparent 72%
    );
    background-size: 260% 260%;
    animation: heroAuroraShift 8s ease-in-out infinite;
    mix-blend-mode: screen;
}

@keyframes heroAuroraShift {
    0% {
        background-position: 8% 42%;
        transform: translate3d(-4%, 0, 0) rotate(0deg);
    }
    50% {
        background-position: 92% 60%;
        transform: translate3d(4%, -2.2%, 0) rotate(2deg);
    }
    100% {
        background-position: 8% 42%;
        transform: translate3d(-4%, 0, 0) rotate(0deg);
    }
}

body.page-home .hero__content,
body.page-exchange .hero__content {
    position: relative;
    z-index: 1;
}

/* Медленный «mesh» — только transform/opacity (композитинг) */
body.page-home .hero-fx__mesh,
body.page-exchange .hero-fx__mesh {
    position: absolute;
    inset: -30%;
    z-index: 0;
    background:
        radial-gradient(ellipse 80% 60% at 20% 30%, rgba(93, 69, 255, 0.38) 0%, transparent 52%),
        radial-gradient(ellipse 70% 50% at 85% 20%, rgba(52, 152, 219, 0.32) 0%, transparent 48%),
        radial-gradient(ellipse 60% 45% at 60% 85%, rgba(139, 92, 246, 0.28) 0%, transparent 45%);
    opacity: 1;
    transform-origin: 50% 50%;
    animation: heroMeshDrift 14s ease-in-out infinite alternate;
    will-change: transform;
}

@keyframes heroMeshDrift {
    0% {
        transform: translate3d(-5%, -2.5%, 0) rotate(-2deg) scale(1);
    }
    100% {
        transform: translate3d(5%, 3%, 0) rotate(7deg) scale(1.08);
    }
}

body.page-home .hero-fx__shift,
body.page-exchange .hero-fx__shift {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    will-change: transform;
}

body.page-home .hero-fx__shift--1,
body.page-exchange .hero-fx__shift--1 {
    width: min(55vw, 420px);
    height: min(55vw, 420px);
    left: 5%;
    top: 0;
}

body.page-home .hero-fx__shift--2,
body.page-exchange .hero-fx__shift--2 {
    width: min(45vw, 340px);
    height: min(45vw, 340px);
    right: 0;
    bottom: -5%;
}

body.page-home .hero-fx__glow,
body.page-exchange .hero-fx__glow {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    filter: blur(48px);
    opacity: 0.76;
    will-change: transform;
}

body.page-home .hero-fx__glow--1,
body.page-exchange .hero-fx__glow--1 {
    background: linear-gradient(135deg, rgba(93, 69, 255, 0.5), rgba(42, 22, 112, 0.15));
    animation: heroGlowFloatA 18s ease-in-out infinite;
}

body.page-home .hero-fx__glow--2,
body.page-exchange .hero-fx__glow--2 {
    background: linear-gradient(225deg, rgba(52, 152, 219, 0.35), rgba(93, 69, 255, 0.2));
    animation: heroGlowFloatB 24s ease-in-out infinite;
}

@keyframes heroGlowFloatA {
    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }
    50% {
        transform: translate3d(10%, 12%, 0);
    }
}

@keyframes heroGlowFloatB {
    0%,
    100% {
        transform: translate3d(0, 0, 0);
    }
    50% {
        transform: translate3d(-10%, -8%, 0);
    }
}

html:not(.theme-dark) body.page-home .hero-fx::before,
html:not(.theme-dark) body.page-exchange .hero-fx::before {
    opacity: 0.42;
    mix-blend-mode: multiply;
    background: linear-gradient(
        105deg,
        transparent 0%,
        rgba(37, 99, 235, 0.2) 22%,
        rgba(99, 102, 241, 0.12) 45%,
        rgba(14, 165, 233, 0.14) 58%,
        transparent 78%
    );
}

html:not(.theme-dark) body.page-home .hero-fx__mesh,
html:not(.theme-dark) body.page-exchange .hero-fx__mesh {
    background:
        radial-gradient(ellipse 80% 60% at 25% 25%, rgba(37, 99, 235, 0.26) 0%, transparent 52%),
        radial-gradient(ellipse 70% 50% at 90% 15%, rgba(59, 130, 246, 0.22) 0%, transparent 48%),
        radial-gradient(ellipse 60% 45% at 55% 90%, rgba(99, 102, 241, 0.18) 0%, transparent 45%);
    opacity: 1;
}

html:not(.theme-dark) body.page-home .hero-fx__glow--1,
html:not(.theme-dark) body.page-exchange .hero-fx__glow--1 {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.35), rgba(147, 197, 253, 0.14));
    opacity: 0.65;
}

html:not(.theme-dark) body.page-home .hero-fx__glow--2,
html:not(.theme-dark) body.page-exchange .hero-fx__glow--2 {
    background: linear-gradient(225deg, rgba(59, 130, 246, 0.3), rgba(129, 140, 248, 0.16));
    opacity: 0.58;
}

/* Telegram / reduced motion — без движения фона */
html.in-telegram body.page-home .hero-fx::before,
html.in-telegram body.page-home .hero-fx__mesh,
html.in-telegram body.page-home .hero-fx__glow,
html.in-telegram body.page-exchange .hero-fx::before,
html.in-telegram body.page-exchange .hero-fx__mesh,
html.in-telegram body.page-exchange .hero-fx__glow {
    animation: none !important;
    transform: none !important;
}

html.in-telegram body.page-home .hero-fx__shift,
html.in-telegram body.page-exchange .hero-fx__shift {
    transform: none !important;
}

html.in-telegram body.page-home .hero-fx__mesh,
html.in-telegram body.page-exchange .hero-fx__mesh {
    opacity: 0.5;
}

html.in-telegram body.page-home .hero-fx::before,
html.in-telegram body.page-exchange .hero-fx::before {
    opacity: 0.28;
}

html.in-telegram body.page-home,
html.in-telegram body.page-exchange {
    overflow-x: clip;
}

/* Жесткий фикс для Telegram на главной:
   выключаем hero-fx слой полностью, т.к. именно он даёт правый вылет */
html.in-telegram body.page-home .hero-fx {
    display: none !important;
}

/* Telegram WebView: чтобы не было горизонтального overflow
   shift--1 раньше был left: 5% + width: 55vw, что в WebView даёт расширение по X */
html.in-telegram body.page-home .hero-fx__shift--1,
html.in-telegram body.page-exchange .hero-fx__shift--1 {
    left: 0;
}

html.in-telegram body.page-home .hero-fx,
html.in-telegram body.page-exchange .hero-fx {
    overflow-x: hidden;
    overflow: hidden;
}

/* В Telegram blur иногда "раздвигает" область рисования и провоцирует горизонтальный оверфлоу.
   Клиппим также внутренние shift-контейнеры, чтобы размытие не выходило за края. */
html.in-telegram body.page-home .hero-fx__shift,
html.in-telegram body.page-exchange .hero-fx__shift {
    overflow: hidden;
}

/* Telegram WebView иногда "протаскивает" слои по X, если им задан отрицательный inset слева/справа.
   Поэтому для главной дополнительно убираем расширение по X. */
html.in-telegram body.page-home .hero-fx__mesh {
    inset: -30% 0 -30% 0 !important; /* оставляем только вылет по Y */
}

html.in-telegram body.page-home .hero-fx::before {
    inset: -15% 0 -15% 0 !important; /* убираем отрицательный X */
}

@media (prefers-reduced-motion: reduce) {
    body.page-home .hero-fx::before,
    body.page-home .hero-fx__mesh,
    body.page-home .hero-fx__glow,
    body.page-exchange .hero-fx::before,
    body.page-exchange .hero-fx__mesh,
    body.page-exchange .hero-fx__glow {
        animation: none !important;
        transform: none !important;
    }

    body.page-home .hero-fx__shift,
    body.page-exchange .hero-fx__shift {
        transform: none !important;
    }
}
