// Variation A — Editorial Index
// Asymmetric Swiss editorial: oversized display type, hairline rules,
// long-list work section with right-side hover preview pane.

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

const P = window.PORTFOLIO;

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

// --- Image slot — clean labeled placeholder (Swiss "no image yet") ----
// A flat tinted rectangle with a single hairline diagonal and clear
// monospace caption. Reads as intentional, not decorative.
function ImageSlot({ kind = "ROLE", title = "", meta = "" }) {
  return (
    <div style={{
      position: "relative",
      width: "100%", height: "100%",
      background: "var(--paper-2)",
      color: "var(--ink-2)",
      overflow: "hidden",
      borderTop: "1px solid var(--rule)",
      borderBottom: "1px solid var(--rule)",
    }}>
      <svg viewBox="0 0 100 60" preserveAspectRatio="none"
           style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}>
        <line x1="0" y1="0" x2="100" y2="60" stroke="currentColor" strokeOpacity="0.35" strokeWidth="0.25" vectorEffect="non-scaling-stroke" />
        <line x1="100" y1="0" x2="0" y2="60" stroke="currentColor" strokeOpacity="0.35" strokeWidth="0.25" vectorEffect="non-scaling-stroke" />
      </svg>
      <div style={{
        position: "absolute", inset: 0,
        display: "flex", flexDirection: "column",
        justifyContent: "space-between",
        padding: 14,
      }}>
        <div style={{
          fontFamily: "var(--mono)", fontSize: 10,
          letterSpacing: "0.14em", textTransform: "uppercase",
          color: "var(--ink-2)",
          display: "flex", justifyContent: "space-between",
        }}>
          <span>[{kind}]</span>
          <span>img · 4:3</span>
        </div>
        <div style={{
          fontFamily: "var(--mono)", fontSize: 10,
          letterSpacing: "0.1em", textTransform: "uppercase",
          color: "var(--ink-2)",
        }}>
          <div style={{ color: "var(--ink)", marginBottom: 2, fontSize: 11 }}>{title}</div>
          {meta && <div>↳ {meta}</div>}
        </div>
      </div>
    </div>
  );
}

