// CCSE 2026 website — app shell: lang + theme state, assembly
function App() {
  const [lang, setLang] = React.useState(() => detectLang());
  const [theme, setTheme] = React.useState(() => {
    try { return localStorage.getItem("ccse-site-theme") || "light"; } catch (e) { return "light"; }
  });
  const t = window.CCSE_CONTENT[lang] || window.CCSE_CONTENT.es;

  React.useEffect(() => {
    document.documentElement.setAttribute("data-theme", theme);
    try { localStorage.setItem("ccse-site-theme", theme); } catch (e) {}
  }, [theme]);

  React.useEffect(() => {
    const el = document.documentElement;
    el.setAttribute("lang", t.htmlLang || lang);
    el.setAttribute("dir", t.dir || "ltr");
    document.title = t.seoTitle;
    const md = document.querySelector('meta[name="description"]');
    if (md) md.setAttribute("content", t.seoDesc);
    try {
      localStorage.setItem("ccse-site-lang", lang);
      const url = new URL(location.href);
      url.searchParams.set("lang", lang);
      history.replaceState(null, "", url);
    } catch (e) {}
  }, [lang]);

  return (
    <React.Fragment>
      <Nav t={t} lang={lang} setLang={setLang} theme={theme} setTheme={setTheme} />
      <main key={lang}>
        <Hero t={t} />
        <ProofStrip t={t} />
        <Features t={t} />
        <Screenshots t={t} />
        <HowItWorks t={t} />
        <ExamInfo t={t} />
        <Quiz t={t} lang={lang} />
        <Reviews t={t} />
        <Languages t={t} />
        <Faq t={t} />
        <FinalCta t={t} lang={lang} />
      </main>
      <Footer t={t} />
    </React.Fragment>
  );
}

// Boot only once the design-system bundle is present — the compiler emits
// _ds_bundle.js at end of turn, and the retry loader in index.html re-fetches
// it if the first request 404s. This makes an already-open tab self-heal.
(function boot() {
  if (!window.CCSE2026DesignSystem_bedcf0 || !window.CCSE2026DesignSystem_bedcf0.Button) {
    setTimeout(boot, 150);
    return;
  }
  const el = document.getElementById("root");
  if (!window.__ccseRoot) window.__ccseRoot = ReactDOM.createRoot(el);
  window.__ccseRoot.render(<App />);
})();
