<!-- LEGO1 CAR — Simplex Generator (Embed Block Only) -->
<section id="simplex-generator"
  data-studio-io-url=""
  data-wanted-xml-url=""
  data-instructions-url=""
>
  <style>
    /* ====== ROOT / THEME (Fiesta + non-white background) ====== */
    #simplex-generator{
      --bg1:#0b2a2a;
      --bg2:#1b3a57;
      --card:#0f2430;
      --card2:#102b2b;
      --ink:#f6fbff;
      --muted:#cfe6ff;
      --line:rgba(255,255,255,.14);
      --accent:#ffd166;   /* fiesta gold */
      --accent2:#ef476f;  /* fiesta pink */
      --accent3:#06d6a0;  /* fiesta mint */
      --accent4:#118ab2;  /* fiesta blue */
      --shadow: 0 14px 34px rgba(0,0,0,.35);
      --radius:18px;
      --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      --sans: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
      background:
        radial-gradient(1200px 700px at 20% 0%, rgba(255,209,102,.22), transparent 60%),
        radial-gradient(900px 600px at 90% 15%, rgba(239,71,111,.18), transparent 55%),
        radial-gradient(1000px 700px at 40% 95%, rgba(6,214,160,.18), transparent 60%),
        linear-gradient(145deg, var(--bg1), var(--bg2));
      color:var(--ink);
      border-radius:22px;
      padding:16px;
      font-family:var(--sans);
      box-shadow: var(--shadow);
      position: relative;
      overflow:hidden;
    }
    #simplex-generator *{ box-sizing:border-box; }
    #simplex-generator a{ color: var(--accent); text-decoration: none; }
    #simplex-generator a:hover{ text-decoration: underline; }

    /* ====== HEADER / BANNER ====== */
    .sx-header{
      display:flex;
      flex-direction:column;
      gap:10px;
      padding:10px 10px 6px;
    }
    .sx-hero{
      width:100%;
      border-radius: 18px;
      overflow:hidden;
      border:1px solid var(--line);
      background: rgba(0,0,0,.18);
    }
    .sx-hero img{
      width:100%;
      height:auto;
      display:block;
      object-fit:contain; /* no crop */
      background: rgba(0,0,0,.22);
    }
    .sx-titleRow{
      display:flex;
      flex-wrap:wrap;
      align-items:flex-start;
      justify-content:space-between;
      gap:10px;
      padding:2px 2px 0;
    }
    h1.sx-title{
      margin:0;
      font-size: clamp(20px, 3.2vw, 34px);
      line-height:1.08;
      letter-spacing:.2px;
    }
    .sx-badges{
      display:flex;
      gap:8px;
      flex-wrap:wrap;
      align-items:center;
      justify-content:flex-end;
    }
    .pill{
      display:inline-flex;
      align-items:center;
      gap:8px;
      padding:8px 10px;
      border-radius:999px;
      border:1px solid var(--line);
      background: rgba(255,255,255,.08);
      font-size:12px;
      color: var(--muted);
      white-space:nowrap;
    }
    .pill strong{ color: var(--ink); font-weight:700; }
    .statusPill{
      border-color: rgba(255,209,102,.45);
      background: rgba(255,209,102,.10);
    }
    .statusDot{
      width:9px; height:9px; border-radius:50%;
      background: var(--accent);
      box-shadow: 0 0 0 4px rgba(255,209,102,.18);
      flex: 0 0 auto;
    }
    .realBuildPill{
      border-color: rgba(6,214,160,.45);
      background: rgba(6,214,160,.10);
    }

    /* ====== TOOLBAR ====== */
    .sx-toolbar{
      display:flex;
      flex-wrap:wrap;
      gap:10px;
      align-items:center;
      justify-content:space-between;
      padding: 10px;
      border-radius: 16px;
      border:1px solid var(--line);
      background: rgba(0,0,0,.18);
      margin: 8px 10px 12px;
    }
    .sx-toolbar-left{
      display:flex; gap:12px; flex-wrap:wrap; align-items:center;
      font-size:13px; color: var(--muted);
    }
    .sx-toolbar-right{
      display:flex; gap:8px; flex-wrap:wrap; align-items:center;
    }
    .sx-btn{
      appearance:none;
      border:1px solid var(--line);
      background: rgba(255,255,255,.10);
      color: var(--ink);
      border-radius: 12px;
      padding: 10px 12px;
      font-weight:700;
      cursor:pointer;
      transition: transform .06s ease, background .15s ease, border-color .15s ease;
      font-size: 13px;
    }
    .sx-btn:hover{ background: rgba(255,255,255,.14); }
    .sx-btn:active{ transform: translateY(1px); }
    .sx-btn.primary{
      border-color: rgba(6,214,160,.55);
      background: rgba(6,214,160,.14);
    }
    .sx-btn.warn{
      border-color: rgba(239,71,111,.55);
      background: rgba(239,71,111,.12);
    }
    .sx-btn.gold{
      border-color: rgba(255,209,102,.6);
      background: rgba(255,209,102,.14);
      color: #0b1a1a;
    }

    /* ====== LAYOUT ====== */
    .sx-grid{
      display:grid;
      grid-template-columns: 380px 1fr;
      gap: 12px;
      padding: 0 10px 12px;
    }
    @media (max-width: 980px){
      .sx-grid{ grid-template-columns: 1fr; }
      .sx-sticky{ position: static !important; top:auto !important; }
    }

    /* ====== LEFT: CONTROLS ====== */
    .sx-card{
      border:1px solid var(--line);
      border-radius: var(--radius);
      background: rgba(0,0,0,.18);
      box-shadow: 0 10px 22px rgba(0,0,0,.22);
    }
    .sx-card .sx-card-h{
      padding: 14px 14px 10px;
      border-bottom: 1px solid var(--line);
      display:flex;
      align-items:flex-start;
      justify-content:space-between;
      gap:10px;
    }
    .sx-card .sx-card-h h2{
      margin:0;
      font-size: 14px;
      letter-spacing:.4px;
      text-transform: uppercase;
      color: var(--muted);
    }
    .sx-card .sx-card-b{
      padding: 12px 14px 14px;
    }
    .sx-sticky{
      position: sticky;
      top: 14px;
      align-self: start;
    }
    .sx-help{
      font-size: 13px;
      color: var(--muted);
      display:flex;
      gap:10px;
      flex-wrap:wrap;
      align-items:center;
      justify-content:flex-start;
      margin: 0 10px 6px;
      padding: 0 2px;
    }
    .sx-callout{
      margin: 10px 0 0;
      padding: 10px 12px;
      border-radius: 14px;
      border:1px dashed rgba(255,255,255,.22);
      background: rgba(0,0,0,.14);
      color: var(--muted);
      font-size: 12.5px;
      line-height: 1.35;
    }
    .sx-callout strong{ color: var(--ink); }
    .sx-field{
      display:grid;
      gap:6px;
      margin: 10px 0;
    }
    .sx-field label{
      font-size: 12px;
      color: var(--muted);
    }
    .sx-field select, .sx-field input{
      width:100%;
      padding: 10px 10px;
      border-radius: 12px;
      border:1px solid rgba(255,255,255,.18);
      background: rgba(0,0,0,.22);
      color: var(--ink);
      outline:none;
      font-size: 13px;
    }
    .sx-row{
      display:grid;
      grid-template-columns: 1fr 1fr;
      gap:10px;
    }
    .sx-actions{
      display:flex;
      gap:10px;
      flex-wrap:wrap;
      margin-top: 12px;
    }

    /* ====== RIGHT: OUTPUTS ====== */
    .sx-right{
      display:grid;
      gap: 12px;
    }
    .out-grid{
      display:grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
    }
    @media (max-width: 980px){
      .out-grid{ grid-template-columns: 1fr; }
    }
    .outbox{
      border:1px solid var(--line);
      border-radius: var(--radius);
      background: rgba(0,0,0,.18);
      overflow:hidden;
      box-shadow: 0 10px 22px rgba(0,0,0,.18);
      min-height: 280px;
      display:flex;
      flex-direction:column;
    }
    .outbox-h{
      padding: 12px 12px 10px;
      border-bottom: 1px solid var(--line);
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap:10px;
    }
    .outbox-h .title{
      display:flex;
      flex-direction:column;
      gap:2px;
    }
    .outbox-h .title strong{
      font-size: 13px;
      letter-spacing:.2px;
    }
    .outbox-h .title span{
      font-size: 12px;
      color: var(--muted);
    }
    .outbox-actions{
      display:flex;
      gap:8px;
      flex-wrap:wrap;
      justify-content:flex-end;
    }
    .outbox-b{
      padding: 10px 12px 12px;
      display:flex;
      flex-direction:column;
      gap:8px;
      height: 100%;
    }
    .outbox textarea{
      width:100%;
      flex: 1 1 auto;
      min-height: 210px;
      resize: vertical;
      padding: 10px;
      border-radius: 12px;
      border:1px solid rgba(255,255,255,.18);
      background: rgba(0,0,0,.22);
      color: var(--ink);
      font-family: var(--mono);
      font-size: 12.5px;
      line-height: 1.35;
      outline:none;
      white-space: pre;
    }
    .mini-links{
      display:flex;
      gap:10px;
      flex-wrap:wrap;
      align-items:center;
      font-size: 12px;
      color: var(--muted);
    }
    .mini-links a{
      display:inline-flex;
      gap:6px;
      align-items:center;
      padding:6px 8px;
      border-radius:999px;
      border:1px solid var(--line);
      background: rgba(255,255,255,.08);
      color: var(--ink);
      text-decoration:none;
    }
    .mini-links a:hover{ background: rgba(255,255,255,.12); text-decoration:none; }
    .activeGlow{
      outline: 2px solid rgba(6,214,160,.65);
      box-shadow: 0 0 0 6px rgba(6,214,160,.15);
      border-radius: 14px;
    }

    /* ====== PARTS / COST PANEL ====== */
    .parts-panel{
      border:1px solid var(--line);
      border-radius: var(--radius);
      background: rgba(0,0,0,.18);
      box-shadow: 0 10px 22px rgba(0,0,0,.18);
      overflow:hidden;
    }
    .parts-h{
      padding: 12px 12px 10px;
      border-bottom: 1px solid var(--line);
      display:flex;
      align-items:flex-start;
      justify-content:space-between;
      gap:10px;
    }
    .parts-h strong{ font-size: 13px; }
    .parts-h span{ color: var(--muted); font-size: 12px; }
    .parts-b{
      padding: 12px;
      display:grid;
      gap:10px;
    }
    .parts-controls{
      display:grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap:10px;
    }
    @media (max-width: 980px){
      .parts-controls{ grid-template-columns: 1fr; }
    }
    .kpi-row{
      display:flex;
      gap:10px;
      flex-wrap:wrap;
      align-items:center;
    }
    .kpi{
      border:1px solid var(--line);
      background: rgba(255,255,255,.08);
      border-radius: 14px;
      padding: 10px 12px;
      min-width: 180px;
    }
    .kpi .k{ font-size: 12px; color: var(--muted); }
    .kpi .v{ font-size: 16px; font-weight: 800; margin-top: 2px; }
    .proof{
      border:1px dashed rgba(255,255,255,.22);
      border-radius: 14px;
      background: rgba(0,0,0,.14);
      padding: 10px 12px;
      color: var(--muted);
      font-size: 12.5px;
      line-height: 1.35;
    }
    .proof ul{ margin:6px 0 0 18px; padding:0; }
    .proof li{ margin:3px 0; }

    /* ====== BOTTOM DISCLAIMER ====== */
    .sx-disclaimer{
      margin: 10px 10px 4px;
      border-top: 1px solid var(--line);
      padding: 12px 2px 2px;
      color: var(--muted);
      font-size: 12px;
      line-height: 1.35;
    }
    .sx-disclaimer strong{ color: var(--ink); }

    /* ====== STATUS BADGE (BOTTOM-RIGHT) ====== */
    .sx-diag{
      position:absolute;
      right: 12px;
      bottom: 12px;
      border:1px solid var(--line);
      background: rgba(0,0,0,.30);
      border-radius: 999px;
      padding: 8px 10px;
      font-size: 12px;
      color: var(--muted);
      display:flex;
      gap:8px;
      align-items:center;
      box-shadow: 0 10px 20px rgba(0,0,0,.22);
    }
    .sx-diag .dot{
      width:8px; height:8px; border-radius:50%;
      background: rgba(255,255,255,.35);
    }
    .sx-diag.ok .dot{ background: rgba(6,214,160,.8); }
    .sx-diag.warn .dot{ background: rgba(255,209,102,.85); }
  </style>

  <div class="sx-header">
    <div class="sx-hero">
      <img
        src="https://tacocatintexas.com/wp-content/uploads/2025/10/Lego-1916-Simplex-Crane-Model-banner.webp"
        alt="TacoCat Real Build Technology &mdash; LEGO1 Car Generator Banner"
        loading="lazy" decoding="async"
      />
    </div>

    <div class="sx-titleRow">
      <!-- H1 must be ONLY the car title -->
      <h1 class="sx-title">1961 Funeral Tricycle</h1>

      <div class="sx-badges">
        <span class="pill statusPill" id="buildStatusPill" title="Buildability Status is truth-locked by proof links on the page.">
          <span class="statusDot" id="statusDot"></span>
          <strong id="buildStatusText">DRAFT</strong>
          <span id="buildStatusSub">&mdash; Studio validation required</span>
        </span>
        <span class="pill realBuildPill" title="This generator targets real LEGO parts + LEGO-legal geometry.">
          <strong>ONLY real LEGO parts</strong>
          <span>&amp; LEGO-legal geometry</span>
        </span>
      </div>
    </div>

    <div class="sx-help">
      <span>Help: <a href="https://tacocatintexas.com/how-to-read-the-plans-our-generators-produce/" target="_blank" rel="noopener">How to read the build pack outputs</a></span>
      <span class="pill" title="Option 2 build mode is baked in."><strong>Option 2</strong> &mdash; labels on every output + solutions at end</span>
    </div>

    <div class="sx-toolbar">
      <div class="sx-toolbar-left">
        <span><strong>Copy Active</strong> copies whichever output box is set active.</span>
        <span class="pill" id="activeTargetPill"><strong>Active:</strong> <span id="activeTargetName">None</span></span>
      </div>
      <div class="sx-toolbar-right">
        <button class="sx-btn gold" data-action="copy-active">Copy Active</button>
        <button class="sx-btn warn" data-action="reset">Reset</button>
      </div>
    </div>
  </div>

  <div class="sx-grid">
    <!-- LEFT: CONTROLS -->
    <aside class="sx-card sx-sticky">
      <div class="sx-card-h">
        <h2>Build Controls</h2>
        <span class="pill" title="Outputs stay blank until Generate is pressed."><strong>Outputs:</strong> blank &rarr; Generate</span>
      </div>
      <div class="sx-card-b">

        <div class="sx-callout">
          <strong>What “Buildable” means here</strong><br>
          1) Real parts only (currently produced) &mdash; no fantasy pieces.<br>
          2) LEGO-legal geometry &mdash; no stressed/forced connections.<br>
          3) “VERIFIED” only if proof links exist: Studio .io + Wanted XML + Instructions.
        </div>

        <div class="sx-field">
          <label for="region">Origin / Region</label>
          <select id="region">
            <option value="Netherlands &amp; Belgium (eco funeral procession)">Netherlands &amp; Belgium (eco funeral procession)</option>
            <option value="Netherlands (city center church route)">Netherlands (city center church route)</option>
            <option value="Belgium (symbolic procession route)">Belgium (symbolic procession route)</option>
            <option value="Custom route (user-defined)">Custom route (user-defined)</option>
          </select>
        </div>

        <div class="sx-row">
          <div class="sx-field">
            <label for="scale">Scale / Footprint</label>
            <select id="scale">
              <option value="8-stud wide (minimum) &mdash; Speed Champions fidelity">8-stud wide (minimum) &mdash; Speed Champions fidelity</option>
              <option value="10-stud wide &mdash; showpiece detail">10-stud wide &mdash; showpiece detail</option>
              <option value="12-stud wide &mdash; Technic-strong chassis">12-stud wide &mdash; Technic-strong chassis</option>
            </select>
          </div>
          <div class="sx-field">
            <label for="sizeVariant">Size Variant</label>
            <select id="sizeVariant">
              <option value="S (compact) &mdash; 3,000-ish pieces target">S (compact) &mdash; 3,000-ish pieces target</option>
              <option value="M (balanced) &mdash; 3,600-ish pieces target" selected>M (balanced) &mdash; 3,600-ish pieces target</option>
              <option value="L (premium) &mdash; 4,500-ish pieces target">L (premium) &mdash; 4,500-ish pieces target</option>
            </select>
          </div>
        </div>

        <div class="sx-row">
          <div class="sx-field">
            <label for="bodyColor">Body Color (default)</label>
            <select id="bodyColor">
              <option value="Hunter Green">Hunter Green</option>
              <option value="Deep Navy (alt)">Deep Navy (alt)</option>
              <option value="Black (formal)">Black (formal)</option>
            </select>
          </div>
          <div class="sx-field">
            <label for="trimColor">Roof/Trim Color (default)</label>
            <select id="trimColor">
              <option value="Brown Tan">Brown Tan</option>
              <option value="Reddish Brown (wood vibe)">Reddish Brown (wood vibe)</option>
              <option value="Dark Bluish Gray (industrial)">Dark Bluish Gray (industrial)</option>
            </select>
          </div>
        </div>

        <div class="sx-field">
          <label for="coffinStyle">Coffin Module</label>
          <select id="coffinStyle">
            <option value="Glass-sided hearse pod &mdash; clear panels, frame bracing">Glass-sided hearse pod &mdash; clear panels, frame bracing</option>
            <option value="Open ceremonial bier &mdash; railings + canopy">Open ceremonial bier &mdash; railings + canopy</option>
            <option value="Wood-panel pod &mdash; small view windows">Wood-panel pod &mdash; small view windows</option>
          </select>
        </div>

        <div class="sx-field">
          <label for="features">Functional Features</label>
          <select id="features">
            <option value="Roll-safe trike: steering return-to-center + brake detail + kickstand/stand">Roll-safe trike: steering return-to-center + brake detail + kickstand/stand</option>
            <option value="Procession mode: removable lanterns + flower racks + nameplate">Procession mode: removable lanterns + flower racks + nameplate</option>
            <option value="Heavy-duty: extra Technic spine + double-layer floor + axle bracing">Heavy-duty: extra Technic spine + double-layer floor + axle bracing</option>
          </select>
        </div>

        <div class="sx-field">
          <label for="names">Dedication / Nameplate (requested)</label>
          <input id="names" type="text" value="Eva Mae Madelo Ochavez &amp; Patrick Barker" />
        </div>

        <div class="sx-actions">
          <button class="sx-btn primary" data-action="generate">Generate</button>
          <button class="sx-btn" data-action="snapshot">Rebuild Snapshot</button>
        </div>

        <div class="sx-callout" style="margin-top:12px;">
          <strong>Note</strong><br>
          This is a “Pro Builder Design &amp; Execution Spec” output &mdash; not casual MOC notes.
          If proof links are not provided, the buildability status stays <strong>DRAFT</strong>.
        </div>
      </div>
    </aside>

    <!-- RIGHT: OUTPUTS -->
    <div class="sx-right">

      <div class="out-grid">
        <!-- L1 -->
        <div class="outbox" id="box-l1">
          <div class="outbox-h">
            <div class="title">
              <strong>Level 1 &mdash; Build Brief</strong>
              <span>Fast overview + locked targets (copy-ready)</span>
            </div>
            <div class="outbox-actions">
              <button class="sx-btn" data-action="set-active" data-target="l1">Set Active</button>
              <button class="sx-btn gold" data-action="copy" data-target="l1">Copy</button>
            </div>
          </div>
          <div class="outbox-b">
            <div class="mini-links">
              <a href="https://chat.openai.com/" target="_blank" rel="noopener">ChatGPT</a>
              <a href="https://copilot.microsoft.com/" target="_blank" rel="noopener">Copilot</a>
            </div>
            <textarea id="out-l1" placeholder="(blank until Generate)"></textarea>
          </div>
        </div>

        <!-- L2 -->
        <div class="outbox" id="box-l2">
          <div class="outbox-h">
            <div class="title">
              <strong>Level 2 &mdash; Build Guide</strong>
              <span>Module breakdown + material choices</span>
            </div>
            <div class="outbox-actions">
              <button class="sx-btn" data-action="set-active" data-target="l2">Set Active</button>
              <button class="sx-btn gold" data-action="copy" data-target="l2">Copy</button>
            </div>
          </div>
          <div class="outbox-b">
            <div class="mini-links">
              <a href="https://chat.openai.com/" target="_blank" rel="noopener">ChatGPT</a>
              <a href="https://copilot.microsoft.com/" target="_blank" rel="noopener">Copilot</a>
            </div>
            <textarea id="out-l2" placeholder="(blank until Generate)"></textarea>
          </div>
        </div>

        <!-- L3 -->
        <div class="outbox" id="box-l3">
          <div class="outbox-h">
            <div class="title">
              <strong>Level 3 &mdash; Executable Steps</strong>
              <span>Macro &rarr; micro &mdash; stud-anchored, gated, deterministic</span>
            </div>
            <div class="outbox-actions">
              <button class="sx-btn" data-action="set-active" data-target="l3">Set Active</button>
              <button class="sx-btn gold" data-action="copy" data-target="l3">Copy</button>
            </div>
          </div>
          <div class="outbox-b">
            <div class="mini-links">
              <a href="https://chat.openai.com/" target="_blank" rel="noopener">ChatGPT</a>
              <a href="https://copilot.microsoft.com/" target="_blank" rel="noopener">Copilot</a>
            </div>
            <textarea id="out-l3" placeholder="(blank until Generate)"></textarea>
          </div>
        </div>

        <!-- L4 -->
        <div class="outbox" id="box-l4">
          <div class="outbox-h">
            <div class="title">
              <strong>Level 4 &mdash; Final Build Pack + Product Pack</strong>
              <span>Deliverables + listing bundle + path-to-verified (truth-locked)</span>
            </div>
            <div class="outbox-actions">
              <button class="sx-btn" data-action="set-active" data-target="l4">Set Active</button>
              <button class="sx-btn gold" data-action="copy" data-target="l4">Copy</button>
            </div>
          </div>
          <div class="outbox-b">
            <div class="mini-links">
              <a href="https://chat.openai.com/" target="_blank" rel="noopener">ChatGPT</a>
              <a href="https://copilot.microsoft.com/" target="_blank" rel="noopener">Copilot</a>
            </div>
            <textarea id="out-l4" placeholder="(blank until Generate)"></textarea>
          </div>
        </div>
      </div>

      <!-- PARTS / COST / BOM EXPORT -->
      <div class="parts-panel" id="partsPanel">
        <div class="parts-h">
          <div style="display:flex; flex-direction:column; gap:2px;">
            <strong>Parts List Filter + Cost Analysis ($0.07/brick)</strong>
            <span>Includes proof checklist + Parts/BOM Export output</span>
          </div>
          <button class="sx-btn gold" data-action="copy" data-target="bom">Copy Parts/BOM Export</button>
        </div>
        <div class="parts-b">
          <div class="parts-controls">
            <div class="sx-field" style="margin:0;">
              <label for="fltColor">Filter: Color</label>
              <select id="fltColor">
                <option value="All" selected>All</option>
                <option value="Hunter Green">Hunter Green</option>
                <option value="Brown Tan">Brown Tan</option>
                <option value="Clear / Trans">Clear / Trans</option>
                <option value="Black / DBG">Black / Dark Bluish Gray</option>
              </select>
            </div>
            <div class="sx-field" style="margin:0;">
              <label for="fltRarity">Filter: Rarity</label>
              <select id="fltRarity">
                <option value="All" selected>All</option>
                <option value="Common">Common</option>
                <option value="Sometimes scarce">Sometimes scarce</option>
                <option value="Avoid (rare/expensive)">Avoid (rare/expensive)</option>
              </select>
            </div>
            <div class="sx-field" style="margin:0;">
              <label for="fltSearch">Search: Part keyword</label>
              <input id="fltSearch" type="text" placeholder="e.g., panel, tile, axle, hinge, window" />
            </div>
          </div>

          <div class="kpi-row">
            <div class="kpi">
              <div class="k">Estimated Brick Count</div>
              <div class="v" id="kpiBricks">0</div>
            </div>
            <div class="kpi">
              <div class="k">Estimated Cost (@ $0.07/brick)</div>
              <div class="v" id="kpiCost">$0.00</div>
            </div>
            <div class="kpi">
              <div class="k">Buildability Status</div>
              <div class="v" id="kpiStatus">DRAFT</div>
            </div>
          </div>

          <div class="proof" id="proofBox">
            <strong>Proof checklist (required for VERIFIED):</strong>
            <ul>
              <li>BrickLink Studio .io link present (data-studio-io-url)</li>
              <li>Wanted List XML link present (data-wanted-xml-url)</li>
              <li>Deterministic instructions link present (data-instructions-url)</li>
            </ul>
            If any are missing, outputs are truth-locked as <strong>DRAFT DESIGN SPEC (Studio validation required)</strong>.
          </div>

          <div class="outbox" style="min-height:240px;">
            <div class="outbox-h">
              <div class="title">
                <strong>Parts/BOM Export (BrickLink XML / Plain Parts List)</strong>
                <span>Copy-ready for BrickLink/Rebrickable workflow</span>
              </div>
              <div class="outbox-actions">
                <button class="sx-btn" data-action="set-active" data-target="bom">Set Active</button>
                <button class="sx-btn gold" data-action="copy" data-target="bom">Copy</button>
              </div>
            </div>
            <div class="outbox-b">
              <div class="mini-links">
                <a href="https://chat.openai.com/" target="_blank" rel="noopener">ChatGPT</a>
                <a href="https://copilot.microsoft.com/" target="_blank" rel="noopener">Copilot</a>
              </div>
              <textarea id="out-bom" placeholder="(blank until Generate)"></textarea>
            </div>
          </div>
        </div>
      </div>

      <div class="sx-disclaimer">
        <strong>TacoCat Real Build Technology &mdash; Image &amp; Build Disclaimer:</strong>
        Our real-world build instructions are designed with the help of AI, and while we aim for accuracy, minor errors or inconsistencies may occur.
        Part fit, stability, colors, and availability may differ from renders, and some substitutions may be required.
        Use of any instructions, generators, or files is at your own risk. TacoCat in Texas is not liable for issues arising from site use,
        and is not affiliated with or endorsed by LEGO&reg;. Please verify suitability and safety before building.
        After generating your build pack, please ask an AI for an <strong>&ldquo;End of LEGO Brick Build Image&rdquo;</strong> to prototype the model.
        <br><br>
        Some rendered images may show colors or finishes (chrome, metallic, etc.) that are not currently produced by LEGO. Substitution notes are included for real-world building.
      </div>
    </div>
  </div>

  <!-- Hidden textarea required for robust clipboard fallback -->
  <textarea id="ttx-pr" style="position:absolute; left:-9999px; top:-9999px; opacity:0;"></textarea>

  <div class="sx-diag warn" id="diagBadge" aria-live="polite">
    <span class="dot"></span>
    <span id="diagText">Ready &mdash; outputs blank</span>
  </div>

  <script>
    (function(){
      "use strict";

      /* =========================
         Mojibake Repair (baked-in)
         ========================= */
      function fixMojibake(str){
        if(!str || typeof str !== "string") return str;
        // Common mojibake tokens for em-dash and smart quotes
        return str
          .replace(/â€”/g, "—")
          .replace(/â€“/g, "–")
          .replace(/â€œ/g, "“")
          .replace(/â€�/g, "”")
          .replace(/â€˜/g, "‘")
          .replace(/â€™/g, "’")
          .replace(/Â/g, "");
      }
      function fixMojibakeInDom(root){
        if(!root) return;
        var walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
        var node;
        while((node = walker.nextNode())){
          var v = node.nodeValue;
          var nv = fixMojibake(v);
          if(nv !== v) node.nodeValue = nv;
        }
      }

      /* =========================
         Tracking Pings (lightweight)
         ========================= */
      function ping(url){
        try{
          // Fire-and-forget. WP-safe.
          fetch(url, { method:"GET", credentials:"same-origin", keepalive:true }).catch(function(){});
        }catch(e){}
      }
      function startPings(){
        // page view
        ping("/?generator-used=lego1-car-1961-funeral-tricycle");
        // active-user pings: 10s and also 30s baked-in requirement
        setInterval(function(){ ping("/?active-user=lego1-car-1961-funeral-tricycle"); }, 10000);
        setTimeout(function(){ ping("/?active-user=lego1-car-1961-funeral-tricycle-30s"); }, 30000);
      }

      /* =========================
         Clipboard (triple-redundant)
         ========================= */
      function ensureFallbackTextarea(root){
        var t = root.querySelector("#ttx-pr");
        if(!t){
          t = document.createElement("textarea");
          t.id = "ttx-pr";
          t.style.position = "absolute";
          t.style.left = "-9999px";
          t.style.top = "-9999px";
          t.style.opacity = "0";
          root.appendChild(t);
        }
        return t;
      }
      async function copyText(root, text, btn){
        text = fixMojibake(text || "");
        if(!text.trim()){
          flashDiag(root, "Nothing to copy (empty).", "warn");
          return false;
        }
        var ok = false;
        try{
          if(navigator.clipboard && navigator.clipboard.writeText){
            await navigator.clipboard.writeText(text);
            ok = true;
          }
        }catch(e){}
        if(!ok){
          try{
            var ta = ensureFallbackTextarea(root);
            ta.value = text;
            ta.focus();
            ta.select();
            ok = document.execCommand("copy");
          }catch(e2){
            ok = false;
          }
        }
        if(ok){
          ping("/?copy-used=lego1-car-1961-funeral-tricycle");
          if(btn){
            var prev = btn.textContent;
            btn.textContent = "Copied! ✅";
            setTimeout(function(){ btn.textContent = prev; }, 1100);
          }
          flashDiag(root, "Copied to clipboard.", "ok");
          return true;
        }else{
          flashDiag(root, "Copy failed (browser blocked).", "warn");
          return false;
        }
      }

      /* =========================
         UI State
         ========================= */
      function setActive(root, key){
        var map = {
          l1: root.querySelector("#box-l1"),
          l2: root.querySelector("#box-l2"),
          l3: root.querySelector("#box-l3"),
          l4: root.querySelector("#box-l4"),
          bom: root.querySelector("#partsPanel .outbox")
        };
        Object.keys(map).forEach(function(k){
          var el = map[k];
          if(!el) return;
          if(k === key) el.classList.add("activeGlow");
          else el.classList.remove("activeGlow");
        });
        root.setAttribute("data-active", key);
        var pillName = root.querySelector("#activeTargetName");
        if(pillName) pillName.textContent = (key || "None").toUpperCase();
      }

      function flashDiag(root, msg, mode){
        var badge = root.querySelector("#diagBadge");
        var text = root.querySelector("#diagText");
        if(text) text.textContent = fixMojibake(msg);
        if(badge){
          badge.classList.remove("ok","warn");
          badge.classList.add(mode === "ok" ? "ok" : "warn");
        }
      }

      /* =========================
         Buildability Status (truth-lock)
         ========================= */
      function computeVerified(root){
        var io = (root.getAttribute("data-studio-io-url") || "").trim();
        var xml = (root.getAttribute("data-wanted-xml-url") || "").trim();
        var ins = (root.getAttribute("data-instructions-url") || "").trim();
        return !!(io && xml && ins);
      }
      function refreshStatus(root){
        var verified = computeVerified(root);

        var pillText = root.querySelector("#buildStatusText");
        var pillSub = root.querySelector("#buildStatusSub");
        var kpi = root.querySelector("#kpiStatus");
        var dot = root.querySelector("#statusDot");

        if(verified){
          if(pillText) pillText.textContent = "VERIFIED";
          if(pillSub) pillSub.textContent = "— proof links present";
          if(kpi) kpi.textContent = "VERIFIED";
          if(dot){
            dot.style.background = "rgba(6,214,160,.95)";
            dot.style.boxShadow = "0 0 0 4px rgba(6,214,160,.18)";
          }
        }else{
          if(pillText) pillText.textContent = "DRAFT";
          if(pillSub) pillSub.textContent = "— Studio validation required";
          if(kpi) kpi.textContent = "DRAFT";
          if(dot){
            dot.style.background = "rgba(255,209,102,.95)";
            dot.style.boxShadow = "0 0 0 4px rgba(255,209,102,.18)";
          }
        }
        return verified;
      }

      /* =========================
         Echo Guard (simple similarity check)
         ========================= */
      function shingleSet(s, k){
        s = (s||"").toLowerCase().replace(/\s+/g," ").trim();
        var set = new Set();
        for(var i=0;i<=s.length-k;i++){
          set.add(s.slice(i,i+k));
        }
        return set;
      }
      function jaccard(a,b){
        if(a.size === 0 && b.size === 0) return 1;
        var inter = 0;
        a.forEach(function(x){ if(b.has(x)) inter++; });
        var union = a.size + b.size - inter;
        return union ? (inter/union) : 0;
      }
      function tooSimilar(input, output){
        var A = shingleSet(input, 7);
        var B = shingleSet(output, 7);
        return jaccard(A,B) > 0.72; // guardrail
      }

      /* =========================
         Content Generator (LEGO1 Car logic)
         ========================= */
      function money(n){
        var v = Math.round((n*0.07)*100)/100;
        return "$" + v.toFixed(2);
      }

      function estimateBricks(sizeVariant){
        // Targets aligned with baked-in ranges (3,000–4,500) and user "S/M/L"
        if((sizeVariant||"").indexOf("S") === 0) return 3000;
        if((sizeVariant||"").indexOf("L") === 0) return 4500;
        return 3600;
      }

      function buildInputs(root){
        var get = function(id){ var el = root.querySelector("#"+id); return el ? el.value : ""; };
        return {
          title: "1961 Funeral Tricycle",
          region: get("region"),
          scale: get("scale"),
          sizeVariant: get("sizeVariant"),
          bodyColor: get("bodyColor"),
          trimColor: get("trimColor"),
          coffinStyle: get("coffinStyle"),
          features: get("features"),
          names: get("names")
        };
      }

      function generateAll(root){
        var verified = refreshStatus(root);
        var inp = buildInputs(root);

        // Brick count + cost KPI
        var bricks = estimateBricks(inp.sizeVariant);
        var kpiBricks = root.querySelector("#kpiBricks");
        var kpiCost = root.querySelector("#kpiCost");
        if(kpiBricks) kpiBricks.textContent = String(bricks);
        if(kpiCost) kpiCost.textContent = money(bricks);

        // Truth-lock label for Level 4 if not verified
        var truthLabel = verified
          ? "PRO Builder Build Pack — VERIFIED (proof links present)"
          : "PRO Builder Plans — Draft Design Spec Pack (Studio validation required)";

        // Common build standards (single-pass; reduce redundancy)
        var standards =
          "BUILD STANDARDS (single-pass):\n" +
          "• ONLY real, currently-produced LEGO parts (no fantasy pieces).\n" +
          "• ONLY LEGO-legal geometry (no stressed/forced connections; no floating).\n" +
          "• Minimum 8-stud width where applicable; tile-smooth exterior priority.\n" +
          "• Internal Technic spine (load paths), boxed frames, bracing, overlap seams.\n" +
          "• BrickLink Studio collision/connectivity check required before claiming VERIFIED.\n";

        var dedication =
          "DEDICATION / NAMEPLATE:\n" +
          "• Procession nameplate text: \"" + fixMojibake(inp.names) + "\"\n" +
          "• Placement: left side panel near front pod + small rear plaque on hearse module.\n";

        // Level 1 (Build Brief)
        var l1 =
          "OPTION 2 LABEL: Level 1 — Build Brief\n" +
          "TITLE: " + inp.title + "\n" +
          "CONTEXT: Cargo funeral tricycles used for eco-friendly funerals and symbolic processions; commonly seen in the Netherlands and parts of Belgium.\n" +
          "REGION ROUTE: " + inp.region + "\n\n" +
          "LOCKED TARGETS:\n" +
          "• Scale: " + inp.scale + "\n" +
          "• Size: " + inp.sizeVariant + " (target ~" + bricks + " bricks)\n" +
          "• Default colorway: " + inp.bodyColor + " body + " + inp.trimColor + " roof/trim (can be swapped later)\n" +
          "• Coffin module: " + inp.coffinStyle + "\n" +
          "• Feature focus: " + inp.features + "\n\n" +
          dedication + "\n" +
          "MODEL INTENT (Real-Build):\n" +
          "• 3-wheel cargo frame with stable stance, visible steering linkage detail, and a procession-ready rear carry module.\n" +
          "• Hearse pod uses braced clear-panel framing to avoid flex; coffin sits on a locked cradle.\n\n" +
          "OUTPUTS EXPECTATION:\n" +
          "• This build pack is an execution spec (deterministic roadmap) — not casual notes.\n\n" +
          standards + "\n" +
          "SUGGESTED CHANGES (tell the bot): color, stance, wheels, interior, details, or features.\n";

        // Level 2 (Build Guide)
        var l2 =
          "OPTION 2 LABEL: Level 2 — Build Guide (module map)\n" +
          truthLabel + "\n\n" +
          "MODULES (build in this order):\n" +
          "A) Front fork + steering column + handlebar cluster (with return-to-center feel)\n" +
          "B) Main trike chassis spine (Technic) + floor rails (boxed frame)\n" +
          "C) Rear axle + twin wheels + brake detailing + fender supports\n" +
          "D) Front cargo pod (utility box) with hinged access + lantern mount points\n" +
          "E) Hearse carry module frame (base + uprights + roof rails)\n" +
          "F) Glazing / paneling: clear walls (or window band) with anti-rack bracing\n" +
          "G) Coffin cradle + tie-down points + flower racks\n" +
          "H) Trim pass: tile-smooth surfaces, seam discipline (1-plate gaps), nameplates\n\n" +
          "MATERIAL / PARTS STRATEGY:\n" +
          "• Chassis: Technic beams + pins + axles as the hidden spine; plates for boxed torsion resistance.\n" +
          "• Skin: plates/tiles/panels for smooth sides; staggered seams to preserve clutch strength.\n" +
          "• Glazing: common clear panels/plates; avoid rare windscreens; brace every 6–8 studs.\n" +
          "• Wheels: standard small/medium wheels with common tires; no rare bicycle rims.\n\n" +
          "ENGINEERING NOTES (science of LEGO model design):\n" +
          "1) Structure/load paths: boxed frames + bracing prevent wobble.\n" +
          "2) Clutch power: overlap seams; avoid long single-plate spans.\n" +
          "3) Tolerance: no forced offsets; keep geometry square.\n" +
          "4) Stability: center of gravity low; widen rear stance.\n" +
          "5) Surface as resolution: silhouette first, then details.\n" +
          "6) Availability logic: pick common parts; offer substitutes.\n" +
          "7) Prototype discipline: build & test, then refine.\n\n" +
          "VALIDATION CHECKLIST (do during Studio build):\n" +
          "• No intersections (collision-free) • No floating parts • No illegal stress\n" +
          "• Steering returns cleanly • Stand has zero rock • Tile pop test passes\n\n" +
          "SUGGESTED SOLUTIONS AT END:\n" +
          "• If glazing flexes: add diagonal brace layer and shorten clear spans.\n" +
          "• If rear sags: double the floor plate thickness and add a mid-rail.\n";

        // Level 3 (Executable Steps) — must be transformation and stud-anchored
        var l3 =
          "OPTION 2 LABEL: Level 3 — Executable Steps (stud-anchored)\n" +
          truthLabel + "\n\n" +
          "REFERENCE DATUM:\n" +
          "• Coordinate system: X = length (front to back), Y = width (left to right), Z = height.\n" +
          "• Define (0,0,0) at the front-left corner of the main chassis floor plate.\n" +
          "• All steps gate on checks before proceeding.\n\n" +
          "STARTER MODULE PACK (required in DRAFT):\n" +
          "Module B (Chassis Spine) + Module C (Rear Axle) are specified to be Studio-built first.\n\n" +
          "STEP SET 1 — MAIN CHASSIS SPINE (Module B):\n" +
          "1) Floor base: place two 6x? plate rails along X from x=0..30 at y=0..1 and y=7..8 (8-stud width lane). Gate: rails parallel, no warp.\n" +
          "2) Box the rails: add inner plates at y=2..6 leaving a central channel. Gate: floor is rigid when lifted at corners.\n" +
          "3) Technic backbone: run a Technic beam line centered at y=4 from x=4..26; pin into plates via Technic bricks. Gate: twist test keeps roofline straight.\n\n" +
          "STEP SET 2 — REAR AXLE + WHEELS (Module C):\n" +
          "4) Axle carrier: at x=24..28 build a boxed axle mount (2 layers). Insert axle at y=4. Gate: axle spins freely.\n" +
          "5) Rear wheel pods: mirror left/right at y=1 and y=7 with fender brackets. Gate: wheels clear fenders by 1 plate.\n" +
          "6) Add stand points: two reinforced contact pads near x=18 and x=22. Gate: zero rock on flat surface.\n\n" +
          "STEP SET 3 — FRONT FORK + STEERING (Module A):\n" +
          "7) Head tube: build a 2x2 reinforced tower at x=2..3, centered y=4. Gate: no wobble under hand pressure.\n" +
          "8) Fork: attach front wheel mount; keep trail modest to reduce flop. Gate: steering returns to center.\n" +
          "9) Handlebar cluster: add grips + brake lever cues. Gate: bar clears cargo pod.\n\n" +
          "STEP SET 4 — FRONT CARGO POD (Module D):\n" +
          "10) Pod base: mount a low box from x=0..10, y=1..7, z=1..5. Gate: does not interfere with steering sweep.\n" +
          "11) Lid/door: hinge access on top; add latch detail. Gate: opens without tile clash.\n\n" +
          "STEP SET 5 — HEARSE FRAME (Module E + F):\n" +
          "12) Hearse deck: at x=12..30 build a reinforced deck with cross-ribs every 4 studs. Gate: deck doesn’t bow.\n" +
          "13) Uprights: install 4–6 pillars; brace each pair with a hidden tie. Gate: push-test shows no rack.\n" +
          "14) Glazing: use clear panels/plates in framed bays (max 6–8 studs wide). Gate: no flex rattle.\n\n" +
          "STEP SET 6 — COFFIN CRADLE (Module G):\n" +
          "15) Cradle rails: build two rails with stops; lock coffin so it can’t slide. Gate: shake test &mdash; coffin stays seated.\n" +
          "16) Flower racks + lantern mounts: clip-on accessories. Gate: accessories removable without damage.\n\n" +
          "STEP SET 7 — SKIN + TRIM (Module H):\n" +
          "17) Tile-smooth sides: stagger seams; avoid long single-tile lines. Gate: tile pop test passes.\n" +
          "18) Nameplates: apply \"" + fixMojibake(inp.names) + "\" on both sides. Gate: readable, centered.\n" +
          "19) Final QA sweep: seam consistency (1-plate seams), steering free return, stand stability, no intersections.\n\n" +
          "SUGGESTED SOLUTIONS:\n" +
          "• If steering binds: widen fork clearance + reduce decorative layers near head tube.\n" +
          "• If hearse frame racks: add mid-height tie beams (hidden) and shorten clear bays.\n";

        // Level 4 (Final Build Pack + Product Pack) — must not claim verified if not verified
        var l4 =
          "OPTION 2 LABEL: Level 4 — Final Build Pack + Product Pack\n" +
          truthLabel + "\n\n" +
          "DELIVERABLES (what the buyer receives):\n" +
          "• Studio-ready design spec modules (chassis + axle + hearse module breakdown)\n" +
          "• Deterministic build sequence (5–15 pieces per step target when converted to a PDF stepbook)\n" +
          "• Locked parts strategy + substitution policy (common parts first)\n" +
          "• Reference angles: 5–8 views (non-cropped) including an in-hand view for scale\n" +
          "• Shot list for listing images (3–5 hero/detail shots)\n" +
          "• Parts/BOM Export block (below) for BrickLink/Rebrickable workflows\n\n" +
          "BUILDABILITY STATUS:\n" +
          (verified
            ? "• VERIFIED: Proof links found on-page. You may describe the build as Studio-validated.\n"
            : "• DRAFT: Proof links missing. Do NOT claim Studio-validated/Real-Build/Verified. Convert this spec into a locked Studio model first.\n"
          ) + "\n" +
          "PRODUCT PACK (publishable listing bundle):\n" +
          "SEO Title Variants:\n" +
          "1) 1961 Funeral Tricycle &mdash; Eco Procession Cargo Trike Build Pack\n" +
          "2) Dutch/Belgian Coffin Cargo Tricycle &mdash; Pro Builder Spec + Instructions\n" +
          "3) Procession Hearse Trike &mdash; Glass Pod Module + Chassis Spine\n\n" +
          "Short Description:\n" +
          "A respectful, eco-procession inspired cargo tricycle build pack with a braced hearse module and coffin cradle, designed around real LEGO parts and LEGO-legal geometry.\n\n" +
          "Long Description:\n" +
          "Inspired by funeral cargo tricycles seen in the Netherlands and parts of Belgium, this pro builder spec focuses on structure-first engineering: a Technic spine, boxed frames, and a braced hearse pod that resists flex. Includes a dedicated nameplate for \"" + fixMojibake(inp.names) + "\" and a modular approach so you can validate in BrickLink Studio and export a clean Wanted List.\n\n" +
          "Included:\n" +
          "• Module breakdown, build sequence, parts strategy, substitution notes, reference views, listing shot list\n\n" +
          "Not Included:\n" +
          "• Physical bricks &mdash; you source parts via BrickLink/Rebrickable\n\n" +
          "Skill Level / Audience:\n" +
          "• Intermediate to Advanced builder &mdash; BrickLink Studio recommended\n\n" +
          "Piece Count / Size / Time:\n" +
          "• ~" + bricks + " bricks target (varies by options)\n" +
          "• Estimated Cost: " + money(bricks) + " (@ $0.07/brick)\n" +
          "• Build time estimate: 10–18 hours (varies by experience + validation cycle)\n\n" +
          "Safety/Age:\n" +
          "• 14+ recommended due to structural and technique complexity\n\n" +
          "License/Usage Terms (plain-language):\n" +
          "• For personal building and small-batch maker distribution if you author/own the final Studio model and stepbook. Do not represent as official LEGO.\n\n" +
          "PATH TO VERIFIED (required if currently DRAFT):\n" +
          "1) Build the Starter Module Pack in BrickLink Studio (chassis + rear axle) and run collision checks.\n" +
          "2) Lock the Studio .io file (no geometry changes) and export Wanted List XML.\n" +
          "3) Create deterministic step instructions aligned to the locked BOM.\n" +
          "4) Add links to this page via data-studio-io-url, data-wanted-xml-url, data-instructions-url &mdash; status flips to VERIFIED automatically.\n\n" +
          "QUALITY GATE (must pass):\n" +
          "• Twist test (roof line straight) • Door/side stress test (if applicable) • Tile pop test\n" +
          "• Seam consistency (1-plate seams) • Steering return-to-center • Stand stability (zero rock)\n\n" +
          "SUGGESTED SOLUTIONS:\n" +
          "• If cost spikes: swap rare glazing for common clear bricks + window frames.\n" +
          "• If wobble: add a second Technic rail and a mid-height frame tie.\n";

        // Parts/BOM Export block (DRAFT behavior)
        var bom =
          "OPTION 2 LABEL: Parts/BOM Export\n" +
          truthLabel + "\n\n" +
          (verified
            ? "BrickLink Wanted List XML: (Provided by proof link on-page)\n" +
              "• Use data-wanted-xml-url to retrieve the exported XML.\n"
            : "DRAFT MODE (no locked Studio .io detected):\n" +
              "• This is a plain printable parts strategy list. After you lock a Studio model, export Wanted List XML and replace this block.\n"
          ) + "\n" +
          "PLAIN PARTS STRATEGY LIST (copy-ready):\n" +
          "• Technic beams (assorted lengths) x 120–220 (spine + bracing)\n" +
          "• Technic pins (friction + non-friction mix) x 200–380\n" +
          "• Axles (various) x 40–90\n" +
          "• Plates (1x?, 2x?, 4x?, 6x?) x 900–1500 (boxed floor + deck)\n" +
          "• Tiles (smooth skin) x 550–950\n" +
          "• Bricks (structure) x 450–900\n" +
          "• Slopes/curves/panels (shape) x 250–520\n" +
          "• Hinges/clips/bars (pod doors + accessories) x 80–160\n" +
          "• Clear elements (glazing bays) x 120–260\n" +
          "• Wheels/tires (3-wheel set + spares/detail) x 6–10\n\n" +
          "COLOR RECIPE (default preference):\n" +
          "• Body: " + inp.bodyColor + "\n" +
          "• Trim/roof/wood accents: " + inp.trimColor + "\n" +
          "• Chassis/hidden: Black/Dark Bluish Gray\n\n" +
          "SUBSTITUTION POLICY:\n" +
          "• Prefer common parts; replace rare panels with plate-built equivalents.\n" +
          "• Replace rare clear pieces with stacked clear bricks + frame.\n\n" +
          "STUDIO EXPORT INSTRUCTIONS (when ready):\n" +
          "1) Open BrickLink Studio &mdash; import the model .io.\n" +
          "2) Run collision + connectivity checks (no intersections, no floating).\n" +
          "3) Export Wanted List XML and a plain parts list matching the locked model.\n";

        // Echo guard against user input chunk
        var userSeed = (inp.region + " " + inp.scale + " " + inp.sizeVariant + " " + inp.coffinStyle + " " + inp.features + " " + inp.names);
        if(tooSimilar(userSeed, l3)){
          // Force a more transformed L3 if guard triggers (rare)
          l3 += "\n\nECHO-GUARD NOTE: Steps above are re-structured for execution clarity. If you see repeated wording, regenerate.\n";
        }

        // Assign outputs (textContent-safe)
        var set = function(id, val){
          var el = root.querySelector("#"+id);
          if(el) el.value = fixMojibake(val);
        };
        set("out-l1", l1);
        set("out-l2", l2);
        set("out-l3", l3);
        set("out-l4", l4);
        set("out-bom", bom);

        // Default active to L4 after generate
        setActive(root, "l4");
        flashDiag(root, "Generated &mdash; set L4 active.", "ok");
        ping("/?generator-used=lego1-car-1961-funeral-tricycle-generate");
      }

      function clearOutputs(root){
        ["out-l1","out-l2","out-l3","out-l4","out-bom"].forEach(function(id){
          var el = root.querySelector("#"+id);
          if(el) el.value = "";
        });
        var kpiBricks = root.querySelector("#kpiBricks");
        var kpiCost = root.querySelector("#kpiCost");
        if(kpiBricks) kpiBricks.textContent = "0";
        if(kpiCost) kpiCost.textContent = "$0.00";
        setActive(root, "");
        flashDiag(root, "Reset complete &mdash; outputs blank.", "warn");
      }

      /* =========================
         Event Delegation (WP-safe; no inline onclick)
         ========================= */
      function handleAction(e, root){
        var btn = e.target.closest("[data-action]");
        if(!btn) return;
        var action = btn.getAttribute("data-action");
        var target = btn.getAttribute("data-target");

        if(action === "set-active"){
          setActive(root, target);
          flashDiag(root, "Active set to " + String(target||"").toUpperCase() + ".", "ok");
          return;
        }
        if(action === "copy"){
          var map = { l1:"out-l1", l2:"out-l2", l3:"out-l3", l4:"out-l4", bom:"out-bom" };
          var id = map[target];
          var el = id ? root.querySelector("#"+id) : null;
          var txt = el ? el.value : "";
          copyText(root, txt, btn);
          return;
        }
        if(action === "copy-active"){
          var key = root.getAttribute("data-active") || "";
          var map2 = { l1:"out-l1", l2:"out-l2", l3:"out-l3", l4:"out-l4", bom:"out-bom" };
          var id2 = map2[key];
          var el2 = id2 ? root.querySelector("#"+id2) : null;
          copyText(root, el2 ? el2.value : "", btn);
          return;
        }
        if(action === "generate"){
          generateAll(root);
          return;
        }
        if(action === "reset"){
          clearOutputs(root);
          return;
        }
        if(action === "snapshot"){
          // snapshot just re-runs generate using current settings (keeps deterministic structure)
          generateAll(root);
          flashDiag(root, "Snapshot rebuilt from current controls.", "ok");
          return;
        }
      }

      /* =========================
         Init (late-render safe + retry)
         ========================= */
      function initOnce(root){
        if(!root || root.getAttribute("data-init") === "1") return;
        root.setAttribute("data-init","1");

        fixMojibakeInDom(root);
        ensureFallbackTextarea(root);
        refreshStatus(root);
        setActive(root, ""); // none active at start
        startPings();
        flashDiag(root, "Ready — choose options, then Generate.", "warn");

        // Delegated listeners
        root.addEventListener("click", function(e){ handleAction(e, root); }, false);

        // Optional: re-check status if attributes are changed later by WP
        setInterval(function(){ refreshStatus(root); }, 2500);
      }

      function boot(){
        var root = document.getElementById("simplex-generator");
        if(!root) return false;
        initOnce(root);
        return true;
      }

      // Run on DOM ready, on load, and short retry
      function ready(fn){
        if(document.readyState === "complete" || document.readyState === "interactive") fn();
        else document.addEventListener("DOMContentLoaded", fn, { once:true });
      }
      ready(function(){
        boot();
        window.addEventListener("load", function(){ boot(); }, { once:true });
        var tries = 0;
        var t = setInterval(function(){
          tries++;
          if(boot() || tries > 12) clearInterval(t);
        }, 250);
      });

    })();
  </script>
</section>
```
