// Sections for the Validate Before You Build landing page.

/* ── Responsive styles ───────────────────────────────────── */
const RESPONSIVE_CSS = `
  .build-hero-wrap {
    max-width: 1320px;
    margin: 0 auto;
    padding: 88px 40px 88px;
    display: flex;
    flex-direction: column;
    gap: 40px;
  }
  .build-inside-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 80px;
    align-items: center;
  }
  .build-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  .build-evidence-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
  .build-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
  }
  .build-cover-col {
    display: flex;
    justify-content: center;
    padding: 20px 40px;
  }
  .build-table-row {
    display: grid;
    grid-template-columns: 0.9fr 1fr 1.6fr;
    gap: 24px;
  }

  @media (max-width: 900px) {
    .build-hero-wrap {
      gap: 32px;
      padding: 48px 24px 56px !important;
    }
    .build-inside-grid {
      grid-template-columns: 1fr;
      gap: 40px;
      padding: 56px 24px !important;
    }
    .build-cover-col { display: none; }
    .build-stats-grid {
      grid-template-columns: 1fr;
      gap: 0;
    }
    .build-stats-grid > div {
      border-right: none !important;
      border-bottom: 1px solid var(--av-rule);
      padding-left: 0 !important;
      padding-right: 0 !important;
      padding-bottom: 20px;
      padding-top: 20px;
    }
    .build-stats-grid > div:first-child { padding-top: 0; }
    .build-stats-grid > div:last-child { border-bottom: none; padding-bottom: 0; }
    .build-evidence-grid {
      grid-template-columns: 1fr;
    }
    .build-cards-grid {
      grid-template-columns: 1fr;
    }
    .build-section-pad {
      padding: 64px 24px 48px !important;
    }
    .build-closing-inner {
      padding: 72px 24px 64px !important;
    }
    .build-footer {
      padding: 24px 24px !important;
      flex-direction: column !important;
      align-items: flex-start !important;
      gap: 12px !important;
    }
    .build-table-row {
      grid-template-columns: 1fr;
      gap: 6px;
    }
  }

  @media (max-width: 480px) {
    .build-hero-wrap { padding: 36px 20px 48px !important; }
    .build-inside-grid { padding: 48px 20px !important; }
    .build-section-pad { padding: 56px 20px 40px !important; }
    .build-closing-inner { padding: 64px 20px 56px !important; }
    .build-footer { padding: 24px 20px !important; }
  }
`;

const ResponsiveStyles = () => (
  <style dangerouslySetInnerHTML={{ __html: RESPONSIVE_CSS }} />
);

const softTint = (hex) => `${hex}14`;

/* ── NavBar ──────────────────────────────────────────────── */
const BuildNavBar = () => (
  <>
    <ResponsiveStyles />
    <header style={{
      background: "var(--av-canvas)",
      borderBottom: "1px solid var(--av-rule)",
    }}>
      <div style={{
        maxWidth: 1320, margin: "0 auto", padding: "0 40px", height: 75,
        display: "flex", justifyContent: "space-between", alignItems: "center",
      }}>
        <a href="https://algoverde.ai" aria-label="AlgoVerde — home"
          style={{ display: "inline-flex", alignItems: "center", textDecoration: "none" }}>
          <BuildLogo width={170} />
        </a>
      </div>
    </header>
  </>
);

