/* ─────────────────────────────────────────────────────────────────────
   home-animations.css — премиум-эффекты главной (light theme).
   Подключается из views/index.ejs.
   Все эффекты уважают prefers-reduced-motion и (hover: none).

   Содержит: adaptive typography · scroll-progress · view-transitions ·
   spotlight · magnetic · gradient-border · word-reveal · counters.
   ───────────────────────────────────────────────────────────────────── */

/* 0 ── Adaptive typography + horizontal-overflow guard ─────────────── */

html, body { overflow-x: clip; }

main h1, main h2, main h3 {
    text-wrap: balance;
    overflow-wrap: break-word;
}

main p { text-wrap: pretty; overflow-wrap: break-word; }


/* 1 ── Scroll progress: CSS scroll-driven (Chrome 115+) с JS-фолбеком ─ */

.scroll-progress {
    position: fixed;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, #2563eb 0%, #06b6d4 50%, #2563eb 100%);
    transform-origin: left center;
    transform: scaleX(var(--scroll-progress, 0));
    z-index: 100;
    pointer-events: none;
    will-change: transform;
}

@supports (animation-timeline: scroll()) {
    .scroll-progress {
        animation: scroll-progress-animate linear;
        animation-timeline: scroll(root);
        transform: scaleX(0);
    }
    @keyframes scroll-progress-animate {
        to { transform: scaleX(1); }
    }
}


/* 2 ── View Transitions (Chrome 111+ | Safari 18+) ─────────────────── */

@view-transition { navigation: auto; }

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 220ms;
    animation-timing-function: cubic-bezier(0.32, 0.72, 0.24, 1);
}


/* 3 ── Spotlight: radial-gradient под курсор. mix-blend-mode позволяет
   подсветке проходить ПОВЕРХ контента и background-decorations без
   нужды переопределять position у дочерних абсолютных слоёв. ───────── */

.spotlight {
    position: relative;
}
.spotlight::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(
        500px circle at var(--mx, 50%) var(--my, 0%),
        rgba(59, 130, 246, 0.18),
        transparent 65%
    );
    opacity: 0;
    transition: opacity 380ms cubic-bezier(0.32, 0.72, 0.24, 1);
    pointer-events: none;
    /* mix-blend-mode: screen на dark — добавляет мягкое свечение,
       не затемняет текст. */
    mix-blend-mode: screen;
    z-index: 1;
}
.spotlight:hover::before { opacity: 1; }


/* Light-spotlight для светлых секций: subtle blue tint под курсором */
.spotlight-light {
    position: relative;
}
.spotlight-light::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(
        420px circle at var(--mx, 50%) var(--my, 0%),
        rgba(59, 130, 246, 0.10),
        transparent 60%
    );
    opacity: 0;
    transition: opacity 380ms cubic-bezier(0.32, 0.72, 0.24, 1);
    pointer-events: none;
    /* multiply на light — добавляет лёгкий оттенок без посветления */
    mix-blend-mode: multiply;
    z-index: 1;
}
.spotlight-light:hover::before { opacity: 1; }


/* 4 ── Magnetic CTA — кнопка тянется к курсору (через CSS-vars) ───── */

.magnetic {
    transform: translate3d(var(--mx-shift, 0), var(--my-shift, 0), 0);
    transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.magnetic:active { transform: translate3d(0, 0, 0) scale(0.98); }


/* 5 ── Gradient-border: вращающийся conic поверх primary CTA ──────── */

.gradient-border {
    position: relative;
    isolation: isolate;
}
.gradient-border::before {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: inherit;
    background: conic-gradient(
        from 0deg,
        #2563eb 0deg, #06b6d4 90deg, #6366f1 180deg, #06b6d4 270deg, #2563eb 360deg
    );
    z-index: -1;
    animation: gradient-rotate 6s linear infinite;
    opacity: 0.85;
}
.gradient-border::after {
    /* inner cover so only the rim is visible */
    content: "";
    position: absolute;
    inset: 1px;
    border-radius: inherit;
    background: inherit;
    z-index: -1;
}
@keyframes gradient-rotate {
    to { transform: rotate(360deg); }
}


/* 6 ── Word-reveal на h1 hero (data-split) ─────────────────────────── */

[data-split] .word {
    display: inline-block;
    opacity: 0;
    transform: translateY(0.4em);
    animation: word-reveal 720ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
    animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes word-reveal {
    to { opacity: 1; transform: translateY(0); }
}


/* 7 ── Counter — стилизация без JS-зависимостей (JS подставит число) ─ */

[data-counter] {
    font-variant-numeric: tabular-nums;
    /* tabular для стабильной ширины при инкременте */
}


/* 8 ── reduced-motion: всё выключаем ─────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .scroll-progress { animation: none !important; transform: scaleX(1); opacity: 0.4; }
    .spotlight::before,
    .spotlight-light::before { display: none; }
    .magnetic { transform: none !important; }
    .gradient-border::before { animation: none !important; opacity: 0.6; }
    [data-split] .word { animation: none !important; opacity: 1; transform: none; }
    @view-transition { navigation: none; }
}


/* 9 ── (hover: none) — на тач-устройствах magnetic/spotlight не работают ─ */

@media (hover: none) {
    .magnetic { transform: none !important; }
    .spotlight::before,
    .spotlight-light::before { display: none; }
}
