<!-- RUBY-BACKUP · part 295 -->
if(typeof buildStreets==='function'){
      buildStreets();
      setTimeout(function(){
        try{
          if(typeof window._streets==='undefined' || !window._streets){
            buildStreets();
          } else {
            var _in = false;
            if(typeof scene!=='undefined'){
              scene.traverse(function(o){ if(o===window._streets) _in = true; });
              if(!_in) scene.add(window._streets);
            }
          }
        }catch(e){}
      }, 4000);
    }
  }catch(e){}
}
if(typeof window!=='undefined'){
  window.addEventListener('load', function(){ setTimeout(ensurePermanentStreets, 1500); });
  setTimeout(function(){ try{ ensurePermanentStreets(); }catch(e){} }, 2000);
}
function buildStreets(){
  try{
    // NEVER replace on startup/restart — only build if missing (King's law)
    if(window._streets){
      // already there — make sure it's in the scene, don't rebuild
      var _in = false;
      if(typeof scene!=='undefined'){
        scene.traverse(function(o){ if(o===window._streets) _in = true; });
        if(!_in) scene.add(window._streets);
      }
      return;
    }
    var g = new THREE.Group();
    var roadMat = new THREE.MeshStandardMaterial({color:0x1a1a1a, roughness:0.85, metalness:0.1});
    var lineMat = new THREE.MeshStandardMaterial({color:0xffd700, emissive:0xffd700, emissiveIntensity:0.8});
    var edgeMat = new THREE.MeshStandardMaterial({color:0xffffff, emissive:0xffffff, emissiveIntensity:0.3});
    var dashMat = new THREE.MeshBasicMaterial({color:0xf5f5f5});
    var plazaMat = new THREE.MeshStandardMaterial({color:0x3a3a3a, roughness:0.8});
    // helper: curved road from points
    function curvedRoad(points, width){
      var curve = new THREE.CatmullRomCurve3(points.map(function(p, idx){
        // realistic elevation: base 10 + rolling hills
        // NOTE: geo.scale(1,0.1,1) below divides Y by 10, so build 10x high
        var _d = Math.sqrt(p[0]*p[0]+p[1]*p[1]);
        var _h = (10 + Math.sin(_d*0.02)*4 + Math.sin(_d*0.05+1.3)*2) * 10;
        return new THREE.Vector3(p[0], _h, p[1]);
      })); /* highways rise and fall — not flat */
      var geo = new THREE.TubeGeometry(curve, 64, width/2, 8, false);
      // flatten the tube to make it a road
      geo.scale(1, 0.1, 1);
      var road = new THREE.Mesh(geo, roadMat);
      road.name = 'street-curve';
      g.add(road);
      // gold center line
      var lineGeo = new THREE.TubeGeometry(curve, 64, 0.1, 6, false);
      lineGeo.scale(1, 0.15, 1);
      var line = new THREE.Mesh(lineGeo, lineMat);
      line.position.y = 10.2; /* above the road */
      line.name = 'street-line';
      g.add(line);
      /* ROAD DESIGN — white edge lines that follow the curve properly */
      try{
        [-1, 1].forEach(function(s){
          /* build offset curve by sampling normals along the path */
          var edgePts = [];
          var segs = 64;
          for(var ei=0; ei<=segs; ei++){
            var t = ei/segs;
            var pt = curve.getPoint(t);
            var tan = curve.getTangent(t);
            var nx = -tan.z, nz = tan.x;
            var nlen = Math.sqrt(nx*nx + nz*nz) || 1;
            var off = s * (width/2 - 0.8);
            /* match the road's height */
            var _h = pt.y;
            edgePts.push(new THREE.Vector3(pt.x + nx/nlen*off, _h + 0.3, pt.z + nz/nlen*off));
          }
          var edgeCurve = new THREE.CatmullRomCurve3(edgePts);
          var edgeGeo = new THREE.TubeGeometry(edgeCurve, 64, 0.18, 6, false);
          var edgeLine = new THREE.Mesh(edgeGeo, new THREE.MeshBasicMaterial({color:0xffffff}));
          edgeLine.name = 'road-edge-design';
          g.add(edgeLine);
        });
      }catch(e){}
    }
    // central plaza — roundabout
    var plaza = new THREE.Mesh(new THREE.CylinderGeometry(4, 4, 0.15, 24), plazaMat); /* small — not blocking */
    plaza.position.set(0, 10, 0); /* 5 blocks high */
    plaza.name = 'plaza';
    g.add(plaza);
    var plazaRing = new THREE.Mesh(new THREE.TorusGeometry(3.5, 0.2, 8, 32), lineMat);
    plazaRing.position.set(0, 10.15, 0); /* above the plaza */
    plazaRing.rotation.x = Math.PI/2;
    plazaRing.name = 'plaza-ring';
    g.add(plazaRing);
    // winding roads radiating from plaza — STRETCHED BIG
    curvedRoad([[12,0], [50,15], [100,10], [200,30], [400,20], [600,40], [800,60], [1000,50], [1200,70]], 16);
    curvedRoad([[12,0], [40,-25], [90,-40], [180,-35], [350,-50], [550,-40], [750,-60], [950,-50], [1150,-70]], 16);
    curvedRoad([[0,12], [-15,50], [-10,100], [-30,200], [-20,400], [-40,600], [-60,800], [-50,1000], [-70,1200]], 16);
    curvedRoad([[0,12], [20,55], [15,110], [35,220], [30,420], [50,600], [60,800], [70,1000], [80,1180]], 14);
    curvedRoad([[-12,0], [-50,-15], [-100,-10], [-200,-30], [-400,-20], [-600,-40], [-800,-60], [-1000,-50], [-1200,-70]], 16);
    curvedRoad([[0,-12], [15,-50], [10,-100], [30,-200], [20,-400], [40,-600], [50,-800], [60,-1000], [70,-1