GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Kuiper, cosmos and drawing engines / cosmic / tools/explore/repokuiper

Repokuiper Galaxy and 2 more files

A JavaScript file in the explore folder of Cosmic that draws places, using SHA-256 and uses data from the kuiper-belt repository.

682 lines of JavaScript and CSS from cosmic, in 3 files. Topic: Kuiper, cosmos and drawing engines. Section 1129 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. Repokuiper Galaxy render · cosmic / tools/explore/repokuiper/repokuiper-galaxy.css lines 1–55
  2. Repokuiper Galaxy render · cosmic / tools/explore/repokuiper/repokuiper-galaxy.js lines 1–573
  3. Repokuiper Nav render · cosmic / tools/explore/repokuiper/repokuiper-nav.css lines 1–54

Repokuiper Galaxy

A style sheet in the explore folder of Cosmic.

rendercosmic / tools/explore/repokuiper/repokuiper-galaxy.css · lines 1–55 of 55 · Not reached from any entry point (candidate for review)

What it does
Side effects: changes the web page (DOM).
What it achieves
`repokuiper-galaxy.css` (K4, ACCRETION-52): estate galaxy panels: file card, breadcrumb inside a star, guided tour, repository card section.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/repokuiper · style sheet
Uses
none found
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
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/repokuiper/repokuiper-galaxy.css:1-55 · blob 44b98c841a2a7e8fd532de8585e60b5e04a08e9c · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: unknown · users: none · canonical: unreached_review
/* repokuiper-galaxy.css (K4, ACCRETION-52): estate galaxy panels: file card, breadcrumb inside a star, guided tour,
   repository card section. Scoped to #kp-gx-*, .gx-*. Palette: #000 #0b0e14 #2f343d #fff #a6adbb #66ccff #00ffff.
   390px first, 44px taps, no sideways scroll. */
#kp-gx-card,#kp-gx-tour,#kp-gx-path,#kp-gx-toast{position:fixed;box-sizing:border-box;overflow-wrap:anywhere}
#kp-gx-card[hidden],#kp-gx-tour[hidden],#kp-gx-path[hidden],#kp-gx-toast[hidden]{display:none}

/* file card: a bottom sheet on phones, a side panel on wide screens (like the core card) */
#kp-gx-card{left:0;right:0;bottom:0;top:auto!important;max-height:48vh;overflow-y:auto;overflow-x:hidden;z-index:22;background:#0b0e14;
  border-top:1px solid #00ffff;padding:10px 12px calc(12px + env(safe-area-inset-bottom));-webkit-overflow-scrolling:touch}
