<!-- SAGA-STAGING · part 41 -->
le.error(e); } }

/* TRANSITION BANDS — blend zones between districts, not hard borders. 2026-10-04. */
function buildTransitions(){
  if(window.STAGING_CLEAN_MAP) return; // Clean map: old builder disabled
  try{
    /* Gradient strips where city meets forest, desert meets water, etc. */
    function blendZone(x1, z1, x2, z2, c1, c2){
      var dx = x2 - x1, dz = z2 - z1;
      var len = Math.sqrt(dx*dx + dz*dz);
      var segs = 10;
      for(var i = 0; i < segs; i++){
        var t = i / (segs - 1);
        var px = x1 + dx * t;
        var pz = z1 + dz * t;
        /* Lerp color */
        var r = ((c1 >> 16) & 255) * (1-t) + ((c2 >> 16) & 255) * t;
        var g = ((c1 >> 8) & 255) * (1-t) + ((c2 >> 8) & 255) * t;
        var b = (c1 & 255) * (1-t) + (c2 & 255) * t;
        var col = (Math.round(r) << 16) | (Math.round(g) << 8) | Math.round(b);
        var strip = new THREE.Mesh(new THREE.PlaneGeometry(40, len/segs + 2),
          new THREE.MeshStandardMaterial({color: col, roughness: 0.9, transparent: true, opacity: 0.7}));
        strip.rotation.x = -Math.PI/2;
        strip.position.set(px, 0.3, pz);
        strip.rotation.z = Math.atan2(dx, dz);
        scene.add(strip);
      }
    }
    /* City (gold) -> Forest (green) */
    blendZone(100, -50, -50, 50, 0xd4a017, 0x1a5a1a);
    /* Desert (sand) -> Ocean (blue) */
    blendZone(800, 1400, 1200, 800, 0xd4b896, 0x0088cc);
    /* Village (warm) -> Peaks (white) */
    blendZone(-80, 250, -500, -500, 0xd4c4a0, 0xffffff);
  }catch(e){ console.error(e); }
}
if(typeof buildTransitions === 'function'){ try{ buildTransitions(); }catch(e){ console.error(e); } }

/* FREIGHT PORTALS — underground cargo network entrances. 2026-10-04. */
function buildFreight(){
  if(window.STAGING_CLEAN_MAP) return; // Clean map: old builder disabled
  try{
    var darkMat = new THREE.MeshStandardMaterial({color: 0x1a1a1a, roughness: 0.9});
    function portal(x, z){
      /* Ramp going down */
      var ramp = new THREE.Mesh(new THREE.BoxGeometry(12, 2, 30), darkMat);
      ramp.position.set(x, -2, z);
      ramp.rotation.x = 0.2;
      scene.add(ramp);
      /* Portal frame */
      var frame = new THREE.Mesh(new THREE.BoxGeometry(14, 10, 2), darkMat);
      frame.position.set(x, 3, z - 14);
      scene.add(frame);
      /* Opening */
      var opening = new THREE.Mesh(new THREE.PlaneGeometry(10, 7),
        new THREE.MeshBasicMaterial({color: 0x000000}));
      opening.position.set(x, 3, z - 12.9);
      scene.add(opening);
      /* Warning lights */
      for(var l = -1; l <= 1; l++){
        var light = new THREE.Mesh(new THREE.SphereGeometry(0.5, 8, 6),
          new THREE.MeshBasicMaterial({color: 0xff0000}));
        light.position.set(x + l*6, 8.5, z - 12.8);
        scene.add(light);
      }
    }
    portal(150, -100);
    portal(-130, 180);
    portal(2050, 2000);
  }catch(e){ console.error(e); }
}
if(typeof buildFreight === 'function'){ try{ buildFreight(); }catch(e){ console.error(e); } }

/* DISTRICT CENTERS — plazas at the heart. 2026-10-04. */
function buildPlazas(){
  if(window.STAGING_CLEAN_MAP) return; // Clean map: old builder disabled
  try{
    var stoneMat = new THREE.MeshStandardMaterial({color: 0x999988, roughness: 0.8});
    var goldMat = new THREE.MeshStandardMaterial({color: 0xd4a017, metalness: 0.6, roughness: 0.4});
    function plaza(x, z, r){
      /* Circular plaza */
      var pz = new THREE.Mesh(new THREE.CircleGeometry(r, 24), stoneMat);
      pz.rotation.x = -Math.PI/2;
      pz.position.set(x, 0.25, z);
      scene.add(pz);
      /* Central fountain */
      var base = new THREE.Mesh(new THREE.CylinderGeometry(4, 5, 2, 12), stoneMat);
      base.position.set(x, 1, z);
      scene.add(base);
      var water = new THREE.Mesh(new THREE.CylinderGeometry(3.5, 3.5, 0.5, 12),
        new THREE.MeshStandardMaterial({color: 0x0088cc, transparent: true, opacity: 0.7}));
      water.position.set(x, 2.2, z);
      scene.add(water);
      /* Obelisk */
      var ob = new THREE.Mesh(new THREE.BoxGeometry(2, 15, 2), goldMat);
      ob.position.set(x, 9, z);
      scene.add(ob);
      var tip = new THREE.Mesh(new THREE.ConeGeometry(1.5, 3, 4), goldMat);
      tip.position.set(x, 18, z);
      scene.add(tip);
    }
    plaza(100, -100, 30);   /* City */
    plaza(-80, 180, 25);    /* Village */
    plaza(2000, 2000, 35);  /* Ahupua'a 1 */
    plaza(0, 1500, 28);     /* Observatory */
  }catch(e){ console.error(e); }
}
if(typeof buildPlazas === 'function'){ try{ buildPlazas(); }catch(e){ console.error(e); } }

/* LAVA TUBES — underground in shield volcanoes (Hawaii). 2026-10-04. */
function buildLavaTubes(){
  if(window.STAGING_CLEAN_MAP) return; // Clean map: old builder disabled
  try{
    var tubeMat = new THREE.MeshStandardMaterial({color: 0x1a1a1a, roughness: 1, side: THREE.BackSide});
    var glowMat = new THREE.MeshBasicMaterial({color: 0xff4400});
    function lavaTube(x, z, len, angle){
      /* Tube entrance — 