/* global React */
// landing-body.jsx — Pillars, Mockups, Day-with-Valence, FAQ, Waitlist, Footer

const { useEffect: useEffectB, useRef: useRefB, useState: useStateB, useMemo: useMemoB } = React;

// ─── Intersection-based reveal hook ──────────────────────────────────────
function useReveal() {
  const ref = useRefB(null);
  useEffectB(() => {
    const el = ref.current; if (!el) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach((entry) => {
        if (entry.isIntersecting) {
          entry.target.classList.add("in");
        }
      });
    }, { threshold: 0.15 });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return ref;
}

// ─── Tilt-on-hover wrapper ───────────────────────────────────────────────
function Tilt({ children, max = 8 }) {
  const ref = useRefB(null);
  const onMove = (e) => {
    const el = ref.current; if (!el) return;
    const r = el.getBoundingClientRect();
    const x = (e.clientX - r.left) / r.width;
    const y = (e.clientY - r.top) / r.height;
    const rx = (0.5 - y) * max;
    const ry = (x - 0.5) * max;
    el.style.transform = `perspective(900px) rotateX(${rx}deg) rotateY(${ry}deg) translateZ(0)`;
  };
  const onLeave = () => { if (ref.current) ref.current.style.transform = ""; };
  return (
    <div ref={ref} onMouseMove={onMove} onMouseLeave={onLeave}
      style={{ transition: "transform 300ms cubic-bezier(0.4,0,0.2,1)", transformStyle: "preserve-3d", height: "100%" }}>
      {children}
    </div>
  );
}

