<!-- LIVE · part 39 -->
-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){ console.error(e); }
}
if(typeof buildUValleys === 'function'){ try{ buildUValleys(); }catch(e){ console.error(e); } }

/* 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) % clothColors.length]);
    }

  }catch(e){ console.error(e); }
}
if(typeof buildPeople === 'function'){ try{ buildPeople(); }catch(e){ console.error(e); } }















/* WORLD HEART — the crystal at the center of everything. 2026-10-04. */
function buildWorldHeart(){
  try{
    window._dynamics = window._dynamics || [];
    /* Massive crystal */
    var heart = new THREE.Mesh(new THREE.OctahedronGeometry(15, 0),
      new THREE.MeshStandardMaterial({
        color: 0xffd700, emissive: 0xaa7700, emissiveIntensity: 1,
        transparent: true, opacity: 0.9, roughness: 0.1, metalness: 0.3
      }));
    heart.position.set(0, 40, 0);
    scene.add(heart);
    /* Inner glow */
    var glow = new THREE.Mesh(new THREE.OctahedronGeometry(10, 0),
      new THREE.MeshBasicMaterial({color: 0xfff8dc, transparent: true, opacity: 0.6}));
    glow.position.set(0, 40, 0);
    scene.add(glow);
    /* Floating rings */
    for(var r = 0; r < 3; r++){
      (function(){
        var ring = new THREE.Mesh(new THREE.TorusGeometry(25 + r*1