<!-- LIVE · part 62 -->
p:Date.now()
  };
  this.latest=out;return out;
 },
 requestAI:function(agentId){
  var R=window.ACTOR_RUNTIME;if(!R||!R.ai.allowed)return false;
  R.ai.active=true;R.ai.agentId=String(agentId||"ai");R.ai.control="shadow";return true;
 },
 drive:function(agentId,intent){
  var R=window.ACTOR_RUNTIME;if(!R||!R.ai.active||R.ai.agentId!==String(agentId||"ai"))return false;
  return R.submitIntent("ai",intent||{});
 },
 stop:function(agentId){
  var R=window.ACTOR_RUNTIME;if(!R||R.ai.agentId!==String(agentId||"ai"))return false;
  return R.submitIntent("ai",{moveX:0,moveZ:0,jump:false,ascend:false,descend:false});
 },
 release:function(agentId){
  var R=window.ACTOR_RUNTIME;if(!R||R.ai.agentId!==String(agentId||"ai"))return false;
  R.submitIntent("human",{moveX:0,moveZ:0});R.ai.active=false;R.ai.agentId=null;R.ai.control="none";return true;
 },
 humanTakeover:function(){
  var R=window.ACTOR_RUNTIME;if(!R)return false;
  R.submitIntent("human",{moveX:0,moveZ:0});R.ai.active=false;R.ai.agentId=null;R.ai.control="none";return true;
 }
};
setInterval(function(){try{window.WORLD_INTELLIGENCE.snapshot();}catch(e){}},200);
/* ===== END AI CONTROL INTERFACE — v209 ===== */
/* ===== AI TERRAIN PILOT — v211 ===== */
window.AI_TERRAIN_PILOT={version:211,enabled:false,agentId:"world-ai",decision:"IDLE",ticks:0};
window.AI_TERRAIN_PILOT.tick=function(){var A=this,W=window.WORLD_INTELLIGENCE,R=window.ACTOR_RUNTIME;if(!A.enabled||!W||!R||!R.ai.active||R.ai.agentId!==A.agentId)return;var T=R.terrainPrediction;if(!T){A.decision="WAIT";W.stop(A.agentId);return;}if(T.safe&&T.classification==="SAFE GROUND"){A.decision="FORWARD";W.drive(A.agentId,{moveX:0,moveZ:1});}else{A.decision="STOP / "+T.classification;W.stop(A.agentId);}A.ticks++;};
window.AI_TERRAIN_PILOT.start=function(){var W=window.WORLD_INTELLIGENCE;if(!W||!W.requestAI(this.agentId))return false;this.enabled=true;this.decision="START";return true;};
window.AI_TERRAIN_PILOT.stop=function(){this.enabled=false;this.decision="IDLE";var W=window.WORLD_INTELLIGENCE;if(W)W.stop(this.agentId);return true;};
setInterval(function(){try{window.AI_TERRAIN_PILOT.tick();}catch(e){window.AI_TERRAIN_PILOT.decision="ERROR";}},100);
/* ===== END AI TERRAIN PILOT — v211 ===== */

/* ===== END ACTOR MOBILE DEBUG — v203 ===== */
/* ===== END AI ACTOR RUNTIME — v202 ===== */

function toggleMove(){
  moveModeIdx = (moveModeIdx + 1) % moveModes.length;
  moveMode = moveModes[moveModeIdx];
  if(moveMode === 'still'){
    say('still');
  } else if(moveMode === 'walk'){
    say('walk — joystick to move');
  } else if(moveMode === 'fly'){
    say('fly — joystick to soar');
  }
}



/* Movement applied in animate loop below */

/* ===== PRECISE MAP — canvas, exact positions ===== */
var mapCanvas = null, mapOpen = false;
function toggleMap(){
  if(!mapCanvas){
    mapCanvas = document.createElement('canvas');
    mapCanvas.width = 300; mapCanvas.height = 300;
    mapCanvas.style.cssText = 'position:fixed;top:70px;right:12px;z-index:90;border:2px solid #8a6a1c;border-radius:24px;background:rgba(10,8,4,0.95);display:none;';
    document.body.appendChild(mapCanvas);
  }
  mapOpen = !mapOpen;
  mapCanvas.style.display = mapOpen ? 'block' : 'none';
  if(mapOpen) drawMap();
}
var cityMapImg = new Image();
cityMapImg.src = '/coders100/buttons/city-map.webp';
function drawMap(){
  if(!mapCanvas || !mapOpen) return;
  var ctx = mapCanvas.getContext('2d');
  var W = 300, H = 300;
  /* city map background */
  if(cityMapImg.complete && cityMapImg.naturalWidth > 0){
    ctx.drawImage(cityMapImg, 0, 0, W, H);
  } else {
    ctx.clearRect(0,0,W,H);
  }
  /* range: 400 units across */
  var range = 400, scale = W/range;
  var cx = W/2, cy = H/2;
  /* grid */
  ctx.strokeStyle = '#333'; ctx.lineWidth = 1;
  for(var g=-200; g<=200; g+=50){
    ctx.beginPath(); ctx.moveTo(cx+g*scale, 0); ctx.lineTo(cx+g*scale, H); ctx.stroke();
    ctx.beginPath(); ctx.moveTo(0, cy+g*scale); ctx.lineTo(W, cy+g*scale); ctx.stroke();
  }
  /* north arrow */
  ctx.fillStyle = '#ffd700'; ctx.font = '12px Georgia';
  ctx.fillText('N', cx-4, 16);
  ctx.beginPath(); ctx.moveTo(cx, 20); ctx.lineTo(cx-5, 32); ctx.lineTo(cx+5, 32); ctx.fill();
  /* districts */
  ctx.fillStyle = '#d8a920';
  var dx = (600-kingPos.x)*scale, dz = (600-kingPos.z)*scale;
  if(Math.abs(dx)<W/2 && Math.abs(dz)<H/2){
    ctx.beginPath(); ctx.arc(cx+dx, cy+dz, 6, 0, Math.PI*2); ctx.fill();
    ctx.fillText('Practice', cx+dx+8, cy+dz);
  }
  /* player — precise */
  var px = cx, py = cy;
  ctx.fillStyle = '#00ffff';
  ctx.beginPath(); ctx.arc(px, py, 5, 0, Math.PI*2); ctx.fill();
  /* facing direction */
  var fx = Math.cos(camYaw), fz = Math.sin(camYaw);
  ctx.strokeStyle = '#00ffff'; ctx.lineWidth = 2;
  ctx.beginPath(); ctx.moveTo(px, py); ctx.lineTo(px+fx*20, py+fz*20); ctx.stroke();
  /* coordinates */
  ctx.fillStyle = '#ffd700'; ctx.font = '11px monospace';
  ctx.fillText(Math.round(kingPos.x)+','+Math.round(kingPos.z), 8, H-8);
  