/* ===== Sorgent shared chrome + primitives (exported to window) ===== */
const { useState, useEffect, useRef } = React;

/* ---------- icons ---------- */
const Arrow = ({ s = 18 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square"><path d="M5 12h14M13 6l6 6-6 6" /></svg>
);
const ArrowUR = ({ s = 18 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square"><path d="M7 17L17 7M8 7h9v9" /></svg>
);
const Check = ({ s = 18 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="square"><path d="M5 13l4 4L19 7" /></svg>
);
const XIcon = ({ s = 16 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square"><path d="M6 6l12 12M18 6L6 18" /></svg>
);
const Send = ({ s = 16 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="square" strokeLinejoin="round"><path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" /></svg>
);
const IcTool = ({ s = 44 }) => (
  <svg width={s} height={s} viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="square" strokeLinejoin="round"><path d="M30 6l12 12-7 7-12-12z" /><path d="M23 13L6 30v12h12l17-17" /><path d="M6 42l9-9" /></svg>
);
const IcCommunity = ({ s = 44 }) => (
  <svg width={s} height={s} viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2"><circle cx="24" cy="24" r="17" />{[...Array(8)].map((_, i) => { const a = (i / 8) * Math.PI * 2; return <circle key={i} cx={24 + Math.cos(a) * 17} cy={24 + Math.sin(a) * 17} r="3" fill="currentColor" stroke="none" />; })}<circle cx="24" cy="24" r="3.4" fill="currentColor" stroke="none" /></svg>
);
const IcProjects = ({ s = 44 }) => (
  <svg width={s} height={s} viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="square"><path d="M10 38L38 10M10 10l28 28" /><path d="M24 4v8M24 36v8M4 24h8M36 24h8" /></svg>
);
const IcFlag = ({ s = 44 }) => (
  <svg width={s} height={s} viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="square" strokeLinejoin="round"><path d="M12 44V6" /><path d="M12 8h26l-6 8 6 8H12" /></svg>
);
const IcCompass = ({ s = 44 }) => (
  <svg width={s} height={s} viewBox="0 0 48 48" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinejoin="round"><circle cx="24" cy="24" r="19" /><path d="M32 16l-5 11-11 5 5-11z" fill="currentColor" stroke="none" opacity="0.9" /></svg>
);
const IcInstagram = ({ s = 16 }) => (
  <svg width={s} height={s} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect x="2" y="2" width="20" height="20" rx="5" /><circle cx="12" cy="12" r="4" /><circle cx="17.5" cy="6.5" r="1" fill="currentColor" stroke="none" /></svg>
);

/* ---------- ornaments ---------- */
const Ornament = () => (
  <svg className="ornament" viewBox="0 0 1200 26" preserveAspectRatio="xMidYMid meet" fill="none" stroke="currentColor" strokeWidth="1.4">
    <path d="M0 13 L40 2 L80 13 L120 24 L160 13 L200 2 L240 13 L280 24 L320 13 L360 2 L400 13 L440 24 L480 13 L520 2 L560 13 L600 24 L640 13 L680 2 L720 13 L760 24 L800 13 L840 2 L880 13 L920 24 L960 13 L1000 2 L1040 13 L1080 24 L1120 13 L1160 2 L1200 13" />
    {[...Array(15)].map((_, i) => { const cx = i * 80 + 40; return <path key={i} d={`M${cx} 7 L${cx + 6} 13 L${cx} 19 L${cx - 6} 13 Z`} fill="currentColor" stroke="none" />; })}
  </svg>
);
const CtaOrn = () => (
  <svg className="cta-orn" viewBox="0 0 1200 600" preserveAspectRatio="xMidYMid slice" fill="none" stroke="currentColor" strokeWidth="2">
    {[...Array(7)].map((_, r) => [...Array(13)].map((_, c) => { const x = c * 100, y = r * 100; return <path key={`${r}-${c}`} d={`M${x} ${y - 34} L${x + 34} ${y} L${x} ${y + 34} L${x - 34} ${y} Z`} />; }))}
  </svg>
);
const Mountains = () => (
  <svg className="hero-mtn" viewBox="0 0 1440 460" preserveAspectRatio="xMidYMax slice" fill="none">
    <path d="M0 460 L0 300 L240 150 L430 270 L640 90 L860 250 L1060 130 L1260 240 L1440 160 L1440 460 Z" fill="#221C14" />
    <path d="M0 460 L0 360 L210 250 L420 340 L660 210 L900 330 L1140 240 L1440 330 L1440 460 Z" fill="#1B160F" />
    <path d="M0 460 L0 410 L300 350 L560 405 L820 345 L1120 400 L1440 360 L1440 460 Z" fill="#15110D" />
    <path d="M640 90 L860 250 L740 250 Z" fill="none" stroke="rgba(196,69,54,0.5)" strokeWidth="1.5" />
  </svg>
);
const Logo = ({ s = 38 }) => (
  <img src="sorgent-logo.png" alt="Sorgent" className="brand-mark" width={s} height={s}
    style={{ width: s, height: s, objectFit: "contain", display: "block" }} />
);

/* ---------- soaring eagle silhouette (decorative) ---------- */
const Eagle = () => (
  <svg className="eagle" viewBox="0 0 140 86" fill="currentColor" aria-hidden="true">
    <g className="eagle-wings">
      <path d="M52 43 L30 36 L36 43 L30 50 Z" />
      <ellipse cx="64" cy="43" rx="16" ry="4.4" />
      <circle cx="83" cy="43" r="4" />
      <path d="M86 41 L93 43 L86 45 Z" />
      <path d="M70 41 Q62 20 50 9 L46 3 L50 10 L43 7 L49 14 L41 12 L48 18 Q58 28 62 42 Z" />
      <path d="M70 45 Q62 66 50 77 L46 83 L50 76 L43 79 L49 72 L41 74 L48 68 Q58 58 62 44 Z" />
    </g>
  </svg>
);

const STAR_SEED = [
  [6,8,1.6,4.2,0],[14,20,1,5.5,1.2],[22,11,1.3,4.8,0.6],[31,26,1,6,2.1],[39,14,1.7,5,0.3],
  [47,23,1,4.5,1.7],[55,9,1.2,5.8,0.9],[63,28,1,5.2,2.4],[71,16,1.5,4.6,0.5],[79,24,1,6.1,1.4],
  [87,12,1.3,5,2],[93,22,1,4.9,0.8],[10,30,1,5.6,1.1],[27,6,1.4,4.7,1.9],[44,32,1,5.9,0.4],
  [60,19,1.1,5.1,2.2],[76,31,1.6,4.4,0.7],[90,30,1,5.7,1.6],[18,15,1,5.3,2.5],[52,30,1.2,4.8,1],
  [68,7,1,6,0.2],[84,18,1.4,5.4,1.8],[36,21,1,4.6,2.3],[4,18,1.1,5.5,0.9],[96,15,1.3,5,1.5],
];
const Stars = () => (
  <div className="hero-stars" aria-hidden="true">
    {STAR_SEED.map(([x, y, s, tw, td], i) => (
      <i key={i} style={{ left: x + "%", top: y + "%", width: s, height: s, "--tw": tw + "s", "--td": td + "s" }} />
    ))}
  </div>
);

/* full hero ambiance: dusk glow + stars + gliding eagles */
const HeroSky = () => (
  <React.Fragment>
    <div className="hero-glow" />
    <div className="hero-glow cool" />
    <Stars />
    <div className="hero-eagles">
      <div className="eagle-fly" style={{ width: 64, opacity: 0.34, animation: "glide 34s linear infinite" }}><Eagle /></div>
      <div className="eagle-fly" style={{ width: 40, opacity: 0.22, animation: "glide 52s linear -22s infinite", filter: "blur(0.4px)" }}><Eagle /></div>
    </div>
  </React.Fragment>
);

/* ---------- navigation (hash router) ---------- */
const NAV = [
  ["/builders", "Программа Builders"], ["/showcase", "Showcase"],
  ["/community", "Sorgent Community"], ["/products", "Sorgent Products"],
  ["/faq", "FAQ"],
];
function go(path) { window.location.hash = "#" + path; }
function useRoute() {
  const [path, setPath] = useState(() => window.location.hash.replace(/^#/, "") || "/");
  useEffect(() => {
    const on = () => { setPath(window.location.hash.replace(/^#/, "") || "/"); window.scrollTo(0, 0); };
    window.addEventListener("hashchange", on);
    return () => window.removeEventListener("hashchange", on);
  }, []);
  return path;
}
const A = ({ to, className, children, ...rest }) => (
  <a href={"#" + to} className={className} {...rest}>{children}</a>
);

/* ---------- scroll-reveal hook (fires once when element enters viewport) ---------- */
function useInView(opts) {
  const ref = useRef(null);
  const [seen, setSeen] = useState(false);
  useEffect(() => {
    const el = ref.current;
    if (!el) return;
    if (typeof IntersectionObserver === "undefined") { setSeen(true); return; }
    const io = new IntersectionObserver((entries) => {
      entries.forEach((e) => { if (e.isIntersecting) { setSeen(true); io.disconnect(); } });
    }, { threshold: 0.2, rootMargin: "0px 0px -8% 0px", ...(opts || {}) });
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return [ref, seen];
}

/* ---------- illustration frame: scroll-reveal entrance + looping video (or still image) ----------
   video:  mp4 source — when set, renders an autoplaying muted loop with `src` as poster/fallback
   anim:   entrance direction — "up" | "left" | "right" | "scale"
   motion: continuous idle (PNG only) — "float" | "walk" | undefined
   glow:   soft warm halo behind the figure for depth
   hover:  gentle scale on hover                                                          */
function Illo({ src, video, alt = "", max, anim = "up", motion, glow, hover, delay = 0, className = "" }) {
  const [ref, inView] = useInView();
  const vidRef = useRef(null);
  useEffect(() => {
    if (!video || !vidRef.current) return;
    const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
    const apply = () => { if (mq.matches) { try { vidRef.current.pause(); } catch (e) {} } };
    apply();
    mq.addEventListener ? mq.addEventListener("change", apply) : mq.addListener(apply);
    return () => { mq.removeEventListener ? mq.removeEventListener("change", apply) : mq.removeListener(apply); };
  }, [video]);
  return (
    <figure
      ref={ref}
      className={`illo illo-${anim}${inView ? " in" : ""}${hover ? " illo-hover" : ""}${video ? " illo-video" : ""} ${className}`}
      style={{ maxWidth: max, transitionDelay: delay + "s" }}
    >
      {glow && <span className="illo-glow" aria-hidden="true" />}
      {video
        ? (
          <video ref={vidRef} className="illo-media" autoPlay loop muted playsInline preload="auto" poster={src} aria-label={alt}>
            <source src={video} type="video/mp4" />
            <img src={src} alt={alt} />
          </video>
        )
        : (
          <img src={src} alt={alt} draggable="false"
            className={motion ? "illo-motion illo-" + motion : ""}
            style={motion ? { animationDelay: (delay + 0.5) + "s" } : undefined} />
        )}
    </figure>
  );
}

function Nav({ path }) {
  const [open, setOpen] = useState(false);
  useEffect(() => { setOpen(false); }, [path]);
  return (
    <React.Fragment>
      <nav className="bar">
        <div className="wrap bar-inner">
          <a className="brand" href="#/">
            <Logo s={38} />
            <span>
              <span className="brand-name">SORGENT AI</span>
              <span className="brand-sub">Builders Community</span>
            </span>
          </a>
          <div className="nav-links">
            {NAV.map(([to, label]) => <a key={to} href={"#" + to} className={path === to ? "active" : ""}>{label}</a>)}
            <a className="nav-join" href="#/apply">Присоединиться</a>
          </div>
          <button className="burger" onClick={() => setOpen(!open)} aria-label="menu">
            {open ? <XIcon s={24} /> : <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M3 6h18M3 12h18M3 18h18" /></svg>}
          </button>
        </div>
      </nav>
      {open && (
        <div className="mobile-menu">
          {NAV.map(([to, label]) => <a key={to} href={"#" + to} onClick={() => setOpen(false)}>{label}</a>)}
          <a href="#/apply" onClick={() => setOpen(false)} style={{ marginTop: 16, justifyContent: "center", color: "var(--terra-2)", fontWeight: 600 }}>Присоединиться</a>
        </div>
      )}
    </React.Fragment>
  );
}

function Footer() {
  return (
    <footer className="foot">
      <div className="wrap foot-inner">
        <div className="foot-brand"><Logo s={18} /><span>Sorgent AI © 2026</span></div>
        <div className="foot-links">
          <a href="https://www.instagram.com/sorgentai/" target="_blank" rel="noopener noreferrer" className="foot-social"><IcInstagram s={14} /> Instagram</a>
          <a href="https://t.me/sorgentAi" target="_blank" rel="noopener noreferrer" className="foot-social"><Send s={14} /> Telegram канал</a>
          <a href="https://t.me/SorgentAii" target="_blank" rel="noopener noreferrer">Написать нам</a>
        </div>
      </div>
    </footer>
  );
}

/* mini-hero used by interior pages. pass `art` to show an illustration beside the copy */
function MiniHero({ rubric, title, sub, art }) {
  if (art) {
    return (
      <header className="minihero has-art">
        <div className="hero-grid" />
        <div className="wrap minihero-art-inner">
          <div className="mh-copy">
            <span className="rubric reveal d1" style={{ marginBottom: 28, display: "inline-flex" }}>{rubric}</span>
            <h1 className="mh-title reveal d2">{title}</h1>
            {sub && <p className="mh-sub reveal d3" style={{ marginTop: 28 }}>{sub}</p>}
          </div>
          <div className="mh-art reveal d3">{art}</div>
        </div>
      </header>
    );
  }
  return (
    <header className="minihero">
      <div className="hero-grid" />
      <div className="wrap minihero-inner">
        <div>
          <span className="rubric reveal d1" style={{ marginBottom: 28, display: "inline-flex" }}>{rubric}</span>
          <h1 className="mh-title reveal d2">{title}</h1>
        </div>
        {sub && <p className="mh-sub reveal d3">{sub}</p>}
      </div>
    </header>
  );
}

/* dusk scene #1 — a builder striding toward towering summits to conquer (HOME) */
const SceneSummits = () => (
  <svg className="cta-scene" viewBox="0 0 1440 440" preserveAspectRatio="xMidYMax slice" fill="none" aria-hidden="true">
    <defs>
      <radialGradient id="ctaSun" cx="50%" cy="100%" r="62%">
        <stop offset="0%" stopColor="#F4B25E" stopOpacity="0.9" />
        <stop offset="32%" stopColor="#D85B43" stopOpacity="0.5" />
        <stop offset="70%" stopColor="#8B1538" stopOpacity="0.1" />
        <stop offset="100%" stopColor="#8B1538" stopOpacity="0" />
      </radialGradient>
      <linearGradient id="ctaGround" x1="0" y1="0" x2="0" y2="1">
        <stop offset="0%" stopColor="#1d140d" />
        <stop offset="100%" stopColor="#0f0a06" />
      </linearGradient>
    </defs>

    {/* sun glow low on the horizon */}
    <ellipse cx="720" cy="330" rx="420" ry="200" fill="url(#ctaSun)" />

    {/* stars */}
    <g fill="#F5F1EB">
      <circle cx="200" cy="54" r="1.4" opacity="0.6" /><circle cx="360" cy="96" r="1" opacity="0.45" />
      <circle cx="540" cy="44" r="1.2" opacity="0.6" /><circle cx="900" cy="70" r="1.2" opacity="0.55" />
      <circle cx="1080" cy="46" r="1" opacity="0.45" /><circle cx="1230" cy="92" r="1.4" opacity="0.6" />
      <circle cx="1340" cy="60" r="1" opacity="0.45" /><circle cx="120" cy="120" r="1" opacity="0.4" />
    </g>
    {/* lone eagle high over the range */}
    <g transform="translate(1020 96)" fill="#C9B79C" opacity="0.45">
      <path d="M0 0 Q-13 -8 -28 -4 Q-17 -2 -13 2 Q-7 6 0 3 Q7 6 13 2 Q17 -2 28 -4 Q13 -8 0 0 Z" />
    </g>

    {/* ---- towering summits (the big peaks to conquer) ---- */}
    {/* back-left peak */}
    <path d="M120 360 L430 96 L560 360 Z" fill="#2a1f17" />
    <path d="M430 96 L520 273 L470 250 L445 285 Z" fill="#3a2c20" opacity="0.6" />
    {/* center peak — tallest */}
    <path d="M520 360 L760 40 L1010 360 Z" fill="#231a13" />
    <path d="M760 40 L760 360 L1010 360 Z" fill="#1a130d" />
    <path d="M760 40 L864 250 L815 226 L788 270 Z" fill="#4a3829" opacity="0.55" />
    {/* right peak */}
    <path d="M900 360 L1170 110 L1380 360 Z" fill="#1f1710" />
    <path d="M1170 110 L1170 360 L1380 360 Z" fill="#160f0a" />

    {/* summit flags (markers — swap for your own logos via the slots) */}
    <g stroke="#C44536" strokeWidth="3" strokeLinecap="round">
      <line x1="430" y1="96" x2="430" y2="64" /><line x1="760" y1="40" x2="760" y2="2" /><line x1="1170" y1="110" x2="1170" y2="80" />
    </g>
    <g fill="#C44536">
      <path d="M430 66 L458 73 L430 80 Z" />
      <path d="M760 4 L792 12 L760 20 Z" />
      <path d="M1170 82 L1196 88 L1170 94 Z" />
    </g>

    {/* foreground ground the builder walks on */}
    <path d="M0 440 L0 372 C 260 352 520 392 760 378 C 1010 364 1230 396 1440 376 L1440 440 Z" fill="url(#ctaGround)" />
    {/* trail toward the peaks */}
    <path d="M360 432 C 480 410 590 400 690 386 C 740 380 752 372 758 360" stroke="#C44536" strokeWidth="2" strokeDasharray="2 13" strokeLinecap="round" opacity="0.55" />

    {/* ---- the builder, striding forward ---- */}
    <g transform="translate(352 432) scale(1.25)">
      <ellipse cx="2" cy="2" rx="26" ry="5" fill="#000" opacity="0.35" />
      <g fill="#0E0A06" stroke="#D85B43" strokeWidth="1.1" strokeLinejoin="round">
        {/* backpack */}
        <rect x="-15" y="-46" width="11" height="20" rx="4" />
        {/* head */}
        <circle cx="0" cy="-52" r="6" />
        {/* torso, leaning into the climb */}
        <path d="M-6 -47 L6 -49 L9 -27 L-3 -25 Z" />
        {/* front leg striding forward */}
        <path d="M6 -27 L16 -12 L20 2 L14 3 L10 -10 L2 -24 Z" />
        {/* back leg pushing off */}
        <path d="M-2 -26 L-10 -12 L-16 0 L-10 2 L-6 -10 L4 -24 Z" />
        {/* forward arm */}
        <path d="M5 -44 L15 -36 L18 -28 L13 -27 L9 -35 L1 -40 Z" />
      </g>
      {/* trekking pole */}
      <line x1="17" y1="-30" x2="26" y2="4" stroke="#8a6a4a" strokeWidth="1.6" strokeLinecap="round" />
    </g>
  </svg>
);

/* dusk scene #2 — the builder atop conquered towers of big companies (BUILDERS) */
const SceneConquered = () => {
  const towers = [
    [120, 96, 250, "○"], [232, 112, 168, "△"], [360, 100, 300, "□"],
    [832, 116, 214, "◇"], [978, 96, 168, "△"], [1108, 124, 262, "○"], [1268, 100, 300, "□"],
  ];
  return (
    <svg className="cta-scene" viewBox="0 0 1440 440" preserveAspectRatio="xMidYMax slice" fill="none" aria-hidden="true">
      <defs>
        <radialGradient id="ctaSun2" cx="50%" cy="100%" r="60%">
          <stop offset="0%" stopColor="#F4B25E" stopOpacity="0.85" />
          <stop offset="34%" stopColor="#D85B43" stopOpacity="0.45" />
          <stop offset="72%" stopColor="#8B1538" stopOpacity="0.08" />
          <stop offset="100%" stopColor="#8B1538" stopOpacity="0" />
        </radialGradient>
      </defs>
      <ellipse cx="715" cy="340" rx="440" ry="220" fill="url(#ctaSun2)" />
      <g fill="#F5F1EB">
        <circle cx="220" cy="50" r="1.3" opacity="0.55" /><circle cx="430" cy="86" r="1" opacity="0.4" />
        <circle cx="600" cy="40" r="1.2" opacity="0.55" /><circle cx="880" cy="64" r="1.1" opacity="0.5" />
        <circle cx="1080" cy="44" r="1" opacity="0.4" /><circle cx="1260" cy="80" r="1.3" opacity="0.55" />
      </g>
      <g transform="translate(1040 84)" fill="#C9B79C" opacity="0.4">
        <path d="M0 0 Q-13 -8 -28 -4 Q-17 -2 -13 2 Q-7 6 0 3 Q7 6 13 2 Q17 -2 28 -4 Q13 -8 0 0 Z" />
      </g>

      {/* surrounding big-company towers (logo placeholders — swap via slots) */}
      {towers.map(([x, w, top, mark], i) => (
        <g key={i}>
          <rect x={x} y={top} width={w} height={440 - top} fill={i % 2 ? "#1a130d" : "#221812"} />
          <rect x={x + w - 3} y={top} width="3" height={440 - top} fill="#3a2c20" opacity="0.7" />
          {/* window rows */}
          {[...Array(Math.floor((440 - top) / 34))].map((_, r) =>
            [...Array(Math.max(1, Math.floor(w / 30)))].map((_, c) => (
              <rect key={r + "-" + c} x={x + 10 + c * 28} y={top + 18 + r * 34} width="9" height="12"
                fill="#E8973F" opacity={(r + c) % 3 === 0 ? 0.5 : 0.13} />
            ))
          )}
          {/* logo placeholder plaque */}
          <rect x={x + w / 2 - 16} y={top + 14} width="32" height="32" rx="4" fill="none" stroke="#6a4a32" strokeWidth="1.4" />
          <text x={x + w / 2} y={top + 36} textAnchor="middle" fontSize="20" fill="#8a6a4a" fontFamily="Onest, sans-serif">{mark}</text>
        </g>
      ))}

      {/* central tallest tower — the one we conquered */}
      <rect x="592" y="70" width="248" height="370" fill="#161009" />
      <rect x="592" y="70" width="248" height="6" fill="#2a1d12" />
      <rect x="592" y="70" width="4" height="370" fill="#3a2c20" opacity="0.6" />
      {[...Array(10)].map((_, r) =>
        [...Array(7)].map((_, c) => (
          <rect key={r + "-" + c} x={606 + c * 32} y={92 + r * 34} width="10" height="13"
            fill="#E8973F" opacity={(r * 7 + c) % 4 === 0 ? 0.55 : 0.12} />
        ))
      )}

      {/* the builder, planting a flag on the summit */}
      <g transform="translate(700 70)">
        <line x1="26" y1="-58" x2="26" y2="-2" stroke="#C44536" strokeWidth="3.5" strokeLinecap="round" />
        <path d="M26 -58 L62 -49 L26 -40 Z" fill="#C44536" />
        <g fill="#0E0A06" stroke="#D85B43" strokeWidth="1.1" strokeLinejoin="round">
          <circle cx="0" cy="-44" r="6.2" />
          <rect x="-13" y="-39" width="11" height="20" rx="4" />
          <path d="M-7 -38 L7 -38 L6 -16 L-6 -16 Z" />
          <path d="M-6 -16 L-9 2 L-3 2 L-1 -15 Z" />
          <path d="M2 -16 L6 2 L12 2 L8 -15 Z" />
          {/* raised arm holding flag pole */}
          <path d="M5 -36 L22 -52 L26 -49 L9 -31 Z" />
        </g>
      </g>
    </svg>
  );
};

/* dusk scene #3 — builders around a workbench, building a product (SHOWCASE) */
const WBuilder = ({ x, flip }) => (
  <g transform={`translate(${x} 360) scale(${flip ? -1 : 1} 1)`} fill="#0E0A06" stroke="#D85B43" strokeWidth="1.1" strokeLinejoin="round">
    <circle cx="0" cy="-46" r="6" />
    <rect x="-13" y="-41" width="10" height="18" rx="4" />
    <path d="M-6 -40 L7 -40 L6 -18 L-5 -18 Z" />
    <path d="M-5 -18 L-7 0 L-1 0 L1 -17 Z" />
    <path d="M2 -18 L7 0 L13 0 L7 -17 Z" />
    {/* arm reaching toward the table */}
    <path d="M5 -36 L20 -28 L22 -23 L17 -22 L7 -30 Z" />
  </g>
);
const SceneWorkshop = () => (
  <svg className="cta-scene" viewBox="0 0 1440 440" preserveAspectRatio="xMidYMax slice" fill="none" aria-hidden="true">
    <defs>
      <radialGradient id="ctaSun3" cx="50%" cy="46%" r="42%">
        <stop offset="0%" stopColor="#F4B25E" stopOpacity="0.5" />
        <stop offset="45%" stopColor="#D85B43" stopOpacity="0.18" />
        <stop offset="100%" stopColor="#8B1538" stopOpacity="0" />
      </radialGradient>
    </defs>
    <g fill="#F5F1EB">
      <circle cx="200" cy="56" r="1.3" opacity="0.5" /><circle cx="430" cy="40" r="1" opacity="0.4" />
      <circle cx="980" cy="50" r="1.2" opacity="0.5" /><circle cx="1240" cy="70" r="1.3" opacity="0.5" />
      <circle cx="1120" cy="38" r="1" opacity="0.4" />
    </g>
    {/* glow around the product being built */}
    <ellipse cx="720" cy="250" rx="300" ry="180" fill="url(#ctaSun3)" />

    {/* the workbench */}
    <path d="M470 318 L970 318 L1010 360 L430 360 Z" fill="#2a1d13" />
    <path d="M470 318 L970 318 L968 326 L472 326 Z" fill="#3d2a1a" />
    <rect x="452" y="360" width="14" height="80" fill="#1d140d" />
    <rect x="974" y="360" width="14" height="80" fill="#1d140d" />

    {/* product under construction — glowing assembled blocks */}
    <g>
      <rect x="664" y="250" width="112" height="70" rx="4" fill="#1a130d" stroke="#C44536" strokeWidth="1.5" />
      <rect x="676" y="262" width="88" height="34" rx="2" fill="#C44536" opacity="0.32" />
      <rect x="676" y="304" width="40" height="8" rx="2" fill="#E8973F" opacity="0.6" />
      {/* a stacked block being added, mid-air */}
      <rect x="700" y="208" width="42" height="30" rx="3" fill="#241811" stroke="#D85B43" strokeWidth="1.3" />
      <rect x="708" y="216" width="26" height="6" rx="2" fill="#E8973F" opacity="0.5" />
      {/* scaffolding lines */}
      <path d="M664 250 L664 226 M776 250 L776 226" stroke="#6a4a32" strokeWidth="1" strokeDasharray="2 5" opacity="0.7" />
      {/* spark */}
      <g stroke="#F4B25E" strokeWidth="1.6" strokeLinecap="round" opacity="0.8">
        <line x1="721" y1="196" x2="721" y2="188" /><line x1="711" y1="200" x2="706" y2="195" /><line x1="731" y1="200" x2="736" y2="195" />
      </g>
    </g>

    {/* tool icons floating above */}
    <g stroke="#8a6a4a" strokeWidth="1.5" fill="none" opacity="0.6">
      <path d="M560 230 l10 -10 a6 6 0 1 0 -8 -8 l-10 10 z" />
      <path d="M880 224 l16 0 M888 216 l0 16" strokeWidth="2" />
    </g>

    {/* builders around the bench */}
    <WBuilder x={520} flip={false} />
    <WBuilder x={930} flip={true} />
    <WBuilder x={620} flip={false} />

    {/* foreground floor */}
    <rect x="0" y="402" width="1440" height="38" fill="#120c08" />
  </svg>
);

/* dusk scene #4 — community gathered around a fire, talking (COMMUNITY) */
const Seated = ({ x, face = 1 }) => (
  <g transform={`translate(${x} 392) scale(${face} 1)`} fill="#0E0A06" stroke="#D85B43" strokeWidth="1.1" strokeLinejoin="round">
    <circle cx="0" cy="-30" r="6" />
    <path d="M-9 -26 Q-2 -31 5 -25 L10 -6 L-11 -6 Z" />
    <path d="M5 -24 L15 -14 L17 -8 L9 -10 L2 -18 Z" />
  </g>
);
const SceneCommunity = () => (
  <svg className="cta-scene" viewBox="0 0 1440 440" preserveAspectRatio="xMidYMax slice" fill="none" aria-hidden="true">
    <defs>
      <radialGradient id="ctaFire" cx="50%" cy="100%" r="60%">
        <stop offset="0%" stopColor="#F4B25E" stopOpacity="0.7" />
        <stop offset="34%" stopColor="#D85B43" stopOpacity="0.32" />
        <stop offset="72%" stopColor="#8B1538" stopOpacity="0.06" />
        <stop offset="100%" stopColor="#8B1538" stopOpacity="0" />
      </radialGradient>
    </defs>
    <g fill="#F5F1EB">
      <circle cx="200" cy="50" r="1.3" opacity="0.5" /><circle cx="430" cy="80" r="1" opacity="0.4" />
      <circle cx="620" cy="40" r="1.2" opacity="0.5" /><circle cx="880" cy="60" r="1.1" opacity="0.45" />
      <circle cx="1080" cy="44" r="1" opacity="0.4" /><circle cx="1260" cy="74" r="1.3" opacity="0.5" />
    </g>
    {/* distant ridge */}
    <path d="M0 300 L240 250 L470 296 L720 240 L980 300 L1230 252 L1440 296 L1440 360 L0 360 Z" fill="#1a130d" opacity="0.7" />
    {/* fire glow */}
    <ellipse cx="720" cy="380" rx="360" ry="180" fill="url(#ctaFire)" />
    {/* ground */}
    <path d="M0 440 L0 372 C 360 356 1080 356 1440 372 L1440 440 Z" fill="#120c08" />

    {/* campfire */}
    <g>
      <line x1="700" y1="392" x2="744" y2="380" stroke="#5a4030" strokeWidth="4" strokeLinecap="round" />
      <line x1="700" y1="380" x2="744" y2="392" stroke="#4a3424" strokeWidth="4" strokeLinecap="round" />
      <path d="M722 384 C 712 372 730 364 720 350 C 736 358 740 376 734 386 C 740 380 742 374 742 370 C 748 380 742 392 722 392 C 712 392 712 388 722 384 Z" fill="#D85B43" />
      <path d="M723 384 C 718 376 728 372 723 360 C 731 366 732 378 729 385 Z" fill="#F4B25E" />
    </g>

    {/* people seated around the fire, facing center */}
    <Seated x={560} face={1} /><Seated x={640} face={1} />
    <Seated x={820} face={-1} /><Seated x={900} face={-1} />
    <Seated x={470} face={1} /><Seated x={985} face={-1} />

    {/* speech bubbles — conversation */}
    <g>
      <rect x="516" y="332" width="34" height="20" rx="5" fill="#1d140d" stroke="#6a4a32" strokeWidth="1" />
      <path d="M528 352 l6 7 l3 -7 z" fill="#1d140d" stroke="#6a4a32" strokeWidth="1" />
      <g fill="#C9B79C"><circle cx="525" cy="342" r="1.6" /><circle cx="533" cy="342" r="1.6" /><circle cx="541" cy="342" r="1.6" /></g>
    </g>
    <g>
      <rect x="892" y="322" width="34" height="20" rx="5" fill="#1d140d" stroke="#6a4a32" strokeWidth="1" />
      <path d="M912 342 l-6 7 l-3 -7 z" fill="#1d140d" stroke="#6a4a32" strokeWidth="1" />
      <g fill="#C9B79C"><circle cx="901" cy="332" r="1.6" /><circle cx="909" cy="332" r="1.6" /><circle cx="917" cy="332" r="1.6" /></g>
    </g>
  </svg>
);

/* dusk scene #5 — a constellation of launched products, builder presenting (PRODUCTS) */
const AppWin = ({ x, y, w, h }) => (
  <g>
    <rect x={x} y={y} width={w} height={h} rx="5" fill="#1a130d" stroke="#D85B43" strokeWidth="1.3" />
    <rect x={x} y={y} width={w} height="11" rx="5" fill="#241811" />
    <g fill="#C44536"><circle cx={x + 9} cy={y + 5.5} r="1.8" /><circle cx={x + 16} cy={y + 5.5} r="1.8" /><circle cx={x + 23} cy={y + 5.5} r="1.8" /></g>
    <rect x={x + 9} y={y + 20} width={w - 18} height={h - 30} rx="3" fill="#C44536" opacity="0.16" />
    <rect x={x + 9} y={y + h - 14} width={(w - 18) * 0.5} height="5" rx="2" fill="#E8973F" opacity="0.55" />
  </g>
);
const SceneProducts = () => (
  <svg className="cta-scene" viewBox="0 0 1440 440" preserveAspectRatio="xMidYMax slice" fill="none" aria-hidden="true">
    <defs>
      <radialGradient id="ctaSunP" cx="50%" cy="40%" r="50%">
        <stop offset="0%" stopColor="#F4B25E" stopOpacity="0.4" />
        <stop offset="46%" stopColor="#D85B43" stopOpacity="0.14" />
        <stop offset="100%" stopColor="#8B1538" stopOpacity="0" />
      </radialGradient>
    </defs>
    <g fill="#F5F1EB">
      <circle cx="180" cy="44" r="1.3" opacity="0.5" /><circle cx="400" cy="80" r="1" opacity="0.4" />
      <circle cx="1040" cy="40" r="1.2" opacity="0.5" /><circle cx="1300" cy="66" r="1.3" opacity="0.5" />
      <circle cx="560" cy="34" r="1" opacity="0.4" /><circle cx="860" cy="54" r="1.1" opacity="0.45" />
    </g>
    <ellipse cx="720" cy="210" rx="420" ry="200" fill="url(#ctaSunP)" />

    {/* constellation links from the builder up to the products */}
    <g stroke="#C44536" strokeWidth="1.2" strokeDasharray="2 9" opacity="0.45">
      <path d="M720 410 L500 150" /><path d="M720 410 L760 96" /><path d="M720 410 L1010 170" /><path d="M720 410 L300 240" /><path d="M720 410 L1180 250" />
    </g>

    {/* launched product windows, various sizes */}
    <AppWin x={250} y={206} w={96} h={66} />
    <AppWin x={448} y={116} w={108} h={74} />
    <AppWin x={712} y={66} w={120} h={82} />
    <AppWin x={958} y={134} w={104} h={72} />
    <AppWin x={1132} y={214} w={92} h={64} />

    {/* the builder, presenting (arm raised to the launches) */}
    <g transform="translate(706 410) scale(1.3)">
      <ellipse cx="2" cy="2" rx="24" ry="5" fill="#000" opacity="0.35" />
      <g fill="#0E0A06" stroke="#D85B43" strokeWidth="1.1" strokeLinejoin="round">
        <circle cx="0" cy="-46" r="6.2" />
        <path d="M-7 -41 L7 -41 L6 -18 L-6 -18 Z" />
        <path d="M-6 -18 L-9 2 L-3 2 L-1 -17 Z" />
        <path d="M2 -18 L7 2 L13 2 L7 -17 Z" />
        {/* raised presenting arm */}
        <path d="M4 -39 L20 -54 L24 -50 L9 -34 Z" />
      </g>
    </g>
    {/* ground */}
    <rect x="0" y="410" width="1440" height="30" fill="#120c08" />
  </svg>
);

const CtaScene = ({ variant }) =>
  variant === "conquered" ? <SceneConquered />
    : variant === "workshop" ? <SceneWorkshop />
      : variant === "community" ? <SceneCommunity />
        : variant === "products" ? <SceneProducts />
          : <SceneSummits />;

/* reusable CTA poster. quiet=true drops the loud apply button → soft text link only */
function CtaPoster({ rubric, title, note, primary, link, scene, quiet }) {
  return (
    <section className="cta">
      <CtaScene variant={scene} />
      <div className="wrap cta-inner">
        <span className="rubric">{rubric}</span>
        <h2>{title}</h2>
        {note && <p className="cta-note">{note}</p>}
        <div className="cta-foot">
          {quiet
            ? <a className="cta-link" href={"#" + primary[1]}>{primary[0]} <Arrow s={16} /></a>
            : <a className="btn-primary" href={"#" + primary[1]}>{primary[0]} <Arrow s={18} /></a>}
          {link && !quiet && <a className="cta-link" href={"#" + link[1]}>{link[0]} <Arrow s={16} /></a>}
        </div>
      </div>
    </section>
  );
}

/* floating «contact us» widget — soft, non-pushy, all pages */
function ContactWidget() {
  const [open, setOpen] = useState(false);
  return (
    <div className="contact-widget">
      {open && (
        <div className="contact-popup">
          <p>Есть вопросы про Sorgent? Напиши нам в Telegram — ответим живым человеком.</p>
          <a href="https://t.me/SorgentAii" target="_blank" rel="noopener noreferrer" className="btn-primary contact-tg">
            Telegram <Arrow s={14} />
          </a>
        </div>
      )}
      <button className="contact-fab" onClick={() => setOpen(!open)} aria-label="Связаться">
        {open
          ? <XIcon s={20} />
          : <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><line x1="22" y1="2" x2="11" y2="13" /><polygon points="22 2 15 22 11 13 2 9 22 2" /></svg>}
      </button>
    </div>
  );
}

function Tooltip({ text }) {
  return (
    <span className="tt"><button className="tt-btn" aria-label="info">i</button><span className="tt-pop">{text}</span></span>
  );
}

/* ---------- brand marks (simplified monochrome, currentColor; reused in tech strip + climb) ---------- */
const MarkGoogle = () => (
  <g fill="none" stroke="currentColor" strokeWidth="3.2" strokeLinecap="round" strokeLinejoin="round">
    <path d="M25.6 8.6 A11 11 0 1 0 27 17 L16.6 17" />
  </g>
);
const MarkOpenAI = () => (
  <g fill="none" stroke="currentColor" strokeWidth="2.3" strokeLinejoin="round">
    <path d="M16 3 L27 9.5 L27 22.5 L16 29 L5 22.5 L5 9.5 Z" />
    <path d="M16 4 L16 16 M16 16 L26.4 22 M16 16 L5.6 22" />
  </g>
);
const MarkClaude = () => (
  <g stroke="currentColor" strokeWidth="2.2" strokeLinecap="round">
    {[...Array(12)].map((_, i) => {
      const a = i * Math.PI / 6, c = Math.cos(a), s = Math.sin(a);
      return <line key={i} x1={16 + 4.6 * c} y1={16 + 4.6 * s} x2={16 + 12.6 * c} y2={16 + 12.6 * s} />;
    })}
  </g>
);
const MarkMicrosoft = () => (
  <g fill="currentColor">
    <rect x="3.5" y="3.5" width="10.5" height="10.5" /><rect x="18" y="3.5" width="10.5" height="10.5" />
    <rect x="3.5" y="18" width="10.5" height="10.5" /><rect x="18" y="18" width="10.5" height="10.5" />
  </g>
);
const MarkMeta = () => (
  <g fill="none" stroke="currentColor" strokeWidth="2.6" strokeLinejoin="round" strokeLinecap="round">
    <path d="M6 16 C6 9.5 13.5 9.5 16 16 C18.5 22.5 26 22.5 26 16 C26 9.5 18.5 9.5 16 16 C13.5 22.5 6 22.5 6 16 Z" />
  </g>
);
const MarkReact = () => (
  <g fill="none" stroke="currentColor" strokeWidth="1.7">
    <ellipse cx="16" cy="16" rx="13" ry="5" />
    <ellipse cx="16" cy="16" rx="13" ry="5" transform="rotate(60 16 16)" />
    <ellipse cx="16" cy="16" rx="13" ry="5" transform="rotate(120 16 16)" />
    <circle cx="16" cy="16" r="2.5" fill="currentColor" stroke="none" />
  </g>
);
const MarkVercel = () => (
  <g fill="currentColor"><path d="M16 5 L28.5 26.5 L3.5 26.5 Z" /></g>
);
const MarkFigma = () => (
  <g fill="currentColor">
    <rect x="6.4" y="1.6" width="9.2" height="9.2" rx="2" /><rect x="16.4" y="1.6" width="9.2" height="9.2" rx="2" />
    <rect x="6.4" y="11.4" width="9.2" height="9.2" rx="2" /><circle cx="21" cy="16" r="4.6" />
    <rect x="6.4" y="21.2" width="9.2" height="9.2" rx="2" />
  </g>
);
const MarkSupabase = () => (
  <g fill="currentColor"><path d="M17.5 1.6 L6.5 16.8 L15 16.8 L14.5 30.4 L25.5 15.2 L17 15.2 Z" /></g>
);

const TechLogo = ({ mark, name, cls }) => (
  <span className={"blogo" + (cls ? " " + cls : "")}>
    <svg viewBox="0 0 32 32" className="blogo-mark">{mark}</svg>
    <span className="blogo-txt">{name}</span>
  </span>
);
const LogoOpenAI = () => <TechLogo mark={<MarkOpenAI />} name="OpenAI" />;
const LogoClaude = () => <TechLogo mark={<MarkClaude />} name="Claude" cls="claude" />;
const LogoGoogle = () => <TechLogo mark={<MarkGoogle />} name="Google" />;
const LogoFigma = () => <TechLogo mark={<MarkFigma />} name="Figma" />;
const LogoReact = () => <TechLogo mark={<MarkReact />} name="React" />;
const LogoSupabase = () => <TechLogo mark={<MarkSupabase />} name="Supabase" />;
const LogoVercel = () => <TechLogo mark={<MarkVercel />} name="Vercel" />;

Object.assign(window, {
  Arrow, ArrowUR, Check, XIcon, Send, IcTool, IcCommunity, IcProjects, IcFlag, IcCompass, IcInstagram,
  Ornament, CtaOrn, Mountains, Logo, Eagle, Stars, HeroSky, NAV, go, useRoute, useInView, A, Illo, Nav, Footer, MiniHero, CtaPoster, ContactWidget, Tooltip,
  MarkGoogle, MarkOpenAI, MarkClaude, MarkMicrosoft, MarkMeta, MarkReact, MarkVercel, MarkFigma, MarkSupabase,
  TechLogo, LogoOpenAI, LogoClaude, LogoGoogle, LogoFigma, LogoReact, LogoSupabase, LogoVercel,
});
