<!-- LIVE · part 102 -->
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');
})();




/* FORTRESS OF THE DEEP — the Imperial Core buried beneath mountains.
   King's word 2026-10-07: underground fortress with tunnels. */
function buildFortressDeep(){
  try{
    var chromeMat = new THREE.MeshStandardMaterial({color: 0xaaaaaa, metalness: 0.9, roughness: 0.2});
    var goldMat = new THREE.MeshStandardMaterial({color: 0xd4a017, metalness: 0.7, roughness: 0.3});
    var darkMat = new THREE.MeshStandardMaterial({color: 0x1a1a1a, roughness: 0.8});
    var holoCyan = new THREE.MeshBasicMaterial({color: 0x00ffff, transparent: true, opacity: 0.4, side: THREE.DoubleSide});
    var holoGold = new THREE.MeshBasicMaterial({color: 0xffd700, transparent: true, opacity: 0.3, side: THREE.DoubleSide});
    var rockMat = new THREE.MeshStandardMaterial({color: 0x3a3a3a, roughness: 0.95});

    var CX = 0, CZ = 0;
    var DEPTH = -80; /* How deep the fortress sits */

    /* GRAND PLAZA — now underground */
    var plaza = new THREE.Mesh(new THREE.CylinderGeometry(60, 65, 2, 32), darkMat);
    plaza.position.set(CX, DEPTH + 1, CZ);
    scene.add(plaza);
    var plazaTrim = new THREE.Mesh(new THREE.TorusGeometry(60, 1, 8, 64), goldMat);
    plazaTrim.rotation.x = Math.PI / 2;
    plazaTrim.position.set(CX, DEPTH + 2, CZ);
    scene.add(plazaTrim);

    /* CENTRAL SPIRE — rising from the deep */
    var spire = new THREE.Mesh(new THREE.CylinderGeometry(4, 8, 80, 8), chromeMat);
    spire.position.set(CX, DEPTH + 42, CZ);
    scene.add(spire);
    var spireCrown = new THREE.Mesh(new THREE.OctahedronGeometry(6), goldMat);
 