<!-- SOLID CITY · part 3051 -->
a floor that fights back — the
     * envelope below re-proves, as it always has. */
    (function verticalAlign() {
      var arcS = [0];
      for (var vi2 = 1; vi2 < N; vi2++) arcS.push(arcS[vi2 - 1] + (st[vi2].ds || stepM));
      var pIdx = [0];
      for (vi2 = 1; vi2 < N - 1; vi2++) if (arcS[vi2] - arcS[pIdx[pIdx.length - 1]] >= 12) pIdx.push(vi2);
      pIdx.push(N - 1);
      var m = pIdx.length, H = pIdx.map(function (ix) { return prof[ix]; });
      if (spec.pinStartY != null) H[0] = spec.pinStartY;
      if (spec.pinEndY != null) H[m - 1] = spec.pinEndY;
      for (var lp = 0; lp < 3; lp++) {
        for (var j = 0; j < m - 1; j++) {
          var dS = arcS[pIdx[j + 1]] - arcS[pIdx[j]];
          if (H[j + 1] < H[j] - gradeCap * dS && j + 1 < m - 1) H[j + 1] = H[j] - gradeCap * dS;
        }
        for (j = m - 1; j > 0; j--) {
          var dS2 = arcS[pIdx[j]] - arcS[pIdx[j - 1]];
          if (H[j - 1] < H[j] - gradeCap * dS2 && j - 1 > 0) H[j - 1] = H[j] - gradeCap * dS2;
        }
      }
      /* THE SMOOTHING (the Cut's other half): the PVI heights are
       * averaged toward their neighbours — a hump PVI is SLICED,
       * a dip PVI is filled — three rounds, the pins never moving,
       * and the grade chains re-prove every fall after each round.
       * This is where the ups and downs are spent: the profile
       * stops riding every roll of the land and starts flowing
       * through it, as a river does. A PVI moves ONLY when the
       * move lessens its own grade break — a road already calm
       * (the Islands road measured rougher after a blind pass)
       * is left exactly as it lies. */
      for (var sm = 0; sm < 3; sm++) {
        var Hs = H.slice();
        for (j = 1; j < m - 1; j++) {
          var dA = arcS[pIdx[j]] - arcS[pIdx[j - 1]], dB = arcS[pIdx[j + 1]] - arcS[pIdx[j]];
          var cand = H[j] * 0.5 + (H[j - 1] + H[j + 1]) * 0.25;
          var kink = Math.abs((H[j + 1] - H[j]) / dB - (H[j] - H[j - 1]) / dA);
          var kink2 = Math.abs((H[j + 1] - cand) / dB - (cand - H[j - 1]) / dA);
          if (kink2 < kink) Hs[j] = cand;
        }
        H = Hs;
        for (lp = 0; lp < 2; lp++) {
          for (j = 0; j < m - 1; j++) {
            var dS3 = arcS[pIdx[j + 1]] - arcS[pIdx[j]];
            if (H[j + 1] < H[j] - gradeCap * dS3 && j + 1 < m - 1) H[j + 1] = H[j] - gradeCap * dS3;
          }
          for (j = m - 1; j > 0; j--) {
            var dS4 = arcS[pIdx[j]] - arcS[pIdx[j - 1]];
            if (H[j - 1] < H[j] - gradeCap * dS4 && j - 1 > 0) H[j - 1] = H[j] - gradeCap * dS4;
          }
        }
      }
      var segG = [], segL = [];
      for (j = 0; j < m - 1; j++) { segL.push(arcS[pIdx[j + 1]] - arcS[pIdx[j]]); segG.push((H[j + 1] - H[j]) / Math.max(segL[j], 0.01)); }
      var curves = [];
      for (j = 1; j < m - 1; j++) {
        var Apc = Math.abs(segG[j] - segG[j - 1]) * 100;
        var L = Math.min(Math.max(6 * Apc, 8), 60, 0.85 * Math.min(segL[j - 1], segL[j]));
        if (L >= 2) curves.push({ sC: arcS[pIdx[j]], L: L, gIn: segG[j - 1], gOut: segG[j], yPVI: H[j] });
      }
      var seg = 0;
      for (vi2 = 0; vi2 < N; vi2++) {
        var s = arcS[vi2];
        while (seg < m - 2 && s > arcS[pIdx[seg + 1]]) seg++;
        var y = H[seg] + segG[seg] * (s - arcS[pIdx[seg]]);
        for (var ci = 0; ci < curves.length; ci++) {
          var cv = curves[ci];
          if (s >= cv.sC - cv.L / 2 && s <= cv.sC + cv.L / 2) {
            var t = s - (cv.sC - cv.L / 2);
            y = (cv.yPVI - cv.gIn * cv.L / 2) + cv.gIn * t + (cv.gOut - cv.gIn) * t * t / (2 * cv.L);
            break;
          }
        }
        prof[vi2] = y;
      }
    })();
    for (i = 0; i < N; i++) if (prof[i] < cutY[i]) prof[i] = cutY[i];   // the design may cut; the demand may not
    envelope(); envelope();
    /* a guest at a node is given the host's PLANE for its first
     * stretch of arc: the host's grade along its own heading, the
     * host's bank across it, and the guest's profile held within a
     * hand's breadth of that plane for twelve metres — so two
     * roads leave a junction as ONE surface, and what seam remains
     * is the disc's to cover, never the traveller's to feel. Where
     * the floor and the plane quarrel, the floor wins: a road may
     * ride above its host's plane on honest fill, but it is never
     * buried to keep an appointment. */
    if (spec.pinHost) {
      var ph = spec.pinHost, tbH = Math.tan(ph.bank), arcH = 0;
      for (i = 0; i < N; i++) {
        if (i) arcH += st[i].ds || stepM;
        if (arcH > 12) break;
        var alH = (st[i].x - ph.x) * ph.fx + (st[i].z - ph.z) * ph.fz;
        var acH = (st[i].x - ph.x) * ph.rx + (st[i].z - ph.z) * ph.rz;
        var pyH = ph.y + ph.grade * alH + tbH * acH;
        if (prof[i] < pyH - 0.35) prof[i] = pyH - 0.35;
        if (prof[i] > pyH + 0.35) prof[i] = pyH + 0.35;
        if (prof[i] < cutY[i]) prof[i] = cutY[i];
      }
     