<!-- SOLID CITY · part 2483 -->
- cz)) / den;
  var w2 = 1 - w0 - w1;
  if (w0 < -0.01 || w1 < -0.01 || w2 < -0.01) return null;
  return w0 * ay + w1 * by + w2 * cy;
}
function standY(x, z, py) {
  var rects = M.rects; if (!rects) return -1000;
  /* THE GATE SPLIT (2026-10-14, from the study of the published
   * controllers: Unreal steps up 0.45 m, Unity 0.1–0.4 m, Godot snaps
   * 0.1 m grounded-only): one 1.6 m gate let a walker step onto
   * chest-high surfaces and hid real seams from his feet. On foot the
   * gate is now 0.45 m — the mountain walk census reads clean under
   * it, worst riser 0.44 m. A DRIVER keeps the proven 1.6: at speed
   * on a 38% grade the car's own ground runs ahead of a tight gate
   * between frames, and the drive proofs were sworn under 1.6. The
   * mode is read from the city's own state — S here is SC.api.S
   * (verified in city.js, where the api object is built as
   * { T: T, S: S, ... } and S.drive stands while a car is driven).
   * The gate is a ceiling only: anything at or below the feet is
   * always eligible, so landing and falling are untouched. */
  var gate = (typeof S !== 'undefined' && S && S.drive) ? 1.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=20261014k'); } 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-rejection-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';
