// shared-ui.jsx — cinematic design language chrome shared by every page.
// Exports window.UI = { tokens, Nav, Footer, ContactBand, SectionLabel, PageHead, Logo }
(function () {
  const t = {
    amber: "#e7a95c",
    ink: "#070707",
    panel: "#0e0e0e",
    card: "#0a0a0a",
    text: "#ececec",
    muted: "rgba(236,236,236,.55)",
    faint: "rgba(236,236,236,.38)",
    line: "rgba(255,255,255,.10)",
    disp: '"Bebas Neue", sans-serif',
    body: '"Archivo", system-ui, sans-serif',
    mono: '"DM Mono", ui-monospace, monospace',
  };

  function Logo({ size = 34 }) {
    return (
      <svg width={size} height={size} viewBox="0 0 34 34" fill="none" aria-label="Dancing Shapes logo">
        <path d="M3 25 C 9 25, 11 9, 17 9 S 25 25, 31 25" stroke={t.amber} strokeWidth="1.6" fill="none" strokeLinecap="round" opacity="0.7" />
        <circle cx="3" cy="25" r="3" fill={t.amber} />
        <path d="M17 5.4 L 20.2 11 L 13.8 11 Z" fill={t.text} />
        <rect x="28.2" y="22.2" width="5.6" height="5.6" rx="1" fill={t.amber} transform="rotate(12 31 25)" />
      </svg>
    );
  }

  // Maps a nav label (and a few extras) to its page file. Relative so it works
  // under a GitLab Pages subpath (e.g. /dancingshapes/).
  const NAV_HREF = {
    "Reel": "index.html",
    "Work": "work.html",
    "Addons": "addons.html",
    "Art": "art.html",
    "About": "about.html",
    "Tutorials": "tutorials.html",
  };

  // Desktop nav. `active` = label string to underline.
  function Nav({ active }) {
    const D = window.DATA;
    return (
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between",
        padding: "0 64px", height: 84, borderBottom: `1px solid ${t.line}`, background: t.ink }}>
        <a href="index.html" style={{ textDecoration: "none", display: "flex", alignItems: "center", gap: 14 }}>
          <Logo />
          <div style={{ fontFamily: t.disp, fontSize: 28, letterSpacing: "0.12em", color: t.text }}>
            DANCING<span style={{ color: t.amber }}>SHAPES</span>
          </div>
        </a>
        <div style={{ display: "flex", gap: 36, alignItems: "center" }}>
          {D.nav.map((n) => {
            const on = n === active;
            return (
              <a key={n} href={NAV_HREF[n] || "index.html"} style={{ textDecoration: "none",
                fontFamily: t.mono, fontSize: 12, letterSpacing: "0.14em", textTransform: "uppercase",
                color: on ? t.text : t.muted, paddingBottom: 3,
                borderBottom: on ? `1.5px solid ${t.amber}` : "1.5px solid transparent" }}>{n}</a>
            );
          })}
        </div>
      </div>
    );
  }

  // Mobile nav — hamburger + wordmark, with a tap-to-open full-screen menu.
  function NavMobile({ active }) {
    const D = window.DATA;
    const [open, setOpen] = React.useState(false);
    return (
      <div style={{ position: "sticky", top: 0, zIndex: 20, background: t.ink, borderBottom: `1px solid ${t.line}` }}>
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between",
          padding: "0 20px", height: 60 }}>
          <a href="index.html" style={{ textDecoration: "none", display: "flex", alignItems: "center", gap: 9 }}>
            <Logo size={26} />
            <div style={{ fontFamily: t.disp, fontSize: 21, letterSpacing: "0.1em", color: t.text }}>
              DANCING<span style={{ color: t.amber }}>SHAPES</span>
            </div>
          </a>
          <button aria-label="Menu" onClick={() => setOpen((v) => !v)}
            style={{ background: "none", border: "none", padding: 8, cursor: "pointer", display: "flex", flexDirection: "column", gap: 4 }}>
            {[0, 1, 2].map((i) => <span key={i} style={{ width: 22, height: 1.6, background: open ? t.amber : t.text, transition: "background .15s" }} />)}
          </button>
        </div>
        {open && (
          <div style={{ borderTop: `1px solid ${t.line}`, background: t.ink, padding: "8px 0 14px" }}>
            {D.nav.map((n) => {
              const on = n === active;
              return (
                <a key={n} href={NAV_HREF[n] || "index.html"} style={{ display: "block", textDecoration: "none",
                  fontFamily: t.disp, fontSize: 32, letterSpacing: "0.04em", padding: "10px 20px",
                  color: on ? t.amber : t.text }}>{n}</a>
              );
            })}
          </div>
        )}
      </div>
    );
  }

  // Numbered section label with hairline rule.
  function SectionLabel({ n, children, color = t.amber }) {
    return (
      <div style={{ display: "flex", alignItems: "center", gap: 14, marginBottom: 28 }}>
        <span style={{ fontFamily: t.mono, fontSize: 12, letterSpacing: "0.2em", color }}>{n}</span>
        <span style={{ fontFamily: t.mono, fontSize: 12, letterSpacing: "0.2em", color: t.text, textTransform: "uppercase" }}>{children}</span>
        <span style={{ flex: 1, height: 1, background: t.line }} />
      </div>
    );
  }

  // Big page header band: kicker + giant Bebas title + optional lede.
  function PageHead({ kicker, title, lede, mobile = false }) {
    return (
      <div style={{ padding: mobile ? "44px 20px 30px" : "84px 64px 56px", borderBottom: `1px solid ${t.line}`, background: t.ink }}>
        <div style={{ fontFamily: t.mono, fontSize: mobile ? 11 : 12, letterSpacing: "0.24em", color: t.amber, marginBottom: mobile ? 14 : 20, textTransform: "uppercase" }}>
          {kicker}
        </div>
        <div style={{ fontFamily: t.disp, fontSize: mobile ? 68 : 150, lineHeight: 0.86, letterSpacing: "0.005em", color: t.text }}>
          {title}
        </div>
        {lede && (
          <div style={{ fontFamily: t.body, fontSize: mobile ? 16 : 21, color: "rgba(236,236,236,.78)", marginTop: mobile ? 16 : 26, maxWidth: mobile ? "100%" : 760, lineHeight: 1.5, textWrap: "pretty", whiteSpace: "pre-line" }}>
            {lede}
          </div>
        )}
      </div>
    );
  }

  function LinkedInIcon({ size = 14, color = "currentColor" }) {
    return (
      <svg width={size} height={size} viewBox="0 0 24 24" fill={color} aria-hidden="true" style={{ display: "block" }}>
        <path d="M20.45 20.45h-3.56v-5.57c0-1.33-.02-3.04-1.85-3.04-1.85 0-2.14 1.45-2.14 2.94v5.67H9.35V9h3.42v1.56h.05c.48-.9 1.64-1.85 3.37-1.85 3.6 0 4.27 2.37 4.27 5.46v6.28zM5.34 7.43a2.06 2.06 0 1 1 0-4.13 2.06 2.06 0 0 1 0 4.13zM7.12 20.45H3.55V9h3.57v11.45zM22.22 0H1.77C.79 0 0 .77 0 1.72v20.55C0 23.23.79 24 1.77 24h20.45c.98 0 1.78-.77 1.78-1.73V1.72C24 .77 23.2 0 22.22 0z" />
      </svg>
    );
  }

  function IMDbIcon({ h = 14 }) {
    return (
      <svg height={h} viewBox="0 0 64 32" aria-hidden="true" style={{ display: "block" }}>
        <rect x="0.5" y="0.5" width="63" height="31" rx="5" fill="#0a0a0a" />
        <text x="32" y="23" textAnchor="middle" fontFamily="Archivo, sans-serif" fontWeight="800" fontSize="18" fill="#F5C518" letterSpacing="0.5">IMDb</text>
      </svg>
    );
  }

  // Amber contact band + footer (shared close to every page).
  function ContactBand({ mobile = false }) {
    const D = window.DATA;
    if (mobile) {
      return (
        <div style={{ background: t.amber, color: t.ink, padding: "40px 20px" }}>
          <div style={{ fontFamily: t.disp, fontSize: 58, lineHeight: 0.9 }}>GET IN<br />TOUCH</div>
          <div style={{ fontFamily: t.mono, fontSize: 17, letterSpacing: "0.06em", margin: "16px 0 14px", wordBreak: "break-all" }}>{D.email}</div>
          <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-start", gap: 13, margin: "0 0 22px" }}>
            <a href={D.linkedin} target="_blank" rel="noopener" style={{ textDecoration: "none", color: t.ink, fontFamily: t.mono, fontSize: 16, letterSpacing: "0.06em", display: "inline-flex", alignItems: "center", gap: 10, borderBottom: `1.5px solid ${t.ink}`, paddingBottom: 3 }}><LinkedInIcon size={18} />LINKEDIN ↗</a>
            <a href={D.imdb} target="_blank" rel="noopener" style={{ textDecoration: "none", color: t.ink, fontFamily: t.mono, fontSize: 16, letterSpacing: "0.06em", display: "inline-flex", alignItems: "center", gap: 10, borderBottom: `1.5px solid ${t.ink}`, paddingBottom: 3 }}><IMDbIcon h={19} />IMDB ↗</a>
          </div>
          <div>
          <a href={`mailto:${D.email}`} style={{ textDecoration: "none", fontFamily: t.disp, fontSize: 20, letterSpacing: "0.1em",
            color: t.ink, border: `2px solid ${t.ink}`, padding: "11px 22px", display: "inline-block" }}>
            SEND A MESSAGE →
          </a>
          </div>
        </div>
      );
    }
    return (
      <div style={{ background: t.amber, color: t.ink }}>
        <div style={{ maxWidth: 1280, margin: "0 auto", padding: "76px 80px", display: "flex", alignItems: "center", justifyContent: "space-between" }}>
          <div style={{ fontFamily: t.disp, fontSize: 92, lineHeight: 0.88, letterSpacing: "0.01em" }}>GET IN TOUCH</div>
          <div style={{ textAlign: "right" }}>
            <div style={{ fontFamily: t.mono, fontSize: 18, letterSpacing: "0.06em", marginBottom: 14 }}>{D.email}</div>
            <div style={{ display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 13, marginBottom: 22 }}>
              <a href={D.linkedin} target="_blank" rel="noopener" style={{ textDecoration: "none", color: t.ink, fontFamily: t.mono, fontSize: 17, letterSpacing: "0.06em", display: "inline-flex", alignItems: "center", gap: 10, borderBottom: `1.5px solid ${t.ink}`, paddingBottom: 3 }}><LinkedInIcon size={19} />LINKEDIN ↗</a>
              <a href={D.imdb} target="_blank" rel="noopener" style={{ textDecoration: "none", color: t.ink, fontFamily: t.mono, fontSize: 17, letterSpacing: "0.06em", display: "inline-flex", alignItems: "center", gap: 10, borderBottom: `1.5px solid ${t.ink}`, paddingBottom: 3 }}><IMDbIcon h={20} />IMDB ↗</a>
            </div>
            <div>
            <a href={`mailto:${D.email}`} style={{ textDecoration: "none", fontFamily: t.disp, fontSize: 22, letterSpacing: "0.1em",
              color: t.ink, border: `2px solid ${t.ink}`, padding: "12px 28px", display: "inline-block" }}>
              SEND A MESSAGE →
            </a>
            </div>
          </div>
        </div>
      </div>
    );
  }

  function Footer({ mobile = false }) {
    return (
      <div style={{ padding: mobile ? "20px" : "26px 64px", display: "flex", justifyContent: "space-between", fontFamily: t.mono,
        fontSize: mobile ? 10 : 11, letterSpacing: "0.15em", color: t.muted, background: t.ink }}>
        <span>DANCINGSHAPES.COM</span><span>© 2026 TAL HERSHKOVICH</span>
      </div>
    );
  }

  window.UI = { tokens: t, Logo, Nav, NavMobile, SectionLabel, PageHead, ContactBand, Footer, NAV_HREF };
})();
