{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "grid",
  "title": "Grid",
  "description": "A district map with filters and waypoints, plus an atlas and globe of the Atlantic relay network.",
  "dependencies": [
    "lucide-react@1.73.0"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/cyber.json",
    "https://www.cyberspec.dev/r/badge.json",
    "https://www.cyberspec.dev/r/button.json",
    "https://www.cyberspec.dev/r/button-group.json",
    "https://www.cyberspec.dev/r/collapsible.json",
    "https://www.cyberspec.dev/r/map.json",
    "https://www.cyberspec.dev/r/map-demo.json",
    "https://www.cyberspec.dev/r/micro.json",
    "https://www.cyberspec.dev/r/panel.json",
    "https://www.cyberspec.dev/r/readout.json",
    "https://www.cyberspec.dev/r/reticle.json",
    "https://www.cyberspec.dev/r/screen.json",
    "https://www.cyberspec.dev/r/segmented-control.json",
    "https://www.cyberspec.dev/r/toaster.json",
    "https://www.cyberspec.dev/r/toggle-group.json",
    "https://www.cyberspec.dev/r/tooltip.json"
  ],
  "files": [
    {
      "path": "registry/cyber/blocks/grid/city.ts",
      "content": "// The district, generated. Two quarters of streets, each on its own slightly\n// turned grid, meet across a canal; a rail line cuts over both. Everything\n// comes from one seeded generator, so the map is the same on every load, and\n// the streets are a real graph: markers stand on its crossings, and a route\n// is the shortest walk along it.\n\nexport const W = 1200\nexport const H = 700\n\nexport type Kind = \"job\" | \"vendor\" | \"safehouse\" | \"contact\"\nexport type Point = readonly [number, number]\n\nexport type Marker = {\n  id: string\n  kind: Kind\n  name: string\n  text: string\n  /** One more fact, as a label and what it reads. */\n  fact: readonly [string, string]\n  x: number\n  y: number\n  district: string\n  sector: string\n  /** Walking distance from the player, along the streets. */\n  metres: number\n  /** The walk itself, from the player to the marker. */\n  route: Point[]\n}\n\ntype Node = { x: number; y: number; quarter: number; inside: boolean; links: number[] }\n\n// mulberry32: small, fast, and the same everywhere.\nfunction seeded(seed: number) {\n  let state = seed\n  return () => {\n    state = (state + 0x6d2b79f5) | 0\n    let t = Math.imul(state ^ (state >>> 15), 1 | state)\n    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t\n    return ((t ^ (t >>> 14)) >>> 0) / 4294967296\n  }\n}\n\nconst n = (value: number) => (Math.round(value * 10) / 10).toString()\n\n// The canal runs west to east, falling as it goes, so the northern quarter\n// is wide in the east and the southern one in the west.\nexport const canalY = (x: number) => 236 + 0.2 * x + 58 * Math.sin(x / 178 + 0.7) + 22 * Math.sin(x / 71 + 2.2)\nconst BANK = 31\n\nconst quarters = [\n  { name: \"Glasswater\", north: true, angle: -9, ox: 640, oy: 160, su: [62, 104], sv: [50, 84], au: 1, av: 2 },\n  { name: \"Lowtide\", north: false, angle: 6, ox: 520, oy: 560, su: [50, 86], sv: [42, 70], au: 2, av: 0 },\n] as const\n\n// Two things too big to be a block: an exchange hall and a spire.\nexport const landmarks = [\n  { id: \"exchange\", name: \"Vanta Exchange\", x: 432, y: 142, r: 56 },\n  { id: \"spire\", name: \"Meridian Spire\", x: 812, y: 598, r: 42 },\n] as const\n\nexport const rail: Point[] = [\n  [-20, 662],\n  [196, 606],\n  [404, 486],\n  [596, 300],\n  [786, 196],\n  [1004, 128],\n  [1220, 98],\n]\nexport const stations: Point[] = [rail[1], rail[4]]\n\nfunction distanceToRail(x: number, y: number) {\n  let best = Infinity\n  for (let i = 0; i < rail.length - 1; i++) {\n    const [ax, ay] = rail[i]\n    const [bx, by] = rail[i + 1]\n    const dx = bx - ax\n    const dy = by - ay\n    const t = Math.max(0, Math.min(1, ((x - ax) * dx + (y - ay) * dy) / (dx * dx + dy * dy)))\n    best = Math.min(best, Math.hypot(x - ax - t * dx, y - ay - t * dy))\n  }\n  return best\n}\n\nexport const districtAt = (x: number, y: number) => {\n  const side = y - canalY(x)\n  return side < -18 ? quarters[0].name : side > 18 ? quarters[1].name : \"Sluice Canal\"\n}\n\n// The survey grid printed over the map: columns A to H, rows 1 to 5.\nexport const SECTOR_W = W / 8\nexport const SECTOR_H = H / 5\nexport const sectorAt = (x: number, y: number) =>\n  `${\"ABCDEFGH\"[Math.max(0, Math.min(7, Math.floor(x / SECTOR_W)))]}${Math.max(0, Math.min(4, Math.floor(y / SECTOR_H))) + 1}`\n\nconst places: Omit<Marker, \"x\" | \"y\" | \"district\" | \"sector\" | \"metres\" | \"route\">[] = [\n  {\n    id: \"cold-relay\",\n    kind: \"job\",\n    name: \"Cold Relay\",\n    text: \"A Vanta relay on a rooftop stopped answering. Mara Voss wants it talking again before the Neon Jackals notice.\",\n    fact: [\"Pays\", \"¤ 4 200\"],\n  },\n  {\n    id: \"kestrel-counter\",\n    kind: \"vendor\",\n    name: \"Kestrel Counter\",\n    text: \"Carbines, parts and rounds, sold from behind armoured glass. KR-9 magazines are in stock.\",\n    fact: [\"Stock\", \"Firearms\"],\n  },\n  {\n    id: \"mara-voss\",\n    kind: \"contact\",\n    name: \"Mara Voss\",\n    text: \"Fixer. She keeps her usual table until the rain stops, and she has work if you have the time.\",\n    fact: [\"Standing\", \"Trusted\"],\n  },\n  {\n    id: \"quay-loft\",\n    kind: \"safehouse\",\n    name: \"Quay Loft\",\n    text: \"Two rooms over a net-mender's shop. The stash is behind the boiler, and the door code changes weekly.\",\n    fact: [\"Stash\", \"12 of 40 slots\"],\n  },\n  {\n    id: \"glass-ledger\",\n    kind: \"job\",\n    name: \"Glass Ledger\",\n    text: \"Ren Aoki needs a copy of a Solace Mutual claims ledger. Walk in as a client, walk out with the copy.\",\n    fact: [\"Pays\", \"¤ 6 800\"],\n  },\n  {\n    id: \"brandts-bench\",\n    kind: \"vendor\",\n    name: \"Brandt's Bench\",\n    text: \"Ilya's workshop. Deck repairs while you wait, and a Vanta Mk.II on the shelf if you can pay for it.\",\n    fact: [\"Stock\", \"Decks and parts\"],\n  },\n  {\n    id: \"ren-aoki\",\n    kind: \"contact\",\n    name: \"Ren Aoki\",\n    text: \"Broker. Buys information at a fair price and sells it at an unfair one.\",\n    fact: [\"Standing\", \"Neutral\"],\n  },\n  {\n    id: \"night-freight\",\n    kind: \"job\",\n    name: \"Night Freight\",\n    text: \"Dex Marlowe is a driver short for one run across the canal. No questions about the crates.\",\n    fact: [\"Pays\", \"¤ 2 150\"],\n  },\n  {\n    id: \"lumen-stall\",\n    kind: \"vendor\",\n    name: \"Lumen Stall\",\n    text: \"Second-hand Onyx optics, cleaned and recalibrated. Most of them even come with a serial.\",\n    fact: [\"Stock\", \"Optics\"],\n  },\n  {\n    id: \"signal-annex\",\n    kind: \"safehouse\",\n    name: \"Signal Annex\",\n    text: \"A Static Saints crash pad with a clean line out. Sleep here and the heat on you drops.\",\n    fact: [\"Stash\", \"Empty\"],\n  },\n  {\n    id: \"bloom-test\",\n    kind: \"job\",\n    name: \"Bloom Test\",\n    text: \"Ilya Brandt wants Static Bloom run against a live Onyx gate, and the logs brought home.\",\n    fact: [\"Pays\", \"¤ 3 400\"],\n  },\n  {\n    id: \"okafor-clinic\",\n    kind: \"vendor\",\n    name: \"Okafor Clinic\",\n    text: \"Juno Okafor patches runners and fits Meridian augments. Solace Mutual cards are not accepted.\",\n    fact: [\"Stock\", \"Medical, augments\"],\n  },\n  {\n    id: \"sable-quinn\",\n    kind: \"contact\",\n    name: \"Sable Quinn\",\n    text: \"Runner. Knows every roof between here and the Stacks, and which of them still hold weight.\",\n    fact: [\"Standing\", \"Friendly\"],\n  },\n  {\n    id: \"union-dues\",\n    kind: \"job\",\n    name: \"Union Dues\",\n    text: \"Lowtide Union is owed by a dock boss who stopped picking up. Deliver the reminder politely.\",\n    fact: [\"Pays\", \"¤ 1 900\"],\n  },\n]\n\nfunction build() {\n  const random = seeded(0x5ec7a11)\n  const between = (low: number, high: number) => low + (high - low) * random()\n  const nodes: Node[] = []\n  const roads = { minor: [] as string[], major: [] as string[] }\n  const blocks: [string[], string[], string[]] = [[], [], []]\n  const lots: string[] = []\n\n  const onLand = (x: number, y: number, north: boolean) => {\n    if (x < -70 || x > W + 70 || y < -70 || y > H + 70) return false\n    const side = y - canalY(x)\n    if (north ? side > -BANK : side < BANK) return false\n    return landmarks.every((mark) => Math.hypot(x - mark.x, y - mark.y) > mark.r + 14)\n  }\n\n  const link = (a: number, b: number, major: boolean) => {\n    nodes[a].links.push(b)\n    nodes[b].links.push(a)\n    roads[major ? \"major\" : \"minor\"].push(`M${n(nodes[a].x)} ${n(nodes[a].y)}L${n(nodes[b].x)} ${n(nodes[b].y)}`)\n  }\n\n  quarters.forEach((quarter, q) => {\n    const turn = (quarter.angle * Math.PI) / 180\n    const cos = Math.cos(turn)\n    const sin = Math.sin(turn)\n    const at = (u: number, v: number): Point => [quarter.ox + u * cos - v * sin, quarter.oy + u * sin + v * cos]\n    const cuts = (from: number, to: number, [low, high]: readonly [number, number]) => {\n      const out: number[] = []\n      for (let value = from; value < to; value += between(low, high)) out.push(value)\n      return out\n    }\n    const us = cuts(-1150, 1150, quarter.su)\n    const vs = cuts(-820, 820, quarter.sv)\n\n    const index = us.map((u) =>\n      vs.map((v) => {\n        const [x, y] = at(u, v)\n        if (!onLand(x, y, quarter.north)) return -1\n        nodes.push({ x, y, quarter: q, inside: x > 0 && x < W && y > 0 && y < H, links: [] })\n        return nodes.length - 1\n      }),\n    )\n\n    // Every fourth or fifth street is an avenue.\n    const avenueU = (i: number) => i % 5 === quarter.au\n    const avenueV = (j: number) => j % 4 === quarter.av\n    for (let i = 0; i < us.length; i++) {\n      for (let j = 0; j < vs.length; j++) {\n        const here = index[i][j]\n        if (here < 0) continue\n        const east = index[i + 1]?.[j] ?? -1\n        const south = index[i][j + 1] ?? -1\n        if (east >= 0) link(here, east, avenueV(j))\n        if (south >= 0) link(here, south, avenueU(i))\n      }\n    }\n\n    // A block is a cell with streets on all four sides. It's cut into\n    // buildings until they're small, with a few left out as yards.\n    const building = (u0: number, v0: number, u1: number, v1: number) => {\n      const [cx, cy] = at((u0 + u1) / 2, (v0 + v1) / 2)\n      if (distanceToRail(cx, cy) < 11) return\n      const corners = [at(u0, v0), at(u1, v0), at(u1, v1), at(u0, v1)]\n      const path = `M${corners.map(([x, y]) => `${n(x)} ${n(y)}`).join(\"L\")}Z`\n      const roll = random()\n      blocks[roll < 0.56 ? 0 : roll < 0.86 ? 1 : 2].push(path)\n    }\n    const cut = (u0: number, v0: number, u1: number, v1: number, depth: number) => {\n      const w = u1 - u0\n      const h = v1 - v0\n      if ((w < 30 && h < 30) || depth > 2 || (depth > 0 && random() < 0.16)) {\n        if (random() > 0.09) building(u0, v0, u1, v1)\n        return\n      }\n      const share = between(0.36, 0.64)\n      const gap = 1.6\n      if (w >= h) {\n        cut(u0, v0, u0 + w * share - gap, v1, depth + 1)\n        cut(u0 + w * share + gap, v0, u1, v1, depth + 1)\n      } else {\n        cut(u0, v0, u1, v0 + h * share - gap, depth + 1)\n        cut(u0, v0 + h * share + gap, u1, v1, depth + 1)\n      }\n    }\n    for (let i = 0; i < us.length - 1; i++) {\n      for (let j = 0; j < vs.length - 1; j++) {\n        if (index[i][j] < 0 || index[i + 1][j] < 0 || index[i][j + 1] < 0 || index[i + 1][j + 1] < 0) continue\n        const pad = (avenue: boolean) => (avenue ? 6 : 4.5)\n        const u0 = us[i] + pad(avenueU(i))\n        const u1 = us[i + 1] - pad(avenueU(i + 1))\n        const v0 = vs[j] + pad(avenueV(j))\n        const v1 = vs[j + 1] - pad(avenueV(j + 1))\n        // An open lot now and then: drawn as an outline, with nothing on it.\n        if (random() < 0.06) {\n          const corners = [at(u0 + 3, v0 + 3), at(u1 - 3, v0 + 3), at(u1 - 3, v1 - 3), at(u0 + 3, v1 - 3)]\n          lots.push(`M${corners.map(([x, y]) => `${n(x)} ${n(y)}`).join(\"L\")}Z`)\n          continue\n        }\n        cut(u0, v0, u1, v1, 0)\n      }\n    }\n  })\n\n  // Three bridges: from the northern crossing nearest the water at each\n  // place, to whichever southern crossing is closest to it.\n  const bridges: string[] = []\n  for (const x of [262, 618, 968]) {\n    let from = -1\n    nodes.forEach((node, i) => {\n      if (node.quarter !== 0 || !node.inside || Math.abs(node.x - x) > 52) return\n      if (from < 0 || node.y > nodes[from].y) from = i\n    })\n    if (from < 0) continue\n    let to = -1\n    nodes.forEach((node, i) => {\n      if (node.quarter !== 1 || !node.inside) return\n      const reach = (other: Node) => Math.hypot(other.x - nodes[from].x, other.y - nodes[from].y)\n      if (to < 0 || reach(node) < reach(nodes[to])) to = i\n    })\n    if (to < 0) continue\n    nodes[from].links.push(to)\n    nodes[to].links.push(from)\n    bridges.push(`M${n(nodes[from].x)} ${n(nodes[from].y)}L${n(nodes[to].x)} ${n(nodes[to].y)}`)\n  }\n\n  // The player stands on a southern crossing near the middle of the sheet.\n  const crossing = (node: Node) => node.inside && node.links.length >= 3\n  let home = -1\n  nodes.forEach((node, i) => {\n    if (node.quarter !== 1 || !crossing(node)) return\n    const reach = (other: Node) => Math.hypot(other.x - 548, other.y - 512)\n    if (home < 0 || reach(node) < reach(nodes[home])) home = i\n  })\n\n  // Shortest walks from there to everywhere (Dijkstra; the graph is small).\n  const walk = nodes.map(() => Infinity)\n  const back = nodes.map(() => -1)\n  const done = nodes.map(() => false)\n  if (home >= 0) walk[home] = 0\n  for (;;) {\n    let next = -1\n    for (let i = 0; i < nodes.length; i++) if (!done[i] && walk[i] < Infinity && (next < 0 || walk[i] < walk[next])) next = i\n    if (next < 0) break\n    done[next] = true\n    for (const other of nodes[next].links) {\n      const length = walk[next] + Math.hypot(nodes[other].x - nodes[next].x, nodes[other].y - nodes[next].y)\n      if (length < walk[other]) {\n        walk[other] = length\n        back[other] = next\n      }\n    }\n  }\n\n  // Marker sites: crossings well inside the sheet (clear of where the side\n  // panels sit at the widest view), spaced apart, reachable on foot.\n  const order = nodes.map((_, i) => i)\n  for (let i = order.length - 1; i > 0; i--) {\n    const j = Math.floor(random() * (i + 1))\n    ;[order[i], order[j]] = [order[j], order[i]]\n  }\n  const sites: number[] = []\n  for (const i of order) {\n    const node = nodes[i]\n    if (!crossing(node) || walk[i] === Infinity || i === home) continue\n    if (node.x < W * 0.24 || node.x > W * 0.73 || node.y < 84 || node.y > H - 84) continue\n    if (distanceToRail(node.x, node.y) < 24) continue\n    if (Math.hypot(node.x - nodes[home].x, node.y - nodes[home].y) < 96) continue\n    if (sites.some((other) => Math.hypot(node.x - nodes[other].x, node.y - nodes[other].y) < 88)) continue\n    sites.push(i)\n    if (sites.length === places.length) break\n  }\n  // The first job is the tracked one: over the canal, a fair walk away.\n  let far = -1\n  sites.forEach((site, at) => {\n    if (nodes[site].quarter !== 0) return\n    if (far < 0 || Math.abs(walk[site] - 470) < Math.abs(walk[sites[far]] - 470)) far = at\n  })\n  if (far > 0) sites.unshift(...sites.splice(far, 1))\n\n  const routeTo = (site: number) => {\n    const points: Point[] = []\n    for (let at = site; at >= 0; at = back[at]) points.unshift([nodes[at].x, nodes[at].y])\n    return points\n  }\n  const markers: Marker[] = sites.map((site, at) => {\n    const { x, y } = nodes[site]\n    return {\n      ...places[at],\n      x,\n      y,\n      district: districtAt(x, y),\n      sector: sectorAt(x, y),\n      metres: Math.round((walk[site] * 1.5) / 10) * 10,\n      route: routeTo(site),\n    }\n  })\n\n  const canal: string[] = []\n  for (let x = -40; x <= W + 40; x += 20) canal.push(`${x} ${n(canalY(x))}`)\n\n  return {\n    you: { x: nodes[home]?.x ?? W / 2, y: nodes[home]?.y ?? H / 2 },\n    markers,\n    paths: {\n      canal: `M${canal.join(\"L\")}`,\n      minor: roads.minor.join(\"\"),\n      major: roads.major.join(\"\"),\n      bridges: bridges.join(\"\"),\n      blocks: blocks.map((tone) => tone.join(\"\")),\n      lots: lots.join(\"\"),\n      rail: `M${rail.map(([x, y]) => `${x} ${y}`).join(\"L\")}`,\n    },\n  }\n}\n\nexport const city = build()\n\nexport const pathOf = (points: Point[]) => (points.length ? `M${points.map(([x, y]) => `${n(x)} ${n(y)}`).join(\"L\")}` : \"\")\n",
      "type": "registry:component",
      "target": "@components/blocks/grid/city.ts"
    },
    {
      "path": "registry/cyber/blocks/grid/grid.css",
      "content": "@layer ui-sdk, cyber.tokens, cyber.base, cyber.ui, cyber.blocks, cyber.fx, cyber.a11y;\n\n@layer cyber.blocks {\n  [data-skin=\"cyber\"] [data-grid-screen] {\n    grid-template-columns: minmax(0, 1fr);\n    container: grid-screen / inline-size;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-picker] {\n    max-inline-size: 100%;\n\n    @media (pointer: coarse) {\n      --cy-h: var(--cy-h-lg);\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-relays] {\n    --map-height: clamp(350px, min(47vw, 52svh), 620px);\n  }\n\n  [data-skin=\"cyber\"] [data-kit=\"grid-map\"] {\n    display: grid;\n    min-width: 0;\n  }\n\n  /* What's being tracked and what's in view, at the end of the status strip. */\n  [data-skin=\"cyber\"] [data-grid-now] {\n    display: flex;\n    flex-wrap: wrap;\n    gap: 8px 28px;\n    margin: 0;\n\n    & div {\n      display: grid;\n      gap: 4px;\n      justify-items: start;\n    }\n\n    & dt {\n      font-size: var(--cy-text-xs);\n      color: var(--cy-ink-mute);\n    }\n\n    & dd {\n      min-height: 20px;\n      display: flex;\n      align-items: center;\n      margin: 0;\n    }\n  }\n\n  /* ── The stage ─────────────────────────────────────────────────────── */\n\n  /* The map fills the stage and the panels float over its edges, in the two\n     outer columns. --grid-l and --grid-r are how much of the map those\n     columns cover; the script reads them to find the clear middle. */\n  [data-skin=\"cyber\"] [data-grid-stage] {\n    --grid-l: 252px;\n    --grid-r: 318px;\n\n    display: grid;\n    grid-template-columns: var(--grid-l) minmax(0, 1fr) var(--grid-r);\n    grid-template-rows: minmax(0, 1fr) auto;\n    height: clamp(620px, 76svh, 780px);\n    min-width: 0;\n\n    /* Narrower, the map takes the width and the panels follow it. */\n    @container grid-screen (max-width: 990px) {\n      --grid-l: 0px;\n      --grid-r: 0px;\n\n      grid-template-columns: minmax(0, 1fr);\n      grid-template-rows: auto;\n      gap: 12px;\n      height: auto;\n    }\n  }\n\n  /* The viewport: a window onto the sheet. Nothing in it scrolls; the sheet\n     is moved by transform, and what falls outside is clipped. The cut\n     corners match the frame laid over it. */\n  [data-skin=\"cyber\"] [data-grid-view] {\n    --_cut: var(--cy-cut-lg);\n\n    grid-area: 1 / 1 / -1 / -1;\n    position: relative;\n    min-width: 0;\n    overflow: clip;\n    contain: layout paint;\n    clip-path: polygon(var(--_cut) 0, 100% 0, 100% calc(100% - var(--_cut)), calc(100% - var(--_cut)) 100%, 0 100%, 0 var(--_cut));\n    background: var(--cy-void);\n    cursor: grab;\n    user-select: none;\n    /* A finger still scrolls the page past the map, until the sheet is\n       tall enough to need panning that way too. */\n    touch-action: pan-y;\n\n    &[data-pan=\"both\"] {\n      touch-action: none;\n    }\n\n    &[data-dragging] {\n      cursor: grabbing;\n    }\n\n    /* The sheet darkens toward the sides the panels sit on. */\n    &::after {\n      content: \"\";\n      position: absolute;\n      inset: 0;\n      pointer-events: none;\n      background:\n        linear-gradient(to right, color-mix(in srgb, var(--cy-void) 78%, transparent), transparent calc(var(--grid-l) + 90px)),\n        linear-gradient(to left, color-mix(in srgb, var(--cy-void) 78%, transparent), transparent calc(var(--grid-r) + 90px));\n    }\n\n    /* Its own outline would be clipped with the corners: the frame over it\n       lights instead (below). */\n    &:focus-visible {\n      outline: none;\n    }\n\n    @container grid-screen (max-width: 990px) {\n      grid-area: 1 / 1;\n      height: clamp(260px, min(98cqi, 52svh), 500px);\n\n      &::after {\n        content: none;\n      }\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-edge] {\n    --frame-cut: var(--cy-cut-lg);\n    --frame-line: var(--cy-line-ctl);\n    --frame-fill: transparent;\n\n    grid-area: 1 / 1 / -1 / -1;\n    z-index: 1;\n    pointer-events: none;\n\n    @container grid-screen (max-width: 990px) {\n      grid-area: 1 / 1;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-view]:focus-visible + [data-grid-edge] {\n    --frame-line: var(--cy-signal);\n    box-shadow: inset 0 0 0 1px var(--cy-signal);\n  }\n\n  /* The sheet, in its own units (1200 by 700), scaled and offset to the\n     view. A map doesn't mirror, so its positions are physical. */\n  [data-skin=\"cyber\"] [data-grid-world] {\n    position: absolute;\n    left: 0;\n    top: 0;\n    width: 1200px;\n    height: 700px;\n    transform-origin: 0 0;\n    transform: translate(var(--tx, 0px), var(--ty, 0px)) scale(var(--k, 1));\n    transition: transform 240ms var(--cy-ease-snap);\n\n    [data-dragging] > & {\n      transition: none;\n    }\n  }\n\n  [data-skin=\"cyber\"] :is([data-grid-terrain], [data-grid-route]) {\n    position: absolute;\n    inset: 0;\n    width: 100%;\n    height: 100%;\n    overflow: visible;\n    pointer-events: none;\n  }\n\n  /* ── The sheet's ink ───────────────────────────────────────────────── */\n\n  [data-skin=\"cyber\"] [data-grid-survey] path {\n    fill: none;\n    stroke: var(--cy-line-deco);\n    stroke-width: 1;\n    stroke-dasharray: 2 6;\n    opacity: 0.7;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-water] {\n    fill: none;\n    stroke: color-mix(in srgb, var(--cy-signal) 13%, var(--cy-void));\n    stroke-width: 32;\n    stroke-linejoin: bevel;\n\n    &[data-grid-water=\"bank\"] {\n      stroke: var(--cy-signal-dim);\n      stroke-width: 35;\n    }\n    &[data-grid-water=\"flow\"] {\n      stroke: var(--cy-signal-dim);\n      stroke-width: 1;\n      stroke-dasharray: 3 14;\n    }\n    &[data-grid-water=\"sample\"] {\n      stroke: var(--cy-signal-dim);\n      stroke-width: 7;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-road] {\n    fill: none;\n    stroke: color-mix(in srgb, var(--cy-rare) 42%, var(--cy-void));\n    stroke-width: 2;\n    stroke-linecap: square;\n\n    &[data-grid-road=\"major\"],\n    &[data-grid-road=\"bridge\"] {\n      stroke: color-mix(in srgb, var(--cy-rare) 82%, var(--cy-void));\n      stroke-width: 3.5;\n    }\n    &[data-grid-road=\"bridge-bed\"] {\n      stroke: var(--cy-void);\n      stroke-width: 9;\n      stroke-linecap: butt;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-block] {\n    fill: color-mix(in srgb, var(--cy-accent) 24%, var(--cy-void));\n\n    &[data-grid-block=\"1\"] {\n      fill: color-mix(in srgb, var(--cy-accent) 40%, var(--cy-void));\n    }\n    &[data-grid-block=\"2\"] {\n      fill: color-mix(in srgb, var(--cy-accent) 62%, var(--cy-void));\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-lot] {\n    fill: none;\n    stroke: var(--cy-line-deco);\n    stroke-width: 1;\n    stroke-dasharray: 3 3;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-track] {\n    fill: none;\n    stroke: var(--cy-signal);\n    stroke-width: 1.5;\n    stroke-linejoin: miter;\n\n    &[data-grid-track=\"bed\"] {\n      stroke: var(--cy-void);\n      stroke-width: 11;\n    }\n    &[data-grid-track=\"ties\"] {\n      stroke: var(--cy-signal-dim);\n      stroke-width: 7;\n      stroke-dasharray: 1.5 5;\n    }\n    &[data-grid-track=\"station\"] {\n      fill: var(--cy-void);\n      stroke-width: 2;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-landmark] path {\n    fill: var(--cy-panel);\n    stroke: var(--cy-ink);\n    stroke-width: 1.5;\n\n    &[data-grid-landmark-core] {\n      fill: var(--cy-accent);\n      stroke: none;\n    }\n  }\n\n  /* Print on the sheet: sector codes and landmark names in micro-print,\n     the districts' names large. All of it is decoration; the names that\n     matter are in the panels. */\n  [data-skin=\"cyber\"] [data-grid-print] text {\n    font-family: var(--cy-mono);\n    font-size: 8px;\n    letter-spacing: 0.08em;\n    text-transform: uppercase;\n    fill: var(--cy-line-ctl);\n    paint-order: stroke;\n    stroke: var(--cy-void);\n    stroke-width: 3px;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-name] {\n    font-family: var(--cy-font);\n    font-size: 21px;\n    font-weight: 700;\n    letter-spacing: 0.5em;\n    text-transform: uppercase;\n    fill: var(--cy-ink-hi);\n    paint-order: stroke;\n    stroke: var(--cy-void);\n    stroke-width: 5px;\n    opacity: 0.9;\n\n    &[data-grid-name=\"water\"] {\n      font-family: var(--cy-mono);\n      font-size: 8px;\n      font-weight: 400;\n      letter-spacing: 0.4em;\n      fill: var(--cy-signal);\n      stroke-width: 3px;\n    }\n  }\n\n  /* The route: the one yellow line. It keeps its weight at any zoom. */\n  [data-skin=\"cyber\"] [data-grid-route] {\n    animation: var(--cy-fx-in) 320ms var(--cy-ease-snap) backwards;\n\n    & path {\n      fill: none;\n      stroke: var(--cy-flag);\n      stroke-width: 3px;\n      stroke-linejoin: miter;\n      stroke-linecap: square;\n    }\n    & [data-grid-route-bed] {\n      stroke: var(--cy-void);\n      stroke-width: 7px;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-route-sample] {\n    fill: none;\n    stroke: var(--cy-flag);\n    stroke-width: 2.5;\n  }\n\n  /* ── Pins ──────────────────────────────────────────────────────────── */\n\n  /* A pin stands on a point of the sheet and is scaled back by the sheet's\n     own scale, so markers stay one size at every zoom. */\n  [data-skin=\"cyber\"] [data-grid-pin] {\n    position: absolute;\n    left: calc(var(--x) * 1px);\n    top: calc(var(--y) * 1px);\n    display: grid;\n    transform: translate(-50%, -50%) scale(calc(1 / var(--k, 1)));\n    transition: transform 240ms var(--cy-ease-snap);\n\n    [data-dragging] & {\n      transition: none;\n    }\n\n    &:is([data-chosen], :focus-within) {\n      z-index: 1;\n    }\n\n    @media (hover: hover) {\n      &:hover {\n        z-index: 1;\n      }\n    }\n  }\n\n  /* The waypoint's pennant, so it isn't told apart by its yellow alone. */\n  [data-skin=\"cyber\"] [data-grid-pennant] {\n    padding: 1px 4px 0;\n    font-family: var(--cy-mono);\n    font-size: 9px;\n    font-weight: 600;\n    line-height: 1.3;\n    letter-spacing: 0.08em;\n    color: var(--cy-on-solid);\n    background: var(--cy-flag);\n    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%);\n    pointer-events: none;\n\n    [data-grid-pin] > & {\n      position: absolute;\n      top: calc(100% + 6px);\n      left: 50%;\n      translate: -50% 0;\n    }\n  }\n\n  [data-skin=\"cyber\"] :is([data-grid-you], [data-grid-you-sample]) {\n    pointer-events: none;\n\n    & path {\n      fill: var(--cy-ink-hi);\n    }\n    & [data-grid-you-ring] {\n      fill: color-mix(in srgb, var(--cy-accent) 45%, var(--cy-void));\n      stroke: var(--cy-ink-hi);\n      stroke-width: 2;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-you] svg {\n    display: block;\n    width: 30px;\n    height: 30px;\n    filter: drop-shadow(0 0 calc(6px * var(--cy-fx)) var(--cy-glow));\n\n    /* A small lamp, breathing: this is where you are. */\n    & [data-grid-you-ring] {\n      animation: var(--cy-fx-pulse) 2.4s linear infinite;\n    }\n  }\n\n  /* Micro-print in the sheet's margins. */\n  [data-skin=\"cyber\"] [data-grid-micro] {\n    position: absolute;\n    left: 50%;\n    translate: -50% 0;\n\n    &[data-grid-micro=\"top\"] {\n      top: 9px;\n    }\n    &[data-grid-micro=\"bottom\"] {\n      bottom: 9px;\n\n      /* Keep the compact map's lower margin clear of small print. */\n      @container grid-screen (max-width: 990px) {\n        display: none;\n      }\n    }\n  }\n\n  /* ── Keys and panels over the sheet ────────────────────────────────── */\n\n  [data-skin=\"cyber\"] [data-grid-layers-key] {\n    display: none;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-tools] {\n    grid-area: 2 / 1;\n    justify-self: start;\n    z-index: 2;\n    margin: 0 0 16px 16px;\n\n    @container grid-screen (max-width: 990px) {\n      grid-area: auto;\n      justify-self: stretch;\n      display: flex;\n      flex-wrap: wrap;\n      align-items: center;\n      justify-content: space-between;\n      gap: 6px;\n      margin: 0;\n\n      & > [data-grid-layers-key] {\n        display: inline-flex;\n        padding-inline: 10px;\n        &[aria-expanded=\"true\"] {\n          --frame-line: var(--cy-line-hot);\n          --frame-fill: var(--cy-fill-active);\n          color: var(--cy-ink-hi);\n        }\n      }\n      & [data-kit=\"button-group\"] [data-kit=\"button\"]:not([data-icon]) {\n        min-inline-size: 52px;\n        padding-inline: 8px;\n      }\n    }\n  }\n\n  /* A rail takes no clicks itself, so the sheet can be dragged between and\n     beside its panels. */\n  [data-skin=\"cyber\"] [data-grid-rail] {\n    z-index: 2;\n    display: flex;\n    flex-direction: column;\n    gap: 16px;\n    min-width: 0;\n    pointer-events: none;\n\n    & > * {\n      pointer-events: auto;\n    }\n\n    & [data-kit=\"panel-surface\"] {\n      --frame-fill: color-mix(in srgb, var(--tone) 5%, var(--cy-panel));\n    }\n\n    &[data-grid-rail=\"detail\"] {\n      grid-area: 1 / 3 / -1 / 4;\n      justify-content: space-between;\n      padding: 16px 16px 16px 0;\n    }\n\n    &[data-grid-rail=\"filters\"] {\n      grid-area: 1 / 1 / 2 / 2;\n      padding: 16px 0 0 16px;\n    }\n\n    @container grid-screen (max-width: 990px) {\n      &[data-grid-rail=\"detail\"],\n      &[data-grid-rail=\"filters\"] {\n        grid-area: auto;\n        justify-content: flex-start;\n        padding: 0;\n      }\n\n      &[data-grid-rail=\"filters\"]:not([data-open]) {\n        display: none;\n      }\n      &[data-grid-rail=\"detail\"] {\n        display: grid;\n        grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);\n        align-items: start;\n      }\n    }\n\n    @container grid-screen (max-width: 560px) {\n      &[data-grid-rail=\"detail\"] {\n        grid-template-columns: minmax(0, 1fr);\n        gap: 12px;\n      }\n    }\n  }\n\n  /* The toggle strip and the legend fill the panel's width. */\n  [data-skin=\"cyber\"] [data-grid-rail=\"filters\"] [data-kit=\"panel-body\"] {\n    gap: 14px;\n  }\n\n  /* ── The dossier ───────────────────────────────────────────────────── */\n\n  [data-skin=\"cyber\"] [data-grid-dossier] {\n    display: grid;\n    gap: 6px;\n    min-width: 0;\n    animation: var(--cy-fx-in) 240ms var(--cy-ease-snap) backwards;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-title] {\n    font-size: var(--cy-text-xl);\n    font-weight: 700;\n    line-height: 1.1;\n    letter-spacing: var(--cy-track);\n    text-transform: uppercase;\n    overflow-wrap: anywhere;\n    color: var(--tone-ink, var(--cy-ink));\n  }\n\n  [data-skin=\"cyber\"] [data-grid-figures] {\n    display: grid;\n    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);\n    align-items: end;\n    gap: 10px 16px;\n    padding-block: 10px;\n    border-block: 1px solid var(--cy-line-deco);\n\n    & > [data-grid-fact] {\n      grid-column: 1 / -1;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-actions] {\n    display: grid;\n    grid-template-columns: repeat(auto-fit, minmax(min(100%, 110px), 1fr));\n    gap: 6px;\n    & > button {\n      min-inline-size: 0;\n      gap: 5px;\n      padding-inline: 6px;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-fact] {\n    display: flex;\n    flex-wrap: wrap;\n    align-items: baseline;\n    justify-content: space-between;\n    gap: 2px 12px;\n    margin: 0;\n\n    & dt {\n      font-size: var(--cy-text-xs);\n      color: var(--cy-ink-mute);\n    }\n    & dd {\n      margin: 0;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-here] {\n    display: grid;\n    gap: 2px;\n    font-size: var(--cy-text-lg);\n    font-weight: 600;\n    line-height: 1.2;\n    letter-spacing: var(--cy-track);\n    text-transform: uppercase;\n    color: var(--cy-ink-hi);\n\n    & [data-kit=\"hint\"] {\n      font-weight: 500;\n      letter-spacing: 0;\n      text-transform: none;\n    }\n  }\n\n  [data-skin=\"cyber\"] [data-grid-time] {\n    font-size: var(--cy-text-lg);\n  }\n\n  /* ── The legend ────────────────────────────────────────────────────── */\n\n  [data-skin=\"cyber\"] [data-grid-legend] {\n    display: grid;\n    gap: 5px;\n    padding-block-start: 4px;\n  }\n\n  [data-skin=\"cyber\"] [data-grid-legend-row] {\n    display: grid;\n    grid-template-columns: 30px minmax(0, 1fr) auto;\n    align-items: center;\n    gap: 10px;\n    min-height: 20px;\n    font-size: var(--cy-text-sm);\n    font-weight: 600;\n    letter-spacing: var(--cy-track);\n    text-transform: uppercase;\n    color: var(--cy-ink);\n  }\n\n  [data-skin=\"cyber\"] [data-grid-swatch] {\n    display: grid;\n    place-items: center;\n    color: var(--cy-signal);\n\n    & svg {\n      display: block;\n      width: 28px;\n      height: 12px;\n      overflow: visible;\n    }\n    & svg.lucide {\n      width: 14px;\n      height: 14px;\n    }\n    & [data-grid-you-sample] {\n      width: 16px;\n      height: 16px;\n    }\n  }\n\n  @container grid-screen (max-width: 560px) {\n    [data-skin=\"cyber\"] [data-grid-picker] {\n      flex-basis: 100%;\n    }\n    [data-skin=\"cyber\"] [data-grid-screen] [data-kit=\"screen-status-lead\"] {\n      inline-size: 100%;\n      justify-content: space-between;\n      gap: 8px 12px;\n    }\n    [data-skin=\"cyber\"] [data-grid-now] {\n      gap: 5px 14px;\n      & div {\n        display: flex;\n        align-items: center;\n        gap: 6px;\n      }\n    }\n  }\n  @media (pointer: coarse) {\n    [data-skin=\"cyber\"] [data-grid-screen] {\n      --cy-h-sm: 44px;\n    }\n  }\n  @container grid-screen (max-width: 300px) {\n    [data-skin=\"cyber\"] [data-grid-layers-key] > svg {\n      display: none;\n    }\n  }\n}\n",
      "type": "registry:file",
      "target": "@components/blocks/grid/grid.css"
    },
    {
      "path": "registry/cyber/blocks/grid/grid.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Briefcase, House, Layers, LocateFixed, MessageSquare, Minus, Navigation, Plus, Store } from \"lucide-react\"\nimport { sfx } from \"@/registry/cyber/lib/sound\"\nimport { relayAnnotations, relayGlobeAnnotations, relayMarkers, relayRoutes } from \"@/registry/cyber/examples/map-demo\"\nimport {\n  H,\n  SECTOR_H,\n  SECTOR_W,\n  W,\n  canalY,\n  city,\n  districtAt,\n  landmarks,\n  pathOf,\n  sectorAt,\n  stations,\n  type Kind,\n  type Marker,\n} from \"@/registry/cyber/blocks/grid/city\"\nimport { Badge } from \"@/registry/cyber/ui/badge\"\nimport { Button } from \"@/registry/cyber/ui/button\"\nimport { ButtonGroup } from \"@/registry/cyber/ui/button-group\"\nimport { Collapsible } from \"@/registry/cyber/ui/collapsible\"\nimport { Map, type MapView } from \"@/registry/cyber/ui/map\"\nimport { Corners, Micro } from \"@/registry/cyber/ui/micro\"\nimport { Panel } from \"@/registry/cyber/ui/panel\"\nimport { Readout } from \"@/registry/cyber/ui/readout\"\nimport { Reticle } from \"@/registry/cyber/ui/reticle\"\nimport { Screen } from \"@/registry/cyber/ui/screen\"\nimport { SegmentedControl } from \"@/registry/cyber/ui/segmented-control\"\nimport { notify } from \"@/registry/cyber/ui/toaster\"\nimport { ToggleGroup } from \"@/registry/cyber/ui/toggle-group\"\nimport { Tooltip } from \"@/registry/cyber/ui/tooltip\"\nimport \"@/registry/cyber/blocks/grid/grid.css\"\n\n// The district map. The sheet is drawn once, from the generator in city.ts;\n// over it stand the markers (each a key), the runner's own position, and the\n// route to the waypoint in yellow. The sheet moves by transform alone: drag\n// it, or focus it and use the arrows, and zoom with the keys in its corner\n// or with plus and minus. Choosing a marker fills the dossier beside the\n// map; \"Set waypoint\" redraws the route to it.\n//\n// At full width the panels float over the edges of the sheet, the way a deck\n// overlays its map, and the sheet is told how much of itself they cover\n// (--grid-l and --grid-r) so that centering and \"bring into view\" aim for\n// the clear middle. On a narrow screen the map takes the width and the\n// panels follow it.\n\nconst kinds: { value: Kind; label: string; plural: string; icon: React.ReactNode }[] = [\n  { value: \"job\", label: \"Job\", plural: \"Jobs\", icon: <Briefcase aria-hidden /> },\n  { value: \"vendor\", label: \"Vendor\", plural: \"Vendors\", icon: <Store aria-hidden /> },\n  { value: \"safehouse\", label: \"Safehouse\", plural: \"Safehouses\", icon: <House aria-hidden /> },\n  { value: \"contact\", label: \"Contact\", plural: \"Contacts\", icon: <MessageSquare aria-hidden /> },\n]\nconst kindOf = (kind: Kind) => kinds.find((entry) => entry.value === kind)!\n\n// Nearest first: that's the order the markers are reached by Tab.\nconst markers = [...city.markers].sort((a, b) => a.metres - b.metres)\nconst tracked = city.markers[0]\n\n// The view opens on the middle of the first route, so both of its ends show.\nconst opening = {\n  x: (Math.min(...tracked.route.map(([x]) => x)) + Math.max(...tracked.route.map(([x]) => x))) / 2,\n  y: (Math.min(...tracked.route.map(([, y]) => y)) + Math.max(...tracked.route.map(([, y]) => y))) / 2,\n}\n\n// Zoom steps, and how much closer than \"covering\" a snug window opens.\nconst zooms = [1, 1.4, 2, 3]\nconst START_ZOOM = 0\nconst BASE = 1.14\n\ntype View = { zoom: number; x: number; y: number }\ntype Size = { w: number; h: number; l: number; r: number }\ntype MapMode = \"district\" | \"atlas\" | \"globe\"\nconst mapModes = [\n  { value: \"district\", label: \"District\" },\n  { value: \"atlas\", label: \"Atlas\" },\n  { value: \"globe\", label: \"Globe\" },\n] satisfies { value: MapMode; label: string }[]\n\n// The example page has shareable views. Embedding this block elsewhere\n// leaves the host application's URL and history alone.\nfunction isGridPage() {\n  return window.location.pathname.replace(/\\/$/, \"\") === \"/grid\"\n}\n\nconst clamp = (value: number, low: number, high: number) => Math.min(high, Math.max(low, value))\n\n// Where the sheet sits for a view: its scale, its offset, and the view's\n// center after clamping. Its edges can reach the clear space between panels.\nfunction place(view: View, size: Size | null) {\n  if (!size) return { k: 1, tx: 0, ty: 0, x: view.x, y: view.y, tall: false }\n  // The scale at which the sheet just covers the window. Where that leaves\n  // almost nothing to pan to (a window shaped like the sheet), it opens a\n  // little closer; a tall window already has the sheet's width to cross.\n  const cover = Math.max(size.w / W, size.h / H)\n  const snug = W * cover - size.w < size.w * 0.12 && H * cover - size.h < size.h * 0.12\n  const k = cover * (snug ? BASE : 1) * zooms[view.zoom]\n  const midX = (size.l + size.w - size.r) / 2\n  const midY = size.h / 2\n  const tx = clamp(midX - view.x * k, size.w - size.r - W * k, size.l)\n  const ty = clamp(midY - view.y * k, size.h - H * k, 0)\n  return { k, tx, ty, x: (midX - tx) / k, y: (midY - ty) / k, tall: H * k - size.h > 1 }\n}\n\n// The sheet itself. It never changes, so it's drawn once and left alone\n// while the view moves over it.\nconst Terrain = React.memo(function Terrain() {\n  const { paths } = city\n  const columns = Array.from({ length: 8 }, (_, i) => i)\n  const rows = Array.from({ length: 5 }, (_, i) => i)\n  return (\n    <svg data-grid-terrain=\"\" viewBox={`0 0 ${W} ${H}`} aria-hidden focusable=\"false\">\n      <g data-grid-survey=\"\">\n        {columns.slice(1).map((i) => (\n          <path key={`c${i}`} d={`M${i * SECTOR_W} 0V${H}`} />\n        ))}\n        {rows.slice(1).map((i) => (\n          <path key={`r${i}`} d={`M0 ${i * SECTOR_H}H${W}`} />\n        ))}\n      </g>\n      <path data-grid-water=\"bank\" d={paths.canal} />\n      <path data-grid-water=\"\" d={paths.canal} />\n      <path data-grid-water=\"flow\" d={paths.canal} />\n      <path data-grid-road=\"minor\" d={paths.minor} />\n      <path data-grid-road=\"major\" d={paths.major} />\n      <path data-grid-road=\"bridge-bed\" d={paths.bridges} />\n      <path data-grid-road=\"bridge\" d={paths.bridges} />\n      <path data-grid-lot=\"\" d={paths.lots} />\n      {paths.blocks.map((d, tone) => (\n        <path key={tone} data-grid-block={tone} d={d} />\n      ))}\n      <path data-grid-track=\"bed\" d={paths.rail} />\n      <path data-grid-track=\"ties\" d={paths.rail} />\n      <path data-grid-track=\"\" d={paths.rail} />\n      {stations.map(([x, y]) => (\n        <path key={`${x}`} data-grid-track=\"station\" d={`M${x - 7} ${y - 7}h14v14h-14Z`} />\n      ))}\n      {landmarks.map((mark) =>\n        mark.id === \"exchange\" ? (\n          <g key={mark.id} data-grid-landmark=\"\">\n            {[1, 0.72, 0.44].map((scale) => (\n              <path key={scale} d={hexagon(mark.x, mark.y, mark.r * scale)} />\n            ))}\n            <path data-grid-landmark-core=\"\" d={hexagon(mark.x, mark.y, mark.r * 0.2)} />\n            <path\n              d={[0, 1, 2, 3, 4, 5]\n                .map((i) => {\n                  const a = (Math.PI / 3) * i\n                  return `M${mark.x + Math.cos(a) * mark.r * 0.44} ${mark.y + Math.sin(a) * mark.r * 0.44}L${mark.x + Math.cos(a) * mark.r} ${mark.y + Math.sin(a) * mark.r}`\n                })\n                .join(\"\")}\n            />\n          </g>\n        ) : (\n          <g key={mark.id} data-grid-landmark=\"\">\n            {[1, 0.66, 0.34].map((scale) => (\n              <path key={scale} d={diamond(mark.x, mark.y, mark.r * scale)} />\n            ))}\n            <path data-grid-landmark-core=\"\" d={diamond(mark.x, mark.y, mark.r * 0.16)} />\n            <path d={`M${mark.x - mark.r} ${mark.y}h${mark.r * 0.66}M${mark.x + mark.r} ${mark.y}h${-mark.r * 0.66}M${mark.x} ${mark.y - mark.r}v${mark.r * 0.66}M${mark.x} ${mark.y + mark.r}v${-mark.r * 0.66}`} />\n          </g>\n        ),\n      )}\n      <g data-grid-print=\"\">\n        {columns.map((i) =>\n          rows.map((j) => (\n            <text key={`${i}${j}`} x={i * SECTOR_W + 5} y={j * SECTOR_H + 11}>\n              {sectorAt(i * SECTOR_W + 1, j * SECTOR_H + 1)}\n            </text>\n          )),\n        )}\n        {landmarks.map((mark) => (\n          <text key={mark.id} x={mark.x} y={mark.y + mark.r + 13} textAnchor=\"middle\">\n            {mark.name}\n          </text>\n        ))}\n      </g>\n      <text data-grid-name=\"\" x=\"742\" y=\"104\" transform=\"rotate(-9 742 104)\" textAnchor=\"middle\">\n        Glasswater\n      </text>\n      <text data-grid-name=\"\" x=\"668\" y=\"672\" transform=\"rotate(6 668 672)\" textAnchor=\"middle\">\n        Lowtide\n      </text>\n      <text data-grid-name=\"water\" x=\"700\" y={canalY(700) + 3} transform={`rotate(4 700 ${canalY(700)})`} textAnchor=\"middle\">\n        Sluice Canal\n      </text>\n    </svg>\n  )\n})\n\nfunction hexagon(x: number, y: number, r: number) {\n  const points = [0, 1, 2, 3, 4, 5].map((i) => {\n    const a = (Math.PI / 3) * i + Math.PI / 6\n    return `${(x + Math.cos(a) * r).toFixed(1)} ${(y + Math.sin(a) * r).toFixed(1)}`\n  })\n  return `M${points.join(\"L\")}Z`\n}\n\nconst diamond = (x: number, y: number, r: number) => `M${x} ${y - r}L${x + r} ${y}L${x} ${y + r}L${x - r} ${y}Z`\n\n// One line of the legend: a swatch drawn with the map's own strokes, and\n// what it stands for.\nfunction LegendRow({ label, value, children }: { label: string; value?: string; children: React.ReactNode }) {\n  return (\n    <div role=\"listitem\" data-grid-legend-row=\"\">\n      <span data-grid-swatch=\"\" aria-hidden>\n        {children}\n      </span>\n      <span>{label}</span>\n      {value && <span data-kit=\"value\">{value}</span>}\n    </div>\n  )\n}\n\nconst stroke = (kind: React.ReactNode) => (\n  <svg viewBox=\"0 0 28 12\" focusable=\"false\">\n    {kind}\n  </svg>\n)\n\nfunction useClock() {\n  const [now, setNow] = React.useState(() => new Date())\n  React.useEffect(() => {\n    const timer = setInterval(() => setNow(new Date()), 15000)\n    return () => clearInterval(timer)\n  }, [])\n  return now.toLocaleTimeString(\"en-GB\", { hour: \"2-digit\", minute: \"2-digit\", hour12: false })\n}\n\nexport default function Grid() {\n  const [mode, setMode] = React.useState<MapMode>(\"district\")\n  const [relayId, setRelayId] = React.useState<string | null>(\"sound\")\n  const [relayViews, setRelayViews] = React.useState<Partial<Record<\"atlas\" | \"globe\", MapView>>>({})\n  const isDistrict = mode === \"district\"\n  const stage = React.useRef<HTMLDivElement>(null)\n  const viewport = React.useRef<HTMLDivElement>(null)\n  const measured = React.useRef<Size | null>(null)\n  const [size, setSize] = React.useState<Size | null>(null)\n  const [view, setView] = React.useState<View>({ zoom: START_ZOOM, ...opening })\n  const [dragging, setDragging] = React.useState(false)\n  const [shown, setShown] = React.useState<Kind[]>(kinds.map((kind) => kind.value))\n  const [chosen, setChosen] = React.useState(tracked.id)\n  const [waypointId, setWaypointId] = React.useState(tracked.id)\n  const [layersOpen, setLayersOpen] = React.useState(false)\n  const layersId = React.useId()\n  const help = React.useId()\n  const time = useClock()\n\n  React.useLayoutEffect(() => {\n    if (!isGridPage()) return\n    const readView = () => {\n      const next = new URLSearchParams(window.location.search).get(\"view\")\n      setMode(next === \"globe\" || next === \"atlas\" ? next : \"district\")\n    }\n    readView()\n    window.addEventListener(\"popstate\", readView)\n    return () => window.removeEventListener(\"popstate\", readView)\n  }, [])\n\n  const chooseMode = (next: MapMode | null) => {\n    if (!next) return\n    setMode(next)\n    if (isGridPage()) {\n      const url = new URL(window.location.href)\n      if (next === \"district\") url.searchParams.delete(\"view\")\n      else url.searchParams.set(\"view\", next)\n      window.history.replaceState(window.history.state, \"\", url)\n    }\n  }\n\n  React.useLayoutEffect(() => {\n    const el = viewport.current\n    const host = stage.current\n    if (!el || !host) return\n    const measure = () => {\n      const style = getComputedStyle(host)\n      const next = {\n        w: el.clientWidth,\n        h: el.clientHeight,\n        l: parseFloat(style.getPropertyValue(\"--grid-l\")) || 0,\n        r: parseFloat(style.getPropertyValue(\"--grid-r\")) || 0,\n      }\n      measured.current = next\n      setSize(next)\n    }\n    measure()\n    const observer = new ResizeObserver(measure)\n    observer.observe(el)\n    return () => observer.disconnect()\n  }, [isDistrict])\n\n  const at = place(view, size)\n  const latest = React.useRef(at)\n  React.useEffect(() => {\n    latest.current = at\n  })\n\n  // Every move starts from where the sheet really is (the clamped center),\n  // so pushing against an edge doesn't bank distance to be undone later.\n  const move = (change: (now: View) => View) =>\n    setView((now) => {\n      const from = place(now, measured.current)\n      const next = change({ zoom: now.zoom, x: from.x, y: from.y })\n      const to = place(next, measured.current)\n      return { zoom: next.zoom, x: to.x, y: to.y }\n    })\n  const pan = (dx: number, dy: number) => move((now) => ({ ...now, x: now.x + dx / latest.current.k, y: now.y + dy / latest.current.k }))\n  const zoomBy = (step: number) => {\n    const zoom = clamp(view.zoom + step, 0, zooms.length - 1)\n    if (zoom === view.zoom) return false\n    move((now) => ({ ...now, zoom }))\n    return true\n  }\n  const centerOn = (point: { x: number; y: number }) => move((now) => ({ ...now, x: point.x, y: point.y }))\n\n  const waypoint = markers.find((marker) => marker.id === waypointId) ?? tracked\n  // The waypoint stays on the map whatever the filters say: the route ends there.\n  const visible = markers.filter((marker) => shown.includes(marker.kind) || marker.id === waypoint.id)\n  const selected = visible.find((marker) => marker.id === chosen) ?? waypoint\n  const onRoute = selected.id === waypoint.id\n  const kind = kindOf(selected.kind)\n\n  const setWaypoint = (marker: Marker) => {\n    if (marker.id === waypointId) return\n    setChosen(marker.id)\n    setWaypointId(marker.id)\n    notify(\"Waypoint set\", { tone: \"success\", description: `${marker.name}, ${marker.metres} m by street.` })\n  }\n\n  // A marker reached by Tab may be off the sheet's visible part, or under a\n  // panel: bring it to the middle.\n  const reveal = (marker: Marker) => {\n    const s = measured.current\n    if (!s) return\n    const now = latest.current\n    const x = now.tx + marker.x * now.k\n    const y = now.ty + marker.y * now.k\n    if (x < s.l + 24 || x > s.w - s.r - 24 || y < 24 || y > s.h - 24) centerOn(marker)\n  }\n\n  const drag = React.useRef<{ id: number; x: number; y: number; from: View; k: number } | null>(null)\n  const onPointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n    if (event.button !== 0 || (event.target as Element).closest(\"button\")) return\n    drag.current = { id: event.pointerId, x: event.clientX, y: event.clientY, from: { zoom: view.zoom, x: at.x, y: at.y }, k: at.k }\n    // Capture keeps the drag alive past the window's edge; without it the\n    // drag still works inside.\n    try {\n      event.currentTarget.setPointerCapture(event.pointerId)\n    } catch {}\n    setDragging(true)\n  }\n  const onPointerMove = (event: React.PointerEvent<HTMLDivElement>) => {\n    const start = drag.current\n    if (!start || start.id !== event.pointerId) return\n    const x = start.from.x - (event.clientX - start.x) / start.k\n    const y = start.from.y - (event.clientY - start.y) / start.k\n    move(() => ({ zoom: start.from.zoom, x, y }))\n  }\n  const onPointerEnd = (event: React.PointerEvent<HTMLDivElement>) => {\n    if (drag.current?.id !== event.pointerId) return\n    drag.current = null\n    setDragging(false)\n  }\n\n  // The map's own keys, live only while focus is on the sheet or a marker.\n  const onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n    if (event.metaKey || event.ctrlKey || event.altKey) return\n    const step = 96\n    const keys: Record<string, () => void> = {\n      ArrowLeft: () => pan(-step, 0),\n      ArrowRight: () => pan(step, 0),\n      ArrowUp: () => pan(0, -step),\n      ArrowDown: () => pan(0, step),\n      \"+\": () => { if (zoomBy(1)) sfx(\"increment\") },\n      \"=\": () => { if (zoomBy(1)) sfx(\"increment\") },\n      \"-\": () => { if (zoomBy(-1)) sfx(\"decrement\") },\n      _: () => { if (zoomBy(-1)) sfx(\"decrement\") },\n      \"0\": () => move((now) => ({ ...now, zoom: START_ZOOM })),\n      Home: () => centerOn(city.you),\n      w: () => {\n        const id = (event.target as Element).closest(\"[data-grid-pin]\")?.getAttribute(\"data-marker\")\n        setWaypoint(markers.find((marker) => marker.id === id) ?? selected)\n      },\n    }\n    const act = keys[event.key.length === 1 ? event.key.toLowerCase() : event.key]\n    if (!act) return\n    event.preventDefault()\n    act()\n  }\n\n  const percent = Math.round(zooms[view.zoom] * 100)\n  const route = pathOf(waypoint.route)\n\n  const picker = (\n    <div data-grid-picker=\"\">\n      <SegmentedControl fill label=\"Map view\" options={mapModes} value={mode} onValueChange={chooseMode} />\n    </div>\n  )\n  if (!isDistrict) {\n    return (\n      <Screen\n        label={mode === \"globe\" ? \"Relay globe\" : \"Relay atlas\"}\n        data-grid-screen=\"\"\n        status={\n          <>\n            {picker}\n            <Readout label=\"Stations\" value={relayMarkers.length} size=\"sm\" />\n            <Readout label=\"Links\" value={relayRoutes.length} size=\"sm\" />\n          </>\n        }\n        hints={[\n          { keys: [\"←\", \"↑\", \"↓\", \"→\"], label: mode === \"globe\" ? \"Rotate\" : \"Pan\" },\n          { keys: [\"+\", \"-\"], label: \"Zoom\" },\n          { keys: \"Home\", label: \"Reset view\" },\n        ]}\n      >\n        <div data-grid-relays=\"\">\n          <Map\n            label=\"Atlantic relay network\"\n            projection={mode === \"globe\" ? \"globe\" : \"mercator\"}\n            markers={relayMarkers}\n            routes={relayRoutes}\n            annotations={mode === \"globe\" ? relayGlobeAnnotations : relayAnnotations}\n            value={relayId}\n            onValueChange={setRelayId}\n            view={relayViews[mode]}\n            onViewChange={(next) => setRelayViews((views) => ({ ...views, [mode]: next }))}\n          />\n        </div>\n      </Screen>\n    )\n  }\n  return (\n    <Screen\n      label=\"District map\"\n      data-grid-screen=\"\"\n      status={\n        <>\n          {picker}\n          <Readout label=\"Markers shown\" value={visible.length} size=\"sm\" tone=\"accent\" />\n          <Readout label=\"Route\" value={waypoint.metres} unit=\"m\" size=\"sm\" tone=\"flag\" />\n          <Readout label=\"Zoom\" value={percent} unit=\"%\" size=\"sm\" />\n        </>\n      }\n      aside={\n        <dl data-grid-now=\"\">\n          <div>\n            <dt data-kit=\"label\">Waypoint</dt>\n            <dd>\n              <Badge tone=\"flag\">{waypoint.name}</Badge>\n            </dd>\n          </div>\n          <div>\n            <dt data-kit=\"label\">In view</dt>\n            <dd data-kit=\"value\">\n              {districtAt(at.x, at.y)} {sectorAt(at.x, at.y)}\n            </dd>\n          </div>\n        </dl>\n      }\n      hints={[\n        { keys: [\"←\", \"↑\", \"↓\", \"→\"], label: \"Pan\" },\n        { keys: [\"+\", \"-\"], label: \"Zoom\" },\n        { keys: \"↵\", label: \"Select marker\" },\n        { keys: \"W\", label: \"Waypoint\" },\n        { keys: \"Home\", label: \"Find me\" },\n      ]}\n      code=\"CS-G4 // SURVEY 7741-C // SHEET 04 // LINK STABLE\"\n    >\n      <div data-kit=\"grid-map\">\n        <div ref={stage} data-grid-stage=\"\">\n          <h2 data-sr-only>Map</h2>\n          <div\n            ref={viewport}\n            data-grid-view=\"\"\n            data-dragging={dragging ? \"\" : undefined}\n            data-pan={at.tall ? \"both\" : \"across\"}\n            role=\"group\"\n            aria-label=\"District map of Lowtide and Glasswater\"\n            aria-describedby={help}\n            tabIndex={0}\n            onPointerDown={onPointerDown}\n            onPointerMove={onPointerMove}\n            onPointerUp={onPointerEnd}\n            onPointerCancel={onPointerEnd}\n            onLostPointerCapture={onPointerEnd}\n            onKeyDown={onKeyDown}\n          >\n            <p id={help} data-sr-only>\n              Arrow keys pan the map. Plus and minus zoom. Home centers on your position. W sets the waypoint to the focused or selected marker.\n              You are at Tidewall Row, {districtAt(city.you.x, city.you.y)}.\n            </p>\n            <div data-grid-world=\"\" style={{ \"--k\": at.k, \"--tx\": `${at.tx}px`, \"--ty\": `${at.ty}px` } as React.CSSProperties}>\n              <Terrain />\n              {/* Remounted for each waypoint, so the new route tears in. */}\n              <svg key={waypoint.id} data-grid-route=\"\" viewBox={`0 0 ${W} ${H}`} aria-hidden focusable=\"false\">\n                <path data-grid-route-bed=\"\" d={route} vectorEffect=\"non-scaling-stroke\" />\n                <path d={route} vectorEffect=\"non-scaling-stroke\" />\n              </svg>\n              <span data-grid-pin=\"\" data-grid-you=\"\" style={{ \"--x\": city.you.x, \"--y\": city.you.y } as React.CSSProperties} aria-hidden>\n                <svg viewBox=\"0 0 36 36\" focusable=\"false\">\n                  <path data-grid-you-ring=\"\" d=\"M18 2 32 10v16L18 34 4 26V10Z\" />\n                  <path d=\"M18 9l7 16-7-4-7 4Z\" />\n                </svg>\n              </span>\n              {visible.map((marker) => {\n                const isChosen = marker.id === selected.id\n                const isWaypoint = marker.id === waypoint.id\n                const entry = kindOf(marker.kind)\n                return (\n                  <span\n                    key={marker.id}\n                    data-grid-pin=\"\"\n                    data-marker={marker.id}\n                    data-chosen={isChosen ? \"\" : undefined}\n                    style={{ \"--x\": marker.x, \"--y\": marker.y } as React.CSSProperties}\n                  >\n                    <Reticle active={isChosen} tag={isChosen ? marker.name : undefined}>\n                      <Tooltip content={`${marker.name} · ${marker.metres} m${isWaypoint ? \" · waypoint\" : \"\"}`} side=\"bottom\">\n                        <Button\n                          icon\n                          tone={isWaypoint ? \"flag\" : \"signal\"}\n                          aria-label={`${entry.label}: ${marker.name}`}\n                          aria-pressed={isChosen}\n                          onClick={() => setChosen(marker.id)}\n                          onFocus={() => reveal(marker)}\n                        >\n                          {entry.icon}\n                        </Button>\n                      </Tooltip>\n                    </Reticle>\n                    {isWaypoint && (\n                      <span data-grid-pennant=\"\" aria-hidden>\n                        WP\n                      </span>\n                    )}\n                  </span>\n                )\n              })}\n            </div>\n            <Corners size={10} inset={8} />\n            <Micro data-grid-micro=\"top\">Survey 7741-C // 1:8000 // North up</Micro>\n            <Micro data-grid-micro=\"bottom\">Node 3F:A2 // Sheet 04 of 11 // Rev 0.1</Micro>\n          </div>\n          {/* The frame's edge, laid over the sheet so its cut corners show. */}\n          <span data-grid-edge=\"\" data-frame=\"tl br\" aria-hidden />\n\n          <div data-grid-tools=\"\">\n            <ButtonGroup\n              label=\"Map zoom\"\n              keys={[\n                { label: \"Zoom out\", icon: <Minus aria-hidden />, action: \"decrement\", disabled: view.zoom === 0, onPress: () => zoomBy(-1) },\n                {\n                  label: `Reset zoom, ${percent}%`,\n                  content: <span data-kit=\"value\">{percent}%</span>,\n                  onPress: () => move((now) => ({ ...now, zoom: START_ZOOM })),\n                },\n                { label: \"Zoom in\", icon: <Plus aria-hidden />, action: \"increment\", disabled: view.zoom === zooms.length - 1, onPress: () => zoomBy(1) },\n                { label: \"Center on my position\", icon: <LocateFixed aria-hidden />, onPress: () => centerOn(city.you) },\n              ]}\n            />\n            <Button data-grid-layers-key=\"\" aria-controls={layersId} aria-expanded={layersOpen} onClick={() => setLayersOpen((open) => !open)}>\n              <Layers aria-hidden /> Layers\n            </Button>\n          </div>\n\n          <div data-grid-rail=\"filters\" id={layersId} data-open={layersOpen ? \"\" : undefined}>\n            <Panel title=\"Filters\" code=\"OVERLAY // 4 LAYERS\" level={2}>\n              <ToggleGroup<Kind>\n                label=\"Marker kinds\"\n                multiple\n                orientation=\"vertical\"\n                value={shown}\n                onValueChange={(next) => setShown(next)}\n                options={kinds.map((entry) => ({ value: entry.value, label: entry.plural, icon: entry.icon }))}\n              />\n              <Collapsible label=\"Legend\" summary=\"10 symbols\">\n                <div role=\"list\" aria-label=\"Map legend\" data-grid-legend=\"\">\n                  {kinds.map((entry) => (\n                    <LegendRow\n                      key={entry.value}\n                      label={entry.label}\n                      value={String(markers.filter((marker) => marker.kind === entry.value).length).padStart(2, \"0\")}\n                    >\n                      {entry.icon}\n                    </LegendRow>\n                  ))}\n                  <LegendRow label=\"Waypoint\">\n                    <span data-grid-pennant=\"\">WP</span>\n                  </LegendRow>\n                  <LegendRow label=\"Route\">{stroke(<path data-grid-route-sample=\"\" d=\"M1 9H12V3H27\" />)}</LegendRow>\n                  <LegendRow label=\"Your position\">\n                    <svg data-grid-you-sample=\"\" viewBox=\"0 0 36 36\" focusable=\"false\">\n                      <path data-grid-you-ring=\"\" d=\"M18 2 32 10v16L18 34 4 26V10Z\" />\n                      <path d=\"M18 9l7 16-7-4-7 4Z\" />\n                    </svg>\n                  </LegendRow>\n                  <LegendRow label=\"Street, avenue\">\n                    {stroke(\n                      <>\n                        <path data-grid-road=\"minor\" d=\"M1 3H27\" />\n                        <path data-grid-road=\"major\" d=\"M1 9H27\" />\n                      </>,\n                    )}\n                  </LegendRow>\n                  <LegendRow label=\"Canal\">{stroke(<path data-grid-water=\"sample\" d=\"M0 6H28\" />)}</LegendRow>\n                  <LegendRow label=\"Rail\">\n                    {stroke(\n                      <>\n                        <path data-grid-track=\"ties\" d=\"M1 6H27\" />\n                        <path data-grid-track=\"\" d=\"M1 6H27\" />\n                      </>,\n                    )}\n                  </LegendRow>\n                </div>\n              </Collapsible>\n            </Panel>\n          </div>\n\n          <div data-grid-rail=\"detail\">\n            <Panel\n              title=\"Selected marker\"\n              code={`${selected.id.toUpperCase()} // SECTOR ${selected.sector} // ${onRoute ? \"ON ROUTE\" : \"OFF ROUTE\"}`}\n              tone={onRoute ? \"flag\" : \"default\"}\n              level={2}\n              actions={<Badge tone={onRoute ? \"flag\" : \"signal\"}>{kind.label}</Badge>}\n              footer={\n                <p role=\"status\">\n                  {onRoute ? \"Waypoint. The route ends here.\" : `The route runs to ${waypoint.name}.`}\n                </p>\n              }\n            >\n              {/* Keyed by the marker, so a new selection tears in; the keys\n                  below stay mounted, and focus on them is never dropped. */}\n              <div key={selected.id} data-grid-dossier=\"\">\n                <h3 data-grid-title=\"\">{selected.name}</h3>\n                <p data-kit=\"hint\">\n                  {selected.district}, sector {selected.sector}\n                </p>\n                <p>{selected.text}</p>\n              </div>\n              <div data-grid-figures=\"\">\n                <Readout label=\"Distance\" value={selected.metres} unit=\"m\" tone={onRoute ? \"flag\" : \"signal\"} />\n                <Readout label=\"On foot\" value={Math.max(1, Math.round(selected.metres / 80))} unit=\"min\" size=\"sm\" />\n                <dl data-grid-fact=\"\">\n                  <dt data-kit=\"label\">{selected.fact[0]}</dt>\n                  <dd data-kit=\"value\">{selected.fact[1]}</dd>\n                </dl>\n              </div>\n              <div data-grid-actions=\"\">\n                <Button size=\"sm\" onClick={() => {\n                  centerOn(selected)\n                  viewport.current?.focus({ preventScroll: true })\n                  viewport.current?.scrollIntoView({ block: \"nearest\", inline: \"nearest\" })\n                }}>\n                  <LocateFixed aria-hidden />\n                  Show on map\n                </Button>\n                {/* A flag key that's off keeps its solid yellow under the hatching,\n                    which leaves its label unreadable; off, it's a plain key. */}\n                <Button size=\"sm\" tone={onRoute ? \"secondary\" : \"flag\"} disabled={onRoute} focusableWhenDisabled onClick={() => setWaypoint(selected)}>\n                  <Navigation aria-hidden />\n                  Set waypoint\n                </Button>\n              </div>\n            </Panel>\n\n            <Panel title=\"Current location\" code=\"FIX 3 OF 3 // DRIFT 0.4 M\" tone=\"signal\" level={2}>\n              <p data-grid-here=\"\">\n                Tidewall Row\n                <span data-kit=\"hint\">\n                  {districtAt(city.you.x, city.you.y)}, sector {sectorAt(city.you.x, city.you.y)}\n                </span>\n              </p>\n              <dl data-grid-fact=\"\">\n                <dt data-kit=\"label\">Local time</dt>\n                <dd data-kit=\"value\" data-grid-time=\"\">\n                  {time}\n                </dd>\n              </dl>\n            </Panel>\n          </div>\n        </div>\n      </div>\n    </Screen>\n  )\n}\n",
      "type": "registry:component",
      "target": "@components/blocks/grid/grid.tsx"
    }
  ],
  "categories": [
    "screen"
  ],
  "type": "registry:block"
}
