/* ==========================================================================
   Safon Techs — Motion Layer
   Additive polish: smooth page transitions, ambient aurora, cursor glow,
   card spotlight + 3D tilt, ripples, split-text headings, scroll reveals.
   Everything is disabled automatically for prefers-reduced-motion.
   ========================================================================== */

/* ── Native smooth scrolling (keyboard, anchors, fallback) ───────────────── */
@media (prefers-reduced-motion: no-preference) {
    html { scroll-behavior: smooth; }
}

/* ── Page enter / leave curtain (pure CSS on enter, so there is no flash) ── */
html::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 10010;
    background: var(--cyber-base);
    pointer-events: none;
    opacity: 0;
    animation: mo-curtain-in 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
html.mo-leaving::after {
    pointer-events: all;
    animation: mo-curtain-out 0.26s ease both;
}
@keyframes mo-curtain-in  { from { opacity: 1; } to { opacity: 0; } }
@keyframes mo-curtain-out { from { opacity: 0; } to { opacity: 1; } }

/* ── Ambient aurora background ───────────────────────────────────────────── */
.mo-aurora {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}
.mo-blob {
    position: absolute;
    display: block;
    border-radius: 50%;
    opacity: 0.6;
    will-change: transform;
}
.mo-b1 {
    width: 60vmax; height: 60vmax; left: -18vmax; top: -22vmax;
    background: radial-gradient(circle, rgba(0, 245, 255, 0.13) 0%, transparent 65%);
    background: radial-gradient(circle, color-mix(in srgb, var(--cyber-accent) 20%, transparent) 0%, transparent 65%);
    animation: mo-drift-1 28s ease-in-out infinite alternate;
}
.mo-b2 {
    width: 56vmax; height: 56vmax; right: -22vmax; bottom: -26vmax;
    background: radial-gradient(circle, rgba(255, 0, 229, 0.11) 0%, transparent 65%);
    background: radial-gradient(circle, color-mix(in srgb, var(--cyber-pink) 17%, transparent) 0%, transparent 65%);
    animation: mo-drift-2 34s ease-in-out infinite alternate;
}
.mo-b3 {
    width: 42vmax; height: 42vmax; left: 38%; top: 28%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.10) 0%, transparent 65%);
    background: radial-gradient(circle, color-mix(in srgb, var(--cyber-indigo) 15%, transparent) 0%, transparent 65%);
    animation: mo-drift-3 40s ease-in-out infinite alternate;
}
:root.solar-mode .mo-blob { opacity: 0.3; }
@keyframes mo-drift-1 { to { transform: translate3d(22vmax, 14vmax, 0) scale(1.18); } }
@keyframes mo-drift-2 { to { transform: translate3d(-20vmax, -16vmax, 0) scale(1.12); } }
@keyframes mo-drift-3 { to { transform: translate3d(-14vmax, 12vmax, 0) scale(1.25); } }

/* ── Cursor-following glow (desktop only) ────────────────────────────────── */
.mo-cursor-glow {
    position: fixed;
    left: 0; top: 0;
    width: 560px; height: 560px;
    margin: -280px 0 0 -280px;
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.5s ease;
    will-change: transform;
    background: radial-gradient(circle, rgba(0, 245, 255, 0.10) 0%, transparent 62%);
    background: radial-gradient(circle, color-mix(in srgb, var(--cyber-accent) 15%, transparent) 0%, transparent 62%);
}
.mo-cursor-glow.on { opacity: 1; }
:root.solar-mode .mo-cursor-glow.on { opacity: 0.55; }

/* ── Card spotlight + 3D tilt ────────────────────────────────────────────── */
.mo-spot {
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0;
    z-index: 3;
    transition: opacity 0.4s ease;
    background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 50%), rgba(0, 245, 255, 0.13), transparent 60%);
    background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 50%), color-mix(in srgb, var(--cyber-accent) 17%, transparent), transparent 60%);
}
.mo-tilting > .mo-spot { opacity: 1; }
.mo-tilting {
    transform: perspective(1000px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(-6px) !important;
}

/* ── Button ripple ───────────────────────────────────────────────────────── */
.mo-ripple {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 70%);
    transform: scale(0);
    opacity: 0.9;
    animation: mo-ripple 0.65s ease-out forwards;
}
@keyframes mo-ripple { to { transform: scale(1); opacity: 0; } }

/* ── Split-text headings (word mask reveal) ──────────────────────────────── */
.mo-w {
    display: inline-block;
    overflow: hidden;
    vertical-align: top;
    padding-bottom: 0.14em;
    margin-bottom: -0.14em;
}
.mo-wi {
    display: inline-block;
    transition: transform 0.85s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.6s ease;
}
.mo-split:not(.mo-in) .mo-wi { transform: translateY(108%); opacity: 0; }

/* ── Generic staggered reveal ────────────────────────────────────────────── */
.mo-rv {
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1), transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}
.mo-rv:not(.mo-in) { opacity: 0; transform: translateY(26px); }

