<!-- RUBY-BACKUP · part 157 -->
 the map */
var _origDrawHolomap = null;

/* THE MAP FILLS: you plant, you visit, it blooms. The winner's map is full. */
var POIS_VISITED = {};
try{
  var pv = localStorage.getItem('ruby-pois-visited');
  if(pv) POIS_VISITED = JSON.parse(pv);
}catch(e){}
function savePoisVisited(){
  try{ localStorage.setItem('ruby-pois-visited', JSON.stringify(POIS_VISITED)); }catch(e){}
}
function markPoiVisited(name){
  if(!POIS_VISITED[name]){
    POIS_VISITED[name] = true;
    savePoisVisited();
    try{
      var count = Object.keys(POIS_VISITED).length;
      if(count >= 20){
        codeStatus('The map is filled. You did it.');
        if(typeof playfulSparkle==='function' && typeof mePos!=='undefined'){
          playfulSparkle(new THREE.Vector3(mePos.x, mePos.y+3, mePos.z), 0xffd700);
        }
      }
    }catch(e){}
  }
}
setInterval(function(){
  try{
    if(typeof mePos==='undefined' || typeof MAP_POIS==='undefined') return;
    MAP_POIS.forEach(function(poi){
      var d = Math.sqrt(Math.pow(mePos.x-poi.x,2) + Math.pow(mePos.z-poi.z,2));
      if(d < 8) markPoiVisited(poi.name);
    });
  }catch(e){}
}, 2000);




/* FIX STATION — the creator */
var FIX_STATION = null;
var FIX_BTN = null;
function warpFixStation(){
  try{
    if(FIX_BTN){ document.body.removeChild(FIX_BTN); FIX_BTN = null; }
    if(FIX_STATION){ document.body.removeChild(FIX_STATION); FIX_STATION = null; return; }
    FIX_BTN = document.createElement('button');
    FIX_BTN.textContent = '🙌';
    FIX_BTN.style.cssText = 'position:fixed;left:12px;top:38%;z-index:20001;width:56px;height:56px;border-radius:50%;font-size:28px;cursor:pointer;background:rgba(0,0,0,0.9);border:2px solid #ffd700;';
    FIX_BTN.onclick = function(){
      document.body.removeChild(FIX_BTN); FIX_BTN = null;
      // /solid in COLLAPSED mode (not expanded)
      if(typeof warpSolid==='function'){ warpSolid(); }
      setTimeout(function(){
        try{ if(document.activeElement && document.activeElement.blur) document.activeElement.blur(); }catch(e){}
        // ensure /solid stays collapsed
        try{
          var sk = document.querySelector('[style*="z-index:20000"]');
          if(sk && sk.style.height !== '70%') sk.style.height = '70%';
        }catch(e){}
        openFixStation();
      }, 500);
    };
    document.body.appendChild(FIX_BTN);
    try{ codeStatus('Tap 🤲 to open.'); }catch(e){}
  }catch(e){}
}
function openFixStation(){
  try{
    FIX_STATION = document.createElement('div');
    FIX_STATION.style.cssText = 'position:fixed;top:0;right:0;width:60%;height:60%;z-index:20002;background:#0d0d12;border-bottom:3px solid #00ff88;border-left:3px solid #00ff88;border-radius:0 0 0 16px;display:flex;flex-direction:column;';
    var bar = document.createElement('div');
    bar.style.cssText = 'padding:12px;display:flex;justify-content:space-between;align-items:center;border-bottom:1px solid #333;';
    bar.innerHTML = '<span style="color:#00ff88;font-size:15px;">🤲 Creator</span>';
    var x = document.createElement('button');
    x.textContent = '\u2715';
    x.style.cssText = 'background:none;border:1px solid #666;border-radius:6px;color:#888;padding:6px 12px;cursor:pointer;';
    x.onclick = function(){ warpFixStation(); };
    bar.appendChild(x);
    FIX_STATION.appendChild(bar);
    var body = document.createElement('div');
    body.style.cssText = 'flex:1;position:relative;overflow:hidden;'
      + 'background:repeating-linear-gradient(0deg,transparent,transparent 19px,rgba(0,0,0,0.3) 20px),'
      + 'repeating-linear-gradient(90deg,transparent,transparent 19px,rgba(0,0,0,0.3) 20px),'
      + '#ffffff;';
    // creator table label
    var label = document.createElement('div');
    label.textContent = 'CREATOR TABLE';
    label.style.cssText = 'position:absolute;top:8px;left:0;right:0;text-align:center;color:#ffd700;font-size:10px;letter-spacing:3px;opacity:0.5;';
    body.appendChild(label);
    // the object — center
    var objWrap = document.createElement('div');
    objWrap.style.cssText = 'position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);text-align:center;';
    var selName = (window._selectedBlock && window._selectedBlock.name) ? window._selectedBlock.name.substring(0,20) : 'object';
    objWrap.innerHTML = '<div style="font-size:64px;">🧳</div><div style="color:#ffd700;font-size:11px;margin-top:4px;">'+selName+'</div>';
    body.appendChild(objWrap);
    var handsOn = false;
    var hand = document.createElement('div');
    hand.textContent = '🙌';
    hand.style.cssText = 'position:absolute;bottom:12px;left:50%;transform:translateX(-50%);font-size:48px;cursor:pointer;';
    hand.onclick = function(){
      handsOn = !handsOn;
      hand.textContent = handsOn ? '🤲' : '🙌';
      hand.style.fontSize = handsOn ? '80px' : '48px';
      try{ codeStatus(handsOn ? 'Hands ON.' : 'Hands OFF.'); }catch(e){}
    };
    body.appendChild(hand);
    // buttons AROUND the object
    var tools = [['🎯','calibra