// site/sections-a.jsx — nav · hero (team amplified) · outcomes strip · why · how
const { useState: aUS, useEffect: aUE } = React;

// ════════════════════════════════════════════════════════════════════════
//  NAV
// ════════════════════════════════════════════════════════════════════════
function Nav({ theme, setTheme }) {
  const links = [
    { h: "#how", t: "How it works" },
    { h: "#engine", t: "The engine" },
    { h: "#cost", t: "AI cost" },
    { h: "#story", t: "Our story" },
  ];
  return (
    <nav className="site-nav">
      <Logo size={30} />
      <span style={{ flex: 1 }} />
      <div style={{ display: "flex", alignItems: "center", gap: 22 }} className="nav-links-wrap">
        {links.map(l => <a key={l.h} href={l.h} className="navlink">{l.t}</a>)}
      </div>
      <span style={{ width: 1, height: 22, background: "var(--border-2)" }} className="nav-sep" />
      <button className="btn" data-variant="ghost" style={{ height: 32, width: 32, padding: 0, justifyContent: "center" }}
        onClick={() => setTheme(theme === "dark" ? "light" : "dark")} title="Toggle theme" aria-label="Toggle theme">
        <Ico name={theme === "dark" ? "sun" : "moon"} size={15} />
      </button>
      <a className="btn" data-variant="primary" data-book="1" href="#cta" style={{ height: 34, textDecoration: "none" }}>
        Book a walkthrough <Ico name="arrowR" size={13} className="arr" />
      </a>
    </nav>
  );
}

// ════════════════════════════════════════════════════════════════════════
//  HERO — SEE, the Software Engineering Engine (the engine diagram is the hero)
// ════════════════════════════════════════════════════════════════════════
const ENGINE_STAGES = [
  { short: "Govern", icon: "target", n: 3, tier: "portfolio" },
  { short: "Design", icon: "sparkle", n: 3, tier: "product" },
  { short: "Platform", icon: "shield", n: 2, tier: "product" },
  { short: "Build", icon: "box", n: 4, tier: "developer" },
  { short: "Quality", icon: "check", n: 4, tier: "helper" },
  { short: "Implement", icon: "dispatch", n: 2, tier: "helper" },
  { short: "Support", icon: "refresh", n: 2, tier: "helper" },
];

function EngineDiagram() {
  return (
    <div style={{ position: "relative", borderRadius: "var(--r-4)", background: "var(--bg-raised)", border: "var(--hairline) solid var(--border-2)",
      boxShadow: "0 1px 0 oklch(1 0 0 / 0.04) inset, 0 30px 80px -20px oklch(from var(--accent) calc(l - 0.35) c h / 0.45), 0 12px 40px oklch(0 0 0 / 0.45)",
      padding: "22px 22px 20px", overflow: "hidden" }}>
      {/* header: the engine identity */}
      <div style={{ display: "flex", alignItems: "center", gap: 12, paddingBottom: 18, borderBottom: "var(--hairline) solid var(--border-1)" }}>
        <Mark size={40} />
        <div style={{ flex: 1, minWidth: 0 }}>
          <div style={{ display: "flex", alignItems: "center", gap: 8 }}>
            <span style={{ fontFamily: DISP_F, fontSize: 19, color: "var(--accent)", letterSpacing: "-0.01em", fontWeight: 600 }}>SEE</span>
            <span style={{ fontSize: 11, color: "var(--fg-3)", letterSpacing: "0.12em", textTransform: "uppercase" }}>Software Engineering Engine</span>
          </div>
          <div style={{ fontSize: 12, color: "var(--fg-3)", marginTop: 2 }}>20+ senior roles · the complete value stream</div>
        </div>
        <span className="badge" data-tone="ok" style={{ height: 22, flexShrink: 0 }}><span className="dot" />running</span>
      </div>

      {/* the value stream — idea → production */}
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", margin: "16px 2px 12px" }}>
        <span className="mono" style={{ fontSize: 10.5, color: "var(--fg-3)", letterSpacing: "0.08em" }}>IDEA</span>
        <span className="mono" style={{ fontSize: 10.5, color: "var(--fg-3)", letterSpacing: "0.08em" }}>IN PRODUCTION</span>
      </div>
      <div style={{ display: "flex", alignItems: "stretch", gap: 0 }}>
        {ENGINE_STAGES.map((s, i) => (
          <React.Fragment key={s.short}>
            <div style={{ flex: 1, display: "flex", flexDirection: "column", alignItems: "center", gap: 8, textAlign: "center", minWidth: 0 }}>
              <span style={{ width: 38, height: 38, borderRadius: 10, background: "var(--accent-soft)", color: "var(--accent)", display: "grid", placeItems: "center", border: "var(--hairline) solid var(--accent-border)" }}><Ico name={s.icon} size={18} /></span>
              <span style={{ fontSize: 11.5, fontWeight: 600, color: "var(--fg-1)", lineHeight: 1.15 }}>{s.short}</span>
              <span style={{ display: "inline-flex", alignItems: "center", gap: 5 }}>
                <span className="tier-stripe" data-tier={s.tier} style={{ width: 3, height: 12, borderRadius: 2 }} />
                <span className="mono" style={{ fontSize: 10.5, color: "var(--fg-3)" }}>{s.n} roles</span>
              </span>
            </div>
            {i < ENGINE_STAGES.length - 1 && (
              <span style={{ display: "flex", alignItems: "center", paddingTop: 11, color: "var(--border-3)", flexShrink: 0 }}><Ico name="chevR" size={14} /></span>
            )}
          </React.Fragment>
        ))}
      </div>

      {/* base: the two differentiators */}
      <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginTop: 20, paddingTop: 16, borderTop: "var(--hairline) solid var(--border-1)" }}>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 7, fontSize: 12, color: "var(--fg-2)", background: "var(--accent-softer)", border: "var(--hairline) solid var(--accent-border)", borderRadius: 999, padding: "5px 12px" }}>
          <Ico name="refresh" size={13} c="var(--accent)" /> Self-correcting — improves every run
        </span>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 7, fontSize: 12, color: "var(--fg-2)", background: "var(--bg-sunken)", border: "var(--hairline) solid var(--border-2)", borderRadius: 999, padding: "5px 12px" }}>
          <Ico name="check" size={13} c="var(--ok)" stroke={2.2} /> Your team approves what ships
        </span>
      </div>
    </div>
  );
}

