<!-- RUBY-BACKUP · part 328 -->
e!=='undefined') scene.add(g);
      window._highwaySigns = g;
    }
    /* else: signs live inside the highway group — permanently fixed */
    var sceneRef = (typeof scene!=='undefined') ? scene : null;
    pushCommand({
      name: 'build highway signs',
      execute: function(){ if(sceneRef) sceneRef.add(g); },
      undo: function(){ if(sceneRef) sceneRef.remove(g); }
    });
    if(typeof codeStatus==='function') codeStatus(ANCESTOR_NAMES.length + ' ancestor signs stand');
  }catch(e){ if(typeof codeStatus==='function') codeStatus('highway signs failed'); }
}
/* DISTRICT ACTIVATION — King chooses what loads, nothing auto */
window._districts = {};
function registerDistrict(name, label, buildFn){
  window._districts[name] = {label:label, build:buildFn, loaded:false};
}
function toggleDistrict(name){
  try{
    var d = window._districts[name];
    if(!d) return;
    if(!d.loaded){
      d.build();
      d.loaded = true;
      if(typeof codeStatus==='function') codeStatus(d.label+' activated');
    }else{
      if(typeof codeStatus==='function') codeStatus(d.label+' already built');
    }
  }catch(e){}
}
/* ONE BUTTON — tap to activate next district */
(function(){
  try{
    var order = ['palace','phi','practice','bridges','sovereign'];
    var labels = {palace:'\uD83C\uDFF0 Palace', phi:'\u03A6 Phi', practice:'\uD83C\uDF93 Practice', bridges:'\uD83C\uDF09 Bridges', sovereign:'\u26A1 Sovereign'};
    var idx = 0;
    var btn = document.createElement('button');
    btn.id = 'district-one-btn';
    btn.innerHTML = '\uD83C\uDFDB\uFE0F';
    btn.title = 'Activate next district';
    btn.style.cssText = 'width:56px;height:56px;min-width:56px;min-height:56px;background:#8a6a1c;color:#ffd700;border:2px solid #ffd700;border-radius:50%;font-size:22px;line-height:1;padding:0;margin:0;cursor:pointer;-webkit-tap-highlight-color:transparent;flex-shrink:0;';
    btn.onclick = function(){
      try{
        // find next unbuilt district
        for(var i=0; i<order.length; i++){
          var n = order[(idx+i)%order.length];
          var d = window._districts[n];
          if(d && !d.loaded){
            toggleDistrict(n);
            idx = (idx+i+1)%order.length;
            // show what's next
            var next = order[idx];
            btn.title = 'Next: '+labels[next];
            return;
          }
        }
        if(typeof codeStatus==='function') codeStatus('all districts built');
      }catch(e){}
    };
    var anchor = document.getElementById('map-toggle-btn');
    if(anchor && anchor.parentNode){ anchor.parentNode.insertBefore(btn, anchor.nextSibling); }
    else document.body.appendChild(btn);
    // reliable collector: keep trying to move into menu panel
    var _mtries = 0;
    var _mtimer = setInterval(function(){
      _mtries++;
      try{
        var panel = document.getElementById('buttonmenupanel');
        var mb = document.getElementById('district-one-btn');
        if(panel && mb && !panel.contains(mb)){
          mb.style.position='static'; mb.style.bottom='auto'; mb.style.right='auto';
          panel.appendChild(mb);
        }
        var tb = document.getElementById('map-toggle-btn');
        if(panel && tb && !panel.contains(tb)){
          tb.style.position='static'; tb.style.bottom='auto'; tb.style.right='auto';
          panel.appendChild(tb);
        }
        if(_mtries>60) clearInterval(_mtimer);
      }catch(e){}
    }, 1000);
  }catch(e){}
})();
/* MAP TOGGLE BUTTON — King chooses when map opens */
(function(){
  try{
    var btn = document.createElement('button');
    btn.id = 'map-toggle-btn';
    btn.innerHTML = '\uD83D\uDDFA\uFE0F';
    btn.title = 'Open/close map';
    btn.style.cssText = 'width:46px;height:46px;background:#00aaaa;color:#fff;border:2px solid #fff;border-radius:50%;font-size:20px;line-height:1;padding:0;cursor:pointer;-webkit-tap-highlight-color:transparent;';
    var _mapTapT = 0;
    btn.onclick = function(){
      try{
        var now = Date.now();
        if(now - _mapTapT < 400){
          if(typeof window.cycleCamera==='function') window.cycleCamera();
        }else{
          if(typeof toggleMap==='function') toggleMap();
        }
        _mapTapT = now;
      }catch(e){}
    };
    // insert after clear-cache button or at menu
    var anchor = document.getElementById('clear-cache-btn');
    if(anchor && anchor.parentNode){ anchor.parentNode.insertBefore(btn, anchor.nextSibling); }
    else{ document.body.appendChild(btn); btn.style.position='fixed'; btn.style.bottom='170px'; btn.style.right='10px'; btn.style.zIndex='9999'; }
  }catch(e){}
})();
/* CLEAR CACHE BUTTON — wipe everything and reload fresh */
(function(){
  try{
    var btn = document.createElement('button');
    btn.id = 'clear-cache-btn';
    btn.innerHTML = '🧹';
    btn.title = 'Clear cache & reload fresh';
    btn.style.cssText = 'width:46px;height:46px;background:#ff4444;color:#fff;border:2px solid #fff;border-radius:50%;font-size:20px;line-heig