/* ============================================================
   HOME — common SGSITS org page. Introduces the institute and
   its three student engineering teams, then routes into each.
   ============================================================ */

function TeamChoice({ team, onEnter }) {
  const a = team.accent;
  const [hover, setHover] = React.useState(false);
  return (
    <button
      onClick={() => onEnter(team.id)}
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      onFocus={() => setHover(true)}
      onBlur={() => setHover(false)}
      className="team-choice"
      aria-label={"View " + team.name}
      style={{
        position: "relative", overflow: "hidden", textAlign: "left", padding: 0,
        background: "var(--surface)", border: "1px solid " + (hover ? a : "var(--border)"),
        borderTop: "4px solid " + a, minHeight: 440, display: "flex", flexDirection: "column",
        cursor: "pointer", transition: "transform .25s ease, border-color .25s ease, box-shadow .25s ease",
        transform: hover ? "translateY(-6px)" : "none",
        boxShadow: hover ? "0 18px 50px -18px " + a + "aa" : "none",
      }}>
      <div aria-hidden style={{ position: "absolute", inset: 0, zIndex: 0 }}>
        {team.cover ?
          <img src={team.cover} alt="" style={{ width: "100%", height: "100%", objectFit: "cover", opacity: 1, transition: "transform .5s ease", transform: hover ? "scale(1.06)" : "none" }} /> :
          <Ph label="ADD TEAM PHOTO" style={{ position: "absolute", inset: 0 }} />}
        <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(8,8,8,0.32) 0%, rgba(8,8,8,0) 26%, rgba(8,8,8,0) 62%, rgba(8,8,8,0.2) 100%)" }} />
      </div>

      <span aria-hidden className="head" style={{ position: "absolute", right: 16, top: 2, fontSize: 104, lineHeight: 1, color: a, opacity: 0.28, zIndex: 1, pointerEvents: "none", textShadow: "0 2px 24px rgba(0,0,0,0.75)" }}>{team.mono}</span>

      <div style={{
        position: "relative", zIndex: 2, marginTop: "auto", margin: "auto 12px 12px", padding: hover ? "22px 22px" : "16px 22px",
        background: "rgba(12,12,12,0.42)",
        border: "1px solid rgba(255,255,255,0.16)", borderRadius: 12,
        backdropFilter: "blur(10px) saturate(150%)", WebkitBackdropFilter: "blur(10px) saturate(150%)",
        boxShadow: "0 14px 34px -18px rgba(0,0,0,0.65), inset 0 1px 0 rgba(255,255,255,0.12)",
        transition: "padding .3s ease, background .25s ease",
      }}>
        <div className="label" style={{ fontSize: 12, letterSpacing: "0.14em", color: a, marginBottom: 8, textShadow: "0 1px 8px rgba(0,0,0,0.6)" }}>{team.discipline}</div>
        <div className="head" style={{ fontSize: "clamp(28px,2.4vw,40px)", lineHeight: 0.95, color: "var(--text)", textShadow: "0 2px 18px rgba(0,0,0,0.65)" }}>{team.name}</div>
        <div style={{ maxHeight: hover ? 160 : 0, opacity: hover ? 1 : 0, overflow: "hidden", transition: "max-height .3s ease, opacity .25s ease" }}>
          <p className="body muted" style={{ fontSize: 14, lineHeight: 1.6, margin: "12px 0 18px", maxWidth: 360 }}>{team.blurb}</p>
        </div>
        <span className="label" style={{ display: "inline-flex", alignItems: "center", gap: 10, fontSize: 13, letterSpacing: "0.08em", color: hover ? a : "var(--text)", marginTop: 10, transition: "color .2s ease" }}>
          View Team
          <span style={{ display: "grid", transform: hover ? "translateX(4px)" : "none", transition: "transform .2s ease" }}>
            <Icon name="arrow" size={15} color="currentColor" />
          </span>
        </span>
      </div>
    </button>
  );
}

function StatsStrip({ stats, fill, float }) {
  return (
    <section style={{ background: float ? "transparent" : "#111", borderTop: float ? "none" : "1px solid rgba(255,255,255,0.06)", borderBottom: float ? "none" : "1px solid rgba(255,255,255,0.06)", width: "100%", display: fill ? "flex" : undefined, alignItems: fill ? "center" : undefined }}>
      <div className="wrap stats-grid" style={{ display: "grid", gridTemplateColumns: "repeat(3,1fr)", gap: 16, alignItems: "stretch", width: "100%", paddingTop: float ? 0 : "clamp(16px,2vw,26px)", paddingBottom: float ? 0 : "clamp(16px,2vw,26px)" }}>
        {stats.map((s, i) => (
          <StatCell key={i} {...s} />
        ))}
      </div>
    </section>
  );
}

