<!-- RUBY-BACKUP · part 533 -->
+ '"');
  }catch(e){ codeStatus('engrave failed'); }
}
/* BLOCK WRITER — write text on the selected block, for the ancestors */
function writeOnBlock(text){
  try{
    var target = window._highlighted || window._selectedBlock;
    if(!target){ codeStatus('tap a block first, then write'); return; }
    // create canvas with the text
    var canvas = document.createElement('canvas');
    canvas.width = 512; canvas.height = 128;
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = '#111111';
    ctx.fillRect(0,0,512,128);
    ctx.fillStyle = '#ffd700';
    ctx.font = 'bold 48px serif';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';
    // intaglio-style: draw text with engraved effect
    ctx.fillText(text.substring(0,20), 256, 64);
    var tex = new THREE.CanvasTexture(canvas);
    // apply to all meshes in the target
    target.traverse(function(m){
      if(m.isMesh){
        if(!m.userData._matCloned){ m.material = m.material.clone(); m.userData._matCloned = true; }
        m.material.map = tex;
        m.material.needsUpdate = true;
      }
    });
    // command for undo
    pushCommand({
      name: 'write "' + text.substring(0,20) + '"',
      execute: function(){
        target.traverse(function(m){ if(m.isMesh && m.material){ m.material.map = tex; m.material.needsUpdate = true; } });
      },
      undo: function(){
        target.traverse(function(m){ if(m.isMesh && m.material){ m.material.map = null; m.material.needsUpdate = true; } });
      }
    });
    codeStatus('wrote "' + text.substring(0,20) + '"');
  }catch(e){ codeStatus('write failed'); }
}
/* CODE CONSOLE — paste area for Solid, for speed */
var _consoleOpen = false;
function toggleCodeConsole(){
  _consoleOpen = !_consoleOpen;
  var cc = document.getElementById('codeConsole');
  if(_consoleOpen){
    if(!cc){
      cc = document.createElement('div');
      cc.id = 'codeConsole';
      cc.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.92);z-index:20000;display:flex;align-items:center;justify-content:center;padding:16px;box-sizing:border-box;';
      cc.innerHTML = '<div style="background:#0a0a0a;border:2px solid #ffd700;border-radius:12px;padding:16px;width:100%;max-width:500px;display:flex;flex-direction:column;gap:10px;">'
        + '<div style="color:#ffd700;font-family:monospace;font-size:14px;">SOLID CODE CONSOLE — paste & run</div>'
        + '<textarea id="codeInput" placeholder="// paste JavaScript here" style="width:100%;height:200px;background:#111;color:#0f0;border:1px solid #333;border-radius:8px;font-family:monospace;font-size:12px;padding:10px;box-sizing:border-box;resize:vertical;"></textarea>'
        + '<div style="display:flex;gap:10px;">'
        + '<button id="codeRun" style="flex:1;background:#ffd700;color:#111;border:none;border-radius:8px;padding:12px;font-size:16px;cursor:pointer;">▶ Run</button>'
        + '<button id="codeClear" style="background:#333;color:#fff;border:none;border-radius:8px;padding:12px 20px;font-size:16px;cursor:pointer;">Clear</button>'
        + '<button id="codeClose" style="background:#333;color:#fff;border:none;border-radius:8px;padding:12px 20px;font-size:16px;cursor:pointer;">X</button>'
        + '</div>'
        + '<div id="codeOutput" style="color:#888;font-family:monospace;font-size:11px;max-height:80px;overflow-y:auto;"></div>'
        + '</div>';
      document.body.appendChild(cc);
      document.getElementById('codeRun').onclick = function(){
        var code = document.getElementById('codeInput').value;
        var out = document.getElementById('codeOutput');
        try{
          var result = eval(code);
          out.innerHTML = '<span style="color:#0f0;">OK: ' + String(result).substring(0,200) + '</span>';
          try{ codeStatus('code ran'); }catch(e){}
        }catch(e){
          out.innerHTML = '<span style="color:#f44;">ERR: ' + e.message + '</span>';
        }
      };
      document.getElementById('codeClear').onclick = function(){
        document.getElementById('codeInput').value = '';
        document.getElementById('codeOutput').innerHTML = '';
      };
      document.getElementById('codeClose').onclick = function(){ toggleCodeConsole(); };
      cc.onclick = function(e){ if(e.target===cc) toggleCodeConsole(); };
    }else{
      cc.style.display = 'flex';
    }
  }else if(cc){
    cc.style.display = 'none';
  }
}
var _helpOpen = false;
function toggleHelp(){
  _helpOpen = !_helpOpen;
  var h = document.getElementById('helpOverlay');
  if(_helpOpen){
    if(!h){
      h = document.createElement('div');
      h.id = 'helpOverlay';
      h.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.9);z-index:20000;display:flex;align-items:center;justify-content:center;padding:20px;box-sizing:border-box;';
      h.innerHTML = '<div style="background:#111;border:2px solid #ffd700;border-radius:16px;padding:24px;max-width:400px;max-h