// Marketing sections — mono-first, paper-toned, declarative voice.

const { useState: useStateS } = React;

function useMobile(bp = 768) {
  const [m, setM] = React.useState(typeof window !== 'undefined' && window.innerWidth <= bp);
  React.useEffect(() => {
    const h = () => setM(window.innerWidth <= bp);
    window.addEventListener('resize', h);
    return () => window.removeEventListener('resize', h);
  }, [bp]);
  return m;
}

function Eyebrow({ children, n }) {
  return (
    <div style={{
      display: "flex", alignItems: "center", gap: 10,
      fontFamily: "var(--font-mono)", fontSize: 11.5, fontWeight: 600,
      letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--ink-2)",
      marginBottom: 18,
    }}>
      {n && <span style={{
        display: "inline-flex", alignItems: "center", justifyContent: "center",
        width: 22, height: 22, borderRadius: 999,
        border: "1px solid var(--border)", color: "var(--ink-2)",
        fontSize: 11, letterSpacing: 0,
      }}>{n}</span>}
      <span>{children}</span>
    </div>
  );
}

function SectionTitle({ children, kicker, sub, align = "left" }) {
  return (
    <div style={{ textAlign: align, maxWidth: align === "center" ? 720 : "none", margin: align === "center" ? "0 auto" : 0 }}>
      {kicker && <Eyebrow>{kicker}</Eyebrow>}
      <h2 style={{
        fontFamily: "var(--font-mono)", fontWeight: 700,
        fontSize: "clamp(24px, 3.6vw, 42px)", lineHeight: 1.15,
        letterSpacing: "-0.02em", margin: 0, color: "var(--ink-1)", textWrap: "balance",
      }}>{children}</h2>
      {sub && <p style={{
        marginTop: 14, marginBottom: 0,
        fontFamily: "var(--font-mono)", fontSize: 15, lineHeight: 1.7,
        color: "var(--ink-2)", maxWidth: "62ch", textWrap: "pretty",
        marginLeft: align === "center" ? "auto" : 0,
        marginRight: align === "center" ? "auto" : 0,
      }}>{sub}</p>}
    </div>
  );
}

function PrimaryBtn({ children, href, ghost, full }) {
  return (
    <a href={href || "#"} target={href && href.startsWith("http") ? "_blank" : undefined} rel="noreferrer" style={{
      display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 8,
      fontFamily: "var(--font-mono)", fontSize: 13.5, fontWeight: 600,
      padding: "10px 18px", borderRadius: 999,
      background: ghost ? "transparent" : "var(--accent)",
      color: ghost ? "var(--ink-1)" : "#fff",
      border: ghost ? "1px solid var(--border-strong)" : "1px solid var(--accent)",
      textDecoration: "none", cursor: "pointer",
      width: full ? "100%" : undefined,
    }}>
      {children}
    </a>
  );
}

function ContainerCol({ children, style }) {
  const isMobile = useMobile();
  return (
    <div style={{ maxWidth: 1160, margin: "0 auto", padding: isMobile ? "0 20px" : "0 32px", ...style }}>
      {children}
    </div>
  );
}

/* ── Nav ── */
function TopNav({ dark, onToggleTheme }) {
  const isMobile = useMobile();
  const [menuOpen, setMenuOpen] = useStateS(false);

  const NAV_LINKS = [["How it works","#how"],["Features","#features"],["Pricing","#pricing"],["FAQ","#faq"]];

  const SunIcon = () => (
    <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <circle cx="12" cy="12" r="4"/>
      <line x1="12" y1="2" x2="12" y2="5"/>
      <line x1="12" y1="19" x2="12" y2="22"/>
      <line x1="4.22" y1="4.22" x2="6.34" y2="6.34"/>
      <line x1="17.66" y1="17.66" x2="19.78" y2="19.78"/>
      <line x1="2" y1="12" x2="5" y2="12"/>
      <line x1="19" y1="12" x2="22" y2="12"/>
      <line x1="4.22" y1="19.78" x2="6.34" y2="17.66"/>
      <line x1="17.66" y1="6.34" x2="19.78" y2="4.22"/>
    </svg>
  );
  const MoonIcon = () => (
    <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
    </svg>
  );

  const ThemePill = () => (
    <button
      onClick={onToggleTheme}
      aria-label="Toggle theme"
      style={{
        background: "var(--surface-3)",
        border: "1px solid var(--border)",
        borderRadius: 999,
        padding: 3,
        display: "inline-flex",
        alignItems: "center",
        gap: 2,
        cursor: "pointer",
        flexShrink: 0,
        boxShadow: "inset 0 1px 3px rgba(0,0,0,0.07)",
      }}
    >
      {/* Sun slot */}
      <span style={{
        width: 30, height: 30, borderRadius: 999,
        display: "flex", alignItems: "center", justifyContent: "center",
        background: !dark ? "var(--surface)" : "transparent",
        boxShadow: !dark ? "0 1px 4px rgba(0,0,0,0.13), 0 0 0 0.5px rgba(0,0,0,0.06)" : "none",
        color: !dark ? "var(--ink-1)" : "var(--ink-3)",
        transition: "background 180ms ease, box-shadow 180ms ease, color 180ms ease",
      }}>
        <SunIcon />
      </span>
      {/* Moon slot */}
      <span style={{
        width: 30, height: 30, borderRadius: 999,
        display: "flex", alignItems: "center", justifyContent: "center",
        background: dark ? "var(--surface)" : "transparent",
        boxShadow: dark ? "0 1px 4px rgba(0,0,0,0.13), 0 0 0 0.5px rgba(0,0,0,0.06)" : "none",
        color: dark ? "var(--ink-1)" : "var(--ink-3)",
        transition: "background 180ms ease, box-shadow 180ms ease, color 180ms ease",
      }}>
        <MoonIcon />
      </span>
    </button>
  );

  return (
    <nav className="melo-nav" style={{
      position: "sticky", top: 0, zIndex: 50,
      background: "color-mix(in oklab, var(--paper) 85%, transparent)",
      backdropFilter: "saturate(140%) blur(10px)",
      borderBottom: "1px solid var(--border-faint)",
    }}>
      <div style={{ maxWidth: 1160, margin: "0 auto", padding: isMobile ? "12px 20px" : "14px 32px", display: "flex", alignItems: "center", gap: 16 }}>
        {/* Logo */}
        <a href="#top" style={{ display: "flex", alignItems: "center", gap: 8, textDecoration: "none", color: "var(--ink-1)", flexShrink: 0 }}>
          <span style={{
            width: 26, height: 26, borderRadius: 7,
            background: "var(--ink-1)", color: "var(--paper)",
            display: "inline-flex", alignItems: "center", justifyContent: "center",
            fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 14,
          }}>m</span>
          <span style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 15, letterSpacing: "-0.01em" }}>melo</span>
          <span className="ed-tag ed-tag--butter" style={{ marginLeft: 4, fontSize: 10 }}>beta</span>
        </a>

        <div style={{ flex: 1 }} />

        {/* Desktop: nav links */}
        {!isMobile && (
          <div style={{ display: "flex", alignItems: "center", gap: 4, fontFamily: "var(--font-mono)", fontSize: 13 }}>
            {NAV_LINKS.map(([label, href]) => (
              <a key={label} href={href} style={{ padding: "6px 12px", borderRadius: 999, color: "var(--ink-2)", textDecoration: "none" }}>{label}</a>
            ))}
          </div>
        )}

        {/* Desktop: theme pill + CTA */}
        {!isMobile && (
          <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
            <ThemePill />
            <PrimaryBtn href="https://wa.me/message/H3SMFZFN7RHRO1">Try for free →</PrimaryBtn>
          </div>
        )}

        {/* Mobile: theme pill + hamburger */}
        {isMobile && (
          <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
            <ThemePill />
            <button
              onClick={() => setMenuOpen(o => !o)}
              aria-label="Toggle menu"
              style={{
                width: 36, height: 36, borderRadius: 8,
                border: "1px solid var(--border)", background: "var(--surface)",
                display: "flex", alignItems: "center", justifyContent: "center",
                cursor: "pointer", color: "var(--ink-1)", flexShrink: 0,
              }}
            >
              {menuOpen
                ? <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="2" y1="2" x2="14" y2="14"/><line x1="14" y1="2" x2="2" y2="14"/></svg>
                : <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="2" y1="5" x2="14" y2="5"/><line x1="2" y1="9" x2="14" y2="9"/><line x1="2" y1="13" x2="14" y2="13"/></svg>
              }
            </button>
          </div>
        )}
      </div>

      {/* Mobile dropdown */}
      {isMobile && menuOpen && (
        <div style={{
          borderTop: "1px solid var(--border-faint)",
          background: "var(--surface)",
          padding: "12px 20px 20px",
          display: "flex", flexDirection: "column", gap: 4,
        }}>
          {NAV_LINKS.map(([label, href]) => (
            <a key={label} href={href} onClick={() => setMenuOpen(false)} style={{
              padding: "12px 8px", fontFamily: "var(--font-mono)", fontSize: 15, fontWeight: 500,
              color: "var(--ink-1)", textDecoration: "none", borderBottom: "1px solid var(--border-faint)",
            }}>{label}</a>
          ))}
          <div style={{ marginTop: 12 }}>
            <PrimaryBtn href="https://wa.me/message/H3SMFZFN7RHRO1" full>Try for free →</PrimaryBtn>
          </div>
        </div>
      )}
    </nav>
  );
}

