/* Utility */
const rand = (min,max)=> Math.random()*(max-min)+min;

/* =======================================================
   STARS
======================================================= */
const STAR_LAYERS = [
  {id:'stars-deep', count:90, size:[1,2]},
  {id:'stars-mid', count:110, size:[1.2,2.6]},
  {id:'stars-front', count:130, size:[1.5,3.2]}
];

function createStars(){
  STAR_LAYERS.forEach(layer=>{
    const box = document.getElementById(layer.id);
    if(!box) return;
    box.innerHTML='';
    for(let i=0;i<layer.count;i++){
      const s = document.createElement('span');
      s.className='star';
      const w = rand(layer.size[0],layer.size[1]);
      s.style.width = s.style.height = w+'px';
      s.style.left = rand(0,100)+'%';
      s.style.top = rand(0,100)+'%';
      s.style.animationDelay = rand(0,6)+'s';
      box.appendChild(s);
    }
  });
}

/* =======================================================
   FIREFLIES (BOTTOM AREA)
======================================================= */
function createFireflies(){
  const field = document.getElementById('fireflyField');
  if(!field) return;

  field.innerHTML = '';

  const count = 55;

  for(let i=0;i<count;i++){
    const p = document.createElement('span');
    p.className='particle';

    p.style.left = rand(0,100)+'%';
    p.style.top  = rand(0,100)+'%';

    const size = rand(6,12);
    p.style.width = p.style.height = size+'px';
    p.style.animationDelay = rand(0,3000)+'ms';

    field.appendChild(p);
  }
}

/* =======================================================
   INIT
======================================================= */
document.addEventListener('DOMContentLoaded', ()=>{
  createStars();
  createFireflies();
});
