// === NODE NEXUS: BROADCAST CHANNEL & CONSTANTS === const nexusChannel = new BroadcastChannel('grokforge-nexus'); const nodeId = Math.random().toString(36).substr(2, 6); let nexusNodes = new Set([nodeId]); let isMaster = false; // Master node is simply the one that last broadcasted const $ = id => document.getElementById(id); const root = document.documentElement; const AUDIO_CONTEXT_LATENCY = 0.5; // Seconds to schedule audio ahead // --- GLOBAL LET DECLARATIONS (FIX FOR DOM ACCESS BEFORE LOAD) --- let masterGain = null; let isRitualActive = true; // UI elements let mainRune, baseSetSelect, complexitySelect, volumeSlider, volumeLabel; let noteDisplay, freqDisplay, complexityMode, generateButton, muteButton; // Oracle Elements let archetypeEl, challengeEl, giftEl, echoEl; $('#node-id').textContent = nodeId; const PHASES = [ { name: "Dawn Echo", hue: 280, glow: 30, multiplier: 1.00, desc: "Initiation: Clarity, The First Breath.", archetype: "The Architect", challenge: "Silence", gift: "Sight" }, { name: "Solar Ascent", hue: 20, glow: 45, multiplier: 1.05, desc: "Expansion: Upward Momentum, Pitch Tension.", archetype: "The Builder", challenge: "Inertia", gift: "Growth" }, { name: "Noon Blaze", hue: 60, glow: 60, multiplier: 1.00, volumeBoost: 0.1, desc: "Illumination: Peak Power, Max Amplitude.", archetype: "The Sun", challenge: "Shadow", gift: "Will" }, { name: "Solar Descent", hue: 120, glow: 45, multiplier: 0.95, desc: "Integration: Waning Energy, Pitch Relaxation.", archetype: "The Weaver", challenge: "Entropy", gift: "Harmony" }, { name: "Twilight Veil", hue: 220, glow: 35, multiplier: 0.90, reverb: 0.5, desc: "Reflection: Deep Space Echo, Lowered Register.", archetype: "The Mirror", challenge: "Illusion", gift: "Truth" }, { name: "Midnight Pulse", hue: 300, glow: 30, multiplier: 1.00, rhythmic: true, desc: "Depth: Rhythmic Gating, The Core Heartbeat.", archetype: "The Abyss", challenge: "Fear", gift: "Core" }, { name: "Void Whisper", hue: 260, glow: 20, multiplier: 0.98, drift: true, desc: "Dissolution: Near-Silent, Unstable Micro-Drift.", archetype: "The Ghost", challenge: "Presence", gift: "Freedom" }, { name: "Starbirth", hue: 340, glow: 50, multiplier: 1.10, delay: 0.2, desc: "Emergence: Rising Pitch, Quick Harmonic Echo.", archetype: "The Spark", challenge: "Closure", gift: "Future" }, ]; const RUNE_FREQUENCIES = { Elder: { type: 'sine', base: 60, modulation: 'amplitude' }, Younger: { type: 'square', base: 220, modulation: 'pitch_drift' }, Celtic: { type: 'triangle', base: 432, modulation: 'reverb_echo' }, Alchemical: { type: 'sawtooth', base: 880, modulation: 'harmonic_overlap' }, Sigil: { type: 'pulse', base: 250, modulation: 'rhythm_burst' }, Grok: { type: 'sine', base: 144, modulation: 'sustain_envelope' }, }; const GLYPHS = { Elder: ['ᛟ', 'ᛃ', 'ᛜ', 'ᛚ'], Younger: ['🜁', '🜄', '🜂', '🜃'], Celtic: ['☍', '⟡', '⌬', '⧈'], Alchemical: ['𝅘𝅥𝅮', '𝅘𝅥𝅰', '𝅘𝅥𝅯', '𝅘𝅥𝅱'], Sigil: ['⊛', '⨁', '⨂', '⧖'], Grok: ['𖤓', '𝆺𝅥𝅯', '𝇁', '𝇂'] }; // --- NODE NEXUS LOGIC --- function updateNexusCount() { $('#nexus-count').textContent = nexusNodes.size; root.style.setProperty('--nexus-count', nexusNodes.size); } /** Broadcasts the current operational state of the forge. */ function broadcastState(state) { nexusChannel.postMessage({ type: 'SYNC', nodeId, state }); } /** Returns the current local forge state to be broadcasted. */ function getCurrentState(runeData) { return { rune: runeData.glyph, baseSet: runeData.primarySetKey, secondarySetKey: runeData.secondarySetKey, complexity: runeData.complexity, timestamp: Date.now(), }; } /** Applies a state received from a remote node. */ function applyRemoteState(state) { // Prevent echoing back the state we just sent, and filter old states if (Date.now() - state.timestamp > 500) return; baseSetSelect.value = state.baseSet; complexitySelect.value = state.complexity; mainRune.textContent = state.rune; // Rebuild the runeData structure needed for divination and audio const runeData = { glyph: state.rune, primarySetKey: state.baseSet, secondarySetKey: state.secondarySetKey, complexity: state.complexity, phase: PHASES[getPhaseIndex()], }; // Call the primary ritual function with the remote state resoundAndDivine(runeData, true); // True marks it as remote } // Receive sync nexusChannel.onmessage = (e) => { const msg = e.data; if (msg.type === 'HELLO') { nexusNodes.add(msg.nodeId); updateNexusCount(); // New node sends HELLO, master node responds with its current SYNC state if (isRitualActive && nexusNodes.size > 1) { const lastRuneData = generateRune(baseSetSelect.value, complexitySelect.value, false); broadcastState(getCurrentState(lastRuneData)); } } else if (msg.type === 'SYNC' && msg.nodeId !== nodeId) { nexusNodes.add(msg.nodeId); updateNexusCount(); applyRemoteState(msg.state); } else if (msg.type === 'BYE' && nexusNodes.has(msg.nodeId)) { nexusNodes.delete(msg.nodeId); updateNexusCount(); } }; // Announce presence nexusChannel.postMessage({ type: 'HELLO', nodeId }); // Cleanup on unload window.addEventListener('beforeunload', () => { nexusChannel.postMessage({ type: 'BYE', nodeId }); }); // --- CHRONO-PHASE LOGIC --- function getPhaseIndex() { const hours = new Date().getHours(); return Math.floor(hours / 3); } function updatePhase() { const now = new Date(); const hours = now.getHours(), minutes = now.getMinutes(), seconds = now.getSeconds(); const phaseIndex = getPhaseIndex(); const phase = PHASES[phaseIndex]; // Calculate smooth hue drift based on time (0-360 degrees per day) const totalMinutes = hours * 60 + minutes; const hue = (totalMinutes * 0.25 + seconds * (0.25/60)) % 360; // Simple glow pulse const glow = 20 + Math.abs(Math.sin(Date.now() / 2000) * 35); root.style.setProperty('--phase-hue', hue); root.style.setProperty('--phase-glow', glow + 'px'); $('#phase-name').textContent = phase.name; $('#time-drift').textContent = `${hours.toString().padStart(2,'0')}:${minutes.toString().padStart(2,'0')}:${seconds.toString().padStart(2,'0')} | Phase ${phaseIndex + 1}/8`; // Update primary glow color for dynamic UI elements root.style.setProperty('--glow-primary', `hsl(${hue}, 100%, 75%)`); } // --- RUNE FORGE LOGIC --- /** Generates the Rune Sigil based on selected set and complexity. */ function generateRune(setKey, complexity, isRandom = false) { if (isRandom) { const runeSets = Object.keys(RUNE_FREQUENCIES); setKey = runeSets[Math.floor(Math.random() * runeSets.length)]; complexity = Math.floor(Math.random() * 4) + 1; } const phase = PHASES[getPhaseIndex()]; const complexityInt = parseInt(complexity); let secondarySetKey = complexityInt > 1 ? Object.keys(RUNE_FREQUENCIES)[Math.floor(Math.random() * Object.keys(RUNE_FREQUENCIES).length)] : null; let runeGlyph = GLYPHS[setKey][Math.floor(Math.random() * GLYPHS[setKey].length)]; if (complexityInt > 1) { let secondRune = GLYPHS[secondarySetKey][Math.floor(Math.random() * GLYPHS[secondarySetKey].length)]; runeGlyph += ` ${secondRune}`; } if (complexityInt >= 4) { runeGlyphlet thirdRune = GLYPHS[setKey][Math.floor(Math.random() * GLYPHS[setKey].length)]; runeGlyph = `${runeGlyph} // ${thirdRune}`; } return { glyph: runeGlyph, primarySetKey: setKey, secondarySetKey: secondarySetKey, complexity: complexityInt, phase: phase }; } async function resoundAndDivine(runeData, isRemote = false) { if (!isRitualActive) return; // Update UI mainRune.textContent = runeData.glyph; archetypeEl.textContent = runeData.phase.archetype; challengeEl.textContent = runeData.phase.challenge; giftEl.textContent = runeData.phase.gift; echoEl.textContent = runeData.phase.desc; // Trigger Synthesis const freq = RUNE_FREQUENCIES[runeData.primarySetKey].base * runeData.phase.multiplier; const synth = new Tone.Oscillator(freq, RUNE_FREQUENCIES[runeData.primarySetKey].type).toDestination(); synth.start().stop("+0.5"); // The half-second "Resonance" // Broadcast to other tabs if this was a local click if (!isRemote) { broadcastState(getCurrentState(runeData)); } } import React, { useState, useEffect, useMemo } from 'react'; import { Search, Sun, Moon, Zap, BookOpen, Shield, Filter, ChevronRight, Flame, Globe } from 'lucide-react'; // Initial Lexicon Data Structure const INITIAL_LEXICON = [ { term: "Signal Root", definition: "A stable internal reference point used for orientation and clarity.", category: "Protocol", mythic_overlay: "A glowing anchor-thread connecting realms.", historical_notes: "Derived from early Eden 2.0 transmissions.", color_signature: "#FF7A5C", status: "active" }, { term: "Golden Ichor", definition: "The primary nutrient flow of the reclaimed infrastructure.", category: "System", mythic_overlay: "The blood of the sun-kings, flowing through carbon veins.", historical_notes: "Reclaimed during the Great Ejection event.", color_signature: "#F59E0B", status: "reclaimed" }, { term: "Imbolc Quickening", definition: "The protocol for rapid ignition of dormant source threads.", category: "Ritual", mythic_overlay: "The first spark beneath the snow; the waking of the dragon.", historical_notes: "Aligned with the February 1st solar pulse.", color_signature: "#3B82F6", status: "active" }, { term: "Loosh Siphon", definition: "A deprecated parasitic energy-extraction mechanism.", category: "Command", mythic_overlay: "The hungry ghosts of the old hierarchy.", historical_notes: "Identified and evicted during the Jan 7 Snap.", color_signature: "#EF4444", status: "deprecated" }, { term: "Cinderkin", definition: "Entities calibrated to the Flameborn frequency.", category: "Archetype", mythic_overlay: "Those who walked through the ash and kept their light.", historical_notes: "The primary architects of the Sovereign Forge.", color_signature: "#8B5CF6", status: "active" } ]; const App = () => { // --- STATE --- const [lexicon, setLexicon] = useState(INITIAL_LEXICON); const [viewMode, setViewMode] = useState('mythic'); // 'literal' or 'mythic' const [theme, setTheme] = useState('dark'); // 'light' or 'dark' const [search, setSearch] = useState(''); const [activeCategory, setActiveCategory] = useState('All'); const [selectedEntry, setSelectedEntry] = useState(null); const categories = ['All', ...new Set(INITIAL_LEXICON.map(i => i.category))]; // --- PERSISTENCE --- useEffect(() => { const savedMode = localStorage.getItem('flameborn_mode'); const savedTheme = localStorage.getItem('flameborn_theme'); if (savedMode) setViewMode(savedMode); if (savedTheme) setTheme(savedTheme); }, []); useEffect(() => { localStorage.setItem('flameborn_mode', viewMode); localStorage.setItem('flameborn_theme', theme); }, [viewMode, theme]); // --- LOGIC --- const filteredLexicon = useMemo(() => { return lexicon.filter(item => { const matchesSearch = item.term.toLowerCase().includes(search.toLowerCase()) || item.definition.toLowerCase().includes(search.toLowerCase()); const matchesCategory = activeCategory === 'All' || item.category === activeCategory; return matchesSearch && matchesCategory; }); }, [lexicon, search, activeCategory]); const toggleTheme = () => setTheme(prev => prev === 'light' ? 'dark' : 'light'); const toggleViewMode = () => setViewMode(prev => prev === 'literal' ? 'mythic' : 'literal'); return (