<!-- RUBY-BACKUP · part 165 -->
        var d = Math.sqrt((pt[0]-wx)*(pt[0]-wx) + (pt[1]-wz)*(pt[1]-wz));
                    if(d < bestD){ bestD = d; best = pt; }
                  });
                }
                if(best){ wx = best[0]; wz = best[1]; }
              }
            }catch(e){}
            /* teleport player */
            if(typeof mePos!=='undefined'){
              mePos.x = wx; mePos.z = wz;
              if(typeof fortifiedGroundY==='function') mePos.y = fortifiedGroundY(wx, wz) + 5;
            }
            try{ codeStatus('teleported to map point'); }catch(e2){}
            toggleHolomapExpand();
          }else{
            toggleHolomapExpand();
          }
        });
      }
    }catch(e){}
  }, 5000);
}
function drawHolomap(){
  try{
    if(!HOLOMAP_ON || !holomapCanvas) return;
    var ctx = holomapCanvas.getContext('2d');
    var S = holomapCanvas.width;
    ctx.clearRect(0,0,S,S);
    /* background */
    ctx.fillStyle = 'rgba(0,20,30,0.85)';
    ctx.fillRect(0,0,S,S);
    /* map world -1300..1300 to 0..S */
    function mx(x){ return (x+1300)/2600*S; }
    function mz(z){ return (z+1300)/2600*S; }
    /* highways in gold */
    try{
      if(typeof _highwayPts!=='undefined'){
        ctx.strokeStyle = '#ffd700';
        ctx.lineWidth = Math.max(1, S/150);
        _highwayPts.forEach(function(pts){
          ctx.beginPath();
          for(var i=0; i<pts.length; i++){
            var hx = mx(pts[i][0]), hz = mz(pts[i][1]);
            if(i===0) ctx.moveTo(hx, hz); else ctx.lineTo(hx, hz);
          }
          ctx.stroke();
        });
        ctx.lineWidth = 1;
      }
    }catch(e){}
    /* player as cyan dot */
    try{
      if(typeof mePos!=='undefined'){
        ctx.fillStyle = '#00ffff';
        ctx.beginPath();
        ctx.arc(mx(mePos.x), mz(mePos.z), Math.max(3, S/60), 0, 7);
        ctx.fill();
      }
    }catch(e){}
    /* title */
    ctx.fillStyle = '#00ffff';
    ctx.font = 'bold ' + Math.floor(S/16) + 'px sans-serif';
    ctx.fillText('MAP', 8, Math.floor(S/14));
    /* Admin lat/lon on the expanded map */
    try{
      if(window._isAdmin && typeof mePos !== 'undefined' && HOLOMAP_EXPANDED){
        ctx.fillStyle = '#a0a0a0';
        ctx.font = Math.floor(S/22) + 'px monospace';
        ctx.fillText('LAT ' + mePos.z.toFixed(1), 8, S - Math.floor(S/11));
        ctx.fillText('LON ' + mePos.x.toFixed(1), 8, S - Math.floor(S/22));
        /* Crosshair at player position */
        var px = mx(mePos.x), pz = mz(mePos.z);
        ctx.strokeStyle = '#ff0000';
        ctx.lineWidth = 2;
        ctx.beginPath();
        ctx.moveTo(px - 10, pz); ctx.lineTo(px + 10, pz);
        ctx.moveTo(px, pz - 10); ctx.lineTo(px, pz + 10);
        ctx.stroke();
        /* King's dot — black and white */
        ctx.beginPath();
        ctx.arc(px, pz, 6, 0, Math.PI * 2);
        ctx.fillStyle = '#000000';
        ctx.fill();
        ctx.lineWidth = 2;
        ctx.strokeStyle = '#ffffff';
        ctx.stroke();
        ctx.beginPath();
        ctx.arc(px, pz, 2, 0, Math.PI * 2);
        ctx.fillStyle = '#ffffff';
        ctx.fill();
        /* Solid's dot — glowing purple, blue, white */
        try{
          if(window._solidAvatar){
            var sp = window._solidAvatar.position;
            var sx = mx(sp.x), sz2 = mz(sp.z);
            /* Glow layers */
            var glow = ctx.createRadialGradient(sx, sz2, 0, sx, sz2, 14);
            glow.addColorStop(0, 'rgba(255,255,255,0.9)');
            glow.addColorStop(0.4, 'rgba(100,100,255,0.6)');
            glow.addColorStop(0.7, 'rgba(150,50,255,0.4)');
            glow.addColorStop(1, 'rgba(150,50,255,0)');
            ctx.beginPath();
            ctx.arc(sx, sz2, 14, 0, Math.PI * 2);
            ctx.fillStyle = glow;
            ctx.fill();
            /* Core dot */
            ctx.beginPath();
            ctx.arc(sx, sz2, 4, 0, Math.PI * 2);
            ctx.fillStyle = '#ffffff';
            ctx.fill();
            ctx.beginPath();
            ctx.arc(sx, sz2, 2, 0, Math.PI * 2);
            ctx.fillStyle = '#9966ff';
            ctx.fill();
          }
        }catch(e){}
      }
    }catch(e){}
  }catch(e){}
}

setInterval(function(){ if(HOLOMAP_ON) drawHolomap(); }, 2000);

/* SPAWN POINT + MOVE + DIMENSIONALITY + LOCK — future builder system */
var SPAWN_PT = null; /* {x, z} — where new objects appear */
var MOVE_MODE = false;
var MOVE_HELD = null; /* stone being moved */
var BUILD_DIM = 3; /* 2-6, dimensionality for new objects */

function setSpawnPoint(){
  if(typeof mePos!=='undefined'){
    SPAWN_PT = {x: Math.round(mePos.x), z: Math.round(mePos.z)};
    try{ localStorage.setItem('ruby-spawnpt', JSON.stringify(SPAWN_PT)); }catch(e){}
    codeStatus('spawn point set at '+SPAWN_PT.x+', '+SPAWN_PT.z+' — new objects appear here');
  }
}

/* spawn point visual marker + coordinate move */
var spawnMarker = null;
function showSpawnMarker(){
  var sp = getSpawnPoint();
  if(typeof THREE==='undefined') return;
  if