/* ============================================
   crft.sh — Animations
   CRT phosphor effects, all CSS-only
   ============================================ */

/* === Scanlines === */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

/* Horizontal scanlines */
.scanlines::before {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent 0px,
        transparent 1px,
        rgba(0, 0, 0, 0.12) 1px,
        rgba(0, 0, 0, 0.12) 2px
    );
    animation: scanline-drift 10s linear infinite;
}

/* RGB sub-pixel hint + flicker */
.scanlines::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(
            90deg,
            rgba(255, 0, 0, 0.008) 0px,
            rgba(0, 255, 0, 0.008) 1px,
            rgba(0, 100, 255, 0.008) 2px,
            transparent 3px
        );
    animation: flicker 8s infinite;
}

@keyframes scanline-drift {
    0% { transform: translateY(0); }
    100% { transform: translateY(4px); }
}

@keyframes flicker {
    0%, 94%, 100% { opacity: 1; }
    95% { opacity: 0.92; }
    96% { opacity: 1; }
    97% { opacity: 0.95; }
}

/* === Blinking Cursor === */
.cursor {
    display: inline-block;
    width: 0.55em;
    height: 1.15em;
    background-color: var(--accent);
    vertical-align: text-bottom;
    animation: blink 1s steps(2, start) infinite;
    box-shadow: 0 0 6px var(--accent-glow);
}

@keyframes blink {
    to { visibility: hidden; }
}

/* === Typewriter === */
.typewriter {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--accent);
    width: 0;
    animation:
        typing 1.2s steps(25, end) forwards,
        cursor-fade 0.7s steps(2, start) infinite;
}

@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes cursor-fade {
    to { border-color: transparent; }
}

/* === Staggered Page Load === */
.main-content {
    animation: fadeIn 0.5s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Stagger panels on load */
.panel:nth-child(1) { animation: panelIn 0.4s ease-out 0.1s both; }
.panel:nth-child(2) { animation: panelIn 0.4s ease-out 0.2s both; }
.panel:nth-child(3) { animation: panelIn 0.4s ease-out 0.3s both; }
.panel:nth-child(4) { animation: panelIn 0.4s ease-out 0.4s both; }
.panel:nth-child(5) { animation: panelIn 0.4s ease-out 0.5s both; }

@keyframes panelIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === Phosphor Glow Pulse === */
.ascii-header pre {
    animation: phosphor-pulse 4s ease-in-out infinite;
}

@keyframes phosphor-pulse {
    0%, 100% {
        text-shadow: 0 0 4px rgba(0, 255, 65, 0.4);
    }
    50% {
        text-shadow:
            0 0 4px rgba(0, 255, 65, 0.4),
            0 0 12px rgba(0, 255, 65, 0.2),
            0 0 20px rgba(0, 255, 65, 0.1);
    }
}

/* === Panel Border Glow on Hover === */
.panel {
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
    border-color: var(--panel-border-bright);
    box-shadow: 0 0 8px rgba(0, 255, 65, 0.08);
}

/* === Link Hover === */
a {
    transition: color 0.2s ease, text-shadow 0.2s ease;
}

/* === Post List Hover Slide === */
.post-list li {
    transition: background 0.2s ease, padding-left 0.2s ease;
}

.post-list li:hover {
    padding-left: 0.5rem;
}

/* === 404 Glitch === */
.four-oh-four pre {
    animation: glitch-glow 3s ease-in-out infinite;
}

@keyframes glitch-glow {
    0%, 100% {
        text-shadow: 0 0 10px rgba(255, 0, 255, 0.4);
    }
    25% {
        text-shadow:
            2px 0 rgba(255, 0, 0, 0.3),
            -2px 0 rgba(0, 255, 255, 0.3),
            0 0 10px rgba(255, 0, 255, 0.4);
    }
    50% {
        text-shadow: 0 0 15px rgba(255, 0, 255, 0.5);
    }
    75% {
        text-shadow:
            -1px 0 rgba(255, 0, 0, 0.2),
            1px 0 rgba(0, 255, 255, 0.2),
            0 0 10px rgba(255, 0, 255, 0.4);
    }
}

/* === Reduced Motion === */
@media (prefers-reduced-motion: reduce) {
    .scanlines::before,
    .scanlines::after {
        animation: none;
    }

    .cursor {
        animation: none;
        visibility: visible;
    }

    .typewriter {
        animation: none;
        width: auto;
        white-space: normal;
        border-right: none;
        overflow: visible;
    }

    .main-content {
        animation: none;
        opacity: 1;
    }

    .panel,
    .panel:nth-child(1),
    .panel:nth-child(2),
    .panel:nth-child(3),
    .panel:nth-child(4),
    .panel:nth-child(5) {
        animation: none;
        opacity: 1;
    }

    .ascii-header pre {
        animation: none;
    }

    .panel {
        transition: none;
    }

    .four-oh-four pre {
        animation: none;
    }

    a {
        transition: none;
    }

    .post-list li {
        transition: none;
    }
}
