<!-- RUBY-BACKUP · part 433 -->
on') placeRegalia();
    else if(sec.fn==='goldenCity' && typeof goldenCity==='function') goldenCity();
    else if(sec.fn==='placeGraffiti' && typeof placeGraffiti==='function') placeGraffiti();
    else if(sec.fn==='heavyBuild' && typeof heavyBuild==='function') heavyBuild();
  }catch(e){}
  SWEEP_IDX++;
  /* move to next */
  setTimeout(function(){ sweepNext(); }, 4000);
}
function freeMap(){
  codeStatus('freeing the map...');
  /* clear a wide district for gold: x from -50 to 50, z from -50 to 50 */
  /* remove non-permanent clutter in the district */
  if(typeof scene!=='undefined'){
    var toRemove = [];
    scene.traverse(function(obj){
      if(obj.userData && !obj.userData.permanent && !obj.userData.isPhoneCaller
         && !obj.userData.isForbidden && !obj.userData.isCapsule
         && obj.position && Math.abs(obj.position.x)<50 && Math.abs(obj.position.z)<50
         && obj.geometry && obj.geometry.type==='BoxGeometry'){
        toRemove.push(obj);
      }
    });
    toRemove.forEach(function(obj){
      if(obj.parent) obj.parent.remove(obj);
    });
    codeStatus('freed '+toRemove.length+' clutter stones — the district breathes');
  }
  /* expand: golden plaza at center */
  goldenPlaza();
}
function goldenPlaza(){
  if(typeof scene==='undefined') return;
  /* a golden plaza floor — 40x40 */
  var plaza = new THREE.Mesh(new THREE.PlaneGeometry(40, 40),
    new THREE.MeshStandardMaterial({color: 0x8a6d2f, metalness: 0.7, roughness: 0.3}));
  plaza.rotation.x = -Math.PI/2;
  plaza.position.y = 0.01;
  scene.add(plaza);
  /* gold trim border */
  var border = new THREE.Mesh(new THREE.RingGeometry(19, 20, 64),
    new THREE.MeshStandardMaterial({color: 0xd4af37, metalness: 0.95, roughness: 0.1, emissive: 0x664400, emissiveIntensity: 0.5}));
  border.rotation.x = -Math.PI/2;
  border.position.y = 0.02;
  scene.add(border);
  /* center fountain — galaxy water */
  var fountainBase = new THREE.Mesh(new THREE.CylinderGeometry(2, 2.5, 1, 16),
    new THREE.MeshStandardMaterial({color: 0xd4af37, metalness: 0.9, roughness: 0.2}));
  fountainBase.position.y = 0.5;
  scene.add(fountainBase);
  var water = new THREE.Mesh(new THREE.CylinderGeometry(1.8, 1.8, 0.2, 16),
    new THREE.MeshStandardMaterial({color: 0x1a0f4a, emissive: 0x4422aa, emissiveIntensity: 0.8, transparent: true, opacity: 0.8}));
  water.position.y = 1.05;
  scene.add(water);
  /* galaxy sparkles above fountain */
  setInterval(function(){
    water.material.emissiveIntensity = 0.6 + Math.random()*0.5;
  }, 1000);
  codeStatus('the golden plaza stands — 40x40, fountain of galaxy water');
}
function goldenCity(){
  GOLD_MODE = true;
  try{ localStorage.setItem('ruby-gold-mode', '1'); }catch(e){}
  codeStatus('the city dresses in gold...');
  /* sky signs */
  try{ skySign('GALAXY WEALTH', -20, 25, 0xffd700); }catch(e){}
  try{ skySign('ETERNAL FORTUNE', 20, 25, 0xff66ff); }catch(e){}
  /* cosmic dusk */
  if(typeof scene!=='undefined'){
    try{
      scene.background = new THREE.Color(0x1a0f2e);
      scene.fog = new THREE.Fog(0x1a0f2e, 30, 120);
    }catch(e){}
  }
  /* gold light */
  if(typeof scene!=='undefined'){
    try{
      var goldLight = new THREE.DirectionalLight(0xffd700, 0.6);
      goldLight.position.set(30, 40, -30);
      scene.add(goldLight);
    }catch(e){}
  }
  /* recolor EXISTING towers to gold */
  if(typeof scene!=='undefined'){
    try{
      var goldMat = new THREE.MeshStandardMaterial({color: 0xd4af37, metalness: 0.95, roughness: 0.15});
      var jewelColors = [0xffd700, 0xff66ff, 0x66ffff, 0xffffff, 0xff3355];
      var count = 0;
      scene.traverse(function(obj){
        if(obj.userData && obj.userData.permanent && obj.geometry && obj.geometry.type==='BoxGeometry'){
          obj.material = goldMat;
          count++;
        }
        /* jeweled windows */
        if(obj.geometry && obj.geometry.type==='PlaneGeometry' && obj.material && obj.material.emissive){
          var jc = jewelColors[Math.floor(Math.random()*jewelColors.length)];
          obj.material.color.set(jc);
          obj.material.emissive.set(jc);
          obj.material.emissiveIntensity = 1.5;
        }
      });
      codeStatus('dressed '+count+' towers in gold');
    }catch(e){}
  }
  /* heavy build */
  setTimeout(function(){ heavyBuild(); }, 2000);
  setTimeout(function(){ placeRegalia(); }, 4000);
  setTimeout(function(){ placeGraffiti(); }, 6000);
  setTimeout(function(){ placeGuardian(); }, 8000);
}
function skySign(text, x, y, color){
  if(typeof scene==='undefined') return;
  var cv = document.createElement('canvas');
  cv.width = 1024; cv.height = 128;
  var ctx = cv.getContext('2d');
  ctx.fillStyle = 'rgba(0,0,0,0)';
  ctx.fillRect(0, 0, 1024, 128);
  ctx.font = 'bold 72px Arial';
  ctx.textAlign = 'center';
  ctx.shadowColor = '#'+color.toString(16).padStart(6,'0');
  ctx.shadowBlur = 30;
  ctx.fillStyle = '#'+color.toString(16).padStart(6,'0');
  ctx.fillText(text, 512, 90);
  var tex = 