const HEADLINES = {
  engine: <>Your software roadmap,<br />delivered by <span style={{ color: "var(--accent)" }}>SEE.</span></>,
  see: <>One problem. The right<br />AI team. <span style={{ color: "var(--accent)" }}>Reviewable work.</span></>,
  cost: <>Senior-grade delivery,<br />a <span style={{ color: "var(--accent)" }}>fraction of the AI bill.</span></>,
};

function Hero({ headline = "engine", showProof = true }) {
  return (
    <header id="top" style={{ position: "relative", overflow: "hidden", borderBottom: "var(--hairline) solid var(--border-1)" }}>
      <div className="glow" style={{ width: 620, height: 620, top: -260, left: "8%", background: "oklch(from var(--accent) l c h / 0.16)" }} />
      <div className="glow" style={{ width: 460, height: 460, top: -120, right: "4%", background: "oklch(from var(--tier-portfolio) l c h / 0.10)" }} />
      <div className="grid-bg" style={{ position: "absolute", inset: 0, zIndex: 0 }} />
      <div style={{ position: "relative", zIndex: 1, maxWidth: 1180, margin: "0 auto", padding: "76px 32px 88px",
        display: "grid", gridTemplateColumns: "1.02fr 1.08fr", gap: 56, alignItems: "center" }} className="hero-grid">
        <div>
          <div style={{ display: "inline-flex", alignItems: "center", gap: 8, height: 28, padding: "0 13px 0 9px", borderRadius: 999,
            background: "var(--bg-raised)", border: "var(--hairline) solid var(--border-2)", marginBottom: 24 }}>
            <span style={{ width: 6, height: 6, borderRadius: 3, background: "var(--accent)" }} />
            <span style={{ fontSize: 12, color: "var(--fg-2)" }}><strong style={{ color: "var(--accent)", fontWeight: 600 }}>SEE</strong> — the Software Engineering Engine</span>
          </div>
          <h1 className="h-display" style={{ fontSize: "clamp(38px, 5vw, 58px)", margin: 0 }}>
            {HEADLINES[headline] || HEADLINES.engine}
          </h1>
          <p style={{ fontSize: 17, lineHeight: 1.55, color: "var(--fg-2)", maxWidth: 520, marginTop: 22 }}>
            wakalix is the complete software engineering engine — senior AI roles covering every stage: strategy, product, platform, build, quality, implementation, and ongoing support. One connected system alongside your team. Start with one real problem to prove it works. The same engine scales to your whole engineering organization.
          </p>
          <div style={{ display: "flex", gap: 12, marginTop: 30, flexWrap: "wrap" }}>
            <a className="btn btn-lg" data-variant="primary" data-book="1" href="#cta" style={{ textDecoration: "none" }}>
              Book a walkthrough <Ico name="arrowR" size={14} className="arr" />
            </a>
            <a className="btn btn-lg" href="#usecases" style={{ textDecoration: "none" }}>Bring one problem</a>
          </div>
        </div>
        <div className="reveal hero-shot">
          <EngineDiagram />
        </div>
      </div>
      {showProof && <OutcomeStrip />}
    </header>
  );
}

