import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

console.log("Swipe3AM: Initializing Engine...");

const rootElement = document.getElementById('root');

if (rootElement) {
  try {
    const root = ReactDOM.createRoot(rootElement);
    root.render(
      <React.StrictMode>
        <App />
      </React.StrictMode>
    );
    console.log("Swipe3AM: Boot Sequence Complete.");
  } catch (error: any) {
    console.error("Swipe3AM: Critical Failure during render:", error);
    rootElement.innerHTML = `
      <div style="background: #020617; color: #4facfe; height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: sans-serif; padding: 20px; text-align: center;">
        <div style="font-size: 40px; margin-bottom: 20px;">⚠️</div>
        <h1 style="font-weight: 900; letter-spacing: -1px; margin: 0;">APP_CRASH_DETECTED</h1>
        <p style="color: #64748b; font-size: 12px; margin-top: 10px; text-transform: uppercase;">The engine encountered a fatal error.</p>
        <div style="margin-top: 30px; padding: 15px; background: rgba(255,255,255,0.05); border-radius: 10px; font-family: monospace; font-size: 11px; color: #ef4444; max-width: 400px; text-align: left; overflow: auto;">
          ${error.message || error}
        </div>
        <button onclick="window.location.reload()" style="margin-top: 30px; background: #4facfe; color: white; border: none; padding: 12px 24px; border-radius: 8px; font-weight: bold; cursor: pointer;">RETRY BOOT</button>
      </div>
    `;
  }
} else {
  document.body.innerHTML = "FATAL: Root element '#root' missing from DOM.";
}