function StatCell({ n, prefix, suffix, label }) {
  const [ref, seen] = useInView(0.4);
  const val = useCountUp(n, seen);
  return (
    <div ref={ref} style={{
      display: "flex", flexDirection: "row", alignItems: "center", gap: "clamp(14px,1.6vw,22px)",
      padding: "clamp(16px,1.8vw,26px) clamp(20px,2.4vw,34px)", position: "relative", overflow: "hidden",
      background: "linear-gradient(140deg, rgba(255,255,255,0.045), rgba(255,255,255,0.012))",
      border: "1px solid rgba(255,255,255,0.10)", borderRadius: 14,
      backdropFilter: "blur(14px)", WebkitBackdropFilter: "blur(14px)",
      boxShadow: "0 24px 50px -20px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,255,255,0.08)",
    }}>
      <span aria-hidden style={{ position: "absolute", inset: 0, background: "radial-gradient(120% 100% at 0% 0%, color-mix(in srgb, var(--orange) 16%, transparent), transparent 55%)", pointerEvents: "none" }} />
      <div style={{ display: "flex", alignItems: "baseline", gap: 6, position: "relative", flexShrink: 0 }}>
        {prefix && <span className="head" style={{ fontSize: "clamp(28px,3.6vw,46px)", color: "var(--orange)", lineHeight: 1 }}>{prefix}</span>}
        {n !== null && <span className="head" style={{ fontSize: "clamp(34px,4.4vw,56px)", color: "var(--orange)", lineHeight: 1 }}>{val}</span>}
        {suffix && <span className="head" style={{ fontSize: "clamp(22px,2.8vw,32px)", color: "var(--orange)", lineHeight: 1 }}>{suffix}</span>}
      </div>
      <span aria-hidden style={{ width: 1, alignSelf: "stretch", background: "rgba(255,255,255,0.12)", position: "relative", flexShrink: 0 }} />
      <span className="label" style={{ fontSize: 16, letterSpacing: "0.13em", color: "rgba(255,255,255,0.6)", lineHeight: 1.5, whiteSpace: "pre-line", position: "relative" }}>{label}</span>
    </div>
  );
}

function OrgStat({ n, prefix, suffix, label, icon, boxed }) {
  const [ref, seen] = useInView(0.5);
  const val = useCountUp(n, seen);
  return (
    <div ref={ref} style={{ display: "flex", alignItems: "center", gap: 18, padding: "clamp(22px,3vw,38px) clamp(18px,3vw,36px)", borderLeft: boxed ? "none" : "1px solid var(--border)", background: boxed ? "var(--surface)" : "transparent" }}>
      <div style={{ display: "flex", flexDirection: "column", gap: 4, minWidth: 0 }}>
        <div style={{ display: "flex", alignItems: "baseline", gap: 4 }}>
          {prefix && <span className="head" style={{ fontSize: "clamp(28px,3.5vw,44px)", color: "var(--accent)", lineHeight: 0.85 }}>{prefix}</span>}
          <span className="head" style={{ fontSize: "clamp(38px,5vw,58px)", color: "var(--accent)", lineHeight: 0.85 }}>{val}</span>
          {suffix && <span className="head" style={{ fontSize: "clamp(22px,3vw,34px)", color: "var(--orange)", lineHeight: 0.85 }}>{suffix}</span>}
        </div>
        <span className="label" style={{ fontSize: 11, letterSpacing: "0.12em", color: "var(--muted)" }}>{label}</span>
      </div>
    </div>
  );
}

/* INNOVATE / COLLABORATE / COMPETE — above-the-fold feature cards */
function OrgFeatureCards({ onInnovate, onCollaborate, onCompete }) {
  const cards = [
    { icon: "bolt",   solid: true,  title: "INNOVATE",    text: "Pushing the boundaries of design and engineering.", on: onInnovate },
    { icon: "people", solid: false, title: "COLLABORATE", text: "United by passion, driven by teamwork.",            on: onCollaborate },
    { icon: "trophy", solid: true,  title: "COMPETE",     text: "From concept to competition, we never stop improving.", on: onCompete },
  ];
  return (
    <div className="wrap feature-cards" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 18 }}>
      {cards.map((c, i) => (
        <button key={i} className="card feature-card" onClick={c.on} style={{
          textAlign: "left", cursor: "pointer", color: "inherit", font: "inherit",
          padding: "clamp(20px,2.2vw,28px)", position: "relative",
          display: "flex", alignItems: "center", gap: 18,
        }}>
          <span aria-hidden className="feature-ico" style={{
            flex: "0 0 auto", width: 60, height: 60, borderRadius: "50%",
            display: "grid", placeItems: "center",
            background: c.solid ? "var(--orange)" : "var(--surface-2)",
            border: c.solid ? "none" : "1px solid var(--border-2)",
          }}>
            <Icon name={c.icon} size={26} color={c.solid ? "#0A0A0A" : "var(--text)"} strokeWidth={1.8} />
          </span>
          <span style={{ display: "flex", flexDirection: "column", gap: 6, minWidth: 0 }}>
            <span className="head" style={{ fontSize: "clamp(18px,1.5vw,22px)", color: "var(--text)", lineHeight: 1 }}>{c.title}</span>
            <span className="body muted" style={{ fontSize: 14, lineHeight: 1.5 }}>{c.text}</span>
          </span>
          <span className="feature-arrow" style={{ position: "absolute", right: 18, bottom: 16, color: "var(--orange)" }}>
            <Icon name="arrow" size={16} color="var(--orange)" />
          </span>
        </button>
      ))}
    </div>
  );
}

/* ── Hero ── shared assets + copy, then selectable layouts ── */
const HERO_PANELS = [
  { src: "uploads/teams/gs-motorsports/car/FS_Track_Cornering.jpg", pos: "center 40%", label: "Formula Student" },
  { src: "uploads/teams/gs-racers-baja/Baja_RainSplash.jpg",  pos: "center 45%", label: "GS Racers · Baja SAE" },
  { src: "uploads/teams/yaan/Yan_Flight.jpeg",                pos: "center 35%", label: "Aero Segment" },
];
const HERO_H = "100%";

