<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Rewrited</title> <!-- Updated tab title -->
    <link rel="icon" href="https://i.ibb.co/179QYyj/circle-logo.png" type="image/png">
    <style>
        /* General Reset */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background-color: #000; /* Black background */
            color: #fff; /* White text */
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            padding: 20px;
        }

        main {
            background-color: #111; /* Slightly lighter black */
            padding: 30px;
            border-radius: 20px; /* Rounded corners */
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8); /* Subtle shadow */
            max-width: 600px;
            width: 100%;
            position: relative; /* For positioning the small text */
        }

        h2 {
            text-align: center;
            margin-bottom: 20px;
        }

        .credit {
            position: absolute;
            bottom: 10px;
            right: 10px;
            font-size: 12px; /* Smaller font size */
            color: #aaa; /* Light gray */
        }

        textarea {
            width: 100%;
            height: 150px;
            background-color: #222; /* Darker text area */
            color: #fff;
            border: none;
            border-radius: 20px; /* Rounded corners */
            padding: 15px;
            resize: none; /* Disable resizing */
        }

        textarea:focus {
            outline: none;
            box-shadow: 0 0 10px rgba(0, 255, 0, 0.5); /* Green glow on focus */
        }

        button {
            width: 100%;
            padding: 15px;
            margin-top: 20px;
            background-color: #4CAF50; /* Green button */
            color: #fff;
            border: none;
            border-radius: 30px; /* Rounded button */
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #45a049; /* Darker green on hover */
        }

        #output {
            margin-top: 20px;
            background-color: #222; /* Output background */
            color: #fff;
            padding: 15px;
            border-radius: 20px; /* Rounded corners */
            min-height: 100px;
            display: flex;
            align-items: center;
            justify-content: center;
            text-align: center;
            white-space: pre-wrap;
        }
    </style>
</head>
<body>
    <main>
        <h2>Rewriter Tool</h2>
        <textarea id="inputText" placeholder="Type your text here..."></textarea>
        <button id="rewriteButton">Rewrite</button>
        <div id="output">Your rewritten text will appear here...</div>
        <div class="credit">by @felony4l</div>
    </main>

    <script>
        document.getElementById('rewriteButton').addEventListener('click', async () => {
            const inputText = document.getElementById('inputText').value;

            if (!inputText.trim()) {
                alert("Please enter text to rewrite!");
                return;
            }

            try {
                // Update the fetch URL to point to your deployed backend on Render
                const response = await fetch('https://site-uhjp.onrender.com/rewrite', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ text: inputText })
                });

                if (!response.ok) {
                    throw new Error('Failed to fetch the response');
                }

                const data = await response.json();
                const output = document.getElementById('output');
                
                // Use innerHTML to render the HTML content
                output.innerHTML = data.rewrittenText || "Error: Unable to rewrite.";
            } catch (error) {
                alert("Error with the API call: " + error.message);
            }
        });
    </script>
</body>
</html>