/* ── Hero ─────────────────────────────────────────────────── */
const BuildHeroSection = ({ Italic, t, accent }) => (
  <section>
    <div className="build-hero-wrap">
      <BuildEyebrow color={t.accentColor}>{t.eyebrowText}</BuildEyebrow>

      <h1 style={{
        fontFamily: "var(--font-sans)", fontWeight: 600,
        fontSize: "clamp(42px, 6.4vw, 88px)", lineHeight: 0.98, letterSpacing: "-0.038em",
        color: "var(--av-ink)", margin: 0, maxWidth: 1180, textWrap: "balance",
      }}>
        Validate <Italic>before</Italic> you build.
      </h1>

      <p style={{
        fontSize: "clamp(16px, 2vw, 21px)", lineHeight: 1.5, color: "var(--av-ink-soft)",
        fontFamily: "var(--font-sans)", margin: 0, maxWidth: 800, textWrap: "pretty",
      }}>
        How automakers can put customers in the room before the capital is committed,
        with a living AI model of the market that moves customer learning to the front
        of the vehicle program, while the product can still change.
      </p>

      {/* CTA row */}
      <div style={{ display: "flex", gap: 14, alignItems: "center", flexWrap: "wrap" }}>
        <a href={BUILD_PDF} download onClick={() => buildTrackDownload("hero")} style={{
          background: "var(--av-ink)", color: "#fff", border: "none",
          padding: "17px 28px", borderRadius: 10, fontSize: 15.5, fontWeight: 500,
          cursor: "pointer", fontFamily: "var(--font-sans)", textDecoration: "none",
          display: "inline-flex", alignItems: "center", gap: 12,
          transition: "background 160ms ease, transform 160ms ease",
          letterSpacing: "-0.005em",
        }}
          onMouseEnter={(e) => { e.currentTarget.style.background = accent; e.currentTarget.style.transform = "translateY(-1px)"; }}
          onMouseLeave={(e) => { e.currentTarget.style.background = "var(--av-ink)"; e.currentTarget.style.transform = "none"; }}
        >
          <span>{t.ctaLabel}</span>
        </a>
        <a href="#inside" style={{
          fontSize: 14, fontWeight: 500, color: "var(--av-ink-soft)",
          textDecoration: "none", padding: "14px 8px",
          display: "inline-flex", alignItems: "center", gap: 8,
          transition: "color 160ms ease",
        }}
          onMouseEnter={(e) => e.currentTarget.style.color = accent}
          onMouseLeave={(e) => e.currentTarget.style.color = "var(--av-ink-soft)"}
        >
          <span>See what's inside</span>
          <span>↓</span>
        </a>
      </div>

      {/* Proof row */}
      <div className="build-stats-grid" style={{
        marginTop: 16, paddingTop: 36, borderTop: "1px solid var(--av-rule)",
      }}>
        {[
          { k: "Front-end journey", v: <><span style={{ color: "var(--av-ink-muted)", textDecoration: "line-through", fontWeight: 500 }}>12–18</span> <span style={{ color: accent }}>3–4 months</span></>, note: "Idea to vehicle concept at one global automaker" },
          { k: "Rank correlation", v: <span style={{ color: accent }}>0.97</span>, note: "GenAI Personas vs. a human panel, across ten sentiment drivers" },
          { k: "Blind backtest", v: <span style={{ color: accent }}>96.3%</span>, note: "Agreement with a 2,100-person human study" },
        ].map((s, i) => (
          <div key={i} style={{
            paddingRight: 24, borderRight: i < 2 ? "1px solid var(--av-rule)" : "none",
            paddingLeft: i > 0 ? 24 : 0,
          }}>
            <div style={{
              fontSize: 11, fontWeight: 500, letterSpacing: "0.18em",
              textTransform: "uppercase", color: "var(--av-ink-muted)", marginBottom: 10,
            }}>{s.k}</div>
            <div style={{
              fontSize: 26, fontWeight: 600, letterSpacing: "-0.02em",
              color: "var(--av-ink)", lineHeight: 1.1, marginBottom: 8,
              fontVariantNumeric: "tabular-nums",
            }}>{s.v}</div>
            <div style={{ fontSize: 12, color: "var(--av-ink-muted)", lineHeight: 1.45 }}>{s.note}</div>
          </div>
        ))}
      </div>
    </div>
  </section>
);

