Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

theme effects paint on a dedicated layer element; heading treatment becomes tokens

[._.]/ Adam Eivy8b7f08bc7c56
diff --git a/client/src/components/brain/tabs/BrainGraph.jsx b/client/src/components/brain/tabs/BrainGraph.jsx
index 4957d9fefa..45cfaaf9dc 100644
--- a/client/src/components/brain/tabs/BrainGraph.jsx
+++ b/client/src/components/brain/tabs/BrainGraph.jsx
@@ -16,6 +16,7 @@ import InlineConfirmRow from '../../ui/InlineConfirmRow';
import BrailleSpinner from '../../BrailleSpinner';
import useHoverTooltip from '../../../hooks/useHoverTooltip';
import useFirstTouchHint from '../../../hooks/useFirstTouchHint';
+import usePrefersReducedMotion from '../../../hooks/usePrefersReducedMotion';
import { formatDateNumeric } from '../../../utils/formatters';
const EDGE_COLORS = {
@@ -241,9 +242,7 @@ export default function BrainGraph() {
const [typeFilters, setTypeFilters] = useState(() =>
Object.fromEntries(BRAIN_TYPES.map(t => [t, true]))
);
- const [reducedMotion, setReducedMotion] = useState(() =>
- window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false
- );
+ const reducedMotion = usePrefersReducedMotion();
const motionSettings = graphMotionSettings(reducedMotion);
const graphRef = useRef(null);
@@ -254,15 +253,6 @@ export default function BrainGraph() {
// and onPointerMissed can stand down for the threshold pick below.
const touchGestureRef = useRef(false);
- useEffect(() => {
- const media = window.matchMedia?.('(prefers-reduced-motion: reduce)');
- if (!media) return undefined;
- const updatePreference = () => setReducedMotion(media.matches);
- updatePreference();
- media.addEventListener?.('change', updatePreference);
- return () => media.removeEventListener?.('change', updatePreference);
- }, []);
-
const focusId = currentFocusId(focusTrail);
// Initial load: bounded overview + lightweight search index + embedding gaps.
diff --git a/client/src/components/cos/CoreCoSAvatar.jsx b/client/src/components/cos/CoreCoSAvatar.jsx
index 09c30eb8e9..aaf37c8ee6 100644
--- a/client/src/components/cos/CoreCoSAvatar.jsx
+++ b/client/src/components/cos/CoreCoSAvatar.jsx
@@ -2,7 +2,10 @@ import { useEffect, useRef } from 'react';
import CoSAvatarFrame from './CoSAvatarFrame';
import { AGENT_STATES } from './constants';
import { drawWireframeCore } from '../../lib/wireframeCore.js';
-import { parseColor } from '../../lib/chipContrast.js';
+import { parseColor, parseTriple } from '../../lib/chipContrast.js';
+import useCanvasDprSize from '../../hooks/useCanvasDprSize.js';
+import useCanvasRollPalette from '../../hooks/useCanvasRollPalette.js';
+import usePrefersReducedMotion from '../../hooks/usePrefersReducedMotion.js';
// Core Assembly — the Kestrel Neon concept's rotating wireframe icosahedron,
// drawn on a plain 2D canvas. No WebGL, so it skips CoSCanvasGuard and works
@@ -24,17 +27,24 @@ const STATE_MOTION = {
ideating: { spin: 1.3, breathe: 1 },
};
+// Edge color per state, parsed once — the draw loop must not re-parse hex
+// every frame for one of seven values.
+const STATE_EDGE_RGB = Object.fromEntries(Object.entries(AGENT_STATES).map(([state, { color }]) => {
+ const { r, g, b } = parseColor(color);
+ return [state, [r, g, b]];
+}));
+
const FALLBACK_NODE_RGB = [255, 43, 214];
const FALLBACK_DIM_RGB = [107, 115, 144];
const TILT = 0.5;
const readTriple = (styles, prop, fallback) => {
- const parts = styles.getPropertyValue(prop).trim().split(/\s+/).map(Number);
- return parts.length >= 3 && parts.slice(0, 3).every(Number.isFinite) ? parts.slice(0, 3) : fallback;
+ const { r, g, b } = parseTriple(styles.getPropertyValue(prop));
+ return [r, g, b].every(Number.isFinite) ? [r, g, b] : fallback;
};
-// Canvas fillStyle can't read CSS custom properties, so resolve the theme
-// tokens once per theme switch (mirrors `rollPalette` / `useChartColors`).
+// Canvas fillStyle can't read CSS custom properties; useCanvasRollPalette
+// re-runs this on every theme switch.
const resolvePalette = () => {
if (typeof window === 'undefined' || typeof getComputedStyle !== 'function') {
return { nodeRgb: FALLBACK_NODE_RGB, dimRgb: FALLBACK_DIM_RGB, font: 'monospace' };
@@ -47,30 +57,23 @@ const resolvePalette = () => {
};
};
-const stateEdgeRgb = (state) => {
- const parsed = parseColor((AGENT_STATES[state] || AGENT_STATES.sleeping).color);
- return parsed ? [parsed.r, parsed.g, parsed.b] : [0, 240, 255];
-};
-
export default function CoreCoSAvatar({ state = 'sleeping', speaking = false, background = false }) {
const wrapRef = useRef(null);
const canvasRef = useRef(null);
+ const drawRef = useRef(null);
// Latest props for the animation loop — the loop is bound once so a state
// change never restarts the spin from zero.
const propsRef = useRef({ state, speaking });
propsRef.current = { state, speaking };
+ const reduceMotion = usePrefersReducedMotion();
+ const paletteRef = useCanvasRollPalette(drawRef, resolvePalette);
+ useCanvasDprSize(wrapRef, canvasRef, undefined, drawRef);
useEffect(() => {
- const wrap = wrapRef.current;
const canvas = canvasRef.current;
const ctx = canvas?.getContext('2d');
- if (!wrap || !ctx) return undefined;
+ if (!ctx) return undefined;
- const media = window.matchMedia?.('(prefers-reduced-motion: reduce)');
- let reduce = media?.matches ?? false;
- let palette = resolvePalette();
- let width = 0;
- let height = 0;
let spin = 0.8;
let phase = 0;
let lastTs = null;
@@ -78,53 +81,36 @@ export default function CoreCoSAvatar({ state = 'sleeping', speaking = false, ba
// Drag offsets so "Drag to rotate" on the frame is true for this avatar too.
const drag = { pointerId: null, x: 0, y: 0, ax: 0, ay: 0 };
- const draw = (ts) => {
+ const draw = (ts = performance.now()) => {
const { state: currentState, speaking: isSpeaking } = propsRef.current;
const motion = STATE_MOTION[currentState] || STATE_MOTION.sleeping;
- const dt = lastTs === null || reduce ? 0 : Math.min(0.1, (ts - lastTs) / 1000);
+ const dt = lastTs === null || reduceMotion ? 0 : Math.min(0.1, (ts - lastTs) / 1000);
lastTs = ts;
spin += dt * motion.spin * (isSpeaking ? 1.8 : 1);
phase += dt * (0.4 + (isSpeaking ? 1.2 : 0));
- const breathe = reduce ? 0 : motion.breathe * (0.5 + 0.5 * Math.sin(ts / 700));
+ const breathe = reduceMotion ? 0 : motion.breathe * (0.5 + 0.5 * Math.sin(ts / 700));
+ // useCanvasDprSize sized the bitmap at the device pixel ratio; draw in CSS px.
+ const dpr = window.devicePixelRatio || 1;
drawWireframeCore(ctx, {
- width,
- height,
+ width: canvas.width / dpr,
+ height: canvas.height / dpr,
ax: TILT + drag.ax,
ay: spin + drag.ay,
phase,
pulse: Math.min(1, breathe + (isSpeaking ? 0.5 : 0)),
- edgeRgb: stateEdgeRgb(currentState),
- ...palette,
+ edgeRgb: STATE_EDGE_RGB[currentState] || STATE_EDGE_RGB.sleeping,
+ ...paletteRef.current,
});
};
+ drawRef.current = () => draw();
const loop = (ts) => {
draw(ts);
- if (!reduce) raf = requestAnimationFrame(loop);
- };
-
- const restart = () => {
- cancelAnimationFrame(raf);
- lastTs = null;
- raf = requestAnimationFrame(loop);
- };
-
- const resize = () => {
- width = Math.max(1, Math.floor(wrap.clientWidth));
- height = Math.max(1, Math.floor(wrap.clientHeight));
- const dpr = Math.min(window.devicePixelRatio || 1, 3);
- canvas.width = Math.round(width * dpr);
- canvas.height = Math.round(height * dpr);
- canvas.style.width = `${width}px`;
- canvas.style.height = `${height}px`;
- ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
- draw(performance.now());
+ // Under reduced motion one frame is the whole animation.
+ if (!reduceMotion) raf = requestAnimationFrame(loop);
};
+ raf = requestAnimationFrame(loop);
- const onMotionPreference = () => {
- reduce = media.matches;
- restart();
- };
const onPointerDown = (event) => {
drag.pointerId = event.pointerId;
drag.x = event.clientX;
@@ -137,23 +123,11 @@ export default function CoreCoSAvatar({ state = 'sleeping', speaking = false, ba
drag.ax += (event.clientY - drag.y) * 0.01;
drag.x = event.clientX;
drag.y = event.clientY;
- if (reduce) draw(performance.now());
+ if (reduceMotion) draw();
};
const onPointerUp = (event) => {
if (drag.pointerId === event.pointerId) drag.pointerId = null;
};
-
- resize();
- restart();
- const observer = typeof ResizeObserver === 'function' ? new ResizeObserver(resize) : null;
- observer?.observe(wrap);
- // Re-resolve the ring/readout colors when the theme switches (same signal
- // useCanvasRollPalette watches).
- const themeObserver = typeof MutationObserver === 'function'
- ? new MutationObserver(() => { palette = resolvePalette(); if (reduce) draw(performance.now()); })
- : null;
- themeObserver?.observe(document.documentElement, { attributes: true, attributeFilter: ['data-port-theme'] });
- media?.addEventListener?.('change', onMotionPreference);
canvas.addEventListener('pointerdown', onPointerDown);
canvas.addEventListener('pointermove', onPointerMove);
canvas.addEventListener('pointerup', onPointerUp);
@@ -161,15 +135,13 @@ export default function CoreCoSAvatar({ state = 'sleeping', speaking = false, ba
return () => {
cancelAnimationFrame(raf);
- observer?.disconnect();
- themeObserver?.disconnect();
- media?.removeEventListener?.('change', onMotionPreference);
+ drawRef.current = null;
canvas.removeEventListener('pointerdown', onPointerDown);
canvas.removeEventListener('pointermove', onPointerMove);
canvas.removeEventListener('pointerup', onPointerUp);
canvas.removeEventListener('pointercancel', onPointerUp);
};
- }, []);
+ }, [paletteRef, reduceMotion]);
return (
<CoSAvatarFrame label="Core assembly avatar. Drag to rotate." background={background}>
diff --git a/client/src/components/cos/CoreCoSAvatar.test.jsx b/client/src/components/cos/CoreCoSAvatar.test.jsx
index 0a1d8d93ec..0e06e9fc87 100644
--- a/client/src/components/cos/CoreCoSAvatar.test.jsx
+++ b/client/src/components/cos/CoreCoSAvatar.test.jsx
@@ -22,9 +22,10 @@ describe('CoreCoSAvatar', () => {
drawCalls.length = 0;
rafCallbacks = [];
reduceMotion = false;
- // happy-dom has no 2D canvas; the frame math is mocked above, so a bare
- // context object is enough for the component to size and draw.
+ // happy-dom has no 2D canvas or ResizeObserver; the frame math is mocked
+ // above, so a bare context is enough for the component to size and draw.
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue({ setTransform: vi.fn() });
+ vi.stubGlobal('ResizeObserver', class { observe() {} disconnect() {} });
vi.stubGlobal('requestAnimationFrame', vi.fn((cb) => { rafCallbacks.push(cb); return rafCallbacks.length; }));
vi.stubGlobal('cancelAnimationFrame', vi.fn());
vi.stubGlobal('matchMedia', vi.fn(() => ({
@@ -49,8 +50,7 @@ describe('CoreCoSAvatar', () => {
it('draws edges in the agent-state color and rings in the theme secondary accent', () => {
render(<CoreCoSAvatar state="coding" />);
expect(screen.getByRole('group', { name: /Core assembly avatar/ })).toBeInTheDocument();
- // The mount resize paints one frame synchronously.
- expect(drawCalls.length).toBeGreaterThanOrEqual(1);
+ tick(0);
const frame = drawCalls.at(-1);
expect(frame.edgeRgb).toEqual(rgbOf(AGENT_STATES.coding.color));
expect(frame.nodeRgb).toEqual([255, 43, 214]);
@@ -90,10 +90,4 @@ describe('CoreCoSAvatar', () => {
expect(rafCallbacks).toHaveLength(0);
expect(drawCalls.at(-1).pulse).toBe(0);
});
-
- it('hides the canvas from assistive tech on the background stage', () => {
- const { container } = render(<CoreCoSAvatar state="sleeping" background />);
- expect(screen.queryByRole('group')).not.toBeInTheDocument();
- expect(container.querySelector('[aria-hidden="true"]')).toContainElement(screen.getByTestId('core-avatar-canvas'));
- });
});
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index 4bfd5a2757..953ef15c1c 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -221,8 +221,9 @@ grep -i "what you want to do" client/src/hooks/README.md
| `useMusicVideoModelSettings` | A project's saved render pins — video backend/model/generation-mode/audio-reactive LoRA + the image-side frame pin — with the Video Gen catalog they read from. Optimistic-local + silent PATCH, rollback + toast on failure; `saving` gates the dependent generate buttons. Returns `{ models, modelsLoading, defaultModel, saving, settings, effectiveModelId, activeModel, audioReactiveModels, audioReactiveLoras, detectedAudioReactiveLora, audioReactiveReady, audioReactiveSelected, videoBlockedReason, change, changeFramePin }`. `videoBlockedReason` is the single "why can't I generate" string (an unavailable audio-reactive setup) shared by the disabled buttons, their tooltips, and the blocked-call toast. | The Music Video renderer selects and anything building a scene-clip job payload from them. |
| `useMusicVideoSceneMedia` | Both per-scene generation lanes (reference frame + scene clip) over `useSceneRenderLifecycle`, the frame/shot prompt builders (concept-style suffix), and the batch "generate the missing ones" actions. Returns `{ genScenes, genVideoScenes, buildFramePrompt, buildShotPrompt, generateFrame, generateSceneVideo, continueSceneVideo, generateMissingFrames, generateMissingVideos }`. | The Music Video scene board — don't re-wire the two lanes or re-derive the i2v/a2v/extend payloads. |
| `useMusicVideoManualTempo` | The manual-tempo fallback for a project whose auto-detected BPM is null: BPM/offset drafts (reset on project switch), tap-tempo estimation, and the persisted `setMusicVideoManualTempo` call. Returns `{ bpm, setBpm, offset, setOffset, saving, tap, submit }`. | The Music Video "No tempo detected" row. |
-| `useCanvasDprSize` | DevicePixelRatio-aware canvas sizing shared by the piano-roll renderers (`<PianoRoll>`, `<MidiPianoRoll>`): sizes the bitmap to container-width × height at the DPR, applies the transform, and redraws via a `drawRef` on mount + every `ResizeObserver` resize (observer created once per height, never churned by draw-closure changes). Returns a ref holding the current CSS width so draw code doesn't measure the DOM per frame. | Both piano-roll canvases. |
-| `useCanvasRollPalette` | Resolves the roll canvas palette (theme-following `--port-accent` + roll bg via `rollPalette`) into a ref, re-resolving on theme switch (`data-port-theme` MutationObserver) and repainting through a `drawRef`. Hands back a ref, not state, so a theme swap redraws the imperative canvas without a React re-render. | Both piano-roll canvases need theme-aware accent/bg colors that canvas `fillStyle` can't read from CSS vars. |
+| `useCanvasDprSize` | DevicePixelRatio-aware canvas sizing shared by the piano-roll renderers (`<PianoRoll>`, `<MidiPianoRoll>`): sizes the bitmap to container-width × height (or the container height when `height` is `undefined`) at the DPR, applies the transform, and redraws via a `drawRef` on mount + every `ResizeObserver` resize (observer created once per height, never churned by draw-closure changes). Returns a ref holding the current CSS width so draw code doesn't measure the DOM per frame. | Both piano-roll canvases. |
+| `useCanvasRollPalette` | Resolves a canvas palette into a ref — `rollPalette` by default, or any resolver passed as the second argument (the Core Assembly avatar reads `--port-accent-2`), re-resolving on theme switch (`data-port-theme` MutationObserver) and repainting through a `drawRef`. Hands back a ref, not state, so a theme swap redraws the imperative canvas without a React re-render. | Both piano-roll canvases need theme-aware accent/bg colors that canvas `fillStyle` can't read from CSS vars. |
+| `usePrefersReducedMotion` | The user's `prefers-reduced-motion` setting as a boolean, tracking live changes. CSS animations honor the media query themselves; this is for imperative loops (a rAF canvas loop, a three.js frameloop) that must stop scheduling frames on their own. Consumed by `cos/CoreCoSAvatar.jsx` and `brain/tabs/BrainGraph.jsx`. |
| `useMidiNotes` | Fetch + parse a transcribed `.mid` file into the piano-roll view-model (`parseMidiFile` in `lib/midiNotes.js`), with a module-level per-URL cache so remounts (collapse, tab switches) don't refetch/reparse. Returns `{ status: 'idle'\|'loading'\|'ready'\|'error', data, error, reload }`; a generation counter drops stale in-flight responses on URL change/unmount. Plain `fetch` of the static file URL — errors surface inline, never as toasts (#2477). | `<MidiVisualization>` (Rounds ReferenceAnalysis + Music Video). |
| `useChordPlayer` | Chord-sheet play-along transport for a SongBook `tab`/`chordpro` sheet (#4104) — the chord counterpart of `useDrumPlayer`: parses the (already-transposed) text, owns one `createChordPlayer`, the practice settings (tempo + beats-per-chord persisted per song, count-in, machine-global click) and the sounding-chord highlight read off the audio clock. Returns `{ chordCount, hasChords, writtenTempo, bpm, setBpm, setBpmPercent, beatsPerBar, setBeatsPerBar, countInBars, setCountInBars, clickEnabled, setClickEnabled, playing, pulse, sounding, getPlayhead, toggle, stop }`. Timing edits stop playback rather than re-time a running schedule. | `<ChordTransportBar>` + `<ChordPreview>` (SongBook viewer/editor/importer). |
| `useDrumPlayer` | Drum play-along transport for a SongBook `drum` chart (#3115): parses the chart (`lib/drumNotation.js`), owns one `createDrumPlayer` per chart plus the practice settings and the sheet playhead. Returns `{ chart, barCount, writtenTempo, bpm, setBpm, setBpmPercent, countInBars, setCountInBars, loopEnabled, setLoopEnabled, loopFrom, loopTo, setLoopRange, clickEnabled, setClickEnabled, clickVolume, setClickVolume, kitId, setKitId, playing, activeStep, currentBar, toggle, stop }`. The practice tempo persists per song in `safeStorage` (never into the record) while the selected kit (`songbook:drumKit`), the click toggle (`songbook:drumClick`) and the click level (`songbook:drumClickVolume`) persist per MACHINE; a timing-critical edit (tempo / count-in / loop) STOPS playback rather than re-timing already-scheduled audio, while the click toggle, the click level and the kit swap apply live (raising the level off silence also unmutes, so the slider is never a dead control); the player + its interval + scheduled hits tear down on stop, chart change and unmount. | The SongBook viewer and snapshot-based drum previews. Don't hand-wire `createDrumPlayer` + BPM persistence + playhead state again. |
diff --git a/client/src/hooks/index.js b/client/src/hooks/index.js
index c7ab19603f..d98e0e8db8 100644
--- a/client/src/hooks/index.js
+++ b/client/src/hooks/index.js
@@ -94,6 +94,7 @@ export { default as useMidiNotes } from './useMidiNotes.js';
export { default as useMidiPlayer } from './useMidiPlayer.js';
export { default as useCanvasDprSize } from './useCanvasDprSize.js';
export { default as useCanvasRollPalette } from './useCanvasRollPalette.js';
+export { default as usePrefersReducedMotion } from './usePrefersReducedMotion.js';
export { default as useLiveSuggest } from './useLiveSuggest.js';
export { default as useSidebarResize } from './useSidebarResize.js';
export { default as useTokenPopover } from './useTokenPopover.js';
diff --git a/client/src/hooks/useCanvasDprSize.js b/client/src/hooks/useCanvasDprSize.js
index 34de6a2659..3abcdd24a4 100644
--- a/client/src/hooks/useCanvasDprSize.js
+++ b/client/src/hooks/useCanvasDprSize.js
@@ -10,6 +10,10 @@ import { useEffect, useRef } from 'react';
// observer is created once per height and never torn down just because the
// draw closure was recreated.
//
+// `height` is a fixed CSS px value; pass `undefined` to follow the container's
+// own height instead (the canvas then keeps its CSS size from its classes and
+// only the bitmap is resized — the Core Assembly avatar fills an aspect box).
+//
// Returns a ref holding the current CSS width — the draw code reads it
// instead of measuring the DOM per frame.
export default function useCanvasDprSize(wrapRef, canvasRef, height, drawRef) {
@@ -20,15 +24,18 @@ export default function useCanvasDprSize(wrapRef, canvasRef, height, drawRef) {
if (!el) return undefined;
const resize = () => {
const w = Math.floor(el.clientWidth);
- if (!w) return;
+ const h = height ?? Math.floor(el.clientHeight);
+ if (!w || !h) return;
widthRef.current = w;
const canvas = canvasRef.current;
if (!canvas) return;
const dpr = (typeof window !== 'undefined' && window.devicePixelRatio) || 1;
canvas.width = Math.round(w * dpr);
- canvas.height = Math.round(height * dpr);
- canvas.style.width = `${w}px`;
- canvas.style.height = `${height}px`;
+ canvas.height = Math.round(h * dpr);
+ if (height !== undefined) {
+ canvas.style.width = `${w}px`;
+ canvas.style.height = `${height}px`;
+ }
const ctx = canvas.getContext('2d');
if (ctx) ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
drawRef.current();
diff --git a/client/src/hooks/useCanvasRollPalette.js b/client/src/hooks/useCanvasRollPalette.js
index b8f4680ed1..1a0ebd2257 100644
--- a/client/src/hooks/useCanvasRollPalette.js
+++ b/client/src/hooks/useCanvasRollPalette.js
@@ -8,19 +8,23 @@ import { rollPalette } from '../lib/canvasRoll.js';
// hardcoding hex. Mirrors `useChartColors`'s `data-port-theme` MutationObserver
// (set by `useTheme` on <html>), but hands back a ref — not React state — so a
// theme switch repaints the canvas without forcing a component re-render.
-export default function useCanvasRollPalette(drawRef) {
+//
+// `resolve` is the token reader — `rollPalette` for the piano rolls; any other
+// imperative canvas (the Core Assembly avatar) passes its own so the theme
+// observer lifecycle lives in one place.
+export default function useCanvasRollPalette(drawRef, resolve = rollPalette) {
// Lazy one-time init — `useRef(rollPalette())` would re-run the getComputedStyle
// read on every render (hover repaints re-render this component), defeating the
// point of caching the palette.
const paletteRef = useRef(null);
- if (paletteRef.current === null) paletteRef.current = rollPalette();
+ if (paletteRef.current === null) paletteRef.current = resolve();
useEffect(() => {
- const apply = () => { paletteRef.current = rollPalette(); drawRef.current?.(); };
+ const apply = () => { paletteRef.current = resolve(); drawRef.current?.(); };
apply();
if (typeof MutationObserver !== 'function') return undefined;
const observer = new MutationObserver(apply);
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-port-theme'] });
return () => observer.disconnect();
- }, [drawRef]);
+ }, [drawRef, resolve]);
return paletteRef;
}
diff --git a/client/src/hooks/usePrefersReducedMotion.js b/client/src/hooks/usePrefersReducedMotion.js
new file mode 100644
index 0000000000..76b258708b
--- /dev/null
+++ b/client/src/hooks/usePrefersReducedMotion.js
@@ -0,0 +1,20 @@
+import { useEffect, useState } from 'react';
+
+const QUERY = '(prefers-reduced-motion: reduce)';
+
+// The user's `prefers-reduced-motion` setting as React state, tracking live
+// changes. CSS animations honor the media query on their own; this is for the
+// imperative ones — a requestAnimationFrame loop, a three.js frameloop — that
+// have to stop scheduling frames themselves.
+export default function usePrefersReducedMotion() {
+ const [reduced, setReduced] = useState(() => window.matchMedia?.(QUERY).matches ?? false);
+ useEffect(() => {
+ const media = window.matchMedia?.(QUERY);
+ if (!media) return undefined;
+ const update = () => setReduced(media.matches);
+ update();
+ media.addEventListener?.('change', update);
+ return () => media.removeEventListener?.('change', update);
+ }, []);
+ return reduced;
+}
diff --git a/client/src/hooks/useTheme.js b/client/src/hooks/useTheme.js
index b329f24cdf..d1cbff1d65 100644
--- a/client/src/hooks/useTheme.js
+++ b/client/src/hooks/useTheme.js
@@ -11,24 +11,22 @@ import { getSettings, updateSettings } from '../services/apiSystem.js';
const STORAGE_KEY = 'portos-theme';
-// Custom properties the last applyTheme() wrote. A theme only declares the
-// tokens it uses (the optional --port-fx-* effect tokens especially), and an
-// inline property on <html> outlives a theme switch — so without clearing
-// these, Kestrel Neon's multiply-blend scanlines would still tint Classic
-// Midnight after the user switched away.
-let appliedVars = new Set();
-
const applyTheme = (id) => {
const theme = getTheme(id);
const style = document.documentElement.style;
const vars = { ...theme.colors, ...theme.tokens };
- for (const prop of appliedVars) {
- if (!(prop in vars)) style.removeProperty(prop);
+ // A theme only declares the tokens it uses (the optional --port-fx-* effect
+ // tokens especially), and an inline property on <html> outlives a theme
+ // switch — so drop every --port-* the next theme does not declare, or Kestrel
+ // Neon's multiply-blend scanlines would still tint Classic Midnight after the
+ // user switched away. Read off the DOM rather than remembered, so it also
+ // clears what an earlier bundle left behind.
+ for (const prop of Array.from(style)) {
+ if (prop.startsWith('--port-') && !(prop in vars)) style.removeProperty(prop);
}
for (const [prop, value] of Object.entries(vars)) {
style.setProperty(prop, value);
}
- appliedVars = new Set(Object.keys(vars));
const root = document.documentElement;
root.dataset.portTheme = theme.id;
root.dataset.portThemeFamily = theme.family;
diff --git a/client/src/hooks/useTheme.test.jsx b/client/src/hooks/useTheme.test.jsx
index 3707396bd3..16c0737b8e 100644
--- a/client/src/hooks/useTheme.test.jsx
+++ b/client/src/hooks/useTheme.test.jsx
@@ -21,10 +21,10 @@ afterEach(() => {
});
describe('useTheme applies the manifest to <html>', () => {
- const withEffects = Object.values(THEMES).find((t) => t.effects?.length);
- const withoutEffects = Object.values(THEMES).find((t) => !t.effects?.length);
- // A token only the effects theme declares — it must not survive the switch.
- const privateToken = Object.keys(withEffects.tokens).find((k) => !(k in withoutEffects.tokens));
+ const withEffects = THEMES['kestrel-neon'];
+ const withoutEffects = THEMES[DEFAULT_THEME_ID];
+ // Declared only by the effects theme — it must not survive the switch.
+ const privateToken = '--port-fx-overlay-blend';
it('publishes the effects list and clears it again for a theme with none', () => {
const { result } = renderHook(() => useTheme());
@@ -36,7 +36,8 @@ describe('useTheme applies the manifest to <html>', () => {
});
it('removes custom properties the next theme does not declare', () => {
- expect(privateToken).toBeTruthy();
+ expect(privateToken in withEffects.tokens).toBe(true);
+ expect(privateToken in withoutEffects.tokens).toBe(false);
const { result } = renderHook(() => useTheme());
act(() => result.current.setTheme(withEffects.id));
expect(document.documentElement.style.getPropertyValue(privateToken)).not.toBe('');
diff --git a/client/src/index.css b/client/src/index.css
index 4a482dd66e..b8394a0d5f 100644
--- a/client/src/index.css
+++ b/client/src/index.css
@@ -40,6 +40,12 @@
/* Default theme CSS vars (Classic Midnight) - overridden by JS on load */
:root {
+ /* Heading typography — every theme may override; the effects layer's glitch
+ rests on --port-heading-glow so it never dictates a theme's title look. */
+ --port-heading-tracking: 0;
+ --port-heading-glow: none;
+ --port-title-tracking: var(--port-heading-tracking);
+ --port-title-transform: none;
--port-bg: 15 15 15;
--port-card: 26 26 26;
--port-border: 42 42 42;
@@ -325,7 +331,13 @@ html[data-port-theme] h1,
html[data-port-theme] h2,
html[data-port-theme] h3 {
font-family: var(--port-font-display);
- letter-spacing: 0;
+ letter-spacing: var(--port-heading-tracking);
+ text-shadow: var(--port-heading-glow);
+}
+
+html[data-port-theme] h1 {
+ letter-spacing: var(--port-title-tracking);
+ text-transform: var(--port-title-transform);
}
html[data-port-theme] .bg-port-bg {
@@ -1458,19 +1470,22 @@ html[data-port-theme="blueprint-ops-day"] header :is(h1, h2, h3) {
/* === Theme effects layer ===
A theme opts into full-screen effects by listing them in `effects` in
- portosThemes.js; useTheme publishes that list as
- html[data-port-theme-effects="scanlines vignette …"], so each block below
- keys on the ~= attribute selector. Colors, strengths, and timings come from
- --port-fx-* tokens the theme declares (defaults here), so a new theme
- composes effects without adding selectors of its own.
-
- The overlay effects (scanlines, vignette, sweep) share ONE body::after so
- they compose in a single background list; an effect the theme did not list
- resolves to a transparent layer. */
+ portosThemes.js (registry: THEME_EFFECTS; catalogue and tokens:
+ docs/themes/README.md). useTheme publishes that list as
+ html[data-port-theme-effects="scanlines vignette …"], and each block below
+ keys on the ~= attribute selector, parameterized by --port-fx-* tokens the
+ theme declares (defaults here).
+
+ Everything paints on the dedicated <div class="port-fx-layer"> main.jsx
+ renders beside the app, never on body/#root pseudo-elements a theme might
+ also style: ::before is the below-content slot (grid floor), ::after the
+ static above-content overlay (scanlines + vignette, composed in one
+ background list — an unlisted effect resolves to a transparent layer), and
+ the .port-fx-sweep child is the moving band, animated with transform so it
+ stays on the compositor instead of repainting the blended overlay. */
:root {
--port-fx-scanline-color: rgb(255 255 255 / 0.025);
--port-fx-scanline-period: 5px;
- --port-fx-scanline-thickness: 1px;
--port-fx-overlay-blend: screen;
--port-fx-overlay-opacity: 0.22;
--port-fx-vignette-color: rgb(0 0 0 / 0.55);
@@ -1481,52 +1496,59 @@ html[data-port-theme="blueprint-ops-day"] header :is(h1, h2, h3) {
--port-fx-grid-floor-opacity: 0.45;
--port-fx-grid-floor-duration: 3s;
--port-fx-glitch-period: 9s;
- /* Resolved per listed effect below; unlisted effects stay transparent. */
- --port-fx-scanline-active: transparent;
- --port-fx-vignette-active: transparent;
- --port-fx-sweep-active: transparent;
}
html[data-port-theme-effects~="scanlines"] { --port-fx-scanline-active: var(--port-fx-scanline-color); }
html[data-port-theme-effects~="vignette"] { --port-fx-vignette-active: var(--port-fx-vignette-color); }
-html[data-port-theme-effects~="sweep"] { --port-fx-sweep-active: var(--port-fx-sweep-color); }
-html:is([data-port-theme-effects~="scanlines"], [data-port-theme-effects~="vignette"], [data-port-theme-effects~="sweep"]) body::after {
+.port-fx-layer,
+.port-fx-sweep {
+ pointer-events: none;
+}
+
+html:is([data-port-theme-effects~="scanlines"], [data-port-theme-effects~="vignette"]) .port-fx-layer::after {
content: "";
position: fixed;
inset: 0;
z-index: 9998;
pointer-events: none;
background:
- linear-gradient(180deg, transparent, var(--port-fx-sweep-active), transparent) 0 -20% / 100% 18% no-repeat,
- radial-gradient(ellipse at center, transparent 58%, var(--port-fx-vignette-active) 100%),
+ radial-gradient(ellipse at center, transparent 58%, var(--port-fx-vignette-active, transparent) 100%),
repeating-linear-gradient(
0deg,
- transparent 0 calc(var(--port-fx-scanline-period) - var(--port-fx-scanline-thickness)),
- var(--port-fx-scanline-active) calc(var(--port-fx-scanline-period) - var(--port-fx-scanline-thickness)) var(--port-fx-scanline-period)
+ transparent 0 calc(var(--port-fx-scanline-period) - 1px),
+ var(--port-fx-scanline-active, transparent) calc(var(--port-fx-scanline-period) - 1px) var(--port-fx-scanline-period)
);
mix-blend-mode: var(--port-fx-overlay-blend);
opacity: var(--port-fx-overlay-opacity);
}
-html[data-port-theme-effects~="sweep"] body::after {
+html[data-port-theme-effects~="sweep"] .port-fx-sweep {
+ position: fixed;
+ left: 0;
+ right: 0;
+ top: 0;
+ height: 18vh;
+ z-index: 9998;
+ background: linear-gradient(180deg, transparent, var(--port-fx-sweep-color), transparent);
+ transform: translate3d(0, -100%, 0);
+ will-change: transform;
animation: portos-fx-sweep var(--port-fx-sweep-duration) linear infinite;
}
@keyframes portos-fx-sweep {
- to { background-position: 0 120%, 0 0, 0 0; }
+ to { transform: translate3d(0, 100vh, 0); }
}
-/* Perspective grid floor: fixed behind content, masked so it fades toward the
- horizon. Lives on #root::before because body::before is the shared
- token-driven backdrop and a background-image cannot be tilted. */
-html[data-port-theme-effects~="grid-floor"] #root::before {
+/* Perspective grid floor: three viewports wide and one tall, hinged at its
+ bottom edge and tilted away so the near rows stay full size while the far
+ rows converge toward a horizon about a quarter of the way up the screen.
+ The extra width keeps the foreshortened far edge wider than the viewport.
+ Motion is a plane-local translate of exactly one row, so the loop is
+ seamless and the masked texture is rasterized once. */
+html[data-port-theme-effects~="grid-floor"] .port-fx-layer::before {
content: "";
position: fixed;
- /* Three viewports wide and one tall, hinged at its bottom edge and tilted
- away: the near rows stay full size while the far rows converge toward a
- horizon about a quarter of the way up the screen. The extra width keeps
- the foreshortened far edge wider than the viewport. */
left: -100%;
right: -100%;
bottom: -6%;
@@ -1536,62 +1558,65 @@ html[data-port-theme-effects~="grid-floor"] #root::before {
background:
linear-gradient(90deg, var(--port-fx-grid-floor-x) 1px, transparent 1px) 0 0 / 60px 100%,
linear-gradient(0deg, var(--port-fx-grid-floor-y) 1px, transparent 1px) 0 0 / 100% 40px;
- transform: perspective(1200px) rotateX(60deg);
+ transform: perspective(1200px) rotateX(60deg) translateY(0);
transform-origin: 50% 100%;
mask-image: linear-gradient(180deg, transparent 30%, #000 75%);
-webkit-mask-image: linear-gradient(180deg, transparent 30%, #000 75%);
opacity: var(--port-fx-grid-floor-opacity);
+ will-change: transform;
animation: portos-fx-gridmove var(--port-fx-grid-floor-duration) linear infinite;
}
@keyframes portos-fx-gridmove {
- to { background-position: 0 0, 0 40px; }
+ to { transform: perspective(1200px) rotateX(60deg) translateY(40px); }
}
-/* Page titles glitch every few seconds: at rest for most of the cycle, then a
- two-step chromatic split between the two accents. */
+/* Page titles glitch every few seconds: at rest (the theme's own heading glow)
+ for most of the cycle, then a two-step chromatic split between the accents. */
html[data-port-theme-effects~="glitch"] h1 {
animation: portos-fx-glitch var(--port-fx-glitch-period) steps(2) infinite;
}
@keyframes portos-fx-glitch {
- 0%, 92%, 100% { text-shadow: 0 0 12px rgb(var(--port-accent) / 0.5); transform: none; }
+ 0%, 92%, 100% { text-shadow: var(--port-heading-glow); transform: none; }
94% { text-shadow: -3px 0 rgb(var(--port-accent-2)), 3px 0 rgb(var(--port-accent)); transform: translate(-1px, 1px); }
96% { text-shadow: 4px 0 rgb(var(--port-accent-2)), -4px 0 rgb(var(--port-accent)); transform: translate(2px, -1px); }
98% { text-shadow: -1px 0 rgb(var(--port-accent-2)), 1px 0 rgb(var(--port-accent)); transform: translate(1px, 0); }
}
@media (prefers-reduced-motion: reduce) {
- html[data-port-theme-effects] body::after,
- html[data-port-theme-effects] #root::before,
+ html[data-port-theme-effects] .port-fx-sweep,
+ html[data-port-theme-effects] .port-fx-layer::before,
html[data-port-theme-effects] h1 {
animation: none;
}
}
-/* === Kestrel Neon (CRT boot terminal) === */
-html[data-port-theme="kestrel-neon"] body {
- text-shadow: 0 0 10px rgb(var(--port-accent) / 0.08);
+/* === Kestrel (CRT boot terminal) — shared by Neon and Dawn === */
+html[data-port-theme-family="kestrel"] :is(.bg-port-card, [class~="bg-port-card/50"]):is(.border, .rounded, .rounded-lg, .rounded-xl, .rounded-2xl) {
+ border-color: rgb(var(--port-accent-2) / var(--port-kestrel-card-border-alpha)) !important;
+ background-image: linear-gradient(180deg, rgb(var(--port-accent) / 0.06), transparent 32px);
}
-html[data-port-theme="kestrel-neon"] :is(h1, h2, h3) {
- letter-spacing: 0.06em;
- text-shadow: 0 0 12px rgb(var(--port-accent) / 0.5);
+html[data-port-theme-family="kestrel"] :is(pre, code, textarea, input) {
+ caret-color: rgb(var(--port-accent));
}
-html[data-port-theme="kestrel-neon"] h1 {
- text-transform: uppercase;
- letter-spacing: 0.14em;
+html[data-port-theme-family="kestrel"] aside nav [aria-current="page"] {
+ border-left: 2px solid rgb(var(--port-accent-2));
}
-html[data-port-theme="kestrel-neon"] :is(.bg-port-card, [class~="bg-port-card/50"]):is(.border, .rounded, .rounded-lg, .rounded-xl, .rounded-2xl) {
- border-color: rgb(var(--port-accent-2) / 0.3) !important;
- background-image: linear-gradient(180deg, rgb(var(--port-accent) / 0.06), transparent 32px);
+/* === Kestrel Neon (night): the glow === */
+html[data-port-theme="kestrel-neon"] {
+ --port-kestrel-card-border-alpha: 0.3;
+}
+
+html[data-port-theme="kestrel-neon"] body {
+ text-shadow: 0 0 10px rgb(var(--port-accent) / 0.08);
}
html[data-port-theme="kestrel-neon"] :is(pre, code, textarea, input) {
text-shadow: 0 0 8px rgb(var(--port-accent) / 0.25);
- caret-color: rgb(var(--port-accent));
}
html[data-port-theme="kestrel-neon"] :is(input, textarea, select):focus,
@@ -1601,36 +1626,12 @@ html[data-port-theme="kestrel-neon"] a:focus-visible {
}
html[data-port-theme="kestrel-neon"] aside nav [aria-current="page"] {
- border-left: 2px solid rgb(var(--port-accent-2));
text-shadow: 0 0 8px rgb(var(--port-accent) / 0.6);
}
-html[data-port-theme="kestrel-neon"] ::selection {
- background: rgb(var(--port-accent-2) / 0.45);
- color: rgb(255 255 255);
-}
-
-/* === Kestrel Dawn (Kestrel Neon, day) === */
-html[data-port-theme="kestrel-neon-day"] :is(h1, h2, h3) {
- letter-spacing: 0.06em;
-}
-
-html[data-port-theme="kestrel-neon-day"] h1 {
- text-transform: uppercase;
- letter-spacing: 0.14em;
-}
-
-html[data-port-theme="kestrel-neon-day"] :is(.bg-port-card, [class~="bg-port-card/50"]):is(.border, .rounded, .rounded-lg, .rounded-xl, .rounded-2xl) {
- border-color: rgb(var(--port-accent-2) / 0.26) !important;
- background-image: linear-gradient(180deg, rgb(var(--port-accent) / 0.06), transparent 32px);
-}
-
-html[data-port-theme="kestrel-neon-day"] :is(pre, code, textarea, input) {
- caret-color: rgb(var(--port-accent));
-}
-
-html[data-port-theme="kestrel-neon-day"] aside nav [aria-current="page"] {
- border-left: 2px solid rgb(var(--port-accent-2));
+/* === Kestrel Dawn (day) === */
+html[data-port-theme="kestrel-neon-day"] {
+ --port-kestrel-card-border-alpha: 0.26;
}
/* Accessibility: Global focus styles for keyboard navigation */
diff --git a/client/src/lib/chipContrast.js b/client/src/lib/chipContrast.js
index 14ebe0aae1..1f7ca4ebe1 100644
--- a/client/src/lib/chipContrast.js
+++ b/client/src/lib/chipContrast.js
@@ -23,8 +23,9 @@ import { THEMES } from '../themes/portosThemes.js';
import { clamp } from '../utils/formatters.js';
import { evictOldest } from './boundedMap.js';
-// `"234 228 219"` (the `--port-*` color-var form) → `{ r, g, b }`.
-const parseTriple = (triple) => {
+// `"234 228 219"` (the `--port-*` color-var form) → `{ r, g, b }` (NaN channels
+// for anything else — callers validate with Number.isFinite).
+export const parseTriple = (triple) => {
const [r, g, b] = String(triple).trim().split(/\s+/).map(Number);
return { r, g, b };
};
diff --git a/client/src/lib/wireframeCore.js b/client/src/lib/wireframeCore.js
index e2ba424d5e..1f35590343 100644
--- a/client/src/lib/wireframeCore.js
+++ b/client/src/lib/wireframeCore.js
@@ -99,6 +99,7 @@ export function drawWireframeCore(ctx, {
ctx.setLineDash([]);
// Edges, depth-shaded: near edges are brighter, thicker, and glow.
+ ctx.shadowColor = rgba(edgeRgb, 0.8);
for (const [a, b] of ICOSAHEDRON_EDGES) {
const pa = proj[a];
const pb = proj[b];
@@ -107,7 +108,6 @@ export function drawWireframeCore(ctx, {
const alpha = 0.35 + 0.55 * (1 - (depth + 1) / 2);
ctx.strokeStyle = rgba(edgeRgb, alpha);
ctx.lineWidth = near ? 1.4 : 0.7;
- ctx.shadowColor = rgba(edgeRgb, 0.8);
ctx.shadowBlur = near ? 6 + pulse * 6 : 0;
ctx.beginPath();
ctx.moveTo(pa[0], pa[1]);
diff --git a/client/src/main.jsx b/client/src/main.jsx
index edd843f65a..2d67d7deaf 100644
--- a/client/src/main.jsx
+++ b/client/src/main.jsx
@@ -65,6 +65,10 @@ const router = createBrowserRouter([
element: (
<>
<App />
+ {/* Theme effects (scanlines, grid floor, sweep) paint on this element's
+ pseudo-elements and child — see the "Theme effects layer" in
+ index.css. Empty and inert for themes that list no effects. */}
+ <div className="port-fx-layer" aria-hidden="true"><span className="port-fx-sweep" /></div>
<Toaster
position="bottom-right"
toastOptions={{
diff --git a/client/src/themes/portosThemes.js b/client/src/themes/portosThemes.js
index 233c743a08..adaec4d7c8 100644
--- a/client/src/themes/portosThemes.js
+++ b/client/src/themes/portosThemes.js
@@ -28,16 +28,9 @@ const DEFAULT_ACCENT2 = {
'--port-accent-2-text': '216 180 254',
};
-// Optional full-screen effects a theme composes by listing them in `effects`.
-// Each is a shared CSS block in index.css keyed on
-// html[data-port-theme-effects~="<name>"] and parameterized by --port-fx-*
-// tokens (defaults in index.css :root), so a new theme picks effects and tunes
-// their colors without adding selectors of its own.
-// scanlines — CRT line overlay above the app (body::after)
-// vignette — darkened viewport edges on that same overlay
-// sweep — a phosphor band drifting down the overlay
-// grid-floor — a perspective grid receding under the page (#root::before)
-// glitch — periodic chromatic split on page titles (h1)
+// Full-screen effects a theme composes by listing them in `effects`; each is
+// a shared block in index.css ("Theme effects layer") tuned by --port-fx-*
+// tokens. Catalogue and tokens: docs/themes/README.md, "Effects".
export const THEME_EFFECTS = Object.freeze(['scanlines', 'vignette', 'sweep', 'grid-floor', 'glitch']);
const baseMotionTokens = {
@@ -54,6 +47,37 @@ const classicShapeTokens = {
'--port-radius-pill': '9999px',
};
+// Kestrel Neon / Kestrel Dawn share their shell: monospaced everywhere, square
+// corners, uppercase tracked titles. The day entry differs only in color,
+// shadow, and effect tuning.
+const kestrelShellTokens = {
+ '--port-motion-fast': '90ms',
+ '--port-motion-medium': '160ms',
+ '--port-motion-slow': '300ms',
+ '--port-radius-sm': '0',
+ '--port-radius-md': '0.125rem',
+ '--port-radius-lg': '0.25rem',
+ '--port-radius-xl': '0.375rem',
+ '--port-radius-pill': '0.25rem',
+ '--port-bg-alpha': '1',
+ '--port-border-alpha': '0.3',
+ '--port-sidebar-alpha': '0.96',
+ '--port-panel-padding-scale': '0.92',
+ '--port-font-ui': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace",
+ '--port-font-display': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace",
+ '--port-font-mono': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace",
+ '--port-heading-tracking': '0.06em',
+ '--port-title-tracking': '0.14em',
+ '--port-title-transform': 'uppercase',
+ '--port-border-style': 'solid',
+ '--port-body-size': 'cover, cover',
+ '--port-body-overlay-opacity': '1',
+ '--port-app-backdrop': 'transparent',
+ '--port-control-border': 'rgb(var(--port-border) / 0.3)',
+ '--port-fx-scanline-period': '3px',
+ '--port-fx-overlay-blend': 'multiply',
+};
+
export const THEMES = {
[DEFAULT_THEME_ID]: {
id: DEFAULT_THEME_ID,
@@ -455,10 +479,6 @@ export const THEMES = {
'--port-chart-3': '255 214 10',
'--port-chart-4': '0 194 255',
'--port-chart-grid': '0 245 160',
- '--port-fx-scanline-color': 'rgb(255 255 255 / 0.025)',
- '--port-fx-scanline-period': '5px',
- '--port-fx-overlay-blend': 'screen',
- '--port-fx-overlay-opacity': '0.22',
},
},
@@ -545,7 +565,6 @@ export const THEMES = {
'--port-chart-4': '8 100 134',
'--port-chart-grid': '8 108 67',
'--port-fx-scanline-color': 'rgb(10 60 30 / 0.04)',
- '--port-fx-scanline-period': '5px',
'--port-fx-overlay-blend': 'multiply',
'--port-fx-overlay-opacity': '0.4',
},
@@ -755,39 +774,21 @@ export const THEMES = {
'--port-focus-ring': '0 240 255',
},
tokens: {
- '--port-motion-fast': '90ms',
- '--port-motion-medium': '160ms',
- '--port-motion-slow': '300ms',
- '--port-radius-sm': '0',
- '--port-radius-md': '0.125rem',
- '--port-radius-lg': '0.25rem',
- '--port-radius-xl': '0.375rem',
- '--port-radius-pill': '0.25rem',
- '--port-bg-alpha': '1',
+ ...kestrelShellTokens,
'--port-card-alpha': '0.92',
'--port-card-min-alpha': '0.88',
- '--port-border-alpha': '0.3',
- '--port-sidebar-alpha': '0.96',
'--port-overlay-alpha': '0.8',
- '--port-panel-padding-scale': '0.92',
- '--port-font-ui': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace",
- '--port-font-display': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace",
- '--port-font-mono': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace",
+ '--port-heading-glow': '0 0 12px rgb(var(--port-accent) / 0.5)',
'--port-shadow-card': '0 0 0 1px rgb(var(--port-accent-2) / 0.14), 0 0 34px rgb(var(--port-accent-2) / 0.08), inset 0 0 48px rgb(0 0 0 / 0.45)',
'--port-shadow-elevated': '0 0 0 1px rgb(var(--port-accent) / 0.28), 0 0 44px rgb(var(--port-accent) / 0.14), 0 18px 60px rgb(0 0 0 / 0.7)',
'--port-shadow-interactive': '0 0 0 1px rgb(var(--port-accent) / 0.45), 0 0 18px rgb(var(--port-accent) / 0.22)',
'--port-backdrop-filter': 'blur(6px)',
- '--port-border-style': 'solid',
'--port-body-gradient': 'radial-gradient(ellipse at 50% 0%, rgb(16 20 42) 0%, rgb(5 6 10) 60%)',
'--port-body-texture': 'radial-gradient(ellipse at 50% 100%, rgb(var(--port-accent-2) / 0.08) 0%, transparent 55%)',
- '--port-body-size': 'cover, cover',
- '--port-body-overlay-opacity': '1',
- '--port-app-backdrop': 'transparent',
'--port-sidebar-bg': 'rgb(10 12 22 / 0.94)',
'--port-input-bg': 'rgb(3 4 8 / 0.8)',
'--port-control-bg': 'rgb(14 18 36 / 0.94)',
'--port-control-bg-hover': 'rgb(22 30 56 / 0.98)',
- '--port-control-border': 'rgb(var(--port-border) / 0.3)',
'--port-active-bg': 'linear-gradient(90deg, rgb(var(--port-accent) / 0.16), rgb(var(--port-accent-2) / 0.1))',
'--port-hover-bg': 'rgb(var(--port-accent) / 0.08)',
'--port-terminal-bg': 'rgb(3 4 8)',
@@ -798,17 +799,10 @@ export const THEMES = {
'--port-chart-4': '92 255 138',
'--port-chart-grid': '0 240 255',
'--port-fx-scanline-color': 'rgb(0 0 0 / 0.18)',
- '--port-fx-scanline-period': '3px',
- '--port-fx-overlay-blend': 'multiply',
'--port-fx-overlay-opacity': '0.8',
- '--port-fx-vignette-color': 'rgb(0 0 0 / 0.55)',
- '--port-fx-sweep-color': 'rgb(var(--port-accent) / 0.07)',
- '--port-fx-sweep-duration': '7s',
'--port-fx-grid-floor-x': 'rgb(var(--port-accent-2) / 0.32)',
'--port-fx-grid-floor-y': 'rgb(var(--port-accent) / 0.32)',
'--port-fx-grid-floor-opacity': '0.7',
- '--port-fx-grid-floor-duration': '3s',
- '--port-fx-glitch-period': '9s',
},
},
@@ -852,39 +846,20 @@ export const THEMES = {
'--port-focus-ring': '14 124 140',
},
tokens: {
- '--port-motion-fast': '90ms',
- '--port-motion-medium': '160ms',
- '--port-motion-slow': '300ms',
- '--port-radius-sm': '0',
- '--port-radius-md': '0.125rem',
- '--port-radius-lg': '0.25rem',
- '--port-radius-xl': '0.375rem',
- '--port-radius-pill': '0.25rem',
- '--port-bg-alpha': '1',
+ ...kestrelShellTokens,
'--port-card-alpha': '1',
'--port-card-min-alpha': '1',
- '--port-border-alpha': '0.3',
- '--port-sidebar-alpha': '0.96',
'--port-overlay-alpha': '0.66',
- '--port-panel-padding-scale': '0.92',
- '--port-font-ui': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace",
- '--port-font-display': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace",
- '--port-font-mono': "'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Liberation Mono', monospace",
'--port-shadow-card': '0 0 0 1px rgb(var(--port-accent-2) / 0.12), 0 8px 24px -10px rgb(14 124 140 / 0.18)',
'--port-shadow-elevated': '0 0 0 1px rgb(var(--port-accent) / 0.24), 0 22px 54px -16px rgb(14 124 140 / 0.28)',
'--port-shadow-interactive': '0 0 0 1px rgb(var(--port-accent) / 0.5), 0 0 14px rgb(var(--port-accent) / 0.14)',
'--port-backdrop-filter': 'none',
- '--port-border-style': 'solid',
'--port-body-gradient': 'radial-gradient(ellipse at 50% 0%, rgb(255 255 255) 0%, rgb(234 236 246) 60%)',
'--port-body-texture': 'radial-gradient(ellipse at 50% 100%, rgb(var(--port-accent-2) / 0.07) 0%, transparent 55%)',
- '--port-body-size': 'cover, cover',
- '--port-body-overlay-opacity': '1',
- '--port-app-backdrop': 'transparent',
'--port-sidebar-bg': 'rgb(255 255 255 / 0.9)',
'--port-input-bg': 'rgb(255 255 255 / 0.92)',
'--port-control-bg': 'rgb(244 246 252 / 0.96)',
'--port-control-bg-hover': 'rgb(228 232 246 / 0.98)',
- '--port-control-border': 'rgb(var(--port-border) / 0.3)',
'--port-active-bg': 'linear-gradient(90deg, rgb(var(--port-accent) / 0.14), rgb(var(--port-accent-2) / 0.08))',
'--port-hover-bg': 'rgb(var(--port-accent) / 0.07)',
'--port-terminal-bg': 'rgb(246 247 252)',
@@ -895,8 +870,6 @@ export const THEMES = {
'--port-chart-4': '21 128 61',
'--port-chart-grid': '14 124 140',
'--port-fx-scanline-color': 'rgb(var(--port-accent) / 0.05)',
- '--port-fx-scanline-period': '3px',
- '--port-fx-overlay-blend': 'multiply',
'--port-fx-overlay-opacity': '0.6',
'--port-fx-grid-floor-x': 'rgb(var(--port-accent-2) / 0.2)',
'--port-fx-grid-floor-y': 'rgb(var(--port-accent) / 0.22)',
diff --git a/docs/plans/2026-09-04-kestrel-neon-theme.md b/docs/plans/2026-09-04-kestrel-neon-theme.md
index 8b3388d12d..53ac03922c 100644
--- a/docs/plans/2026-09-04-kestrel-neon-theme.md
+++ b/docs/plans/2026-09-04-kestrel-neon-theme.md
@@ -34,16 +34,23 @@ a theme lists effects in its manifest (`effects: [...]`, registry
`THEME_EFFECTS`); `useTheme` publishes them as `data-port-theme-effects` on
`<html>`; each effect is one block keyed on
`html[data-port-theme-effects~="<name>"]` and parameterized by `--port-fx-*`
-tokens defaulted in `:root`. The three overlay effects (scanlines, vignette,
-sweep) share one `body::after` and compose as a single background list;
-unlisted effects resolve to a transparent layer. `grid-floor` lives on
-`#root::before` because `body::before` is the token-driven backdrop and a
-background image cannot be tilted. `glitch` animates `h1`. Every animation is
-off under `prefers-reduced-motion`. Black ICE Terminal's scanlines moved onto
-the shared layer with identical values, so it renders as before.
+tokens defaulted in `:root`. Everything paints on a dedicated
+`<div class="port-fx-layer">` rendered by `main.jsx`, so a theme's own
+`body::before/::after` rules (Lumen Glass Day's drift) can never collide with
+it: `::before` is the below-content slot (`grid-floor`), `::after` the static
+overlay (`scanlines` + `vignette` composed in one background list, unlisted
+effects transparent), and a `.port-fx-sweep` child is the moving band. The
+sweep and the floor animate `transform` only, so they stay on the compositor
+instead of repainting a blended full-screen layer every frame. `glitch`
+animates `h1` and rests on the new `--port-heading-glow` token (with
+`--port-heading-tracking`, `--port-title-tracking`, `--port-title-transform`,
+heading treatment is now a manifest concern, not a selector block). Every
+animation is off under `prefers-reduced-motion`. Black ICE Terminal's
+scanlines moved onto the shared layer with identical values, so it renders as
+before.
-**`applyTheme` clears stale tokens**: it remembers the properties it set and
-removes any the next theme does not declare (`useTheme.test.jsx` pins both the
+**`applyTheme` clears stale tokens**: it walks the inline `--port-*`
+properties on `<html>` and removes any the next theme does not declare (`useTheme.test.jsx` pins both the
effects attribute and the clearing).
**Core Assembly avatar** (`client/src/components/cos/CoreCoSAvatar.jsx`,
@@ -51,8 +58,11 @@ style id `core`): a plain 2D canvas, so it needs no WebGL and skips
`CoSCanvasGuard`. Geometry and the frame renderer are pure
(`client/src/lib/wireframeCore.js`). Edges take the agent-state color (the
intentional 7-way `AGENT_STATES` enum); rings and vertices follow
-`--port-accent-2`, re-resolved on theme switch through the same
-`data-port-theme` mutation signal `useCanvasRollPalette` watches. Spin and glow
+`--port-accent-2`, re-resolved on theme switch through `useCanvasRollPalette`
+(which now takes the resolver as an argument) and sized through
+`useCanvasDprSize` (which now follows the container height); reduced motion
+comes from the new shared `usePrefersReducedMotion` hook, which BrainGraph
+also adopted. Spin and glow
scale per state, `speaking` bursts both, drag rotates, and reduced motion holds
one static frame. It is theme-independent: pick it under any theme.
diff --git a/docs/themes/README.md b/docs/themes/README.md
index f2e3dcfb4a..7f95f193db 100644
--- a/docs/themes/README.md
+++ b/docs/themes/README.md
@@ -59,17 +59,21 @@ Only the tokens the active theme declares stay on `<html>`: `applyTheme` removes
## Effects
-Full-screen effects are shared primitives, not per-theme CSS. A theme lists the ones it wants in its manifest and tunes them with `--port-fx-*` tokens; `useTheme` publishes the list as `data-port-theme-effects` on `<html>`, and `index.css` keys one block per effect on `html[data-port-theme-effects~="<name>"]`.
+Full-screen effects are shared primitives, not per-theme CSS. A theme lists the ones it wants in its manifest and tunes them with `--port-fx-*` tokens; `useTheme` publishes the list as `data-port-theme-effects` on `<html>`, and `index.css` keys one block per effect on `html[data-port-theme-effects~="<name>"]`. Everything paints on the dedicated `<div class="port-fx-layer">` that `main.jsx` renders beside the app — never on `body` or `#root` pseudo-elements a theme might also style — so a theme's own backdrop rules (Lumen Glass Day's drifting mesh lives on `body::before/::after`) cannot collide with it.
| Effect | Where it paints | Tokens |
| --- | --- | --- |
-| `scanlines` | CRT line overlay above the app (`body::after`) | `--port-fx-scanline-color`, `--port-fx-scanline-period`, `--port-fx-scanline-thickness` |
+| `scanlines` | CRT line overlay above the app (`.port-fx-layer::after`) | `--port-fx-scanline-color`, `--port-fx-scanline-period` |
| `vignette` | darkened viewport edges on that overlay | `--port-fx-vignette-color` |
-| `sweep` | a phosphor band drifting down that overlay | `--port-fx-sweep-color`, `--port-fx-sweep-duration` |
-| `grid-floor` | a perspective grid receding under the page (`#root::before`) | `--port-fx-grid-floor-x`, `--port-fx-grid-floor-y`, `--port-fx-grid-floor-opacity`, `--port-fx-grid-floor-duration` |
+| `sweep` | a phosphor band drifting down the screen (`.port-fx-sweep`, transform-animated so it never repaints the overlay) | `--port-fx-sweep-color`, `--port-fx-sweep-duration` |
+| `grid-floor` | a perspective grid receding under the page (`.port-fx-layer::before`) | `--port-fx-grid-floor-x`, `--port-fx-grid-floor-y`, `--port-fx-grid-floor-opacity`, `--port-fx-grid-floor-duration` |
| `glitch` | periodic chromatic split on page titles (`h1`) | `--port-fx-glitch-period` |
-The three overlay effects share one `body::after` and compose in a single background list, governed by `--port-fx-overlay-blend` and `--port-fx-overlay-opacity`; an effect the theme did not list resolves to a transparent layer. Every effect animation is disabled under `prefers-reduced-motion`. `THEME_EFFECTS` in `portosThemes.js` is the registry — `npm run theme:check` fails on an unknown name and on a registered effect with no CSS block. Adding an effect means: a name in `THEME_EFFECTS`, one `html[data-port-theme-effects~="<name>"]` block with its tokens defaulted in `:root`, and a row here.
+`scanlines` and `vignette` share the overlay and compose in a single background list, governed by `--port-fx-overlay-blend` and `--port-fx-overlay-opacity`; an effect the theme did not list resolves to a transparent layer. Every effect animation is disabled under `prefers-reduced-motion`. `THEME_EFFECTS` in `portosThemes.js` is the registry — `npm run theme:check` fails on an unknown name, on a registered effect with no CSS block, and on a `--port-fx-*` token declared for an effect the theme does not list (it would silently paint nothing). A theme declares only the tokens where it diverges from the `:root` defaults. Adding an effect means: a name in `THEME_EFFECTS`, one `html[data-port-theme-effects~="<name>"]` block with its tokens defaulted in `:root`, its token prefix in `check-themes.js`, and a row here.
+
+## Typography tokens
+
+Headings read `--port-heading-tracking` and `--port-heading-glow` (h1–h3) plus `--port-title-tracking` and `--port-title-transform` (h1 only), all defaulted to neutral in `:root`, so a theme sets its title treatment in the manifest instead of a selector block — Kestrel's uppercase, tracked, glowing titles are four tokens. The `glitch` effect rests on `--port-heading-glow`, so listing it never changes a theme's resting title look.
Black ICE Terminal (both modes) uses `scanlines`; Kestrel Neon uses all five, and Kestrel Dawn `scanlines` + `grid-floor`.
diff --git a/scripts/check-themes.js b/scripts/check-themes.js
index f2965a5950..94c1140194 100644
--- a/scripts/check-themes.js
+++ b/scripts/check-themes.js
@@ -83,6 +83,16 @@ const REQUIRED_TOKEN_VARS = [
'--port-motion-slow',
];
+// --port-fx-* token prefix → the effect(s) that read it.
+const FX_TOKEN_OWNERS = [
+ ['--port-fx-scanline-', ['scanlines']],
+ ['--port-fx-overlay-', ['scanlines', 'vignette']],
+ ['--port-fx-vignette-', ['vignette']],
+ ['--port-fx-sweep-', ['sweep']],
+ ['--port-fx-grid-floor-', ['grid-floor']],
+ ['--port-fx-glitch-', ['glitch']],
+];
+
const REQUIRED_DOC_SECTIONS = [
'## Intent',
'## Integration Rules',
@@ -124,9 +134,19 @@ async function main() {
assert(theme.accent?.startsWith('#'), `${id} needs a hex accent`);
assert(Array.isArray(theme.swatches) && theme.swatches.length >= 4, `${id} needs at least four swatches`);
- for (const effect of theme.effects ?? []) {
+ const effects = theme.effects ?? [];
+ for (const effect of effects) {
assert(THEME_EFFECTS.includes(effect), `${id} lists unknown effect ${effect}`);
}
+ // A --port-fx-* token tunes exactly one effect (the overlay tokens tune the
+ // two overlay effects); declaring one for an effect the theme does not list
+ // would silently paint nothing.
+ for (const token of Object.keys(theme.tokens ?? {})) {
+ const owner = FX_TOKEN_OWNERS.find(([prefix]) => token.startsWith(prefix));
+ if (!token.startsWith('--port-fx-')) continue;
+ assert(owner, `${id} declares ${token}, which no effect reads`);
+ assert(owner[1].some((effect) => effects.includes(effect)), `${id} declares ${token} without listing ${owner[1].join(' or ')}`);
+ }
assert(isPlainObject(theme.colors), `${id} colors must be a plain object`);
assert(isPlainObject(theme.tokens), `${id} tokens must be a plain object`);