/* =============================================================================
   EFFECTS.CSS - Advanced Visual Effects System
   Zeroed Ascent - Indie Game Studio | REDESIGN v2
   ============================================================================= */

/* --- CRT SCANLINES --- */
.fx-scanlines {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: var(--z-fx);
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.15) 2px,
        rgba(0, 0, 0, 0.15) 4px
    );
    opacity: 0.08;
    will-change: auto;
    contain: strict;
}

/* --- ANIMATED 3D GRID BACKGROUND --- */
.fx-grid-bg {
    position: fixed;
    inset: -50%;
    width: 200vw;
    height: 200vh;
    background-image:
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 60px 60px;
    transform: perspective(500px) rotateX(60deg);
    opacity: 0.12;
    z-index: var(--z-background);
    will-change: background-position;
    animation: gridScroll 30s linear infinite;
    contain: strict;
}

@keyframes gridScroll {
    0% { background-position: 0 0; }
    100% { background-position: 0 60px; }
}

.fx-grid-bg.paused {
    animation-play-state: paused;
}

@media (max-width: 768px) {
    .fx-grid-bg {
        animation: none;
        opacity: 0.06;
    }
}

/* --- VIGNETTE EFFECT --- */
.fx-vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: calc(var(--z-fx) - 2);
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        transparent 40%,
        rgba(3, 3, 8, 0.3) 70%,
        rgba(3, 3, 8, 0.7) 100%
    );
    contain: strict;
}

/* --- NOISE TEXTURE OVERLAY --- */
.fx-noise {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: calc(var(--z-fx) - 1);
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    contain: strict;
}

/* --- AMBIENT GLOW ORB (radial light that follows theme) --- */
.fx-ambient-orb {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    pointer-events: none;
    z-index: var(--z-background);
    opacity: 0.07;
    filter: blur(120px);
    animation: ambientOrb 20s ease-in-out infinite;
    contain: strict;
}

.fx-ambient-orb.primary {
    background: var(--accent-primary);
    top: -200px;
    right: -200px;
}

.fx-ambient-orb.secondary {
    background: var(--accent-secondary);
    bottom: -200px;
    left: -200px;
    animation-delay: -10s;
    animation-direction: reverse;
}

@keyframes ambientOrb {
    0%, 100% {
        transform: translate(0, 0) scale(1);
        opacity: 0.05;
    }
    25% {
        transform: translate(-50px, 30px) scale(1.1);
        opacity: 0.08;
    }
    50% {
        transform: translate(20px, -40px) scale(0.9);
        opacity: 0.06;
    }
    75% {
        transform: translate(40px, 20px) scale(1.05);
        opacity: 0.07;
    }
}

/* --- GHOST TRAIL PARTICLES --- */
.ghost-particle {
    position: absolute;
    width: 60px;
    height: 80px;
    pointer-events: none;
    opacity: 0.3;
    z-index: calc(var(--z-player) - 10);
    will-change: opacity, transform;
    contain: layout style;
}

/* --- HUD CORNER BRACKETS --- */
.hud-corners {
    position: fixed;
    inset: 1.5rem;
    pointer-events: none;
    z-index: var(--z-base);
    opacity: 0.15;
}

.hud-corners::before,
.hud-corners::after,
.hud-corners .hud-bl,
.hud-corners .hud-br {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    border-color: var(--accent-primary);
    border-style: solid;
    border-width: 0;
}

.hud-corners::before {
    top: 0;
    left: 0;
    border-top-width: 1px;
    border-left-width: 1px;
}

.hud-corners::after {
    top: 0;
    right: 0;
    border-top-width: 1px;
    border-right-width: 1px;
}

.hud-corners .hud-bl {
    bottom: 0;
    left: 0;
    border-bottom-width: 1px;
    border-left-width: 1px;
}

.hud-corners .hud-br {
    bottom: 0;
    right: 0;
    border-bottom-width: 1px;
    border-right-width: 1px;
}

/* --- GLITCH TEXT EFFECT --- */
.glitch-text {
    position: relative;
}

.glitch-text::before,
.glitch-text::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.glitch-text::before {
    color: var(--accent-tertiary);
    animation: glitch-shift-1 4s infinite linear alternate-reverse;
    clip-path: polygon(0 0, 100% 0, 100% 35%, 0 35%);
    opacity: 0.8;
}

.glitch-text::after {
    color: var(--accent-primary);
    animation: glitch-shift-2 3s infinite linear alternate-reverse;
    clip-path: polygon(0 65%, 100% 65%, 100% 100%, 0 100%);
    opacity: 0.8;
}

