// v5 — Section dividers, Closing CTA, Substantial Footer, App entry

// SECTION DIVIDER — quiet typographic plate between IA groups
const V5GroupDivider = ({ label, n, title, copy }) => {
  return (
    <section className="v5-group-divider" data-screen-label={`Group · ${label}`}>
      <div className="v4-container">
        <div className="v5-group-divider-rule"></div>
        <div className="v5-group-divider-row">
          <span className="v5-group-divider-n">{n}</span>
          <div className="v5-group-divider-main">
            <span className="v5-group-divider-label">— {label}</span>
            <h2 className="v5-group-divider-title">
              <WordReveal text={title} stagger={55} />
            </h2>
          </div>
          <div className="v5-group-divider-copy">
            <FadeIn delay={250}>{copy}</FadeIn>
          </div>
        </div>
      </div>
    </section>);

};

// ENGAGEMENT MODES — content-driven cards for the contact section
// ENGAGEMENT MODES — ordered along the idea commercialization timeline
const MODES = [
{
  name: "Workshop",
  range: "1–5 days · with Portal",
  body: "Structured sessions that move a team from scattered ideas to sharper decisions. Run with Portal when the room needs research, provocation, category signal, or outside creative pressure.",
  fit: "Best when the team has the ingredients but needs signal, structure, and a better decision.",
  href: "mailto:znerold@gmail.com?subject=Workshop%20with%20Portal",
  cursor: "1–5 days · Portal collective",
  // Idea commercialization timeline coverage — indices into IDEA_STAGES
  zones: [0, 1]
},
{
  name: "Prototype sprint",
  range: "1–3 weeks · with Portal",
  body: "A fast concept-to-artifact cycle using AI-native workflows, live research, and senior creative direction. Built for moments when a deck is not enough and the team needs something tangible to react to.",
  fit: "Best when you need to make a hard decision, and the prototype has to do the convincing.",
  href: "mailto:znerold@gmail.com?subject=Prototype%20sprint%20with%20Portal",
  cursor: "1–3 wks · research-fed",
  zones: [2, 3, 4]
},
{
  name: "Consulting",
  range: "4–12 weeks",
  body: "Focused strategic engagement to shape a category, brand, product platform, website, campaign system, or AI-enabled workflow. Defined scope, defined deliverables, senior judgment from start to finish.",
  fit: "Best when there is a specific problem to solve and a deadline to hit.",
  href: "mailto:znerold@gmail.com?subject=Consulting%20engagement",
  cursor: "4–12 wks · scope-defined",
  zones: [1, 2, 3, 4]
},
{
  name: "Embedded advisory",
  range: "3–6 months",
  body: "Part-time senior partnership inside the team's existing rhythm. Useful when product, brand, growth, AI, or category decisions need ongoing pressure, clarity, and cross-functional judgment.",
  fit: "Best when the company is at an inflection point and needs a senior partner in the room.",
  href: "mailto:znerold@gmail.com?subject=Embedded%20advisory",
  cursor: "3–6 mo · in the room",
  zones: [0, 1, 2, 3, 4, 5, 6]
},
{
  name: "Selective staff leadership",
  range: "Open-ended",
  body: "Director, VP, or senior leadership roles for the right team. I'm open to staff opportunities when the category, people, mandate, and operating model make sense.",
  fit: "Best when the role needs range, judgment, and a builder's relationship to ambiguity.",
  href: "mailto:znerold@gmail.com?subject=Staff%20leadership%20conversation",
  cursor: "Senior placement",
  zones: [0, 1, 2, 3, 4, 5, 6]
}];


// Idea commercialization timeline — stages a new idea travels through
const IDEA_STAGES = [
{ id: "signal", label: "Signal", note: "Audience, culture, category" },
{ id: "frame", label: "Frame", note: "Thesis, positioning, language" },
{ id: "concept", label: "Concept", note: "Directions, range, system" },
{ id: "validate", label: "Validate", note: "Reduce, test, choose" },
{ id: "prototype", label: "Prototype", note: "Make it real" },
{ id: "ship", label: "Ship", note: "Production, launch, handoff" },
{ id: "scale", label: "Scale", note: "Operate, learn, grow" }];


