/* ============================================================
   STORYBOOK v7 — part 1
   - Fig 1: v1 monitor composition restored, but extension lives
     in the upper-right of the browser chrome (manager strip
     visible), and a small extension card floats off from there.
     No leader lines from annotations.
   - Fig 2: only ONE Auto Print button on the lower (detail)
     surface, top-right of the page.
   Depends on scene-utils.jsx and APMark from v3-1 (we re-export).
   ============================================================ */


/* ------------------------------------------------------------
   A6_TemplatesAndRouting — NEW SETUP SLIDE
   Narrowed to ONE doc type (invoices) so the story is crystal:
     1. BUILD CUSTOM HTML INVOICE TEMPLATES
        Three different invoice templates, visibly distinct
        (Default / Wholesale / International). The active one
        peeks its raw HTML/Liquid markup so the "this is code
        you author" nature is unmistakable.
     2. ROUTING RULES
        Every rule emits an invoice — different rules pick
        different invoice templates based on order context.
------------------------------------------------------------ */
/* SlideLabel — left-aligned (slides 1 & 2) */
const SlideLabel = ({ num, title, body }) => (
  <g>
    <text x="32" y="32" fontFamily="Geist Mono, monospace" fontSize="11" fill={PALETTE.honeyDk}
          textAnchor="start" fontWeight="700" letterSpacing="0.18em">{num}</text>
    <text x="32" y="52" fontFamily="Geist, sans-serif" fontSize="20" fill={PALETTE.ink}
          textAnchor="start" fontWeight="500" letterSpacing="-0.01em">{title}</text>
    <foreignObject x="32" y="58" width="480" height="60">
      <div xmlns="http://www.w3.org/1999/xhtml"
           style={{fontFamily:"'Geist', sans-serif", fontSize:"12px", color:PALETTE.ink3,
                   lineHeight:"1.45", textAlign:"left"}}>
        {body}
      </div>
    </foreignObject>
  </g>
);

/* SlideLabelRight — right-aligned (slide 3) */
const SlideLabelRight = ({ num, title, body }) => (
  <g>
    <text x="968" y="32" fontFamily="Geist Mono, monospace" fontSize="11" fill={PALETTE.honeyDk}
          textAnchor="end" fontWeight="700" letterSpacing="0.18em">{num}</text>
    <text x="968" y="52" fontFamily="Geist, sans-serif" fontSize="20" fill={PALETTE.ink}
          textAnchor="end" fontWeight="500" letterSpacing="-0.01em">{title}</text>
    <foreignObject x="488" y="58" width="480" height="60">
      <div xmlns="http://www.w3.org/1999/xhtml"
           style={{fontFamily:"'Geist', sans-serif", fontSize:"12px", color:PALETTE.ink3,
                   lineHeight:"1.45", textAlign:"right"}}>
        {body}
      </div>
    </foreignObject>
  </g>
);

