
// App.jsx — Main shell + Tweaks

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "atmosphere": "Nebula",
  "signalIntensity": 70,
  "typeWeight": "Refined"
}/*EDITMODE-END*/;

// ── Context ──────────────────────────────────────────────────────────────────
const TweakCtx = React.createContext(TWEAK_DEFAULTS);
const useTweakCtx = () => React.useContext(TweakCtx);

// ── Atmosphere config ─────────────────────────────────────────────────────────
const ATMOSPHERES = {
  Void: {
    heroBg: 'radial-gradient(ellipse 60% 40% at 50% 30%, #0d1422 0%, #0B1222 80%)',
    heroOrb: 'rgba(59,130,246,0.05)',
    gridOpacity: 0.02,
    nebulaOverlay: null,
    pageBg: '#0B1222',
  },
  Nebula: {
    heroBg: 'radial-gradient(ellipse 80% 60% at 50% 30%, #0f1d3a 0%, #0B1222 70%)',
    heroOrb: 'rgba(59,130,246,0.12)',
    gridOpacity: 0.04,
    nebulaOverlay: 'radial-gradient(ellipse 100% 80% at 70% 20%, rgba(99,40,180,0.07) 0%, transparent 60%), radial-gradient(ellipse 60% 50% at 20% 80%, rgba(59,130,246,0.06) 0%, transparent 50%)',
    pageBg: '#0B1222',
  },
  Aurora: {
    heroBg: 'radial-gradient(ellipse 90% 70% at 50% 20%, #0a1f18 0%, #0B1222 65%)',
    heroOrb: 'rgba(100,200,80,0.10)',
    gridOpacity: 0.03,
    nebulaOverlay: 'radial-gradient(ellipse 120% 60% at 50% 10%, rgba(100,200,80,0.07) 0%, rgba(59,130,246,0.05) 50%, transparent 75%)',
    pageBg: '#090f0d',
  },
};

// ── Signal intensity → lime color derived values ──────────────────────────────
const getSignal = (intensity) => {
  // intensity 0–100
  const alpha = 0.08 + (intensity / 100) * 0.92;
  const glowSpread = 10 + (intensity / 100) * 50;
  const glowOpacity = 0.08 + (intensity / 100) * 0.42;
  const limeOpacity = 0.5 + (intensity / 100) * 0.5;
  return { alpha, glowSpread, glowOpacity, limeOpacity };
};

// ── Type weight config ────────────────────────────────────────────────────────
const TYPE_CONFIGS = {
  Ghost:   { weight: 200, tracking: '0.01em',  scale: 1.04 },
  Refined: { weight: 300, tracking: '-0.02em', scale: 1.0  },
  Impact:  { weight: 500, tracking: '-0.04em', scale: 0.96 },
};

