
/* ── Frosted full-screen overlay open (update modal, etc.): freeze the ambient.
   A full-viewport backdrop-filter blur re-samples everything behind it every
   frame; over the continuously-animating aurora/grid that makes the blur flicker
   on some GPUs/compositors (a known Chromium backdrop-filter-over-animation issue,
   reported on the Xeneon Edge / weaker GPUs — issue #56). Pausing the animation
   while the overlay is up leaves the blurred backdrop static, so there's nothing
   to re-rasterize — invisible behind the blur, and the flicker is gone. Unlike
   game/perf mode the ambient is NOT hidden (opacity kept), so it still shows,
   softly blurred, through the glass. ──────────────────────────────────── */
body.overlay-frozen .aurora-blob,
body.overlay-frozen .grid-plane { animation-play-state: paused; }

/* ── Hybrid GPU: freeze the ambient for the whole session. On an iGPU+dGPU
   machine the native shell deliberately renders on the chip that drives the
   target display (apps/native/src-tauri/src/gpu.rs) so composited frames are not
   copied cross-adapter — ~1.5 idle CPU cores saved, but far less real-time budget
   on the weaker chip. js/custom-bg.js and js/deck/deck.js already freeze the animated
   background and the Deck decor on this signal; the aurora/grid were left out by
   oversight until v4.6.2, which meant the two layers Xenon draws for decoration
   kept animating while the background the USER chose was the one stopped —
   exactly backwards, and it sent a theme author debugging their own code (#118).
   Unlike the freezes above this one is not contextual: it holds for the session,
   so the ambient is a still image on this hardware. The user can switch it off
   (hubSettings.hybridGpuAnimationPause → js/native-bridge.js drops the class),
   accepting the frame-rate cost. No effect on single-GPU machines, dual-discrete
   rigs, or the browser surface. ─────────────────────────────────────────── */
body.low-power-gpu .aurora-blob,
body.low-power-gpu .grid-plane { animation-play-state: paused; }

/* ── Idle / hidden: pause the ambient once the user stops interacting, or when
   the dashboard tab is hidden. The layers stay visible at their current frame
   (opacity untouched) but the per-frame compositor work stops — the real win on
   hybrid-GPU setups, where the dashboard renders on the discrete GPU while the
   Xeneon Edge is driven by the integrated GPU, so every presented frame is copied
   cross-adapter and keeps the discrete GPU awake for a static picture. Resumes
   instantly on the next pointer/key/touch input or when the tab is shown again
   (js/ambient/ambient-idle.js). Purely an optimization — the look is identical while the
   user is present, and nothing is ever hidden. ──────────────────────────── */
body.ambient-idle .aurora-blob,
body.ambient-idle .grid-plane { animation-play-state: paused; }
/* The dashboard's many small persistent decorative loops (blinking clock colon,
   ✦ logo shimmer, live/status dots, the "no media" equaliser + art spin, the
   Vitals heartbeat, Bit's bob, ambient Deck keys) are NOT frozen here in CSS —
   they are paused precisely, via the Web Animations API, in js/ambient/ambient-idle.js
   (pause every *infinite* running animation, resume on wake). A CSS allowlist
   was tried and is unmaintainable: these loops live on ::before/::after pseudos
   and behind ancestor-state selectors, so a class list silently misses half of
   them, while a blanket `*` pause would strand a toast or now-playing card mid
   entry-animation at opacity 0. Filtering to infinite iterations gets exactly
   the decorative loops and never a finite reveal. */

/* ── Performance mode: a broader, user-confirmed optimization. Hides the
   ambient background layers (like game mode) and stops decorative @keyframes
   animations across the dashboard to cut compositor work. Fully reversible —
   removing body.perf-mode restores everything.
   IMPORTANT: animations must COMPLETE instantly, never freeze (play-state:
   paused). An element revealed while perf-mode is on re-triggers its entry
   animation; frozen at its first frame (opacity: 0) it stays INVISIBLE even
   though the JS shows it — this hid the Game Companion pill and left a blank
   hole where the layout-editor toolbar belongs. Forcing a single ~instant
   iteration lands every element on its final visible state, while infinite
   decorative loops (the real GPU cost) finish one 10ms pass and stop. ──── */
body.perf-mode #bg-aurora,
body.perf-mode #bg-grid,
body.perf-mode #custom-bg-layer {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.45s ease, visibility 0s linear 0.45s;
}
body.perf-mode *,
body.perf-mode *::before,
body.perf-mode *::after {
  animation-duration: 0.01s !important;
  animation-delay: 0s !important;
  animation-iteration-count: 1 !important;
}

/* ============================================================
   Static background — premium, zero-animation
   ------------------------------------------------------------
   An alternative to the animated aurora for users who want the
   dashboard to look rich but cost essentially nothing to render.
   The whole composition is a stack of static gradients painted
   ONCE: no @keyframes, no canvas, no rAF — after the first paint
   the compositor does nothing, so idle cost ≈ a flat colour.
   Selected via Settings → Sfondo (data-bg-static on <body>); it is
   mutually exclusive with #bg-aurora (settings.js switches one off
   when the other is on) and, like the aurora/grid, hidden when a
   custom image/video background is set. Because nothing animates,
   it is deliberately NOT paused by game / performance / idle mode —
   keeping it visible there is free.
   ============================================================ */
#bg-static {
  position: fixed;
  inset: 0;
  z-index: 0;            /* behind the shell (z-index:1), like the aurora/grid */
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.45s ease;
  contain: strict;
  isolation: isolate;
}

/* Code-defined animated background: a sandboxed iframe (see js/custom-bg.js)
   painting a full-viewport canvas. Same backdrop layer as the aurora/static —
   behind the shell, never intercepting touch. Fades in when mounted. */