const V5Engagements = () => {
  const [active, setActive] = useState(2); // start on Consulting
  const [paused, setPaused] = useState(false);

  useEffect(() => {
    if (paused) return;
    const id = setInterval(() => setActive((a) => (a + 1) % MODES.length), 5500);
    return () => clearInterval(id);
  }, [paused]);

  const pick = (i) => {setPaused(true);setActive(i);};
  const activeMode = MODES[active];
  const minZone = Math.min(...activeMode.zones);
  const maxZone = Math.max(...activeMode.zones);
  const N = IDEA_STAGES.length;

  return (
    <section id="engagements" className="v5-engagements" data-screen-label="Engagements">
      <div className="v4-container">
        {/* Compact opener — tiny dim eyebrow, headline directly below */}
        <header className="v5-engagements-head">
          <span className="v5-engagements-eyebrow">
            <span className="v5-engagements-eyebrow-rule"></span>
            <span className="v5-engagements-eyebrow-num">04</span>
            <span>Engagements · ways to work together</span>
          </span>
          <h2 className="v5-engagements-title" data-cursor="Five plug-in points">
            <WordReveal text="Bring me in when the idea is" stagger={55} />
            <br />
            <span className="emph"><WordReveal text="new, messy, or hard to explain." stagger={60} startDelay={400} /></span>
          </h2>
          <p className="v5-engagements-lede">
            <FadeIn delay={350}>
              Five ways to enter the work, depending on where the idea is stuck: signal, frame, concept, validation, prototype, ship, or scale.
            </FadeIn>
          </p>
        </header>

        {/* Idea-commercialization timeline — horizontal, shows active mode's coverage */}
        <div className="v5-engagements-timeline">
          <div className="v5-engagements-timeline-rail">
            {/* Background line */}
            <span className="v5-engagements-timeline-line"></span>

            {/* Active coverage band */}
            <span
              className="v5-engagements-timeline-band"
              style={{
                left: `${minZone / (N - 1) * 100}%`,
                right: `${100 - maxZone / (N - 1) * 100}%`
              }}
              aria-hidden="true">
            </span>

            {/* Stage markers */}
            {IDEA_STAGES.map((s, i) => {
              const isActive = activeMode.zones.includes(i);
              return (
                <div key={s.id}
                className={`v5-engagements-timeline-stage ${isActive ? "is-active" : ""}`}
                style={{ left: `${i / (N - 1) * 100}%` }}
                data-cursor={`Stage · ${s.label}`}>
                  
                  <span className="v5-engagements-timeline-dot"></span>
                  <span className="v5-engagements-timeline-stage-n">{String(i + 1).padStart(2, "0")}</span>
                  <span className="v5-engagements-timeline-stage-label">{s.label}</span>
                  <span className="v5-engagements-timeline-stage-note">{s.note}</span>
                </div>);

            })}
          </div>
        </div>

        {/* Two-column body — mode picker on left, dynamic detail on right */}
        <div className="v5-engagements-body">
          {/* Mode picker — linear list of selectable engagements */}
          <div className="v5-engagements-picker">
            {MODES.map((m, i) =>
            <button
              key={m.name}
              type="button"
              onClick={() => pick(i)}
              onMouseEnter={() => pick(i)}
              className={`v5-engagements-mode-row ${i === active ? "is-active" : ""}`}
              data-cursor={m.cursor}>
              
                <span className="v5-engagements-mode-row-n">{String(i + 1).padStart(2, "0")}</span>
                <span className="v5-engagements-mode-row-name">{m.name}</span>
                <span className="v5-engagements-mode-row-range">{m.range}</span>
                <span className="v5-engagements-mode-row-marker" aria-hidden="true"></span>
              </button>
            )}
          </div>

          {/* Dynamic detail panel — transitions when active mode changes */}
          <div key={activeMode.name} className="v5-engagements-detail">
            <div className="v5-engagements-detail-head">
              <span className="v5-engagements-detail-n">Mode {String(active + 1).padStart(2, "0")} of 0{MODES.length}</span>
              <span className="v5-engagements-detail-zones">
                Covers stages {String(minZone + 1).padStart(2, "0")}–{String(maxZone + 1).padStart(2, "0")}
              </span>
            </div>
            <div className="v5-engagements-detail-body">
              <h3 className="v5-engagements-detail-name">{activeMode.name}</h3>
              <p className="v5-engagements-detail-body-copy">{activeMode.body}</p>
              <p className="v5-engagements-detail-fit">
                <span className="v5-engagements-detail-fit-label">Best when</span>
                <span className="emph">{activeMode.fit.replace(/^Best when\s*/, "")}</span>
              </p>
              <Magnetic strength={14}>
                <a href={activeMode.href} className="v5-engagements-detail-cta" data-cursor={activeMode.cursor}>
                  <span>Talk about {/^(a|e|i|o|u)/i.test(activeMode.name) ? "an" : "a"} {activeMode.name.toLowerCase()}</span>
                  <span className="v5-engagements-detail-cta-arr">→</span>
                </a>
              </Magnetic>
            </div>
          </div>
        </div>
      </div>
    </section>);

};