// --- HEADER ----------------------------------------------------------
function HeaderA({ density }) {
  const isMobile = useIsMobile();
  const pad = density === "loose" ? 36 : density === "tight" ? 18 : 24;
  return (
    <header style={{
      display: "flex", alignItems: "baseline", justifyContent: "space-between",
      padding: isMobile ? "16px 20px" : `${pad}px 48px`,
      borderBottom: "1px solid var(--rule)",
      position: "sticky", top: 0, zIndex: 10,
      background: "var(--paper)", backdropFilter: "blur(8px)",
    }}>
      <div style={{ display: "flex", gap: 18, alignItems: "baseline" }}>
        <span style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)" }}>
          Sam Awasthi —
        </span>
        {!isMobile && (
          <span style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)" }}>
            Portfolio · Index · 2026
          </span>
        )}
      </div>
      {!isMobile && (
        <nav style={{ display: "flex", gap: 24, fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase" }}>
          {[["Work", "#work"], ["Agents", "#agents"], ["Playbooks", "#playbooks"], ["Room", "#room"], ["Recs", "#recommendations"], ["Background", "#about"], ["Contact", "#contact"]].map(([l, h]) => (
            <a key={l} href={h} style={{ color: "var(--ink)", textDecoration: "none", borderBottom: "1px solid transparent" }}
               onMouseEnter={e => e.currentTarget.style.borderBottomColor = "var(--accent)"}
               onMouseLeave={e => e.currentTarget.style.borderBottomColor = "transparent"}>
              {l}
            </a>
          ))}
        </nav>
      )}
      {isMobile && (
        <nav style={{ display: "flex", gap: 16, fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.1em", textTransform: "uppercase" }}>
          {[["Work", "#work"], ["Built", "#builds"], ["Contact", "#contact"]].map(([l, h]) => (
            <a key={l} href={h} style={{ color: "var(--ink)", textDecoration: "none" }}>{l}</a>
          ))}
        </nav>
      )}
    </header>
  );
}

// --- HERO ------------------------------------------------------------
function HeroA({ heroVariant }) {
  if (heroVariant === "marquee") return <HeroMarquee />;
  if (heroVariant === "asymmetric") return <HeroAsymmetric />;
  return <HeroEditorial />;
}

function HeroEditorial() {
  const isMobile = useIsMobile();
  return (
    <section style={{
      padding: isMobile ? "60px 20px 48px" : "120px 48px 80px",
      borderBottom: "1px solid var(--rule)",
      display: "grid",
      gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr",
      gap: isMobile ? 32 : 48,
      alignItems: "end",
    }}>
      <div>
        <div style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-2)", marginBottom: 32 }}>
          Introduction
        </div>
        <h1 style={{
          fontFamily: "var(--display)",
          fontSize: "clamp(64px, 9vw, 152px)",
          lineHeight: 0.92,
          letterSpacing: "-0.04em",
          fontWeight: 500,
          margin: 0,
          textWrap: "balance",
        }}>
          Hi, I'm <span style={{ fontStyle: "italic", fontWeight: 400 }}>Sam</span><br />
          Awasthi<span style={{ color: "var(--accent)" }}>.</span>
        </h1>
        <div style={{ marginTop: 32, fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", color: "var(--ink-2)", textTransform: "uppercase" }}>
          {P.location} · {new Date().getFullYear()}
        </div>
      </div>
      <div style={{ paddingBottom: 12 }}>
        <p style={{
          fontFamily: "var(--ui)", fontSize: 22, lineHeight: 1.35,
          fontWeight: 400, margin: 0, color: "var(--ink)",
          maxWidth: 520,
          textWrap: "pretty",
        }}>
          Growth & GTM operator. Creator with <span style={{ color: "var(--accent)" }}>400k+</span> followers and <span style={{ color: "var(--accent)" }}>400M+</span> views. I take a decade of audience-building inside early-stage AI startups and build growth engines from first principles.
        </p>
        <div style={{ marginTop: 36, display: "flex", gap: 24, fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)" }}>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 8 }}>
            <span style={{ width: 8, height: 8, borderRadius: "50%", background: "var(--accent)", display: "inline-block" }} /> Available
          </span>
          <span>{P.status}</span>
        </div>
      </div>
    </section>
  );
}

function HeroMarquee() {
  const phrases = ["Growth", "GTM", "Distribution", "Positioning", "Creator", "Operator", "AI Tools", "First-Principles", "400M+ Views", "400k+ Audience"];
  return (
    <section style={{ borderBottom: "1px solid var(--rule)", padding: "80px 0 64px" }}>
      <div style={{ padding: "0 48px", display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 48 }}>
        <div style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-2)" }}>Sam Awasthi</div>
        <div style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)" }}>{P.location}</div>
      </div>
      <div style={{ overflow: "hidden", borderTop: "1px solid var(--rule)", borderBottom: "1px solid var(--rule)", padding: "24px 0" }}>
        <div style={{
          display: "inline-flex", whiteSpace: "nowrap",
          animation: "marquee 40s linear infinite",
          fontFamily: "var(--display)", fontSize: "clamp(56px, 8vw, 120px)",
          letterSpacing: "-0.03em", lineHeight: 1, fontWeight: 500,
        }}>
          {[...phrases, ...phrases, ...phrases].map((p, i) => (
            <span key={i} style={{ paddingInline: 32 }}>
              {p}<span style={{ color: "var(--accent)", padding: "0 16px" }}>✦</span>
            </span>
          ))}
        </div>
      </div>
      <div style={{ padding: "48px 48px 0", display: "grid", gridTemplateColumns: "1fr 1fr", gap: 48 }}>
        <p style={{ fontFamily: "var(--ui)", fontSize: 22, lineHeight: 1.35, margin: 0, maxWidth: 540, textWrap: "pretty" }}>
          {P.bio}
        </p>
        <p style={{ fontFamily: "var(--ui)", fontSize: 22, lineHeight: 1.35, margin: 0, maxWidth: 540, color: "var(--ink-2)", textWrap: "pretty" }}>
          {P.bio2}
        </p>
      </div>
      <style>{`@keyframes marquee { from { transform: translateX(0); } to { transform: translateX(-33.33%); } }`}</style>
    </section>
  );
}

function HeroAsymmetric() {
  return (
    <section style={{
      padding: "80px 48px",
      borderBottom: "1px solid var(--rule)",
      display: "grid",
      gridTemplateColumns: "2fr 3fr 2fr",
      gap: 32,
      minHeight: "78vh",
      alignItems: "stretch",
    }}>
      <div style={{ borderRight: "1px solid var(--rule)", paddingRight: 32, display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
        <div style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-2)" }}>
          Subject<br /><span style={{ color: "var(--ink)" }}>Sam Awasthi</span>
        </div>
        <div style={{ aspectRatio: "1/1", border: "1px solid var(--rule)" }}>
          <ImageSlot kind="PORTRAIT" title="Sam Awasthi" meta="London · 2026" />
        </div>
      </div>
      <div style={{ display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
        <h1 style={{
          fontFamily: "var(--display)",
          fontSize: "clamp(56px, 7vw, 120px)",
          lineHeight: 0.95,
          letterSpacing: "-0.035em",
          fontWeight: 500, margin: 0,
        }}>
          Building <span style={{ color: "var(--accent)" }}>distribution</span>,<br />
          one&nbsp;<span style={{ fontStyle: "italic", fontWeight: 400 }}>founder</span> at a time.
        </h1>
        <p style={{ fontFamily: "var(--ui)", fontSize: 18, lineHeight: 1.45, maxWidth: 520, marginTop: 32, textWrap: "pretty" }}>
          {P.bio}
        </p>
      </div>
      <div style={{ borderLeft: "1px solid var(--rule)", paddingLeft: 32, display: "flex", flexDirection: "column", gap: 24, justifyContent: "flex-end" }}>
        {P.metrics.slice(0, 3).map((m, i) => (
          <div key={i} style={{ paddingTop: 16, borderTop: i ? "1px dashed var(--rule)" : "none" }}>
            <div style={{ fontFamily: "var(--display)", fontSize: 40, fontWeight: 500, lineHeight: 1, letterSpacing: "-0.02em" }}>{m.value}</div>
            <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)", marginTop: 6 }}>{m.label}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

// --- METRICS STRIP --------------------------------------------------
function parseMetric(value) {
  // "400k+" -> { num: 400, suffix: "k+" }, "400M+" -> { num: 400, suffix: "M+" }, "10 yrs" -> { num: 10, suffix: " yrs" }, "80+" -> { num: 80, suffix: "+" }
  const m = String(value).match(/^([\d,.]+)\s*(.*)$/);
  if (!m) return { num: null, suffix: value };
  const num = parseFloat(m[1].replace(/,/g, ""));
  return { num: isNaN(num) ? null : num, suffix: m[2] || "" };
}

function AnimatedNumber({ value, duration = 1400 }) {
  const { num, suffix } = parseMetric(value);
  const [display, setDisplay] = useState(num == null ? null : 0);
  const ref = useRef(null);
  const startedRef = useRef(false);

  useEffect(() => {
    if (num == null) return;
    const el = ref.current;
    if (!el) return;
    const io = new IntersectionObserver((entries) => {
      entries.forEach(e => {
        if (e.isIntersecting && !startedRef.current) {
          startedRef.current = true;
          const start = performance.now();
          const tick = (t) => {
            const p = Math.min(1, (t - start) / duration);
            // easeOutCubic
            const eased = 1 - Math.pow(1 - p, 3);
            setDisplay(num * eased);
            if (p < 1) requestAnimationFrame(tick);
            else setDisplay(num);
          };
          requestAnimationFrame(tick);
        }
      });
    }, { threshold: 0.4 });
    io.observe(el);
    return () => io.disconnect();
  }, [num, duration]);

  if (num == null) {
    return <span ref={ref}>{value}</span>;
  }
  // formatting: keep integer for whole numbers, else 1 decimal
  const isInt = Number.isInteger(num);
  const formatted = isInt
    ? Math.round(display).toLocaleString()
    : display.toFixed(1);
  return <span ref={ref}>{formatted}{suffix}</span>;
}

function MetricsStrip() {
  const isMobile = useIsMobile();
  return (
    <section style={{ padding: isMobile ? "24px 20px" : "32px 48px", borderBottom: "1px solid var(--rule)", display: "grid", gridTemplateColumns: isMobile ? "1fr 1fr" : "repeat(4, 1fr)" }}>
      {P.metrics.map((m, i) => (
        <div key={i} style={{
          paddingLeft: (isMobile ? i % 2 !== 0 : i !== 0) ? 24 : 0,
          borderLeft: (isMobile ? i % 2 !== 0 : i !== 0) ? "1px solid var(--rule)" : "none",
          paddingTop: isMobile && i >= 2 ? 20 : 0,
          borderTop: isMobile && i >= 2 ? "1px solid var(--rule)" : "none",
        }}>
          <div style={{ fontFamily: "var(--display)", fontSize: "clamp(36px, 4vw, 56px)", fontWeight: 500, lineHeight: 1, letterSpacing: "-0.02em", display: "flex", alignItems: "baseline", gap: 10 }}>
            <AnimatedNumber value={m.value} />
            {i === 0 && (
              <span aria-hidden="true" style={{
                width: 8, height: 8, borderRadius: "50%",
                background: "var(--accent)",
                animation: "samPulse 2s ease-in-out infinite",
                alignSelf: "center",
                flex: "0 0 8px",
              }} />
            )}
          </div>
          <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--ink-2)", marginTop: 8 }}>{m.label}</div>
        </div>
      ))}
    </section>
  );
}

// --- WORK LIST WITH HOVER PREVIEW -----------------------------------
function WorkListA({ items, sectionLabel, kindKey }) {
  const isMobile = useIsMobile();
  const [hover, setHover] = useState(null);
  const wrapRef = useRef(null);

  return (
    <section id={kindKey} style={{ borderBottom: "1px solid var(--rule)", padding: isMobile ? "48px 20px" : "80px 48px" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 48 }}>
        <div style={{ display: "flex", gap: 24, alignItems: "baseline" }}>
          <h2 style={{ fontFamily: "var(--display)", fontSize: 36, fontWeight: 500, margin: 0, letterSpacing: "-0.02em", color: "var(--accent)" }}>
            {sectionLabel}
          </h2>
        </div>
      </div>

      <div style={{ position: "relative" }}>
        {items.map((item, i) => (
          <WorkRow
            key={item.id}
            item={item}
            index={i}
            isOpen={hover === item.id}
            onToggle={() => setHover(hover === item.id ? null : item.id)}
          />
        ))}
      </div>
    </section>
  );
}

// --- BUILT SECTIONS (Agents + Playbooks under one ③) ----------------
function BuiltSectionsA({ agents, playbooks }) {
  const isMobile = useIsMobile();
  return (
    <section id="builds" style={{ borderBottom: "1px solid var(--rule)", padding: isMobile ? "48px 20px" : "80px 48px" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 56 }}>
        <div style={{ display: "flex", gap: 24, alignItems: "baseline" }}>
          <h2 style={{ fontFamily: "var(--display)", fontSize: 36, fontWeight: 500, margin: 0, letterSpacing: "-0.02em", color: "var(--accent)" }}>
            Things I've Built
          </h2>
        </div>
        <span style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", color: "var(--ink-2)" }}>
          AI agents · GTM playbooks
        </span>
      </div>

      <div style={{
        display: "grid",
        gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr",
        gap: isMobile ? 40 : 48,
      }}>
        <BuiltColumn id="agents" kicker="AI" label="AI Agents & Workflows" items={agents} hrefBase="agents" />
        <BuiltColumn id="playbooks" kicker="GTM" label="Playbooks & Work" items={playbooks} hrefBase="playbooks" />
      </div>
    </section>
  );
}

function BuiltColumn({ id, kicker, label, items, hrefBase }) {
  return (
    <div id={id} style={{ minWidth: 0 }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 24, paddingBottom: 16, borderBottom: "2px solid var(--ink)" }}>
        <div style={{ display: "flex", gap: 14, alignItems: "baseline", flexWrap: "wrap" }}>
          <span style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--accent)" }}>{kicker}</span>
          <h3 style={{ fontFamily: "var(--display)", fontSize: 22, fontWeight: 500, margin: 0, letterSpacing: "-0.01em" }}>
            {label}
          </h3>
        </div>
      </div>
      <div>
        {items.map((item, i) => (
          <CompactRow key={item.id} item={item} index={i} hrefBase={hrefBase} />
        ))}
      </div>
    </div>
  );
}

function CompactRow({ item, index, hrefBase }) {
  const [hover, setHover] = useState(false);
  const isBuild = item.kind === "Build";
  const title = item.title;
  const sub = isBuild ? item.subtitle : item.org;
  const meta = item.period || item.year || "";
  const href = `${item.id}.html`;
  return (
    <a href={href}
       onMouseEnter={() => setHover(true)}
       onMouseLeave={() => setHover(false)}
       style={{
         display: "grid",
         gridTemplateColumns: "32px 1fr 16px",
         alignItems: "baseline",
         gap: 16,
         padding: "20px 0",
         borderBottom: "1px solid var(--rule)",
         color: "var(--ink)",
         textDecoration: "none",
         fontFamily: "var(--ui)",
       }}>
      <span style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.12em", color: "var(--ink-2)" }}>
        {String(index + 1).padStart(2, "0")}
      </span>
      <div style={{ minWidth: 0 }}>
        <div style={{
          fontFamily: "var(--display)",
          fontSize: "clamp(20px, 1.7vw, 26px)",
          fontWeight: 500, letterSpacing: "-0.015em",
          lineHeight: 1.15,
          color: hover ? "var(--accent)" : "var(--ink)",
          transition: "color 0.25s",
        }}>
          {title}
        </div>
        <div style={{ marginTop: 6, display: "flex", gap: 12, flexWrap: "wrap", alignItems: "baseline" }}>
          <span style={{ fontFamily: "var(--ui)", fontSize: 13, color: "var(--ink-2)" }}>{sub}</span>
          {meta && <span style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)" }}>· {meta}</span>}
        </div>
      </div>
      <span style={{
        fontFamily: "var(--mono)", fontSize: 14,
        color: hover ? "var(--accent)" : "var(--ink-2)",
        transform: hover ? "translateX(4px)" : "none",
        transition: "transform 0.25s, color 0.25s",
        lineHeight: 1,
      }}>→</span>
    </a>
  );
}

function WorkRow({ item, index, isOpen, onToggle }) {
  const isMobile = useIsMobile();
  const isBuild = item.kind === "Build";
  const isPlaybook = item.kind === "Playbook";
  const title = (isBuild || isPlaybook) ? item.title : item.company;
  const subtitle = isBuild ? item.subtitle : isPlaybook ? `${item.org} · ${item.role}` : item.role;
  const year = item.period || item.year || "";

  // Magnetic hover state
  const btnRef = useRef(null);
  const [mag, setMag] = useState({ x: 0, y: 0, hov: false });
  const handleMove = (e) => {
    const el = btnRef.current;
    if (!el) return;
    const r = el.getBoundingClientRect();
    const cx = r.left + r.width / 2;
    const cy = r.top + r.height / 2;
    // normalize -1..1 across width/height
    const nx = (e.clientX - cx) / (r.width / 2);
    const ny = (e.clientY - cy) / (r.height / 2);
    setMag({ x: Math.max(-1, Math.min(1, nx)), y: Math.max(-1, Math.min(1, ny)), hov: true });
  };
  const handleLeave = () => setMag({ x: 0, y: 0, hov: false });

  // Magnitude of movement in px
  const TITLE_PULL = 10;
  const PLUS_PULL = 14;

  return (
    <div style={{
      borderTop: "1px solid var(--rule)",
      background: isOpen ? "var(--paper-2)" : "transparent",
      transition: "background 0.3s",
    }}>
      <button
        ref={btnRef}
        onClick={onToggle}
        onMouseMove={handleMove}
        onMouseLeave={handleLeave}
        style={{
          width: "100%", textAlign: "left",
          display: "grid",
          gridTemplateColumns: isMobile ? "32px 1fr 24px" : "60px 1.4fr 1.5fr 200px 32px",
          alignItems: "center",
          gap: isMobile ? 12 : 24,
          padding: isMobile ? "18px 0" : "24px 16px 24px 0",
          background: "transparent", border: "none",
          color: "var(--ink)", cursor: "pointer",
          fontFamily: "var(--ui)",
        }}
      >
        <span style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", color: "var(--ink-2)" }}>
          {String(index + 1).padStart(2, "0")}
        </span>
        <span style={{
          fontFamily: "var(--display)",
          fontSize: "clamp(28px, 3vw, 44px)",
          fontWeight: 500, letterSpacing: "-0.02em",
          lineHeight: 1.05,
          color: isOpen ? "var(--accent)" : (mag.hov ? "var(--accent)" : "var(--ink)"),
          transition: "color 0.3s, transform 0.35s cubic-bezier(.2,.8,.2,1)",
          transform: mag.hov ? `translate(${mag.x * TITLE_PULL}px, ${mag.y * TITLE_PULL * 0.5}px)` : "translate(0,0)",
          display: "inline-block",
          willChange: "transform",
        }}>
          {title}
        </span>
        {!isMobile && (
          <span style={{
            fontFamily: "var(--ui)", fontSize: 16,
            color: "var(--ink-2)", fontWeight: 400,
            transition: "transform 0.4s cubic-bezier(.2,.8,.2,1), opacity 0.3s",
            transform: mag.hov ? `translateX(${mag.x * 4}px)` : "translateX(0)",
            display: "inline-block",
            opacity: mag.hov && !isOpen ? 0.6 : 1,
          }}>
            {subtitle}
          </span>
        )}
        {!isMobile && (
          <span style={{
            fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em",
            textTransform: "uppercase", color: "var(--ink-2)",
            textAlign: "right",
          }}>
            {year}
          </span>
        )}
        <span style={{
          fontFamily: "var(--mono)", fontSize: 18,
          color: isOpen ? "var(--accent)" : (mag.hov ? "var(--accent)" : "var(--ink-2)"),
          transition: "transform 0.4s cubic-bezier(.2,.8,.2,1), color 0.3s",
          transform: isOpen
            ? "rotate(45deg)"
            : (mag.hov
                ? `translate(${mag.x * PLUS_PULL}px, ${mag.y * PLUS_PULL}px) scale(1.25)`
                : "translate(0,0) scale(1)"),
          textAlign: "right",
          lineHeight: 1,
          display: "inline-block",
          willChange: "transform",
        }}>+</span>
      </button>

      <div style={{
        maxHeight: isOpen ? 1600 : 0,
        overflow: "hidden",
        transition: "max-height 0.6s cubic-bezier(.2,.8,.2,1), opacity 0.4s",
        opacity: isOpen ? 1 : 0,
      }}>
        <RowDetail item={item} />
      </div>
    </div>
  );
}

function RowDetail({ item }) {
  const isMobile = useIsMobile();
  const isBuild = item.kind === "Build";
  const isPlaybook = item.kind === "Playbook";
  const isRole = !isBuild && !isPlaybook;
  const previewTitle = (isBuild || isPlaybook) ? item.title : item.company;
  const previewMeta = isBuild ? item.subtitle : isPlaybook ? item.org : item.period;
  const bodyText = isBuild ? item.detail : isPlaybook ? item.summary : item.summary;
  const hasMedia = item.youtube || (!isRole);
  return (
    <div style={{
      display: "grid",
      gridTemplateColumns: isMobile ? "1fr" : (hasMedia ? "60px 1fr 1.4fr" : "60px 1fr"),
      gap: 32,
      padding: isMobile ? "8px 0 32px" : "8px 0 48px",
    }}>
      {!isMobile && <div />}
      {hasMedia && (
      <div>
        <div style={{ aspectRatio: "16/9", border: "1px solid var(--rule)", marginBottom: 16, overflow: "hidden", background: "var(--paper-2)" }}>
          {item.youtube ? (
            <iframe
              src={`https://www.youtube.com/embed/${item.youtube}`}
              title={previewTitle}
              frameBorder="0"
              allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
              allowFullScreen
              style={{ width: "100%", height: "100%", border: "none", display: "block" }}
            />
          ) : (
            <ImageSlot kind={isBuild ? "BUILD" : "DOC"} title={previewTitle} meta={previewMeta} />
          )}
        </div>
        <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--ink-2)" }}>
          {isBuild ? item.subtitle : isPlaybook ? `${item.org} · ${item.period}` : item.period}
        </div>
        {item.tags && (
          <div style={{ marginTop: 14, display: "flex", flexWrap: "wrap", gap: 6 }}>
            {item.tags.map(t => (
              <span key={t} style={{
                fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.08em",
                textTransform: "uppercase", color: "var(--ink-2)",
              }}># {t}</span>
            ))}
          </div>
        )}
      </div>
      )}
      <div>
        {bodyText && (
          <p style={{ fontFamily: "var(--ui)", fontSize: 18, lineHeight: 1.5, marginTop: 0, color: "var(--ink)", maxWidth: 720, textWrap: "pretty" }}>
            {bodyText}
          </p>
        )}
        {item.outcome && (
          <div style={{
            marginTop: 24,
            padding: "16px 0",
            borderTop: "1px solid var(--rule)",
            borderBottom: "1px solid var(--rule)",
          }}>
            <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--ink-2)", marginBottom: 6 }}>
              Outcome
            </div>
            <div style={{ fontFamily: "var(--ui)", fontSize: 16, lineHeight: 1.5, color: "var(--ink)" }}>
              {item.outcome}
            </div>
          </div>
        )}
        {item.outcomes && item.outcomes.length > 0 && (
          <ul style={{ marginTop: 20, paddingLeft: 0, listStyle: "none" }}>
            {item.outcomes.map((o, j) => (
              <li key={j} style={{
                display: "grid", gridTemplateColumns: "20px 1fr",
                gap: 16, padding: "10px 0",
                fontFamily: "var(--ui)", fontSize: 16, lineHeight: 1.5,
                color: "var(--ink)",
                alignItems: "baseline",
              }}>
                <span aria-hidden="true" style={{
                  width: 6, height: 6, borderRadius: "50%",
                  background: "var(--accent)", justifySelf: "center",
                  transform: "translateY(-2px)",
                }}></span>
                <span style={{ textWrap: "pretty" }}>{o}</span>
              </li>
            ))}
          </ul>
        )}
        {item.stack && (
          <div style={{ marginTop: 20, display: "flex", flexWrap: "wrap", gap: 6 }}>
            {item.stack.map(s => (
              <span key={s} style={{
                fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.08em",
                textTransform: "uppercase", color: "var(--ink-2)",
                border: "1px solid var(--rule)", padding: "4px 10px",
              }}>{s}</span>
            ))}
          </div>
        )}
        {item.links && (
          <div style={{ marginTop: 24, display: "flex", gap: 18, flexWrap: "wrap" }}>
            {item.links.map(l => (
              <a key={l.label} href={l.href} target="_blank" rel="noreferrer"
                 style={{
                   fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em",
                   textTransform: "uppercase", color: "var(--ink)",
                   borderBottom: "1px solid var(--ink)", paddingBottom: 2, textDecoration: "none",
                 }}>
                {l.label} ↗
              </a>
            ))}
          </div>
        )}
      </div>
    </div>
  );
}


// --- IN THE ROOM (talks/recognition) --------------------------------
function RoomCard({ r, i, total, isMobile, children }) {
  const cardRef = useRef(null);
  const [pos, setPos] = useState({ x: 50, y: 50, on: false });
  const handleMove = (e) => {
    const el = cardRef.current;
    if (!el) return;
    const rect = el.getBoundingClientRect();
    setPos({
      x: ((e.clientX - rect.left) / rect.width) * 100,
      y: ((e.clientY - rect.top) / rect.height) * 100,
      on: true,
    });
  };
  const handleLeave = () => setPos(p => ({ ...p, on: false }));

  return (
    <div
      ref={cardRef}
      onMouseMove={handleMove}
      onMouseLeave={handleLeave}
      className={r.href ? "room-card-link" : ""}
      style={{
        padding: isMobile ? 20 : 28,
        borderTop: "1px solid var(--rule)",
        borderRight: !isMobile && (i + 1) % 3 ? "1px solid var(--rule)" : "none",
        borderBottom: isMobile ? (i < total - 1 ? "1px solid var(--rule)" : "none") : (i >= total - 3 ? "1px solid var(--rule)" : "none"),
        position: "relative",
        transition: "background 160ms ease",
        overflow: "hidden",
        isolation: "isolate",
      }}
    >
      {/* Cursor spotlight */}
      <div
        aria-hidden="true"
        style={{
          position: "absolute",
          inset: 0,
          pointerEvents: "none",
          opacity: pos.on ? 1 : 0,
          transition: "opacity 280ms ease",
          background: `radial-gradient(420px circle at ${pos.x}% ${pos.y}%, color-mix(in oklch, var(--accent) 14%, transparent) 0%, transparent 55%)`,
          zIndex: 0,
        }}
      />
      <div style={{ position: "relative", zIndex: 1 }}>
        {children}
      </div>
    </div>
  );
}

function InTheRoomA() {
  const isMobile = useIsMobile();
  return (
    <section id="room" style={{ borderBottom: "1px solid var(--rule)", padding: isMobile ? "48px 20px" : "80px 48px" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 48 }}>
        <div style={{ display: "flex", gap: 24, alignItems: "baseline" }}>
          <h2 style={{ fontFamily: "var(--display)", fontSize: 36, fontWeight: 500, margin: 0, letterSpacing: "-0.02em", color: "var(--accent)" }}>In the Room</h2>
        </div>
        <span style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", color: "var(--ink-2)" }}>Talks · panels · recognition</span>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: 0 }}>
        {P.inTheRoom.map((r, i) => (
          <RoomCard
            key={i}
            r={r}
            i={i}
            total={P.inTheRoom.length}
            isMobile={isMobile}
          >
            <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 16 }}>
              <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.14em", textTransform: "uppercase", color: "var(--ink-2)" }}>
                {String(i + 1).padStart(2, "0")} — {r.where}
              </div>
              {r.href && (
                <span aria-hidden="true" style={{ fontFamily: "var(--mono)", fontSize: 11, color: "var(--ink-2)" }}>↗</span>
              )}
            </div>
            {r.href ? (
              <a
                href={r.href}
                target="_blank"
                rel="noreferrer"
                style={{ color: "inherit", textDecoration: "none" }}
              >
                <h3 style={{ fontFamily: "var(--display)", fontSize: 24, fontWeight: 500, margin: 0, letterSpacing: "-0.015em", lineHeight: 1.15 }}>{r.title}</h3>
              </a>
            ) : (
              <h3 style={{ fontFamily: "var(--display)", fontSize: 24, fontWeight: 500, margin: 0, letterSpacing: "-0.015em", lineHeight: 1.15 }}>{r.title}</h3>
            )}
            <p style={{ fontFamily: "var(--ui)", fontSize: 14, lineHeight: 1.5, color: "var(--ink-2)", marginTop: 16, textWrap: "pretty" }}>
              {r.detail}
            </p>
            {r.hrefAlt && (
              <div style={{ marginTop: 14 }}>
                <a
                  href={r.hrefAlt}
                  target="_blank"
                  rel="noreferrer"
                  style={{
                    fontFamily: "var(--mono)",
                    fontSize: 10,
                    letterSpacing: "0.12em",
                    textTransform: "uppercase",
                    color: "var(--ink-2)",
                    textDecoration: "none",
                    borderBottom: "1px solid var(--rule)",
                    paddingBottom: 1,
                  }}
                >
                  Alt link ↗
                </a>
              </div>
            )}
          </RoomCard>
        ))}
      </div>
    </section>
  );
}

// --- RECOMMENDATIONS ------------------------------------------------
function RecommendationsA() {
  const isMobile = useIsMobile();
  const items = P.recommendations || [];
  if (!items.length) return null;
  return (
    <section id="recommendations" style={{ borderBottom: "1px solid var(--rule)", padding: isMobile ? "48px 20px" : "80px 48px" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 56 }}>
        <h2 style={{ fontFamily: "var(--display)", fontSize: 36, fontWeight: 500, margin: 0, letterSpacing: "-0.02em", color: "var(--accent)" }}>
          Recommendations
        </h2>
        <span style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", color: "var(--ink-2)" }}>
          From people I've worked with
        </span>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "repeat(3, 1fr)", gap: 0, borderTop: "1px solid var(--rule)", borderBottom: "1px solid var(--rule)" }}>
        {items.map((r, i) => {
          return (
            <figure key={i} style={{
              margin: 0,
              padding: isMobile ? "32px 0" : "40px 32px 36px",
              borderRight: !isMobile && i < items.length - 1 ? "1px solid var(--rule)" : "none",
              borderBottom: isMobile && i < items.length - 1 ? "1px solid var(--rule)" : "none",
              display: "flex", flexDirection: "column", gap: 24,
            }}>
              <span aria-hidden="true" style={{
                fontFamily: "var(--display)",
                fontSize: 56,
                lineHeight: 0.6,
                color: "var(--accent)",
                letterSpacing: "-0.04em",
                opacity: 0.55,
              }}>"</span>
              <blockquote style={{
                margin: 0,
                fontFamily: "var(--display)",
                fontSize: 19,
                lineHeight: 1.45,
                fontWeight: 400,
                letterSpacing: "-0.005em",
                color: "var(--ink)",
                textWrap: "pretty",
                flex: 1,
              }}>
                {r.quote}
              </blockquote>
              <figcaption style={{ display: "flex", flexDirection: "column", gap: 2, paddingTop: 18, borderTop: "1px dashed var(--rule)" }}>
                <span style={{ fontFamily: "var(--ui)", fontSize: 14, fontWeight: 500, color: "var(--ink)" }}>{r.name}</span>
                <span style={{ fontFamily: "var(--ui)", fontSize: 13, color: "var(--ink-2)", lineHeight: 1.35 }}>{r.role}</span>
                <span style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)", marginTop: 4 }}>
                  {[r.relation, r.date].filter(Boolean).join(" · ")}
                </span>
              </figcaption>
            </figure>
          );
        })}
      </div>
    </section>
  );
}

