GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Solar and storage design / globalgrid2050 / solar-design-studio/202609271740-site-world/world

Solar Design Studio — Site World Page and 1 more file

A web page in GlobalGrid2050 that draws bill of quantities, cables, substations and postcodes. Published at https://globalgrid2050.com/solar-design-studio/202609271853-site-world/.

474 lines of HTML and JavaScript from globalgrid2050, in 2 files. Topic: Solar and storage design. Section 169 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Xray transform · globalgrid2050 / solar-design-studio/202609271740-site-world/world/xray.mjs lines 1–111
  2. Solar Design Studio — Site World Page render · globalgrid2050 / solar-design-studio/202609271853-site-world/index.html lines 1–363

Xray

A JavaScript module in the world folder of GlobalGrid2050 that works with cables.

transformglobalgrid2050 / solar-design-studio/202609271740-site-world/world/xray.mjs · lines 1–111 of 111 · version 2026-09-27 17:40

What it does
It calculates cables. Defines 10 functions or classes, including xrayFilter, len2, samples, buriedLines, push.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables.
Downstream impact
Used directly by 1 file: Xray UI (globalgrid2050). Reached from 2 other entry points, including Solar Design Studio — Site World Page (globalgrid2050, https://globalgrid2050.com/solar-design-studio/202609271853-site-world/); Substrate (globalgrid2050).
What it achieves
It is built from the xray filter helper (`xrayFilter`), the len2 step (`len2`) and the samples step (`samples`). The as-built X-ray view. Once a trench is backfilled nothing of it shows on the ground; this view draws the ground faint and see-through and the buried works bright.
Why it matters
Imported by Xray UI.
Application
globalgrid2050 · solar-design-studio/202609271740-site-world/world · JavaScript module
Uses
Trench Section (import), Spec Rules (import)
Used by
imported by Xray UI (dynamic import)
Produces
XRAY, xrayFilter, samples, buriedLines, xrayBatches, xraySummary
Defines here
xrayFilter, len2, samples, buriedLines, push, far, P, box, xrayBatches, xraySummary
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271740-site-world/world/xray.mjs:1-111 · blob 810bdbffec76577bd4352c3dd4e38239742711d4 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
// xray.mjs: the as-built X-ray view. Once a trench is backfilled nothing of it shows on the ground; this view draws the
// ground faint and see-through and the buried works bright: every trench's walls and floor, the ducts and cables at their
// true positions in the section, the warning tape and tiles, draw pits and joint bays, at their depth under the measured
// ground. Loaded the first time the X-ray is switched on (xray-ui.mjs); nothing here runs on the first frame.
//
// xrayFilter(batches, extra) is the frame filter: occluders (the hidden ground mesh that hides what is under a hill) are
// dropped so buried lines show, every other batch is drawn at a fraction of its alpha, and the X-ray batches go on top.
// buriedLines(runs, opts) builds those batches from trench runs in local metres. Pure: no DOM.

import { crossSection } from './trench-section.mjs';
import { applyGround, OPERATOR_SPEC } from './spec-rules.mjs';

export const XRAY = Object.freeze({
  dim: 0.3,          // everything above ground at 30 % of its alpha: the ground reads as a faint veil
  rangeM: 900,       // runs further than this from the viewer are left out
  stepM: 6,          // rails follow the ground at this spacing
  sliceEvery: 3,     // a cross-section slice every third step
  colour: Object.freeze({ trench: [0.95, 0.78, 0.4, 0.85], duct: [0.45, 0.85, 1, 1], cable: [1, 0.5, 0.3, 1],
    marker: [1, 0.95, 0.25, 0.9], pit: [0.95, 0.97, 1, 1], joint: [0.8, 0.6, 1, 1] })
});

/** The frame with the X-ray applied: no occluders, the rest dimmed, the X-ray batches added last. */
export function xrayFilter(batches, extra = [], dim = XRAY.dim) {
  const out = [];
  for (const b of batches) {
    if (b.occluder) continue;
    out.push(b.color ? { ...b, color: [b.color[0], b.color[1], b.color[2], (b.color[3] ?? 1) * dim] } : b);
  }
  return out.concat(extra);
}

const len2 = (a, b) => Math.hypot(b[0] - a[0], b[1] - a[1]);

// Points every `step` metres along a plan polyline (and at each corner), with the unit normal (left of travel).
export function samples(pts, step) {
  const out = [];
  for (let i = 1; i < pts.length; i++) {
    const a = pts[i - 1], b = pts[i], L = len2(a, b);
    if (!(L > 0)) continue;
    const nx = -(b[1] - a[1]) / L, ny = (b[0] - a[0]) / L, k = Math.max(1, Math.ceil(L / step));
    for (let j = out.length ? 1 : 0; j <= k; j++) out.push({ x: a[0] + (b[0] - a[0]) * j / k, y: a[1] + (b[1] - a[1]) * j / k, nx, ny });
  }
  return out;
}

/**
 * buriedLines(runs, { groundAt, eye, pits, joints, rangeM, stepM }) -> { trench, duct, cable, marker, pit, joint } Float32Arrays
 * runs: [{ path: [[x, y]...] local metres, section (trench-sections.json form), cableOdMm }]
 * pits / joints: [{ at: [x, y], l, w, depth }] local metres. Positions are relative to `base` ([x, y, z]).
 */
export function buriedLines(runs, { groundAt, eye = null, pits = [], joints = [], rangeM = XRAY.rangeM, stepM = XRAY.stepM,
  base = [0, 0, 0], spec = OPERATOR_SPEC } = {}) {
  const v = { trench: [], duct: [], cable: [], marker: [], pit: [], joint: [] };
  const push = (k, a, b) => v[k].push(a[0] - base[0], a[1] - base[1], a[2] - base[2], b[0] - base[0], b[1] - base[1], b[2] - base[2]);
  const far = pts => eye && pts.every(p => Math.hypot(p[0] - eye[0], p[1] - eye[1]) > rangeM);
  for (const r of runs) {
    if (!r.path || r.path.length < 2 || far(r.path)) continue;
    const eff = applyGround(r.section, spec, 'normal'), cs = crossSection(r.section, eff, { cableOdMm: r.cableOdMm || null });
    const S = samples(r.path, stepM).map(s => ({ ...s, g: groundAt(s.x, s.y) })).filter(s => Number.isFinite(s.g));
    const P = (s, [u, z]) => [s.x + s.nx * u, s.y + s.ny * u, s.g + z];
    const rails = [
      ['trench', [-cs.width / 2, -cs.depth]], ['trench', [cs.width / 2, -cs.depth]], ['trench', [-cs.topHalf, 0]], ['trench', [cs.topHalf, 0]],
      ...cs.items.map(it => [it.kind === 'duct' ? 'duct' : 'cable', [it.u, it.z]]),
      ...cs.markers.flatMap(m => [['marker', [m.u0, m.z]], ['marker', [m.u1, m.z]]])
    ];
    S.forEach((s, i) => {
      if (i) for (const [k, uz] of rails) push(k, P(S[i - 1], uz), P(s, uz));
      if (i % XRAY.sliceEvery === 0 || i === S.length - 1) {                       // a slice: walls, floor, ducts and cables
        for (let j = 1; j < cs.outline.length; j++) push('trench', P(s, cs.outline[j - 1]), P(s, cs.outline[j]));
        for (const m of cs.markers) push('marker', P(s, [m.u0, m.z]), P(s, [m.u1, m.z]));
        for (const it of cs.items) {
          const n = it.kind === 'duct' ? 10 : 6, k = it.kind === 'duct' ? 'duct' : 'cable';
          for (let q = 0; q < n; q++) {
            const t0 = 2 * Math.PI * q / n, t1 = 2 * Math.PI * (q + 1) / n;
            push(k, P(s, [it.u + it.r * Math.cos(t0), it.z + it.r * Math.sin(t0)]), P(s, [it.u + it.r * Math.cos(t1), it.z + it.r * Math.sin(t1)]));
          }
        }
      }
    });
  }
  const box = (k, [x, y], l, w, depth) => {
    const g = groundAt(x, y);
    if (!Number.isFinite(g) || (eye && Math.hypot(x - eye[0], y - eye[1]) > rangeM)) return;
    const c = [[-l / 2, -w / 2], [l / 2, -w / 2], [l / 2, w / 2], [-l / 2, w / 2]].map(([a, b]) => [x + a, y + b]);
    for (let i = 0; i < 4; i++) {
      const a = c[i], b = c[(i + 1) % 4];
      push(k, [...a, g], [...b, g]); push(k, [...a, g - depth], [...b, g - depth]); push(k, [...a, g], [...a, g - depth]);
    }
  };
  for (const p of pits) box('pit', p.at, p.l ?? 1.2, p.w ?? 0.9, p.depth ?? 1.0);
  for (const j of joints) box('joint', j.at, j.l ?? 4, j.w ?? 1.5, j.depth ?? 1.2);
  const out = {};
  for (const [k, a] of Object.entries(v)) out[k] = new Float32Array(a);
  return out;
}

/** Line batches for the renderer from buriedLines output. */
export function xrayBatches(lines, { base, version }) {
  return Object.entries(lines).filter(([, a]) => a.length).map(([k, a]) => ({ key: 'xray-' + k, version, positions: a, color: XRAY.colour[k], origin: base }));
}

/** Words for the readout: what the X-ray draws. */
export function xraySummary(runs, pits, joints, totals = null) {
  const m = runs.reduce((t, r) => t + r.path.slice(1).reduce((u, q, i) => u + len2(r.path[i], q), 0), 0);
  // totals: the block's own count (trench-plan.mjs), the same numbers as its readout; drawn Design trenches are added to it.
  const n = runs.length, drawn = totals ? n - totals.trenches : 0;
  const what = totals ? `${totals.trenches} trench${totals.trenches === 1 ? '' : 'es'} dug on the block (${Math.round(totals.dugM)} m)`
    + `${drawn > 0 ? ` and ${drawn} drawn in Design` : ''}` : `${n} buried trench run${n === 1 ? '' : 's'} (${Math.round(m)} m)`;
  return `X-ray on: ${what}, ${pits.length} draw pit${pits.length === 1 ? '' : 's'}, `
    + `${joints.length} joint bay${joints.length === 1 ? '' : 's'} shown under the ground. Ducts blue, cables orange, tape and tiles yellow.`;
}

Solar Design Studio — Site World Page

A web page in GlobalGrid2050 that draws bill of quantities, cables, substations and postcodes. Published at https://globalgrid2050.com/solar-design-studio/202609271853-site-world/.

renderglobalgrid2050 / solar-design-studio/202609271853-site-world/index.html · lines 1–363 of 363 · version 2026-09-27 18:53 · Entry point

What it does
It draws bill of quantities, cables, substations and postcodes. Side effects: changes the web page (DOM); makes network requests.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'design'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary. Domain terms in the code: cables, substations, postcodes.
Inputs & outputs
In: user-supplied file (file picker); form fields (user input). Out: CSV file bill-of-quantities.csv; downloaded file bill-of-quantities.csv; web page; SVG drawing. Coordinate systems named: OSGB36 / EPSG:27700 (British National Grid).
Downstream impact
It is itself an entry point, published at https://globalgrid2050.com/solar-design-studio/202609271853-site-world/.
What it achieves
Every module the first frame imports is fetched with the page, all at once, not one import level at a time; the manifest.
Why it matters
No other file in the estate was found to import it; it is an entry point.
Application
globalgrid2050 · solar-design-studio/202609271853-site-world · page
Uses
Substrate (modulepreload), Links (modulepreload), Bng (modulepreload), Origin (modulepreload), Camera (modulepreload), Views (modulepreload), Frame Gate (modulepreload), Device Budget (modulepreload), and 15 more
Used by
none found
Produces
none declared
Defines here
none
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 solar-design-studio/202609271853-site-world/index.html:1-363 · blob 43c86335e901381d30d0030d841f3f2a5a3183de · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<title>Site world</title>
<link rel="icon" href="data:,">
<!-- Every module the first frame imports is fetched with the page, all at once, not one import level at a time; the
     manifest, the lib's texts and the ground's two layers are asked for now too (layers.mjs takes each once and still
     checks its hash against the manifest). Review E; tests/first-frame.test.mjs keeps these lists true. -->
<link rel="modulepreload" href="world/substrate.mjs"><link rel="modulepreload" href="world/links.mjs"><link rel="modulepreload" href="world/bng.mjs">
<link rel="modulepreload" href="world/origin.mjs"><link rel="modulepreload" href="world/camera.mjs"><link rel="modulepreload" href="world/views.mjs">
<link rel="modulepreload" href="world/frame-gate.mjs"><link rel="modulepreload" href="world/device-budget.mjs"><link rel="modulepreload" href="world/lines.mjs">
<link rel="modulepreload" href="world/input.mjs"><link rel="modulepreload" href="world/layers.mjs"><link rel="modulepreload" href="world/arrival.mjs">
<link rel="modulepreload" href="world/attribution.mjs"><link rel="modulepreload" href="world/sites-ui.mjs"><link rel="modulepreload" href="world/layers-panel.mjs">
<link rel="modulepreload" href="world/wcs-terrain.mjs"><link rel="modulepreload" href="world/layers/terrain.mjs"><link rel="modulepreload" href="world/lift.mjs">
<link rel="modulepreload" href="world/fade.mjs"><link rel="modulepreload" href="world/lib/index.mjs"><link rel="modulepreload" href="world/lib/earthworks.mjs">
<link rel="modulepreload" href="world/lib/tiles.mjs"><link rel="modulepreload" href="world/lib/drape.mjs">
<script>window.__early = new Map(['manifest.json', 'lib/tiles.mjs', 'lib/drape.mjs', 'lib/earthworks.mjs', 'layers/terrain.mjs',
  'layers/ground-grid.mjs'].map(p => { const u = new URL('world/' + p, location.href).href;
  return [u, fetch(u, { cache: 'no-cache' }).catch(e => ({ ok: false, status: e.message }))]; }));</script>
<style>
  :root { --bg: #0a0a0a; --line: #9cdbff; --text: #cfe9ff; --dim: #6f8ea6; --panel: rgba(10, 10, 10, 0.86); --edge: #1c2c3a;
    --foot: 20px; --btn: 30px; }
  html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 12px/1.45 system-ui, sans-serif; overflow: hidden; }
  button, select { font: inherit; }
  #view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
  #where { position: fixed; left: 10px; bottom: calc(var(--foot) + 8px); color: var(--dim); pointer-events: none; }
  #help-toggle { position: fixed; right: 10px; bottom: calc(var(--foot) + 6px); min-height: 28px; border-radius: 4px; padding: 0 10px;
    background: var(--panel); color: var(--dim); border: 1px solid var(--edge); cursor: pointer; }
  #help-toggle[aria-expanded="true"] { color: var(--text); border-color: var(--line); }
  .panel { position: fixed; box-sizing: border-box; background: var(--panel); border: 1px solid var(--edge); border-radius: 6px;
    padding: 10px 12px; overflow: auto; }
  .panel[hidden] { display: none; }
  /* right: 76px leaves the drone lift buttons (56 px at right 10 px) clear of Controls */
  #help { right: 76px; bottom: calc(var(--foot) + 42px); width: min(380px, calc(100vw - 86px)); max-height: calc(100vh - var(--foot) - 110px); }
  #help dl, #design dl { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 3px 10px; margin: 0 0 8px; }
  #help dt, #design dt { color: var(--text); overflow-wrap: anywhere; } /* a long label wraps; the value keeps its column */
  #help dd, #design dd { margin: 0; color: var(--dim); min-width: 0; overflow-wrap: anywhere; }
  #help .fold > summary { cursor: pointer; color: var(--text); font-weight: 600; min-height: var(--btn); display: flex; align-items: center; }
  /* Wide screens: How to use and the controls side by side, so neither has to scroll. */
  @media (min-width: 900px) and (pointer: fine) { #help:not([hidden]) { width: min(640px, calc(100vw - 86px)); display: grid;
    grid-template-columns: 1fr 1fr; gap: 0 16px; align-items: start; } }
  #help h3 { margin: 8px 0 4px; font-size: 11px; font-weight: 600; color: var(--text); }
  #help p, #help ol, #help ul.basis { margin: 0 0 6px; } #help ol, #help ul.basis { padding-left: 18px; color: var(--dim); }
  #help b { color: var(--text); font-weight: 600; } #help dl.dash-help dt { min-width: 44px; }
  @media (pointer: coarse) { #help .mouse { display: none; } } @media (pointer: fine) { #help .touch { display: none; } }
  #help .credit { margin: 8px 0 0; padding: 0; list-style: none; color: var(--dim); font-size: 10px; }
  #help .credit a { color: var(--dim); }
  #layers .lp.in-help { position: static; width: auto; max-height: none; overflow: visible; background: none; border: 0;
    border-top: 1px solid var(--edge); border-radius: 0; padding: 8px 0 0; margin: 8px 0 0; }
  #layers .sun-time { border: 0; margin: 4px 0 0; padding: 0; display: grid; gap: 4px; }
  #layers .sun-time[hidden] { display: none; }
  #layers .sun-time legend { color: var(--dim); font-size: 11px; padding: 0; }
  #layers .sun-time label { display: grid; gap: 2px; color: var(--dim); }
  #layers .sun-time input { min-height: var(--btn); background: #111; color: var(--text); border: 1px solid var(--edge); border-radius: 4px; }
  #layers .sun-time .note { margin: 0; color: var(--dim); font-size: 11px; }
  #dash { position: fixed; top: 8px; right: 8px; display: flex; gap: 4px; }
  #dash button, #design button, #help button { background: var(--panel); color: var(--dim); border: 1px solid var(--edge); border-radius: 4px;
    padding: 5px 9px; cursor: pointer; min-height: var(--btn); }
  #dash button[aria-pressed="true"], #dash button[aria-expanded="true"], #design button[aria-pressed="true"],
    #help button[aria-pressed="true"] { color: #fff; border-color: var(--line); }
  #design button:disabled { opacity: 0.45; cursor: default; }
  #layers { top: calc(var(--btn) + 20px); right: 8px; width: min(360px, calc(100vw - 16px)); max-height: calc(100vh - 120px); }
  #layers .lp > h2 { display: none; } /* the panel header names it, beside the GridAtlas link */
  #layers .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 8px; }
  #layers h2 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--dim); text-transform: uppercase; }
  #layers button { background: var(--panel); color: var(--text); border: 1px solid var(--edge); border-radius: 4px;
    padding: 5px 9px; cursor: pointer; min-height: var(--btn); }
  #layers button[aria-pressed="true"] { color: #fff; border-color: var(--line); }
  #layers dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0 0 8px; }
  #layers dt { color: var(--text); white-space: nowrap; } #layers dd { margin: 0; color: var(--dim); overflow-wrap: anywhere; }
  #help .row { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 8px; }
  #headset-row:has(> #headset[hidden]) { display: none; } /* shown only where a headset session is supported */
  #design .note { margin: 0 0 8px; color: var(--dim); font-size: 11px; overflow-wrap: anywhere; }
  #design .note:empty { display: none; }
  #design input[type="text"] { box-sizing: border-box; width: 100%; background: #111; color: var(--text);
    border: 1px solid var(--edge); border-radius: 4px; min-height: var(--btn); margin: 0 0 8px; }
  #design input[type="text"][hidden] { display: none; }
  #design .fold { margin: 0 0 8px; }
  #design .fold > summary { cursor: pointer; color: var(--text); min-height: var(--btn); display: flex; align-items: center; }
  #design .phase-slider input { width: 100%; min-height: var(--btn); margin: 0; }
  #design .phase-slider-label { color: var(--text); font-size: 11px; margin: 0 0 4px; }
  #find .site-section { margin: 8px 0 0; }
  #find .site-select { display: grid; gap: 4px; color: var(--dim); font-size: 11px; }
  #find .site-select select { min-height: var(--btn); background: #111; color: var(--text); border: 1px solid var(--edge); border-radius: 4px; }
  #tour-caption { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--foot) + 44px); max-width: min(480px, 60vw);
    padding: 4px 10px; background: var(--panel); border: 1px solid var(--edge); border-radius: 4px; color: var(--text); pointer-events: none; }
  #tour-caption[hidden] { display: none; }
  #design { top: calc(var(--btn) + 20px); right: 8px; width: min(300px, calc(100vw - 16px)); max-height: calc(100vh - 120px); }
  #design .row { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 8px; }
  #design button:disabled { opacity: 0.45; cursor: default; }
  #design label { display: grid; gap: 2px; margin: 0 0 8px; color: var(--dim); }
  #design label[hidden], #design a[hidden] { display: none; }
  #design a.btn { display: inline-flex; align-items: center; min-height: var(--btn); padding: 0 9px; box-sizing: border-box;
    color: var(--text); border: 1px solid var(--edge); border-radius: 4px; text-decoration: none; }
  #design select { background: #111; color: var(--text); border: 1px solid var(--edge); border-radius: 4px; min-height: var(--btn); max-width: 100%; }
  #design-readout dd { color: var(--text); font-variant-numeric: tabular-nums; }
  #design-readout .warn, #spec-status.warn, #plant-status.warn, #block-status.warn { color: #ff8a7a; }
  #plant-readout dd, #block-readout dd { color: var(--text); font-variant-numeric: tabular-nums; }
  #block-readout dd.fault, .xray-box .note .fault { color: #ff6b5e; } #block-readout dd.tight, .xray-box .note .tight { color: #ffb27a; }
  #block-stage { color: var(--text); margin: 0 0 6px; }
  #design input[type=number] { background: #111; color: var(--text); border: 1px solid var(--edge); border-radius: 4px; min-height: var(--btn); }
  #spec-status { color: var(--dim); margin: 0; font-size: 12px; }
  #design figure { margin: 0 0 8px; } #design figure[hidden] { display: none; }
  #design svg { display: block; width: 100%; height: 90px; }
  #design svg polyline { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
  #design svg .ground { stroke: var(--line); } #design svg .floor { stroke: #ffc773; stroke-dasharray: 4 3; }
  #design svg text { fill: var(--dim); font-size: 12px; }
  #design figcaption { color: var(--dim); font-size: 10px; }
  #find.find-panel { top: calc(var(--btn) + 20px); right: 8px; }
  #lift { position: fixed; right: 10px; bottom: 50%; display: flex; flex-direction: column; gap: 6px; transform: translateY(50%); }
  #lift[hidden] { display: none; }
  #design:not([hidden]) ~ #lift { right: calc(min(300px, 100vw - 16px) + 18px); } /* Up/Down stay beside an open Design panel */
  #layers:not([hidden]) ~ #lift { right: calc(min(360px, 100vw - 16px) + 18px); } /* and beside an open Layers panel */
  #lift button { width: 56px; height: 44px; background: var(--panel); color: var(--text); border: 1px solid var(--edge);
    border-radius: 6px; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; }
  #lift button:active { border-color: var(--line); }
  #ground-feet { display: block; color: var(--text); opacity: 0.8; } #ground-feet[hidden] { display: none; }
  #ground-readout { border-top: 1px solid var(--edge); padding-top: 6px; margin: 0 0 8px; } #ground-readout[hidden] { display: none; }
  #ground-readout h3 { font-size: 12px; font-weight: 600; margin: 0 0 4px; }
  #ground-readout dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 0; }
  #ground-readout dt { color: var(--text); } #ground-readout dd { margin: 0; color: var(--dim); overflow-wrap: anywhere; }
  #ground-readout dd.warn { color: #ffb27a; } #ground-readout ul { margin: 2px 0 0; padding-left: 14px; }
  #ground-readout a { color: var(--line); }
  #help .lp { position: static; width: auto; max-height: none; overflow: visible; background: none; border: 0; border-top: 1px solid var(--edge);
    border-radius: 0; padding: 6px 0 0; margin: 0 0 8px; }
  #layer-details { margin: 0 0 8px; color: var(--dim); } #layer-details > summary { cursor: pointer; min-height: var(--btn); display: flex; align-items: center; }
  #where-detail { margin: 0 0 6px; color: var(--dim); font-variant-numeric: tabular-nums; }
  #design .hint { margin: 0 0 8px; color: var(--text); }
  #design[data-state="choose"] #design-draw, #design[data-state="choose"] #design-readout,
  #design[data-state="result"] #design-draw { display: none; }
  #design-options[hidden] { display: none; }
  /* Design sections as tabs (Build, Measure, Plant, Share): one short panel at a time, most of all on a phone. */
  #design .tabs { flex-wrap: nowrap; } #design .tabs button { flex: 1; min-width: 0; }
  #design .tabs button[aria-selected="true"] { color: var(--text); border-color: var(--line); }
  #design .dtab[hidden] { display: none; }
  /* Small cards over the world: the first step, and the place just found. Hidden while any panel is open. */
  /* Centred along the top, clear of the plan inset (top left) and the dash (top right). */
  .card { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); width: min(340px, calc(100vw - 16px)); box-sizing: border-box; display: flex;
    align-items: stretch; gap: 4px; background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; padding: 4px; }
  .card[hidden], body[data-panel] .card { display: none; }
  .card button { background: none; border: 0; color: var(--text); cursor: pointer; min-height: var(--btn); border-radius: 4px; }
  .card button:hover { background: rgba(156, 219, 255, 0.08); }
  #start-go { flex: 1; text-align: left; padding: 4px 8px; }
  .card .close { min-width: var(--btn); font-size: 16px; color: var(--dim); }
  #place > div { flex: 1; padding: 4px 8px; display: grid; gap: 2px; }
  #place-name { color: #fff; } #place-grid, #place-terrain { color: var(--dim); } #place-terrain:empty { display: none; }
  /* While Design is open, the joypad, Up and Down step aside so taps land on the ground or the panel. */
  body[data-panel="design"] #pad, body[data-panel="design"] #lift { display: none !important; }
  @media (max-width: 900px) and (pointer: fine) { .card { top: calc(var(--btn) + 20px); } }
  @media (pointer: fine) { body[data-panel="help"] #lift { display: none; } } /* keys still fly the drone */
  #status { color: var(--dim); font-size: 11px; overflow-wrap: anywhere; }
  #attribution { position: fixed; left: 0; right: 0; bottom: 0; height: var(--foot); box-sizing: border-box; padding: 3px 10px 4px;
    font-size: 10px; line-height: 13px; color: var(--dim); background: rgba(10, 10, 10, 0.72); pointer-events: none;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #attribution .short { display: none; }
  #pad { position: fixed; left: 24px; bottom: calc(var(--foot) + 36px); width: 120px; height: 120px; border-radius: 50%; touch-action: none;
    border: 1px solid var(--edge); background: rgba(156, 219, 255, 0.04); display: none; }
  #pad span { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%;
    border: 1px solid var(--line); background: rgba(156, 219, 255, 0.12); pointer-events: none; }
  @media (max-width: 900px) { #attribution .full { display: none; } #attribution .short { display: inline; } }
  /* Narrow screens: the credit may take two lines; everything above the footer moves up with --foot. */
  @media (max-width: 600px) { :root { --foot: max(33px, var(--foot-fit, 33px)); } #attribution { white-space: normal; height: auto; } }
  @media (pointer: fine) { #help dl.touch { display: none; } }
  /* Phones: every text box at 16 px or more, so focusing one never zooms the page (and it can be read). */
  @media (pointer: coarse), (max-width: 600px) { input, select, textarea { font-size: 16px !important; } }
  /* Touch screens: 44 px targets; panels open as a sheet under the dash so the joypad, Up and Down stay clear. */
  @media (pointer: coarse) {
    :root { --btn: 44px; }
    #pad { display: block; }
    #help dl.keys, #design dl.keys { display: none; }
    #where { bottom: auto; top: calc(var(--btn) + 16px); right: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #dash button { min-width: 48px; }
    #design button, #design a.btn, #help button, #layers button { min-width: 44px; }
    #help-toggle { min-height: 44px; min-width: 44px; bottom: calc(var(--foot) + 8px); }
    #lift, #design:not([hidden]) ~ #lift, #layers:not([hidden]) ~ #lift { right: 10px; bottom: calc(var(--foot) + 64px); transform: none; }
    #help, #design, #layers, #find.find-panel { top: calc(var(--btn) + 40px); left: 8px; right: 8px; bottom: auto; width: auto;
      max-height: calc(100vh - var(--btn) - 40px - var(--foot) - 180px); overflow: auto; }
    #find.find-panel input { height: 44px; }
    .card { top: calc(var(--btn) + 40px); left: 8px; transform: none; width: auto; right: 8px; max-width: 420px; }
    /* Design is a short sheet along the bottom: tools, one line of guidance, Undo / Done / Clear; results after Done. */
    /* the ground above stays clear to tap; a taller footer (--foot-fit) shortens the sheet, never lifts it */
    #design { top: auto; bottom: calc(var(--foot) + 4px); max-height: min(35vh, calc(35vh + 33px - var(--foot))); }
    /* While drawing, the sheet keeps the hint, the tool in use (tap it again to choose another), Options and Undo / Done / Clear. */
    #design[data-state="draw"] > :not(#design-hint):not(#design-draw):not(.dtab) { display: none; }
    #design[data-state="draw"] .dtab > :not([role="group"][aria-label$="tool"]):not(#design-options):not(#works-option-box) { display: none; }
    #design[data-state="draw"] [data-tool][aria-pressed="false"] { display: none; }
    #design[data-state="draw"] #design-readout, #design[data-state="draw"] #design-profile-box,
    #design[data-state="draw"] #design-keys, #design[data-state="choose"] #design-keys { display: none; }
    #design[data-state="result"] #design-keys { display: none; }
    #design-draw { flex-wrap: nowrap; } #design-draw button { flex: 1; }
    body[data-panel="design"] #help-toggle { display: none; }
    #help .credit a, #layers .credit a { display: flex; align-items: center; min-height: 40px; }
  }
</style>
</head>
<body>
<canvas id="view" tabindex="0" aria-label="Site world. Move with W and S or the move pad, turn with A and D; look by dragging."></canvas>
<div id="where" role="status"><span id="where-line"></span><span id="ground-feet" hidden></span></div>
<nav id="dash" aria-label="View">
  <button type="button" data-view="standing" aria-pressed="true">Walk</button>
  <button type="button" data-view="aerial" aria-pressed="false">Drone</button>
  <button type="button" id="find-toggle" aria-expanded="false" aria-controls="find">Find</button>
  <button type="button" id="design-toggle" aria-expanded="false" aria-controls="design">Design</button>
  <button type="button" id="layers-toggle" aria-expanded="false" aria-controls="layers">Layers</button>
</nav>
<section id="layers" class="panel" hidden aria-labelledby="layers-title">
  <header class="head"><h2 id="layers-title">Layers</h2>
    <button type="button" id="to-gridatlas" title="Open GridAtlas at this spot">Open in GridAtlas</button></header>
  <div id="layers-slot"></div>
</section>
<p id="tour-caption" role="status" hidden></p>
<section id="design" class="panel" hidden aria-label="Design" data-state="choose">
  <div class="row tabs" role="tablist" aria-label="Design sections">
    <button type="button" role="tab" id="design-tab-build-btn" data-tab="build" aria-selected="true" aria-controls="design-tab-build">Build</button>
    <button type="button" role="tab" id="design-tab-measure-btn" data-tab="measure" aria-selected="false" aria-controls="design-tab-measure" tabindex="-1">Measure</button>
    <button type="button" role="tab" id="design-tab-plant-btn" data-tab="plant" aria-selected="false" aria-controls="design-tab-plant" tabindex="-1">Plant</button>
    <button type="button" role="tab" id="design-tab-share-btn" data-tab="share" aria-selected="false" aria-controls="design-tab-share" tabindex="-1">Share</button>
  </div>
  <p id="design-hint" class="hint" role="status">Choose a design tool</p>
  <div class="dtab" role="tabpanel" id="design-tab-build" data-tab="build" aria-labelledby="design-tab-build-btn">
    <div class="row" role="group" aria-label="Design tool">
      <button type="button" data-tool="trench" aria-pressed="false">Trench</button>
      <button type="button" data-tool="cable" aria-pressed="false">Cable</button>
      <button type="button" id="design-options-toggle" aria-expanded="false" aria-controls="design-options">Options</button>
    </div>
    <div class="row" role="group" aria-label="Earthworks tool">
      <button type="button" data-tool="road" aria-pressed="false">Road</button>
      <button type="button" data-tool="pad" aria-pressed="false">Pad</button>
      <button type="button" data-tool="fence" aria-pressed="false">Fence</button>
      <button type="button" data-tool="piles" aria-pressed="false">Pile row</button>
      <button type="button" data-tool="hdd" aria-pressed="false">Drilled crossing</button>
    </div>
    <label id="works-option-box" hidden><span id="works-option-label">Option</span> <select id="works-option"></select></label>
    <div id="design-options" hidden>
      <label>Trench section <select id="trench-section"></select></label>
      <label>Cable (voltage and size) <select id="cable-type"></select></label>
    </div>
    <div class="row">
      <button type="button" id="design-to-substation" disabled
        title="Draws a straight first draft from the last point to the nearest substation">Route to nearest substation</button>
    </div>
    <details class="fold" id="phases-fold"><summary>Construction phases</summary>
      <div id="phases-box"></div>
      <p id="phases-check" class="note"></p>
    </details>
  </div>
  <div class="dtab" role="tabpanel" id="design-tab-measure" data-tab="measure" aria-labelledby="design-tab-measure-btn" hidden>
    <div class="row" role="group" aria-label="Schedules">
      <button type="button" id="design-drums">Drum schedule</button>
      <button type="button" id="design-boq">Bill of quantities</button>
      <a id="works-csv" class="btn" hidden download="bill-of-quantities.csv">Download CSV</a>
    </div>
    <figure id="design-profile-box" hidden>
      <svg id="design-profile" role="img" aria-label="Level profile along the route"></svg>
      <figcaption>Ground level (solid) and trench floor (dashed) along the route</figcaption>
    </figure>
  </div>
  <div class="dtab" role="tabpanel" id="design-tab-plant" data-tab="plant" aria-labelledby="design-tab-plant-btn" hidden>
    <div id="design-spec"></div>
    <div id="ground-readout" hidden aria-live="polite"></div>
  </div>
  <div class="dtab" role="tabpanel" id="design-tab-share" data-tab="share" aria-labelledby="design-tab-share-btn" hidden>
    <div class="row" role="group" aria-label="File">
      <button type="button" id="project-save" title="Download the design as a .json file">Save</button>
      <button type="button" id="project-open" title="Open a design or tour .json file">Open</button>
      <button type="button" id="project-share" title="Put the design in a link you can send">Share</button>
      <button type="button" id="project-print" title="Plan sheet with the current view">Print</button>
    </div>
    <input type="file" id="project-file" accept=".json,application/json" hidden>
    <input type="text" id="project-link" readonly hidden aria-label="Share link">
    <p id="project-note" class="note" aria-live="polite"></p>
    <details class="fold" id="tour-fold"><summary>Tour</summary>
      <div class="row">
        <button type="button" id="tour-record" aria-pressed="false">Record</button>
        <button type="button" id="tour-play" aria-pressed="false" disabled>Play</button>
        <button type="button" id="tour-save" disabled>Save tour</button>
      </div>
    </details>
  </div>
  <div class="row" id="design-draw">
    <button type="button" id="design-undo">Undo</button>
    <button type="button" id="design-finish">Done</button>
    <button type="button" id="design-clear">Clear</button>
  </div>
  <dl id="design-readout" aria-live="polite"></dl>
  <p id="design-disclaimer" class="note">Estimates for early design. Confirm with the network operator and a qualified engineer.</p>
  <dl id="design-keys"></dl>
</section>
<div id="start" class="card" hidden>
  <button type="button" id="start-go">Town, postcode or planning reference — e.g. Cirencester</button>
  <button type="button" id="start-close" class="close" aria-label="Dismiss">×</button>
</div>
<div id="place" class="card" hidden role="status">
  <div><strong id="place-name"></strong><span id="place-grid"></span><span id="place-terrain"></span></div>
  <button type="button" id="place-close" class="close" aria-label="Close">×</button>
</div>
<div id="lift" hidden>
  <button type="button" data-lift="1" aria-label="Fly up">Up</button>
  <button type="button" data-lift="-1" aria-label="Fly down">Down</button>
</div>
<div id="pad" aria-label="Move pad: drag up to go forward, sideways to turn"><span></span></div>
<button id="help-toggle" type="button" aria-expanded="false" aria-controls="help">Controls</button>
<section id="help" class="panel" hidden aria-label="Controls and how to use">
  <details class="fold" id="help-how"><summary>How to use</summary>
  <p id="help-what">Walk and fly real UK ground, then draw trenches and cable routes and read lengths, spoil and levels.</p>
  <ol class="steps">
    <li><b>Find</b> a town, postcode, OS grid reference (e.g. SP 01 09) or planning reference.</li>
    <li>Look at the grid on the ground: overhead lines, towers and substations.</li>
    <li><b>Design</b> a cable route: choose Cable, <span class="mouse">click</span><span class="touch">tap</span> points on the ground,
      then Finish.</li>
  </ol>
  <h3>Buttons</h3>
  <dl class="dash-help">
    <dt>Walk</dt><dd>stand on the ground at eye height (1.7 m)</dd>
    <dt>Drone</dt><dd>fly above the ground; <span class="mouse">Space up, Q down</span><span class="touch">hold Up or Down</span></dd>
    <dt>Find</dt><dd>go to a project, postcode, planning reference, OS grid reference or lat, lon</dd>
    <dt>Design</dt><dd>draw trenches, cables, roads, pads, fences, pile rows and drilled crossings; schedules and quantities</dd>
    <dt>Layers</dt><dd>what is loaded here and its state</dd>
    <dt>Type</dt><dd>command line: type a design command, e.g. <i>plant 50mw south</i>, <i>pitch 7</i>, <i>undo</i><span class="mouse"> (or press /)</span></dd>
  </dl>
  <h3>What the numbers rest on</h3>
  <ul class="basis">
    <li>Ground: <span id="help-ground">EA LIDAR Composite DTM 1 m, ±15 cm</span></li>
    <li>Levels: <span id="help-datum">metres above Ordnance Datum Newlyn</span></li>
    <li>Values not measured are marked <i>assumed</i> where they appear.</li>
    <li><b>Desktop study only:</b> not a survey or a design. Confirm on site before use.</li>
  </ul>
  </details>
  <div class="ctl">
  <h3>Moving</h3>
  <dl class="keys">
    <dt>W / S</dt><dd>forward and back (or up / down arrows)</dd>
    <dt>A / D</dt><dd>turn left and right (or left / right arrows)</dd>
    <dt>Drag</dt><dd>look around</dd>
    <dt>Shift</dt><dd>hold to move slowly and precisely</dd>
    <dt>F</dt><dd>drone on and off · Space up, Q down</dd>
    <dt>Space</dt><dd>in Walk, jump (hold for a little higher); lands on the ground or a solid top</dd>
    <dt>B</dt><dd>binoculars at 7× or 10× (wheel to step), with a rangefinder in the middle</dd>
  </dl>
  <dl class="touch">
    <dt>Move pad</dt><dd>drag up to go forward, sideways to turn</dd>
    <dt>Drag</dt><dd>anywhere else to look around</dd>
    <dt>Double tap</dt><dd>the centre of the move pad to jump</dd>
    <dt>Binoculars</dt><dd>in the row below; pinch to step between 7× and 10×</dd>
  </dl>
  <div class="row" id="help-links">
    <span id="headset-row"><button type="button" id="headset" aria-pressed="false" hidden>Headset view</button></span>
    <button type="button" id="raycast" aria-pressed="false" hidden
      title="Draws the measured ground solid, with sun shadows, on this device's graphics card (WebGL2). Off by default.">Solid ground (GPU)</button>
  </div>
  <details id="layer-details"><summary>Layer details</summary><p id="where-detail"></p><div id="status"></div></details>
  <ul id="credits" class="credit"><li>Terrain: Environment Agency LIDAR Composite DTM 1 m · © Environment Agency copyright and/or
    database right 2022. All rights reserved. · Open Government Licence v3.0</li></ul>
  </div>
</section>
<footer id="attribution"><span class="full" id="credit-full">Terrain: Environment Agency LIDAR Composite DTM 1 m ·
  © Environment Agency copyright and/or database right 2022. All rights reserved. · Open Government Licence v3.0</span><span
  class="short" id="credit-short">Terrain © Environment Agency 2022 · OGL v3.0</span></footer>
<script type="module" src="world/substrate.mjs"></script>
</body>
</html>