// ─── Value pillars: Contacts · Calendar · Pipeline ───────────────────────
function Pillars() {
  const ref = useReveal();
  const items = [
    {
      key: "contacts", label: "Contacts",
      title: "Every name. Every signal.",
      body: "One place for who you know — with the context that makes the next conversation matter.",
      bullets: ["Auto-enriched from the web", "Last-touch + warmth indicators", "Tied to firms and opportunities"],
      icon: (
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
          <path d="M16 21v-2a4 4 0 00-4-4H6a4 4 0 00-4 4v2" />
          <circle cx="9" cy="7" r="4" />
          <path d="M22 21v-2a4 4 0 00-3-3.87" />
          <path d="M16 3.13a4 4 0 010 7.75" />
        </svg>
      ),
      widget: (
        <div className="w w-contact">
          <div className="w-contact-head">
            <div className="w-avatar">RP</div>
            <div className="w-contact-id">
              <div className="w-contact-name">Riley Park</div>
              <div className="w-contact-role">VP Leasing · Eaton Capital</div>
            </div>
            <div className="w-warmth">
              <span className="w-warmth-dot" />
              <span className="w-warmth-label">Warm</span>
            </div>
          </div>
          <div className="w-stat-row">
            <div className="w-stat">
              <div className="w-stat-label">Last touched</div>
              <div className="w-stat-value">14 days ago</div>
            </div>
            <div className="w-stat">
              <div className="w-stat-label">Open deals</div>
              <div className="w-stat-value">3 · <span className="w-num">$4.2M</span></div>
            </div>
          </div>
          <div className="w-suggest">
            <div className="w-suggest-tag">
              <svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor"><path d="M12 2l2.4 7.2H22l-6.2 4.5 2.4 7.2L12 16.4l-6.2 4.5 2.4-7.2L2 9.2h7.6z"/></svg>
              <span>Suggested next step</span>
            </div>
            <div className="w-suggest-body">
              Call back about the <span className="w-emph">verbal yes</span> on the Eaton Capital lease — going on five days quiet.
            </div>
            <div className="w-suggest-actions">
              <button className="w-suggest-btn primary">Call now</button>
              <button className="w-suggest-btn">Snooze</button>
            </div>
          </div>
        </div>
      ),
    },
    {
      key: "calendar", label: "Calendar",
      title: "The week, decoded.",
      body: "Your meetings already exist. Valence connects them to the people, deals, and follow-ups that matter.",
      bullets: ["Bound to leads and accounts", "Prep notes, automatic", "Today, tomorrow, no-show alerts"],
      icon: (
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
          <rect x="3" y="4" width="18" height="18" rx="2" />
          <path d="M16 2v4M8 2v4M3 10h18" />
        </svg>
      ),
      widget: (
        <div className="w w-cal">
          <div className="w-cal-head">
            <div>
              <div className="w-cal-eyebrow">Today</div>
              <div className="w-cal-date">Tuesday, May 12</div>
            </div>
            <div className="w-cal-now">11:42</div>
          </div>
          <div className="w-cal-rail">
            <div className="w-cal-slot done">
              <div className="w-cal-time">09:15</div>
              <div className="w-cal-event">
                <div className="w-cal-event-title">Prep — Eaton Capital</div>
                <div className="w-cal-event-meta">30 min quiet block · done</div>
              </div>
            </div>
            <div className="w-cal-slot live">
              <div className="w-cal-spine"><span className="w-cal-dot" /></div>
              <div className="w-cal-time">11:30</div>
              <div className="w-cal-event">
                <div className="w-cal-event-title">Lunch · Eaton Capital</div>
                <div className="w-cal-event-meta">The Avenue · with R. Chen</div>
                <div className="w-cal-pill"><span className="w-pip" />Lease — verbal yes</div>
              </div>
            </div>
            <div className="w-cal-slot upcoming">
              <div className="w-cal-time">14:00</div>
              <div className="w-cal-event">
                <div className="w-cal-event-title">Riley Park site visit</div>
                <div className="w-cal-event-meta">Prep auto-attached · 3 docs</div>
              </div>
            </div>
          </div>
        </div>
      ),
    },
    {
      key: "pipeline", label: "Pipeline",
      title: "Deals you don't drop.",
      body: "Stages, amounts, the names you've been meaning to call back. Quietly tracked. Quietly nudged.",
      bullets: ["Drag through stages", "Forecast vs. last quarter", "The 'who hasn't heard from you' list"],
      icon: (
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round">
          <path d="M3 17l6-6 4 4 8-8" />
          <path d="M14 7h7v7" />
        </svg>
      ),
      widget: (
        <div className="w w-pipe">
          <div className="w-pipe-head">
            <div>
              <div className="w-pipe-label">Forecast · this quarter</div>
              <div className="w-pipe-num">$4.2M</div>
            </div>
            <div className="w-pipe-trend">
              <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"><path d="M7 17l10-10M9 7h8v8"/></svg>
              +12% wk
            </div>
          </div>
          <div className="w-pipe-progress">
            <div className="w-pipe-progress-fill" style={{ width: "62%" }} />
          </div>
          <div className="w-pipe-progress-meta">
            <span>62% to goal</span>
            <span className="w-pipe-goal">$6.8M target</span>
          </div>
          <div className="w-pipe-cols">
            <div className="w-pipe-col">
              <div className="w-pipe-stage">
                <span className="w-pipe-stage-name">Verbal</span>
                <span className="w-pipe-stage-count">2</span>
              </div>
              <div className="w-pipe-deal">
                <div className="w-pipe-deal-name">Eaton Capital</div>
                <div className="w-pipe-deal-amt">$1.4M</div>
              </div>
              <div className="w-pipe-deal">
                <div className="w-pipe-deal-name">M. Tanaka</div>
                <div className="w-pipe-deal-amt">$310K</div>
              </div>
            </div>
            <div className="w-pipe-col">
              <div className="w-pipe-stage">
                <span className="w-pipe-stage-name">Proposal</span>
                <span className="w-pipe-stage-count">1</span>
              </div>
              <div className="w-pipe-deal soft">
                <div className="w-pipe-deal-name">Riley Park</div>
                <div className="w-pipe-deal-amt">$680K</div>
              </div>
            </div>
          </div>
        </div>
      ),
    },
  ];
  return (
    <section id="how" className="pillars reveal" ref={ref}>
      <div className="wrap">
        <p className="va-section-label">How it works</p>
        <h2 className="section-title">Three things you carry in your head.<br /><span className="copper-italic">One place to put them.</span></h2>
        <p className="section-sub">Valence is built around the three nouns of independent sales: the contact, the calendar, the deal. Everything else gets out of the way.</p>

        <div className="pillar-grid">
          {items.map((it, i) => (
            <div className="pillar-pair" key={it.key}>
              <Tilt>
                <div className="pillar-card">
                  <div className="pillar-icon">{it.icon}</div>
                  <p className="va-section-label">0{i + 1} · {it.label}</p>
                  <h3 className="pillar-title">{it.title}</h3>
                  <p className="pillar-body">{it.body}</p>
                  <ul className="pillar-bullets">
                    {it.bullets.map((b, bi) => (
                      <li key={bi}><span className="dash" />{b}</li>
                    ))}
                  </ul>
                </div>
              </Tilt>
              {it.widget}
            </div>
          ))}
        </div>
      </div>

      <style>{`
        .pillars { padding: 120px 0 80px; }
        .copper-italic { font-style: italic; background: var(--va-gradient-accent); -webkit-background-clip: text; background-clip: text; color: transparent; }

        /* Two-row grid: row 1 = pillar cards, row 2 = widgets.
           Each .pillar-pair spans both rows and uses subgrid so its
           card aligns with the other cards and its widget with the
           other widgets. */
        .pillar-grid {
          display: grid; grid-template-columns: repeat(3, 1fr);
          grid-template-rows: auto auto;
          column-gap: 24px; row-gap: 28px; margin-top: 64px;
        }
        .pillar-pair {
          display: grid; grid-template-rows: subgrid;
          grid-row: span 2; row-gap: 28px;
        }
        @media (max-width: 900px) {
          .pillar-grid { grid-template-columns: 1fr; grid-template-rows: none; }
          .pillar-pair {
            grid-template-rows: auto auto;
            grid-row: auto;
            display: flex; flex-direction: column; gap: 20px;
          }
        }

        .pillar-card {
          background: var(--va-bg-card); border: 1px solid var(--va-divider);
          border-radius: 22px; padding: 32px;
          box-shadow: 0 2px 8px rgba(44,62,80,0.04);
          transition: box-shadow 0.3s, border-color 0.3s;
          will-change: transform;
          height: 100%;
          display: flex; flex-direction: column;
        }
        .pillar-card:hover { box-shadow: 0 16px 48px rgba(44,62,80,0.10); border-color: rgba(184,115,51,0.20); }
        .pillar-icon {
          width: 44px; height: 44px; border-radius: 12px;
          background: var(--va-copper-soft); color: var(--va-copper);
          display: flex; align-items: center; justify-content: center;
          margin-bottom: 24px;
        }
        .pillar-icon svg { width: 22px; height: 22px; }
        .pillar-title { font-family: var(--va-font-display); font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin: 8px 0 12px; line-height: 1.2; }
        .pillar-body { font-size: 15px; line-height: 1.55; color: var(--va-text-secondary); margin: 0 0 20px; }
        .pillar-bullets { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--va-divider); padding-top: 16px; margin-top: auto; }
        .pillar-bullets li { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--va-text-secondary); padding: 6px 0; }
        .pillar-bullets .dash { width: 14px; height: 1.5px; background: var(--va-copper); flex-shrink: 0; border-radius: 1px; }

        /* ─── App-section widget previews ─────────────────────────────── */
        .w {
          background: var(--va-bg-card);
          border: 1px solid var(--va-divider);
          border-radius: 22px;
          padding: 22px;
          font-family: var(--va-font-text);
          color: var(--va-text-primary);
          height: 100%;
          display: flex; flex-direction: column;
          box-shadow: 0 2px 8px rgba(0,0,0,0.18);
        }
        .w .w-num, .w .w-amt { font-variant-numeric: tabular-nums; }
        .w-pip { width: 5px; height: 5px; border-radius: 50%; background: var(--va-copper); display: inline-block; }

        /* Contacts widget */
        .w-contact-head { display: flex; align-items: center; gap: 12px; }
        .w-avatar {
          width: 44px; height: 44px; border-radius: 14px;
          background: var(--va-copper-soft); color: var(--va-copper);
          display: flex; align-items: center; justify-content: center;
          font-family: var(--va-font-display); font-weight: 700; font-size: 15px; letter-spacing: 0.02em;
          flex-shrink: 0;
        }
        .w-contact-id { flex: 1; min-width: 0; }
        .w-contact-name { font-family: var(--va-font-display); font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
        .w-contact-role { font-size: 12px; color: var(--va-text-secondary); margin-top: 2px; }
        .w-warmth {
          display: inline-flex; align-items: center; gap: 6px;
          padding: 5px 10px; border-radius: 999px;
          background: rgba(61, 153, 112, 0.12);
          color: var(--va-success);
          font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
        }
        .w-warmth-dot {
          width: 7px; height: 7px; border-radius: 50%;
          background: var(--va-success);
          box-shadow: 0 0 0 3px rgba(61,153,112,0.18);
          animation: w-pulse 2.4s ease-in-out infinite;
        }
        @keyframes w-pulse { 0%,100% { opacity: 0.8 } 50% { opacity: 1 } }
        .w-stat-row {
          display: grid; grid-template-columns: 1fr 1fr;
          gap: 12px; margin-top: 18px;
          padding: 14px 0; border-top: 1px solid var(--va-divider); border-bottom: 1px solid var(--va-divider);
        }
        .w-stat-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--va-text-tertiary); }
        .w-stat-value { font-family: var(--va-font-display); font-size: 15px; font-weight: 700; margin-top: 4px; }
        .w-stat-value .w-num { color: var(--va-copper); }
        .w-suggest {
          margin-top: 16px; padding: 14px;
          border-radius: 14px;
          background: var(--va-copper-soft);
          border: 1px solid rgba(184,115,51,0.20);
          display: flex; flex-direction: column; gap: 10px;
          margin-top: auto; /* pin to bottom for equal-height alignment */
        }
        .w-suggest-tag {
          display: inline-flex; align-items: center; gap: 6px;
          font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
          color: var(--va-copper);
        }
        .w-suggest-body { font-size: 13px; line-height: 1.45; color: var(--va-text-primary); }
        .w-suggest-body .w-emph { color: var(--va-copper); font-weight: 600; }
        .w-suggest-actions { display: flex; gap: 8px; }
        .w-suggest-btn {
          flex: 1;
          background: transparent; color: var(--va-text-primary);
          border: 1px solid var(--va-divider);
          padding: 8px 12px; border-radius: 10px;
          font-family: inherit; font-size: 12px; font-weight: 600;
          cursor: pointer; transition: background 0.15s;
        }
        .w-suggest-btn:hover { background: rgba(255,255,255,0.04); }
        .w-suggest-btn.primary {
          background: var(--va-gradient-accent); color: #fff; border-color: transparent;
          box-shadow: 0 4px 12px rgba(184,115,51,0.30);
        }

        /* Calendar widget */
        .w-cal-head { display: flex; align-items: flex-start; justify-content: space-between; }
        .w-cal-eyebrow { font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--va-copper); margin-bottom: 4px; }
        .w-cal-date { font-family: var(--va-font-display); font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
        .w-cal-now { font-family: var(--va-font-text); font-size: 13px; font-weight: 600; color: var(--va-text-secondary); font-variant-numeric: tabular-nums; padding: 4px 10px; background: var(--va-bg-sunken); border-radius: 999px; }
        .w-cal-rail { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
        .w-cal-slot {
          display: grid; grid-template-columns: 48px 1fr; gap: 10px;
          padding: 10px; border-radius: 12px;
          background: rgba(255,255,255,0.02);
          border: 1px solid var(--va-divider-soft);
          position: relative;
        }
        .w-cal-slot.done { opacity: 0.55; }
        .w-cal-slot.live {
          border-color: rgba(184,115,51,0.40);
          background: linear-gradient(180deg, rgba(184,115,51,0.10), rgba(184,115,51,0.04));
          box-shadow: 0 0 0 1px rgba(184,115,51,0.10);
        }
        .w-cal-spine { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--va-copper); border-radius: 3px 0 0 3px; }
        .w-cal-dot { display: none; }
        .w-cal-time { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--va-text-tertiary); font-variant-numeric: tabular-nums; padding-top: 2px; }
        .w-cal-slot.live .w-cal-time { color: var(--va-copper); }
        .w-cal-event-title { font-family: var(--va-font-display); font-weight: 700; font-size: 13px; letter-spacing: -0.005em; }
        .w-cal-event-meta { font-size: 11px; color: var(--va-text-secondary); margin-top: 2px; }
        .w-cal-pill {
          display: inline-flex; align-items: center; gap: 6px;
          margin-top: 8px; padding: 4px 10px;
          background: var(--va-copper-soft);
          color: var(--va-copper);
          border-radius: 999px;
          font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
        }

        /* Pipeline widget */
        .w-pipe { gap: 0; }
        .w-pipe-head {
          display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
        }
        .w-pipe-label { font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--va-copper); }
        .w-pipe-num { font-family: var(--va-font-display); font-weight: 700; font-size: 28px; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
        .w-pipe-trend {
          display: inline-flex; align-items: center; gap: 4px;
          padding: 4px 10px; border-radius: 999px;
          background: rgba(61,153,112,0.12); color: var(--va-success);
          font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
        }
        .w-pipe-progress {
          height: 6px; background: var(--va-bg-sunken); border-radius: 999px;
          margin-top: 16px; overflow: hidden;
        }
        .w-pipe-progress-fill {
          height: 100%; background: var(--va-gradient-accent); border-radius: 999px;
          box-shadow: 0 0 12px rgba(184,115,51,0.40);
        }
        .w-pipe-progress-meta {
          display: flex; justify-content: space-between;
          font-size: 11px; color: var(--va-text-tertiary);
          margin-top: 6px; font-variant-numeric: tabular-nums;
        }
        .w-pipe-goal { color: var(--va-text-secondary); }
        .w-pipe-cols {
          display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
          margin-top: 18px;
        }
        .w-pipe-col {
          background: var(--va-bg-sunken);
          border-radius: 12px;
          padding: 10px;
        }
        .w-pipe-stage {
          display: flex; align-items: center; justify-content: space-between;
          font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
          color: var(--va-text-tertiary);
          padding: 0 2px 8px;
          border-bottom: 1px solid var(--va-divider);
          margin-bottom: 8px;
        }
        .w-pipe-stage-count {
          background: rgba(255,255,255,0.06); color: var(--va-text-secondary);
          padding: 1px 7px; border-radius: 999px; font-size: 9px;
        }
        .w-pipe-deal {
          background: var(--va-bg-card);
          border-left: 2px solid var(--va-copper);
          border-radius: 8px;
          padding: 8px 10px;
          margin-bottom: 6px;
          box-shadow: 0 1px 2px rgba(0,0,0,0.20);
        }
        .w-pipe-deal:last-child { margin-bottom: 0; }
        .w-pipe-deal.soft { border-left-color: rgba(184,115,51,0.40); }
        .w-pipe-deal-name { font-family: var(--va-font-display); font-weight: 700; font-size: 12px; letter-spacing: -0.005em; }
        .w-pipe-deal-amt { font-size: 11px; color: var(--va-copper); font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
      `}</style>
    </section>
  );
}

