/* =====================================================================
   CHAPTERS — all interactive chapter components
===================================================================== */

const { useState: useS, useContext: useC, useEffect: useE, useRef: useR } = React;

/* ── helpers ──────────────────────────────────────────────────────── */
function getNicheEx(obj, niche) {
  return obj[niche] || obj["other"] || "";
}

function SectionHeader({ eyebrow, title, lead }) {
  return (
    <div style={{ marginBottom: "36px" }}>
      {eyebrow && <div className="chapter-eyebrow">{eyebrow}</div>}
      <h2 className="chapter-h2" dangerouslySetInnerHTML={{ __html: title }} />
      {lead && <p className="chapter-lead">{lead}</p>}
    </div>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 00 — INTRO / NICHE PICKER
═══════════════════════════════════════════════════════════════════ */
function ChIntro() {
  const { niche, setNiche } = useC(NicheCtx);

  return (
    <section className="chapter" id="intro" data-reveal>
      <SectionHeader
        eyebrow="Welcome"
        title="The <em>7 factors</em> that decide whether your content goes viral or vanishes."
        lead="This guide distills everything that separates scroll-stopping short-form content from the content that gets skipped. Work through it once, apply it every time you hit record."
      />

      <div className="factor-list">
        {[
          ["01", "Topic"],
          ["02", "Hooks"],
          ["03", "Value"],
          ["04", "Script Angle"],
          ["05", "CTA"],
          ["06", "Video Format"],
          ["07", "Editing Style"],
        ].map(([n, label]) => (
          <div className="factor-pill" key={n}>
            <span className="factor-pill-num">{n}</span>
            <span className="factor-pill-label">{label}</span>
          </div>
        ))}
        <div className="factor-pill" style={{ borderColor: "rgba(201,150,58,0.4)", background: "rgba(201,150,58,0.07)" }}>
          <span className="factor-pill-num" style={{ background: "var(--accent)", color: "#0A0A09" }}>+</span>
          <span className="factor-pill-label" style={{ color: "var(--accent-ink)" }}>Script Lab</span>
        </div>
      </div>

      <div style={{ marginTop: "48px" }}>
        <div className="chapter-eyebrow" style={{ marginBottom: "12px" }}>Personalise your examples</div>
        <h3 style={{ fontFamily: "var(--font-serif)", fontSize: "22px", color: "var(--ink)", marginBottom: "8px" }}>
          What's your niche?
        </h3>
        <p style={{ fontSize: "14px", color: "var(--ink-2)", marginBottom: "20px", maxWidth: "460px" }}>
          Pick one and every example throughout this guide adapts to your space.
        </p>
        <div className="niche-grid">
          {NICHES.map(n => (
            <button
              key={n.id}
              className={"niche-btn" + (niche === n.id ? " is-selected" : "")}
              onClick={() => setNiche(n.id)}
            >
              <span className="niche-btn-emoji">{n.emoji}</span>
              <span>{n.label}</span>
            </button>
          ))}
        </div>
        {niche && (
          <div className="niche-box" style={{ marginTop: "8px" }}>
            <span className="niche-box-icon">{NICHES.find(n => n.id === niche)?.emoji}</span>
            <div>
              <div className="niche-box-label">Your niche is set</div>
              <div className="niche-box-text">
                All examples, templates, and scripts below are now tailored for{" "}
                <strong>{NICHES.find(n => n.id === niche)?.label}</strong> content.
                You can change this at any time by clicking a different niche above.
              </div>
            </div>
          </div>
        )}
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 01 — TOPIC
═══════════════════════════════════════════════════════════════════ */
function ChTopic() {
  const { niche } = useC(NicheCtx);
  const examples = TOPIC_EXAMPLES[niche] || TOPIC_EXAMPLES["other"];
  const nicheLabel = NICHES.find(n => n.id === niche)?.label || "your niche";

  return (
    <section className="chapter" id="topic" data-reveal>
      <SectionHeader
        eyebrow="Factor 01"
        title="<em>Topic</em> — Start where your audience already is."
        lead="The best content doesn't invent a conversation. It finds the conversation your audience is already having and drops into it. Your topic needs to feel like it was written for one specific person."
      />

      <div style={{ marginBottom: "32px" }}>
        <div className="chapter-eyebrow" style={{ marginBottom: "14px" }}>Where to find winning topics</div>
        <div style={{ display: "flex", flexDirection: "column", gap: "10px" }}>
          {[
            { icon: "💬", label: "Competitor comments", desc: "Read the comments on the top creators in your niche. Every question is a content idea. Every complaint is a hook." },
            { icon: "🔍", label: "YouTube autocomplete", desc: "Type your niche into YouTube and read every suggested search. These are real searches from real people with real problems." },
            { icon: "🟠", label: "Reddit & Quora", desc: "Search your niche on Reddit. The most upvoted questions = the topics people most want answered. Free research, forever." },
            { icon: "📊", label: "Your own analytics", desc: "Which posts have your highest saves and comments? That's your audience telling you exactly what to make more of." },
          ].map(({ icon, label, desc }) => (
            <div key={label} style={{ display: "flex", gap: "14px", padding: "16px 18px", background: "var(--surface)", border: "1px solid var(--line-2)", borderRadius: "var(--radius)" }}>
              <span style={{ fontSize: "20px", flexShrink: 0, marginTop: "2px" }}>{icon}</span>
              <div>
                <div style={{ fontSize: "14px", fontWeight: 700, color: "var(--ink)", marginBottom: "4px" }}>{label}</div>
                <div style={{ fontSize: "13px", color: "var(--ink-2)", lineHeight: "1.55" }}>{desc}</div>
              </div>
            </div>
          ))}
        </div>
      </div>

      <div>
        <div className="chapter-eyebrow" style={{ marginBottom: "14px" }}>
          Topic examples — {nicheLabel}
        </div>
        <div style={{ display: "flex", flexDirection: "column", gap: "8px" }}>
          {examples.map((ex, i) => (
            <div key={i} style={{ display: "flex", alignItems: "flex-start", justifyContent: "space-between", gap: "12px", padding: "14px 16px", background: "var(--surface)", border: "1px solid var(--line-2)", borderRadius: "var(--radius)" }}>
              <div style={{ display: "flex", gap: "12px", alignItems: "flex-start", flex: 1 }}>
                <span style={{ fontFamily: "var(--font-mono)", fontSize: "11px", color: "var(--muted-2)", paddingTop: "2px", flexShrink: 0 }}>#{i + 1}</span>
                <span style={{ fontSize: "14px", color: "var(--ink-2)", lineHeight: "1.55" }}>{ex}</span>
              </div>
              <CopyBtn text={ex} />
            </div>
          ))}
        </div>
      </div>

      <div className="info-box" style={{ marginTop: "28px" }}>
        <span className="info-box-icon">💡</span>
        <p className="info-box-text">
          <strong>The test:</strong> If your topic could apply to any niche, it's too broad. "How to be more productive" loses. "How to batch 30 days of {nicheLabel} content in one afternoon" wins.
        </p>
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 02 — HOOKS
═══════════════════════════════════════════════════════════════════ */
function ChHooks() {
  const { niche } = useC(NicheCtx);
  const [tab, setTab] = useS("verbal");

  const tabData = HOOK_DATA[tab] || [];
  const exKey = "example_" + (niche === "trading" ? "trading" : "fitness");
  const fallbackKey = "example_fitness";

  return (
    <section className="chapter" id="hooks" data-reveal>
      <SectionHeader
        eyebrow="Factor 02"
        title="<em>Hooks</em> — You have 0.5 seconds. Make them count."
        lead="A viral hook has three layers working together: what you SAY, what's on SCREEN as text, and what viewers SEE in the frame. All three need to align and amplify each other. Most creators only think about one."
      />

      <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: "10px", marginBottom: "36px" }}>
        {[
          { key: "verbal",  icon: "🎤", label: "Verbal Hook", sub: "What you say in the first 3 seconds" },
          { key: "written", icon: "📝", label: "Written Hook", sub: "Text on screen — works for silent viewers" },
          { key: "visual",  icon: "👁️", label: "Visual Hook", sub: "What's in the frame before you speak" },
        ].map(({ key, icon, label, sub }) => (
          <button
            key={key}
            onClick={() => setTab(key)}
            style={{
              padding: "16px",
              borderRadius: "var(--radius-lg)",
              border: tab === key ? "2px solid var(--accent)" : "2px solid var(--line-2)",
              background: tab === key ? "var(--accent-soft)" : "var(--surface)",
              cursor: "pointer",
              textAlign: "left",
              transition: "all 0.18s",
              boxShadow: tab === key ? "0 0 16px var(--accent-glow)" : "none",
              fontFamily: "var(--font-sans)",
            }}
          >
            <div style={{ fontSize: "22px", marginBottom: "8px" }}>{icon}</div>
            <div style={{ fontSize: "13px", fontWeight: 700, color: tab === key ? "var(--accent-ink)" : "var(--ink)", marginBottom: "4px" }}>{label}</div>
            <div style={{ fontSize: "11.5px", color: "var(--muted)", lineHeight: "1.4" }}>{sub}</div>
          </button>
        ))}
      </div>

      <div className="hook-cards">
        {tabData.map((h, i) => {
          const exText = h[exKey] || h[fallbackKey] || "";
          return (
            <div className="hook-card" key={i}>
              <div className="hook-card-head">
                <span className="hook-card-label">{h.label}</span>
                <CopyBtn text={exText} />
              </div>
              <div className="hook-card-template">{h.template}</div>
              {exText && <div className="hook-card-example">{exText}</div>}
            </div>
          );
        })}
      </div>

      <div className="info-box" style={{ marginTop: "28px" }}>
        <span className="info-box-icon">⚡</span>
        <p className="info-box-text">
          <strong>The 5X Outlier Trick:</strong> Find the 5 best-performing posts in your niche right now. Study only the hooks — verbal, visual, written. You'll see a pattern within 20 minutes. Use that pattern, don't reinvent it.
        </p>
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 03 — VALUE
═══════════════════════════════════════════════════════════════════ */
function ChValue() {
  const { niche } = useC(NicheCtx);

  return (
    <section className="chapter" id="value" data-reveal>
      <SectionHeader
        eyebrow="Factor 03"
        title="<em>Value</em> — Give them something worth stopping for."
        lead="The hook gets the view. Value earns the follow, the save, and the share. There are four types of value that consistently work. Rotate between them — don't rely on just one."
      />

      <div className="value-grid">
        {VALUE_TYPES.map((v, i) => {
          const exKey = "example_" + niche;
          const exText = v[exKey] || v["example_other"] || v["example_fitness"];
          return (
            <div className="value-card" key={i}>
              <div className="value-card-icon">{v.icon}</div>
              <div className="value-card-title">{v.title}</div>
              <div className="value-card-desc">{v.desc}</div>
              {exText && <div className="value-card-example">{exText}</div>}
            </div>
          );
        })}
      </div>

      <div className="info-box" style={{ marginTop: "28px" }}>
        <span className="info-box-icon">🎯</span>
        <p className="info-box-text">
          <strong>The save test:</strong> Before you post, ask — "Would I save this?" If the answer is no, the value isn't specific enough yet. Saves are the strongest signal to the algorithm.
        </p>
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 04 — SCRIPT ANGLE
═══════════════════════════════════════════════════════════════════ */
function ChAngle() {
  const { niche } = useC(NicheCtx);
  const [openId, setOpenId] = useS(null);

  return (
    <section className="chapter" id="angle" data-reveal>
      <SectionHeader
        eyebrow="Factor 04"
        title="<em>Script Angle</em> — The frame changes everything."
        lead="Same topic, different angle = completely different performance. Tap any angle to see its template and a niche-specific example. Mix and match — the same piece of information can be a how-to, a myth-bust, and a hot take."
      />

      <div className="angle-grid">
        {ANGLES.map(a => {
          const isOpen = openId === a.id;
          const exText = getNicheEx(a.examples, niche);
          return (
            <div
              key={a.id}
              className={"angle-card" + (isOpen ? " is-open" : "")}
              onClick={() => setOpenId(isOpen ? null : a.id)}
            >
              <div className="angle-card-head">
                <span className="angle-card-icon">{a.icon}</span>
                <span className="angle-card-name">{a.title}</span>
                <span className="angle-card-chevron">▼</span>
              </div>
              {isOpen && (
                <div className="angle-card-body" onClick={e => e.stopPropagation()}>
                  <p className="angle-card-desc">{a.desc}</p>
                  <div className="angle-template-label">Template</div>
                  <div className="angle-template-box">{a.template}</div>
                  {exText && (
                    <>
                      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "8px" }}>
                        <div className="angle-template-label" style={{ marginBottom: 0 }}>Example — {NICHES.find(n => n.id === niche)?.label}</div>
                        <CopyBtn text={exText} />
                      </div>
                      <div className="angle-example-box">{exText}</div>
                    </>
                  )}
                </div>
              )}
            </div>
          );
        })}
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 05 — CTA
═══════════════════════════════════════════════════════════════════ */
function ChCTACh() {
  const { niche } = useC(NicheCtx);
  const [goal, setGoal] = useS("following");
  const ctaData = CTA_OPTIONS[goal];
  const nicheLabel = NICHES.find(n => n.id === niche)?.label || "your niche";

  return (
    <section className="chapter" id="cta-ch" data-reveal>
      <SectionHeader
        eyebrow="Factor 05"
        title="<em>CTA</em> — One ask. Every single time."
        lead="The call-to-action is where most creators get greedy. They ask people to follow, save, comment, AND share in the same breath. Pick one. Make it specific. Make it easy. What's your goal with this content?"
      />

      <div className="cta-toggle">
        {Object.entries(CTA_OPTIONS).map(([key, val]) => (
          <button
            key={key}
            className={"cta-toggle-btn" + (goal === key ? " is-on" : "")}
            onClick={() => setGoal(key)}
          >
            <div className="cta-toggle-icon">{val.icon}</div>
            <div className="cta-toggle-label">{val.label}</div>
            <div className="cta-toggle-sub">{val.sub}</div>
          </button>
        ))}
      </div>

      <div className="cta-phrases">
        <div className="cta-phrases-title">Ready-to-use CTA phrases</div>
        {ctaData.phrases.map((phrase, i) => {
          const filled = phrase.replace("{niche}", nicheLabel).replace("{NICHE}", nicheLabel.toUpperCase());
          return (
            <div className="cta-phrase-row" key={i}>
              <span className="cta-phrase-text" dangerouslySetInnerHTML={{ __html: filled.replace(/\{([^}]+)\}/g, '<strong>{$1}</strong>') }} />
              <CopyBtn text={filled} />
            </div>
          );
        })}
      </div>

      <div className="cta-tip">
        <span className="cta-tip-icon">⚡</span>
        <p className="cta-tip-text">
          <strong>ManyChat:</strong> {ctaData.tip}
        </p>
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 06 — VIDEO FORMAT
═══════════════════════════════════════════════════════════════════ */
function ChFormat() {
  const [openId, setOpenId] = useS(null);

  return (
    <section className="chapter" id="format" data-reveal>
      <SectionHeader
        eyebrow="Factor 06"
        title="<em>Video Format</em> — Match the format to the message."
        lead="There are 11 main formats. Each one fits different content goals, energy levels, and production setups. Tap any card to see when it works best and how hard it is to pull off."
      />

      <div className="format-grid">
        {VIDEO_FORMATS.map(f => {
          const isOpen = openId === f.id;
          return (
            <div
              key={f.id}
              className={"format-card" + (isOpen ? " is-open" : "")}
              onClick={() => setOpenId(isOpen ? null : f.id)}
            >
              <div className="format-card-icon">{f.icon}</div>
              <div className="format-card-name">
                {f.title}
              </div>
              {!isOpen && (
                <div className="format-card-footer">
                  <DiffBadge level={f.difficulty} />
                  <ViralDots score={f.virality} />
                </div>
              )}
              {isOpen && (
                <div className="format-card-desc">
                  <div style={{ marginBottom: "10px" }}>{f.desc}</div>
                  <div style={{ display: "flex", gap: "8px", alignItems: "center" }}>
                    <DiffBadge level={f.difficulty} />
                    <span style={{ fontSize: "11px", color: "var(--muted)" }}>Viral potential:</span>
                    <ViralDots score={f.virality} />
                  </div>
                </div>
              )}
            </div>
          );
        })}
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 07 — EDITING STYLE
═══════════════════════════════════════════════════════════════════ */
function ChEditing() {
  return (
    <section className="chapter" id="editing" data-reveal>
      <SectionHeader
        eyebrow="Factor 07"
        title="<em>Editing Style</em> — Production quality is a trust signal."
        lead="You don't need expensive gear or a professional editor. You need three things done right. These are the editing elements that separate watchable content from content people skip."
      />

      <div className="editing-cards">
        {EDITING_ELEMENTS.map(el => (
          <div className="editing-card" key={el.id}>
            <div className="editing-card-head">
              <div className="editing-card-icon">{el.icon}</div>
              <div className="editing-card-title">{el.title}</div>
            </div>
            <p className="editing-card-what">{el.what}</p>
            <div className="editing-card-row">
              <div className="editing-mini editing-mini-why">
                <div className="editing-mini-label">Why it matters</div>
                <div className="editing-mini-text">{el.why}</div>
              </div>
              <div className="editing-mini editing-mini-tip">
                <div className="editing-mini-label">Pro tip</div>
                <div className="editing-mini-text">{el.tip}</div>
              </div>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 08 — SCRIPT LAB
═══════════════════════════════════════════════════════════════════ */
function ChLab() {
  const { niche } = useC(NicheCtx);
  const [mode, setMode] = useS("easy");
  const [selectedId, setSelectedId] = useS(null);

  const structures = SCRIPT_STRUCTURES[mode] || [];
  const selected = structures.find(s => s.id === selectedId) || null;

  const getExample = (s) => {
    if (!s) return null;
    return s.examples[niche] || s.examples["other"] || s.examples["fitness"] || null;
  };

  const getExampleText = (s) => {
    const ex = getExample(s);
    return ex ? ex.join("\n") : "";
  };

  return (
    <section className="chapter" id="lab" data-reveal>
      <SectionHeader
        eyebrow="Script Lab"
        title="Pick a structure. <em>Fill in the blanks.</em> Hit record."
        lead="Two flavours: Easy structures for fast production and high volume. Complex structures for deeper engagement and more saves. Pick one, see the template, copy the example."
      />

      <div className="lab-toggle">
        {[["easy", "⚡ Easy Structures"], ["complex", "🧠 Complex Structures"]].map(([key, label]) => (
          <button
            key={key}
            className={"lab-toggle-btn" + (mode === key ? " is-on" : "")}
            onClick={() => { setMode(key); setSelectedId(null); }}
          >
            {label}
          </button>
        ))}
      </div>

      <div className="lab-structure-list">
        {structures.map(s => (
          <button
            key={s.id}
            className={"lab-struct-btn" + (selectedId === s.id ? " is-on" : "")}
            onClick={() => setSelectedId(selectedId === s.id ? null : s.id)}
          >
            <div className="lab-struct-name">{s.title}</div>
            <div className="lab-struct-sub">{s.tag}</div>
          </button>
        ))}
      </div>

      {selected && (
        <div className="lab-output">
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "6px" }}>
            <div className="lab-output-title">{selected.title} — Structure</div>
          </div>

          <div style={{ fontSize: "12px", color: "var(--muted)", marginBottom: "14px", padding: "10px 14px", background: "var(--bg-tint)", borderRadius: "8px" }}>
            <span style={{ color: "var(--accent-ink)", fontWeight: 700 }}>Best for: </span>{selected.best_for}
          </div>

          <div className="lab-lines">
            {selected.structure.map((line, i) => (
              <div className="lab-line" key={i}>
                <span className="lab-line-num">{i + 1}.</span>
                <span className="lab-line-text">{line}</span>
              </div>
            ))}
          </div>

          {getExample(selected) && (
            <>
              <div style={{ borderTop: "1px solid var(--line)", paddingTop: "16px", marginTop: "4px" }}>
                <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "12px" }}>
                  <div className="lab-example-label">
                    Example — {NICHES.find(n => n.id === niche)?.label}
                  </div>
                  <CopyBtn text={getExampleText(selected)} />
                </div>
                <div className="lab-example-lines">
                  {getExample(selected).map((line, i) => (
                    <div className="lab-example-line" key={i}>{line}</div>
                  ))}
                </div>
              </div>
            </>
          )}
        </div>
      )}

      {!selectedId && (
        <div style={{ padding: "28px", background: "var(--surface)", border: "1px dashed var(--line-2)", borderRadius: "var(--radius-lg)", textAlign: "center", color: "var(--muted)", fontSize: "14px" }}>
          ↑ Select a structure above to see the template and a niche-specific example
        </div>
      )}
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 09 — 4-STEP PROCESS
═══════════════════════════════════════════════════════════════════ */
function ChProcess() {
  return (
    <section className="chapter" id="process" data-reveal>
      <SectionHeader
        eyebrow="The Process"
        title="Write every script in <em>4 steps.</em>"
        lead="Once you've absorbed the 7 factors, this is the order of operations for every single piece of content you create. Don't skip steps — especially steps 2 and 4."
      />

      <div className="process-timeline">
        {PROCESS_STEPS.map(step => (
          <div className="process-step" key={step.num}>
            <div className="process-step-dot" />
            <div className="process-step-num">STEP {step.num}</div>
            <div className="process-step-title">
              <span className="process-step-icon">{step.icon}</span>
              {step.title}
            </div>
            <p className="process-step-desc">{step.desc}</p>
            <div className="process-step-action">{step.action}</div>
          </div>
        ))}
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 10 — PRE-PUBLISH CHECKLIST
═══════════════════════════════════════════════════════════════════ */
function ChChecklist() {
  const storageKey = "cf_checklist_v1";
  const saved = (() => {
    try { return JSON.parse(localStorage.getItem(storageKey)) || {}; } catch { return {}; }
  })();

  const [checked, setChecked] = useS(saved);

  const toggle = (id) => {
    setChecked(prev => {
      const next = { ...prev, [id]: !prev[id] };
      try { localStorage.setItem(storageKey, JSON.stringify(next)); } catch {}
      return next;
    });
  };

  const score = CHECKLIST_ITEMS.filter(c => checked[c.id]).length;
  const total = CHECKLIST_ITEMS.length;
  const pct = Math.round((score / total) * 100);

  const getMessage = () => {
    if (score === total) return "You're ready to post. Hit publish.";
    if (score >= 8)  return "Nearly there — don't skip the last few.";
    if (score >= 6)  return "Good progress — keep going.";
    if (score >= 3)  return "Getting there. Work through each one.";
    return "Start at the top and work your way down.";
  };

  const resetAll = () => {
    const fresh = {};
    CHECKLIST_ITEMS.forEach(c => (fresh[c.id] = false));
    setChecked(fresh);
    try { localStorage.setItem(storageKey, JSON.stringify(fresh)); } catch {}
  };

  return (
    <section className="chapter" id="checklist" data-reveal>
      <SectionHeader
        eyebrow="Pre-Publish Checklist"
        title="Don't post until you can <em>check all 10.</em>"
        lead="Run every piece of content through this before you hit post. Saved to your browser — it persists between sessions."
      />

      <div className="checklist-score">
        <div>
          <div className="checklist-score-num">{score}</div>
          <div className="checklist-score-denom">/ {total}</div>
        </div>
        <div className="checklist-score-bar-wrap">
          <div className="checklist-score-label">{getMessage()}</div>
          <div className="checklist-score-bar">
            <div className="checklist-score-fill" style={{ width: pct + "%" }} />
          </div>
          <div className="checklist-score-msg">{pct}% complete</div>
        </div>
        <button
          onClick={resetAll}
          style={{ fontSize: "12px", color: "var(--muted)", padding: "6px 12px", border: "1px solid var(--line-2)", borderRadius: "6px", cursor: "pointer", flexShrink: 0, background: "none", fontFamily: "var(--font-sans)" }}
        >
          Reset
        </button>
      </div>

      <div className="checklist-items">
        {CHECKLIST_ITEMS.map(item => (
          <div
            key={item.id}
            className={"checklist-item" + (checked[item.id] ? " is-checked" : "")}
            onClick={() => toggle(item.id)}
          >
            <div className="checklist-box">
              {checked[item.id] && "✓"}
            </div>
            <span className="checklist-text">{item.text}</span>
          </div>
        ))}
      </div>
    </section>
  );
}

/* ═══════════════════════════════════════════════════════════════════
   CH 11 — WORK WITH ME CTA
═══════════════════════════════════════════════════════════════════ */
function ChWorkWithMe() {
  return (
    <section className="chapter cta-end-section" id="cta-end">
      <div className="cta-end-tag">✦ Ready to Apply This?</div>
      <h2 className="cta-end-title">
        Let's build your brand<br/>
        <em>together.</em>
      </h2>
      <p className="cta-end-sub">
        This guide gives you the framework. I give you the execution — scripts, editing, strategy, and growth — done for you every month.
      </p>

      <div className="cta-end-btns">
        <a className="btn btn-primary" href="https://www.orcalynx.com/book" target="_blank" rel="noopener">
          Book a Free Strategy Call →
        </a>
        <a className="btn btn-ghost" href="https://wa.me/9779811015121" target="_blank" rel="noopener">
          💬 Send a WhatsApp
        </a>
      </div>

      <div className="cta-end-links">
        <a className="cta-pill" href="https://www.orcalynx.com/" target="_blank" rel="noopener">orcalynx.com ↗</a>
        <a className="cta-pill" href="https://www.orcalynx.com/results" target="_blank" rel="noopener">View Client Results ↗</a>
        <a className="cta-pill" href="https://www.orcalynx.com/playbook" target="_blank" rel="noopener">Instagram Playbook ↗</a>
        <a className="cta-pill" href="https://www.instagram.com/marketing.shekhar" target="_blank" rel="noopener">@marketing.shekhar ↗</a>
      </div>

      <div style={{ marginTop: "48px", padding: "24px", background: "var(--surface)", border: "1px solid var(--line-2)", borderRadius: "var(--radius-lg)", maxWidth: "480px", margin: "48px auto 0" }}>
        <div style={{ fontSize: "11px", fontWeight: 700, letterSpacing: "0.1em", textTransform: "uppercase", color: "var(--accent)", marginBottom: "10px" }}>What we do</div>
        <p style={{ fontSize: "13.5px", color: "var(--ink-2)", lineHeight: "1.65" }}>
          We handle everything — strategy, scripts, filming direction, editing, captions, and posting — for founders, coaches, and traders who want to grow a premium personal brand without spending hours on content every week.
        </p>
        <div style={{ marginTop: "14px", display: "flex", gap: "6px", flexWrap: "wrap" }}>
          {["Scripts", "Editing", "Strategy", "Growth"].map(tag => (
            <span key={tag} className="tag tag-accent">{tag}</span>
          ))}
        </div>
      </div>
    </section>
  );
}

Object.assign(window, {
  ChIntro, ChTopic, ChHooks, ChValue,
  ChAngle, ChCTACh, ChFormat, ChEditing,
  ChLab, ChProcess, ChChecklist, ChWorkWithMe,
});
