/* ==========================================================================
   effects.css - the atmosphere layer.

   A skin decides *colours and shapes*. An effect decides *atmosphere*: grain,
   scanlines, falling particles, a glitch. They are separate on purpose, because
   the same effect has to work on any skin, and a new effect must not require
   touching a single component.

       <html data-skin="horror" data-fx="vhs">

   Applied by ui.js: every skin declares a default effect (SKIN_FX in ui.js), the
   user can override it, and "none" is always available.

   Hard rules, because these run on old hardware:
     - CSS only. No WebGL, no canvas, no per-frame JavaScript.
     - Only background-position / transform / opacity animate.
     - Every effect is a fixed-position overlay that ignores pointer events.
     - prefers-reduced-motion turns all of it off.
     - No effect may reduce text contrast below the skin's own baseline.
   ========================================================================== */

/* ---------------------------------------------------------------- scaffold
   One overlay element, created by ui.js only when an effect is active, so a
   plain page pays nothing. Two pseudo-elements give us a pattern layer and a
   wash layer without extra DOM. */

.fx-layer {
  position: fixed;
  inset: 0;
  z-index: 90;              /* above content, below modals (80 is the scrim) */
  pointer-events: none;
  overflow: hidden;
  contain: strict;
}
.fx-layer::before,
.fx-layer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------------- grain
   Film grain: one static SVG noise tile, no animation. Cheap enough to keep on
   permanently, and it is what makes `paper` and `warm` feel printed. */

html[data-fx="grain"] .fx-layer::before {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  opacity: .055;
  mix-blend-mode: multiply;
}
html[data-fx="grain"][data-theme="dark"] .fx-layer::before,
html[data-fx="grain"][data-theme="oled"] .fx-layer::before {
  mix-blend-mode: screen;
  opacity: .04;
}

/* -------------------------------------------------------------- scanlines
   A CRT raster. 3px period, one dark line in three, plus a very faint flicker
   that is slow enough not to be distracting. */

html[data-fx="scanlines"] .fx-layer::before {
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, .28) 0px,
    rgba(0, 0, 0, .28) 1px,
    rgba(0, 0, 0, 0) 1px,
    rgba(0, 0, 0, 0) 3px
  );
  opacity: .5;
  animation: fx-flicker 6s steps(60, end) infinite;
}
html[data-fx="scanlines"] .fx-layer::after {
  background: radial-gradient(120% 100% at 50% 50%, rgba(0,0,0,0) 55%, rgba(0,0,0,.35) 100%);
}
@keyframes fx-flicker {
  0%, 100% { opacity: .5; }
  48% { opacity: .5; }
  50% { opacity: .42; }
  52% { opacity: .5; }
}

/* -------------------------------------------------------------------- vhs
   Horror. Three ingredients: the raster, a rolling bright band, and a chroma
   split on the chrome. The split is done with a 1px text-shadow rather than a
   filter, because a blur filter on the whole page is the one thing that would
   kill a weak GPU. */

html[data-fx="vhs"] .fx-layer::before {
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, .34) 0px,
    rgba(0, 0, 0, .34) 1px,
    rgba(0, 0, 0, 0) 1px,
    rgba(0, 0, 0, 0) 4px
  );
  opacity: .55;
}
html[data-fx="vhs"] .fx-layer::after {
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, .07) 46%,
    rgba(255, 255, 255, .12) 50%,
    rgba(255, 255, 255, .07) 54%,
    rgba(255, 255, 255, 0) 100%
  );
  background-size: 100% 240%;
  animation: fx-vhs-roll 7s linear infinite;
}
@keyframes fx-vhs-roll {
  from { background-position: 0 -120%; }
  to { background-position: 0 120%; }
}
/* the chroma split: red left, cyan right, 1px, on headings and the bar only */
html[data-fx="vhs"] .brand-text b,
html[data-fx="vhs"] .post-who .name,
html[data-fx="vhs"] .card-h,
html[data-fx="vhs"] .profile-head h1 {
  text-shadow: 1px 0 rgba(255, 0, 40, .45), -1px 0 rgba(0, 220, 255, .35);
}
html[data-fx="vhs"] .topbar {
  box-shadow: 0 0 0 1px rgba(255, 0, 40, .25), 0 2px 18px rgba(120, 0, 0, .35);
}
/* a slow horizontal wobble on the whole page, tiny enough to read as tape */
html[data-fx="vhs"] #app {
  animation: fx-vhs-wobble 9s steps(2, end) infinite;
}
@keyframes fx-vhs-wobble {
  0%, 96%, 100% { transform: translateX(0); }
  97% { transform: translateX(-1px); }
  98% { transform: translateX(1px); }
}

