/* global React */
// Shared full-screen section helpers (Sl*), used by the About page and available to
// future narrative pages. Exported on window.SL. Originally written for the retired
// storefront Sailing pages (archived in sailing-performance-web/work/storefront-native-pages).
const { Icon, Eyebrow, Btn, Reveal, DeviceShowcase, AccentText } = window;

const slInner = (children, style = {}) => (
  <div style={{ maxWidth: 1080, margin: "0 auto", position: "relative", ...style }}>{children}</div>
);

// ---------------- SlSection — natural-height section shell ----------------
// Mirrors product.jsx's cdSection (bg image + local radial scrim under the
// text column) but WITHOUT the 100vh floor or the snap class — these pages
// scroll normally. className "sl-sec" carries the mobile padding override
// (added to index.html's CSS by another work package).
function SlSection({ children, id, style = {}, bg = null, bgOpacity = 0.14, scrimX = "30%", deep = false }) {
  return (
    <section id={id} className="snap-sec sl-sec" style={{ position: "relative", minHeight: "100vh", padding: "110px 32px 84px", display: "flex", flexDirection: "column", justifyContent: "center",
      ...(bg ? { overflow: "hidden" } : null),
      background: deep ? "var(--bg-deep)" : "transparent",
      borderTop: deep ? "1px solid var(--hairline)" : "none",
      borderBottom: deep ? "1px solid var(--hairline)" : "none",
      ...style }}>
      {bg && <div aria-hidden="true" style={{ position: "absolute", inset: 0, backgroundImage: `url(${bg})`, backgroundSize: "cover",
        backgroundRepeat: "no-repeat", backgroundPosition: "center", opacity: bgOpacity, pointerEvents: "none" }} />}
      {bg && <div aria-hidden="true" style={{ position: "absolute", inset: 0, pointerEvents: "none",
        background: `radial-gradient(ellipse 62% 55% at ${scrimX} 45%, rgba(7,22,37,.75), transparent 72%)` }} />}
      {slInner(children)}
    </section>
  );
}

// ---------------- SlBack — "Home" link, shared by both heroes ----------------
function SlBack({ go }) {
  return (
    <button onClick={() => go("home")} style={{ all: "unset", cursor: "pointer", display: "inline-flex", alignItems: "center", gap: 7,
      fontFamily: "var(--font-ui)", fontSize: 13, color: "var(--ink-3)", marginBottom: 26 }}
      onMouseEnter={(e) => e.currentTarget.style.color = "var(--ink)"} onMouseLeave={(e) => e.currentTarget.style.color = "var(--ink-3)"}>
      <Icon name="ArrowLeft" size={15} /> Home
    </button>
  );
}

// ---------------- SlPaper — navy figure card (Sailing Performance only) ----------------
// The approved art direction for this product: a navy line-art card
// against the otherwise dark suite chrome, rather than the blue glass panels
// the rest of the site uses for imagery.
function SlPaper({ image, alt, kicker, caption, eager }) {
  return (
    <div style={{ borderRadius: 16, overflow: "hidden", background: "#0b111e", border: "1px solid var(--hairline-2)" }}>
      <div style={{ position: "relative", width: "100%", aspectRatio: "16 / 9", background: "#0b111e" }}>
        <img src={image} alt={alt} loading={eager ? "eager" : "lazy"} style={{ position: "absolute", inset: 0, width: "100%", height: "100%", objectFit: "cover", display: "block" }} />
      </div>
      {(kicker || caption) && (
        <div style={{ padding: "14px 18px 16px", background: "var(--panel)" }}>
          {kicker && <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, fontWeight: 700, letterSpacing: ".14em", textTransform: "uppercase", color: "var(--cyan-2)", marginBottom: 6 }}>{kicker}</div>}
          {caption && <p style={{ fontFamily: "var(--font-ui)", fontWeight: 400, fontSize: 13, lineHeight: 1.55, color: "var(--ink-3)", margin: 0 }}>{caption}</p>}
        </div>
      )}
    </div>
  );
}

