function MiniInv({ v, dark }) {
  return (
    <div style={{ display: "flex", alignItems: "center", gap: 10, padding: 10, borderRadius: 12, background: dark ? "rgba(255,255,255,.06)" : "#fff", border: "1px solid " + (dark ? "rgba(255,255,255,.1)" : "var(--border-subtle)"), boxShadow: dark ? "none" : "0 2px 8px rgba(15,23,42,.04)" }}>
      <LogoAvatar dom={v.dom} name={v.firm} size={34} />
      <div style={{ minWidth: 0, flex: 1 }}>
        <p className="trunc" style={{ fontSize: 13, fontWeight: 600, color: dark ? "#fff" : "var(--text-primary)" }}>{v.name}</p>
        <span className="trunc" style={{ fontSize: 11, color: dark ? "#8D97B5" : "var(--text-muted)", display: "block", marginTop: 1 }}>{v.firm}</span>
      </div>
    </div>
  );
}

function ArtInvestorWall() {
  const cols = [0, 1, 2, 3].map(c => CH.investors.filter((_, i) => i % 4 === c));
  return (
    <div className="fade-y" style={{ height: 300, width: "100%", display: "grid", gridTemplateColumns: "repeat(4,minmax(0,1fr))", gap: 10, overflow: "hidden" }}>
      {cols.map((col, c) => <div key={c} style={{ overflow: "hidden" }}><div className={"vcol" + (c % 2 ? " dn" : "")} style={{ "--dur": 22 + c * 5 + "s" }}>{[...col, ...col].map((v, i) => <MiniInv key={i} v={v} />)}</div></div>)}
    </div>
  );
}

function ArtNetwork() {
  const pts = [[16, 18], [84, 16], [10, 70], [90, 72], [50, 92]];
  const people = [0, 1, 2, 3, 4].map(i => CH.investors[i]);
  return (
    <div style={{ position: "relative", width: "100%", height: 260 }}>
      <svg viewBox="0 0 100 100" preserveAspectRatio="none" style={{ position: "absolute", inset: 0, width: "100%", height: "100%" }}>
        {pts.map(([x, y], i) => <line key={i} x1="50" y1="48" x2={x} y2={y} stroke="#1E3A8A" strokeOpacity=".35" strokeWidth=".5" strokeDasharray="2 2" vectorEffect="non-scaling-stroke" style={{ animation: "dash 1.6s linear infinite" }} />)}
      </svg>
      <div style={{ position: "absolute", left: "50%", top: "48%", transform: "translate(-50%,-50%)", width: 74, height: 74, borderRadius: "50%", background: "linear-gradient(135deg,#1E3A8A,#3B82F6)", display: "flex", alignItems: "center", justifyContent: "center", boxShadow: "0 0 0 8px rgba(59,130,246,.12),0 12px 30px rgba(30,58,138,.35)" }}><img src="assets/logos/icon-white.png" alt="" style={{ width: 32 }} /></div>
      {people.map((v, i) => <div key={i} style={{ position: "absolute", left: pts[i][0] + "%", top: pts[i][1] + "%", transform: "translate(-50%,-50%)", display: "flex", flexDirection: "column", alignItems: "center", gap: 4 }}><LogoAvatar dom={v.dom} name={v.firm} size={42} style={{ boxShadow: "0 0 0 3px #fff,0 6px 16px rgba(15,23,42,.18)" }} /><MatchScore value={v.match} style={{ height: 18, fontSize: 10, animation: `pulse 2.6s ${i * .4}s ease-in-out infinite` }} /></div>)}
    </div>
  );
}

function ArtPerks() {
  return (
    <div style={{ width: "100%", display: "flex", flexDirection: "column", gap: 8 }}>
      {CH.perks.slice(0, 4).map((p, i) => (
        <div key={p.name} style={{ display: "flex", alignItems: "center", gap: 12, padding: "10px 12px", borderRadius: 12, border: "1px solid var(--border-subtle)", background: "#fff", transform: `translateX(${i % 2 ? 14 : 0}px)` }}>
          <FirmLogo dom={p.dom} name={p.name} size={26} />
          <div style={{ flex: 1, minWidth: 0 }}><p className="trunc" style={{ fontSize: 13, fontWeight: 700 }}>{p.name}</p><p className="mono" style={{ fontSize: 11, color: "var(--accent-primary)" }}>{p.value}</p></div>
          <span style={{ fontSize: 11, fontWeight: 700, color: "var(--accent-primary)", padding: "4px 10px", borderRadius: 99, background: "rgba(30,58,138,.08)" }}>Claim</span>
        </div>
      ))}
    </div>
  );
}

