/* ============================================
   Glitch Effect Styles
   Cyberpunk glitch animations
   ============================================ */

/* ============================================
   Base Glitch Setup
   ============================================ */

.glitch {
    position: relative;
    display: inline-block;
}

/* Copy text to pseudo-elements for glitch effect */
.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: transparent;
}

/* ============================================
   Glitch Active State
   ============================================ */

.glitch-active::before {
    left: 2px;
    text-shadow: -2px 0 #00ffff;
    clip: rect(44px, 450px, 56px, 0);
    animation: glitch-anim 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) both infinite;
}

.glitch-active::after {
    left: -2px;
    text-shadow: -2px 0 #ff00ff, 2px 2px #00ffff;
    clip: rect(44px, 450px, 56px, 0);
    animation: glitch-anim2 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) reverse both infinite;
}

/* ============================================
   Glitch Animation 1 (Cyan)
   ============================================ */

@keyframes glitch-anim {
    0% {
        clip: rect(93px, 9999px, 43px, 0);
        transform: translate(0);
    }
    20% {
        clip: rect(37px, 9999px, 100px, 0);
        transform: translate(-2px, 2px);
    }
    40% {
        clip: rect(10px, 9999px, 75px, 0);
        transform: translate(-2px, -2px);
    }
    60% {
        clip: rect(65px, 9999px, 12px, 0);
        transform: translate(2px, 2px);
    }
    80% {
        clip: rect(45px, 9999px, 88px, 0);
        transform: translate(2px, -2px);
    }
    100% {
        clip: rect(12px, 9999px, 54px, 0);
        transform: translate(0);
    }
}

/* ============================================
   Glitch Animation 2 (Purple)
   ============================================ */

@keyframes glitch-anim2 {
    0% {
        clip: rect(12px, 9999px, 54px, 0);
        transform: translate(0);
    }
    20% {
        clip: rect(45px, 9999px, 88px, 0);
        transform: translate(2px, -2px);
    }
    40% {
        clip: rect(65px, 9999px, 12px, 0);
        transform: translate(2px, 2px);
    }
    60% {
        clip: rect(10px, 9999px, 75px, 0);
        transform: translate(-2px, -2px);
    }
    80% {
        clip: rect(37px, 9999px, 100px, 0);
        transform: translate(-2px, 2px);
    }
    100% {
        clip: rect(93px, 9999px, 43px, 0);
        transform: translate(0);
    }
}

/* ============================================
   Glitch on Hover (for interactive elements)
   ============================================ */

.glitch:hover::before {
    animation: glitch-anim 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) both 2;
}

.glitch:hover::after {
    animation: glitch-anim2 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) reverse both 2;
}

/* ============================================
   Subtle Glitch (for text)
   ============================================ */

.glitch-subtle::before {
    left: 1px;
    text-shadow: -1px 0 #00ffff;
}

.glitch-subtle::after {
    left: -1px;
    text-shadow: 1px 0 #ff00ff;
}

.glitch-subtle.glitch-active::before {
    animation: glitch-subtle-anim 0.3s ease both;
}

.glitch-subtle.glitch-active::after {
    animation: glitch-subtle-anim 0.3s ease reverse both;
}

@keyframes glitch-subtle-anim {
    0%, 100% {
        transform: translate(0);
        opacity: 0;
    }
    50% {
        transform: translate(2px);
        opacity: 1;
    }
}

/* ============================================
   Glitch Line Effect
   ============================================ */

.glitch-line {
    position: relative;
}

.glitch-line::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: 2px;
    background: #00ffff;
    opacity: 0;
    animation: glitch-line-scan 3s linear infinite;
}

@keyframes glitch-line-scan {
    0%, 90%, 100% {
        opacity: 0;
        top: 50%;
    }
    92% {
        opacity: 1;
        top: 0%;
    }
    94% {
        opacity: 1;
        top: 100%;
    }
    96% {
        opacity: 0;
        top: 50%;
    }
}

/* ============================================
   Glitch Box (for containers)
   ============================================ */

.glitch-box {
    position: relative;
}

.glitch-box::before,
.glitch-box::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 255, 255, 0.1);
    opacity: 0;
    pointer-events: none;
}

.glitch-box.glitch-active::before {
    animation: glitch-box-anim 0.3s steps(2, end) 2;
    left: 2px;
}

.glitch-box.glitch-active::after {
    animation: glitch-box-anim 0.3s steps(2, end) reverse 2;
    left: -2px;
    background: rgba(255, 0, 255, 0.1);
}

