<!-- SAGA-STAGING · part 84 -->
 "No history yet.");
  } else if(typeof say === "function") say("No history yet.");
}

window.__sagaExecMark('7120');

/* ===== REAL SYSTEM 2 — v105 ===== */
function openWear(){
  if(typeof say === "function") say("Wear: your avatar wears what you choose.");
  /* Cycle avatar colors */
  if(typeof window._epistolary !== "undefined" && window._epistolary){
    var colors = [0x2a2a35, 0xd8a920, 0x00ccff, 0xff0000];
    var cur = window._epistolary.userData.wearIdx || 0;
    cur = (cur + 1) % colors.length;
    window._epistolary.userData.wearIdx = cur;
    window._epistolary.traverse(function(o){
      if(o.material && o.material.color) o.material.color.setHex(colors[cur]);
    });
  }
}
var _redSeams = false;
function toggleRedSeams(){
  _redSeams = !_redSeams;
  if(typeof placedBlocks !== "undefined"){
    placedBlocks.forEach(function(b){
      b.traverse(function(o){
        if(o.material && o.material.emissive){
          o.material.emissive.setHex(_redSeams ? 0xff0000 : 0x000000);
        }
      });
    });
  }
  if(typeof say === "function") say(_redSeams ? "Red seams on." : "Red seams off.");
}
function tapToCrown(){
  if(typeof say === "function") say("Tap a block to crown it.");
  window._crownMode = true;
}
function switchDimension(){
  if(typeof runCode === "function") runCode("dim");
  else if(typeof say === "function") say("Dimension shifted.");
}
function openSoliditronium(){
  if(typeof runCode === "function") runCode("soliditronium");
  else if(typeof say === "function") say("Soliditronium online.");
}
function openCapsule(){
  if(typeof say === "function") say("Capsule: your saved builds.");
  if(typeof runCode === "function") runCode("capsule");
}

/* ===== REAL TOOLBAR — v106 ===== */
function setCreateMode(){ if(typeof activeTool !== "undefined") activeTool = "create"; if(typeof say === "function") say("Create mode."); }
function setDeleteMode(){ if(typeof activeTool !== "undefined") activeTool = "delete"; if(typeof say === "function") say("Delete mode."); }
function showShapes(){ if(typeof runCode === "function") runCode("shapes"); else if(typeof say === "function") say("Shapes."); }
function showRender(){ if(typeof say === "function") say("Render options."); }
function doJump(){ if(typeof runCode === "function") runCode("jump"); else if(typeof say === "function") say("Jump!"); }
function setGrabMode(){ if(typeof activeTool !== "undefined") activeTool = "grab"; if(typeof say === "function") say("Grab mode."); }
function openChat(){ if(typeof say === "function") say("Chat."); }
function goToDialog(){ var d = prompt("Go to LAT,LON:"); if(d && typeof runCode === "function") runCode("tp " + d.replace(",", " ")); }
function toggleMusic(){ if(typeof say === "function") say("Music."); }
function openContinuum(){ if(typeof say === "function") say("Continuum."); }
function setPlaceMode(){ if(typeof activeTool !== "undefined") activeTool = "place"; if(typeof say === "function") say("Place mode."); }
function showHelp(){ if(typeof showTeachMe === "function") showTeachMe(); else if(typeof say === "function") say("Help: move, look, tap, build."); }
function openFixStation(){ if(typeof say === "function") say("Fix station."); }
function showSky(){ if(typeof say === "function") say("Sky options."); }
window.__sagaExecMark('7170');

// BATTLE ENGAGEMENT + TARGET LOCK + CANNONS - King's order 2026-10-06.
(function(){
  if(window.battleDone) return;
  window.battleDone = true;

  window._lockedTarget = null;
  window._inBattle = false;
  window._targets = [];

  // Lock visual: red diamond
  var lockMesh = null;
  function showLock(target){
    hideLock();
    if(!target || !target.position) return;
    var geo = new THREE.OctahedronGeometry(1.2);
    var mat = new THREE.MeshBasicMaterial({color:0xff0033, wireframe:true});
    lockMesh = new THREE.Mesh(geo, mat);
    lockMesh.position.copy(target.position);
    lockMesh.position.y += 3;
    scene.add(lockMesh);
  }
  function hideLock(){
    if(lockMesh && lockMesh.parent) lockMesh.parent.remove(lockMesh);
    lockMesh = null;
  }
  function updateLock(){
    if(lockMesh && window._lockedTarget && window._lockedTarget.position){
      lockMesh.position.copy(window._lockedTarget.position);
      lockMesh.position.y += 3;
      lockMesh.rotation.y += 0.05;
    }
  }
  setInterval(updateLock, 50);

  // Tap to lock: raycast on tap (not on joystick)
  var raycaster = new THREE.Raycaster();
  var tapPos = new THREE.Vector2();
  document.addEventListener('touchstart', function(e){
    // Only if not on joystick or buttons (left 40% bottom 40% is joystick zone)
    var t = e.touches[0];
    if(t.clientX < window.innerWidth * 0.45 && t.clientY > window.innerHeight * 0.55) return;
    // Don't interfere with cannon button or UI
    if(e.target !== document.body && e.target !== document.querySelector('canvas')) return;
  }, {passive:true});

  document.addEventListener('touchend', function(e){
    var t = e.changedTouches[0];
  