// ESCHER MARK — three interlocked Borromean rings. Each pair overlaps with an
// alternating over/under weave (A>B, B>C, C>A) so no ring sits consistently in front;
// the eye keeps trying to resolve the stacking order. Minimal at rest, hover starts a
// slow rotation and a soft diffused halo, click twirls 540° flipping the weave parity.
const EscherMark = () => {
  const [twirl, setTwirl] = React.useState(0);
  return (
    <button
      type="button"
      className="cz-mark"
      onClick={() => setTwirl((t) => t + 1)}
      aria-label="Three interlocked rings — click to bend them"
      data-cursor="Click to bend reality">
      
      <span className="cz-mark-twirl" style={{ transform: `rotate(${twirl * 540}deg)` }}>
        <svg className="cz-mark-svg" viewBox="0 0 40 40" aria-hidden="true">
          {/* Crossing chips (bg-colored) + clipped re-draws are how the weave is forged.
               Geometry: equilateral arrangement, centers at
               A(20,16) — top,  B(16.10, 22.75) — bottom-left,  C(23.90, 22.75) — bottom-right
               radius 7. Crossings calculated and chips centered on each. */}
          <defs>
            <clipPath id="czr-ab1"><rect x="21.59" y="20.78" width="3" height="3" /></clipPath>
            <clipPath id="czr-ab2"><rect x="11.51" y="14.97" width="3" height="3" /></clipPath>
            <clipPath id="czr-bc1"><rect x="18.5" y="27.06" width="3" height="3" /></clipPath>
            <clipPath id="czr-bc2"><rect x="18.5" y="15.44" width="3" height="3" /></clipPath>
          </defs>
          {/* Base rings — default stacking: C on top, then B, then A on bottom */}
          <circle cx="20" cy="16" r="7" className="cz-ring cz-ring-a" />
          <circle cx="16.10" cy="22.75" r="7" className="cz-ring cz-ring-b" />
          <circle cx="23.90" cy="22.75" r="7" className="cz-ring cz-ring-c" />
          {/* Make A win over B at both A-B crossings (flips B's default dominance) */}
          <rect x="21.59" y="20.78" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-ab1)"><circle cx="20" cy="16" r="7" className="cz-ring cz-ring-a" /></g>
          <rect x="11.51" y="14.97" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-ab2)"><circle cx="20" cy="16" r="7" className="cz-ring cz-ring-a" /></g>
          {/* Make B win over C at both B-C crossings */}
          <rect x="18.5" y="27.06" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-bc1)"><circle cx="16.10" cy="22.75" r="7" className="cz-ring cz-ring-b" /></g>
          <rect x="18.5" y="15.44" width="3" height="3" className="cz-chip" />
          <g clipPath="url(#czr-bc2)"><circle cx="16.10" cy="22.75" r="7" className="cz-ring cz-ring-b" /></g>
        </svg>
      </span>
    </button>);

};

