<!-- SOLID CITY · part 3062 -->
 demand keeps its honest floor above;
     * the DESIGN is granted a cut allowance — a second floor 2.2 m
     * lower, used by every clamp after the alignment is drawn.
     * The road may slice that deep through a hump instead of
     * riding over it; the drape and the new cliff walls dress the
     * cut, and the smoothing passes in the alignment spend the
     * allowance where the land rolls hardest. */
    var CUT = 2.2;
    var cutY = floorY.map(function (v) { return v - CUT; });
    function envelope() {
      var i2;
      for (i2 = 1; i2 < N; i2++) { var d = st[i2].ds || stepM; var need = prof[i2 - 1] - gradeCap * d; if (prof[i2] < need) prof[i2] = need; }
      for (i2 = N - 2; i2 >= 0; i2--) { var d2 = st[i2 + 1].ds || stepM; var need2 = prof[i2 + 1] - gradeCap * d2; if (prof[i2] < need2) prof[i2] = need2; }
    }
    /* THE VERTICAL ALIGNMENT — the corridor's second element
     * chain, in the vertical plane (the curriculum's discipline
     * 2). The design profile is a chain of GRADE SEGMENTS through
     * PVIs — points of vertical intersection — joined by PARABOLIC
     * vertical curves: y = yPVC + gIn·t + (gOut−gIn)·t²/(2L), the
     * curve's length from its rate L = K·A (K = 6 m per percent of
     * grade change, A the grades' difference). PVIs stand about
     * twelve metres apart on the terrain's demand (the floored
     * want computed above); the pins are the chain's two ends,
     * exact by construction; the chain is grade-limited by raising
     * the low end of any over-cap segment, the envelope's own
     * discipline, before a single parabola is drawn. What the
     * parabolas cannot honour — 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]])