<!-- SAGA-STAGING · part 103 -->
ort as backup
    var abort = document.getElementById('v219-abort');
    if(abort) abort.click();
  };

  /* ---------- State refresh ---------- */
  function refreshCockpit(){
    try {
      var R = window.ACTOR_RUNTIME;
      var SD = window.SOLID_DRIVE;
      if(!R) return;

      // Pill state
      var aiDriving = R.authority === 'ai_guarded' && R.ai && R.ai.active;
      var aiName = (window.AI_DRIVER && window.AI_DRIVER.activeAgent)
        ? window.AI_DRIVER.activeAgent.name
        : ((window.SOLID_DRIVE && window.SOLID_DRIVE._agentName) || 'SOLID');
      if(aiDriving){
        pill.textContent = '◉ ' + aiName.toUpperCase() + ' DRIVING';
        pill.style.color = CYAN;
        pill.style.borderColor = CYAN;
        takeover.style.display = 'block';
      } else {
        pill.textContent = '◉ YOU DRIVE';
        pill.style.color = GOLD;
        pill.style.borderColor = GOLD;
        takeover.style.display = 'none';
      }

      // Drive status
      var ds = document.getElementById('cockpit-drive-status');
      var authBtn = document.getElementById('cockpit-authorize');
      if(ds){
        var connName = (window.AI_DRIVER && window.AI_DRIVER.activeAgent)
          ? window.AI_DRIVER.activeAgent.name
          : ((SD && SD._agentName) || null);
        if(SD && SD.active){
          ds.innerHTML = '<span style="color:' + CYAN + ';">● Connected</span>' +
            (connName ? '<span style="color:' + DIM + ';font-size:12px;"> — ' + connName + '</span>' : '');
          if(authBtn) authBtn.style.display = 'none';
        } else if(connName){
          ds.innerHTML = '<span style="color:' + CYAN + ';">AI: ' + connName + ' — READY</span>';
          if(authBtn) authBtn.style.display = 'none';
        } else {
          ds.innerHTML = '<span style="color:' + DIM + ';">No AI connected</span>';
          if(authBtn) authBtn.style.display = 'block';
        }
      }

      // Safety
      var sv = R.safetySupervisor;
      var ss = document.getElementById('ck-safety-state');
      if(ss && sv){
        ss.textContent = sv.status + (sv.permit ? ' ✓' : '');
        ss.style.color = (sv.status === 'SAFE' && sv.permit) ? '#7ab87a' : WINE;
      }
      var ca = document.getElementById('ck-authority');
      if(ca) ca.textContent = R.authority;
      var co = document.getElementById('ck-owner');
      if(co){
        co.textContent = R.input.owner === 'human' ? 'YOU' : 'SOLID';
        co.style.color = R.input.owner === 'human' ? GOLD : CYAN;
      }

      // Diagnostics (from hidden SD panel)
      var diagSrc = document.getElementById('sd-diag');
      var diagDst = document.getElementById('cockpit-diag-body');
      if(diagSrc && diagDst) diagDst.textContent = diagSrc.textContent;

    } catch(e){}
  }

  // Refresh pill every 500ms (lightweight)
  setInterval(function(){
    try {
      var R = window.ACTOR_RUNTIME;
      if(!R) return;
      var aiDriving = R.authority === 'ai_guarded' && R.ai && R.ai.active;
      var aiName2 = (window.AI_DRIVER && window.AI_DRIVER.activeAgent)
        ? window.AI_DRIVER.activeAgent.name
        : ((window.SOLID_DRIVE && window.SOLID_DRIVE._agentName) || 'SOLID');
      if(aiDriving){
        pill.textContent = '◉ ' + aiName2.toUpperCase() + ' DRIVING';
        pill.style.color = CYAN;
        pill.style.borderColor = CYAN;
        takeover.style.display = 'block';
      } else {
        pill.textContent = '◉ YOU DRIVE';
        pill.style.color = GOLD;
        pill.style.borderColor = GOLD;
        takeover.style.display = 'none';
      }
    } catch(e){}
  }, 500);

  // Also sync hidden SD status display for its internal logic
  var origSdSetStatus = window._sdSetStatusHook;
  setInterval(refreshCockpit, 2000);

  if(window.console) console.log('[Cockpit] Installed');
})();





/* ===== NEW WORLD — first playable region. King's order 2026-10-07 ===== */
/* Staging only. Spawn, hill, valley, plateau, landmark. Explicit registry. */
function buildNewWorld(){
  try {
    if(window._newWorldBuilt) return;
    window._newWorldBuilt = true;
    
    var terrainMat = new THREE.MeshStandardMaterial({color: 0x3a6a3a, roughness: 0.9});
    var rockMat = new THREE.MeshStandardMaterial({color: 0x6a6a6a, roughness: 0.95});
    var sandMat = new THREE.MeshStandardMaterial({color: 0xc4a060, roughness: 0.9});
    
    // 1. SPAWN PLAIN — large flat area at origin (200x200)
    var plain = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), terrainMat);
    plain.rotation.x = -Math.PI/2;
    plain.position.set(0, 0, 0);
    plain.receiveShadow = true;
    scene.add(plain);
    if(window.WORLD_REGISTRY) window.WORLD_REGISTRY.register(plain, 'terrain-spawn');
    if(window.WF && window.WF.registerSurface) window.WF.registerSurface(plain, 'ground', {name:'spawn_plain'});
    
    // 2. HILL — gentle rise to the north (at z=-80)
    var hillGeo = new THREE.SphereGeometry(40, 24, 16, 0, Math.PI*2, 0, Math.PI/2);
    var hill = new THREE.Mesh(hillG