<!-- SAGA · part 41 -->
ng: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide
    });
    /* Sun shafts — angled from sun position */
    for(var i = 0; i < 12; i++){
      (function(){
        var rx = (Math.random() - 0.5) * 600;
        var rz = (Math.random() - 0.5) * 600;
        var ray = new THREE.Mesh(new THREE.PlaneGeometry(20, 300), rayMat);
        ray.position.set(rx, 150, rz);
        ray.rotation.z = 0.4; /* Angled like sunlight */
        ray.rotation.y = Math.random() * Math.PI;
        scene.add(ray);
        var ph = Math.random() * 10;
        window._dynamics.push(function(t){
          /* Billboard: face camera around Y */
          var dx = camera.position.x - ray.position.x;
          var dz = camera.position.z - ray.position.z;
          ray.rotation.y = Math.atan2(dx, dz);
          ray.material.opacity = 0.06 + Math.sin(t * 0.5 + ph) * 0.03;
        });
      })();
    }
  }catch(e){}
}
if(typeof buildGodRays === 'function'){ window._buildQueue.push(buildGodRays); }

/* U-SHAPED VALLEYS — glacial troughs with ribbon lakes. 2026-10-04. */
function buildUValleys(){
  try{
    var rockMat = new THREE.MeshStandardMaterial({color: 0x4a4a4a, roughness: 0.95});
    var waterMat = new THREE.MeshStandardMaterial({color: 0x0088cc, transparent: true, opacity: 0.7});

    function uValley(x1, z1, x2, z2, width, depth){
      var dx = x2 - x1, dz = z2 - z1;
      var len = Math.sqrt(dx*dx + dz*dz);
      var angle = Math.atan2(dx, dz);
      /* Valley floor — flat */
      var floor = new THREE.Mesh(new THREE.PlaneGeometry(width*0.4, len), waterMat);
      floor.rotation.x = -Math.PI/2;
      floor.position.set((x1+x2)/2, 0.3, (z1+z2)/2);
      floor.rotation.z = angle;
      scene.add(floor);
      /* Steep walls — both sides */
      for(var s = -1; s <= 1; s += 2){
        var wallLen = 8;
        for(var i = 0; i < wallLen; i++){
          var t = i / (wallLen - 1);
          var wx = x1 + dx*t + s * width/2 * (1 - t*0.2);
          var wz = z1 + dz*t + s * width/3 * (1 - t*0.2);
          var wh = depth * (1 - Math.abs(t - 0.5) * 0.5);
          var wall = new THREE.Mesh(new THREE.BoxGeometry(width/4, wh, len/wallLen + 5), rockMat);
          wall.position.set(wx, wh/2, wz);
          wall.rotation.y = angle;
          scene.add(wall);
        }
      }
      /* Ribbon lake on floor */
      var lake = new THREE.Mesh(new THREE.PlaneGeometry(width*0.3, len*0.6), waterMat);
      lake.rotation.x = -Math.PI/2;
      lake.position.set((x1+x2)/2, 0.35, (z1+z2)/2);
      lake.rotation.z = angle;
      scene.add(lake);
    }

    uValley(-3500, -3500, -2500, -2500, 200, 80);
    uValley(3000, 3000, 4000, 2500, 180, 70);

  }catch(e){}
}
if(typeof buildUValleys === 'function'){ window._buildQueue.push(buildUValleys); }

/* PEOPLE — simple figures walking the streets. For the children. 2026-10-04. */
function buildPeople(){
  try{
    window._dynamics = window._dynamics || [];
    var skinMat = new THREE.MeshStandardMaterial({color: 0xd4a080, roughness: 0.8});
    var clothColors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff];

    function person(x, z, color){
      var p = new THREE.Group();
      /* Body */
      var body = new THREE.Mesh(new THREE.CylinderGeometry(0.5, 0.7, 2, 8),
        new THREE.MeshStandardMaterial({color: color, roughness: 0.8}));
      body.position.y = 1.5;
      p.add(body);
      /* Head */
      var head = new THREE.Mesh(new THREE.SphereGeometry(0.5, 12, 8), skinMat);
      head.position.y = 3;
      p.add(head);
      /* Legs */
      var legL = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.2, 1.5, 6), skinMat);
      legL.position.set(-0.3, 0.75, 0);
      p.add(legL);
      var legR = new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0.2, 1.5, 6), skinMat);
      legR.position.set(0.3, 0.75, 0);
      p.add(legR);
      p.position.set(x, 0.13, z);
      scene.add(p);
      /* Walk animation */
      var walkPh = Math.random() * 10;
      var dir = Math.random() * Math.PI * 2;
      var speed = 0.5 + Math.random() * 0.5;
      var cx = x, cz = z;
      var range = 30;
      window._dynamics.push(function(t){
        walkPh += 0.1 * speed;
        /* Move in circle */
        var nt = t * 0.1 * speed + dir;
        p.position.x = cx + Math.cos(nt) * range;
        p.position.z = cz + Math.sin(nt) * range;
        p.rotation.y = -nt + Math.PI/2;
        /* Leg swing */
        legL.rotation.x = Math.sin(walkPh) * 0.5;
        legR.rotation.x = -Math.sin(walkPh) * 0.5;
        /* Bob */
        p.position.y = 0.13 + Math.abs(Math.sin(walkPh)) * 0.1;
      });
      return p;
    }

    /* People in the city */
    for(var i = 0; i < 15; i++){
      person(100 + (Math.random()-0.5)*80, -100 + (Math.random()-0.5)*80,
        clothColors[i % clothColors.length]);
    }
    /* People in the village */
    for(var j = 0; j < 10; j++){
      person(-80 + (Math.random()-0.5)*50, 180 + (Math.random()-0.5)*50,
        clothColors[(j+3) % cloth