// PaintMini marketing homepage.
// Self-contained so the public landing can evolve without touching the app shell.

const HOME_ASSETS = {
  hero: '/assets/home-hero-before-after.jpg',
  workbench: '/assets/home-workbench.jpg',
  paintLibrary: '/assets/home-paint-library.jpg',
  ranger: '/assets/home-ranger-showcase.jpg',
  uploadPrimed: '/assets/home-upload-primed.jpg',
  paintTray: '/assets/home-paint-tray.jpg',
  guideSheet: '/assets/home-guide-sheet.jpg',
  crimsonTemplar: '/assets/home-crimson-templar.jpg',
  verdigrisSentinel: '/assets/home-verdigris-sentinel.jpg',
  stormSorceress: '/assets/home-storm-sorceress.jpg',
};

const NAV_LINKS = [
  ['how', 'How it works'],
  ['features', 'Features'],
  ['gallery', 'Gallery'],
  ['pricing', 'Pricing'],
  ['faq', 'FAQ'],
];

const HOME_GALLERY = [
  {
    img: HOME_ASSETS.ranger,
    name: 'Emerald Pathfinder',
    sub: 'Expert cloak, leather, bone cloth',
    tier: 'EXP',
    palette: ['#244D3A', '#A65D2E', '#D9C8A8', '#C89E5A', '#2E2A24'],
  },
  {
    img: HOME_ASSETS.crimsonTemplar,
    name: 'Crimson Templar',
    sub: 'Intermediate armor and trim',
    tier: 'INT',
    palette: ['#9A1B1F', '#080806', '#C89E5A', '#D9C8A8', '#7E7C7B'],
  },
  {
    img: HOME_ASSETS.verdigrisSentinel,
    name: 'Verdigris Sentinel',
    sub: 'Aged bronze construct',
    tier: 'ADV',
    palette: ['#4A6B5A', '#876837', '#C89E5A', '#3A3B3C', '#A89066'],
  },
];

const LAND_PRICING = [
  { name: 'Starter', per: '$1.00 per credit', credits: 5, price: '$5', note: 'Try a few colorways' },
  { name: 'Studio', per: '$0.75 per credit', credits: 20, price: '$15', note: 'Best for an army box', best: true },
  { name: 'Atelier', per: '$0.60 per credit', credits: 50, price: '$30', note: 'Batch your backlog' },
];

const LAND_FAQ = [
  {
    q: 'What does PaintMini generate?',
    a: 'A finished painted preview on your miniature, a paint list, a step-by-step painting guide, and a printable PDF for your bench.',
  },
  {
    q: 'Can it use the paints I already own?',
    a: 'Yes. Save paints to your collection, then filter schemes to your shelf so suggestions stay practical instead of becoming another shopping list.',
  },
  {
    q: 'Do I need painting experience?',
    a: 'No. Beginner plans keep techniques simple. Intermediate adds layers and edge highlights. Expert opens up advanced effects like OSL, NMM, glazing, and freehand.',
  },
  {
    q: 'How much does one render cost?',
    a: 'One credit creates one painted plate, guide, and PDF. New painters get 1 free credit, and credit packs start at $5 with no subscription.',
  },
];

function MBtn({ variant = 'primary', onClick, children, className = '', style }) {
  return (
    <button
      className={`home-btn home-btn--${variant} ${className}`}
      onClick={onClick}
      style={style}
    >
      {children}
    </button>
  );
}

