/* ============================================================
   COURSEDY — Landing page
   ============================================================ */

/* ---------- Top nav ---------- */
function Nav({ go }) {
  const [scrolled, setScrolled] = useState(false);
  useEffect(() => {
    const el = document.querySelector('[data-landing-scroll]');
    if (!el) return;
    const fn = () => setScrolled(el.scrollTop > 12);
    el.addEventListener('scroll', fn); return () => el.removeEventListener('scroll', fn);
  }, []);
  const links = [
    { label: 'Features',     id: 'features' },
    { label: 'How it works', id: 'how-it-works' },
    { label: 'Pricing',      id: 'pricing' },
    { label: 'FAQ',          id: 'faq' },
  ];
  const scrollTo = (id) => {
    const sc = document.querySelector('[data-landing-scroll]');
    const target = document.getElementById(id);
    if (!sc || !target) return;
    const top = target.getBoundingClientRect().top - sc.getBoundingClientRect().top + sc.scrollTop - 70;
    sc.scrollTo({ top, behavior: 'smooth' });
  };
  return (
    <header style={{ position: 'sticky', top: 0, zIndex: 50, transition: 'all .25s',
      background: scrolled ? 'rgba(250,250,248,.8)' : 'transparent',
      backdropFilter: scrolled ? 'blur(14px)' : 'none',
      borderBottom: scrolled ? '1px solid var(--line)' : '1px solid transparent' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', padding: '15px 28px', display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
        <Logo onClick={() => go('landing')} />
        <nav className="row" style={{ gap: 4 }}>
          {links.map(l => (
            <a
              key={l.id}
              className="btn btn-ghost btn-sm"
              style={{ fontWeight: 500, color: 'var(--ink-2)', cursor: 'pointer' }}
              onClick={(e) => { e.preventDefault(); scrollTo(l.id); }}
            >{l.label}</a>
          ))}
        </nav>
        <div className="row" style={{ gap: 8 }}>
          <Btn variant="ghost" size="sm" onClick={() => go('signin')}>Sign in</Btn>
          <Btn variant="primary" size="sm" onClick={() => go('signup')} iconR={<ArrowR />}>Start free</Btn>
        </div>
      </div>
    </header>
  );
}

/* ---------- Hero animated demo ---------- */
const DEMO_OUTLINE = [
  { m: 'Foundations of Watercolor', ls: ['Materials & your first wash', 'Color mixing on paper', 'Water control basics'] },
  { m: 'Techniques That Matter', ls: ['Wet-on-wet vs wet-on-dry', 'Layering & glazing', 'Lifting and corrections'] },
  { m: 'Painting Real Subjects', ls: ['Skies & loose landscapes', 'Botanicals step by step'] },
  { m: 'Finishing & Sharing', ls: ['Framing your work', 'Building a small portfolio'] },
];
function HeroDemo() {
  const [phase, setPhase] = useState('typing'); // typing -> thinking -> building -> done
  const [typed, setTyped] = useState('');
  const [built, setBuilt] = useState(0);
  const topic = 'Intro to Watercolor Painting';
  useEffect(() => {
    let t = []; let alive = true;
    const run = () => {
      setPhase('typing'); setTyped(''); setBuilt(0);
      // type
      [...topic].forEach((_, i) => t.push(setTimeout(() => alive && setTyped(topic.slice(0, i + 1)), 380 + i * 42)));
      const typedDone = 380 + topic.length * 42 + 250;
      t.push(setTimeout(() => alive && setPhase('thinking'), typedDone));
      t.push(setTimeout(() => alive && setPhase('building'), typedDone + 1100));
      DEMO_OUTLINE.forEach((_, i) => t.push(setTimeout(() => alive && setBuilt(i + 1), typedDone + 1100 + 520 + i * 620)));
      const total = typedDone + 1100 + 520 + DEMO_OUTLINE.length * 620 + 2600;
      t.push(setTimeout(() => alive && run(), total));
    };
    run();
    return () => { alive = false; t.forEach(clearTimeout); };
  }, []);
  return (
    <div className="card" style={{ width: '100%', maxWidth: 940, margin: '0 auto', boxShadow: 'var(--sh-lg)', overflow: 'hidden', borderRadius: 'var(--r-lg)' }}>
      {/* window chrome */}
      <div className="row" style={{ height: 42, padding: '0 14px', borderBottom: '1px solid var(--line)', gap: 8, background: 'var(--surface-2)' }}>
        <span className="row" style={{ gap: 6 }}>
          {['#E5675F','#E9B23C','#46B962'].map(c => <span key={c} style={{ width: 11, height: 11, borderRadius: 50, background: c }} />)}
        </span>
        <div className="row grow" style={{ justifyContent: 'center' }}>
          <span className="mono" style={{ fontSize: 11.5, color: 'var(--faint)' }}>coursedy.com / create</span>
        </div>
        <span style={{ width: 50 }} />
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: '1fr 1.15fr', minHeight: 340 }}>
        {/* left: prompt panel */}
        <div style={{ padding: '22px 22px', borderRight: '1px solid var(--line)', display: 'flex', flexDirection: 'column', gap: 16 }}>
          <div className="row" style={{ gap: 8 }}>
            <span className="logo-mark" style={{ width: 24, height: 24 }}><Spark size={14} /></span>
            <span style={{ fontWeight: 600, fontSize: 14 }}>Course brief</span>
          </div>
          <div>
            <div className="label" style={{ fontSize: 12 }}>What do you want to teach?</div>
            <div className="field" style={{ display: 'flex', alignItems: 'center', height: 'auto', minHeight: 46, padding: '11px 13px', fontSize: 14.5, borderColor: phase==='typing' ? 'var(--brand)' : 'var(--line-strong)', boxShadow: phase==='typing' ? '0 0 0 3.5px var(--brand-tint)' : 'none' }}>
              <span>{typed}</span>{phase === 'typing' && <span className="cursor-blink" />}
            </div>
          </div>
          <div className="row" style={{ gap: 8, flexWrap: 'wrap' }}>
            <span className="pill" style={{ height: 26, fontSize: 12 }}>Audience · Beginners</span>
            <span className="pill" style={{ height: 26, fontSize: 12 }}>Depth · 4 modules</span>
          </div>
          <div className="grow" />
          <button className="btn btn-ai" style={{ width: '100%' }} disabled>
            {phase === 'thinking' || phase === 'building' ? <><span className="spinner" /> Generating…</> : <><Sparkles size={16} /> Generate course</>}
          </button>
        </div>
        {/* right: streaming outline */}
        <div className="scroll" style={{ padding: '20px 22px', background: 'var(--paper)', overflow: 'hidden' }}>
          <div className="row" style={{ justifyContent: 'space-between', marginBottom: 14 }}>
            <span className="mono" style={{ fontSize: 11, letterSpacing: '.1em', textTransform: 'uppercase', color: 'var(--faint)' }}>Live outline</span>
            {phase === 'building' && <span className="row" style={{ gap: 6, fontSize: 11.5, color: 'var(--brand)' }} ><span className="live-dot" />writing</span>}
          </div>
          {phase === 'thinking' ? (
            <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
              <div className="row" style={{ gap: 8, color: 'var(--muted)', fontSize: 13.5 }}><TypingDots /> Designing curriculum…</div>
              {[88,72,80,64].map((w,i) => <div key={i} className="skeleton" style={{ height: 14, width: `${w}%` }} />)}
            </div>
          ) : phase === 'typing' ? (
            <div className="center" style={{ height: 240, color: 'var(--faint)', fontSize: 13.5, flexDirection: 'column', gap: 10 }}>
              <SparkOutline size={28} style={{ opacity: .5 }} />
              Your course will appear here
            </div>
          ) : (
            <div style={{ display: 'flex', flexDirection: 'column', gap: 9 }}>
              {DEMO_OUTLINE.slice(0, built).map((mod, i) => (
                <div key={i} className="fade-up" style={{ background: 'var(--surface)', border: '1px solid var(--line)', borderRadius: 10, padding: '11px 13px' }}>
                  <div className="row" style={{ gap: 9 }}>
                    <span className="badge badge-brand" style={{ width: 22, justifyContent: 'center' }}>{i+1}</span>
                    <b style={{ fontSize: 13.5, letterSpacing: '-0.01em' }}>{mod.m}</b>
                  </div>
                  <div style={{ marginTop: 8, display: 'flex', flexDirection: 'column', gap: 5, paddingLeft: 31 }}>
                    {mod.ls.map((l, j) => (
                      <div key={j} className="row" style={{ gap: 7, fontSize: 12.5, color: 'var(--muted)' }}>
                        <File size={12} style={{ color: 'var(--faint)' }} /> {l}
                      </div>
                    ))}
                  </div>
                </div>
              ))}
              {built >= DEMO_OUTLINE.length && (
                <div className="row fade-in" style={{ gap: 7, color: 'var(--green)', fontSize: 13, fontWeight: 600, marginTop: 4 }}>
                  <CheckCircle size={15} /> Course ready · 4 modules · 10 lessons
                </div>
              )}
            </div>
          )}
        </div>
      </div>
    </div>
  );
}

