/* =====================================================================
   crt.css — the look of sky/crt.js: reset 1 on an old television.
   --crt (set by crt.js, STRENGTH) turns everything here up or down together.
   ===================================================================== */

/* the set: over everything (the buttons and the loading screen too: it's all on the screen), never in the way of a click */
.crt {
    position: fixed;
    inset: 0;
    z-index: 2147483050;
    pointer-events: none;
    overflow: hidden;
}
.crt > i,
.crt > .crt-glass { position: absolute; inset: 0; display: block; }

/* the tube's mask: red, green and blue stripes, side by side */
.crt .crt-mask {
    background: repeating-linear-gradient(to right, rgba(255, 30, 30, .55) 0 1px, rgba(30, 255, 60, .55) 1px 2px, rgba(40, 70, 255, .55) 2px 3px);
    mix-blend-mode: multiply;
    opacity: calc(var(--crt) * .3);
}
/* a dark band rolling slowly up the picture: the camera and the set not quite in step */
.crt .crt-roll {
    inset: auto 0 auto 0;
    top: 0;
    height: 36vh;
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .1) 30%, rgba(0, 0, 0, .17) 50%, rgba(0, 0, 0, .1) 70%, rgba(0, 0, 0, 0));
    opacity: var(--crt);
    animation: crt-roll 11s linear infinite;
    will-change: transform;
}
@keyframes crt-roll {
    from { transform: translateY(105vh); }
    to { transform: translateY(-40vh); }
}
/* the faint flicker of the picture (a few percent darker now and then: never anything like a flash) */
.crt .crt-flick {
    background: #000;
    opacity: 0;
    animation: crt-flick 4.7s steps(1) infinite;
}
@keyframes crt-flick {
    0% { opacity: 0; }
    7% { opacity: calc(var(--crt) * .035); }
    9% { opacity: 0; }
    31% { opacity: calc(var(--crt) * .02); }
    34% { opacity: 0; }
    62% { opacity: calc(var(--crt) * .045); }
    63% { opacity: calc(var(--crt) * .015); }
    66% { opacity: 0; }
    88% { opacity: calc(var(--crt) * .025); }
    90% { opacity: 0; }
}
/* the tube: its rounded corners (black beyond them) and the picture darkening towards its edges. no glare */
.crt .crt-tube {
    border-radius: 7vmin / 9vmin;
    box-shadow:
        0 0 0 40vmax #050505,
        inset 0 0 calc(var(--crt) * 16vmin) calc(var(--crt) * 3vmin) rgba(0, 0, 0, .6),
        inset 0 0 calc(var(--crt) * 3vmin) rgba(0, 0, 0, .45);
}
/* the broadcast's mark: a blinking red ● REC, then LIVE, the camera and the time on air (bottom right, clear of every
   page's buttons; on a phone, up top in the middle, where nothing's tapped) */