.hero-stat-pill strong { font-variant-numeric: tabular-nums; }

/* ── Reduced motion: switch the whole layer off ──────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    html::after, html.mo-leaving::after { animation: none; opacity: 0; pointer-events: none; }
    .mo-blob { animation: none; }
    .mo-cursor-glow { display: none; }
    .mo-split:not(.mo-in) .mo-wi { transform: none; opacity: 1; }
    .mo-rv:not(.mo-in) { opacity: 1; transform: none; }
    .mo-tilting { transform: none !important; }
    .mo-ripple { display: none; }
}

/* ==========================================================================
   PHONE / TOUCH PERFORMANCE LAYER
   Goal: butter-smooth scrolling on mid-range phones. Everything below removes
   work that forces the GPU to repaint or re-blur while the finger is moving.
   Desktop (mouse) keeps the full effects.
   ========================================================================== */

/* Crisp ASCII text with the Isometra font */
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeSpeed; }

/* No 300ms tap delay, no grey tap flash */
a, button, [role="button"], input, select, textarea, label {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Footer is far below the fold: skip its layout/paint until needed */
footer { content-visibility: auto; contain-intrinsic-size: auto 700px; }

@media (hover: none), (pointer: coarse), (max-width: 992px) {

    /* 1. backdrop-filter is the #1 cause of scroll lag on phones → remove.
          Backgrounds are already near-opaque, so the look barely changes. */
    *, *::before, *::after {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }
    header.scrolled { background: rgba(5, 7, 18, 0.96); }
    html.solar-mode header.scrolled { background: rgba(255, 255, 255, 0.97); }

    /* 2. No full-screen page curtain (it repaints the whole screen twice per navigation) */
    html::after, html.mo-leaving::after { display: none !important; animation: none !important; }

    /* 3. Aurora: keep the soft colour, drop the movement and the 3rd blob */
    .mo-blob { animation: none !important; will-change: auto; opacity: 0.45; }
    .mo-b3 { display: none; }
    .mo-cursor-glow { display: none !important; }

    /* 4. Animated box-shadows / rings repaint every frame → freeze them */
    .safon-ai-header-btn,
    .safon-academy-header-btn,
    .safon-nexus-header-btn,
    .safon-affiliate-header-btn { animation: none !important; }
    html body .platform-slide-card .platform-icon-box::after { animation: none !important; opacity: 0.35; }
    html body .newsletter-badge i { animation: none !important; }
    .live-dot, [class*="pulse"] { animation-duration: 3s; }

    /* 5. Lighter reveals: shorter, smaller travel, no per-word stagger */
    .mo-rv { transition-duration: 0.45s; }
    .mo-rv:not(.mo-in) { transform: translateY(14px); }
    .mo-wi { transition-duration: 0.45s; transition-delay: 0s !important; }
    .mo-split:not(.mo-in) .mo-wi { transform: translateY(40%); }

    /* 6. Inertial momentum scrolling stays native (fastest path) */
    html, body { overscroll-behavior-y: none; }
    body { -webkit-overflow-scrolling: touch; }

    /* 7. Heavy shadows → cheaper ones on cards */
    html body .platform-slide-card,
    html body .service-card { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); }
}

/* ==========================================================================
   PHONE PERFORMANCE — ROUND 2
   Removes the remaining always-running paint work on touch devices.
   ========================================================================== */
@media (hover: none), (pointer: coarse), (max-width: 992px) {

    /* filter: blur(90px) on big animated layers is extremely expensive on phones.
       The radial-gradient is already soft, so a static gradient looks the same. */
    .hero-glow { filter: none !important; animation: none !important; will-change: auto; }

    /* Gradient text shimmer repaints the text every frame → static gradient */
    .hero-highlight { animation: none !important; }

    /* Floating / pulsing decoration → static (opacity/transform-only ones can stay few) */
    .hero-badge, .hero-badge i,
    .hero-stat-pill, .hero-stat-pill i,
    .hero-cta-btn .fa-arrow-down,
    .eco-icon-wrap,
    .nexus-glow, .ai-glow, .academy-glow, .affiliate-glow { animation: none !important; }

    /* "transition: all" animates layout/paint properties too → only cheap ones */
    .eco-btn, .service-card, .platform-slide-card, .ecosystem-card {
        transition-property: transform, opacity, border-color, background-color;
    }

    /* Slider: native, GPU-friendly swiping */
    .platforms-slider-container {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        will-change: scroll-position;
    }
    .platform-slide-card { contain: layout paint style; }

    /* Don't fade in the hero lines one by one (many simultaneous animations on load) */
    .hero-section [class*="hero-"] { animation-duration: 0.5s !important; animation-delay: 0s !important; }
}

/* Never run decorative animations while the tab is in the background or user prefers less */
@media (prefers-reduced-motion: reduce) {
    .hero-glow, .hero-highlight, .hero-badge, .hero-stat-pill, .eco-icon-wrap { animation: none !important; }
}