/* ---------- Hero ---------- */
function Hero({ go }) {
  return (
    <section style={{ position: 'relative', overflow: 'hidden' }}>
      <div className="grid-bg" style={{ position: 'absolute', inset: 0, maskImage: 'radial-gradient(120% 80% at 50% 0%, #000 30%, transparent 72%)', WebkitMaskImage: 'radial-gradient(120% 80% at 50% 0%, #000 30%, transparent 72%)' }} />
      <div style={{ position: 'absolute', top: -120, left: '50%', transform: 'translateX(-50%)', width: 720, height: 420, background: 'radial-gradient(circle, rgba(91,84,230,.14), transparent 65%)', pointerEvents: 'none' }} />
      <div style={{ position: 'relative', maxWidth: 1200, margin: '0 auto', padding: '64px 28px 0', textAlign: 'center' }}>
        <div className="reveal" style={{ '--d': '0s', display: 'inline-flex' }}>
          <span className="pill brand" style={{ height: 32, paddingLeft: 6 }}>
            <span className="badge badge-brand" style={{ background: 'var(--brand)', color: '#fff' }}>NEW</span>
            Agentic AI chat · WYSIWYG editor · 8 export formats
          </span>
        </div>
        <h1 className="display reveal" style={{ '--d': '.06s', fontSize: 'clamp(36px,6vw,72px)', marginTop: 24, maxWidth: 880, marginLeft: 'auto', marginRight: 'auto' }}>
          From a single idea to a complete course — <span style={{ background: 'var(--ai-grad)', WebkitBackgroundClip: 'text', backgroundClip: 'text', color: 'transparent' }}>in minutes.</span>
        </h1>
        <p className="lead reveal" style={{ '--d': '.12s', fontSize: 'clamp(17px,2vw,21px)', maxWidth: 620, margin: '22px auto 0' }}>
          Coursedy turns any topic into a finished course — modules, written lessons, quizzes, and slide notes — then lets you refine every word inline or via AI chat. Export to DOCX, PDF, SCORM, ePub, and more.
        </p>
        <div className="row reveal" style={{ '--d': '.18s', justifyContent: 'center', gap: 12, marginTop: 30, flexWrap: 'wrap' }}>
          <Btn variant="brand" size="lg" onClick={() => go('signup')} iconR={<ArrowR />}>Start free — no card</Btn>
          <Btn variant="outline" size="lg" onClick={() => go('creator')} icon={<PlayCircle />}>See it generate</Btn>
        </div>
        <div className="row reveal" style={{ '--d': '.24s', justifyContent: 'center', gap: 18, marginTop: 18, fontSize: 13, color: 'var(--muted)' }}>
          <span className="row" style={{ gap: 6 }}><Check size={14} style={{ color: 'var(--green)' }} /> Free course on signup</span>
          <span className="row" style={{ gap: 6 }}><Check size={14} style={{ color: 'var(--green)' }} /> SCORM 1.2 + ePub + DOCX</span>
          <span className="row" style={{ gap: 6 }}><Check size={14} style={{ color: 'var(--green)' }} /> No credit card</span>
        </div>
        <div className="reveal" style={{ '--d': '.32s', marginTop: 48, paddingBottom: 8 }}>
          <HeroDemo />
        </div>
      </div>
    </section>
  );
}