function HeroCopy({ onExplore, onSponsors }) {
  return (
    <React.Fragment>
      <h1 className="head hero-title" style={{ margin: 0, lineHeight: 0.91, fontSize: "clamp(26px,3.4vw,46px)", letterSpacing: "-0.01em" }}>
        <span className="hero-line"><span style={{ display: "block", color: "var(--text)" }}>TEAM <span id="hero-g-mark">GS</span></span></span>
        <span className="hero-line"><span style={{ display: "block", color: "var(--orange)" }}>RACERS</span></span>
      </h1>
      <p className="body hero-el hero-sub" style={{ "--hi": 1, margin: "12px 0 0", fontSize: "clamp(12px,1.2vw,14px)", color: "rgba(255,255,255,0.62)", lineHeight: 1.6, maxWidth: 380 }}>
        A passion for innovation.<br />A drive for excellence.<br />One team, limitless possibilities.
      </p>
      <div className="hero-el hero-cta-row" style={{ "--hi": 2, display: "flex", gap: 10, marginTop: 18, flexWrap: "wrap" }}>
        <button className="btn btn-primary" onClick={onExplore} style={{ fontSize: 12, padding: "10px 18px" }}>
          Explore Teams <span className="arrow"><Icon name="arrow" size={13} color="#0A0A0A" /></span>
        </button>
        <button className="btn btn-ghost" onClick={onSponsors} style={{ fontSize: 12, padding: "10px 18px" }}>Our Sponsors</button>
      </div>
    </React.Fragment>
  );
}

/* Shared left scrim — solid black from the left edge up to the G of "TEAM GS",
   then a long smooth fade into the photo. Measures the real G position so it
   tracks font loading, resize and responsive type sizes. */
function CopyScrim() {
  const ref = React.useRef(null);
  const [stops, setStops] = React.useState(null); // { solid, fade } in px
  React.useEffect(() => {
    const measure = () => {
      const el = ref.current;
      const g = document.getElementById("hero-g-mark");
      if (!el || !g) return;
      const s = el.getBoundingClientRect();
      const r = g.getBoundingClientRect();
      if (s.width === 0) return;
      const solid = Math.max(0, r.left - s.left);        // black is solid up to the G
      const fade = Math.min(s.width, solid + s.width * 0.34); // then fades out
      setStops({ solid, fade });
    };
    measure();
    const t = setTimeout(measure, 350);
    window.addEventListener("resize", measure);
    if (document.fonts && document.fonts.ready) document.fonts.ready.then(measure).catch(() => {});
    return () => { clearTimeout(t); window.removeEventListener("resize", measure); };
  }, []);
  const bg = stops
    ? "linear-gradient(90deg, rgba(5,5,5,1) 0%, rgba(5,5,5,1) " + stops.solid + "px, rgba(5,5,5,0.55) " + ((stops.solid + stops.fade) / 2) + "px, rgba(5,5,5,0) " + stops.fade + "px)"
    : "linear-gradient(90deg, rgba(5,5,5,1) 0%, rgba(5,5,5,1) 22%, rgba(5,5,5,0.55) 33%, rgba(5,5,5,0) 46%)";
  return (
    <div ref={ref} aria-hidden className="copy-scrim" style={{ position: "absolute", inset: 0, zIndex: 3, pointerEvents: "none", background: bg }} />
  );
}

/* 0 — BANNER: single pre-composed triptych, full-bleed */
const HERO_BANNER = { src: "uploads/hero/teams-triptych.jpg", pos: "center center" };
function HeroBanner({ copy }) {
  return (
    <section style={{ position: "relative", height: HERO_H, minHeight: 0, overflow: "hidden", background: "#0a0a0a" }}>
      <img src={HERO_BANNER.src} alt="SGSITS engineering teams — Aero Segment drone, GS Racers Baja ATV and Formula Student formula car"
        style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: HERO_BANNER.pos }} />
      <div aria-hidden style={{ position: "absolute", inset: 0, background: "linear-gradient(100deg, rgba(5,5,5,0.94) 0%, rgba(5,5,5,0.72) 32%, rgba(5,5,5,0.28) 58%, rgba(5,5,5,0.12) 100%)" }} />
      <CopyScrim />
      <div className="hero-copy-slot" style={{ position: "absolute", inset: 0, zIndex: 4, display: "flex", alignItems: "center", padding: "0 clamp(24px,5vw,80px)", pointerEvents: "none" }}>
        <div style={{ maxWidth: 560, pointerEvents: "auto" }}>{copy}</div>
      </div>
    </section>
  );
}

/* 1 — SPLIT: three skewed diagonal panels */
function HeroSplit({ copy }) {
  const p = HERO_PANELS;
  const clips = [
    "polygon(0% 0%, 58% 0%, 52% 100%, 0% 100%)",
    "polygon(54% 0%, 80% 0%, 74% 100%, 48% 100%)",
    "polygon(76% 0%, 100% 0%, 100% 100%, 70% 100%)",
  ];
  const dividers = [{ left: "52%" }, { left: "73.5%" }];
  return (
    <section style={{ position: "relative", height: HERO_H, minHeight: 0, overflow: "hidden", background: "#0a0a0a" }}>
      {p.map((x, i) => (
        <div key={i} style={{ position: "absolute", inset: 0, clipPath: clips[i], zIndex: 1 }}>
          <img src={x.src} alt={i === 0 ? "SGSITS teams" : ""} aria-hidden={i > 0 ? "true" : undefined}
            style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: x.pos }} />
          <div style={{ position: "absolute", inset: 0, background: i === 0
            ? "linear-gradient(105deg, rgba(5,5,5,0.92) 0%, rgba(5,5,5,0.6) 52%, rgba(5,5,5,0.15) 100%)"
            : "linear-gradient(105deg, rgba(5,5,5,0.5) 0%, rgba(5,5,5,0.15) 100%)" }} />
        </div>
      ))}
      {dividers.map((d, i) => (
        <div key={i} aria-hidden="true" style={{
          position: "absolute", top: 0, bottom: 0, left: d.left, width: 3,
          background: "var(--orange)", transform: "skewX(-6deg)", zIndex: 3,
          boxShadow: "0 0 18px 3px rgba(255,107,0,0.4)"
        }} />
      ))}
      <CopyScrim />
      <div className="hero-copy-slot" style={{ position: "absolute", inset: 0, zIndex: 4, display: "flex", alignItems: "center", padding: "0 clamp(24px,5vw,80px)", pointerEvents: "none" }}>
        <div style={{ maxWidth: 580, pointerEvents: "auto" }}>{copy}</div>
      </div>
      <div style={{ position: "absolute", bottom: 0, left: 0, right: 0, zIndex: 5, display: "flex", borderTop: "1px solid rgba(255,255,255,0.07)", pointerEvents: "none" }}>
        {p.map((x, i) => (
          <div key={i} className="label" style={{
            flex: i === 0 ? "0 0 52%" : i === 1 ? "0 0 22%" : "1",
            padding: "10px clamp(16px,3vw,40px)", fontSize: 11,
            color: "rgba(255,255,255,0.30)", letterSpacing: "0.1em",
            borderRight: i < 2 ? "1px solid rgba(255,255,255,0.07)" : "none",
            background: "rgba(5,5,5,0.5)",
          }}>{x.label}</div>
        ))}
      </div>
    </section>
  );
}