/* ── Inside the Paper ────────────────────────────────────── */
const BuildInsideSection = ({ t, Italic }) => (
  <section id="inside" style={{
    background: "#fff", borderTop: "1px solid var(--av-rule)", borderBottom: "1px solid var(--av-rule)",
  }}>
    <div className="build-inside-grid" style={{ maxWidth: 1320, margin: "0 auto", padding: "80px 40px" }}>
      <div className="build-cover-col">
        <BuildCover width={280} rotate={-4} />
      </div>
      <div style={{ display: "flex", flexDirection: "column", gap: 24, maxWidth: 640 }}>
        <BuildEyebrow color={t.accentColor}>Inside the paper</BuildEyebrow>
        <h2 style={{
          fontFamily: "var(--font-sans)", fontWeight: 600,
          fontSize: "clamp(32px, 4vw, 44px)", letterSpacing: "-0.025em", lineHeight: 1.05, margin: 0,
        }}>
          The bets <Italic>before</Italic> the build.
        </h2>
        <p style={{
          fontSize: "clamp(15px, 1.8vw, 17px)", color: "var(--av-ink-soft)", lineHeight: 1.55, margin: 0,
        }}>
          Every vehicle program starts as a set of bets: who will buy it, what they will
          value, and which features will earn their place. The paper walks through the three
          bets automakers make before tooling, with a real program example at each one.
        </p>
        <div style={{ marginTop: 12 }}>
          {[
            "The bets before the build",
            "One foundation that compounds",
            "Customers you can question",
            "Bet #1: Define the audience",
            "Bet #2: Develop the concept",
            "Bet #3: Refine the proposition",
            "Built around your process, defensible by design",
            "Start with one decision",
          ].map((title, i) => (
            <BuildTocChip key={i} idx={["i","ii","iii","iv","v","vi","vii","viii"][i]} color={t.accentColor}>
              {title}
            </BuildTocChip>
          ))}
        </div>
      </div>
    </div>
  </section>
);

