{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ultra-pill-nav","type":"registry:component","title":"Ultra Pill Nav","description":"A floating glass pill nav that tightens as the page scrolls, with the Aura Dial in it: press U and every Ultra part of the page retunes.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/ultra-pill-nav.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, KeyboardEvent as ReactKeyboardEvent, PointerEvent as ReactPointerEvent, RefObject } from \"react\";\n\n/**\n * UltraPillNav — a floating glass pill that tightens as the page scrolls, with the reader's dial in it.\n *\n * Brand, three links, the Aura Dial glyph and one button. Over the first\n * 120px of scroll the pill narrows by 220px and its glass fills in, read\n * from whatever scrolls it (the window or a scrolling box). The dial opens\n * from the corner (or with U) to retune every Ultra asset on the page. On a\n * phone the links move into a sheet that closes on Escape or an outside tap.\n * Same-page links glide to their section.\n *\n* Part of the Ultra kit: an adaptive style whose grammar is the viewer. Every\n * Ultra asset reads six live values (contrast, warmth, light, density, motion,\n * focus) from one shared tuning and re-forms its tone, edges, density and\n * tempo to match: move any Ultra control and every Ultra asset on the page\n * follows. Values the viewer sets are saved on the device (localStorage\n * key ultra:v1); the rest follow the system (prefers-contrast,\n * prefers-reduced-motion, prefers-color-scheme) and the time of day. Nothing\n * is sent anywhere. Every colour is solved for APCA contrast at runtime, so no\n * tuning can make text illegible. Springs are critically damped (no\n * overshoot) and motion 0 swaps states. Type through var(--font-ultra)\n * (Google Sans Flex, whose GRAD and ROND axes follow contrast) over Geist.\n * Paste it as its own file: it carries its own copy of the small engine, and\n * copies on one page share a single store through Symbol.for.\n */\n\n/** The six values every Ultra asset reads. Each runs 0..1. */\nexport type UAxis = \"contrast\" | \"warmth\" | \"density\" | \"motion\" | \"focus\" | \"light\";\n\nexport type UAxes = Record<UAxis, number>;\n\n/** Dial order, clockwise from the top. */\nconst U_AXES: UAxis[] = [\"contrast\", \"warmth\", \"light\", \"density\", \"motion\", \"focus\"];\n\n/** Pole names, so a value can be read aloud (\"Contrast: crisp, 72%\"). */\nconst U_POLES: Record<UAxis, [string, string]> = {\n  contrast: [\"soft\", \"crisp\"],\n  warmth: [\"cool\", \"warm\"],\n  light: [\"dark\", \"paper\"],\n  density: [\"airy\", \"dense\"],\n  motion: [\"still\", \"lively\"],\n  focus: [\"wide\", \"narrow\"],\n};\n\n/** What the server renders and what an asset shows before the store boots. */\nconst U_DEFAULTS: UAxes = { contrast: 0.45, warmth: 0.3, light: 0.1, density: 0.4, motion: 0.45, focus: 0.35 };\n\n/** The exposure band no text can sit on (ground L 0.46..0.66): light snaps out of it. */\nconst U_LIGHT_GAP: [number, number] = [0.46, 0.54];\n\nconst uClamp = (v: number, a = 0, b = 1) => (v < a ? a : v > b ? b : v);\n\nconst uLerp = (a: number, b: number, t: number) => a + (b - a) * t;\n\nconst uSmooth = (a: number, b: number, x: number) => {\n  const t = uClamp((x - a) / (b - a));\n  return t * t * (3 - 2 * t);\n};\n\n/** Nearest safe exposure: anything inside the unsafe band goes to its closer edge. */\nfunction uSafeLight(v: number): number {\n  const [a, b] = U_LIGHT_GAP;\n  if (v <= a || v >= b) return uClamp(v);\n  return v - a < b - v ? a : b;\n}\n\ninterface UStore {\n  v: 1;\n  /** The values the viewer pinned (dragged). Only these are saved. */\n  pinned: Partial<UAxes>;\n  /** Values derived from the system (prefers-*) and the clock. */\n  auto: UAxes;\n  /** Which auto values the system decided (those beat an author's seed). */\n  sys: { contrast: boolean; motion: boolean };\n  /** The author's starting look for values the viewer has not set. */\n  seed: Partial<UAxes>;\n  /** pinned over auto: what assets read. A new object on every change. */\n  snap: UAxes;\n  listeners: Set<() => void>;\n  booted: boolean;\n  /** The one goal on screen: the first claimant wins the filled accent. */\n  goals: string[];\n  /** Shared pointer, for gaze-driven assets. Written by one passive listener. */\n  gaze: { x: number; y: number; speed: number; t: number; live: boolean };\n}\n\nconst U_KEY = \"ultra:v1\";\n\nfunction uStore(): UStore {\n  const g = globalThis as unknown as Record<symbol, UStore | undefined>;\n  const sym = Symbol.for(\"viberdy.ultra.v1\");\n  let s = g[sym];\n  if (!s) {\n    s = {\n      v: 1,\n      pinned: {},\n      auto: { ...U_DEFAULTS },\n      sys: { contrast: false, motion: false },\n      seed: {},\n      snap: { ...U_DEFAULTS },\n      listeners: new Set(),\n      booted: false,\n      goals: [],\n      gaze: { x: -1, y: -1, speed: 0, t: 0, live: false },\n    };\n    g[sym] = s;\n  }\n  return s;\n}\n\nfunction uEmit(s: UStore) {\n  const seed = { ...s.seed };\n  if (s.sys.contrast) delete seed.contrast;\n  if (s.sys.motion) delete seed.motion;\n  s.snap = { ...s.auto, ...seed, ...s.pinned };\n  s.snap.light = uSafeLight(s.snap.light);\n  s.listeners.forEach((fn) => fn());\n}\n\nfunction uMedia(q: string): boolean {\n  return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(q).matches;\n}\n\n/** Auto values: system preferences first, then the clock (read at boot and when the tab returns, never on a timer). */\nfunction uAuto(): UAxes {\n  const a: UAxes = { ...U_DEFAULTS };\n  if (uMedia(\"(prefers-contrast: more)\")) a.contrast = 0.95;\n  else if (uMedia(\"(prefers-contrast: less)\")) a.contrast = 0.12;\n  if (uMedia(\"(prefers-reduced-motion: reduce)\")) a.motion = 0;\n  if (uMedia(\"(pointer: coarse)\")) a.density = 0.25;\n  const h = new Date().getHours() + new Date().getMinutes() / 60;\n  // Warmth rises through the evening and lowers the light with it: a warm tint alone\n  // does not cut the evening's short-wave load, dimming does (RPI LRC, 2018).\n  const evening = h >= 17 ? uSmooth(17, 21, h) : h < 8 ? 1 - uSmooth(6, 8, h) : 0;\n  a.warmth = uLerp(0.3, 0.82, evening);\n  const paper = uMedia(\"(prefers-color-scheme: light)\");\n  a.light = paper ? uLerp(0.86, 0.7, evening) : uLerp(0.12, 0.04, evening);\n  return a;\n}\n\nfunction uLoad(): Partial<UAxes> {\n  try {\n    const raw = window.localStorage.getItem(U_KEY);\n    if (!raw) return {};\n    const data = JSON.parse(raw) as { v?: number; p?: Record<string, unknown> };\n    if (data.v !== 1 || !data.p) return {};\n    const out: Partial<UAxes> = {};\n    for (const k of U_AXES) {\n      const v = data.p[k];\n      if (typeof v === \"number\" && Number.isFinite(v)) out[k] = uClamp(v);\n    }\n    return out;\n  } catch {\n    return {};\n  }\n}\n\nfunction uSave(s: UStore) {\n  try {\n    window.localStorage.setItem(U_KEY, JSON.stringify({ v: 1, p: s.pinned }));\n  } catch {\n    // storage blocked: the tuning still works for this visit\n  }\n}\n\nfunction uSys(s: UStore) {\n  s.sys = {\n    contrast: uMedia(\"(prefers-contrast: more)\") || uMedia(\"(prefers-contrast: less)\"),\n    motion: uMedia(\"(prefers-reduced-motion: reduce)\"),\n  };\n}\n\nfunction uBoot() {\n  const s = uStore();\n  if (s.booted || typeof window === \"undefined\") return;\n  s.booted = true;\n  s.auto = uAuto();\n  uSys(s);\n  s.pinned = uLoad();\n  // A shared setup (#u=c7w3l2...: one letter per value and a base-36 digit) is read once.\n  const shared = /[#&]u=([a-z0-9]{2,12})/i.exec(window.location.hash);\n  if (shared && shared[1]) {\n    const code = shared[1].toLowerCase();\n    for (let i = 0; i + 1 < code.length; i += 2) {\n      const axis = U_AXES.find((k) => k[0] === code[i]);\n      const v = parseInt(code[i + 1] ?? \"\", 36);\n      if (axis && Number.isFinite(v)) s.pinned[axis] = uClamp(v / 35);\n    }\n    uSave(s);\n  }\n  uEmit(s);\n  const refresh = () => {\n    s.auto = uAuto();\n    uSys(s);\n    uEmit(s);\n  };\n  for (const q of [\"(prefers-contrast: more)\", \"(prefers-contrast: less)\", \"(prefers-reduced-motion: reduce)\", \"(prefers-color-scheme: light)\"]) {\n    window.matchMedia(q).addEventListener(\"change\", refresh);\n  }\n  document.addEventListener(\"visibilitychange\", () => {\n    if (document.visibilityState === \"visible\") refresh();\n  });\n  window.addEventListener(\"storage\", (e) => {\n    if (e.key !== U_KEY) return;\n    s.pinned = uLoad();\n    uEmit(s);\n  });\n  const gz = s.gaze;\n  window.addEventListener(\n    \"pointermove\",\n    (e) => {\n      const dt = Math.max(1, e.timeStamp - gz.t);\n      const d = gz.live ? Math.hypot(e.clientX - gz.x, e.clientY - gz.y) : 0;\n      gz.speed = gz.speed * 0.7 + ((d / dt) * 1000) * 0.3;\n      gz.x = e.clientX;\n      gz.y = e.clientY;\n      gz.t = e.timeStamp;\n      gz.live = true;\n    },\n    { passive: true },\n  );\n  document.documentElement.addEventListener(\"pointerleave\", () => {\n    gz.live = false;\n  });\n}\n\n/** Pin a value (the viewer chose it; it is saved), or pass null to hand it back to auto. */\nexport function setUltra(axis: UAxis, value: number | null) {\n  const s = uStore();\n  if (value === null) delete s.pinned[axis];\n  else s.pinned[axis] = axis === \"light\" ? uClamp(value) : uClamp(value);\n  uSave(s);\n  uEmit(s);\n}\n\n/**\n * The author's starting look for values the viewer has not set (they win\n * over the clock, never over a system preference for reduced motion or more\n * contrast, and never over the viewer). Not saved.\n */\nexport function seedUltra(values: Partial<UAxes>) {\n  const s = uStore();\n  const next: Partial<UAxes> = { ...s.seed };\n  let changed = false;\n  for (const k of U_AXES) {\n    const v = values[k];\n    if (typeof v === \"number\" && Number.isFinite(v) && next[k] !== uClamp(v)) {\n      next[k] = uClamp(v);\n      changed = true;\n    }\n  }\n  if (!changed) return;\n  s.seed = next;\n  uEmit(s);\n}\n\n/** Forget every pinned value. */\nexport function resetUltra() {\n  const s = uStore();\n  s.pinned = {};\n  uSave(s);\n  uEmit(s);\n}\n\nfunction uSubscribe(fn: () => void) {\n  const s = uStore();\n  s.listeners.add(fn);\n  uBoot();\n  return () => {\n    s.listeners.delete(fn);\n  };\n}\n\nconst uSnap = () => uStore().snap;\n\nconst uServerSnap = () => U_DEFAULTS;\n\n/**\n * The tuning, live. `tune` pins values for this instance only (a demo, a\n * fixed brand moment); they are never saved. `bounds` lets an author limit\n * the expressive direction only: motion, density and focus can be capped,\n * contrast can be floored, warmth and light can be ranged. The way back to\n * calm (motion 0, contrast 1, density 0, focus 0) can never be bounded.\n * `seed` is the author's starting look (see seedUltra).\n */\nexport function useUltra(tune?: Partial<UAxes>, bounds?: Partial<Record<UAxis, [number, number]>>, seed?: Partial<UAxes>): UAxes {\n  const snap = useSyncExternalStore(uSubscribe, uSnap, uServerSnap);\n  const seedKey = JSON.stringify(seed ?? null);\n  useLayoutEffect(() => {\n    const v = JSON.parse(seedKey) as Partial<UAxes> | null;\n    if (v) seedUltra(v);\n  }, [seedKey]);\n  // Compared by value, so inline objects do not churn.\n  const tuneKey = JSON.stringify(tune ?? null);\n  const boundsKey = JSON.stringify(bounds ?? null);\n  return useMemo(() => {\n    const tune = JSON.parse(tuneKey) as Partial<UAxes> | null;\n    const bounds = JSON.parse(boundsKey) as Partial<Record<UAxis, [number, number]>> | null;\n    const out: UAxes = { ...snap };\n    if (tune) {\n      for (const k of U_AXES) {\n        const v = tune[k];\n        if (typeof v === \"number\" && Number.isFinite(v)) out[k] = uClamp(v);\n      }\n    }\n    if (bounds) {\n      for (const k of U_AXES) {\n        const b = bounds[k];\n        if (!b) continue;\n        let [lo, hi] = b;\n        if (k === \"motion\" || k === \"density\" || k === \"focus\") lo = 0;\n        if (k === \"contrast\") hi = 1;\n        out[k] = uClamp(out[k], Math.min(lo, hi), Math.max(lo, hi));\n      }\n    }\n    out.light = uSafeLight(out.light);\n    return out;\n  }, [snap, tuneKey, boundsKey]);\n}\n\ntype URgb = [number, number, number];\n\nfunction uOklab(L: number, a: number, b: number): URgb {\n  const l_ = L + 0.3963377774 * a + 0.2158037573 * b;\n  const m_ = L - 0.1055613458 * a - 0.0638541728 * b;\n  const s_ = L - 0.0894841775 * a - 1.291485548 * b;\n  const l = l_ * l_ * l_;\n  const m = m_ * m_ * m_;\n  const s = s_ * s_ * s_;\n  const lin: URgb = [\n    4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n    -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n    -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n  ];\n  return lin.map((x) => {\n    const v = uClamp(x);\n    return Math.round((v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055) * 255);\n  }) as URgb;\n}\n\nfunction uOklch(L: number, C: number, h: number): URgb {\n  const r = (h * Math.PI) / 180;\n  return uOklab(L, C * Math.cos(r), C * Math.sin(r));\n}\n\nconst uHex = (c: URgb) => \"#\" + c.map((v) => v.toString(16).padStart(2, \"0\")).join(\"\");\n\nfunction uY(c: URgb): number {\n  return 0.2126729 * Math.pow(c[0] / 255, 2.4) + 0.7151522 * Math.pow(c[1] / 255, 2.4) + 0.072175 * Math.pow(c[2] / 255, 2.4);\n}\n\n/** APCA-W3 0.0.98G lightness contrast (signed: negative = light text on dark). */\nfunction uApca(text: URgb, bg: URgb): number {\n  let yt = uY(text);\n  let yb = uY(bg);\n  if (yt < 0.022) yt += Math.pow(0.022 - yt, 1.414);\n  if (yb < 0.022) yb += Math.pow(0.022 - yb, 1.414);\n  if (Math.abs(yb - yt) < 0.0005) return 0;\n  if (yb > yt) {\n    const s = (Math.pow(yb, 0.56) - Math.pow(yt, 0.57)) * 1.14;\n    return s < 0.1 ? 0 : (s - 0.027) * 100;\n  }\n  const s = (Math.pow(yb, 0.65) - Math.pow(yt, 0.62)) * 1.14;\n  return s > -0.1 ? 0 : (s + 0.027) * 100;\n}\n\n/** The warmth tint: a straight line in OKLab from slate to amber, neutral at 0.5 (never a hue walk through green). */\nfunction uTint(w: number, mag: number): [number, number] {\n  return [uLerp(-0.0048, 0.0055, w) * mag, uLerp(-0.0132, 0.015, w) * mag];\n}\n\nfunction uCol(L: number, w: number, mag: number): URgb {\n  const [a, b] = uTint(w, mag);\n  return uOklab(L, a, b);\n}\n\n/** Find the ink lightness that reaches |Lc| = target on this ground (bisection, 24 steps). */\nfunction uSolve(bg: URgb, target: number, dark: boolean, w: number): URgb {\n  let lo = 0.02;\n  let hi = 0.995;\n  for (let i = 0; i < 24; i++) {\n    const m = (lo + hi) / 2;\n    const lc = Math.abs(uApca(uCol(m, w, 0.6), bg));\n    if (dark) {\n      if (lc < target) lo = m;\n      else hi = m;\n    } else if (lc < target) hi = m;\n    else lo = m;\n  }\n  return uCol((lo + hi) / 2, w, 0.6);\n}\n\n/** The accent's hue: a calm, low-chroma blue-violet, clear of every other kit's saturated blue. */\nconst U_HUE = 262;\n\nexport interface UTokens {\n  dark: boolean;\n  /** Ground lightness (OKLab L), for shaders. */\n  groundL: number;\n  ground: string;\n  s1: string;\n  s2: string;\n  well: string;\n  ink1: string;\n  ink2: string;\n  ink3: string;\n  hair: string;\n  /** Hairline alpha: edges only appear as contrast rises past 0.55. */\n  edge: number;\n  acc: string;\n  onAcc: string;\n  /** 4px base unit, scaled by density. */\n  unit: number;\n  body: number;\n  lh: number;\n  /** Critically damped spring stiffness; 0 means no motion (swap states). */\n  k: number;\n  /** The gaze aperture in px, from focus. */\n  aperture: number;\n  grad: number;\n  rond: number;\n  /** Ground and ink as linear-ish triples (0..1 sRGB) for canvases and shaders. */\n  groundRgb: URgb;\n  inkRgb: URgb;\n  accRgb: URgb;\n}\n\nconst uTokenCache = new Map<string, UTokens>();\n\n/** Every colour, size and tempo an Ultra asset uses, derived from the six values. No asset holds a fixed hex. */\nexport function ultraTokens(x: UAxes, hue = U_HUE): UTokens {\n  const q = (v: number) => Math.round(v * 200) / 200;\n  const key = [x.contrast, x.warmth, x.light, x.density, x.motion, x.focus].map(q).join(\",\") + \":\" + hue;\n  const hit = uTokenCache.get(key);\n  if (hit) return hit;\n  const c = q(x.contrast);\n  const w = q(x.warmth);\n  const lt = uSafeLight(q(x.light));\n  const d = q(x.density);\n  const m = q(x.motion);\n  const f = q(x.focus);\n  const dark = lt < 0.5;\n  // Exposure moves the ground within its room; contrast deepens it a little.\n  const gL = dark\n    ? uLerp(0.15, 0.3, lt / U_LIGHT_GAP[0]) - 0.03 * (c - 0.45)\n    : uLerp(0.89, 0.975, (lt - U_LIGHT_GAP[1]) / (1 - U_LIGHT_GAP[1])) + 0.012 * (c - 0.45);\n  const step = dark ? uLerp(0.03, 0.05, c) : uLerp(0.022, 0.04, c);\n  const g = uCol(gL, w, 1);\n  const s1 = uCol(dark ? gL + step : Math.min(0.995, gL + step * 0.7), w, dark ? 1 : 0.6);\n  const s2 = uCol(dark ? gL + step * 2 : Math.min(0.998, gL + step * 1.2), w, dark ? 1 : 0.5);\n  const well = uCol(gL - step * 0.8, w, 1);\n  const ink1 = uSolve(g, uLerp(75, 95, c), dark, w);\n  const ink2 = uSolve(g, uLerp(60, 72, c), dark, w);\n  const ink3 = uSolve(g, uLerp(52, 60, c), dark, w);\n  const hair = uSolve(g, uLerp(30, 45, c), dark, w);\n  const acc = dark ? uOklch(uLerp(0.84, 0.88, c), 0.09, hue) : uOklch(uLerp(0.5, 0.44, c), 0.14, hue);\n  // A label on the fill: solved, never pure black or white.\n  const onAcc = uSolve(acc, dark ? 70 : 78, !dark, w);\n  const t: UTokens = {\n    dark,\n    groundL: gL,\n    ground: uHex(g),\n    s1: uHex(s1),\n    s2: uHex(s2),\n    well: uHex(well),\n    ink1: uHex(ink1),\n    ink2: uHex(ink2),\n    ink3: uHex(ink3),\n    hair: uHex(hair),\n    edge: uClamp((c - 0.55) / 0.45),\n    acc: uHex(acc),\n    onAcc: uHex(onAcc),\n    unit: 4 * uLerp(1.18, 0.82, d),\n    body: uLerp(17, 15, d),\n    lh: uLerp(1.62, 1.45, d),\n    k: m < 0.02 ? 0 : uLerp(190, 560, m),\n    aperture: uLerp(560, 170, f),\n    grad: dark ? uLerp(40, 0, c) : uLerp(70, 30, c),\n    rond: uLerp(45, 8, c),\n    groundRgb: g,\n    inkRgb: ink1,\n    accRgb: acc,\n  };\n  uTokenCache.set(key, t);\n  return t;\n}\n\n/** The tokens as CSS custom properties on an asset root. Children read var(--u-*). */\nexport function ultraVars(t: UTokens): CSSProperties {\n  return {\n    \"--u-ground\": t.ground,\n    \"--u-s1\": t.s1,\n    \"--u-s2\": t.s2,\n    \"--u-well\": t.well,\n    \"--u-ink1\": t.ink1,\n    \"--u-ink2\": t.ink2,\n    \"--u-ink3\": t.ink3,\n    \"--u-hair\": t.hair,\n    \"--u-edge\": String(t.edge),\n    \"--u-acc\": t.acc,\n    \"--u-on-acc\": t.onAcc,\n    \"--u-unit\": t.unit.toFixed(2) + \"px\",\n    \"--u-body\": t.body.toFixed(2) + \"px\",\n    \"--u-lh\": t.lh.toFixed(3),\n    // Signature layer: one tempo (0ms at motion 0), the shadow and glow colours, the caught-light edge.\n    \"--u-dur\": (t.k ? Math.round(uLerp(980, 520, (t.k - 190) / 370)) : 0) + \"ms\",\n    \"--u-shade\": t.dark ? \"rgba(0,0,0,.5)\" : \"rgba(28,32,52,.14)\",\n    \"--u-glow\": \"color-mix(in oklab, \" + t.acc + \" \" + (t.dark ? 55 : 42) + \"%, transparent)\",\n    \"--u-lit\": t.dark ? \"rgba(255,255,255,.075)\" : \"rgba(255,255,255,.92)\",\n    colorScheme: t.dark ? \"dark\" : \"light\",\n    color: t.ink1,\n    fontFamily: 'var(--font-ultra, \"Google Sans Flex\", \"Geist\", ui-sans-serif, system-ui, sans-serif)',\n    fontVariationSettings: '\"GRAD\" ' + t.grad.toFixed(0) + ', \"ROND\" ' + t.rond.toFixed(0),\n  } as CSSProperties;\n}\n\n/**\n * The kit's signature layer, shared by every Ultra asset and timed by --u-dur\n * (the viewer's motion value; 0ms at motion 0 and under reduced motion, so\n * every entrance lands at once):\n *   .u-rise   a blur-and-rise entrance, staggered by --u-i\n *   .u-draw   a stroke that draws itself in (set pathLength=\"1\")\n *   .u-glass  a lifted surface: tinted gradient, caught-light top edge, soft shadow\n *   .u-lamp   a light and a lit edge that follow the pointer (--mx/--my, set on pointermove)\n *   .u-cta    the page's one goal: an accent glow, a lift and a sheen on hover\n */\nconst U_FX =\n  \"@keyframes u-rise{from{opacity:0;transform:translateY(.55em);filter:blur(6px)}}\" +\n  \"@keyframes u-draw{from{stroke-dashoffset:1}}\" +\n  \"@keyframes u-sheen{from{transform:translateX(-130%) skewX(-18deg)}to{transform:translateX(330%) skewX(-18deg)}}\" +\n  \"@keyframes u-spin{to{transform:rotate(1turn)}}\" +\n  \".u-scope .u-rise{animation:u-rise var(--u-dur) cubic-bezier(.16,1,.3,1) both;animation-delay:calc(var(--u-i,0) * var(--u-dur) * .09)}\" +\n  \".u-scope .u-draw{stroke-dasharray:1;stroke-dashoffset:0;animation:u-draw calc(var(--u-dur) * 2) cubic-bezier(.65,0,.35,1) both;animation-delay:calc(var(--u-i,0) * var(--u-dur) * .05)}\" +\n  \".u-scope .u-glass{background:linear-gradient(180deg,var(--u-s2),var(--u-s1) 62%);box-shadow:inset 0 1px 0 var(--u-lit),inset 0 0 0 1px color-mix(in oklab,var(--u-hair) calc(16% + var(--u-edge) * 60%),transparent),0 1px 2px var(--u-shade),0 30px 64px -34px var(--u-shade)}\" +\n  \".u-scope .u-lamp{position:relative;isolation:isolate}\" +\n  \".u-scope .u-lamp::before,.u-scope .u-lamp::after{content:'';position:absolute;inset:0;border-radius:inherit;pointer-events:none;opacity:0;transition:opacity calc(var(--u-dur) * .5)}\" +\n  \".u-scope .u-lamp::before{z-index:-1;background:radial-gradient(var(--u-lamp-r,240px) circle at var(--mx,50%) var(--my,50%),color-mix(in oklab,var(--u-acc) 13%,transparent),transparent 70%)}\" +\n  \".u-scope .u-lamp::after{padding:1px;background:radial-gradient(180px circle at var(--mx,50%) var(--my,50%),color-mix(in oklab,var(--u-acc) 85%,transparent),transparent 70%);-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask-composite:exclude}\" +\n  \".u-scope .u-lamp:hover::before,.u-scope .u-lamp:hover::after{opacity:1}\" +\n  \".u-scope .u-cta{position:relative;overflow:hidden;isolation:isolate;box-shadow:inset 0 1px 0 rgba(255,255,255,.4),0 0 0 1px color-mix(in oklab,var(--u-acc) 80%,transparent),0 10px 28px -10px var(--u-glow);transition:transform calc(var(--u-dur) * .45) cubic-bezier(.16,1,.3,1),box-shadow calc(var(--u-dur) * .45)}\" +\n  \".u-scope .u-cta:hover{transform:translateY(-1px);box-shadow:inset 0 1px 0 rgba(255,255,255,.4),0 0 0 1px var(--u-acc),0 16px 40px -10px var(--u-glow)}\" +\n  \".u-scope .u-cta:active{transform:translateY(0) scale(.98)}\" +\n  \".u-scope .u-cta::after{content:'';position:absolute;inset:0 auto 0 0;width:42%;pointer-events:none;background:linear-gradient(90deg,transparent,rgba(255,255,255,.5),transparent);transform:translateX(-130%) skewX(-18deg)}\" +\n  \".u-scope .u-cta:hover::after{animation:u-sheen calc(var(--u-dur) * 1.3) cubic-bezier(.16,1,.3,1)}\" +\n  \".u-scope .u-arr{transition:transform calc(var(--u-dur) * .45) cubic-bezier(.16,1,.3,1)}.u-scope .u-cta:hover .u-arr{transform:translateX(3px)}\" +\n  \"@media (prefers-reduced-motion:reduce){.u-scope .u-rise,.u-scope .u-draw,.u-scope .u-cta::after{animation:none!important}.u-scope .u-cta{transition:none}}\";\n\n/**\n * The kit's scoped CSS: the one focus ring (the accent, 2px, offset 3px, the\n * element's own radius), tabular figures, and transitions off for elements a\n * frame loop writes. Rendered once per asset; identical text dedupes in React 19.\n */\nconst U_CSS =\n  \".u-scope :focus-visible{outline:2px solid var(--u-acc)!important;outline-offset:3px!important;border-radius:revert-layer!important}\" +\n  \".u-scope .u-num{font-variant-numeric:tabular-nums}\" +\n  \".u-scope [data-u-live]{transition:none!important}\" +\n  U_FX;\n\n/**\n * The scrolling box an element lives in: the nearest ancestor that actually\n * scrolls, or null for the window. Resolved on every frame, because a box only\n * becomes a scroller once its content is taller than it.\n */\nfunction uScrollParent(el: Element | null): HTMLElement | null {\n  let n = el?.parentElement ?? null;\n  while (n && n !== document.body && n !== document.documentElement) {\n    const oy = getComputedStyle(n).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && n.scrollHeight > n.clientHeight + 1) return n;\n    n = n.parentElement;\n  }\n  return null;\n}\n\ninterface UFrame {\n  /** The element's box, in viewport pixels. */\n  rect: DOMRect;\n  /** The visible part of whatever scrolls it: the scroller's box, or the window. */\n  view: { top: number; height: number; left: number; width: number };\n}\n\n/**\n * Run `apply` with the element's position whenever anything scrolls or\n * resizes, at most once per frame. One capture-phase scroll listener hears\n * every scroller, so the same section works on a page and inside a scrolling\n * preview. `apply` writes to the DOM; nothing here re-renders React.\n */\nfunction useUScrollFrame<T extends HTMLElement>(ref: RefObject<T | null>, apply: (f: UFrame) => void) {\n  const applyRef = useRef(apply);\n  useEffect(() => {\n    applyRef.current = apply;\n  });\n  useEffect(() => {\n    let raf = 0;\n    const run = () => {\n      raf = 0;\n      const el = ref.current;\n      if (!el) return;\n      const sp = uScrollParent(el);\n      const r = sp ? sp.getBoundingClientRect() : null;\n      const view = sp && r ? { top: r.top, height: sp.clientHeight, left: r.left, width: sp.clientWidth } : { top: 0, height: window.innerHeight, left: 0, width: window.innerWidth };\n      applyRef.current({ rect: el.getBoundingClientRect(), view });\n    };\n    const kick = () => {\n      if (!raf) raf = requestAnimationFrame(run);\n    };\n    document.addEventListener(\"scroll\", kick, { capture: true, passive: true });\n    window.addEventListener(\"resize\", kick);\n    const ro = typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(kick) : null;\n    if (ref.current && ro) ro.observe(ref.current);\n    run();\n    return () => {\n      document.removeEventListener(\"scroll\", kick, { capture: true });\n      window.removeEventListener(\"resize\", kick);\n      ro?.disconnect();\n      if (raf) cancelAnimationFrame(raf);\n    };\n  }, [ref]);\n}\n\n/** Links built from props: https, http, mailto, same-site paths and anchors only (tabs and newlines stripped, backslashes refused). */\nfunction uSafeHref(href: string): string {\n  const h = href.replace(/[\\t\\n\\r]/g, \"\").trim();\n  if (!h || h.includes(String.fromCharCode(92))) return \"#\";\n  if (h.startsWith(\"#\") || (h.startsWith(\"/\") && !h.startsWith(\"//\"))) return h;\n  return /^(https?:|mailto:)/i.test(h) ? h : \"#\";\n}\n\n/** Scroll whatever scrolls `el` to a same-page anchor; falls back to the browser for anything else. */\nfunction uGo(e: { currentTarget: HTMLAnchorElement; preventDefault: () => void }) {\n  const href = e.currentTarget.getAttribute(\"href\") ?? \"\";\n  if (!href.startsWith(\"#\") || href.length < 2) return;\n  const root = e.currentTarget.closest(\"[data-u-site]\") ?? document;\n  const target = root.querySelector<HTMLElement>('[data-u-anchor=\"' + href.slice(1) + '\"]');\n  if (!target) return;\n  e.preventDefault();\n  const sp = uScrollParent(target);\n  const smooth: ScrollBehavior = uStore().snap.motion < 0.02 ? \"auto\" : \"smooth\";\n  if (sp) sp.scrollTo({ top: sp.scrollTop + target.getBoundingClientRect().top - sp.getBoundingClientRect().top, behavior: smooth });\n  else window.scrollTo({ top: window.scrollY + target.getBoundingClientRect().top, behavior: smooth });\n}\n\n/** viberdy's V, as a solid mark that takes the current colour. */\nfunction UVMark({ size = 28, className }: { size?: number; className?: string }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 32 32\" aria-hidden className={className}>\n      <rect width=\"32\" height=\"32\" rx=\"9\" fill=\"currentColor\" />\n      <path d=\"M9 10.5 L15.2 22.5 L16.8 22.5 L23 10.5 L19.6 10.5 L16 18.2 L12.4 10.5 Z\" fill=\"var(--u-ground)\" />\n    </svg>\n  );\n}\n\n/** The kit's arrow: slides on a .u-cta hover. */\nfunction UArrow() {\n  return (\n    <svg className=\"u-arr\" width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden>\n      <path d=\"M2 7h9M7.5 3.5L11 7l-3.5 3.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n\nconst AD_NAMES: Record<UAxis, string> = {\n  contrast: \"Contrast\",\n  warmth: \"Warmth\",\n  light: \"Light\",\n  density: \"Density\",\n  motion: \"Motion\",\n  focus: \"Focus\",\n};\n\n/** Which values the viewer pinned, as a stable string (\"contrast,light\"); \"\" on the server. */\nfunction useUltraPinned(): Set<UAxis> {\n  const key = useSyncExternalStore(\n    uSubscribe,\n    () => U_AXES.filter((k) => typeof uStore().pinned[k] === \"number\").join(\",\"),\n    () => \"\",\n  );\n  return useMemo(() => new Set((key ? key.split(\",\") : []) as UAxis[]), [key]);\n}\n\n/** A point on axis i of a hexagon (clockwise from 12 o'clock), rounded so server and browser agree. */\nfunction adPoint(i: number, r: number, cx: number, cy: number): [number, number] {\n  const a = (-90 + i * 60) * (Math.PI / 180);\n  return [Math.round((cx + Math.cos(a) * r) * 100) / 100, Math.round((cy + Math.sin(a) * r) * 100) / 100];\n}\n\nfunction adWord(axis: UAxis, v: number) {\n  const [lo, hi] = U_POLES[axis];\n  return AD_NAMES[axis] + \": \" + (v < 0.5 ? lo : hi) + \", \" + Math.round(v * 100) + \" percent\";\n}\n\n/** The share code: one letter per value plus a base-36 digit (#u=c7w3l2d4m5f2). */\nfunction adCode(a: UAxes, pinned: Set<UAxis>) {\n  return U_AXES.filter((k) => pinned.has(k))\n    .map((k) => k[0] + Math.round(a[k] * 35).toString(36))\n    .join(\"\");\n}\n\n/**\n * The shape the dial draws: eased toward the tuning so a reset or a shared\n * link morphs the hexagon instead of jumping it. Under the hand (hold) and at\n * motion 0 it is the tuning itself.\n */\nfunction useAdEase(target: UAxes, k: number, hold: boolean): UAxes {\n  const [shown, setShown] = useState(target);\n  const live = useRef({ cur: target, target, k, hold });\n  const key = U_AXES.map((ax) => target[ax].toFixed(4)).join(\",\");\n  useEffect(() => {\n    live.current.target = target;\n    live.current.k = k;\n    live.current.hold = hold;\n  });\n  useEffect(() => {\n    const L = live.current;\n    let raf = 0;\n    let last = 0;\n    const step = (now: number) => {\n      const dt = last ? Math.min(0.05, (now - last) / 1000) : 1 / 60;\n      last = now;\n      const r = 1 - Math.exp((-dt * L.k) / 45);\n      const next = { ...L.cur };\n      let done = true;\n      for (const ax of U_AXES) {\n        const d = L.target[ax] - L.cur[ax];\n        if (L.hold || !L.k || Math.abs(d) < 0.002) next[ax] = L.target[ax];\n        else {\n          next[ax] = L.cur[ax] + d * r;\n          done = false;\n        }\n      }\n      L.cur = next;\n      setShown(next);\n      raf = done ? 0 : requestAnimationFrame(step);\n    };\n    raf = requestAnimationFrame(step);\n    return () => cancelAnimationFrame(raf);\n  }, [key, k, hold]);\n  return hold || !k ? target : shown;\n}\n\n/** The aura's three colours: the accent, an orchid, and a third that runs cool to amber with warmth. */\nfunction adHues(tk: UTokens, warmth: number): [string, string, string] {\n  const L = tk.dark ? 0.84 : 0.56;\n  return [tk.acc, uHex(uOklch(L, tk.dark ? 0.1 : 0.13, uLerp(305, 345, warmth))), uHex(uOklch(L, tk.dark ? 0.09 : 0.12, uLerp(215, 60, warmth)))];\n}\n\nconst AD_CSS =\n  \"@property --u-ad-a{syntax:'<angle>';inherits:false;initial-value:0deg}\" +\n  \"@keyframes u-ad-turn{to{--u-ad-a:1turn}}\" +\n  \"@keyframes u-ad-pulse{from{transform:scale(.7);opacity:.55}to{transform:scale(2.1);opacity:0}}\" +\n  \".u-ad-glyph{position:relative;transition:transform calc(var(--u-dur) * .45) cubic-bezier(.16,1,.3,1),opacity 160ms}\" +\n  \".u-ad-glyph:hover{transform:scale(1.06)}\" +\n  \".u-ad-glyph::before{content:'';position:absolute;inset:0;border-radius:inherit;padding:1.5px;pointer-events:none;background:conic-gradient(from var(--u-ad-a),var(--u-ad-1),var(--u-ad-2),var(--u-ad-3),var(--u-ad-1));-webkit-mask:linear-gradient(#000 0 0) content-box,linear-gradient(#000 0 0);-webkit-mask-composite:xor;mask-composite:exclude;animation:u-ad-turn calc(var(--u-dur) * 9) linear infinite}\" +\n  \".u-ad-halo{opacity:0;transition:opacity 200ms}\" +\n  \".u-ad-v:hover .u-ad-halo,.u-ad-v:focus-visible .u-ad-halo{opacity:.2}\" +\n  \".u-ad-v[data-grab] .u-ad-halo{opacity:.3}\" +\n  \".u-ad-pulse{transform-box:fill-box;transform-origin:center;animation:u-ad-pulse calc(var(--u-dur) * 1.8) cubic-bezier(.16,1,.3,1) infinite}\" +\n  \".u-ad-aura{animation:u-spin calc(var(--u-dur) * 24) linear infinite}\" +\n  \"@media (prefers-reduced-motion:reduce){.u-ad-glyph::before,.u-ad-pulse,.u-ad-aura{animation:none!important}}\";\n\nexport interface AuraDialProps {\n  /** inline sits in the flow; fixed pins it to a corner of the viewport. */\n  placement?: \"inline\" | \"fixed\";\n  corner?: \"br\" | \"bl\" | \"tr\" | \"tl\";\n  defaultOpen?: boolean;\n  /** Toggles the dial when no field is focused; null turns it off. */\n  hotkey?: string | null;\n  /** Leave out a value the page cannot change (for example light on a page with one polarity). */\n  axes?: UAxis[];\n  /** The closed glyph's size in px (the panel is 248). */\n  size?: number;\n  onChange?: (axes: UAxes) => void;\n  className?: string;\n}\n\n/**\n * AuraDial — your six values as one shape: a hexagon you pull, and the page re-forms under your hand.\n */\nexport function AuraDial({ placement = \"inline\", corner = \"br\", defaultOpen = false, hotkey = \"u\", axes: show = U_AXES, size = 40, onChange, className = \"\" }: AuraDialProps) {\n  const a = useUltra();\n  const tk = ultraTokens(a);\n  const pinned = useUltraPinned();\n  const [open, setOpen] = useState(defaultOpen);\n  const [grab, setGrab] = useState<UAxis | null>(null);\n  const [copied, setCopied] = useState(false);\n  const btnRef = useRef<HTMLButtonElement>(null);\n  const panelRef = useRef<HTMLDivElement>(null);\n  const svgRef = useRef<SVGSVGElement>(null);\n  const onChangeRef = useRef(onChange);\n  const id = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n  const visible = U_AXES.filter((k) => show.includes(k));\n\n  useEffect(() => {\n    onChangeRef.current = onChange;\n  });\n\n  useEffect(() => {\n    if (!hotkey) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key.toLowerCase() !== hotkey.toLowerCase() || e.metaKey || e.ctrlKey || e.altKey || e.repeat) return;\n      const t = e.target as HTMLElement | null;\n      if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;\n      setOpen((o) => !o);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    return () => window.removeEventListener(\"keydown\", onKey);\n  }, [hotkey]);\n\n  const write = (axis: UAxis, v: number | null) => {\n    setUltra(axis, v);\n    onChangeRef.current?.(uStore().snap);\n  };\n\n  // Panel geometry: a 248px plane, the hexagon centred in its top 228px.\n  const W = 248;\n  const CX = 124;\n  const CY = 118;\n  const R = 78;\n  const R0 = 14;\n  const rOf = (v: number) => R0 + (R - R0) * v;\n\n  const fromPointer = (axis: UAxis, clientX: number, clientY: number) => {\n    const svg = svgRef.current;\n    if (!svg) return 0;\n    const box = svg.getBoundingClientRect();\n    const k = box.width / W;\n    const x = (clientX - box.left) / k - CX;\n    const y = (clientY - box.top) / k - CY;\n    const i = U_AXES.indexOf(axis);\n    const ang = (-90 + i * 60) * (Math.PI / 180);\n    const along = x * Math.cos(ang) + y * Math.sin(ang);\n    let v = uClamp((along - R0) / (R - R0));\n    // Detents at quarters, 0.03 wide.\n    for (const d of [0, 0.25, 0.5, 0.75, 1]) if (Math.abs(v - d) < 0.03) v = d;\n    return v;\n  };\n\n  // The drag follows the pointer anywhere on the page until release (window listeners, so a\n  // release off the corner still ends it).\n  const onVertexDown = (axis: UAxis) => (e: ReactPointerEvent<SVGGElement>) => {\n    if (e.button !== 0) return;\n    e.preventDefault();\n    setGrab(axis);\n    if (e.pointerType === \"touch\" && typeof navigator.vibrate === \"function\") navigator.vibrate(4);\n    const pid = e.pointerId;\n    const move = (ev: PointerEvent) => {\n      if (ev.pointerId === pid) write(axis, fromPointer(axis, ev.clientX, ev.clientY));\n    };\n    const up = (ev: PointerEvent) => {\n      if (ev.pointerId !== pid) return;\n      window.removeEventListener(\"pointermove\", move);\n      window.removeEventListener(\"pointerup\", up);\n      window.removeEventListener(\"pointercancel\", up);\n      setGrab(null);\n      if (axis === \"light\") {\n        const raw = uStore().pinned.light;\n        if (typeof raw === \"number\") write(\"light\", uSafeLight(raw));\n      }\n    };\n    window.addEventListener(\"pointermove\", move);\n    window.addEventListener(\"pointerup\", up);\n    window.addEventListener(\"pointercancel\", up);\n  };\n  const onVertexKey = (axis: UAxis) => (e: ReactKeyboardEvent<SVGGElement>) => {\n    const step = e.shiftKey ? 0.2 : 0.05;\n    let v = a[axis];\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowUp\") v += step;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowDown\") v -= step;\n    else if (e.key === \"Home\") v = 0;\n    else if (e.key === \"End\") v = 1;\n    else if (e.key === \"Backspace\" || e.key === \"Delete\") {\n      e.preventDefault();\n      write(axis, null);\n      return;\n    } else if (e.key === \"Escape\") {\n      setOpen(false);\n      btnRef.current?.focus();\n      return;\n    } else return;\n    e.preventDefault();\n    if (axis === \"light\") {\n      const up = v > a.light;\n      if (v > U_LIGHT_GAP[0] && v < U_LIGHT_GAP[1]) v = up ? U_LIGHT_GAP[1] : U_LIGHT_GAP[0];\n    }\n    write(axis, uClamp(v));\n  };\n\n  const copy = () => {\n    const url = location.origin + location.pathname + location.search + \"#u=\" + adCode(a, pinned);\n    navigator.clipboard?.writeText(url).then(\n      () => {\n        setCopied(true);\n        window.setTimeout(() => setCopied(false), 1600);\n      },\n      () => {},\n    );\n  };\n\n  const poly = (r: (i: number) => number, cx: number, cy: number) =>\n    U_AXES.map((_, i) => adPoint(i, r(i), cx, cy).join(\",\")).join(\" \");\n  const k = tk.k;\n  const v = useAdEase(a, k, grab !== null);\n  const [h1, h2, h3] = adHues(tk, a.warmth);\n  const morph = k ? \"transform 420ms cubic-bezier(.16,1,.3,1), opacity 260ms ease-out, filter 320ms ease-out\" : \"opacity 120ms linear\";\n  const gs = Math.max(28, Math.min(48, size * uLerp(1, 0.8, a.density)));\n  const gr = (x: number) => gs * (0.13 + 0.3 * x);\n  const fixedPos: CSSProperties =\n    placement === \"fixed\"\n      ? { position: \"fixed\", zIndex: 60, [corner[0] === \"b\" ? \"bottom\" : \"top\"]: 24, [corner[1] === \"r\" ? \"right\" : \"left\"]: 24 }\n      : {};\n  const origin = (corner[0] === \"b\" ? \"bottom\" : \"top\") + \" \" + (corner[1] === \"r\" ? \"right\" : \"left\");\n  // The aura behind the shape swells with how far the tuning reaches.\n  const reach = U_AXES.reduce((s, ax) => s + v[ax], 0) / 6;\n  const hues = { \"--u-ad-1\": h1, \"--u-ad-2\": h2, \"--u-ad-3\": h3 } as CSSProperties;\n  const grad = (gid: string) => (\n    <linearGradient id={gid} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n      <stop offset=\"0\" stopColor={h1} />\n      <stop offset=\"0.55\" stopColor={h2} />\n      <stop offset=\"1\" stopColor={h3} />\n    </linearGradient>\n  );\n\n  return (\n    <div className={\"u-scope relative inline-block \" + className} style={{ ...ultraVars(tk), ...hues, ...fixedPos, width: gs, height: gs }}>\n      <style>{U_CSS + AD_CSS}</style>\n      <button\n        ref={btnRef}\n        type=\"button\"\n        aria-expanded={open}\n        aria-controls={\"ad\" + id}\n        aria-label=\"Your tuning: contrast, warmth, light, density, motion and focus\"\n        onClick={() => setOpen((o) => !o)}\n        className=\"u-ad-glyph grid h-full w-full cursor-pointer place-items-center rounded-[30%] p-0\"\n        style={{ background: tk.s1, border: 0, boxShadow: \"inset 0 1px 0 var(--u-lit), 0 8px 22px -10px var(--u-glow)\", opacity: open ? 0 : 1 }}\n      >\n        <svg width={gs} height={gs} viewBox={\"0 0 \" + gs + \" \" + gs} aria-hidden>\n          <defs>{grad(\"adgg\" + id)}</defs>\n          <polygon points={poly((i) => gr(v[U_AXES[i] as UAxis]), gs / 2, gs / 2)} fill={\"url(#adgg\" + id + \")\"} fillOpacity={0.4} stroke={\"url(#adgg\" + id + \")\"} strokeWidth={1.5} strokeLinejoin=\"round\" />\n          {U_AXES.map((ax, i) => {\n            const [x, y] = adPoint(i, gr(v[ax]), gs / 2, gs / 2);\n            return <circle key={ax} cx={x} cy={y} r={1.9} fill={pinned.has(ax) ? tk.ink1 : tk.s1} stroke={tk.ink1} strokeWidth={1.1} />;\n          })}\n        </svg>\n      </button>\n      <div\n        ref={panelRef}\n        id={\"ad\" + id}\n        role=\"dialog\"\n        aria-label=\"Your tuning\"\n        className=\"u-glass absolute overflow-hidden rounded-[28px]\"\n        style={{\n          width: W,\n          [corner[0] === \"b\" ? \"bottom\" : \"top\"]: 0,\n          [corner[1] === \"r\" ? \"right\" : \"left\"]: 0,\n          color: tk.ink1,\n          transformOrigin: origin,\n          transform: open ? \"scale(1)\" : \"scale(\" + (gs / W).toFixed(3) + \")\",\n          opacity: open ? 1 : 0,\n          filter: open || !k ? \"none\" : \"blur(10px)\",\n          pointerEvents: open ? \"auto\" : \"none\",\n          visibility: open ? \"visible\" : \"hidden\",\n          transition: morph + (open ? \"\" : \", visibility 0s linear 420ms\"),\n          zIndex: 2,\n        }}\n      >\n        {/* The aura: the dial's three colours turning slowly behind the shape. */}\n        <div\n          aria-hidden\n          className=\"pointer-events-none absolute\"\n          style={{ left: CX - 100, top: 48 + CY - 100, width: 200, height: 200, transform: \"scale(\" + (0.55 + 0.6 * reach).toFixed(3) + \")\", transition: k ? \"transform 600ms cubic-bezier(.16,1,.3,1)\" : undefined }}\n        >\n          <div className=\"u-ad-aura h-full w-full rounded-full\" style={{ background: \"conic-gradient(from 30deg, \" + h1 + \", \" + h2 + \", \" + h3 + \", \" + h1 + \")\", filter: \"blur(34px)\", opacity: tk.dark ? 0.3 : 0.38 }} />\n        </div>\n        <div className=\"relative flex items-center justify-between px-5 pt-4 text-[12.5px] font-medium\" style={{ color: tk.ink3 }}>\n          <span>Your tuning</span>\n          <button\n            type=\"button\"\n            onClick={() => {\n              setOpen(false);\n              btnRef.current?.focus();\n            }}\n            className=\"-mr-2 grid h-8 w-8 cursor-pointer place-items-center rounded-full\"\n            style={{ background: \"transparent\", border: 0, color: tk.ink2 }}\n            aria-label=\"Close\"\n          >\n            <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" aria-hidden>\n              <path d=\"M2 2l8 8M10 2l-8 8\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n            </svg>\n          </button>\n        </div>\n        <svg ref={svgRef} width={W} height={228} viewBox={\"0 0 \" + W + \" 228\"} className=\"relative block touch-none select-none\">\n          <defs>\n            {grad(\"adg\" + id)}\n            <radialGradient id={\"adw\" + id}>\n              <stop offset=\"0\" stopColor={tk.ink1} stopOpacity={tk.dark ? 0.07 : 0.05} />\n              <stop offset=\"1\" stopColor={tk.ink1} stopOpacity={0} />\n            </radialGradient>\n            <filter id={\"adf\" + id} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n              <feGaussianBlur stdDeviation=\"7\" />\n            </filter>\n          </defs>\n          <polygon points={poly(() => R, CX, CY)} fill={\"url(#adw\" + id + \")\"} />\n          {[0.25, 0.5, 0.75, 1].map((t) => (\n            <polygon key={t} points={poly(() => rOf(t), CX, CY)} fill=\"none\" stroke={tk.hair} strokeOpacity={(t === 1 ? 0.45 : 0.22) + 0.35 * tk.edge} strokeWidth={1} strokeDasharray={t === 1 ? undefined : \"1.5 4\"} />\n          ))}\n          {U_AXES.map((ax, i) => {\n            const [x0, y0] = adPoint(i, R0, CX, CY);\n            const [x1, y1] = adPoint(i, R, CX, CY);\n            return <line key={ax} x1={x0} y1={y0} x2={x1} y2={y1} stroke={grab === ax ? h1 : tk.hair} strokeOpacity={grab === ax ? 0.9 : 0.4 + 0.4 * tk.edge} strokeWidth={grab === ax ? 1.5 : 1} />;\n          })}\n          {/* The band no text survives: the light rail is hatched there. */}\n          {(() => {\n            const i = U_AXES.indexOf(\"light\");\n            const [x0, y0] = adPoint(i, rOf(U_LIGHT_GAP[0]), CX, CY);\n            const [x1, y1] = adPoint(i, rOf(U_LIGHT_GAP[1]), CX, CY);\n            return <line x1={x0} y1={y0} x2={x1} y2={y1} stroke={tk.ink3} strokeWidth={5} strokeDasharray=\"1.5 1.5\" strokeOpacity={0.7} />;\n          })()}\n          {/* The shape, lit: a soft glow of itself underneath, a tinted fill, a gradient edge. */}\n          <polygon points={poly((i) => rOf(v[U_AXES[i] as UAxis]), CX, CY)} fill={\"url(#adg\" + id + \")\"} opacity={tk.dark ? 0.8 : 0.55} filter={\"url(#adf\" + id + \")\"} />\n          <polygon points={poly((i) => rOf(v[U_AXES[i] as UAxis]), CX, CY)} fill={\"url(#adg\" + id + \")\"} fillOpacity={tk.dark ? 0.3 : 0.28} stroke={\"url(#adg\" + id + \")\"} strokeWidth={1.75} strokeLinejoin=\"round\" />\n          {U_AXES.map((ax, i) => {\n            const [lx, ly] = adPoint(i, R + 20, CX, CY);\n            const quiet = grab !== null && grab !== ax;\n            return (\n              <text key={ax} x={lx} y={ly + 4} textAnchor=\"middle\" fontSize={11.5} fontWeight={grab === ax ? 600 : 500} fill={grab === ax ? tk.ink1 : tk.ink3} style={{ opacity: quiet ? 0.5 : 1, transition: k ? \"opacity 160ms\" : undefined }}>\n                {grab === ax ? U_POLES[ax][a[ax] < 0.5 ? 0 : 1] + \" \" + Math.round(a[ax] * 100) : AD_NAMES[ax]}\n              </text>\n            );\n          })}\n          {visible.map((ax) => {\n            const i = U_AXES.indexOf(ax);\n            const [x, y] = adPoint(i, rOf(v[ax]), CX, CY);\n            const on = pinned.has(ax);\n            const quiet = grab !== null && grab !== ax;\n            return (\n              <g\n                key={ax}\n                role=\"slider\"\n                tabIndex={open ? 0 : -1}\n                aria-label={AD_NAMES[ax]}\n                aria-valuemin={0}\n                aria-valuemax={100}\n                aria-valuenow={Math.round(a[ax] * 100)}\n                aria-valuetext={adWord(ax, a[ax]) + (on ? \"\" : \", following your system\")}\n                data-grab={grab === ax ? \"\" : undefined}\n                className=\"u-ad-v cursor-grab outline-none active:cursor-grabbing\"\n                style={{ opacity: quiet ? 0.45 : 1, transition: k ? \"opacity 160ms\" : undefined }}\n                onPointerDown={onVertexDown(ax)}\n                onDoubleClick={() => write(ax, null)}\n                onKeyDown={onVertexKey(ax)}\n              >\n                <circle cx={x} cy={y} r={14} fill=\"transparent\" />\n                <circle className=\"u-ad-halo\" cx={x} cy={y} r={13} fill={h1} />\n                {grab === ax && k ? <circle className=\"u-ad-pulse\" cx={x} cy={y} r={9} fill=\"none\" stroke={h1} strokeWidth={1.5} /> : null}\n                <circle cx={x} cy={y} r={grab === ax ? 7 : 5.5} fill={on ? tk.ink1 : tk.s1} stroke={tk.ink1} strokeWidth={1.5} style={{ transition: k ? \"r 160ms\" : undefined, filter: on ? \"drop-shadow(0 0 5px \" + h1 + \")\" : undefined }} />\n              </g>\n            );\n          })}\n        </svg>\n        <div className=\"relative flex items-center justify-between gap-2 whitespace-nowrap px-5 pb-4 text-[12px]\" style={{ color: tk.ink3 }}>\n          <span className=\"inline-flex items-center gap-1.5\">\n            <svg width=\"22\" height=\"8\" viewBox=\"0 0 22 8\" aria-hidden>\n              <circle cx=\"4\" cy=\"4\" r=\"3\" fill=\"none\" stroke={tk.ink3} strokeWidth=\"1.2\" />\n              <circle cx=\"16\" cy=\"4\" r=\"3\" fill={tk.ink3} />\n            </svg>\n            system / you\n          </span>\n          <span className=\"flex items-center gap-3\">\n            <button type=\"button\" onClick={copy} disabled={pinned.size === 0} className=\"cursor-pointer p-0 underline decoration-1 underline-offset-4 disabled:cursor-default disabled:no-underline disabled:opacity-50\" style={{ background: \"none\", border: 0, color: tk.ink2, font: \"inherit\" }}>\n              {copied ? \"Copied\" : \"Share\"}\n            </button>\n            <button type=\"button\" onClick={() => { resetUltra(); onChangeRef.current?.(uStore().snap); }} disabled={pinned.size === 0} className=\"cursor-pointer p-0 underline decoration-1 underline-offset-4 disabled:cursor-default disabled:no-underline disabled:opacity-50\" style={{ background: \"none\", border: 0, color: tk.ink2, font: \"inherit\" }}>\n              Reset\n            </button>\n          </span>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport interface UNavLink {\n  label: string;\n  href: string;\n}\n\nconst UN_LINKS: UNavLink[] = [\n  { label: \"Library\", href: \"/library\" },\n  { label: \"Styles\", href: \"/styles\" },\n  { label: \"Pricing\", href: \"/pricing\" },\n];\n\nconst UN_CSS =\n  \".u-nav-link{position:relative;padding:8px 12px;border-radius:999px;text-decoration:none;transition:color 160ms,background-color 160ms}\" +\n  \".u-nav-link:hover{background:color-mix(in oklab,var(--u-ink1) 7%,transparent);color:var(--u-ink1)!important}\" +\n  \".u-nav-sheet{transform-origin:top right;transition:opacity calc(var(--u-dur) * .4),transform calc(var(--u-dur) * .5) cubic-bezier(.16,1,.3,1),visibility 0s}\" +\n  \".u-nav-sheet[data-closed]{opacity:0;transform:translateY(-6px) scale(.97);visibility:hidden;pointer-events:none;transition:opacity calc(var(--u-dur) * .3),transform calc(var(--u-dur) * .3),visibility 0s linear calc(var(--u-dur) * .3)}\";\n\nexport interface UltraPillNavProps {\n  brand?: string;\n  links?: UNavLink[];\n  cta?: { label: string; href: string };\n  /** The Aura Dial glyph beside the button (U opens it). */\n  dial?: boolean;\n  className?: string;\n}\n\n/**\n * UltraPillNav — a floating glass pill that tightens as the page scrolls, with the reader's dial in it.\n */\nexport function UltraPillNav({ brand = \"viberdy\", links = UN_LINKS, cta = { label: \"Get Ultra\", href: \"#plans\" }, dial = true, className = \"\" }: UltraPillNavProps) {\n  const tk = ultraTokens(useUltra());\n  const ref = useRef<HTMLElement>(null);\n  const [open, setOpen] = useState(false);\n  const menuId = useId().replace(/[^a-zA-Z0-9]/g, \"\");\n\n  // Tighten over the first 120px of scroll: the pill narrows, its glass fills in.\n  useUScrollFrame(ref, () => {\n    const el = ref.current;\n    if (!el) return;\n    const sp = uScrollParent(el);\n    const y = sp ? sp.scrollTop : window.scrollY;\n    el.style.setProperty(\"--u-nav\", uClamp(y / 120).toFixed(3));\n  });\n\n  useEffect(() => {\n    if (!open) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false);\n    };\n    const onDown = (e: PointerEvent) => {\n      if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);\n    };\n    window.addEventListener(\"keydown\", onKey);\n    window.addEventListener(\"pointerdown\", onDown);\n    return () => {\n      window.removeEventListener(\"keydown\", onKey);\n      window.removeEventListener(\"pointerdown\", onDown);\n    };\n  }, [open]);\n\n  return (\n    <nav ref={ref} aria-label=\"Main\" className={\"u-scope @container relative w-full \" + className} style={{ ...ultraVars(tk), color: tk.ink1, background: \"transparent\" }}>\n      <style>{U_CSS + UN_CSS}</style>\n      <div\n        className=\"relative mx-auto flex h-14 items-center gap-2 rounded-full pl-3 pr-2\"\n        style={{ maxWidth: \"calc(1180px - var(--u-nav, 0) * 220px)\", transition: tk.k ? \"max-width calc(var(--u-dur) * .6) cubic-bezier(.16,1,.3,1)\" : undefined }}\n      >\n        <span aria-hidden className=\"u-glass pointer-events-none absolute inset-0 rounded-full\" style={{ opacity: \"calc(0.35 + var(--u-nav, 0) * 0.65)\" }} />\n        <a href={uSafeHref(\"/\")} className=\"relative flex items-center gap-2 rounded-full pr-2 text-[16px] font-[620] tracking-[-0.02em] no-underline\" style={{ color: tk.ink1 }}>\n          <UVMark size={30} />\n          {brand}\n        </a>\n        <div className=\"relative ml-4 hidden items-center gap-0.5 text-[14px] font-medium @2xl:flex\">\n          {links.map((l) => (\n            <a key={l.href + l.label} href={uSafeHref(l.href)} onClick={uGo} className=\"u-nav-link\" style={{ color: tk.ink2 }}>\n              {l.label}\n            </a>\n          ))}\n        </div>\n        <div className=\"relative ml-auto flex items-center gap-2\">\n          {dial ? <AuraDial size={36} corner=\"tr\" hotkey=\"u\" /> : null}\n          <a href={uSafeHref(cta.href)} onClick={uGo} className=\"u-cta hidden h-10 items-center gap-2 rounded-full px-4 text-[14px] font-medium no-underline @md:inline-flex\" style={{ background: tk.acc, color: tk.onAcc }}>\n            {cta.label}\n            <UArrow />\n          </a>\n          <button\n            type=\"button\"\n            aria-expanded={open}\n            aria-controls={\"un\" + menuId}\n            aria-label={open ? \"Close menu\" : \"Open menu\"}\n            onClick={() => setOpen((o) => !o)}\n            className=\"grid h-10 w-10 cursor-pointer place-items-center rounded-full border-0 @2xl:hidden\"\n            style={{ background: \"color-mix(in oklab, \" + tk.ink1 + \" 8%, transparent)\", color: tk.ink1 }}\n          >\n            <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden>\n              <path d={open ? \"M3.5 3.5l9 9M12.5 3.5l-9 9\" : \"M2.5 5.5h11M2.5 10.5h11\"} stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n            </svg>\n          </button>\n        </div>\n      </div>\n      <div\n        id={\"un\" + menuId}\n        data-closed={open ? undefined : \"\"}\n        className=\"u-nav-sheet u-glass absolute right-2 top-[calc(100%+8px)] z-10 flex w-[min(320px,calc(100%-16px))] flex-col gap-1 rounded-[24px] p-2 @2xl:hidden\"\n      >\n        {links.map((l) => (\n          <a\n            key={l.href + l.label}\n            href={uSafeHref(l.href)}\n            onClick={(e) => {\n              setOpen(false);\n              uGo(e);\n            }}\n            className=\"u-nav-link text-[16px] font-medium\"\n            style={{ color: tk.ink1, padding: \"12px 14px\" }}\n          >\n            {l.label}\n          </a>\n        ))}\n        <a\n          href={uSafeHref(cta.href)}\n          onClick={(e) => {\n            setOpen(false);\n            uGo(e);\n          }}\n          className=\"u-cta mt-1 inline-flex h-12 items-center justify-center gap-2 rounded-full text-[15px] font-medium no-underline\"\n          style={{ background: tk.acc, color: tk.onAcc }}\n        >\n          {cta.label}\n          <UArrow />\n        </a>\n      </div>\n    </nav>\n  );\n}\n","type":"registry:component","target":"components/viberdy/ultra-pill-nav.tsx"}],"meta":{"tier":"free","tags":["navbar","navigation","glass","sticky nav","mobile menu","adaptive","theme","dark mode"],"href":"https://viberdy.dev/library/ultra-pill-nav","aiPrompt":"Add the Ultra \"UltraPillNav\" to this app: a floating glass pill nav that tightens as the page scrolls. Over its first 120px of scroll it narrows and lifts off the page, and it holds the Aura Dial glyph beside the one filled button, so the reader can open the dial (or press U) from anywhere and retune every Ultra component.\n\nHow to use it:\n- Put it in a sticky container at the top of the page: `<div className=\"sticky top-0 z-50\"><UltraPillNav brand=\"Your brand\" links={[{ label: \"Docs\", href: \"/docs\" }]} cta={{ label: \"Get started\", href: \"#plans\" }} /></div>`.\n- `dial={false}` drops the dial glyph if the page has its own.\n- It reads the scroll of whatever scrolls it, so it also works inside a scrolling box.\n- On a phone (container under 768px) the links fold into a menu sheet; it closes on Escape, on a link, or on a press outside it, and the button says whether it opens or closes the menu.\n- Links go through `uSafeHref`; hash links scroll smoothly within an Ultra site.","license":"https://viberdy.dev/license"}}