/* 2 — MOSAIC: editorial split — solid text panel + 3-image collage */
function HeroMosaic({ copy }) {
  const p = HERO_PANELS;
  return (
    <section className="hero-mosaic" style={{ position: "relative", height: HERO_H, minHeight: 0, overflow: "hidden", background: "#0a0a0a", display: "grid", gridTemplateColumns: "minmax(0,0.92fr) 1.08fr" }}>
      <div className="hero-mosaic-copy" style={{ display: "flex", alignItems: "center", padding: "0 clamp(24px,4vw,64px)", background: "linear-gradient(180deg,#0d0d0d,#070707)", borderRight: "1px solid rgba(255,255,255,0.06)", position: "relative", zIndex: 2 }}>
        <div aria-hidden style={{ position: "absolute", left: -8, bottom: 12, fontFamily: "var(--f-head)", fontSize: "clamp(120px,18vw,260px)", lineHeight: 1, color: "rgba(255,107,0,0.05)", pointerEvents: "none", userSelect: "none" }}>SGS</div>
        <div style={{ maxWidth: 520, position: "relative" }}>{copy}</div>
      </div>
      <div className="hero-mosaic-grid" style={{ display: "grid", gridTemplateColumns: "1.3fr 1fr", gridTemplateRows: "1fr 1fr", gap: 4, padding: 4 }}>
        {[0, 1, 2].map((i) => (
          <div key={i} style={{ position: "relative", overflow: "hidden", gridRow: i === 0 ? "1 / span 2" : "auto" }}>
            <img src={p[i].src} alt={p[i].label} style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: p[i].pos, display: "block" }} />
            <div style={{ position: "absolute", inset: 0, background: "linear-gradient(180deg, rgba(5,5,5,0) 55%, rgba(5,5,5,0.85) 100%)" }} />
            <div className="label" style={{ position: "absolute", left: 14, bottom: 12, fontSize: 10, letterSpacing: "0.1em", color: "rgba(255,255,255,0.85)" }}>
              <span style={{ color: "var(--orange)" }}>/ </span>{p[i].label}
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

/* 3B — DUO: single pre-composed two-shot photo (Baja splash test + track pass), full-bleed */
const HERO_DUO = { src: "uploads/hero/baja-duo-composite.jpg", pos: "center center", label: "GS Racers · Baja SAE" };
function HeroDuo({ copy }) {
  const p = HERO_DUO;
  return (
    <section style={{ position: "relative", height: HERO_H, minHeight: 0, overflow: "hidden", background: "#0a0a0a" }}>
      <img src={p.src} alt="GS Racers Baja buggy — splash test and track pass"
        style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: p.pos }} />
      <div aria-hidden style={{ position: "absolute", inset: 0, background: "linear-gradient(100deg, rgba(5,5,5,1) 0%, rgba(5,5,5,1) 26%, rgba(5,5,5,0.3) 36%, rgba(5,5,5,0) 48%)" }} />
      <CopyScrim />
      {/* accent line marking the photo's own seam */}
      <div aria-hidden="true" style={{
        position: "absolute", top: 0, bottom: 0, left: "calc(68% - 1.5px)", width: 3,
        background: "var(--orange)", zIndex: 3,
        boxShadow: "0 0 18px 3px rgba(255,107,0,0.4)"
      }} />
      <div className="hero-copy-slot" style={{ position: "absolute", inset: 0, zIndex: 4, display: "flex", alignItems: "center", padding: "0 clamp(24px,5vw,80px)", pointerEvents: "none" }}>
        <div style={{ maxWidth: 420, pointerEvents: "auto" }}>{copy}</div>
      </div>
      <div className="label" style={{ position: "absolute", bottom: 0, left: 0, right: 0, zIndex: 5, padding: "10px clamp(16px,3vw,40px)", fontSize: 11, color: "rgba(255,255,255,0.55)", letterSpacing: "0.1em", background: "rgba(5,5,5,0.35)", pointerEvents: "none" }}>{p.label}</div>
    </section>
  );
}

/* 3 — FILMSTRIP: full-bleed lead image + vertical perforated film strip (click a frame to swap the lead) */
function HeroFilmstrip({ copy }) {
  const p = HERO_PANELS;
  const [active, setActive] = React.useState(0);
  return (
    <section style={{ position: "relative", height: HERO_H, minHeight: 0, overflow: "hidden", background: "#0a0a0a" }}>
      {p.map((x, i) => (
        <React.Fragment key={i}>
          {/* blurred fill so there are no empty bars around the fully-shown photo */}
          <img aria-hidden="true" src={x.src} alt=""
            style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: "center",
              filter: "blur(34px) brightness(0.42)", transform: "scale(1.14)",
              opacity: i === active ? 1 : 0, transition: "opacity .5s ease" }} />
          {/* the full, uncropped photo */}
          <img src={x.src} alt={i === active ? x.label : ""} aria-hidden={i === active ? undefined : "true"}
            style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "contain", objectPosition: "center",
              opacity: i === active ? 1 : 0, transition: "opacity .5s ease" }} />
        </React.Fragment>
      ))}
      <CopyScrim />
      <div className="hero-copy-slot" style={{ position: "absolute", inset: 0, zIndex: 4, display: "flex", alignItems: "center", padding: "0 clamp(24px,5vw,80px)", pointerEvents: "none" }}>
        <div style={{ maxWidth: 560, pointerEvents: "auto" }}>{copy}</div>
      </div>
      {/* vertical film strip, center-anchored on the right so it clears the overlapping feature cards */}
      <div className="hero-filmstrip" style={{ position: "absolute", right: "clamp(20px,4vw,56px)", top: "50%", transform: "translateY(calc(-50% - 26px))", zIndex: 5, background: "#050505", padding: "12px 8px", border: "1px solid rgba(255,255,255,0.10)", boxShadow: "0 18px 50px rgba(0,0,0,0.55)", display: "flex", flexDirection: "column", gap: 8 }}>
        <span aria-hidden="true" className="hero-filmstrip-perf" style={{ marginBottom: 2 }} />
        {p.map((x, i) => {
          const on = i === active;
          return (
            <figure key={i} style={{ margin: 0, width: "clamp(100px,11vw,132px)", display: "flex", flexDirection: "column", gap: 4 }}>
              <button type="button" aria-label={"Show " + x.label} aria-pressed={on} onClick={() => setActive(i)}
                onMouseEnter={() => setActive(i)}
                style={{ position: "relative", aspectRatio: "16 / 9", overflow: "hidden", padding: 0, cursor: "pointer", display: "block",
                  border: on ? "2px solid var(--orange)" : "1px solid rgba(255,255,255,0.16)",
                  boxShadow: on ? "0 0 16px rgba(255,107,0,0.35)" : "none", background: "none", transition: "border-color .2s ease, box-shadow .2s ease" }}>
                <img src={x.src} alt="" style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: x.pos, display: "block", opacity: on ? 1 : 0.7, transition: "opacity .2s ease" }} />
              </button>
              <figcaption className="label" style={{ fontSize: 9, color: on ? "rgba(255,255,255,0.75)" : "rgba(255,255,255,0.42)", letterSpacing: "0.07em", lineHeight: 1.3, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", transition: "color .2s ease" }}>{x.label}</figcaption>
            </figure>
          );
        })}
        <span aria-hidden="true" className="hero-filmstrip-perf" style={{ marginTop: 2 }} />
      </div>
    </section>
  );
}

