// Home page — per section 3 of the spec
const HERO_WORDS = ["collapsing.", "consolidating.", "re-platforming.", "thinning."];

function CyclingWord() {
  const [i, setI] = React.useState(0);
  const [phase, setPhase] = React.useState("in"); // in | out
  const reducedMotion = React.useRef(
    typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches
  );
  React.useEffect(() => {
    if (reducedMotion.current) return;
    let t1, t2;
    const loop = () => {
      t1 = setTimeout(() => setPhase("out"), 3600);
      t2 = setTimeout(() => {
        setI(v => (v + 1) % HERO_WORDS.length);
        setPhase("in");
        loop();
      }, 4200);
    };
    loop();
    return () => { clearTimeout(t1); clearTimeout(t2); };
  }, []);
  // Ghost reserves layout width = longest word, so width changes during the
  // cross-fade don't cause the heading to reflow.
  const longest = HERO_WORDS.reduce((a, b) => (b.length > a.length ? b : a), "");
  return (
    <span className="home-hero-cycle" aria-live="polite">
      <span className="home-hero-cycle-ghost" aria-hidden="true">{longest}</span>
      <span className={"home-hero-cycle-inner home-hero-cycle-" + phase} key={i}>
        {HERO_WORDS[i]}
      </span>
    </span>
  );
}

function Home() {
  return (
  <PageShell current="index.html">

    {/* Hero */}
    <section className="home-hero">
      <div className="h-container">
        <div className="h-reveal">
          <div className="home-hero-status">
            <span className="home-status-dot" aria-hidden="true"></span>
            <span className="home-status-label">HONA LLC · Currently booking</span>
          </div>
          <h1 className="h-display h-h1 home-hero-title">
            Enterprise software is <CyclingWord />
          </h1>
          <p className="home-hero-sub">
            Advisory for deep tech founders. A control plane for the enterprises wiring AI into production.
          </p>
          <div className="home-hero-ctas">
            <PrimaryCta href="moat-method.html">Work with us</PrimaryCta>
            <GhostCta href="products/data-intelligence-control-plane.html">Explore the Control Plane</GhostCta>
          </div>
        </div>
      </div>
    </section>

    {/* Two lines — the only concrete sell */}
    <section className="h-section">
      <div className="h-container">
        <div className="h-sec-head h-reveal">
          <h2 className="h-display h-h2">Advisory for the founders. Software for the teams.</h2>
        </div>
        <div className="h-grid-2 two-lines">
          <div className="h-card h-card-lg h-reveal two-line-card">
            <Label>Advisory</Label>
            <h3 className="h-display h-h3 two-line-title">For deep tech founders whose deals are stalling.</h3>
            <ul className="two-line-list">
              <li>Diagnose why your narrative isn't landing with enterprise buyers.</li>
              <li>Rebuild around a defensible architectural position, not a feature list.</li>
              <li>Install a repeatable motion your team can run without you.</li>
            </ul>
            <GhostCta href="moat-method.html">Explore Advisory Services</GhostCta>
          </div>
          <div className="h-card h-card-lg h-reveal two-line-card">
            <Label>Flagship product</Label>
            <h3 className="h-display h-h3 two-line-title">The control plane for enterprise data and AI agents.</h3>
            <ul className="two-line-list">
              <li>Governance, lineage, and access control in one layer.</li>
              <li>Built for teams that refuse to surrender data portability.</li>
              <li>The architectural surface AI-native enterprises will have to standardize on.</li>
            </ul>
            <GhostCta href="products/data-intelligence-control-plane.html">Explore the Control Plane</GhostCta>
          </div>
        </div>
      </div>
    </section>

    <style>{`
      .home-hero { padding: 96px 0 112px; }
      .home-hero-title { margin-top: 28px; max-width: 22ch; }

      /* Live status indicator — conveys "actively engaging", not decoration */
      .home-hero-status {
        display: inline-flex;
        align-items: center;
        gap: 10px;
        padding: 6px 12px 6px 10px;
        border: 1px solid var(--border);
        border-radius: 999px;
      }
      .home-status-dot {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: var(--accent);
        position: relative;
        flex: 0 0 auto;
        animation: homeStatusPulse 2s ease-out infinite;
      }
      .home-status-dot::after {
        content: "";
        position: absolute; inset: 0;
        border-radius: 50%;
        background: var(--accent);
        animation: homeStatusRing 2s ease-out infinite;
      }
      .home-status-label {
        font-family: 'DM Mono', ui-monospace, monospace;
        font-size: 11px;
        letter-spacing: 3px;
        text-transform: uppercase;
        color: var(--accent);
        font-weight: 500;
      }
      @keyframes homeStatusPulse {
        0%, 100% { opacity: 1; }
        50%      { opacity: 0.75; }
      }
      @keyframes homeStatusRing {
        0%   { transform: scale(1);   opacity: 0.6; }
        80%  { transform: scale(2.4); opacity: 0; }
        100% { transform: scale(2.4); opacity: 0; }
      }
      @media (prefers-reduced-motion: reduce) {
        .home-status-dot,
        .home-status-dot::after { animation: none; }
        .home-status-dot::after { display: none; }
      }

      /* Cycling word — the thesis, alive. Ghost element reserves the longest
         word's width so word changes don't cause heading reflow / vertical
         jitter of the subtitle and CTAs below. */
      .home-hero-cycle {
        display: inline-grid;
        align-items: start;
        justify-items: start;
        vertical-align: baseline;
        color: var(--accent);
        white-space: nowrap;
      }
      .home-hero-cycle > * { grid-area: 1 / 1; }
      .home-hero-cycle-ghost { visibility: hidden; pointer-events: none; }
      .home-hero-cycle-inner {
        transition: opacity 480ms ease, transform 480ms ease, filter 480ms ease;
      }
      .home-hero-cycle-in  { opacity: 1; transform: translateY(0);    filter: blur(0); }
      .home-hero-cycle-out { opacity: 0; transform: translateY(-8px); filter: blur(6px); }
      @media (prefers-reduced-motion: reduce) {
        .home-hero-cycle-inner { transition: none; }
      }

      .home-hero-sub  { font-size: 18px; color: var(--text-secondary); max-width: 640px; margin: 28px 0 32px; line-height: 1.55; }
      .home-hero-ctas { display: flex; gap: 12px; flex-wrap: wrap; }

      /* Two-line cards */
      .two-lines { gap: 20px; }
      .two-line-card {
        display: flex; flex-direction: column; gap: 18px;
        transition: border-color 200ms ease, transform 200ms ease, background 200ms ease;
      }
      .two-line-card:hover {
        border-color: var(--accent);
        transform: translateY(-2px);
        background: color-mix(in oklch, var(--bg-surface) 92%, var(--accent));
      }
      .two-line-title { margin: 0; }
      .two-line-list {
        list-style: none; padding: 0; margin: 4px 0 8px;
        display: flex; flex-direction: column; gap: 14px;
        color: var(--text-primary); font-size: 16px; line-height: 1.5;
      }
      .two-line-list li { position: relative; padding-left: 26px; }
      .two-line-list li::before {
        content: ""; position: absolute; left: 0; top: 11px;
        width: 14px; height: 1px; background: var(--accent);
      }
    `}</style>
  </PageShell>
  );
}

ReactDOM.createRoot(document.getElementById('app')).render(<Home />);
