/*
 * Discópico — Global immersive atmosphere
 * A single, site-wide ambient background that lives BEHIND all content.
 * Concept: the splash is crossing the threshold; this is the space on the
 * other side — the same deep-red glow, now calm, breathing at the edges of
 * vision. Richness lives in the side margins; the center stays dark and still
 * so content is always readable.
 *
 * Load order: import AFTER tokens.css (needs --rojo / --bg).
 * The DOM for this system is injected by atmosphere.js as the first child of
 * <body>; this file only styles it. Purely decorative: pointer-events:none,
 * aria-hidden, no content ever depends on it.
 *
 * Tuning: every look decision (color, opacity, speed, where the halos fall)
 * is a value in this file. Nothing here is baked into an image.
 */

/* ─── ROOT CONTAINER ─────────────────────────────────────
   Fixed, full-viewport, painted behind normal content
   (z-index:-1 sits above the body's solid background but
   below every content element, which keeps clicks/scroll/
   selection untouched).
   ──────────────────────────────────────────────────────── */
#atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  contain: layout paint style;
  /* Gentle first appearance. On route changes the View Transition
     cross-fade (below) carries continuity, so this never reads as a reset. */
  animation: atm-fade-in 1200ms ease both;
}

@keyframes atm-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Intensity dial — separated from the container so the entrance fade and the
   per-viewport intensity never fight each other. Desktop = full presence. */
.atm-field {
  position: absolute;
  inset: 0;
  opacity: 1;
}

/* Shared base for the moving light layers */
.atm-glow,
.atm-haze {
  position: absolute;
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* ─── SIDE HALOS ─────────────────────────────────────────
   Two deep, desaturated red glows anchored to the left/right
   edges. Brightest near the margins, faded well before the
   centered content column. Reds match the splash DNA
   (≈#A20106 → #780208 → #3C0104 → transparent).
   They breathe very slowly, out of phase, so the motion never
   reads as a loop.
   ──────────────────────────────────────────────────────── */
.atm-glow-left {
  top: -10%;
  bottom: -10%;
  left: 0;
  width: 46%;
  background: radial-gradient(58% 52% at 13% 42%,
      rgba(162, 1, 6, 0.30) 0%,
      rgba(120, 2, 8, 0.15) 32%,
      rgba(60, 1, 4, 0.05) 56%,
      transparent 74%);
  animation: atm-drift-left 62s ease-in-out infinite alternate;
}

.atm-glow-right {
  top: -10%;
  bottom: -10%;
  right: 0;
  width: 46%;
  background: radial-gradient(58% 52% at 87% 58%,
      rgba(150, 2, 9, 0.26) 0%,
      rgba(110, 2, 8, 0.13) 32%,
      rgba(56, 1, 4, 0.05) 56%,
      transparent 74%);
  animation: atm-drift-right 74s ease-in-out infinite alternate;
}

/* ─── AMBIENT HAZE ───────────────────────────────────────
   Very large, very faint drifting luminosity. Adds depth and
   an almost-imperceptible change in density over time so the
   space feels alive rather than static.
   ──────────────────────────────────────────────────────── */
.atm-haze {
  inset: -25%;
  background:
    radial-gradient(38% 40% at 28% 30%, rgba(140, 3, 10, 0.10) 0%, transparent 60%),
    radial-gradient(42% 44% at 72% 74%, rgba(88, 2, 8, 0.09) 0%, transparent 62%);
  animation: atm-haze-drift 88s ease-in-out infinite alternate;
}

/* ─── CENTER SHADE (readability mask) ────────────────────
   Keeps the vertical band where content lives the darkest and
   calmest area. Resolved by composition, not an opaque panel:
   a soft near-black gradient that fades out toward the sides.
   Static — no motion behind reading zones.
   ──────────────────────────────────────────────────────── */
.atm-shade {
  position: absolute;
  inset: 0;
  background: radial-gradient(46% 96% at 50% 46%,
      rgba(10, 10, 10, 0.55) 0%,
      rgba(10, 10, 10, 0.28) 42%,
      rgba(10, 10, 10, 0.00) 76%);
}

/* ─── FLARES ("destellos") ────────────────────────────────
   Desktop-only, sparse, soft blooms of light — no drawn shape and
   no trajectory. Same radial-gradient + soft-falloff language and
   red palette as the side halos. Each one breathes once in place
   (grows in, trembles through a couple of irregular pulses,
   contracts back out) and is gone — a surprise, not an effect.
   Position and size are set inline per instance by atmosphere.js;
   this rule only defines the shared visual recipe.
   Sits above the light layers, below the grain.
   ──────────────────────────────────────────────────────── */
.atm-flares {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.atm-flare {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle,
      rgba(255, 109, 115, 0.40) 0%,
      rgba(200, 2, 9, 0.22) 34%,
      rgba(120, 2, 8, 0.08) 64%,
      transparent 88%);
  filter: blur(14px);   /* genuine defocus, not just gradient falloff — "más desenfocados" */
  transform: scale(0.4);
  opacity: 0;
  will-change: transform, opacity;
}

/* ─── FILM GRAIN ─────────────────────────────────────────
   Static grayscale noise (same texture family as the splash),
   at very low opacity via soft-light. Zero per-frame cost.
   ──────────────────────────────────────────────────────── */
.atm-grain {
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  opacity: 0.06;
  mix-blend-mode: soft-light;
}

/* ─── SLOW MOVEMENT ──────────────────────────────────────
   Transform/opacity only (GPU-composited). Small travel, long
   durations, alternate direction. Never a pulse or a beat.
   ──────────────────────────────────────────────────────── */
@keyframes atm-drift-left {
  0%   { transform: translate3d(0, 0, 0)        scale(1);    opacity: 0.92; }
  100% { transform: translate3d(2.5%, -3%, 0)   scale(1.09); opacity: 1;    }
}

@keyframes atm-drift-right {
  0%   { transform: translate3d(0, 0, 0)        scale(1.05); opacity: 1;    }
  100% { transform: translate3d(-2.5%, 3%, 0)   scale(1);    opacity: 0.88; }
}

@keyframes atm-haze-drift {
  0%   { transform: translate3d(0, 0, 0)        scale(1);    }
  50%  { transform: translate3d(-3%, 2%, 0)     scale(1.1);  }
  100% { transform: translate3d(3%, -2%, 0)     scale(1.06); }
}

/* ─── PAUSE WHEN TAB HIDDEN ──────────────────────────────
   atmosphere.js toggles .atm-paused to stop CSS motion while
   the tab is in the background (paired with rAF pause in JS).
   ──────────────────────────────────────────────────────── */
#atmosphere.atm-paused .atm-glow,
#atmosphere.atm-paused .atm-haze {
  animation-play-state: paused;
}

/* ─── RESPONSIVE: adapt per viewport, don't scale ────────
   Tablet: fewer, calmer layers; reading first. (Flares are
   disabled from JS below the desktop breakpoint.)
   ──────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .atm-field { opacity: 0.72; }
  .atm-haze  { display: none; }              /* fewer layers */
  .atm-grain { opacity: 0.045; }
  .atm-shade {
    background: radial-gradient(52% 96% at 50% 46%,
        rgba(10, 10, 10, 0.48) 0%,
        rgba(10, 10, 10, 0.24) 44%,
        rgba(10, 10, 10, 0.00) 78%);
  }
}

