{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "map-route-replay",
  "type": "registry:component",
  "title": "Map Route Replay",
  "description": "A procedural isometric city on canvas where a run replays as a glowing runner with a fading trail and kilometre markers. A time-of-day slider moves the sun, its shadows and the sky tint.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "maps",
    "map",
    "route",
    "replay",
    "isometric",
    "running",
    "canvas"
  ],
  "docs": "https://hyperblur.dev/effects/map-route-replay",
  "files": [
    {
      "path": "registry/hyperblur/map-route-replay.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/map-route-replay.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MapRouteReplayProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onProgress\" | \"children\"> {\n  accent?: string;\n  routeSeed?: number;\n  distanceKm?: number;\n  durationSec?: number;\n  autoplay?: boolean;\n  loop?: boolean;\n  paceSecPerKm?: number;\n  hour?: number;\n  defaultHour?: number;\n  onHourChange?: (hour: number) => void;\n  onProgress?: (progress: number, km: number) => void;\n  label?: string;\n}\n\ntype Pt = [number, number];\ntype C3 = [number, number, number];\ntype Box = { x0: number; y0: number; x1: number; y1: number; h: number; t: number; id: number };\ntype Cell = { i: number; j: number; k: number };\ntype City = { n: number; seed: number; boxes: Box[]; cells: Cell[]; trees: Pt[]; ave: [Pt, Pt] };\ntype View = { k: number; ox: number; oy: number; c: number; cos: number; sin: number; zs: number };\ntype Light = { ux: number; uy: number; el: number; night: number; warm: number };\n\nconst GRID = 14;\nconst ANGLE = 0.52;\nconst RW = 0.42;\nconst SAMPLES = 720;\nconst MONO = \"ui-monospace, SFMono-Regular, Menlo, monospace\";\nconst NORMALS: Pt[] = [\n  [0, -1],\n  [1, 0],\n  [0, 1],\n  [-1, 0],\n];\nconst DIRS: Pt[] = [\n  [1, 0],\n  [0, 1],\n  [-1, 0],\n  [0, -1],\n];\nconst RM_QUERY = \"(prefers-reduced-motion: reduce)\";\n\nfunction mix32(n: number) {\n  let x = n | 0;\n  x = Math.imul(x ^ (x >>> 16), 0x7feb352d);\n  x = Math.imul(x ^ (x >>> 15), 0x846ca68b);\n  x ^= x >>> 16;\n  return (x >>> 0) / 4294967296;\n}\n\nfunction rnd(seed: number, a: number, b = 0, c = 0) {\n  return mix32(seed * 374761393 + a * 668265263 + b * 2246822519 + c * 3266489917 + 1013904223);\n}\n\nfunction riverY(x: number, n: number, seed: number) {\n  return n * 0.72 + Math.sin(x * 0.42 + seed * 0.7) * 1.25 + Math.sin(x * 0.93 + seed) * 0.32;\n}\n\nfunction buildCity(n: number, seed: number): City {\n  const boxes: Box[] = [];\n  const cells: Cell[] = [];\n  const trees: Pt[] = [];\n  const pi = 2 + Math.floor(rnd(seed, 1) * 3);\n  const pj = 2 + Math.floor(rnd(seed, 2) * 2);\n  const a: Pt = [0, n * (0.1 + rnd(seed, 3) * 0.08)];\n  const b: Pt = [n, n * (0.4 + rnd(seed, 4) * 0.1)];\n  const ax = b[0] - a[0];\n  const ay = b[1] - a[1];\n  const al = Math.hypot(ax, ay);\n  const dcx = n * 0.56;\n  const dcy = n * 0.42;\n  let id = 0;\n  for (let j = 0; j < n; j++) {\n    for (let i = 0; i < n; i++) {\n      const cx = i + 0.5;\n      const cy = j + 0.5;\n      const dr = Math.abs(cy - riverY(cx, n, seed));\n      if (dr < RW + 0.08) continue;\n      if (dr < 0.95) {\n        cells.push({ i, j, k: 2 });\n        for (let q = 0; q < 3; q++) {\n          const tx = i + 0.2 + rnd(seed, i, j, q * 2 + 40) * 0.6;\n          const ty = j + 0.2 + rnd(seed, i, j, q * 2 + 41) * 0.6;\n          if (Math.abs(ty - riverY(tx, n, seed)) > RW + 0.14) trees.push([tx, ty]);\n        }\n        continue;\n      }\n      if (i >= pi && i < pi + 3 && j >= pj && j < pj + 2) {\n        cells.push({ i, j, k: 1 });\n        for (let q = 0; q < 6; q++) {\n          trees.push([i + 0.2 + rnd(seed, i, j, q * 2 + 60) * 0.6, j + 0.2 + rnd(seed, i, j, q * 2 + 61) * 0.6]);\n        }\n        continue;\n      }\n      const da = Math.abs((cx - a[0]) * ay - (cy - a[1]) * ax) / al;\n      if (da < 0.66) {\n        cells.push({ i, j, k: 3 });\n        if (rnd(seed, i, j, 70) < 0.6) trees.push([cx + (rnd(seed, i, j, 71) - 0.5) * 0.5, cy + (rnd(seed, i, j, 72) - 0.5) * 0.5]);\n        continue;\n      }\n      cells.push({ i, j, k: 0 });\n      const s = 0.16;\n      const g = 0.05;\n      const x0 = i + s;\n      const y0 = j + s;\n      const x1 = i + 1 - s;\n      const y1 = j + 1 - s;\n      const r = rnd(seed, i, j, 7);\n      const lots: [number, number, number, number][] = [];\n      if (r < 0.34) {\n        lots.push([x0, y0, x1, y1]);\n      } else if (r < 0.72) {\n        const m = 0.4 + rnd(seed, i, j, 8) * 0.2;\n        if (rnd(seed, i, j, 9) < 0.5) {\n          const xm = x0 + (x1 - x0) * m;\n          lots.push([x0, y0, xm - g / 2, y1], [xm + g / 2, y0, x1, y1]);\n        } else {\n          const ym = y0 + (y1 - y0) * m;\n          lots.push([x0, y0, x1, ym - g / 2], [x0, ym + g / 2, x1, y1]);\n        }\n      } else {\n        const xm = (x0 + x1) / 2;\n        const ym = (y0 + y1) / 2;\n        lots.push(\n          [x0, y0, xm - g / 2, ym - g / 2],\n          [xm + g / 2, y0, x1, ym - g / 2],\n          [x0, ym + g / 2, xm - g / 2, y1],\n          [xm + g / 2, ym + g / 2, x1, y1],\n        );\n      }\n      const core = Math.exp(-((cx - dcx) ** 2 + (cy - dcy) ** 2) / 16);\n      lots.forEach((l, q) => {\n        const u = rnd(seed, i, j, 20 + q);\n        let h = 0.08 + core * (0.3 + u * 1.05) + rnd(seed, i, j, 30 + q) * 0.12;\n        if (u > 0.9 && core > 0.4) h *= 1.5;\n        boxes.push({ x0: l[0], y0: l[1], x1: l[2], y1: l[3], h: Math.min(2.6, h), t: rnd(seed, i, j, 50 + q), id: id++ });\n      });\n    }\n  }\n  return { n, seed, boxes, cells, trees, ave: [a, b] };\n}\n\nfunction buildRoute(seed: number, n: number): Pt[] {\n  const lo = 4;\n  const hi = n - 4;\n  const wet = (x: number, y: number) => Math.abs(y - riverY(x, n, seed)) < RW + 0.1;\n  for (let attempt = 0; attempt < 40; attempt++) {\n    const sx = lo + Math.floor(rnd(seed, 11, attempt) * (hi - lo + 1));\n    const sy = lo + Math.floor(rnd(seed, 12, attempt) * (hi - lo + 1));\n    if (wet(sx, sy)) continue;\n    const pts: Pt[] = [[sx, sy]];\n    const seen = new Set<number>([sx * 100 + sy]);\n    let dir = Math.floor(rnd(seed, 13, attempt) * 4);\n    let total = 0;\n    for (let step = 0; step < 48 && total < 20; step++) {\n      const r = rnd(seed, step, attempt, 5);\n      const order = r < 0.4 ? [0, 1, 3] : r < 0.7 ? [1, 0, 3] : [3, 0, 1];\n      const len = 1 + Math.floor(rnd(seed, step, attempt, 6) * 3);\n      let moved = 0;\n      for (const o of order) {\n        const d = (dir + o) % 4;\n        const [dx, dy] = DIRS[d];\n        let [cx, cy] = pts[pts.length - 1];\n        let count = 0;\n        for (let q = 0; q < len; q++) {\n          const nx = cx + dx;\n          const ny = cy + dy;\n          if (nx < lo || nx > hi || ny < lo || ny > hi) break;\n          if (seen.has(nx * 100 + ny) || wet(nx, ny)) break;\n          if (dy === 0 && wet(cx + dx / 2, cy)) break;\n          seen.add(nx * 100 + ny);\n          pts.push([nx, ny]);\n          cx = nx;\n          cy = ny;\n          count++;\n        }\n        if (count > 0) {\n          moved = count;\n          dir = d;\n          break;\n        }\n      }\n      if (!moved) break;\n      total += moved;\n    }\n    if (total >= 14) {\n      const out: Pt[] = [pts[0]];\n      for (let q = 1; q < pts.length - 1; q++) {\n        const p = out[out.length - 1];\n        const c = pts[q];\n        const nx = pts[q + 1];\n        const straight = (c[0] - p[0]) * (nx[1] - c[1]) - (c[1] - p[1]) * (nx[0] - c[0]) === 0;\n        if (!straight) out.push(c);\n      }\n      out.push(pts[pts.length - 1]);\n      return out;\n    }\n  }\n  return [\n    [lo, lo],\n    [hi, lo],\n    [hi, lo + 2],\n    [lo + 1, lo + 2],\n    [lo + 1, hi - 1],\n    [hi, hi - 1],\n  ];\n}\n\nfunction sampleRoute(pts: Pt[], count: number): Pt[] {\n  const dense: Pt[] = [pts[0]];\n  for (let i = 1; i < pts.length - 1; i++) {\n    const a = pts[i - 1];\n    const p = pts[i];\n    const b = pts[i + 1];\n    const la = Math.hypot(p[0] - a[0], p[1] - a[1]);\n    const lb = Math.hypot(b[0] - p[0], b[1] - p[1]);\n    const ra = Math.min(0.3, la / 2);\n    const rb = Math.min(0.3, lb / 2);\n    const p1: Pt = [p[0] - ((p[0] - a[0]) / la) * ra, p[1] - ((p[1] - a[1]) / la) * ra];\n    const p2: Pt = [p[0] + ((b[0] - p[0]) / lb) * rb, p[1] + ((b[1] - p[1]) / lb) * rb];\n    for (let q = 0; q <= 8; q++) {\n      const t = q / 8;\n      const u = 1 - t;\n      dense.push([u * u * p1[0] + 2 * u * t * p[0] + t * t * p2[0], u * u * p1[1] + 2 * u * t * p[1] + t * t * p2[1]]);\n    }\n  }\n  dense.push(pts[pts.length - 1]);\n  const acc = [0];\n  for (let i = 1; i < dense.length; i++) {\n    acc.push(acc[i - 1] + Math.hypot(dense[i][0] - dense[i - 1][0], dense[i][1] - dense[i - 1][1]));\n  }\n  const total = acc[acc.length - 1];\n  const out: Pt[] = [];\n  let seg = 1;\n  for (let q = 0; q < count; q++) {\n    const d = (q / (count - 1)) * total;\n    while (seg < dense.length - 1 && acc[seg] < d) seg++;\n    const span = acc[seg] - acc[seg - 1] || 1;\n    const t = Math.min(1, Math.max(0, (d - acc[seg - 1]) / span));\n    out.push([\n      dense[seg - 1][0] + (dense[seg][0] - dense[seg - 1][0]) * t,\n      dense[seg - 1][1] + (dense[seg][1] - dense[seg - 1][1]) * t,\n    ]);\n  }\n  return out;\n}\n\nfunction proj(v: View, x: number, y: number, z: number): Pt {\n  const dx = x - v.c;\n  const dy = y - v.c;\n  const rx = dx * v.cos - dy * v.sin;\n  const ry = dx * v.sin + dy * v.cos;\n  return [v.ox + (rx - ry) * v.k * 0.866, v.oy + (rx + ry) * v.k * 0.5 - z * v.k * 0.82 * v.zs];\n}\n\nfunction lightAt(hour: number): Light {\n  const t = Math.min(1, Math.max(0, (hour - 6) / 12));\n  const phi = -Math.PI / 4 + t * Math.PI;\n  return {\n    ux: Math.cos(phi),\n    uy: Math.sin(phi),\n    el: Math.sin(Math.PI * t) * 1.05,\n    night: Math.min(1, Math.max(0, (6.7 - hour) / 0.9, (hour - 18.4) / 0.9)),\n    warm: Math.min(1, Math.max(0, 1 - Math.abs(hour - 7) / 1.7, 1 - Math.abs(hour - 17.7) / 1.9)),\n  };\n}\n\nfunction mixc(a: C3, b: C3, t: number): C3 {\n  return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];\n}\n\nfunction shade(a: C3, m: number, b: C3, t: number): C3 {\n  return [Math.min(255, a[0] * m + b[0] * t), Math.min(255, a[1] * m + b[1] * t), Math.min(255, a[2] * m + b[2] * t)];\n}\n\nfunction rgba(c: C3, a = 1) {\n  return `rgba(${Math.round(c[0])},${Math.round(c[1])},${Math.round(c[2])},${a.toFixed(3)})`;\n}\n\nfunction quad(ctx: CanvasRenderingContext2D, p: Pt[]) {\n  ctx.moveTo(p[0][0], p[0][1]);\n  for (let i = 1; i < p.length; i++) ctx.lineTo(p[i][0], p[i][1]);\n  ctx.closePath();\n}\n\nfunction hull(points: Pt[]): Pt[] {\n  const p = points.slice().sort((a, b) => a[0] - b[0] || a[1] - b[1]);\n  const cross = (o: Pt, a: Pt, b: Pt) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);\n  const lower: Pt[] = [];\n  for (const q of p) {\n    while (lower.length >= 2 && cross(lower[lower.length - 2], lower[lower.length - 1], q) <= 0) lower.pop();\n    lower.push(q);\n  }\n  const upper: Pt[] = [];\n  for (let i = p.length - 1; i >= 0; i--) {\n    const q = p[i];\n    while (upper.length >= 2 && cross(upper[upper.length - 2], upper[upper.length - 1], q) <= 0) upper.pop();\n    upper.push(q);\n  }\n  return lower.slice(0, -1).concat(upper.slice(0, -1));\n}\n\nfunction parseColor(ctx: CanvasRenderingContext2D, value: string, fb: C3): C3 {\n  ctx.fillStyle = \"#000000\";\n  ctx.fillStyle = value;\n  const v = String(ctx.fillStyle);\n  if (v[0] === \"#\" && v.length === 7) {\n    return [parseInt(v.slice(1, 3), 16), parseInt(v.slice(3, 5), 16), parseInt(v.slice(5, 7), 16)];\n  }\n  const m = v.match(/[\\d.]+/g);\n  return m && m.length >= 3 ? [Number(m[0]), Number(m[1]), Number(m[2])] : fb;\n}\n\nfunction drawLayer(g: CanvasRenderingContext2D, bl: CanvasRenderingContext2D, w: number, h: number, city: City, v: View, L: Light, acc: C3) {\n  let ctx = g;\n  const n = city.n;\n  const P = (x: number, y: number, z = 0) => proj(v, x, y, z);\n  const nt = L.night;\n  const day = 1 - nt;\n  const wm = L.warm * day;\n  const sun = mixc([255, 238, 214], [255, 138, 78], wm);\n\n  const sky = ctx.createLinearGradient(0, 0, 0, h);\n  sky.addColorStop(0, rgba(mixc(mixc([15, 20, 32], [38, 20, 30], wm), [5, 7, 14], nt)));\n  sky.addColorStop(1, rgba(mixc(mixc([8, 10, 16], [22, 12, 15], wm), [3, 4, 8], nt)));\n  ctx.fillStyle = sky;\n  ctx.fillRect(0, 0, w, h);\n\n  const ground = mixc(mixc([17, 20, 29], [26, 20, 25], wm * 0.6), [9, 11, 18], nt);\n  ctx.beginPath();\n  quad(ctx, [P(0, 0), P(n, 0), P(n, n), P(0, n)]);\n  ctx.fillStyle = rgba(ground);\n  ctx.fill();\n\n  ctx.beginPath();\n  for (let i = 0; i <= n; i++) {\n    const a = P(i, 0);\n    const b = P(i, n);\n    const c = P(0, i);\n    const d = P(n, i);\n    ctx.moveTo(a[0], a[1]);\n    ctx.lineTo(b[0], b[1]);\n    ctx.moveTo(c[0], c[1]);\n    ctx.lineTo(d[0], d[1]);\n  }\n  ctx.strokeStyle = \"rgba(255,255,255,0.035)\";\n  ctx.lineWidth = 1;\n  ctx.stroke();\n\n  const kinds: C3[] = [\n    mixc([25, 29, 40], [12, 14, 22], nt),\n    mixc([20, 41, 33], [9, 21, 18], nt),\n    mixc([20, 34, 30], [10, 18, 17], nt),\n    mixc([23, 26, 35], [11, 13, 20], nt),\n  ];\n  for (let kind = 0; kind < 4; kind++) {\n    ctx.beginPath();\n    for (const c of city.cells) {\n      if (c.k !== kind) continue;\n      const m = kind === 0 ? 0.1 : 0.06;\n      quad(ctx, [P(c.i + m, c.j + m), P(c.i + 1 - m, c.j + m), P(c.i + 1 - m, c.j + 1 - m), P(c.i + m, c.j + 1 - m)]);\n    }\n    ctx.fillStyle = rgba(kinds[kind]);\n    ctx.fill();\n  }\n\n  const [aa, ab] = city.ave;\n  const al = Math.hypot(ab[0] - aa[0], ab[1] - aa[1]);\n  const nx = (-(ab[1] - aa[1]) / al) * 0.17;\n  const ny = ((ab[0] - aa[0]) / al) * 0.17;\n  ctx.beginPath();\n  quad(ctx, [P(aa[0] + nx, aa[1] + ny), P(ab[0] + nx, ab[1] + ny), P(ab[0] - nx, ab[1] - ny), P(aa[0] - nx, aa[1] - ny)]);\n  ctx.fillStyle = rgba(ground);\n  ctx.fill();\n  ctx.beginPath();\n  const s0 = P(aa[0], aa[1]);\n  const s1 = P(ab[0], ab[1]);\n  ctx.moveTo(s0[0], s0[1]);\n  ctx.lineTo(s1[0], s1[1]);\n  ctx.setLineDash([4, 5]);\n  ctx.strokeStyle = \"rgba(255,255,255,0.07)\";\n  ctx.stroke();\n  ctx.setLineDash([]);\n\n  const water = mixc(mixc([13, 31, 56], [30, 30, 52], wm * 0.5), [7, 15, 31], nt);\n  const top: Pt[] = [];\n  const bot: Pt[] = [];\n  for (let x = 0; x <= n + 0.001; x += 0.25) {\n    const y = riverY(x, n, city.seed);\n    top.push(P(x, y - RW));\n    bot.push(P(x, y + RW));\n  }\n  ctx.beginPath();\n  quad(ctx, top.concat(bot.reverse()));\n  ctx.fillStyle = rgba(water);\n  ctx.fill();\n  ctx.beginPath();\n  top.forEach((p, i) => (i ? ctx.lineTo(p[0], p[1]) : ctx.moveTo(p[0], p[1])));\n  bot.forEach((p, i) => (i ? ctx.lineTo(p[0], p[1]) : ctx.moveTo(p[0], p[1])));\n  ctx.strokeStyle = rgba(mixc([110, 160, 255], sun, wm * 0.5), 0.16);\n  ctx.stroke();\n  ctx.beginPath();\n  for (let i = 1; i < n; i++) {\n    const y = riverY(i, n, city.seed);\n    quad(ctx, [P(i - 0.09, y - RW - 0.06), P(i + 0.09, y - RW - 0.06), P(i + 0.09, y + RW + 0.06), P(i - 0.09, y + RW + 0.06)]);\n  }\n  ctx.fillStyle = rgba(mixc(ground, [60, 66, 80], 0.25));\n  ctx.fill();\n\n  const tr = v.k * 0.075;\n  ctx.beginPath();\n  for (const t of city.trees) {\n    const p = P(t[0] + 0.04, t[1] + 0.04);\n    ctx.moveTo(p[0] + tr, p[1]);\n    ctx.arc(p[0], p[1], tr, 0, Math.PI * 2);\n  }\n  ctx.fillStyle = \"rgba(0,0,0,0.3)\";\n  ctx.fill();\n  ctx.beginPath();\n  for (const t of city.trees) {\n    const p = P(t[0], t[1], 0.08);\n    ctx.moveTo(p[0] + tr, p[1]);\n    ctx.arc(p[0], p[1], tr, 0, Math.PI * 2);\n  }\n  ctx.fillStyle = rgba(shade(mixc([38, 84, 62], [17, 38, 31], nt), 1, sun, 0.06 * day));\n  ctx.fill();\n\n  const wx = L.ux * v.cos + L.uy * v.sin;\n  const wy = -L.ux * v.sin + L.uy * v.cos;\n  if (day > 0.02) {\n    ctx.beginPath();\n    for (const b of city.boxes) {\n      const len = Math.min(3.2, b.h / Math.tan(Math.max(0.16, L.el)));\n      const ox = -wx * len;\n      const oy = -wy * len;\n      const hp = hull([\n        P(b.x0, b.y0),\n        P(b.x1, b.y0),\n        P(b.x1, b.y1),\n        P(b.x0, b.y1),\n        P(b.x0 + ox, b.y0 + oy),\n        P(b.x1 + ox, b.y0 + oy),\n        P(b.x1 + ox, b.y1 + oy),\n        P(b.x0 + ox, b.y1 + oy),\n      ]);\n      quad(ctx, hp);\n    }\n    ctx.fillStyle = `rgba(0,0,0,${(0.34 * day).toFixed(3)})`;\n    ctx.fill();\n  }\n\n  ctx = bl;\n  const rn = NORMALS.map(([x, y]) => [x * v.cos - y * v.sin, x * v.sin + y * v.cos] as Pt);\n  const vis = rn.map((p) => p[0] + p[1] > 0.001);\n  const lam = rn.map((p) => Math.max(0, p[0] * L.ux + p[1] * L.uy));\n  const depth = (b: Box) => {\n    const dx = (b.x0 + b.x1) / 2 - v.c;\n    const dy = (b.y0 + b.y1) / 2 - v.c;\n    return dx * v.cos - dy * v.sin + dx * v.sin + dy * v.cos;\n  };\n  const sorted = city.boxes.slice().sort((a, b) => depth(a) - depth(b));\n  const topBase = mixc([44, 51, 68], [20, 24, 37], nt);\n  const sideBase = mixc([28, 33, 46], [12, 15, 25], nt);\n  const sunTop = 0.06 + Math.sin(L.el) * 0.16;\n  for (const b of sorted) {\n    const c: Pt[] = [\n      [b.x0, b.y0],\n      [b.x1, b.y0],\n      [b.x1, b.y1],\n      [b.x0, b.y1],\n    ];\n    const tone = 0.88 + b.t * 0.24;\n    for (let e = 0; e < 4; e++) {\n      if (!vis[e]) continue;\n      const p = c[e];\n      const q = c[(e + 1) % 4];\n      ctx.beginPath();\n      quad(ctx, [P(p[0], p[1]), P(q[0], q[1]), P(q[0], q[1], b.h), P(p[0], p[1], b.h)]);\n      ctx.fillStyle = rgba(shade(sideBase, tone * (e % 2 ? 0.92 : 1.05), sun, lam[e] * 0.36 * day));\n      ctx.fill();\n      if (nt > 0.05) {\n        const floors = Math.floor((b.h - 0.08) / 0.14);\n        const cols = Math.max(1, Math.round(Math.hypot(q[0] - p[0], q[1] - p[1]) / 0.12));\n        ctx.fillStyle = `rgba(255,196,120,${(0.85 * nt).toFixed(3)})`;\n        for (let f = 0; f < floors; f++) {\n          for (let k = 0; k < cols; k++) {\n            if (rnd(city.seed, b.id, e * 37 + f, k) > 0.34) continue;\n            const u = (k + 0.5) / cols;\n            const w0 = P(p[0] + (q[0] - p[0]) * u, p[1] + (q[1] - p[1]) * u, 0.12 + f * 0.14);\n            ctx.fillRect(w0[0] - 0.7, w0[1] - 0.6, 1.4, 1.2);\n          }\n        }\n      }\n    }\n    ctx.beginPath();\n    quad(ctx, c.map((p) => P(p[0], p[1], b.h)));\n    ctx.fillStyle = rgba(shade(topBase, tone, sun, sunTop * day));\n    ctx.fill();\n    ctx.strokeStyle = `rgba(255,255,255,${(0.05 + 0.04 * day).toFixed(3)})`;\n    ctx.lineWidth = 0.6;\n    ctx.stroke();\n    if (b.h > 1.5 && nt > 0.3) {\n      const r = P((b.x0 + b.x1) / 2, (b.y0 + b.y1) / 2, b.h + 0.05);\n      ctx.beginPath();\n      ctx.arc(r[0], r[1], 1.4, 0, Math.PI * 2);\n      ctx.fillStyle = rgba(acc, nt);\n      ctx.fill();\n    }\n  }\n\n  const gx = L.ux - L.uy;\n  const gy = L.ux + L.uy;\n  const gl = Math.hypot(gx, gy) || 1;\n  const glow = ctx.createRadialGradient(w / 2 + (gx / gl) * w * 0.55, h / 2 + (gy / gl) * h * 0.75, 0, w / 2 + (gx / gl) * w * 0.55, h / 2 + (gy / gl) * h * 0.75, Math.max(w, h) * 0.7);\n  glow.addColorStop(0, rgba(sun, 0.1 * day + 0.08 * wm));\n  glow.addColorStop(1, rgba(sun, 0));\n  ctx.globalCompositeOperation = \"lighter\";\n  ctx.fillStyle = glow;\n  ctx.fillRect(0, 0, w, h);\n  if (nt > 0) {\n    const moon = ctx.createRadialGradient(w * 0.15, -h * 0.1, 0, w * 0.15, -h * 0.1, Math.max(w, h) * 0.8);\n    moon.addColorStop(0, `rgba(90,120,200,${(0.1 * nt).toFixed(3)})`);\n    moon.addColorStop(1, \"rgba(90,120,200,0)\");\n    ctx.fillStyle = moon;\n    ctx.fillRect(0, 0, w, h);\n  }\n  ctx.globalCompositeOperation = \"source-over\";\n  const vg = ctx.createRadialGradient(w / 2, h / 2, Math.min(w, h) * 0.35, w / 2, h / 2, Math.max(w, h) * 0.75);\n  vg.addColorStop(0, \"rgba(4,5,8,0)\");\n  vg.addColorStop(1, \"rgba(4,5,8,0.6)\");\n  ctx.fillStyle = vg;\n  ctx.fillRect(0, 0, w, h);\n}\n\nfunction fitView(route: Pt[], w: number, h: number, n: number): View {\n  const base: View = { k: 1, ox: 0, oy: 0, c: n / 2, cos: Math.cos(ANGLE), sin: Math.sin(ANGLE), zs: h < 260 ? 0.62 : 1 };\n  let minX = Infinity;\n  let maxX = -Infinity;\n  let minY = Infinity;\n  let maxY = -Infinity;\n  for (let i = 0; i < route.length; i += 8) {\n    const p = proj(base, route[i][0], route[i][1], 0);\n    minX = Math.min(minX, p[0]);\n    maxX = Math.max(maxX, p[0]);\n    minY = Math.min(minY, p[1]);\n    maxY = Math.max(maxY, p[1]);\n  }\n  minY -= 0.9;\n  const padX = Math.min(40, w * 0.08);\n  const top = h < 260 ? 40 : 64;\n  const bottom = h < 260 ? 44 : 64;\n  const k = Math.max(8, Math.min((w - padX * 2) / (maxX - minX), (h - top - bottom) / (maxY - minY), Math.min(w, h) / 4.5));\n  return {\n    ...base,\n    k,\n    ox: padX + (w - padX * 2 - (maxX - minX) * k) / 2 - minX * k,\n    oy: top + (h - top - bottom - (maxY - minY) * k) / 2 - minY * k,\n  };\n}\n\nfunction easeBack(x: number) {\n  const c = 1.70158;\n  return 1 + (c + 1) * Math.pow(x - 1, 3) + c * Math.pow(x - 1, 2);\n}\n\nfunction clock(sec: number) {\n  const s = Math.max(0, Math.round(sec));\n  const h = Math.floor(s / 3600);\n  const m = Math.floor((s % 3600) / 60);\n  const r = s % 60;\n  const mm = String(m).padStart(h ? 2 : 1, \"0\");\n  return `${h ? `${h}:` : \"\"}${mm}:${String(r).padStart(2, \"0\")}`;\n}\n\nfunction fmtHour(hour: number) {\n  const h = Math.floor(hour);\n  const m = Math.round((hour - h) * 60);\n  return `${String(h).padStart(2, \"0\")}:${String(m).padStart(2, \"0\")}`;\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(RM_QUERY);\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\nconst css = `\n.hb-ub1 {\n  --hb-ub1-a: #ff4d4d;\n  --hb-ub1-p: 0%;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  aspect-ratio: 16 / 10;\n  min-height: 180px;\n  overflow: hidden;\n  isolation: isolate;\n  border-radius: 14px;\n  border: 1px solid rgba(255, 255, 255, 0.09);\n  background: #07090d;\n  color: #ededed;\n  font-family: inherit;\n  container-type: inline-size;\n}\n.hb-ub1 *, .hb-ub1 *::before, .hb-ub1 *::after { box-sizing: border-box; }\n.hb-ub1-cv { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }\n.hb-ub1-glass {\n  position: absolute;\n  background: rgba(9, 10, 13, 0.66);\n  border: 1px solid rgba(255, 255, 255, 0.08);\n  -webkit-backdrop-filter: blur(10px);\n  backdrop-filter: blur(10px);\n}\n.hb-ub1-hud {\n  left: 10px;\n  top: 10px;\n  display: flex;\n  flex-direction: column;\n  gap: 3px;\n  padding: 7px 11px 8px;\n  border-radius: 10px;\n  pointer-events: none;\n}\n.hb-ub1-k {\n  display: flex;\n  align-items: center;\n  gap: 6px;\n  font: 600 9px/1 ${MONO};\n  letter-spacing: 0.14em;\n  text-transform: uppercase;\n  color: #8f8f8f;\n}\n.hb-ub1-k::before {\n  content: \"\";\n  width: 6px;\n  height: 6px;\n  border-radius: 50%;\n  background: var(--hb-ub1-a);\n  box-shadow: 0 0 8px var(--hb-ub1-a);\n}\n.hb-ub1-km { display: flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }\n.hb-ub1-km b { font-size: 19px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }\n.hb-ub1-km span, .hb-ub1-sub { font-size: 10.5px; color: #a1a1a1; white-space: nowrap; font-variant-numeric: tabular-nums; }\n.hb-ub1-sun {\n  right: 10px;\n  top: 10px;\n  display: flex;\n  align-items: center;\n  gap: 7px;\n  height: 30px;\n  padding: 0 10px;\n  border-radius: 999px;\n}\n.hb-ub1-sun svg { flex: none; width: 14px; height: 14px; color: #ffc27a; }\n.hb-ub1-sun[data-night=\"true\"] svg { color: #a9c2ff; }\n.hb-ub1-hr { min-width: 34px; font: 500 10px/1 ${MONO}; color: #ededed; text-align: right; font-variant-numeric: tabular-nums; }\n.hb-ub1-bar {\n  left: 10px;\n  right: 10px;\n  bottom: 10px;\n  display: flex;\n  align-items: center;\n  gap: 10px;\n  height: 38px;\n  padding: 0 12px 0 5px;\n  border-radius: 999px;\n}\n.hb-ub1-play {\n  flex: none;\n  display: grid;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: #ededed;\n  color: #0a0a0a;\n  cursor: pointer;\n  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease;\n}\n.hb-ub1-play:hover { transform: scale(1.07); background: #fff; }\n.hb-ub1-play:active { transform: scale(0.95); }\n.hb-ub1-play svg { width: 12px; height: 12px; }\n.hb-ub1-range {\n  --hb-ub1-f: 0%;\n  --hb-ub1-tc: var(--hb-ub1-a);\n  -webkit-appearance: none;\n  appearance: none;\n  min-width: 0;\n  height: 18px;\n  margin: 0;\n  padding: 0;\n  background: transparent;\n  cursor: pointer;\n}\n.hb-ub1-scrub { flex: 1; --hb-ub1-f: var(--hb-ub1-p); }\n.hb-ub1-hour { width: 64px; --hb-ub1-tc: #ffc27a; }\n.hb-ub1-range::-webkit-slider-runnable-track {\n  height: 3px;\n  border-radius: 3px;\n  background: linear-gradient(90deg, var(--hb-ub1-tc) var(--hb-ub1-f), rgba(255, 255, 255, 0.16) var(--hb-ub1-f));\n}\n.hb-ub1-range::-moz-range-track {\n  height: 3px;\n  border-radius: 3px;\n  background: linear-gradient(90deg, var(--hb-ub1-tc) var(--hb-ub1-f), rgba(255, 255, 255, 0.16) var(--hb-ub1-f));\n}\n.hb-ub1-range::-webkit-slider-thumb {\n  -webkit-appearance: none;\n  appearance: none;\n  width: 12px;\n  height: 12px;\n  margin-top: -4.5px;\n  border: 2px solid var(--hb-ub1-tc);\n  border-radius: 50%;\n  background: #fff;\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-ub1-tc) 26%, transparent);\n  transition: transform 0.15s ease;\n}\n.hb-ub1-range::-moz-range-thumb {\n  width: 8px;\n  height: 8px;\n  border: 2px solid var(--hb-ub1-tc);\n  border-radius: 50%;\n  background: #fff;\n  box-shadow: 0 0 0 3px color-mix(in srgb, var(--hb-ub1-tc) 26%, transparent);\n}\n.hb-ub1-range:active::-webkit-slider-thumb { transform: scale(1.2); }\n.hb-ub1-play:focus-visible, .hb-ub1-range:focus-visible { outline: 2px solid var(--hb-ub1-a); outline-offset: 3px; border-radius: 999px; }\n.hb-ub1-pct { flex: none; min-width: 30px; font: 500 10px/1 ${MONO}; color: #a1a1a1; text-align: right; font-variant-numeric: tabular-nums; }\n@container (max-width: 400px) {\n  .hb-ub1-km b { font-size: 16px; }\n  .hb-ub1-hour { width: 50px; }\n  .hb-ub1-pct { display: none; }\n  .hb-ub1-bar { height: 34px; }\n  .hb-ub1-play { width: 24px; height: 24px; }\n}\n@container (max-width: 300px) {\n  .hb-ub1-sub { display: none; }\n  .hb-ub1-hr { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-ub1-play, .hb-ub1-range::-webkit-slider-thumb { transition: none; }\n}\n`;\n\ntype Api = { draw: () => void; relayer: () => void; kick: () => void; seek: (p: number) => void; progress: () => number };\n\nexport function MapRouteReplay({\n  accent = \"#ff4d4d\",\n  routeSeed = 7,\n  distanceKm = 8,\n  durationSec = 18,\n  autoplay = true,\n  loop = true,\n  paceSecPerKm = 312,\n  hour,\n  defaultHour = 17.5,\n  onHourChange,\n  onProgress,\n  label = \"Route replay\",\n  className = \"\",\n  style,\n  ...rest\n}: MapRouteReplayProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const scrubRef = React.useRef<HTMLInputElement>(null);\n  const kmRef = React.useRef<HTMLElement>(null);\n  const timeRef = React.useRef<HTMLSpanElement>(null);\n  const pctRef = React.useRef<HTMLSpanElement>(null);\n  const api = React.useRef<Api | null>(null);\n  const reduced = React.useSyncExternalStore(subscribeMotion, () => window.matchMedia(RM_QUERY).matches, () => false);\n  const [innerHour, setInnerHour] = React.useState(defaultHour);\n  const [playState, setPlayState] = React.useState<boolean | null>(null);\n  const hr = Math.min(21, Math.max(5, hour ?? innerHour));\n  const playing = playState ?? (autoplay && !reduced);\n  const st = React.useRef({\n    progress: 0,\n    playing: false,\n    hour: hr,\n    accent,\n    duration: durationSec,\n    loop,\n    pace: paceSecPerKm,\n    reduced: false,\n    scrubbing: false,\n    onProgress,\n  });\n\n  React.useEffect(() => {\n    const s = st.current;\n    s.accent = accent;\n    s.duration = durationSec;\n    s.loop = loop;\n    s.pace = paceSecPerKm;\n    s.onProgress = onProgress;\n    api.current?.draw();\n  }, [accent, durationSec, loop, paceSecPerKm, onProgress]);\n\n  React.useEffect(() => {\n    st.current.hour = hr;\n    api.current?.relayer();\n  }, [hr]);\n\n  React.useEffect(() => {\n    const s = st.current;\n    s.reduced = reduced;\n    if (reduced && s.progress === 0 && !s.playing) api.current?.seek(1);\n  }, [reduced]);\n\n  React.useEffect(() => {\n    st.current.playing = playing;\n    api.current?.kick();\n  }, [playing]);\n\n  React.useEffect(() => {\n    const root = rootRef.current;\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!root || !canvas || !ctx) return;\n    const s = st.current;\n    const city = buildCity(GRID, routeSeed);\n    const route = sampleRoute(buildRoute(routeSeed, GRID), SAMPLES);\n    const layer = document.createElement(\"canvas\");\n    const lctx = layer.getContext(\"2d\");\n    const blds = document.createElement(\"canvas\");\n    const bctx = blds.getContext(\"2d\");\n    if (!lctx || !bctx) return;\n    const dist = Math.max(0.5, distanceKm);\n    const passed: number[] = new Array(Math.max(0, Math.ceil(dist) - 1)).fill(-1);\n    const scr = new Float32Array(route.length * 2);\n    let w = 0;\n    let h = 0;\n    let dpr = 1;\n    let view: View | null = null;\n    let raf = 0;\n    let last = 0;\n    let hold = 0;\n    let visible = true;\n    let rgb: C3 = [255, 77, 77];\n    let rgbFor = \"\";\n\n    const report = () => {\n      const p = s.progress;\n      const km = p * dist;\n      const now = performance.now();\n      for (let k = 0; k < passed.length; k++) {\n        const f = (k + 1) / dist;\n        if (p >= f && passed[k] < 0) passed[k] = now;\n        else if (p < f) passed[k] = -1;\n      }\n      if (kmRef.current) kmRef.current.textContent = km.toFixed(2);\n      if (timeRef.current) timeRef.current.textContent = clock(km * s.pace);\n      if (pctRef.current) pctRef.current.textContent = `${Math.round(p * 100)}%`;\n      const sc = scrubRef.current;\n      if (sc) {\n        if (!s.scrubbing) sc.value = String(Math.round(p * 1000));\n        sc.setAttribute(\"aria-valuetext\", `${km.toFixed(2)} of ${dist.toFixed(2)} km`);\n      }\n      root.style.setProperty(\"--hb-ub1-p\", `${(p * 100).toFixed(2)}%`);\n      s.onProgress?.(p, km);\n    };\n\n    const relayer = () => {\n      if (!view) return;\n      if (rgbFor !== s.accent) {\n        rgb = parseColor(lctx, s.accent, [255, 77, 77]);\n        rgbFor = s.accent;\n      }\n      lctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      lctx.clearRect(0, 0, w, h);\n      bctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      bctx.clearRect(0, 0, w, h);\n      drawLayer(lctx, bctx, w, h, city, view, lightAt(s.hour), rgb);\n    };\n\n    const draw = (t = performance.now()) => {\n      if (!view) return;\n      if (rgbFor !== s.accent) relayer();\n      const A = (a: number) => `rgba(${rgb[0]},${rgb[1]},${rgb[2]},${a.toFixed(3)})`;\n      ctx.setTransform(1, 0, 0, 1, 0, 0);\n      ctx.clearRect(0, 0, canvas.width, canvas.height);\n      ctx.drawImage(layer, 0, 0);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      const M = route.length;\n      const f = s.progress * (M - 1);\n      const i0 = Math.min(M - 1, Math.floor(f));\n      const fr = f - i0;\n      const hx = i0 < M - 1 ? scr[i0 * 2] + (scr[i0 * 2 + 2] - scr[i0 * 2]) * fr : scr[i0 * 2];\n      const hy = i0 < M - 1 ? scr[i0 * 2 + 1] + (scr[i0 * 2 + 3] - scr[i0 * 2 + 1]) * fr : scr[i0 * 2 + 1];\n      ctx.lineCap = \"round\";\n      ctx.lineJoin = \"round\";\n\n      const routePass = () => {\n        if (i0 < M - 1) {\n          ctx.beginPath();\n          ctx.moveTo(hx, hy);\n          for (let i = i0 + 1; i < M; i++) ctx.lineTo(scr[i * 2], scr[i * 2 + 1]);\n          ctx.setLineDash([1.5, 4]);\n          ctx.strokeStyle = \"rgba(237,237,237,0.5)\";\n          ctx.lineWidth = 1.4;\n          ctx.stroke();\n          ctx.setLineDash([]);\n        }\n  \n        if (f > 0) {\n          ctx.beginPath();\n          ctx.moveTo(scr[0], scr[1]);\n          for (let i = 1; i <= i0; i++) ctx.lineTo(scr[i * 2], scr[i * 2 + 1]);\n          ctx.lineTo(hx, hy);\n          ctx.strokeStyle = A(0.32);\n          ctx.lineWidth = 2;\n          ctx.stroke();\n          const tail = Math.round(M * 0.16);\n          const from = Math.max(0, i0 - tail);\n          ctx.globalCompositeOperation = \"lighter\";\n          ctx.beginPath();\n          ctx.moveTo(scr[from * 2], scr[from * 2 + 1]);\n          for (let i = from + 1; i <= i0; i++) ctx.lineTo(scr[i * 2], scr[i * 2 + 1]);\n          ctx.lineTo(hx, hy);\n          ctx.strokeStyle = A(0.18);\n          ctx.lineWidth = 7;\n          ctx.stroke();\n          ctx.globalCompositeOperation = \"source-over\";\n          for (let j = from; j <= i0; j += 6) {\n            const e = Math.min(i0, j + 6);\n            const q = Math.max(0, (j - (i0 - tail)) / tail);\n            ctx.beginPath();\n            ctx.moveTo(scr[j * 2], scr[j * 2 + 1]);\n            for (let m = j + 1; m <= e; m++) ctx.lineTo(scr[m * 2], scr[m * 2 + 1]);\n            if (e === i0) ctx.lineTo(hx, hy);\n            ctx.strokeStyle = A(0.3 + q * 0.7);\n            ctx.lineWidth = 1.6 + q * 1.8;\n            ctx.stroke();\n            if (e === i0) break;\n          }\n        }\n      };\n      routePass();\n      ctx.setTransform(1, 0, 0, 1, 0, 0);\n      ctx.drawImage(blds, 0, 0);\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.globalAlpha = 0.42;\n      routePass();\n      ctx.globalAlpha = 1;\n\n      ctx.beginPath();\n      ctx.arc(scr[0], scr[1], 3.4, 0, Math.PI * 2);\n      ctx.fillStyle = \"#0a0a0a\";\n      ctx.fill();\n      ctx.strokeStyle = \"rgba(237,237,237,0.9)\";\n      ctx.lineWidth = 1.4;\n      ctx.stroke();\n      const ex = scr[(M - 1) * 2];\n      const ey = scr[(M - 1) * 2 + 1];\n      ctx.beginPath();\n      ctx.rect(ex - 3.5, ey - 3.5, 7, 7);\n      ctx.fillStyle = s.progress >= 1 ? A(1) : \"#0a0a0a\";\n      ctx.fill();\n      ctx.stroke();\n\n      let latest = -1;\n      for (let k = 0; k < passed.length; k++) if (passed[k] >= 0) latest = k;\n      ctx.font = `600 9px ${MONO}`;\n      ctx.textAlign = \"center\";\n      ctx.textBaseline = \"middle\";\n      for (let k = 0; k < passed.length; k++) {\n        const idx = Math.round(((k + 1) / dist) * (M - 1));\n        const x = scr[idx * 2];\n        const y = scr[idx * 2 + 1];\n        if (passed[k] < 0) {\n          ctx.beginPath();\n          ctx.arc(x, y, 1.7, 0, Math.PI * 2);\n          ctx.fillStyle = \"rgba(237,237,237,0.5)\";\n          ctx.fill();\n          continue;\n        }\n        const age = (t - passed[k]) / 1000;\n        const pop = s.reduced ? 1 : easeBack(Math.min(1, Math.max(0, age / 0.45)));\n        const hy2 = y - 12 * pop;\n        ctx.beginPath();\n        ctx.moveTo(x, y);\n        ctx.lineTo(x, hy2);\n        ctx.strokeStyle = \"rgba(237,237,237,0.5)\";\n        ctx.lineWidth = 1;\n        ctx.stroke();\n        ctx.beginPath();\n        ctx.moveTo(x, hy2 - 3.2 * pop);\n        ctx.lineTo(x + 3.2 * pop, hy2);\n        ctx.lineTo(x, hy2 + 3.2 * pop);\n        ctx.lineTo(x - 3.2 * pop, hy2);\n        ctx.closePath();\n        ctx.fillStyle = A(1);\n        ctx.fill();\n        const big = k === latest && (age < 2.6 || s.reduced || !s.playing);\n        if (big) {\n          const text = `${k + 1} KM`;\n          const tw = ctx.measureText(text).width + 12;\n          ctx.save();\n          ctx.translate(x, hy2 - 12);\n          ctx.scale(pop, pop);\n          ctx.beginPath();\n          ctx.roundRect(-tw / 2, -7.5, tw, 15, 7.5);\n          ctx.fillStyle = \"rgba(10,10,12,0.88)\";\n          ctx.fill();\n          ctx.strokeStyle = A(0.7);\n          ctx.lineWidth = 1;\n          ctx.stroke();\n          ctx.fillStyle = \"#ededed\";\n          ctx.fillText(text, 0, 0.5);\n          ctx.restore();\n        } else {\n          ctx.fillStyle = \"rgba(237,237,237,0.85)\";\n          ctx.fillText(String(k + 1), x, hy2 - 9);\n        }\n      }\n\n      const pulse = s.reduced ? 0.4 : (t / 1100) % 1;\n      ctx.globalCompositeOperation = \"lighter\";\n      const g = ctx.createRadialGradient(hx, hy, 0, hx, hy, 18);\n      g.addColorStop(0, A(0.6));\n      g.addColorStop(1, A(0));\n      ctx.fillStyle = g;\n      ctx.beginPath();\n      ctx.arc(hx, hy, 18, 0, Math.PI * 2);\n      ctx.fill();\n      const beam = ctx.createLinearGradient(hx, hy, hx, hy - 36);\n      beam.addColorStop(0, A(0.85));\n      beam.addColorStop(1, A(0));\n      ctx.beginPath();\n      ctx.moveTo(hx, hy);\n      ctx.lineTo(hx, hy - 36);\n      ctx.strokeStyle = beam;\n      ctx.lineWidth = 1.5;\n      ctx.stroke();\n      ctx.globalCompositeOperation = \"source-over\";\n      ctx.beginPath();\n      ctx.arc(hx, hy, 4 + pulse * 9, 0, Math.PI * 2);\n      ctx.strokeStyle = A(0.75 * (1 - pulse));\n      ctx.lineWidth = 1.2;\n      ctx.stroke();\n      ctx.beginPath();\n      ctx.arc(hx, hy, 3.4, 0, Math.PI * 2);\n      ctx.fillStyle = \"#ffffff\";\n      ctx.fill();\n      ctx.strokeStyle = A(1);\n      ctx.lineWidth = 1.6;\n      ctx.stroke();\n    };\n\n    const frame = (t: number) => {\n      raf = 0;\n      const dt = last ? Math.min(0.05, (t - last) / 1000) : 0;\n      last = t;\n      if (s.playing && !s.scrubbing) {\n        if (s.progress >= 1) {\n          hold += dt;\n          if (s.loop && hold > 1.6) {\n            s.progress = 0;\n            hold = 0;\n            report();\n          } else if (!s.loop) {\n            s.playing = false;\n            setPlayState(false);\n          }\n        } else {\n          s.progress = Math.min(1, s.progress + dt / Math.max(1, s.duration));\n          hold = 0;\n          report();\n        }\n      }\n      draw(t);\n      if (visible && (s.playing || !s.reduced)) raf = requestAnimationFrame(frame);\n      else last = 0;\n    };\n\n    const kick = () => {\n      if (raf || !visible) {\n        draw();\n        return;\n      }\n      last = 0;\n      raf = requestAnimationFrame(frame);\n    };\n\n    const resize = () => {\n      const r = root.getBoundingClientRect();\n      if (r.width < 2 || r.height < 2) return;\n      w = r.width;\n      h = r.height;\n      dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.round(w * dpr);\n      canvas.height = Math.round(h * dpr);\n      layer.width = canvas.width;\n      layer.height = canvas.height;\n      blds.width = canvas.width;\n      blds.height = canvas.height;\n      view = fitView(route, w, h, GRID);\n      for (let i = 0; i < route.length; i++) {\n        const p = proj(view, route[i][0], route[i][1], 0.02);\n        scr[i * 2] = p[0];\n        scr[i * 2 + 1] = p[1];\n      }\n      relayer();\n      draw();\n    };\n\n    api.current = {\n      draw: () => draw(),\n      relayer: () => {\n        relayer();\n        draw();\n      },\n      kick,\n      seek: (p: number) => {\n        s.progress = Math.min(1, Math.max(0, p));\n        hold = 0;\n        report();\n        draw();\n      },\n      progress: () => s.progress,\n    };\n\n    s.progress = 0;\n    s.reduced = window.matchMedia(RM_QUERY).matches;\n    if (s.reduced && !s.playing) s.progress = 1;\n    resize();\n    report();\n    const ro = new ResizeObserver(resize);\n    ro.observe(root);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      if (visible) kick();\n    });\n    io.observe(root);\n    kick();\n    return () => {\n      ro.disconnect();\n      io.disconnect();\n      cancelAnimationFrame(raf);\n      raf = 0;\n      api.current = null;\n    };\n  }, [routeSeed, distanceKm]);\n\n  const changeHour = (value: number) => {\n    if (hour === undefined) setInnerHour(value);\n    onHourChange?.(value);\n  };\n\n  const toggle = () => {\n    if (!playing && api.current && api.current.progress() >= 1) api.current.seek(0);\n    setPlayState(!playing);\n  };\n\n  const night = hr < 6.5 || hr > 18.5;\n  const dist = Math.max(0.5, distanceKm);\n  const pace = clock(paceSecPerKm);\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-ub1 ${className}`.trim()}\n      style={{ \"--hb-ub1-a\": accent, ...style } as React.CSSProperties}\n      {...rest}\n    >\n      <style href=\"hb-map-route-replay\" precedence=\"default\">\n        {css}\n      </style>\n      <canvas ref={canvasRef} className=\"hb-ub1-cv\" aria-hidden=\"true\" />\n      <div className=\"hb-ub1-glass hb-ub1-hud\">\n        <span className=\"hb-ub1-k\">{label}</span>\n        <div className=\"hb-ub1-km\">\n          <b ref={kmRef}>0.00</b>\n          <span>/ {dist.toFixed(2)} km</span>\n        </div>\n        <span className=\"hb-ub1-sub\">\n          <span ref={timeRef}>0:00</span> elapsed · {pace} /km\n        </span>\n      </div>\n      <div className=\"hb-ub1-glass hb-ub1-sun\" data-night={night ? \"true\" : \"false\"}>\n        {night ? (\n          <svg viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\">\n            <path d=\"M20.5 14.6A8.5 8.5 0 0 1 9.4 3.5a8.5 8.5 0 1 0 11.1 11.1Z\" />\n          </svg>\n        ) : (\n          <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" aria-hidden=\"true\">\n            <circle cx=\"12\" cy=\"12\" r=\"4\" fill=\"currentColor\" />\n            <path d=\"M12 2.5v2M12 19.5v2M2.5 12h2M19.5 12h2M5.3 5.3l1.4 1.4M17.3 17.3l1.4 1.4M5.3 18.7l1.4-1.4M17.3 6.7l1.4-1.4\" />\n          </svg>\n        )}\n        <input\n          type=\"range\"\n          className=\"hb-ub1-range hb-ub1-hour\"\n          min={5}\n          max={21}\n          step={0.25}\n          value={hr}\n          aria-label=\"Time of day\"\n          aria-valuetext={fmtHour(hr)}\n          style={{ \"--hb-ub1-f\": `${(((hr - 5) / 16) * 100).toFixed(2)}%` } as React.CSSProperties}\n          onChange={(e) => changeHour(Number(e.currentTarget.value))}\n        />\n        <span className=\"hb-ub1-hr\">{fmtHour(hr)}</span>\n      </div>\n      <div className=\"hb-ub1-glass hb-ub1-bar\">\n        <button type=\"button\" className=\"hb-ub1-play\" aria-label={playing ? \"Pause replay\" : \"Play replay\"} onClick={toggle}>\n          {playing ? (\n            <svg viewBox=\"0 0 12 12\" fill=\"currentColor\" aria-hidden=\"true\">\n              <rect x=\"2\" y=\"1.5\" width=\"2.8\" height=\"9\" rx=\"0.8\" />\n              <rect x=\"7.2\" y=\"1.5\" width=\"2.8\" height=\"9\" rx=\"0.8\" />\n            </svg>\n          ) : (\n            <svg viewBox=\"0 0 12 12\" fill=\"currentColor\" aria-hidden=\"true\">\n              <path d=\"M3 1.8v8.4a.6.6 0 0 0 .9.5l7-4.2a.6.6 0 0 0 0-1L3.9 1.3a.6.6 0 0 0-.9.5Z\" />\n            </svg>\n          )}\n        </button>\n        <input\n          ref={scrubRef}\n          type=\"range\"\n          className=\"hb-ub1-range hb-ub1-scrub\"\n          min={0}\n          max={1000}\n          step={1}\n          defaultValue={0}\n          aria-label=\"Replay position\"\n          onPointerDown={() => {\n            st.current.scrubbing = true;\n          }}\n          onPointerUp={() => {\n            st.current.scrubbing = false;\n          }}\n          onPointerCancel={() => {\n            st.current.scrubbing = false;\n          }}\n          onBlur={() => {\n            st.current.scrubbing = false;\n          }}\n          onChange={(e) => api.current?.seek(Number(e.currentTarget.value) / 1000)}\n        />\n        <span ref={pctRef} className=\"hb-ub1-pct\">\n          0%\n        </span>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}