<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Podcast Name Generator</title>
    <style>
        /* Base styles */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            min-height: 100vh;
            background: linear-gradient(135deg, #EEF2FF 0%, #F5F3FF 50%, #FCE7F3 100%);
            color: #111827;
            line-height: 1.5;
        }

        /* Container */
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 4rem 1rem;
        }

        /* Header */
        .header {
            text-align: center;
            margin-bottom: 3rem;
        }

        .icon-container {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
            background-color: #EEF2FF;
            border-radius: 9999px;
            margin-bottom: 1.5rem;
        }

        .header h1 {
            font-size: 2.5rem;
            font-weight: bold;
            margin-bottom: 1rem;
            color: #111827;
        }

        .header p {
            font-size: 1.125rem;
            color: #4B5563;
            max-width: 36rem;
            margin: 0 auto;
        }

        /* Search Section */
        .search-container {
            background-color: white;
            border-radius: 1rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            margin-bottom: 2rem;
            backdrop-filter: blur(8px);
            background-color: rgba(255, 255, 255, 0.9);
        }

        .search-form {
            display: flex;
            gap: 1rem;
        }

        .search-input {
            flex: 1;
            padding: 0.75rem 1rem;
            border: 1px solid #D1D5DB;
            border-radius: 0.5rem;
            font-size: 1rem;
            transition: all 0.2s;
        }

        .search-input:hover {
            border-color: #9CA3AF;
        }

        .search-input:focus {
            outline: none;
            border-color: #6366F1;
            box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
        }

        .generate-btn {
            padding: 0.75rem 1.5rem;
            background-color: #4F46E5;
            color: white;
            border: none;
            border-radius: 0.5rem;
            font-weight: 500;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            transition: all 0.2s;
        }

        .generate-btn:hover {
            background-color: #4338CA;
        }

        .generate-btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

        /* Results Section */
        .results-container {
            background-color: white;
            border-radius: 1rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
            backdrop-filter: blur(8px);
            background-color: rgba(255, 255, 255, 0.9);
            display: none;
        }

        .results-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
        }

        .results-title {
            font-size: 1.25rem;
            font-weight: 600;
            color: #111827;
        }

        .regenerate-btn {
            color: #4F46E5;
            padding: 0.5rem 1rem;
            border: none;
            background: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            border-radius: 0.5rem;
            transition: all 0.2s;
        }

        .regenerate-btn:hover {
            background-color: #EEF2FF;
        }

        .name-list {
            display: grid;
            gap: 1rem;
        }

        .name-card {
            padding: 1rem;
            background: linear-gradient(to right, #EEF2FF, #F5F3FF);
            border-radius: 0.5rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            transition: all 0.2s;
        }

        .name-card:hover {
            background: linear-gradient(to right, #E0E7FF, #EDE9FE);
        }

        .copy-btn {
            padding: 0.5rem;
            color: #6B7280;
            background: none;
            border: none;
            cursor: pointer;
            border-radius: 0.5rem;
            transition: all 0.2s;
        }

        .copy-btn:hover {
            color: #4F46E5;
            background-color: rgba(255, 255, 255, 0.5);
        }

        .error-message {
            text-align: center;
            color: #DC2626;
            background-color: #FEE2E2;
            padding: 0.5rem 1rem;
            border-radius: 0.5rem;
            margin-bottom: 1.5rem;
            display: none;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        .spinner {
            animation: spin 1s linear infinite;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="icon-container">
                <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="#4F46E5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/>
                    <path d="M19 10v2a7 7 0 0 1-14 0v-2"/>
                    <line x1="12" y1="19" x2="12" y2="23"/>
                    <line x1="8" y1="23" x2="16" y2="23"/>
                </svg>
            </div>
            <h1>Podcast Name Generator</h1>
            <p>Transform your ideas into captivating podcast names. Enter a keyword or topic to discover unique and engaging titles for your next podcast.</p>
        </div>

        <div class="search-container">
            <div class="search-form">
                <input type="text" id="keyword" class="search-input" placeholder="Enter a keyword (e.g., technology, true crime, cooking)">
                <button id="generateBtn" class="generate-btn">
                    <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"/>
                        <path d="M5 3v4"/>
                        <path d="M19 17v4"/>
                        <path d="M3 5h4"/>
                        <path d="M17 19h4"/>
                    </svg>
                    Generate
                </button>
            </div>
        </div>

        <div id="error" class="error-message"></div>

        <div id="results" class="results-container">
            <div class="results-header">
                <h2 class="results-title">Generated Names</h2>
                <button id="regenerateBtn" class="regenerate-btn">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8"/>
                        <path d="M21 3v5h-5"/>
                        <path d="M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16"/>
                        <path d="M3 21v-5h5"/>
                    </svg>
                    Regenerate
                </button>
            </div>
            <div id="namesList" class="name-list"></div>
            <h2>
                <a href="https://podcastpontifications.com/cv4/dreamhost/" target="_blank" style="color: #0000ff; text-decoration: underline;">
                    Get The .COM Domain Name Here
                </a>
            </h2>
        </div>
    </div>

    <script src="https://podcastpontifications.com/png/newscript.js"></script>
    <script>
        // DOM Elements
        const elements = {
            keyword: document.getElementById('keyword'),
            generateBtn: document.getElementById('generateBtn'),
            regenerateBtn: document.getElementById('regenerateBtn'),
            results: document.getElementById('results'),
            namesList: document.getElementById('namesList'),
            error: document.getElementById('error')
        };

        // UI Helper Functions
        const ui = {
            showError: (message) => {
                elements.error.textContent = message;
                elements.error.style.display = 'block';
                setTimeout(() => {
                    elements.error.style.display = 'none';
                }, 3000);
            },

            setLoading: (isLoading) => {
                elements.generateBtn.disabled = isLoading;
                elements.generateBtn.innerHTML = isLoading ? 
                    '<svg class="spinner" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 3v3m6.366-.366-2.12 2.12M21 12h-3m.366 6.366-2.12-2.12M12 21v-3m-6.366.366 2.12-2.12M3 12h3m-.366-6.366 2.12 2.12"/></svg> Generating...' :
                    '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m12 3-1.912 5.813a2 2 0 0 1-1.275 1.275L3 12l5.813 1.912a2 2 0 0 1 1.275 1.275L12 21l1.912-5.813a2 2 0 0 1 1.275-1.275L21 12l-5.813-1.912a2 2 0 0 1-1.275-1.275L12 3Z"/><path d="M5 3v4"/><path d="M19 17v4"/><path d="M3 5h4"/><path d="M17 19h4"/></svg> Generate';
            },

            displayNames: (names) => {
                elements.namesList.innerHTML = '';
                names.forEach(name => {
                    const div = document.createElement('div');
                    div.className = 'name-card';
                    div.innerHTML = `
                        <span>${name}</span>
                        <button class="copy-btn" onclick="copyToClipboard('${name.replace(/'/g, "\\'")}', this)">
                            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                <rect width="14" height="14" x="8" y="8" rx="2" ry="2"/>
                                <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/>
                            </svg>
                        </button>
                    `;
                    elements.namesList.appendChild(div);
                });
                elements.results.style.display = 'block';
            }
        };

        // Copy to clipboard function
        async function copyToClipboard(text, button) {
            try {
                await navigator.clipboard.writeText(text);
                const originalHTML = button.innerHTML;
                button.innerHTML = `
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#16A34A" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polyline points="20 6 9 17 4 12"/>
                    </svg>
                `;
                setTimeout(() => {
                    button.innerHTML = originalHTML;
                }, 2000);
            } catch (err) {
                ui.showError('Failed to copy to clipboard');
            }
        }

        // Generate names function
        async function generateNames() {
            const keyword = elements.keyword.value.trim();
            
            if (!keyword) {
                ui.showError('Please enter a keyword');
                return;
            }

            ui.setLoading(true);
            elements.results.style.display = 'none';

            try {
                const names = await window.generatePodcastNames(keyword); // Call the backend function from your script
                if (!names || names.length === 0) {
                    throw new Error('No names were generated');
                }
                ui.displayNames(names);
            } catch (error) {
                console.error('Generation error:', error);
                ui.showError('Error generating names. Please try again.');
            } finally {
                ui.setLoading(false);
            }
        }

        // Event Listeners
        elements.generateBtn.addEventListener('click', generateNames);
        elements.regenerateBtn.addEventListener('click', generateNames);
        elements.keyword.addEventListener('keypress', (e) => {
            if (e.key === 'Enter') generateNames();
        });

        // Initialize
        document.addEventListener('DOMContentLoaded', () => {
            elements.keyword.focus();
        });
    </script>
</body>
</html>
