// Canaisay Landing v2 — app module (sections + assembly + tweaks).
(function () {
  const { useState } = React;
  const {
    Logo, Brand, AppleMark, Reveal, demoHref, openWaitlist,
    WaitlistModal, Topbar, Hero, trackSalesClick,
  } = window;

  // —————————————————————————————————————————————
  // Section header
  // —————————————————————————————————————————————
  function SectionHead({ eyebrow, title, sub, id }) {
    return (
      <header className="sec-head" id={id}>
        <div className="eyebrow">{eyebrow}</div>
        <h2 className="sec-title">{title}</h2>
        {sub && <p className="sec-sub">{sub}</p>}
      </header>
    );
  }

  // —————————————————————————————————————————————
  // WHY — the problem, with a swipe between talking and watching
  // —————————————————————————————————————————————
  const PROBLEMS = {
    talk: {
      tab: "When you're talking",
      lead: (
        <>
          In a live call you're doing three jobs at once — <strong>listening</strong>,
          <strong> remembering</strong>, and <strong>deciding what to say next</strong>.
          One always slips: the reference you half-knew, the number you meant to cite,
          the comeback that lands a beat too late.
        </>
      ),
      before: [
        "Half-listening while you rehearse your reply.",
        "The fact you needed surfaces an hour after the call.",
        "Notes pull your eyes off the person you're talking to.",
      ],
      after: [
        "The context is held for you — names, claims, numbers.",
        "One card arrives the second it's useful, then it's gone.",
        "Your eyes stay on the room. The effort stays invisible.",
      ],
    },
    watch: {
      tab: "When you're watching",
      lead: (
        <>
          A lecture, an earnings call, a science talk — the speaker drops a
          <strong> name</strong>, a <strong>term</strong>, a <strong>date</strong>,
          and you've already lost the next sentence. So you pause, you google, you
          rewind… and the thread is gone.
        </>
      ),
      before: [
        "Pause and google every unfamiliar name or term.",
        "Rewind to catch the point you missed while searching.",
        "Ten tabs deep — and you've lost the plot of the talk.",
      ],
      after: [
        "Every reference explained inline, the moment it's said.",
        "Keep playing — no pausing, no second screen.",
        "The lecture finally makes sense, end to end.",
      ],
    },
  };

  function Why() {
    const [mode, setMode] = useState("talk");
    const p = PROBLEMS[mode];
    return (
      <section className="section" id="why">
        <SectionHead
          eyebrow="THE PROBLEM"
          title={<>It moves faster<br />than memory.</>}
        />
        <Reveal>
          <div className="why-swipe" role="tablist" aria-label="Two situations">
            <span className={`why-swipe-pill ${mode === "watch" ? "is-right" : ""}`} aria-hidden="true" />
            <button role="tab" aria-selected={mode === "talk"} className={`why-swipe-opt ${mode === "talk" ? "is-on" : ""}`} onClick={() => setMode("talk")}>
              When you're talking
            </button>
            <button role="tab" aria-selected={mode === "watch"} className={`why-swipe-opt ${mode === "watch" ? "is-on" : ""}`} onClick={() => setMode("watch")}>
              When you're watching
            </button>
          </div>
        </Reveal>

        <div className="why-swap" key={mode}>
          <p className="why-lead">{p.lead}</p>
          <div className="why-grid">
            <article className="why-col why-before">
              <div className="why-col-k">On your own</div>
              <ul>
                {p.before.map((t, i) => <li key={i}>{t}</li>)}
              </ul>
            </article>
            <article className="why-col why-after">
              <div className="why-col-k">With <Brand /></div>
              <ul>
                {p.after.map((t, i) => <li key={i}>{t}</li>)}
              </ul>
            </article>
          </div>
        </div>
      </section>
    );
  }

  // —————————————————————————————————————————————
  // WHAT IT DOES — three concrete capabilities
  // —————————————————————————————————————————————
  const PILLARS = [
    {
      n: "01",
      k: "Hears every reference",
      body: "Live on a call or playing in a video — names, numbers, claims and jargon are caught the moment they're spoken. Nothing to type, nothing to look up.",
    },
    {
      n: "02",
      k: "Surfaces one card, on time",
      body: "Not a transcript and not a teleprompter. One factual card or one sharp reframe, exactly when it helps — then it's gone.",
    },
    {
      n: "03",
      k: "Disappears on command",
      body: "One keystroke hides everything. Audio never leaves your Mac. No bot joins the call, no recording lives on a server.",
    },
  ];

  function WhatItDoes() {
    return (
      <section className="section" id="how">
        <SectionHead
          eyebrow="WHAT IT DOES"
          title="It holds the context, so you don't have to."
        />
        <div className="pillars">
          {PILLARS.map((p, i) => (
            <Reveal delay={i * 80} key={p.n}>
              <article className="pillar">
                <div className="pillar-n">{p.n}</div>
                <h3 className="pillar-k">{p.k}</h3>
                <p className="pillar-body">{p.body}</p>
              </article>
            </Reveal>
          ))}
        </div>
      </section>
    );
  }

  // —————————————————————————————————————————————
  // WHERE IT WORKS — four real rooms
  // —————————————————————————————————————————————
  const CASES = [
    {
      id: "lecture", tab: "Lecture", tint: "sky", field: "Education", mode: "Watching",
      who: "Recorded · Modern History",
      quote: "…by 1923 reparations had tipped Weimar into hyperinflation.",
      card: { eyebrow: "Context", title: "Weimar hyperinflation, 1923", text: "1 USD ≈ 4.2 trillion marks. Driven by reparations + the Ruhr occupation, not printing alone." },
    },
    {
      id: "science", tab: "Science talk", tint: "mint", field: "Science", mode: "Watching",
      who: "Keynote · Molecular Biology",
      quote: "CRISPR-Cas9 lets us edit a single base pair in vivo.",
      card: { eyebrow: "Term", title: "CRISPR-Cas9, in one line", text: "A guided find-and-replace for DNA: a guide RNA finds the site, Cas9 cuts, the cell's repair makes the edit." },
    },
    {
      id: "earnings", tab: "Earnings call", tint: "peach", field: "Business", mode: "Watching",
      who: "Q3 webcast · CFO",
      quote: "We're guiding to mid-teens operating margin, ex-FX.",
      card: { eyebrow: "Metric", title: "Operating margin, ex-FX", text: "Operating profit ÷ revenue, with currency swings stripped out — so you judge the business, not exchange rates." },
    },
    {
      id: "client", tab: "Client call", tint: "peach", field: "Business", mode: "In the room",
      who: "Dana · VP Ops",
      quote: "Honestly, it's more than we'd budgeted this year.",
      card: { eyebrow: "Objection", title: "Reframe the cost, don't discount", text: "Anchor on the manual process — ~12 hrs/week across the team — not the sticker price." },
    },
    {
      id: "interview", tab: "Interview", tint: "sky", field: "Career", mode: "In the room",
      who: "Amir · Hiring manager",
      quote: "Tell me about a system you owned that fell over.",
      card: { eyebrow: "Structure · STAR", title: "One incident, four beats", text: "Lead with scope, land on recovery time and the guardrail you shipped after." },
    },
  ];

  function WhereItWorks() {
    const [active, setActive] = useState("lecture");
    const c = CASES.find((x) => x.id === active);
    return (
      <section className="section" id="cases">
        <SectionHead
          eyebrow="WHERE IT WORKS"
          title="Anything you watch. Any room you're in."
          sub="A recorded lecture, a science keynote, an earnings call, a client review, a final-round interview — same engine, tuned to the moment."
        />
        <Reveal>
          <div className="cases-wrap">
            <div className="cases-tabs">
              {CASES.map((x) => (
                <button
                  key={x.id}
                  className={`ctab ${active === x.id ? "is-active" : ""}`}
                  onClick={() => setActive(x.id)}
                >
                  {x.tab}
                </button>
              ))}
            </div>
            <div className={`case-panel tint-${c.tint}`}>
              <div className="case-left">
                <div className="case-tags">
                  <span className="case-field">{c.field}</span>
                  <span className={`case-mode ${c.mode === "Watching" ? "is-watch" : "is-live"}`}>
                    {c.mode === "Watching" ? (
                      <svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M8 5v14l11-7z"/></svg>
                    ) : (
                      <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" aria-hidden="true"><circle cx="12" cy="12" r="8"/><circle cx="12" cy="12" r="2.4" fill="currentColor" stroke="none"/></svg>
                    )}
                    {c.mode}
                  </span>
                </div>
                <div className="case-room">{c.who}</div>
                <div className="case-quote">“{c.quote}”</div>
              </div>
              <div className="case-right">
                <div className="cs-card is-in cs-card--static">
                  <div className="cs-card-head">
                    <Logo size={20} />
                    <span className="cs-card-brand">CANAISAY</span>
                    <span className="cs-card-eyebrow">{c.card.eyebrow}</span>
                  </div>
                  <div className="cs-card-title">{c.card.title}</div>
                  <div className="cs-card-body">{c.card.text}</div>
                </div>
              </div>
            </div>
          </div>
        </Reveal>
      </section>
    );
  }

  // —————————————————————————————————————————————
  // ROADMAP
  // —————————————————————————————————————————————
  const PHASES = [
    { k: "NOW", t: "Mac-first private beta", d: "Realtime listening + context cards, tuned for how conversations actually drift." },
    { k: "NEXT", t: "Context packs", d: "History, finance, company snapshots and live-event framing you can switch on per call." },
    { k: "LATER", t: "More surfaces", d: "Browser and meeting rooms, then a shared view for remote teams." },
    { k: "TRUST", t: "Citations & confidence", d: "Every card sourced and dated. One keystroke off — invite-only until it's airtight." },
  ];

  function Roadmap() {
    return (
      <section className="section" id="roadmap">
        <SectionHead
          eyebrow="ROADMAP"
          title="Mac first. Then everywhere you talk."
        />
        <Reveal>
          <div className="phases">
            {PHASES.map((p) => (
              <div key={p.k} className={`phase phase-${p.k.toLowerCase()}`}>
                <div className="phase-k">{p.k}</div>
                <div className="phase-t">{p.t}</div>
                <div className="phase-d">{p.d}</div>
              </div>
            ))}
          </div>
        </Reveal>
      </section>
    );
  }

  // —————————————————————————————————————————————
  // FINAL CTA
  // —————————————————————————————————————————————
  function FinalCTA() {
    return (
      <section className="section cta-block" id="cta">
        <Reveal>
          <div className="cta-card">
            <Logo size={64} />
            <h2 className="cta-title">Stay the sharpest person in the room.</h2>
            <p className="cta-sub">
              Join the Mac-first private beta. Audio stays local, no bot joins your
              call, and nothing is recorded anywhere we control.
            </p>
            <div className="cta-buttons">
              <a href="#cta" className="btn-primary" onClick={(e) => openWaitlist(e, "final")}>
                <AppleMark /> Download for Mac
              </a>
              <a href="mailto:first@canaisay.com?subject=Talk%20to%20Sales%20%E2%80%94%20Canaisay" className="btn-ghost" onClick={() => trackSalesClick("final")}>
                <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>
                Talk to Sales
              </a>
            </div>
            <div className="cta-trust">
              <span>Audio stays local</span>
              <span className="sep">·</span>
              <span>No bot joins your call</span>
              <span className="sep">·</span>
              <span>Invite-only beta</span>
            </div>
          </div>
        </Reveal>
      </section>
    );
  }

  // —————————————————————————————————————————————
  // Footer
  // —————————————————————————————————————————————
  function Footer() {
    return (
      <footer className="footer">
        <div className="foot-left">
          <Logo size={32} />
          <div>
            <div className="foot-k"><Brand /></div>
            <div className="foot-sub">
              Live context for calls and videos. Built for the way they actually move.
            </div>
          </div>
        </div>
        <div className="foot-links">
          <a href="#why">Why</a>
          <a href="#how">What it does</a>
          <a href="#cases">Where it works</a>
          <a href="#roadmap">Roadmap</a>
        </div>
        <div className="foot-bottom">
          <span>© 2026 <Brand />. Live context for calls and videos.</span>
          <a href="mailto:borisovkmail@gmail.com" className="foot-contact">
            <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><rect x="3" y="5" width="18" height="14" rx="2"/><path d="m3 7 9 6 9-6"/></svg>
            Contact us
          </a>
        </div>
      </footer>
    );
  }

  // —————————————————————————————————————————————
  // Root
  // —————————————————————————————————————————————
  function App() {
    return (
      <div className="site">
        <div className="sky" aria-hidden="true">
          <span className="sky-blob a" />
          <span className="sky-blob b" />
          <span className="sky-blob c" />
        </div>

        <Topbar />
        <main>
          <Hero />
          <Why />
          <WhatItDoes />
          <WhereItWorks />
          <Roadmap />
          <FinalCTA />
        </main>
        <Footer />
        <WaitlistModal />
      </div>
    );
  }

  const root = ReactDOM.createRoot(document.getElementById("root"));
  root.render(<App />);
})();