const A6_TemplatesAndRouting = ({ motion = true, annotated = true, showLabels = true, staticPose = false }) => {
  const W = 1000, H = 600;
  const animate = motion && !staticPose;
  return (
    <div style={{ width: "100%", aspectRatio: `${W} / ${H}` }}>
      <svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" style={{ display: "block", overflow: "visible" }}>
        <defs>
          <linearGradient id="a6-0-bg" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0" stopColor={PALETTE.paper}/><stop offset="1" stopColor={PALETTE.paper2}/>
          </linearGradient>
        </defs>
        <rect width={W} height={H} fill="url(#a6-0-bg)"/>

        {showLabels && (
          <Tag x={40} y={36} text="01 · CUSTOM TEMPLATES AND PRINT RULES" color={PALETTE.honeyDk} size={14} weight={600}/>
        )}

        {/* ============================================================
           STEP 1.1 — INVOICE TEMPLATES (left half)
        ============================================================ */}
        <g transform="translate(40, 120)">
          <Annotation x={0} y={-44} label="1.1 · CUSTOM HTML TEMPLATES" body={["Author your own templates in HTML —", "use variables to pull each order's data into every document."]}/>

          {/* library frame */}
          <rect x="0" y="0" width="420" height="436" rx="10" fill={PALETTE.paper} stroke={PALETTE.ink} strokeWidth="1.4"/>
          <rect x="0" y="0" width="420" height="34" rx="10" fill={PALETTE.paper3}/>
          <rect x="0" y="24" width="420" height="10" fill={PALETTE.paper3}/>
          {/* file-folder tab */}
          <g transform="translate(14, 8)">
            <rect x="0" y="0" width="22" height="18" rx="3" fill={PALETTE.honey} stroke={PALETTE.honeyLn} strokeWidth="0.7"/>
            <text x="11" y="13" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink} textAnchor="middle" fontWeight="700">{`</>`}</text>
          </g>
          <text x="44" y="22" fontFamily="Geist Mono, monospace" fontSize="10" fill={PALETTE.ink} fontWeight="700" letterSpacing="0.14em">INVOICE TEMPLATES</text>
          <g transform="translate(354, 8)">
            <rect x="0" y="0" width="56" height="18" rx="3" fill={PALETTE.honey} stroke={PALETTE.honeyLn} strokeWidth="0.8"/>
            <text x="28" y="13" fontFamily="Geist, sans-serif" fontSize="9" fill={PALETTE.ink} textAnchor="middle" fontWeight="700">+ New</text>
          </g>

          {/* THREE invoice template cards — visibly different layouts */}
          {(() => {
            const templates = [
              {
                key: "default",
                title: "Default invoice",
                meta: "letter · doc · v3",
                accent: PALETTE.ink,
                hl: false,
                draw: (
                  <>
                    {/* tidy minimal: small wordmark + line items */}
                    <rect x="14" y="12" width="40" height="3" fill={PALETTE.ink}/>
                    <rect x="14" y="18" width="28" height="1.6" fill={PALETTE.ink5}/>
                    <line x1="14" y1="26" x2="142" y2="26" stroke={PALETTE.ink5} strokeWidth="0.4"/>
                    {[32,38,44,50,56].map((y, j) => (
                      <g key={j}>
                        <rect x="14" y={y} width="74" height="1.4" fill={PALETTE.ink5}/>
                        <rect x="124" y={y} width="14" height="1.4" fill={PALETTE.ink4}/>
                      </g>
                    ))}
                    <line x1="14" y1="62" x2="142" y2="62" stroke={PALETTE.ink5} strokeWidth="0.4"/>
                    <rect x="100" y="68" width="38" height="2.2" fill={PALETTE.ink}/>
                  </>
                ),
              },
              {
                key: "wholesale",
                title: "Wholesale invoice",
                meta: "letter · doc · v7",
                accent: PALETTE.honey,
                hl: true, // active
                draw: (
                  <>
                    {/* big honey header bar + LOGO + columns */}
                    <rect x="0" y="0" width="156" height="14" fill={PALETTE.honey}/>
                    <text x="8" y="10" fontFamily="Geist Mono, monospace" fontSize="6" fill={PALETTE.ink} fontWeight="800" letterSpacing="0.18em">WHOLESALE INVOICE</text>
                    <rect x="14" y="20" width="34" height="3" fill={PALETTE.ink}/>
                    <rect x="14" y="26" width="56" height="1.6" fill={PALETTE.ink5}/>
                    {/* PO box */}
                    <rect x="100" y="20" width="42" height="14" rx="1" fill={PALETTE.paper3} stroke={PALETTE.ink} strokeWidth="0.4"/>
                    <text x="103" y="25" fontFamily="Geist Mono, monospace" fontSize="3.5" fill={PALETTE.ink5}>PO #</text>
                    <text x="103" y="32" fontFamily="Geist Mono, monospace" fontSize="5" fill={PALETTE.ink} fontWeight="700">88204</text>
                    {/* table header */}
                    <rect x="14" y="40" width="128" height="5" fill={PALETTE.paper3}/>
                    {[48, 54, 60, 66].map((y, j) => (
                      <g key={j}>
                        <rect x="14" y={y} width="60" height="1.4" fill={PALETTE.ink5}/>
                        <rect x="80" y={y} width="14" height="1.4" fill={PALETTE.ink4}/>
                        <rect x="100" y={y} width="14" height="1.4" fill={PALETTE.ink4}/>
                        <rect x="120" y={y} width="20" height="1.4" fill={PALETTE.ink}/>
                      </g>
                    ))}
                    <line x1="14" y1="72" x2="142" y2="72" stroke={PALETTE.ink} strokeWidth="0.6"/>
                    <text x="100" y="80" fontFamily="Geist Mono, monospace" fontSize="5" fill={PALETTE.ink5}>NET 30</text>
                    <rect x="120" y="76" width="20" height="3" fill={PALETTE.ink}/>
                  </>
                ),
              },
              {
                key: "intl",
                title: "International invoice",
                meta: "letter · doc · v2",
                accent: "#5C7B89",
                hl: false,
                draw: (
                  <>
                    {/* customs/commercial: stamp + multi-currency cell */}
                    <text x="14" y="14" fontFamily="Geist Mono, monospace" fontSize="6" fill={PALETTE.ink} fontWeight="800" letterSpacing="0.16em">COMMERCIAL INVOICE</text>
                    <text x="14" y="22" fontFamily="Geist Mono, monospace" fontSize="4" fill={PALETTE.ink5}>HS · COO · CUSTOMS</text>
                    {/* circular stamp */}
                    <circle cx="128" cy="22" r="11" fill="none" stroke="#5C7B89" strokeWidth="0.7"/>
                    <circle cx="128" cy="22" r="7" fill="none" stroke="#5C7B89" strokeWidth="0.5"/>
                    <text x="128" y="24" fontFamily="Geist Mono, monospace" fontSize="3.6" fill="#5C7B89" textAnchor="middle" fontWeight="700">EXPORT</text>
                    <line x1="14" y1="38" x2="142" y2="38" stroke={PALETTE.ink5} strokeWidth="0.4"/>
                    {[44, 50, 56].map((y, j) => (
                      <g key={j}>
                        <rect x="14" y={y} width="40" height="1.4" fill={PALETTE.ink5}/>
                        <rect x="58" y={y} width="14" height="1.4" fill={PALETTE.ink4}/>
                        <rect x="78" y={y} width="22" height="1.4" fill={PALETTE.ink4}/>
                        <rect x="106" y={y} width="14" height="1.4" fill="#5C7B89"/>
                        <rect x="124" y={y} width="14" height="1.4" fill="#5C7B89"/>
                      </g>
                    ))}
                    <line x1="14" y1="62" x2="142" y2="62" stroke={PALETTE.ink5} strokeWidth="0.4"/>
                    <text x="14" y="70" fontFamily="Geist Mono, monospace" fontSize="4" fill={PALETTE.ink5}>USD · €</text>
                    <rect x="100" y="68" width="40" height="2.2" fill="#5C7B89"/>
                  </>
                ),
              },
            ];
            return templates.map((t, i) => {
              const x = 16;
              const y = 42 + i * 134;
              return (
                <g key={t.key} transform={`translate(${x}, ${y})`}>
                  {/* card */}
                  <rect x="0" y="0" width="388" height="120" rx="6" fill={PALETTE.paper2} stroke={t.hl ? PALETTE.honeyLn : PALETTE.rule} strokeWidth={t.hl ? 1.4 : 0.7}/>

                  {/* mini doc preview (left) */}
                  <g transform="translate(12, 12)">
                    <rect x="0" y="0" width="156" height="96" rx="2" fill="#FAFAF7" stroke={PALETTE.ink} strokeWidth="0.6"/>
                    {/* accent corner stripe */}
                    <rect x="0" y="0" width="156" height={t.hl ? 0 : 0} fill={t.accent}/>
                    {t.draw}
                  </g>

                  {/* metadata + chip (right) */}
                  <g transform="translate(180, 16)">
                    {/* type chip — </> indicates HTML */}
                    <g>
                      <rect x="0" y="0" width="80" height="16" rx="3" fill={PALETTE.ink}/>
                      <text x="6" y="12" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.honey} fontWeight="700">{`</>`}</text>
                      <text x="22" y="11" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.paper} letterSpacing="0.12em" fontWeight="700">HTML · LIQUID</text>
                    </g>
                    <text x="0" y="36" fontFamily="Geist, sans-serif" fontSize="13" fill={PALETTE.ink} fontWeight="700">{t.title}</text>
                    <text x="0" y="50" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink4}>{t.meta}</text>

                    {/* peek of underlying HTML/Liquid (only on the active/highlighted card) — static display */}
                    {t.hl ? (
                      <g transform="translate(0, 60)">
                        <rect x="0" y="0" width="194" height="44" rx="3" fill={PALETTE.ink} stroke={PALETTE.ink3} strokeWidth="0.6"/>
                        <rect x="0" y="0" width="194" height="10" rx="3" fill={PALETTE.ink2}/>
                        <text x="6" y="7.5" fontFamily="Geist Mono, monospace" fontSize="6" fill={PALETTE.ink5} letterSpacing="0.1em">wholesale-invoice.html.liquid</text>
                        <defs>
                          <clipPath id="a6-code-clip"><rect x="4" y="12" width="186" height="30"/></clipPath>
                        </defs>
                        <g clipPath="url(#a6-code-clip)">
                          <text x="6" y="20" fontFamily="Geist Mono, monospace" fontSize="6.5" fill={PALETTE.honey}>
                            {`<table class="lines wholesale">`}
                          </text>
                          <text x="6" y="28" fontFamily="Geist Mono, monospace" fontSize="6.5" fill={PALETTE.paper}>
                            {`  <tr class="line">`}
                          </text>
                          <text x="6" y="36" fontFamily="Geist Mono, monospace" fontSize="6.5" fill={PALETTE.paper}>
                            {`    <td>{{ product.title }}</td>`}
                          </text>
                        </g>
                        {/* blinking caret — only subtle indicator of liveness */}
                        {animate && (
                          <rect x="6" y="38" width="2" height="6" fill={PALETTE.honey}>
                            <animate attributeName="opacity" values="1;0;1" dur="0.9s" repeatCount="indefinite"/>
                          </rect>
                        )}
                      </g>
                    ) : (
                      <g transform="translate(0, 64)" opacity="0.55">
                        <rect x="0" y="0" width="194" height="32" rx="3" fill={PALETTE.paper3} stroke={PALETTE.rule} strokeWidth="0.5"/>
                        <text x="8" y="12" fontFamily="Geist Mono, monospace" fontSize="6" fill={PALETTE.ink4} letterSpacing="0.1em">{t.key}-invoice.html.liquid</text>
                        <line x1="8" y1="18" x2="80" y2="18" stroke={PALETTE.ink5} strokeWidth="0.5"/>
                        <line x1="8" y1="22" x2="60" y2="22" stroke={PALETTE.ink5} strokeWidth="0.5"/>
                        <line x1="8" y1="26" x2="100" y2="26" stroke={PALETTE.ink5} strokeWidth="0.5"/>
                      </g>
                    )}
                  </g>

                  {/* edit affordance */}
                  <g transform="translate(360, 12)" opacity="0.85">
                    <rect x="0" y="0" width="16" height="16" rx="3" fill={PALETTE.paper}/>
                    <path d="M 4 11 L 11 4 L 13 6 L 6 13 L 4 13 Z" fill="none" stroke={PALETTE.ink3} strokeWidth="0.9"/>
                  </g>

                  {/* active glow — pulses in animation; rendered at peak in static pose */}
                  {((animate || staticPose) && t.hl) && (
                    <rect x="-2" y="-2" width="392" height="124" rx="6" fill="none" stroke={PALETTE.honey} strokeWidth="1.6" opacity={staticPose ? "1" : "0"}>
                      {animate && <animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1;0.18;0.5;0.6;1" dur="6s" repeatCount="indefinite"/>}
                    </rect>
                  )}
                </g>
              );
            });
          })()}
        </g>

        {/* connector arrow between steps */}
        <g>
          <path d="M 470 338 L 530 338" fill="none" stroke={PALETTE.ink3} strokeWidth="1.6"/>
          <path d="M 530 338 L 522 334 M 530 338 L 522 342" fill="none" stroke={PALETTE.ink3} strokeWidth="1.6" strokeLinecap="round"/>
          <Tag x={500} y={328} text="picked by" anchor="middle" color={PALETTE.ink4} size={9}/>
        </g>

        {/* ============================================================
           STEP 1.2 — ROUTING RULES (right half)
           One rule per template — each rule's WHEN condition
           picks the matching template.
        ============================================================ */}
        <g transform="translate(540, 120)">
          <Annotation x={0} y={-44} label="1.2 · PRINT RULES" body={["Configure print rules for any document type —", "order context decides which template fires and which printer it lands on."]}/>

          <rect x="0" y="0" width="420" height="436" rx="10" fill={PALETTE.ink} stroke={PALETTE.ink} strokeWidth="1.4"/>
          <rect x="0" y="0" width="420" height="34" rx="10" fill={PALETTE.honeyDk}/>
          <rect x="0" y="24" width="420" height="10" fill={PALETTE.honeyDk}/>
          <text x="14" y="22" fontFamily="Geist Mono, monospace" fontSize="10" fill={PALETTE.paper} fontWeight="700" letterSpacing="0.14em">WHEN TO PRINT WHICH INVOICE</text>
          <circle cx="402" cy="17" r="3.5" fill={PALETTE.ok}>
            {animate && <animate attributeName="opacity" values="1;0.4;1" dur="1.6s" repeatCount="indefinite"/>}
          </circle>

          {/* legend */}
          <g transform="translate(14, 56)">
            <text x="0" y="0" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink5} letterSpacing="0.12em">WHEN ORDER CONTEXT MATCHES…</text>
            <text x="0" y="14" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink5} letterSpacing="0.12em">…RENDER THE MATCHING INVOICE TEMPLATE</text>
          </g>

          {/* THREE invoice rule rows — one per template */}
          {[
            { when: "customer.tag = wholesale", tpl: "Wholesale invoice",     active: true,  hue: PALETTE.honey  },
            { when: "shipping.country ≠ US",    tpl: "International invoice", active: false, hue: "#5C7B89"      },
            { when: "else (default)",           tpl: "Default invoice",       active: false, hue: PALETTE.paper },
          ].map((r, i) => (
            <g key={i} transform={`translate(14, ${110 + i * 110})`}>
              <rect x="0" y="0" width="392" height="96" rx="6" fill={PALETTE.ink2} stroke={PALETTE.ink3} strokeWidth="0.6"/>
              {/* RULE HEADER */}
              <text x="14" y="18" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink5} letterSpacing="0.12em">RULE 0{i+1}</text>
              {/* WHEN */}
              <text x="14" y="38" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink5} letterSpacing="0.12em">WHEN</text>
              <text x="14" y="56" fontFamily="Geist Mono, monospace" fontSize="11" fill={PALETTE.paper}>{r.when}</text>
              {/* arrow */}
              <text x="14" y="80" fontFamily="Geist Mono, monospace" fontSize="14" fill={PALETTE.honey} fontWeight="700">→</text>
              {/* RENDER */}
              <text x="36" y="72" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink5} letterSpacing="0.12em">RENDER</text>
              <text x="36" y="86" fontFamily="Geist, sans-serif" fontSize="13" fill={r.hue} fontWeight="600">{r.tpl}</text>
              {/* mini doc icon on the right */}
              <g transform="translate(346, 14)">
                <rect x="0" y="0" width="30" height="68" rx="2" fill="#FAFAF7" stroke={r.hue} strokeWidth="0.9"/>
                <rect x="0" y="0" width="30" height="5" fill={r.hue}/>
                {[12,18,24,30,36,42,48].map((y, j) => (
                  <rect key={j} x="4" y={y} width={[22,18,20,16,22,14,18][j]} height="1" fill={PALETTE.ink5}/>
                ))}
                <rect x="18" y="58" width="10" height="4" fill={r.hue}/>
              </g>
              {((animate || staticPose) && r.active) && (
                <rect x="0" y="0" width="392" height="96" rx="6" fill="none" stroke={PALETTE.honey} strokeWidth="1.6" opacity={staticPose ? "1" : "0"}>
                  {animate && <animate attributeName="opacity" values="0;0;1;1;0;0" keyTimes="0;0.1;0.18;0.5;0.6;1" dur="6s" repeatCount="indefinite"/>}
                </rect>
              )}
            </g>
          ))}
        </g>

      </svg>
    </div>
  );
};