// ---------------- SlHero — shared hero shell for both pages ----------------
// `figure` (Sailing Performance): two-column, text left / SlPaper right.
// `bg` (Sailing Simulator): full-bleed background image behind a single
// centered text column, with a left-to-right scrim so the copy stays legible.
function SlHero({ go, spec }) {
  const facts = spec.facts || [];
  return (
    <section className="snap-sec" style={{ position: "relative", minHeight: "100vh", display: "flex", flexDirection: "column", justifyContent: "center", overflow: "hidden", padding: "110px 32px 84px", background: "var(--bg-deep)" }}>
      {spec.bg && <div aria-hidden="true" style={{ position: "absolute", inset: 0, backgroundImage: `url(${spec.bg})`, backgroundSize: "cover",
        backgroundPosition: "center", opacity: spec.bgOpacity ?? 0.14, pointerEvents: "none" }} />}
      {spec.bg && <div aria-hidden="true" style={{ position: "absolute", inset: 0, pointerEvents: "none",
        background: "linear-gradient(90deg, var(--bg-deep) 10%, rgba(7,12,21,.55) 52%, transparent 100%)" }} />}
      <div aria-hidden="true" style={{ position: "absolute", inset: 0, pointerEvents: "none",
        background: "radial-gradient(ellipse 70% 80% at 82% 8%, rgba(80,134,182,.12), transparent 58%)" }} />
      {slInner(
        <div>
          <SlBack go={go} />
          <div className="responsive-grid" style={{ display: "grid", gridTemplateColumns: spec.figure ? "1.1fr .9fr" : "1fr", gap: 48, alignItems: "center" }}>
            <div style={{ maxWidth: spec.figure ? "none" : 680, margin: spec.figure ? 0 : "0 auto", textAlign: spec.figure ? "left" : "center" }}>
              {spec.eyebrow && <div className="rise" style={{ animationDelay: ".1s" }}><Eyebrow>{spec.eyebrow}</Eyebrow></div>}
              <h1 className="rise" style={{ animationDelay: ".16s", fontFamily: "var(--font-head)", fontWeight: 400, whiteSpace: "pre-line",
                fontSize: "clamp(34px,4.8vw,58px)", lineHeight: 1.06, letterSpacing: "-0.01em", color: "#fff", margin: "14px 0 0" }}>
                <AccentText text={spec.title} accent={spec.accentWord} />
              </h1>
              <p className="rise" style={{ animationDelay: ".24s", fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: "clamp(16px,1.7vw,18.5px)",
                lineHeight: 1.65, color: "var(--ink-2)", margin: "20px 0 0", maxWidth: spec.figure ? 520 : 640,
                marginLeft: spec.figure ? 0 : "auto", marginRight: spec.figure ? 0 : "auto" }}>{spec.tagline}</p>
              {facts.length > 0 && (
                <div className="rise" style={{ animationDelay: ".3s", marginTop: 20, display: "flex", justifyContent: spec.figure ? "flex-start" : "center",
                  flexWrap: "wrap", gap: 8, fontFamily: "var(--font-mono)", fontSize: 11.5, letterSpacing: ".03em", color: "var(--ink-3)" }}>
                  {facts.map((f, i) => (
                    <span key={f} style={{ display: "inline-flex", alignItems: "center", gap: 8 }}>
                      {i > 0 && <span style={{ color: "var(--ink-4)" }}>·</span>}{f}
                    </span>
                  ))}
                </div>
              )}
              <div className="rise" style={{ animationDelay: ".36s", display: "flex", gap: 13, marginTop: 32, flexWrap: "wrap",
                justifyContent: spec.figure ? "flex-start" : "center" }}>
                <Btn size="lg" onClick={() => go("contact-sales")} iconRight="ArrowRight">{spec.ctaLabel}</Btn>
                {spec.ghostAnchor && (
                  <Btn size="lg" variant="ghost" onClick={() => go(spec.route, spec.ghostAnchor)}>{spec.ghostLabel}</Btn>
                )}
              </div>
            </div>
            {spec.figure && (
              <div className="rise" style={{ animationDelay: ".2s" }}>
                <SlPaper image={spec.figure.image} alt={spec.figure.alt} kicker={spec.figure.kicker} caption={spec.figure.caption} eager />
              </div>
            )}
          </div>
        </div>
      )}
    </section>
  );
}