/* 4 — SLIDESHOW: crossfading lead image with Ken-Burns drift */
function HeroSlideshow({ copy }) {
  const p = HERO_PANELS;
  const [idx, setIdx] = React.useState(0);
  React.useEffect(() => {
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
    const tick = () => setInterval(() => setIdx((i) => (i + 1) % p.length), 4200);
    let id = tick();
    const onVis = () => {
      clearInterval(id);
      if (!document.hidden) id = tick();
    };
    document.addEventListener("visibilitychange", onVis);
    return () => { clearInterval(id); document.removeEventListener("visibilitychange", onVis); };
  }, []);
  return (
    <section style={{ position: "relative", height: HERO_H, minHeight: 0, overflow: "hidden", background: "#0a0a0a" }}>
      {p.map((x, i) => (
        <img key={i} decoding="async" src={x.src} alt={i === 0 ? "SGSITS teams" : ""} aria-hidden={i > 0 ? "true" : undefined}
          className={i === 1 ? "hero-slide-rainsplash" : undefined}
          style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", objectPosition: x.pos,
            opacity: i === idx ? 1 : 0, transform: i === idx ? "scale(1.07)" : "scale(1)",
            transition: "opacity 1.2s ease, transform 5.4s ease" }} />
      ))}
      <div style={{ position: "absolute", inset: 0, background: "linear-gradient(100deg, rgba(5,5,5,0.9) 0%, rgba(5,5,5,0.55) 50%, rgba(5,5,5,0.2) 100%)" }} />
      <CopyScrim />
      <div className="hero-copy-slot" style={{ position: "absolute", inset: 0, zIndex: 4, display: "flex", alignItems: "center", padding: "0 clamp(24px,5vw,80px)", pointerEvents: "none" }}>
        <div style={{ maxWidth: 560, pointerEvents: "auto" }}>{copy}</div>
      </div>
      <div className="hero-dots" style={{ position: "absolute", bottom: 22, left: "clamp(24px,5vw,80px)", zIndex: 5, display: "flex", gap: 6, alignItems: "center" }}>
        {p.map((x, i) => (
          <button key={i} aria-label={x.label} aria-current={i === idx ? "true" : undefined} onClick={() => setIdx(i)}
            style={{ width: i === idx ? 36 : 18, height: 20, padding: "8px 3px", border: "none", background: "none", cursor: "pointer", display: "grid", transition: "width .35s ease" }}>
            <span style={{ width: "100%", height: 4, background: i === idx ? "var(--orange)" : "rgba(255,255,255,0.35)", transition: "background .35s ease" }}></span>
          </button>
        ))}
      </div>
    </section>
  );
}