// SUBSTANTIAL FOOTER — colophon-style closing surface
const V5Footer = () => {
  const year = new Date().getFullYear();
  const today = new Date().toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }).toUpperCase();
  return (
    <footer className="v5-footer">
      {/* Spine line — the practice's tagline, full bleed */}
      <div className="v5-footer-spine">
        <div className="v4-container">
          <FadeIn as="div" className="v5-footer-spine-inner">
            <span className="v5-footer-spine-mark">— Colophon</span>
            <span className="wire-underline always v5-footer-spine-wrap" data-cursor="The spine of the practice">
              <SplitText text="Making new categories make sense." className="v5-footer-spine-text" />
            </span>
            <span className="v5-footer-spine-meta">Ed. 05 · {today}</span>
          </FadeIn>
        </div>
      </div>

      <div className="v4-container">
        <div className="v5-footer-grid">
          {/* Identity column */}
          <div className="v5-footer-col v5-footer-col-id">
            <div className="v5-footer-mark" data-cursor="Chris Znerold · Boulder">
              <EscherMark />
              <div>
                <span className="v5-footer-mark-name" style={{ fontWeight: "600" }}>Chris Znerold</span>
                <span className="v5-footer-mark-sub">Independent Design Practice</span>
              </div>
            </div>
            <p className="v5-footer-blurb">
              Design director, author, educator, and AI-native creative strategist. I help unfamiliar ideas become products, brands, and systems people understand, trust, and use.
            </p>
            <div className="v5-footer-pins">
              <div className="v5-footer-pin">
                <span className="v5-footer-pin-label">Studio</span>
                <span className="v5-footer-pin-val">Portal · est. 2013</span>
              </div>
              <div className="v5-footer-pin">
                <span className="v5-footer-pin-label">Faculty</span>
                <span className="v5-footer-pin-val">CU Boulder · 2017–now</span>
              </div>
              <div className="v5-footer-pin">
                <span className="v5-footer-pin-label">Location</span>
                <span className="v5-footer-pin-val">Boulder, Colorado</span>
              </div>
              <div className="v5-footer-pin">
                <span className="v5-footer-pin-label">Engage</span>
                <span className="v5-footer-pin-val">Consulting · Advisory · Teaching · Leadership</span>
              </div>
            </div>
            <div className="v5-footer-subnav" style={{ display: "none" }}></div>
          </div>

          {/* Showcase column — single featured project, by artifact */}
          <div className="v5-footer-col v5-footer-col-showcase">
            <span className="v5-footer-col-label">— In focus</span>
            <a href="showcase.html" className="v5-footer-feature" data-cursor="Open the full Outdoorsy case study" data-cursor-style="cta">
              <span className="v5-footer-feature-meta">
                <span className="v5-footer-feature-n">F/01</span>
                <span className="v5-footer-feature-year">2022–24</span>
              </span>
              <span className="v5-footer-feature-name">Outdoorsy</span>
              <span className="v5-footer-feature-note">Host platform · brand · cross-platform design system</span>
              <span className="v5-footer-feature-cta">
                <span>Open case study</span>
                <span className="v5-footer-feature-arr">→</span>
              </span>
            </a>
          </div>

          {/* Talk to me column — full contact details */}
          <div className="v5-footer-col v5-footer-col-contact">
            <span className="v5-footer-col-label">— Contact</span>
            <ul className="v5-footer-contact-list">
              <li>
                <span className="v5-footer-contact-key">Email</span>
                <Magnetic strength={8}>
                  <a href="mailto:znerold@gmail.com" data-cursor="Open in your mail client" className="v5-footer-contact-val">znerold@gmail.com</a>
                </Magnetic>
              </li>
              <li>
                <span className="v5-footer-contact-key">LinkedIn</span>
                <Magnetic strength={8}>
                  <a href="https://www.linkedin.com/in/znerold" target="_blank" rel="noopener" data-cursor="Open profile" className="v5-footer-contact-val">in/znerold</a>
                </Magnetic>
              </li>
              <li>
                <span className="v5-footer-contact-key">Studio</span>
                <a className="v5-footer-contact-val" href="https://portaldesign.com/" target="_blank" rel="noopener" data-cursor="Portal · studio" data-cursor-style="cta">portaldesign.com</a>
              </li>
              <li>
                <span className="v5-footer-contact-key">Faculty</span>
                <a className="v5-footer-contact-val" href="https://www.colorado.edu/thebrandstudios/thefaculty" target="_blank" rel="noopener" data-cursor="CU Boulder · The Brand Studios" data-cursor-style="cta">CU Boulder · 2017–now</a>
              </li>
              <li>
                <span className="v5-footer-contact-key">Located</span>
                <a className="v5-footer-contact-val" href="https://www.dropbox.com/scl/fi/xtj1zu6pg8xi9m9ta3yf8/The-Bill-Bowen-House-Sunshine-Canyon-Colorado.pdf?rlkey=6v7zjmwu825a84pr4q1gmqg6o&st=2yaenyb8&dl=0" target="_blank" rel="noopener" data-cursor="The Bill Bowen House · Sunshine Canyon" data-cursor-style="cta">Boulder, Colorado · MST</a>
              </li>
            </ul>
            <Magnetic strength={10}>
              <a href="#engagements" className="v5-footer-cta" data-cursor="2026 · taking introductions">
                <span className="v5-footer-cta-dot"></span>
                Available · 2026
                <span className="v5-footer-cta-arr">→</span>
              </a>
            </Magnetic>
          </div>
        </div>

        {/* Bottom ribbon */}
        <div className="v5-footer-ribbon">
          <div className="v5-footer-ribbon-left">
            <span>© {year} · Chris Znerold</span>
            <span className="v5-footer-ribbon-dot">·</span>
            <span>Independent design practice</span>
            <span className="v5-footer-ribbon-dot">·</span>
            <span>Boulder, Colorado</span>
          </div>
          <div className="v5-footer-ribbon-right">
            <span><a href="https://portaldesign.com/" target="_blank" rel="noopener" data-cursor="Portal · studio" data-cursor-style="nav">Portal is the studio layer.</a></span>
            <span className="v5-footer-ribbon-dot">·</span>
            <span><a href="https://www.colorado.edu/thebrandstudios" target="_blank" rel="noopener" data-cursor="CU Boulder · The Brand Studios" data-cursor-style="nav">Teaching is the method layer.</a></span>
            <span className="v5-footer-ribbon-dot">·</span>
            <span><span className="emph">The work makes new categories make sense.</span></span>
          </div>
        </div>
      </div>
    </footer>);

};

