<!-- SAGA3 · part 44 -->
st);
    }

    station(100, -80);    /* City Central */
    station(-80, 160);    /* Village */
    station(2000, 1980);  /* Ahupua'a */
    station(3000, 480);   /* Shoreline */

  }catch(e){}
}
if(typeof buildStations === 'function'){ try{ buildStations(); }catch(e){} }

/* SCHOOLS — places of learning, for the children. 2026-10-04. */
function buildSchools(){
  try{
    var wallMat = new THREE.MeshStandardMaterial({color: 0xf0e0c0, roughness: 0.9});
    var roofMat = new THREE.MeshStandardMaterial({color: 0x2a5aaa, roughness: 0.8});

    function school(x, z){
      var sc = new THREE.Group();
      /* Main building */
      var main = new THREE.Mesh(new THREE.BoxGeometry(20, 8, 12), wallMat);
      main.position.y = 4;
      sc.add(main);
      /* Roof */
      var roof = new THREE.Mesh(new THREE.BoxGeometry(22, 1, 14), roofMat);
      roof.position.y = 8.5;
      sc.add(roof);
      /* Door */
      var door = new THREE.Mesh(new THREE.PlaneGeometry(3, 5),
        new THREE.MeshBasicMaterial({color: 0x8a5a2a}));
      door.position.set(0, 2.5, 6.01);
      sc.add(door);
      /* Windows — bright, welcoming */
      for(var w = -2; w <= 2; w++){
        if(w === 0) continue;
        var win = new THREE.Mesh(new THREE.PlaneGeometry(2, 2),
          new THREE.MeshBasicMaterial({color: 0xaaddff}));
        win.position.set(w*4, 5, 6.01);
        sc.add(win);
      }
      /* Playground */
      var yard = new THREE.Mesh(new THREE.CircleGeometry(15, 20),
        new THREE.MeshStandardMaterial({color: 0x4aaa4a, roughness: 1}));
      yard.rotation.x = -Math.PI/2;
      yard.position.set(18, 0.1, 0);
      sc.add(yard);
      /* Swing set */
      var frame = new THREE.Mesh(new THREE.BoxGeometry(6, 0.3, 0.3), wallMat);
      frame.position.set(18, 4, 0);
      sc.add(frame);
      for(var s = -1; s <= 1; s += 2){
        var leg = new THREE.Mesh(new THREE.CylinderGeometry(0.15, 0.15, 4, 6), wallMat);
        leg.position.set(18 + s*3, 2, 0);
        sc.add(leg);
        var swing = new THREE.Mesh(new THREE.BoxGeometry(1, 0.2, 1), roofMat);
        swing.position.set(18 + s*3, 2, 0);
        sc.add(swing);
      }
      sc.position.set(x, 0.13, z);
      scene.add(sc);
    }

    school(-80, 220);   /* Village school */
    school(140, -100);  /* City school */

  }catch(e){}
}
if(typeof buildSchools === 'function'){ try{ buildSchools(); }catch(e){} }

/* MARKETS — gathering places with stalls. 2026-10-04. */
function buildMarkets(){
  try{
    var woodMat = new THREE.MeshStandardMaterial({color: 0x8a6a3a, roughness: 0.8});
    var canvasColors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff8800];

    function stall(x, z, colorIdx, rot){
      var st = new THREE.Group();
      /* Table */
      var table = new THREE.Mesh(new THREE.BoxGeometry(4, 1, 3), woodMat);
      table.position.y = 1;
      st.add(table);
      /* Posts */
      for(var p = 0; p < 4; p++){
        var post = new THREE.Mesh(new THREE.CylinderGeometry(0.15, 0.15, 4, 6), woodMat);
        post.position.set(p < 2 ? -1.8 : 1.8, 2, p % 2 === 0 ? -1.3 : 1.3);
        st.add(post);
      }
      /* Canopy */
      var canopy = new THREE.Mesh(new THREE.BoxGeometry(4.5, 0.3, 3.5),
        new THREE.MeshStandardMaterial({color: canvasColors[colorIdx % canvasColors.length], roughness: 0.9}));
      canopy.position.y = 4;
      st.add(canopy);
      /* Goods */
      for(var g = 0; g < 5; g++){
        var good = new THREE.Mesh(new THREE.SphereGeometry(0.3, 8, 6),
          new THREE.MeshStandardMaterial({color: canvasColors[(colorIdx+g) % canvasColors.length]}));
        good.position.set((Math.random()-0.5)*3, 1.7, (Math.random()-0.5)*2);
        st.add(good);
      }
      st.position.set(x, 0.13, z);
      st.rotation.y = rot || 0;
      scene.add(st);
    }

    /* City market — 8 stalls in a row */
    for(var i = 0; i < 8; i++){
      stall(80 + i*8, -120, i, 0);
    }
    /* Village market — 6 stalls in circle */
    for(var j = 0; j < 6; j++){
      var ja = (j / 6) * Math.PI * 2;
      stall(-80 + Math.cos(ja)*25, 180 + Math.sin(ja)*25, j+2, ja);
    }

  }catch(e){}
}
if(typeof buildMarkets === 'function'){ try{ buildMarkets(); }catch(e){} }

/* RESIDENTIAL ZONES — where the people live. 2026-10-04. */
function buildHomes(){
  try{
    window._dynamics = window._dynamics || [];
    var wallMat = new THREE.MeshStandardMaterial({color: 0xd4c4a0, roughness: 0.9});
    var roofMat = new THREE.MeshStandardMaterial({color: 0x8a3a1a, roughness: 0.8});

    function house(x, z, rot){
      var h = new THREE.Group();
      /* Walls */
      var walls = new THREE.Mesh(new THREE.BoxGeometry(8, 5, 6), wallMat);
      walls.position.y = 2.5;
      h.add(walls);
      /* Roof */
      var roof = new THREE.Mesh(new THREE.ConeGeometry(6, 3, 4), roofMat);
      roof.position.y = 6.5;
      roof.rotation.y = Math.PI/4;
      h.add(roof);
      /* Door glow */
      var door = new THREE.Mesh(new THREE.PlaneGeometry(1.5, 3),
      