// ─── Product mockups in iPhone frames ────────────────────────────────────
function Mockups() {
  const ref = useReveal();
  const phones = [
    { src: "screens/dashboard.html", label: "Dashboard", caption: "The morning landing page.", note: "Greeting, today's calendar, what needs a call." },
    { src: "screens/Calendar.html",  label: "Calendar",  caption: "Bound to the deal.",        note: "Meetings tagged to leads, prepped automatically." },
    { src: "screens/Contact.html",   label: "Contact",   caption: "Everything you know.",      note: "History, firm, opportunities — one calm screen." },
  ];
  return (
    <section id="mockups" className="mockups reveal" ref={ref}>
      <div className="wrap">
        <p className="va-section-label">The product</p>
        <h2 className="section-title">Built like a Moleskine. <br />Runs like a CRM.</h2>
        <p className="section-sub">Native iOS first. The interface is deliberately quiet — but every screen is bound to the next.</p>
      </div>

      <div className="phone-rail no-scrollbar">
        <div className="phone-row">
          {phones.map((p, i) => (
            <div key={i} className="phone-slot" style={{ transform: `translateY(${i % 2 === 0 ? -16 : 16}px)` }}>
              <div className="phoneframe">
                <div className="notch" />
                <div className="screen-host">
                  <iframe src={p.src} title={p.label} loading="lazy" scrolling="no" />
                </div>
              </div>
              <div className="phone-caption">
                <p className="va-section-label">{p.label}</p>
                <p className="caption-title">{p.caption}</p>
                <p className="caption-note">{p.note}</p>
              </div>
            </div>
          ))}
        </div>
      </div>

      <style>{`
        .mockups { padding: 80px 0 100px; background: var(--va-bg-sunken); }
        .phone-rail { overflow-x: auto; padding: 60px 32px 80px; }
        .phone-row { display: flex; gap: 56px; min-width: max-content; padding: 0 max(24px, calc((100vw - 1200px) / 2)); }
        .phone-slot { width: 320px; transition: transform 0.6s var(--va-ease); }
        .phone-caption { margin-top: 28px; max-width: 320px; }
        .caption-title { font-family: var(--va-font-display); font-size: 22px; font-weight: 700; letter-spacing: -0.01em; margin: 6px 0 6px; line-height: 1.2; }
        .caption-note { font-size: 14px; color: var(--va-text-secondary); margin: 0; line-height: 1.5; }
      `}</style>
    </section>
  );
}

