// Card Draw v4 — perched raven center, season-image card backs, proper flow: // Page load -> 4 face-down cards + perched raven center. NO question panel. // Click a card OR "Let the Raven Choose" -> question appears below. const { useState: useStateC4, useEffect: useEffectC4, useRef: useRefC4 } = React; const DRAW_STATE_KEY_V4 = 'up_v4_draw_state'; function dayKeyV4() { const d = new Date(); return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`; } function loadDrawV4() { try { return JSON.parse(localStorage.getItem(DRAW_STATE_KEY_V4) || 'null'); } catch { return null; } } function saveDrawV4(s) { try { localStorage.setItem(DRAW_STATE_KEY_V4, JSON.stringify(s)); } catch {} } function CardDrawV4() { const PILLARS = window.PILLARS_V4; const BLESSINGS = window.BLESSINGS_V4; const ToolIcon = window.ToolIconV4; // Phases: 'idle' | 'shuffling' | 'revealed' | 'already' const [phase, setPhase] = useStateC4('idle'); const [chosenIdx, setChosenIdx] = useStateC4(null); const [order, setOrder] = useStateC4([0, 1, 2, 3]); const [questionIdx, setQuestionIdx] = useStateC4(0); const [blessingIdx, setBlessingIdx] = useStateC4(0); const [activeTool, setActiveTool] = useStateC4(null); const revealRef = useRefC4(null); // Default state: ALWAYS show the cards on page load. // The daily lock no longer auto-restores the previous reveal — // it only prevents losing the draw if the user reloads after picking. // (Removed the auto-jump to 'already' that was breaking the initial view.) const chosenPillar = chosenIdx !== null ? PILLARS[order[chosenIdx]] : null; const ravenChoose = () => { const newOrder = [0,1,2,3].sort(() => Math.random() - 0.5); setOrder(newOrder); setActiveTool(null); setPhase('shuffling'); setTimeout(() => { const idx = Math.floor(Math.random() * 4); setChosenIdx(idx); setTimeout(() => completeDraw(newOrder, idx), 500); }, 1100); }; const pickCard = (idx) => { if (phase !== 'idle') return; setActiveTool(null); setChosenIdx(idx); setTimeout(() => completeDraw(order, idx), 500); }; const completeDraw = (orderArr, idx) => { const pillar = PILLARS[orderArr[idx]]; const qIdx = Math.floor(Math.random() * pillar.questions.length); const bIdx = Math.floor(Math.random() * BLESSINGS.length); setQuestionIdx(qIdx); setBlessingIdx(bIdx); setPhase('revealed'); saveDrawV4({ day: dayKeyV4(), order: orderArr, chosenIdx: idx, questionIdx: qIdx, blessingIdx: bIdx }); setTimeout(() => { if (revealRef.current) { const top = revealRef.current.getBoundingClientRect().top + window.scrollY - 90; window.scrollTo({ top, behavior: 'smooth' }); } }, 600); }; const drawAnother = () => { try { localStorage.removeItem(DRAW_STATE_KEY_V4); } catch {} setChosenIdx(null); setActiveTool(null); setOrder([0,1,2,3].sort(() => Math.random() - 0.5)); setPhase('idle'); // Scroll back up to the cards setTimeout(() => { const drawEl = document.getElementById('draw'); if (drawEl) { const top = drawEl.getBoundingClientRect().top + window.scrollY - 80; window.scrollTo({ top, behavior: 'smooth' }); } }, 200); }; const isCardsView = phase === 'idle' || phase === 'shuffling'; return (
Four cards. One season. One question for today.
The card you draw is the one you need.
{pillar.essence}