/* Section components — Hero, Vision, Principles carousel, Team. */

const { useState, useEffect, useRef, useMemo } = React;

const CALENDLY_URL = "https://calendly.com/heba-byarchestudio";
const openCalendly = () => {
  if (window.Calendly) {
    window.Calendly.initPopupWidget({ url: CALENDLY_URL });
  } else {
    window.open(CALENDLY_URL, "_blank");
  }
};

function useIsMobile(bp = 768) {
  const [v, setV] = useState(() => window.innerWidth <= bp);
  useEffect(() => {
    const h = () => setV(window.innerWidth <= bp);
    window.addEventListener("resize", h);
    return () => window.removeEventListener("resize", h);
  }, [bp]);
  return v;
}

/* Scroll-reveal wrapper — fades + slides children up when they enter the viewport. */
const Reveal = ({ children, delay = 0, threshold = 0.12, style = {} }) => {
  const ref = useRef(null);
  const [vis, setVis] = useState(false);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    const obs = new IntersectionObserver(
      ([e]) => { if (e.isIntersecting) { setVis(true); obs.unobserve(el); } },
      { threshold }
    );
    obs.observe(el);
    return () => obs.disconnect();
  }, []);
  return (
    <div ref={ref} style={{
      ...style,
      opacity: vis ? 1 : 0,
      transform: vis ? "translateY(0px)" : "translateY(32px)",
      transition: `opacity 0.8s cubic-bezier(.16,1,.3,1) ${delay}s, transform 0.8s cubic-bezier(.16,1,.3,1) ${delay}s`,
    }}>
      {children}
    </div>
  );
};

/* ───────────────────────── Hero ───────────────────────── */

const NavBar = () => {
  const [scrolled, setScrolled] = useState(false);
  const [overOrange, setOverOrange] = useState(false);
  const [sectionBg, setSectionBg] = useState(null);
  const [menuOpen, setMenuOpen] = useState(false);
  const isMobile = useIsMobile(768);

  useEffect(() => {
    if (menuOpen) document.body.style.overflow = "hidden";
    else document.body.style.overflow = "";
    return () => { document.body.style.overflow = ""; };
  }, [menuOpen]);

  useEffect(() => {
    const onScroll = () => {
      setScrolled(window.scrollY > 24);
      const x = window.innerWidth / 2;
      const y = 28;
      const nav = document.getElementById("__archeNav");
      const prev = nav && nav.style.pointerEvents;
      if (nav) nav.style.pointerEvents = "none";
      const el = document.elementFromPoint(x, y);
      if (nav) nav.style.pointerEvents = prev || "";
      if (!el) return;
      let cur = el;
      let foundBg = null;
      while (cur && cur !== document.body) {
        const tag = cur.tagName;
        if (tag === "FOOTER" || tag === "SECTION") {
          foundBg = getComputedStyle(cur).backgroundColor;
          break;
        }
        cur = cur.parentElement;
      }
      const isOrange = foundBg === "rgb(232, 79, 47)";
      setOverOrange(isOrange);
      setSectionBg(foundBg);
    };
    onScroll();
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll);
    return () => {
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
    };
  }, []);

  // Compute nav background from actual section bg
  const navBg = (() => {
    if (!scrolled) return "transparent";
    if (!sectionBg) return "rgba(245,244,242,0.78)";
    const m = sectionBg.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
    if (m) return `rgba(${m[1]},${m[2]},${m[3]},0.78)`;
    return "rgba(245,244,242,0.78)";
  })();

  const navItems = ["Services", "Plans", "Team"];
  const fg = overOrange ? "var(--white)" : "var(--orange)";
  const btnBg = overOrange ? "var(--white)" : "var(--orange)";
  const btnFg = overOrange ? "var(--orange)" : "var(--white)";

  // Click bounce for nav links
  const navLinkClick = (e) => {
    const el = e.currentTarget;
    el.style.transform = "scale(0.88)";
    setTimeout(() => { el.style.transform = "scale(1.06)"; }, 100);
    setTimeout(() => { el.style.transform = "scale(1)"; }, 260);
  };

  return (
    <>
      <style>{`html { scroll-behavior: smooth; }`}</style>
      <nav id="__archeNav" style={{
        display: isMobile ? "flex" : "grid",
        gridTemplateColumns: isMobile ? undefined : "1fr auto 1fr",
        alignItems: "center",
        justifyContent: isMobile ? "space-between" : undefined,
        gap: isMobile ? undefined : 48,
        padding: isMobile
          ? (scrolled ? "12px 20px" : "20px 20px")
          : (scrolled ? "14px 48px" : "32px 48px"),
        position: "fixed", top: 0, left: 0, right: 0, zIndex: 50,
        background: navBg,
        backdropFilter: scrolled ? "saturate(140%) blur(14px)" : "none",
        WebkitBackdropFilter: scrolled ? "saturate(140%) blur(14px)" : "none",
        transition: "padding .25s ease, background .25s ease, color .25s ease"
      }}>
        {isMobile ? (
          <>
            <button onClick={() => setMenuOpen(true)} aria-label="Open menu" style={{
              display: "flex", flexDirection: "column", gap: 5, padding: 4
            }}>
              <span style={{ display: "block", width: 32, height: 3, background: fg, borderRadius: 12, transition: "background .25s" }} />
              <span style={{ display: "block", width: 32, height: 3, background: fg, borderRadius: 12, transition: "background .25s" }} />
            </button>
          </>
        ) : (
          <>
            <div style={{ display: "flex", alignItems: "center", gap: 48, justifyContent: "flex-start" }}>
              {navItems.slice(0, 2).map((label) =>
                <a key={label} href={`#${label.toLowerCase()}`} style={{
                  color: fg, fontFamily: "var(--sans)", fontSize: 16, fontWeight: 500,
                  letterSpacing: "0.01em", display: "inline-block",
                  transition: "opacity .2s, color .25s ease, transform .25s cubic-bezier(.2,.7,.2,1)"
                }}
                onMouseEnter={(e) => { e.currentTarget.style.opacity = 0.7; e.currentTarget.style.transform = "translateY(-1px)"; }}
                onMouseLeave={(e) => { e.currentTarget.style.opacity = 1; e.currentTarget.style.transform = "translateY(0)"; }}
                onClick={navLinkClick}>
                  {label}</a>
              )}
            </div>
            <a href="#top" style={{
              fontFamily: "var(--display)",
              fontSize: scrolled ? 30 : 26,
              lineHeight: 1, color: fg, letterSpacing: "0.01em",
              transition: "font-size .25s ease, color .25s ease",
              whiteSpace: "nowrap"
            }}>Arché</a>
            <div style={{ display: "flex", alignItems: "center", gap: 48, justifyContent: "flex-end" }}>
              <a href={`#${navItems[2].toLowerCase()}`} style={{
                color: fg, fontFamily: "var(--sans)", fontSize: 16, fontWeight: 500,
                letterSpacing: "0.01em", display: "inline-block",
                transition: "opacity .2s, color .25s ease, transform .25s cubic-bezier(.2,.7,.2,1)"
              }}
              onMouseEnter={(e) => { e.currentTarget.style.opacity = 0.7; e.currentTarget.style.transform = "translateY(-1px)"; }}
              onMouseLeave={(e) => { e.currentTarget.style.opacity = 1; e.currentTarget.style.transform = "translateY(0)"; }}
              onClick={navLinkClick}>
                {navItems[2]}</a>
              <button onClick={openCalendly} style={{
                background: btnBg, color: btnFg,
                padding: "12px 24px", borderRadius: 48, fontWeight: 500, fontSize: 16,
                transition: "background .25s, color .25s, transform .2s cubic-bezier(.2,.7,.2,1), box-shadow .3s"
              }}
              onMouseEnter={(e) => { e.currentTarget.style.transform = "scale(1.04)"; e.currentTarget.style.boxShadow = "0 4px 20px rgba(232,79,47,0.3)"; }}
              onMouseLeave={(e) => { e.currentTarget.style.transform = "scale(1)"; e.currentTarget.style.boxShadow = "none"; }}
              onMouseDown={(e) => e.currentTarget.style.transform = "scale(0.95)"}
              onMouseUp={(e) => e.currentTarget.style.transform = "scale(1.04)"}>
                Book a call</button>
            </div>
          </>
        )}
      </nav>

      {/* Mobile menu overlay */}
      {isMobile && (
        <div style={{
          position: "fixed", inset: 0, zIndex: 100,
          background: "var(--bg)", color: "var(--orange)",
          display: "flex", flexDirection: "column",
          padding: "28px 28px 40px",
          opacity: menuOpen ? 1 : 0,
          pointerEvents: menuOpen ? "auto" : "none",
          transition: "opacity .3s ease",
          overflow: "auto"
        }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start" }}>
            <div style={{
              fontFamily: "var(--display)", fontSize: 72, color: "var(--orange)",
              lineHeight: 1, letterSpacing: "-0.01em"
            }}>Arché</div>
            <button onClick={() => setMenuOpen(false)} aria-label="Close menu" style={{
              fontSize: 32, color: "var(--orange)", padding: 8, lineHeight: 1, marginTop: 8
            }}>{"\u2715"}</button>
          </div>
          <div style={{ height: 1, background: "var(--orange)", opacity: 0.2, marginTop: 16 }} />
          <div style={{
            display: "flex", flexDirection: "column", gap: 16, marginTop: 40, alignItems: "center"
          }}>
            {navItems.map((label) => (
              <a key={label} href={`#${label.toLowerCase()}`}
                onClick={() => setMenuOpen(false)}
                style={{
                  fontSize: 28, fontWeight: 500, color: "var(--orange)",
                  fontFamily: "var(--sans)", letterSpacing: "-0.01em",
                  transition: "opacity .2s", padding: "8px 0"
                }}
                onMouseEnter={(e) => e.currentTarget.style.opacity = 0.6}
                onMouseLeave={(e) => e.currentTarget.style.opacity = 1}>
                {label}
              </a>
            ))}
          </div>
          <div style={{ marginTop: "auto", paddingTop: 32 }}>
            <button onClick={() => { setMenuOpen(false); openCalendly(); }} style={{
              width: "100%", background: "var(--orange)", color: "var(--white)",
              padding: "18px 32px", borderRadius: 48, fontWeight: 500, fontSize: 18,
              transition: "transform .15s"
            }}
            onMouseDown={(e) => e.currentTarget.style.transform = "scale(0.97)"}
            onMouseUp={(e) => e.currentTarget.style.transform = "scale(1)"}>
              Book a call
            </button>
          </div>
        </div>
      )}
    </>
  );

};