/* ---------- Trust bar ---------- */
function TrustBar() {
  const logos = ['Teachable', 'Kajabi', 'Gumroad', 'Thinkific', 'Podia', 'Skool'];
  return (
    <section style={{ maxWidth: 1100, margin: '0 auto', padding: '56px 28px 8px' }}>
      <p className="mono" style={{ textAlign: 'center', fontSize: 12, letterSpacing: '.1em', textTransform: 'uppercase', color: 'var(--faint)', marginBottom: 26 }}>
        Exports straight into the tools you already use
      </p>
      <div className="row" style={{ justifyContent: 'center', gap: 'clamp(24px,5vw,56px)', flexWrap: 'wrap', opacity: .55 }}>
        {logos.map(l => <span key={l} style={{ fontSize: 20, fontWeight: 700, letterSpacing: '-0.02em', color: 'var(--ink-2)' }}>{l}</span>)}
      </div>
    </section>
  );
}

/* ---------- How it works ---------- */
function HowItWorks() {
  return (
    <section id="how-it-works" style={{ maxWidth: 1200, margin: '0 auto', padding: '96px 28px' }}>
      <SectionHead center eyebrow="How it works" title="Three steps from idea to finished course" />
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 20, marginTop: 56 }}>
        {STEPS.map((s, i) => (
          <div key={s.n} className="card" style={{ padding: '28px 26px', position: 'relative' }}>
            <div className="mono" style={{ fontSize: 13, color: 'var(--brand)', fontWeight: 600, letterSpacing: '.06em' }}>{s.n}</div>
            <h3 style={{ fontSize: 20, marginTop: 16, letterSpacing: '-0.02em' }}>{s.title}</h3>
            <p className="muted" style={{ fontSize: 14.5, lineHeight: 1.55, marginTop: 10 }}>{s.body}</p>
            {i < 2 && <div style={{ position: 'absolute', right: -12, top: '50%', color: 'var(--line-strong)', zIndex: 2 }} className="hide-sm"><ArrowR size={20} /></div>}
          </div>
        ))}
      </div>
    </section>
  );
}