function OutcomeStrip() {
  const items = [
    { icon: "target", t: "Start with one problem" },
    { icon: "bolt", t: "Real results in 2 weeks" },
    { icon: "coin", t: "AI spend, capped & proven" },
    { icon: "layers", t: "Grow role by role" },
    { icon: "x", t: "Cancel anytime" },
  ];
  return (
    <div style={{ position: "relative", zIndex: 1, borderTop: "var(--hairline) solid var(--border-1)", background: "var(--bg-base)" }}>
      <div style={{ maxWidth: 1180, margin: "0 auto", padding: "22px 32px", display: "flex", flexWrap: "wrap", alignItems: "center", justifyContent: "center", gap: "14px 30px" }} className="outcome-strip">
        {items.map((s, i) => (
          <span key={i} style={{ display: "inline-flex", alignItems: "center", gap: 9 }}>
            <span style={{ width: 24, height: 24, borderRadius: 7, background: "var(--accent-soft)", color: "var(--accent)", display: "grid", placeItems: "center", flexShrink: 0 }}><Ico name={s.icon} size={13} /></span>
            <span style={{ fontSize: 13, color: "var(--fg-2)", fontWeight: 500, whiteSpace: "nowrap" }}>{s.t}</span>
          </span>
        ))}
      </div>
    </div>
  );
}

// ════════════════════════════════════════════════════════════════════════
//  WHY — the gap, in the customer's words
// ════════════════════════════════════════════════════════════════════════
function Why() {
  return (
    <Section id="why" pad="82px 32px" max={900}>
      <div className="reveal" style={{ textAlign: "center" }}>
        <Eyebrow icon="bolt">The gap</Eyebrow>
        <h2 className="h-section" style={{ fontSize: "clamp(28px, 3.4vw, 40px)", margin: 0 }}>
          AI tools give your engineers autocomplete.<br />Your roadmap needs <span style={{ color: "var(--accent)" }}>delivered work.</span>
        </h2>
        <p style={{ fontSize: 16.5, lineHeight: 1.6, color: "var(--fg-2)", maxWidth: 640, margin: "22px auto 0" }}>
          Copilots help one person type faster — and quietly run up an unpredictable token bill. The backlog still waits on people you can't hire fast enough. wakalix puts senior AI specialists on real jobs — a whole change, tested and corrected — and hands your team finished work to approve. Capable enough to ship. Disciplined enough to stay on budget.
        </p>
      </div>
    </Section>
  );
}

