<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Generate AI-powered images instantly with our Image Generator tool.">
    <meta name="keywords" content="image generator, AI images, generate images, AI art">
    <meta name="author" content="PhatNotTaken">
    <link rel="icon" href="↻✎‗miku _ hazl_x.png" type="image/x-icon">
    <title></title>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            const titleText = "Image Generator | PhatNotTaken"; // Nội dung của title
            let index = 0;
            const titleElement = document.querySelector("title");

            function updateTitle() {
                titleElement.textContent = titleText.slice(0, index); // Cập nhật phần title với những ký tự đã được thêm vào
                index++;
                if (index <= titleText.length) {
                    setTimeout(updateTitle, 300); // Tốc độ xuất hiện
                } else {
                    setTimeout(function() {
                        index = 0; // Đặt lại chỉ số để lặp lại
                        updateTitle(); // Bắt đầu lại vòng lặp
                    }, 1000); // Thời gian chờ sau khi kết thúc hiệu ứng
                }
            }

            updateTitle(); // Gọi hàm để bắt đầu hiệu ứng
        });
    </script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
    <style>
        /* style.css */
body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    height: 100vh; /* Giữ chiều cao 100% của viewport */
    overflow: hidden; /* Không cho phép cuộn toàn bộ trang */
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    cursor: none; /* Ẩn con trỏ mặc định */
}

.video-background {
    position: fixed; /* Giữ video luôn ở nền */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.video-background video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.container {
    text-align: center;
    background: rgba(255, 255, 255, 0.2); /* Nền trong suốt nhẹ */
    backdrop-filter: blur(10px); /* Hiệu ứng làm mờ nền phía sau */
    padding: 30px;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.3); /* Viền trong suốt nhẹ */
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3); /* Hiệu ứng đổ bóng */
    width: 90%;
    max-width: 600px;
    max-height: 80%; /* Đặt chiều cao tối đa cho card */
    overflow-y: auto; /* Cho phép cuộn nội dung trong card */
    position: relative; /* Giữ vị trí của card cố định so với nội dung bên trong */
    scrollbar-width: none;
}


h1 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    background: linear-gradient(90deg, red, orange, yellow, green, cyan, blue, purple);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientAnimation 3s linear infinite;
    background-size: 300% 300%;
    display: inline-block;
}

@keyframes gradientAnimation {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 100% 50%;
    }
}