const Hero = () => {
  const isMobile = useIsMobile(768);

  if (isMobile) {
    return (
      <section style={{
        position: "relative", height: "100dvh", background: "var(--bg)",
        padding: "32px 24px",
        display: "flex", flexDirection: "column", justifyContent: "space-between",
        overflow: "hidden"
      }}>
        {/* Top: nav spacer + logo + coordinates */}
        <div style={{ display: "flex", flexDirection: "column", gap: 32 }}>
          <div style={{ height: 48 }} />
          <div>
            <h1 style={{
              margin: 0, fontFamily: "var(--display)", fontWeight: 400,
              fontSize: 150, lineHeight: 0.85,
              letterSpacing: "-0.01em", color: "var(--orange)"
            }}>Arché</h1>
            <div style={{ marginTop: 10, fontSize: 16, lineHeight: 1.4, color: "var(--orange)" }}>
              <div>Seattle</div>
              <div>47.6061° N, 122.3328°</div>
            </div>
          </div>
        </div>

        {/* Bottom: tagline + two columns */}
        <Reveal delay={0.1}>
        <div style={{ display: "flex", flexDirection: "column", gap: 64 }}>
          <p style={{
            margin: 0, fontSize: 32, fontWeight: 500, lineHeight: 1.1,
            color: "var(--orange)"
          }}>We help startups build the right product, the right way.</p>
          <div style={{ display: "flex", gap: 48 }}>
            <div style={{ flex: 1 }}>
              <div style={{ fontWeight: 500, marginBottom: 8, fontSize: 16 }}>Starting at 170$/hr</div>
              <div style={{ height: 8 }} />
              <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gap: 4, fontWeight: 400, fontSize: 16 }}>
                <li>Office hours</li>
                <li>Sprint</li>
                <li>Studio</li>
              </ul>
            </div>
            <div style={{ flex: 1 }}>
              <div style={{ fontWeight: 500, marginBottom: 8, fontSize: 16 }}>Specializing in</div>
              <div style={{ height: 8 }} />
              <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gap: 4, fontWeight: 400, fontSize: 16 }}>
                <li>Product Strategy</li>
                <li>Product Design</li>
                <li>LLM Implementation</li>
              </ul>
            </div>
          </div>
        </div>
        </Reveal>
      </section>
    );
  }

  return (
    <section style={{
      position: "relative", minHeight: 900, background: "var(--bg)",
      padding: "32px 48px 80px"
    }}>
      <div style={{ paddingTop: 175, maxWidth: 1344, margin: "0 auto", position: "relative" }}>
        <h1 style={{
          margin: 0, fontFamily: "var(--display)", fontWeight: 400,
          fontSize: "clamp(140px, 24vw, 350px)", lineHeight: 0.85,
          letterSpacing: "-0.01em", color: "var(--orange)"
        }}>Arché</h1>
        <div style={{ marginTop: 14, fontSize: 16, lineHeight: 1.4, color: "var(--orange)" }}>
          <div>Seattle</div>
          <div>47.6061° N, 122.3328°</div>
        </div>
        <Reveal delay={0.15}>
        <div style={{
          marginTop: 100, display: "grid",
          gridTemplateColumns: "minmax(280px, 373px) 1fr auto auto",
          gap: 48, alignItems: "flex-start"
        }}>
          <p style={{
            margin: 0, fontSize: 32, fontWeight: 500, lineHeight: 1.1,
            color: "var(--orange)", maxWidth: 380, textWrap: "pretty"
          }}>We help startups build the right product, the right way.</p>
          <div />
          <div style={{ minWidth: 160 }}>
            <div style={{ fontWeight: 500, marginBottom: 20 }}>Starting at 170$/hr</div>
            <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gap: 6, fontWeight: 400 }}>
              <li>Office hours</li>
              <li>Sprint</li>
              <li>Studio</li>
            </ul>
          </div>
          <div style={{ minWidth: 160 }}>
            <div style={{ fontWeight: 500, marginBottom: 20 }}>Specializing in</div>
            <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gap: 6, fontWeight: 400 }}>
              <li>Product Strategy</li>
              <li>Product Design</li>
              <li>LLM Implementation</li>
            </ul>
          </div>
        </div>
        </Reveal>
      </div>
    </section>
  );
};


/* ───────────────────────── Vision (red band) ───────────────────────── */

const Vision = () => {
  const isMobile = useIsMobile(768);
  return (
    <section style={{
      background: "var(--orange)", color: "var(--white)",
      minHeight: isMobile ? "auto" : 900,
      display: "flex", alignItems: "center", justifyContent: "center",
      padding: isMobile ? "82px 48px" : "120px 48px"
    }}>
      <div style={{ maxWidth: 676, width: "100%", textAlign: "left" }}>
        <Reveal>
          <h2 style={{
            margin: 0, fontFamily: "var(--sans)", fontWeight: 500,
            fontSize: isMobile ? 42 : 48, lineHeight: 1.05,
            color: "var(--white)", textWrap: "balance"
          }}>
            Every founder starts with a{" "}
            <em style={{
              fontFamily: "var(--serif)", fontStyle: "italic", fontWeight: 400,
              fontSize: "1.05em", letterSpacing: "0.005em"
            }}>vision</em>
            . The challenge is turning it into something{" "}
            <em style={{
              fontFamily: "var(--serif)", fontStyle: "italic", fontWeight: 400,
              fontSize: "1.05em"
            }}>Real</em>.
          </h2>
        </Reveal>
        <Reveal delay={0.15}>
          <div style={{
            marginTop: isMobile ? 24 : 40,
            display: "grid", gap: 18,
            fontSize: 16, lineHeight: 1.55, fontWeight: 400,
            maxWidth: 620, color: "rgba(255,255,255,0.95)"
          }}>
            <p style={{ margin: 0 }}>We've been founders ourselves. We know how overwhelming the journey can be. You're selling, fundraising, and learning at record speed while trying to stay sane.</p>
            <p style={{ margin: 0 }}>We noticed that non‑product founders don't lack vision or conviction. They lack the tools, processes, and partners to translate that vision into a product their users need. That's the gap we're trying to close.</p>
          </div>
        </Reveal>
      </div>
    </section>
  );
};


