<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>VISCERAL CURRENT | Sovereign OS v5.3-Codex</title>

    

    <!-- 2026 Tech Stack: Core Dependencies -->

    <script src="https://cdn.tailwindcss.com"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.49/Tone.js"></script>

    

    <!-- React & Babel for Single-File Execution -->

    <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>

    <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>

    <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>


    <style>

        @import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,700;0,900;1,900&family=JetBrains+Mono:wght@400;700;800&display=swap');

        

        :root {

            --brand-purple: #8b5cf6;

            --brand-blue: #3b82f6;

            --brand-red: #ef4444;

        }


        body {

            margin: 0;

            overflow: hidden;

            background-color: #000;

            font-family: 'Inter', sans-serif;

            color: white;

            cursor: crosshair;

        }


        .font-mono { font-family: 'JetBrains Mono', monospace; }


        /* Cinematic Manifold Layers */

        #background-engine {

            position: fixed;

            top: 0; left: 0; width: 100vw; height: 100vh;

            z-index: -1;

        }


        .bg-layer {

            position: absolute;

            inset: 0;

            background-size: cover;

            background-position: center;

            opacity: 0;

            transition: opacity 3s cubic-bezier(0.16, 1, 0.3, 1);

            filter: brightness(0.35) contrast(1.25);

        }


        .bg-active { opacity: 1; }


        /* HUD Styling */

        .glass {

            background: rgba(4, 4, 10, 0.9);

            backdrop-filter: blur(60px);

            border: 1px solid rgba(255, 255, 255, 0.06);

            box-shadow: 0 40px 120px 0 rgba(0, 0, 0, 1);

        }


        .mission-gradient {

            background: linear-gradient(to right, #fff 30%, var(--brand-purple) 100%);

            -webkit-background-clip: text;

            -webkit-text-fill-color: transparent;

        }


        /* Forensic Scanlines */

        body::after {

            content: " ";

            display: block;

            position: absolute;

            top: 0; left: 0; bottom: 0; right: 0;

            background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.02), rgba(0, 255, 0, 0.015), rgba(0, 0, 255, 0.02));

            z-index: 100;

            background-size: 100% 2px, 3px 100%;

            pointer-events: none;

        }


        .custom-scroll::-webkit-scrollbar { width: 2px; }

        .custom-scroll::-webkit-scrollbar-thumb { background: var(--brand-purple); border-radius: 10px; }


        .ai-shimmer {

            background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.3), transparent);

            background-size: 200% 100%;

            animation: shimmer 2s infinite linear;

        }


        @keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }


        #canvas-mount {

            position: fixed;

            inset: 0;

            z-index: 10;

        }


        .node-active-glitch {

            animation: glitch 0.3s infinite;

        }


        @keyframes glitch {

            0% { transform: translate(0); }

            50% { transform: translate(-2px, 1px); opacity: 0.8; }

            100% { transform: translate(0); }

        }

    </style>

</head>

