/* The scope run (home, under the hero): the visitor's scroll is a sewer camera travelling down the line.
   Three states, plainest first:
   1. no script: the six steps are a readable list of cards under the opening band; the real camera frames at the
      roots and the cracks are a row under the card's words that swipes sideways;
   2. script + reduced motion: the same list, each card under a still frame of its station (scope.js draws them);
      "See the real thing" opens the frames inside the card;
   3. script + motion: scrollytelling. The canvas stage sticks under the top bar and takes no room in the flow; the
      opening band and the steps scroll over it. Each step is a stretch of open pipe (padding) and then a hold, in which
      its card parks low on the screen (position: sticky, bottom) while the camera creeps past the station. The camera's
      display is its own sticky layer above the cards, so it reads the whole way down. "See the real thing" opens the
      frames over the picture: a sheet above the card on phones, a panel beside it on wide screens.
   Nothing here changes how the page scrolls. */
.scope { --scope-dark: #17100C; --park: clamp(28px, 9vh, 96px); --tag: #F2C230; padding: 0; background: var(--trench); color: #fff; }
.scope-stage, .scope-hud, .scope-still, .scope-cut, .scope-shot, .hud-tc { display: none; }

/* The opening: the band of topsoil right under the lawn. It lifts off the picture as the visitor scrolls */
.scope-head { position: relative; padding: clamp(40px, calc(7 * min(1vw, 19.2px)), 88px) var(--m) clamp(32px, calc(5 * min(1vw, 19.2px)), 60px); background: var(--soil-1); color: var(--char); }
.scope-head h2 { max-width: 11ch; }
.scope-head p { margin-top: 16px; max-width: 36ch; font-size: var(--step-lead); line-height: 1.4; }
.scope-head .text-link { margin-top: 8px; }
/* The cut-away under the lawn, carried down from the cleanout that stands on it (scope.js draws it when cleanout.js
   says where that is): the riser comes down, sweeps through an elbow and joins the old clay line, which runs off
   across the soil above the words. The drawing may start above the band, in the soil under the lawn */
.scope-head.has-cut { padding-top: calc(var(--cut-room, 0px) + 30px); }
.scope-head.has-cut .scope-cut { display: block; position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
@media (min-width: 901px) {   /* wide screens: the words in one shallow block under the line, the soil open beside them */
  .scope-head.has-cut { display: grid; grid-template-columns: auto 1fr; column-gap: 40px; align-items: center;
    padding-top: calc(var(--cut-room, 0px) + 22px); padding-bottom: 36px; }
  .scope-head.has-cut h2 { grid-column: 1 / -1; max-width: none; }
  .scope-head.has-cut p { margin-top: 14px; max-width: 46ch; }
  .scope-head.has-cut .text-link { margin-top: 14px; justify-self: start; }
}

/* The steps as a list of cards */
.scope-steps { list-style: none; margin: 0; padding: clamp(28px, calc(5 * min(1vw, 19.2px)), 56px) var(--m) clamp(48px, calc(7 * min(1vw, 19.2px)), 88px); display: grid; gap: 28px 24px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.scope-step { display: flex; flex-direction: column; min-width: 0; }
.scope-card { position: relative; flex: 1; background: var(--char); color: #fff; border-radius: 14px; padding: 18px 20px 20px; }
.scope-ft { font: 700 0.9375rem/1 var(--display); letter-spacing: 0.08em; text-transform: uppercase; font-variant-numeric: tabular-nums; color: var(--tag); }
/* the station's name, and beside it (roots, cracks) the way to the real frames */
.scope-top { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.scope-card h3 { font-size: clamp(1.6rem, 1.35rem + calc(0.9 * min(1vw, 19.2px)), 2rem); font-weight: 800; }
.scope-top ~ p { margin-top: 10px; line-height: 1.45; }
.scope-fix { padding-left: 12px; border-left: 4px solid var(--blue); }
/* Doug's own practical point: a small label, then his words, a step quieter than the card's */
.scope-note { color: #E9E5DD; }
.scope-note b { display: block; margin-bottom: 2px; font: 700 0.9375rem/1.2 var(--display); letter-spacing: 0.02em; color: var(--tag); }
.scope-cta { margin-top: 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 22px; }
.scope-cta .text-link { color: #fff; }
/* "More from Doug": only where the card has to stay short (scope.js sets .scope--tuck and shows the button) */
.scope-more { display: none; }
.scope--tuck .scope-card:not(.is-more) .scope-note { display: none; }
.scope--tuck .scope-more:not([hidden]) { position: relative; flex: none; display: inline-flex; align-items: center; min-height: 48px; margin-left: auto; padding: 0 2px 0 6px;
  border: 0; background: none; color: var(--tag); font: 700 1rem/1 var(--text); cursor: pointer; touch-action: manipulation; }
.scope-more span { margin-left: 0.28em; }
.scope-more::after { content: ''; width: 9px; height: 9px; margin: -5px 3px 0 9px; border-right: 2.5px solid; border-bottom: 2.5px solid; transform: rotate(45deg); }
.scope-more[aria-expanded="true"]::after { margin-top: 5px; transform: rotate(-135deg); }

/* "See the real thing": a tag in the camera display's yellow with a little lens on it */
.scope-see { position: relative; flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 13px 0 10px; border: 0; border-radius: 999px;
  background: var(--tag); color: var(--char); font: 700 1rem/1 var(--text); white-space: nowrap; cursor: pointer; touch-action: manipulation; }
.scope-see[hidden] { display: none; }
.scope-see::before { content: ''; flex: none; width: 18px; height: 14px; border: 2.5px solid; border-radius: 4px; background: radial-gradient(circle, currentColor 2.4px, transparent 3px); }
.scope-see::after { content: ''; position: absolute; inset: -7px 0; }   /* the hit area: 48 px tall */
.scope-see[aria-expanded="true"] { background: #fff; }
@media (hover: hover) and (pointer: fine) { .scope-see:hover { background: #F7D560; } .scope-see[aria-expanded="true"]:hover { background: #fff; } }

/* The real camera frames (the client's own, from customers' inspections): a row that swipes sideways, one frame at a
   time, each with its caption. --rp is the box's own padding; --pic-mid the middle of the picture, where the arrows sit */
.scope-reel { --rp: 0px; --pic-mid: calc(var(--rp) + 28.125cqw); position: relative; container-type: inline-size; margin-top: 14px; }
html.js .scope-reel:not(.is-open) { display: none; }
.reel-track { list-style: none; margin: 0; padding: 0; display: flex; gap: 10px; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; border-radius: 8px; }
html.js .reel-track { scrollbar-width: none; }
html.js .reel-track::-webkit-scrollbar { display: none; }
.reel-shot { flex: 0 0 86%; min-width: 0; scroll-snap-align: start; scroll-snap-stop: always; }
html.js .reel-shot { flex-basis: 100%; }
.reel-shot figure { margin: 0; }
.reel-shot picture { display: block; }
.reel-shot img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; background: var(--scope-dark); }
.reel-shot figcaption { padding: 8px 2px 0; font-size: 0.9375rem; line-height: 1.35; }
.reel-shot figcaption b { margin-right: 6px; font: 700 0.875rem/1 var(--display); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; color: var(--tag); }
.reel-src { margin-top: 6px; font-size: 0.875rem; line-height: 1.4; color: #C9C5BD; }
/* arrows and close: 48 px to press, a 36 px disc to look at */
.scope-reel button { position: absolute; z-index: 1; width: 48px; height: 48px; padding: 0; border: 0; border-radius: 50%; background: none; color: #fff; cursor: pointer; touch-action: manipulation; }
.scope-reel button[hidden] { display: none; }
.scope-reel button::before { content: ''; position: absolute; inset: 6px; border: 2px solid #fff; border-radius: 50%; background: var(--char); }
.scope-reel button::after { content: ''; position: absolute; left: 50%; top: 50%; width: 9px; height: 9px; border-right: 2.5px solid; border-bottom: 2.5px solid; }
.reel-prev { left: calc(var(--rp) + 2px); top: calc(var(--pic-mid) - 24px); }
.reel-prev::after { transform: translate(-30%, -50%) rotate(135deg); }
.reel-next { right: calc(var(--rp) + 2px); top: calc(var(--pic-mid) - 24px); }
.reel-next::after { transform: translate(-70%, -50%) rotate(-45deg); }
.reel-close { right: calc(var(--rp) + 2px); top: calc(var(--rp) + 2px); }
.scope-reel .reel-close::after { width: 14px; height: 14px; border: 0; transform: translate(-50%, -50%) rotate(45deg);
  background: linear-gradient(currentColor, currentColor) center / 100% 2.5px no-repeat, linear-gradient(currentColor, currentColor) center / 2.5px 100% no-repeat; }
.scope-reel button[aria-disabled="true"] { opacity: 0.35; cursor: default; }
@media (hover: hover) and (pointer: fine) { .scope-reel button:not([aria-disabled="true"]):hover::before { background: #444; } }

/* The way back up: five cleanout risers, two and then three, each a white pipe with its cap and square nut */
.scope-exits { margin-top: 30px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 30px 26px; padding: 0 9px 2px; }
.scope-exits a { grid-column: span 2; position: relative; display: flex; align-items: flex-end; min-height: 84px; padding: 26px 8px 10px; background: #F4F2EE; color: var(--char);
  border: 3px solid #111; border-top: 0; border-radius: 0 0 6px 6px; font: 700 1.0625rem/1.15 var(--display); text-decoration: none; touch-action: manipulation; }
.scope-exits a:nth-child(-n+2) { grid-column: span 3; padding-inline: 10px; }
.scope-exits a::before { content: ''; position: absolute; left: -12px; right: -12px; top: -3px; height: 20px; background: #F4F2EE; border: 3px solid #111; border-radius: 6px; }
.scope-exits a::after { content: ''; position: absolute; left: 50%; top: -14px; width: 22px; height: 14px; margin-left: -11px; background: #F4F2EE; border: 3px solid #111; border-bottom: 0; border-radius: 4px 4px 0 0; }
.scope-exits a:focus-visible { outline-offset: 12px; }
@media (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  .scope-exits a { transition: transform var(--t-hover) var(--ease-out); }
  .scope-exits a:hover { transform: translateY(-4px); }
}
@media (hover: hover) and (pointer: fine) { .scope-exits a:hover { background: #fff; } }

/* Reduced motion: an illustrated list. Each still sits on top of its card */
@media (prefers-reduced-motion: reduce) {
  html.js .scope-still { display: block; width: 100%; height: auto; border-radius: 14px 14px 0 0; background: var(--scope-dark); }
  html.js .scope-still + .scope-card { border-radius: 0 0 14px 14px; }
}

@media (max-width: 900px) { .scope { --park: 24px; } }
@media (max-width: 760px) {
  .scope { --park: calc(env(safe-area-inset-bottom) + 96px); }   /* clear of the Call and Quote dock */
  .scope-head { padding-bottom: 26px; }
  .scope-steps { padding-inline: 12px; }
  .scope-card { padding: 12px 14px 14px; }
  .scope-card h3 { font-size: 1.5rem; }
  .scope-top { margin-top: 8px; }
  .scope-top ~ p { margin-top: 6px; line-height: 1.4; }
  /* the dock already carries Call: the card's own action is the link, shaped as the quiet button; "More from Doug"
     shares its row */
  .scope-cta { margin-top: 12px; flex-wrap: nowrap; gap: 8px; }
  .scope-cta .pill { display: none; }
  .scope-cta .text-link { flex: 1 1 auto; justify-content: center; min-height: 48px; padding: 0 10px; border: 2px solid #fff; border-radius: 999px; text-decoration: none; white-space: nowrap; }
  .scope-exits { margin-top: 28px; gap: 28px 26px; }
  .scope-exits a { min-height: 78px; font-size: 1rem; }
}
@media (max-width: 384px) { .scope-more span { display: none; } }   /* narrow phones: "More", so it still shares the row */

/* ---------- Script and motion: the run ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* A solid dark behind everything, so the phone's floating toolbar tints dark too. The section is its own stack:
     picture 0, cards 1, the camera's display 2, the opening band 3; the next section slides over all of it */
  html.js .scope { background: var(--scope-dark); z-index: 0; }
  /* the stage runs to the foot of the largest viewport (lvh), so the picture also fills the strip a phone's toolbar
     leaves when it shrinks; the cards park against the visible bottom, and scope.js frames inside the visible part */
  html.js .scope-stage { display: block; position: sticky; top: var(--bar-h); z-index: 0; overflow: hidden; background: var(--scope-dark);
    height: calc(100vh - var(--bar-h)); margin-bottom: calc(var(--bar-h) - 100vh);
    height: calc(100svh - var(--bar-h)); margin-bottom: calc(var(--bar-h) - 100svh);
    height: calc(100lvh - var(--bar-h)); margin-bottom: calc(var(--bar-h) - 100lvh); }
  html.js .scope-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
  html.js .scope-head { z-index: 3; }
  @media (max-width: 760px) {
    /* phones: the card is as short as it can be, so the picture keeps the room. The display strip right above
       already reads the feet; Doug's note waits behind "More from Doug"; under about 740 px of screen the card's
       text steps down to 16 px (svh: steady while a phone's toolbar comes and goes) */
    html.js .scope-card { padding: 10px 14px 12px; }
    html.js .scope-card .scope-ft { display: none; }
    html.js .scope-top { margin-top: 0; min-height: 34px; flex-wrap: nowrap; }
    html.js .scope-top ~ p { margin-top: 5px; line-height: 1.375; font-size: clamp(1rem, calc(1rem + (100svh - 740px) * 999), var(--step-body)); }
    html.js .scope-cta { margin-top: 8px; }
  }
  html.js .scope-steps { position: relative; z-index: 1; display: block; padding-block: 0; pointer-events: none; }
  /* open pipe first (the camera travels), then the hold (the card parks, the camera creeps). The first step has the
     same open stretch as the rest: with the opening band at the top of the screen its card is still below the screen,
     so it never sits half under the phone's Call and Quote dock beside the band's words; it rides in as the band leaves */
  html.js .scope-step { justify-content: flex-end; padding-top: 62vh; min-height: 140vh; padding-top: 62svh; min-height: 140svh; }
  @media (min-width: 901px) {
    /* Let the opening band clear the heading before the first card parks; phone timing stays as it is. */
    html.js .scope-step:first-child { padding-top: 98vh; padding-top: 98svh; }
  }
  html.js .scope-card { flex: none; position: sticky; bottom: var(--park); width: min(100%, 420px); pointer-events: auto; }
  /* Douglas, 17 Nov: the black boxes that travel with the camera are half see-through, so the pipe shows behind them */
  html.js .scope-card { background: rgb(34 34 34 / .45); text-shadow: 0 1px 3px rgb(0 0 0 / .55); }

  /* The real frames, over the picture (scope.js says which, and how much room there is). Phones: a sheet that rises
     from the card's top edge, the card stays; when the room under the display strip is short it covers the strip too
     (.reel-over lifts the cards' layer over the display for as long as it is open). Wide screens: a panel in the
     open picture beside the card */
  html.js .scope.reel-over .scope-steps { z-index: 2; }
  .scope-reel.is-sheet, .scope-reel.is-side { --rp: 8px; position: absolute; z-index: 1; margin: 0; padding: var(--rp); border-radius: 14px; background: var(--char);
    opacity: 0; transition: opacity var(--t-ui) var(--ease-out), transform var(--t-ui) var(--ease-out); }
  .scope-reel.is-sheet { --pic-mid: calc((var(--reel-h, 260px) - var(--cap, 52px)) / 2); left: -4px; right: -4px; bottom: calc(100% + 8px - var(--reel-drop, 0px)); height: var(--reel-h, 260px);
    display: flex; flex-direction: column; transform: translateY(14px); }
  .scope-reel.is-side { --rp: 10px; left: calc(100% + 24px); bottom: var(--reel-lift, 0px); width: var(--reel-w, 640px); transform: translateX(-14px); }
  .scope-reel.is-in { opacity: 1; transform: none; }
  .is-sheet .reel-track { flex: 1; min-height: 0; }
  .is-sheet .reel-shot figure { height: 100%; display: flex; flex-direction: column; }
  .is-sheet .reel-shot picture { flex: 1; min-height: 0; }
  .is-sheet .reel-shot img { height: 100%; aspect-ratio: auto; }
  .is-sheet .reel-shot figcaption { flex: none; min-height: calc(2.7em + 8px); }   /* two lines, so every frame is the same height */
  .is-sheet .reel-src { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .is-side .reel-src { margin: 4px 2px 2px; }

  /* The camera's on-screen display. Phones: a solid strip under the top bar, like the bezel of the scope's monitor;
     the cards slide away beneath it and the feet keep counting */
  html.js .scope-hud { display: block; position: sticky; top: var(--bar-h); z-index: 2; height: 62px; margin-bottom: -62px; pointer-events: none;
    background: var(--char); border-top: 1px solid rgb(255 255 255 / .16); color: #fff; font-family: var(--display); font-variant-numeric: tabular-nums;
    -webkit-user-select: none; user-select: none; }
  .hud-id, .hud-ft { position: absolute; top: 9px; display: inline-flex; align-items: center; gap: 8px; height: 24px;
    font-weight: 700; font-size: 0.875rem; line-height: 1; letter-spacing: 0.08em; white-space: nowrap; }
  .hud-id { left: 16px; }
  .hud-id b { font-weight: 600; margin-left: 4px; }
  .hud-rec { width: 10px; height: 10px; border-radius: 50%; background: #E0463A; animation: hud-rec 1.6s steps(1, end) infinite; }
  .hud-ft { right: 16px; gap: 5px; }
  .hud-ft b { font-weight: 800; font-size: 1.25rem; letter-spacing: 0.04em; }
  /* feet and inches, as a real scope's overlay writes them: each number in a box two digits wide, set right, so the
     brackets and marks stand still while it counts. The inches' empty first place is the space after the feet */
  .hud-n { display: inline-block; width: calc(2ch + 0.08em); font-style: normal; text-align: right; }
  .hud-n + .hud-n { margin-left: 0.12em; }
  .hud-rail { position: absolute; left: 18px; right: 18px; top: 42px; height: 8px; border-radius: 4px; background: #4D4D4D; }
  .hud-fill { position: absolute; inset: 0; border-radius: 4px; background: var(--blue); transform-origin: 0 50%; transform: scaleX(0); }
  .hud-tick { position: absolute; top: -3px; width: 4px; height: 14px; margin-left: -2px; border-radius: 2px; background: #fff; box-shadow: 0 0 0 2px var(--char); font-style: normal; }
  .hud-tick.is-at { background: var(--tag); }
  .hud-tick span { display: none; }

  /* The defect, pointed out on the picture: a bracket on it, its name on a tag, a leader between them. scope.js keeps
     bracket and tag inside the clear part of the picture (under the display, above or beside the card) */
  .hud-mark { position: absolute; left: 0; top: 0; width: var(--s, 120px); height: var(--s, 120px); margin: calc(var(--s, 120px) / -2) 0 0 calc(var(--s, 120px) / -2);
    pointer-events: none; font-family: var(--display); opacity: 0; transition: opacity var(--t-hover) ease; }
  .hud-mark.is-on { opacity: 1; }
  .hud-box { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; fill: none; stroke-linecap: round; stroke-linejoin: round;
    transform: scale(1.3); transition: transform var(--t-panel) var(--ease-out); }
  .hud-mark.is-on .hud-box { transform: scale(1); }
  .hud-box path { vector-effect: non-scaling-stroke; stroke: #fff; stroke-width: 4; }
  .hud-box path:first-child { stroke: var(--char); stroke-width: 8; }
  .hud-name { position: absolute; left: 0; bottom: calc(100% + 16px); padding: 6px 10px 5px; border: 2.5px solid var(--char); border-radius: 6px; background: var(--tag); color: var(--char);
    font-weight: 800; font-size: 1.0625rem; line-height: 1; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; }
  .hud-name::after { content: ''; position: absolute; left: 14px; top: 100%; width: 4px; height: 16px; margin-top: 2.5px; background: var(--char); }
  .hud-mark.is-right .hud-name { left: auto; right: 0; }
  .hud-mark.is-right .hud-name::after { left: auto; right: 14px; }
  .hud-mark.is-below .hud-name { bottom: auto; top: calc(100% + 16px); }
  .hud-mark.is-below .hud-name::after { top: auto; bottom: 100%; margin: 0 0 2.5px; }
  .hud-mark.is-side .hud-name { left: calc(100% + 14px); bottom: auto; top: 0; }
  .hud-mark.is-side .hud-name::after { left: auto; right: 100%; top: 50%; width: 11.5px; height: 4px; margin: -2px 2.5px 0 0; }

  /* Wide screens: the cards have the left lane, so the display starts to the right of it, as chips over the picture */
  @media (min-width: 901px) {
    html.js .scope-hud { --lane: calc(var(--m) + 452px); height: 96px; margin-bottom: -96px; background: none; border-top: 0; }
    .hud-id, .hud-ft { top: 18px; height: 34px; padding: 0 12px; border-radius: 6px; background: rgb(34 34 34 / .45); text-shadow: 0 1px 3px rgb(0 0 0 / .55); font-size: 1rem; }
    .hud-id { left: var(--lane); } .hud-ft { right: var(--m); }
    .hud-ft b { font-size: 1.5rem; }
    .hud-rail { left: calc(var(--lane) + 4px); right: max(calc(var(--m) + 4px), 60px); top: 70px; background: var(--char); }
    .hud-fill { inset: 2px; border-radius: 2px; }
    .hud-name { font-size: 1.25rem; padding: 8px 12px 7px; }
  }
  @media (min-width: 1200px) {   /* room on the rail to name the stations */
    html.js .scope-hud { height: 124px; margin-bottom: -124px; }
    .hud-tick span { display: block; position: absolute; top: 22px; left: 50%; transform: translateX(-50%); padding: 5px 7px 4px; border-radius: 5px; background: rgb(34 34 34 / .45); text-shadow: 0 1px 3px rgb(0 0 0 / .55);
      font-weight: 600; font-size: 0.875rem; line-height: 1; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
    .hud-fill + .hud-tick span { left: -4px; transform: none; }
  }
}
@keyframes hud-rec { 50% { opacity: 0.25; } }

/* The worm is redrawn ring by ring in scope.js; there is no rigid picture transform or CSS pulsing. */
.scope-worm { pointer-events: none; }

/* The scope identifier uses the same artwork as the opening. */
.hud-brand { width: 64px; height: auto; flex: none; }
@media (min-width: 761px) { .hud-brand { width: 76px; } }
