<!-- SOLID CITY · part 2477 -->
.6 : 0.45;
  var best = -1000;
  for (var i = 0; i < rects.length; i++) {
    var r = rects[i], dx = x - r.cx, dz = z - r.cz;
    var lx = dx * r.cos - dz * r.sin, lz = dx * r.sin + dz * r.cos;
    if (Math.abs(lx - r.lx) <= r.hw && Math.abs(lz - r.lz) <= r.hd) {
      if (py == null || r.y <= py + gate) { if (r.y > best) best = r.y; }
    }
  }
  // the pitched surfaces (roads, driveways, paths, pads) — the same reading
  // the ward joins get: the highest triangle that passes the walker's gate
  if (M.triIx) {
    var bx = Math.floor(x / 16), bz = Math.floor(z / 16);
    for (var gx = bx - 1; gx <= bx + 1; gx++) for (var gz = bz - 1; gz <= bz + 1; gz++) {
      var cell = M.triIx[gx + ':' + gz]; if (!cell) continue;
      for (var ci = 0; ci < cell.length; ci++) {
        var ty = triYAt(M.tris, cell[ci], x, z);
        if (ty == null) continue;
        if (py == null || ty <= py + gate) { if (ty > best) best = ty; }
      }
    }
  }
  return best;
}
function load() {
  M.state = 'loading';
  var ga = A.groundAt || (typeof groundAt === 'function' ? groundAt : null);
  var p; try { p = import('/city/mountain-homes.js?v=20261014i'); } catch (e) { p = Promise.reject(e); }
  p.then(function (mod) {
    var make = mod.createMountainHomes || mod.default;
    var g = make({ THREE: A.T, groundAt: ga });
    A.world.add(g); M.group = g; M.state = 'ready';
    M.rects = (g.userData && g.userData.standRects) || null;
    M.tris = (g.userData && g.userData.standTris) || null;
    if (M.tris) {
      M.triIx = {};
      for (var ti = 0; ti + 8 < M.tris.length; ti += 9) {
        var tcx = (M.tris[ti] + M.tris[ti + 3] + M.tris[ti + 6]) / 3, tcz = (M.tris[ti + 2] + M.tris[ti + 5] + M.tris[ti + 8]) / 3;
        var tk = Math.floor(tcx / 16) + ':' + Math.floor(tcz / 16);
        (M.triIx[tk] = M.triIx[tk] || []).push(ti);
      }
    }
    collide(g.userData || {}); hyperStop(); watchStop();
  }).catch(function (e) { M.state = 'failed'; try { console.warn('[city] Ancestors homes skipped:', e && e.message); } catch (x) {} });
}
function update(dt) {
  if (M.state === 'idle') { if (A.isBuilt && !A.isBuilt()) return; M.wait -= dt; if (M.wait <= 0) load(); return; }
  if (M.state !== 'ready' || document.hidden) return;
  var c = A.camera.position, d = Math.hypot(c.x + A.origin.x - POS.x, c.z + A.origin.z - POS.z);
  M.group.visible = d < 11000;
  if (S.mode === 'walk') {
    var pd = Math.hypot(S.p.x - POS.x, S.p.z - POS.z);
    if (pd < 420 && !M.said) { M.said = true; if (window.CityHyper && CityHyper.narrate) CityHyper.narrate("<b>Nā Hale o nā Kūpuna</b> — the Ancestors' Homes. 'Ohana compounds on the green benches; every door opens.", 7); }
    else if (pd > 700) M.said = false;
  }
}
function radar(g, blip, fl) { if (M.state === 'ready') blip(POS.x, POS.z, '#4a8a3a', fl ? 3 : 6, fl ? '' : 'HOMES'); }
window.CityMountainHomes = { update: update, radar: radar, pos: POS, standY: standY, state: function () { return M.state; }, group: function () { return M.group; } };
})();


===== FILE: public/city/mountain-homes-place.js.bak-darkgreen2-20261014 =====
/* Solid City — places NĀ HALE O NĀ KŪPUNA, THE ANCESTORS' HOMES (public/city/mountain-homes.js)
   on the green coastal benches around the Ancestral Roads, by order of the King:
   "We need to build homes for hawaiians."
   Lazy: imported after the city is built; any import/build error is caught and the city carries on.
   The module sites every home on the real terrain at runtime (placement law:
   gentle benches only, ledges and cliffs untouched, a driveway to every door).
   Adds: collision (userData.footprint, world-absolute), P.y-aware standY (floors,
   lanai, stairs), a radar marker 'HOMES', a Hyper Controller stop, and a Watch
   (GRAND TOUR) caption. One quiet line on first approach. */
(function () {
'use strict';
if (!window.SC || !SC.api) return;
var A = SC.api, S = A.S;
var POS = { x: 300, z: -1500 }, NAME = "Nā Hale o nā Kūpuna — The Ancestors' Homes";
var M = { state: 'idle', group: null, wait: 4.5, said: false, rects: null, tris: null, triIx: null };
function addBox(cx, cz, w, d, rot, y0, y1) {
  var nx = Math.max(1, Math.ceil(w / 2.5)), nz = Math.max(1, Math.ceil(d / 2.5)), cw = w / nx, cd = d / nz, c = Math.cos(rot), s = Math.sin(rot);
  var hx = cw / 2 * Math.abs(c) + cd / 2 * Math.abs(s), hz = cw / 2 * Math.abs(s) + cd / 2 * Math.abs(c);
  for (var i = 0; i < nx; i++) for (var j = 0; j < nz; j++) {
    var ox = -w / 2 + cw * (i + 0.5), oz = -d / 2 + cd * (j + 0.5), lx = cx + ox * c + oz * s, lz = cz - ox * s + oz * c;
    A.solids.push({ x0: lx - hx, x1: lx + hx, z0: lz - hz, z1: lz + hz, y0: y0, y1: y1, mountainHomes: true });
  }
}
function collide(ud) { (ud.footprint || []).forEach(function (b) { addBox(b[0], b[1], b[2], b[3], b[6] || 0, b[4], b[5]); }); }
function hyperStop() {
  var H = window.CityHyper; if (!H || !H.pois || H.pois.some(function (p) { return p.id === 'ancestors-homes'; })) return;
  H.pois.push({ id: 