/* ── Hero ── */
function HeroSection({ replayKey, onReplay }) {
  const isMobile = useMobile();
  const MARQUEE_ITEMS = ["coffee $4.50","rent 1850 — paid","salary +5000","split dinner $86 with mike, ana","groceries 64.20","uber to airport 45","how much did i spend on food?","monthly summary please","🎤 coffee 4, lunch 12, gym 30","spotify subscription","₹1,200 for chai","€38 books","🎤 gasolina 800 pesos, mercado 1200","set budget dining 300","remind ana to pay me back","🎤 petrol 50, groceries 40, parking 8"];
  const doubled = [...MARQUEE_ITEMS, ...MARQUEE_ITEMS];

  return (
    <section id="top" className="melo-section" style={{ padding: isMobile ? "48px 0 64px" : "72px 0 96px", position: "relative" }}>
      <ContainerCol>
        <div style={{
          display: "grid",
          gridTemplateColumns: isMobile ? "1fr" : "minmax(0, 1.05fr) minmax(0, 0.95fr)",
          gap: isMobile ? 40 : 64, alignItems: "center",
        }}>
          {/* Copy */}
          <div>
            <Eyebrow>An AI bookkeeper for WhatsApp</Eyebrow>
            <h1 style={{
              fontFamily: "var(--font-mono)", fontWeight: 700,
              fontSize: isMobile ? "clamp(36px, 10vw, 52px)" : "clamp(40px, 5.5vw, 68px)",
              lineHeight: 1.02, letterSpacing: "-0.035em",
              margin: 0, color: "var(--ink-1)", textWrap: "balance",
            }}>
              Track expenses<br />
              inside <em style={{ fontStyle: "italic", fontWeight: 700, color: "var(--accent)" }}>WhatsApp</em>.
            </h1>
            <p style={{
              marginTop: 24, marginBottom: 0,
              fontFamily: "var(--font-mono)", fontSize: isMobile ? 15 : 16.5, lineHeight: 1.65,
              color: "var(--ink-2)", maxWidth: "52ch", textWrap: "pretty",
            }}>
              No new app. No spreadsheets. Message Melo the way you'd message a friend — type <em>"coffee with sarah $12"</em> or just send a voice note rattling off your day — and the AI handles the bookkeeping. Categories, totals, summaries, splits. All in the chat you're already in.
            </p>
            <div style={{ display: "flex", flexWrap: "wrap", gap: 12, marginTop: 32 }}>
              <PrimaryBtn href="https://wa.me/message/H3SMFZFN7RHRO1">Start on WhatsApp <span style={{ marginLeft: 2 }}>↗</span></PrimaryBtn>
              <PrimaryBtn href="#demo" ghost>View demo</PrimaryBtn>
            </div>
            <div style={{
              marginTop: 40, display: "flex", flexWrap: "wrap", gap: 10,
              fontFamily: "var(--font-mono)", fontSize: 12.5, color: "var(--ink-2)", alignItems: "center",
            }}>
              <span className="ed-tag ed-tag--sage">simple</span>
              <span className="ed-tag ed-tag--sky">private</span>
              <span className="ed-tag ed-tag--butter">end-to-end encrypted</span>
              <span style={{ color: "var(--ink-3)", marginLeft: 4 }}>— free for personal use</span>
            </div>
          </div>

          {/* Chat */}
          <div style={{ position: "relative" }}>
            <ChatHero replayKey={replayKey} isMobile={isMobile} />
            <button onClick={onReplay} style={{
              position: "absolute", top: -2, right: 0,
              fontFamily: "var(--font-mono)", fontSize: 11,
              padding: "6px 12px", borderRadius: 999,
              border: "1px solid var(--border)", background: "var(--surface)",
              color: "var(--ink-2)", cursor: "pointer", letterSpacing: "0.06em",
            }}>↻ replay</button>
          </div>
        </div>
      </ContainerCol>

      {/* Marquee */}
      <div style={{ marginTop: isMobile ? 48 : 80, overflow: "hidden", borderTop: "1px solid var(--border-faint)", borderBottom: "1px solid var(--border-faint)", padding: "16px 0" }}>
        <div style={{ display: "flex", gap: 32, animation: "meloMarquee 45s linear infinite", whiteSpace: "nowrap", fontFamily: "var(--font-mono)", fontSize: 13, color: "var(--ink-2)" }}>
          {doubled.map((s, i) => (
            <span key={i} style={{ display: "inline-flex", alignItems: "center", gap: 16 }}>
              <span style={{ color: "var(--ink-3)" }}>"</span>{s}<span style={{ color: "var(--ink-3)" }}>"</span>
              <span style={{ color: "var(--ink-3)" }}>·</span>
            </span>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ── Features ── */
const FEATURES = [
  {
    label: "01", title: "Chat-based logging",
    body: "Type the way you think. \"Lunch $15.\" \"Salary $5000.\" The model understands slang, multiple currencies, splits, refunds, and recurring items — without a form in sight.",
    bullets: ["Multi-currency", "Splits & shares", "Receipts via photo"],
  },
  {
    label: "02", title: "Smart analytics, in chat",
    body: "Weekly and monthly summaries arrive on the same thread. Ask follow-ups in plain English. There is no dashboard to log into because the chat itself is the dashboard.",
    bullets: ["Weekly digest", "Ask anything", "Budget alerts"],
  },
  {
    label: "03", title: "Auto-categorization",
    body: "Melo knows McDonald's is Food and Uber is Transport. It learns your private quirks too — that \"Lemur\" is your dog walker and goes under Pets — and gets quieter as it gets right.",
    bullets: ["28 default categories", "Custom rules", "Learns over time"],
  },
  {
    label: "04", title: "Private by design",
    body: "Bank-level encryption, end-to-end on the WhatsApp side, encrypted at rest on ours. We never sell your data. You can wipe everything with one message: \"forget me.\"",
    bullets: ["E2E on WhatsApp", "AES-256 at rest", "One-message delete"],
  },
  {
    label: "05", title: "Voice note logging",
    body: "Rambled off five expenses on the way home? Just send a voice note. Melo transcribes it, picks out every amount, and logs them all — in any language you speak. English, Hindi, Spanish, Arabic, Portuguese — it doesn't matter. One clip, every entry captured.",
    bullets: ["Any language", "Multiple entries per clip", "Instant transcription"],
    wide: true,
  },
];

function FeaturesSection() {
  const isMobile = useMobile();
  return (
    <section id="features" className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <SectionTitle kicker="What it does"
          sub="Melo is small on purpose. Four jobs done well, no twenty-button settings panel.">
          Everything you need to master your money — and nothing you don't.
        </SectionTitle>
        <div style={{
          marginTop: isMobile ? 36 : 56,
          display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(2, minmax(0, 1fr))",
          gap: 1, background: "var(--border)", border: "1px solid var(--border)", borderRadius: 12, overflow: "hidden",
        }}>
          {FEATURES.map((f) => (
            <div key={f.label} className="melo-card" style={{
              background: "var(--surface)", padding: isMobile ? "24px 20px" : "32px 32px 28px",
              display: "flex", flexDirection: "column", gap: 14,
              gridColumn: (!isMobile && f.wide) ? "1 / -1" : undefined,
            }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                <div style={{ fontFamily: "var(--font-mono)", fontSize: 11, fontWeight: 600, color: "var(--ink-3)", letterSpacing: "0.16em" }}>{f.label}</div>
                {f.wide && (
                  <span style={{
                    fontFamily: "var(--font-mono)", fontSize: 10.5, fontWeight: 600,
                    letterSpacing: "0.12em", textTransform: "uppercase",
                    background: "var(--accent-soft)", color: "var(--accent)",
                    border: "1px solid var(--accent)", borderRadius: 999,
                    padding: "2px 9px",
                  }}>New</span>
                )}
              </div>
              <div style={{ display: f.wide && !isMobile ? "grid" : "block", gridTemplateColumns: "1fr 1fr", gap: 32 }}>
                <div style={{ display: "flex", flexDirection: "column", gap: 14 }}>
                  <h3 style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: isMobile ? 19 : 22, margin: 0, letterSpacing: "-0.01em", color: "var(--ink-1)" }}>{f.title}</h3>
                  <p style={{ fontFamily: "var(--font-mono)", fontSize: 14.5, lineHeight: 1.65, color: "var(--ink-2)", margin: 0, textWrap: "pretty" }}>{f.body}</p>
                  <div style={{ display: "flex", flexWrap: "wrap", gap: 6, marginTop: 6 }}>
                    {f.bullets.map((b, i) => (
                      <span key={i} className="ed-tag" style={{ background: "var(--surface-3)", color: "var(--ink-2)", fontSize: 11.5 }}>{b}</span>
                    ))}
                  </div>
                </div>
                {f.wide && !isMobile && (
                  <div style={{ display: "flex", flexDirection: "column", gap: 10, justifyContent: "center" }}>
                    {[
                      { lang: "EN", clip: "Coffee four bucks, lunch twelve, Uber home twenty-two fifty", entries: ["Dining · $4.00", "Dining · $12.00", "Transport · $22.50"] },
                      { lang: "ES", clip: "Gasolina ochocientos pesos, mercado mil doscientos", entries: ["Transport · $800", "Groceries · $1,200"] },
                    ].map(ex => (
                      <div key={ex.lang} style={{ background: "var(--surface-2)", border: "1px solid var(--border)", borderRadius: 10, padding: "12px 14px", display: "flex", flexDirection: "column", gap: 8 }}>
                        <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
                          <span style={{ fontFamily: "var(--font-mono)", fontSize: 10, fontWeight: 700, color: "var(--ink-3)", letterSpacing: "0.12em", textTransform: "uppercase", background: "var(--surface-3)", border: "1px solid var(--border)", borderRadius: 4, padding: "1px 6px" }}>{ex.lang}</span>
                          <span style={{ flex: 1, height: 24, display: "flex", alignItems: "center", gap: 1 }}>
                            {Array.from({ length: 28 }).map((_, i) => (
                              <span key={i} style={{ display: "inline-block", width: 2, borderRadius: 1, background: "var(--ink-3)", height: `${8 + Math.abs(Math.sin(i * 1.3 + ex.lang.charCodeAt(0))) * 14}px`, opacity: 0.55 }} />
                            ))}
                          </span>
                          <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, color: "var(--ink-3)" }}>0:{ex.entries.length * 4 + 1}s</span>
                        </div>
                        <div style={{ display: "flex", gap: 6, flexWrap: "wrap" }}>
                          {ex.entries.map((e, i) => (
                            <span key={i} style={{ fontFamily: "var(--font-mono)", fontSize: 11.5, background: "var(--surface)", border: "1px solid var(--border)", borderRadius: 6, padding: "3px 8px", color: "var(--ink-1)" }}>✓ {e}</span>
                          ))}
                        </div>
                      </div>
                    ))}
                  </div>
                )}
              </div>
            </div>
          ))}
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── How it works ── */
const STEPS = [
  {
    n: "1", title: "Snap or text",
    body: "Send a text or a photo of your receipt to the Melo number. The first time you talk to Melo, it learns your currency, time zone, and pay cycle — that's the whole onboarding.",
    sample: { from: "user", text: "uber 24.50" },
  },
  {
    n: "2", title: "Instant processing",
    body: "Vision and language models extract merchant, date, amount, and category in well under a second. Ambiguous? Melo asks one question, never twenty.",
    sample: { from: "ai", text: "Got it — Transport, $24.50. Tagging this trip as work?" },
  },
  {
    n: "3", title: "Insights on demand",
    body: "Ask anything later — \"how much on food this month?\", \"compare august to september\", \"am I on track for rent?\" — and get a numeric answer, not a chart-shaped guess.",
    sample: { from: "ai", text: "October food: $312.40. That's $48 less than September. You're 23% under budget." },
  },
];

function HowSection() {
  const isMobile = useMobile();
  return (
    <section id="how" className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", background: "var(--surface-2)", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <SectionTitle kicker="How it works" sub="Three steps. None of them involve installing anything.">
          From "ugh, I'll do it later" to logged in under a second.
        </SectionTitle>
        <div style={{ marginTop: isMobile ? 36 : 56, display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, minmax(0, 1fr))", gap: isMobile ? 32 : 24 }}>
          {STEPS.map(s => (
            <div key={s.n} style={{ display: "flex", flexDirection: "column", gap: 16 }}>
              <div style={{
                width: 36, height: 36, borderRadius: 999,
                border: "1px solid var(--border-strong)",
                display: "flex", alignItems: "center", justifyContent: "center",
                fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 14, color: "var(--ink-1)",
              }}>{s.n}</div>
              <h3 style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 19, margin: 0, letterSpacing: "-0.01em", color: "var(--ink-1)" }}>{s.title}</h3>
              <p style={{ fontFamily: "var(--font-mono)", fontSize: 14, lineHeight: 1.65, color: "var(--ink-2)", margin: 0, textWrap: "pretty" }}>{s.body}</p>
              <div style={{ marginTop: 4, display: "flex", justifyContent: s.sample.from === "user" ? "flex-end" : "flex-start" }}>
                <div style={{
                  maxWidth: "92%", padding: "8px 12px", borderRadius: 10,
                  background: s.sample.from === "user" ? "var(--accent)" : "var(--surface)",
                  color: s.sample.from === "user" ? "#fff" : "var(--ink-1)",
                  border: s.sample.from === "user" ? "1px solid var(--accent)" : "1px solid var(--border)",
                  fontFamily: "var(--font-mono)", fontSize: 13, lineHeight: 1.5,
                }}>{s.sample.text}</div>
              </div>
            </div>
          ))}
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── Live Demo ── */
const DEMO_TXNS = [
  { d: "Oct 28", who: "Pret a Manger",   cat: "Dining",    v:   8.40, tone: "peach" },
  { d: "Oct 28", who: "Uber",            cat: "Transport", v:  14.20, tone: "sky" },
  { d: "Oct 27", who: "Whole Foods",     cat: "Groceries", v:  62.10, tone: "sage" },
  { d: "Oct 27", who: "Spotify",         cat: "Subs",      v:   9.99, tone: "lavender" },
  { d: "Oct 26", who: "Sarah (split)",   cat: "Dining",    v:  28.67, tone: "peach" },
  { d: "Oct 26", who: "BP — petrol",     cat: "Transport", v:  41.00, tone: "sky" },
  { d: "Oct 25", who: "Trader Joe's",    cat: "Groceries", v:  38.40, tone: "sage" },
  { d: "Oct 24", who: "Salary",          cat: "Income",    v: -3200,  tone: "butter" },
  { d: "Oct 23", who: "Lemur (dog)",     cat: "Pets",      v:  45.00, tone: "rose" },
  { d: "Oct 22", who: "Apple One",       cat: "Subs",      v:  19.95, tone: "lavender" },
];
const DEMO_CATS = ["All","Dining","Transport","Groceries","Subs","Pets","Income"];

function DemoSection() {
  const [cat, setCat] = useStateS("All");
  const isMobile = useMobile();
  const filtered = DEMO_TXNS.filter(t => cat === "All" || t.cat === cat);
  const total = filtered.filter(t => t.v > 0).reduce((s, t) => s + t.v, 0);
  return (
    <section id="demo" className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <SectionTitle kicker="Behind the chat"
          sub="Every message becomes a row. You can browse them on web if you want — but you almost never need to.">
          A ledger that builds itself.
        </SectionTitle>
        <div style={{ marginTop: 48, background: "var(--surface)", border: "1px solid var(--border)", borderRadius: 12, overflow: "hidden" }}>
          {/* Toolbar */}
          <div style={{
            padding: "14px 18px", borderBottom: "1px solid var(--border)",
            display: "flex", flexWrap: "wrap", alignItems: "center", gap: 8,
            background: "var(--surface-2)",
          }}>
            <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)", letterSpacing: "0.12em", textTransform: "uppercase" }}>Filter</span>
            <div style={{ display: "flex", flexWrap: "wrap", gap: 6 }}>
              {DEMO_CATS.map(c => (
                <button key={c} onClick={() => setCat(c)} style={{
                  fontFamily: "var(--font-mono)", fontSize: 12.5,
                  padding: "5px 12px", borderRadius: 999,
                  border: "1px solid " + (cat === c ? "var(--accent)" : "var(--border)"),
                  background: cat === c ? "var(--accent-soft)" : "var(--surface)",
                  color: cat === c ? "var(--accent)" : "var(--ink-2)",
                  cursor: "pointer",
                }}>{c}</button>
              ))}
            </div>
            {!isMobile && <div style={{ flex: 1 }} />}
            {!isMobile && (
              <span style={{ fontFamily: "var(--font-mono)", fontSize: 12.5, color: "var(--ink-2)" }}>
                {filtered.length} rows · spend <strong style={{ color: "var(--ink-1)" }}>${total.toFixed(2)}</strong>
              </span>
            )}
          </div>
          {/* Rows — scrollable on mobile */}
          <div style={{ overflowX: "auto", WebkitOverflowScrolling: "touch" }}>
            <div style={{ minWidth: isMobile ? 480 : "auto" }}>
              {filtered.map((t, i) => (
                <div key={i} style={{
                  display: "grid", gridTemplateColumns: "84px 1fr 120px 100px",
                  alignItems: "center", gap: 12, padding: "12px 18px",
                  borderBottom: i === filtered.length - 1 ? "none" : "1px solid var(--border-faint)",
                  fontFamily: "var(--font-mono)", fontSize: 13.5,
                }}>
                  <span style={{ color: "var(--ink-3)", fontVariantNumeric: "tabular-nums" }}>{t.d}</span>
                  <span style={{ color: "var(--ink-1)" }}>{t.who}</span>
                  <span><span className={`ed-tag ed-tag--${t.tone}`}>{t.cat}</span></span>
                  <span style={{ textAlign: "right", fontVariantNumeric: "tabular-nums", color: t.v < 0 ? "var(--accent)" : "var(--ink-1)", fontWeight: 600 }}>
                    {t.v < 0 ? "+" : "−"}${Math.abs(t.v).toFixed(2)}
                  </span>
                </div>
              ))}
              {filtered.length === 0 && (
                <div style={{ padding: 32, textAlign: "center", color: "var(--ink-3)", fontFamily: "var(--font-mono)", fontSize: 13 }}>
                  Nothing here yet. Ask Melo: <em>"log $X for {cat.toLowerCase()}"</em>.
                </div>
              )}
            </div>
          </div>
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── Privacy ── */
function PrivacySection() {
  const isMobile = useMobile();
  return (
    <section id="privacy" className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", background: "var(--surface-2)", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "minmax(0, 1fr) minmax(0, 1.1fr)", gap: isMobile ? 40 : 64, alignItems: "start" }}>
          <div>
            <Eyebrow>Privacy</Eyebrow>
            <h2 style={{
              fontFamily: "var(--font-mono)", fontWeight: 700,
              fontSize: "clamp(24px, 3.4vw, 38px)", lineHeight: 1.15,
              letterSpacing: "-0.02em", margin: 0, color: "var(--ink-1)", textWrap: "balance",
            }}>Your money is your business — and only yours.</h2>
            <p style={{ marginTop: 18, fontFamily: "var(--font-mono)", fontSize: 14.5, lineHeight: 1.7, color: "var(--ink-2)", maxWidth: "52ch", textWrap: "pretty" }}>
              The honest reason people don't track expenses is that handing a stranger your spending feels gross. Melo is built so we see as little as possible, store it well, and hand it back the moment you ask.
            </p>
          </div>
          <div className="melo-card" style={{ background: "var(--surface)", border: "1px solid var(--border)", borderRadius: 12, padding: 0, overflow: "hidden" }}>
            {[
              ["Encrypted on WhatsApp", "All messages travel end-to-end via WhatsApp's protocol. Nobody at Melo can read them in flight."],
              ["Encrypted at rest", "Your ledger is stored AES-256 encrypted, isolated per user, in EU & US regions."],
              ["Never sold, never trained on", "We do not sell data, share with brokers, or fine-tune our models on your spending."],
              ["One-message delete", "Send \"forget me\" and your data is purged within 24 hours. Receipts attached."],
            ].map(([t, b], i, arr) => (
              <div key={t} style={{ padding: "20px 24px", borderBottom: i === arr.length - 1 ? "none" : "1px solid var(--border-faint)", display: "grid", gridTemplateColumns: "20px 1fr", gap: 16 }}>
                <span style={{ fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--ink-3)", letterSpacing: "0.12em" }}>0{i+1}</span>
                <div>
                  <div style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 14.5, color: "var(--ink-1)", marginBottom: 4 }}>{t}</div>
                  <div style={{ fontFamily: "var(--font-mono)", fontSize: 13.5, lineHeight: 1.6, color: "var(--ink-2)", textWrap: "pretty" }}>{b}</div>
                </div>
              </div>
            ))}
          </div>
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── Pricing ── */
const PLANS = [
  {
    name: "Free", price: "$0", cadence: "forever",
    sub: "Everything most people need. No credit card.",
    features: ["Unlimited messages","1 currency","Auto-categorize","Weekly summary","30-day history"],
    cta: "Start on WhatsApp", primary: false,
  },
  {
    name: "Plus", price: "$4", cadence: "/ month",
    sub: "For people who actually look at the numbers.",
    features: ["Everything in Free","Unlimited history","Multi-currency","Custom categories & rules","Splits with reminders","Receipt OCR"],
    cta: "Start free trial", primary: true,
  },
  {
    name: "Households", price: "$8", cadence: "/ month",
    sub: "Shared finances without shared anxiety.",
    features: ["Everything in Plus","Up to 4 members","Shared categories","Per-person budgets","Monthly statement (PDF)"],
    cta: "Set up household", primary: false,
  },
];

function PricingSection() {
  const isMobile = useMobile();
  return (
    <section id="pricing" className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <SectionTitle kicker="Pricing"
          sub="Free forever for personal use. Upgrade only if you want history beyond a month, multi-currency, or households.">
          Three plans. The first one is enough for most people.
        </SectionTitle>
        <div style={{ marginTop: isMobile ? 36 : 56, display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, minmax(0, 1fr))", gap: 16 }}>
          {PLANS.map(p => (
            <div key={p.name} className="melo-card" style={{
              background: p.primary ? "var(--ink-1)" : "var(--surface)",
              color: p.primary ? "var(--ink-inverse)" : "var(--ink-1)",
              border: p.primary ? "1px solid var(--ink-1)" : "1px solid var(--border)",
              borderRadius: 12, padding: 28,
              display: "flex", flexDirection: "column", gap: 16, position: "relative",
            }}>
              {p.primary && <span style={{
                position: "absolute", top: 14, right: 14,
                fontFamily: "var(--font-mono)", fontSize: 10.5,
                background: "var(--accent)", color: "#fff",
                padding: "3px 10px", borderRadius: 999, letterSpacing: "0.1em",
              }}>POPULAR</span>}
              <div style={{ fontFamily: "var(--font-mono)", fontSize: 14, fontWeight: 700 }}>{p.name}</div>
              <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
                <span style={{ fontFamily: "var(--font-mono)", fontSize: 40, fontWeight: 700, letterSpacing: "-0.03em" }}>{p.price}</span>
                <span style={{ fontFamily: "var(--font-mono)", fontSize: 13, opacity: 0.7 }}>{p.cadence}</span>
              </div>
              <p style={{ fontFamily: "var(--font-mono)", fontSize: 13.5, lineHeight: 1.55, margin: 0, opacity: p.primary ? 0.85 : 1, color: p.primary ? "var(--ink-inverse)" : "var(--ink-2)", textWrap: "pretty" }}>{p.sub}</p>
              <div style={{ borderTop: "1px solid " + (p.primary ? "rgba(255,255,255,0.16)" : "var(--border-faint)"), margin: "4px 0" }} />
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 8 }}>
                {p.features.map(f => (
                  <li key={f} style={{
                    fontFamily: "var(--font-mono)", fontSize: 13.5, lineHeight: 1.5,
                    display: "grid", gridTemplateColumns: "16px 1fr", gap: 10,
                    color: p.primary ? "var(--ink-inverse)" : "var(--ink-1)",
                  }}>
                    <span style={{ color: "var(--accent)", marginTop: 1 }}>•</span>
                    <span>{f}</span>
                  </li>
                ))}
              </ul>
              <a href="https://wa.me/message/H3SMFZFN7RHRO1" target="_blank" rel="noreferrer" style={{
                marginTop: "auto", display: "inline-flex", justifyContent: "center", alignItems: "center",
                fontFamily: "var(--font-mono)", fontSize: 13.5, fontWeight: 600,
                padding: "10px 16px", borderRadius: 999, textDecoration: "none", cursor: "pointer",
                background: p.primary ? "var(--accent)" : "var(--surface)",
                color: p.primary ? "#fff" : "var(--ink-1)",
                border: "1px solid " + (p.primary ? "var(--accent)" : "var(--border-strong)"),
              }}>{p.cta} →</a>
            </div>
          ))}
        </div>
        <p style={{ marginTop: 32, textAlign: "center", fontFamily: "var(--font-mono)", fontSize: 12.5, color: "var(--ink-3)" }}>
          Annual billing saves 20%. No hidden fees. Cancel by sending Melo "cancel".
        </p>
      </ContainerCol>
    </section>
  );
}

/* ── Comparison ── */
function ComparisonSection() {
  const isMobile = useMobile();
  const rows = [
    ["Where it lives",         "Inside WhatsApp",        "Standalone app",               "Spreadsheet"],
    ["Time to log an expense", "≈ 2 seconds",            "≈ 30 seconds",                 "≈ 60 seconds"],
    ["Onboarding",             "Send one message",       "Sign up, OTP, KYC, link bank", "Build the sheet yourself"],
    ["Categorization",         "AI, learns your habits", "Rules-based",                  "Manual"],
    ["Insights",               "Ask in plain English",   "Pre-built dashboards",         "Pivot tables, if you must"],
    ["Notifications",          "Same thread you read",   "Push you'll mute",             "None"],
  ];
  return (
    <section className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", background: "var(--surface-2)", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <SectionTitle kicker="Honestly compared"
          sub="If a budgeting app or spreadsheet is already working for you, keep it. Melo exists for the rest of us.">
          Why a chat beats an app.
        </SectionTitle>
        {/* Scrollable on mobile */}
        <div style={{ marginTop: 48, overflowX: "auto", WebkitOverflowScrolling: "touch", borderRadius: 12 }}>
          <div style={{ background: "var(--surface)", border: "1px solid var(--border)", borderRadius: 12, overflow: "hidden", minWidth: isMobile ? 540 : "auto" }}>
            <div style={{
              display: "grid", gridTemplateColumns: "1.2fr 1fr 1fr 1fr",
              background: "var(--surface-2)", borderBottom: "1px solid var(--border)",
              padding: "14px 20px", fontFamily: "var(--font-mono)", fontSize: 11.5,
              letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-3)",
            }}>
              <span></span>
              <span style={{ color: "var(--accent)" }}>Melo</span>
              <span>Budgeting app</span>
              <span>Spreadsheet</span>
            </div>
            {rows.map((r, i) => (
              <div key={i} style={{
                display: "grid", gridTemplateColumns: "1.2fr 1fr 1fr 1fr",
                padding: "14px 20px", gap: 12,
                borderBottom: i === rows.length - 1 ? "none" : "1px solid var(--border-faint)",
                fontFamily: "var(--font-mono)", fontSize: 13.5, alignItems: "center",
              }}>
                <span style={{ color: "var(--ink-2)" }}>{r[0]}</span>
                <span style={{ color: "var(--ink-1)", fontWeight: 600 }}>{r[1]}</span>
                <span style={{ color: "var(--ink-2)" }}>{r[2]}</span>
                <span style={{ color: "var(--ink-2)" }}>{r[3]}</span>
              </div>
            ))}
          </div>
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── Voice Notes ── */
function VoiceSection() {
  const isMobile = useMobile();

  const DEMOS = [
    {
      lang: "English", flag: "🇺🇸",
      clip: "Coffee was four, grabbed lunch for twelve bucks, and the Uber home was like twenty-two fifty",
      entries: [
        { label: "Dining", v: "$4.00",   tone: "peach" },
        { label: "Dining", v: "$12.00",  tone: "peach" },
        { label: "Transport", v: "$22.50", tone: "sky" },
      ],
    },
    {
      lang: "Hindi", flag: "🇮🇳",
      clip: "Chai ke liye bees rupaye, auto mein pachas, aur ghar ke liye sabzi ek sau bees",
      entries: [
        { label: "Dining",    v: "₹20",  tone: "peach" },
        { label: "Transport", v: "₹50",  tone: "sky" },
        { label: "Groceries", v: "₹120", tone: "sage" },
      ],
    },
    {
      lang: "Spanish", flag: "🇪🇸",
      clip: "Gasolina ochocientos pesos, mercado mil doscientos, y la renta cuatro mil",
      entries: [
        { label: "Transport", v: "$800",  tone: "sky" },
        { label: "Groceries", v: "$1,200", tone: "sage" },
        { label: "Rent",      v: "$4,000", tone: "lavender" },
      ],
    },
  ];

  const [active, setActive] = useStateS(0);
  const demo = DEMOS[active];

  function WaveBar({ seed, height }) {
    return <span style={{ display: "inline-block", width: 2.5, borderRadius: 2, background: "var(--accent)", height: height + "px", opacity: 0.55, flexShrink: 0 }} />;
  }

  function Waveform({ seed }) {
    return (
      <div style={{ display: "flex", alignItems: "center", gap: 1.5, height: 32, overflow: "hidden" }}>
        {Array.from({ length: 40 }).map((_, i) => {
          const h = 4 + Math.abs(Math.sin((i + seed) * 0.7) * Math.cos((i + seed) * 0.4 + 1)) * 22;
          return <WaveBar key={i} seed={seed} height={h} />;
        })}
      </div>
    );
  }

  return (
    <section className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol>
        <div style={{
          display: "grid",
          gridTemplateColumns: isMobile ? "1fr" : "minmax(0, 1fr) minmax(0, 1fr)",
          gap: isMobile ? 40 : 72, alignItems: "center",
        }}>
          {/* Copy */}
          <div>
            <Eyebrow>Voice notes</Eyebrow>
            <h2 style={{
              fontFamily: "var(--font-mono)", fontWeight: 700,
              fontSize: "clamp(24px, 3.6vw, 42px)", lineHeight: 1.15,
              letterSpacing: "-0.02em", margin: 0, color: "var(--ink-1)", textWrap: "balance",
            }}>
              Say it.<br />Log everything.
            </h2>
            <p style={{ marginTop: 18, fontFamily: "var(--font-mono)", fontSize: 15, lineHeight: 1.7, color: "var(--ink-2)", maxWidth: "48ch", textWrap: "pretty" }}>
              Ramble off your whole day in one voice note — coffee, lunch, Uber, groceries, whatever. Melo transcribes it and pulls out every amount automatically. One clip, every expense captured.
            </p>
            <div style={{ marginTop: 28, display: "flex", flexDirection: "column", gap: 12 }}>
              {[
                ["Any language", "Speak in English, Hindi, Spanish, Arabic, Portuguese, French — Melo understands."],
                ["Multiple entries, one clip", "Don't log one by one. List everything in a single voice note and Melo splits them all."],
                ["Same thread, no app", "Your voice notes live in WhatsApp. Nothing to install, nothing extra to open."],
              ].map(([t, b]) => (
                <div key={t} style={{ display: "grid", gridTemplateColumns: "18px 1fr", gap: 12, alignItems: "start" }}>
                  <span style={{ color: "var(--accent)", fontFamily: "var(--font-mono)", fontSize: 14, marginTop: 1 }}>↳</span>
                  <div>
                    <span style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 13.5, color: "var(--ink-1)" }}>{t} — </span>
                    <span style={{ fontFamily: "var(--font-mono)", fontSize: 13.5, color: "var(--ink-2)" }}>{b}</span>
                  </div>
                </div>
              ))}
            </div>
          </div>

          {/* Interactive demo */}
          <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {/* Language tabs */}
            <div style={{ display: "flex", gap: 6 }}>
              {DEMOS.map((d, i) => (
                <button key={d.lang} onClick={() => setActive(i)} style={{
                  fontFamily: "var(--font-mono)", fontSize: 12, fontWeight: 600,
                  padding: "5px 13px", borderRadius: 999, cursor: "pointer",
                  border: "1px solid " + (active === i ? "var(--accent)" : "var(--border)"),
                  background: active === i ? "var(--accent-soft)" : "var(--surface)",
                  color: active === i ? "var(--accent)" : "var(--ink-2)",
                  transition: "border-color 160ms, background 160ms, color 160ms",
                }}>{d.flag} {d.lang}</button>
              ))}
            </div>

            {/* Voice note bubble (user side) */}
            <div style={{
              background: "var(--surface)", border: "1px solid var(--border)",
              borderRadius: 14, padding: "14px 16px",
              display: "flex", flexDirection: "column", gap: 12,
            }}>
              <div style={{ display: "flex", justifyContent: "flex-end" }}>
                <div style={{
                  maxWidth: "88%", background: "var(--accent)",
                  borderRadius: "12px 4px 12px 12px",
                  padding: "10px 14px", display: "flex", flexDirection: "column", gap: 6,
                }}>
                  <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                    <span style={{ fontSize: 16 }}>🎤</span>
                    <Waveform seed={active * 7} />
                    <span style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, color: "rgba(255,255,255,0.75)", flexShrink: 0 }}>0:{demo.entries.length * 4 + 1}s</span>
                  </div>
                  <div style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "rgba(255,255,255,0.8)", fontStyle: "italic", lineHeight: 1.4 }}>
                    "{demo.clip}"
                  </div>
                </div>
              </div>

              {/* AI response */}
              <div style={{ display: "flex", justifyContent: "flex-start" }}>
                <div style={{
                  maxWidth: "90%", background: "var(--surface-2)",
                  border: "1px solid var(--border)", borderRadius: "4px 12px 12px 12px",
                  padding: "12px 14px", display: "flex", flexDirection: "column", gap: 8,
                }}>
                  <div style={{ fontFamily: "var(--font-mono)", fontSize: 12.5, color: "var(--ink-2)", lineHeight: 1.4 }}>
                    Got {demo.entries.length} expense{demo.entries.length > 1 ? "s" : ""} from your voice note —
                  </div>
                  <div style={{ display: "flex", flexDirection: "column", gap: 5 }}>
                    {demo.entries.map((e, i) => (
                      <div key={i} style={{ display: "flex", alignItems: "center", gap: 8, fontFamily: "var(--font-mono)", fontSize: 13 }}>
                        <span style={{ color: "var(--accent)", fontSize: 11 }}>✓</span>
                        <span className={`ed-tag ed-tag--${e.tone}`} style={{ fontSize: 11 }}>{e.label}</span>
                        <span style={{ color: "var(--ink-1)", fontWeight: 600, fontVariantNumeric: "tabular-nums" }}>{e.v}</span>
                      </div>
                    ))}
                  </div>
                  <div style={{ fontFamily: "var(--font-mono)", fontSize: 11.5, color: "var(--ink-3)", marginTop: 2 }}>
                    All logged. Anything to adjust?
                  </div>
                </div>
              </div>
            </div>

            <p style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)", margin: 0, lineHeight: 1.5 }}>
              Works with any accent, any currency symbol, and mixed-language clips.
            </p>
          </div>
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── FAQ ── */
const FAQS = [
  ["Do I need to install anything?", "No. Melo lives entirely inside WhatsApp. Open WhatsApp, message the Melo number, and you're using it. Removing Melo is the same as deleting any contact."],
  ["Does Melo connect to my bank?", "Not by default, and we don't recommend it. You log expenses by sending messages. Bank-link is on the roadmap for Plus, opt-in only, with read-only credentials and zero retention of raw transactions."],
  ["Which currencies and languages?", "All major currencies (auto-detected from message context), plus crypto. English, Spanish, Portuguese, French, Hindi, and Arabic at launch — both for typed messages and voice notes. You can switch languages mid-clip and Melo will follow."],
  ["What happens to my data if I stop using it?", "Nothing changes — your ledger sits idle, encrypted, until you ask for it. Send \"forget me\" and we purge everything within 24 hours and email you a confirmation."],
  ["Why WhatsApp, not Signal or iMessage?", "Reach. WhatsApp has 2.8 billion users globally and is the default chat app outside North America. We'll add Signal and iMessage support — most likely in that order."],
  ["Is it actually private?", "We see what you message Melo, encrypted in transit and at rest. We do not sell data, do not train on it, and do not share with advertisers. Read the technical write-up under Privacy."],
];

function FaqSection() {
  const [open, setOpen] = useStateS(0);
  const isMobile = useMobile();
  return (
    <section id="faq" className="melo-section" style={{ padding: isMobile ? "64px 0" : "96px 0", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol style={{ maxWidth: 880 }}>
        <SectionTitle kicker="FAQ" sub="Everything I'd want to know before sending a stranger my coffee receipts.">
          Plain answers.
        </SectionTitle>
        <div style={{ marginTop: 48, borderTop: "1px solid var(--border)" }}>
          {FAQS.map(([q, a], i) => (
            <div key={i} style={{ borderBottom: "1px solid var(--border)" }}>
              <button onClick={() => setOpen(open === i ? -1 : i)} style={{
                width: "100%", textAlign: "left", padding: isMobile ? "16px 4px" : "20px 4px",
                display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16,
                background: "transparent", border: "none", cursor: "pointer",
                fontFamily: "var(--font-mono)", fontSize: isMobile ? 14 : 16, fontWeight: 600, color: "var(--ink-1)",
              }}>
                <span>{q}</span>
                <span style={{
                  fontFamily: "var(--font-mono)", fontSize: 18, color: "var(--ink-3)",
                  transition: "transform 200ms var(--ease)",
                  transform: open === i ? "rotate(45deg)" : "rotate(0)",
                  flexShrink: 0,
                }}>+</span>
              </button>
              <div style={{ maxHeight: open === i ? 300 : 0, overflow: "hidden", transition: "max-height 280ms var(--ease)" }}>
                <div style={{ padding: "0 4px 24px", fontFamily: "var(--font-mono)", fontSize: 14.5, lineHeight: 1.7, color: "var(--ink-2)", textWrap: "pretty", maxWidth: "62ch" }}>{a}</div>
              </div>
            </div>
          ))}
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── Closing CTA ── */
function CtaSection() {
  const isMobile = useMobile();
  return (
    <section className="melo-section" style={{ padding: isMobile ? "80px 0 64px" : "120px 0 96px", borderTop: "1px solid var(--border-faint)" }}>
      <ContainerCol style={{ textAlign: "center" }}>
        <Eyebrow>Get started</Eyebrow>
        <h2 style={{
          fontFamily: "var(--font-mono)", fontWeight: 700,
          fontSize: isMobile ? "clamp(32px, 8vw, 48px)" : "clamp(36px, 5vw, 60px)",
          lineHeight: 1.05, letterSpacing: "-0.03em",
          margin: "0 auto", color: "var(--ink-1)", maxWidth: "18ch", textWrap: "balance",
        }}>
          Start tracking in <em style={{ color: "var(--accent)", fontStyle: "italic" }}>thirty seconds</em>.
        </h2>
        <p style={{
          marginTop: 18, fontFamily: "var(--font-mono)", fontSize: 15.5, lineHeight: 1.7,
          color: "var(--ink-2)", maxWidth: "56ch", margin: "18px auto 0", textWrap: "pretty",
        }}>
          Join the people who quietly ditched the spreadsheet. The first message is the only setup.
        </p>
        <div style={{ marginTop: 36, display: "flex", gap: 12, flexWrap: "wrap", justifyContent: "center", flexDirection: isMobile ? "column" : "row", alignItems: isMobile ? "center" : undefined }}>
          <PrimaryBtn href="https://wa.me/message/H3SMFZFN7RHRO1">Chat with Melo ↗</PrimaryBtn>
          <PrimaryBtn href="#pricing" ghost>See pricing</PrimaryBtn>
        </div>
        <div style={{ marginTop: 20, fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)" }}>
          Free forever for basic use · No credit card · No spam
        </div>
      </ContainerCol>
    </section>
  );
}

/* ── Footer ── */
function FooterSection() {
  const isMobile = useMobile();

  const COLS = [
    ["Navigate", [
      ["Features",        "#features"],
      ["Pricing",         "#pricing"],
      ["Security",        "#privacy"],
    ]],
    ["Legal", [
      ["Privacy policy",  "privacy.html"],
      ["Terms of service","terms.html"],
      ["Data deletion",   "privacy.html#data-deletion"],
    ]],
  ];

  const ALL_CARDS = [
    { l:  2, t: 55,  r: -5, type: "txn",  who: "Salary credit",  cat: "Income",    tone: "butter",   v: "+$5,000"  },
    { l:  7, t: 215, r:  2, type: "txn",  who: "Pret a Manger",  cat: "Dining",    tone: "peach",    v: "$8.40"    },
    { l: 18, t:  16, r: -2, type: "txn",  who: "Whole Foods",    cat: "Groceries", tone: "sage",     v: "$62.10"   },
    { l: 23, t: 188, r:  3, type: "chat", text: "How much on food this month?",       from: "user"   },
    { l: 35, t:   6, r: -1, type: "mini", text: "October · 23% under budget · $714.70"              },
    { l: 42, t: 155, r:  4, type: "chat", text: "split $86 dinner — mike & ana",       from: "user"   },
    { l: 54, t:  50, r: -4, type: "txn",  who: "BP petrol",      cat: "Transport", tone: "sky",      v: "$41.00"   },
    { l: 59, t: 248, r:  2, type: "chat", text: "₹1,200 for chai",                     from: "user"   },
    { l: 67, t:  12, r:  1, type: "txn",  who: "Lemur the dog",  cat: "Pets",      tone: "rose",     v: "$45.00"   },
    { l: 72, t: 150, r: -3, type: "chat", text: "remind ana she owes me $28.67",       from: "user"   },
    { l: 81, t:  58, r:  3, type: "txn",  who: "Apple One",      cat: "Subs",      tone: "lavender", v: "$19.95"   },
    { l: 87, t: 228, r: -2, type: "chat", text: "€38 for books",                        from: "user"   },
  ];

  const CARDS = isMobile
    ? ALL_CARDS.filter(c => c.l >= 18 && c.l <= 80).slice(0, 6)
    : ALL_CARDS;

  const ART_H = isMobile ? 290 : 340;

  return (
    <footer className="melo-footer-card" style={{
      borderTop: "1px solid var(--border)",
      background: "var(--surface-2)",
      paddingTop: isMobile ? 40 : 56,
    }}>
      <ContainerCol>
        <div style={{
          display: "grid",
          gridTemplateColumns: isMobile ? "1fr" : "1.8fr 1fr 1fr",
          gap: isMobile ? 32 : 56,
        }}>
          {/* Brand */}
          <div>
            <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
              <span style={{
                width: 26, height: 26, borderRadius: 7,
                background: "var(--ink-1)", color: "var(--paper)",
                display: "inline-flex", alignItems: "center", justifyContent: "center",
                fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 14,
              }}>m</span>
              <span style={{ fontFamily: "var(--font-mono)", fontWeight: 700, fontSize: 15, color: "var(--ink-1)" }}>melo</span>
            </div>
            <p style={{ marginTop: 14, fontFamily: "var(--font-mono)", fontSize: 13.5, lineHeight: 1.65, color: "var(--ink-2)", maxWidth: "40ch" }}>
              The world's simplest expense tracker — living right inside the chat app you already use.
            </p>
          </div>

          {COLS.map(([h, items]) => (
            <div key={h}>
              <div style={{ fontFamily: "var(--font-mono)", fontSize: 11, fontWeight: 600, letterSpacing: "0.15em", textTransform: "uppercase", color: "var(--ink-3)", marginBottom: 14 }}>{h}</div>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
                {items.map(([label, href]) => (
                  <li key={label}>
                    <a href={href} style={{ fontFamily: "var(--font-mono)", fontSize: 13.5, color: "var(--ink-2)", textDecoration: "none" }}>{label}</a>
                  </li>
                ))}
              </ul>
            </div>
          ))}
        </div>

        {/* Copyright */}
        <div style={{
          marginTop: 40, paddingTop: 20, paddingBottom: 32,
          borderTop: "1px solid var(--border-faint)",
          display: "flex", justifyContent: "space-between", alignItems: "center",
          fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-3)",
          flexWrap: "wrap", gap: 12,
        }}>
          <span>© 2026 Melo Labs · Made for the chat-first crowd.</span>
          <span>v0.4.2 · status: <span style={{ color: "#3FB950" }}>● all systems normal</span></span>
        </div>
      </ContainerCol>

      {/* Art canvas — same surface-2 background, scattered cards */}
      <div style={{
        position: "relative", height: ART_H, overflow: "hidden",
        borderTop: "1px solid var(--border-faint)",
        background: "var(--surface-3)",
      }}>
        {/* Ghost currency symbols */}
        {[["$","4%","-28px",200], ["€","43%","6px",155], ["₹","75%","-20px",175]].map(([s, l, t, sz]) => (
          <div key={s} style={{
            position: "absolute", left: l, top: t,
            fontFamily: "var(--font-mono)", fontWeight: 700,
            fontSize: (isMobile ? Math.round(sz * 0.6) : sz) + "px",
            lineHeight: 1, color: "var(--ink-1)",
            opacity: 0.035,
            userSelect: "none", pointerEvents: "none",
          }}>{s}</div>
        ))}

        {/* Scattered cards */}
        {CARDS.map((c, i) => {
          const base = {
            position: "absolute",
            left: c.l + "%",
            top: c.t + "px",
            transform: `rotate(${c.r}deg)`,
            fontFamily: "var(--font-mono)",
          };

          if (c.type === "txn") return (
            <div key={i} style={{
              ...base,
              background: "var(--surface)",
              border: "1px solid var(--border)",
              borderRadius: 8, padding: "9px 13px",
              display: "flex", flexDirection: "column", gap: 4,
              minWidth: 130,
              boxShadow: "0 1px 4px rgba(0,0,0,0.06)",
            }}>
              <div style={{ fontSize: 10, color: "var(--ink-3)", letterSpacing: "0.1em", display: "flex", alignItems: "center", gap: 5 }}>
                <span className={`ed-tag ed-tag--${c.tone}`} style={{ fontSize: 10, padding: "1px 6px" }}>{c.cat}</span>
              </div>
              <div style={{ fontSize: 13, fontWeight: 600, color: "var(--ink-1)" }}>{c.who}</div>
              <div style={{ fontSize: 12, color: "var(--ink-2)", fontVariantNumeric: "tabular-nums" }}>{c.v}</div>
            </div>
          );

          if (c.type === "chat") {
            const isUser = c.from === "user";
            return (
              <div key={i} style={{
                ...base,
                background: isUser ? "var(--accent)" : "var(--surface)",
                border: "1px solid " + (isUser ? "var(--accent)" : "var(--border)"),
                borderRadius: isUser ? "10px 3px 10px 10px" : "3px 10px 10px 10px",
                padding: "7px 12px",
                fontSize: 12,
                color: isUser ? "#fff" : "var(--ink-2)",
                maxWidth: 190, lineHeight: 1.45,
                boxShadow: "0 1px 4px rgba(0,0,0,0.06)",
              }}>{c.text}</div>
            );
          }

          if (c.type === "mini") return (
            <div key={i} style={{
              ...base,
              background: "var(--surface)",
              border: "1px solid var(--border-faint)",
              borderRadius: 6, padding: "5px 10px",
              fontSize: 11, color: "var(--ink-3)",
              letterSpacing: "0.04em", whiteSpace: "nowrap",
            }}>{c.text}</div>
          );

          return null;
        })}

        {/* Bottom tagline */}
        <div style={{
          position: "absolute", bottom: 20, left: 0, right: 0,
          textAlign: "center",
          fontFamily: "var(--font-mono)", fontSize: 11,
          color: "var(--ink-3)",
          letterSpacing: "0.28em", textTransform: "uppercase",
          opacity: 0.5,
          pointerEvents: "none",
        }}>
          every spend, remembered
        </div>
      </div>
    </footer>
  );
}

window.TopNav = TopNav;
window.HeroSection = HeroSection;
window.FeaturesSection = FeaturesSection;
window.HowSection = HowSection;
window.VoiceSection = VoiceSection;
window.DemoSection = DemoSection;
window.PrivacySection = PrivacySection;
window.PricingSection = PricingSection;
window.ComparisonSection = ComparisonSection;
window.FaqSection = FaqSection;
window.CtaSection = CtaSection;
window.FooterSection = FooterSection;