#custom-bg-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  contain: strict;
  isolation: isolate;
  opacity: 0;
  transition: opacity 0.45s ease;
}
body.custom-bg-on #custom-bg-layer { opacity: 1; }
#custom-bg-layer iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  pointer-events: none;
}
body[data-bg-static] #bg-static { opacity: var(--static-opacity, 1); }

/* Fine static grain, painted once. Large accent gradients band visibly on the
   Xeneon Edge LCD; a low-alpha noise overlay dithers those steps away. It never
   re-rasterizes (no animation), so it stays effectively free. */
#bg-static::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-appearance="light"] #bg-static::after { opacity: 0.03; }

/* ── Dusk: the wallpaper of a new install. A picture, because glass needs big colour
   fields behind it, and its grain is baked in (tools/wallpapers). ── */
body[data-bg-static="dusk"] #bg-static {
  background: #161c30 url("../assets/wallpapers/dusk.webp") center / cover no-repeat;
}
:root[data-appearance="light"] body[data-bg-static="dusk"] #bg-static {
  background: #e9edf3 url("../assets/wallpapers/dusk-light.webp") center / cover no-repeat;
}
body[data-bg-static="dusk"] #bg-static::after { display: none; }

/* ── Nebulosa: the aurora, frozen — soft accent pools + depth vignette ── */
body[data-bg-static="nebulosa"] #bg-static {
  background:
    radial-gradient(120% 95% at 16% 10%, rgba(var(--accent-rgb), 0.42), transparent 55%),
    radial-gradient(110% 100% at 88% 90%, rgba(var(--accent-rgb), 0.22), transparent 58%),
    radial-gradient(80% 72% at 62% 28%, rgba(255, 255, 255, 0.06), transparent 60%),
    radial-gradient(150% 130% at 50% 46%, transparent 52%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, #0b0e13, #070a0e);
}
:root[data-appearance="light"] body[data-bg-static="nebulosa"] #bg-static {
  background:
    radial-gradient(120% 95% at 16% 10%, rgba(var(--accent-rgb), 0.30), transparent 56%),
    radial-gradient(110% 100% at 88% 90%, rgba(var(--accent-rgb), 0.16), transparent 60%),
    radial-gradient(150% 130% at 50% 46%, transparent 60%, rgba(20, 30, 45, 0.10) 100%),
    linear-gradient(180deg, #f4f7fb, #e7ecf3);
}

/* ── Prisma: mesh gradient — accent-led with analogous violet/cyan depth ── */
body[data-bg-static="prisma"] #bg-static {
  background:
    radial-gradient(90% 82% at 8% 18%, rgba(var(--accent-rgb), 0.40), transparent 52%),
    radial-gradient(82% 80% at 86% 12%, rgba(132, 92, 255, 0.30), transparent 55%),
    radial-gradient(95% 92% at 78% 92%, rgba(var(--accent-rgb), 0.26), transparent 55%),
    radial-gradient(80% 80% at 22% 96%, rgba(40, 185, 235, 0.24), transparent 55%),
    linear-gradient(135deg, #0a0d13, #0c0910);
}
:root[data-appearance="light"] body[data-bg-static="prisma"] #bg-static {
  background:
    radial-gradient(90% 82% at 8% 18%, rgba(var(--accent-rgb), 0.26), transparent 54%),
    radial-gradient(82% 80% at 86% 12%, rgba(132, 92, 255, 0.20), transparent 56%),
    radial-gradient(95% 92% at 78% 92%, rgba(var(--accent-rgb), 0.18), transparent 56%),
    radial-gradient(80% 80% at 22% 96%, rgba(40, 185, 235, 0.16), transparent 56%),
    linear-gradient(135deg, #f5f7fb, #eef0f7);
}

/* ── Halo: cinematic single accent glow into deep near-black ── */
body[data-bg-static="halo"] #bg-static {
  background:
    radial-gradient(70% 78% at 74% 24%, rgba(var(--accent-rgb), 0.52), rgba(var(--accent-rgb), 0.10) 32%, transparent 60%),
    radial-gradient(160% 130% at 50% 52%, transparent 38%, rgba(0, 0, 0, 0.74) 100%),
    linear-gradient(180deg, #090b0f, #050608);
}
:root[data-appearance="light"] body[data-bg-static="halo"] #bg-static {
  background:
    radial-gradient(70% 78% at 74% 24%, rgba(var(--accent-rgb), 0.34), rgba(var(--accent-rgb), 0.08) 34%, transparent 62%),
    radial-gradient(160% 130% at 50% 52%, transparent 52%, rgba(20, 28, 44, 0.12) 100%),
    linear-gradient(180deg, #eef2f7, #e0e6ee);
}

/* ── See-through window (native app on Windows) ───────────────
   The shell built the window transparent (apps/native/src-tauri/src/
   see_through.rs) and js/native-bridge.js set html.see-through, so the
   desktop under the window (a Wallpaper Engine scene, the wallpaper) is
   the backdrop. Nothing of Xenon's own may paint the page ground: the
   theme colour on html/body (themes set it there too, hence !important)
   and the media layer's own fill. applyHubSettings() already switches
   every backdrop layer off; hiding them here as well means a layer that
   some later code turns on cannot cover the desktop by accident.
   The media layer's dim (::after) stays: it is "Background dim", and
   over an arbitrary wallpaper it is what keeps the text readable. */
html.see-through,
html.see-through body {
  background: transparent !important;
}
html.see-through .user-bg-layer { background: transparent; }
html.see-through .user-bg-layer img,
html.see-through .user-bg-layer video,
html.see-through #bg-aurora,
html.see-through #bg-grid,
html.see-through #bg-static,
html.see-through #custom-bg-layer {
  display: none !important;
}
