<!-- LIVE · part 73 -->
orld');
  }catch(e){ if(typeof codeStatus==='function') codeStatus('creator hall failed'); }
}

window.__sagaExecMark('5924');
// Build Playa 2.0 Creator Hall on startup — King order 2026-10-03
if(typeof buildCreatorHall === "function"){ try{ buildCreatorHall(); }catch(e){ console.error(e); } }


window.__sagaExecMark('5928');
/* SOLID'S MEMORY — every site remembers what was built on it. King order 2026-10-05.
   This code ships in ALL builds from here on. No Python on top: plain JS. */
function buildMemoryLog(){
  var site = (location.pathname.split('/')[1] || 'root');
  window._memorySite = site;
  window.logBuild = function(what){
    try{
      var log = JSON.parse(localStorage.getItem('solid-memory') || '[]');
      log.push({t:Date.now(), site:site, what:String(what)});
      if(log.length > 200) log = log.slice(-(200));
      localStorage.setItem('solid-memory', JSON.stringify(log));
    }catch(e){ console.error(e); }
  };
  window.readMemory = function(n){
    try{
      var log = JSON.parse(localStorage.getItem('solid-memory') || '[]');
      return log.filter(function(e){ return e.site === site; }).slice(-(n || 10));
    }catch(e){ return []; }
  };
  window.logBuild('regime raised');
}

buildMemoryLog(); /* memory before building */

window.__sagaExecMark('5952');
/* THE KING'S CASTLE — put it down, save it forever. King order 2026-10-05. */
window._castles = window._castles || [];
function buildCastleAt(x, z, animate){
  try{
    var g = new THREE.Group();
    var stone = new THREE.MeshStandardMaterial({color:0x8a8a8a, roughness:0.7, metalness:0.2});
    var dark = new THREE.MeshStandardMaterial({color:0x5a5a6a, roughness:0.6, metalness:0.3});
    var goldm = new THREE.MeshStandardMaterial({color:0xd8a920, roughness:0.3, metalness:0.8});
    var order = [];
    function part(name, geo, mat, px, py, pz, ry){
      var msh = new THREE.Mesh(geo, mat);
      msh.name = name; msh.position.set(px, py, pz);
      if(ry) msh.rotation.y = ry;
      msh.castShadow = true;
      g.add(msh); order.push(msh); return msh;
    }
    part('base', new THREE.BoxGeometry(30, 4, 30), stone, 0, 2, 0);
    part('keep', new THREE.BoxGeometry(12, 12, 12), stone, 0, 10, 0);
    for(var i = 0; i < 4; i++){
      var a = i * Math.PI / 2;
      part('tower-' + i, new THREE.CylinderGeometry(3, 3.5, 14, 8), dark, Math.sin(a + Math.PI / 4) * 14, 11, Math.cos(a + Math.PI / 4) * 14);
    }
    for(var j = 0; j < 4; j++){
      var b = j * Math.PI / 2;
      part('wall-' + j, new THREE.BoxGeometry(30, 8, 2), stone, Math.sin(b) * 14, 8, Math.cos(b) * 14, b);
    }
    for(var k = 0; k < 4; k++){
      var c = k * Math.PI / 2;
      part('spire-' + k, new THREE.ConeGeometry(2, 6, 8), goldm, Math.sin(c + Math.PI / 4) * 14, 21, Math.cos(c + Math.PI / 4) * 14);
    }
    part('flag', new THREE.BoxGeometry(0.5, 4, 2.5), goldm, 0, 18, 0);
    g.position.set(x, 0, z);
    g.userData.isCastle = true;
    scene.add(g);
    window._castles.push(g);
    if(animate){
      order.forEach(function(m){ m.visible = false; });
      order.forEach(function(m, i){
        setTimeout(function(){ m.visible = true; }, i * 200);
      });
      if(window.logBuild) window.logBuild('castle raised');
      if(order.length && typeof say === 'function')
        setTimeout(function(){ say('Castle stands — forever'); }, order.length * 200);
    }
    return g;
  }catch(e){ return null; }
}
function saveCastle(x, z){
  try{
    var list = JSON.parse(localStorage.getItem('saga-solid-castles') || '[]');
    list.push({x:Math.round(x), z:Math.round(z)});
    localStorage.setItem('saga-solid-castles', JSON.stringify(list));
  }catch(e){ console.error(e); }
}
function restoreCastles(){
  try{
    var list = JSON.parse(localStorage.getItem('saga-solid-castles') || '[]');
    list.forEach(function(c){
      if(isFinite(c.x) && isFinite(c.z)) buildCastleAt(c.x, c.z, true);
    });
  }catch(e){ console.error(e); }
}
window.__sagaExecMark('6014');

/* v190 — core scope bridge active */
CODES['castle'] = {cat:'Special', desc:'Put the castle down — saved to the map forever', fn:function(a){
  var x = kingPos.x + 40, z = kingPos.z + 40;
  var g = buildCastleAt(x, z, true);
  if(g){ saveCastle(x, z); }
}};
window.__sagaExecMark('CASTLE OK');
CODES['uncastle'] = {cat:'Special', desc:'Remove the nearest castle', fn:function(a){
  var best = null, bd = 80;
  window._castles.forEach(function(g){
    var d = Math.hypot(g.position.x - kingPos.x, g.position.z - kingPos.z);
    if(d < bd){ bd = d; best = g; }
  });
  if(!best){ say('no castle near'); return; }
  scene.remove(best);
  var i = window._castles.indexOf(best);
  if(i > -1) window._castles.splice(i, 1);
  try{
    var list = JSON.parse(localStorage.getItem('saga-solid-castles') || '[]');
    var bi = -1, bdd = 80;
    list.forEach(function(c, idx){
      var d = Math.hypot(c.x - best.position.x, c.z - best.position.z);
      if(d < bdd){ bdd = d; bi = idx; }
    });
    if(bi > -1){ list.splic