<!-- LIVE · part 86 -->
ht/2) / height; /* 0=base, 1=top */
      /* Flutes: high-frequency vertical channels (water erosion) */
      var fluteFreq = 8 + (seed % 5);
      var flute = Math.sin(x * 0.05 * fluteFreq + seed) * 0.5 + 0.5;
      flute = Math.pow(flute, 1.5); /* Sharpen valleys */
      /* Depth of flutes increases with height */
      var depth = flute * width * 0.4 * hNorm;
      /* Ridge profile: narrow at top, wider at base */
      var profile = (1 - hNorm * 0.7);
      var z = depth * profile;
      /* Add secondary roughness */
      z += Math.sin(x * 0.3 + y * 0.2 + seed * 2) * width * 0.05 * hNorm;
      /* Peak jaggedness — top edge varies */
      if(hNorm > 0.9){
        z += Math.sin(x * 0.2 + seed * 3) * width * 0.15;
      }
      pos.setZ(i, z);
      /* Vary height for jagged skyline */
      if(hNorm > 0.95){
        pos.setY(i, y + Math.sin(x * 0.15 + seed) * height * 0.08);
      }
    }
    geo.computeVertexNormals();
    /* Make double-sided */
    var mat = new THREE.MeshStandardMaterial({
      color: 0x4a5d3a, roughness: 0.9, side: THREE.DoubleSide,
      flatShading: true
    });
    var mesh = new THREE.Mesh(geo, mat);
    /* Bend into a slight arc */
    return mesh;
  }
  /* Replace mountain cones with Nā Pali ridges */
  var toRemove = [];
  var seed = 1;
  scene.traverse(function(obj){
    if(obj.isMesh && obj.geometry && obj.geometry.type === 'ConeGeometry'){
      obj.geometry.computeBoundingBox();
      var h = obj.geometry.boundingBox.max.y - obj.geometry.boundingBox.min.y;
      if(h > 20){
        toRemove.push(obj);
        var distFromCenter = Math.sqrt(obj.position.x*obj.position.x + obj.position.z*obj.position.z);
        if(true){ /* Always build — no more missing mountains */
          /* Build Nā Pali ridge at this location */
          var ridge = napaliRidge(h * 4, h * 1.2, h * 0.8, seed * 7.3);
          ridge.position.set(obj.position.x, h * 0.4, obj.position.z);
          ridge.rotation.y = (seed * 1.7) % (Math.PI * 2);
          /* Two-sided ridge — add back for depth */
          var ridge2 = ridge.clone();
          ridge2.rotation.y += Math.PI / 3;
          ridge2.position.x += 20; ridge2.position.z += 15;
          scene.add(ridge);
          scene.add(ridge2);
        }
        seed++;
      }
    }
  });
  /* Remove old cones */
  toRemove.forEach(function(obj){ scene.remove(obj); });
  if(typeof say === 'function') say('Nā Pali ridges raised');
}, 5000);



/* ===== CLIFF BOUNDARIES — around all builds. King's order 2026-10-06 ===== */
setTimeout(function buildCliffBoundaries(){
  function cliffSegment(w, h, d){
    /* Steep cliff — narrow, tall, rugged */
    var geo = new THREE.BoxGeometry(w, h, d, 4, 8, 4);
    var pos = geo.attributes.position;
    for(var i = 0; i < pos.count; i++){
      var vx = pos.getX(i), vy = pos.getY(i), vz = pos.getZ(i);
      var n = Math.sin(vx * 0.3) * Math.cos(vz * 0.25) + Math.sin(vy * 0.2) * 0.5;
      pos.setX(i, vx + n * 2);
      pos.setZ(i, vz + n * 2);
    }
    geo.computeVertexNormals();
    var mat = new THREE.MeshStandardMaterial({color: 0x5a4a3a, roughness: 0.95, flatShading: true});
    return new THREE.Mesh(geo, mat);
  }
  function cliffBoundary(cx, cz, radius, segments){
    for(var i = 0; i < segments; i++){
      var ang = (i / segments) * Math.PI * 2;
      var px = cx + Math.cos(ang) * radius;
      var pz = cz + Math.sin(ang) * radius;
      var h = 40 + Math.random() * 30;
      var cliff = cliffSegment(15, h, 15);
      cliff.position.set(px, h/2, pz);
      cliff.rotation.y = ang + Math.PI/2;
      scene.add(cliff);
    }
  }
  /* Build boundaries around known build areas */
  cliffBoundary(100, -100, 120, 16);   /* City */
  cliffBoundary(0, 0, 150, 18);        /* Origin/Central */
  cliffBoundary(500, 500, 100, 14);    /* Spawn */
  cliffBoundary(2000, 1920, 200, 20);  /* Volcano area */
  cliffBoundary(-2000, 1920, 200, 20); /* Volcano area 2 */
  if(typeof say === 'function') say('Cliff boundaries raised');
}, 7000);

/* ===== MOUNTAIN BUILDER — lattice + fractal domes, unified. King's method 2026-10-06 ===== */
setTimeout(function buildMountains(){
  return; /* DISABLED 2026-10-06 — duplicate mountain code */
  var rockMat = new THREE.MeshStandardMaterial({color: 0x3a7a3a, roughness: 0.9}); /* GREEN */
  var seed = 12345;
  function rand(){ seed = (seed * 16807) % 2147483647; return (seed - 1) / 2147483646; }

  function makeDome(r, h, smooth){
    var g = new THREE.Group();
    /* Base — tapered cylinder */
    var baseH = h * 0.6;
    var base = new THREE.Mesh(new THREE.CylinderGeometry(r * 0.55, r, baseH, 20, 4), rockMat);
    base.position.y = baseH / 2;
    g.add(base);
    /* Dome top — sphere, smoother when smooth=1 */
    var domeR = r * 0.55;
    var dome = new THREE.Mesh(new THREE.SphereGeometry(domeR, 20, 14, 0, Math.PI*2, 0, Math.PI/2), rockMat);
    dome.position.y = baseH;
    if(smooth) dome.scale.y = 0.6; /* Flatter dome */
    g.add(dome);
    return g;
  }