// --- ABOUT / EDUCATION / RECOGNITION --------------------------------
function AboutA() {
  const isMobile = useIsMobile();
  return (
    <section id="about" style={{ borderBottom: "1px solid var(--rule)", padding: isMobile ? "48px 20px" : "80px 48px" }}>
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", marginBottom: 56 }}>
        <div style={{ display: "flex", gap: 24, alignItems: "baseline" }}>
          <h2 style={{ fontFamily: "var(--display)", fontSize: 36, fontWeight: 500, margin: 0, letterSpacing: "-0.02em", color: "var(--accent)" }}>Background</h2>
        </div>
      </div>
      <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 40 : 64 }}>
        <div>
          <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-2)", marginBottom: 16 }}>Education</div>
          {P.education.map((e, i) => (
            <div key={i} style={{ paddingTop: 18, paddingBottom: 18, borderTop: "1px solid var(--rule)", borderBottom: i === P.education.length - 1 ? "1px solid var(--rule)" : "none" }}>
              <div style={{ fontFamily: "var(--display)", fontSize: 22, fontWeight: 500, letterSpacing: "-0.01em" }}>{e.school}</div>
              <div style={{ fontFamily: "var(--ui)", fontSize: 14, color: "var(--ink-2)", marginTop: 6 }}>{e.degree}</div>
              {e.note && <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--ink-2)", marginTop: 8 }}>{e.note}</div>}
            </div>
          ))}
        </div>
        <div>
          <div style={{ fontFamily: "var(--mono)", fontSize: 10, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-2)", marginBottom: 16 }}>Volunteering & Recognition</div>
          {P.recognition.map((r, i) => {
            const Tag = r.href ? "a" : "div";
            return (
              <Tag
                key={i}
                {...(r.href ? { href: r.href, target: "_blank", rel: "noreferrer" } : {})}
                style={{
                  display: "grid",
                  gridTemplateColumns: "180px 1fr 24px",
                  gap: 20,
                  padding: "14px 0",
                  borderTop: "1px solid var(--rule)",
                  borderBottom: i === P.recognition.length - 1 ? "1px solid var(--rule)" : "none",
                  color: "inherit",
                  textDecoration: "none",
                  alignItems: "baseline",
                }}
              >
                <span style={{ fontFamily: "var(--display)", fontSize: 17, fontWeight: 500 }}>{r.label}</span>
                <span style={{ fontFamily: "var(--ui)", fontSize: 14, color: "var(--ink-2)", lineHeight: 1.4 }}>{r.note}</span>
                <span aria-hidden="true" style={{ fontFamily: "var(--mono)", fontSize: 11, color: "var(--ink-2)", textAlign: "right", opacity: r.href ? 1 : 0 }}>↗</span>
              </Tag>
            );
          })}
        </div>
      </div>
    </section>
  );
}

