<!-- SOLID CITY · part 3628 -->
nd a forest of
 * GIANT trees — the King's wish: towering 25-40 m ancients, thick trunks,
 * broad canopies. The village nestles among them.
 * Self-contained ES module. Local frame: terrace tops at y=0 (A), -18 (B), -36 (C).
 *
 *   import { createMaunaVillage } from '/city/village-mauna.js';
 *   const g = createMaunaVillage({ THREE, position: {x, y, z} });
 *   // g.userData: footprint, update(t), terraceTops
 */
function mulberry(a) { return function () { a |= 0; a = a + 0x6D2B79F5 | 0; var t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; }
export function createMaunaVillage(o) {
  var T = o.THREE, P = o.position || { x: 0, y: 0, z: 0 };
  var root = new T.Group(); root.name = 'village-mauna'; root.position.set(P.x, P.y, P.z);
  var foot = [];
  var haleRef = { g: null };
  var R = mulberry(20261011);
  var C = {
    basalt: 0x1c1a20, wood: 0x5a4028, woodDark: 0x3a2a18, thatch: 0x8a6a3a,
    leaf: 0x1e4a24, leafDeep: 0x14331a, trunk: 0x4a3420,
    fire: 0xff9a30, warm: 0xffc060, gold: 0xd8aa48
  };
  var basaltMat = new T.MeshLambertMaterial({ color: C.basalt });
  var woodMat = new T.MeshLambertMaterial({ color: C.wood });
  var woodDarkMat = new T.MeshLambertMaterial({ color: C.woodDark });
  var thatchMat = new T.MeshLambertMaterial({ color: C.thatch });
  var leafMat = new T.MeshLambertMaterial({ color: C.leaf });
  var leafDeepMat = new T.MeshLambertMaterial({ color: C.leafDeep });
  var trunkMat = new T.MeshLambertMaterial({ color: C.trunk });
  var terraceMat = new T.MeshLambertMaterial({ color: 0x2e2a26 });

  // ---------- three terraces ----------
  // A upper (gathering hale), B mid (huts), C lower (huts + lookout)
  var TER = [
    { x: 0, z: -85, y: 0,   r: 58 },
    { x: 0, z: 0,   y: -18, r: 60 },
    { x: 0, z: 85,  y: -36, r: 58 }
  ];
  TER.forEach(function (t) {
    var disc = new T.Mesh(new T.CylinderGeometry(t.r, t.r + 6, 46, 40), terraceMat);
    disc.position.set(t.x, t.y - 23, t.z); root.add(disc);
    var top = new T.Mesh(new T.CylinderGeometry(t.r, t.r, 1.5, 40), new T.MeshLambertMaterial({ color: 0x3a332c }));
    top.position.set(t.x, t.y + 0.4, t.z); root.add(top);
  });

  // ---------- warm window glow material ----------
  var winMat = new T.MeshBasicMaterial({ color: C.warm });

  // ---------- huts (hale-style gabled) ----------
  function hut(x, z, ty, ry, s) {
    s = s || 1;
    var g = new T.Group();
    var w = 9 * s, d = 7 * s, h = 3.6 * s;
    var walls = new T.Mesh(new T.BoxGeometry(w, h, d), woodMat); walls.position.y = h / 2; g.add(walls);
    // pitched roof: two slabs
    var rl = Math.sqrt((w / 2 + 1) * (w / 2 + 1) + 4 * s * s);
    var ang = Math.atan2(2 * s, w / 2 + 1);
    [-1, 1].forEach(function (sd) {
      var slab = new T.Mesh(new T.BoxGeometry(rl, 0.5 * s, d + 1.5 * s), thatchMat);
      slab.position.set(sd * (w / 4 + 0.4 * s), h + 1.0 * s, 0);
      slab.rotation.z = sd * ang; g.add(slab);
    });
    // warm windows (front) + door glow
    var win = new T.Mesh(new T.PlaneGeometry(1.6 * s, 1.2 * s), winMat);
    win.position.set(-w / 4, h * 0.55, d / 2 + 0.06); g.add(win);
    var win2 = win.clone(); win2.position.x = w / 4; g.add(win2);
    var door = new T.Mesh(new T.PlaneGeometry(1.8 * s, 2.6 * s), new T.MeshBasicMaterial({ color: 0xffb050 }));
    door.position.set(0, 1.3 * s, d / 2 + 0.06); g.add(door);
    g.position.set(x, ty, z); g.rotation.y = ry;
    root.add(g);
    foot.push([x, z, w + 1, d + 1, ty, ty + h + 2.4 * s, ry]);
  }
  // Terrace B huts (5)
  hut(-28, -12, -18, 0.3, 1); hut(8, -22, -18, -0.2, 1.1); hut(34, 4, -18, 0.5, 0.95);
  hut(-8, 26, -18, 3.3, 1.05); hut(-38, 18, -18, 2.8, 0.9);
  // Terrace C huts (5)
  hut(-30, 72, -36, 0.4, 1); hut(6, 66, -36, -0.3, 1.1); hut(36, 92, -36, 0.6, 0.95);
  hut(-12, 108, -36, 3.1, 1); hut(28, 112, -36, 2.9, 0.9);

  // ---------- gathering hale (open-sided, Terrace A) ----------
  (function () {
    var ty = 0, cx = 0, cz = -85;
    var g = new T.Group();
    var W = 20, D = 14, PH = 5.5;
    // corner + mid posts
    [[-W/2,-D/2],[W/2,-D/2],[-W/2,D/2],[W/2,D/2],[0,-D/2],[0,D/2],[-W/2,0],[W/2,0]].forEach(function (p) {
      var post = new T.Mesh(new T.CylinderGeometry(0.45, 0.55, PH, 8), woodDarkMat);
      post.position.set(p[0], PH / 2, p[1]); g.add(post);
    });
    // big pitched thatch roof
    var rl = Math.sqrt((W / 2 + 2) * (W / 2 + 2) + 16);
    var ang = Math.atan2(4, W / 2 + 2);
    [-1, 1].forEach(function (sd) {
      var slab = new T.Mesh(new T.BoxGeometry(rl, 0.7, D + 3), thatchMat);
      slab.position.set(sd * (W / 4 + 0.8), PH + 2, 0); slab.rotation.z = sd * ang; g.add(slab);
    });
    // low stone curb walls (open above)
    [[0, -D/2, W, 0.6], [0, D/2, W, 0.6]].forEach(function (w) {
      var curb = new T.Mesh(new T.BoxGeometry(w[2], 1.1, w[3] + 0.6), basaltMat);
      curb.position.set(w[0], 0.55, w[1]); g.add(curb);
    });
    // fire pit
    var pit 