<!-- SAGA-STAGING · part 83 -->
document.createElement("div");
  div.style.cssText = "position:fixed;top:30%;left:20%;right:20%;z-index:300;background:rgba(0,0,0,0.95);border:2px solid #d8a920;border-radius:12px;padding:20px;color:#ffd700;text-align:center;";
  div.innerHTML = "<h3>PRESETS</h3>" + presets.map(function(p, i){
    return "<button data-i='"+i+"' style='display:block;width:80%;margin:8px auto;padding:10px;background:#111;border:1px solid #d8a920;color:#ffd700;border-radius:8px;cursor:pointer;'>"+p[0]+"</button>";
  }).join("") + "<button id='presets-close' style='margin-top:10px;padding:8px 20px;background:#333;color:#ffd700;border:1px solid #d8a920;border-radius:8px;cursor:pointer;'>CLOSE</button>";
  document.body.appendChild(div);
  div.querySelectorAll("[data-i]").forEach(function(b){
    b.addEventListener("click", function(){
      var p = presets[parseInt(b.getAttribute("data-i"))];
      if(typeof kingPos !== "undefined"){ kingPos.x = p[1]; kingPos.z = p[2]; }
      if(typeof say === "function") say("To " + p[0]);
      div.remove();
    });
  });
  document.getElementById("presets-close").addEventListener("click", function(){ div.remove(); });
}
function crownView(){
  if(typeof kingPos !== "undefined" && typeof playerBody !== "undefined" && playerBody){
    kingPos.x = playerBody.position.x + 10;
    kingPos.z = playerBody.position.z + 10;
    if(typeof say === "function") say("Crown view.");
  }
}

/* ===== REAL BUILD — v102 ===== */
function fillGaps(){
  if(typeof runCode === "function"){ runCode("fillgaps"); }
  else if(typeof say === "function") say("Filling gaps.");
}
function recolorBlocks(){
  /* Cycle selected block through colors */
  if(typeof selected !== "undefined" && selected && selected.material){
    var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff, 0xd8a920];
    var cur = selected.material.color ? selected.material.color.getHex() : 0;
    var idx = colors.indexOf(cur);
    var next = colors[(idx + 1) % colors.length];
    if(selected.material.color) selected.material.color.setHex(next);
    if(typeof say === "function") say("Recolored.");
  } else {
    if(typeof say === "function") say("Tap a block first.");
  }
}

/* ===== REAL SOCIAL — v103 ===== */
function sendInvite(){
  var link = window.location.origin + "/saga-solid/";
  if(navigator.share){
    navigator.share({title: "Join my kingdom", url: link});
  } else {
    prompt("Share this link:", link);
  }
  if(typeof say === "function") say("Invite sent.");
}
function showPresence(){
  fetch("/api/chat/online").then(function(r){ return r.json(); }).then(function(d){
    var users = (d.users || []).map(function(u){ return u.username || u; }).join(", ");
    if(typeof say === "function") say(users ? ("Here: " + users) : "Just you.");
  }).catch(function(){ if(typeof say === "function") say("Just you."); });
}
function manageWaypoints(){
  if(typeof runCode === "function") runCode("wps");
  else if(typeof say === "function") say("Waypoints.");
}
function startTreasure(){
  if(typeof say === "function") say("Treasure hunt! Find the gold beacon.");
  /* Place a gold beacon at random location */
  if(typeof scene !== "undefined" && typeof THREE !== "undefined"){
    var g = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.5, 30),
      new THREE.MeshBasicMaterial({color: 0xffd700, transparent: true, opacity: 0.6}));
    var x = (Math.random()-0.5)*200, z = (Math.random()-0.5)*200;
    g.position.set(x, 15, z);
    g.userData.isTreasure = true;
    scene.add(g);
    window._treasureBeacon = g;
  }
}
function toggleWalkline(){
  if(window._walkline){
    scene.remove(window._walkline);
    window._walkline = null;
    if(typeof say === "function") say("Walkline off.");
  } else {
    var pts = [];
    for(var i=0; i<=20; i++) pts.push(new THREE.Vector3(i*5-50, 0.5, 0));
    var geo = new THREE.BufferGeometry().setFromPoints(pts);
    var line = new THREE.Line(geo, new THREE.LineBasicMaterial({color: 0x00ff88}));
    scene.add(line);
    window._walkline = line;
    if(typeof say === "function") say("Walkline on. Follow the green.");
  }
}

/* ===== REAL SYSTEM 1 — v104 ===== */
var _kidMode = false;
function toggleKidMode(){
  _kidMode = !_kidMode;
  if(typeof say === "function") say(_kidMode ? "Kid mode on. Safe and simple." : "Kid mode off.");
}
function startTutorial(){
  if(typeof say === "function"){
    say("Tutorial: Left stick moves. Right stick looks. Tap blocks to build.");
  }
  /* Show the Teach Me guide if it exists */
  if(typeof showTeachMe === "function") showTeachMe();
}
function checkBalance(){
  if(typeof placedBlocks !== "undefined"){
    var n = placedBlocks.length;
    if(typeof say === "function") say(n + " blocks. Balanced.");
  }
}
function shipStatus(){
  if(typeof say === "function") say("Ship: all systems go.");
}
function showHistory(){
  if(typeof readMemory === "function"){
    var m = readMemory();
    if(typeof say === "function") say(m ? "History recalls." :