// ---------------- SlHead — eyebrow + h2 + body paragraph(s) ----------------
function SlHead({ eyebrow, headline, accentWord, body, align = "left", max = 680 }) {
  const centered = align === "center";
  const body_ = typeof body === "string" ? [body] : (body || []);
  return (
    <Reveal style={{ textAlign: align, maxWidth: centered ? max : "none", marginLeft: centered ? "auto" : 0, marginRight: centered ? "auto" : 0 }}>
      {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
      <h2 style={{ fontFamily: "var(--font-head)", fontWeight: 400, fontSize: "clamp(28px,3.6vw,44px)", lineHeight: 1.14,
        letterSpacing: "-0.01em", color: "var(--ink)", margin: "14px 0 0", maxWidth: max, whiteSpace: "pre-line" }}>
        <AccentText text={headline} accent={accentWord} />
      </h2>
      {body_.map((para, i) => (
        <p key={i} style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 16, lineHeight: 1.75, color: "var(--ink-3)",
          margin: "16px 0 0", maxWidth: max, marginLeft: centered ? "auto" : 0, marginRight: centered ? "auto" : 0 }}>{para}</p>
      ))}
    </Reveal>
  );
}

// ---------------- SlCards / SlBullets — local icon-card & bullet renderers ----------------
// Same visual language as product.jsx's CDCards/CDBullets (surface card /
// ruled bullet row over the storefront tokens), kept local so this file has
// no coupling to product.jsx's internal helpers beyond the shared atoms.
function SlCards({ items, cols }) {
  const n = cols || (items.length % 3 === 0 ? 3 : (items.length === 4 ? 2 : 3));
  return (
    <div className="responsive-grid" style={{ display: "grid", gridTemplateColumns: `repeat(${n},1fr)`, gap: 16, marginTop: 32 }}>
      {items.map(([icon, title, desc], i) => (
        <Reveal key={title} delay={i * 60}>
          <div style={{ height: "100%", padding: "24px 22px", borderRadius: 16, background: "var(--surface)", border: "1px solid var(--hairline)" }}>
            <span style={{ width: 42, height: 42, borderRadius: 12, background: "rgba(80,134,182,.08)", border: "1px solid rgba(80,134,182,.18)",
              display: "flex", alignItems: "center", justifyContent: "center", color: "var(--cyan-2)", marginBottom: 15 }}><Icon name={icon} size={19} /></span>
            <div style={{ fontFamily: "var(--font-ui)", fontSize: 15.5, fontWeight: 600, color: "var(--ink)", marginBottom: 6 }}>{title}</div>
            <div style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 13.5, lineHeight: 1.6, color: "var(--ink-3)" }}>{desc}</div>
          </div>
        </Reveal>
      ))}
    </div>
  );
}

function SlBulletRow({ icon, title, desc, first }) {
  const [h, setH] = React.useState(false);
  return (
    <div onMouseEnter={() => setH(true)} onMouseLeave={() => setH(false)}
      style={{ display: "flex", gap: 14, alignItems: "flex-start", padding: "15px 12px", margin: "0 -12px", borderRadius: 12,
        borderTop: first ? "none" : "1px solid var(--hairline)",
        background: h ? "rgba(80,134,182,.06)" : "transparent",
        transform: h ? "translateX(5px)" : "none",
        transition: "background .25s var(--ease), transform .25s var(--ease)" }}>
      <span style={{ width: 34, height: 34, flexShrink: 0, borderRadius: 10,
        background: h ? "var(--cyan)" : "rgba(80,134,182,.08)",
        border: h ? "1px solid var(--cyan)" : "1px solid rgba(80,134,182,.18)",
        color: h ? "var(--cyan-ink)" : "var(--cyan-2)",
        display: "flex", alignItems: "center", justifyContent: "center", transition: "all .25s var(--ease)" }}>
        <Icon name={icon} size={16} />
      </span>
      <p style={{ margin: 0, fontFamily: "var(--font-ui)", fontSize: 15.5, lineHeight: 1.6 }}>
        <span style={{ fontWeight: 600, color: "var(--ink)" }}>{title}</span>
        <span style={{ fontWeight: 300, color: h ? "var(--ink-2)" : "var(--ink-3)", transition: "color .25s" }}> — {desc}</span>
      </p>
    </div>
  );
}
function SlBullets({ items, contained = true }) {
  return (
    <div style={contained ? { maxWidth: 640, margin: "32px auto 0", textAlign: "left" } : { textAlign: "left", marginTop: 32 }}>
      {items.map(([icon, title, desc], i) => (
        <Reveal key={title} delay={i * 70}>
          <SlBulletRow icon={icon} title={title} desc={desc} first={i === 0} />
        </Reveal>
      ))}
    </div>
  );
}