// ════════════════════════════════════════════════════════════════════════
//  HOW — start small, grow + the self-correcting engine
// ════════════════════════════════════════════════════════════════════════
function How() {
  const steps = [
    { n: "01", t: "Bring one problem", d: "A feature that's been stuck, a flaky test suite, a migration nobody has time for. One real thing — not a six-month plan." },
    { n: "02", t: "Your AI team forms", d: "The specialists the job needs — dev, review, test, architect — briefed on your codebase, conventions and guardrails." },
    { n: "03", t: "It corrects its own work", d: "Before a person ever sees it, the work is reviewed, tested and fixed against your bar. Each miss becomes a permanent guardrail." },
    { n: "04", t: "You review and ship", d: "Approve real, reviewable work delivered into your systems, then grow role by role. Cancel any time — the work is yours to keep." },
  ];
  return (
    <Section id="how" bg="var(--bg-base)" style={{ borderTop: "var(--hairline) solid var(--border-1)", borderBottom: "var(--hairline) solid var(--border-1)" }}>
      <div className="reveal" style={{ maxWidth: 720, marginBottom: 48 }}>
        <Eyebrow icon="route">How it works</Eyebrow>
        <h2 className="h-section" style={{ fontSize: "clamp(28px, 3.6vw, 42px)", margin: 0 }}>Start small. It gets better as it goes.</h2>
        <p style={{ fontSize: 16, lineHeight: 1.6, color: "var(--fg-2)", marginTop: 18 }}>
          No big migration, no rip-and-replace. You bring one problem and the engine works it — checking and correcting itself along the way. If you like what you see, you grow.
        </p>
      </div>
      {/* horizontal timeline with a continuous rail */}
      <div className="how-timeline reveal">
        <div className="how-rail" aria-hidden="true"></div>
        {steps.map((s, i) => (
          <div key={i} className="how-step">
            <span className="num-badge" style={{ position: "relative", zIndex: 1, background: "var(--bg-base)" }}>{s.n}</span>
            <div style={{ fontSize: 16.5, fontWeight: 600, color: "var(--fg-1)", margin: "16px 0 8px" }}>{s.t}</div>
            <div style={{ fontSize: 13.5, lineHeight: 1.55, color: "var(--fg-3)" }}>{s.d}</div>
          </div>
        ))}
      </div>
      {/* self-correcting engine — the differentiator */}
      <div className="reveal" style={{ display: "flex", gap: 16, alignItems: "flex-start", marginTop: 40, padding: "22px 24px", borderRadius: "var(--r-4)", background: "var(--accent-softer)", border: "var(--hairline) solid var(--accent-border)" }}>
        <span style={{ width: 46, height: 46, borderRadius: 12, background: "var(--accent)", color: "var(--accent-fg)", display: "grid", placeItems: "center", flexShrink: 0 }}><Ico name="refresh" size={23} /></span>
        <div>
          <div style={{ fontSize: 16.5, fontWeight: 600, color: "var(--fg-1)", marginBottom: 5 }}>The part most AI tools skip: it catches its own mistakes.</div>
          <div style={{ fontSize: 14, lineHeight: 1.55, color: "var(--fg-2)", maxWidth: 820 }}>
            Step 3 is the difference. The engine grades every piece of work against your standards, fixes what fails, and turns each problem into a guardrail the whole system inherits — so quality climbs run after run, instead of you re-reviewing the same mistakes.
          </div>
        </div>
      </div>
    </Section>
  );
}

// ════════════════════════════════════════════════════════════════════════
//  BRIDGE — from one problem to running the whole org
// ════════════════════════════════════════════════════════════════════════
function Bridge() {
  return (
    <Section id="bridge" pad="72px 32px" max={900} style={{ borderTop: "var(--hairline) solid var(--border-1)" }}>
      <div className="reveal bridge-grid" style={{ display: "grid", gridTemplateColumns: "1.1fr 0.9fr", gap: 52, alignItems: "center" }}>
        <div>
          <Eyebrow icon="layers">From one problem to the whole org</Eyebrow>
          <h2 className="h-section" style={{ fontSize: "clamp(26px, 3.2vw, 38px)", margin: 0 }}>
            One problem is the entry point.<br />The engine is already there<br /><span style={{ color: "var(--accent)" }}>when you're ready for more.</span>
          </h2>
          <p style={{ fontSize: 16, lineHeight: 1.6, color: "var(--fg-2)", marginTop: 20 }}>
            Most teams start with one thing that's been stuck — a migration, a test suite, a feature that keeps slipping. That first win builds the trust and the muscle memory to go further. When you're ready, the same engine scales: more roles, more of your products, the full value stream from strategy to production running alongside your people.
          </p>
        </div>
        <div className="reveal" style={{ transitionDelay: "80ms", display: "flex", flexDirection: "column", gap: 12 }}>
          {[
            { n: "Week 1–2", t: "One problem, one team", d: "A small group of specialists on one stuck thing. You see reviewable work.", accent: true },
            { n: "Month 1–3", t: "More problems, same engine", d: "Bring the engine to more of your roadmap. The engine already knows your standards.", accent: false },
            { n: "Quarter 2+", t: "The whole org, running alongside", d: "Strategy, product, platform, build, quality, implementation, support — the complete value stream alongside your people.", accent: false },
          ].map((s, i) => (
            <div key={i} style={{ display: "flex", gap: 14, padding: "16px 18px", borderRadius: "var(--r-4)",
              background: s.accent ? "var(--accent-softer)" : "var(--bg-raised)",
              border: `var(--hairline) solid ${s.accent ? "var(--accent-border)" : "var(--border-1)"}` }}>
              <span className="mono" style={{ fontSize: 11, fontWeight: 600, color: "var(--accent)", whiteSpace: "nowrap", paddingTop: 2, minWidth: 68 }}>{s.n}</span>
              <div>
                <div style={{ fontSize: 14, fontWeight: 600, color: "var(--fg-1)", marginBottom: 3 }}>{s.t}</div>
                <div style={{ fontSize: 13, color: "var(--fg-3)", lineHeight: 1.5 }}>{s.d}</div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </Section>
  );
}

Object.assign(window, { Nav, Hero, Why, How, Bridge });