function SponsorStrip() {
  const TITLE = { name: "Hindustan Equipments", src: "uploads/sponsor/hindustan-equipments.png" };
  const partners = [
  { name: "PATH", src: "uploads/sponsor/gold/path.png" },
  { name: "Virtuoso CNC Arts", src: "uploads/sponsor/gold/virtuoso-cnc-arts.png" },
  { name: "Bhagirath Brothers", src: "uploads/sponsor/gold/bhagirath-brothers.png" },
  { name: "Fluidomat", src: "uploads/sponsor/gold/fluidomat.png" },
  { name: "Tirupati Industries", src: "uploads/sponsor/silver/tirupati-industries.png" },
  { name: "Bajrang", src: "uploads/sponsor/silver/bajrang.png" },
  { name: "TPL", src: "uploads/sponsor/silver/tpl.png" },
  { name: "Neo Hydraulics", src: "uploads/sponsor/silver/neo-hydraulics.png" },
  { name: "Techforce Composites", src: "uploads/sponsor/silver/techforce-composites.jpg" },
  { name: "Mantra Composites", src: "uploads/sponsor/silver/mantra-composites.png" },
  { name: "Magpie", src: "uploads/sponsor/bronze/magpie.png" },
  { name: "Prashanti", src: "uploads/sponsor/bronze/prashanti.png" },
  { name: "SGSITS Alumni Assoc.", src: "uploads/sponsor/gold/sgsits-alumni-assoc.png" },
  { name: "SKF", src: "uploads/sponsor/bronze/skf.png" },
  { name: "IPG", src: "uploads/sponsor/bronze/ipg.png" },
  { name: "Ansys", src: "uploads/sponsor/bronze/ansys.png" },
  { name: "SolidWorks", src: "uploads/sponsor/bronze/solidworks.png" },
  { name: "Abhikalp", src: "uploads/sponsor/bronze/abhikalp.png" },
  { name: "Wings", src: "uploads/sponsor/gold/wings.jpg" },
  { name: "Ascentt", src: "uploads/sponsor/gold/ascentt.jpg" },
  { name: "Vishalfab", src: "uploads/sponsor/gold/vishalfab.jpg" },
  { name: "JSW Sarbloh Motors", src: "uploads/sponsor/gold/jsw-sarbloh-motors.jpg" },
  { name: "Batch 1998", src: "uploads/sponsor/silver/batch-1998.jpg" },
  { name: "Scientific", src: "uploads/sponsor/silver/scientific.jpg" },
  { name: "Robosol", src: "uploads/sponsor/silver/robosol.jpg" },
  { name: "Batch 1975", src: "uploads/sponsor/silver/batch-1975.jpg" },
  { name: "Khanwalkar Industries", src: "uploads/sponsor/silver/khanwalkar-industries.jpg" },
  { name: "Si Mangla", src: "uploads/sponsor/silver/si-mangla.jpg" },
  { name: "AICTE IDEA Lab", src: "uploads/sponsor/bronze/aicte-idea-lab.png" },
  { name: "Monica Opto Hub", src: "uploads/sponsor/bronze/monica-opto-hub.png" },
  { name: "MPFC", src: "uploads/sponsor/bronze/mpfc.png" },
  { name: "Shubh Traders", src: "uploads/sponsor/bronze/shubh-traders.png" },
  { name: "T-Motor", src: "uploads/sponsor/bronze/t-motor.png" }];

  const row = [TITLE, ...partners, TITLE, ...partners];
  // pause the marquee while it's out of view — it otherwise animates on every frame
  const mqRef = React.useRef(null);
  React.useEffect(() => {
    const el = mqRef.current;
    if (!el || !("IntersectionObserver" in window)) return;
    const io = new IntersectionObserver(([e]) => el.classList.toggle("offscreen", !e.isIntersecting));
    io.observe(el);
    return () => io.disconnect();
  }, []);
  return (
    <React.Fragment>
      {/* Supporting partners marquee — title sponsor included */}
      <section style={{ borderTop: "1px solid var(--border)", borderBottom: "1px solid var(--border)", background: "var(--surface)", padding: "36px 0", overflow: "hidden" }}>
        <div className="wrap" style={{ marginBottom: 18, display: "flex", justifyContent: "space-between", alignItems: "baseline", gap: 16, flexWrap: "wrap" }}>
          <span className="eyebrow">Supporting partners</span>
          <span className="label" style={{ fontSize: 11, color: "var(--muted-2)", letterSpacing: "0.16em" }}>{partners.length + 1} PARTNERS · SEASON 2026</span>
        </div>
        <div className="marquee" ref={mqRef}>
          <div className="marquee-track">
            {row.map((s, i) =>
            <div key={i} className="sponsor-logo" title={s.name}>
                <div className="logo-tile">
                  <img src={s.src} alt={s.name} loading="lazy" />
                </div>
              </div>
            )}
          </div>
        </div>
      </section>
    </React.Fragment>);

}

/* ── NEWSROOM ── upcoming events + special moments + future prospects ── */
const NEWS_IG = (window.ORG && window.ORG.socials && window.ORG.socials[0] && window.ORG.socials[0].href) || "#";

/* sub-section heading used by all three newsroom rows */
function NewsroomRowHead({ eyebrow, title }) {
  return (
    <div style={{ display: "flex", alignItems: "baseline", gap: 14, marginBottom: 22 }}>
      <div className="label" style={{ fontSize: 11, color: "var(--orange)", letterSpacing: "0.14em", flexShrink: 0 }}>{eyebrow}</div>
      <span aria-hidden style={{ height: 1, flex: 1, background: "var(--border)" }} />
      <h3 className="head" style={{ margin: 0, fontSize: "clamp(18px,1.6vw,22px)", color: "var(--text)" }}>{title}</h3>
    </div>
  );
}