/* ----------------------------------------------------------------- matrix
   Falling columns of glyphs. A vertical repeating gradient scrolls downward -
   no elements, no JS. Green on black, faint enough to sit behind text. */

html[data-fx="matrix"] .fx-layer::before {
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(122, 209, 122, 0) 0px,
    rgba(122, 209, 122, .5) 1px,
    rgba(122, 209, 122, .1) 3px,
    rgba(122, 209, 122, 0) 22px,
    rgba(122, 209, 122, .35) 24px,
    rgba(122, 209, 122, 0) 30px
  );
  background-size: 14px 100%;
  opacity: .3;
  animation: fx-matrix-rain 3.2s linear infinite;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,.15), #000 30%, #000 70%, rgba(0,0,0,.15));
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,.15), #000 30%, #000 70%, rgba(0,0,0,.15));
}
@keyframes fx-matrix-rain {
  from { background-position: 0 0; }
  to { background-position: 0 100vh; }
}
html[data-fx="matrix"] .fx-layer::after {
  background: radial-gradient(120% 90% at 50% 0%, rgba(122, 209, 122, .06), rgba(0,0,0,0) 70%);
}

/* ----------------------------------------------------------------- glitch
   Cyberpunk. No continuous animation - a glitch that never stops is just noise.
   Instead the chrome gets a permanent 1px chroma edge, and cards glitch for
   120ms when hovered, which makes the effect feel deliberate. */

html[data-fx="glitch"] .fx-layer::before {
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(0, 240, 255, .06) 0px,
    rgba(0, 240, 255, .06) 1px,
    rgba(0, 0, 0, 0) 1px,
    rgba(0, 0, 0, 0) 2px
  );
  opacity: .8;
}
html[data-fx="glitch"] .brand-text b,
html[data-fx="glitch"] .card-h,
html[data-fx="glitch"] .tab.active {
  text-shadow: 1px 0 rgba(255, 0, 128, .5), -1px 0 rgba(0, 240, 255, .5);
}
html[data-fx="glitch"] .topbar {
  box-shadow: inset 0 -1px 0 rgba(255, 0, 128, .45), inset 0 1px 0 rgba(0, 240, 255, .35);
}
html[data-fx="glitch"] .card:hover,
html[data-fx="glitch"] .post:hover {
  animation: fx-glitch 160ms steps(3, end) 1;
}
@keyframes fx-glitch {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-1px, 1px); }
  66% { transform: translate(1px, -1px); }
  100% { transform: translate(0, 0); }
}

/* ------------------------------------------------------------------- snow
   New year. Two layers at different speeds and sizes gives depth for almost no
   cost. Snow is dots on a tiled radial gradient, so the DOM is untouched. */

html[data-fx="snow"] .fx-layer::before {
  background-image:
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,.85), rgba(255,255,255,0) 60%),
    radial-gradient(2px 2px at 90px 70px, rgba(255,255,255,.6), rgba(255,255,255,0) 60%),
    radial-gradient(1.5px 1.5px at 150px 20px, rgba(255,255,255,.75), rgba(255,255,255,0) 60%),
    radial-gradient(2.5px 2.5px at 60px 120px, rgba(255,255,255,.5), rgba(255,255,255,0) 60%);
  background-size: 180px 180px;
  animation: fx-snow-fall 14s linear infinite;
  opacity: .9;
}
html[data-fx="snow"] .fx-layer::after {
  background-image:
    radial-gradient(1.5px 1.5px at 40px 60px, rgba(255,255,255,.55), rgba(255,255,255,0) 60%),
    radial-gradient(2px 2px at 120px 10px, rgba(255,255,255,.45), rgba(255,255,255,0) 60%),
    radial-gradient(1px 1px at 170px 90px, rgba(255,255,255,.6), rgba(255,255,255,0) 60%);
  background-size: 220px 220px;
  animation: fx-snow-fall 22s linear infinite;
  opacity: .7;
}
@keyframes fx-snow-fall {
  from { background-position: 0 -180px; }
  to { background-position: 30px 100vh; }
}

/* ----------------------------------------------------------------- leaves
   Autumn. Warmer and slower than snow, with a sideways drift so it does not read
   as the same effect recoloured. */

