document.addEventListener('DOMContentLoaded', () => {
    // Scroll Reveal Animation
    const reveals = document.querySelectorAll('.reveal');

    const revealOnScroll = () => {
        for (let i = 0; i < reveals.length; i++) {
            const windowHeight = window.innerHeight;
            const elementTop = reveals[i].getBoundingClientRect().top;
            const elementVisible = 150;

            if (elementTop < windowHeight - elementVisible) {
                reveals[i].classList.add('active');
            }
        }
    };

    window.addEventListener('scroll', revealOnScroll);
    revealOnScroll(); // Initial check

    // Smooth scroll for anchors
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            document.querySelector(this.getAttribute('href')).scrollIntoView({
                behavior: 'smooth'
            });
        });
    });

    // Simulate real-time data for HLC sensors
    const sensorValue = document.getElementById('sensor-value');
    if (sensorValue) {
        setInterval(() => {
            const val = (Math.random() * 0.05 - 0.02).toFixed(3);
            sensorValue.textContent = val + ' mm';
            sensorValue.style.color = Math.abs(val) > 0.04 ? '#ff4d4d' : '#00ff88';
        }, 3000);
    }
});
