/* ============================================================
   site-animations.css
   Additive motion + responsive layer. Linked on every page.
   Does not alter design tokens — theme colors/fonts untouched.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

img, svg, video { max-width: 100%; height: auto; }
html { -webkit-text-size-adjust: 100%; }

/* ---- Hero height: avoid mobile browser toolbar jump-resize ---- */
@supports (height: 100dvh) {
    .min-h-\[90vh\] { min-height: 90dvh; }
}

/* ---- Tablet-range tightening (768px–1023px): pull back a few
        desktop-only paddings/gaps that read as too wide on tablets ---- */
@media (min-width: 768px) and (max-width: 1023px) {
    .matrix-grid .gap-16 { gap: 2.5rem; }
}

a:focus-visible, button:focus-visible {
    outline: 2px solid #3366ff;
    outline-offset: 3px;
}

/* ---- Page load fade ---- */
@keyframes saPageIn { from { opacity: 0; } to { opacity: 1; } }
body { animation: saPageIn .5s ease both; }

/* ---- Intro splash — reveals the brand name, then fades out. Present on
        every page. Hidden by default; index.html ships with the
        "sa-splash-play" class already in its markup so it autoplays on
        load there. On every page (including index.html after that first
        play), clicking the nav logo removes and re-adds the class (with
        a forced reflow) to replay it — see initSplashReplay() in
        site-animations.js. ---- */
#sa-splash {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
#sa-splash.sa-splash-play {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    animation: saSplashOut .6s ease forwards;
    animation-delay: 1.3s;
}
/* Distinct monospace face for the splash text, set apart from the
   site's usual Space Grotesk / Inter pairing */
.sa-splash-font {
    font-family: "JetBrains Mono", ui-monospace, "Space Mono", monospace;
}
#sa-splash .sa-splash-letter {
    display: inline-block;
    opacity: 1;
    transform: translateY(0);
}
#sa-splash.sa-splash-play .sa-splash-letter {
    animation: saSplashLetterIn .5s cubic-bezier(.22, .61, .36, 1) forwards;
}
#sa-splash .sa-splash-cursor {
    display: inline-block;
    margin-left: 4px;
}
#sa-splash.sa-splash-play .sa-splash-cursor {
    animation: saSplashBlink 1s step-end infinite;
}
@keyframes saSplashLetterIn {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes saSplashBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
@keyframes saSplashOut {
    from { opacity: 1; visibility: visible; }
    to   { opacity: 0; visibility: hidden; pointer-events: none; }
}

/* ---- Hero name + role intro (index.html only) — the name fades up as
        the splash finishes fading out, then the role types itself in
        with a blinking terminal-style caret. ---- */
.sa-hero-name {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    animation: saHeroNameIn .7s cubic-bezier(.22, .61, .36, 1) forwards;
    animation-delay: 1.6s;
}
@keyframes saHeroNameIn {
    to { opacity: 1; transform: translateY(0); }
}
.sa-hero-role {
    display: inline-block;
    opacity: 0;
    transform: translateY(16px);
    animation: saHeroNameIn .7s cubic-bezier(.22, .61, .36, 1) forwards;
    animation-delay: 2.1s;
}

/* ---- Tile tilt — tiles opt in via .sa-tilt, JS drives rotateX/rotateY
        off cursor position within the tile, with its own rAF easing —
        deliberately no CSS "transition: transform" here, since a
        competing transition on the same property (see the scroll-reveal
        rule below, which also transitions transform for its fade-up)
        would fight the per-frame updates and either block or lag them.
        Titles inside opt in via .sa-tilt-title and get a blue glow that
        tracks the same cursor position, via the --sa-tx/--sa-ty custom
        properties JS sets on the parent .sa-tilt tile (they inherit down
        to the title). ---- */
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
    .sa-tilt {
        position: relative;
        will-change: transform;
    }
    /* Blurred glow halo behind the tile, brightening on hover — the
       square-edged equivalent of a rounded "gradient border glow" card,
       kept edge-square to match this site's borderRadius:0 theme. */
    .sa-tilt::before {
        content: "";
        position: absolute;
        inset: -6px;
        z-index: -1;
        background: radial-gradient(circle at var(--sa-tx, 50%) var(--sa-ty, 50%), #3366ff, transparent 70%);
        filter: blur(18px);
        opacity: 0;
        transition: opacity .5s ease;
        pointer-events: none;
    }
    .sa-tilt:hover::before {
        opacity: .35;
    }
    .sa-tilt-title {
        transition: background-position .1s ease-out;
    }
    @supports ((-webkit-background-clip: text) or (background-clip: text)) {
        .sa-tilt-title {
            background-image: radial-gradient(180px circle at var(--sa-tx, 50%) var(--sa-ty, 50%), #3366ff 0%, #e2e2e2 70%);
            -webkit-background-clip: text;
            background-clip: text;
            -webkit-text-fill-color: transparent;
            color: transparent;
        }
    }
}

/* ---- Nav shadow once scrolled ---- */
nav.sa-scrolled { box-shadow: 0 8px 30px rgba(0, 0, 0, .45); }

/* ---- Nav link underline sweep ---- */
nav a { position: relative; }
nav a::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: -6px;
    width: 0;
    height: 1px;
    background: #3366ff;
    transition: width .3s ease;
}
nav a:hover::after { width: 100%; }

/* ---- Hamburger (injected by site-animations.js) ---- */
.sa-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: flex-end;
    gap: 5px;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    z-index: 60;
}
@media (max-width: 767px) {
    .sa-hamburger { display: flex; }
}
.sa-hamburger span {
    display: block;
    height: 2px;
    background: #e2e2e2;
    transition: transform .3s ease, opacity .3s ease, width .3s ease, background .3s ease;
}
.sa-hamburger span:nth-child(1) { width: 24px; }
.sa-hamburger span:nth-child(2) { width: 18px; }
.sa-hamburger span:nth-child(3) { width: 24px; }
.sa-hamburger.sa-open span { background: #3366ff; }
.sa-hamburger.sa-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); width: 24px; }
.sa-hamburger.sa-open span:nth-child(2) { opacity: 0; }
.sa-hamburger.sa-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); width: 24px; }