// ---------------- SlChips — pill row (compatibility section) ----------------
function SlChips({ items }) {
  return (
    <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginTop: 26 }}>
      {items.map((c) => (
        <span key={c} style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--ink-2)", padding: "6px 12px",
          borderRadius: 999, background: "rgba(80,134,182,.07)", border: "1px solid rgba(80,134,182,.2)" }}>{c}</span>
      ))}
    </div>
  );
}

// ---------------- SlRoles — five role tabs + a decorative deck-plan ----------------
// The deck plan is a purely decorative bow-to-transom schematic; it is only
// mounted at wide viewports (checked at mount + on resize) rather than hidden
// with a component-local <style> media query.
function useShowDeckPlan() {
  const [show, setShow] = React.useState(() => typeof window !== "undefined" && window.innerWidth >= 860);
  React.useEffect(() => {
    const onResize = () => setShow(window.innerWidth >= 860);
    window.addEventListener("resize", onResize);
    return () => window.removeEventListener("resize", onResize);
  }, []);
  return show;
}

function DeckPlanSvg({ activeIndex, stations }) {
  const n = stations.length;
  const top = 30, bottom = 300, cx = 55;
  const ys = stations.map((_, i) => top + ((bottom - top) * i) / (n - 1));
  return (
    <svg viewBox="0 0 110 330" width="100%" height="330" role="img" aria-hidden="true" style={{ maxWidth: 150, margin: "0 auto", display: "block" }}>
      {/* hull outline — pointed bow at top, flat transom at bottom */}
      <path d={`M ${cx} 6 C 95 70, 100 220, 92 300 L 18 300 C 10 220, 15 70, ${cx} 6 Z`}
        fill="rgba(80,134,182,.05)" stroke="rgba(80,134,182,.35)" strokeWidth="1.5" />
      {/* centreline */}
      <line x1={cx} y1="14" x2={cx} y2="298" stroke="rgba(80,134,182,.18)" strokeWidth="1" strokeDasharray="2 4" />
      {stations.map((s, i) => (
        <g key={s} transform={`translate(${cx} ${ys[i]})`}>
          <circle r={i === activeIndex ? 7 : 4.5} fill={i === activeIndex ? "var(--cyan)" : "rgba(80,134,182,.4)"}
            stroke={i === activeIndex ? "#fff" : "none"} strokeWidth="1.5" />
        </g>
      ))}
      <text x={cx} y="16" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="7" fill="var(--ink-4)" letterSpacing=".08em">BOW</text>
      <text x={cx} y="316" textAnchor="middle" fontFamily="var(--font-mono)" fontSize="7" fill="var(--ink-4)" letterSpacing=".08em">TRANSOM</text>
    </svg>
  );
}

