// app.jsx — compose everything, palette/motion tweaks, mount
const { useEffect: useEf } = React;

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "palette": "studio",
  "motion": true,
  "accent": "coral"
}/*EDITMODE-END*/;

function App() {
  const [t, setTweak] = useTweaks(TWEAK_DEFAULTS);
  useReveal();

  useEf(() => {
    const mq = window.matchMedia('(prefers-reduced-motion: reduce)');
    if (mq.matches) setTweak('motion', false);
    const onChange = (e) => setTweak('motion', !e.matches);
    mq.addEventListener('change', onChange);
    return () => mq.removeEventListener('change', onChange);
  }, []);

  useEf(() => {
    const boot = document.getElementById('boot');
    if (!boot) return;
    boot.style.transition = 'opacity .5s';
    boot.style.opacity = '0';
    const id = setTimeout(() => boot.remove(), 520);
    return () => clearTimeout(id);
  }, []);

  // apply palette + motion to <html>
  useEf(() => {
    document.documentElement.setAttribute('data-palette', t.palette);
    document.documentElement.setAttribute('data-motion', t.motion ? 'on' : 'off');
  }, [t.palette, t.motion]);

  // optional accent override (hue of --primary) on top of palette
  useEf(() => {
    const map = {
      coral:  null,            // use palette default
      blush:  '#E6A8B4',
      amber:  '#E3B98A',
      sage:   '#9DBCA8',
    };
    const v = map[t.accent];
    if (v) document.documentElement.style.setProperty('--primary', v);
    else document.documentElement.style.removeProperty('--primary');
  }, [t.accent, t.palette]);

  return (
    <React.Fragment>
      <AmbientBackground motion={t.motion ? 'on' : 'off'} />
      <CursorGlow motion={t.motion ? 'on' : 'off'} />
      <ScrollTint />
      <Header />
      <main>
        <Hero />
        <AboutSection />
        <WhySection />
        <PhilosophySection />
        <AppsSection />
        <SupportSection />
        <CTASection />
      </main>
      <Footer />

      <TweaksPanel>
        <TweakSection label="Atmosphere" />
        <TweakRadio label="Palette" value={t.palette}
          options={['studio', 'warm', 'calm']}
          onChange={(v) => setTweak('palette', v)} />
        <TweakColor label="Accent" value={
            { coral: '#E89B9B', blush: '#E6A8B4', amber: '#E3B98A', sage: '#9DBCA8' }[t.accent]
          }
          options={['#E89B9B', '#E6A8B4', '#E3B98A', '#9DBCA8']}
          onChange={(v) => {
            const inv = { '#E89B9B': 'coral', '#E6A8B4': 'blush', '#E3B98A': 'amber', '#9DBCA8': 'sage' };
            setTweak('accent', inv[v] || 'coral');
          }} />
        <TweakSection label="Motion" />
        <TweakToggle label="Ambient animation" value={t.motion}
          onChange={(v) => setTweak('motion', v)} />
      </TweaksPanel>
    </React.Fragment>
  );
}

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