/* ---- Mobile dropdown panel (JS toggles this class on the existing nav-links div) ---- */
@media (max-width: 767px) {
    .sa-mobile-open {
        display: flex !important;
        position: fixed;
        top: 65px;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 0 !important;
        background: rgba(10, 10, 10, .97);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-bottom: 1px solid #2a2a2a;
        padding: 8px 32px 24px;
        max-height: calc(100vh - 65px);
        overflow-y: auto;
        animation: saSlideDown .35s cubic-bezier(.22, .61, .36, 1) both;
    }
    .sa-mobile-open a {
        width: 100%;
        padding: 16px 0;
        border-bottom: 1px solid rgba(255, 255, 255, .06);
        font-size: 12px;
    }
    body.sa-nav-locked { overflow: hidden; }
}
@keyframes saSlideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Scroll-triggered reveal — transition-based, not a @keyframes
        animation. A "both"-fill animation on transform never releases
        the property afterward (animations beat inline styles in the
        cascade), which silently blocked .sa-tilt's mouse-driven
        transform on these same elements. A transition hands transform
        back to the normal cascade once it settles, so inline styles
        (tilt) can freely override it again. ---- */
[data-sa-reveal] {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity .7s cubic-bezier(.22, .61, .36, 1), transform .7s cubic-bezier(.22, .61, .36, 1);
}
[data-sa-reveal].sa-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ---- Scroll progress bar ---- */
#sa-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 2px;
    width: 0%;
    background: #3366ff;
    box-shadow: 0 0 8px rgba(51, 102, 255, .8);
    z-index: 9999;
    pointer-events: none;
}

/* ---- Back-to-top button ---- */
#sa-to-top {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0a0a0a;
    border: 1px solid #3366ff;
    color: #3366ff;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity .3s ease, transform .3s ease, background .2s ease, color .2s ease;
    z-index: 50;
}
#sa-to-top.sa-show { opacity: 1; pointer-events: auto; transform: translateY(0); }
#sa-to-top:hover { background: #3366ff; color: #fff; }
#sa-to-top svg { width: 18px; height: 18px; }
@media (max-width: 767px) {
    #sa-to-top { right: 14px; bottom: 14px; width: 40px; height: 40px; }
}

/* ---- Hero pointer-glow (desktop / fine-pointer only, scoped to .matrix-grid) ---- */
@media (min-width: 768px) {
    .matrix-grid { position: relative; }
    .matrix-grid::before {
        content: "";
        position: absolute;
        inset: 0;
        pointer-events: none;
        background: radial-gradient(420px circle at var(--sa-x, 50%) var(--sa-y, 50%), rgba(51, 102, 255, .10), transparent 60%);
        opacity: 0;
        transition: opacity .4s ease;
        z-index: 1;
    }
    .matrix-grid:hover::before { opacity: 1; }
}

/* ---- Sitewide cursor glow — follows the pointer on every page, not just the hero ---- */
@media (min-width: 768px) {
    #sa-cursor-glow {
        position: fixed;
        inset: 0;
        pointer-events: none;
        z-index: 2;
        opacity: 0;
        transition: opacity .5s ease;
        background: radial-gradient(600px circle at var(--sa-x, 50%) var(--sa-y, 50%), rgba(51, 102, 255, .07), transparent 70%);
    }
    #sa-cursor-glow.sa-active { opacity: 1; }
}

/* ---- Custom trailing cursor (dot + lagging ring) — desktop / fine-pointer only.
        Layered on top of the default system cursor, not a replacement for it. ---- */
@media (min-width: 768px) and (hover: hover) and (pointer: fine) {
    #sa-cursor-dot, #sa-cursor-ring {
        position: fixed;
        top: 0;
        left: 0;
        pointer-events: none;
        border-radius: 9999px;
        transform: translate3d(-50%, -50%, 0);
        opacity: 0;
        z-index: 9998;
    }
    #sa-cursor-dot {
        width: 6px;
        height: 6px;
        background: #3366ff;
        transition: opacity .3s ease;
    }
    #sa-cursor-ring {
        width: 32px;
        height: 32px;
        border: 1px solid rgba(51, 102, 255, .5);
        transition: opacity .3s ease, width .25s ease, height .25s ease, background-color .25s ease, border-color .25s ease;
    }
    body.sa-cursor-active #sa-cursor-dot,
    body.sa-cursor-active #sa-cursor-ring { opacity: 1; }

    #sa-cursor-ring.sa-cursor-hover {
        width: 54px;
        height: 54px;
        background: rgba(51, 102, 255, .1);
        border-color: #3366ff;
    }
}

/* ---- CTA shine sweep — scoped to real solid primary buttons only ---- */
a.bg-primary, button.bg-primary {
    position: relative;
    overflow: hidden;
}
a.bg-primary::before, button.bg-primary::before {
    content: "";
    position: absolute;
    top: 0;
    left: -60%;
    width: 40%;
    height: 100%;
    background: linear-gradient(120deg, transparent, rgba(255, 255, 255, .25), transparent);
    transform: skewX(-20deg);
    transition: left .6s ease;
    pointer-events: none;
}
a.bg-primary:hover::before, button.bg-primary:hover::before { left: 130%; }
