/* sky-16 — living sky over the baked backgrounds (see sky-16.mjs, tools/sky-16.py).
   Compositor-only: every animation touches transform/scale/opacity. Additive light uses
   mix-blend-mode:plus-lighter on the OUTERMOST element of each effect; .sky16 itself must stay a
   non-stacking-context layer so effects blend with the background inside .scene-world12.
   Loops are phase-locked to a global clock: delay = var(--d) - var(--age). */
.sky16{position:absolute;inset:0;pointer-events:none}
.sky16 i{position:absolute;display:block;pointer-events:none}
.sky16>i{mix-blend-mode:plus-lighter}
.sky16>.s16o{mix-blend-mode:normal}

/* Moon: the disc stays exactly as painted; only a soft additive halo breathes (about ±9%, 9-12s). */
.s16h{aspect-ratio:1;translate:-50% -50%;border-radius:50%;
  background:radial-gradient(closest-side,color-mix(in srgb,var(--c) 6%,transparent) 0,color-mix(in srgb,var(--c) 7%,transparent) 32%,color-mix(in srgb,var(--c) 11%,transparent) 45%,color-mix(in srgb,var(--c) 6.5%,transparent) 60%,color-mix(in srgb,var(--c) 2.2%,transparent) 80%,transparent 100%);
  opacity:.9;animation:s16-halo var(--p) ease-in-out calc(var(--d) - var(--age,0ms)) infinite alternate}
@keyframes s16-halo{from{opacity:.82}to{opacity:1}}

/* Tier A: hero glints on baked 4-point stars. Outer opacity (p1) x cross scale (p2, incommensurate)
   x rare flare (p3, 20-40s) never repeat visibly. */
.s16a{aspect-ratio:1;translate:-50% -50%;animation:s16-tw var(--p1) ease-in-out calc(var(--d1) - var(--age,0ms)) infinite}
.s16a>.s16x{inset:0;background:var(--c);
  -webkit-mask:url(/art/sky-16/atlas.png) var(--sp,25%) 0/500% 100% no-repeat;mask:url(/art/sky-16/atlas.png) var(--sp,25%) 0/500% 100% no-repeat;
  animation:s16-sc var(--p2) ease-in-out calc(var(--d2) - var(--age,0ms)) infinite alternate,s16-flare var(--p3) linear calc(var(--d3) - var(--age,0ms)) infinite}
.s16a>.s16b{inset:-95%;border-radius:50%;
  background:radial-gradient(closest-side,color-mix(in srgb,var(--k) 55%,transparent) 0,color-mix(in srgb,var(--c) 30%,transparent) 18%,color-mix(in srgb,var(--c) 9%,transparent) 48%,transparent 100%);
  animation:s16-bloom var(--p2) ease-in-out calc(var(--d2) - var(--age,0ms)) infinite alternate,s16-flare var(--p3) linear calc(var(--d3) - var(--age,0ms)) infinite}
