' + l + '
'; }).join(''); } async function loadFollowup() { var msgEl = document.getElementById('df5Msg'); var optEl = document.getElementById('df5Opts'); if (!msgEl || !optEl) return; msgEl.innerHTML = LOADER; optEl.innerHTML = ''; var areas = { mood: checkIn.mood, focus: checkIn.focus, energy: checkIn.energy, stress: checkIn.stress, clarity: checkIn.clarity }; var lowest = Object.entries(areas).sort(function(a, b) { return a[1] - b[1]; })[0]; var msgPrompt = 'The user\'s ' + lowest[0] + ' is at ' + lowest[1] + '/10 today. ' + 'Write 1-2 warm sentences responding and asking what is underneath it. ' + 'Warm, conversational, not clinical.'; var optsPrompt = 'For someone whose ' + lowest[0] + ' is low today, give 4 short tap-to-select ' + 'follow-up options (each under 10 words, real, grounded). ' + 'Return ONLY a JSON array of 4 strings, nothing else.'; var results = await Promise.all([ callClaude([{ role: 'user', content: msgPrompt }], 120), callClaude([{ role: 'user', content: optsPrompt }], 160) ]); var clariMsg = results[0]; if (!clariMsg || clariMsg.length < 10) { var msgFallbacks = { mood: 'Your mood is sitting low today. That matters to me. What is underneath it?', focus: 'Focus is scattered right now. That usually means something is pulling at your attention. What is it?', energy: 'Your energy is low. That tells me something. What has been draining you?', stress: 'Stress is high today. I see that. What is the thing that is actually weighing on you most?', clarity:'Clarity is hard to find right now. When we are unclear, it usually means we know the answer and we are afraid of it. What do you think it is?' }; clariMsg = msgFallbacks[lowest[0]] || 'Something feels hard today. Tell me what is really going on.'; } msgEl.textContent = clariMsg; var areaOpts = { mood: ['Something feels heavy but I cannot name it', 'Going through the motions today', 'Tired of feeling this way', 'Disconnected from myself'], focus: ['Brain will not stop jumping around', 'Too many things at once', 'Avoiding something I know I need to do', 'Overwhelmed before I even start'], energy: ['Running on empty', 'Poor sleep is catching up with me', 'Giving too much and not refilling', 'Body feels heavy and slow'], stress: ['Pressure from every direction', 'Something specific is weighing on me', 'I am holding it all together but barely', 'Anxiety underneath the busyness'], clarity: ['Cannot see the path forward', 'Too many decisions at once', 'Lost in my own head', 'Not sure what I actually want'] }; var opts = areaOpts[lowest[0]] || ['Overthinking, mind will not quiet', 'Avoiding something I need to face', 'Too many things at once', 'Just feel off today']; try { var parsed = JSON.parse(results[1].replace(/```json|```/g, '').trim()); if (Array.isArray(parsed) && parsed.length >= 4) opts = parsed; } catch(e) {} opts.forEach(function(opt) { var btn = document.createElement('button'); btn.className = 'option-btn'; btn.textContent = opt; btn.onclick = function() { [].slice.call(document.querySelectorAll('.option-btn')).forEach(function(b) { b.classList.remove('chosen'); }); this.classList.add('chosen'); checkIn.followupAnswer = opt; }; optEl.appendChild(btn); }); var jpEl = document.getElementById('df6Prompt'); if (jpEl) { var jpPrompt = 'Based on low ' + lowest[0] + ', write ONE short journal prompt under 15 words starting with What, Where, or When. Return only the question.'; var jp = await callClaude([{ role: 'user', content: jpPrompt }], 50); jpEl.textContent = jp || 'What is actually going on underneath everything today?'; } } function setJP(text) { var ta = document.getElementById('journalEntry'); if (ta) { ta.value = text; ta.focus(); } } function saveJournal() { checkIn.journal = (document.getElementById('journalEntry') || {}).value || ''; } async function loadMicroAction() { var iconEl = document.getElementById('df7Icon'); var textEl = document.getElementById('df7Text'); var whyEl = document.getElementById('df7Why'); if (!textEl) return; textEl.innerHTML = '