html[data-fx="leaves"] .fx-layer::before {
  background-image:
    radial-gradient(3px 2px at 30px 40px, rgba(214,132,54,.75), rgba(214,132,54,0) 60%),
    radial-gradient(2px 3px at 110px 80px, rgba(176,92,42,.6), rgba(176,92,42,0) 60%),
    radial-gradient(2.5px 2px at 60px 130px, rgba(150,110,40,.65), rgba(150,110,40,0) 60%);
  background-size: 190px 190px;
  animation: fx-leaf-fall 18s linear infinite;
}
html[data-fx="leaves"] .fx-layer::after {
  background-image:
    radial-gradient(2px 2px at 80px 20px, rgba(196,120,50,.45), rgba(196,120,50,0) 60%),
    radial-gradient(3px 2px at 20px 100px, rgba(160,90,40,.4), rgba(160,90,40,0) 60%);
  background-size: 240px 240px;
  animation: fx-leaf-fall 28s linear infinite reverse;
}
@keyframes fx-leaf-fall {
  from { background-position: 0 -190px; }
  to { background-position: -60px 100vh; }
}

/* ----------------------------------------------------------------- aurora
   A very slow drift of two soft colour fields. The calmest effect in the set,
   and the only one that reads as "modern". */

html[data-fx="aurora"] .fx-layer::before {
  background:
    radial-gradient(60% 45% at 15% 10%, rgba(120, 150, 255, .16), rgba(0,0,0,0) 70%),
    radial-gradient(50% 40% at 85% 25%, rgba(180, 120, 255, .12), rgba(0,0,0,0) 70%),
    radial-gradient(55% 45% at 50% 95%, rgba(90, 220, 200, .1), rgba(0,0,0,0) 70%);
  animation: fx-aurora-drift 26s ease-in-out infinite alternate;
}
@keyframes fx-aurora-drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1.02); }
  to { transform: translate3d(2%, 1%, 0) scale(1.08); }
}

/* ------------------------------------------------------------------- glow
   Neon. A pulsing rim on the accent surfaces. Slow and shallow, or it becomes a
   strobe. */

html[data-fx="glow"] .topbar {
  box-shadow: 0 1px 22px rgba(168, 107, 255, .22);
  animation: fx-glow-pulse 5s ease-in-out infinite;
}
html[data-fx="glow"] .card-h i,
html[data-fx="glow"] .brand-mark {
  filter: drop-shadow(0 0 4px rgba(168, 107, 255, .5));
}
@keyframes fx-glow-pulse {
  0%, 100% { box-shadow: 0 1px 22px rgba(168, 107, 255, .22); }
  50% { box-shadow: 0 1px 30px rgba(168, 107, 255, .38); }
}

/* ------------------------------------------------------------------ sheen
   Aero. One diagonal highlight that sweeps the bar every few seconds, exactly
   like the glass in Vista - and, like Vista, only on the bar. */

html[data-fx="sheen"] .topbar {
  position: sticky;   /* keeps the existing behaviour, the sweep needs a stacking context */
}
html[data-fx="sheen"] .topbar::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    100deg,
    rgba(255,255,255,0) 30%,
    rgba(255,255,255,.28) 45%,
    rgba(255,255,255,.05) 52%,
    rgba(255,255,255,0) 70%
  );
  background-size: 240% 100%;
  animation: fx-sheen-sweep 7s ease-in-out infinite;
}
@keyframes fx-sheen-sweep {
  0%, 55% { background-position: 140% 0; }
  75%, 100% { background-position: -60% 0; }
}

/* -------------------------------------------------------------- paper-cut
   Brutal. No motion at all - just a hard 1px misregistration on the bar, the
   print-offset look of a badly aligned two-colour job. */

html[data-fx="paper-cut"] .topbar {
  box-shadow: 3px 3px 0 var(--border);
}
html[data-fx="paper-cut"] .card,
html[data-fx="paper-cut"] .post {
  box-shadow: 4px 4px 0 var(--border);
}

/* ============================================================== controls
   A tiny switch in Settings so an effect can be turned off without changing
   the skin. Rendered by app.more.js. */

.fx-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fx-row .check { margin: 0; }
.fx-note { flex: 1 1 100%; font-size: 11px; color: var(--muted); }

/* Anything that animates above is switched off here, globally, in one place. */
@media (prefers-reduced-motion: reduce) {
  .fx-layer,
  .fx-layer::before,
  .fx-layer::after,
  html[data-fx="vhs"] #app,
  html[data-fx="sheen"] .topbar::after,
  html[data-fx="glow"] .topbar { animation: none !important; }
  html[data-fx="glitch"] .card:hover,
  html[data-fx="glitch"] .post:hover { animation: none !important; }
}