function ArtEvent() {
  const sp = [CH.investors[8], CH.investors[9], CH.investors[16]];
  return (
    <div style={{ width: "100%", borderRadius: 16, overflow: "hidden", border: "1px solid rgba(255,255,255,.12)", background: "rgba(255,255,255,.04)" }}>
      <div style={{ position: "relative", height: 110, background: "radial-gradient(70% 90% at 30% 0%,rgba(59,130,246,.6),transparent 70%),linear-gradient(135deg,#13214F,#0F172A)", padding: 14, display: "flex", alignItems: "flex-start", justifyContent: "space-between" }}>
        <span style={{ display: "flex", alignItems: "center", gap: 6, fontSize: 11, fontWeight: 700, color: "#fff", background: "var(--status-live)", padding: "4px 10px", borderRadius: 99 }}><span style={{ width: 6, height: 6, borderRadius: 6, background: "#fff", animation: "ch-live-pulse 1.6s infinite" }}></span>Live Now</span>
        <span className="mono" style={{ fontSize: 11, color: "#B8C1D9" }}>01:24:08</span>
        <p style={{ position: "absolute", left: 14, bottom: 12, fontFamily: "var(--font-display)", fontSize: 20, fontWeight: 800, color: "#fff" }}>Pitch Night #47</p>
      </div>
      <div style={{ padding: 14, display: "flex", flexDirection: "column", gap: 12 }}>
        <div style={{ display: "flex", gap: 8 }}>{sp.map(v => <div key={v.name} style={{ flex: 1, minWidth: 0, display: "flex", alignItems: "center", gap: 6 }}><LogoAvatar dom={v.dom} name={v.firm} size={26} /><span className="trunc" style={{ fontSize: 11.5, color: "#DDE3F3" }}>{v.name.split(" ")[0]}</span></div>)}</div>
        <p style={{ fontSize: 12, color: "#8D97B5" }}><b className="mono" style={{ color: "#fff" }}>247</b> founders · <b className="mono" style={{ color: "#fff" }}>89</b> investors attending</p>
        <Button variant="solid" size="sm" fullWidth style={{ background: "#fff", color: "var(--accent-primary)" }}>Join Now</Button>
      </div>
    </div>
  );
}

function ArtIncubators() {
  return (
    <div style={{ width: "100%", display: "flex", flexDirection: "column", gap: 14 }}>
      <div style={{ display: "grid", gridTemplateColumns: "repeat(4,1fr)", gap: 8 }}>
        {CH.incubators.map((c, i) => <div key={c.name} title={c.name} style={{ aspectRatio: "1", borderRadius: 14, border: "1px solid var(--border-subtle)", background: "#fff", display: "flex", alignItems: "center", justifyContent: "center", boxShadow: "0 4px 14px rgba(15,23,42,.06)", animation: `fl 5s ${i * .5}s ease-in-out infinite` }}><FirmLogo dom={c.dom} name={c.name} size={32} /></div>)}
      </div>
      <div style={{ display: "flex", alignItems: "center", gap: 10, padding: 12, borderRadius: 12, background: "linear-gradient(120deg,rgba(30,58,138,.06),rgba(229,166,0,.06))", border: "1px solid var(--border-subtle)" }}>
        <LogoAvatar dom="ycombinator.com" name="YC" size={36} />
        <div style={{ flex: 1 }}><p style={{ fontSize: 13, fontWeight: 700 }}>Office hours with a YC alum</p><p className="mono" style={{ fontSize: 11, color: "var(--text-muted)" }}>Wed · 16:00 · 12 seats left</p></div>
        <Icon name="Video" size={18} color="var(--accent-primary)" />
      </div>
    </div>
  );
}