/* ── Problem / Foundation Section ────────────────────────── */
const BuildProblemSection = ({ accent, Italic, t }) => (
  <section className="build-section-pad"
    style={{ maxWidth: 1320, margin: "0 auto", padding: "96px 40px 64px" }}>

    {/* Pull quote */}
    <div style={{
      borderLeft: `4px solid ${accent}`,
      paddingLeft: 28, marginBottom: 56, maxWidth: 820,
    }}>
      <p style={{
        fontFamily: "var(--font-serif)", fontStyle: "italic", fontWeight: 500,
        fontSize: "clamp(20px, 2.5vw, 26px)", lineHeight: 1.45,
        color: "var(--av-ink)", margin: 0,
      }}>
        "The bigger gain was not the speed. It was learning early enough to act on what
        customers said."
      </p>
    </div>

    {/* Three bets */}
    <div style={{ marginBottom: 28, maxWidth: 720 }}>
      <p style={{ fontSize: "clamp(15px, 1.8vw, 17px)", color: "var(--av-ink-soft)", lineHeight: 1.55, margin: 0 }}>
        By the time customer evidence arrives, many of a program's bets are already locked into
        budgets, briefs and engineering plans. The paper brings customer evidence to three of them.
      </p>
    </div>
    <div className="build-cards-grid" style={{ marginBottom: 64 }}>
      {[
        { n: "1", title: "Define the audience", body: "Whom to retain, whom to attract, and where needs remain unmet." },
        { n: "2", title: "Develop the concept", body: "Turn “enter the three-row segment” into an actual product." },
        { n: "3", title: "Refine the proposition", body: "Look past a positive score to what actually drives choice." },
      ].map((c) => (
        <div key={c.n} style={{
          background: "#fdeae3", borderRadius: 16, padding: "28px",
          display: "flex", flexDirection: "column", gap: 14,
        }}>
          <span style={{
            width: 30, height: 30, borderRadius: "50%", background: "#E64A19",
            color: "#fff", display: "flex", alignItems: "center", justifyContent: "center",
            fontSize: 12, fontWeight: 700, fontFamily: "var(--font-sans)",
          }}>{c.n}</span>
          <div style={{
            fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 18,
            color: "var(--av-ink)", letterSpacing: "-0.01em",
          }}>{c.title}</div>
          <p style={{ fontSize: 14, color: "var(--av-ink-soft)", lineHeight: 1.55, margin: 0 }}>{c.body}</p>
        </div>
      ))}
    </div>

    {/* Two-col: milestone research vs one foundation */}
    <div className="build-evidence-grid">
      <div style={{
        background: "#fff", border: "1px solid var(--av-rule)", borderRadius: 16,
        padding: "36px", display: "flex", flexDirection: "column", gap: 20,
      }}>
        <div style={{
          fontSize: 11, fontWeight: 500, letterSpacing: "0.18em",
          textTransform: "uppercase", color: "var(--av-ink-muted)",
          display: "flex", alignItems: "center", gap: 8,
        }}>
          <span style={{ width: 20, height: 2, background: "var(--av-ink-muted)" }}></span>
          Today
        </div>
        <h3 style={{
          fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 22,
          letterSpacing: "-0.015em", color: "var(--av-ink)", lineHeight: 1.2, margin: 0,
        }}>Research runs on milestones. Questions don't.</h3>
        <p style={{ fontSize: 14, color: "var(--av-ink-soft)", lineHeight: 1.6, margin: 0 }}>
          A new powertrain reopens the audience question. An interior change creates a new
          trade-off. A competitor launch moves the benchmark. Brief, fieldwork, analysis,
          debrief: insights often land after the decision they should have shaped, built on
          customer knowledge scattered across old studies, slide decks and engineering files.
        </p>
      </div>

      <div style={{
        background: softTint(accent), border: `1px solid ${accent}33`, borderRadius: 16,
        padding: "36px", display: "flex", flexDirection: "column", gap: 20,
      }}>
        <div style={{
          fontSize: 11, fontWeight: 500, letterSpacing: "0.18em",
          textTransform: "uppercase", color: accent,
          display: "flex", alignItems: "center", gap: 8,
        }}>
          <span style={{ width: 20, height: 2, background: accent }}></span>
          With AlgoVerde
        </div>
        <h3 style={{
          fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 22,
          letterSpacing: "-0.015em", color: "var(--av-ink)", lineHeight: 1.2, margin: 0,
        }}>One Living AI Model of your market.</h3>
        <div style={{ display: "flex", flexDirection: "column", gap: 14 }}>
          {[
            { label: "Company Know-How" },
            { label: "Market Intelligence" },
            { label: "GenAI Personas" },
            { label: "Company Profile" },
          ].map((row, i) => (
            <div key={i} style={{
              padding: "12px 0",
              borderTop: "1px solid var(--av-rule-soft)",
              display: "flex", gap: 14, alignItems: "center",
            }}>
              <span style={{
                width: 8, height: 8, borderRadius: "50%",
                background: accent, flexShrink: 0,
              }}></span>
              <div style={{ fontSize: 14, fontWeight: 600, color: "var(--av-ink)" }}>{row.label}</div>
            </div>
          ))}
        </div>
        <p style={{ fontSize: 12, color: "var(--av-ink-muted)", lineHeight: 1.5, margin: 0 }}>
          How the four connect, and why the model gets more useful with every decision: inside the paper.
        </p>
      </div>
    </div>
  </section>
);