<body>


    <!-- BOOTSTRAP ROOT -->

    <div id="root"></div>


    <!-- MAIN OS APPLICATION CORE -->

    <script type="text/babel">

        const { useState, useEffect, useRef, useMemo } = React;


        const App = () => {

            const mountRef = useRef(null);

            const [isBooted, setIsBooted] = useState(false);

            const [stage, setStage] = useState('threshold'); // threshold, os, prospectus

            const [activeNode, setActiveNode] = useState(null);

            const [sharedDataCount, setSharedDataCount] = useState(0);

            const [depth, setDepth] = useState(0);

            const [isAiThinking, setIsAiThinking] = useState(false);

            const [aiResponse, setAiResponse] = useState("");

            const [aiChallenge, setAiChallenge] = useState("");

            const [userInput, setUserInput] = useState("");

            const [variance, setVariance] = useState("1.00000");

            const [archetype, setArchetype] = useState("Establishing Profile...");

            const [audioStarted, setAudioStarted] = useState(false);


            const nodes = useMemo(() => [

                "Stoic Baseline", "Breath Control", "Capital Flow", "Ego Death", "Strategic Reach",

                "Victorville Foundation", "Montana Grit", "Bio-Algorithm", "Sovereign Haven", "Domain Logic",

                "Neural Elasticity", "High Stakes", "Grace Under Pressure", "Asset Architecture", "Forensic Mindset",

                "Yield Matrix", "Assumption Tracking", "Current Navigation", "Anchor Discipline", "Spiritual Forge",

                "Capacity Optimization", "The 33 Vector", "The 9 Completion", "The 3 Foundation", "Digital Dominion",

                "Biological Sovereignty", "Market Fluidity", "Cognitive Friction", "Infinite Branching", "Unity in Action",

                "The 44th Node", "Pure Potency", "Creative Chaos", "Ordered Flow", "Shadow Integration",

                "Practical Mysticism", "Economic Stealth", "Personal Cartography", "Identity Filter", "Grit Synthesis",

                "Atmosphere Authority", "Real-Time Alignment", "Presence Protocol", "Final Sovereignty"

            ], []);


            // 1. ENGINE STARTUP

            useEffect(() => {

                init3D();

                setTimeout(() => setIsBooted(true), 2500);

            }, []);


            // 2. 5D INTERACTIVE ENGINE (THREE.JS)

            const sceneRef = useRef(null);

            const nodeGroupRef = useRef(null);

            const cameraRef = useRef(null);


            const init3D = () => {

                const scene = new THREE.Scene();

                scene.fog = new THREE.FogExp2(0x000000, 0.001);

                sceneRef.current = scene;


                const camera = new THREE.PerspectiveCamera(65, window.innerWidth / window.innerHeight, 1, 5000);

                camera.position.z = 1500;

                cameraRef.current = camera;


                const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });

                renderer.setSize(window.innerWidth, window.innerHeight);

                renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));

                mountRef.current.appendChild(renderer.domElement);


                const nodeGroup = new THREE.Group();

                scene.add(nodeGroup);

                nodeGroupRef.current = nodeGroup;


                nodes.forEach((name, i) => {

                    const geo = new THREE.SphereGeometry(8, 24, 24);

                    const mat = new THREE.MeshBasicMaterial({ color: 0x8b5cf6, transparent: true, opacity: 0.15 });

                    const mesh = new THREE.Mesh(geo, mat);

                    const angle = i * 0.55;

                    const dist = 280 + (i * 6);

                    mesh.position.set(Math.cos(angle) * dist, (Math.random() - 0.5) * 500, Math.sin(angle) * dist);

                    mesh.userData = { id: i, name: name };

                    nodeGroup.add(mesh);

                });


                const starGeo = new THREE.BufferGeometry();

                const starPos = new Float32Array(7000 * 3);

                for (let i = 0; i < 7000 * 3; i++) starPos[i] = (Math.random() - 0.5) * 6000;

                starGeo.setAttribute('position', new THREE.BufferAttribute(starPos, 3));

                const starField = new THREE.Points(starGeo, new THREE.PointsMaterial({ color: 0x3b82f6, size: 2, transparent: true, opacity: 0.4 }));

                scene.add(starField);


                const raycaster = new THREE.Raycaster();

                const mouse = new THREE.Vector2();


                window.addEventListener('mousemove', (e) => {

                    mouse.x = (e.clientX / window.innerWidth) * 2 - 1;

                    mouse.y = -(e.clientY / window.innerHeight) * 2 + 1;

                    gsap.to(camera.position, { x: mouse.x * 80, y: mouse.y * 80 + 50, duration: 3 });

                });


                window.addEventListener('mousedown', () => {

                    raycaster.setFromCamera(mouse, camera);

                    const intersects = raycaster.intersectObjects(nodeGroup.children);

                    if (intersects.length > 0) triggerInquiry(intersects[0].object.userData.id);

                });


                const animate = () => {

                    requestAnimationFrame(animate);

                    nodeGroup.rotation.y += 0.0004 * (1 + sharedDataCount / 10);

                    starField.rotation.y += 0.00003;

                    renderer.render(scene, camera);

                };

                animate();


                window.addEventListener('resize', () => {

                    camera.aspect = window.innerWidth / window.innerHeight;

                    camera.updateProjectionMatrix();

                    renderer.setSize(window.innerWidth, window.innerHeight);

                });

            };


            // 3. AI PROTOCOL LAYER

            const callGemini = async (prompt, sys = "") => {

                const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-09-2025:generateContent?key=`;

                try {

                    const response = await fetch(apiUrl, {

                        method: 'POST',

                        headers: { 'Content-Type': 'application/json' },

                        body: JSON.stringify({

                            contents: [{ parts: [{ text: prompt }] }],

                            systemInstruction: { parts: [{ text: sys }] }

                        })

                    });

                    const data = await response.json();

                    return data.candidates?.[0]?.content?.parts?.[0]?.text || "Protocol failure.";

                } catch (e) { return "Architect Offline."; }

            };


            const callGeminiTTS = async (text) => {

                const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-tts:generateContent?key=`;

                try {

                    const response = await fetch(apiUrl, {

                        method: 'POST',

                        headers: { 'Content-Type': 'application/json' },

                        body: JSON.stringify({

                            contents: [{ parts: [{ text: text }] }],

                            generationConfig: {

                                responseModalities: ["AUDIO"],

                                speechConfig: { voiceConfig: { prebuiltVoiceConfig: { voiceName: "Charon" } } }

                            }

                        })

                    });

                    const result = await response.json();

                    const audioData = result?.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;

                    if (audioData) new Audio(`data:audio/wav;base64,${audioData}`).play();

                } catch (e) {}

            };


            // 4. FUNCTIONAL LOGIC

            const triggerInquiry = async (id = null) => {

                const idx = id !== null ? id : (sharedDataCount % 44);

                setActiveNode(nodes[idx]);

                setAiResponse("");

                setAiChallenge("Generating forensic probe...");

                setIsAiThinking(true);

                

                const prompt = `Node: "${nodes[idx]}". Progress: ${sharedDataCount}/44. Pose one intense forensic question.`;

                const response = await callGemini(prompt, "Sovereign Architect. Forensic tone.");

                setAiChallenge(response);

                setIsAiThinking(false);

                callGeminiTTS(response);

            };


            const submitVector = async () => {

                setIsAiThinking(true);

                const response = await callGemini(`Node "${activeNode}": realization "${userInput}". Critique it for practical grit and provide a 5-digit Variance score.`, "Sovereign Auditor.");

                setAiResponse(response);

                const vMatch = response.match(/0\.\d+/);

                if (vMatch) setVariance(vMatch[0]);


                setSharedDataCount(prev => prev + 1);

                setDepth(Math.floor(((sharedDataCount + 1) / 44) * 100));

                setIsAiThinking(false);


                if (nodeGroupRef.current) {

                    const mesh = nodeGroupRef.current.children[nodes.indexOf(activeNode)];

                    if (mesh) { mesh.material.color.setHex(0xffffff); mesh.material.opacity = 1; mesh.scale.set(4, 4, 4); }

                }

            };


            const enterOS = () => {

                gsap.to(cameraRef.current.position, { z: 800, duration: 4, ease: "power4.inOut" });

                setStage('os');

                if (!audioStarted) {

                    Tone.start();

                    setAudioStarted(true);

                }

            };


            return (

                <div className="relative w-full h-screen bg-black overflow-hidden selection:bg-purple-500/30">

                    

                    {/* BACKGROUND ENGINES */}

                    <div id="background-engine">

                        <div className={`bg-layer bg-active`} style={{ backgroundImage: `url('https://images.unsplash.com/photo-1462331940025-496dfbfc7564?auto=format&fit=crop&q=100&w=3000')` }} />

                        <div className={`bg-layer ${sharedDataCount < 22 ? 'bg-active' : ''}`} style={{ backgroundImage: `url('https://images.unsplash.com/photo-1464822759023-fed622ff2c3b?auto=format&fit=crop&q=100&w=3000')` }} />

                        <div className="absolute inset-0 bg-black/70" />

                    </div>


                    <div id="canvas-mount" ref={mountRef} />


                    {/* BOOT LOADER */}

                    {!isBooted && (

                        <div className="fixed inset-0 z-[1000] bg-black flex flex-col items-center justify-center">

                            <div className="w-16 h-16 border-2 border-purple-500/20 border-t-purple-500 rounded-full animate-spin mb-8" />

                            <p className="font-mono text-[10px] uppercase tracking-[0.8em] text-white/40">Syncing Codex Environment...</p>

                        </div>

                    )}


                    {/* STAGE: THRESHOLD */}

                    {stage === 'threshold' && (

                        <div className="fixed inset-0 z-[150] flex items-center justify-center bg-black/80 backdrop-blur-xl p-8">

                            <div className="max-w-6xl w-full text-center space-y-16">

                                <img src="Gemini_Generated_Image_aumrwoaumrwoaumr.jpg" className="w-72 h-72 mx-auto drop-shadow-[0_0_50px_rgba(139,92,246,0.5)] transition-transform hover:scale-110" alt="Logo" />

                                <div className="space-y-4">

                                    <span className="text-purple-500 font-mono text-xs font-black uppercase tracking-[1em] animate-pulse block">Epistemic Alignment Required</span>

                                    <h1 className="text-8xl md:text-[11rem] font-black italic uppercase leading-[0.8] tracking-tighter mission-gradient">VISCERAL<br/>CURRENT</h1>

                                </div>

                                <div className="glass p-16 rounded-[6rem] border-white/5 space-y-10 max-w-4xl mx-auto">

                                    <p className="text-2xl font-light italic text-white/90">"Unifying deep spiritual intelligence with the grit of practical application."</p>

                                    <div className="flex gap-8">

                                        <button onClick={enterOS} className="flex-1 py-8 bg-white text-black font-black uppercase tracking-widest rounded-[3rem] hover:scale-105 active:scale-95 transition-all">Establish Anchor</button>

                                        <button onClick={enterOS} className="flex-1 py-8 bg-purple-600 text-white font-black uppercase tracking-widest rounded-[3rem] hover:scale-105 active:scale-95 transition-all shadow-[0_0_80px_rgba(139,92,246,0.3)]">Establish Current</button>

                                    </div>

                                </div>

                            </div>

                        </div>

                    )}


                    {/* STAGE: OS HUD */}

                    {stage === 'os' && (

                        <div className="fixed inset-0 z-50 flex flex-col justify-between p-12 pointer-events-none">

                            <div className="flex justify-between items-start">

                                <div className="glass p-10 rounded-[4rem] w-[32rem] border-t-white/10 pointer-events-auto shadow-2xl">

                                    <div className="flex items-center gap-8 mb-8">

                                        <img src="Gemini_Generated_Image_6n7b416n7b416n7b.jpg" className="w-24 h-24 rounded-3xl border border-white/10" alt="Codex" />

                                        <div className="space-y-1">

                                            <h2 className="text-[11px] font-black uppercase tracking-[0.5em] text-white/30 font-mono">Sovereign Identity</h2>

                                            <p className="text-xs font-bold text-blue-400 font-mono tracking-widest">CODEX_ID: LOCAL_SESS</p>

                                        </div>

                                    </div>

                                    <div className="space-y-6">

                                        <div className="flex justify-between items-end">

                                            <span className="text-[10px] font-mono uppercase text-white/20 tracking-[0.4em]">Manifold Completion</span>

                                            <span className="text-6xl font-black">{depth}%</span>

                                        </div>

                                        <div className="w-full h-2 bg-white/5 rounded-full overflow-hidden">

                                            <div className="h-full bg-gradient-to-r from-blue-600 via-purple-500 to-white transition-all duration-1000" style={{ width: `${depth}%` }} />

                                        </div>

                                    </div>

                                </div>


                                <div className="glass p-10 rounded-[4rem] text-right pointer-events-auto min-w-[280px] border-r-purple-500/20 shadow-2xl">

                                    <p className="text-[10px] font-mono text-white/20 uppercase tracking-[0.4em] mb-2">AAT Variance</p>

                                    <p className="text-4xl font-black text-blue-400 tracking-tighter font-mono">{variance}</p>

                                    <div className="mt-6 pt-6 border-t border-white/5">

                                        <p className="text-[9px] text-white/50 uppercase tracking-widest">Environment Mode</p>

                                        <p className="text-xs font-black text-white">{sharedDataCount < 22 ? 'FORGE_GRIT' : 'DEEP_COSMOS'}</p>

                                    </div>

                                </div>

                            </div>


                            <div className="absolute right-12 top-1/2 -translate-y-1/2 w-80 h-[50vh] overflow-y-auto pr-8 pointer-events-auto custom-scroll space-y-3">

                                {nodes.map((n, i) => (

                                    <div key={i} className={`glass p-5 rounded-[2.5rem] border border-white/5 transition-all cursor-pointer ${i < sharedDataCount ? 'border-purple-500 bg-purple-500/10' : 'opacity-20 hover:opacity-100'}`} onClick={() => triggerInquiry(i)}>

                                        <span className="text-[9px] font-mono text-white/40 block">VEC {String(i+1).padStart(2,'0')}</span>

                                        <span className="text-xs font-black uppercase tracking-[0.2em]">{n}</span>

                                    </div>

                                ))}

                            </div>


                            <div className="flex justify-center mb-12">

                                <div className="glass p-12 rounded-[5rem] w-full max-w-3xl flex items-center justify-between border-t-purple-500/30 pointer-events-auto shadow-2xl">

                                    <div className="space-y-1">

                                        <h3 className="text-base font-black uppercase tracking-[0.4em] text-white">Initialize New Probe</h3>

                                        <p className="text-xs text-white/30 italic font-mono uppercase">Sync alignment to current reality.</p>

                                    </div>

                                    <button onClick={() => triggerInquiry()} className="px-14 py-7 bg-white text-black font-black uppercase tracking-[0.4em] rounded-[3rem] hover:bg-purple-600 hover:text-white transition-all shadow-2xl active:scale-95">✨ Forensic Inquiry</button>

                                </div>

                            </div>

                        </div>

                    )}


                    {/* MODAL: PROBE */}

                    {activeNode && (

                        <div className="fixed inset-0 z-[200] bg-black/98 backdrop-blur-3xl flex items-center justify-center p-12">

                            <div className="glass p-20 rounded-[6rem] w-full max-w-4xl border-purple-500/20 space-y-12 relative shadow-2xl animate-in zoom-in duration-500">

                                <button onClick={() => setActiveNode(null)} className="absolute top-16 right-16 text-white/10 hover:text-white transition-all text-[11px] font-mono uppercase tracking-[0.5em]">[ Kill signal ]</button>

                                

                                <div className="space-y-6">

                                    <span className="text-purple-500 font-mono text-xs font-bold uppercase tracking-[0.8em] block animate-pulse">// Analysis Protocol Active</span>

                                    <h2 className="text-6xl font-black italic uppercase leading-none tracking-tighter text-white">{activeNode}</h2>

                                    <p className="text-white/60 text-xl italic leading-relaxed font-mono">✨ {aiChallenge}</p>

                                </div>


                                <div className="space-y-10">

                                    <textarea value={userInput} onChange={(e) => setUserInput(e.target.value)} placeholder="Define your practical realization..." className="w-full h-52 bg-white/5 border border-white/10 p-12 rounded-[4.5rem] font-mono text-lg focus:outline-none focus:border-purple-500 transition-all custom-scroll resize-none text-white/90 shadow-inner" spellcheck="false" />

                                    {aiResponse && (

                                        <div className="p-10 bg-purple-500/10 border border-purple-500/20 rounded-[4rem] space-y-6">

                                            <span className="text-[11px] font-black text-purple-400 uppercase tracking-[0.5em]">Forensic Audit Interpretation</span>

                                            <p className="text-base italic text-white/90 font-mono leading-relaxed">{aiResponse}</p>

                                        </div>

                                    )}

                                    <button onClick={submitVector} disabled={isAiThinking || !userInput} className="w-full py-10 bg-purple-600 text-white font-black uppercase tracking-widest rounded-[3.5rem] shadow-[0_0_100px_rgba(139,92,246,0.4)] hover:scale-[1.02] active:scale-95 transition-all flex items-center justify-center gap-8 disabled:opacity-30">

                                        {isAiThinking ? <div className="w-8 h-8 border-2 border-white/20 border-t-white rounded-full animate-spin" /> : "Commit Vector to Forensic Codex"}

                                    </button>

                                </div>

                            </div>

                        </div>

                    )}

                </div>

            );

        };


        const container = document.getElementById('root');

        const root = ReactDOM.createRoot(container);

        root.render(<App />);

    </script>

</body>

</html>