<!-- SOLID CITY · part 2984 -->
t'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];
      }
      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(cutY[ai2], lim);
      }
      var arcB = 0;
      for (ai2 = N - 2; ai2 >= 0 && ai2 >= N - 9; ai2--) {
        arcB += st[ai2 + 1].ds || stepM;
        var limB = prof[N - 1] + gradeCap * arcB;
        if (prof[ai2] > limB) prof[ai2] = Math.max(cutY[ai2], limB);
      }
    })();
    /* THE SHOULDER PASS (the hardening night, 2026-10-14): the
     * last shaping of the profile, and the answer to the knees
     * the census convicted. A crest eased at its floor still met
     * its descent in a single segment (−1% into −38% at Road C's
     * apex brow), because the descent is drawn by the envelope
     * at the grade cap while the crest rests at its eased
     * height, and nothing until now owned the JOIN. The pass
     * diffuses any station break sharper than 20 points: the
     * station walks halfway toward the chord of its neighbours,
     * again and again, a move accepted only when the three
     * breaks it touches lose more sharpness than they gain, and
     * never outside the sworn bounds — never below the cut
     * floor, never above the higher of its present height and
     * its demand floor. The pin aprons' ground — the first and
     * last nine stations — is not the pass's to touch: the
     * junction discs own it, as the apron's epistle swore. */
    (function shoulderPass() {
      function grades() { var g = [0]; for (var gi = 1; gi < N; gi++) g.push((prof[gi] - prof[gi - 1]) / (st[gi].ds || stepM)); return g; }
      for (var sw2 = 0; sw2 < 6; sw2++) {
        var moved = 0;
        for (var j = 9; j < N - 9; j++) {
          var g = grades();
          if (Math.abs(g[j + 1] - g[j]) <= 0.20) continue;
          var before = Math.abs(g[j] - g[j - 1]) + Math.abs(g[j + 1] - g[j]) + Math.abs(g[j + 2] - g[j + 1]);
          var chord = (prof[j - 1] + prof[j + 1]) / 2;
          var cand = prof[j] + (chord - prof[j]) * 0.5;
          var hi = Math.max(prof[j],