// ─── A day with Valence — horizontal scroll timeline ─────────────────────
function DayTimeline() {
  const ref = useReveal();
  const moments = [
    {
      time: "07:42", title: "Good morning, Jordan.",
      detail: "Today: 3 calls · 1 site visit · Eaton Capital lease closes.",
      mini: (
        <div className="moment-mini greeting-mini">
          <div className="mini-greet">Good morning, <span className="copper-gradient">Jordan</span></div>
          <div className="mini-meta"><span className="copper-num">3</span> calls · <span className="copper-num">1</span> visit</div>
          <div className="mini-dot-bond" />
        </div>
      ),
    },
    {
      time: "09:15", title: "Floating bar — add the broker you met yesterday.",
      detail: "One field at a time. Name. Email. Firm. Save.",
      mini: (
        <div className="moment-mini bar-mini">
          <div className="mini-bar">
            <span className="mini-bar-text">Name</span>
            <div className="mini-bar-plus">+</div>
          </div>
          <div className="mini-bar-steps">
            <span className="dotstep active" /><span className="dotstep" /><span className="dotstep" /><span className="dotstep" />
          </div>
        </div>
      ),
    },
    {
      time: "11:30", title: "Lunch with Eaton Capital.",
      detail: "Calendar opens the deal beside the meeting. Three previous touches, in order.",
      mini: (
        <div className="moment-mini cal-mini">
          <div className="mini-row"><div className="mini-time">11:30</div><div className="mini-event">Eaton Capital — lunch</div></div>
          <div className="mini-row faint"><div className="mini-time">14:00</div><div className="mini-event">Riley Park site visit</div></div>
          <div className="mini-row faint"><div className="mini-time">16:30</div><div className="mini-event">Call: M. Tanaka</div></div>
        </div>
      ),
    },
    {
      time: "15:08", title: "Move Eaton to 'verbal yes.'",
      detail: "Drag a card. The pipeline updates. Forecast nudges up.",
      mini: (
        <div className="moment-mini pipe-mini">
          <div className="pipe-cols">
            <div className="pipe-col">
              <div className="pipe-head">Verbal</div>
              <div className="pipe-card">Eaton Capital<br /><span className="pipe-num">$1.4M</span></div>
            </div>
            <div className="pipe-col">
              <div className="pipe-head">Signed</div>
              <div className="pipe-card faint">—</div>
            </div>
          </div>
          <div className="pipe-trend">+ $1.4M this week</div>
        </div>
      ),
    },
    {
      time: "18:55", title: "Two names you haven't heard from in 30 days.",
      detail: "Valence noticed. A quiet nudge — not a notification storm.",
      mini: (
        <div className="moment-mini nudge-mini">
          <div className="nudge-title">2 contacts gone cold</div>
          <div className="nudge-row"><div className="avatar a1">RP</div><div><div className="nm">R. Park</div><div className="sb">last: 34 days</div></div></div>
          <div className="nudge-row"><div className="avatar a2">MT</div><div><div className="nm">M. Tanaka</div><div className="sb">last: 41 days</div></div></div>
        </div>
      ),
    },
    {
      time: "21:10", title: "Free for the rest of the day.",
      detail: "Empty state, no apology. The book of business is in order.",
      mini: (
        <div className="moment-mini done-mini">
          <div className="done-glyph">
            <svg width="32" height="32" viewBox="0 0 24 24" fill="none">
              <path d="M5 12l5 5 9-11" stroke="#B87333" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
          </div>
          <div className="done-text">Nothing today.</div>
        </div>
      ),
    },
  ];

  return (
    <section id="day" className="day reveal" ref={ref}>
      <div className="wrap">
        <p className="va-section-label">A day with Valence</p>
        <h2 className="section-title">Tuesday, in six moments.</h2>
        <p className="section-sub">No notifications. No badges. Just the right thing, at the right moment, in a voice that doesn't shout.</p>
      </div>

      <div className="day-rail no-scrollbar">
        <div className="day-track">
          <div className="day-spine" />
          {moments.map((m, i) => (
            <div key={i} className="moment">
              <div className="moment-time">{m.time}</div>
              <div className="moment-dot" />
              <div className="moment-mini-wrap">{m.mini}</div>
              <div className="moment-title">{m.title}</div>
              <div className="moment-detail">{m.detail}</div>
            </div>
          ))}
        </div>
      </div>

      <style>{`
        .day { padding: 100px 0 80px; }
        .day-rail { overflow-x: auto; padding: 60px 0 40px; margin-top: 40px; }
        .day-track { display: flex; gap: 64px; padding: 0 max(32px, calc((100vw - 1200px) / 2)); min-width: max-content; position: relative; }
        .day-spine { position: absolute; left: 32px; right: 32px; top: 38px; height: 1px; background: linear-gradient(to right, transparent, var(--va-divider) 8%, var(--va-divider) 92%, transparent); }

        .moment { width: 280px; position: relative; flex: 0 0 auto; }
        .moment-time { font-family: var(--va-font-text); font-size: 12px; font-weight: 600; letter-spacing: 0.08em; color: var(--va-text-tertiary); font-variant-numeric: tabular-nums; }
        .moment-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--va-copper); box-shadow: 0 0 0 4px var(--va-bg), 0 0 0 5px rgba(184,115,51,0.25); margin: 16px 0 24px; }
        .moment-mini-wrap { margin-bottom: 24px; height: 140px; }
        .moment-title { font-family: var(--va-font-display); font-size: 18px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; color: var(--va-text-primary); text-wrap: balance; }
        .moment-detail { font-size: 13px; color: var(--va-text-secondary); line-height: 1.5; margin-top: 8px; }

        /* moment minis */
        .moment-mini { width: 100%; height: 100%; border-radius: 16px; padding: 16px; background: var(--va-bg-card); border: 1px solid var(--va-divider); box-shadow: var(--va-shadow-card); display: flex; flex-direction: column; gap: 8px; }
        .copper-gradient { background: var(--va-gradient-accent); -webkit-background-clip: text; background-clip: text; color: transparent; }
        .copper-num { color: var(--va-copper); font-weight: 600; font-variant-numeric: tabular-nums; }

        .mini-greet { font-family: var(--va-font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
        .mini-meta { font-size: 12px; color: var(--va-text-secondary); }
        .mini-dot-bond { margin-top: auto; height: 28px; background: radial-gradient(circle at 30% 50%, rgba(184,115,51,0.18) 0, transparent 50%), radial-gradient(circle at 70% 50%, rgba(184,115,51,0.12) 0, transparent 50%); border-radius: 8px; }

        .mini-bar { background: var(--va-bg-sunken); border-radius: 999px; padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--va-text-tertiary); }
        .mini-bar-plus { background: var(--va-copper); color: white; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; }
        .mini-bar-steps { display: flex; gap: 4px; justify-content: center; margin-top: 12px; }
        .dotstep { width: 16px; height: 2px; background: var(--va-divider); border-radius: 1px; }
        .dotstep.active { background: var(--va-copper); }

        .mini-row { display: flex; align-items: center; gap: 10px; font-size: 12px; padding: 4px 0; }
        .mini-time { color: var(--va-copper); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 38px; }
        .mini-event { color: var(--va-text-primary); }
        .mini-row.faint .mini-time, .mini-row.faint .mini-event { color: var(--va-text-tertiary); }

        .pipe-cols { display: flex; gap: 6px; }
        .pipe-col { flex: 1; }
        .pipe-head { font-size: 10px; font-weight: 600; color: var(--va-text-tertiary); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
        .pipe-card { background: var(--va-bg-sunken); border-radius: 8px; padding: 6px 8px; font-size: 11px; color: var(--va-text-primary); border-left: 2px solid var(--va-copper); }
        .pipe-card.faint { color: var(--va-text-tertiary); border-color: var(--va-divider); }
        .pipe-num { color: var(--va-copper); font-weight: 600; font-variant-numeric: tabular-nums; font-size: 10px; }
        .pipe-trend { margin-top: auto; font-size: 11px; color: var(--va-success); font-weight: 500; }

        .nudge-title { font-size: 12px; font-weight: 600; color: var(--va-text-primary); margin-bottom: 4px; }
        .nudge-row { display: flex; gap: 8px; align-items: center; }
        .avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--va-copper-soft); color: var(--va-copper); font-size: 10px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
        .avatar.a2 { background: rgba(44,62,80,0.08); color: var(--va-slate); }
        .nudge-row .nm { font-size: 12px; color: var(--va-text-primary); font-weight: 500; }
        .nudge-row .sb { font-size: 10px; color: var(--va-text-tertiary); }

        .done-mini { align-items: center; justify-content: center; }
        .done-glyph { width: 48px; height: 48px; border-radius: 50%; background: var(--va-copper-soft); display: flex; align-items: center; justify-content: center; margin: auto auto 0; }
        .done-text { font-family: var(--va-font-display); font-size: 18px; font-weight: 700; color: var(--va-text-primary); letter-spacing: -0.01em; margin: 8px auto auto; }
      `}</style>
    </section>
  );
}