/* ── Trust: validated against human research ─────────────── */
const BuildTrustSection = ({ accent, t, Italic }) => {
  const rows = [
    { test: "Blind backtest", against: "A 2,100-person human study", result: "96.3% agreement, mean absolute error of 3.7 points" },
    { test: "Parallel foresight study", against: "An automotive OEM's own foresight study", result: "Scenarios assessed as aligned and comparable to the established research process" },
  ];
  return (
    <section className="build-section-pad"
      style={{ maxWidth: 1320, margin: "0 auto", padding: "64px 40px 96px" }}>
      <div style={{ marginBottom: 40, maxWidth: 760 }}>
        <BuildEyebrow color={t.accentColor}>Customers you can question</BuildEyebrow>
        <h2 style={{
          fontFamily: "var(--font-sans)", fontWeight: 600,
          fontSize: "clamp(32px, 4vw, 48px)", letterSpacing: "-0.028em", lineHeight: 1.05,
          marginTop: 18, marginBottom: 16,
        }}>
          Skepticism is the <Italic>right starting point</Italic>.
        </h2>
        <p style={{ fontSize: "clamp(15px, 1.8vw, 17px)", color: "var(--av-ink-soft)", lineHeight: 1.6 }}>
          GenAI Personas are purpose-built models of your customer segments, neither twins of
          individual buyers nor stock AI characters. They were tested head to head against
          human research.
        </p>
      </div>

      {rows.map((r, i) => (
        <div key={i} className="build-table-row" style={{
          padding: "20px 0", borderBottom: "1px solid var(--av-rule-soft)",
          borderTop: i === 0 ? "1px solid var(--av-rule)" : "none", alignItems: "baseline",
        }}>
          <div style={{
            fontSize: 11, fontWeight: 500, letterSpacing: "0.12em", textTransform: "uppercase",
            color: "var(--av-ink-muted)",
          }}>{r.test}</div>
          <div style={{ fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 15, color: "var(--av-ink)" }}>{r.against}</div>
          <div style={{ fontSize: 14, color: accent, fontWeight: 500, lineHeight: 1.5 }}>{r.result}</div>
        </div>
      ))}
      <p style={{ fontSize: 13, color: "var(--av-ink-muted)", lineHeight: 1.5, marginTop: 16, marginBottom: 0 }}>
        The full validation set, and the segment where the personas went further than the
        traditional study, are in the paper.
      </p>
    </section>
  );
};

/* ── Proof: automotive examples ──────────────────────────── */
const BuildExamplesSection = ({ accent, t, Italic }) => {
  const rows = [
    { stage: "Define the audience", project: "Identifying audiences for growth", outcome: "Cohorts for retention and growth, for the relaunch of a successful model" },
    { stage: "Develop the concept", project: "Separating aspiration from everyday needs", outcome: "What buyers want a vehicle to represent, versus what it must deliver every day" },
    { stage: "Refine the proposition", project: "Addressing barriers within existing constraints", outcome: "Options to ease hesitation on an offer whose specifications were already fixed" },
  ];
  return (
    <section style={{ background: "#fff", borderTop: "1px solid var(--av-rule)", borderBottom: "1px solid var(--av-rule)" }}>
      <div className="build-section-pad" style={{ maxWidth: 1320, margin: "0 auto", padding: "96px 40px 80px" }}>
        <div style={{ marginBottom: 48, maxWidth: 760 }}>
          <BuildEyebrow color={t.accentColor}>From the paper</BuildEyebrow>
          <h2 style={{
            fontFamily: "var(--font-sans)", fontWeight: 600,
            fontSize: "clamp(32px, 4vw, 48px)", letterSpacing: "-0.028em", lineHeight: 1.05,
            marginTop: 18, marginBottom: 16,
          }}>
            The evidence moved. <Italic>So did the concept</Italic>.
          </h2>
          <p style={{ fontSize: "clamp(15px, 1.8vw, 17px)", color: "var(--av-ink-soft)", lineHeight: 1.6 }}>
            In one vehicle program, AlgoVerde linked customer exploration directly to concept
            creation and produced multiple developed vehicle concepts.
          </p>
        </div>

        <div style={{
          background: accent, borderRadius: 16, color: "#fff",
          padding: "32px 36px", marginBottom: 56, maxWidth: 900,
        }}>
          <p style={{ fontSize: 16, lineHeight: 1.6, margin: 0 }}>
            As new evidence emerged about the EV transition and customer preferences, the team
            revisited core product assumptions and adjusted the concept direction, while there
            was still room to act and before major technology commitments were made.
          </p>
        </div>

        <div style={{ marginBottom: 24 }}>
          <BuildEyebrow color={t.accentColor}>Across the three bets</BuildEyebrow>
          <h3 style={{
            fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: "clamp(24px, 3vw, 32px)",
            letterSpacing: "-0.02em", marginTop: 16,
          }}>A glimpse of the other programs.</h3>
        </div>

        {rows.map((r, i) => (
          <div key={i} className="build-table-row" style={{
            padding: "20px 0", borderBottom: "1px solid var(--av-rule-soft)", alignItems: "baseline",
          }}>
            <div style={{
              fontSize: 11, fontWeight: 500, letterSpacing: "0.12em", textTransform: "uppercase",
              color: "var(--av-ink-muted)",
            }}>{r.stage}</div>
            <div style={{ fontFamily: "var(--font-sans)", fontWeight: 600, fontSize: 15, color: "var(--av-ink)" }}>{r.project}</div>
            <div style={{ fontSize: 14, color: accent, fontWeight: 500, lineHeight: 1.5 }}>{r.outcome}</div>
          </div>
        ))}
        <p style={{ fontSize: 13, color: "var(--av-ink-muted)", lineHeight: 1.5, marginTop: 16, marginBottom: 0 }}>
          Plus what drives consideration when a proposition tests well, and what each team
          changed as a result. The full breakdown is in the paper.
        </p>
      </div>
    </section>
  );
};

