`;
outputDiv.innerHTML = htmlContent;
};
function getResolutionHook(paradoxType, resolution, goal, point) {
const traveler = "Dr. Aris Thorne"; // Fixed character name for consistency
const resolutionKey = resolution.split('(')[0].trim();
const hooks = {
"Grandfather Paradox": {
"Self-Consistency (Novikov)": `The timeline resists ${traveler}'s attempt to ${goal}. Describe the bizarre sequence of events at ${point} where every action ${traveler} takes, no matter how clever, inevitably leads to the original sequence of events being preserved, forcing ${traveler} to concede to fate.`,
"Multiverse Split": `The moment ${traveler} successfully achieves ${goal}, reality fractures. ${traveler} is stranded in the new timeline where the paradox never happened, but now they must deal with the original timeline's consequences bleeding into their new reality.`,
"Temporal Guardians": `Just as ${traveler} raises their hand to intervene at ${point}, a Temporal Guardian materializes, freezing the scene. ${traveler} is now put on trial in a hyper-dimensional court for violating the fundamental law of causality, facing the penalty of non-existence.`,
"Temporal Inertia": `The past is difficult to change. When ${traveler} attempts ${goal}, they find the key figures possess an uncanny temporal immunity. Describe how the world at ${point} feels thick, heavy, and reluctant to accept the modification, making the task an agonizing, slow-motion physical struggle.`,
"Quantum Entanglement Break": `The act of ${traveler} intervening at ${point} causes their present-day existence to flicker. The paradox is resolved by the quantum state of ${traveler}'s past self becoming so unstable that ${traveler} must return and stabilize their own history—not by changing it, but by reinforcing the events they tried to prevent.`,
},
"Bootstrap Paradox": {
"Self-Consistency (Novikov)": `The secret plans ${traveler} brought back to enable ${goal} are realized to have been transcribed from the very plans they were given in the future. The information has no origin. The pressure of this realization causes ${traveler} to undergo a philosophical crisis: are they an actor or merely a conduit of destiny?`,
"Multiverse Split": `The information ${traveler} brings back is only needed because they created a branching timeline that lacked it. ${traveler} realizes their act of intervention wasn't solving the original paradox but creating a new one in a desperate bid for existence in the new reality.`,
"Temporal Guardians": `The Temporal Guardians arrive, not to stop the time travel, but to retrieve the paradoxical object/information that enabled ${goal}. They inform ${traveler} that such objects are temporal anomalies and must be quarantined in a nexus outside of time to preserve the system's entropy.`,
"Temporal Inertia": `The information ${traveler} used for ${goal} appears to be correct but is subtly flawed—a flaw necessary for the timeline to continue. The key is in the error, not the fact. Write the moment ${traveler} finds the minuscule, critical error that was necessary for their entire timeline to exist.`,
"Quantum Entanglement Break": `The infinite loop of the bootstrap paradox creates a point of temporal singularity at ${point}. To stop the singularity from consuming the timeline, ${traveler} must destroy the anomalous object, accepting that the knowledge used for ${goal} will be permanently lost to all future versions of reality.`,
},
// Fallback for other types
"_default": `The paradox of ${paradoxType} is now active due to ${traveler}'s actions at ${point}. The only way to resolve it under the ${resolutionKey} principle is for ${traveler} to perform a final, impossible act. Write the scene where ${traveler} accepts the necessary sacrifice to mend (or split) the flow of time.`
};
return (hooks[paradoxType] && hooks[paradoxType][resolutionKey]) ? hooks[paradoxType][resolutionKey] : hooks["_default"];
}
// --- Utility: HTML Escape ---
function escapeHtml(text) {
if (!text) return '';
return text.replace(/[&<>"']/g, function(m) {
switch (m) {
case '&': return '&';
case '<': return '<';
case '>': return '>';
case '"': return '"';
case "'": return ''';
default: return m;
}
});
}
// --- PDF Download ---
window.ttprDownloadPDF = function() {
const element = document.getElementById('ttpr-print-area');
const title = document.getElementById('ttpr-title').value || "Paradox_Scenario";
document.body.classList.add('ttpr-generating-pdf');
const opt = {
margin: [0.5, 0.5],
filename: `${title.replace(/\s+/g, '_')}_Outline.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().set(opt).from(element).save().then(() => {
document.body.classList.remove('ttpr-generating-pdf');
});
};
