<!-- RUBY-BACKUP · part 164 -->
ndChild(holomapCanvas);
      }
      holomapCanvas.style.display = 'block';
      if(typeof drawHolomap==='function') drawHolomap();
    }
  }catch(e){}
}
/* restore bam builds on load */
if(typeof window!=='undefined'){
  window.addEventListener('load', function(){
    setTimeout(function(){
      try{
        var builds = JSON.parse(localStorage.getItem('bam-builds-v1')||'[]');
        builds.forEach(function(b){
          var mat = new THREE.MeshStandardMaterial({color:0xffd700, metalness:0.5, roughness:0.4});
          var mesh = null;
          if(b.shape==='box') mesh = new THREE.Mesh(new THREE.BoxGeometry(b.size, b.size, b.size), mat);
          else if(b.shape==='sphere') mesh = new THREE.Mesh(new THREE.SphereGeometry(b.size/2, 16, 12), mat);
          else if(b.shape==='tower') mesh = new THREE.Mesh(new THREE.BoxGeometry(b.size/2, b.size*3, b.size/2), mat);
          else if(b.shape==='wall') mesh = new THREE.Mesh(new THREE.BoxGeometry(b.size*3, b.size, b.size/4), mat);
          if(mesh && typeof scene!=='undefined'){
            mesh.position.set(b.x, b.y, b.z);
            mesh.name = 'bam-restored';
            scene.add(mesh);
          }
        });
      }catch(e){}
    }, 3000);
  });
}
if(typeof window!=='undefined'){
  window.addEventListener('load', function(){ setTimeout(ensurePermanentMap, 2000); });
  setTimeout(function(){ try{ ensurePermanentMap(); }catch(e){} }, 3000);
}
function toggleHolomap(){
  HOLOMAP_ON = !HOLOMAP_ON;
  if(HOLOMAP_ON){
    if(!holomapCanvas){
      holomapCanvas = document.createElement('canvas');
      holomapCanvas.width = 200; holomapCanvas.height = 200;
      holomapCanvas.style.cssText = 'position:fixed;top:70px;right:10px;z-index:9999;border:1px solid #00ffff;background:rgba(0,20,30,0.7);border-radius:8px;';
      document.body.appendChild(holomapCanvas);
    }
    holomapCanvas.style.display = 'block';
    drawHolomap();
    codeStatus('HOLOMAP — future style, cyan hologram');
  }else{
    if(holomapCanvas) holomapCanvas.style.display = 'none';
    codeStatus('holomap off');
  }
}
var HOLOMAP_EXPANDED = false;
var HOLOMAP_MODE = 0; /* 0=surface, 1=underworld, 2=galaxies */
var GALAXIES = [
  {n:'Milky Way', x:0, z:0, s:12, c:'#ffffff'},
  {n:'Andromeda', x:40, z:-30, s:10, c:'#ffccff'},
  {n:'Triangulum', x:-50, z:20, s:7, c:'#ccffff'},
  {n:'Large Magellanic', x:25, z:45, s:6, c:'#ffffcc'},
  {n:'Whirlpool', x:-35, z:-45, s:8, c:'#ffcccc'},
  {n:'Sombrero', x:60, z:10, s:7, c:'#ccffcc'},
  {n:'Pinwheel', x:-60, z:-10, s:9, c:'#ccccff'},
  {n:'Centaurus A', x:10, z:-60, s:8, c:'#ffddaa'}
];
function toggleHolomapExpand(){
  HOLOMAP_EXPANDED = !HOLOMAP_EXPANDED;
  try{
    if(HOLOMAP_EXPANDED){
      holomapCanvas.style.cssText = 'position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);z-index:10001;border:2px solid #00ffff;background:rgba(0,20,30,0.92);border-radius:12px;width:70vw;height:70vw;max-width:400px;max-height:400px;';
      holomapCanvas.width = 400; holomapCanvas.height = 400;
    }else{
      holomapCanvas.style.cssText = 'position:fixed;top:70px;right:10px;z-index:9999;border:1px solid #00ffff;background:rgba(0,20,30,0.7);border-radius:8px;width:200px;height:200px;';
      holomapCanvas.width = 200; holomapCanvas.height = 200;
    }
    drawHolomap();
  }catch(e){}
}
/* map mode cycle: tap top-left corner to switch Surface/Underworld/Galaxies */
function cycleHolomapMode(){
  HOLOMAP_MODE = (HOLOMAP_MODE+1)%3;
  var names = ['SURFACE','UNDERWORLD','GALAXIES'];
  try{ codeStatus('map: ' + names[HOLOMAP_MODE]); }catch(e){}
  try{ drawHolomap(); }catch(e){}
}
/* tap expanded map to teleport */
if(typeof window!=='undefined'){
  setTimeout(function(){
    try{
      if(typeof holomapCanvas!=='undefined' && holomapCanvas){
        holomapCanvas.addEventListener('click', function(e){
          var rect = holomapCanvas.getBoundingClientRect();
          var tapY = (e.clientY - rect.top) / rect.height;
          /* top 10% = mode cycle */
          if(tapY < 0.1){
            cycleHolomapMode();
            return;
          }
          if(HOLOMAP_EXPANDED){
            var cx = (e.clientX - rect.left) / rect.width;
            var cy = (e.clientY - rect.top) / rect.height;
            if(HOLOMAP_MODE===2) return; /* no teleport in galaxy mode */
            var wx = cx * 2600 - 1300;
            var wz = cy * 2600 - 1300;
            /* snap to nearest building or road segment if close */
            try{
              if(HOLOMAP_MODE===0){
                var best = null, bestD = 80;
                if(typeof window._cityDots!=='undefined'){
                  window._cityDots.forEach(function(pt){
                    var d = Math.sqrt((pt[0]-wx)*(pt[0]-wx) + (pt[1]-wz)*(pt[1]-wz));
                    if(d < bestD){ bestD = d; best = pt; }
                  });
                }
                if(typeof window._roadPts!=='undefined'){
                  window._roadPts.forEach(function(pt){
            