/* upcoming events — dated cards; accent color-codes the card to the team it concerns (defaults to home orange = Formula Student) */
function EventCard({ tag, date, title, blurb, accent }) {
  const c = accent || "var(--orange)";
  return (
    <a href={NEWS_IG} target="_blank" rel="noopener" className="card event-card" style={{ display: "flex", flexDirection: "column", gap: 14, padding: "24px 24px 22px", textDecoration: "none", ...(accent ? { "--pcard-accent": accent } : {}) }}>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
        <span aria-hidden style={{ width: 44, height: 44, borderRadius: "50%", display: "grid", placeItems: "center", background: "var(--surface-2)", border: "1px solid var(--border-2)", flexShrink: 0 }}>
          <Icon name="calendar" size={20} color={c} strokeWidth={1.7} />
        </span>
        <span className="label" style={{ fontSize: 11, color: c, letterSpacing: "0.12em", padding: "5px 10px", border: "1px solid var(--border-2)" }}>{date}</span>
      </div>
      <div>
        <div className="label" style={{ fontSize: 10, color: c, letterSpacing: "0.14em", marginBottom: 8 }}>{tag}</div>
        <div className="head" style={{ fontSize: "clamp(18px,1.5vw,22px)", lineHeight: 1.1, color: "var(--text)" }}>{title}</div>
        <p className="body muted" style={{ fontSize: 14, lineHeight: 1.6, margin: "10px 0 0" }}>{blurb}</p>
      </div>
      <span className="label news-cta" style={{ display: "inline-flex", alignItems: "center", gap: 8, fontSize: 12, letterSpacing: "0.08em", color: c, marginTop: "auto" }}>
        See on Instagram <Icon name="arrow" size={14} color={c} />
      </span>
    </a>
  );
}

/* special moments — a photo + short caption; drop a real photo into the Ph's `img` prop */
function MomentCard({ img, href, label, title, blurb }) {
  const photo = <Ph img={img} label={label} style={{ height: 220 }} />;
  return (
    <div className="card moment-card" style={{ overflow: "hidden" }}>
      {href ?
      <a href={href} target="_blank" rel="noopener" aria-label={title} style={{ display: "block" }}>{photo}</a> :
      photo}
      <div style={{ padding: "18px 20px 22px" }}>
        <div className="head" style={{ fontSize: "clamp(17px,1.4vw,20px)", lineHeight: 1.15, color: "var(--text)" }}>{title}</div>
        <p className="body muted" style={{ fontSize: 14, lineHeight: 1.6, margin: "8px 0 0" }}>{blurb}</p>
      </div>
    </div>
  );
}

/* future prospects — season goals per team */
function ProspectCard({ tag, title, blurb, tagColor, accent }) {
  return (
    <div className="card prospect-card" style={{ display: "flex", flexDirection: "column", gap: 12, padding: "24px 24px 26px", ...(accent ? { "--pcard-accent": accent } : {}) }}>
      <span aria-hidden className="pcard-icon" style={{ width: 44, height: 44, borderRadius: "50%", display: "grid", placeItems: "center", background: "var(--surface-2)", border: "1px solid var(--border-2)" }}>
        <Icon name="bolt" size={20} color="var(--muted-2)" strokeWidth={1.7} />
      </span>
      <div>
        <div className="label" style={{ fontSize: 10, color: tagColor || "var(--muted-2)", letterSpacing: "0.14em", marginBottom: 8 }}>{tag}</div>
        <div className="head" style={{ fontSize: "clamp(18px,1.5vw,22px)", lineHeight: 1.1, color: "var(--text)" }}>{title}</div>
        <p className="body muted" style={{ fontSize: 14, lineHeight: 1.6, margin: "10px 0 0" }}>{blurb}</p>
      </div>
    </div>
  );
}

function NewsroomSection() {
  return (
    <section style={{ borderTop: "1px solid var(--border)", background: "var(--bg)" }}>
      <div className="wrap" style={{ paddingTop: 86, paddingBottom: 86 }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", gap: 20, flexWrap: "wrap", marginBottom: 48 }}>
          <div className="sec-title">
            <span className="bar" />
            <h2>Newsroom</h2>
          </div>
          <span className="eyebrow" style={{ paddingBottom: 6 }}>Events, moments &amp; what&rsquo;s next</span>
        </div>

        <div style={{ marginBottom: 56 }}>
          <NewsroomRowHead eyebrow="UPCOMING EVENTS" title="What&rsquo;s on the calendar" />
          <div className="newsroom-grid-3" style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))", gap: 18 }}>
            <EventCard accent="#FF6B00" tag="FORMULA STUDENT" date="2027 SEASON" title="Formula Bharat &amp; Supra SAE India 2027" blurb="Our formula car returns to both national circuits — Formula Bharat and Supra SAE India — for the 2027 season campaign." />
            <EventCard accent="#1E90D8" tag="GS RACERS · BAJA" date="2027 SEASON" title="e-Baja 2027" blurb="Fielding our first all-electric ATV entry at e-Baja 2027, as the team builds toward a full electric powertrain." />
            <EventCard accent="#3D7AB5" tag="AERO SEGMENT" date="NOV 2026 – MAR 2027" title="Aerothon &amp; ADDC" blurb="Aerothon in November 2026, followed by the Autonomous Drone Development Challenge in March 2027 — back-to-back flight campaigns." />
          </div>
        </div>

        <div style={{ marginBottom: 56 }}>
          <NewsroomRowHead eyebrow="SPECIAL MOMENTS" title="Milestones worth remembering" />
          <div className="newsroom-grid-3" style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(260px, 380px))", gap: 18 }}>
            <MomentCard img="uploads/moments/working-shed-inauguration.jpeg" href="https://www.instagram.com/p/C1hTJs_JbnY/" label="WORKING SHED — INAUGURATION" title="Inauguration of Our Workshop by Batch 1998" blurb="Batch 1998 formally inaugurated the GS Racers workshop and dedicated it to their beloved friend Sumit." />
          </div>
        </div>

        <div>
          <NewsroomRowHead eyebrow="FUTURE PROSPECTS" title="Where we&rsquo;re headed" />
          <div className="newsroom-grid-3" style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(260px, 1fr))", gap: 18 }}>
            <ProspectCard tag="FORMULA STUDENT" tagColor="#FF6B00" accent="#FF6B00" title="Moving to an EV Powertrain" blurb="Planning our shift from combustion to an electric powertrain for the Formula car in an upcoming season." />
            <ProspectCard tag="BAJA" tagColor="#1E90D8" accent="#1E90D8" title="Eyeing Autonomous Baja" blurb="Building toward fielding an entry in the Autonomous Baja category, adding self-driving capability to our ATV platform." />
          </div>
        </div>
      </div>
    </section>
  );
}