@keyframes glitch-box-anim {
    0%, 100% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
}

/* ============================================
   RGB Split Effect
   ============================================ */

.rgb-split {
    position: relative;
}

.rgb-split::before,
.rgb-split::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.8;
}

.rgb-split::before {
    color: #00ffff;
    animation: rgb-split-left 0.4s ease infinite;
}

.rgb-split::after {
    color: #ff00ff;
    animation: rgb-split-right 0.4s ease infinite;
}

@keyframes rgb-split-left {
    0%, 100% {
        transform: translate(0);
        opacity: 0;
    }
    25%, 75% {
        transform: translate(-1px, 0);
        opacity: 0.8;
    }
}

@keyframes rgb-split-right {
    0%, 100% {
        transform: translate(0);
        opacity: 0;
    }
    25%, 75% {
        transform: translate(1px, 0);
        opacity: 0.8;
    }
}

/* ============================================
   Corrupted Text Effect
   ============================================ */

.corrupted {
    position: relative;
}

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

.corrupted.glitch-active::before {
    animation: corrupted-anim 0.5s steps(5, end) infinite;
    color: #00ff00;
    clip: rect(0, 900px, 0, 0);
}

.corrupted.glitch-active::after {
    animation: corrupted-anim 0.5s steps(5, end) infinite reverse;
    color: #ff0000;
    clip: rect(0, 900px, 0, 0);
}

@keyframes corrupted-anim {
    0% {
        clip: rect(42px, 9999px, 44px, 0);
    }
    10% {
        clip: rect(12px, 9999px, 59px, 0);
    }
    20% {
        clip: rect(48px, 9999px, 29px, 0);
    }
    30% {
        clip: rect(18px, 9999px, 83px, 0);
    }
    40% {
        clip: rect(68px, 9999px, 36px, 0);
    }
    50% {
        clip: rect(55px, 9999px, 14px, 0);
    }
    60% {
        clip: rect(25px, 9999px, 61px, 0);
    }
    70% {
        clip: rect(79px, 9999px, 7px, 0);
    }
    80% {
        clip: rect(37px, 9999px, 92px, 0);
    }
    90% {
        clip: rect(64px, 9999px, 20px, 0);
    }
    100% {
        clip: rect(5px, 9999px, 46px, 0);
    }
}

/* ============================================
   Distortion Wave Effect
   ============================================ */

.distortion {
    position: relative;
}

.distortion.glitch-active {
    animation: distortion-wave 0.8s ease;
}

@keyframes distortion-wave {
    0%, 100% {
        transform: skew(0deg);
    }
    20% {
        transform: skew(-2deg);
    }
    40% {
        transform: skew(2deg);
    }
    60% {
        transform: skew(-1deg);
    }
    80% {
        transform: skew(1deg);
    }
}

/* ============================================
   Flicker Effect
   ============================================ */

.flicker {
    animation: flicker 0.15s infinite alternate;
}

@keyframes flicker {
    0%, 50%, 100% {
        opacity: 1;
    }
    25%, 75% {
        opacity: 0.4;
    }
}

/* ============================================
   Glitch for Navigation Links
   ============================================ */

.nav-glitch::before,
.nav-glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
}

.nav-glitch:hover::before {
    opacity: 1;
    color: #00ffff;
    animation: nav-glitch-1 0.3s ease 2;
}

.nav-glitch:hover::after {
    opacity: 1;
    color: #ff00ff;
    animation: nav-glitch-2 0.3s ease 2;
}

@keyframes nav-glitch-1 {
    0%, 100% {
        transform: translate(0);
    }
    50% {
        transform: translate(-2px, 1px);
    }
}

@keyframes nav-glitch-2 {
    0%, 100% {
        transform: translate(0);
    }
    50% {
        transform: translate(2px, -1px);
    }
}

/* ============================================
   Reduced Motion Preferences
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .glitch::before,
    .glitch::after,
    .glitch-active::before,
    .glitch-active::after {
        animation: none;
    }

    .glitch:hover::before,
    .glitch:hover::after {
        animation: none;
    }

    .flicker {
        animation: none;
    }

    .distortion.glitch-active {
        animation: none;
    }
}

/* ============================================
   Mobile Optimizations
   ============================================ */

@media (max-width: 768px) {
    /* Reduce intensity on mobile */
    .glitch-active::before {
        left: 1px;
    }

    .glitch-active::after {
        left: -1px;
    }

    /* Disable some effects on mobile for performance */
    .glitch-line::after {
        display: none;
    }
}