@keyframes glitch-shift-1 {
    0%, 90%, 100% { transform: translate(0); }
    92% { transform: translate(-3px, 1px); }
    94% { transform: translate(2px, -1px); }
    96% { transform: translate(-1px, 2px); }
    98% { transform: translate(3px, 0); }
}

@keyframes glitch-shift-2 {
    0%, 88%, 100% { transform: translate(0); }
    90% { transform: translate(2px, -1px); }
    93% { transform: translate(-3px, 1px); }
    95% { transform: translate(1px, -2px); }
    97% { transform: translate(-2px, 0); }
}

/* --- HOLOGRAPHIC SHIMMER --- */
.holo-shimmer {
    position: relative;
    overflow: hidden;
}

.holo-shimmer::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(
        45deg,
        transparent 30%,
        rgba(0, 234, 255, 0.03) 40%,
        rgba(191, 90, 242, 0.03) 50%,
        transparent 60%
    );
    animation: holoShimmer 8s linear infinite;
    pointer-events: none;
}

@keyframes holoShimmer {
    0% { transform: translateX(-30%) translateY(-30%) rotate(0deg); }
    100% { transform: translateX(30%) translateY(30%) rotate(360deg); }
}

/* --- ANIMATED GRADIENT BORDER --- */
.gradient-border {
    position: relative;
    background: var(--bg-panel);
    z-index: 0;
}

.gradient-border::before {
    content: '';
    position: absolute;
    inset: -1px;
    background: linear-gradient(
        var(--gradient-angle, 0deg),
        var(--accent-primary),
        var(--accent-secondary),
        var(--accent-tertiary),
        var(--accent-primary)
    );
    z-index: -1;
    animation: gradientRotate 6s linear infinite;
    opacity: 0.6;
}

.gradient-border::after {
    content: '';
    position: absolute;
    inset: 1px;
    background: var(--bg-panel);
    z-index: -1;
}

@keyframes gradientRotate {
    0% { --gradient-angle: 0deg; }
    100% { --gradient-angle: 360deg; }
}

/* Fallback for browsers without @property support */
@supports not (background: paint(something)) {
    .gradient-border::before {
        animation: gradientBorderFallback 6s linear infinite;
    }

    @keyframes gradientBorderFallback {
        0% { background-position: 0% 50%; }
        50% { background-position: 100% 50%; }
        100% { background-position: 0% 50%; }
    }

    .gradient-border::before {
        background: linear-gradient(
            90deg,
            var(--accent-primary),
            var(--accent-secondary),
            var(--accent-tertiary),
            var(--accent-primary),
            var(--accent-secondary)
        );
        background-size: 300% 100%;
    }
}

/* --- PULSE GLOW --- */
@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 5px var(--accent-glow), 0 0 20px transparent;
    }
    50% {
        box-shadow: 0 0 10px var(--accent-glow), 0 0 40px var(--accent-dim);
    }
}

.pulse-glow {
    animation: pulseGlow 3s ease-in-out infinite;
}

/* --- PULSE ANIMATION --- */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* --- DATA STREAM (vertical flowing dots) --- */
.fx-data-stream {
    position: absolute;
    width: 1px;
    height: 100%;
    top: 0;
    background: repeating-linear-gradient(
        to bottom,
        var(--accent-primary) 0px,
        var(--accent-primary) 2px,
        transparent 2px,
        transparent 12px
    );
    opacity: 0.15;
    animation: dataStream 4s linear infinite;
    pointer-events: none;
}

@keyframes dataStream {
    0% { background-position: 0 0; }
    100% { background-position: 0 14px; }
}

/* --- SCAN LINE (horizontal sweep) --- */
.fx-scan-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
    opacity: 0.3;
    animation: scanSweep 4s ease-in-out infinite;
    pointer-events: none;
}

@keyframes scanSweep {
    0%, 100% {
        top: -2px;
        opacity: 0;
    }
    10% { opacity: 0.3; }
    90% { opacity: 0.3; }
    100% {
        top: 100%;
        opacity: 0;
    }
}

/* --- FADE ANIMATIONS --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

.fade-out {
    animation: fadeOut 0.5s ease forwards;
}

/* --- SLIDE ANIMATIONS --- */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.slide-up {
    animation: slideUp 0.6s var(--transition-smooth) forwards;
}

.slide-down {
    animation: slideDown 0.6s var(--transition-smooth) forwards;
}