// ── NavBar ────────────────────────────────────────────────────────────────────
const NavBar = () => {
  const [scrolled, setScrolled] = React.useState(false);
  const { signalIntensity } = useTweakCtx();
  const sig = getSignal(signalIntensity);

  React.useEffect(() => {
    const handler = () => setScrolled(window.scrollY > 60);
    window.addEventListener('scroll', handler, { passive: true });
    return () => window.removeEventListener('scroll', handler);
  }, []);

  return (
    <nav style={{
      position: 'fixed',
      top: 0, left: 0, right: 0,
      zIndex: 100,
      padding: '20px 5vw',
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'space-between',
      background: scrolled ? 'rgba(8,15,28,0.85)' : 'transparent',
      backdropFilter: scrolled ? 'blur(16px)' : 'none',
      borderBottom: scrolled ? '1px solid rgba(255,255,255,0.05)' : 'none',
      transition: 'all 0.35s ease',
    }}>
      {/* Logo video */}
      <style>{`
        @keyframes nws-logo-pulse {
          0%   { box-shadow: 0 0 0px 0px rgba(59,130,246,0), 0 0 0px 0px rgba(99,40,180,0); }
          30%  { box-shadow: 0 0 18px 6px rgba(59,130,246,0.45), 0 0 32px 14px rgba(99,40,180,0.18); }
          55%  { box-shadow: 0 0 8px 2px rgba(59,130,246,0.18), 0 0 14px 5px rgba(99,40,180,0.08); }
          75%  { box-shadow: 0 0 22px 8px rgba(59,130,246,0.5), 0 0 40px 18px rgba(99,40,180,0.22); }
          100% { box-shadow: 0 0 0px 0px rgba(59,130,246,0), 0 0 0px 0px rgba(99,40,180,0); }
        }
      `}</style>
      <div
        onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
        style={{ cursor: 'pointer', display: 'flex', alignItems: 'center', gap: '10px', flexShrink: 0 }}
      >
        <div style={{
          width: '92px', height: '92px',
          borderRadius: '16px',
          overflow: 'hidden',
          flexShrink: 0,
          background: 'transparent',
          animation: 'nws-logo-pulse 2.4s ease-in-out infinite',
        }}>
          <video
            autoPlay loop muted playsInline
            style={{ width: '100%', height: '100%', objectFit: 'cover', display: 'block', mixBlendMode: 'screen' }}
          >
            <source src="assets/logo-loop.webm" type="video/webm" />
            <source src="assets/logo-loop.mp4" type="video/mp4" />
          </video>
        </div>
      </div>

      {/* Nav links */}
      <div style={{ display: 'flex', gap: '32px', alignItems: 'center' }}>
        {[
          { label: 'Services', id: 'services' },
          { label: 'How It Works', id: 'how-it-works' },
          { label: 'Results', id: 'social-proof' },
        ].map(({ label, id }) => (
          <a key={id} href={`#${id}`}
            onClick={e => { e.preventDefault(); document.getElementById(id)?.scrollIntoView({ behavior: 'smooth' }); }}
            style={{ fontFamily: "'DM Sans', sans-serif", fontSize: '0.82rem', letterSpacing: '0.04em', color: '#64748B', textDecoration: 'none', transition: 'color 0.2s ease' }}
            onMouseEnter={e => e.target.style.color = '#e8e8e8'}
            onMouseLeave={e => e.target.style.color = '#64748B'}
          >{label}</a>
        ))}

        <button
          onClick={() => document.getElementById('cta-footer')?.scrollIntoView({ behavior: 'smooth' })}
          style={{
            fontFamily: "'DM Sans', sans-serif",
            fontSize: '0.8rem', fontWeight: 500,
            padding: '8px 20px', borderRadius: '6px',
            background: 'transparent',
            color: `rgba(173,255,47,${sig.limeOpacity})`,
            border: `1px solid rgba(173,255,47,${sig.glowOpacity * 0.8})`,
            cursor: 'pointer', transition: 'all 0.2s ease', letterSpacing: '0.02em',
          }}
          onMouseEnter={e => {
            e.currentTarget.style.background = `rgba(173,255,47,0.08)`;
            e.currentTarget.style.borderColor = `rgba(173,255,47,0.6)`;
          }}
          onMouseLeave={e => {
            e.currentTarget.style.background = 'transparent';
            e.currentTarget.style.borderColor = `rgba(173,255,47,${sig.glowOpacity * 0.8})`;
          }}
        >Get Started</button>
      </div>
    </nav>
  );
};

// ── Atmosphere overlay injected into body ─────────────────────────────────────
const AtmosphereLayer = () => {
  const { atmosphere } = useTweakCtx();
  const cfg = ATMOSPHERES[atmosphere] || ATMOSPHERES.Nebula;
  if (!cfg.nebulaOverlay) return null;
  return (
    <div style={{
      position: 'fixed', inset: 0, zIndex: 0,
      background: cfg.nebulaOverlay,
      pointerEvents: 'none',
      transition: 'background 1s ease',
    }} />
  );
};

// ── App ───────────────────────────────────────────────────────────────────────
const App = () => {
  const [tweaks, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const { atmosphere } = tweaks;
  const cfg = ATMOSPHERES[atmosphere] || ATMOSPHERES.Nebula;

  return (
    <TweakCtx.Provider value={tweaks}>
      <div style={{
        background: cfg.pageBg,
        minHeight: '100vh',
        color: '#e8e8e8',
        position: 'relative',
        transition: 'background 1s ease',
      }}>
        <AtmosphereLayer />
        <NavBar />
        <HeroSection tweaks={tweaks} />
        <ScrollJourney />
        <ServicesSection tweaks={tweaks} />
        <HowItWorksSection tweaks={tweaks} />
        <SocialProofSection tweaks={tweaks} />
        <CTAFooterSection tweaks={tweaks} />

        {/* Tweaks Panel */}
        <TweaksPanel title="Tweaks">
          <TweakSection label="Atmosphere" />
          <TweakRadio
            label="Mood"
            value={tweaks.atmosphere}
            options={['Void', 'Nebula', 'Aurora']}
            onChange={v => setTweak('atmosphere', v)}
          />

          <TweakSection label="Signal Intensity" />
          <TweakSlider
            label="Lime accent energy"
            value={tweaks.signalIntensity}
            min={10} max={100} step={1}
            unit="%"
            onChange={v => setTweak('signalIntensity', v)}
          />

          <TweakSection label="Type Character" />
          <TweakRadio
            label="Weight"
            value={tweaks.typeWeight}
            options={['Ghost', 'Refined', 'Impact']}
            onChange={v => setTweak('typeWeight', v)}
          />
        </TweaksPanel>
      </div>
    </TweakCtx.Provider>
  );
};

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