/* Background designs — Sonar, Aurora, Horizon and Void.
 *
 * Moved out of atlas-themes.css so the login screen runs the same rules as
 * the app. It used to carry hand-written miniatures of these instead, and
 * they were wrong: aurora's dots were drawn at 46px against the app's
 * 96px/132px, roughly four times the density, which is what made the login
 * screen read as a dot texture the app never showed.
 *
 * The selectors still say body.atlas-os because the markup is the same on
 * both pages -- login.html carries the same #atlas-os-backdrop and the body
 * class with it. Nothing else from atlas-themes.css is needed: these rules
 * compose entirely from --atlas-background, --atlas-primary, --atlas-secondary
 * and --atlas-grid.
 */

/* The backdrop's own geometry. These were in style.css, which the login
   screen does not load, so without them the backdrop had no position and the
   designs above had nothing to paint on. The app still loads style.css, so
   they are removed there rather than duplicated. */

.atlas-os-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 120% 80% at 50% 40%, #0a1628 0%, #050a12 55%, #020508 100%);
}

.atlas-mc-bg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(var(--atlas-rgb, 80, 200, 255), 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(var(--atlas-rgb, 80, 200, 255), 0.04) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 90% 75% at 50% 45%, black 15%, transparent 80%);
}

.atlas-mc-scanline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(var(--atlas-rgb, 80, 200, 255), 0.04) 48%,
    transparent 52%
  );
  background-size: 100% 240px;
  animation: atlas-mc-scanline 10s linear infinite;
  opacity: 0.4;
}

@keyframes atlas-mc-scanline {
  from { background-position: 0 -240px; }
  to { background-position: 0 100vh; }
}

/* ── Shared multitheme backgrounds ──────────────────────────────────────
 * Backgrounds are independent of colour themes. Every design is composed
 * from the active palette, so users can pair any theme with any background. */
body.atlas-os:not([data-atlas-background]),
body.atlas-os[data-atlas-background="sonar"],
html[data-atlas-background="sonar"] body.atlas-os {
  --atlas-background-particle-opacity: 0.7;
}