function SlRoles({ spec }) {
  const stations = spec.tabs.map((t) => t.station);
  const [active, setActive] = React.useState(0);
  const tabRefs = React.useRef([]);
  const showDeck = useShowDeckPlan();
  const tab = spec.tabs[active];

  // Roving tabindex: arrows/Home/End move BOTH the selection and the focus,
  // so keyboard users never lose their place in the tab sequence.
  const onKeyDown = (e) => {
    const n = stations.length;
    let next = null;
    if (e.key === "ArrowRight") next = (active + 1) % n;
    else if (e.key === "ArrowLeft") next = (active - 1 + n) % n;
    else if (e.key === "Home") next = 0;
    else if (e.key === "End") next = n - 1;
    if (next === null) return;
    e.preventDefault();
    setActive(next);
    const el = tabRefs.current[next];
    if (el && typeof el.focus === "function") el.focus();
  };

  return (
    <div id="roles">
      <SlHead eyebrow={spec.eyebrow} headline={spec.headline} body={spec.body} max={680} />
      <Reveal delay={80}>
        <div role="tablist" aria-label="Crew positions" onKeyDown={onKeyDown} style={{ display: "flex", flexWrap: "wrap", gap: 8, marginTop: 32 }}>
          {stations.map((s, i) => {
            const on = i === active;
            return (
              <button key={s} ref={(el) => { tabRefs.current[i] = el; }} id={`sl-tab-${i}`} role="tab" aria-controls={`sl-panel-${i}`} aria-selected={on} tabIndex={on ? 0 : -1} onClick={() => setActive(i)}
                style={{ all: "unset", cursor: "pointer", boxSizing: "border-box", padding: "9px 16px", borderRadius: 999,
                  background: on ? "rgba(80,134,182,.14)" : "var(--surface)",
                  border: `1px solid ${on ? "rgba(80,134,182,.5)" : "var(--hairline-2)"}`,
                  fontFamily: "var(--font-ui)", fontSize: 13.5, fontWeight: on ? 600 : 400,
                  color: on ? "var(--cyan-2)" : "var(--ink-2)", transition: "background .2s, border-color .2s, color .2s" }}>
                {s}
              </button>
            );
          })}
        </div>
      </Reveal>
      <div className="responsive-grid" style={{ display: "grid", gridTemplateColumns: showDeck ? "150px 1fr" : "1fr", gap: 40, marginTop: 32, alignItems: "start" }}>
        {showDeck && (
          <Reveal delay={100}>
            <DeckPlanSvg activeIndex={active} stations={stations} />
          </Reveal>
        )}
        <Reveal key={tab.station} delay={40}>
          <div role="tabpanel" id={`sl-panel-${active}`} aria-labelledby={`sl-tab-${active}`} tabIndex={0} style={{ padding: "26px 26px", borderRadius: 18, background: "var(--surface)", border: "1px solid var(--hairline)" }}>
            <div style={{ fontFamily: "var(--font-mono)", fontSize: 10.5, fontWeight: 700, letterSpacing: ".14em", textTransform: "uppercase", color: "var(--cyan-2)", marginBottom: 8 }}>{tab.station}</div>
            <h3 style={{ fontFamily: "var(--font-head)", fontWeight: 400, fontSize: "clamp(20px,2.4vw,26px)", color: "var(--ink)", margin: 0 }}>{tab.h3}</h3>
            <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 15, lineHeight: 1.7, color: "var(--ink-3)", margin: "12px 0 0" }}>{tab.body}</p>
            <div style={{ display: "flex", flexDirection: "column", gap: 9, marginTop: 20 }}>
              {tab.metrics.map((m) => (
                <span key={m} style={{ display: "flex", gap: 9, alignItems: "flex-start", fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 13.5, lineHeight: 1.55, color: "var(--ink-2)" }}>
                  <Icon name="Check" size={14} color="var(--cyan-2)" style={{ marginTop: 3, flexShrink: 0 }} />{m}
                </span>
              ))}
            </div>
            <div style={{ marginTop: 20, padding: "14px 16px", borderRadius: 12, borderLeft: "2px solid var(--cyan)", background: "rgba(80,134,182,.05)" }}>
              <div style={{ fontFamily: "var(--font-mono)", fontSize: 9.5, letterSpacing: ".1em", textTransform: "uppercase", color: "var(--ink-4)", marginBottom: 6 }}>Sample debrief line · {tab.station}</div>
              <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontStyle: "italic", fontSize: 14, lineHeight: 1.6, color: "var(--ink-2)", margin: 0 }}>“{tab.quote}”</p>
            </div>
          </div>
        </Reveal>
      </div>
    </div>
  );
}

