// landing-sections.jsx — "why" → footer (filen.io-style)
const { useState: useStateLS, useRef: useRefLS, useEffect: useEffectLS } = React;

// ─── "WHY YOU NEED ROSTEALTH" — 3 columns w/ dotted connector + glow icons ─────
const WhySection = () => {
  const r = useReveal();
  const cols = [
    { color: '#22D3EE', glow: 'rgba(129,140,248,0.5)', icon: <Icon.Bolt />, title: 'All features', body: "RoStealth offers a wide range of tracking features, delivering a complete community overview. You'll feel at home really fast." },
    { color: '#5EEAD4', glow: 'rgba(192,132,252,0.5)', icon: <Icon.Shield />, title: 'Public data only', body: 'RoStealth reads only data Roblox already makes public. No passwords, no account access, no private data — ever.' },
    { color: '#34D399', glow: 'rgba(52,211,153,0.5)', icon: <Icon.Eye />, title: 'Transparent', body: 'No hidden bots or shady scripts running in the background. Just the official public Roblox API, used honestly.' },
  ];
  return (
    <section style={{ padding: 'clamp(80px,12vh,140px) max(24px,5vw)', position: 'relative' }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <SectionHead title="Why you need RoStealth in your" gradientWord="life" sub="All the tools you need to run a tight community, built around honest, public data. RoStealth strives for the perfect mix of insight, simplicity, and trust." />
        <div ref={r} style={{ position: 'relative', display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 40, marginTop: 24 }} className="footer-grid">
          {/* dotted connector */}
          <div style={{ position: 'absolute', top: 30, left: '20%', right: '20%', height: 1, borderTop: '1px dashed var(--border2)', pointerEvents: 'none' }} className="why-connector" />
          {cols.map((c, i) => (
            <div key={i} style={{ textAlign: 'center', display: 'flex', flexDirection: 'column', alignItems: 'center', position: 'relative' }}>
              <div style={{ position: 'relative', marginBottom: 24 }}>
                <div style={{ width: 60, height: 60, borderRadius: 16, background: 'var(--bg2)', border: '1px solid var(--border)', display: 'flex', alignItems: 'center', justifyContent: 'center', color: c.color, position: 'relative', zIndex: 1 }}>
                  <span style={{ transform: 'scale(1.4)' }}>{c.icon}</span>
                </div>
                {/* glow beam underneath */}
                <div style={{ position: 'absolute', bottom: -8, left: '50%', transform: 'translateX(-50%)', width: 50, height: 16, background: `radial-gradient(ellipse at center, ${c.glow} 0%, transparent 75%)`, filter: 'blur(6px)', pointerEvents: 'none' }} />
              </div>
              <h3 style={{ fontSize: 22, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--t1)', marginBottom: 12 }}>{c.title}</h3>
              <p style={{ fontSize: 15, color: 'var(--t2)', lineHeight: 1.7, maxWidth: 280 }}>{c.body}</p>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

// ─── "ALL-IN-ONE SOLUTION" — 4 column feature grid ─────────────────────────────
const FeaturesSection = () => {
  const ref = useRefLS(null);
  useEffectLS(() => {
    const el = ref.current; if (!el) return;
    const cells = Array.from(el.children);
    cells.forEach((c, i) => { c.classList.add('reveal'); c.style.transitionDelay = `${(i % 4) * 50}ms`; });
    let done = false;
    const show = () => { if (done) return; done = true; cells.forEach(c => c.classList.add('in')); };
    let io;
    try { io = new IntersectionObserver(es => es.forEach(e => { if (e.isIntersecting) show(); }), { threshold: 0.05 }); io.observe(el); } catch (_) { show(); }
    const t = setTimeout(show, 1500);
    return () => { io && io.disconnect(); clearTimeout(t); };
  }, []);

  const feats = [
    { icon: <Icon.User />, title: 'Built for everybody', body: 'Made for clan leaders, group owners, moderators, and anyone who runs a Roblox community.' },
    { icon: <Icon.Dashboard />, title: 'Ease of use', body: 'Our clean dashboard makes both beginners and power users feel right at home.' },
    { icon: <Icon.Pricing />, title: 'Pricing like no other', body: 'No subscriptions or hidden fees — every feature is included for one flat $5 pass.' },
    { icon: <Icon.Bolt />, title: 'Real-time', body: 'Status refreshes every 30 seconds, so your board reflects changes almost as they happen.' },
    { icon: <Icon.Discord />, title: 'Discord alerts', body: 'Route any status change straight to your server with custom webhook conditions.' },
    { icon: <Icon.Key />, title: 'Full API access', body: 'Pull the same live data into your own bots with a clean, documented REST API.' },
    { icon: <Icon.Group />, title: 'Track whole groups', body: 'Monitor an entire clan by its Group ID — member count, active members, and ranks.' },
    { icon: <Icon.Flag />, title: 'Flag & triage', body: 'Mark members worth a closer look. Flagged accounts float to the top and surface in alerts.' },
  ];

  return (
    <section id="features" style={{ padding: 'clamp(80px,12vh,140px) max(24px,5vw)' }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <SectionHead title="An all-in-one solution built for" gradientWord="you" sub="Explore a feature-rich tracking platform tailored to your community. From live status and Discord alerts to session history and a full API — all in one place." />
        <div ref={ref} style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 0, border: '1px solid var(--border)', borderRadius: 16, overflow: 'hidden' }} className="feat-grid">
          {feats.map((f, i) => {
            const col = i % 4, row = Math.floor(i / 4);
            return (
              <div key={i} style={{ padding: '28px 24px', borderLeft: col > 0 ? '1px solid var(--border)' : 'none', borderTop: row > 0 ? '1px solid var(--border)' : 'none', transition: 'background 0.2s', cursor: 'default' }}
                onMouseEnter={e => e.currentTarget.style.background = 'rgba(255,255,255,0.018)'}
                onMouseLeave={e => e.currentTarget.style.background = 'transparent'}>
                <div style={{ color: 'var(--t2)', marginBottom: 18, display: 'flex' }}><span style={{ transform: 'scale(1.3)', transformOrigin: 'left center' }}>{f.icon}</span></div>
                <h3 style={{ fontSize: 17, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--t1)', marginBottom: 10 }}>{f.title}</h3>
                <p style={{ fontSize: 13.5, color: 'var(--t2)', lineHeight: 1.65 }}>{f.body}</p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
};

// ─── LIVE FEED (kept, restyled minimal) ───────────────────────────────────────
const FEED_POOL = [
  { user: 'xShadowReaper', status: 'online', text: 'came online' },
  { user: 'FrostClan_Leader', status: 'in-game', text: 'joined Arsenal' },
  { user: 'Phantom_Wolf', status: 'online', text: 'came online' },
  { user: 'VelocityX99', status: 'offline', text: 'went offline' },
  { user: 'DarkMatter_X', status: 'in-game', text: 'joined Da Hood' },
  { user: 'ShadowRift_7', status: 'online', text: 'came online' },
  { user: 'NightOwl_99', status: 'in-game', text: 'joined Bloxburg' },
  { user: 'GhostRunner', status: 'offline', text: 'went offline' },
  { user: 'ClanLord_V', status: 'online', text: 'came online' },
];

const LiveFeed = () => {
  const [items, setItems] = useStateLS(() => FEED_POOL.slice(0, 7).map((e, i) => ({ ...e, id: i, fresh: false })));
  const nextIdxRef = useRefLS(7);
  const nextKeyRef = useRefLS(100);
  useEffectLS(() => {
    const id = setInterval(() => {
      const event = FEED_POOL[nextIdxRef.current % FEED_POOL.length]; nextIdxRef.current++;
      const key = nextKeyRef.current++;
      setItems(prev => [{ ...event, id: key, fresh: true }, ...prev.slice(0, 6).map(e => ({ ...e, fresh: false }))]);
    }, 1900);
    return () => clearInterval(id);
  }, []);
  const r = useReveal();
  const sc = s => s === 'online' ? 'var(--green)' : s === 'in-game' ? 'var(--amber)' : 'var(--t4)';
  return (
    <section id="activity" style={{ padding: 'clamp(60px,9vh,110px) max(24px,5vw)' }}>
      <div style={{ maxWidth: 540, margin: '0 auto' }}>
        <SectionHead title="Happening right" gradientWord="now" sub="Status changes stream in the moment they occur." />
        <div ref={r} style={{ background: 'var(--bg1)', border: '1px solid var(--border)', borderRadius: 16, overflow: 'hidden' }}>
          <div style={{ padding: '11px 18px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 8 }}>
            <span style={{ width: 7, height: 7, borderRadius: '50%', background: 'var(--green)', animation: 'pulse-dot 2.2s ease-in-out infinite' }} />
            <span style={{ fontSize: 12.5, color: 'var(--t2)', fontWeight: 500 }}>Live feed</span>
            <span style={{ marginLeft: 'auto', fontSize: 11, color: 'var(--t4)' }}>updates every 2s</span>
          </div>
          {items.map((event, i) => (
            <div key={event.id} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '11px 18px', borderBottom: i < items.length - 1 ? '1px solid rgba(255,255,255,0.04)' : 'none', opacity: Math.max(0.2, 1 - i * 0.11), animation: event.fresh ? 'feed-enter 0.35s var(--ease-out-expo) both' : 'none', transition: 'opacity 0.4s' }}>
              <Avatar name={event.user} size={28} />
              <div style={{ flex: 1 }}><span style={{ fontSize: 13.5, fontWeight: 600, color: 'var(--t1)' }}>{event.user}</span> <span style={{ fontSize: 13.5, color: 'var(--t3)' }}>{event.text}</span></div>
              <div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0 }}>
                <span style={{ width: 6, height: 6, borderRadius: '50%', background: sc(event.status) }} />
                <span style={{ fontSize: 11, color: 'var(--t4)' }}>{i === 0 ? 'now' : `${i * 2}s ago`}</span>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
};

// ─── PRICING ──────────────────────────────────────────────────────────────────
const PricingSection = ({ onSignup }) => {
  const r = useReveal();
  const feats = ['Unlimited users & groups', 'Real-time updates every 30s', '30-day activity history', 'Discord webhook alerts', 'Custom alert conditions', 'Full REST API access'];
  return (
    <section id="pricing" style={{ padding: 'clamp(80px,12vh,140px) max(24px,5vw)' }}>
      <div style={{ maxWidth: 520, margin: '0 auto' }}>
        <SectionHead title="One payment." gradientWord="30 days." sub="Pay once, get full access for 30 days. No subscriptions, no renewals, no surprises." />
        <div ref={r}>
          <div style={{ background: 'var(--bg1)', border: '1px solid var(--border2)', borderRadius: 20, padding: 36, position: 'relative', overflow: 'hidden' }}>
            <div style={{ position: 'absolute', top: -1, left: 0, right: 0, height: 2, background: 'linear-gradient(90deg, #22D3EE, #2DD4BF, #34D399)' }} />
            <div style={{ display: 'flex', alignItems: 'flex-start', justifyContent: 'space-between', flexWrap: 'wrap', gap: 20, marginBottom: 28 }}>
              <div>
                <div style={{ fontSize: 12.5, fontWeight: 500, color: 'var(--p4)', letterSpacing: '0.04em', textTransform: 'uppercase', marginBottom: 14 }}>30-Day Pass</div>
                <div style={{ display: 'flex', alignItems: 'baseline', gap: 6 }}>
                  <span style={{ fontSize: 56, fontWeight: 800, color: 'var(--t1)', letterSpacing: '-0.05em', lineHeight: 1 }}>$5</span>
                  <span style={{ fontSize: 15, color: 'var(--t3)' }}> / 30 days</span>
                </div>
                <div style={{ fontSize: 13, color: 'var(--t3)', marginTop: 10 }}>One-time payment · full access</div>
              </div>
              <WhiteBtn onClick={onSignup} style={{ padding: '12px 24px', fontSize: 14.5 }}>Get access</WhiteBtn>
            </div>
            <div style={{ height: 1, background: 'var(--border)', marginBottom: 24 }} />
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: '13px 24px' }}>
              {feats.map(f => (
                <div key={f} style={{ display: 'flex', gap: 10, alignItems: 'flex-start' }}>
                  <span style={{ color: 'var(--green)', flexShrink: 0, marginTop: 2 }}><Icon.Check /></span>
                  <span style={{ fontSize: 14, color: 'var(--t1)' }}>{f}</span>
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

// ─── FAQ ──────────────────────────────────────────────────────────────────────
const FAQItem = ({ q, a }) => {
  const [open, setOpen] = useStateLS(false);
  return (
    <div style={{ borderBottom: '1px solid var(--border)' }}>
      <button onClick={() => setOpen(o => !o)} style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, padding: '20px 4px', background: 'none', border: 'none', cursor: 'pointer', textAlign: 'left', fontFamily: 'var(--font)' }}>
        <span style={{ fontSize: 16, fontWeight: 600, color: 'var(--t1)', letterSpacing: '-0.01em' }}>{q}</span>
        <span style={{ color: open ? 'var(--p4)' : 'var(--t3)', flexShrink: 0, transform: open ? 'rotate(45deg)' : 'none', transition: 'transform 0.25s var(--ease-out-expo)', display: 'flex' }}><Icon.Plus /></span>
      </button>
      <div style={{ maxHeight: open ? 240 : 0, overflow: 'hidden', transition: 'max-height 0.3s var(--ease-out-expo)' }}>
        <p style={{ fontSize: 15, color: 'var(--t2)', lineHeight: 1.72, padding: '0 4px 22px', maxWidth: 680 }}>{a}</p>
      </div>
    </div>
  );
};

const FAQ = () => {
  const faqs = [
    ['Is this allowed? Is it spying?', "RoStealth only reads data Roblox already makes public — the same presence and profile info anyone can see on a profile page. No private data, no account access, and no passwords are ever involved."],
    ['Do you need my Roblox password?', "Never. RoStealth authenticates you with your own RoStealth account and reads public Roblox data through the official public API."],
    ['How fast do statuses update?', "Your pass refreshes every 30 seconds, so the board reflects changes almost as they happen."],
    ['What does a pass include?', "Everything: unlimited users and groups, real-time updates, 30-day history, Discord alerts, custom conditions, and API access — full access for 30 days from purchase."],
    ['Is RoStealth affiliated with Roblox?', "No. RoStealth is an independent tool and is not affiliated with, endorsed by, or sponsored by Roblox Corporation."],
  ];
  return (
    <section id="faq" style={{ padding: 'clamp(80px,12vh,140px) max(24px,5vw)' }}>
      <div style={{ maxWidth: 760, margin: '0 auto' }}>
        <SectionHead title="Questions," gradientWord="answered." />
        <div>{faqs.map(([q, a]) => <FAQItem key={q} q={q} a={a} />)}</div>
      </div>
    </section>
  );
};

// ─── FINAL CTA ────────────────────────────────────────────────────────────────
const FinalCTA = ({ onSignup }) => {
  const r = useReveal();
  return (
    <section style={{ padding: 'clamp(90px,13vh,150px) max(24px,5vw)', position: 'relative', overflow: 'hidden' }}>
      <div style={{ position: 'absolute', bottom: -140, left: '50%', transform: 'translateX(-50%)', width: 900, height: 420, background: 'radial-gradient(ellipse at center, rgba(6,182,212,0.13), transparent 65%)', pointerEvents: 'none' }} />
      <div ref={r} style={{ position: 'relative', maxWidth: 620, margin: '0 auto', textAlign: 'center' }}>
        <h2 style={{ fontSize: 'clamp(32px,5vw,56px)', fontWeight: 700, letterSpacing: '-0.04em', lineHeight: 1.05, color: 'var(--t1)', textWrap: 'balance' }}>
          Stop guessing <span style={GRADIENT_TEXT}>who's online.</span>
        </h2>
        <p style={{ fontSize: 17, color: 'var(--t2)', lineHeight: 1.65, maxWidth: 460, margin: '20px auto 0' }}>Add your first member in under a minute. Watch your community come alive on a single board.</p>
        <div style={{ display: 'flex', justifyContent: 'center', marginTop: 36 }}>
          <WhiteBtn onClick={onSignup}>Get started — $5</WhiteBtn>
        </div>
        <p style={{ fontSize: 13, color: 'var(--t4)', marginTop: 18 }}>No subscription. Full access for 30 days.</p>
      </div>
    </section>
  );
};

// ─── FOOTER ───────────────────────────────────────────────────────────────────
const Footer = ({ onTerms, onPrivacy }) => {
  const cols = [
    ['Product', ['Features', 'How it works', 'Pricing', 'FAQ']],
    ['Company', ['About', 'Help center', 'Contact', 'Status']],
    ['Legal', ['Terms', 'Privacy', 'Trust & security', 'Cookies']],
  ];
  const legalActions = { 'Terms': onTerms, 'Privacy': onPrivacy };
  return (
    <footer style={{ borderTop: '1px solid var(--border)', padding: '56px max(24px,5vw) 36px', background: 'var(--bg0)' }}>
      <div style={{ maxWidth: 1080, margin: '0 auto' }}>
        <div style={{ display: 'flex', gap: 12, alignItems: 'flex-start', padding: '14px 18px', border: '1px solid var(--border)', borderRadius: 12, marginBottom: 48, background: 'var(--bg1)' }}>
          <span style={{ color: 'var(--p4)', flexShrink: 0, marginTop: 1 }}><Icon.Shield /></span>
          <p style={{ fontSize: 13, color: 'var(--t2)', lineHeight: 1.65 }}>RoStealth uses only publicly available Roblox data for entertainment and legitimate community management. Not affiliated with or endorsed by Roblox Corporation. Users must comply with Roblox's Terms of Service.</p>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: '1.6fr repeat(3,1fr)', gap: 32 }} className="footer-grid">
          <div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 14 }}>
              <LogoMark size={26} />
              <span style={{ fontSize: 15, fontWeight: 700, color: 'var(--t1)', letterSpacing: '-0.02em' }}>RoStealth</span>
            </div>
            <p style={{ fontSize: 13, color: 'var(--t3)', lineHeight: 1.65, maxWidth: 270 }}>Roblox community intelligence. Track public activity, watch live status, and keep your group tight.</p>
            <div style={{ display: 'flex', gap: 7, marginTop: 18 }}>
              {['X', 'TT', 'IG', 'DC'].map(s => (
                <div key={s} style={{ width: 32, height: 32, borderRadius: 8, border: '1px solid var(--border)', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 10, color: 'var(--t3)', cursor: 'pointer', transition: 'border-color 0.15s, color 0.15s' }} onMouseEnter={e => { e.currentTarget.style.borderColor = 'var(--border2)'; e.currentTarget.style.color = 'var(--t1)'; }} onMouseLeave={e => { e.currentTarget.style.borderColor = 'var(--border)'; e.currentTarget.style.color = 'var(--t3)'; }}>{s}</div>
              ))}
            </div>
          </div>
          {cols.map(([h, links]) => (
            <div key={h}>
              <div style={{ fontSize: 11, fontWeight: 600, color: 'var(--t3)', textTransform: 'uppercase', letterSpacing: '0.1em', marginBottom: 16 }}>{h}</div>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 11 }}>
                {links.map(l => <span key={l} onClick={legalActions[l] || undefined} style={{ fontSize: 14, color: 'var(--t2)', cursor: 'pointer', transition: 'color 0.15s' }} onMouseEnter={e => e.currentTarget.style.color = 'var(--t1)'} onMouseLeave={e => e.currentTarget.style.color = 'var(--t2)'}>{l}</span>)}
              </div>
            </div>
          ))}
        </div>
        <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12, marginTop: 44, paddingTop: 24, borderTop: '1px solid var(--border)' }}>
          <span style={{ fontSize: 13, color: 'var(--t4)' }}>© 2026 RoStealth · rostealth.site</span>
          <span style={{ fontSize: 13, color: 'var(--t4)' }}>Not affiliated with Roblox Corporation.</span>
        </div>
      </div>
    </footer>
  );
};

// ─── PAGE WRAPPER ─────────────────────────────────────────────────────────────
const LandingPage = ({ onLogin, onSignup, onTerms, onPrivacy }) => (
  <div style={{ overflowX: 'hidden' }}>
    <LandingNav onLogin={onLogin} onSignup={onSignup} />
    <Hero onSignup={onSignup} />
    <HowItWorks />
    <WhySection />
    <FeaturesSection />
    <LiveFeed />
    <PricingSection onSignup={onSignup} />
    <FAQ />
    <FinalCTA onSignup={onSignup} />
    <Footer onTerms={onTerms} onPrivacy={onPrivacy} />
  </div>
);

Object.assign(window, { LandingPage, WhySection, FeaturesSection, LiveFeed, PricingSection, FAQ, FinalCTA, Footer });