body.atlas-os:not([data-atlas-background]) .atlas-os-backdrop,
body.atlas-os[data-atlas-background="sonar"] .atlas-os-backdrop,
html[data-atlas-background="sonar"] body.atlas-os .atlas-os-backdrop {
  background: radial-gradient(ellipse 120% 80% at 50% 40%, color-mix(in srgb, var(--atlas-background) 82%, var(--atlas-primary)) 0%, var(--atlas-background) 55%, var(--os-backdrop-edge, #020508) 100%) !important;
}

body.atlas-os:not([data-atlas-background]) .atlas-mc-bg,
body.atlas-os[data-atlas-background="sonar"] .atlas-mc-bg,
html[data-atlas-background="sonar"] body.atlas-os .atlas-mc-bg {
  display: block;
  background-image:
    linear-gradient(var(--atlas-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--atlas-grid) 1px, transparent 1px) !important;
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 90% 75% at 50% 45%, black 15%, transparent 80%);
}

body.atlas-os:not([data-atlas-background]) .atlas-mc-scanline,
body.atlas-os[data-atlas-background="sonar"] .atlas-mc-scanline,
html[data-atlas-background="sonar"] body.atlas-os .atlas-mc-scanline {
  display: block;
}

body.atlas-os[data-atlas-background="aurora"] .atlas-os-backdrop,
html[data-atlas-background="aurora"] body.atlas-os .atlas-os-backdrop {
  background:
    radial-gradient(ellipse 70% 55% at 18% 20%, color-mix(in srgb, var(--atlas-primary) 24%, transparent), transparent 72%),
    radial-gradient(ellipse 65% 50% at 82% 72%, color-mix(in srgb, var(--atlas-secondary) 22%, transparent), transparent 74%),
    linear-gradient(145deg, color-mix(in srgb, var(--atlas-background) 94%, var(--atlas-primary)), var(--atlas-background) 58%, var(--os-backdrop-edge, #020508)) !important;
}

/* Aurora is a studio: a stage lit from off frame, as Active Theory's site
   is, the reference given for "next gen 3d rendering". The key light sits
   past the top-left corner -- where the glass globe's light comes from
   (globeLooks.js, DEFAULT_LIGHT), so the glass and the room agree -- and
   throws soft shafts through a haze towards the globe; a rim light in the
   second colour sits past the bottom right. Its particles are dust in those
   lights, seen through a lens (studioDust.js), and the lens's grain and
   vignette lie over the stage (.atlas-os-lens, below).

   The dot grid it carried is gone: a fixed 96px lattice of pixel dots is a
   screen texture, and the dust is what fills the air now. */
body.atlas-os[data-atlas-background="aurora"] .atlas-mc-bg,
body.atlas-os[data-atlas-background="aurora"] .atlas-mc-scanline,
html[data-atlas-background="aurora"] body.atlas-os .atlas-mc-bg,
html[data-atlas-background="aurora"] body.atlas-os .atlas-mc-scanline {
  display: none;
}

/* The dust draws its own alpha: bright in a beam, gone outside one. */
body.atlas-os[data-atlas-background="aurora"] .atlas-mc-particles,
html[data-atlas-background="aurora"] body.atlas-os .atlas-mc-particles {
  opacity: 1;
}

.atlas-mc-light,
.atlas-os-lens {
  display: none;
}

/* The two lights and the haze they glow in. Screen-blended, so they only
   ever add light to the ground beneath. */
body.atlas-os[data-atlas-background="aurora"] .atlas-mc-light,
html[data-atlas-background="aurora"] body.atlas-os .atlas-mc-light {
  --studio-key: color-mix(in srgb, #fff 42%, var(--atlas-primary));
  --studio-rim: color-mix(in srgb, #fff 16%, var(--atlas-secondary));
  display: block;
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
  mix-blend-mode: screen;
  background:
    radial-gradient(circle at 0 0, color-mix(in srgb, var(--studio-key) 40%, transparent) 0, color-mix(in srgb, var(--studio-key) 13%, transparent) 20vmax, color-mix(in srgb, var(--studio-key) 4%, transparent) 42vmax, transparent 70vmax),
    radial-gradient(circle at 100% 100%, color-mix(in srgb, var(--studio-rim) 34%, transparent) 0, color-mix(in srgb, var(--studio-rim) 10%, transparent) 16vmax, transparent 48vmax);
}

/* The key's shafts: three sets of rays at periods that never line up, so they
   read as light broken by something off frame rather than a sunburst; held
   to a cone aimed at the globe, fading with distance, softened. The element
   is centred on the corner the light comes from, so turning it swings the
   shafts about their source. */
body.atlas-os[data-atlas-background="aurora"] .atlas-mc-light::before,
html[data-atlas-background="aurora"] body.atlas-os .atlas-mc-light::before {
  content: '';
  position: absolute;
  left: -90vmax;
  top: -90vmax;
  width: 180vmax;
  height: 180vmax;
  background:
    repeating-conic-gradient(from 0deg at 50% 50%, color-mix(in srgb, var(--studio-key) 19%, transparent) 0deg 1deg, transparent 1deg 3.7deg),
    repeating-conic-gradient(from 1.7deg at 50% 50%, color-mix(in srgb, var(--studio-key) 13%, transparent) 0deg 2.2deg, transparent 2.2deg 6.1deg),
    repeating-conic-gradient(from 0.4deg at 50% 50%, color-mix(in srgb, var(--studio-key) 9%, transparent) 0deg 0.5deg, transparent 0.5deg 2.3deg);
  -webkit-mask-image:
    radial-gradient(circle at 50% 50%, #000 0, rgb(0 0 0 / 0.5) 22vmax, transparent 62vmax),
    conic-gradient(from 0deg at 50% 50%, transparent 96deg, #000 114deg, #000 136deg, transparent 158deg);
  -webkit-mask-composite: source-in;
  mask-image:
    radial-gradient(circle at 50% 50%, #000 0, rgb(0 0 0 / 0.5) 22vmax, transparent 62vmax),
    conic-gradient(from 0deg at 50% 50%, transparent 96deg, #000 114deg, #000 136deg, transparent 158deg);
  mask-composite: intersect;
  filter: blur(4px);
  animation: atlas-studio-shafts 52s ease-in-out infinite alternate;
}

/* Haze turning slowly in the key's light: what makes the shafts volumetric
   rather than painted on. */
body.atlas-os[data-atlas-background="aurora"] .atlas-mc-light::after,
html[data-atlas-background="aurora"] body.atlas-os .atlas-mc-light::after {
  content: '';
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(ellipse 34% 22% at 34% 30%, color-mix(in srgb, var(--studio-key) 9%, transparent), transparent 70%),
    radial-gradient(ellipse 26% 30% at 22% 52%, color-mix(in srgb, var(--studio-key) 6%, transparent), transparent 72%),
    radial-gradient(ellipse 30% 20% at 70% 76%, color-mix(in srgb, var(--studio-rim) 7%, transparent), transparent 70%);
  filter: blur(18px);
  animation: atlas-studio-haze 70s ease-in-out infinite alternate;
}

@keyframes atlas-studio-shafts {
  from { rotate: -2.5deg; opacity: 0.82; }
  to { rotate: 2.5deg; opacity: 1; }
}

@keyframes atlas-studio-haze {
  from { translate: -2% -1%; scale: 1; }
  to { translate: 3% 2%; scale: 1.06; }
}

/* The lens, over the stage and the globe, under every window: a vignette, and
   film grain that moves a step at a time the way grain does. */
body.atlas-os[data-atlas-background="aurora"] .atlas-os-lens,
html[data-atlas-background="aurora"] body.atlas-os .atlas-os-lens {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  pointer-events: none;
}

body.atlas-os[data-atlas-background="aurora"] .atlas-os-lens::before,
html[data-atlas-background="aurora"] body.atlas-os .atlas-os-lens::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 125% 110% at 50% 46%, transparent 52%, rgb(0 0 0 / 0.34) 100%);
}

body.atlas-os[data-atlas-background="aurora"] .atlas-os-lens::after,
html[data-atlas-background="aurora"] body.atlas-os .atlas-os-lens::after {
  content: '';
  position: absolute;
  inset: -160px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.86' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: overlay;
  opacity: 0.09;
  animation: atlas-studio-grain 0.5s steps(1, end) infinite;
}

@keyframes atlas-studio-grain {
  0% { translate: 0 0; }
  17% { translate: -61px 37px; }
  33% { translate: 43px -88px; }
  50% { translate: -97px -23px; }
  67% { translate: 79px 64px; }
  83% { translate: -29px 101px; }
}

/* On a light ground the lights are daylight -- white, not screen-blended,
   which would add nothing to a pale ground -- and the lens's edges darken
   only a little. */
html[data-os-appearance="light"][data-atlas-background="aurora"] body.atlas-os .atlas-mc-light,
html[data-os-appearance="light"] body.atlas-os[data-atlas-background="aurora"] .atlas-mc-light {
  --studio-key: #fff;
  --studio-rim: color-mix(in srgb, #fff 55%, var(--atlas-secondary));
  mix-blend-mode: normal;
}

html[data-os-appearance="light"][data-atlas-background="aurora"] body.atlas-os .atlas-os-lens::before,
html[data-os-appearance="light"] body.atlas-os[data-atlas-background="aurora"] .atlas-os-lens::before {
  background: radial-gradient(ellipse 125% 110% at 50% 46%, transparent 55%, rgb(24 28 44 / 0.1) 100%);
}

html[data-os-appearance="light"][data-atlas-background="aurora"] body.atlas-os .atlas-os-lens::after,
html[data-os-appearance="light"] body.atlas-os[data-atlas-background="aurora"] .atlas-os-lens::after {
  opacity: 0.06;
}

/* Still with Reduce Motion: the light holds where it is, the grain is a
   single frame. With Increase Contrast the lens goes: grain and vignette
   are both a loss of contrast by design. */
@media (prefers-reduced-motion: reduce) {
  .atlas-mc-light::before,
  .atlas-mc-light::after,
  .atlas-os-lens::after {
    animation: none !important;
  }
}

@media (prefers-contrast: more) {
  .atlas-os-lens {
    display: none !important;
  }
}

body.atlas-os[data-atlas-background="horizon"] .atlas-os-backdrop,
html[data-atlas-background="horizon"] body.atlas-os .atlas-os-backdrop {
  background:
    radial-gradient(ellipse 90% 35% at 50% 72%, color-mix(in srgb, var(--atlas-primary) 19%, transparent), transparent 72%),
    linear-gradient(to bottom, color-mix(in srgb, var(--atlas-background) 92%, #000) 0 48%, var(--atlas-background) 100%) !important;
}

body.atlas-os[data-atlas-background="horizon"] .atlas-mc-bg,
html[data-atlas-background="horizon"] body.atlas-os .atlas-mc-bg {
  display: block;
  inset: 40% -10% -25%;
  transform: perspective(480px) rotateX(58deg);
  transform-origin: center bottom;
  background-image:
    linear-gradient(var(--atlas-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--atlas-grid) 1px, transparent 1px) !important;
  background-size: 52px 34px;
  mask-image: linear-gradient(to bottom, transparent, black 28%, transparent 94%);
}

body.atlas-os[data-atlas-background="horizon"] .atlas-mc-scanline,
html[data-atlas-background="horizon"] body.atlas-os .atlas-mc-scanline {
  display: none;
}

body.atlas-os[data-atlas-background="horizon"] .atlas-mc-particles,
html[data-atlas-background="horizon"] body.atlas-os .atlas-mc-particles {
  opacity: 0.24;
}

body.atlas-os[data-atlas-background="void"] .atlas-os-backdrop,
html[data-atlas-background="void"] body.atlas-os .atlas-os-backdrop {
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--atlas-background) 93%, var(--atlas-primary)) 0%, var(--atlas-background) 58%, var(--os-backdrop-edge, #010204) 100%) !important;
}

/* Background brightness (Customize > Background, theme.js applyBgBrightness):
   the backdrop and what it carries, lifted or lowered as a whole -- Void's own
   glow among them. Only while it is not 100%, so the default draws through no
   filter at all. */
html[data-atlas-bg-brightness] .atlas-os-backdrop {
  filter: brightness(var(--atlas-bg-brightness, 1));
}

body.atlas-os[data-atlas-background="void"] .atlas-mc-bg,
body.atlas-os[data-atlas-background="void"] .atlas-mc-scanline,
body.atlas-os[data-atlas-background="void"] .atlas-mc-particles,
html[data-atlas-background="void"] body.atlas-os .atlas-mc-bg,
html[data-atlas-background="void"] body.atlas-os .atlas-mc-scanline,
html[data-atlas-background="void"] body.atlas-os .atlas-mc-particles {
  display: none !important;
}

/* ── The themed backdrop ───────────────────────────────────────────────────
 * Moved here from atlas-themes.css, below the designs, which is where it sat
 * there. The designs carry !important on background/background-image, so these
 * only decide what the backdrop and its grid look like where a design leaves
 * them alone -- the sonar scanline, mainly. Keeping them beside the designs is
 * what lets the login screen reach the same answer without loading the app's
 * chrome stylesheet. */

/* The html[...] form is carried alongside the body[...] one, exactly as the
   palette blocks do. The app sets the attribute on both elements; the login
   screen paints before <body> exists, so only <html> can have it there. */
body.atlas-os[data-atlas-theme] .atlas-os-backdrop,
html[data-atlas-theme] body.atlas-os .atlas-os-backdrop {
  background: radial-gradient(ellipse 120% 80% at 50% 40%, color-mix(in srgb, var(--atlas-background) 88%, var(--atlas-primary)) 0%, var(--atlas-background) 55%, var(--os-backdrop-edge, #020508) 100%);
}

body.atlas-os[data-atlas-theme] .atlas-mc-bg,
html[data-atlas-theme] body.atlas-os .atlas-mc-bg {
  background-image:
    linear-gradient(var(--atlas-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--atlas-grid) 1px, transparent 1px);
}

body.atlas-os[data-atlas-theme] .atlas-mc-scanline,
html[data-atlas-theme] body.atlas-os .atlas-mc-scanline {
  background: linear-gradient(to bottom, transparent 0%, color-mix(in srgb, var(--atlas-primary) 8%, transparent) 48%, transparent 52%);
}
