<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="Markitect {version}">
    <title>{title}</title>

    {css_content}

    <!-- External dependencies - same as non-edit mode -->
    <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"
            onload="window.markitectMarkedLoaded = true"
            onerror="console.error('CDN library failed to load - network or firewall blocking marked.js'); window.markitectMarkedError = true;"></script>
</head>
<body class="{mode_class}">

    <!-- Content container with fallback content -->
    <div id="markdown-content">
        {fallback_content}
    </div>

    <!-- Configuration Data Interface - ONLY place where Python data enters JavaScript -->
    <script id="markitect-config" type="application/json">{config_json}</script>

    <!-- JavaScript modules from TestDrive-JSUI capability -->
    <script src="capabilities/testdrive-jsui/js/core/debug-system.js"></script>
    <script src="capabilities/testdrive-jsui/js/core/section-manager.js"></script>
    <script src="capabilities/testdrive-jsui/js/components/debug-panel.js"></script>
    <script src="capabilities/testdrive-jsui/js/components/dom-renderer.js"></script>
    <script src="capabilities/testdrive-jsui/js/controls/control-base.js"></script>
    <script src="capabilities/testdrive-jsui/js/controls/contents-control.js"></script>
    <script src="capabilities/testdrive-jsui/js/controls/status-control.js"></script>
    <script src="capabilities/testdrive-jsui/js/controls/debug-control.js"></script>
    <script src="capabilities/testdrive-jsui/js/controls/edit-control.js"></script>
    <script src="capabilities/testdrive-jsui/js/config-loader.js"></script>
    <script src="capabilities/testdrive-jsui/js/main-updated.js"></script>

    <!-- Simple initialization - same pattern as non-edit mode -->
    <script>
        window.addEventListener('load', function() {
            console.log('🎯 Edit mode loading complete, initializing...');

            // Handle CDN loading errors (same as non-edit mode)
            if (window.markitectMarkedError) {
                console.error("CDN library failed to load - network or firewall blocking marked.js");
            }

            // Simple initialization without retries
            try {
                if (typeof MarkitectMain !== 'undefined') {
                    console.log('🚀 Starting MarkitectMain initialization...');
                    MarkitectMain.initialize();
                } else {
                    console.warn('⚠️ MarkitectMain not available, edit functionality may be limited');
                }
            } catch (error) {
                console.error('❌ Edit mode initialization failed:', error);
                console.log('📄 Content should still be visible in fallback mode');
            }
        });
    </script>
</body>
</html>