Storage Status: ${storageHealthy ? '● Active (Auto-saving to browser localStorage)' : '⚠ Sandboxed Preview (Export or Copy Backup before closing)'} Best way to use permanently on your phone: Save this HTML file to a free static URL (GitHub Pages / Netlify Drop) and tap "Add to Home Screen". While testing inside Gemini Preview, use the 1-Click Backup button below to save your state to Notes before closing.
Restore from Pasted Backup JSON
`);
document.getElementById('btnCloseSyncModal').addEventListener('click', closeModal);
document.getElementById('btnCopyStateBackup').addEventListener('click', () => {
copyText(JSON.stringify(state), 'Copied full project backup JSON! Paste into Notes to keep safe.');
});
document.getElementById('btnDownloadBackup').addEventListener('click', () => {
document.getElementById('btnExportJSON').click();
});
document.getElementById('btnRestorePastedState').addEventListener('click', () => {
try {
const parsed = JSON.parse(document.getElementById('pasteStateInput').value.trim());
if (!parsed.shots || !parsed.foundry) throw new Error('Invalid');
state = parsed;
logChange('Sync', 'Restored project state from pasted backup JSON.');
saveState();
closeModal();
setActiveView(state.activeView || 'studio');
showToast('Project backup restored successfully!');
} catch (_) {
showToast('Invalid backup JSON. Make sure you copied the full text.', 'err');
}
});
}
inputEl.value = '';
logChange('Quick Instruct', `[${scope} · ${aspect}] "${directive}" -> updated ${affectedCount} shot(s).`);
saveState();
renderAll();
showToast(`Instruction applied — Updated ${affectedCount}/${state.shots.length} shots.`);
}
state.shots.push(s);
state.activeShotId = s.id;
state.shotFilter = 'all';
logChange('Shots', `${cloneFrom ? 'Cloned' : 'Created'} Shot ${s.id} (${s.title}).`);
saveState();
renderAll();
showToast(`Created Shot ${s.id}`);
}
// Top Nav View Tabs
document.getElementById('mainNavTabs').addEventListener('click', (e) => {
const btn = e.target.closest('.nav-tab');
if (btn) setActiveView(btn.dataset.view);
});
// Version Log & Phone Sync Modals
document.getElementById('btnVersionLog').addEventListener('click', openVersionLogModal);
document.getElementById('btnPhoneSync').addEventListener('click', openPhoneSyncModal);
// Mobile Studio Pane Switcher
document.getElementById('mobileStudioBar').addEventListener('click', (e) => {
const btn = e.target.closest('[data-mpane]');
if (!btn) return;
state.mobileStudioPane = btn.dataset.mpane;
saveState();
renderStudio();
});
// Quick Instruct
// Foundry: Lock Toggle
const lockBtn = t.closest('[data-toggle-lock]');
if (lockBtn) {
const hid = lockBtn.dataset.toggleLock;
state.foundry[hid].locked = !state.foundry[hid].locked;
logChange('Foundry', `${state.foundry[hid].locked ? 'Locked' : 'Unlocked'} ${state.foundry[hid].refTag} (${state.foundry[hid].name}).`);
saveState();
renderFoundry();
showToast(`${state.foundry[hid].refTag} ${state.foundry[hid].locked ? 'LOCKED — auto-injecting into active shots!' : 'UNLOCKED for editing.'}`);
return;
}
// Foundry: Copy Turnaround Sheet Prompt & Copy Look-Lock
const turnBtn = t.closest('[data-copy-turnaround]');
if (turnBtn) {
const h = state.foundry[turnBtn.dataset.copyTurnaround];
copyText(buildTurnaroundPrompt(h), `Copied Nano Banana turnaround prompt for ${h.name}!`);
return;
}
const llBtn = t.closest('[data-copy-looklock]');
if (llBtn) {
const h = state.foundry[llBtn.dataset.copyLooklock];
const st = h.states[h.activeState] || Object.values(h.states)[0];
copyText(`${h.refTag} ${h.name} (${st.label}): ${st.desc}\nMacro: ${h.macroAnchor}\nNegative: ${h.negativeLock}`, `Copied Look-Lock for ${h.name}!`);
return;
}
// Shot Card 1-Click Quick Copy (prevent selecting shot when tapping copy)
const sqc = t.closest('[data-shot-qcopy]');
if (sqc) {
e.stopPropagation();
const [sid, kind] = sqc.dataset.shotQcopy.split(':');
const s = state.shots.find(x => x.id === sid);
if (!s) return;
const c = compileShot(s);
const txt = kind === 'nano' ? c.nanoCopyText : kind === 'veo' ? c.veoCopyText : c.fullPackText;
const lbl = kind === 'nano' ? 'Nano Banana' : kind === 'veo' ? 'Veo 3.1' : 'Full Shot Pack';
copyText(txt, `Copied Shot ${sid} (${lbl})!`);
return;
}
// 1-Click Copy Dock inside Center Compiler
const dockCopy = t.closest('[data-dock-copy]');
if (dockCopy) {
const s = getActiveShot();
if (!s) return;
const c = compileShot(s);
const mode = dockCopy.dataset.dockCopy;
const map = {
nano: [c.nanoCopyText, 'Nano Banana Keyframe'],
veo: [c.veoCopyText, 'Veo 3.1 I2V Delta'],
kling: [c.klingCopyText, 'Kling I2V + Negative'],
neg: [c.negativeText, 'Negative Guardrails'],
pack: [c.fullPackText, 'Full Shot Pack (NB+Veo+Kling)']
};
const [txt, lbl] = map[mode] || [c.nanoCopyText, 'Prompt'];
copyText(txt, `Copied Shot ${s.id} (${lbl})!`);
return;
}
// Select Shot
const shotCard = t.closest('[data-select-shot]');
if (shotCard) {
state.activeShotId = shotCard.dataset.selectShot;
if (window.innerWidth <= 960) state.mobileStudioPane = 'compiler';
saveState();
renderStudio();
return;
}
// Conflict Quick-Fix Buttons
if (t.id === 'btnFixSilenceHorn') {
const s = getActiveShot();
if (s) {
s.hornWind = 0;
logChange('Conflict Fix', `Silenced Horn to 0% on Shot ${s.id}.`);
saveState();
renderStudio();
showToast('Horn silenced to 0% — conflict resolved.');
}
return;
}
if (t.id === 'btnFixMuteSong') {
const s = getActiveShot();
if (s) {
s.scoreCue = 'horn_solo';
logChange('Conflict Fix', `Switched Shot ${s.id} to Horn Solo.`);
saveState();
renderStudio();
showToast('Switched to 42-Streamer Horn Solo — conflict resolved.');
}
return;
}
window.addEventListener('DOMContentLoaded', () => {
attachEvents();
updateTopStatusBadges();
setActiveView(state.activeView || 'studio');
});
})();