// ─── FAQ accordion ───────────────────────────────────────────────────────
function FAQ() {
  const ref = useReveal();
  const [openIdx, setOpenIdx] = useStateB(0);
  const items = [
    { q: "Who is Valence for?", a: "Independent operators with a book of business — commercial brokers, sales reps, agency leads, consultants, solo founders. People who already remember everything; we just give it a calmer home." },
    { q: "Is it iOS-only?", a: "iOS first, Android in the second cohort, a lightweight web companion after that. Everything syncs." },
    { q: "Does it replace Salesforce / Hubspot?", a: "For teams of one to five, yes — that's the point. For larger orgs, Valence sits beside your team CRM and feeds it. We don't try to be everything." },
    { q: "How does the waitlist work?", a: "We open seats in waves of about 50. Early signups go first. Refer a colleague and you both move up." },
    { q: "What does it cost?", a: "Free during the private beta. After that: one price, monthly or annual, no per-seat math. We'll tell waitlist members the number before launch." },
    { q: "Where does my data live?", a: "Your phone first, our encrypted store second. We never sell, share, or train on contact data — and you can export to CSV or vCard any time." },
  ];
  return (
    <section id="faq" className="faq reveal" ref={ref}>
      <div className="wrap faq-wrap">
        <div className="faq-left">
          <p className="va-section-label">FAQ</p>
          <h2 className="section-title">Questions, answered without<br /> the marketing voice.</h2>
          <p className="section-sub">Anything else, write to <a href="mailto:hello@valence.app" className="copper-link">hello@valence.app</a>. A human reads them.</p>
        </div>
        <div className="faq-right">
          {items.map((it, i) => (
            <div key={i} className={`faq-item ${openIdx === i ? "open" : ""}`}>
              <button className="faq-q" onClick={() => setOpenIdx(openIdx === i ? -1 : i)}>
                <span>{it.q}</span>
                <span className="faq-plus" aria-hidden="true">
                  <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
                    <path d="M12 5v14M5 12h14" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" />
                  </svg>
                </span>
              </button>
              <div className="faq-a-wrap">
                <div className="faq-a">{it.a}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
      <style>{`
        .faq { padding: 100px 0 80px; }
        .faq-wrap { display: grid; grid-template-columns: 1fr 1.4fr; gap: 80px; align-items: flex-start; }
        @media (max-width: 900px) { .faq-wrap { grid-template-columns: 1fr; gap: 40px; } }
        .copper-link { color: var(--va-copper); border-bottom: 1px solid currentColor; }
        .faq-item { border-bottom: 1px solid var(--va-divider); }
        .faq-q { background: transparent; border: 0; width: 100%; text-align: left; padding: 22px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; cursor: pointer; font-family: var(--va-font-display); font-size: 18px; font-weight: 600; letter-spacing: -0.005em; color: var(--va-text-primary); }
        .faq-plus { width: 30px; height: 30px; border-radius: 50%; background: var(--va-bg-sunken); display: flex; align-items: center; justify-content: center; color: var(--va-text-secondary); transition: transform var(--va-dur-medium) var(--va-ease), background 0.2s; flex-shrink: 0; }
        .faq-item:hover .faq-plus { background: var(--va-copper-soft); color: var(--va-copper); }
        .faq-item.open .faq-plus { transform: rotate(45deg); background: var(--va-copper); color: white; }
        .faq-a-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--va-dur-medium) var(--va-ease); }
        .faq-item.open .faq-a-wrap { grid-template-rows: 1fr; }
        .faq-a { overflow: hidden; padding-right: 56px; font-size: 15px; line-height: 1.6; color: var(--va-text-secondary); }
        .faq-item.open .faq-a { padding-bottom: 22px; }
      `}</style>
    </section>
  );
}

// ─── Big waitlist section near footer ────────────────────────────────────
function WaitlistSection({ tweaks }) {
  const ref = useReveal();
  const [email, setEmail] = useStateB("");
  const [hp, setHp] = useStateB("");
  const [submitted, setSubmitted] = useStateB(false);
  const [pos, setPos] = useStateB(0);
  const [submitting, setSubmitting] = useStateB(false);
  const [error, setError] = useStateB("");
  const { mountRef: tsMountRef, getToken: getTsToken } = window.useTurnstile();

  const submit = async (e) => {
    e.preventDefault();
    if (submitting) return;
    setError("");
    if (!window.EMAIL_RE.test(email)) { setError("Please enter a valid email."); return; }
    setSubmitting(true);
    try {
      const out = await window.submitWaitlistAPI({ email, hp, tsToken: getTsToken() });
      setPos(out.position);
      setSubmitted(true);
    } catch (err) {
      const code = String(err.message || "");
      setError(
        code === "turnstile_failed" ? "Please complete the verification." :
        code === "bad_email"        ? "Please enter a valid email." :
                                      "Couldn't reach the server. Try again in a moment."
      );
    } finally {
      setSubmitting(false);
    }
  };

  return (
    <section id="waitlist" className="big-wait reveal" ref={ref}>
      <div className="wrap">
        <div className="wait-card">
          <div className="wait-bg" />
          <div className="wait-inner">
            <p className="va-section-label" style={{ color: "rgba(255,255,255,0.65)" }}>Join the waitlist</p>
            <h2 className="big-title">Open a seat<br />before the next wave.</h2>
            <p className="big-sub">Private beta. <span className="big-num">487</span> on the list. Next batch this quarter.</p>

            {!submitted ? (
              <div className="big-form-wrap">
                <form className="big-form" onSubmit={submit} noValidate>
                  <input type="email" required value={email} onChange={(e) => setEmail(e.target.value)} placeholder="you@brokerage.com" aria-label="Email" autoComplete="email" />
                  <button type="submit" disabled={submitting}>{submitting ? "Sending…" : "Request access →"}</button>
                </form>
                <input
                  type="text" tabIndex={-1} autoComplete="off" aria-hidden="true"
                  name="company_url" value={hp} onChange={(e) => setHp(e.target.value)}
                  style={{ position: "absolute", left: "-9999px", width: 1, height: 1, opacity: 0 }}
                />
                <div ref={tsMountRef} className="big-turnstile" />
                {error && <p className="big-error" role="alert">{error}</p>}
              </div>
            ) : (
              <div className="big-success">
                <div className="big-success-title">You're in. Position <span className="big-num">#{pos}</span>.</div>
                <div className="big-success-sub">Share with a colleague to move up the list.</div>
                <div className="share-row">
                  <button className="share-btn" onClick={() => navigator.clipboard && navigator.clipboard.writeText(window.location.href)}>Copy referral link</button>
                  <a className="share-link" href={`mailto:?subject=Try Valence with me&body=I'm joining the Valence waitlist. ${window.location.href}`}>Email a colleague</a>
                </div>
              </div>
            )}
          </div>
        </div>
      </div>
      <style>{`
        .big-wait { padding: 60px 0 80px; }
        .wait-card { position: relative; border-radius: 32px; overflow: hidden; background: #0F1620; padding: 80px 48px; color: white; }
        .wait-bg {
          position: absolute; inset: 0; pointer-events: none;
          background:
            radial-gradient(900px 500px at 80% 100%, rgba(184,115,51,0.30) 0%, transparent 60%),
            radial-gradient(700px 400px at 0% 0%, rgba(44,62,80,0.6) 0%, transparent 60%),
            #0F1620;
        }
        .wait-inner { position: relative; max-width: 640px; }
        .big-title { font-family: var(--va-font-display); font-weight: 700; font-size: clamp(36px, 4.6vw, 60px); line-height: 1.05; letter-spacing: -0.025em; margin: 12px 0 16px; color: white; }
        .big-sub { font-size: 17px; color: rgba(255,255,255,0.7); margin: 0 0 32px; }
        .big-num { color: var(--va-copper); font-weight: 600; font-variant-numeric: tabular-nums; }
        .big-form { display: flex; gap: 8px; max-width: 520px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.12); padding: 6px; border-radius: 999px; transition: border-color 0.2s; }
        .big-form:focus-within { border-color: var(--va-copper); }
        .big-form input { flex: 1; background: transparent; border: 0; color: white; padding: 12px 18px; font-size: 15px; font-family: inherit; }
        .big-form input:focus { outline: none; }
        .big-form input::placeholder { color: rgba(255,255,255,0.4); }
        .big-form button { background: var(--va-gradient-accent); color: white; border: 0; border-radius: 999px; padding: 12px 24px; font-size: 14px; font-weight: 600; cursor: pointer; box-shadow: 0 6px 18px rgba(184,115,51,0.4); transition: transform 0.15s; }
        .big-form button:hover:not(:disabled) { transform: translateY(-1px); }
        .big-form button:disabled { opacity: 0.6; cursor: not-allowed; }
        .big-form-wrap { position: relative; max-width: 520px; }
        .big-turnstile { margin-top: 14px; min-height: 0; }
        .big-turnstile:not(:empty) { min-height: 65px; }
        .big-error { margin: 10px 0 0; font-size: 13px; color: #FF8A7A; }
        .big-success-title { font-family: var(--va-font-display); font-size: 28px; font-weight: 700; }
        .big-success-sub { color: rgba(255,255,255,0.7); margin: 8px 0 24px; }
        .share-btn { background: rgba(255,255,255,0.10); color: white; border: 1px solid rgba(255,255,255,0.14); padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 500; cursor: pointer; }
        .share-link { color: var(--va-copper); font-size: 13px; padding: 10px 12px; }
      `}</style>
    </section>
  );
}

// ─── Footer ──────────────────────────────────────────────────────────────
function Footer() {
  return (
    <footer className="foot">
      <div className="wrap foot-wrap">
        <div className="foot-left">
          <window.LockupInline light={false} />
          <p className="foot-tag">A calm CRM for the people who carry the pipeline.</p>
        </div>
        <div className="foot-links">
          <div>
            <p className="va-section-label">Product</p>
            <a href="#how">How it works</a>
            <a href="#day">A day with Valence</a>
          </div>
          <div>
            <p className="va-section-label">Company</p>
            <a href="#faq">FAQ</a>
            <a href="mailto:hello@valence.app">Contact</a>
            <a href="#">Press kit</a>
          </div>
          <div>
            <p className="va-section-label">Legal</p>
            <a href="#">Privacy</a>
            <a href="#">Terms</a>
            <a href="#">Security</a>
          </div>
        </div>
      </div>
      <div className="wrap foot-bottom">
        <span>© Valence Labs, 2026</span>
        <span>Made for the names you keep in your head.</span>
      </div>
      <style>{`
        .foot-wrap { display: grid; grid-template-columns: 1.2fr 2fr; gap: 56px; align-items: flex-start; }
        @media (max-width: 720px) { .foot-wrap { grid-template-columns: 1fr; } }
        .foot-tag { margin: 16px 0 0; color: var(--va-text-secondary); font-size: 14px; max-width: 280px; line-height: 1.5; }
        .foot-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
        .foot-links a { display: block; font-size: 14px; color: var(--va-text-secondary); padding: 5px 0; transition: color 0.15s; }
        .foot-links a:hover { color: var(--va-copper); }
        .foot-bottom { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--va-divider); display: flex; justify-content: space-between; font-size: 12px; color: var(--va-text-tertiary); }
        @media (max-width: 720px) { .foot-bottom { flex-direction: column; gap: 8px; } }
      `}</style>
    </footer>
  );
}

window.Pillars = Pillars;
window.Mockups = Mockups;
window.DayTimeline = DayTimeline;
window.FAQ = FAQ;
window.WaitlistSection = WaitlistSection;
window.Footer = Footer;
