<!-- SAGA-SOLID · part 38 -->
dx + dz*dz);
      /* Flat top */
      var plat = new THREE.Mesh(new THREE.BoxGeometry(width, 20, len), grassMat);
      plat.position.set((x1+x2)/2, height, (z1+z2)/2);
      plat.rotation.y = Math.atan2(dx, dz);
      scene.add(plat);
      /* Cliffs at edges */
      var edge1 = new THREE.Mesh(new THREE.BoxGeometry(8, height, len), rockMat);
      edge1.position.set((x1+x2)/2 - width/2, height/2, (z1+z2)/2);
      edge1.rotation.y = Math.atan2(dx, dz);
      scene.add(edge1);
      var edge2 = new THREE.Mesh(new THREE.BoxGeometry(8, height, len), rockMat);
      edge2.position.set((x1+x2)/2 + width/2, height/2, (z1+z2)/2);
      edge2.rotation.y = Math.atan2(dx, dz);
      scene.add(edge2);
      /* Peaks on rim */
      for(var p = 0; p < 4; p++){
        var t = p / 3;
        var px = x1 + dx*t + (Math.random()-0.5)*width*0.8;
        var pz = z1 + dz*t + (Math.random()-0.5)*width*0.8;
        var peak = new THREE.Mesh(new THREE.ConeGeometry(40, 100, 7), rockMat);
        peak.position.set(px, height + 50, pz);
        scene.add(peak);
      }
    }

    /* Build */
    /* Arête ridges — expanding/contracting */
    areteRidge(-3500, -3000, -1500, -2500, 4);
    areteRidge(2500, 3500, 4000, 3000, 3);

    /* Cirques — concave bowls */
    cirque(-2800, -2800, 80);
    cirque(3200, 3300, 100);

    /* Plateau bridges — connecting mountain groups */
    plateauBridge(-3000, -2000, -2000, -2000, 300, 80);  /* Between peaks 1-3 */
    plateauBridge(2000, 2000, 2000, 1500, 250, 70);      /* Ahupua'a plateau */

  }catch(e){ console.error(e); }
}
/* DISABLED 2026-10-07 — mountain clear, King's word */
/* if(typeof buildRidgesPlateaus === 'function'){ try{ buildRidgesPlateaus(); }catch(e){ console.error(e); } } */

/* CINEMATIC — art direction. Unified light, fog, tone mapping. 2026-10-04.
   From research: one sun rig, ACES, fog=sky, three-point light. */
function applyCinematic(){
  try{
    /* ACES tone mapping — cinematic color */
    renderer.toneMapping = THREE.ACESFilmicToneMapping;
    renderer.toneMappingExposure = 1.1;

    /* Fog — matched to sky horizon (gold) for seamless depth */
    scene.fog = null; /* HAZE REMOVED per King 2026-10-06 */

    /* THREE-POINT LIGHTING */
    /* Remove old lights */
    /* Warm key — golden hour sun */
    var key = new THREE.DirectionalLight(0xffd4a0, 2.2);
    key.position.set(400, 300, -600);
    key.castShadow = true;
    scene.add(key);
    /* Cool fill — 30% of key */
    var fill = new THREE.DirectionalLight(0x88aaff, 0.7);
    fill.position.set(-300, 200, 400);
    scene.add(fill);
    /* Rim light — behind, purple, separates from background */
    var rim = new THREE.DirectionalLight(0x8844ff, 0.5);
    rim.position.set(0, 400, 800);
    scene.add(rim);
    /* Low ambient — preserve drama */
    /* (Keep existing ambient but it should be low) */

    /* Hemisphere — sky/ground bounce */
    var hemi = new THREE.HemisphereLight(0x8a9acc, 0x2a1a0a, 0.4);
    scene.add(hemi);

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


/* GOD RAYS — volumetric light shafts. 2026-10-04. */
function buildGodRays(){
  try{
    window._dynamics = window._dynamics || [];
    var rayMat = new THREE.MeshBasicMaterial({
      color: 0xffd4a0, transparent: true, opacity: 0.08,
      blending: 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){ console.error(e); }
}
if(typeof buildGodRays === 'function'){ try{ buildGodRays(); }catch(e){ console.error(e); } }

/* 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