/* ───────────────────────── Principles (carousel) ───────────────────────── */

const PRINCIPLES = [
{
  id: "right",
  title: "Build the right thing, build the thing right",
  body: "The most beautifully crafted product means nothing if it solves the wrong problem. But once the right problem is clear, we build the product with quality.",
  Icon: IconBuild
},
{
  id: "first",
  title: "Start from first‑principles",
  body: "We don't copy what worked for someone else. We strip the problem down to its most fundamental truths and reason back up.",
  Icon: IconFirstPrinciples
},
{
  id: "vision",
  title: "Start with the vision",
  body: "If something is worth doing, it's worth doing ambitiously. We push founders to start with the ideal solution, then work backwards to the MLP that gets them there.",
  Icon: IconVision
}];


const PrincipleCard = ({ principle, scale, isCenter, clicked, onClick }) => {
  const { title, body, Icon } = principle;
  const w = 350 * scale;
  const h = 550 * scale;
  const iconSize = 200 * scale;

  return (
    <button
      onClick={onClick}
      aria-pressed={clicked}
      style={{
        position: "relative",
        width: w, height: h, borderRadius: 24 * scale,
        flex: "0 0 auto",
        background: clicked ? "var(--orange)" : "var(--white)",
        boxShadow: isCenter ?
        "0 24px 60px -28px rgba(75,32,32,0.18), 0 4px 12px -6px rgba(75,32,32,0.08)" :
        "0 8px 24px -16px rgba(75,32,32,0.12)",
        transition: "transform .45s cubic-bezier(.2,.7,.2,1), background .35s ease, box-shadow .45s ease, width .45s, height .45s",
        cursor: "pointer",
        overflow: "hidden",
        textAlign: "center",
        outline: "none"
      }}>
      
      {/* Default face */}
      <div style={{
        position: "absolute", inset: 0,
        opacity: clicked ? 0 : 1,
        transition: "opacity .3s ease",
        display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center",
        padding: `${120 * scale}px ${32 * scale}px ${64 * scale}px`
      }}>
        <div style={{ color: "var(--orange)", marginBottom: 64 * scale }}>
          <Icon size={iconSize} color="var(--orange)" />
        </div>
        <div style={{
          fontFamily: "var(--sans)", fontWeight: 500, fontSize: 24 * scale,
          color: "var(--orange)", lineHeight: 1.2, padding: `0 ${8 * scale}px`,
          textWrap: "balance"
        }}>{title}</div>
      </div>

      {/* Clicked face */}
      <div style={{
        position: "absolute", inset: 0,
        opacity: clicked ? 1 : 0,
        transition: "opacity .35s ease",
        display: "flex", flexDirection: "column", alignItems: "center",
        padding: `${120 * scale}px ${32 * scale}px ${64 * scale}px`,
        color: "var(--white)"
      }}>
        <div style={{ color: "var(--white)", marginBottom: 82 * scale }}>
          <Icon size={64 * scale} color="var(--white)" />
        </div>
        <div style={{
          fontFamily: "var(--sans)", fontWeight: 500, fontSize: 24 * scale,
          lineHeight: 1.2, color: "var(--white)", marginBottom: 8 * scale,
          textWrap: "balance"
        }}>{title}</div>
        <div style={{
          fontFamily: "var(--sans)", fontWeight: 400, fontSize: 16 * scale,
          lineHeight: 1.4, color: "var(--white)"
        }}>{body}</div>
      </div>
    </button>);

};

const Principles = () => {
  const [center, setCenter] = useState(0);
  const [clicked, setClicked] = useState(null); // index of clicked card
  const railRef = useRef(null);
  const isMobile = useIsMobile(768);

  const total = PRINCIPLES.length;
  // visible = 3 cards; left, center, right (cyclic)
  const visible = useMemo(() => [
  (center - 1 + total) % total,
  center,
  (center + 1) % total],
  [center, total]);

  const handleCardClick = (idx) => {
    if (idx === center) {
      setClicked((prev) => prev === idx ? null : idx);
    } else {
      setClicked(null);
      setCenter(idx);
    }
  };

  // Drag / swipe support (mouse + touch)
  useEffect(() => {
    const el = railRef.current;
    if (!el) return;
    let startX = null;
    let dragging = false;
    const THRESHOLD = 60;

    const onDown = (x) => {startX = x;dragging = true;};
    const onUp = (x) => {
      if (!dragging || startX === null) {dragging = false;return;}
      const dx = x - startX;
      if (Math.abs(dx) > THRESHOLD) {
        setClicked(null);
        if (dx < 0) setCenter((c) => (c + 1) % total);else
        setCenter((c) => (c - 1 + total) % total);
      }
      startX = null;
      dragging = false;
    };

    const md = (e) => onDown(e.clientX);
    const mu = (e) => onUp(e.clientX);
    const ts = (e) => onDown(e.touches[0].clientX);
    const te = (e) => {
      const x = e.changedTouches && e.changedTouches[0] ? e.changedTouches[0].clientX : startX;
      onUp(x);
    };

    el.addEventListener("mousedown", md);
    window.addEventListener("mouseup", mu);
    el.addEventListener("touchstart", ts, { passive: true });
    el.addEventListener("touchend", te);

    // Trackpad horizontal wheel → also swipes
    let wheelLock = 0;
    const onWheel = (e) => {
      // Prefer horizontal intent
      if (Math.abs(e.deltaX) > Math.abs(e.deltaY) && Math.abs(e.deltaX) > 20) {
        e.preventDefault();
        const now = Date.now();
        if (now - wheelLock < 450) return;
        wheelLock = now;
        setClicked(null);
        if (e.deltaX > 0) setCenter((c) => (c + 1) % total);else
        setCenter((c) => (c - 1 + total) % total);
      }
    };
    el.addEventListener("wheel", onWheel, { passive: false });

    return () => {
      el.removeEventListener("mousedown", md);
      window.removeEventListener("mouseup", mu);
      el.removeEventListener("touchstart", ts);
      el.removeEventListener("touchend", te);
      el.removeEventListener("wheel", onWheel);
    };
  }, [total]);

  return (
    <section id="services" style={{
      background: "var(--bg)", padding: isMobile ? "32px 24px" : "120px 48px", position: "relative"
    }}>
      <Reveal>
        <div style={{ textAlign: "center", marginBottom: 48, color: "var(--orange)", fontWeight: 500, fontSize: 16 }}>
          Our principles
        </div>
      </Reveal>

      <div ref={railRef} style={{
        display: "flex", justifyContent: "center", alignItems: "center", gap: isMobile ? 0 : 32,
        minHeight: isMobile ? "auto" : 600, cursor: "grab", userSelect: "none", touchAction: "pan-y"
      }}>
        {(isMobile ? [center] : visible).map((idx, slot) => {
          const isCenter = isMobile ? true : slot === 1;
          return (
            <PrincipleCard
              key={`${idx}-${slot}`}
              principle={PRINCIPLES[idx]}
              scale={isMobile ? 1 : (isCenter ? 1 : 0.818)}
              isCenter={isCenter}
              clicked={isCenter && clicked === idx}
              onClick={() => handleCardClick(idx)} />);


        })}
      </div>

      <div style={{ display: "flex", justifyContent: "center", alignItems: "center", gap: 6, marginTop: isMobile ? 16 : 40 }}>
        {PRINCIPLES.map((_, i) =>
        <button
          key={i}
          aria-label={`Slide ${i + 1}`}
          onClick={() => {setClicked(null);setCenter(i);}}
          style={{
            width: 8, height: 8, borderRadius: "50%",
            background: i === center ? "var(--orange)" : "rgb(217,217,217)",
            transition: "background .2s, transform .2s",
            transform: i === center ? "scale(1.15)" : "scale(1)"
          }} />

        )}
      </div>
    </section>);

};

/* ───────────────────────── Journey (curve + checkpoints) ───────────────────────── */

/* Each checkpoint:
   t = parametric position along the curve (0 = start, 1 = end). Edit `t` to move the dot.
   phase = which of the 3 phase brackets it sits in. */