// APP entry — IA reorganized into 3 groups: Work · Method · About
const V5App = () => {
  useEffect(() => {
    const handler = (ev) => {
      const link = ev.target.closest("a[href^='#']");
      if (!link) return;
      const href = link.getAttribute("href");
      if (href === "#" || href.length < 2) return;
      const el = document.querySelector(href);
      if (!el) return;
      ev.preventDefault();
      window.scrollTo({ top: el.offsetTop - 60, behavior: "smooth" });
    };
    document.addEventListener("click", handler);
    return () => document.removeEventListener("click", handler);
  }, []);

  return (
    <div className="v4-page v5-page">
      <ScrollProgress />
      <CursorCompanion />
      <V5Nav />
      <V5Hero />

      {/* === SHOWCASE === single featured case study replaces the multi-card recent work */}
      <V5Featured />
      <V5Signals />

      {/* === METHOD === starter is baked into V5Method */}
      <V5Method />

      {/* === AI FLUENCY === its own section */}
      <V5AIFluency />

      {/* === ABOUT === facet wheel introduces Chris (consolidated, no separate opener) */}
      <V5Facet />

      {/* === ENGAGEMENTS === ways to work together — orbital roadmap */}
      <V5Engagements />

      <V5Footer />
    </div>);

};

ReactDOM.createRoot(document.getElementById("root")).render(<V5App />);