<!-- SAGA-SOLID · part 51 -->
g.add(new THREE.Mesh(new THREE.CylinderGeometry(1,1.5,8,8), marbleMat.clone()));
    } else if(type === 'tetra'){
      g.add(new THREE.Mesh(new THREE.TetrahedronGeometry(3), cyanMat.clone()));
    } else if(type === 'pyramid'){
      var p1 = new THREE.Mesh(new THREE.ConeGeometry(3,2,4), goldMat.clone()); p1.position.y = 1; g.add(p1);
      var p2 = new THREE.Mesh(new THREE.ConeGeometry(2,1.5,4), marbleMat.clone()); p2.position.y = 2.75; g.add(p2);
    }
    g.traverse(function(o){ if(o.isMesh) o.castShadow = true; });
    return g;
  }
  // AUTO-ALIGN 60-300+: start at 60, 10 units apart, extends past 300 if needed
  function autoAlign(){
    placedBlocks.forEach(function(b, i){
      var x = 60 + (i * 10);
      b.position.x = x;
      b.position.z = 0;
    });
    var endX = 60 + ((placedBlocks.length - 1) * 10);
    status('Aligned 60-' + endX + ': ' + placedBlocks.length + ' blocks in a straight line');
  }
  window._unfoldAll = autoAlign; // exposed for gold wall button
  function spawnBlock(type){
    var b = makeBlock(type);
    var px = 0, pz = 0;
    if(window._sagaCamera){ px = window._sagaCamera.position.x; pz = window._sagaCamera.position.z; }
    // Try to place without overlap (spiral out if needed)
    b.position.set(px + 20, 10, pz + 20);
    b.userData.creatorBlock = true;
    b.userData.blockType = type;
    var attempts = 0;
    while(wouldOverlap(b) && attempts < 20){
      attempts++;
      b.position.x += 8;
      b.position.z += 8;
    }
    if(wouldOverlap(b)){
      status('Cannot place — no space (overlap prevented)');
      return;
    }
    scene.add(b);
    placedBlocks.push(b);
    undoStack.push({action:'add', obj:b});
    selected = b;
    status('Spawned ' + type + ' (' + placedBlocks.length + ' total)');
  }
  // Toggle switches
  function setToggle(el, on){
    if(on) el.classList.add('on');
    else el.classList.remove('on');
  }
  // Block toggles (flip ON to spawn)
  panel.querySelectorAll('[data-block]').forEach(function(toggle){
    toggle.addEventListener('click', function(){
      var isOn = toggle.classList.contains('on');
      // Turn off all block toggles (mutual exclusion)
      panel.querySelectorAll('[data-block]').forEach(function(t){ setToggle(t, false); });
      if(!isOn){
        setToggle(toggle, true);
        spawnBlock(toggle.getAttribute('data-block'));
        // Auto-reset after spawn
        setTimeout(function(){ setToggle(toggle, false); }, 500);
      }
      panel.style.display = 'none'; // close to see the block
    });
  });
  // Tool toggles
  panel.querySelectorAll('[data-tool]').forEach(function(toggle){
    toggle.addEventListener('click', function(){
      var tool = toggle.getAttribute('data-tool');
      var isOn = toggle.classList.contains('on');
      panel.querySelectorAll('[data-tool]').forEach(function(t){ setToggle(t, false); });
      if(tool === 'align'){
        autoAlign();
        panel.style.display = 'none';
        return;
      }
      if(tool === 'undo' && undoStack.length > 0){
        var last = undoStack.pop();
        if(last.action === 'add'){
          scene.remove(last.obj);
          var idx = placedBlocks.indexOf(last.obj);
          if(idx > -1) placedBlocks.splice(idx, 1);
        } else if(last.action === 'remove'){
          scene.add(last.obj);
          placedBlocks.push(last.obj);
        }
        status('Undone');
        return;
      }
      if(!isOn){
        setToggle(toggle, true);
        activeTool = tool;
        if(tool === 'duplicate' && selected){
          var copy = makeBlock(selected.userData.blockType);
          copy.position.copy(selected.position);
          copy.position.x += 10;
          copy.userData.creatorBlock = true;
          copy.userData.blockType = selected.userData.blockType;
          if(!wouldOverlap(copy)){
            scene.add(copy);
            placedBlocks.push(copy);
            undoStack.push({action:'add', obj:copy});
            status('Duplicated');
          } else {
            status('Cannot duplicate — would overlap');
          }
          panel.style.display = 'none';
        } else if(tool === 'delete' && selected){
          scene.remove(selected);
          var di = placedBlocks.indexOf(selected);
          if(di > -1) placedBlocks.splice(di, 1);
          undoStack.push({action:'remove', obj:selected});
          selected = null;
          status('Deleted');
          panel.style.display = 'none';
        } else if(tool === 'color' && selected){
          var colors = [0xffd700, 0x00ccff, 0xff4444, 0xffffff, 0x1a1a1a];
          selected.traverse(function(o){ if(o.isMesh) o.material.color.setHex(colors[Math.floor(Math.random()*colors.length)]); });
          status('Recolored');
          panel.style.display = 'none';
        } else {
          status('Tool: ' + tool + ' active — tap a block in the world');
          panel.style.display = 'none';
        }
      }
    });
  });
  panel.querySelector('#creator-clos