/* Mobile: a whisper. One faint halo, slower, lower contrast,
   center kept calm. Never empty, never an obvious effect.
   Mobile-first experience stays intact. */
@media (max-width: 600px) {
  .atm-field { opacity: 0.5; }
  .atm-glow-right { display: none; }         /* single, subtle source */
  .atm-glow-left {
    width: 70%;
    /* Raised from the original tablet-inherited alphas (0.20 / 0.09): at
       this narrow width the shade override below was smothering the halo
       almost entirely — the whisper needs a minimum floor to register at all. */
    background: radial-gradient(66% 56% at 20% 44%,
        rgba(150, 2, 9, 0.32) 0%,
        rgba(96, 2, 7, 0.15) 38%,
        transparent 72%);
    animation-duration: 96s;                 /* even slower */
  }
  /* The tablet .atm-shade is wide/dark enough to cover nearly the full
     375px width and suppress the already-faint halo underneath it. This
     mobile-specific override narrows and lightens it — content directly
     behind it is still darkened for legibility, it just no longer eats
     the margins where the halo needs room to show. */
  .atm-shade {
    background: radial-gradient(42% 90% at 50% 46%,
        rgba(10, 10, 10, 0.34) 0%,
        rgba(10, 10, 10, 0.16) 46%,
        rgba(10, 10, 10, 0.00) 78%);
  }
  .atm-grain { opacity: 0.035; }
}

/* ─── REDUCED MOTION ─────────────────────────────────────
   Freeze all movement. The composition stays (still, not
   empty); nothing animates.
   ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #atmosphere,
  .atm-glow,
  .atm-haze {
    animation: none !important;
  }
  #atmosphere { opacity: 1; }
}

/* ─── CROSS-DOCUMENT VIEW TRANSITIONS ────────────────────
   Turns page-to-page navigation into a soft cross-fade instead
   of a flash. Because the atmosphere looks nearly identical on
   every page, the root cross-fade reads as the space simply
   staying — reinforcing "the atmosphere doesn't restart."
   Same-origin only; unsupported browsers just navigate normally.
   ──────────────────────────────────────────────────────── */
@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 420ms;
  animation-timing-function: ease;
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none !important;
  }
}
