<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Guardianes de la Fe: Estudio de Herejías Trinitarias</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lato:wght@300;400;700&family=Merriweather:ital,wght@0,300;0,400;0,700;1,300&display=swap" rel="stylesheet">
    
    <!-- Chosen Palette: Codex & Ink -->
    <!-- Primary Background: #f9f7f2 (Warm Parchment) -->
    <!-- Primary Text: #2c3e50 (Deep Ink Blue) -->
    <!-- Accent Gold: #d4af37 (Classic Gold) -->
    <!-- Orthodoxy Blue: #3498db -->
    <!-- Heresy Red: #c0392b -->

    <!-- Application Structure Plan: 
         1. Hero Section: Sets the theological tone.
         2. Interactive Radar (Theological Diagnostics): A Chart.js radar chart contrasting Orthodoxy with selected heresies on 5 theological axes. This visualizes 'where' the theology breaks.
         3. The Heresy Archive (Cards): Grid of historical heresies. Clicking one opens a "Temporal Bridge" modal showing the ancient error vs. the modern sect.
         4. Apologetic Arsenal: A functional tool where users select a modern claim and receive specific Biblical refutations.
         5. Timeline: Visualizing the recurrence of these ideas.
    -->

    <!-- Visualization & Content Choices:
         - Radar Chart: Goal -> Compare theological balance. Viz -> Radar. Interaction -> Toggle datasets. Justification -> Shows how heresies maximize one truth (e.g., Unity) at the expense of another (e.g., Distinction).
         - Modal Detail Views: Goal -> Deep dive. Viz -> Split screen (Old vs New). Interaction -> Open/Close. Justification -> Forces comparison between the root error and the modern fruit.
         - Filterable Grid: Goal -> Organization. Viz -> Cards. Interaction -> Category filtering.
    -->
    
    <!-- CONFIRMATION: NO SVG graphics used. NO Mermaid JS used. -->

    <style>
        body {
            font-family: 'Lato', sans-serif;
            background-color: #f9f7f2;
            color: #2c3e50;
        }
        h1, h2, h3, .serif-title {
            font-family: 'Cinzel', serif;
        }
        .prose-text {
            font-family: 'Merriweather', serif;
        }
        .chart-container {
            position: relative;
            width: 100%;
            max-width: 600px;
            margin-left: auto;
            margin-right: auto;
            height: 400px;
            max-height: 450px;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .modal-overlay {
            backdrop-filter: blur(5px);
            background-color: rgba(0, 0, 0, 0.5);
        }
        /* Custom Scrollbar */
        ::-webkit-scrollbar {
            width: 8px;
        }
        ::-webkit-scrollbar-track {
            background: #f1f1f1; 
        }
        ::-webkit-scrollbar-thumb {
            background: #d4af37; 
            border-radius: 4px;
        }
        ::-webkit-scrollbar-thumb:hover {
            background: #b5952f; 
        }
    </style>
</head>
<body class="antialiased min-h-screen flex flex-col">

    <!-- Navbar -->
    <nav class="bg-[#2c3e50] text-white shadow-lg sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16">
                <div class="flex items-center">
                    <span class="text-2xl font-bold serif-title text-[#d4af37]">Veritas & Error</span>
                </div>
                <div class="hidden md:flex space-x-8 items-center">
                    <button onclick="scrollToSection('diagnostics')" class="hover:text-[#d4af37] transition-colors">Diagnóstico</button>
                    <button onclick="scrollToSection('archive')" class="hover:text-[#d4af37] transition-colors">Archivo Histórico</button>
                    <button onclick="scrollToSection('arsenal')" class="hover:text-[#d4af37] transition-colors">Defensa Bíblica</button>
                </div>
            </div>
        </div>
    </nav>

    <!-- Hero Section -->
    <header class="bg-white border-b border-[#d4af37] py-16 px-4 text-center">
        <div class="max-w-4xl mx-auto">
            <h1 class="text-4xl md:text-5xl font-bold text-[#2c3e50] mb-6">Herejías Trinitarias: <br><span class="text-[#d4af37] text-3xl md:text-4xl">Sombras Históricas, Ecos Modernos</span></h1>
            <p class="text-lg md:text-xl text-gray-600 prose-text max-w-2xl mx-auto leading-relaxed">
                "No hay nada nuevo bajo el sol". Las desviaciones doctrinales modernas son repeticiones de errores antiguos. 
                Explore este estudio comparativo para discernir la verdad ortodoxa de las distorsiones históricas.
            </p>
            <div class="mt-8">
                <button onclick="scrollToSection('archive')" class="bg-[#2c3e50] text-white px-8 py-3 rounded-md hover:bg-[#34495e] transition-colors font-bold border-b-4 border-[#1a252f]">
                    Comenzar Análisis
                </button>
            </div>
        </div>
    </header>

    <!-- Main Content -->
    <main class="flex-grow max-w-7xl mx-auto w-full px-4 sm:px-6 lg:px-8 py-12 space-y-20">

        <!-- SECTION 1: THEOLOGICAL DIAGNOSTICS (RADAR CHART) -->
        <section id="diagnostics" class="bg-white rounded-xl shadow-md overflow-hidden border-t-4 border-[#3498db]">
            <div class="p-8">
                <div class="mb-8 text-center">
                    <h2 class="text-3xl font-bold text-[#2c3e50] mb-4">Diagnóstico Teológico</h2>
                    <p class="text-gray-600 prose-text max-w-3xl mx-auto">
                        Visualice cómo cada herejía distorsiona el equilibrio de la verdad cristiana. La Ortodoxia mantiene la tensión perfecta entre todos los atributos. Seleccione una herejía para compararla con la postura Ortodoxa.
                    </p>
                </div>

                <div class="flex flex-col lg:flex-row gap-8 items-center">
                    <!-- Controls -->
                    <div class="w-full lg:w-1/3 space-y-4">
                        <h3 class="font-bold text-lg border-b pb-2 mb-4">Seleccione para Comparar:</h3>
                        <div class="space-y-2" id="radar-controls">
                            <!-- Buttons generated by JS -->
                        </div>
                        <div class="bg-blue-50 p-4 rounded-lg mt-6 text-sm border-l-4 border-blue-500">
                            <h4 class="font-bold text-blue-800">La Postura Ortodoxa (Referencia)</h4>
                            <p class="text-gray-700 mt-1">Afirma plenamente la Deidad de Cristo, la Deidad del Espíritu, la Distinción de Personas y la Unidad de Esencia simultáneamente.</p>
                        </div>
                    </div>

                    <!-- Chart -->
                    <div class="w-full lg:w-2/3 flex justify-center">
                        <div class="chart-container">
                            <canvas id="theologyRadar"></canvas>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- SECTION 2: THE HERESY ARCHIVE (MAIN GRID) -->
        <section id="archive">
            <div class="flex flex-col md:flex-row justify-between items-end mb-8 border-b pb-4">
                <div>
                    <h2 class="text-3xl font-bold text-[#2c3e50]">Archivo de Herejías</h2>
                    <p class="text-gray-600 mt-2">Haga clic en cualquier tarjeta para ver el análisis detallado y su contraparte moderna.</p>
                </div>
                <div class="mt-4 md:mt-0">
                    <select id="heresy-filter" class="bg-white border border-gray-300 rounded px-3 py-2 focus:outline-none focus:ring-2 focus:ring-[#d4af37]">
                        <option value="all">Mostrar Todas</option>
                        <option value="son">Ataques al Hijo</option>
                        <option value="spirit">Ataques al Espíritu</option>
                        <option value="unity">Ataques a la Unidad/Trinidad</option>
                    </select>
                </div>
            </div>

            <!-- Grid Container -->
            <div id="heresy-grid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
                <!-- Cards generated by JS -->
            </div>
        </section>

        <!-- SECTION 3: APOLOGETIC ARSENAL -->
        <section id="arsenal" class="bg-[#2c3e50] rounded-xl shadow-xl text-white overflow-hidden">
            <div class="p-8 md:p-12">
                <h2 class="text-3xl font-bold text-[#d4af37] mb-6 text-center">Arsenal Apologético</h2>
                <p class="text-center text-gray-300 mb-10 max-w-2xl mx-auto">
                    Seleccione una afirmación herética común escuchada hoy en día para revelar la respuesta bíblica y lógica del cristiano trinitario.
                </p>

                <div class="grid grid-cols-1 lg:grid-cols-2 gap-12">
                    <!-- Left: Selector -->
                    <div class="bg-white/10 p-6 rounded-lg backdrop-blur-sm">
                        <label class="block text-[#d4af37] font-bold mb-3 text-lg">Afirmación Moderna:</label>
                        <select id="claim-selector" class="w-full bg-white text-gray-900 p-3 rounded shadow-inner focus:outline-none focus:ring-4 focus:ring-[#d4af37]" onchange="updateDefense()">
                            <option value="" disabled selected>-- Seleccione una objeción --</option>
                            <!-- Options filled by JS -->
                        </select>
                        
                        <div id="claim-context" class="mt-6 text-gray-300 text-sm italic min-h-[60px]">
                            <!-- Context text -->
                        </div>
                    </div>

                    <!-- Right: Response -->
                    <div class="bg-white text-gray-800 p-6 rounded-lg shadow-2xl relative">
                        <div class="absolute -top-3 -right-3 bg-[#d4af37] text-white w-10 h-10 flex items-center justify-center rounded-full font-bold shadow-lg">
                            ⚔️
                        </div>
                        <h3 class="text-xl font-bold text-[#2c3e50] mb-4 border-b pb-2">Respuesta Bíblica</h3>
                        <div id="defense-content" class="prose-text space-y-4">
                            <p class="text-gray-500 text-center py-8">Seleccione una afirmación para equipar su defensa.</p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

    </main>

    <!-- Footer -->
    <footer class="bg-[#1a252f] text-gray-400 py-8 text-center border-t border-gray-700 mt-12">
        <p>© 2026 Estudio de Teología Histórica y Apologética. Basado en el informe comparativo proporcionado.</p>
        <p class="text-sm mt-2">"Conoceréis la verdad, y la verdad os hará libres." - Juan 8:32</p>
    </footer>

    <!-- MODAL TEMPLATE -->
    <div id="heresy-modal" class="fixed inset-0 z-[100] hidden overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
        <div class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
            <!-- Background overlay -->
            <div class="fixed inset-0 bg-gray-900 bg-opacity-75 transition-opacity modal-overlay" aria-hidden="true" onclick="closeModal()"></div>

            <!-- Modal panel -->
            <span class="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">&#8203;</span>
            <div class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-4xl sm:w-full">
                
                <!-- Modal Header -->
                <div class="bg-[#2c3e50] px-6 py-4 flex justify-between items-center">
                    <h3 class="text-2xl leading-6 font-bold text-[#d4af37]" id="modal-title">Título Herejía</h3>
                    <button type="button" class="text-gray-400 hover:text-white focus:outline-none" onclick="closeModal()">
                        <span class="text-3xl">&times;</span>
                    </button>
                </div>

                <!-- Modal Body -->
                <div class="px-6 py-6 bg-[#f9f7f2]">
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-8 relative">
                        <!-- Vertical Divider for Desktop -->
                        <div class="hidden md:block absolute left-1/2 top-0 bottom-0 w-px bg-gray-300 transform -translate-x-1/2"></div>
                        
                        <!-- Left: History -->
                        <div class="relative">
                            <div class="absolute -top-4 -left-2 bg-gray-200 text-gray-600 text-xs px-2 py-1 rounded font-bold uppercase tracking-wider">Raíz Histórica</div>
                            <h4 class="text-xl font-bold text-[#c0392b] mb-1 mt-4" id="modal-origin-name">Nombre Antiguo</h4>
                            <p class="text-sm text-gray-500 mb-4 italic" id="modal-origin-date">Siglo IV, Arrio</p>
                            
                            <div class="bg-white p-4 rounded shadow-sm border-l-4 border-[#c0392b] mb-4">
                                <h5 class="font-bold text-gray-800 text-sm mb-2">¿Qué creían?</h5>
                                <p class="text-gray-700 text-sm leading-relaxed" id="modal-beliefs">Creencias...</p>
                            </div>

                            <div class="bg-gray-100 p-4 rounded text-sm">
                                <h5 class="font-bold text-gray-800 mb-1">Conflicto con los Credos</h5>
                                <p id="modal-creed-conflict">Conflicto...</p>
                            </div>
                        </div>

                        <!-- Right: Modern -->
                        <div class="relative">
                            <div class="absolute -top-4 -right-2 bg-[#3498db] text-white text-xs px-2 py-1 rounded font-bold uppercase tracking-wider">Eco Moderno</div>
                            <h4 class="text-xl font-bold text-[#2980b9] mb-1 mt-4 text-right" id="modal-modern-name">Grupo Moderno</h4>
                            <p class="text-sm text-gray-500 mb-4 italic text-right" id="modal-modern-group">Testigos de Jehová</p>
                            
                            <div class="bg-blue-50 p-4 rounded shadow-sm border-r-4 border-[#3498db] mb-4 text-right">
                                <h5 class="font-bold text-gray-800 text-sm mb-2">Distintivos Actuales</h5>
                                <p class="text-gray-700 text-sm leading-relaxed" id="modal-modern-distinctions">Distintivos...</p>
                            </div>

                             <div class="mt-6 pt-4 border-t border-gray-200">
                                <h5 class="font-bold text-[#2c3e50] mb-2 flex items-center justify-end">
                                    <span class="mr-2">Respuesta Clave</span> 🛡️
                                </h5>
                                <p class="text-sm text-gray-700 text-right prose-text" id="modal-response-summary">Respuesta...</p>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Modal Footer -->
                <div class="bg-gray-50 px-6 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
                    <button type="button" class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-[#2c3e50] text-base font-medium text-white hover:bg-[#34495e] focus:outline-none sm:ml-3 sm:w-auto sm:text-sm" onclick="closeModal()">
                        Cerrar Archivo
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- JAVASCRIPT LOGIC -->
    <script>
        // --- DATA STORE ---
        // Based on the provided Markdown report
        const heresies = [
            {
                id: 'arrianismo',
                category: 'son',
                name: 'Arrianismo',
                origin: 'Siglo IV (c. 318 d.C.), Alejandría. Propuesto por Arrio.',
                beliefs: 'Sostenían que el Hijo es la primera y más exaltada criatura de Dios, creada de la nada. "Hubo un tiempo en que Él no existía". El Hijo no es consustancial al Padre.',
                creedConflict: 'Nicea: Afirma que Jesús es "engendrado, no creado" y "consustancial". Atanasio: Las personas son coeternas.',
                modernForm: 'Testigos de Jehová (Watchtower), Unitarianismo Bíblico.',
                modernDistinctions: 'Identifican a Jesús como el Arcángel Miguel. Traducen Juan 1:1 como "un dios". Rechazan la adoración a Jesús.',
                response: 'Isaías 43:11 (Solo YHWH salva) vs Tito 2:13 (Jesús Gran Dios). Colosenses 2:9 (Toda la plenitud de la Deidad). Una criatura no puede pagar una deuda infinita.',
                radarScores: [2, 10, 10, 5, 0] // [Deity of Son, Deity of Spirit, Distinct Persons, Unity of Essence, Pre-existence]
            },
            {
                id: 'sabelianismo',
                category: 'unity',
                name: 'Sabelianismo (Modalismo)',
                origin: 'Siglo III. Asociado a Sabelio, Noeto y Práxeas.',
                beliefs: 'Dios es una mónada unipersonal que se manifiesta en tres modos sucesivos (Padre, Hijo, Espíritu) pero nunca simultáneamente.',
                creedConflict: 'Atanasio: "Sin confundir las personas". El modalismo confunde las personas. Implica que el Padre murió en la cruz (Patripasianismo).',
                modernForm: 'Pentecostalismo Unicitario ("Solo Jesús").',
                modernDistinctions: 'Bautismo solo "en nombre de Jesús". Creen que "Jesús" es el nombre del Padre, Hijo y Espíritu. Rechazan Mateo 28:19.',
                response: 'El Bautismo de Jesús (Marcos 1): Padre habla, Hijo en agua, Espíritu desciende (Simultaneidad). Juan 17: Jesús ora al Padre (Relación Yo-Tú).',
                radarScores: [10, 10, 0, 10, 10]
            },
            {
                id: 'macedonianismo',
                category: 'spirit',
                name: 'Macedonianismo (Pneumatómacos)',
                origin: 'Siglo IV. Seguidores de Macedonio I.',
                beliefs: 'Aceptaban divinidad del Hijo (a veces) pero negaban la del Espíritu Santo, viéndolo como fuerza o ángel subordinado.',
                creedConflict: 'Constantinopla (381): Afirma que el Espíritu es "Señor y dador de vida" y recibe "misma adoración".',
                modernForm: 'Testigos de Jehová, Cristadelfianos.',
                modernDistinctions: 'Espíritu Santo es la "fuerza activa" (como electricidad), no una persona. Niegan intelecto o emociones al Espíritu.',
                response: 'Atributos personales: El Espíritu habla (Hch 13:2), tiene voluntad (1 Cor 12:11), se entristece (Ef 4:30). Hechos 5:3-4: Mentir al Espíritu es mentir a Dios.',
                radarScores: [8, 0, 10, 5, 8]
            },
            {
                id: 'triteismo',
                category: 'unity',
                name: 'Triteísmo',
                origin: 'Siglo VI (Juan Filópono).',
                beliefs: 'Padre, Hijo y Espíritu son tres dioses distintos con naturaleza genérica común, unidos solo por voluntad, no por esencia indivisible.',
                creedConflict: 'Nicea: "Creemos en UN solo Dios". Rompe el monoteísmo estricto.',
                modernForm: 'Mormonismo (SUD).',
                modernDistinctions: 'Padre e Hijo tienen cuerpos de carne y hueso. Dios fue hombre antes. Politeísmo/Henoteísmo (pluralidad de dioses).',
                response: 'Deuteronomio 6:4 (Jehová uno es). Isaías 43:10 (Antes de mí no fue formado dios). Juan 4:24 (Dios es Espíritu, no carne).',
                radarScores: [10, 10, 10, 0, 5]
            },
            {
                id: 'socinianismo',
                category: 'son',
                name: 'Socinianismo',
                origin: 'Siglo XVI. Fausto Sozzini.',
                beliefs: 'Jesús no preexistía. Era un hombre perfecto divinizado por obediencia. Salvador por ejemplo, no por expiación.',
                creedConflict: 'Nicea: "Bajó del cielo" (preexistencia). "Dios verdadero de Dios verdadero".',
                modernForm: 'Unitarismo Universalista, Liberalismo Teológico.',
                modernDistinctions: 'Racionalismo: rechazan misterios. Jesús como maestro moral. Niegan necesidad de sacrificio de sangre.',
                response: 'Juan 8:58 ("Antes que Abraham fuese, yo soy"). Filipenses 2:6 (Forma de Dios antes de forma de siervo).',
                radarScores: [0, 8, 10, 8, 0]
            }
        ];

        const claims = [
            {
                text: "\"Jesús es el Arcángel Miguel, la primera creación de Dios.\"",
                heresyId: 'arrianismo',
                refutation: "<strong>Hebreos 1:5-8, 13:</strong> Dios nunca llamó 'Hijo' a ningún ángel, ni dijo a ningún ángel 'Siéntate a mi diestra'. Pero del Hijo dice: 'Tu trono, oh Dios, por el siglo del siglo'. Los ángeles adoran al Hijo; el Hijo no es un ángel, es el Creador de los ángeles (Col 1:16)."
            },
            {
                text: "\"La Trinidad es pagana; Jesús es el único Dios, Padre y Espíritu son solo sus títulos.\"",
                heresyId: 'sabelianismo',
                refutation: "<strong>Juan 17:1-5:</strong> Jesús ora al Padre: 'Glorifícame tú al lado tuyo'. No puede estar al lado de sí mismo. La distinción es real y eterna. <strong>Marcos 1:10-11:</strong> En el bautismo, las tres personas actúan simultáneamente en roles distintos."
            },
            {
                text: "\"El Espíritu Santo no es una persona, es la fuerza activa de Dios.\"",
                heresyId: 'macedonianismo',
                refutation: "<strong>Hechos 13:2:</strong> 'Dijo el Espíritu Santo: Apartadme a Bernabé y a Saulo'. Las fuerzas no hablan ni llaman misioneros. <strong>Efesios 4:30:</strong> 'No contristéis al Espíritu Santo'. No se puede entristecer a la electricidad; solo a una Persona."
            },
            {
                text: "\"El Padre tiene un cuerpo de carne y hueso como nosotros.\"",
                heresyId: 'triteismo',
                refutation: "<strong>Juan 4:24:</strong> 'Dios es Espíritu; y los que le adoran, en espíritu y en verdad es necesario que adoren'. <strong>Lucas 24:39:</strong> Jesús dice: 'Un espíritu no tiene carne ni huesos'. Por tanto, el Padre no tiene cuerpo físico."
            },
            {
                text: "\"Jesús nunca dijo ser Dios, fue un gran maestro moral.\"",
                heresyId: 'socinianismo',
                refutation: "<strong>Juan 8:58:</strong> 'Antes que Abraham fuese, YO SOY'. Usó el nombre divino (Éxodo 3:14) y quisieron apedrearle por blasfemia (hacerse Dios). <strong>Juan 20:28:</strong> Tomás le llama '¡Señor mío, y Dios mío!' y Jesús lo acepta."
            }
        ];

        // --- APP LOGIC ---

        // 1. Initialize Radar Chart
        let theologyChart;

        function initChart() {
            const ctx = document.getElementById('theologyRadar').getContext('2d');
            
            const orthodoxyData = [10, 10, 10, 10, 10]; // The Standard

            theologyChart = new Chart(ctx, {
                type: 'radar',
                data: {
                    labels: [
                        'Deidad de Cristo', 
                        'Personalidad del Espíritu', 
                        'Distinción de Personas', 
                        'Unidad de Esencia', 
                        'Preexistencia Eterna'
                    ],
                    datasets: [{
                        label: 'Ortodoxia Bíblica',
                        data: orthodoxyData,
                        fill: true,
                        backgroundColor: 'rgba(52, 152, 219, 0.2)',
                        borderColor: 'rgba(52, 152, 219, 1)',
                        pointBackgroundColor: 'rgba(52, 152, 219, 1)',
                        pointBorderColor: '#fff',
                        pointHoverBackgroundColor: '#fff',
                        pointHoverBorderColor: 'rgba(52, 152, 219, 1)'
                    }]
                },
                options: {
                    maintainAspectRatio: false,
                    elements: {
                        line: { borderWidth: 3 }
                    },
                    scales: {
                        r: {
                            angleLines: { color: '#ccc' },
                            grid: { color: '#e5e5e5' },
                            pointLabels: {
                                font: { size: 12, family: "'Lato', sans-serif", weight: 'bold' },
                                color: '#2c3e50'
                            },
                            suggestedMin: 0,
                            suggestedMax: 10,
                            ticks: { display: false } // hide numbers on axis
                        }
                    },
                    plugins: {
                        legend: { position: 'bottom' }
                    }
                }
            });
        }

        function updateRadar(heresyId) {
            const heresy = heresies.find(h => h.id === heresyId);
            if (!heresy) return;

            // Remove existing heresy dataset if any (keep Orthodoxy at index 0)
            if (theologyChart.data.datasets.length > 1) {
                theologyChart.data.datasets.pop();
            }

            // Add new heresy data
            theologyChart.data.datasets.push({
                label: heresy.name,
                data: heresy.radarScores,
                fill: true,
                backgroundColor: 'rgba(192, 57, 43, 0.2)',
                borderColor: 'rgba(192, 57, 43, 1)',
                pointBackgroundColor: 'rgba(192, 57, 43, 1)',
                pointBorderColor: '#fff',
                pointHoverBackgroundColor: '#fff',
                pointHoverBorderColor: 'rgba(192, 57, 43, 1)'
            });

            theologyChart.update();
        }

        // 2. Build UI Components
        function renderRadarControls() {
            const container = document.getElementById('radar-controls');
            container.innerHTML = '';
            
            heresies.forEach(h => {
                const btn = document.createElement('button');
                btn.className = "w-full text-left px-4 py-3 rounded border border-gray-200 hover:bg-gray-50 hover:border-[#d4af37] focus:ring-2 focus:ring-[#d4af37] transition-all flex justify-between items-center group";
                btn.onclick = () => {
                    // Visual active state
                    document.querySelectorAll('#radar-controls button').forEach(b => b.classList.remove('bg-gray-100', 'border-[#d4af37]'));
                    btn.classList.add('bg-gray-100', 'border-[#d4af37]');
                    updateRadar(h.id);
                };
                btn.innerHTML = `
                    <span class="font-medium text-gray-700 group-hover:text-[#2c3e50]">${h.name}</span>
                    <span class="text-xs text-gray-400">Ver</span>
                `;
                container.appendChild(btn);
            });
        }

        function renderCards(filter = 'all') {
            const container = document.getElementById('heresy-grid');
            container.innerHTML = '';

            const filtered = filter === 'all' ? heresies : heresies.filter(h => h.category === filter);

            filtered.forEach(h => {
                const card = document.createElement('div');
                card.className = "bg-white rounded-lg shadow-md overflow-hidden card-hover border-t-2 border-gray-100 cursor-pointer flex flex-col h-full";
                card.onclick = () => openModal(h.id);
                
                // Card Content
                card.innerHTML = `
                    <div class="p-6 flex-grow">
                        <div class="flex justify-between items-start mb-4">
                            <h3 class="text-xl font-bold text-[#2c3e50] font-serif">${h.name}</h3>
                            <span class="bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full uppercase font-bold tracking-wide">${h.origin.split(' ')[0] + ' ' + h.origin.split(' ')[1]}</span>
                        </div>
                        <p class="text-gray-600 text-sm mb-4 line-clamp-3 border-l-2 border-[#d4af37] pl-3 italic">
                            "${h.beliefs.substring(0, 100)}..."
                        </p>
                        <div class="mt-4 pt-4 border-t border-gray-100">
                            <p class="text-xs text-gray-400 uppercase font-bold mb-1">Forma Moderna</p>
                            <p class="text-[#c0392b] font-bold text-sm flex items-center">
                                <span class="mr-2">⚠️</span> ${h.modernForm.split(',')[0]}
                            </p>
                        </div>
                    </div>
                    <div class="bg-gray-50 px-6 py-3 text-center border-t border-gray-100">
                        <span class="text-[#3498db] text-sm font-bold hover:underline">Ver Análisis Completo &rarr;</span>
                    </div>
                `;
                container.appendChild(card);
            });
        }

        function renderArsenalOptions() {
            const select = document.getElementById('claim-selector');
            claims.forEach((claim, index) => {
                const option = document.createElement('option');
                option.value = index;
                // Strip quotes for option text
                option.text = claim.text.replace(/"/g, ''); 
                select.appendChild(option);
            });
        }

        // 3. Interactions
        function updateDefense() {
            const index = document.getElementById('claim-selector').value;
            const claim = claims[index];
            const contextDiv = document.getElementById('claim-context');
            const contentDiv = document.getElementById('defense-content');

            // Find related heresy for name
            const heresy = heresies.find(h => h.id === claim.heresyId);

            // Update Context
            contextDiv.innerHTML = `
                <p><strong>Origen:</strong> Concepto asociado al <span class="text-[#d4af37]">${heresy.name}</span>.</p>
                <p class="mt-1">"${claim.text}"</p>
            `;

            // Update Response with animation effect
            contentDiv.style.opacity = 0;
            setTimeout(() => {
                contentDiv.innerHTML = `
                    <div class="bg-blue-50 border-l-4 border-[#3498db] p-4 rounded text-gray-700">
                        ${claim.refutation}
                    </div>
                    <p class="text-sm text-gray-500 mt-4 text-center">
                        La verdad bíblica es consistente: mantiene la distinción de personas sin dividir la esencia divina.
                    </p>
                `;
                contentDiv.style.opacity = 1;
            }, 200);
            contentDiv.style.transition = 'opacity 0.3s';
        }

        function openModal(id) {
            const h = heresies.find(item => item.id === id);
            
            // Populate Modal
            document.getElementById('modal-title').innerText = h.name;
            document.getElementById('modal-origin-name').innerText = h.name + " Histórico";
            document.getElementById('modal-origin-date').innerText = h.origin;
            document.getElementById('modal-beliefs').innerText = h.beliefs;
            document.getElementById('modal-creed-conflict').innerText = h.creedConflict;
            
            document.getElementById('modal-modern-name').innerText = h.modernForm;
            document.getElementById('modal-modern-group').innerText = "Resurgimiento Actual";
            document.getElementById('modal-modern-distinctions').innerText = h.modernDistinctions;
            document.getElementById('modal-response-summary').innerText = h.response;

            // Show
            const modal = document.getElementById('heresy-modal');
            modal.classList.remove('hidden');
            setTimeout(() => {
                modal.querySelector('div.inline-block').classList.remove('opacity-0', 'translate-y-4', 'sm:translate-y-0', 'sm:scale-95');
                modal.querySelector('div.inline-block').classList.add('opacity-100', 'translate-y-0', 'sm:scale-100');
            }, 10);
        }

        function closeModal() {
            const modal = document.getElementById('heresy-modal');
            modal.querySelector('div.inline-block').classList.add('opacity-0', 'translate-y-4', 'sm:translate-y-0', 'sm:scale-95');
            modal.querySelector('div.inline-block').classList.remove('opacity-100', 'translate-y-0', 'sm:scale-100');
            setTimeout(() => {
                modal.classList.add('hidden');
            }, 300);
        }

        function scrollToSection(id) {
            document.getElementById(id).scrollIntoView({ behavior: 'smooth' });
        }

        // 4. Listeners
        document.getElementById('heresy-filter').addEventListener('change', (e) => {
            renderCards(e.target.value);
        });

        // 5. Init
        window.addEventListener('DOMContentLoaded', () => {
            initChart();
            renderRadarControls();
            renderCards();
            renderArsenalOptions();
        });

    </script>
</body>
</html>
Scroll al inicio