"use client"; import { useState, useEffect, useRef, useCallback } from "react"; import Link from "next/link"; import ThemedLayout from "@/components/layouts/ThemedLayout"; const BREATH_PHASES = [ { label: "Inhale", duration: 4, color: "#d4af37" }, { label: "Hold", duration: 4, color: "#a07820" }, { label: "Exhale", duration: 6, color: "#7a5c10" }, { label: "Rest", duration: 2, color: "#4a3c00" }, ]; const TOTAL_CYCLE = BREATH_PHASES.reduce((s, p) => s + p.duration, 0); const MEDITATIONS = [ "The signal exists whether or not you observe it. Observe it.", "Your handle is not your identity. Your actions are.", "Anonymity is not invisibility — it is the deliberate curation of what is seen.", "Every encrypted packet is a sealed letter to yourself across time.", "You are one hop in a circuit that spans the planet.", "In the void between nodes, there is no latency. Only intention.", "Trust no one node. Trust the protocol.", "The archive remembers. The relay forgets. Choose which you are.", ]; const CANDLE_KEY = "cyberlux-candles-v1"; type CandleEntry = { ts: number; note?: string }; function loadCandles(): CandleEntry[] { if (typeof window === "undefined") return []; try { return JSON.parse(localStorage.getItem(CANDLE_KEY) ?? "[]") as CandleEntry[]; } catch { return []; } } function addCandle(note?: string) { const candles = loadCandles(); candles.push({ ts: Date.now(), note }); if (typeof window !== "undefined") { localStorage.setItem(CANDLE_KEY, JSON.stringify(candles.slice(-50))); } return candles.length + 1; } export default function SanctuaryPage() { const [tab, setTab] = useState<"breathe" | "meditate" | "candle">("breathe"); // Breathing exercise const [breathing, setBreathing] = useState(false); const [phase, setPhase] = useState(0); const [phaseTime, setPhaseTime] = useState(0); const breathRef = useRef | null>(null); // Meditation const [meditationIdx, setMeditationIdx] = useState(0); const [meditationSeconds, setMeditationSeconds] = useState(0); const [meditating, setMeditating] = useState(false); const medRef = useRef | null>(null); // Candle const [candleNote, setCandleNote] = useState(""); const [candleLit, setCandleLit] = useState(false); const [candleCount, setCandleCount] = useState(0); useEffect(() => { setCandleCount(loadCandles().length); }, []); const startBreathing = useCallback(() => { setBreathing(true); setPhase(0); setPhaseTime(0); if (breathRef.current) clearInterval(breathRef.current); let elapsed = 0; breathRef.current = setInterval(() => { elapsed++; let acc = 0; for (let i = 0; i < BREATH_PHASES.length; i++) { acc += BREATH_PHASES[i]!.duration; if (elapsed % TOTAL_CYCLE < acc - (BREATH_PHASES[i]!.duration - 1) + (BREATH_PHASES[i]!.duration - 1)) { const cyclePos = elapsed % TOTAL_CYCLE; let phaseAcc = 0; for (let j = 0; j < BREATH_PHASES.length; j++) { if (cyclePos < phaseAcc + BREATH_PHASES[j]!.duration) { setPhase(j); setPhaseTime(cyclePos - phaseAcc); break; } phaseAcc += BREATH_PHASES[j]!.duration; } break; } } }, 1000); }, []); const stopBreathing = useCallback(() => { setBreathing(false); if (breathRef.current) clearInterval(breathRef.current); }, []); useEffect(() => () => { if (breathRef.current) clearInterval(breathRef.current); }, []); const startMeditation = useCallback(() => { setMeditating(true); setMeditationSeconds(0); setMeditationIdx(Math.floor(Math.random() * MEDITATIONS.length)); if (medRef.current) clearInterval(medRef.current); medRef.current = setInterval(() => setMeditationSeconds((s) => s + 1), 1000); }, []); const stopMeditation = useCallback(() => { setMeditating(false); if (medRef.current) clearInterval(medRef.current); }, []); useEffect(() => () => { if (medRef.current) clearInterval(medRef.current); }, []); const lightCandle = () => { const count = addCandle(candleNote.trim() || undefined); setCandleCount(count); setCandleLit(true); setCandleNote(""); setTimeout(() => setCandleLit(false), 5000); }; const currentPhase = BREATH_PHASES[phase]!; const circleScale = (() => { if (!breathing) return 0.5; const progress = phaseTime / currentPhase.duration; if (phase === 0) return 0.5 + progress * 0.5; if (phase === 1) return 1; if (phase === 2) return 1 - progress * 0.5; return 0.5; })(); const formatMedSec = (s: number) => `${Math.floor(s / 60).toString().padStart(2, "0")}:${(s % 60).toString().padStart(2, "0")}`; return (

The Sanctuary

A place of quiet. No tracking. No noise.

{/* Tabs */}
{(["breathe", "meditate", "candle"] as const).map((t) => ( ))}
{/* Breathing */} {tab === "breathe" && (

4-4-6-2 breathing pattern. Calms the nervous system in under two minutes.

{breathing ? currentPhase.label : "Ready"}
{breathing && (
{currentPhase.duration - phaseTime}s
)}
{BREATH_PHASES.map((p, i) => (
{p.label} {p.duration}s
))}
)} {/* Meditation */} {tab === "meditate" && (

"{MEDITATIONS[meditationIdx]}"

{meditating && (
{formatMedSec(meditationSeconds)}
)}
{!meditating && ( )}
{!meditating && meditationSeconds > 0 && (

Session: {formatMedSec(meditationSeconds)}

)}
)} {/* Candle */} {tab === "candle" && (

Light a candle. Add an optional note. Stored only in this browser.{" "} {candleCount} lit so far.