const JOURNEY = [
{
  id: "problem",
  label: "Problem statement",
  phase: 1,
  t: 0.04,
  title: "Problem statement",
  body: "You have a hunch, maybe a personal frustration, a market observation, or a conviction that something is broken. Nothing is built yet. You're figuring out if the problem is real, urgent, and worth your next several years.",
  questions: [
    "What's the problem?",
    "Why is the problem worth solving?",
    "Who are we solving it for?",
    "What's the unfair advantage we have about this problem space that others don't?"],
  helps: [
    "Exploratory user research with real potential users",
    "Problem framing",
    "Market research & opportunity sizing",
    "Customer segmentation & target user group"]
},
{
  id: "launch",
  label: "The Launch",
  phase: 2,
  t: 0.30,
  title: "The Launch",
  body: "You have a clear problem statement with an early signal from target users. Now you need to build a solution to solve their problem; this tends to be the most ambiguous yet exciting stretch of the journey.",
  questions: [
    "What's the ideal solution?",
    "Will customers change their behavior and pay for the solution?",
    "What's the smallest Minimal Loveable Product (MLP) we can build to start learning?"],
  helps: [
    "Solution ideation",
    "Concept validation through structured user research",
    "MVP scoping and product roadmap",
    "Dev-ready design specs",
    "Success metrics definition",
    "Go-to-market strategy to support launch"]
},
{
  id: "valley",
  label: "Valley of despair",
  phase: 2,
  t: 0.55,
  title: "The valley of despair",
  body: "You've launched (Hooray!) Some early users are in. Now the hard part: figuring out what's landing and what isn't. Most startups spend 1–3 years here, iterating, pivoting, and grinding through till they find PMF.",
  questions: [
    "Is the solution actually landing? Or do we need to pivot?",
    "What do we double down on, and what do we kill?",
    "Who do we need to hire for the next 12–24 months?",
    "What do we need to systemize to make our work easier?"],
  helps: [
    "Rapid iteration cycles — design, validate, ship, iterate",
    "Roadmap and prioritization informed by real usage data",
    "Analytics setup and retention analysis",
    "Early design system work",
    "Product rituals (sprints, documentation, decision frameworks)"]
},
{
  id: "pmf",
  label: "Post PMF",
  phase: 3,
  t: 0.78,
  title: "Post PMF",
  body: "Congratulations — you've found PMF in at least one segment. Users are coming back, revenue is growing, and the sales motion is starting to feel repeatable. Now the work shifts from figuring out what to build to growing it sustainably.",
  questions: [
    "How do we grow revenue faster without losing focus?",
    "How do we strengthen our core product to handle scale?",
    "How do we build a product org that doesn't run through the founders?"],
  helps: [
    "KPI setting",
    "Hiring specs and interview frameworks",
    "Roadmap and prioritization informed by real usage data",
    "Engineering debt triage",
    "Onboarding and activation optimization",
    "Optimized design system",
    "Product rituals"]
},
{
  id: "growth",
  label: "Scale up",
  phase: 3,
  t: 0.88,
  title: "Scale up",
  funding: "Funding: Series B, C",
  body: "The hard part is behind you! You have a winning product, a proven business model, and repeatable processes. Now it's about putting more gas on the fire — expanding to new markets, segments, or product lines.",
  questions: [
    "How do we keep our org culture strong while we grow?",
    "How do we expand into new product lines without losing what made us great?",
    "Where do we build, buy, or partner?",
    "How do we maintain shipping velocity as the org grows?"],
  notOffered: true
},
{
  id: "maturity",
  label: "Maturity",
  phase: 3,
  t: 0.99,
  title: "Maturity",
  funding: "Funding: IPO, Exit, Merge, Acquisition",
  body: "You have a mature company, and the big questions are all about legacy — whether that's an exit, a merger, international expansion, or spinning out something new.",
  questions: [
    "What is the long-term strategy for this company and its owners?",
    "How do we keep innovating while managing a mature product?"],
  notOffered: true
}];

// Hand-drawn-style curve. viewBox 1000 x 540.
// Y-axis at x=110, X-axis at y=470.
const CURVE_D = "M 130 420 C 165 415, 195 425, 215 420 C 240 412, 258 392, 282 348 C 312 285, 342 215, 368 148 C 384 165, 405 215, 428 275 C 445 322, 460 358, 478 388 C 495 412, 510 422, 526 420 C 543 418, 556 410, 574 415 C 595 422, 612 425, 632 418 C 660 408, 685 388, 712 355 C 740 318, 763 295, 786 280 C 806 265, 822 250, 838 228 C 854 206, 866 188, 880 165 C 894 142, 910 130, 925 122";

// X-pixel ranges (in 1000-wide viewBox) where each phase bracket sits.
// Phase boundaries match the two vertical dividers in the original sketch.
const PHASES = [
  { id: 1, label: "Is this the right problem?", x1: 130, x2: 320 },
  { id: 2, label: "Is this the right solution?", x1: 320, x2: 700 },
  { id: 3, label: "Is this the right way to scale?", x1: 700, x2: 935 }
];

