<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login | Adult Zone 🔐</title>
    <link rel="icon" type="image/png" href="favicon.png">
    <style>
        /* General Reset */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-image: url('img/velvet-texture.png'); /* Add velvet-like background image */
            background-size: cover;
            background-position: center;
            color: #fff;
            overflow: hidden;
            position: relative;
        }

        body::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: inherit;
            filter: blur(06px);
            z-index: -1;
        }

        .container {
            background: rgba(150, 0, 0, 0.6); /* Red velvet feel */
            border: 1px solid rgba(255, 255, 255, 0.3);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(8px);
            border-radius: 10px;
            padding: 40px;
            width: 380px;
            text-align: center;
            font-size: 1.1rem;
        }

        h1 {
            font-size: 1.8rem;
            margin-bottom: 05px;
            color: #ff4d4d;
        }
        
        h4 {
            font-size: 1.0rem;
            margin-bottom: 30px;
            color: #ffc13b;
        }

        label {
            display: block;
            margin-bottom: 15px;
            text-align: left;
            font-weight: bold;
            color: #ffcccc;
        }

        input {
            width: 100%;
            padding: 12px;
            margin-bottom: 20px;
            border-radius: 5px;
            border: none;
            background: rgba(255, 255, 255, 0.7);
            font-size: 1rem;
            outline: none;
        }

        button {
            width: 100%;
            padding: 14px;
            border: none;
            border-radius: 25px;
            font-size: 1.2rem;
            font-weight: bold;
            background: linear-gradient(135deg, #ff4d4d, #ff0000);
            color: #fff;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        button:hover {
            background: linear-gradient(135deg, #ff0000, #ff4d4d);
        }

        .toggle {
            margin-top: 20px;
            color: #ffd700;
            cursor: pointer;
            text-decoration: none;
        }

        .error {
            color: #ff4d4d;
            font-size: 0.9rem;
            margin-bottom: 20px;
        }

        .success {
            color: #00ff00;
            font-size: 0.9rem;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <div class="container">
    <h1 id="form-heading">Login to Access</h1>
    <h4 id="welcome-heading">Welcome to AdultZone</h4>
    <form id="login-form" method="POST">
        <label for="username">Email:</label>
        <input type="text" name="username" id="username" required>
        <label for="password">Password:</label>
        <input type="password" name="password" id="password" required>
        <?php if (isset($error)) echo "<p class='error'>$error</p>"; ?>
        <?php if (isset($success)) echo "<p class='success'>$success</p>"; ?>
        <button type="submit" name="login">Login</button>
    </form>

    <div id="create-account-form" style="display: none;">
        <form method="POST" onsubmit="return validateEmail()">
            <label for="first_name">First Name:</label>
            <input type="text" name="first_name" id="first_name" required>
            <label for="last_name">Last Name:</label>
            <input type="text" name="last_name" id="last_name" required>
            <label for="email">Email:</label>
            <input type="email" name="email" id="email" required>
            <div id="email-error" class="error-message" style="display: none; color: red;"></div>
            <label for="password">Password:</label>
            <input type="password" name="password" id="password" required>
            <button type="submit" name="create_account">Create Account</button>
        </form>
    </div>

    <p class="toggle" onclick="toggleForms()">↪ Create an Account</p>
</div>

<script>
    function toggleForms() {
        const loginForm = document.getElementById('login-form');
        const createAccountForm = document.getElementById('create-account-form');
        const formHeading = document.getElementById('form-heading');
        const welcomeHeading = document.getElementById('welcome-heading');
        const toggleText = document.querySelector('.toggle');

        if (loginForm.style.display === 'none') {
            loginForm.style.display = 'block';
            createAccountForm.style.display = 'none';
            formHeading.textContent = 'Login to Access';
            welcomeHeading.style.display = 'block';  // Show the "Welcome" heading
            toggleText.textContent = '↪ Create an Account';
        } else {
            loginForm.style.display = 'none';
            createAccountForm.style.display = 'block';
            formHeading.textContent = 'Create an Account';
            welcomeHeading.style.display = 'none';  // Hide the "Welcome" heading
            toggleText.textContent = '↩ Back to Login';
        }
    }

    function validateEmail() {
        const emailInput = document.getElementById('email');
        const emailError = document.getElementById('email-error');
        const email = emailInput.value;
        
        // Check if the email ends with '@mail.com'
        const regex = /^[a-zA-Z0-9._-]+@gmail\.com$/;

        if (!regex.test(email)) {
            emailError.textContent = 'Invalid Email: Please enter a valid email';
            emailError.style.display = 'block';  // Show the error message
            emailInput.style.borderColor = 'red';  // Change input border color to red
            return false;  // Prevent form submission
        } else {
            emailError.style.display = 'none';  // Hide the error message
            emailInput.style.borderColor = '';  // Reset the border color
        }
        return true;  // Allow form submission
    }
</script>

</body>
</html>
