/* afterglow-crt | https://github.com/HauntedCrusader/afterglow-crt */

/* BASE ================================================= */
:root{
    --crt-flicker-speed: 3.5s;

    --crt-warp-x: 1.0015;
    --crt-warp-y: 0.9985;
    --crt-warp-speed: 6s;

    --crt-breath-brightness: 1.04;
    --crt-breath-speed: 8s;

    --crt-scanline-dark: .18;
    --crt-scanline-light: .02;
    --crt-scanline-opacity: .9;
    --crt-scanline-size: 2px;

    --crt-beam-height: 140px;
    --crt-beam-blur: 6px;
    --crt-beam-speed: 9.5s;
    --crt-beam-opacity: .6;

    --crt-ghost-opacity: .04;
    --crt-ghost-blur: 2px;

    --crt-overscan: -3px;
}

/* AMBER PRESET */
body.crt-amber{
    background:#140d00;
    color:#ffb000;

    text-shadow:
        0 0 3px rgba(255,176,0,.6),
        0 0 8px rgba(255,176,0,.35),
        0 0 14px rgba(255,176,0,.15);

    --crt-scanline-dark:.26;
    --crt-scanline-light:.05;
    --crt-scanline-opacity:1;

    --crt-ghost-opacity:.10;
    --crt-ghost-blur:3px;

    --crt-breath-brightness:1.07;
    --crt-flicker-speed:3s;
}
body.crt-amber ::selection{
    background:rgba(255,176,0,.25);
    color:#fff2cc;
}

/* CRT LAYERS =========================================== */
body::after{
    content:"";
    position:fixed;
    inset:0;
    pointer-events:none;
    background:inherit;
    opacity: var(--crt-ghost-opacity);
    filter: blur(var(--crt-ghost-blur));
    z-index:2;
}

.screen {
    position: fixed;
    inset: var(--crt-overscan);
    pointer-events: none;
    z-index:3;

    box-shadow:
        inset 0 0 80px rgba(0,0,0,1),
        inset 0 0 140px rgba(0,0,0,.8);

    animation:
        crtFlicker var(--crt-flicker-speed) linear infinite,
        crtWarp var(--crt-warp-speed) ease-in-out infinite,
        crtBreath var(--crt-breath-speed) ease-in-out infinite;
}

/* Scanlines */
.screen::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;

    background: repeating-linear-gradient(
        to bottom,
        rgba(0,0,0,var(--crt-scanline-dark)) 0px,
        rgba(0,0,0,var(--crt-scanline-dark)) var(--crt-scanline-size),
        rgba(0,0,0,var(--crt-scanline-light)) var(--crt-scanline-size),
        rgba(0,0,0,var(--crt-scanline-light)) calc(var(--crt-scanline-size) * 2)
    );

    opacity: var(--crt-scanline-opacity);
    mix-blend-mode: multiply;
}

/* Glass reflection */
.screen::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 5;

    background: radial-gradient(
        ellipse at center,
        rgba(255,255,255,.13) 0%,
        rgba(255,255,255,.06) 30%,
        rgba(0,0,0,.55) 90%,
        rgba(0,0,0,.92) 100%
    );
}

/* Electron beam */
.screen .beam {
    position: absolute;
    left: 0;
    width: 100%;
    z-index: 3;
    pointer-events: none;

    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(255,255,255,.05) 40%,
        rgba(255,255,255,.18) 50%,
        rgba(255,255,255,.05) 60%,
        transparent 100%
    );

    height: var(--crt-beam-height);
    filter: blur(var(--crt-beam-blur));
    opacity: var(--crt-beam-opacity);
    animation: beamDrop var(--crt-beam-speed) cubic-bezier(.25,.1,.25,1) infinite;
}

/* ANIMATIONS =========================================== */
@keyframes crtFlicker {
    0%  { opacity: 1; }
    96% { opacity: 1; }
    97% { opacity: .94; }
    98% { opacity: 1; }
    99% { opacity: .98; }
    100%{ opacity: 1; }
}

@keyframes crtWarp {
    0% { transform: scale(1,1); }
    50% { transform: scale(var(--crt-warp-x), var(--crt-warp-y)); }
    100% { transform: scale(1,1); }
}

@keyframes crtBreath{
    0%,100%{ filter: brightness(1); }
    50%{ filter: brightness(var(--crt-breath-brightness)); }
}

@keyframes beamDrop {
    0% { top: -160px; opacity: 0; }
    15% { opacity: .6; }
    48% {
        top: 50%;
        transform: translateY(-50%);
        opacity: .4;
    }
    58% {
        top: 50%;
        transform: translateY(-50%);
        opacity: 1;
    }
    70% { opacity: 0; }
    100% {
        top: 55%;
        opacity: 0;
    }
}