// --- CONTACT --------------------------------------------------------
function ContactA() {
  const isMobile = useIsMobile();
  return (
    <section id="contact" style={{ padding: isMobile ? "64px 20px 48px" : "120px 48px 80px", borderBottom: "1px solid var(--rule)" }}>
      <div style={{ display: "grid", gridTemplateColumns: isMobile ? "1fr" : "1fr 1fr", gap: isMobile ? 32 : 48, alignItems: "end" }}>
        <div>
          <div style={{ fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--ink-2)", marginBottom: 24 }}>Get in touch</div>
          <h2 style={{ fontFamily: "var(--display)", fontSize: "clamp(56px, 7vw, 112px)", fontWeight: 500, lineHeight: 0.95, letterSpacing: "-0.035em", margin: 0, textWrap: "balance" }}>
            Let's build<br />
            something<br />
            <span style={{ fontStyle: "italic", fontWeight: 400 }}>distributable</span><span style={{ color: "var(--accent)" }}>.</span>
          </h2>
        </div>
        <div style={{ paddingBottom: 12 }}>
          <p style={{ fontFamily: "var(--ui)", fontSize: 18, lineHeight: 1.45, maxWidth: 480, marginBottom: 32, textWrap: "pretty" }}>
            Currently open to growth, GTM and operator roles at AI/tech scale-ups in London. Hybrid or remote. <span style={{ color: "var(--ink-2)" }}>LinkedIn is the fastest way to reach me.</span>
          </p>
          <div style={{ display: "grid", gap: 4 }}>
            {[
              ["LinkedIn", P.links.linkedin, "Preferred"],
              ["Email", P.links.email, "hello@samawasthi.com"],
              ["YouTube", P.links.youtube, ""],
              ["Instagram", P.links.instagram, ""],
              ["Substack", P.links.substack, ""],
              ["Podcast", P.links.podcast, ""],
              ["GitHub", P.links.github, ""],
            ].map(([l, h, note]) => (
              <a key={l} href={h} target="_blank" rel="noreferrer"
                 style={{
                   display: "grid", gridTemplateColumns: isMobile ? "1fr 24px" : "180px 1fr 24px", alignItems: "center",
                   gap: 16,
                   padding: "16px 0", borderTop: "1px solid var(--rule)",
                   fontFamily: "var(--ui)", fontSize: isMobile ? 16 : 18, color: "var(--ink)", textDecoration: "none",
                 }}
                 onMouseEnter={e => { e.currentTarget.style.paddingLeft = "12px"; e.currentTarget.querySelector(".arrow").style.color = "var(--accent)"; }}
                 onMouseLeave={e => { e.currentTarget.style.paddingLeft = "0"; e.currentTarget.querySelector(".arrow").style.color = "var(--ink-2)"; }}
              >
                <span>{l}</span>
                {!isMobile && (
                  <span style={{
                    fontFamily: l === "LinkedIn" ? "var(--mono)" : "var(--ui)",
                    fontSize: l === "LinkedIn" ? 10 : 14,
                    letterSpacing: l === "LinkedIn" ? "0.14em" : 0,
                    textTransform: l === "LinkedIn" ? "uppercase" : "none",
                    color: l === "LinkedIn" ? "var(--accent)" : "var(--ink-2)",
                    textAlign: "right",
                  }}>{note}</span>
                )}
                <span className="arrow" style={{ fontFamily: "var(--mono)", fontSize: 14, color: "var(--ink-2)", transition: "color 0.3s", textAlign: "right" }}>↗</span>
              </a>
            ))}
          </div>
        </div>
      </div>
    </section>
  );
}

// --- FOOTER ---------------------------------------------------------
function FooterA() {
  const isMobile = useIsMobile();
  return (
    <footer style={{ padding: isMobile ? "24px 20px" : "32px 48px", display: "flex", flexDirection: isMobile ? "column" : "row", gap: isMobile ? 6 : 0, justifyContent: "space-between", fontFamily: "var(--mono)", fontSize: 11, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--ink-2)" }}>
      <span>© {new Date().getFullYear()} Sam Awasthi</span>
      <span>Hand-built · v01 · Editorial Index</span>
      <span>Available for new projects</span>
    </footer>
  );
}

// --- ROOT ----------------------------------------------------------
function PortfolioA({ tweaks }) {
  return (
    <div style={{
      background: "var(--paper)",
      color: "var(--ink)",
      minHeight: "100vh",
      fontFamily: "var(--ui)",
    }}>
      <HeaderA density={tweaks.density} />
      <HeroA heroVariant={tweaks.heroVariant} />
      <MetricsStrip />
      <WorkListA items={P.work} sectionLabel="Work Experience" kindKey="work" />
      <BuiltSectionsA agents={P.agents} playbooks={P.playbooks} />
      <InTheRoomA />
      <RecommendationsA />
      <AboutA />
      <ContactA />
      <FooterA />
    </div>
  );
}

window.PortfolioA = PortfolioA;