/* ── Closing CTA ─────────────────────────────────────────── */
const BuildClosingCTA = ({ t, accent, accentTint }) => (
  <section style={{
    background: "var(--av-bg-dark)", color: "#fff", position: "relative", overflow: "hidden",
  }}>
    <div style={{ position: "absolute", top: 0, left: 0, right: 0, height: 2, background: accent }}></div>
    <div className="build-closing-inner" style={{
      maxWidth: 1320, margin: "0 auto", padding: "96px 40px 88px",
      display: "flex", flexDirection: "column", alignItems: "center",
      gap: 36, textAlign: "center",
    }}>
      <h2 style={{
        fontFamily: "var(--font-sans)", fontWeight: 600,
        fontSize: "clamp(32px, 5vw, 64px)", letterSpacing: "-0.03em", lineHeight: 1.02,
        margin: 0, color: "#fff", maxWidth: 900, textWrap: "balance",
      }}>
        Bring customer learning forward,<br />
        <span style={{ fontFamily: "var(--font-serif)", fontStyle: "italic", fontWeight: 500, color: accentTint }}>
          while the product can still change
        </span>.
      </h2>
      <p style={{
        fontSize: "clamp(15px, 1.8vw, 17px)", color: "rgba(255,255,255,0.65)", lineHeight: 1.6,
        margin: 0, maxWidth: 600,
      }}>
        Explore audience choices, concept directions and proposition trade-offs before major
        development commitments are made. Start with one well-chosen decision.
      </p>
      <div style={{ display: "flex", flexDirection: "column", alignItems: "center", gap: 14, marginTop: 8 }}>
        <a href={BUILD_PDF} download onClick={() => buildTrackDownload("closing")} style={{
          background: "#fff", color: "var(--av-ink)", border: "none",
          padding: "18px 32px", borderRadius: 10, fontSize: 16, fontWeight: 500,
          cursor: "pointer", fontFamily: "var(--font-sans)", textDecoration: "none",
          display: "inline-flex", alignItems: "center", gap: 14,
          transition: "transform 160ms ease, background 160ms ease",
          letterSpacing: "-0.005em",
        }}
          onMouseEnter={(e) => { e.currentTarget.style.transform = "translateY(-2px)"; e.currentTarget.style.background = accentTint; }}
          onMouseLeave={(e) => { e.currentTarget.style.transform = "none"; e.currentTarget.style.background = "#fff"; }}
        >
          <span>{t.ctaLabel}</span>
        </a>
        <div style={{ fontSize: 12, color: "rgba(255,255,255,0.5)", letterSpacing: "0.04em" }}>
          Free PDF · No email required · Automotive product planning
        </div>
      </div>
    </div>
  </section>
);

Object.assign(window, {
  BuildNavBar, BuildHeroSection, BuildInsideSection,
  BuildProblemSection, BuildTrustSection, BuildExamplesSection, BuildClosingCTA,
});
