<!-- SOLID CITY · part 3018 -->
 can leave two stations a
     * few centimetres apart in plan though metres apart along the
     * path — such a micro-station invents a grade out of rounding
     * (a 53% "grade" over 0.66 m was measured at a junction). Merge
     * it: no station stands within 1.2 m of its predecessor. */
    var keptLine = [line[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]);
    }
    keptLine.push(line[line.length - 1]);
    line = keptLine;

    /* THE WIDENING — a switchback is cut wider, never dragged
     * straighter (the finish, second attempt; the first, a plan
     * relaxation toward neighbour midpoints, dragged the legs of
     * the switchbacks across each other and stands refuted by its
     * own census). Where the surveyed line still turns tighter
     * than a carriageway can wear — radius under Rmin at any
     * station, read from the circle through its neighbours — the
     * turn is INFLATED: the apex stations move directly away from
     * the turn's own centre, a little at a time, the way a road
     * crew widens a hairpin into the hill. The legs never approach
     * each other; the route's whole deviation is reported in the
     * stats as fairDev, and the ends stay pinned where the
     * junctions married them. */
    var fairDev = 0;
    (function widen() { /* disabled for measurement */ });

    var N = line.length;

    /* tangents and headings */
    var i, st = [];
    for (i = 0; i < N; i++) {
      var a = line[Math.max(0, i - 1)], b = line[Math.min(N - 1, i + 1)];
      var fx = b[0] - a[0], fz = b[1] - a[1], fl = Math.hypot(fx, fz) || 1;
      fx /= fl; fz /= fl;
      st.push({ x: line[i][0], z: line[i][1], fx: fx, fz: fz, rx: fz, rz: -fx, h: Math.atan2(fx, fz), ds: 0 });
    }
    /* 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): positive = turning toward the right hand */
    for (i = 0; i < N; i++) {
      var h0 = st[Math.max(0, i - 1)].h, h1 = st[Math.min(N - 1, i + 1)].h;
      var run = (st[Math.min(N - 1, i + 1)].ds || stepM) + (st[i].ds || stepM);
      st[i].kappa = wrapAngle(h1 - h0) / Math.max(run, 0.5);
    }

    /* 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 = M