/* --- SCROLL REVEAL --- */
.reveal {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

.reveal-left {
    opacity: 0;
    transform: translateX(-40px);
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal-left.revealed {
    opacity: 1;
    transform: translateX(0);
}

.reveal-right {
    opacity: 0;
    transform: translateX(40px);
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal-right.revealed {
    opacity: 1;
    transform: translateX(0);
}

.reveal-scale {
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.8s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal-scale.revealed {
    opacity: 1;
    transform: scale(1);
}

/* Stagger delays for reveal */
.reveal-delay-1 { transition-delay: 0.1s; }
.reveal-delay-2 { transition-delay: 0.2s; }
.reveal-delay-3 { transition-delay: 0.3s; }
.reveal-delay-4 { transition-delay: 0.4s; }
.reveal-delay-5 { transition-delay: 0.5s; }
.reveal-delay-6 { transition-delay: 0.6s; }

/* --- STAGGER ANIMATION DELAYS --- */
.stagger-1 { animation-delay: 0.1s; }
.stagger-2 { animation-delay: 0.2s; }
.stagger-3 { animation-delay: 0.3s; }
.stagger-4 { animation-delay: 0.4s; }
.stagger-5 { animation-delay: 0.5s; }

/* --- HOVER EFFECTS --- */
.hover-lift {
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.hover-lift:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.hover-glow {
    transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.hover-glow:hover {
    box-shadow:
        0 0 20px var(--accent-glow),
        0 0 60px rgba(0, 234, 255, 0.08),
        inset 0 0 20px rgba(0, 234, 255, 0.03);
    border-color: var(--accent-primary);
}

/* --- TYPING CURSOR --- */
@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.cursor-blink::after {
    content: '_';
    animation: blink 1s step-end infinite;
    color: var(--accent-primary);
}

/* --- TYPEWRITER EFFECT --- */
.typewriter {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--accent-primary);
    animation: typewriter-cursor 0.8s step-end infinite;
}

@keyframes typewriter-cursor {
    0%, 50% { border-color: var(--accent-primary); }
    51%, 100% { border-color: transparent; }
}

/* --- ENERGY RING (around player) --- */
@keyframes energyRing {
    0% {
        transform: scale(0.8);
        opacity: 0.6;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.2;
    }
    100% {
        transform: scale(0.8);
        opacity: 0.6;
    }
}

/* --- FLOAT ANIMATION --- */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.animate-float {
    animation: float 4s ease-in-out infinite;
}

/* --- LOADING SPINNER --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* --- BOOT SEQUENCE TEXT --- */
@keyframes bootFadeIn {
    0% { opacity: 0; transform: translateX(-8px); }
    100% { opacity: 1; transform: translateX(0); }
}

.boot-line {
    opacity: 0;
    animation: bootFadeIn 0.3s ease forwards;
    font-size: 0.65rem;
    color: var(--text-dim);
    font-family: var(--font-mono);
    line-height: 1.8;
}

.boot-line .ok {
    color: var(--accent-primary);
}

.boot-line .warn {
    color: var(--accent-warm);
}

.boot-line .err {
    color: var(--accent-tertiary);
}

/* --- PARTICLE CANVAS --- */
#particle-canvas {
    position: fixed;
    inset: 0;
    z-index: var(--z-particles);
    pointer-events: none;
    opacity: 0.6;
}

/* --- REDUCED MOTION PREFERENCES --- */
@media (prefers-reduced-motion: reduce) {
    .fx-grid-bg {
        animation: none;
    }

    .animate-pulse,
    .animate-float,
    .pulse-glow {
        animation: none;
    }

    .ghost-particle {
        display: none;
    }

    .hover-lift:hover {
        transform: none;
    }

    .glitch-text::before,
    .glitch-text::after {
        animation: none;
        display: none;
    }

    .holo-shimmer::after {
        animation: none;
        display: none;
    }

    .reveal,
    .reveal-left,
    .reveal-right,
    .reveal-scale {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .slide-up,
    .slide-down,
    .fade-in,
    .fade-out {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .fx-ambient-orb {
        animation: none;
    }
}

/* --- VISIBILITY API OPTIMIZATIONS --- */
.visibility-hidden .fx-grid-bg,
.visibility-hidden .animate-pulse,
.visibility-hidden .animate-float,
.visibility-hidden .pulse-glow {
    animation-play-state: paused;
}

.visibility-hidden .ghost-particle {
    display: none;
}

.visibility-hidden .fx-ambient-orb {
    animation-play-state: paused;
}

.visibility-hidden #particle-canvas {
    display: none;
}