/* ------------------------------------------------------------
   APMarkV5 — same favicon as v3 (re-included to be standalone).
------------------------------------------------------------ */
const APMarkV5 = ({ x = 0, y = 0, size = 16, bg = PALETTE.paper, rx = "14" }) => {
  const s = size / 64;
  return (
    <g transform={`translate(${x}, ${y}) scale(${s})`}>
      <rect x="0" y="0" width="64" height="64" rx={rx} fill={bg}/>
      <g>
        <path d="M22.4 8 L41.6 8 L57 50 L46.5 50 L42.8 39.5 L21.2 39.5 L17.5 50 L7 50 Z" fill={PALETTE.ink}/>
        <path d="M30 8 L41.6 8 L36 22 Z" fill={bg}/>
        <path d="M32 16.4 L38.6 31.5 L25.4 31.5 Z" fill={bg}/>
        <rect x="7" y="54" width="50" height="3" fill={PALETTE.honey}/>
      </g>
    </g>
  );
};


/* ------------------------------------------------------------
   A6_LabelIntercept — v1 frame, with extension manager strip
   visible on the browser chrome and a small extension card
   floating off from there in the upper-right.
------------------------------------------------------------ */
const A6_LabelIntercept = ({ motion = true, annotated = true, showLabels = true, staticPose = false }) => {
  const W = 1000, H = 560;
  const animate = motion && !staticPose;
  return (
    <div style={{ width: "100%", aspectRatio: `${W} / ${H}` }}>
      <svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" style={{ display: "block", overflow: "visible" }}>
        <defs>
          <linearGradient id="a6-1-desk" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0" stopColor={PALETTE.paper3}/><stop offset="1" stopColor={PALETTE.paper4}/>
          </linearGradient>
          <linearGradient id="a6-1-sheen" x1="0" x2="1" y1="0" y2="1">
            <stop offset="0" stopColor="#fff" stopOpacity="0.5"/><stop offset="1" stopColor="#fff" stopOpacity="0"/>
          </linearGradient>
          <clipPath id="a6-1-screen"><rect x="44" y="36" width="544" height="300" rx="3"/></clipPath>
        </defs>

        {showLabels && (
          <Tag x={40} y={36} text="04 · LABEL PRINTING" color={PALETTE.honeyDk} size={14} weight={600}/>
        )}

        {/* desk */}
        <g transform="translate(0, 380)">
          <path d="M 60 80 L 940 80 L 1000 140 L 0 140 Z" fill="url(#a6-1-desk)"/>
          <path d="M 60 80 L 940 80 L 1000 140 L 0 140 Z" fill="none" stroke={PALETTE.ink} strokeWidth="1.2" strokeLinejoin="round"/>
          <line x1="120" y1="100" x2="900" y2="100" stroke={PALETTE.paper4} strokeWidth="0.5" opacity="0.6"/>
        </g>

        {/* monitor group — translate(90, 80) keeps it centered with extension card */}
        <g transform="translate(90, 80)">
          <path d="M 280 360 L 360 360 L 380 410 L 260 410 Z" fill={PALETTE.paper3} stroke={PALETTE.ink} strokeWidth="1.2" strokeLinejoin="round"/>
          <ellipse cx="320" cy="412" rx="80" ry="8" fill={PALETTE.ink} opacity="0.12"/>
          <path d="M 220 408 L 420 408 L 430 416 L 210 416 Z" fill={PALETTE.paper4} stroke={PALETTE.ink} strokeWidth="1.2" strokeLinejoin="round"/>
          {/* monitor */}
          <path d="M 600 24 L 624 40 L 624 332 L 600 348 Z" fill={PALETTE.ink2} stroke={PALETTE.ink} strokeWidth="1.2"/>
          <path d="M 32 348 L 600 348 L 624 332 L 56 332 Z" fill={PALETTE.ink} stroke={PALETTE.ink} strokeWidth="1.2"/>
          <rect x="32" y="24" width="568" height="324" rx="6" fill={PALETTE.ink}/>
          <rect x="44" y="36" width="544" height="300" rx="3" fill={PALETTE.paper}/>
          {/* screen contents */}
          <g clipPath="url(#a6-1-screen)">
            {/* browser chrome */}
            <rect x="44" y="36" width="544" height="28" fill={PALETTE.paper2}/>
            <circle cx="58" cy="50" r="4" fill="#E68B7A"/><circle cx="72" cy="50" r="4" fill="#E5C56B"/><circle cx="86" cy="50" r="4" fill="#7CB69E"/>
            <rect x="120" y="44" width="328" height="12" rx="6" fill={PALETTE.paper3}/>
            <text x="138" y="53" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink4}>admin.shopify.com/orders/#1042</text>

            {/* extension manager strip — top right of browser chrome */}
            <g transform="translate(458, 42)">
              <rect x="0" y="0" width="116" height="16" rx="3" fill={PALETTE.paper} stroke={PALETTE.rule} strokeWidth="0.5"/>
              <circle cx="12" cy="8" r="3.6" fill={PALETTE.paper3}/>
              <circle cx="26" cy="8" r="3.6" fill={PALETTE.paper3}/>
              {/* AP extension chip — highlighted */}
              <g transform="translate(34, 2.4)">
                <rect x="0" y="0" width="11" height="11" rx="2.5" fill={PALETTE.honey} stroke={PALETTE.honeyLn} strokeWidth="0.6"/>
                <APMarkV5 x={1} y={1} size={9} bg={PALETTE.honey} rx="2"/>
                {(animate || staticPose) && (
                  <circle cx="5.5" cy="5.5" r={staticPose ? "12" : "6"} fill="none" stroke={PALETTE.honeyLn} strokeWidth="1" opacity={staticPose ? "0.85" : "0"}>
                    {animate && <animate attributeName="r" values="6;14;14" keyTimes="0;0.6;1" dur="6s" repeatCount="indefinite"/>}
                    {animate && <animate attributeName="opacity" values="0;0;0.85;0;0" keyTimes="0;0.4;0.55;0.7;1" dur="6s" repeatCount="indefinite"/>}
                  </circle>
                )}
              </g>
              <circle cx="56" cy="8" r="3.6" fill={PALETTE.paper3}/>
              <circle cx="70" cy="8" r="3.6" fill={PALETTE.paper3}/>
              <circle cx="84" cy="8" r="3.6" fill={PALETTE.paper3}/>
              <text x="106" y="11" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink4} fontWeight="700">⋮</text>
            </g>

            {/* sidebar */}
            <rect x="44" y="64" width="84" height="272" fill={PALETTE.paper2}/>
            {[78, 92, 104, 116, 128].map((y, i) => (
              <rect key={i} x="56" y={y} width={[60,48,56,40,52][i]} height={i === 0 ? 6 : 5} rx="2" fill={i === 0 ? PALETTE.paper4 : PALETTE.paper3}/>
            ))}
            {/* order header */}
            <text x="148" y="92" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink3}>#1042</text>
            <rect x="180" y="83" width="44" height="12" rx="6" fill={PALETTE.ok} opacity="0.18"/>
            <text x="186" y="92" fontFamily="Geist, sans-serif" fontSize="7" fill={PALETTE.ok} fontWeight="600">PAID</text>
            <rect x="148" y="104" width="180" height="10" rx="2" fill={PALETTE.ink}/>
            <rect x="148" y="120" width="120" height="6" rx="2" fill={PALETTE.ink5}/>
            {/* line items */}
            {[142, 194].map((y, i) => (
              <g key={i}>
                <rect x="148" y={y} width="324" height="44" rx="4" fill={PALETTE.paper2} stroke={PALETTE.rule} strokeWidth="0.5"/>
                <rect x="158" y={y + 10} width="24" height="24" rx="3" fill={PALETTE.paper4}/>
                <rect x="190" y={y + 14} width={[120, 100][i]} height="6" rx="2" fill={PALETTE.ink2}/>
                <rect x="190" y={y + 26} width={[80, 60][i]} height="5" rx="2" fill={PALETTE.ink5}/>
              </g>
            ))}
            {/* customer panel */}
            <rect x="486" y="142" width="98" height="60" rx="4" fill={PALETTE.paper2} stroke={PALETTE.rule} strokeWidth="0.5"/>
            <rect x="494" y="152" width="60" height="6" rx="2" fill={PALETTE.ink2}/>
            {[164, 172, 180, 188].map((y, i) => (
              <rect key={i} x="494" y={y} width={[80,70,64,40][i]} height="4" rx="2" fill={PALETTE.ink5}/>
            ))}
            {/* THE BUTTON */}
            <rect x="148" y="258" width="324" height="40" rx="6" fill={PALETTE.honey} stroke={PALETTE.honeyLn} strokeWidth="1"/>
            <text x="310" y="283" fontFamily="Geist, sans-serif" fontSize="13" fill={PALETTE.ink} textAnchor="middle" fontWeight="600">Print label</text>
            {(animate || staticPose) && (
              <circle cx="360" cy="268" r={staticPose ? "14" : "6"} fill="none" stroke={PALETTE.honeyDk} strokeWidth="1.5" opacity={staticPose ? "0.85" : "0"}>
                {animate && <animate attributeName="r" values="6;30;30" keyTimes="0;0.6;1" dur="6s" repeatCount="indefinite"/>}
                {animate && <animate attributeName="opacity" values="0;0.7;0;0;0;0" keyTimes="0;0.05;0.25;0.4;0.7;1" dur="6s" repeatCount="indefinite"/>}
              </circle>
            )}
            {/* cursor */}
            <g transform="translate(360, 268)">
              <path d="M 0 0 L 0 14 L 4 10 L 7 16 L 9 15 L 6 9 L 11 9 Z" fill={PALETTE.ink} stroke={PALETTE.paper} strokeWidth="0.8"/>
              {animate && (
                <animateTransform attributeName="transform" type="translate"
                                  values="360 268; 360 268; 356 264; 360 268; 360 268; 360 268"
                                  keyTimes="0; 0.1; 0.13; 0.16; 0.5; 1" dur="6s" repeatCount="indefinite"/>
              )}
            </g>
            <rect x="44" y="36" width="544" height="300" fill="url(#a6-1-sheen)" opacity="0.4"/>
          </g>
          <rect x="304" y="340" width="48" height="2" rx="1" fill={PALETTE.ink4}/>
        </g>

        {/* flying label with face — static pose freezes at midpoint of arc */}
        <g>
          <g transform={staticPose ? "translate(670, 195)" : "translate(400, 330)"}>
            {animate && (
              <animateTransform attributeName="transform" type="translate"
                                values="400 330; 400 330; 490 270; 610 210; 730 180; 830 168; 850 168; 850 168"
                                keyTimes="0; 0.18; 0.30; 0.42; 0.55; 0.65; 0.74; 1" dur="6s" repeatCount="indefinite"/>
            )}
            <g>
              {animate && (
                <animateTransform attributeName="transform" type="rotate"
                                  values="0; 0; -8; -3; 4; 0; 0; 0"
                                  keyTimes="0; 0.18; 0.30; 0.45; 0.6; 0.7; 0.74; 1" dur="6s" repeatCount="indefinite"/>
              )}
              <g transform="translate(-32, -42)">
                <rect x="2" y="3" width="64" height="84" rx="3" fill={PALETTE.ink} opacity="0.12"/>
                <rect x="0" y="0" width="64" height="84" rx="3" fill="#FAFAF7" stroke={PALETTE.ink} strokeWidth="1.1"/>
                <line x1="0" y1="16" x2="64" y2="16" stroke={PALETTE.ink4} strokeWidth="0.5" strokeDasharray="2 2"/>
                <text x="5" y="11" fontFamily="Geist Mono, monospace" fontSize="5.5" fill={PALETTE.ink3} letterSpacing="0.1em">USPS PRIORITY</text>
                <rect x="5" y="20" width="44" height="2.5" rx="1" fill={PALETTE.ink}/>
                <g transform="translate(6, 30)">
                  {[0,2,5,7,10,12,15,17,19,22,25,28,30,33,36,38,41,44,47,50].map((x, i) => (
                    <rect key={i} x={x} y="0" width={i % 3 === 0 ? 1.6 : 0.8} height="18" fill={PALETTE.ink}/>
                  ))}
                </g>
                <text x="32" y="60" fontFamily="Geist Mono, monospace" fontSize="4.5" fill={PALETTE.ink3} textAnchor="middle">9405 5036 9930 0042 1815</text>
                <rect x="5" y="65" width="54" height="13" rx="1.5" fill={PALETTE.paper3}/>
                <text x="32" y="74" fontFamily="Geist Mono, monospace" fontSize="5" fill={PALETTE.ink3} textAnchor="middle">2 LB · 4×6</text>
                <Face cx={48} cy={6} r={4.5}/>
              </g>
            </g>
          </g>
        </g>

        {/* SMALL EXTENSION CARD — floating off from extension manager strip
            Monitor at translate(90, 80). Chip absolute = (90+458+34+5.5, 80+42+8) = (587.5, 130).
            Card at translate(790, 140). Leader path stays relative — both groups shifted same +30. */}
        <g transform="translate(790, 140)">
          <path d="M 0 8 Q -100 -10 -208 -2"
                fill="none" stroke={PALETTE.honeyLn} strokeWidth="1.2" strokeDasharray="3 3" opacity="0.85"/>

          {/* card — catch-glow shown at peak in static pose */}
          {(animate || staticPose) && (
            <circle cx="40" cy="40" r={staticPose ? "44" : "32"} fill={PALETTE.honey} opacity={staticPose ? "0.18" : "0"}>
              {animate && <animate attributeName="opacity" values="0;0;0.18;0;0;0" keyTimes="0;0.55;0.65;0.75;0.95;1" dur="6s" repeatCount="indefinite"/>}
              {animate && <animate attributeName="r" values="32;32;46;42;42;42" keyTimes="0;0.55;0.7;0.85;1;1" dur="6s" repeatCount="indefinite"/>}
            </circle>
          )}
          <rect x="2" y="3" width="100" height="100" rx="18" fill={PALETTE.ink} opacity="0.12"/>
          <rect x="0" y="0" width="100" height="100" rx="18" fill={PALETTE.ink} stroke={PALETTE.honeyLn} strokeWidth="0.8"/>

          {/* AP favicon mark — same as the extension chip */}
          <g transform="translate(20, 18)">
            <APMarkV5 x={0} y={0} size={60} bg={PALETTE.honey} rx="12"/>
          </g>

          {/* status pill */}
          <rect x="10" y="78" width="80" height="14" rx="7" fill={PALETTE.paper}/>
          <circle cx="20" cy="85" r="2.8" fill={PALETTE.ok}>
            {animate && <animate attributeName="opacity" values="1;0.4;1" dur="1.4s" repeatCount="indefinite"/>}
          </circle>
          <text x="29" y="88" fontFamily="Geist Mono, monospace" fontSize="7" fill={PALETTE.ink3} letterSpacing="0.1em" fontWeight="600">LISTENING</text>

          {/* nameplate UNDER */}
          <Tag x={50} y={120} text="BROWSER EXTENSION" anchor="middle" color={PALETTE.ink2} size={10} weight={600}/>
        </g>

        {/* arc — subtle dashed handoff from screen → extension card */}
        <path d="M 400 330 Q 570 180 790 158" fill="none" stroke={PALETTE.honeyLn} strokeWidth="1.2" strokeDasharray="4 4" opacity="0.45"/>

        {annotated && (
          <>
            <Annotation x={122} y={66} label="4.1 · PRINT LABEL" body={["Print labels from any computer —", "in bulk or from an order's detail page."]}/>
            <Annotation x={890} y={66} label="4.2 · INTERCEPT & ROUTE" body={["Autoprinter's browser extension intercepts the PDF and forwards it", "to the right print station — no extra clicks needed."]} anchor="right"/>
          </>
        )}
      </svg>
    </div>
  );
};