function DeckThumb({ d }) {
  return (
    <div style={{ width: 230, flexShrink: 0, borderRadius: 14, overflow: "hidden", border: "1px solid var(--border-subtle)", background: "#fff", boxShadow: "0 8px 24px rgba(15,23,42,.07)" }}>
      <div style={{ height: 120, padding: 14, background: d.bg, color: "#fff", display: "flex", flexDirection: "column", justifyContent: "space-between", position: "relative", overflow: "hidden" }}>
        <span className="mono" style={{ fontSize: 9, letterSpacing: ".14em", opacity: .8 }}>{d.co.toUpperCase()}</span>
        <p style={{ fontFamily: "var(--font-display)", fontSize: 18, fontWeight: 800, lineHeight: 1.1 }}>{d.title}</p>
        <svg viewBox="0 0 100 40" style={{ position: "absolute", right: 10, top: 14, width: 70, opacity: .55 }}><polyline points={d.pts} fill="none" stroke={d.line} strokeWidth="3" strokeLinecap="round" strokeLinejoin="round" /></svg>
      </div>
      <div style={{ padding: "10px 14px", display: "flex", justifyContent: "space-between", alignItems: "center" }}><span style={{ fontSize: 12, fontWeight: 600 }}>{d.round}</span><span className="mono" style={{ fontSize: 11, color: "var(--text-muted)" }}>{d.slides} slides</span></div>
    </div>
  );
}
const DECKS = [
  { co: "Ledgerly", title: "Series A Deck", round: "Raised $6M", slides: 14, bg: "linear-gradient(135deg,#1E3A8A,#3B82F6)", line: "#F2C14E", pts: "0,35 20,28 40,30 60,16 80,12 100,2" },
  { co: "Northwind", title: "Seed Round", round: "Raised $2.1M", slides: 12, bg: "linear-gradient(135deg,#0F172A,#1E3A8A)", line: "#60A5FA", pts: "0,30 25,26 50,20 75,10 100,6" },
  { co: "Aurelia", title: "Growth Deck", round: "Raised $18M", slides: 18, bg: "linear-gradient(135deg,#A16207,#E5A600)", line: "#fff", pts: "0,36 30,30 55,22 80,8 100,4" },
  { co: "Kinetic", title: "Pre-Seed Pitch", round: "Raised $750K", slides: 10, bg: "linear-gradient(135deg,#0F766E,#10B981)", line: "#fff", pts: "0,34 30,30 60,18 100,10" },
  { co: "Helio", title: "Series B Deck", round: "Raised $32M", slides: 22, bg: "linear-gradient(135deg,#6D28D9,#3B82F6)", line: "#F2C14E", pts: "0,32 20,30 50,18 70,14 100,4" },
  { co: "Mosaic", title: "Seed Teardown", round: "Raised $3.4M", slides: 15, bg: "linear-gradient(135deg,#13214F,#2563EB)", line: "#F2C14E", pts: "0,36 40,24 70,16 100,8" }
];
function ArtDecks() {
  return <div style={{ width: "100%" }}><Marquee dur={45}>{DECKS.map(d => <DeckThumb key={d.co} d={d} />)}</Marquee></div>;
}

function ArtSignals() {
  const l = CH.feed.slice(0, 3);
  return (
    <div style={{ width: "100%", display: "flex", flexDirection: "column", gap: 8 }}>
      {l.map((x, i) => (
        <div key={x.label} className="rv" style={{ "--d": i * 120 + "ms", display: "flex", alignItems: "center", gap: 10, padding: 12, borderRadius: 12, background: "#fff", border: "1px solid var(--border-subtle)", boxShadow: i === 0 ? "0 10px 30px rgba(15,23,42,.08)" : "none" }}>
          <FirmLogo dom={x.dom} name={x.label} size={22} />
          <p className="trunc" style={{ flex: 1, fontSize: 13, fontWeight: 600 }}>{x.label}</p>
          <span className="mono" style={{ fontSize: 11, color: i === 0 ? "var(--status-success)" : "var(--text-muted)" }}>{x.time}</span>
        </div>
      ))}
    </div>
  );
}

Object.assign(window, { ArtSignals, ArtInvestorWall, ArtNetwork, ArtPerks, ArtEvent, ArtIncubators, ArtDecks, MiniInv });