function Landing({ navigate, user }) {
  const [menuOpen, setMenuOpen] = useState(false);
  const startFree = () => navigate(user ? 'editor' : 'auth', user ? {} : { mode: 'signup' });
  const signIn = () => navigate(user ? 'studio' : 'auth', user ? {} : { mode: 'signin' });
  const buy = () => navigate(user ? 'credits' : 'auth', user ? {} : { mode: 'signup' });
  const scrollTo = (id) => document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'start' });

  useEffect(() => {
    const root = document.querySelector('[data-screen-label="landing"]');
    if (!root) return;
    const els = root.querySelectorAll('[data-reveal]');
    const io = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (!entry.isIntersecting) return;
        const delay = entry.target.getAttribute('data-reveal-delay');
        if (delay) entry.target.style.transitionDelay = `${delay}ms`;
        entry.target.classList.add('is-visible');
        io.unobserve(entry.target);
      });
    }, { threshold: 0.12, rootMargin: '0px 0px -8% 0px' });
    els.forEach((el) => io.observe(el));
    return () => io.disconnect();
  }, []);

  return (
    <div data-screen-label="landing" className="home">
      <style>{`
        .home {
          --home-max: 1180px;
          background:
            radial-gradient(circle at 18% 3%, rgba(242,140,56,.12), transparent 30%),
            linear-gradient(180deg, #fffaf3 0%, var(--bg) 34%, #f6f5f0 100%);
          color: var(--ink);
          overflow-x: hidden;
        }
        .home-wrap { width: min(var(--home-max), calc(100% - 40px)); margin: 0 auto; }
        .home-eyebrow {
          font-family: var(--mono);
          font-size: 11px;
          letter-spacing: .15em;
          text-transform: uppercase;
          color: var(--brand-deep);
          font-weight: 700;
        }
        .home-display {
          font-family: var(--serif);
          font-weight: 800;
          letter-spacing: -.04em;
          line-height: .98;
          color: var(--primary-deep);
        }
        .home-copy { color: var(--ink-2); line-height: 1.7; }
        .home-btn {
          display: inline-flex;
          align-items: center;
          justify-content: center;
          min-height: 48px;
          padding: 0 22px;
          border-radius: 8px;
          font-size: 14px;
          font-weight: 800;
          letter-spacing: 0;
          transition: transform .18s ease, box-shadow .18s ease, background .18s ease, border-color .18s ease;
          white-space: nowrap;
        }
        .home-btn:hover { transform: translateY(-2px); }
        .home-btn--primary { background: var(--brand); color: #242424; box-shadow: 0 18px 34px -24px rgba(217,119,42,.95); }
        .home-btn--primary:hover { background: var(--brand-deep); box-shadow: 0 22px 38px -24px rgba(217,119,42,.95); }
        .home-btn--ghost { background: rgba(255,255,255,.76); color: var(--primary-deep); border: 1px solid rgba(36,77,58,.18); }
        .home-btn--ghost:hover { border-color: rgba(36,77,58,.34); background: #fff; }
        .home [data-reveal] { opacity: 0; transform: translateY(22px); transition: opacity .7s ease, transform .7s cubic-bezier(.2,.7,.2,1); }
        .home [data-reveal].is-visible { opacity: 1; transform: none; }
        .home-nav {
          position: sticky;
          top: 0;
          z-index: 50;
          background: rgba(255,250,243,.84);
          border-bottom: 1px solid rgba(36,77,58,.12);
          backdrop-filter: blur(18px);
          -webkit-backdrop-filter: blur(18px);
        }
        .home-nav__inner { display: flex; align-items: center; gap: 28px; height: 72px; }
        .home-nav__links { display: flex; align-items: center; gap: 24px; color: rgba(27,58,44,.72); font-size: 13px; font-weight: 700; }
        .home-nav__links a:hover { color: var(--primary-deep); }
        .home-nav__toggle { display: none; width: 42px; height: 42px; border-radius: 8px; color: var(--primary-deep); background: rgba(36,77,58,.08); place-items: center; }
        .home-hero { display: grid; grid-template-columns: minmax(0, .86fr) minmax(430px, 1.14fr); gap: clamp(32px, 6vw, 74px); align-items: center; padding: clamp(46px, 7vw, 84px) 0 58px; }
        .home-hero h1 { font-size: clamp(52px, 7.5vw, 96px); margin: 16px 0 22px; }
        .home-hero p { max-width: 570px; font-size: 18px; margin: 0 0 30px; }
        .home-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
        .home-proof { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 28px; color: var(--ink-3); font-size: 13px; }
        .home-proof strong { color: var(--ink); }
        .home-hero-card {
          position: relative;
          border-radius: 14px;
          padding: 14px;
          background: rgba(255,255,255,.82);
          border: 1px solid rgba(36,77,58,.14);
          box-shadow: 0 40px 90px -48px rgba(36,77,58,.62);
        }
        .home-hero-frame { position: relative; overflow: hidden; border-radius: 10px; aspect-ratio: 16 / 10; background: var(--surface-2); }
        .home-hero-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
        .home-hero-badge {
          position: absolute;
          left: 18px;
          bottom: 18px;
          display: inline-flex;
          align-items: center;
          gap: 10px;
          padding: 10px 14px;
          border-radius: 999px;
          background: rgba(27,58,44,.92);
          color: var(--sidebar-ink);
          font-size: 12px;
          box-shadow: 0 20px 40px -22px rgba(0,0,0,.7);
        }
        .home-hero-badge span { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); }
        .home-panel {
          background: rgba(255,255,255,.72);
          border-block: 1px solid rgba(36,77,58,.1);
          box-shadow: inset 0 1px 0 rgba(255,255,255,.78);
        }
        .home-mood { display: grid; grid-template-columns: 1fr 1.08fr; gap: 28px; padding: 34px 0; }
        .home-mood__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
        .home-img-card { position: relative; overflow: hidden; min-height: 210px; border-radius: 8px; background: var(--surface-2); border: 1px solid rgba(36,77,58,.12); }
        .home-img-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
        .home-mood__copy {
          padding: clamp(28px, 5vw, 54px);
          border-radius: 12px;
          background: #fff;
          border: 1px solid rgba(36,77,58,.12);
          display: flex;
          flex-direction: column;
          justify-content: center;
        }
        .home-mood__copy h2 { font-size: clamp(34px, 4.4vw, 58px); margin: 12px 0 14px; }
        .home-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-top: 34px; }
        .home-step, .home-price, .home-faq, .home-gallery-card {
          background: #fff;
          border: 1px solid rgba(36,77,58,.12);
          border-radius: 8px;
          box-shadow: 0 22px 48px -36px rgba(36,77,58,.55);
        }
        .home-step { padding: 24px; }
        .home-step__icon {
          width: 48px;
          height: 48px;
          display: grid;
          place-items: center;
          color: var(--brand-deep);
          background: var(--brand-soft);
          border-radius: 8px;
          margin-bottom: 24px;
        }
        .home-step h3, .home-feature h3 { font-family: var(--serif); font-size: 26px; line-height: 1.1; margin: 0 0 10px; color: var(--primary-deep); }
        .home-section { padding: clamp(70px, 9vw, 104px) 0; }
        .home-section__head { max-width: 760px; margin-bottom: 34px; }
        .home-section h2 { font-size: clamp(36px, 5vw, 66px); margin: 10px 0 0; }
        .home-feature { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(28px, 6vw, 70px); align-items: center; }
        .home-feature + .home-feature { margin-top: 72px; }
        .home-feature__copy { max-width: 560px; }
        .home-feature__copy .home-eyebrow { display: inline-block; margin-bottom: 14px; }
        .home-feature__copy h2 { margin: 0 0 22px; }
        .home-feature__copy p { margin: 0; max-width: 500px; font-size: 16px; }
        .home-feature__image { overflow: hidden; border-radius: 10px; border: 1px solid rgba(36,77,58,.12); background: #fff; box-shadow: 0 32px 70px -44px rgba(36,77,58,.7); }
        .home-feature__image img { display: block; width: 100%; height: 100%; object-fit: cover; aspect-ratio: 4 / 3; }
        .home-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 28px; }
        .home-chip { padding: 8px 12px; border-radius: 999px; background: var(--primary-soft); color: var(--primary-deep); font-size: 12.5px; font-weight: 800; }
        .home-gallery { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
        .home-gallery-card { overflow: hidden; }
        .home-gallery-card__img { height: 250px; background: var(--surface-2); }
        .home-gallery-card__img img { width: 100%; height: 100%; object-fit: cover; display: block; }
        .home-gallery-card__body { padding: 16px; }
        .home-swatches { display: flex; gap: 2px; height: 7px; overflow: hidden; border-radius: 999px; margin-top: 14px; }
        .home-swatches span { flex: 1; }
        .home-pricing { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: stretch; }
        .home-price { padding: 26px; position: relative; }
        .home-price.is-best { background: var(--primary-deep); color: var(--sidebar-ink); border-color: transparent; transform: translateY(-10px); }
        .home-price__tag { position: absolute; top: -12px; left: 24px; padding: 5px 10px; border-radius: 999px; background: var(--brand); color: #242424; font-family: var(--mono); font-size: 9px; font-weight: 800; letter-spacing: .1em; }
        .home-price h3 { font-family: var(--serif); font-size: 28px; margin: 0 0 4px; }
        .home-price__credits { display: flex; align-items: baseline; gap: 7px; margin: 22px 0 4px; }
        .home-price__credits strong { font-family: var(--serif); font-size: 48px; line-height: 1; }
        .home-faq { overflow: hidden; }
        .home-faq button { width: 100%; display: flex; justify-content: space-between; gap: 18px; padding: 18px 20px; text-align: left; }
        .home-faq__answer { padding: 0 20px 18px; }
        .home-cta {
          text-align: center;
          padding: clamp(46px, 7vw, 78px) 28px;
          border-radius: 14px;
          background:
            linear-gradient(135deg, rgba(36,77,58,.98), rgba(27,58,44,.98)),
            var(--primary-deep);
          color: var(--sidebar-ink);
          overflow: hidden;
          position: relative;
        }
        .home-cta h2 { font-size: clamp(36px, 6vw, 74px); margin: 10px auto 16px; max-width: 780px; }
        .home-footer { background: var(--primary-deep); color: var(--sidebar-ink-2); }
        .home-footer__inner { display: grid; grid-template-columns: 1.4fr repeat(3, 1fr); gap: 28px; padding: 46px 0; }
        .home-footer a:hover { color: var(--sidebar-ink); }
        @media (prefers-reduced-motion: reduce) {
          .home [data-reveal] { opacity: 1 !important; transform: none !important; transition: none !important; }
          .home-btn:hover { transform: none; }
        }
        @media (max-width: 920px) {
          .home-nav__links, .home-nav__signin { display: none; }
          .home-nav__toggle { display: grid; }
          .home-hero, .home-mood, .home-feature { grid-template-columns: 1fr; }
          .home-hero { padding-top: 42px; }
          .home-steps, .home-gallery, .home-pricing { grid-template-columns: 1fr; }
          .home-price.is-best { transform: none; }
          .home-footer__inner { grid-template-columns: 1fr 1fr; }
        }
        @media (max-width: 620px) {
          .home-wrap { width: min(100% - 28px, var(--home-max)); }
          .home-nav__inner { height: 66px; gap: 12px; }
          .home-hero h1 { font-size: clamp(44px, 15vw, 66px); }
          .home-hero p { font-size: 16px; }
          .home-mood__grid { grid-template-columns: 1fr; }
          .home-footer__inner { grid-template-columns: 1fr; }
        }
      `}</style>

      <div style={{ background: 'var(--primary-deep)', color: 'var(--sidebar-ink)', textAlign: 'center', padding: '10px 14px', fontSize: 13, fontWeight: 800 }}>
        New painters get 1 free credit. Plan your first scheme without a card.
      </div>

      <nav className="home-nav">
        <div className="home-wrap home-nav__inner">
          <a href="#top" onClick={(e) => { e.preventDefault(); scrollTo('top'); }} style={{ display: 'flex', alignItems: 'center' }}>
            <img className="pm-logo" src="/assets/logo-new.png" alt="PaintMini" style={{ height: 31 }} />
          </a>
          <div className="home-nav__links">
            {NAV_LINKS.map(([id, label]) => (
              <a key={id} href={`#${id}`} onClick={(e) => { e.preventDefault(); scrollTo(id); }}>{label}</a>
            ))}
          </div>
          <div style={{ flex: 1 }} />
          <a className="home-nav__signin" href="#" onClick={(e) => { e.preventDefault(); signIn(); }} style={{ color: 'var(--primary-deep)', fontSize: 13, fontWeight: 800 }}>
            {user ? 'Your studio' : 'Sign in'}
          </a>
          <MBtn onClick={startFree} style={{ minHeight: 42, paddingInline: 18 }}>{user ? 'New design' : 'Start free'}</MBtn>
          <button className="home-nav__toggle" aria-label="Menu" onClick={() => setMenuOpen((open) => !open)}>
            <svg width="20" height="20" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round">
              {menuOpen ? <path d="M5 5l10 10M15 5L5 15" /> : <><path d="M3 6h14" /><path d="M3 10h14" /><path d="M3 14h14" /></>}
            </svg>
          </button>
        </div>
      </nav>

      {menuOpen && (
        <div className="pm-drawer-overlay" onClick={() => setMenuOpen(false)}>
          <aside className="pm-drawer" onClick={(e) => e.stopPropagation()}>
            <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 18 }}>
              <img className="pm-logo pm-logo--dark" src="/assets/logo-new.png" alt="PaintMini" style={{ height: 26 }} />
              <button aria-label="Close menu" onClick={() => setMenuOpen(false)} style={{ color: 'var(--sidebar-ink)', width: 34, height: 34, borderRadius: 8, display: 'grid', placeItems: 'center' }}>
                <svg width="18" height="18" viewBox="0 0 18 18" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round"><path d="M4 4l10 10M14 4L4 14"/></svg>
              </button>
            </div>
            <nav style={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
              {NAV_LINKS.map(([id, label]) => (
                <a key={id} href={`#${id}`} onClick={(e) => { e.preventDefault(); setMenuOpen(false); scrollTo(id); }}
                   style={{ color: 'var(--sidebar-ink-2)', fontSize: 15.5, padding: '13px 8px', borderBottom: '1px solid rgba(246,244,239,.06)' }}>{label}</a>
              ))}
            </nav>
            <div style={{ flex: 1 }} />
            <MBtn onClick={() => { setMenuOpen(false); startFree(); }} style={{ width: '100%' }}>
              {user ? 'New design' : 'Start free'}
            </MBtn>
          </aside>
        </div>
      )}

      <header id="top" className="home-wrap home-hero">
        <div data-reveal>
          <span className="home-eyebrow">AI paint planning for tabletop miniatures</span>
          <h1 className="home-display">Visualize. Plan. Paint.</h1>
          <p className="home-copy">
            Upload your miniature, choose the paints on your shelf, and get finished schemes rendered on your exact sculpt with a practical step-by-step guide.
          </p>
          <div className="home-actions">
            <MBtn onClick={startFree}>Upload your miniature</MBtn>
            <MBtn variant="ghost" onClick={() => scrollTo('how')}>See how it works</MBtn>
          </div>
          <div className="home-proof">
            <span><strong>1 free credit</strong> for new painters</span>
            <span>One credit per render</span>
            <span>No subscription</span>
          </div>
        </div>
        <div className="home-hero-card" data-reveal data-reveal-delay="80">
          <div className="home-hero-frame">
            <img src={HOME_ASSETS.hero} alt="A miniature split between grey primer and a finished green and orange paint scheme" />
            <div className="home-hero-badge"><span /> Scheme ready in under a minute</div>
          </div>
        </div>
      </header>

      <section className="home-panel">
        <div className="home-wrap home-mood">
          <div className="home-mood__grid" data-reveal>
            <div className="home-img-card"><img src={HOME_ASSETS.workbench} alt="Brushes and miniature paints on a painter's workbench" /></div>
            <div className="home-img-card"><img src={HOME_ASSETS.uploadPrimed} alt="Unpainted primed miniature ready for a paint plan" /></div>
            <div className="home-img-card"><img src={HOME_ASSETS.paintLibrary} alt="Organized miniature paint bottles and color swatches" /></div>
            <div className="home-img-card"><img src={HOME_ASSETS.stormSorceress} alt="Blue painted storm sorceress miniature from a PaintMini render" /></div>
          </div>
          <div className="home-mood__copy" data-reveal data-reveal-delay="100">
            <span className="home-eyebrow">Built for the workbench</span>
            <h2 className="home-display">Bring your miniatures to life before opening a pot.</h2>
            <p className="home-copy" style={{ margin: 0 }}>
              PaintMini turns planning into part of the hobby: compare palettes, match your owned paints, and walk into the session with a clear order of operations.
            </p>
          </div>
        </div>
      </section>

      <section id="how" className="home-wrap home-section">
        <div className="home-section__head" data-reveal>
          <span className="home-eyebrow">How it works</span>
          <h2 className="home-display">Three steps from primer to plan.</h2>
        </div>
        <div className="home-steps">
          {[
            ['Upload', 'Add a clear photo of your primed or unpainted miniature. PaintMini reads the pose, surfaces, armor, cloth, and base.', 'M4 13.5V7a4 4 0 0 1 8 0v6.5M2 12l6-6 6 6M3 14h10'],
            ['Select paints', 'Choose paints from your saved collection or browse common ranges. Suggestions stay grounded in what you actually own.', 'M8 2a6 6 0 1 0 0 12c1.1 0 1.1-1.4 1.8-2 .6-.5 1.8-.1 2.6-.9A5.8 5.8 0 0 0 8 2ZM5.4 6.4h.1M8 4.8h.1M10.6 6.2h.1M11 9h.1'],
            ['Get your guide', 'Render finished schemes, then follow a bench-ready recipe with colors, order, techniques, and a printable PDF.', 'M4 2h5l3 3v9H4V2Zm5 0v3h3M6 8h4M6 10.5h4M6 13h2'],
          ].map(([title, body, path], i) => (
            <div className="home-step" data-reveal data-reveal-delay={i * 90} key={title}>
              <span className="home-step__icon">
                <svg width="24" height="24" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.4" strokeLinecap="round" strokeLinejoin="round"><path d={path} /></svg>
              </span>
              <h3>{i + 1}. {title}</h3>
              <p className="home-copy" style={{ margin: 0, fontSize: 14 }}>{body}</p>
            </div>
          ))}
        </div>
      </section>

      <section id="features" className="home-wrap home-section" style={{ paddingTop: 20 }}>
        <div className="home-feature" data-reveal>
          <div className="home-feature__copy">
            <span className="home-eyebrow">Paints you own</span>
            <h2 className="home-display">Stop planning around colors you have to buy.</h2>
            <p className="home-copy">
              Save your shelf once, build temporary sets for a warband or army, and ask PaintMini to stay inside those colors. Every result includes the closest paint matches and sensible substitutes.
            </p>
            <div className="home-chip-row">
              {['My shelf: 24', 'Warband set: 12', 'Airbrush colors: 8', 'Beginner safe'].map((chip) => <span className="home-chip" key={chip}>{chip}</span>)}
            </div>
          </div>
          <div className="home-feature__image"><img src={HOME_ASSETS.paintTray} alt="Owned miniature paints organized in a wooden drawer tray" /></div>
        </div>
        <div className="home-feature" data-reveal>
          <div className="home-feature__image"><img src={HOME_ASSETS.guideSheet} alt="Printed miniature painting guide sheet on a clean workbench" /></div>
          <div className="home-feature__copy">
            <span className="home-eyebrow">Skill-aware recipes</span>
            <h2 className="home-display">A showcase scheme is useless if it skips the path.</h2>
            <p className="home-copy">
              Choose Beginner, Intermediate, or Expert and the guide adapts the techniques: basecoats and wash, layered highlights, glazing, OSL, NMM, weathering, and freehand only when you ask for it.
            </p>
            <div className="home-chip-row">
              {['Basecoat', 'Wash', 'Layer', 'Edge highlight', 'OSL', 'NMM'].map((chip) => <span className="home-chip" key={chip}>{chip}</span>)}
            </div>
          </div>
        </div>
      </section>

      <section id="gallery" className="home-wrap home-section">
        <div className="home-section__head" data-reveal>
          <span className="home-eyebrow">Gallery</span>
          <h2 className="home-display">Different models. Different recipes. No recycled hero art.</h2>
        </div>
        <div className="home-gallery">
          {HOME_GALLERY.map((item, i) => (
            <article className="home-gallery-card" data-reveal data-reveal-delay={i * 80} key={item.name}>
              <div className="home-gallery-card__img"><img src={item.img} alt={item.name} /></div>
              <div className="home-gallery-card__body">
                <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }}>
                  <h3 style={{ fontFamily: 'var(--serif)', fontSize: 22, margin: 0, color: 'var(--primary-deep)' }}>{item.name}</h3>
                  <span className="mono" style={{ fontSize: 10, color: 'var(--ink-3)' }}>{item.tier}</span>
                </div>
                <p className="home-copy" style={{ fontSize: 13, margin: '4px 0 0' }}>{item.sub}</p>
                <div className="home-swatches">
                  {item.palette.map((color) => <span key={color} style={{ background: color }} />)}
                </div>
              </div>
            </article>
          ))}
        </div>
      </section>

      <section id="pricing" className="home-panel">
        <div className="home-wrap home-section">
          <div className="home-section__head" style={{ textAlign: 'center', marginInline: 'auto' }} data-reveal>
            <span className="home-eyebrow">Pricing</span>
            <h2 className="home-display">Pay per render. No subscription.</h2>
            <p className="home-copy" style={{ margin: '14px auto 0', maxWidth: 620 }}>
              One credit creates one painted preview, guide, and PDF. Buy credits when you need them.
            </p>
          </div>
          <div className="home-pricing">
            {LAND_PRICING.map((plan, i) => (
              <div className={`home-price ${plan.best ? 'is-best' : ''}`} data-reveal data-reveal-delay={i * 80} key={plan.name}>
                {plan.best && <span className="home-price__tag">BEST VALUE</span>}
                <h3>{plan.name}</h3>
                <p style={{ color: plan.best ? 'var(--sidebar-ink-2)' : 'var(--ink-3)', margin: 0, fontSize: 13 }}>{plan.per}</p>
                <div className="home-price__credits"><strong>{plan.credits}</strong><span>credits</span></div>
                <p style={{ color: plan.best ? 'var(--sidebar-ink-2)' : 'var(--ink-2)', margin: '0 0 22px', minHeight: 24 }}>{plan.note}</p>
                <div style={{ display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12, marginBottom: 18 }}>
                  <span style={{ fontFamily: 'var(--serif)', fontSize: 32, fontWeight: 800 }}>{plan.price}</span>
                  <span style={{ fontSize: 12, color: plan.best ? 'var(--sidebar-ink-2)' : 'var(--ink-3)' }}>one-time</span>
                </div>
                <MBtn variant={plan.best ? 'primary' : 'ghost'} onClick={buy} style={{ width: '100%' }}>Buy {plan.name}</MBtn>
              </div>
            ))}
          </div>
        </div>
      </section>

      <section id="faq" className="home-wrap home-section">
        <div className="home-section__head" style={{ textAlign: 'center', marginInline: 'auto' }} data-reveal>
          <span className="home-eyebrow">FAQ</span>
          <h2 className="home-display">Before your first render.</h2>
        </div>
        <div style={{ maxWidth: 780, margin: '0 auto', display: 'grid', gap: 12 }}>
          {LAND_FAQ.map((item, i) => <FaqItem key={item.q} q={item.q} a={item.a} defaultOpen={i === 0} />)}
        </div>
      </section>

      <section className="home-wrap" style={{ padding: '0 0 84px' }}>
        <div className="home-cta" data-reveal>
          <span className="home-eyebrow" style={{ color: 'var(--brand-bright)' }}>Ready when your primer is dry</span>
          <h2 className="home-display" style={{ color: 'var(--sidebar-ink)' }}>Turn your next miniature into a clear paint plan.</h2>
          <p style={{ color: 'var(--sidebar-ink-2)', maxWidth: 560, margin: '0 auto 26px', fontSize: 16, lineHeight: 1.7 }}>
            Start with a free credit, render a scheme on your model, and bring a better plan to the bench.
          </p>
          <div className="home-actions" style={{ justifyContent: 'center' }}>
            <MBtn onClick={startFree}>Start free</MBtn>
            <MBtn variant="ghost" onClick={signIn}>Sign in</MBtn>
          </div>
        </div>
      </section>

      <footer className="home-footer">
        <div className="home-wrap home-footer__inner">
          <div>
            <img className="pm-logo pm-logo--dark" src="/assets/logo-new.png" alt="PaintMini" style={{ height: 27, marginBottom: 14 }} />
            <p style={{ maxWidth: 320, margin: 0, fontSize: 13, lineHeight: 1.7 }}>
              AI paint schemes, owned-paint filtering, and printable miniature painting guides for the tabletop workbench.
            </p>
          </div>
          {[
            ['Product', [['how', 'How it works'], ['features', 'Features'], ['gallery', 'Gallery']]],
            ['Plans', [['pricing', 'Pricing'], ['faq', 'FAQ'], ['top', 'Start free']]],
            ['Studio', [['top', 'Paint library'], ['top', 'PDF guides'], ['top', 'Share links']]],
          ].map(([title, links]) => (
            <div key={title} style={{ display: 'grid', gap: 10, alignContent: 'start' }}>
              <h5 className="mono" style={{ color: 'var(--sidebar-ink-3)', fontSize: 10, letterSpacing: '.14em', textTransform: 'uppercase', margin: 0 }}>{title}</h5>
              {links.map(([id, label]) => (
                <a key={label} href={`#${id}`} onClick={(e) => { e.preventDefault(); scrollTo(id); }} style={{ fontSize: 13 }}>{label}</a>
              ))}
            </div>
          ))}
        </div>
        <div className="home-wrap" style={{ padding: '17px 0', borderTop: '1px solid var(--sidebar-line)', display: 'flex', justifyContent: 'space-between', flexWrap: 'wrap', gap: 12 }}>
          <span className="mono" style={{ fontSize: 10, letterSpacing: '.08em', color: 'var(--sidebar-ink-3)' }}>© 2026 PAINTMINI</span>
          <span className="mono" style={{ fontSize: 10, letterSpacing: '.08em', color: 'var(--sidebar-ink-3)' }}>MADE FOR THE WORKBENCH</span>
        </div>
      </footer>
    </div>
  );
}

function FaqItem({ q, a, defaultOpen }) {
  const [open, setOpen] = useState(!!defaultOpen);
  return (
    <div className="home-faq" data-reveal>
      <button onClick={() => setOpen((value) => !value)} aria-expanded={open}>
        <span style={{ fontFamily: 'var(--serif)', fontSize: 20, fontWeight: 800, color: 'var(--primary-deep)' }}>{q}</span>
        <span style={{ flex: 'none', width: 24, height: 24, borderRadius: '50%', display: 'grid', placeItems: 'center', color: 'var(--brand-deep)', border: '1px solid rgba(36,77,58,.18)' }}>
          {open ? '-' : '+'}
        </span>
      </button>
      {open && <div className="home-faq__answer home-copy">{a}</div>}
    </div>
  );
}

Object.assign(window, { Landing });
