// Standalone deploy shell — renders ONE LandingPage at real viewport size.
// No design canvas, no artboard clipping. Full-bleed, scrollable body.

function StandaloneShell() {
  const params = new URLSearchParams(window.location.search);
  const direction = window.__DIRECTION__ || params.get('dir') || 'silent';
  const lang = window.__LANG__ || params.get('lang') || 'ko';
  const [mobile, setMobile] = React.useState(window.innerWidth < 768);

  React.useEffect(() => {
    const onResize = () => setMobile(window.innerWidth < 768);
    window.addEventListener('resize', onResize);
    return () => window.removeEventListener('resize', onResize);
  }, []);

  const copy = window.CITELY_COPY[lang];
  // Update the <html lang> attribute so Pretendard hinting picks correctly.
  React.useEffect(() => {
    document.documentElement.setAttribute('lang', lang);
  }, [lang]);

  // Signature motion: IntersectionObserver on the answer-engine mock.
  const [revealed, setRevealed] = React.useState(false);
  React.useEffect(() => {
    const mock = document.querySelector('.ae-mock');
    if (!mock) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting && e.intersectionRatio > 0.2) setRevealed(true);
      });
    }, { threshold: [0, 0.2, 0.5, 1] });
    io.observe(mock);
    return () => io.disconnect();
  }, []);

  return (
    <div className={'site site-standalone ' + (direction === 'structured' ? 'structured' : 'silent')}
         style={{ width: '100%', minHeight: '100vh', overflow: 'visible', background: 'var(--paper)' }}>
      {direction === 'structured' && !mobile && (
        <div style={{
          position: 'fixed', top: 0, bottom: 0, left: 72, right: 72,
          pointerEvents: 'none', zIndex: 0,
          display: 'grid', gridTemplateColumns: 'repeat(12, 1fr)', gap: 24,
        }}>
          {Array.from({ length: 12 }).map((_, i) => (
            <div key={i} style={{ borderLeft: '1px dashed rgba(10,10,10,0.05)' }} />
          ))}
        </div>
      )}
      <div style={{ position: 'relative', zIndex: 1 }}>
        <Nav copy={copy} mobile={mobile} />
        <Hero copy={copy} direction={direction} mobile={mobile} />
        <SectionShift copy={copy} direction={direction} mobile={mobile} revealed={revealed} />
        <SectionPillars copy={copy} direction={direction} mobile={mobile} />
        <SectionModes copy={copy} mobile={mobile} />
        <SectionMethod copy={copy} mobile={mobile} />
        <SectionCases copy={copy} mobile={mobile} />
        <SectionFAQ copy={copy} mobile={mobile} />
        <SectionCTAFooter copy={copy} mobile={mobile} />
      </div>
    </div>
  );
}

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

// Standalone doesn't need the tweaks bridge — but support ?accent= for QA.
(function () {
  const params = new URLSearchParams(window.location.search);
  const a = params.get('accent');
  if (a) document.documentElement.style.setProperty('--accent', a);
  const p = params.get('paper');
  if (p) document.documentElement.style.setProperty('--paper', p);
})();
