/**
 * ALGA ARENA — Particle System
 * Background starfields and slow-floating volumetric cyber dust
 */

'use strict';

window.CinematicParticles = (() => {
    let particles;
    const isReduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
    const count = isReduced ? 50 : (window.innerWidth < 768 ? 150 : 600);

    const init = (scene) => {
        const geom = new THREE.BufferGeometry();
        const positions = new Float32Array(count * 3);

        for (let i = 0; i < count * 3; i += 3) {
            positions[i] = (Math.random() - 0.5) * 20;
            positions[i+1] = (Math.random() - 0.5) * 20;
            positions[i+2] = (Math.random() - 0.5) * 12 - 4;
        }

        geom.setAttribute('position', new THREE.BufferAttribute(positions, 3));

        const mat = new THREE.PointsMaterial({
            color: 0x00d4ff,
            size: 0.04,
            transparent: true,
            opacity: 0.4,
            blending: THREE.AdditiveBlending
        });

        particles = new THREE.Points(geom, mat);
        scene.add(particles);
    };

    const update = (delta, time) => {
        if (!particles) return;
        particles.rotation.y += 0.012 * delta;
        particles.position.y = Math.sin(time * 0.25) * 0.1;
    };

    return { init, update };
})();
