/*
 * CRT and Tron effects. Everything hangs off html.fx (toggle on Meer, stored per device).
 * Only opacity/transform are animated; with "reduce motion" only the static scanlines stay.
 */

@property --fx-angle { syntax: '<angle>'; initial-value: 0deg; inherits: false; }

/*
 * Scanlines and the rolling bar sit inside .app and .tabbar, not as position: fixed layers
 * over the screen: with full-screen fixed layers, Safari on iPhone showed content scrolling
 * between the tab bar and its address bar.
 */
html.fx .app { position: relative; }
html.fx .app::after,
html.fx .tabbar::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
}

/* Rolling bar: a soft band of light moving down the content. */
html.fx .app::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: -80px;
    height: 80px;
    z-index: 49;
    pointer-events: none;
    background: linear-gradient(to bottom, transparent, rgba(111, 227, 255, 0.06), transparent);
    animation: fx-roll 8s linear infinite;
}
@keyframes fx-roll { from { top: -80px; } to { top: 100%; } }

/* Flicker: one short, shallow dip every few seconds (far below the 3 flashes/s limit). */
html.fx .app { animation: fx-flicker 6s infinite; }
@keyframes fx-flicker {
    0%, 97%, 100% { opacity: 1; }
    97.5% { opacity: 0.93; }
    98% { opacity: 1; }
    98.6% { opacity: 0.96; }
}

/* Light trace: one lap around a panel border (class set by fx.js on one panel at a time). */
html.fx .panel.is-tracing::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    padding: 1px;
    pointer-events: none;
    background: conic-gradient(from var(--fx-angle), transparent 0 80%, var(--ice) 92%, transparent 100%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    filter: drop-shadow(0 0 3px var(--ice));
    animation: fx-trace 2s linear 1 forwards;
}
@keyframes fx-trace {
    0% { --fx-angle: 0deg; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { --fx-angle: 360deg; opacity: 0; }
}

/* Glitch on a changed value, now and then (class set by fx.js). */
html.fx .fx-glitch { animation: fx-glitch 0.35s steps(2) 1; }
@keyframes fx-glitch {
    0% { text-shadow: 2px 0 var(--sun), -2px 0 var(--ice); transform: translateX(1px); }
    50% { text-shadow: -2px 0 var(--sun), 2px 0 var(--ice); transform: translateX(-1px); }
    100% { transform: none; }
}
html.fx .fx-glitch { display: inline-block; }

/* Boot: panels draw in one after another, only on the first screen of a session. */
html.fx.fx-boot .app > * { animation: fx-boot 0.6s ease-out both; }
html.fx.fx-boot .app > :nth-child(2) { animation-delay: 0.08s; }
html.fx.fx-boot .app > :nth-child(3) { animation-delay: 0.16s; }
html.fx.fx-boot .app > :nth-child(4) { animation-delay: 0.24s; }
html.fx.fx-boot .app > :nth-child(5) { animation-delay: 0.32s; }
html.fx.fx-boot .app > :nth-child(n+6) { animation-delay: 0.4s; }
@keyframes fx-boot {
    0% { clip-path: inset(0 100% 0 0); opacity: 0.3; }
    60% { clip-path: inset(0 0 0 0); opacity: 0.7; }
    70% { opacity: 0.25; }
    100% { clip-path: inset(0 0 0 0); opacity: 1; }
}

html.fx-paused .app::before, html.fx-paused .app { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) {
    html.fx .app::before { display: none; }
    html.fx .app, html.fx .fx-glitch, html.fx.fx-boot .app > *, html.fx .panel.is-tracing::after { animation: none; }
    html.fx .panel.is-tracing::after { display: none; }
}