// ---------------- SlEdition — two-column edition block ----------------
function SlEditionChecks({ items }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 10, marginTop: 20 }}>
      {items.map((c) => (
        <span key={c} style={{ display: "flex", gap: 9, alignItems: "flex-start", fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 14, lineHeight: 1.55, color: "var(--ink-2)" }}>
          <Icon name="Check" size={15} color="var(--cyan-2)" style={{ marginTop: 3, flexShrink: 0 }} />{c}
        </span>
      ))}
    </div>
  );
}
function SlEdition({ e, go, flip }) {
  const copy = (
    <Reveal delay={flip ? 0 : 80}>
      <Eyebrow>{e.eyebrow}</Eyebrow>
      <h3 style={{ fontFamily: "var(--font-head)", fontWeight: 400, fontSize: "clamp(22px,2.8vw,30px)", color: "var(--ink)", margin: "12px 0 0" }}>{e.h3}</h3>
      <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 15, lineHeight: 1.7, color: "var(--ink-3)", margin: "12px 0 0" }}>{e.body}</p>
      <SlEditionChecks items={e.checks} />
      {e.note && <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 12.5, lineHeight: 1.6, color: "var(--ink-4)", margin: "18px 0 0" }}>{e.note}</p>}
      <div style={{ marginTop: 24 }}>
        <Btn variant="soft" onClick={() => go("contact-sales")}>{e.ctaLabel}</Btn>
      </div>
    </Reveal>
  );
  const figure = (
    <Reveal delay={flip ? 80 : 0}>
      <SlPaper image={e.image} alt={e.imageAlt} kicker={e.kicker} caption={e.caption} />
    </Reveal>
  );
  return (
    <div className="responsive-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 44, alignItems: "center", marginTop: 48 }}>
      {flip ? <>{copy}{figure}</> : <>{figure}{copy}</>}
    </div>
  );
}

// ---------------- SlFaq — native details/summary ----------------
function SlFaq({ items }) {
  return (
    <div style={{ marginTop: 28, display: "flex", flexDirection: "column", gap: 10 }}>
      {items.map(([q, a], i) => (
        <Reveal key={q} delay={i * 40}>
          <details open={i === 0} style={{ borderRadius: 14, background: "var(--surface)", border: "1px solid var(--hairline)", padding: "4px 20px", overflow: "hidden" }}>
            <summary style={{ cursor: "pointer", listStyle: "none", padding: "16px 0", fontFamily: "var(--font-ui)", fontSize: 15, fontWeight: 600, color: "var(--ink)",
              display: "flex", alignItems: "center", justifyContent: "space-between", gap: 12 }}>
              {q}
              <Icon name="ChevronDown" size={16} color="var(--ink-3)" />
            </summary>
            <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 14, lineHeight: 1.7, color: "var(--ink-3)", margin: "0 0 18px" }}>{a}</p>
          </details>
        </Reveal>
      ))}
    </div>
  );
}

// ---------------- SlStatus — ruled rows (tag + optional title + body) ----------------
function SlStatus({ rows }) {
  return (
    <div style={{ marginTop: 28 }}>
      {rows.map((row, i) => {
        const [tag, a, b] = row;
        const hasTitle = row.length >= 3;
        const title = hasTitle ? a : null;
        const body = hasTitle ? b : a;
        return (
          <Reveal key={tag} delay={i * 60}>
            <div style={{ display: "grid", gridTemplateColumns: hasTitle ? "110px 220px 1fr" : "110px 1fr", gap: 20,
              padding: "20px 0", borderTop: i === 0 ? "1px solid var(--hairline)" : "none", borderBottom: "1px solid var(--hairline)",
              alignItems: "baseline" }} className="responsive-grid">
              <span style={{ fontFamily: "var(--font-mono)", fontSize: 11, fontWeight: 700, letterSpacing: ".1em", textTransform: "uppercase", color: "var(--cyan-2)" }}>{tag}</span>
              {hasTitle && <span style={{ fontFamily: "var(--font-ui)", fontSize: 15, fontWeight: 600, color: "var(--ink)" }}>{title}</span>}
              <span style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 14, lineHeight: 1.65, color: "var(--ink-3)" }}>{body}</span>
            </div>
          </Reveal>
        );
      })}
    </div>
  );
}

