<!-- RUBY-BACKUP · part 532 -->
ITOR — compose letters, engrave them on stone tablets */
var _epistleOpen = false;
function toggleEpistleEditor(){
  _epistleOpen = !_epistleOpen;
  var ee = document.getElementById('epistleEditor');
  if(_epistleOpen){
    if(!ee){
      ee = document.createElement('div');
      ee.id = 'epistleEditor';
      ee.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;';
      ee.innerHTML = '<div style="background:#0d0a06;border:2px solid #ffd700;border-radius:12px;padding:20px;width:100%;max-width:480px;display:flex;flex-direction:column;gap:12px;max-height:90vh;overflow-y:auto;">'
        + '<div style="color:#ffd700;font-family:serif;font-size:20px;text-align:center;">✒️ Epistle Editor</div>'
        + '<div style="color:#888;font-size:12px;text-align:center;">Write for the ancestors. Engrave it in stone.</div>'
        + '<input id="epistleTitle" placeholder="Title..." style="background:#111;color:#ffd700;border:1px solid #8a6a1c;border-radius:8px;padding:12px;font-family:serif;font-size:16px;">'
        + '<textarea id="epistleBody" placeholder="Write your epistle here..." style="width:100%;height:220px;background:#111;color:#fff;border:1px solid #8a6a1c;border-radius:8px;font-family:serif;font-size:14px;padding:12px;box-sizing:border-box;resize:vertical;line-height:1.6;"></textarea>'
        + '<div style="display:flex;gap:10px;">'
        + '<button id="epistleEngrave" style="flex:1;background:#ffd700;color:#111;border:none;border-radius:8px;padding:14px;font-size:16px;cursor:pointer;font-weight:bold;">⚒️ Engrave in Stone</button>'
        + '<button id="epistleClose" style="background:#333;color:#fff;border:none;border-radius:8px;padding:14px 20px;font-size:16px;cursor:pointer;">X</button>'
        + '</div>'
        + '</div>';
      document.body.appendChild(ee);
      document.getElementById('epistleEngrave').onclick = function(){ engraveEpistle(); };
      document.getElementById('epistleClose').onclick = function(){ toggleEpistleEditor(); };
      ee.onclick = function(e){ if(e.target===ee) toggleEpistleEditor(); };
    }else{
      ee.style.display = 'flex';
    }
  }else if(ee){
    ee.style.display = 'none';
  }
}
function engraveEpistle(){
  try{
    var title = document.getElementById('epistleTitle').value || 'Untitled';
    var body = document.getElementById('epistleBody').value || '';
    if(!body){ codeStatus('write something first'); return; }
    // create stone tablet
    var tablet = new THREE.Group();
    var stoneMat = new THREE.MeshStandardMaterial({color:0x3a3a3a, roughness:0.9});
    var slab = new THREE.Mesh(new THREE.BoxGeometry(4, 5, 0.4), stoneMat);
    slab.name = 'epistle-slab';
    tablet.add(slab);
    // gold frame
    var frameMat = new THREE.MeshStandardMaterial({color:0xffd700, metalness:0.8, roughness:0.2});
    var frame = new THREE.Mesh(new THREE.BoxGeometry(4.3, 5.3, 0.2), frameMat);
    frame.position.z = -0.15;
    frame.name = 'epistle-frame';
    tablet.add(frame);
    // render text on canvas
    var canvas = document.createElement('canvas');
    canvas.width = 512; canvas.height = 640;
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = '#2a2a2a';
    ctx.fillRect(0,0,512,640);
    ctx.fillStyle = '#ffd700';
    ctx.font = 'bold 36px serif';
    ctx.textAlign = 'center';
    ctx.fillText(title.substring(0,24), 256, 60);
    ctx.strokeStyle = '#ffd700';
    ctx.lineWidth = 2;
    ctx.beginPath(); ctx.moveTo(60,90); ctx.lineTo(452,90); ctx.stroke();
    ctx.fillStyle = '#e8e8e8';
    ctx.font = '24px serif';
    ctx.textAlign = 'left';
    var words = body.split(' ');
    var lines = [], line = '';
    for(var i=0; i<words.length && lines.length<16; i++){
      var test = line + words[i] + ' ';
      if(ctx.measureText(test).width > 440){ lines.push(line); line = words[i] + ' '; }
      else line = test;
    }
    lines.push(line);
    for(var l=0; l<lines.length; l++){
      ctx.fillText(lines[l], 36, 130 + l*32);
    }
    var tex = new THREE.CanvasTexture(canvas);
    var faceMat = new THREE.MeshStandardMaterial({map:tex, roughness:0.8});
    var face = new THREE.Mesh(new THREE.PlaneGeometry(3.8, 4.8), faceMat);
    face.position.z = 0.21;
    face.name = 'epistle-face';
    tablet.add(face);
    // place in world
    tablet.position.set(-15, 2.5, -15);
    tablet.userData.isPrimitive = true;
    tablet.userData.isEpistle = true;
    if(typeof scene!=='undefined') scene.add(tablet);
    window._epistleTablet = tablet;
    var sceneRef = (typeof scene!=='undefined') ? scene : null;
    pushCommand({
      name: 'engrave epistle "' + title.substring(0,20) + '"',
      execute: function(){ if(sceneRef) sceneRef.add(tablet); },
      undo: function(){ if(sceneRef) sceneRef.remove(tablet); }
    });
    toggleEpistleEditor();
    codeStatus('engraved "' + title.substring(0,20) 