/* ---------- Features grid ---------- */
function Features() {
  return (
    <section id="features" style={{ background: 'var(--surface)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', padding: '96px 28px' }}>
        <SectionHead eyebrow="Everything included" title="Everything you need to build great courses" sub="From first draft to final export, Coursedy handles the heavy lifting — you keep the voice." />
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 1, marginTop: 56, background: 'var(--line)', border: '1px solid var(--line)', borderRadius: 'var(--r-lg)', overflow: 'hidden' }}>
          {FEATURES.map((f, i) => {
            const Icon = ICON_BY_NAME(f.icon);
            return (
              <div key={i} style={{ background: 'var(--surface)', padding: '30px 28px', transition: 'background .2s' }}
                onMouseEnter={e => e.currentTarget.style.background = 'var(--surface-2)'}
                onMouseLeave={e => e.currentTarget.style.background = 'var(--surface)'}>
                <div className="center" style={{ width: 44, height: 44, borderRadius: 12, background: 'var(--brand-tint)', color: 'var(--brand)' }}><Icon size={21} /></div>
                <h3 style={{ fontSize: 18, marginTop: 20, letterSpacing: '-0.02em' }}>{f.title}</h3>
                <p className="muted" style={{ fontSize: 14, lineHeight: 1.55, marginTop: 9 }}>{f.body}</p>
              </div>
            );
          })}
        </div>
      </div>
    </section>
  );
}