function OrgHomePage({ go, enterTeam, t = {} }) {
  const scrollToTeams = () => {
    const el = document.getElementById("org-teams");
    if (el) window.scrollTo({ top: el.offsetTop - 70, behavior: "smooth" });
  };
  const stats = [
    { n: 19, label: "SEASONS SINCE 2007" },
    { n: 3, label: "PLATFORMS · BAJA /\nFORMULA / AERO" },
    { n: null, prefix: "AIR 1", label: "MULTIPLE ALL-INDIA RANKS" },
  ];
  const showExtras = t.homeExtras !== false;

  return (
    <main>
      {/* ── above-the-fold: hero + feature cards + stats, all visible on load ── */}
      <div className="home-fold" style={!showExtras ? { display: "flex", flexDirection: "column", height: "calc(100vh - var(--nav-h) + 100px)" } : undefined}>
        <div className="home-hero-wrap" style={showExtras ? { position: "relative", height: "calc(100vh - var(--nav-h))" } : { position: "relative", flex: "1 1 auto", minHeight: 0 }}>
          {(() => {
            const copy = <HeroCopy onExplore={scrollToTeams} onSponsors={() => { go("crowdfunding"); window.scrollTo({ top: 0 }); }} />;
            const layout = t.heroLayout || "banner";
            if (layout === "split")     return <HeroSplit copy={copy} />;
            if (layout === "mosaic")    return <HeroMosaic copy={copy} />;
            if (layout === "duo")       return <HeroDuo copy={copy} />;
            if (layout === "filmstrip") return <HeroFilmstrip copy={copy} />;
            if (layout === "slideshow") return <HeroSlideshow copy={copy} />;
            return <HeroBanner copy={copy} />;
          })()}
        </div>

        {/* stats strip — floats over the bottom of the hero */}
        <div className="stats-float" style={!showExtras ? { flex: "1 1 auto", display: "flex", paddingBottom: 20 } : { position: "relative", zIndex: 3, marginTop: "clamp(-170px,-13vw,-124px)", paddingBottom: 20 }}><StatsStrip stats={stats} fill={!showExtras} float={showExtras} /></div>
      </div>

      {/* ── who we are (org) ── */}
      <section style={{ borderTop: "1px solid var(--border)", background: "var(--surface)" }}>
        <div className="wrap" style={{ paddingTop: 86, paddingBottom: 86 }}>
          <div className="about-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 56, alignItems: "center" }}>
            <div>
              <div className="sec-title" style={{ marginBottom: 26 }}>
                <span className="bar" />
                <h2>Built Here.<br />Raced Everywhere.</h2>
              </div>
              <p className="body" style={{ fontSize: 17, lineHeight: 1.7, color: "var(--text)", margin: "0 0 16px" }}>
                Three student-run teams. One campus. Every machine — formula car, Baja ATV, unmanned aircraft — is designed, fabricated, and campaigned by SGSITS students with no professional engineers on the build.
              </p>
              <p className="body muted" style={{ fontSize: 16, lineHeight: 1.7, margin: "0 0 28px" }}>
                We learn by doing — and we prove it at national and international competitions every season.
              </p>
              <button className="btn btn-ghost" onClick={() => { go("about"); window.scrollTo({ top: 0 }); }}>
                Read Our Story <span className="arrow"><Icon name="arrow" size={16} /></span>
              </button>
            </div>
            <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gridTemplateRows: "auto auto", gap: 14 }}>
              <Ph label="FORMULA CAR" img="uploads/teams/gs-motorsports/car/FB2025_Left.jpeg" imgPos="center 55%" style={{ height: 200, gridColumn: "1 / 2" }} />
              <Ph label="BAJA ATV" img="uploads/teams/gs-racers-baja/Baja_Track.jpg" imgPos="center 55%" style={{ height: 200, gridColumn: "2 / 3", marginTop: 36 }} />
              <Ph label="DRONE / UAV" img="uploads/teams/yaan/Yan_Flight.jpeg" imgPos="center 40%" style={{ height: 160, gridColumn: "1 / 3" }} />
            </div>
          </div>
        </div>
      </section>

      {/* ── our teams ── */}
      <section id="org-teams" style={{ borderTop: "1px solid var(--border)", background: "var(--bg)" }}>
        <div className="wrap" style={{ paddingTop: 86, paddingBottom: 86 }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", gap: 20, flexWrap: "wrap", marginBottom: 40 }}>
            <div className="sec-title">
              <span className="bar" />
              <h2>Our Teams</h2>
            </div>
            <span className="eyebrow" style={{ paddingBottom: 6 }}>Three disciplines &middot; one garage</span>
          </div>
          <div className="landing-grid" style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 18 }}>
            {TEAM_ORDER.map((id) => <TeamChoice key={id} team={TEAMS[id]} onEnter={enterTeam} />)}
          </div>
        </div>
      </section>

      <NewsroomSection />

      <SponsorStrip />
    </main>
  );
}

Object.assign(window, { OrgHomePage, OrgFeatureCards, TeamChoice, HeroCopy, HeroBanner, HeroSplit, HeroMosaic, HeroDuo, HeroFilmstrip, HeroSlideshow, NewsroomSection, EventCard, MomentCard, ProspectCard });