// ---------------- SlClosing — CTA + disclaimer panel + sibling card ----------------
function SlSibling({ go, productKey, text }) {
  const p = (window.PRODUCTS || {})[productKey];
  if (!p) return null;
  return (
    <button onClick={() => go(p.route)} style={{ all: "unset", cursor: "pointer", display: "block", width: "100%", boxSizing: "border-box" }}>
      <div className="liftcard" style={{ padding: "20px 22px", borderRadius: 16, background: "var(--surface)",
        border: "1px solid var(--hairline)", transition: "transform .3s var(--ease), border-color .3s",
        display: "flex", alignItems: "center", gap: 16 }}>
        <span style={{ width: 40, height: 40, flexShrink: 0, borderRadius: 11, background: "rgba(80,134,182,.08)", border: "1px solid rgba(80,134,182,.18)",
          display: "flex", alignItems: "center", justifyContent: "center", color: "var(--cyan-2)" }}><Icon name={p.icon} size={18} /></span>
        <span style={{ textAlign: "left" }}>
          <span style={{ display: "block", fontFamily: "var(--font-mono)", fontSize: 10, letterSpacing: ".1em", textTransform: "uppercase", color: "var(--ink-4)", marginBottom: 4 }}>Also in Sailing</span>
          <span style={{ display: "block", fontFamily: "var(--font-ui)", fontSize: 14.5, fontWeight: 600, color: "var(--ink)" }}>{p.name}</span>
          <span style={{ display: "block", fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 13, lineHeight: 1.5, color: "var(--ink-3)", marginTop: 4 }}>{text}</span>
        </span>
        <Icon name="ArrowRight" size={16} color="var(--ink-3)" style={{ marginLeft: "auto", flexShrink: 0 }} />
      </div>
    </button>
  );
}

function SlClosing({ spec, go, siblingKey }) {
  return (
    <SlSection deep style={{ textAlign: "center" }}>
      <Reveal style={{ maxWidth: 600, margin: "0 auto" }}>
        {spec.eyebrow && <Eyebrow>{spec.eyebrow}</Eyebrow>}
        <h2 style={{ fontFamily: "var(--font-head)", fontWeight: 400, fontSize: "clamp(28px,3.6vw,44px)", color: "var(--ink)", margin: "14px 0 0", whiteSpace: "pre-line" }}>{spec.headline}</h2>
        <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 16, lineHeight: 1.7, color: "var(--ink-3)", margin: "16px auto 30px", maxWidth: 480 }}>{spec.body}</p>
        <Btn size="lg" onClick={() => go("contact-sales")} iconRight="ArrowRight">{spec.ctaLabel}</Btn>
      </Reveal>

      {spec.disclaimer && (
        <Reveal delay={80}>
          <div style={{ textAlign: "left", maxWidth: 640, margin: "44px auto 0", padding: "18px 22px", borderRadius: 14,
            border: "1px solid var(--hairline-2)", background: "var(--wa-02)" }}>
            <div style={{ fontFamily: "var(--font-mono)", fontSize: 10, fontWeight: 700, letterSpacing: ".12em", textTransform: "uppercase", color: "var(--ink-4)", marginBottom: 8 }}>{spec.disclaimer.kicker}</div>
            <p style={{ fontFamily: "var(--font-ui)", fontWeight: 300, fontSize: 12.5, lineHeight: 1.65, color: "var(--ink-3)", margin: 0 }}>{spec.disclaimer.text}</p>
          </div>
        </Reveal>
      )}

      {spec.sibling && (
        <Reveal delay={120}>
          <div style={{ maxWidth: 560, margin: "28px auto 0" }}>
            <SlSibling go={go} productKey={siblingKey} text={spec.sibling.text} />
          </div>
        </Reveal>
      )}
    </SlSection>
  );
}

Object.assign(window, { SL: { SlSection, SlHero, SlHead, SlCards, SlBullets, SlStatus, SlClosing, SlChips, SlFaq } });