const Journey = () => {
  const [activeId, setActiveId] = useState("problem");
  const pathRef = React.useRef(null);
  const [dots, setDots] = useState([]);

  React.useEffect(() => {
    const path = pathRef.current;
    if (!path) return;
    const len = path.getTotalLength();
    setDots(JOURNEY.map((c) => {
      const p = path.getPointAtLength(len * c.t);
      return { id: c.id, x: p.x, y: p.y };
    }));
  }, []);

  const active = JOURNEY.find((c) => c.id === activeId);
  const dotMap = Object.fromEntries(dots.map((d) => [d.id, d]));

  return (
    <section id="journey" style={{
      background: "var(--bg)", color: "var(--orange)",
      padding: "56px 48px 64px"
    }}>
      <style>{`
        @keyframes archePulse {
          0%, 100% { transform: scale(1); opacity: 0.55; }
          50%      { transform: scale(1.6); opacity: 0; }
        }
        .arche-dot-pulse { transform-box: fill-box; transform-origin: center; animation: archePulse 1.8s ease-out infinite; }

        @keyframes sliderGlow {
          0%, 100% { box-shadow: 0 0 8px 2px rgba(232,79,47,0.4), 0 0 20px 6px rgba(232,79,47,0.15); }
          50%      { box-shadow: 0 0 14px 6px rgba(232,79,47,0.55), 0 0 32px 12px rgba(232,79,47,0.2); }
        }

        @keyframes archeWiggle {
          0%   { transform: rotate(0deg); }
          15%  { transform: rotate(-2deg); }
          30%  { transform: rotate(2deg); }
          45%  { transform: rotate(-1.5deg); }
          60%  { transform: rotate(1.5deg); }
          75%  { transform: rotate(-0.5deg); }
          100% { transform: rotate(0deg); }
        }

        .journey-mobile { display: none; }
        @media (max-width: 900px) {
          #journey { padding: 32px 24px !important; }
          #journey .journey-desktop { display: none !important; }
          #journey .journey-mobile { display: flex !important; }
        }
      `}</style>

      <Reveal>
        <div style={{
          textAlign: "center", fontWeight: 500, fontSize: 16, marginBottom: 20
        }}>
          Our Services
        </div>
      </Reveal>
      <Reveal delay={0.1}>
        <div style={{
          textAlign: "center", marginBottom: 56,
          fontSize: 32, fontWeight: 500, letterSpacing: "-0.01em",
          lineHeight: 1.15, color: "var(--orange)",
          maxWidth: 1100, margin: "0 auto 56px"
        }}>
          We believe that every startup goes through this{" "}
          <em style={{
            fontFamily: "var(--serif)", fontStyle: "italic", fontWeight: 400,
            fontSize: "1.05em"
          }}>journey</em>
        </div>
      </Reveal>

      <Reveal delay={0.2}>
      <div className="journey-desktop" style={{
        maxWidth: 1440, margin: "0 auto",
        display: "grid",
        gridTemplateColumns: "minmax(0, 1.05fr) minmax(0, 1fr)",
        gap: 48,
        alignItems: "stretch"
      }}>
        {/* LEFT: phase headers + SVG curve */}
        <div style={{ display: "flex", flexDirection: "column", gap: 28, minHeight: 0 }}>
          {/* Phase header strip — thin band, three columns sized to the curve's phase widths */}
          <div style={{
            display: "flex",
            paddingLeft: `${(130 / 1000) * 100}%`,
            paddingRight: `${((1000 - 935) / 1000) * 100}%`,
          }}>
            {PHASES.map((p) => {
              const phaseActive = active.phase === p.id;
              const flex = (p.x2 - p.x1);
              return (
                <div key={p.id} style={{
                  flex: `${flex} ${flex} 0`,
                  minWidth: 0,
                  textAlign: "center",
                  padding: "6px 8px",
                  fontSize: 12, fontWeight: 500,
                  letterSpacing: "0.02em",
                  color: phaseActive ? "var(--orange)" : "rgba(232,79,47,0.45)",
                  transition: "color .25s",
                  whiteSpace: "normal",
                  lineHeight: 1.3,
                }}>
                  {p.label}
                </div>
              );
            })}
          </div>

          <div style={{ flex: 1, minHeight: 0, display: "flex" }}>
          <svg
            viewBox="0 0 1000 460"
            preserveAspectRatio="xMidYMid meet"
            width="100%"
            style={{ display: "block", overflow: "visible", width: "100%", height: "100%" }}
            aria-label="Founder journey curve"
          >
            {/* Smiley face top */}
            <g stroke="var(--orange)" strokeWidth="2.5" fill="none" strokeLinecap="round">
              <circle cx="56" cy="155" r="24" />
              <circle cx="48" cy="149" r="1.5" fill="var(--orange)" />
              <circle cx="64" cy="149" r="1.5" fill="var(--orange)" />
              <path d="M 46 161 Q 56 170 66 161" />
            </g>
            {/* Sad face bottom */}
            <g stroke="var(--orange)" strokeWidth="2.5" fill="none" strokeLinecap="round">
              <circle cx="56" cy="425" r="24" />
              <circle cx="48" cy="419" r="1.5" fill="var(--orange)" />
              <circle cx="64" cy="419" r="1.5" fill="var(--orange)" />
              <path d="M 46 437 Q 56 428 66 437" />
            </g>

            {/* Y axis */}
            <path d="M 110 470 L 110 130 L 102 144 M 110 130 L 118 144"
              stroke="var(--orange)" strokeWidth="2.5" fill="none" strokeLinecap="round" strokeLinejoin="round" />
            {/* X axis */}
            <path d="M 110 470 L 940 470 L 926 462 M 940 470 L 926 478"
              stroke="var(--orange)" strokeWidth="2.5" fill="none" strokeLinecap="round" strokeLinejoin="round" />

            {/* Phase divider verticals */}
            <line x1="320" y1="135" x2="320" y2="470" stroke="var(--orange)" strokeWidth="1.5" opacity="0.55" strokeDasharray="4 6" />
            <line x1="700" y1="160" x2="700" y2="470" stroke="var(--orange)" strokeWidth="1.5" opacity="0.55" strokeDasharray="4 6" />

            {/* Bracket: building your MLP */}
            <g stroke="var(--orange)" strokeWidth="1.6" fill="none" strokeLinecap="round" opacity="0.85">
              <path d="M 142 432 L 313 432" />
              <path d="M 142 432 L 152 426 M 142 432 L 152 438" />
              <path d="M 313 432 L 303 426 M 313 432 L 303 438" />
            </g>
            <text x="227" y="453" textAnchor="middle"
              fill="var(--orange)" style={{ fontFamily: "Caveat, cursive", fontSize: 22, fontWeight: 500 }}>
              building your
            </text>
            <text x="227" y="472" textAnchor="middle"
              fill="var(--orange)" style={{ fontFamily: "Caveat, cursive", fontSize: 22, fontWeight: 500 }}>
              MLP
            </text>

            {/* Bracket: experimentation */}
            <g stroke="var(--orange)" strokeWidth="1.6" fill="none" strokeLinecap="round" opacity="0.85">
              <path d="M 332 432 L 690 432" />
              <path d="M 332 432 L 342 426 M 332 432 L 342 438" />
              <path d="M 690 432 L 680 426 M 690 432 L 680 438" />
            </g>
            <text x="511" y="453" textAnchor="middle"
              fill="var(--orange)" style={{ fontFamily: "Caveat, cursive", fontSize: 20, fontWeight: 500 }}>
              experimentation
            </text>

            {/* The curve */}
            <path
              ref={pathRef}
              d={CURVE_D}
              fill="none"
              stroke="var(--orange)"
              strokeWidth="4.5"
              strokeLinecap="round"
              strokeLinejoin="round"
            />

            {/* Dots: pulse ring (background) */}
            {dots.map((d) => (
              <circle
                key={`pulse-${d.id}`}
                cx={d.x} cy={d.y} r="9"
                fill="var(--orange)"
                className="arche-dot-pulse"
                style={{ pointerEvents: "none" }}
              />
            ))}

            {/* Dots: solid */}
            {dots.map((d) => (
              <circle key={`solid-${d.id}`} cx={d.x} cy={d.y} r="9"
                fill="var(--orange)" />
            ))}

            {/* Active dot ring */}
            {dots.map((d) => {
              const isActive = d.id === activeId;
              return (
                <circle
                  key={`ring-${d.id}`}
                  cx={d.x} cy={d.y}
                  r="16"
                  fill="none"
                  stroke="var(--orange)"
                  strokeWidth="2"
                  opacity={isActive ? 0.55 : 0}
                  style={{ transition: "opacity .25s" }}
                />
              );
            })}

            {/* Hand-drawn labels next to dots */}
            {dots.map((d) => {
              const c = JOURNEY.find((j) => j.id === d.id);
              // label positioning per dot
              const off = {
                problem: { dx: 18, dy: 5, anchor: "start" },
                launch:  { dx: 14, dy: -14, anchor: "start" },
                valley:  { dx: -10, dy: -14, anchor: "end" },
                pmf:     { dx: 14, dy: 6, anchor: "start" },
                growth:  { dx: 16, dy: 4, anchor: "start" },
                maturity:{ dx: -8, dy: -16, anchor: "end" }
              }[d.id];
              return (
                <text
                  key={`label-${d.id}`}
                  x={d.x + off.dx}
                  y={d.y + off.dy}
                  textAnchor={off.anchor}
                  fill="var(--orange)"
                  style={{ fontFamily: "Caveat, cursive", fontSize: 24, fontWeight: 500, pointerEvents: "none" }}
                >
                  {c.label}
                </text>
              );
            })}

            {/* Click targets */}
            {dots.map((d) => (
              <circle
                key={`hit-${d.id}`}
                cx={d.x} cy={d.y} r="22"
                fill="transparent"
                style={{ cursor: "pointer" }}
                onClick={() => setActiveId(d.id)}
              >
                <title>{JOURNEY.find((c) => c.id === d.id).label}</title>
              </circle>
            ))}
          </svg>
          </div>


        </div>

        {/* RIGHT: checkpoint card */}
        <div style={{
          background: "var(--orange)", color: "var(--white)",
          borderRadius: 20,
          padding: "28px 32px 32px",
          display: "flex", flexDirection: "column", gap: 14,
          alignSelf: "stretch"
        }}>
          <div>
            <h3 style={{
              margin: 0, fontWeight: 500, letterSpacing: "-0.01em",
              lineHeight: 1.1, fontSize: 26
            }}>
              {active.title}
            </h3>
            {active.funding && (
              <div style={{ fontSize: 13, opacity: 0.8, marginTop: 8, fontStyle: "italic" }}>
                {active.funding}
              </div>
            )}
          </div>

          <p style={{ margin: 0, fontSize: 14, lineHeight: 1.5 }}>
            {active.body}
          </p>

          <div>
            <div style={{ fontSize: 13, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", marginBottom: 10, opacity: 0.85 }}>
              Key questions by this milestone
            </div>
            <ul style={{
              margin: 0, paddingLeft: 18,
              display: "flex", flexDirection: "column", gap: 4,
              fontSize: 13.5, lineHeight: 1.45
            }}>
              {active.questions.map((q) => <li key={q}>{q}</li>)}
            </ul>
          </div>

          <div>
            <div style={{ fontSize: 13, fontWeight: 600, letterSpacing: "0.04em", textTransform: "uppercase", marginBottom: 10, opacity: 0.85 }}>
              How we can help
            </div>
            {active.notOffered ? (
              <div style={{
                fontSize: 14.5, lineHeight: 1.5, opacity: 0.85,
                padding: "12px 16px",
                border: "1px dashed rgba(255,255,255,0.5)",
                borderRadius: 12
              }}>
                We currently don't offer our services for this milestone.
              </div>
            ) : (
              <div style={{
                display: "flex", flexWrap: "wrap", gap: 8
              }}>
                {active.helps.map((h) => (
                  <span key={h} style={{
                    display: "inline-block",
                    background: "rgba(255,255,255,0.14)",
                    border: "1px solid rgba(255,255,255,0.35)",
                    color: "var(--white)",
                    borderRadius: 999,
                    padding: "6px 12px",
                    fontSize: 13.5,
                    lineHeight: 1.3
                  }}>
                    {h}
                  </span>
                ))}
              </div>
            )}
          </div>
        </div>
      </div>
      </Reveal>

      {/* MOBILE: horizontal dot slider + card */}
      <div className="journey-mobile" style={{
        flexDirection: "column", gap: 32,
        maxWidth: 342, margin: "0 auto",
        alignItems: "center",
      }}>
        {/* Slider track with dots */}
        {(() => {
          const activeIdx = JOURNEY.findIndex((c) => c.id === activeId);
          const total = JOURNEY.length;
          const trackWidth = 232;
          const dotSpacing = trackWidth / (total - 1);
          const sliderRef = React.useRef(null);

          const handleSliderInteraction = (clientX) => {
            const el = sliderRef.current;
            if (!el) return;
            const rect = el.getBoundingClientRect();
            const offsetX = clientX - rect.left - 20; // 20 = left padding for first dot
            const idx = Math.round(Math.max(0, Math.min(total - 1, offsetX / dotSpacing)));
            setActiveId(JOURNEY[idx].id);
          };

          return (
            <div
              ref={sliderRef}
              style={{
                position: "relative", height: 40, width: trackWidth + 40,
                cursor: "pointer", touchAction: "none",
              }}
              onMouseDown={(e) => handleSliderInteraction(e.clientX)}
              onMouseMove={(e) => { if (e.buttons === 1) handleSliderInteraction(e.clientX); }}
              onTouchStart={(e) => handleSliderInteraction(e.touches[0].clientX)}
              onTouchMove={(e) => { e.preventDefault(); handleSliderInteraction(e.touches[0].clientX); }}
            >
              {/* Track line — extends 16px beyond first and last dot */}
              <div style={{
                position: "absolute", top: 8, left: 20 - 16, width: trackWidth + 32, height: 24,
                background: "rgba(232,79,47,0.12)", borderRadius: 12,
              }} />
              {/* Inactive dots */}
              {JOURNEY.map((c, i) => {
                if (i === activeIdx) return null;
                return (
                  <div key={c.id} style={{
                    position: "absolute",
                    top: 8, left: 20 + i * dotSpacing - 12,
                    width: 24, height: 24, borderRadius: "50%",
                    background: "rgba(232,79,47,0.3)",
                    transition: "all .25s ease",
                  }} />
                );
              })}
              {/* Active dot — large orange circle with glow */}
              <div style={{
                position: "absolute",
                top: 0, left: 20 + activeIdx * dotSpacing - 20,
                width: 40, height: 40, borderRadius: "50%",
                background: "var(--orange)",
                transition: "left .3s cubic-bezier(.2,.7,.2,1)",
                animation: "sliderGlow 2s ease-in-out infinite",
              }} />
            </div>
          );
        })()}

        {/* Card showing active checkpoint */}
        <div style={{
          background: "var(--orange)", color: "var(--white)",
          borderRadius: 24, padding: 32, width: "100%",
          display: "flex", flexDirection: "column", gap: 24,
        }}>
          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            <div style={{ fontSize: 24, fontWeight: 500, lineHeight: 1.2 }}>
              {active.title}
            </div>
            <div style={{ fontSize: 16, fontWeight: 400, lineHeight: 1.5 }}>
              {active.body}
            </div>
          </div>

          <div style={{ display: "flex", flexDirection: "column", gap: 16 }}>
            {/* Key questions */}
            <div style={{ display: "flex", flexDirection: "column", gap: 18 }}>
              <div style={{ fontSize: 17, fontWeight: 500 }}>Key questions</div>
              <ul style={{
                margin: 0, paddingLeft: 24,
                display: "flex", flexDirection: "column", gap: 2,
                fontSize: 16, lineHeight: 1.5,
              }}>
                {active.questions.map((q) => <li key={q}>{q}</li>)}
              </ul>
            </div>

            {/* How we can help */}
            <div style={{ display: "flex", flexDirection: "column", gap: 18 }}>
              <div style={{ fontSize: 17, fontWeight: 500 }}>How we can help</div>
              {active.notOffered ? (
                <div style={{
                  fontSize: 16, lineHeight: 1.5, opacity: 0.85,
                  padding: "12px 16px",
                  border: "1px dashed rgba(255,255,255,0.5)",
                  borderRadius: 12,
                }}>
                  We currently don't offer our services for this milestone.
                </div>
              ) : (
                <div style={{
                  display: "flex", flexWrap: "wrap", gap: 8,
                }}>
                  {active.helps.map((h) => (
                    <span key={h} style={{
                      display: "inline-block",
                      background: "rgba(255,255,255,0.14)",
                      border: "1px solid rgba(255,255,255,0.35)",
                      color: "var(--white)",
                      borderRadius: 999,
                      padding: "6px 12px",
                      fontSize: 14,
                      lineHeight: 1.3,
                    }}>{h}</span>
                  ))}
                </div>
              )}
            </div>
          </div>
        </div>
      </div>
    </section>);

};

/* ───────────────────────── Plans (engagement tiers) ───────────────────────── */

const TIERS = [
{
  name: "Office Hours",
  rate: "170$ / HR",
  duration: "On-demand",
  body: "If you have a quick question, need an expert opinion on the next steps, or want to learn how to approach something you haven't done before."
},
{
  name: "Sprint",
  rate: "200$ / HR",
  duration: "1–3 weeks",
  body: "You have a scoped project with defined deliverables, but you don't have the time or expertise to do it.",
  deliverablesLabel: "Deliverables",
  deliverables: "Product audit, User interviews, Ideation workshop, UX specific flow"
},
{
  name: "Studio",
  rate: "200$ / HR",
  duration: "1 – 6 months",
  body: "You need a product and design function, but you're not ready to hire yet. We come in as your partners, embed fully in your workflow, and help you hit your next milestone, or you're ready to bring someone in-house."
}];


const Plans = () => {
  const isMobile = useIsMobile(768);
  return (
    <section id="plans" style={{
      background: "var(--bg)",
      color: "var(--orange)",
      padding: isMobile ? "64px 24px" : "120px 48px 140px",
      position: "relative"
    }}>
      <Reveal>
        <div style={{
          textAlign: "center", fontWeight: 500, fontSize: 16, letterSpacing: "0.01em",
          marginBottom: isMobile ? 24 : 56
        }}>
          Engagement tiers
        </div>
      </Reveal>

      <Reveal delay={0.15}>
      {isMobile ? (
        <div style={{ display: "flex", flexDirection: "column" }}>
          {TIERS.map((t, i) =>
          <div key={t.name} style={{
            padding: 32,
            borderLeft: "1px solid var(--orange)",
            borderRight: "1px solid var(--orange)",
            borderTop: "1px solid var(--orange)",
            borderBottom: i === TIERS.length - 1 ? "1px solid var(--orange)" : "none",
            display: "flex", flexDirection: "column",
            gap: 32, minHeight: 420
          }}>
              <h3 style={{
              margin: 0, fontFamily: "var(--sans)",
              fontWeight: 500, letterSpacing: "-0.01em",
              lineHeight: 1.1, fontSize: 24
            }}>{t.name}</h3>

              <div style={{ display: "flex", flexDirection: "column", gap: 5 }}>
                <span style={{ fontSize: 16, fontWeight: 300 }}>Starting at</span>
                <span style={{
                fontFamily: "var(--display)",
                fontSize: 40, lineHeight: 0.95, fontWeight: 400
              }}>{t.rate}</span>
              </div>

              <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
                <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                  <span style={{ fontSize: 16, fontWeight: 400 }}>Typical Duration</span>
                  <span style={{ fontSize: 16, fontWeight: 700 }}>{t.duration}</span>
                </div>
                <p style={{ margin: 0, fontSize: 16, lineHeight: 1.55, fontWeight: 400 }}>{t.body}</p>
                {t.deliverables &&
                <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                    <span style={{ fontSize: 16, fontWeight: 400 }}>{t.deliverablesLabel}</span>
                    <span style={{ fontSize: 16, fontWeight: 700, lineHeight: 1.4 }}>{t.deliverables}</span>
                  </div>
                }
              </div>
            </div>
          )}
        </div>
      ) : (
        <div style={{
          maxWidth: 1344, margin: "0 auto",
          borderTop: "1px solid var(--orange)",
          borderBottom: "1px solid var(--orange)",
          display: "grid",
          gridTemplateColumns: "repeat(3, 1fr)"
        }}>
          {TIERS.map((t, i) =>
          <div key={t.name} style={{
            padding: "56px 48px 64px",
            borderLeft: i === 0 ? "1px solid var(--orange)" : "none",
            borderRight: "1px solid var(--orange)",
            display: "flex", flexDirection: "column",
            gap: 32
          }}>
              <h3 style={{
              margin: 0, fontFamily: "var(--sans)",
              fontWeight: 500, letterSpacing: "-0.01em",
              lineHeight: 1.1, fontSize: 24
            }}>{t.name}</h3>

              <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                <span style={{ fontSize: 16, fontWeight: 400 }}>Starting at</span>
                <span style={{
                fontFamily: "var(--display)",
                fontSize: 40, lineHeight: 0.95, letterSpacing: "0.01em",
                fontWeight: 400
              }}>{t.rate}</span>
              </div>

              <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
                <span style={{ fontSize: 16, fontWeight: 400 }}>Typical Duration</span>
                <span style={{ fontSize: 18, fontWeight: 600, letterSpacing: "0.005em" }}>{t.duration}</span>
              </div>

              <p style={{ margin: 0, fontSize: 16, lineHeight: 1.55, fontWeight: 400, maxWidth: 280 }}>{t.body}</p>

              {t.deliverables &&
            <div style={{ display: "flex", flexDirection: "column", gap: 8, marginTop: -8 }}>
                  <span style={{ fontSize: 16, fontWeight: 400 }}>{t.deliverablesLabel}</span>
                  <span style={{ fontSize: 18, fontWeight: 600, lineHeight: 1.4, maxWidth: 280 }}>{t.deliverables}</span>
                </div>
            }
            </div>
          )}
        </div>
      )}
      </Reveal>
    </section>);

};

/* ───────────────────────── Team ───────────────────────── */

const TEAM = [
{
  name: "Heba Dwikat",
  img: "assets/heba.png",
  linkedin: "https://www.linkedin.com/in/heba-dwikat/",
  cardBg: "rgb(217,217,217)",
  bio: "I'm Heba, your PD & PM combo. I've been a 2x founder, worked with startups from pre‑seed to Series C, and built incubated startups inside global companies. My deepest work has been in healthcare and behavioral change. Most recently, I was the second founding PM at Envive AI.",
  pills: [
  { label: "Founder", color: "rgb(38,47,250)" },
  { label: "PM", color: "rgb(32,149,199)" },
  { label: "Designer", color: "rgb(193,116,16)" }]

},
{
  name: "Ryan Alli",
  img: "assets/ryan.png",
  linkedin: "https://www.linkedin.com/in/ryan-alli/",
  cardBg: "rgb(229,229,229)",
  bio: "I'm Ryan, PD x PM. I served as the lead product designer on Uber's fleet and sustainability team, where I coordinated engineering, data science, legal, operations, and product teams across both 0 → 1 and 1 → 100 initiatives. I focus on supporting across the full product spectrum: shaping the initial vision, getting into the code, working up a GTM plan, and making sure the business model actually holds up.",
  pills: [
  { label: "PM", color: "rgb(232,79,47)" },
  { label: "Designer", color: "rgb(193,116,16)" }]

},
{
  name: "Adrian Lavergne",
  img: "assets/adrian.png",
  linkedin: "https://www.linkedin.com/in/adrian-lavergne/",
  cardBg: "rgb(229,229,229)",
  bio: "I'm Adrian. I'm an AI Engineer and researcher for LLMs and stable diffusion models. I've been primarily entrenched in the startup world and as a result, I'm a rapid builder of ideas. Specifically I specialize in creating robust AI systems for critical work (solving for compliance, mitigating hallucinations, and building reliable processes for fine tuning models).",
  pills: [
  { label: "AI Engineer", color: "rgb(129,32,255)" },
  { label: "AI Scientist", color: "rgb(32,149,199)" }]

}];


const TeamMember = ({ member, flip, cardRef: externalCardRef }) => {
  const isMobile = useIsMobile(768);
  const internalCardRef = useRef(null);
  const cardRef = externalCardRef || internalCardRef;

  if (isMobile) {
    return (
      <div style={{
        display: "flex", flexDirection: "column", gap: 16,
        width: "100%",
      }}>
        {/* Portrait card — orange bg */}
        <div ref={cardRef} style={{
          width: "100%",
          borderRadius: 16, background: "var(--orange)",
          padding: 16, display: "flex", flexDirection: "column", gap: 32,
          overflow: "hidden",
        }}>
          <div style={{
            height: 425, borderRadius: 16, overflow: "hidden",
            background: `url(${member.img}) center top / cover no-repeat`
          }} />
          <div style={{ display: "flex", flexDirection: "column", gap: 8 }}>
            {/* Pills row */}
            <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
              {member.pills.map((p, pi) =>
                <span key={p.label} style={{
                  background: pi === 0 && member.name === "Heba Dwikat" ? "#000" : "#fff",
                  color: pi === 0 && member.name === "Heba Dwikat" ? "#fff" : "var(--orange)",
                  padding: "8px 12px", borderRadius: 24, fontSize: 16, fontWeight: 400,
                  lineHeight: 1
                }}>{p.label}</span>
              )}
            </div>
            {/* Name + LinkedIn */}
            <div style={{ display: "flex", alignItems: "center", gap: 16 }}>
              <span style={{ fontWeight: 500, fontSize: 24, lineHeight: 1, color: "var(--white)" }}>{member.name}</span>
              <a href={member.linkedin} target="_blank" rel="noopener noreferrer" aria-label="LinkedIn" style={{ display: "flex" }}>
                <IconLinkedIn size={24} color="#FFFFFF" />
              </a>
            </div>
          </div>
        </div>
        {/* Bio below card */}
        <p style={{ margin: 0, fontSize: 16, lineHeight: 1.5, color: "#682415" }}>{member.bio}</p>
      </div>
    );
  }

  const cardSide =
  <div ref={cardRef} style={{
      width: 690, maxWidth: "100%", height: 556,
      borderRadius: 16, background: "var(--orange)",
      padding: 16,
      display: "flex", flexDirection: "column",
      flex: "0 0 auto",
      transition: "transform .4s cubic-bezier(.2,.7,.2,1), box-shadow .4s",
    }}
  onMouseEnter={(e) => {e.currentTarget.style.transform = "translateY(-4px)";e.currentTarget.style.boxShadow = "0 30px 60px -30px rgba(104,36,21,0.3)";}}
  onMouseLeave={(e) => {e.currentTarget.style.transform = "translateY(0)";e.currentTarget.style.boxShadow = "none";}}>
      <div style={{
      height: 425, borderRadius: 16, overflow: "hidden",
      background: `url(${member.img}) center / cover no-repeat`,
      flex: "0 0 auto"
    }} />
      <div style={{
      marginTop: "auto", paddingTop: 16,
      display: "flex", justifyContent: "space-between", alignItems: "center", gap: 16
    }}>
        <div style={{ display: "flex", alignItems: "center", gap: 16 }}>
          <span style={{ fontWeight: 500, fontSize: 24, lineHeight: 1, color: "var(--white)" }}>{member.name}</span>
          <a href={member.linkedin} target="_blank" rel="noopener noreferrer" aria-label="LinkedIn" style={{ color: "var(--white)", display: "flex", transition: "opacity .2s" }}
        onMouseEnter={(e) => e.currentTarget.style.opacity = 0.65}
        onMouseLeave={(e) => e.currentTarget.style.opacity = 1}>
            <IconLinkedIn size={22} color="#FFFFFF" />
          </a>
        </div>
        <div style={{ display: "flex", gap: 8, flexWrap: "wrap", justifyContent: "flex-end" }}>
          {member.pills.map((p, pi) =>
        <span key={p.label} style={{
            background: pi === 0 && member.name === "Heba Dwikat" ? "#000" : "#fff",
            color: pi === 0 && member.name === "Heba Dwikat" ? "#fff" : "var(--orange)",
            padding: "8px 14px", borderRadius: 24, fontSize: 16, fontWeight: 400,
            lineHeight: 1.1
          }}>{p.label}</span>
        )}
        </div>
      </div>
    </div>;

  const bioSide =
  <div style={{ width: 379, maxWidth: "100%", color: "#682415", flex: "1 1 320px" }}>
      <p style={{ margin: 0, fontSize: 16, lineHeight: 1.5 }}>{member.bio}</p>
    </div>;

  return (
    <div style={{
      display: "flex", flexDirection: "row",
      gap: 48, alignItems: "center", flexWrap: "wrap", justifyContent: "center",
      maxWidth: 1140, margin: "0 auto"
    }}>
      {cardSide}
      {bioSide}
    </div>);
};

/* Horizontal-scroll team (desktop) / stacked vertical (mobile). */
const Team = () => {
  const isMobile = useIsMobile(768);
  const sectionRef = useRef(null);
  const trackRef = useRef(null);
  const panelRefs = useRef([]);
  const cardRefs = useRef([]);

  useEffect(() => {
    if (isMobile) return;

    const _gsap = window.gsap;
    const _ScrollTrigger = window.ScrollTrigger;
    if (!_gsap || !_ScrollTrigger) return;

    _gsap.registerPlugin(_ScrollTrigger);

    const track = trackRef.current;
    const section = sectionRef.current;
    if (!track || !section) return;

    const raf = requestAnimationFrame(() => {
      const totalScroll = track.scrollWidth - window.innerWidth;

      const horizontalTween = _gsap.to(track, {
        x: -totalScroll,
        ease: "none",
        scrollTrigger: {
          trigger: section,
          pin: true,
          scrub: 0.8,
          end: () => "+=" + totalScroll,
          invalidateOnRefresh: true,
        }
      });

      panelRefs.current.forEach((panel, i) => {
        if (!panel) return;

        const card = cardRefs.current[i];

        // Fade-in + slide-up for each panel's content
        const content = panel.querySelector(".team-panel-content");
        if (content && i > 0) {
          _gsap.fromTo(content,
            { opacity: 0, y: 50 },
            {
              opacity: 1, y: 0, duration: 0.4, ease: "power2.out",
              scrollTrigger: {
                trigger: panel,
                containerAnimation: horizontalTween,
                start: "left 80%",
                toggleActions: "play none none reverse",
              }
            }
          );
        }

        // Wiggle animation on the card
        if (card) {
          _ScrollTrigger.create({
            trigger: panel,
            containerAnimation: horizontalTween,
            start: "left 50%",
            onEnter: () => {
              card.style.animation = "archeWiggle 0.6s ease-in-out";
              setTimeout(() => { card.style.animation = "none"; }, 650);
            },
            once: true,
          });
        }
      });

      _ScrollTrigger.refresh();
    });

    return () => {
      cancelAnimationFrame(raf);
      const _ST = window.ScrollTrigger;
      if (_ST) _ST.getAll().forEach((st) => st.kill());
    };
  }, [isMobile]);

  /* ── Mobile: original stacked vertical layout ── */
  if (isMobile) {
    return (
      <section id="team" style={{
        background: "#FDEDEA",
        padding: "64px 24px",
      }}>
        <Reveal>
          <div style={{
            textAlign: "center",
            color: "#682415",
            fontWeight: 500, fontSize: 16,
            marginBottom: 32,
          }}>The team</div>
        </Reveal>
        <div style={{
          width: "100%",
          display: "flex", flexDirection: "column", gap: 32,
        }}>
          {TEAM.map((m, i) =>
            <Reveal key={m.name} delay={i * 0.12} style={{ width: "100%" }}>
              <TeamMember member={m} />
            </Reveal>
          )}
        </div>
      </section>
    );
  }

  /* ── Desktop: GSAP horizontal scroll ── */
  const panelStyle = {
    width: "100vw",
    height: "100vh",
    flexShrink: 0,
    display: "flex",
    alignItems: "center",
    justifyContent: "center",
    background: "#FDEDEA",
  };

  return (
    <section ref={sectionRef} id="team" style={{ overflow: "hidden" }}>
      <div ref={trackRef} style={{ display: "flex", flexWrap: "nowrap" }}>
        {TEAM.map((m, i) => (
          <div
            key={m.name}
            ref={(el) => (panelRefs.current[i] = el)}
            style={{ ...panelStyle, padding: "0 48px" }}
          >
            <div className="team-panel-content" style={{
              display: "flex", flexDirection: "column", alignItems: "center", gap: 0,
            }}>
              {/* "The team" label above the first panel's content */}
              {i === 0 && (
                <div style={{
                  textAlign: "center",
                  color: "#682415",
                  fontWeight: 500,
                  fontSize: 16,
                  marginBottom: 32,
                }}>The team</div>
              )}
              <TeamMember
                member={m}
                cardRef={(el) => (cardRefs.current[i] = el)}
              />
            </div>
          </div>
        ))}
      </div>
    </section>
  );
};

/* ───────────────────────── Footer ───────────────────────── */

const Footer = () => {
  const isMobile = useIsMobile(768);
  return (
    <footer style={{
      background: "var(--orange)", color: "var(--white)",
      padding: isMobile ? "48px 24px 32px" : "64px 48px 40px"
    }}>
      <Reveal>
      <div style={{
        maxWidth: 1344, margin: "0 auto",
        display: "grid",
        gridTemplateColumns: isMobile ? "1fr" : "2fr 1fr 1fr",
        gap: isMobile ? 32 : 48,
        alignItems: "flex-start"
      }}>
        <div>
          <div style={{
            fontFamily: "var(--display)",
            fontSize: isMobile ? 64 : 96,
            lineHeight: 0.85, letterSpacing: "-0.01em"
          }}>Arché</div>
          <div style={{ marginTop: 16, opacity: 0.85, fontSize: 14, lineHeight: 1.5 }}>
            Seattle · 47.6061° N, 122.3328°<br />
            heba@byarchestudio.com
          </div>
        </div>
        {isMobile ? (
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 24 }}>
            {[
              { h: "Specializing in", items: ["Product Strategy", "Product Design", "LLM Implementation"] },
              { h: "Connect", items: ["LinkedIn", "Twitter", "Book a call"] }
            ].map((col) =>
              <div key={col.h}>
                <div style={{ fontWeight: 500, fontSize: 13, opacity: 0.95, marginBottom: 12, textTransform: "uppercase", letterSpacing: "0.08em" }}>{col.h}</div>
                <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gap: 6, fontSize: 14 }}>
                  {col.items.map((item) => <li key={item} style={{ opacity: 0.9 }}>{item === "Book a call" ? <a href="#" onClick={(e) => { e.preventDefault(); openCalendly(); }} style={{ cursor: "pointer" }}>{item}</a> : item}</li>)}
                </ul>
              </div>
            )}
          </div>
        ) : (
          [
            { h: "Specializing in", items: ["Product Strategy", "Product Design", "LLM Implementation"] },
            { h: "Connect", items: ["LinkedIn", "Twitter", "Book a call"] }
          ].map((col) =>
            <div key={col.h}>
              <div style={{ fontWeight: 500, fontSize: 14, opacity: 0.95, marginBottom: 14, textTransform: "uppercase", letterSpacing: "0.08em" }}>{col.h}</div>
              <ul style={{ margin: 0, padding: 0, listStyle: "none", display: "grid", gap: 8, fontSize: 15 }}>
                {col.items.map((item) => <li key={item} style={{ opacity: 0.9 }}>{item === "Book a call" ? <a href="#" onClick={(e) => { e.preventDefault(); openCalendly(); }} style={{ cursor: "pointer" }}>{item}</a> : item}</li>)}
              </ul>
            </div>
          )
        )}
      </div>
      </Reveal>
      <Reveal delay={0.15}>
      <div style={{
        maxWidth: 1344, margin: isMobile ? "32px auto 0" : "48px auto 0",
        paddingTop: isMobile ? 20 : 24,
        borderTop: "1px solid rgba(255,255,255,0.25)",
        display: "flex", justifyContent: "space-between",
        fontSize: 13, opacity: 0.85
      }}>
        <span>&copy; 2026 Arch&eacute; Studio</span>
        <span>Built with intention.</span>
      </div>
      </Reveal>
    </footer>
  );
};


Object.assign(window, { NavBar, Hero, Vision, Principles, Journey, Plans, Team, Footer });