/* ============================================================
   nomi — Testing tab.
   A recorded, auto-playing reel that recreates the live nomi A/B
   research study (vivignette-ui/nomi-research) screen by screen:
   draft directly vs. through a social character, then compare.
   Faithful to nomi's real dark-glass UI. "Open the study" still
   launches the live site in a new tab.
   Registers into window.CASE_PANELS["nomi"].Testing.
   ============================================================ */
(function () {
  const { useState, useEffect, useRef } = React;
  const LIVE = "https://nomi-research-ab.vercel.app/";

  /* nomi's own palette (from the real prototype) */
  const N = {
    accent: "#526C90", accent2: "#7a9cbd", green: "#5caa88",
    soft: "rgba(82,108,144,0.16)", soft2: "rgba(82,108,144,0.08)", border: "rgba(122,156,189,0.28)",
    greenSoft: "rgba(92,170,136,0.12)", greenBorder: "rgba(92,170,136,0.30)",
    t1: "#eeeef2", t2: "#b8b8c8", t3: "#7e7e90",
    bg2: "#17171b", bg3: "#1f1f25", bg4: "#272730",
    b1: "rgba(255,255,255,0.07)", b2: "rgba(255,255,255,0.11)",
    card: "rgba(28,28,36,0.72)",
    page: "radial-gradient(ellipse at 30% 20%, #141c2a 0%, #0a0a0e 60%)",
  };

  /* the scripted run — Kyoto theme, matching the cover */
  const PLATFORM = "Instagram";
  const TASK = "My slow morning in Kyoto. Matcha by the window, then the first cherry blossoms on the walk to the temple. Honest and unhurried, more personal than aspirational.";
  const MODE = "Soft intimate storyteller";
  const SELF = "Warm but not sentimental. Real, a little quiet, never performative.";
  const VIBE = "Cozy";

  const DRAFTS_A = [
    { title: "Aspirational caption", tone: "Generic, Polished", body: "Kyoto mornings ✨ matcha, cherry blossoms, and a walk to the temple. Living my best life 🌸 #kyoto #japan #travel #wanderlust" },
    { title: "Listicle hook", tone: "Generic, Punchy", body: "The perfect Kyoto morning: 1. Fresh matcha 2. Cherry blossoms 3. An ancient temple. Save this for your next trip!" },
    { title: "Travel-brand voice", tone: "Generic, Bright", body: "There is nothing like a Kyoto morning. Matcha by the window and sakura on every street. Wanderlust, activated. 🍵" },
  ];
  const DRAFTS_B = [
    { title: "Soft reflection", tone: "Reflective, Intimate", body: "Woke up slow in Kyoto. Made matcha and watched the street wake up before I did. By the time I walked to the temple the first blossoms had opened, and I did not take many photos. I just wanted to remember how quiet it felt." },
    { title: "Quiet detail", tone: "Personal, Tender", body: "The blossoms were not really the moment. The moment was the matcha going cold while I forgot to drink it, because the street outside was finally waking up too." },
    { title: "Unhurried note", tone: "Calm, Honest", body: "Kyoto has a rhythm you can fall into. Matcha by the window, a slow walk, the first cherry blossoms on the way to the temple. Some mornings do not need a plan." },
  ];

  /* phase script. typing phases self-advance via onDone. */
  const PH = [
    { s: "s1", seg: 0, cap: "Pick a platform and a post idea", dwell: 1100 },
    { s: "s1", seg: 0, cap: "Describe the post", act: "typeTask", dwell: 0 },
    { s: "s1", seg: 0, cap: "Start the study", act: "startBtn", dwell: 1100 },
    { s: "s2", seg: 1, cap: "First, generate directly", act: "genA", dwell: 1500 },
    { s: "s2", seg: 1, cap: "Drafts from the prompt alone", act: "showA", dwell: 1500 },
    { s: "s2", seg: 1, cap: "Choose the one you'd post", act: "pickA", dwell: 1400 },
    { s: "s2", seg: 1, cap: "Rate it — generic, needs editing", act: "rateA", dwell: 1700 },
    { s: "s3", seg: 2, cap: "Now shape a social character", act: "mode", dwell: 1300 },
    { s: "s3", seg: 2, cap: "How do you want to come across?", act: "typeSelf", dwell: 0 },
    { s: "s3", seg: 2, cap: "Add a vibe, tune the sliders", act: "vibe", dwell: 1300 },
    { s: "s3", seg: 2, cap: "Generate through the character", act: "genB", dwell: 1400 },
    { s: "s4", seg: 3, cap: "Character-shaped drafts", act: "showB", dwell: 1500 },
    { s: "s4", seg: 3, cap: "Choose the one you'd post", act: "pickB", dwell: 1400 },
    { s: "s4", seg: 3, cap: "Rate it — closer to me", act: "rateB", dwell: 1700 },
    { s: "s5", seg: 4, cap: "Compare both versions", act: "compare", dwell: 2400 },
    { s: "s7", seg: 6, cap: "What comes next: Nyla", dwell: 2600 },
  ];

  function NomiReel() {
    const [p, setP] = useState(0);
    const [playing, setPlaying] = useState(true);
    const [done, setDone] = useState(false);
    const [tick, setTick] = useState(0);
    const reduced = window.usePrefersReducedMotion ? window.usePrefersReducedMotion() : false;
    const ph = PH[p];
    const order = ["s1", "s2", "s3", "s4", "s5", "s6", "s7"];
    const at = order.indexOf(done ? "s7" : ph.s);
    const reached = function (id) { return at >= order.indexOf(id); };

    function reachedAct(idx, act) {
      for (let i = idx; i >= 0; i--) { if (PH[i].act === act) return true; if (PH[i].s !== PH[idx].s) break; }
      return false;
    }
    function phaseDur(i) {
      const x = PH[i];
      if (x.act === "typeTask") return TASK.length * 22 + 800;
      if (x.act === "typeSelf") return SELF.length * 26 + 800;
      return x.dwell;
    }

    // single advancement timer (also drives pause/resume)
    useEffect(function () {
      if (!playing || done) return;
      const dur = reduced ? Math.min(phaseDur(p), 700) : phaseDur(p);
      const id = setTimeout(function () {
        setP(function (x) { if (x < PH.length - 1) return x + 1; setDone(true); return x; });
      }, dur);
      return function () { clearTimeout(id); };
    }, [p, playing, done, reduced]);

    // typing ticker — runs only on typing phases, restarts each phase
    useEffect(function () {
      setTick(0);
      if (!playing || done) return;
      if (ph.act !== "typeTask" && ph.act !== "typeSelf") return;
      const id = setInterval(function () { setTick(function (t) { return t + 1; }); }, reduced ? 5 : 22);
      return function () { clearInterval(id); };
    }, [p, playing, done, reduced]);

    // derived display state
    const screen = done ? "s7" : ph.s;
    const typedTask = ph.act === "typeTask" ? TASK.slice(0, tick) : "";
    const typedSelf = ph.act === "typeSelf" ? SELF.slice(0, tick) : "";
    const taskVal = reached("s2") ? TASK : (screen === "s1" ? typedTask : "");
    const platformVal = PLATFORM;
    const selfVal = reached("s4") ? SELF : (screen === "s3" ? typedSelf : "");
    const modeOn = (screen === "s3" && reachedAct(p, "mode")) || reached("s4");
    const vibeOn = (screen === "s3" && reachedAct(p, "vibe")) || reached("s4");
    const genningA = ph.act === "genA";
    const draftsAShown = (screen === "s2" && reachedAct(p, "showA")) || reached("s3");
    const pickedA = (screen === "s2" && reachedAct(p, "pickA")) || reached("s3");
    const ratedA = (screen === "s2" && reachedAct(p, "rateA")) || reached("s3");
    const genningB = ph.act === "genB";
    const draftsBShown = (screen === "s4" && reachedAct(p, "showB")) || reached("s5");
    const pickedB = (screen === "s4" && reachedAct(p, "pickB")) || reached("s5");
    const ratedB = (screen === "s4" && reachedAct(p, "rateB")) || reached("s5");
    const compared = reached("s5");

    function restart() { setP(0); setDone(false); setTick(0); setPlaying(true); }
    const seg = done ? 6 : ph.seg;

    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 28 }}>
        <p className="pf-lead" style={{ margin: 0, maxWidth: 820 }}>
          <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>Round one</strong> was the broad A/B study:
          draft a post directly, then draft it again through a social character, and compare. The reel plays the real
          flow, typing and all. You can also open the live study.
        </p>

        <div className="pf-glass pf-glass--thick" style={{ padding: "clamp(16px, 1.8vw, 28px)" }}>
          <div style={{ position: "relative", borderRadius: 20, overflow: "hidden", background: N.page, border: "1px solid rgba(255,255,255,0.09)", fontFamily: "Inter, -apple-system, sans-serif" }}>
            {/* caption chip */}
            <div style={{ position: "absolute", top: 16, left: 16, zIndex: 5, display: "inline-flex", alignItems: "center", gap: 8, padding: "7px 14px", borderRadius: 999, background: "rgba(10,12,18,0.6)", border: "1px solid rgba(255,255,255,0.12)", color: N.t2, fontSize: 11, fontWeight: 500, letterSpacing: "0.06em", textTransform: "uppercase", backdropFilter: "blur(8px)", WebkitBackdropFilter: "blur(8px)" }}>
              <span style={{ width: 7, height: 7, borderRadius: "50%", background: done ? N.green : N.accent2 }} />
              {done ? "Run complete" : ph.cap}
            </div>

            <div style={{ padding: "clamp(40px,5vw,60px) clamp(20px,4vw,52px)", display: "flex", flexDirection: "column", alignItems: "center" }}>
              <div style={{ width: "100%", maxWidth: 600, display: "flex", alignItems: "center" }}>
                <span style={{ fontSize: 15, fontWeight: 600, letterSpacing: "-0.03em", color: N.t1 }}>nomi</span>
              </div>
              {/* progress */}
              <div style={{ width: "100%", maxWidth: 600, marginTop: 18, display: "flex", gap: 6 }}>
                {[0,1,2,3,4,5,6].map(function (i) {
                  return <div key={i} style={{ flex: 1, height: 2, borderRadius: 100, background: i <= seg ? N.accent2 : N.b1, transition: "background 0.4s" }} />;
                })}
              </div>

              {/* card */}
              <div key={screen} style={{ width: "100%", maxWidth: 600, marginTop: 20, background: N.card, border: "1px solid rgba(255,255,255,0.09)", borderRadius: 16, padding: "clamp(24px,3vw,40px)", boxShadow: "0 8px 40px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06)", animation: reduced ? "none" : "nomiFade 0.4s ease both" }}>

                {screen === "s1" && (
                  <div>
                    <div style={ov(N)}>NOMI</div>
                    <div style={disp(N)}>Draft a post for any social media</div>
                    <p style={{ ...body(N), color: N.t1, marginBottom: 24, maxWidth: 480 }}>You'll generate a post draft in two ways: directly, and through a social character. Then you'll evaluate your experiences.</p>
                    <Lbl N={N}>Where will this post live? <Req N={N} /></Lbl>
                    <div style={{ ...field(N), display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 18 }}>
                      <span style={{ color: N.t1 }}>{platformVal}</span>
                      <Chevron />
                    </div>
                    <Lbl N={N}>What do you want to post about? <Req N={N} /></Lbl>
                    <div style={{ ...field(N), minHeight: 96 }}>
                      <span style={{ color: taskVal ? N.t1 : N.t3 }}>{taskVal || "Describe your idea and any context."}</span>
                      {ph.act === "typeTask" && !done && <Caret />}
                    </div>
                    <div style={{ marginTop: 24 }}><Btn N={N} pressed={ph.act === "startBtn"}>Start</Btn></div>
                  </div>
                )}

                {screen === "s2" && (
                  <div>
                    <BackRow N={N} />
                    <div style={h2(N)}>Direct generation</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>Drafts generated from your description alone, with no identity context.</p>
                    {!draftsAShown ? (
                      <Btn N={N} loading={genningA}>{genningA ? "Generating…" : "Generate directly"}</Btn>
                    ) : (
                      <div>
                        <div style={sec(N)}>Choose the draft you'd most likely post <Req N={N} /></div>
                        <DraftList N={N} drafts={DRAFTS_A} sel={pickedA ? 0 : -1} />
                        {ratedA && <RateBlock N={N} q1="How much editing would your chosen draft need?" v1={4} q2="How well does this match how you want to show up?" v2={2} />}
                        {ratedA && <div style={{ marginTop: 22 }}><Btn N={N}>Now try with a character ›</Btn></div>}
                      </div>
                    )}
                  </div>
                )}

                {screen === "s3" && (
                  <div>
                    <BackRow N={N} />
                    <div style={h2(N)}>Create a social character of you</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>What is your social character behind this post?</p>
                    <div style={sec(N)}>Starting mode <Req N={N} /></div>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10, marginBottom: 22 }}>
                      {[["Thoughtful diarist","Reflective, honest, slow-burn"],[ "Polished lifestyle sharer","Curated, aesthetic, aspirational"],[MODE,"Warm, personal, tender"],["Trend-aware curator","Current, cultural, in-the-know"],["Smart playful explainer","Clear, witty, entertaining"]].map(function (m) {
                        const sel = m[0] === MODE && modeOn;
                        return (
                          <div key={m[0]} style={modeCard(N, sel)}>
                            <div style={{ fontSize: 14, fontWeight: 500, color: N.t1 }}>{m[0]}</div>
                            <div style={{ fontSize: 12, color: N.t3, marginTop: 3 }}>{m[1]}</div>
                          </div>
                        );
                      })}
                    </div>
                    <div style={sec(N)}>Adjust identity controls</div>
                    <div style={{ marginBottom: 22 }}>
                      <Slider N={N} l="Soft" r="Sharp" pct={38} />
                      <Slider N={N} l="Personal" r="Polished" pct={35} />
                      <Slider N={N} l="Calm" r="Expressive" pct={42} />
                    </div>
                    <Lbl N={N}>How do you want to come across? <Req N={N} /></Lbl>
                    <div style={{ ...field(N), minHeight: 54 }}>
                      <span style={{ color: selfVal ? N.t1 : N.t3 }}>{selfVal || "e.g. Warm but not sentimental. Real, not polished."}</span>
                      {ph.act === "typeSelf" && !done && <Caret />}
                    </div>
                    <div style={{ ...sec(N), marginTop: 22 }}>Vibe</div>
                    <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                      {["Clean", VIBE, "Dreamy", "Refined", "Playful"].map(function (v) { return <span key={v} style={chip(N, v === VIBE && vibeOn)}>{v}</span>; })}
                    </div>
                    <div style={{ marginTop: 26 }}><Btn N={N} loading={genningB}>{genningB ? "Generating…" : "Generate through this character"}</Btn></div>
                  </div>
                )}

                {screen === "s4" && (
                  <div>
                    <BackRow N={N} />
                    <div style={h2(N)}>Character-shaped drafts</div>
                    <p style={{ ...body(N), marginBottom: 20 }}>Drafts generated through your description and your chosen character.</p>
                    <div style={sec(N)}>Choose the draft you'd most likely post <Req N={N} /></div>
                    <DraftList N={N} drafts={DRAFTS_B} sel={pickedB ? 0 : -1} />
                    {ratedB && <RateBlock N={N} q1="How much editing would your chosen draft need?" v1={2} q2="How well does this match the version of you you intended?" v2={5} />}
                    {ratedB && <div style={{ marginTop: 22 }}><Btn N={N}>Compare both versions ›</Btn></div>}
                  </div>
                )}

                {screen === "s5" && (
                  <div>
                    <BackRow N={N} />
                    <div style={ov(N)}>Comparison</div>
                    <div style={{ ...h2(N), fontSize: 22 }}>Which version worked better?</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>Your chosen draft from each version.</p>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14, marginBottom: 24 }}>
                      <div style={{ background: N.bg3, border: "1px solid " + N.b2, borderRadius: 16, padding: 20 }}>
                        <div style={{ ...sec(N), marginBottom: 8 }}>Direct</div>
                        <div style={{ fontSize: 12.5, fontWeight: 300, color: N.t1, lineHeight: 1.7 }}>{DRAFTS_A[0].body}</div>
                      </div>
                      <div style={{ background: N.soft2, border: "1px solid " + N.border, borderRadius: 16, padding: 20 }}>
                        <div style={{ ...sec(N), marginBottom: 8 }}>Through a character</div>
                        <div style={{ fontSize: 12.5, fontWeight: 300, color: N.t1, lineHeight: 1.7 }}>{DRAFTS_B[0].body}</div>
                      </div>
                    </div>
                    <div style={sec(N)}>Forced-choice comparison</div>
                    {[["Which better matches the you you wanted to express?","Social character"],["Which would you be more likely to post?","Social character"],["Which would need less editing?","Social character"]].map(function (q, i) {
                      return (
                        <div key={i} style={{ marginBottom: 16 }}>
                          <div style={{ fontSize: 13.5, fontWeight: 500, color: N.t1, marginBottom: 9 }}>{i + 1}. {q[0]}</div>
                          <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                            {["Direct", "Social character", "Equal"].map(function (o) { return <span key={o} style={fcBtn(N, compared && o === q[1])}>{o}</span>; })}
                          </div>
                        </div>
                      );
                    })}
                  </div>
                )}

                {screen === "s7" && (
                  <div>
                    <div style={ov(N)}>What comes next</div>
                    <div style={{ ...h2(N), marginBottom: 20 }}>One more concept to react to</div>
                    <div style={{ background: N.bg2, border: "1px solid " + N.b2, borderRadius: 16, padding: "clamp(24px,3vw,36px)" }}>
                      <div style={{ fontSize: 22, fontWeight: 600, letterSpacing: "-0.04em", color: N.t1, marginBottom: 8 }}>Nyla</div>
                      <p style={{ fontSize: 13.5, fontWeight: 300, color: N.t2, lineHeight: 1.65, marginBottom: 20, maxWidth: 440 }}>
                        Nyla helps you shape and manage different social characters over time: one per platform, one per context, all in one place.
                      </p>
                      <div style={{ ...field(N), color: N.t3, marginBottom: 10 }}>your@email.com</div>
                      <Btn N={N} full>Join the waitlist</Btn>
                    </div>
                  </div>
                )}

              </div>
            </div>
          </div>

          {/* transport controls */}
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", flexWrap: "wrap", gap: 16, marginTop: 18 }}>
            <div style={{ display: "flex", gap: 10 }}>
              <button onClick={function () { setPlaying(!playing); }} className="pf-btn gv-lift" aria-label={playing ? "Pause" : "Play"}>
                <i data-lucide={playing ? "pause" : "play"} style={{ width: 16, height: 16, opacity: 0.85 }} />
                {playing ? "Pause" : "Play"}
              </button>
              <button onClick={restart} className="pf-btn gv-lift" aria-label="Restart">
                <i data-lucide="rotate-ccw" style={{ width: 16, height: 16, opacity: 0.85 }} />
                Restart
              </button>
            </div>
            <a href={LIVE} target="_blank" rel="noopener noreferrer" className="pf-btn pf-btn--primary gv-lift">
              Open the study
              <i data-lucide="arrow-up-right" style={{ width: 16, height: 16, opacity: 0.8 }} />
            </a>
          </div>
        </div>

        {/* the prompt, written out */}
        <div className="pf-glass" style={{ padding: "clamp(24px,2.4vw,36px)" }}>
          <div className="pf-eyebrow" style={{ marginBottom: 14, color: "var(--accent)" }}>The post used in this run</div>
          <p className="pf-h3" style={{ margin: 0, fontSize: "clamp(18px,1.8vw,24px)", fontWeight: 300 }}>“{TASK}”</p>
          <p className="pf-body" style={{ margin: "16px 0 0" }}>
            Platform <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>{PLATFORM}</strong>, social character <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>{MODE}</strong>, vibe <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>{VIBE}</strong>. The character-shaped draft read truer to voice and needed far less editing.
          </p>
        </div>
      </div>
    );
  }

  /* ---- small recreated UI bits ---- */
  function Caret() { return <span className="nomi-caret" style={{ display: "inline-block", width: 2, height: "1.05em", background: "#7a9cbd", marginLeft: 2, transform: "translateY(2px)" }} />; }
  function Req(props) { return <span style={{ color: props.N.accent2 }}>*</span>; }
  function Chevron() { return <i data-lucide="chevron-down" style={{ width: 14, height: 14, color: "#7e7e90" }} />; }
  function Lbl(props) { return <div style={{ fontSize: 13, fontWeight: 500, color: props.N.t1, marginBottom: 7 }}>{props.children}</div>; }
  function BackRow(props) {
    return <div style={{ display: "inline-flex", alignItems: "center", gap: 6, fontSize: 13, fontWeight: 500, color: props.N.t2, background: props.N.bg3, border: "1px solid " + props.N.b2, borderRadius: 100, padding: "7px 14px", marginBottom: 22 }}><i data-lucide="chevron-left" style={{ width: 14, height: 14 }} />Back</div>;
  }
  function Btn(props) {
    const N = props.N;
    return <span style={{ display: "inline-flex", alignItems: "center", justifyContent: props.full ? "center" : "flex-start", gap: 7, fontWeight: 500, fontSize: 14, padding: "11px 24px", borderRadius: 100, background: props.loading ? N.accent2 : N.accent, color: "#fff", width: props.full ? "100%" : "auto", transform: props.pressed ? "scale(0.97)" : "none", transition: "transform 0.18s", boxShadow: "0 1px 10px rgba(0,0,0,0.25)" }}>{props.children}</span>;
  }
  function DraftList(props) {
    const N = props.N;
    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 10 }}>
        {props.drafts.map(function (d, i) {
          const sel = i === props.sel;
          return (
            <div key={i} style={{ position: "relative", background: sel ? N.soft : "rgba(255,255,255,0.04)", border: "1px solid " + (sel ? N.border : "rgba(255,255,255,0.09)"), borderRadius: 16, padding: "18px 20px", transition: "all 0.3s" }}>
              <div style={{ position: "absolute", top: 18, right: 18, width: 18, height: 18, borderRadius: "50%", border: "1.5px solid " + (sel ? N.accent : N.b2), background: sel ? N.accent : N.bg4, display: "flex", alignItems: "center", justifyContent: "center" }}>{sel && <span style={{ width: 7, height: 7, borderRadius: "50%", background: "#fff" }} />}</div>
              <div style={{ fontSize: 14, fontWeight: 500, color: N.t1, marginBottom: 5, paddingRight: 28 }}>{d.title}</div>
              <div style={{ fontSize: 12.5, fontWeight: 300, color: N.t2, lineHeight: 1.65, marginBottom: 12 }}>{d.body}</div>
              <span style={{ display: "inline-block", fontSize: 10, fontWeight: 500, letterSpacing: "0.04em", textTransform: "uppercase", color: N.accent2, background: N.soft, border: "1px solid " + N.border, borderRadius: 100, padding: "3px 10px" }}>{d.tone}</span>
            </div>
          );
        })}
      </div>
    );
  }
  function RateScale(props) {
    const N = props.N;
    return (
      <div style={{ marginBottom: 18 }}>
        <div style={{ fontSize: 13, fontWeight: 500, color: N.t1, marginBottom: 10, lineHeight: 1.5 }}>{props.q} <Req N={N} /></div>
        <div style={{ display: "flex", gap: 6 }}>
          {[1,2,3,4,5].map(function (n) {
            const on = n === props.v;
            return <span key={n} style={{ width: 42, height: 42, borderRadius: 8, border: "1px solid " + (on ? N.accent : N.b2), background: on ? N.accent : N.bg3, color: on ? "#fff" : N.t3, fontSize: 13, fontWeight: 500, display: "flex", alignItems: "center", justifyContent: "center" }}>{n}</span>;
          })}
        </div>
      </div>
    );
  }
  function RateBlock(props) {
    const N = props.N;
    return (
      <div>
        <div style={{ height: 1, background: "rgba(255,255,255,0.07)", margin: "24px 0" }} />
        <div style={sec(N)}>Rate this version</div>
        <RateScale N={N} q={props.q1} v={props.v1} />
        <RateScale N={N} q={props.q2} v={props.v2} />
      </div>
    );
  }
  function Slider(props) {
    const N = props.N;
    return (
      <div style={{ display: "grid", gridTemplateColumns: "68px 1fr 68px", alignItems: "center", gap: 12, marginBottom: 12 }}>
        <span style={{ fontSize: 12, fontWeight: 500, color: N.t2 }}>{props.l}</span>
        <div style={{ position: "relative", height: 5, borderRadius: 100, background: "linear-gradient(to right, " + N.accent2 + " " + props.pct + "%, rgba(255,255,255,0.18) " + props.pct + "%)" }}>
          <span style={{ position: "absolute", top: "50%", left: props.pct + "%", transform: "translate(-50%,-50%)", width: 17, height: 17, borderRadius: "50%", background: N.bg2, border: "2px solid " + N.accent2 }} />
        </div>
        <span style={{ fontSize: 12, fontWeight: 500, color: N.t2, textAlign: "right" }}>{props.r}</span>
      </div>
    );
  }
  function ov(N) { return { fontSize: 11, fontWeight: 500, letterSpacing: "0.07em", textTransform: "uppercase", color: N.t3, marginBottom: 10 }; }
  function disp(N) { return { fontSize: 27, fontWeight: 500, letterSpacing: "-0.035em", lineHeight: 1.18, color: N.t1, marginBottom: 10 }; }
  function h2(N) { return { fontSize: 20, fontWeight: 500, letterSpacing: "-0.03em", color: N.t1, marginBottom: 6 }; }
  function body(N) { return { fontSize: 14, fontWeight: 300, color: N.t2, lineHeight: 1.65 }; }
  function sec(N) { return { fontSize: 11, fontWeight: 500, letterSpacing: "0.07em", textTransform: "uppercase", color: N.t3, marginBottom: 14 }; }
  function field(N) { return { fontSize: 13.5, fontWeight: 300, color: N.t1, background: "rgba(255,255,255,0.05)", border: "1px solid rgba(255,255,255,0.11)", borderRadius: 8, padding: "11px 14px", lineHeight: 1.6 }; }
  function modeCard(N, sel) { return { background: sel ? N.soft : "rgba(255,255,255,0.04)", border: "1px solid " + (sel ? N.border : "rgba(255,255,255,0.09)"), borderRadius: 12, padding: "14px 16px", transition: "all 0.25s" }; }
  function chip(N, on) { return { fontSize: 12, fontWeight: 500, padding: "5px 14px", borderRadius: 100, border: "1px solid " + (on ? N.border : N.b2), background: on ? N.soft : N.bg3, color: on ? N.accent2 : N.t2, transition: "all 0.25s" }; }
  function fcBtn(N, on) { return { fontSize: 13, fontWeight: 500, padding: "9px 18px", borderRadius: 100, border: "1px solid " + (on ? N.border : N.b2), background: on ? N.soft : N.bg3, color: on ? N.accent2 : N.t2, transition: "all 0.25s" }; }

  /* ===================== ROUND TWO — Instagram-focused refinement ===================== */
  const LIVE2 = "https://nomi-research2.vercel.app/";
  const TASK2 = "A quiet moment from my weekend in Kyoto: matcha by the window, then the first cherry blossoms on the walk to the temple. Warm, personal, a little reflective.";
  const NOTES2 = "Natural, not over-polished. More personal than inspirational.";
  const MODE2 = "Soft personal storyteller";
  const SELF2 = "Warm, real, and thoughtful. A little polished, but still personal.";
  const VIBE2 = "Cozy";
  const A2 = [
    { title: "Weekend recap caption", tone: "Generic, Polished", body: "A perfect Kyoto weekend 🌸 matcha, cherry blossoms, and a temple stroll. Making memories! #kyoto #japantravel #wanderlust #cherryblossom" },
    { title: "Listicle hook", tone: "Generic, Punchy", body: "3 things that made my Kyoto weekend: 🍵 matcha by the window 🌸 the first cherry blossoms ⛩️ a quiet temple walk. Save this for your trip!" },
    { title: "Bright lifestyle voice", tone: "Generic, Bright", body: "Kyoto did not disappoint 🌸 Matcha mornings and blossom-lined streets. Wanderlust fully activated!" },
  ];
  const B2 = [
    { title: "Slow morning", tone: "Reflective, Intimate", body: "Spent Saturday morning not really doing anything. Made matcha, sat by the window, watched the street wake up. On the walk to the temple the first cherry blossoms had just opened. I didn't take many photos. I just wanted to stay in it a while." },
    { title: "Quiet detail", tone: "Personal, Tender", body: "The matcha went cold because I forgot to drink it. The street outside was finally waking up, and the first blossoms had opened on the way to the temple. Some mornings you just want to remember how quiet they felt." },
    { title: "Unhurried note", tone: "Calm, Honest", body: "Kyoto has a rhythm you fall into without noticing. Matcha by the window, a slow walk, the first cherry blossoms before the temple. No plan, and that was the point." },
  ];
  const MODES2 = [
    ["Thoughtful sharer", "Reflective, warm, quietly observant"],
    ["Polished lifestyle voice", "Curated, clear, aesthetically aware"],
    [MODE2, "Personal, gentle, emotionally close"],
    ["Trend-aware curator", "Current, culturally tuned, expressive"],
    ["Smart playful creator", "Clever, light, confident, engaging"],
  ];
  const ACTIONS2 = ["Save this version", "Reuse this version", "Make another version", "Make this more polished", "Make this more playful"];
  const PH2 = [
    { s: "s1", seg: 0, cap: "Enter your Instagram post idea", dwell: 1000 },
    { s: "s1", seg: 0, cap: "Describe the post", act: "typeTask", dwell: 0 },
    { s: "s1", seg: 0, cap: "Add an optional angle", act: "typeNotes", dwell: 0 },
    { s: "s1", seg: 0, cap: "Start", act: "startBtn", dwell: 1000 },
    { s: "s2", seg: 1, cap: "Generate directly", act: "genA", dwell: 1500 },
    { s: "s2", seg: 1, cap: "Captions from the idea alone", act: "showA", dwell: 1400 },
    { s: "s2", seg: 1, cap: "Choose the one you'd post", act: "pickA", dwell: 1300 },
    { s: "s2", seg: 1, cap: "Rate it — needs editing", act: "rateA", dwell: 1600 },
    { s: "s3", seg: 2, cap: "Shape one version of you", act: "mode", dwell: 1300 },
    { s: "s3", seg: 2, cap: "How should it feel on Instagram?", act: "typeSelf", dwell: 0 },
    { s: "s3", seg: 2, cap: "Add a vibe", act: "vibe", dwell: 1200 },
    { s: "s3", seg: 2, cap: "Generate through this version", act: "genB", dwell: 1400 },
    { s: "s4", seg: 3, cap: "Identity-shaped captions", act: "showB", dwell: 1400 },
    { s: "s4", seg: 3, cap: "Choose the one you'd post", act: "pickB", dwell: 1300 },
    { s: "s4", seg: 3, cap: "Rate it — closer to me", act: "rateB", dwell: 1600 },
    { s: "s5", seg: 4, cap: "Compare both captions", act: "compare", dwell: 2400 },
    { s: "s6", seg: 5, cap: "What you'd do with this version", act: "actions", dwell: 2200 },
    { s: "s7", seg: 6, cap: "React to Nyla", dwell: 2600 },
  ];

  function NomiReel2() {
    const [p, setP] = useState(0);
    const [playing, setPlaying] = useState(true);
    const [done, setDone] = useState(false);
    const [tick, setTick] = useState(0);
    const reduced = window.usePrefersReducedMotion ? window.usePrefersReducedMotion() : false;
    const ph = PH2[p];
    const order = ["s1", "s2", "s3", "s4", "s5", "s6", "s7"];
    const at = order.indexOf(done ? "s7" : ph.s);
    const reached = function (id) { return at >= order.indexOf(id); };
    function reachedAct(idx, act) {
      for (let i = idx; i >= 0; i--) { if (PH2[i].act === act) return true; if (PH2[i].s !== PH2[idx].s) break; }
      return false;
    }
    function phaseDur(i) {
      const x = PH2[i];
      if (x.act === "typeTask") return TASK2.length * 20 + 700;
      if (x.act === "typeNotes") return NOTES2.length * 20 + 600;
      if (x.act === "typeSelf") return SELF2.length * 24 + 700;
      return x.dwell;
    }
    useEffect(function () {
      if (!playing || done) return;
      const dur = reduced ? Math.min(phaseDur(p), 700) : phaseDur(p);
      const id = setTimeout(function () { setP(function (x) { if (x < PH2.length - 1) return x + 1; setDone(true); return x; }); }, dur);
      return function () { clearTimeout(id); };
    }, [p, playing, done, reduced]);
    useEffect(function () {
      setTick(0);
      if (!playing || done) return;
      if (ph.act !== "typeTask" && ph.act !== "typeNotes" && ph.act !== "typeSelf") return;
      const id = setInterval(function () { setTick(function (t) { return t + 1; }); }, reduced ? 5 : 20);
      return function () { clearInterval(id); };
    }, [p, playing, done, reduced]);

    const screen = done ? "s7" : ph.s;
    const taskVal = reached("s2") ? TASK2 : (ph.act === "typeTask" ? TASK2.slice(0, tick) : (reachedAct(p, "typeTask") ? TASK2 : ""));
    const notesVal = reached("s2") ? NOTES2 : (ph.act === "typeNotes" ? NOTES2.slice(0, tick) : (reachedAct(p, "typeNotes") ? NOTES2 : ""));
    const selfVal = reached("s4") ? SELF2 : (screen === "s3" ? (ph.act === "typeSelf" ? SELF2.slice(0, tick) : (reachedAct(p, "typeSelf") ? SELF2 : "")) : "");
    const modeOn = (screen === "s3" && reachedAct(p, "mode")) || reached("s4");
    const vibeOn = (screen === "s3" && reachedAct(p, "vibe")) || reached("s4");
    const genningA = ph.act === "genA";
    const draftsAShown = (screen === "s2" && reachedAct(p, "showA")) || reached("s3");
    const pickedA = (screen === "s2" && reachedAct(p, "pickA")) || reached("s3");
    const ratedA = (screen === "s2" && reachedAct(p, "rateA")) || reached("s3");
    const genningB = ph.act === "genB";
    const pickedB = (screen === "s4" && reachedAct(p, "pickB")) || reached("s5");
    const ratedB = (screen === "s4" && reachedAct(p, "rateB")) || reached("s5");
    const compared = reached("s5");
    const actionsOn = reached("s6") && (ph.act === "actions" || reached("s7"));

    function restart() { setP(0); setDone(false); setTick(0); setPlaying(true); }
    const seg = done ? 6 : ph.seg;
    const fcQ2 = [
      ["Which better matches the you you wanted to express?", "Identity mode"],
      ["Which would you be more likely to post?", "Identity mode"],
      ["Which would need less editing?", "Identity mode"],
      ["Which felt easier to get to a usable result?", "Identity mode"],
      ["If posting again, which path would you choose?", "Use identity mode"],
    ];

    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 28 }}>
        <p className="pf-lead" style={{ margin: 0, maxWidth: 820 }}>
          <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>Round two</strong> builds on round one.
          It narrows the broad A/B test into a focused study for Instagram written content, adds a lightweight
          identity mode, and asks what creators would actually reuse.
        </p>

        <div className="pf-glass pf-glass--thick" style={{ padding: "clamp(16px, 1.8vw, 28px)" }}>
          <div style={{ position: "relative", borderRadius: 20, overflow: "hidden", background: N.page, border: "1px solid rgba(255,255,255,0.09)", fontFamily: "Inter, -apple-system, sans-serif" }}>
            <div style={{ position: "absolute", top: 16, left: 16, zIndex: 5, display: "inline-flex", alignItems: "center", gap: 8, padding: "7px 14px", borderRadius: 999, background: "rgba(10,12,18,0.6)", border: "1px solid rgba(255,255,255,0.12)", color: N.t2, fontSize: 11, fontWeight: 500, letterSpacing: "0.06em", textTransform: "uppercase", backdropFilter: "blur(8px)", WebkitBackdropFilter: "blur(8px)" }}>
              <span style={{ width: 7, height: 7, borderRadius: "50%", background: done ? N.green : N.accent2 }} />
              {done ? "Run complete" : ph.cap}
            </div>

            <div style={{ padding: "clamp(40px,5vw,60px) clamp(20px,4vw,52px)", display: "flex", flexDirection: "column", alignItems: "center" }}>
              <div style={{ width: "100%", maxWidth: 600, display: "flex", alignItems: "center" }}>
                <span style={{ fontSize: 15, fontWeight: 600, letterSpacing: "-0.03em", color: N.t1 }}>nomi</span>
              </div>
              <div style={{ width: "100%", maxWidth: 600, marginTop: 18, display: "flex", gap: 6 }}>
                {[0,1,2,3,4,5,6].map(function (i) { return <div key={i} style={{ flex: 1, height: 2, borderRadius: 100, background: i <= seg ? N.accent2 : N.b1, transition: "background 0.4s" }} />; })}
              </div>

              <div key={screen} style={{ width: "100%", maxWidth: 600, marginTop: 20, background: N.card, border: "1px solid rgba(255,255,255,0.09)", borderRadius: 16, padding: "clamp(24px,3vw,40px)", boxShadow: "0 8px 40px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.06)", animation: reduced ? "none" : "nomiFade 0.4s ease both" }}>

                {screen === "s1" && (
                  <div>
                    <div style={ov(N)}>NOMI</div>
                    <div style={disp(N)}>Create an Instagram post through a version of you</div>
                    <p style={{ ...body(N), color: N.t1, marginBottom: 24, maxWidth: 500 }}>You'll create a caption two ways: directly, then through a lightweight identity mode. Then you'll compare which feels more like how you want to show up on Instagram.</p>
                    <Lbl N={N}>What do you want to post about? <Req N={N} /></Lbl>
                    <div style={{ ...field(N), minHeight: 84, marginBottom: 18 }}>
                      <span style={{ color: taskVal ? N.t1 : N.t3 }}>{taskVal || "Share a quiet moment from my weekend that feels warm and personal."}</span>
                      {ph.act === "typeTask" && !done && <Caret />}
                    </div>
                    <Lbl N={N}>Optional notes or angle <span style={{ fontWeight: 300, color: N.t3 }}>(optional)</span></Lbl>
                    <div style={{ ...field(N), minHeight: 54 }}>
                      <span style={{ color: notesVal ? N.t1 : N.t3 }}>{notesVal || "I want it natural, not over-polished."}</span>
                      {ph.act === "typeNotes" && !done && <Caret />}
                    </div>
                    <div style={{ marginTop: 24 }}><Btn N={N} pressed={ph.act === "startBtn"}>Start</Btn></div>
                  </div>
                )}

                {screen === "s2" && (
                  <div>
                    <BackRow N={N} />
                    <div style={h2(N)}>Direct generation</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>Captions generated from your idea alone, with no identity mode applied.</p>
                    {!draftsAShown ? (
                      <Btn N={N} loading={genningA}>{genningA ? "Generating…" : "Generate directly"}</Btn>
                    ) : (
                      <div>
                        <div style={sec(N)}>Choose the caption you'd most likely post <Req N={N} /></div>
                        <DraftList N={N} drafts={A2} sel={pickedA ? 0 : -1} />
                        {ratedA && <RateBlock N={N} q1="How much editing would your chosen caption need?" v1={4} q2="How well does this match how you want to show up on Instagram?" v2={2} />}
                        {ratedA && <div style={{ marginTop: 22 }}><Btn N={N}>Now try with an identity mode ›</Btn></div>}
                      </div>
                    )}
                  </div>
                )}

                {screen === "s3" && (
                  <div>
                    <BackRow N={N} />
                    <div style={h2(N)}>Shape one version of you</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>This helps nomi understand how you want this post to feel on Instagram.</p>
                    <div style={sec(N)}>Choose a starting mode <Req N={N} /></div>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 10, marginBottom: 22 }}>
                      {MODES2.map(function (m) {
                        const sel = m[0] === MODE2 && modeOn;
                        return (
                          <div key={m[0]} style={modeCard(N, sel)}>
                            <div style={{ fontSize: 14, fontWeight: 500, color: N.t1 }}>{m[0]}</div>
                            <div style={{ fontSize: 12, color: N.t3, marginTop: 3 }}>{m[1]}</div>
                          </div>
                        );
                      })}
                    </div>
                    <div style={sec(N)}>Adjust identity controls</div>
                    <div style={{ marginBottom: 22 }}>
                      <Slider N={N} l="Soft" r="Sharp" pct={38} />
                      <Slider N={N} l="Personal" r="Polished" pct={35} />
                      <Slider N={N} l="Calm" r="Expressive" pct={42} />
                    </div>
                    <Lbl N={N}>What should this version of you feel like on Instagram? <Req N={N} /></Lbl>
                    <div style={{ ...field(N), minHeight: 54 }}>
                      <span style={{ color: selfVal ? N.t1 : N.t3 }}>{selfVal || "Warm, real, and thoughtful. A little polished, but still personal."}</span>
                      {ph.act === "typeSelf" && !done && <Caret />}
                    </div>
                    <div style={{ ...sec(N), marginTop: 22 }}>Vibe</div>
                    <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                      {["Clean", VIBE2, "Dreamy", "Refined", "Playful"].map(function (v) { return <span key={v} style={chip(N, v === VIBE2 && vibeOn)}>{v}</span>; })}
                    </div>
                    <div style={{ marginTop: 26 }}><Btn N={N} loading={genningB}>{genningB ? "Generating…" : "Generate through this version"}</Btn></div>
                  </div>
                )}

                {screen === "s4" && (
                  <div>
                    <BackRow N={N} />
                    <div style={h2(N)}>Identity-shaped captions</div>
                    <p style={{ ...body(N), marginBottom: 20 }}>Captions generated through your idea and the version of you you just shaped.</p>
                    <div style={sec(N)}>Choose the caption you'd most likely post <Req N={N} /></div>
                    <DraftList N={N} drafts={B2} sel={pickedB ? 0 : -1} />
                    {ratedB && <RateBlock N={N} q1="How much editing would your chosen caption need?" v1={2} q2="How well does this match the version of you you intended?" v2={5} />}
                    {ratedB && <div style={{ marginTop: 22 }}><Btn N={N}>Compare both captions ›</Btn></div>}
                  </div>
                )}

                {screen === "s5" && (
                  <div>
                    <BackRow N={N} />
                    <div style={ov(N)}>Comparison</div>
                    <div style={{ ...h2(N), fontSize: 22 }}>Which caption worked better?</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>Your selected caption from each version.</p>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 14, marginBottom: 24 }}>
                      <div style={{ background: N.bg3, border: "1px solid " + N.b2, borderRadius: 16, padding: 20 }}>
                        <div style={{ ...sec(N), marginBottom: 8 }}>Direct</div>
                        <div style={{ fontSize: 12.5, fontWeight: 300, color: N.t1, lineHeight: 1.7 }}>{A2[0].body}</div>
                      </div>
                      <div style={{ background: N.soft2, border: "1px solid " + N.border, borderRadius: 16, padding: 20 }}>
                        <div style={{ ...sec(N), marginBottom: 8 }}>Through an identity mode</div>
                        <div style={{ fontSize: 12.5, fontWeight: 300, color: N.t1, lineHeight: 1.7 }}>{B2[0].body}</div>
                      </div>
                    </div>
                    <div style={sec(N)}>Forced-choice comparison</div>
                    {fcQ2.map(function (q, i) {
                      const opts = i === 4 ? ["Generate directly", "Use identity mode", "Not sure"] : ["Direct", "Identity mode", "Equal"];
                      return (
                        <div key={i} style={{ marginBottom: 15 }}>
                          <div style={{ fontSize: 13, fontWeight: 500, color: N.t1, marginBottom: 8 }}>{i + 1}. {q[0]}</div>
                          <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                            {opts.map(function (o) { return <span key={o} style={fcBtn(N, compared && o === q[1])}>{o}</span>; })}
                          </div>
                        </div>
                      );
                    })}
                  </div>
                )}

                {screen === "s6" && (
                  <div>
                    <BackRow N={N} />
                    <div style={ov(N)}>For future</div>
                    <div style={h2(N)}>What would you do with this version of you?</div>
                    <p style={{ ...body(N), marginBottom: 22 }}>Tap what would actually feel useful if you were posting on Instagram again.</p>
                    <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 8, marginBottom: 24 }}>
                      {ACTIONS2.map(function (a, i) {
                        const on = actionsOn && i < 2;
                        return (
                          <div key={a} style={{ display: "flex", alignItems: "center", gap: 10, padding: "13px 16px", borderRadius: 12, fontSize: 13, fontWeight: 500, textAlign: "left", transition: "all 0.25s",
                            background: on ? N.greenSoft : N.bg3, border: "1px solid " + (on ? N.greenBorder : N.b1), color: on ? N.green : N.t2 }}>
                            <span style={{ width: 26, height: 26, minWidth: 26, borderRadius: 8, background: on ? "transparent" : N.bg4, border: "1px solid " + N.b1, display: "flex", alignItems: "center", justifyContent: "center", color: on ? N.green : N.t3, fontSize: 14 }}>{on ? "✓" : "+"}</span>
                            {a}
                          </div>
                        );
                      })}
                    </div>
                    <div style={{ height: 1, background: "rgba(255,255,255,0.07)", margin: "8px 0 22px" }} />
                    <div style={sec(N)}>A few quick questions</div>
                    {[["Would you save this version of you for future posts?", "Yes, definitely"], ["Would you want another version for a different kind of post?", "Yes, definitely"]].map(function (q, i) {
                      return (
                        <div key={i} style={{ marginBottom: 15 }}>
                          <div style={{ fontSize: 13, fontWeight: 500, color: N.t1, marginBottom: 8 }}>{q[0]}</div>
                          <div style={{ display: "flex", gap: 8, flexWrap: "wrap" }}>
                            {["Yes, definitely", "Maybe", "Not really"].map(function (o) { return <span key={o} style={fcBtn(N, actionsOn && o === q[1])}>{o}</span>; })}
                          </div>
                        </div>
                      );
                    })}
                  </div>
                )}

                {screen === "s7" && (
                  <div>
                    <div style={ov(N)}>What comes next</div>
                    <div style={{ ...h2(N), marginBottom: 20 }}>One more concept to react to</div>
                    <div style={{ background: N.bg2, border: "1px solid " + N.b2, borderRadius: 16, padding: "clamp(24px,3vw,36px)" }}>
                      <div style={{ fontSize: 22, fontWeight: 600, letterSpacing: "-0.04em", color: N.t1, marginBottom: 8 }}>Nyla</div>
                      <p style={{ fontSize: 13.5, fontWeight: 300, color: N.t2, lineHeight: 1.65, marginBottom: 20, maxWidth: 440 }}>
                        Nyla helps you shape and manage different versions of yourself over time, across different kinds of posts and platforms.
                      </p>
                      <div style={{ ...field(N), color: N.t3, marginBottom: 10 }}>your@email.com</div>
                      <Btn N={N} full>Join the waitlist</Btn>
                    </div>
                    <div style={{ height: 1, background: "rgba(255,255,255,0.07)", margin: "24px 0" }} />
                    <div style={sec(N)}>Rate this concept</div>
                    <div style={{ fontSize: 13, fontWeight: 500, color: N.t1, marginBottom: 10 }}>How interesting is the idea of Nyla to you? <Req N={N} /></div>
                    <div style={{ display: "flex", gap: 6 }}>
                      {[1,2,3,4,5].map(function (n) { const on = n === 5 && done; return <span key={n} style={{ width: 42, height: 42, borderRadius: 8, border: "1px solid " + (on ? N.accent : N.b2), background: on ? N.accent : N.bg3, color: on ? "#fff" : N.t3, fontSize: 13, fontWeight: 500, display: "flex", alignItems: "center", justifyContent: "center" }}>{n}</span>; })}
                    </div>
                  </div>
                )}

              </div>
            </div>
          </div>

          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", flexWrap: "wrap", gap: 16, marginTop: 18 }}>
            <div style={{ display: "flex", gap: 10 }}>
              <button onClick={function () { setPlaying(!playing); }} className="pf-btn gv-lift" aria-label={playing ? "Pause" : "Play"}>
                <i data-lucide={playing ? "pause" : "play"} style={{ width: 16, height: 16, opacity: 0.85 }} />
                {playing ? "Pause" : "Play"}
              </button>
              <button onClick={restart} className="pf-btn gv-lift" aria-label="Restart">
                <i data-lucide="rotate-ccw" style={{ width: 16, height: 16, opacity: 0.85 }} />
                Restart
              </button>
            </div>
            <a href={LIVE2} target="_blank" rel="noopener noreferrer" className="pf-btn pf-btn--primary gv-lift">
              Open the study
              <i data-lucide="arrow-up-right" style={{ width: 16, height: 16, opacity: 0.8 }} />
            </a>
          </div>
        </div>

        <div className="pf-glass" style={{ padding: "clamp(24px,2.4vw,36px)" }}>
          <div className="pf-eyebrow" style={{ marginBottom: 14, color: "var(--accent)" }}>What round two changes</div>
          <p className="pf-body" style={{ margin: 0 }}>
            Round one asked a broad question across platforms. Round two focuses it on Instagram written captions,
            replaces the multi-step character builder with one lightweight <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>identity mode</strong>, and adds a reuse step: after comparing, creators say what they would <strong style={{ color: "var(--label-primary)", fontWeight: 500 }}>save, reuse, or remake</strong>, which is the signal that points toward Nyla.
          </p>
        </div>
      </div>
    );
  }

  /* ===================== Testing panel — round switcher ===================== */
  function NomiTesting() {
    const [round, setRound] = useState(0);
    const total = 2;
    return (
      <div style={{ display: "flex", flexDirection: "column", gap: 28 }}>
        <header style={{ maxWidth: 880 }}>
          <h2 className="pf-h2" style={{ margin: 0, fontSize: "clamp(21px, 2.2vw, 30px)" }}>Testing</h2>
          <p className="pf-lead" style={{ margin: "16px 0 0" }}>
            Two rounds of research, each a recorded run of the live nomi study. Round two builds directly on round one.
          </p>
        </header>

        {/* round switcher */}
        <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16 }}>
          <button onClick={function () { setRound(function (r) { return (r + total - 1) % total; }); }}
            className="pf-btn gv-lift" aria-label="Previous round" style={{ padding: 14 }}>
            <i data-lucide="chevron-left" style={{ width: 18, height: 18 }} />
          </button>
          <div style={{ textAlign: "center", flex: 1 }}>
            <div className="pf-h3" style={{ fontSize: "clamp(17px, 1.6vw, 22px)" }}>
              {round === 0 ? "Round 1 of 2: The broad A/B study" : "Round 2 of 2: Focused Instagram refinement"}
            </div>
          </div>
          <button onClick={function () { setRound(function (r) { return (r + 1) % total; }); }}
            className="pf-btn gv-lift" aria-label="Next round" style={{ padding: 14 }}>
            <i data-lucide="chevron-right" style={{ width: 18, height: 18 }} />
          </button>
        </div>

        {round === 0 ? <NomiReel key="r1" /> : <NomiReel2 key="r2" />}
      </div>
    );
  }

  window.CASE_PANELS = window.CASE_PANELS || {};
  window.CASE_PANELS["nomi"] = window.CASE_PANELS["nomi"] || {};
  window.CASE_PANELS["nomi"].Testing = NomiTesting;
})();