.s16a.s16-cool>.s16x{background:color-mix(in srgb,var(--c) 70%,#bfe6ff)}
@keyframes s16-tw{0%{opacity:.34}17%{opacity:.86}29%{opacity:.52}47%{opacity:1}63%{opacity:.4}81%{opacity:.78}100%{opacity:.34}}
@keyframes s16-sc{from{transform:scale(.62)}to{transform:scale(1.16)}}
@keyframes s16-bloom{from{opacity:.3}to{opacity:.85}}
@keyframes s16-flare{0%,95.4%,99.6%,100%{scale:1}97%{scale:1.85}}

/* Tier B: dust twinkle, opacity only. .s16d brightens a baked dot; .s16o dims it with local sky colour. */
.s16d,.s16o{aspect-ratio:1;translate:-50% -50%;border-radius:50%;opacity:0}
.s16d{background:radial-gradient(closest-side,#fff 0,color-mix(in srgb,var(--c) 85%,transparent) 26%,color-mix(in srgb,var(--c) 22%,transparent) 55%,transparent 100%);
  animation:s16-dust var(--p) ease-in-out calc(var(--d) - var(--age,0ms)) infinite}
.s16d.s16v2{animation-name:s16-dust2}
.s16o{background:radial-gradient(closest-side,var(--bg) 0,var(--bg) 42%,color-mix(in srgb,var(--bg) 60%,transparent) 62%,transparent 100%);
  animation:s16-dim var(--p) ease-in-out calc(var(--d) - var(--age,0ms)) infinite}
@keyframes s16-dust{0%,100%{opacity:0}16%{opacity:.95}30%{opacity:.18}46%{opacity:.7}64%{opacity:0}}
@keyframes s16-dust2{0%,100%{opacity:.1}22%{opacity:0}40%{opacity:.85}52%{opacity:.35}70%{opacity:1}86%{opacity:.2}}
@keyframes s16-dim{0%,38%,100%{opacity:0}48%{opacity:.88}56%{opacity:.35}64%{opacity:.8}76%{opacity:0}}

/* Lanterns and fires: irregular flicker nested in a slow breathe. */
.s16l{aspect-ratio:1;translate:-50% -50%;animation:s16-breathe var(--p1) ease-in-out calc(var(--d1) - var(--age,0ms)) infinite alternate}
.s16l>i{inset:0;border-radius:50%;
  background:radial-gradient(closest-side,color-mix(in srgb,var(--c) 40%,transparent) 0,color-mix(in srgb,#ffb347 27%,transparent) 20%,color-mix(in srgb,#ffb347 15%,transparent) 42%,color-mix(in srgb,#ff8a2a 6%,transparent) 68%,transparent 100%);
  animation:s16-flicker var(--p2) linear calc(var(--d2) - var(--age,0ms)) infinite}
.s16fire>i{background:radial-gradient(closest-side,color-mix(in srgb,var(--c) 48%,transparent) 0,color-mix(in srgb,#ff9a2e 30%,transparent) 32%,color-mix(in srgb,#ff5a1e 11%,transparent) 64%,transparent 100%);animation-name:s16-fire}
@keyframes s16-breathe{from{opacity:.66}to{opacity:1}}
@keyframes s16-flicker{0%{opacity:.9}9%{opacity:.62}14%{opacity:.95}27%{opacity:.8}33%{opacity:1}41%{opacity:.7}52%{opacity:.92}58%{opacity:.58}66%{opacity:.88}79%{opacity:1}87%{opacity:.74}100%{opacity:.9}}
@keyframes s16-fire{0%{opacity:.85;transform:scale(1)}13%{opacity:.6;transform:scale(.95)}22%{opacity:1;transform:scale(1.04)}38%{opacity:.72;transform:scale(.97)}51%{opacity:.95;transform:scale(1.06)}63%{opacity:.66}77%{opacity:1;transform:scale(1)}89%{opacity:.78;transform:scale(1.03)}100%{opacity:.85;transform:scale(1)}}

/* Castle / town windows: warm glow that mostly rests and now and then gutters or flares. */
.s16w{aspect-ratio:1;translate:-50% -50%;border-radius:50%;opacity:.35;
  background:radial-gradient(closest-side,#ffd27acc 0,#ffb34766 30%,#ff8a2a1f 62%,transparent 100%);
  animation:s16-window var(--p) linear calc(var(--d) - var(--age,0ms)) infinite}
.s16w.s16v2{animation-name:s16-window2}
@keyframes s16-window{0%,58%,100%{opacity:.35}62%{opacity:.08}65%{opacity:.5}69%{opacity:.18}74%{opacity:.4}88%{opacity:.62}94%{opacity:.35}}
@keyframes s16-window2{0%,100%{opacity:.4}18%{opacity:.62}24%{opacity:.3}71%{opacity:.36}75%{opacity:.05}77%{opacity:.46}80%{opacity:.22}84%{opacity:.4}}

/* Cyan wisps and crystals. */
.s16c{aspect-ratio:1;translate:-50% -50%;border-radius:50%;
  background:radial-gradient(closest-side,#9feaffa0 0,#5fd7ff55 30%,#3aa0ff1a 62%,transparent 100%);
  animation:s16-wisp var(--p) ease-in-out calc(var(--d) - var(--age,0ms)) infinite alternate}
@keyframes s16-wisp{from{opacity:.35;transform:scale(.9)}to{opacity:.9;transform:scale(1.08)}}

/* Particles. Embers: the track rises by its own height, the dot sways by its own width. */
.s16e{animation:s16-rise var(--p) cubic-bezier(.3,.1,.7,1) calc(var(--d) - var(--age,0ms)) infinite}
.s16e>i{left:0;bottom:0;width:100%;aspect-ratio:1;border-radius:50%;
  background:radial-gradient(closest-side,#fff3c4 0,#ffb347 38%,#ff7a1e88 62%,transparent 100%);
  animation:s16-sway var(--p2) ease-in-out calc(var(--d2) - var(--age,0ms)) infinite alternate}
@keyframes s16-rise{0%{transform:translateY(0);opacity:0}10%{opacity:1}62%{opacity:.85}100%{transform:translateY(-100%);opacity:0}}
@keyframes s16-sway{from{transform:translateX(-130%)}to{transform:translateX(130%)}}
/* Fireflies and pollen motes: wander inside their own box, blink independently. */
.s16f{aspect-ratio:1;translate:-50% -50%;animation:s16-wander var(--p) ease-in-out calc(var(--d) - var(--age,0ms)) infinite}
.s16f.s16v2{animation-name:s16-wander2}
.s16f>i{left:50%;top:50%;width:var(--dot);aspect-ratio:1;translate:-50% -50%;border-radius:50%;
  background:radial-gradient(closest-side,#fbffd0 0,#d8ff7acc 30%,#a8e05a44 60%,transparent 100%);
  animation:s16-blink var(--p2) ease-in-out calc(var(--d2) - var(--age,0ms)) infinite}
.s16mote>i{background:radial-gradient(closest-side,#fff1d0cc 0,#ffd9a044 50%,transparent 100%);animation-name:s16-mote}
@keyframes s16-wander{0%,100%{transform:translate(0,0)}24%{transform:translate(19%,-13%)}49%{transform:translate(-8%,-24%)}73%{transform:translate(-22%,7%)}}
@keyframes s16-wander2{0%,100%{transform:translate(0,0)}31%{transform:translate(-17%,-19%)}58%{transform:translate(14%,-6%)}82%{transform:translate(6%,16%)}}
@keyframes s16-blink{0%,100%{opacity:0}30%{opacity:.95}52%{opacity:.7}70%{opacity:.08}}
@keyframes s16-mote{0%,100%{opacity:.08}45%{opacity:.5}}

/* Shooting star (WAAPI). The head is the right end; transform-origin rides with it. */
.s16s{transform-origin:100% 50%;opacity:0;border-radius:2px;
  background:linear-gradient(90deg,transparent 0,#c9d4ff33 30%,#ffeccdcc 80%,#fffaf0 100%)}
.s16s::after{content:"";position:absolute;right:-1px;top:50%;width:5px;height:5px;translate:0 -50%;border-radius:50%;background:#fffdf4;box-shadow:0 0 6px 2px #fff1c880,0 0 14px 4px #ffd27a33}

/* Budget: mobile keeps the hero lights, workspace scenery (behind panels) keeps only the sky. */
@media (max-width:700px){.sky16 [data-m="0"]{display:none}}
.workspace-scenery12 .sky16 :is(.s16d,.s16o,.s16e,.s16f,.s16w){display:none}
html[data-fx-tier="2"] .sky16 :is(.s16e,.s16f){display:none}
html[data-fx-tier="1"] .sky16 :is(.s16e,.s16f,.s16d,.s16o,.s16w){display:none}

/* Paused: tab hidden or scene scrolled away. Phase is kept; nothing restarts. */
html[data-motion=off] .sky16 *,html[data-motion=paused] .sky16 *,[data-offscreen] *,[data-offscreen].sky16 *{animation-play-state:paused!important}

/* Static (toggle off, reduced motion, Save-Data, budget 0): a still but lit sky. */
html[data-motion-static] .sky16 *{animation:none!important}
html[data-motion-static] .sky16 :is(.s16d,.s16o,.s16e,.s16f,.s16w,.s16s){display:none}
html[data-motion-static] .s16a{opacity:.7}
html[data-motion-static] .s16a>.s16x{transform:scale(.9)}
html[data-motion-static] .s16a>.s16b{opacity:.5}
html[data-motion-static] .s16l{opacity:.9}
html[data-motion-static] .s16c{opacity:.6}
@media (prefers-reduced-motion:reduce){
  .sky16 *{animation:none!important}
  .sky16 :is(.s16d,.s16o,.s16e,.s16f,.s16w,.s16s){display:none}
  .s16a{opacity:.7}.s16a>.s16x{transform:scale(.9)}.s16a>.s16b{opacity:.5}.s16l{opacity:.9}.s16c{opacity:.6}
}