#kp-gx-card h2{margin:0 44px 4px 0;font-size:15px;color:#fff}
.gx-syn{color:#fff;margin:4px 0}
.gx-sub{color:#a6adbb;font-size:12px;margin:3px 0}
.gx-sub b{color:#fff;font-weight:normal}
.gx-key{color:#00ffff;font-size:12px;word-break:break-all;margin:6px 0}
.gx-chip{display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:5px;vertical-align:middle}
#kp-gx-card ul,.gx-repo ul{margin:4px 0;padding-left:18px;color:#a6adbb;font-size:12px}
#kp-gx-card li a,.gx-repo li a{display:inline-block;padding:4px 0;min-height:28px}
.gx-arcs .gx-key{margin:0 0 4px;font-size:11px;color:#a6adbb}
.gx-links{display:flex;flex-wrap:wrap;gap:4px 14px;margin-top:8px}
.gx-links a{display:inline-flex;align-items:center;min-height:44px;color:#66ccff}
.gx-places{margin:8px 0 2px;font-size:12px;color:#fff}
.gx-places a{display:inline-block;padding:6px 0;color:#66ccff}
.gx-x{position:absolute;right:6px;top:4px;width:44px;height:44px;font:inherit;font-size:18px;color:#fff;background:transparent;
  border:1px solid #2f343d;border-radius:3px;cursor:pointer}
.gx-x:hover,.gx-x:focus-visible{border-color:#00ffff;color:#00ffff;outline:none}

/* where you are inside a star */
#kp-gx-path{left:8px;right:64px;z-index:12;font-size:12px;color:#a6adbb;background:#000c;border:1px solid #2f343d;border-radius:3px;
  padding:0 8px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:520px}
#kp-gx-path a{color:#00ffff;text-decoration:none;display:inline-block;padding:10px 0;min-height:36px}

/* guided tour: a bottom sheet with large buttons */
#kp-gx-tour{left:8px;right:8px;bottom:calc(8px + env(safe-area-inset-bottom));top:auto!important;max-width:460px;z-index:24;background:#0b0e14;
  border:1px solid #00ffff;border-radius:4px;padding:10px 12px;max-height:56vh;overflow-y:auto;overflow-x:hidden}
#kp-gx-tour h2{margin:2px 0 4px;font-size:15px;color:#00ffff;font-weight:normal}
#kp-gx-tour p{margin:4px 0;color:#fff;font-size:13px;line-height:1.45}
.gx-tn{color:#a6adbb;font-size:11px}
.gx-tb{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px;align-items:center}
.gx-tb button,.gx-tb a{font:inherit;font-size:14px;color:#fff;background:#000;border:1px solid #2f343d;border-radius:3px;min-width:44px;
  min-height:44px;padding:0 12px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;text-decoration:none}
.gx-tb a{color:#66ccff;border-color:#66ccff55}
.gx-tb .gx-next{border-color:#00ffff;color:#00ffff;flex:1}
.gx-tb button:disabled{opacity:.4;cursor:default}
.gx-tb button:hover:not(:disabled),.gx-tb button:focus-visible{border-color:#00ffff;outline:none}
.gx-tb button[aria-label]{margin-left:auto}

#kp-gx-toast{left:50%;transform:translateX(-50%);bottom:72px;top:auto!important;z-index:30;background:#0b0e14;color:#fff;border:1px solid #66ccff;
  border-radius:3px;padding:8px 12px;font-size:12px;max-width:calc(100vw - 24px)}

@media (min-width:760px){
  #kp-gx-card{left:auto;right:12px;top:110px!important;bottom:12px;width:380px;max-height:none;border:1px solid #00ffff;border-radius:4px}
  #kp-gx-tour{left:12px;right:auto;bottom:16px;width:440px}
  #kp-gx-path{right:auto}
}
@media (prefers-reduced-motion:reduce){#kp-gx-card,#kp-gx-tour{scroll-behavior:auto}}

Repokuiper Galaxy

A JavaScript file in the explore folder of Cosmic that draws places, using SHA-256 and uses data from the kuiper-belt repository.

rendercosmic / tools/explore/repokuiper/repokuiper-galaxy.js · lines 1–573 of 573 · Not reached from any entry point (candidate for review) · pattern goFolder (shared by 2 files)

What it does
It draws places. Defines 38 functions or classes, including slugOf, groupOf, hideBtn, loadRepo, prep. Side effects: changes the web page (DOM); makes network requests.
Inputs & outputs
In: data source: kuiper-belt data; JSON file places.json; JSON file index.json.
What it achieves
It hides btn (`hideBtn`), loads repo (`loadRepo`) and loads places (`loadPlaces`). `repokuiper-galaxy.js` (K4, ACCRETION-52): the estate galaxy on `kuiper/index.html`, built on window.KUIPER (CONTRACT v1). every public repository is one star; groups of repositories that link to each other come from index.galaxy.json (`kuiper_galaxy.py`, same build cut) and, when `build.py` applies `cluster_index`. It responds to click events.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/repokuiper · script
Uses
Kuiper Belt — See Through Page (estate URL)
Used by
none found
Produces
slugOf, groupOf, hideBtn, loadRepo, prep, key2u, ready, folderPaths, filePath, loadPlaces, add, get
Defines here
slugOf, groupOf, hideBtn, loadRepo, prep, key2u, ready, folderPaths, filePath, loadPlaces, add, get, droneHref, stHref, placesHtml, repoPlacesHtml, pauseForInside, flyWorld, fitS, unitW, enterRepo, goFolder, goFile, leaveRepo, pass, drawLoading, drawInside, tweening, fileCard, list
Cannot conclude
Whether this code runs, is used by a live app today, or is correct. This is a static reading.
Evidence
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/repokuiper/repokuiper-galaxy.js:1-573 · blob 1912a5830a1b9cb367b18b34ad9aea5ac47ccd6a · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom, network · domain stage: unknown · users: none · canonical: unreached_review
// repokuiper-galaxy.js (K4, ACCRETION-52): the estate galaxy on kuiper/index.html, built on window.KUIPER (CONTRACT v1).
//  * every public repository is one star; groups of repositories that link to each other come from
//    index.galaxy.json (kuiper_galaxy.py, same build cut) and, when build.py applies cluster_index(), are the
//    index universe's folders, so the core places them by ordinal like any folder
//  * cross-repository links drawn as faint arcs (g), brighter for the selected star
//  * zoom into a star and it opens into its own folders and files: the repository's <slug>.json is fetched once
//    and drawn inside the star with the same placement law (positions computed from ordinals, never stored)
//  * a card for every file inside (key, blob, ordinal, uses/used by, links to its section page, its own Kuiper,
//    GitHub, and to Drone View / See Through where the file names a real place)
//  * a guided tour (w): 5-8 stops, a plain sentence and the key behind it at each
// On repository pages it does nothing.
(() => {
'use strict';
if (!window.KUIPER) return;
window.KUIPER.use('galaxy', function galaxy(K) {
  if (!K.isIndex) return;
  const D = K.D, A = K.arr, esc = K.esc, fmt = K.fmt, TAU = Math.PI * 2, R0 = 1000;
  const CI = 0.44, CS = 0.40, CR = 0.24, PHI = 0.6180339887498949;
  const PLACES_URL = '../pilot/places.json', DRONE = '../pilot/index.html', ST_INDEX = '../seethrough/index.json';
  const ST_LIVE = 'https://ventusltd.github.io/kuiper-belt/see-through/';
  const OPEN_PX = 70, PREFETCH_PX = 36, FIT = 0.92;   // a star opens once its radius passes OPEN_PX on screen
  const NB = D.files.length;
  const nameIx = new Map(); for (let i = 0; i < NB; i++) nameIx.set(D.files[i][0], i);
  const slugOf = (i) => String(D.files[i][14] || '').replace(/\.html$/, '');

  let G = null;                       // index.galaxy.json
  let pinned = false, tourSel = -1, flightUntil = 0;   // no auto-unpause while one of our flights is under way
  let showArcs = true, inner = null, pausedByMe = false, tourAt = -1, tourArc = null, active = -1, activeA = 0;
  const repoData = new Map();         // body index -> prepared interior (or a pending promise)
  let arcA = null, arcB = null, arcN = null, arcBin = null, arcMeta = [];
  let places = null, placesP = null;  // {byKey: Map 'repo/path' -> [{t,i,name}], byRepo: Map repo -> {drone: Map, st: Map}}
  let stops = [];

  // ------------------------------------------------------------------ data: galaxy file
  K.loadJSON('galaxy').then((g) => {
    if (!g || !Array.isArray(g.arcs)) { K.setButtonOn('gx-arcs', false); hideBtn('gx-arcs'); hideBtn('gx-tour'); return; }
    G = g;
    const n = g.arcs.length; arcA = new Int16Array(n); arcB = new Int16Array(n); arcN = new Int32Array(n); arcBin = new Uint8Array(n);
    let k = 0;
    for (const a of g.arcs) {
      const ia = nameIx.get(a[0]), ib = nameIx.get(a[1]);
      if (ia == null || ib == null) continue;
      arcA[k] = ia; arcB[k] = ib; arcN[k] = a[2] + a[3]; arcBin[k] = arcN[k] >= 100 ? 2 : arcN[k] >= 10 ? 1 : 0;
      arcMeta[k] = a; k++;
    }
    arcA = arcA.subarray(0, k); arcB = arcB.subarray(0, k);
    stops = (g.tour || []).slice();
    K.redraw();
    if (/^#gx=tour$/.test(location.hash)) startTour();
  });
  const groupOf = (name) => { if (!G) return null; for (const c of G.communities) if (c[2].includes(name)) return c; return null; };
  function hideBtn(id) { const b = document.getElementById('kb-' + id); if (b) b.hidden = true; }

  // ------------------------------------------------------------------ data: one repository's interior (lazy)
  function loadRepo(i) {
    if (repoData.has(i)) { const r = repoData.get(i); return r.then ? r : Promise.resolve(r); }
    const p = fetch(slugOf(i) + '.json').then((r) => { if (!r.ok) throw new Error(r.status); return r.json(); })
      .then((d) => { const r = prep(d); repoData.set(i, r); K.redraw(); return r; })
      .catch(() => { const r = { failed: true }; repoData.set(i, r); return r; });
    repoData.set(i, p);
    return p;
  }
  function prep(d) {
    const nf = d.folders.length, nb = d.files.length, [FI, FS] = d.band || [0.04, 0.34];
    const r = { d, nf, nb, fpar: new Int32Array(nf), fx: new Float64Array(nf), fy: new Float64Array(nf), fr: new Float64Array(nf),
      fdep: new Uint8Array(nf), fsub: new Int32Array(nf), fcol: new Int16Array(nf), fstart: new Int32Array(nf + 1), forder: new Int32Array(nb),
      kstart: new Int32Array(nf + 1), korder: new Int32Array(Math.max(1, nf - 1)),
      bx: new Float64Array(nb), by: new Float64Array(nb), brw: new Float64Array(nb), bfo: new Int32Array(nb), brole: new Int16Array(nb), breach: new Uint8Array(nb),
      // per-frame buffers (allocated once per repository, reused every frame)
      dI: new Int32Array(nb), dX: new Float32Array(nb), dY: new Float32Array(nb), dR: new Float32Array(nb), dn: 0,
      hF: new Int32Array(nf), hX: new Float32Array(nf), hY: new Float32Array(nf), hR: new Float32Array(nf), hn: 0,
      stack: new Int32Array(nf + 1), dots: new Float32Array(nf * 4), cols: (d.roles || []).map((x) => x[2] || '#4c5a65'), paths: null, bout: null, bin: null };
    const key2u = (k) => k / 4294967296, key2th = (k) => ((k * PHI) % 1) * TAU;
    r.fr[0] = R0;
    for (let f = 1; f < nf; f++) {   // the law at t = 0, as build.py layout() and repokuiper.js place(0)
      const [, p, k] = d.folders[f], th = key2th(k), dd = r.fr[p] * (CI + CS * Math.sqrt(key2u(k)));
      r.fpar[f] = p; r.fdep[f] = Math.min(255, r.fdep[p] + 1); r.fr[f] = r.fr[p] * CR;
      r.fx[f] = r.fx[p] + dd * Math.cos(th); r.fy[f] = r.fy[p] + dd * Math.sin(th);
    }
    r.fpar[0] = -1;
    const nfiles = new Int32Array(nf), nkids = new Int32Array(nf);
    for (let j = 0; j < nb; j++) {
      const f = d.files[j], fo = f[1], th = key2th(f[2]), dd = r.fr[fo] * (FI + FS * Math.sqrt(key2u(f[2])));
      r.bfo[j] = fo; nfiles[fo]++;
      r.bx[j] = r.fx[fo] + dd * Math.cos(th); r.by[j] = r.fy[fo] + dd * Math.sin(th);
      r.brw[j] = r.fr[fo] * 0.018 * Math.min(4, Math.max(0.45, Math.sqrt(Math.max(1, f[3])) / 8));
      r.brole[j] = f[4]; r.breach[j] = f[5] & 1;
    }
    for (let f = 1; f < nf; f++) nkids[r.fpar[f]]++;
    for (let f = 0; f < nf; f++) { r.fstart[f + 1] = r.fstart[f] + nfiles[f]; r.kstart[f + 1] = r.kstart[f] + nkids[f]; }
    const fp = r.fstart.slice(0, nf), kp = r.kstart.slice(0, nf);
    for (let j = 0; j < nb; j++) r.forder[fp[r.bfo[j]]++] = j;
    for (let f = 1; f < nf; f++) r.korder[kp[r.fpar[f]]++] = f;
    const tally = new Map();
    for (let j = 0; j < nb; j++) for (let f = r.bfo[j]; f >= 0; f = r.fpar[f]) {
      r.fsub[f]++; const key = f * 64 + (r.brole[j] & 63); tally.set(key, (tally.get(key) || 0) + 1);
    }
    const best = new Int32Array(nf);
    for (const [key, n] of tally) { const f = Math.floor(key / 64); if (n > best[f]) { best[f] = n; r.fcol[f] = key % 64; } }
    return r;
  }
  const ready = (i) => { const r = repoData.get(i); return r && !r.then && !r.failed ? r : null; };
  function folderPaths(r) {
    if (!r.paths) { r.paths = ['']; for (let f = 1; f < r.nf; f++) { const p = r.paths[r.fpar[f]]; r.paths.push(p ? p + '/' + r.d.folders[f][0] : r.d.folders[f][0]); } }
    return r.paths;
  }
  const filePath = (r, j) => { const p = folderPaths(r)[r.bfo[j]]; return (p ? p + '/' : '') + r.d.files[j][0]; };

  // ------------------------------------------------------------------ data: real places (Drone View, See Through)
  function loadPlaces() {
    if (placesP) return placesP;
    const byKey = new Map(), byRepo = new Map();
    const add = (repo, path, item) => {
      const k = repo + '/' + path; (byKey.get(k) || byKey.set(k, []).get(k)).push(item);
      const R = byRepo.get(repo) || byRepo.set(repo, { drone: new Map(), st: new Map() }).get(repo);
      const m = item.t === 'drone' ? R.drone : R.st, id = item.t === 'drone' ? item.i : item.name;
      const e = m.get(id) || m.set(id, { name: item.name, i: item.i, n: 0 }).get(id); e.n++;
    };
    const get = (u) => fetch(u).then((r) => (r.ok ? r.json() : null)).catch(() => null);
    let stBase = ST_LIVE, top = null;
    placesP = Promise.all([get(PLACES_URL), get(ST_INDEX)]).then(([pl, st]) => {
      const re = /^([^@\s]+)@\S+ (.+):\d+-\d+(?: \S+)?$/;
      for (const p of (pl && pl.places) || []) {
        let n = 0, k0 = '';
        for (const f of p.files || []) {
          const m = re.exec(f.key || ''); if (!m || !nameIx.has(m[1])) continue;
          add(m[1], m[2], { t: 'drone', i: p.i, name: p.name }); n++; if (!k0) k0 = f.key;
        }
        if (n && (!top || n > top.n)) top = { name: p.name, i: p.i, n, key: k0, lat: p.lat, lon: p.lon };
      }
      if (st && st.files) {
        if (st.base) stBase = st.base;
        for (const id in st.files) {
          const v = st.files[id], k = String(v.k || ''), s = k.indexOf('/'); if (s < 0 || !nameIx.has(k.slice(0, s))) continue;
          const seen = new Set();
          for (const m of v.m || []) if (!seen.has(m[0])) { seen.add(m[0]); add(k.slice(0, s), k.slice(s + 1), { t: 'st', name: m[0] }); }
        }
      }
      places = { byKey, byRepo, stBase, top };
      return places;
    });
    return placesP;
  }
  const droneHref = (i) => `${DRONE}#place=${i}`;
  const stHref = (name) => `${(places && places.stBase) || ST_LIVE}#sub=${encodeURIComponent(name)}&view=3d`;
  function placesHtml(items, label) {
    if (!items || !items.length) return '';
    const dr = [], st = [], sd = new Set(), ss = new Set();
    for (const it of items) {
      if (it.t === 'drone' && !sd.has(it.i)) { sd.add(it.i); dr.push(`<a href="${droneHref(it.i)}">${esc(it.name)}</a>`); }
      if (it.t === 'st' && !ss.has(it.name)) { ss.add(it.name); st.push(`<a href="${esc(stHref(it.name))}" rel="noopener">${esc(it.name)}</a>`); }
    }
    return `<div class="gx-places"><div class="gx-sub">${label}</div>`
      + (dr.length ? `<div>Drone View: ${dr.slice(0, 8).join(', ')}${dr.length > 8 ? ` (+${dr.length - 8})` : ''}</div>` : '')
      + (st.length ? `<div>See Through: ${st.slice(0, 8).join(', ')}${st.length > 8 ? ` (+${st.length - 8})` : ''}</div>` : '') + '</div>';
  }
  function repoPlacesHtml(name) {
    const R = places && places.byRepo.get(name); if (!R) return '';
    const items = [];
    for (const e of [...R.drone.values()].sort((a, b) => b.n - a.n)) items.push({ t: 'drone', i: e.i, name: e.name + ' (' + e.n + ')' });
    for (const e of [...R.st.values()].sort((a, b) => b.n - a.n)) items.push({ t: 'st', name: e.name });
    return placesHtml(items, 'Real places its files name (number of files):');
  }

  // ------------------------------------------------------------------ camera helpers (world = index universe)
  function pauseForInside(on) {
    if (on && !K.paused) { K.setPaused(true); pausedByMe = true; }
    else if (!on && pausedByMe && tourAt < 0 && performance.now() > flightUntil) { pausedByMe = false; if (K.paused) K.setPaused(false); }
  }
  function flyWorld(wx, wy, s, ms) {
    pinned = true; flightUntil = performance.now() + (ms == null ? 900 : ms + 200);
    pauseForInside(true);   // the onFrame check may have unpaused while the repo data loaded (K1 fix, race in enterRepo)
    if (!tour.hidden && K.W < 760) wy += (tour.offsetHeight / 2) / s;   // keep the target clear of the tour sheet
    K.flyTo(0, wx - A.fx[0], wy - A.fy[0], s, ms); K.redraw();
  }
  const fitS = (worldR, frac) => { const v = K.view(); return Math.min(v.w, v.h) * (frac || 0.46) / Math.max(1e-9, worldR); };
  const unitW = (i) => A.brw[i] * FIT / R0;               // world units per interior unit
  function enterRepo(i, f) {
    flightUntil = performance.now() + 15000;   // hold the pause while the repo data loads; flyWorld sets the real end
    pauseForInside(true);
    return loadRepo(i).then((r) => {
      if (r.failed) { toast(`${D.files[i][0]}: its Kuiper data did not load`); return null; }
      goFolder(i, f || 0); return r;
    });
  }
  function goFolder(i, f) {
    const r = ready(i); if (!r) return;
    const u = unitW(i);
    inner = { i, f };
    flyWorld(A.bx[i] + r.fx[f] * u, A.by[i] + r.fy[f] * u, fitS(r.fr[f] * u));
    showPath();
  }
  function goFile(i, j, noCard) {
    const r = ready(i); if (!r) return;
    const u = unitW(i), f = r.bfo[j];
    inner = { i, f };
    const s = fitS(r.fr[f] * u, 0.9), v = K.view();
    const narrow = K.W < 760, shift = noCard ? 0 : narrow ? (K.H * 0.22) / s : -(Math.min(380, K.W * 0.3) / 2) / s;   // clear of the card
    flyWorld(A.bx[i] + r.bx[j] * u + (narrow ? 0 : -shift), A.by[i] + r.by[j] * u + (narrow ? shift : 0), s);
    void v; if (noCard) { gxSel = { i, j }; closeFileCard(true); } else fileCard(i, j); showPath();
  }
  function leaveRepo() {
    const i = inner ? inner.i : active; inner = null; showPath();
    if (i >= 0) flyWorld(A.bx[i], A.by[i], fitS(A.brw[i] * 5));
    pauseForInside(false);
  }

  // motion we paused for an open star resumes once no star is open, no tour runs and our flight has landed
  K.onFrame((now) => { if (pausedByMe && active < 0 && tourAt < 0 && now > flightUntil) pauseForInside(false); });

  // ------------------------------------------------------------------ overlays
  K.addOverlay('gx-arcs', { z: 'under', draw(g) {
    if (!arcA || (!showArcs && K.sel < 0 && !tourArc && tourSel < 0)) return;
    const fade = 1 - activeA;
    if (fade <= 0.02) return;
    const W = K.W, H = K.H, AL = [0.07, 0.14, 0.26], LW = [0.7, 1.1, 1.7];
    const pass = (bin, hiOnly) => {
      g.beginPath(); let any = false;
      for (let k = 0; k < arcA.length; k++) {
        const a = arcA[k], b = arcB[k];
        const hs = K.sel >= 0 ? K.sel : tourSel;
        const hi = (hs >= 0 && (a === hs || b === hs)) || (tourArc && ((a === tourArc[0] && b === tourArc[1]) || (a === tourArc[1] && b === tourArc[0])));
        if (hiOnly ? !hi : (arcBin[k] !== bin || !showArcs)) continue;
        const p = K.toScreen(A.bx[a], A.by[a]), q = K.toScreen(A.bx[b], A.by[b]);
        const mnx = Math.min(p[0], q[0]), mxx = Math.max(p[0], q[0]), mny = Math.min(p[1], q[1]), mxy = Math.max(p[1], q[1]);
        if (mxx < -40 || mnx > W + 40 || mxy < -40 || mny > H + 40) continue;
        const cx = (p[0] + q[0]) / 2 - (q[1] - p[1]) * 0.2, cy = (p[1] + q[1]) / 2 + (q[0] - p[0]) * 0.2;
        g.moveTo(p[0], p[1]); g.quadraticCurveTo(cx, cy, q[0], q[1]); any = true;
      }
      if (any) g.stroke();
    };
    g.strokeStyle = '#66ccff';
    for (let bin = 0; bin < 3; bin++) { g.globalAlpha = AL[bin] * fade; g.lineWidth = LW[bin]; pass(bin, false); }
    g.globalAlpha = 0.85 * fade; g.lineWidth = 1.6; g.strokeStyle = '#00ffff'; pass(0, true);
    g.globalAlpha = 1; g.lineWidth = 1;
  } });
  K.addOverlay('gx-ring', { z: 'over', draw(g) {   // the tour's star on phones (no card there)
    if (tourSel < 0 || active === tourSel) return;
    const p = K.toScreen(A.bx[tourSel], A.by[tourSel]), r = Math.max(2, A.brw[tourSel] * K.cam.s);
    g.strokeStyle = '#fff'; g.lineWidth = 1.5; g.beginPath(); g.arc(p[0], p[1], r + 6, 0, TAU); g.stroke();
  } });

  // the star that is open: the biggest on screen past OPEN_PX; its interior is drawn over its disc
  K.addOverlay('gx-inside', { z: 'over', keep: true, draw(g) {
    const W = K.W, H = K.H, s = K.cam.s;
    let best = -1, bestR = 0;
    for (let i = 0; i < NB; i++) {
      const rs = A.brw[i] * s; if (rs < PREFETCH_PX) continue;
      const p = K.toScreen(A.bx[i], A.by[i]);
      if (p[0] + rs < 0 || p[0] - rs > W || p[1] + rs < 0 || p[1] - rs > H) continue;
      if (!repoData.has(i)) loadRepo(i);
      if (rs > bestR) { bestR = rs; best = i; }
    }
    const was = active;
    active = bestR >= OPEN_PX ? best : -1;
    activeA = active < 0 ? 0 : Math.min(1, (bestR - OPEN_PX) / 90);
    if (active !== was) {
      if (active >= 0) pauseForInside(true);
      else if (performance.now() > flightUntil) { if (inner) { inner = null; showPath(); } pauseForInside(false); }
      if (active >= 0 && (!inner || inner.i !== active) && performance.now() > flightUntil) { inner = { i: active, f: 0 }; showPath(); }
    }
    if (active < 0) return;
    const r = ready(active); if (!r) return drawLoading(g, active, bestR);
    drawInside(g, active, r, activeA);
  } });
  function drawLoading(g, i, rs) {
    const p = K.toScreen(A.bx[i], A.by[i]);
    g.globalAlpha = 0.8; g.strokeStyle = '#00ffff'; g.lineWidth = 1.5;
    const turn = K.reducedMotion ? 0.75 : (performance.now() / 600) % 1;   // reduced motion: a still arc
    g.beginPath(); g.arc(p[0], p[1], rs + 4, -Math.PI / 2, -Math.PI / 2 + turn * TAU); g.stroke();
    g.lineWidth = 1; g.globalAlpha = 1;
    if (!K.reducedMotion) K.redraw();   // keep the spinner turning until the data is in
  }
  function drawInside(g, i, r, a) {
    const W = K.W, H = K.H, u = unitW(i);
    const p0 = K.toScreen(A.bx[i], A.by[i]), px = K.toScreen(A.bx[i] + u, A.by[i]), py = K.toScreen(A.bx[i], A.by[i] + u);
    const ax = px[0] - p0[0], ay = px[1] - p0[1], bxv = py[0] - p0[0], byv = py[1] - p0[1];   // screen per interior unit
    const sc = Math.hypot(ax, ay), rs = R0 * sc / FIT, lod = Math.max(gxLod, K.lodPx || 7);
    const t0 = performance.now();
    const minDim = Math.min(W, H);
    g.globalAlpha = a; g.fillStyle = '#000'; g.beginPath(); g.arc(p0[0], p0[1], rs + 1, 0, TAU); g.fill();
    g.strokeStyle = '#2f343d'; g.beginPath(); g.arc(p0[0], p0[1], rs + 1, 0, TAU); g.stroke();
    // walk the folder tree; a folder smaller than lod on screen is one dot (level of detail)
    r.dn = 0; r.hn = 0;
    const st = r.stack; let top = 0; st[top++] = 0;
    let deep = 0, deepDep = -1;
    g.beginPath(); g.strokeStyle = '#a6adbb'; g.globalAlpha = 0.18 * a;
    const dots = r.dots; let dn = 0;
    while (top > 0) {
      const f = st[--top];
      const X = p0[0] + r.fx[f] * ax + r.fy[f] * bxv, Y = p0[1] + r.fx[f] * ay + r.fy[f] * byv, R = r.fr[f] * sc;
      if (X + R < 0 || X - R > W || Y + R < 0 || Y - R > H) continue;
      if (f > 0 && R < lod) {
        if (r.fsub[f]) { dots[dn] = X; dots[dn + 1] = Y; dots[dn + 2] = Math.max(1.2, Math.min(R * 0.5, 1 + Math.sqrt(r.fsub[f]) * 0.6)); dots[dn + 3] = r.fcol[f]; dn += 4; r.hF[r.hn] = f; r.hX[r.hn] = X; r.hY[r.hn] = Y; r.hR[r.hn] = -1; r.hn++; }
        continue;
      }
      if (f > 0) { g.moveTo(X + R, Y); g.arc(X, Y, R, 0, TAU); r.hF[r.hn] = f; r.hX[r.hn] = X; r.hY[r.hn] = Y; r.hR[r.hn] = R; r.hn++; }
      const cx = W / 2, cy = (K.safeTop + H) / 2;
      if (R > minDim * 0.3 && Math.hypot(X - cx, Y - cy) < R * 0.8 && r.fdep[f] > deepDep) { deep = f; deepDep = r.fdep[f]; }
      for (let q = r.fstart[f]; q < r.fstart[f + 1]; q++) {
        const j = r.forder[q], x = p0[0] + r.bx[j] * ax + r.by[j] * bxv, y = p0[1] + r.bx[j] * ay + r.by[j] * byv;
        const rr = Math.max(0.8, r.brw[j] * sc);
        if (x < -rr - 40 || x > W + rr + 40 || y < -rr - 40 || y > H + rr + 40) continue;
        r.dI[r.dn] = j; r.dX[r.dn] = x; r.dY[r.dn] = y; r.dR[r.dn] = rr; r.dn++;
      }
      for (let q = r.kstart[f]; q < r.kstart[f + 1]; q++) st[top++] = r.korder[q];
    }
    g.stroke();
    if (inner && inner.i === i && !pinned && !tweening() && deep !== inner.f) { inner.f = deep; showPath(); }
    // folder dots, then bodies, batched by role colour and reach
    for (let c = 0; c < r.cols.length; c++) {
      g.fillStyle = r.cols[c];
      g.globalAlpha = 0.75 * a; g.beginPath(); let any = false;
      for (let k = 0; k < dn; k += 4) if (dots[k + 3] === c) { g.moveTo(dots[k] + dots[k + 2], dots[k + 1]); g.arc(dots[k], dots[k + 1], dots[k + 2], 0, TAU); any = true; }
      if (any) g.fill();
      for (let reach = 1; reach >= 0; reach--) {
        g.globalAlpha = (reach ? 1 : 0.3) * a; g.beginPath(); any = false;
        for (let k = 0; k < r.dn; k++) {
          const j = r.dI[k]; if (r.brole[j] !== c || r.breach[j] !== reach) continue;
          const x = r.dX[k], y = r.dY[k], rr = r.dR[k];
          if (rr < 1.6) g.rect(x - rr, y - rr, 2 * rr, 2 * rr); else { g.moveTo(x + rr, y); g.arc(x, y, rr, 0, TAU); }
          any = true;
        }
        if (any) g.fill();
      }
    }
    // labels that never overlap: folders (largest first), then files (largest first)
    g.font = '11px ui-monospace,Menlo,monospace'; g.textAlign = 'left';
    const placed = [], fits = (b) => !placed.some((p) => b[0] < p[2] && b[2] > p[0] && b[1] < p[3] && b[3] > p[1]);
    const fl = []; for (let k = 0; k < r.hn; k++) if (r.hR[k] > 34) fl.push(k);
    fl.sort((x, y) => r.hR[y] - r.hR[x]);
    let n = 0;
    g.fillStyle = '#a6adbb';
    for (const k of fl) {
      if (n >= 40) break;
      const t = r.d.folders[r.hF[k]][0], w = g.measureText(t).width, x = r.hX[k] - w / 2, y = Math.max(K.safeTop + 12, r.hY[k] - r.hR[k] - 4);
      const b = [x - 2, y - 11, x + w + 2, y + 3]; if (!fits(b)) continue;
      placed.push(b); g.globalAlpha = 0.8 * a; g.fillText(t, x, y); n++;
    }
    const lab = []; for (let k = 0; k < r.dn; k++) if (r.dR[k] > 3.2) lab.push(k);
    lab.sort((x, y) => r.dR[y] - r.dR[x]);
    g.fillStyle = '#fff'; n = 0;
    for (const k of lab) {
      if (n >= 90) break;
      const j = r.dI[k], t = r.d.files[j][0], w = g.measureText(t).width, x = r.dX[k] + r.dR[k] + 4, y = r.dY[k] + 4;
      const b = [x - 2, y - 11, x + w + 2, y + 3]; if (!fits(b)) continue;
      placed.push(b); g.globalAlpha = (r.breach[j] ? 0.9 : 0.55) * a; g.fillText(t, x, y); n++;
    }
    if (gxSel && gxSel.i === i) {
      const j = gxSel.j, x = p0[0] + r.bx[j] * ax + r.by[j] * bxv, y = p0[1] + r.bx[j] * ay + r.by[j] * byv, rr = Math.max(0.8, r.brw[j] * sc);
      g.globalAlpha = a; g.strokeStyle = '#fff'; g.lineWidth = 1.5; g.beginPath(); g.arc(x, y, rr + 5, 0, TAU); g.stroke(); g.lineWidth = 1;
    }
    g.globalAlpha = 1;
    // own frame budget: the core draws a slow overlay only every other frame, so keep this one under ~3 ms
    const ms = performance.now() - t0; gxMs = gxMs ? gxMs * 0.85 + ms * 0.15 : ms;
    if (gxMs > 3 && gxLod < 24) gxLod = Math.min(24, gxLod * 1.15); else if (gxMs < 1.5 && gxLod > 7) gxLod = Math.max(7, gxLod / 1.1);
  }
  let gxLod = 7, gxMs = 0;
  let lastCam = '';
  const tweening = () => { const c = K.cam.x + ',' + K.cam.y + ',' + K.cam.s; const m = c !== lastCam; lastCam = c; return m; };

  // ------------------------------------------------------------------ taps inside an open star
  K.on('tap', (sx, sy) => {
    if (active < 0 || activeA < 0.5) return false;
    const r = ready(active); if (!r) return false;
    let best = -1, bd = 1e9;
    for (let k = 0; k < r.dn; k++) {
      const d = Math.hypot(r.dX[k] - sx, r.dY[k] - sy);
      if (d < Math.max(r.dR[k] + 6, 14) && d - r.dR[k] < bd) { bd = Math.max(0, d - r.dR[k]); best = r.dI[k]; }
    }
    if (best >= 0) { inner = { i: active, f: r.bfo[best] }; fileCard(active, best); showPath(); K.redraw(); return true; }
    let bf = -1, bdep = -1;
    for (let k = 0; k < r.hn; k++) {
      const f = r.hF[k], R = r.hR[k] < 0 ? 16 : r.hR[k];
      if (r.hR[k] >= 0 && r.hR[k] < 14) continue;
      if (Math.hypot(r.hX[k] - sx, r.hY[k] - sy) <= R && r.fdep[f] > bdep && f !== (inner && inner.f)) { bf = f; bdep = r.fdep[f]; }
    }
    if (bf >= 0) { closeFileCard(); goFolder(active, bf); return true; }
    const p = K.toScreen(A.bx[active], A.by[active]);
    if (Math.hypot(p[0] - sx, p[1] - sy) < A.brw[active] * K.cam.s) { closeFileCard(); return true; }   // empty space inside
    return false;
  });

  // ------------------------------------------------------------------ card: a file inside a star (own panel)
  const card = K.panel('gx-card'); card.classList.add('gx-card'); card.setAttribute('role', 'dialog'); card.setAttribute('aria-label', 'file card');
  let gxSel = null;
  function fileCard(i, j) {
    const r = ready(i); if (!r) return;
    K.closeCard(); gxSel = { i, j };
    const d = r.d, f = d.files[j], p = filePath(r, j), ro = (d.roles || [])[f[4]] || ['other', 'Other', '#4c5a65'];
    if (!r.bout) { r.bout = d.files.map(() => []); r.bin = d.files.map(() => []); for (const e of d.edges) { r.bout[e[0]].push(e[1]); r.bin[e[1]].push(e[0]); } }
    const gh = `${d.gh}/blob/${d.commit}/${p.split('/').map(encodeURIComponent).join('/')}`;
    const fl = [f[12], fmt(f[3]) + ' lines', (f[5] & 1) ? 'reachable' : 'unreached', (f[5] & 2) ? 'entry point' : '', (f[5] & 4) ? 'pure' : '',
      f[10] ? 'reached from ' + fmt(f[10]) + ' entries' : '', (f[11] || []).length ? f[11].length + ' functions' : ''].filter(Boolean).join(' &middot; ');
    const list = (arr, label) => arr.length ? `<div class="gx-sub">${label} (${arr.length}):</div><ul>${arr.slice(0, 10).map((k) => `<li><a href="#" data-gx-file="${k}">${esc(filePath(r, k))}</a></li>`).join('')}${arr.length > 10 ? '<li>&hellip;</li>' : ''}</ul>` : '';
    card.innerHTML = '<button class="gx-x" data-gx-close aria-label="close">&#215;</button>'
      + `<h2>${esc(f[7] || f[0])}</h2><div class="gx-sub"><span class="gx-chip" style="background:${esc(ro[2])}"></span>${esc(ro[1])} &middot; in <b>${esc(d.repo)}</b></div>`
      + (f[8] ? `<p class="gx-syn">${esc(f[8])}</p>` : '')
      + `<div class="gx-key">${esc(d.repo)}@${esc(d.commit.slice(0, 12))} ${esc(p)}:1-${f[3]}<br>blob ${f[9] ? esc(f[9]) : '<span class="gx-sub">not read: no clone holds this commit</span>'}<br>ordinal k = ${f[2]} (sha256(path)[:32 bits])</div>`
      + `<div class="gx-sub">${fl}</div>` + list(r.bout[j], 'uses') + list(r.bin[j], 'used by')
      + `<div id="gx-fpl"></div><div class="gx-links">${f[6] ? `<a href="${esc(D.base + f[6])}">section page</a>` : ''}`
      + `<a href="${esc(slugOf(i))}.html#file=${encodeURIComponent(p)}">its Kuiper &#8594;</a><a href="${esc(gh + '#L1-L' + f[3])}" rel="noopener">GitHub</a></div>`;
    card.hidden = false;
    loadPlaces().then(() => { const el = document.getElementById('gx-fpl'); if (el && gxSel && gxSel.i === i && gxSel.j === j) el.innerHTML = placesHtml(places.byKey.get(d.repo + '/' + p), 'This file names real places:'); });
    K.redraw();
  }
  function closeFileCard(keepSel) { if (!keepSel) gxSel = null; if (!card.hidden) card.hidden = true; K.redraw(); }
  K.on('select', () => closeFileCard());

  // ------------------------------------------------------------------ card section: a repository star
  K.addCardSection('galaxy', (i) => {
    const name = D.files[i][0], gr = groupOf(name);
    let h = '<div class="gx-repo">';
    h += `<div class="gx-links"><a href="#" data-gx-enter="${i}"><b>zoom inside &#8594;</b></a></div>`;
    if (gr) h += `<div class="gx-sub">group: <b>${esc(gr[0])}</b> (${gr[2].length} repositor${gr[2].length === 1 ? 'y' : 'ies'})</div>`;
    if (arcA) {
      const rows = [];
      for (let k = 0; k < arcA.length; k++) {
        const a = arcMeta[k]; if (a[0] !== name && a[1] !== name) continue;
        const other = a[0] === name ? a[1] : a[0], out = a[0] === name ? a[2] : a[3], inn = a[0] === name ? a[3] : a[2];
        const ex = (a[0] === name ? a[5] : a[6]) || (a[0] === name ? a[6] : a[5]);
        rows.push([out + inn, `<li><a href="#" data-sel="${nameIx.get(other)}">${esc(other)}</a> ${fmt(out)} out &middot; ${fmt(inn)} in<div class="gx-key">${esc(ex)}</div></li>`]);
      }
      rows.sort((x, y) => y[0] - x[0]);
      if (rows.length) h += `<div class="gx-sub">links with ${rows.length} other repositor${rows.length === 1 ? 'y' : 'ies'} (example edge as key):</div><ul class="gx-arcs">${rows.slice(0, 6).map((x) => x[1]).join('')}</ul>`;
      else h += '<div class="gx-sub">no resolved links to other repositories in this cut</div>';
    }
    h += `<div id="gx-rpl-${i}">${places ? repoPlacesHtml(name) : ''}</div></div>`;
    if (!places) loadPlaces().then(() => { const el = document.getElementById('gx-rpl-' + i); if (el) el.innerHTML = repoPlacesHtml(name); });
    return h;
  });

  // ------------------------------------------------------------------ breadcrumb inside a star
  const path = K.panel('gx-path'); path.classList.add('gx-path');
  let lastPath = '';
  function showPath() {
    let h = '';
    if (inner) {
      const r = ready(inner.i), parts = [];
      if (r) for (let f = inner.f; f > 0; f = r.fpar[f]) parts.unshift(f);
      h = `<a href="#" data-gx-out>galaxy</a> / <a href="#" data-gx-folder="0">${esc(D.files[inner.i][0])}</a>`
        + parts.map((f) => ` / <a href="#" data-gx-folder="${f}">${esc(r.d.folders[f][0])}</a>`).join('');
    }
    if (h === lastPath) return;
    lastPath = h; path.innerHTML = h; path.hidden = !h;
  }

  // ------------------------------------------------------------------ guided tour
  const tour = K.panel('gx-tour'); tour.classList.add('gx-tour'); tour.setAttribute('role', 'dialog'); tour.setAttribute('aria-label', 'guided tour');
  function startTour() {
    if (!stops.length) return;
    loadPlaces().then((pl) => {
      const t = pl && pl.top;
      if (t && !stops.some((s) => s.kind === 'place')) {
        const m = /^([^@\s]+)@\S+ (.+):\d+-\d+(?: \S+)?$/.exec(t.key);
        const at = Math.max(0, stops.length - 1);
        if (m) stops.splice(at, 0, { kind: 'place', target: [m[1], m[2]], place: t.i, title: 'Code that names real places',
          text: `Some files write down real coordinates. ${t.name} is named in ${t.n} file${t.n === 1 ? '' : 's'}; Drone View flies you over it.`,
          key: t.key });
        if (stops.length > 8) stops.splice(stops.length - 2, 1);
        if (tourAt >= 0) renderTour();
      }
    });
    K.setButtonOn('gx-tour', true); tourAt = 0; pauseForInside(true); go(stops[0]); renderTour();
  }
  function stopTour() { tourAt = -1; tourArc = null; tourSel = -1; tour.hidden = true; K.setButtonOn('gx-tour', false); if (active < 0) pauseForInside(false); K.redraw(); }
  function step(dlt) { if (tourAt < 0) return; tourAt = Math.max(0, Math.min(stops.length - 1, tourAt + dlt)); go(stops[tourAt]); renderTour(); }
  function renderTour() {
    const s = stops[tourAt]; if (!s) return;
    let extra = '';
    if (s.kind === 'place') extra = `<a href="${droneHref(s.place)}">open Drone View &#8594;</a>`;
    tour.innerHTML = `<div class="gx-tn">stop ${tourAt + 1} of ${stops.length}</div><h2>${esc(s.title)}</h2><p>${esc(s.text)}</p>`
      + `<div class="gx-key">key: ${esc(s.key)}</div><div class="gx-tb">`
      + `<button data-gx-t="-1" ${tourAt === 0 ? 'disabled' : ''}>&#8592; back</button>`
      + (tourAt < stops.length - 1 ? '<button data-gx-t="1" class="gx-next">next &#8594;</button>' : '<button data-gx-t="end" class="gx-next">finish</button>')
      + `${extra}<button data-gx-t="end" aria-label="close tour">&#215;</button></div>`;
    tour.hidden = false;
    const nx = tour.querySelector('.gx-next'); if (nx && document.activeElement && tour.contains(document.activeElement) === false) { /* keep focus where it is */ }
  }
  function go(s) {
    tourArc = null; tourSel = -1; closeFileCard();
    const narrow = K.W < 760;
    const ix = typeof s.target === 'string' ? nameIx.get(s.target) : null;
    switch (s.kind) {
      case 'galaxy': case 'end': inner = null; showPath(); pauseForInside(false); K.closeCard(); K.home(); break;
      case 'cluster': {
        inner = null; showPath(); pauseForInside(false); K.closeCard();
        const f = D.folders.findIndex((x, k) => k > 0 && x[0] === s.target);
        if (f > 0) K.travel(f);
        else { const gr = groupOf(s.target); if (gr && gr[1] && nameIx.has(gr[1])) { const h = nameIx.get(gr[1]); flyWorld(A.bx[h], A.by[h], fitS(A.brw[h] * 12)); } }
        break;
      }
      case 'repo':
        if (ix == null) break;
        inner = null; showPath(); pauseForInside(false);
        if (narrow) { K.closeCard(); tourSel = ix; } else K.select(ix);
        flyWorld(A.bx[ix], A.by[ix], fitS(A.brw[ix] * 3, 0.4)); break;
      case 'arc': {
        const a = nameIx.get(s.target[0]), b = nameIx.get(s.target[1]); if (a == null || b == null) break;
        inner = null; showPath(); pauseForInside(false); K.closeCard();
        tourArc = [a, b];
        const dx = A.bx[b] - A.bx[a], dy = A.by[b] - A.by[a];
        flyWorld((A.bx[a] + A.bx[b]) / 2 - dy * 0.1, (A.by[a] + A.by[b]) / 2 + dx * 0.1, fitS(Math.hypot(dx, dy) * 0.62 + A.brw[a] + A.brw[b], 0.46));
        break;
      }
      case 'file': case 'place': {
        const i = nameIx.get(s.target[0]); if (i == null) break;
        K.closeCard(); pauseForInside(true);
        loadRepo(i).then((r) => {
          if (r.failed || tourAt < 0) return;
          const j = r.d.files.findIndex((f, k) => filePath(r, k) === s.target[1]);
          if (j >= 0) goFile(i, j, narrow); else goFolder(i, 0);
        });
        break;
      }
    }
    K.redraw();
  }

  // ------------------------------------------------------------------ toolbar, keys, clicks
  K.addButton({ id: 'gx-tour', label: 'tour', title: 'guided tour of the estate (w)', toggle: true, onClick: (on) => (on ? startTour() : stopTour()) });
  K.addButton({ id: 'gx-arcs', label: 'arcs', title: 'links between repositories as faint arcs (g)', toggle: true, onClick: (on) => { showArcs = on; K.redraw(); } });
  K.setButtonOn('gx-arcs', showArcs);
  K.addKey('w', () => { if (tourAt >= 0) stopTour(); else startTour(); return true; });
  K.addKey('g', () => { showArcs = !showArcs; K.setButtonOn('gx-arcs', showArcs); K.redraw(); return true; });
  K.addKey('n', () => { if (tourAt < 0) return false; step(1); return true; });
  K.addKey('b', () => { if (tourAt < 0) return false; step(-1); return true; });
  K.addKey('Escape', () => {
    if (!card.hidden) { closeFileCard(); return true; }
    if (tourAt >= 0) { stopTour(); return true; }
    return false;
  });
  K.addKey('Backspace', (ev) => {
    if (!inner && active < 0) return false;
    if (ev && ev.preventDefault) ev.preventDefault();
    if (!card.hidden) closeFileCard();
    const r = inner && ready(inner.i);
    if (inner && r && inner.f > 0) goFolder(inner.i, r.fpar[inner.f]);
    else leaveRepo();
    return true;
  });
  document.addEventListener('click', (e) => {
    const el = e.target.closest('[data-gx-enter],[data-gx-file],[data-gx-folder],[data-gx-out],[data-gx-close],[data-gx-t]');
    if (!el) return;
    e.preventDefault();
    if (el.dataset.gxEnter != null) { const i = +el.dataset.gxEnter; K.closeCard(); enterRepo(i, 0); }
    else if (el.dataset.gxFile != null && gxSel) { const i = gxSel.i; goFile(i, +el.dataset.gxFile); }
    else if (el.dataset.gxFolder != null && inner) { closeFileCard(); goFolder(inner.i, +el.dataset.gxFolder); }
    else if (el.hasAttribute('data-gx-out')) { closeFileCard(); leaveRepo(); K.home(); }
    else if (el.hasAttribute('data-gx-close')) closeFileCard();
    else if (el.dataset.gxT != null) { const v = el.dataset.gxT; if (v === 'end') stopTour(); else step(+v); }
  });

  // ------------------------------------------------------------------ small things
  const sky = document.getElementById('sky');   // the user's own pan/zoom: the breadcrumb follows the view again
  if (sky) for (const ev of ['pointerdown', 'wheel']) sky.addEventListener(ev, () => { pinned = false; }, { passive: true });
  let toastT = 0;
  function toast(msg) { const t = K.panel('gx-toast'); t.classList.add('gx-toast'); t.textContent = msg; t.hidden = false; clearTimeout(toastT); toastT = setTimeout(() => { t.hidden = true; }, 3500); }
  const m = /^#gx=([^&]+)$/.exec(location.hash);
  if (m && m[1] !== 'tour') { const i = nameIx.get(decodeURIComponent(m[1])); if (i != null) { K.select(i); enterRepo(i, 0); } }

  // self-test surface (read by test_repokuiper_galaxy.py's Playwright check)
  window.__gx = {
    get G() { return G; }, get active() { return active; }, get inner() { return inner && { i: inner.i, f: inner.f }; },
    get tourAt() { return tourAt; }, get sel() { return gxSel && { i: gxSel.i, j: gxSel.j }; }, get stops() { return stops.length; }, get arcs() { return arcA ? arcA.length : 0; },
    loaded: (i) => !!ready(i), enterRepo, goFolder, goFile, startTour, stopTour, step, loadPlaces,
    drawn: () => { const r = active >= 0 && ready(active); return r ? { files: r.dn, folders: r.hn } : null; },
    drawnFiles: (n) => { const r = active >= 0 && ready(active), o = []; if (r) for (let k = 0; k < r.dn && o.length < (n || 20); k++) o.push([r.dI[k], r.dX[k], r.dY[k], r.dR[k]]); return o; },
    layout0(i) { const r = ready(i); if (!r) return null; const f = [], b = []; for (let k = 0; k < r.nf; k++) f.push([r.fx[k], r.fy[k], r.fr[k]]); for (let k = 0; k < r.nb; k++) b.push([r.bx[k], r.by[k]]); return { folders: f, files: b }; },
    screenOfFile(i, j) { const r = ready(i); if (!r) return null; const u = unitW(i); return K.toScreen(A.bx[i] + r.bx[j] * u, A.by[i] + r.by[j] * u); },
  };
});
})();

Repokuiper Nav

A style sheet in the explore folder of Cosmic.

rendercosmic / tools/explore/repokuiper/repokuiper-nav.css · lines 1–54 of 54 · Not reached from any entry point (candidate for review)

What it does
Side effects: changes the web page (DOM).
Why it exists in the grid workflow
Domain stage field_execution (path word 'nav'): on-road and off-road field navigation to the farm gate (access gates, terrain slope, ground-bearing limits, electrical hazards), as Ventus Ltd describes its SatNav work.
What it achieves
`repokuiper-nav.css` (K2, WAYFINDER-38): search/browse panel, trail, onboarding hint, toast, phone zoom pad.
Why it matters
No other file in the estate was found to import it.
Application
cosmic · tools/explore/repokuiper · style sheet
Uses
none found
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
cosmic@51bebf892d63a617408bc5e25b270b9f893e9c03 tools/explore/repokuiper/repokuiper-nav.css:1-54 · blob efe5cd42c8122a7de653bd4e81940ade44303e05 · GitHub at these lines
State
achieves: comment · context: readme_derived · stage: output · effects: dom · domain stage: field_execution · users: EPC_contractor, landowner_planner · canonical: unreached_review
/* repokuiper-nav.css (K2, WAYFINDER-38): search/browse panel, trail, onboarding hint, toast, phone zoom pad.
   Scoped to #kp-nav-*, .nav-*. Palette: #000 #0b0e14 #2f343d #fff #a6adbb #66ccff #00ffff. 390px first, 44px taps. */
#kp-nav-search,#kp-nav-trail{left:8px;right:8px;bottom:8px;max-width:520px;max-height:none;display:flex;flex-direction:column;
  background:#0b0e14;border:1px solid #00ffff;border-radius:4px;padding:8px;z-index:20;overflow:hidden}
#kp-nav-trail{bottom:auto;max-height:70vh;max-height:70dvh}
#kp-nav-search[hidden],#kp-nav-trail[hidden],#kp-nav-hint[hidden],.nav-toast[hidden]{display:none}
.nav-row{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0}
.nav-q{flex:1;min-width:0;font:inherit;font-size:16px;background:#000;color:#fff;border:1px solid #66ccff;border-radius:3px;
  padding:8px;min-height:44px}
.nav-q:focus{outline:2px solid #00ffff;outline-offset:1px}
.nav-btn{font:inherit;font-size:14px;color:#fff;background:#000;border:1px solid #2f343d;border-radius:3px;min-width:44px;
  min-height:44px;padding:0 10px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center}
.nav-btn:hover,.nav-btn:focus-visible{border-color:#00ffff;color:#00ffff;outline:none}
.nav-wide{flex:1}
.nav-title{color:#00ffff;font-weight:normal}
.nav-crumbs{color:#a6adbb;font-size:12px;margin:6px 2px 0;word-break:break-word}
.nav-crumbs a{color:#00ffff;text-decoration:none;display:inline-block;padding:6px 0}
.nav-crumbs .nav-go{color:#66ccff;margin-left:6px}
.nav-list{list-style:none;margin:6px 0 0;padding:0;overflow-y:auto;overflow-x:hidden;flex:1;-webkit-overflow-scrolling:touch}
.nav-list li{display:flex;flex-wrap:wrap;align-items:baseline;gap:0 8px;min-height:44px;padding:6px 4px;border-bottom:1px solid #2f343d;
  cursor:pointer;color:#fff}
.nav-list li.on,.nav-list li:hover{background:#2f343d}
.nav-list li.on .nav-main{color:#00ffff}
.nav-list .nav-empty{color:#a6adbb;cursor:default}
.nav-dot{width:9px;height:9px;border-radius:50%;flex:none;align-self:center;background:#a6adbb}
.nav-ring{background:transparent!important;border:1px solid #a6adbb}
.nav-main{min-width:0;overflow-wrap:anywhere}
.nav-main em{color:#a6adbb;font-style:normal;font-size:11px}
.nav-sub{color:#a6adbb;font-size:11px;min-width:0;overflow-wrap:anywhere;flex-basis:100%;padding-left:17px}
.nav-row .nav-sub{flex-basis:auto;padding-left:0;flex:1}
#kp-nav-hint{left:8px;right:8px;bottom:calc(12px + env(safe-area-inset-bottom));top:auto;max-width:440px;z-index:15;
  background:#0b0e14;border:1px solid #66ccff;border-radius:4px;padding:10px 12px;color:#fff}
#kp-nav-hint p{margin:0 0 8px}
#kp-nav-hint b{color:#00ffff;font-weight:normal}
#kp-nav-hint .nav-sub{padding-left:0}
.nav-toast{position:fixed;left:50%;transform:translateX(-50%);bottom:calc(16px + env(safe-area-inset-bottom));max-width:calc(100vw - 32px);
  background:#0b0e14;border:1px solid #00ffff;color:#fff;border-radius:4px;padding:10px 12px;z-index:30;font-size:12px;
  overflow-wrap:anywhere;pointer-events:none}
.nav-pad{position:fixed;right:8px;top:120px;display:flex;flex-direction:column;gap:6px;z-index:5}
.nav-pad .nav-btn{background:#000c;font-size:20px;line-height:1}
.nav-card{margin-top:8px;border-top:1px solid #2f343d;padding-top:6px}
.nav-card .nav-sub{padding-left:0}
.nav-card a{color:#66ccff;text-decoration:none}
.nav-card .nav-sub a{color:#00ffff}
.nav-links{display:flex;flex-wrap:wrap;gap:4px 14px}
.nav-links a,.nav-card>a{display:inline-flex;align-items:center;min-height:44px}
/* tablet/laptop: keep the panels off the right-hand card; fine pointers get no zoom pad (wheel and keys do it) */
@media (min-width:760px){
  #kp-nav-search,#kp-nav-trail{right:auto;width:440px;bottom:12px}
  .nav-pad.nav-pad-card{right:404px}
  .nav-sub{font-size:12px}
}
@media (hover:hover) and (pointer:fine){.nav-pad{display:none}}
@media (prefers-reduced-motion:reduce){.nav-list li.on{scroll-behavior:auto}}