.crt .crt-live {
    position: absolute;
    right: calc(4.5vmin + 14px);
    bottom: calc(5vmin + 8px);
    display: flex;
    gap: .9em;
    align-items: baseline;
    white-space: nowrap;
    font: 600 clamp(11px, 1.35vw, 17px)/1 ui-monospace, "Courier New", monospace;
    letter-spacing: .12em;
    color: rgba(255, 255, 255, .82);
    text-shadow: 0 0 6px rgba(255, 255, 255, .45), 1px 0 rgba(255, 40, 80, .6), -1px 0 rgba(40, 200, 255, .6);
    opacity: calc(var(--crt) * .9);
    transition: opacity .8s ease .3s;
}
/* (not over the loading screen: it comes on once that's gone, sky/loader.js #dav-loader) */
html:has(#dav-loader:not(.gone)) .crt .crt-live { opacity: 0; transition: none; }
.crt .crt-rec { color: #ff4a3a; text-shadow: 0 0 7px rgba(255, 50, 40, .8); }
.crt .crt-dot { color: #ff2a2a; text-shadow: 0 0 8px rgba(255, 40, 40, .9); animation: crt-blink 1s steps(1) infinite; }
@keyframes crt-blink { 50% { opacity: 0; } }
.crt .crt-time { opacity: .75; }

/* the whole picture, through the SVG filter crt.js writes (--crt-filter): coarser dots and fewer shades, the tube's stripes,
   red pushed one way and blue the other (hardly in the middle, most at the edges, as on a real tube), then the colours
   fuller and the brightest parts glowing, as a camera films a television. html is the one element a filter doesn't
   spoil fixed positions on */
html.crt-on.crt-split { filter: var(--crt-filter); }
/* (with the coarser dots the stripes are in the filter, after them: under them they'd all be read as one stripe) */
html.crt-on.crt-split.crt-dots .crt .crt-mask { display: none; }

/* the glass from Blender (2 Nov, tools/blender/crt_tv.py): its pictures are beside the page, not in it, so the filter's on the body.
   a filter on the body makes the body what its fixed pieces are measured from, so it's kept exactly the window's size */
html.crt-on.crt-set-on { background: #050505; }
html.crt-on.crt-set-on body { width: 100vw; height: 100vh; margin: 0; overflow: hidden; }
html.crt-on.crt-set-on.crt-split { filter: none; }
html.crt-on.crt-set-on.crt-split body { filter: var(--crt-filter); }
html.crt-set-on .crt .crt-mask,
html.crt-set-on .crt .crt-tube { display: none; }
/* (each its own layer on the page's root, stretched to the window; the stripes multiplied into the picture under them) */
.crt-tv {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: fill;
    pointer-events: none;
    z-index: 2147483600;
}
/* (the stripes are in the tube, under the glass: what the glass reflects lies smooth on top of them, whichever arrives first) */
.crt-tv-lines { mix-blend-mode: multiply; opacity: var(--crt); z-index: 2147483590; }

/* switching on and off: two black halves closing on a bright line (and opening off it), over everything but the white-out */
.crt-power {
    position: fixed;
    inset: 0;
    z-index: 2147483550;
    pointer-events: none;
}
.crt-power > i { position: absolute; left: 0; right: 0; display: block; }
.crt-power .cp-top { top: 0; height: 50%; background: #000; }
.crt-power .cp-bot { bottom: 0; height: 50%; background: #000; }
.crt-power .cp-line {
    top: 50%;
    height: 3px;
    margin-top: -1.5px;
    background: #fff;
    box-shadow: 0 0 12px 3px rgba(220, 235, 255, .9), 0 0 40px 10px rgba(180, 210, 255, .5);
}
/* (on: the line's there, then the halves draw back off it, a little too bright for a moment) */
.crt-boot .cp-top { animation: crt-open-top .55s cubic-bezier(.7, 0, .3, 1) .25s both; }
.crt-boot .cp-bot { animation: crt-open-bot .55s cubic-bezier(.7, 0, .3, 1) .25s both; }
.crt-boot .cp-line { animation: crt-boot-line 1.2s ease-out both; }
@keyframes crt-open-top { from { transform: translateY(0); } to { transform: translateY(-101%); } }
@keyframes crt-open-bot { from { transform: translateY(0); } to { transform: translateY(101%); } }
@keyframes crt-boot-line {
    0% { transform: scaleX(0); opacity: 1; }
    20% { transform: scaleX(1); opacity: 1; }
    45% { transform: scaleX(1) scaleY(40); opacity: .5; }
    100% { transform: scaleX(1) scaleY(120); opacity: 0; }
}
/* (off: the halves close on a bright line, the line shrinks to a dot, and the dot fades) */
.crt-shut .cp-top { animation: crt-close-top .28s cubic-bezier(.6, 0, .9, .4) both; }
.crt-shut .cp-bot { animation: crt-close-bot .28s cubic-bezier(.6, 0, .9, .4) both; }
.crt-shut .cp-line { animation: crt-shut-line 1.2s both; }
@keyframes crt-close-top { from { transform: translateY(-101%); } to { transform: translateY(0); } }
@keyframes crt-close-bot { from { transform: translateY(101%); } to { transform: translateY(0); } }
@keyframes crt-shut-line {
    0% { opacity: 0; transform: scaleX(1) scaleY(60); }
    18% { opacity: 1; transform: scaleX(1) scaleY(1); }
    50% { opacity: 1; transform: scaleX(.004) scaleY(1.6); }
    68% { opacity: 1; transform: scaleX(.004) scaleY(1.6); }
    100% { opacity: 0; transform: scaleX(.002) scaleY(1); }
}
.crt-fade { background: #000; animation: crt-fade .4s ease-in both; }
@keyframes crt-fade { from { opacity: 0; } to { opacity: 1; } }

/* phones: the mark up top in the middle, where nothing's tapped, and everything lighter */
@media (max-width: 620px), (max-height: 500px) {
    /* (1 Nov: on a phone the stripes are as big as on a computer, next to much smaller words: so nearly gone, and the
       band lighter, or nothing can be read) */
    .crt .crt-mask { opacity: calc(var(--crt) * .08); }
    .crt .crt-roll { opacity: calc(var(--crt) * .7); }
    .crt .crt-tube { border-radius: 5vmin / 6vmin; }
    .crt .crt-live { font-size: 9px; gap: .7em; right: auto; bottom: auto; left: 50%; top: calc(3vmin + 58px); transform: translateX(-50%); }
}

@media (max-width: 620px) {
    .crt .crt-live { top: calc(3vmin + 92px); }              /* (under the "tap anywhere to hear it" note) */
}

@media (prefers-reduced-motion: reduce) {
    .crt .crt-dot { animation: none; }
    .crt .crt-roll, .crt .crt-flick { animation: none; display: none; }
}
