/* ===== Mazurski Brzask — app root ===== */
function App(){
  React.useEffect(()=>{
    const all = ()=> document.querySelectorAll('.reveal');
    const VH  = ()=> window.innerHeight || document.documentElement.clientHeight || 800;
    const frozen = ()=> document.visibilityState === 'hidden';
    const showNow = (el)=> el.classList.add('in','shown');   // instant, no animation
    const animIn  = (el)=> el.classList.add('in');           // animated entrance

    const io = new IntersectionObserver((entries)=>{
      entries.forEach(e=>{
        if(e.isIntersecting){ frozen()?showNow(e.target):animIn(e.target); io.unobserve(e.target); }
      });
    }, { threshold:0.1, rootMargin:'0px 0px -6% 0px' });
    all().forEach(el=>io.observe(el));

    const sweep = ()=>{
      const h=VH(), fz=frozen();
      document.querySelectorAll('.reveal:not(.in)').forEach(el=>{
        const r=el.getBoundingClientRect();
        if(r.top < h*0.96 && r.bottom > 0){ fz?showNow(el):animIn(el); io.unobserve(el); }
      });
    };
    // if this frame can't run animations (hidden/preview), just show everything
    const dump = ()=>{ if(frozen()) all().forEach(showNow); };

    window.addEventListener('scroll', sweep, {passive:true});
    window.addEventListener('resize', sweep);
    document.addEventListener('visibilitychange', ()=>{ frozen()? all().forEach(showNow) : sweep(); });
    [50,250,700,1400].forEach(t=>setTimeout(()=>{ sweep(); dump(); }, t));
    return ()=>{ io.disconnect(); window.removeEventListener('scroll',sweep); window.removeEventListener('resize',sweep); };
  },[]);

  return (
    <React.Fragment>
      <Nav/>
      <Hero/>
      <About/>
      <Location/>
      <Character/>
      <Advantages/>
      <PlotMap/>
      <CTA/>
      <Contact/>
      <Footer/>
    </React.Fragment>
  );
}

ReactDOM.createRoot(document.getElementById('root')).render(<App/>);
