<!-- SOLID CITY · part 3082 -->
pec.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;
        }
      }
      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] < floorY[i]) prof[i] = floorY[i];
    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] < floorY[i]) prof[i] = floorY[i];
      }
      envelope();
      if (spec.pinStartY != null) {
        prof[0] = spec.pinStartY;
        for (i = 1; i < N; i++) { var dpc = st[i].ds || stepM; var ndc = prof[i - 1] - gradeCap * dpc; if (prof[i] < ndc) prof[i] = ndc; }
      }
    }
    /* the pins are promises, and promises have feet: the cap-chains
     * that honour them meet the natural profile at a corner. A few
     * raise-only passes round those feet with honest fill, the
     * envelope re-proves every grade, and then the pins are set
     * exact once more — the promise stands, and the road walks up
     * to it like a road, not a step. */
    if (spec.pinStartY != null || spec.pinEndY != null) {
      for (var rp = 0; rp < 3; rp++) {
        var rsm = prof.slice();
        for (i = 1; i < N - 1; i++) { var rcand = prof[i - 1] * 0.3 + prof[i] * 0.4 + prof[i + 1] * 0.3; if (rcand > prof[i]) rsm[i] = rcand; }
        prof = rsm;
      }
      envelope();
      if (spec.pinStartY != null) prof[0] = spec.pinStartY;
      if (spec.pinEndY != null) prof[N - 1] = spec.pinEndY;
    }
    /* THE PIN APRON — the envelope's missing half, and the last
     * word on the profile. The cap chains limit how fast the
     * profile may FALL away from a station; nothing limited how
     * fast it may RISE away from a pin, and at the braid head the
     * host's banked plane lifted the second station 0.63 m over
     * the pin in a single step (45%, measured). The apron trims
     * any rise out of a pin to the cap across the first stations,
     * down to the floor and never below it; where the floor itself
     * forbids, the junction disc — which owns that ground — covers
     * what remains. It runs after the host-plane blend and the
     * pins-feet rounding, so nothing after it can reopen the seam. */
    (function pinApron() {
      var arcA = 0;
      for (var ai2 = 1; ai2 < N && ai2 <= 8; ai2++) {
        arcA += st[ai2].ds || stepM;
        var lim = prof[0] + gradeCap * arcA;
        if (prof[ai2] > lim) prof[ai2] = Math.max(floorY[ai2], lim);
      }
      var arcB = 0;
      for (ai2 = N - 2; ai2 >= 0 && ai2 >= N - 9; ai2--) {
        