// Variant A — "Site". Full-width horizontal personal-site layout:
// header row (avatar + name pill + role) top-left, bio left / tags right
// as floating animated pills, booking pills in same style, dark circle
// company bubbles row at the bottom.

const { useState: useStateA, useMemo: useMemoA, useEffect: useEffectA } = React;

// Tracks whether we're on a narrow (mobile) viewport so the layout can stack.
function useIsMobile(bp = 760) {
  const [m, setM] = useStateA(typeof window !== "undefined" ? window.innerWidth <= bp : false);
  useEffectA(() => {
    const on = () => setM(window.innerWidth <= bp);
    on();
    window.addEventListener("resize", on);
    return () => window.removeEventListener("resize", on);
  }, [bp]);
  return m;
}

function LandingClassic({ theme, page }) {
  const P = window.PERSON;
  // Page config controls the booking section: which topics, which calendar,
  // and whether booking shows at all. Falls back to the CEO page.
  const PAGE = page || window.PAGE || {
    showBooking: true,
    heading: "Book a session with me:",
    calendar: P.bookingBase,
    topics: window.TOPICS,
  };
  const TOPICS = PAGE.topics || [];
  const [openTopic, setOpenTopic] = useStateA(null);
  const [hoveredTag, setHoveredTag] = useStateA(null);
  const [submitOpen, setSubmitOpen] = useStateA(false);

  const isDark = theme.isDark;
  const accent = theme.accent;
  const bg = isDark ? "#0e0e10" : "#ffffff";
  const fg = isDark ? "#f4f3ee" : "#0e0e10";
  const muted = isDark ? "rgba(244,243,238,0.5)" : "rgba(14,14,16,0.5)";
  const subtle = isDark ? "rgba(244,243,238,0.78)" : "rgba(14,14,16,0.75)";
  const border = isDark ? "rgba(255,255,255,0.09)" : "rgba(0,0,0,0.10)";
  const pillBg = isDark ? "rgba(255,255,255,0.04)" : "#fafbfc";
  const bubbleBg = isDark ? "#1c1c22" : "#0e0e10";
  const bubbleFg = isDark ? "#f4f3ee" : "#ffffff";
  const showCompanies = theme.showCompanies !== false;
  const showTags = theme.showTags !== false;
  const mobile = useIsMobile();
  const RM = PAGE.roadmap;
  const isRoadmap = !!RM;

  // Brick-wall layout: tags arranged in rows of 2, alternating row offsets
  // for an organic "course" pattern. Stable, not systematic.
  const tagRows = useMemoA(() => {
    const perRow = 2;
    const rows = [];
    for (let i = 0; i < P.tags.length; i += perRow) {
      rows.push(P.tags.slice(i, i + perRow));
    }
    return rows;
  }, [P.tags.length]);

  // Pill — shared button style used for handle, tags, and topics.
  // Rounded-rectangle with a soft drop shadow (matches the user reference).
  const Pill = ({ children, onClick, href, target, large, compact, glow, style, dataAttrs = {} }) => {
    const Tag = href ? "a" : onClick ? "button" : "span";
    return (
      <Tag
        {...href ? { href, target, rel: "noreferrer" } : {}}
        {...onClick ? { onClick } : {}}
        data-cursor={onClick || href ? "hover" : undefined}
        {...dataAttrs}
        className={`gv-pill${glow ? " gv-glow" : ""}`}
        style={{
          display: "inline-flex", alignItems: "center", gap: 6,
          padding: large ? "9px 16px" : compact ? "6px 12px" : "7px 14px",
          fontSize: large ? 14.5 : compact ? 13 : 13.5,
          fontWeight: 500, letterSpacing: "-0.005em",
          fontFamily: '"Inter", system-ui, -apple-system, sans-serif',
          fontFeatureSettings: '"cv11", "ss01"',
          color: fg,
          background: pillBg,
          border: `1px solid ${border}`,
          borderRadius: compact ? 8 : 9,
          cursor: onClick || href ? "pointer" : "default",
          textDecoration: "none",
          boxShadow: isDark ?
          "0 1px 0 rgba(255,255,255,0.04) inset, 0 2px 0 rgba(0,0,0,0.35), 0 4px 10px rgba(0,0,0,0.45)" :
          "0 1px 0 rgba(255,255,255,0.9) inset, 0 2px 0 rgba(15,15,15,0.04), 0 4px 10px rgba(15,15,15,0.06)",
          transition: "transform 360ms cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 280ms ease, background 220ms ease, border-color 220ms ease, color 220ms ease",
          willChange: "transform",
          whiteSpace: "nowrap",
          ...style
        }}>
        
        {children}
      </Tag>);

  };

  return (
    <div style={{
      background: bg,
      color: fg,
      fontFamily: theme.fontStack,
      minHeight: "100%",
      width: "100%",
      padding: mobile ? "48px 20px 56px" : "80px 92px 80px",
      boxSizing: "border-box",
      position: "relative",
      overflow: "hidden"
    }}>
      <style>{`
        @property --gv-ang { syntax: '<angle>'; inherits: false; initial-value: 0deg; }
        @keyframes gv-spin { to { --gv-ang: 360deg; } }

        .gv-glow {
          position: relative;
          isolation: isolate;
        }
        .gv-glow::before {
          content: '';
          position: absolute;
          inset: -1px;
          border-radius: 10px;
          padding: 1px;
          background: conic-gradient(from var(--gv-ang),
            transparent 0deg,
            transparent 250deg,
            rgba(210, 218, 230, 0.95) 305deg,
            rgba(255, 255, 255, 1) 322deg,
            rgba(210, 218, 230, 0.95) 340deg,
            transparent 360deg);
          -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
          -webkit-mask-composite: xor;
                  mask-composite: exclude;
          animation: gv-spin 2.8s linear infinite;
          pointer-events: none;
          z-index: 2;
        }

        .gv-pill:hover {
          transform: translate(var(--gv-dx, 0px), var(--gv-dy, -3px)) !important;
          box-shadow: ${isDark ?
        "0 1px 0 rgba(255,255,255,0.05) inset, 0 4px 0 rgba(0,0,0,0.4), 0 12px 24px rgba(0,0,0,0.55)" :
        "0 1px 0 rgba(255,255,255,0.95) inset, 0 4px 0 rgba(15,15,15,0.06), 0 14px 28px rgba(15,15,15,0.09)"} !important;
          border-color: ${isDark ? "rgba(255,255,255,0.22)" : "rgba(0,0,0,0.22)"} !important;
        }
        .gv-bubble {
          transition: transform 320ms cubic-bezier(.2,.7,.2,1), background 220ms ease, z-index 0ms;
          will-change: transform;
        }
        .gv-bubble:hover {
          transform: translateY(-4px) scale(1.04);
          z-index: 100 !important;
        }
        .gv-avatar-wrap {
          transition: transform 380ms cubic-bezier(.2,.7,.2,1);
          will-change: transform;
        }
        .gv-avatar-wrap:hover {
          transform: scale(1.03);
        }
      `}</style>

      <div style={{
        maxWidth: 1080, margin: "0 auto",
        display: "flex", flexDirection: "column", gap: 0
      }}>
        {/* ────────────── Header row ────────────── */}
        <div style={{
          display: "grid",
          gridTemplateColumns: "auto 1fr",
          gap: mobile ? 18 : 28,
          alignItems: "start",
          marginBottom: mobile ? 52 : 96
        }}>
          {/* Avatar */}
          <Stagger delay={0}>
            <a
              href={P.socials[0].href}
              target="_blank"
              rel="noreferrer"
              data-cursor="hover"
              className="gv-avatar-wrap"
              aria-label={P.name}
              style={{
                display: "block",
                width: 104, height: 104, borderRadius: 999,
                overflow: "hidden",
                border: `1px solid ${border}`,
                background: isDark ? "#1a1a20" : "#f1eee7",
                flexShrink: 0,
                position: "relative"
              }}>

              <image-slot
                id="gigi-avatar"
                shape="circle"
                placeholder="Drop your photo"
                fit="cover"
                {...(P.avatar ? { src: P.avatar } : {})}
                style={{
                  position: "absolute",
                  width: "118%", height: "118%",
                  top: "-9%", left: "-9%",
                  display: "block",
                  background: "transparent",
                  borderRadius: 999
                }}>
              </image-slot>
            </a>
          </Stagger>

          {/* Name block */}
          <div style={{ paddingTop: 4 }}>
            <Stagger delay={60}>
              <h1 style={{
                fontSize: 32, fontWeight: 700, letterSpacing: "-0.03em",
                lineHeight: 1.05, margin: "0 0 12px",
                fontFamily: '"Inter", system-ui, -apple-system, sans-serif',
                fontFeatureSettings: '"cv11", "ss01"'
              }}>{P.name}</h1>
            </Stagger>

            <Stagger delay={120}>
              <div style={{ marginBottom: 12 }}>
                <Pill href={P.socials[0].href} target="_blank" glow>{P.handle}</Pill>
              </div>
            </Stagger>

            <Stagger delay={180}>
              <p style={{
                fontSize: 13.5, lineHeight: 1.5, margin: 0, color: muted,
                letterSpacing: "-0.005em"
              }}>
                {P.role} at{" "}
                <a
                  href={P.roleUrl}
                  data-cursor="hover"
                  style={{ color: fg, fontWeight: 600, textDecoration: "none" }}>
                  {P.roleAt}</a>
              </p>
            </Stagger>
          </div>
        </div>

        {/* ────────────── Roadmap (only on /product-roadmap) ────────────── */}
        {isRoadmap && (
          <React.Fragment>
            <div style={{
              display: "flex",
              flexDirection: mobile ? "column" : "row",
              alignItems: mobile ? "flex-start" : "flex-end",
              justifyContent: "space-between",
              gap: mobile ? 20 : 24,
              marginBottom: 22,
            }}>
              <Stagger delay={60}>
                <h2 style={{
                  fontSize: mobile ? 40 : 56, fontWeight: 700,
                  letterSpacing: "-0.04em", lineHeight: 0.98, margin: 0,
                  fontFamily: '"Inter", system-ui, -apple-system, sans-serif',
                  fontFeatureSettings: '"cv11", "ss01"',
                }}>{RM.title || "Product roadmap"}</h2>
              </Stagger>
              {(RM.submitEmail || RM.submitUrl) && (
                <Stagger delay={120}>
                  <Pill
                    large
                    glow
                    onClick={RM.submitEmail ? () => setSubmitOpen(true) : undefined}
                    href={RM.submitEmail ? undefined : RM.submitUrl}
                    target={RM.submitEmail ? undefined : "_blank"}
                    style={{ ["--gv-dy"]: "-3px" }}
                  >
                    <span style={{ color: accent, fontWeight: 600 }}>＋</span>
                    <span>{RM.submitLabel || "Submit new feature"}</span>
                  </Pill>
                </Stagger>
              )}
            </div>

            <Stagger delay={180}>
              <p style={{
                fontSize: 16, lineHeight: 1.6, margin: "0 0 36px",
                color: isDark ? "rgba(244,243,238,0.85)" : "#3a3a3f",
                letterSpacing: "-0.005em", maxWidth: 560,
                fontFamily: '"Inter", system-ui, -apple-system, sans-serif',
                fontFeatureSettings: '"cv11", "ss01", "ss03"',
              }}>{RM.intro}</p>
            </Stagger>

            <Stagger delay={240}>
              <div style={{
                marginBottom: mobile ? 56 : 96,
                borderRadius: 16,
                overflow: "hidden",
                border: `1px solid ${border}`,
                background: isDark ? "#111114" : "#0e0e10",
                boxShadow: isDark
                  ? "0 12px 40px rgba(0,0,0,0.5)"
                  : "0 12px 40px rgba(15,15,15,0.10)",
              }}>
                {RM.notionUrl ? (
                  <iframe
                    src={RM.notionUrl}
                    title={RM.title || "Product roadmap"}
                    loading="lazy"
                    style={{
                      display: "block", width: "100%",
                      height: mobile ? "70vh" : "78vh",
                      minHeight: 520, border: "none",
                    }}
                  ></iframe>
                ) : (
                  <div style={{
                    padding: "64px 28px", textAlign: "center",
                    color: "rgba(255,255,255,0.6)", fontSize: 14, lineHeight: 1.6,
                  }}>
                    Incolla qui il link pubblico del tuo Notion in
                    <code style={{
                      background: "rgba(255,255,255,0.08)", padding: "2px 6px",
                      borderRadius: 5, margin: "0 5px", fontSize: 12.5,
                    }}>pages.js → roadmap.notionUrl</code>
                    e la board comparirà qui, sempre aggiornata.
                  </div>
                )}
              </div>
            </Stagger>
          </React.Fragment>
        )}

        {/* ────────────── Bio left / Tags right ────────────── */}
        {!isRoadmap && (
        <div style={{
          display: "grid",
          gridTemplateColumns: mobile ? "1fr" : "1.05fr 1fr",
          gap: mobile ? 28 : 28,
          marginBottom: mobile ? 56 : 96,
          alignItems: "start"
        }}>
          <Stagger delay={260}>
            <p style={{
              fontSize: 16, lineHeight: 1.65, margin: 0,
              color: isDark ? "rgba(244,243,238,0.85)" : "#3a3a3f",
              letterSpacing: "-0.005em", maxWidth: 460,
              fontFamily: '"Inter", system-ui, -apple-system, sans-serif',
              fontFeatureSettings: '"cv11", "ss01", "ss03"',
              fontWeight: 400
            }}>{P.bio}</p>
          </Stagger>

          {showTags &&
          <Stagger delay={320}>
              <div style={{
              position: "relative",
              display: "flex", flexDirection: "column",
              alignItems: "flex-start",
              gap: 0,
              paddingTop: 2, lineHeight: "1.8"
            }}>
                {tagRows.map((row, rowIdx) => {
                // Alternating "courses" — even rows flush, odd rows offset
                // by roughly half a brick. Offset drops on mobile.
                const rowOffsetX = mobile ? 0 : (rowIdx % 2 === 0 ? 0 : 38);
                return (
                  <div
                    key={rowIdx}
                    style={{
                      display: "flex",
                      gap: 4,
                      marginTop: rowIdx === 0 ? 0 : -6,
                      transform: `translateX(${rowOffsetX}px)`
                    }}>
                      {row.map((t, j) => {
                      const i = rowIdx * 2 + j;
                      const isHov = hoveredTag === i;
                      const label = typeof t === "string" ? t : t.label;
                      return (
                        <div
                          key={label}
                          onMouseEnter={() => setHoveredTag(i)}
                          onMouseLeave={() => setHoveredTag(null)}
                          style={{
                            position: "relative",
                            zIndex: isHov ? 50 : 1,
                            transform: `translate(${isHov ? 4 : 0}px, ${isHov ? -5 : 0}px)`,
                            transition: isHov ?
                            "transform 380ms cubic-bezier(0.34, 1.56, 0.64, 1)" :
                            "transform 260ms cubic-bezier(0.4, 0, 0.2, 1)",
                            transformOrigin: "left center"
                          }}>
                            <Pill
                            compact
                            glow
                            style={{
                              ["--gv-dx"]: "0px",
                              ["--gv-dy"]: "0px"
                            }}>
                              {label}
                            </Pill>
                          </div>);

                    })}
                    </div>);

              })}
              </div>
            </Stagger>
          }
        </div>
        )}

        {/* ────────────── Booking ────────────── */}
        {PAGE.showBooking && (
        <Stagger delay={420}>
          <h2 style={{
            fontSize: 15, fontWeight: 600, letterSpacing: "-0.005em",
            margin: "0 0 18px", color: fg
          }}>{PAGE.heading || "Book a session with me:"}</h2>
        </Stagger>
        )}

        {/* Booking pills — diagonal "brick wall" like the CEO page. Rows are
               balanced (no lonely trailing single pill) and, on creators/jobs,
               the whole staggered block is centered in the column. */}
        {PAGE.showBooking && (() => {
          // Balance N topics into rows of at most 3, as evenly as possible,
          // so we never get a trailing row with a single pill (e.g. 7 → 3,2,2;
          // 4 → 2,2; 6 → 3,3 unchanged so the CEO page looks identical).
          const n = TOPICS.length;
          const rowCount = Math.max(1, Math.ceil(n / 3));
          const base = Math.floor(n / rowCount);
          let extra = n % rowCount;
          const rows = [];
          let cursor = 0;
          for (let r = 0; r < rowCount; r++) {
            const size = base + (extra > 0 ? 1 : 0);
            if (extra > 0) extra--;
            rows.push(TOPICS.slice(cursor, cursor + size));
            cursor += size;
          }
          const centered = !!PAGE.tidyBooking;
          let idx = 0;
          return (
            <div style={{
              display: "flex", flexDirection: "column",
              alignItems: "flex-start",
              gap: 8,
              marginBottom: mobile ? 72 : 120,
              lineHeight: "1.4",
            }}>
              <div style={{
                display: "flex", flexDirection: "column",
                alignItems: "flex-start", width: mobile ? "100%" : "fit-content", gap: 8,
              }}>
                {rows.map((rowTopics, rowIdx) => {
                  const isLast = rowIdx === rows.length - 1;
                  const isShortLast = isLast && rowTopics.length < rows[0].length;
                  // Left-aligned brick like the CEO page; the trailing short row
                  // (creators/jobs) is centered under the group instead of
                  // hanging off to one side. On mobile we drop the diagonal
                  // offset and let pills wrap so nothing overflows.
                  const rowOffsetX = mobile
                    ? 0
                    : (centered && isShortLast)
                    ? 0
                    : (rowIdx % 2 === 0 ? 0 : 56);
                  return (
                    <div
                      key={rowIdx}
                      style={{
                        display: "flex",
                        gap: 8,
                        flexWrap: mobile ? "wrap" : "nowrap",
                        width: (centered && isShortLast && !mobile) ? "100%" : "auto",
                        justifyContent: (centered && isShortLast && !mobile) ? "center" : "flex-start",
                        transform: `translateX(${rowOffsetX}px)`
                      }}>
                      {rowTopics.map((t) => {
                        const i = idx++;
                        return (
                          <Stagger key={t.id} delay={460 + i * 50}>
                            <Pill
                              large
                              glow
                              onClick={() => setOpenTopic(t)}
                              style={{ ["--gv-dy"]: "-3px" }}>
                              <span>{t.title}</span>
                              <span style={{
                                fontSize: 11.5, color: muted, fontWeight: 500,
                                marginLeft: 4, paddingLeft: 9,
                                borderLeft: `1px solid ${border}`
                              }}>{t.duration}</span>
                            </Pill>
                          </Stagger>);
                      })}
                    </div>);
                })}
              </div>
            </div>);
        })()}

        {/* ────────────── Companies ────────────── */}
        {showCompanies && !isRoadmap &&
        <>
            <Stagger delay={780}>
              <h2 style={{
              fontSize: 15, fontWeight: 400, color: fg,
              letterSpacing: "-0.005em", margin: "0 0 22px"
            }}>Companies I've worked/collaborated with:</h2>
            </Stagger>

            <Stagger delay={820}>
              <div style={{ display: "flex", alignItems: "center", paddingLeft: 0 }}>
                {P.companies.map((c, idx) => {
                const name = typeof c === "string" ? c : c.name;
                const icon = typeof c === "object" ? c.icon : null;
                const initial = name.replace(/\s/g, "").slice(0, 1).toUpperCase();
                const scale = typeof c === "object" && c.scale || 1;
                return (
                  <a
                    key={name}
                    href="#"
                    data-cursor="hover"
                    title={name}
                    aria-label={name}
                    className="gv-bubble gv-bubble-stack"
                    style={{
                      width: 48, height: 48, borderRadius: 999,
                      background: bubbleBg,
                      color: bubbleFg,
                      display: "inline-flex", alignItems: "center", justifyContent: "center",
                      textDecoration: "none",
                      overflow: "hidden",
                      position: "relative",
                      marginLeft: idx === 0 ? 0 : -14,
                      zIndex: idx + 1,
                      border: isDark ?
                      "2px solid #0e0e10" :
                      "2px solid #ffffff",
                      boxShadow: isDark ?
                      "0 2px 8px rgba(0,0,0,0.4)" :
                      "0 2px 8px rgba(15,15,15,0.08)"
                    }}>
                      {icon ?
                    <img
                      src={icon}
                      alt={name}
                      style={{
                        width: "100%", height: "100%",

                        display: "block",
                        transform: `scale(${scale})`,
                        transformOrigin: "center", objectFit: "cover"
                      }} /> :


                    <span style={{
                      fontSize: 14, fontWeight: 600, letterSpacing: "-0.02em",
                      color: bubbleFg
                    }}>{initial}</span>
                    }
                    </a>);

              })}
              </div>
            </Stagger>
          </>
        }

        {/* ────────────── Footer ────────────── */}
        <Stagger delay={900}>
          <div style={{
            marginTop: 96, paddingTop: 20,
            borderTop: `1px solid ${border}`,
            display: "flex", justifyContent: "space-between", alignItems: "center",
            color: muted, fontSize: 12.5
          }}>
            <span>© {P.name} · 2026</span>
            <div style={{ display: "flex", gap: 16 }}>
              {P.socials.map((s) =>
              <a key={s.label} href={s.href} target="_blank" rel="noreferrer" data-cursor="hover" style={{
                color: subtle, textDecoration: "none"
              }}>{s.label}</a>
              )}
            </div>
          </div>
        </Stagger>
      </div>

      <BookingModal topic={openTopic} onClose={() => setOpenTopic(null)} theme={theme} calendar={PAGE.calendar} embedUrl={PAGE.embedUrl} />
      {isRoadmap && RM.submitEmail && (
        <SubmitFeatureModal
          open={submitOpen}
          onClose={() => setSubmitOpen(false)}
          theme={theme}
          config={{ email: RM.submitEmail, endpoint: RM.submitEndpoint, areas: RM.submitAreas }}
        />
      )}
    </div>);

}

window.LandingClassic = LandingClassic;