/* ------------------------------------------------------------
   A6_DocumentIntercept — top: bulk list w/ Auto Print menu in
   header. Bottom: order detail w/ a SINGLE Auto Print button
   in the upper-right of the page.
------------------------------------------------------------ */
const A6_DocumentIntercept = ({ motion = true, annotated = true, showLabels = true, staticPose = false }) => {
  const W = 1000, H = 600;
  const animate = motion && !staticPose;
  const AP = PALETTE.honey;
  const APln = PALETTE.honeyLn;
  return (
    <div style={{ width: "100%", aspectRatio: `${W} / ${H}` }}>
      <svg viewBox={`0 0 ${W} ${H}`} width="100%" height="100%" style={{ display: "block", overflow: "visible" }}>
        <defs>
          <clipPath id="a6-2-list"><rect x="40" y="69" width="500" height="220" rx="6"/></clipPath>
          <clipPath id="a6-2-detail"><rect x="40" y="352" width="500" height="220" rx="6"/></clipPath>
          <linearGradient id="a6-2-bg" x1="0" x2="0" y1="0" y2="1">
            <stop offset="0" stopColor={PALETTE.paper}/><stop offset="1" stopColor={PALETTE.paper2}/>
          </linearGradient>
        </defs>
        <rect width={W} height={H} fill="url(#a6-2-bg)"/>

        {showLabels && (
          <Tag x={960} y={36} text="02 · AUTO PRINT DOCUMENTS" color={PALETTE.honeyDk} size={14} weight={600} anchor="end"/>
        )}

        {/* TOP: bulk list — translated up 27px so top/middle/bottom WS are all ~27px */}
        <g transform="translate(0, -27)">
          <Tag x={40} y={64} text="2.1 · BULK PRINT FROM ORDER LIST" color={PALETTE.honeyDk} size={11} weight={700}/>
          <text x="40" y="78" fontFamily="Geist, sans-serif" fontSize="11" fill={PALETTE.ink4}>Select orders, hit Autoprint — every selected order's docs are queued at once.</text>
          <rect x="40" y="96" width="500" height="220" rx="6" fill={PALETTE.paper} stroke={PALETTE.ink} strokeWidth="1.2"/>
          <rect x="40" y="96" width="500" height="22" fill={PALETTE.paper2}/>
          <text x="290" y="111" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink4} textAnchor="middle">admin.shopify.com/orders</text>
          <g clipPath="url(#a6-2-list)">
            <text x="56" y="138" fontFamily="Geist, sans-serif" fontSize="11" fill={PALETTE.ink} fontWeight="600">Orders</text>
            <rect x="56" y="148" width="468" height="22" rx="3" fill={PALETTE.honeySf} stroke={APln} strokeWidth="0.6"/>
            <rect x="64" y="156" width="10" height="6" rx="1" fill={PALETTE.honeyDk}/>
            <text x="80" y="162" fontFamily="Geist, sans-serif" fontSize="9" fill={PALETTE.ink} fontWeight="600">3 selected</text>
            {/* Auto Print button on the bulk row */}
            <g transform="translate(412, 150)">
              <rect x="0" y="0" width="108" height="20" rx="4" fill={AP} stroke={APln} strokeWidth="1"/>
              <APMarkV5 x={3} y={2} size={16} bg={AP} rx="3"/>
              <text x="62" y="13" fontFamily="Geist, sans-serif" fontSize="10" fill={PALETTE.ink} textAnchor="middle" fontWeight="700">Autoprint ▾</text>
              {(animate || staticPose) && (
                <circle cx="62" cy="10" r={staticPose ? "14" : "6"} fill="none" stroke={APln} strokeWidth="1.5" opacity={staticPose ? "0.7" : "0"}>
                  {animate && <animate attributeName="r" values="6;30;30" keyTimes="0;0.5;1" dur="5s" repeatCount="indefinite"/>}
                  {animate && <animate attributeName="opacity" values="0;0;0.85;0;0;0" keyTimes="0;0.05;0.1;0.3;0.7;1" dur="5s" repeatCount="indefinite"/>}
                </circle>
              )}
            </g>
            {[0, 1, 2, 3].map((i) => {
              const y = 178 + i * 28;
              const checked = i < 3;
              return (
                <g key={i}>
                  <rect x="56" y={y} width="468" height="26" fill={i % 2 ? PALETTE.paper2 : PALETTE.paper}/>
                  <rect x="64" y={y + 10} width="8" height="8" rx="1" fill={checked ? PALETTE.ink : PALETTE.paper} stroke={PALETTE.ink} strokeWidth="0.6"/>
                  {checked && <path d={`M 65 ${y + 14} L 67 ${y + 16} L 71 ${y + 12}`} fill="none" stroke={PALETTE.paper} strokeWidth="1"/>}
                  <text x="80" y={y + 17} fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink2}>#104{2+i}</text>
                  <text x="120" y={y + 17} fontFamily="Geist, sans-serif" fontSize="8" fill={PALETTE.ink3}>{["Ada Lovelace", "Bea Tran", "Carlos Reyes", "Dani Park"][i]}</text>
                  <rect x="240" y={y + 8} width="32" height="11" rx="5" fill={PALETTE.ok} opacity="0.18"/>
                  <text x="256" y={y + 16} fontFamily="Geist, sans-serif" fontSize="6.5" fill={PALETTE.ok} textAnchor="middle" fontWeight="600">PAID</text>
                  <text x="476" y={y + 17} fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink3} textAnchor="end">${[42,128,76,210][i]}.00</text>
                </g>
              );
            })}
          </g>
        </g>

        {/* BOTTOM: detail — ONE Auto Print button, upper right.
            Translated up 6px to balance with block-1 shift; final layout has
            ~27px of whitespace at top, between the two blocks, and at bottom. */}
        <g transform="translate(0, -6)">
          <Tag x={40} y={332} text="2.2 · PRINT ONE ORDER, FROM DETAIL" color={PALETTE.honeyDk} size={11} weight={700}/>
          <text x="40" y="346" fontFamily="Geist, sans-serif" fontSize="11" fill={PALETTE.ink4}>Open an order, hit Autoprint — just that order's docs go through.</text>
          <rect x="40" y="358" width="500" height="220" rx="6" fill={PALETTE.paper} stroke={PALETTE.ink} strokeWidth="1.2"/>
          <rect x="40" y="358" width="500" height="22" fill={PALETTE.paper2}/>
          <text x="290" y="373" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink4} textAnchor="middle">admin.shopify.com/orders/#1042</text>
          <g clipPath="url(#a6-2-detail)">
            {/* page header row */}
            <text x="56" y="400" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink3}>#1042</text>
            <rect x="86" y="392" width="32" height="11" rx="5" fill={PALETTE.ok} opacity="0.18"/>
            <text x="102" y="400" fontFamily="Geist, sans-serif" fontSize="6.5" fill={PALETTE.ok} textAnchor="middle" fontWeight="600">PAID</text>

            {/* ONE Auto Print button — upper right.
                Sized to match the bulk Auto Print button exactly (108×20)
                AND right-aligned with it: both have their right edge at x=520. */}
            <g transform="translate(412, 390)">
              <rect x="0" y="0" width="108" height="20" rx="4" fill={AP} stroke={APln} strokeWidth="1"/>
              <APMarkV5 x={3} y={2} size={16} bg={AP} rx="3"/>
              <text x="62" y="13" fontFamily="Geist, sans-serif" fontSize="10" fill={PALETTE.ink} textAnchor="middle" fontWeight="700">Autoprint ▾</text>
              {(animate || staticPose) && (
                <circle cx="62" cy="10" r={staticPose ? "14" : "6"} fill="none" stroke={APln} strokeWidth="1.5" opacity={staticPose ? "0.7" : "0"}>
                  {animate && <animate attributeName="r" values="6;30;30" keyTimes="0;0.55;1" dur="5s" repeatCount="indefinite" begin="1.5s"/>}
                  {animate && <animate attributeName="opacity" values="0;0;0.85;0;0;0" keyTimes="0;0.05;0.1;0.3;0.7;1" dur="5s" repeatCount="indefinite" begin="1.5s"/>}
                </circle>
              )}
            </g>

            {/* page body */}
            <rect x="56" y="424" width="220" height="8" rx="2" fill={PALETTE.ink}/>
            <rect x="56" y="438" width="160" height="5" rx="2" fill={PALETTE.ink5}/>

            {/* line items column */}
            <rect x="56" y="454" width="320" height="48" rx="4" fill={PALETTE.paper2} stroke={PALETTE.rule} strokeWidth="0.5"/>
            <rect x="64" y="462" width="28" height="32" rx="3" fill={PALETTE.paper4}/>
            <rect x="100" y="466" width="120" height="6" rx="2" fill={PALETTE.ink2}/>
            <rect x="100" y="478" width="80" height="5" rx="2" fill={PALETTE.ink5}/>

            <rect x="56" y="510" width="320" height="48" rx="4" fill={PALETTE.paper2} stroke={PALETTE.rule} strokeWidth="0.5"/>
            <rect x="64" y="518" width="28" height="32" rx="3" fill={PALETTE.paper4}/>
            <rect x="100" y="522" width="100" height="6" rx="2" fill={PALETTE.ink2}/>
            <rect x="100" y="534" width="60" height="5" rx="2" fill={PALETTE.ink5}/>

            {/* customer panel right */}
            <rect x="396" y="454" width="128" height="100" rx="4" fill={PALETTE.paper2} stroke={PALETTE.rule} strokeWidth="0.5"/>
            <rect x="404" y="464" width="60" height="6" rx="2" fill={PALETTE.ink2}/>
            {[0, 1, 2, 3, 4].map((i) => (
              <rect key={i} x="404" y={480 + i * 10} width={[80,70,60,40,52][i]} height="4" rx="2" fill={PALETTE.ink5}/>
            ))}
          </g>
        </g>

        {/* AUTOPRINTER — right side. Lowered to translate(620, 244) so the
            2.3 label + wrapped body sits comfortably above it AND the whole
            (text + object + cog cluster) group reads as roughly centered
            vertically on the slide.
            Right-half body now hosts a small horizontal routing decision tree
            (source dot → 3 destination circles) so the visual matches the
            "QUEUES + ROUTES" label.
            3-cog cluster (big + medium + small, interlocking, varying spin
            speeds + directions) bleeds past the object's bottom-right corner
            for that "machinery in motion" feel. */}
        <g transform="translate(620, 244)">
          <rect x="-3" y="3" width="320" height="150" rx="14" fill={PALETTE.ink} opacity="0.12"/>
          <rect x="0" y="0" width="320" height="150" rx="14" fill={PALETTE.ink}/>
          <rect x="0" y="0" width="320" height="34" rx="14" fill={AP}/>
          <rect x="0" y="20" width="320" height="14" fill={AP}/>
          <APMarkV5 x={10} y={6} size={22} bg={AP} rx="4"/>
          <text x="40" y="22" fontFamily="Geist Mono, monospace" fontSize="11" fill={PALETTE.ink} fontWeight="700" letterSpacing="0.16em">AUTOPRINTER</text>
          <text x="310" y="22" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink} textAnchor="end" letterSpacing="0.12em" fontWeight="600">SHOPIFY APP</text>

          {/* Queue panel — left side of body. */}
          <rect x="20" y="46" width="160" height="80" rx="6" fill={PALETTE.ink2} stroke={PALETTE.ink3} strokeWidth="0.5"/>
          <text x="28" y="60" fontFamily="Geist Mono, monospace" fontSize="8" fill={PALETTE.ink5} letterSpacing="0.1em" fontWeight="600">Queued</text>
          <g transform="translate(28, 66)">
            {[
              ["#1042 · Packing Slip", 0],
              ["#1042 · Invoice", 1],
              ["#1043 · Packing Slip", 2],
              ["#1044 · Packing Slip", 3],
            ].map(([label, i]) => (
              <g key={i} transform={`translate(0, ${i * 13})`}>
                <rect x="0" y="0" width="144" height="11" rx="2" fill={PALETTE.ink}/>
                <circle cx="6" cy="5.5" r="2" fill={AP}>
                  {animate && <animate attributeName="opacity" values="1;0.3;1" dur="1.4s" repeatCount="indefinite" begin={`${i * 0.2}s`}/>}
                </circle>
                <text x="14" y="8" fontFamily="Geist Mono, monospace" fontSize="7" fill={PALETTE.ink5}>{label}</text>
              </g>
            ))}
          </g>

          {/* Routing decision tree — right of queue. 2-layer-deep asymmetric
              tree: layer-1 root → 2 layer-2 nodes → 2 layer-3 nodes (both
              branching off the BOTTOM layer-2 node only, not the top one).
              Layers spaced 47px apart so the tree spans more of the cavity:
              ~10px gap from queue's right edge AND ~10px gap from the cog
              cluster's left edge. Tree visibly fills the available space. */}
          <g>
            {/* Layer 1 — root */}
            <circle cx="190" cy="86" r="3" fill={AP}/>
            {/* Layer 1 → Layer 2 connections */}
            <path d="M 193 86 L 234 72" stroke={PALETTE.honeyLn} strokeWidth="0.8" strokeDasharray="2 2" fill="none" opacity="0.75"/>
            <path d="M 193 86 L 234 100" stroke={PALETTE.honeyLn} strokeWidth="0.8" strokeDasharray="2 2" fill="none" opacity="0.75"/>
            {/* Layer 2 — 2 nodes */}
            <circle cx="237" cy="72" r="3.5" fill="none" stroke={AP} strokeWidth="1.2"/>
            <circle cx="237" cy="100" r="3.5" fill="none" stroke={AP} strokeWidth="1.2"/>
            {/* Layer 2 (bottom node only) → Layer 3 connections */}
            <path d="M 240 100 L 281 92" stroke={PALETTE.honeyLn} strokeWidth="0.8" strokeDasharray="2 2" fill="none" opacity="0.75"/>
            <path d="M 240 100 L 281 110" stroke={PALETTE.honeyLn} strokeWidth="0.8" strokeDasharray="2 2" fill="none" opacity="0.75"/>
            {/* Layer 3 — 2 nodes */}
            <circle cx="284" cy="92" r="3.5" fill="none" stroke={AP} strokeWidth="1.2"/>
            <circle cx="284" cy="110" r="3.5" fill="none" stroke={AP} strokeWidth="1.2"/>
          </g>

          {/* 3-cog cluster — floating over the lower-right corner.
              Formation: Big (upper-left), Small (middle-right), Medium (lower-left).
              Big touches Small; Medium touches Small; Big and Medium do NOT
              touch (small sits between them, meshing with both).
              Gear physics: Big CW, Small CCW (driven by Big), Medium CW
              (driven by Small). Speeds inversely proportional to radius. */}
          {/* Big cog — visual r=14, clockwise 5s */}
          <g transform="translate(311, 140)">
            <g>
              {animate && <animateTransform attributeName="transform" type="rotate" from="0" to="360" dur="5s" repeatCount="indefinite"/>}
              {[0, 45, 90, 135, 180, 225, 270, 315].map((angle) => (
                <rect key={angle} x="-2" y="-14" width="4" height="6" rx="1" fill={AP} transform={`rotate(${angle})`}/>
              ))}
              <circle cx="0" cy="0" r="9" fill="none" stroke={AP} strokeWidth="2"/>
              <circle cx="0" cy="0" r="3" fill={AP}/>
            </g>
          </g>
          {/* Small cog — visual r=7, counter-clockwise 2.5s. Sits between
              Big and Medium, meshing with both. */}
          <g transform="translate(326, 151)">
            <g>
              {animate && <animateTransform attributeName="transform" type="rotate" from="0" to="-360" dur="2.5s" repeatCount="indefinite"/>}
              {[0, 60, 120, 180, 240, 300].map((angle) => (
                <rect key={angle} x="-1" y="-7" width="2" height="3" rx="0.5" fill={AP} transform={`rotate(${angle})`}/>
              ))}
              <circle cx="0" cy="0" r="4.5" fill="none" stroke={AP} strokeWidth="1.2"/>
              <circle cx="0" cy="0" r="1.5" fill={AP}/>
            </g>
          </g>
          {/* Medium cog — visual r=10, clockwise 3.5s */}
          <g transform="translate(316, 163)">
            <g>
              {animate && <animateTransform attributeName="transform" type="rotate" from="0" to="360" dur="3.5s" repeatCount="indefinite"/>}
              {[0, 45, 90, 135, 180, 225, 270, 315].map((angle) => (
                <rect key={angle} x="-1.5" y="-10" width="3" height="4" rx="0.5" fill={AP} transform={`rotate(${angle})`}/>
              ))}
              <circle cx="0" cy="0" r="6.5" fill="none" stroke={AP} strokeWidth="1.5"/>
              <circle cx="0" cy="0" r="2" fill={AP}/>
            </g>
          </g>
        </g>

        {/* 3.3 annotation rendered BEFORE the flying docs so the docs paint
            on top as they cross the text block area. */}
        {annotated && (
          <g>
            <Tag x={940} y={200} anchor="end" text="2.3 · AUTOPRINTER QUEUES + ROUTES" color={PALETTE.honeyDk} size={11} weight={700}/>
            <text x="940" y="214" fontFamily="Geist, sans-serif" fontSize="11" fill={PALETTE.ink4} textAnchor="end">Print jobs are routed to Autoprinter for template</text>
            <text x="940" y="228" fontFamily="Geist, sans-serif" fontSize="11" fill={PALETTE.ink4} textAnchor="end">selection and print routing.</text>
          </g>
        )}

        {/* PAYLOADS IN FLIGHT */}
        <g>
          {/* slip stack from list — 3 docs (3 were selected).
              Spawn at right edge of bulk Auto Print button. Click peaks at
              t=0.10 → fade in 0.13-0.16 → straight steady-pace flight from
              start to the middle of the autoprinter object (780, 319) over
              0.20-0.62 → land + fade out. */}
          <g transform="translate(550, 133)">
            {animate && (
              <animateTransform attributeName="transform" type="translate"
                                values="550 133; 550 133; 780 319; 780 319"
                                keyTimes="0; 0.20; 0.62; 1" dur="5s" repeatCount="indefinite"/>
            )}
            <g transform="translate(-30, -38)" opacity={staticPose ? "1" : "0"}>
              {animate && (
                <animate attributeName="opacity"
                         values="0; 0; 1; 1; 0; 0"
                         keyTimes="0; 0.13; 0.16; 0.74; 0.80; 1"
                         dur="5s" repeatCount="indefinite"/>
              )}
              {/* back page #3 — just an outline, no content */}
              <rect x="8" y="6" width="60" height="76" rx="2" fill={PALETTE.ink} opacity="0.08"/>
              <rect x="6" y="4" width="60" height="76" rx="2" fill="#FAFAF7" stroke={PALETTE.ink} strokeWidth="1"/>
              {/* middle page #2 — outline */}
              <rect x="5" y="3" width="60" height="76" rx="2" fill={PALETTE.ink} opacity="0.08"/>
              <rect x="3" y="2" width="60" height="76" rx="2" fill="#FAFAF7" stroke={PALETTE.ink} strokeWidth="1"/>
              {/* front page — full content */}
              <rect x="2" y="3" width="60" height="76" rx="2" fill={PALETTE.ink} opacity="0.1"/>
              <rect x="0" y="0" width="60" height="76" rx="2" fill="#FAFAF7" stroke={PALETTE.ink} strokeWidth="1"/>
              <text x="6" y="12" fontFamily="Geist Mono, monospace" fontSize="5" fill={PALETTE.ink3}>PACKING SLIP · #1042</text>
              <rect x="6" y="18" width="36" height="2" fill={PALETTE.ink}/>
              {[24, 28, 32, 36, 40, 46, 50, 54].map((y, i) => (
                <rect key={i} x="6" y={y} width={[40, 34, 38, 30, 20, 36, 32, 28][i]} height="1.5" fill={i < 5 ? PALETTE.ink5 : PALETTE.ink4}/>
              ))}
              <rect x="6" y="60" width="48" height="12" rx="1" fill={PALETTE.paper3}/>
              <Face cx={50} cy={9} r={4.5}/>
              {/* "×3" badge to make the multiplicity unmistakable */}
              <g transform="translate(54, 70)">
                <circle cx="0" cy="0" r="9" fill={PALETTE.honey} stroke={PALETTE.ink} strokeWidth="0.8"/>
                <text x="0" y="3" fontFamily="Geist Mono, monospace" fontSize="9" fill={PALETTE.ink} textAnchor="middle" fontWeight="700">×3</text>
              </g>
            </g>
          </g>
          {/* slip from detail (Auto Print upper right).
              Spawn at right edge of detail Auto Print button. Click peaks at
              t=0.40 (begin=1.5s on a 5s cycle) → fade in 0.42-0.46 → straight
              steady-pace flight from start to the middle of the autoprinter
              object (780, 319) over 0.50-0.85 → land + fade out. */}
          <g transform="translate(550, 395)">
            {animate && (
              <animateTransform attributeName="transform" type="translate"
                                values="550 395; 550 395; 780 319; 780 319"
                                keyTimes="0; 0.50; 0.85; 1" dur="5s" repeatCount="indefinite"/>
            )}
            <g transform="translate(-30, -38)" opacity={staticPose ? "1" : "0"}>
              {animate && (
                <animate attributeName="opacity"
                         values="0; 0; 1; 1; 0; 0"
                         keyTimes="0; 0.42; 0.46; 0.95; 0.99; 1"
                         dur="5s" repeatCount="indefinite"/>
              )}
              <rect x="2" y="3" width="60" height="76" rx="2" fill={PALETTE.ink} opacity="0.1"/>
              <rect x="0" y="0" width="60" height="76" rx="2" fill="#FAFAF7" stroke={PALETTE.ink} strokeWidth="1"/>
              <text x="6" y="12" fontFamily="Geist Mono, monospace" fontSize="5" fill={PALETTE.ink3}>INVOICE · #1042</text>
              <rect x="6" y="18" width="40" height="2" fill={PALETTE.ink}/>
              {[24, 28, 32, 36, 40, 46, 50, 54].map((y, i) => (
                <rect key={i} x="6" y={y} width={[42, 30, 38, 26, 18, 32, 36, 30][i]} height="1.5" fill={i < 5 ? PALETTE.ink5 : PALETTE.ink4}/>
              ))}
              <rect x="6" y="60" width="48" height="12" rx="1" fill={PALETTE.paper3}/>
            </g>
          </g>
        </g>

        {/* Static-pose arrows: documents → AUTOPRINTER, fan-in style.
            Top arrow points at AUTOPRINTER's upper-left corner area; bottom
            arrow points at lower-left corner area. Both angle inward toward
            the box. (Replaces an earlier "both aim at the visual center"
            version that looked unbalanced because the top doc is far above
            the box while the bottom doc sits right at its bottom edge.)
            Tips terminate 5px short of the box's left edge (x=620).
            Dashed honey line + open chevron tip — matches the visual
            vocabulary of the existing connector arrows + routing-tree
            dashed connectors. Only rendered in static-pose mode (the
            animated version has the flying docs themselves performing
            the "direction-of-flow" job). */}
        {staticPose && (
          <g>
            {/* top: bulk slip stack at (550, 133) → tip at AUTOPRINTER top edge near left corner (625, 240) */}
            <path d="M 580 133 L 625 240" fill="none" stroke={PALETTE.honeyLn} strokeWidth="1.4" strokeDasharray="4 3"/>
            <path d="M 625 240 L 626 234 M 625 240 L 620 236" fill="none" stroke={PALETTE.honeyLn} strokeWidth="1.4" strokeLinecap="round"/>
            {/* bottom: detail slip at (550, 395) → tip at lower-left corner area (615, 378) */}
            <path d="M 580 395 L 615 378" fill="none" stroke={PALETTE.honeyLn} strokeWidth="1.4" strokeDasharray="4 3"/>
            <path d="M 615 378 L 609 378 M 615 378 L 612 383" fill="none" stroke={PALETTE.honeyLn} strokeWidth="1.4" strokeLinecap="round"/>
          </g>
        )}

      </svg>
    </div>
  );
};


Object.assign(window, {
  A7_TemplatesAndRouting: A6_TemplatesAndRouting,
  A7_LabelIntercept: A6_LabelIntercept,
  A7_DocumentIntercept: A6_DocumentIntercept,
  APMarkV5,
});
