<!-- SOLID CITY · part 3012 -->
o station within 1.2 m of its
     * predecessor (the ends are promises and stay exact). */
    var keptLine = [line[0]], keptHead = [aligned.head[0]], keptKap = [aligned.kap[0]];
    for (var li = 1; li < line.length - 1; li++) {
      var lastK = keptLine[keptLine.length - 1];
      if (Math.hypot(line[li][0] - lastK[0], line[li][1] - lastK[1]) >= 1.2) { keptLine.push(line[li]); keptHead.push(aligned.head[li]); keptKap.push(aligned.kap[li]); }
    }
    keptLine.push(line[line.length - 1]); keptHead.push(aligned.head[aligned.head.length - 1]); keptKap.push(aligned.kap[aligned.kap.length - 1]);
    line = keptLine;
    var fairDev = 0;   // the corridor moves no station after sampling; the name stays for the record books

    var N = line.length;

    /* tangents and headings — ANALYTIC, from the elements */
    var i, st = [];
    for (i = 0; i < N; i++) {
      var hh = keptHead[i];
      var fx = Math.sin(hh), fz = Math.cos(hh);
      st.push({ x: line[i][0], z: line[i][1], fx: fx, fz: fz, rx: fz, rz: -fx, h: hh, ds: 0, kappa: keptKap[i] });
    }
    /* NOTE the right vector: forward (fx, fz) with the city's heading
     * convention (heading = atan2(fx, fz), forward = (sin, cos)) has its
     * right hand at (fz, -fx) in plan — at heading 0 (facing +z) the
     * right is +x: (fz, -fx) = (1, 0). Verified against the factory's
     * own frames before a single triangle was drawn. */
    for (i = 1; i < N; i++) st[i].ds = Math.hypot(st[i].x - st[i - 1].x, st[i].z - st[i - 1].z);
    /* curvature (signed) rides in st.kappa from the alignment:
     * positive = turning toward the right hand, continuous by
     * construction — ramps on the clothoids, constant on the arcs,
     * zero on the straights. No finite differences anywhere. */

    /* THE BENCH (the King's technique, from his photographs of the
     * Waipiʻo road, 2026-10-13): a mountain road is DUG INTO the
     * topography — dirt on ONE side. The uphill edge keys to the land
     * and the cut bank rises above it; the downhill edge carries a
     * shoulder and a guardrail over the drop. Dirt on both sides
     * belongs only to a through-cut where a road pierces a ridge.
     * So: first learn which side is uphill over the road's whole run. */
    var upScore = 0;
    for (i = 0; i < N; i++) {
      var sU = st[i];
      var uRg = groundAt(sU.x + sU.rx * (hw + 1.2), sU.z + sU.rz * (hw + 1.2));
      var uLg = groundAt(sU.x - sU.rx * (hw + 1.2), sU.z - sU.rz * (hw + 1.2));
      upScore += (uRg - uLg);
    }
    var upSide = upScore >= 0 ? 1 : -1;

    /* the profile: keyed to the uphill edge, floored by the surface.
     * desired: the uphill edge sits a hair under its own ground (the
     * dirt meets the road), and the surface rises from that edge
     * toward the centre at a civil cross slope. The floor's law is
     * stated where it is computed (v3, below). */
    /* the cross-section is read through a median first: a rib that
     * crosses the line for ONE station is a feature of the land, not
     * an order to the road — the road answers the land's grain, and
     * the rib's corner is dressed by the cut bank where it stands.
     * The floor (v3) swears two things only: the centre is never
     * buried, and no edge may drag the whole surface more than
     * 1.35 m above the centre for its own sake. */
    var rawC = [], rawL = [], rawR = [];
    for (i = 0; i < N; i++) {
      var s0 = st[i];
      rawC.push(groundAt(s0.x, s0.z));
      rawL.push(groundAt(s0.x - s0.rx * hw, s0.z - s0.rz * hw));
      rawR.push(groundAt(s0.x + s0.rx * hw, s0.z + s0.rz * hw));
      s0.gC = rawC[i];
    }
    function med3(arr, j) {
      var a = arr[Math.max(0, j - 1)], b = arr[j], c = arr[Math.min(N - 1, j + 1)];
      return a + b + c - Math.min(a, b, c) - Math.max(a, b, c);
    }
    var prof = [], floorY = [];
    for (i = 0; i < N; i++) {
      var s = st[i];
      var gC = med3(rawC, i);
      var gL = med3(rawL, i), gR = med3(rawR, i);
      var crossMax = Math.max(gL, gC, gR);
      var gUp = upSide > 0 ? gR : gL;
      var sCross = Math.max(-0.04, Math.min(0.10, (gC - gUp) / hw));
      var want = gUp - 0.06 + hw * sCross;
      if (want > gC + 1.05) want = gC + 1.05;        // never fill the centre higher
      prof.push(want);
      floorY.push(Math.max(gC + 0.06, Math.min(crossMax - 0.30, gC + 1.35)));
      s.crossMax = crossMax; s.gUp = gUp;
    }
    /* The envelope survives as the profile's SAFETY NET (it is
     * called again below and inside the host-plane blend): the
     * profile never sinks under its floor and never grades beyond
     * the cap; its passes only ever RAISE — a limiter that could
     * also lower would drag the surface under the floor it was
     * sworn to keep (the first build's burial was that crime). */
    for (i = 0; i < N; i++) if (prof[i] < floorY[i]) prof[i] = floorY[i];
    function envelope() {
      var i2;
      for (i2 = 1; i2 < N; i2++) { var d = st[i2].ds || s