/* ---------- Audiences ---------- */
const AUD = [
  { id: 'creator', label: 'Creators', icon: 'Star', head: 'Sell courses, not weekends', body: 'Draft a full paid course in an afternoon instead of a month. Export to DOCX, PDF, SCORM, or ePub and spend your time teaching — not formatting.', points: ['DOCX, PDF, SCORM, ePub exports', 'Built-in quizzes & slide notes', 'WYSIWYG + inline editing'] },
  { id: 'teams', label: 'Companies', icon: 'Briefcase', head: 'Training, on demand', body: 'Turn an internal brief into onboarding or compliance training before the meeting ends. SCORM 1.2 packages drop straight into your LMS.', points: ['SCORM 1.2 LMS-ready exports', 'Edit history audit trail', 'Quiz CSV for compliance tracking'] },
  { id: 'schools', label: 'Educators', icon: 'Book', head: 'Curriculum in a click', body: 'Scaffold lesson plans, assessments, and study guides aligned to your objectives — then refine with your classroom voice using inline editing or AI chat.', points: ['Objective-aligned modules', 'Auto quizzes with explanations', 'Drag-drop reordering & previews'] },
];
function Audiences() {
  const [tab, setTab] = useState('creator');
  const a = AUD.find(x => x.id === tab);
  const Icon = ICON_BY_NAME(a.icon);
  return (
    <section style={{ maxWidth: 1200, margin: '0 auto', padding: '96px 28px' }}>
      <SectionHead center eyebrow="Built for everyone who teaches" title="One engine, every kind of course" />
      <div className="row" style={{ justifyContent: 'center', gap: 8, marginTop: 36, flexWrap: 'wrap' }}>
        {AUD.map(x => <button key={x.id} className={`chip ${tab === x.id ? 'active' : ''}`} onClick={() => setTab(x.id)}>{x.label}</button>)}
      </div>
      <div className="card" key={tab} style={{ marginTop: 32, display: 'grid', gridTemplateColumns: '1fr 1fr', overflow: 'hidden', boxShadow: 'var(--sh-md)' }}>
        <div className="scale-in" style={{ padding: '46px 44px', display: 'flex', flexDirection: 'column', justifyContent: 'center' }}>
          <div className="center" style={{ width: 48, height: 48, borderRadius: 13, background: 'var(--brand-tint)', color: 'var(--brand)' }}><Icon size={23} /></div>
          <h3 style={{ fontSize: 28, marginTop: 22, letterSpacing: '-0.03em' }}>{a.head}</h3>
          <p className="muted" style={{ fontSize: 15.5, lineHeight: 1.6, marginTop: 12 }}>{a.body}</p>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 11, marginTop: 22 }}>
            {a.points.map(p => <div key={p} className="row" style={{ gap: 10, fontSize: 14.5 }}><span className="center" style={{ width: 20, height: 20, borderRadius: 50, background: 'var(--green-tint)', color: 'var(--green)' }}><Check size={13} /></span>{p}</div>)}
          </div>
        </div>
        <div className="scale-in" style={{ background: a && catOf('tech').grad, position: 'relative', minHeight: 380, display: 'flex', alignItems: 'center', justifyContent: 'center', padding: 30, background: 'var(--ai-grad-soft)', borderLeft: '1px solid var(--line)' }}>
          <AudiencePreview aud={tab} />
        </div>
      </div>
    </section>
  );
}
function AudiencePreview({ aud }) {
  // a small contextual mock per audience
  const items = {
    creator: COURSES.slice(3, 6),
    teams: COURSES.slice(1, 4),
    schools: COURSES.slice(5, 8),
  }[aud] || COURSES.slice(0, 3);
  return (
    <div style={{ width: '100%', maxWidth: 320, display: 'flex', flexDirection: 'column', gap: 11 }}>
      {items.map((c, i) => (
        <div key={c.id} className="card fade-up" style={{ '--d': `${i*.08}s`, padding: 12, display: 'flex', gap: 12, alignItems: 'center', boxShadow: 'var(--sh-sm)' }}>
          <div style={{ width: 52, height: 52, borderRadius: 9, background: catOf(c.cat).grad, flexShrink: 0 }} />
          <div style={{ minWidth: 0 }}>
            <div style={{ fontSize: 13.5, fontWeight: 600, letterSpacing: '-0.01em', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{c.title}</div>
            <div className="muted" style={{ fontSize: 12, marginTop: 3 }}>{c.modules.length} modules · {c.hours}h</div>
          </div>
        </div>
      ))}
    </div>
  );
}

/* ---------- Testimonials ---------- */
function Testimonials() {
  return (
    <section style={{ background: 'var(--surface)', borderTop: '1px solid var(--line)', borderBottom: '1px solid var(--line)' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', padding: '96px 28px' }}>
        <SectionHead eyebrow="Loved by builders" title="Trusted by educators and creators" />
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 20, marginTop: 56 }}>
          {TESTIMONIALS.map((t, i) => (
            <div key={i} className="card" style={{ padding: '28px 26px', display: 'flex', flexDirection: 'column' }}>
              <Quote size={26} style={{ color: 'var(--brand-tint-2)' }} />
              <p style={{ fontSize: 15.5, lineHeight: 1.6, marginTop: 16, flex: 1, letterSpacing: '-0.01em' }}>{t.quote}</p>
              <div className="row" style={{ gap: 12, marginTop: 22 }}>
                <Avatar name={t.name} size={40} cat={t.cat} />
                <div>
                  <div style={{ fontSize: 14, fontWeight: 600 }}>{t.name}</div>
                  <div className="muted" style={{ fontSize: 12.5 }}>{t.role}</div>
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---------- Pricing ---------- */
function Pricing({ go }) {
  return (
    <section id="pricing" style={{ maxWidth: 1140, margin: '0 auto', padding: '96px 28px' }}>
      <SectionHead center eyebrow="Pricing" title="Simple, transparent pricing" sub="Start free — no credit card required. Upgrade when you’re ready to scale." />
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 20, marginTop: 56, alignItems: 'start' }}>
        {PRICING.map(p => (
          <div key={p.name} className="card" style={{ padding: '30px 28px', position: 'relative', display: 'flex', flexDirection: 'column',
            border: p.highlight ? '1.5px solid var(--brand)' : '1px solid var(--line)',
            boxShadow: p.highlight ? 'var(--sh-md)' : 'var(--sh-xs)', transform: p.highlight ? 'scale(1.02)' : 'none' }}>
            {p.highlight && <span className="badge badge-brand" style={{ position: 'absolute', top: -11, left: 28, background: 'var(--brand)', color: '#fff', height: 24 }}>MOST POPULAR</span>}
            <div style={{ fontSize: 15, fontWeight: 600 }}>{p.name}</div>
            <div className="muted" style={{ fontSize: 13.5, marginTop: 3 }}>{p.tagline}</div>
            <div className="row" style={{ alignItems: 'baseline', gap: 3, marginTop: 20 }}>
              <span style={{ fontSize: 44, fontWeight: 800, letterSpacing: '-0.04em' }}>${p.price}</span>
              <span className="muted" style={{ fontSize: 15 }}>{p.period}</span>
            </div>
            <Btn variant={p.highlight ? 'brand' : 'outline'} block onClick={() => go('signup')} style={{ marginTop: 22 }}>{p.cta}</Btn>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 12, marginTop: 26 }}>
              {p.feats.map(f => (
                <div key={f} className="row" style={{ gap: 10, fontSize: 14 }}>
                  <Check size={16} style={{ color: 'var(--brand)', flexShrink: 0 }} /><span style={{ color: 'var(--ink-2)' }}>{f}</span>
                </div>
              ))}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

/* ---------- FAQ ---------- */
function FAQ() {
  const [open, setOpen] = useState(0);
  return (
    <section id="faq" style={{ maxWidth: 800, margin: '0 auto', padding: '64px 28px 96px' }}>
      <SectionHead center eyebrow="Questions" title="Frequently asked" />
      <div style={{ marginTop: 44, display: 'flex', flexDirection: 'column', gap: 10 }}>
        {FAQS.map((f, i) => (
          <div key={i} className="card" style={{ overflow: 'hidden', cursor: 'pointer' }} onClick={() => setOpen(open === i ? -1 : i)}>
            <div className="row" style={{ justifyContent: 'space-between', padding: '18px 22px', gap: 16 }}>
              <span style={{ fontSize: 16, fontWeight: 600, letterSpacing: '-0.01em' }}>{f.q}</span>
              <span style={{ transform: open === i ? 'rotate(180deg)' : 'none', transition: 'transform .25s', color: 'var(--faint)', flexShrink: 0 }}><ChevD size={18} /></span>
            </div>
            {open === i && <div className="muted fade-in" style={{ padding: '0 22px 20px', fontSize: 14.5, lineHeight: 1.6, maxWidth: 640 }}>{f.a}</div>}
          </div>
        ))}
      </div>
    </section>
  );
}

/* ---------- Final CTA ---------- */
function FinalCTA({ go }) {
  return (
    <section style={{ maxWidth: 1200, margin: '0 auto', padding: '0 28px 96px' }}>
      <div style={{ position: 'relative', borderRadius: 'var(--r-xl)', overflow: 'hidden', background: 'var(--ink)', padding: 'clamp(48px,7vw,84px) 28px', textAlign: 'center' }} className="noise">
        <div style={{ position: 'absolute', inset: 0, background: 'radial-gradient(80% 120% at 50% 0%, rgba(91,84,230,.5), transparent 60%)' }} />
        <div style={{ position: 'relative' }}>
          <h2 className="display" style={{ color: '#fff', fontSize: 'clamp(30px,5vw,52px)' }}>Ready to build your first course?</h2>
          <p style={{ color: 'rgba(255,255,255,.7)', fontSize: 18, marginTop: 18, maxWidth: 480, margin: '18px auto 0' }}>Start your free trial today. Your first course is two minutes away.</p>
          <div className="row" style={{ justifyContent: 'center', gap: 12, marginTop: 32 }}>
            <Btn variant="brand" size="lg" onClick={() => go('signup')} iconR={<ArrowR />}>Start free</Btn>
            <Btn variant="ghost" size="lg" onClick={() => go('signin')} style={{ color: '#fff', background: 'rgba(255,255,255,.1)' }}>I have an account</Btn>
          </div>
        </div>
      </div>
    </section>
  );
}

/* ---------- Footer ---------- */
function Footer({ go }) {
  const cols = [
    { h: 'Product', links: ['Features', 'Pricing', 'My library', 'Changelog'] },
    { h: 'Company', links: ['About', 'Blog', 'Careers', 'Contact'] },
    { h: 'Resources', links: ['Help center', 'FAQ', 'Community', 'Status'] },
    { h: 'Legal', links: ['Privacy', 'Terms', 'Compliance', 'Security'] },
  ];
  return (
    <footer style={{ borderTop: '1px solid var(--line)', background: 'var(--surface)' }}>
      <div style={{ maxWidth: 1200, margin: '0 auto', padding: '56px 28px 28px', display: 'grid', gridTemplateColumns: '1.6fr 1fr 1fr 1fr 1fr', gap: 28 }}>
        <div>
          <Logo />
          <p className="muted" style={{ fontSize: 13.5, lineHeight: 1.6, marginTop: 14, maxWidth: 240 }}>AI-powered course builder for creators, training teams, and educators.</p>
        </div>
        {cols.map(c => (
          <div key={c.h}>
            <div style={{ fontSize: 13, fontWeight: 600, marginBottom: 14 }}>{c.h}</div>
            <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
              {c.links.map(l => <a key={l} className="muted" style={{ fontSize: 13.5, cursor: 'pointer' }} onClick={() => l==='My library'?go('library'):l==='Pricing'?go('upgrade'):null}>{l}</a>)}
            </div>
          </div>
        ))}
      </div>
      <div style={{ maxWidth: 1200, margin: '0 auto', padding: '20px 28px', borderTop: '1px solid var(--line)' }} className="row">
        <span className="muted" style={{ fontSize: 13 }}>© 2026 Coursedy. All rights reserved.</span>
        <span className="grow" />
        <span className="row" style={{ gap: 16 }}>
          <a className="muted" style={{ fontSize: 13, cursor: 'pointer' }}>Privacy</a>
          <a className="muted" style={{ fontSize: 13, cursor: 'pointer' }}>Terms</a>
        </span>
      </div>
    </footer>
  );
}

/* ---------- Landing root ---------- */
function Landing({ go }) {
  return (
    <div data-landing-scroll className="scroll" style={{ height: '100vh', overflowY: 'auto', background: 'var(--paper)' }} data-screen-label="Landing">
      <Nav go={go} />
      <Hero go={go} />
      <TrustBar />
      <HowItWorks />
      <Features />
      <Audiences />
      <Testimonials />
      <Pricing go={go} />
      <FAQ />
      <FinalCTA go={go} />
      <Footer go={go} />
    </div>
  );
}

Object.assign(window, { Landing });