form {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

input, button {
    margin-bottom: 10px; /* Thêm khoảng cách giữa các phần tử */
}

input {
    flex: 1;
    padding: 10px;
    border: 2px solid #000;
    border-radius: 6px;
    margin-right: 10px;
    background: rgba(255, 255, 255, 0.2); /* Nền trong suốt nhẹ */
    color: #000000 !important; /* Đặt màu chữ thành đen */
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s;
    -webkit-text-fill-color: #000000 !important; /* Đặt màu chữ đen trong trình duyệt Webkit */
    text-shadow: none !important; /* Loại bỏ hiệu ứng đổ bóng */
}

input::placeholder {
    color: rgba(0, 0, 0, 0.6); /* Màu placeholder thành xám đen */
    text-shadow: none !important; /* Loại bỏ đổ bóng của placeholder */
}

input:focus {
    border-color: #ffffff; /* Thay đổi màu viền khi input được focus */
}


button {
    padding: 10px 20px;
    border: none;
    background-color: #007bff;
    color: white;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #0056b3;
}

.spinner {
    margin: 20px auto;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #fff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

#result {
    margin-top: 20px;
    text-align: center;
}

#generatedImage {
    max-width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    margin: 10px 0;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.actions button,
.actions a {
    padding: 10px 15px;
    border: none;
    background: linear-gradient(90deg, #d49dcd, #e2abe4); /* Gradient màu xanh lá */
    color: white;
    border-radius: 8px;
    text-decoration: none;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease-in-out;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Hiệu ứng bóng */
}

.actions button:hover,
.actions a:hover {
    transform: translateY(-3px); /* Nổi lên khi hover */
    background: linear-gradient(90deg, #df89c5, #dd93d7); /* Đổi hướng gradient */
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3); /* Bóng đậm hơn */
}

.cursor {
    position: fixed;
    top: 0;
    left: 0;
    width: 40px; /* Kích thước trỏ chuột */
    height: 40px;
    background: url('miku.png') no-repeat center center; /* Hình ảnh trỏ chuột */
    background-size: contain; /* Đảm bảo hình ảnh vừa khít */
    pointer-events: none; /* Không ảnh hưởng đến sự tương tác */
    transform: translate(-50%, -50%);
    z-index: 9999;
    transition: opacity 0.2s ease; /* Mờ dần khi rời màn hình */
}


.emoji-container {
    position: absolute;
    top: -10px; /* Căn chỉnh vị trí các emoji */
    left: 10px;
    display: flex;
    gap: 5px; /* Khoảng cách giữa các emoji */
}

/* Căn chỉnh và thêm hiệu ứng động */
.emoji {
    width: 20px;
    height: 20px;
    animation: bounce 1.5s infinite ease-in-out;
}

/* Hiệu ứng động cho emoji */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
}

.emoji-gif {
    width: 24px; /* Kích thước của emoji */
    height: 24px;
    margin-right: 8px; /* Khoảng cách giữa emoji và chữ */
    display: inline-block;
    vertical-align: middle; /* Căn giữa với chữ */
    animation: float 1.5s infinite ease-in-out; /* Thêm hiệu ứng */
}


#title {
            font-size: 3em;
            font-weight: bold;
            overflow: hidden;
            white-space: nowrap;
            width: 0;
            animation: expandTitle 5s forwards;
        }
        @keyframes expandTitle {
            0% {
                width: 0;
            }
            100% {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <!-- Video Background -->
    <div class="video-background">
        <video autoplay muted loop>
            <source src="background.mp4" type="video/mp4">
            Your browser does not support the video tag.
        </video>
    </div>

    <!-- Main Content -->
    <div class="container">
        <h1><img src="https://cdn.discordapp.com/emojis/1141781016562896958.gif?size=44&animated=true" alt="Emoji" class="emoji-gif"> <span class="title-gradient"></span>Image Generator <img src="https://cdn.discordapp.com/emojis/1144376423683985498.gif?size=44&animated=true" alt="Emoji" class="emoji-gif"></h1>
        <form id="apiForm">
            <input type="text" id="promptInput" placeholder="Enter your prompt..." required>
            <button type="submit" id="generateButton"><img src="https://cdn.discordapp.com/emojis/1311966013528473600.gif?size=44&animated=true" alt="Emoji" class="emoji-gif">Generate</button>
        </form>
        <div id="loading" class="spinner" style="display: none;"></div>
        <div id="result" style="display: none;">
            <p><strong>Generated Image:</strong></p>
            <img id="generatedImage" alt="Generated Image">
            <div class="actions">
                <button id="copyButton">Copy URL</button>
                <button id="downloadButton" href="#" download>Download</button>
            </div>
        </div>
        <div id="errorMessage" style="display: none; color: red;"></div>
    </div>

    <!-- Custom Cursor -->
    <div class="cursor"></div>
    <script>
        const apiUrl = 'https://steep-sun-7df7.vanphat51nbs2010.workers.dev/api/image?prompt='; // Base URL của API

document.getElementById('apiForm').addEventListener('submit', async (e) => {
    e.preventDefault(); // Ngăn form gửi đi mặc định

    const promptInput = document.getElementById('promptInput').value; // Lấy giá trị prompt
    const loadingDiv = document.getElementById('loading'); // Hiển thị trạng thái loading
    const resultDiv = document.getElementById('result'); // Div hiển thị kết quả
    const errorMessage = document.getElementById('errorMessage');
    const generatedImage = document.getElementById('generatedImage');
    const downloadButton = document.getElementById('downloadButton');

    // Reset trạng thái
    loadingDiv.style.display = 'block';
    resultDiv.style.display = 'none';
    errorMessage.style.display = 'none';

    try {
        // Gửi request đến API
        const response = await fetch(`${apiUrl}${encodeURIComponent(promptInput)}`, {
            method: 'GET', // API sử dụng phương thức GET
        });

        if (!response.ok) {
            throw new Error(`API Error: ${response.status}`);
        }

        const data = await response.json(); // Parse kết quả JSON
        const imageUrl = data.image; // Lấy giá trị "image"

        // Hiển thị ảnh
        generatedImage.src = imageUrl;

        // Tải ảnh thực sự dưới dạng Blob
        const imageResponse = await fetch(imageUrl);
        const imageBlob = await imageResponse.blob();

        // Tạo Object URL từ Blob
        const blobUrl = URL.createObjectURL(imageBlob);

        // Gắn URL Blob vào nút tải xuống
        downloadButton.href = blobUrl;
        downloadButton.download = 'downloaded-image.png'; // Đặt tên file mặc định

        // Hiển thị ảnh và nút tải về
        resultDiv.style.display = 'block';
    } catch (error) {
        // Hiển thị lỗi
        errorMessage.style.display = 'block';
        errorMessage.textContent = `Error: ${error.message}`;
    } finally {
        // Ẩn loading
        loadingDiv.style.display = 'none';
    }
});
// Nút Copy URL
document.getElementById('copyButton').addEventListener('click', () => {
    const imageUrl = document.getElementById('generatedImage').src;

    navigator.clipboard.writeText(imageUrl).then(() => {
        alert('Image URL copied to clipboard!');
    }).catch(() => {
        alert('Failed to copy URL.');
    });
});

document.addEventListener('DOMContentLoaded', () => {
    // Xóa bất kỳ phần tử con trỏ nào trước đó (để tránh nhân đôi)
    const existingCursor = document.querySelector('.cursor');
    if (existingCursor) existingCursor.remove();

    // Tạo phần tử con trỏ
    const cursor = document.createElement('div');
    cursor.classList.add('cursor');
    document.body.appendChild(cursor);

    let mouseX = 0, mouseY = 0;

    // Lắng nghe sự kiện di chuyển chuột
    document.addEventListener('mousemove', (e) => {
        mouseX = e.clientX;
        mouseY = e.clientY;
        cursor.style.opacity = '1'; // Hiển thị lại khi di chuyển chuột
    });

    // Sử dụng requestAnimationFrame để làm mượt di chuyển
    const updateCursor = () => {
        cursor.style.transform = `translate(${mouseX}px, ${mouseY}px)`;
        requestAnimationFrame(updateCursor);
    };

    updateCursor();

    // Ẩn con trỏ khi chuột rời cửa sổ trình duyệt
    document.addEventListener('mouseleave', () => {
        cursor.style.opacity = '0';
    });

    // Hiện lại con trỏ khi chuột quay lại
    document.addEventListener('mouseenter', () => {
        cursor.style.opacity = '1';
    });
});

const titleElement = document.getElementById("title");
        titleElement.style.animationPlayState = 'running';

    </script>
    <script src="flower.js"></script>
</body>
</html>
