/* ------------------------------------------------
   TRB Thermal Vision – Styles
   ------------------------------------------------ */

body {
    transition: filter 0.3s ease;
}

/* Thermal only */
html.thermal-active body {
    filter: url(#trb-thermal-filter);
    will-change: filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Low-fi only */
html.lowfi-active body {
    filter: url(#trb-lowfi-filter);
    will-change: filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Night vision only */
html.nightvision-active body {
    filter: url(#trb-nightvision-filter);
    will-change: filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* CRT only */
html.crt-active body {
    filter: url(#trb-crt-filter);
    will-change: filter;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Combinations – stack with low-fi (thermal + nightvision are mutually exclusive) */
html.thermal-active.lowfi-active body {
    filter: url(#trb-thermal-filter) url(#trb-lowfi-filter);
}

html.nightvision-active.lowfi-active body {
    filter: url(#trb-nightvision-filter) url(#trb-lowfi-filter);
}

html.thermal-active.crt-active body {
    filter: url(#trb-thermal-filter) url(#trb-crt-filter);
}

html.nightvision-active.crt-active body {
    filter: url(#trb-nightvision-filter) url(#trb-crt-filter);
}

/* Pixel grid overlay – GPU composited, phase shifts on scroll */
html.lowfi-active body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    background:
        repeating-linear-gradient(
            to right,
            rgba(0, 0, 0, 0.3) 0px,
            rgba(0, 0, 0, 0.3) 2px,
            transparent 2px,
            transparent 8px
        ),
        repeating-linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.3) 0px,
            rgba(0, 0, 0, 0.3) 2px,
            transparent 2px,
            transparent 8px
        );
    background-position: 0 var(--trb-grid-offset, 0px);
    will-change: background-position;
}

/* Force pixelated rendering on images */
html.lowfi-active img {
    image-rendering: pixelated;
}

/* CRT scanline overlay – horizontal interlaced lines */
html.crt-active body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 9998;
    pointer-events: none;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 2px,
        rgba(0, 0, 0, 0.7) 2px,
        rgba(0, 0, 0, 0.7) 4px
    );
    will-change: transform;
    animation: crt-flicker 0.2s infinite;
}

@keyframes crt-flicker {
    0%   { opacity: 1; }
    15%  { opacity: 0.72; }
    28%  { opacity: 0.97; }
    42%  { opacity: 0.65; }
    55%  { opacity: 0.9; }
    70%  { opacity: 0.74; }
    85%  { opacity: 1; }
    92%  { opacity: 0.68; }
    100% { opacity: 0.95; }
}
