<?php
session_start();
require_once 'config.php';

$username = $usernumber = $password = $repassword = '';
$username_err = $usernumber_err = $password_err = $repassword_err = $register_err = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
	// Validate username
	if (empty(trim($_POST['username']))) {
		$username_err = 'Please enter a username.';
	} else {
		$sql = 'SELECT id FROM users WHERE username = ?';
		if ($stmt = mysqli_prepare($link, $sql)) {
			mysqli_stmt_bind_param($stmt, 's', $_POST['username']);
			mysqli_stmt_execute($stmt);
			mysqli_stmt_store_result($stmt);
			if (mysqli_stmt_num_rows($stmt) > 0) {
				$username_err = 'This username is already taken.';
			} else {
				$username = trim($_POST['username']);
			}
			mysqli_stmt_close($stmt);
		}
	}

	// Validate usernumber
	if (empty(trim($_POST['usernumber']))) {
		$usernumber_err = 'Please enter a user number.';
	} elseif (!ctype_digit($_POST['usernumber'])) {
		$usernumber_err = 'User number must be an integer.';
	} else {
		$sql = 'SELECT id FROM users WHERE usernumber = ?';
		if ($stmt = mysqli_prepare($link, $sql)) {
			mysqli_stmt_bind_param($stmt, 'i', $_POST['usernumber']);
			mysqli_stmt_execute($stmt);
			mysqli_stmt_store_result($stmt);
			if (mysqli_stmt_num_rows($stmt) > 0) {
				$usernumber_err = 'This user number is already taken.';
			} else {
				$usernumber = trim($_POST['usernumber']);
			}
			mysqli_stmt_close($stmt);
		}
	}

	// Validate password
	if (empty(trim($_POST['password']))) {
		$password_err = 'Please enter a password.';
	} elseif (strlen(trim($_POST['password'])) < 6) {
		$password_err = 'Password must have at least 6 characters.';
	} else {
		$password = trim($_POST['password']);
	}

	// Validate re-password
	if (empty(trim($_POST['repassword']))) {
		$repassword_err = 'Please confirm password.';
	} else {
		$repassword = trim($_POST['repassword']);
		if ($password !== $repassword) {
			$repassword_err = 'Passwords do not match.';
		}
	}

	// Check input errors before inserting in database
	if (empty($username_err) && empty($usernumber_err) && empty($password_err) && empty($repassword_err)) {
        $sql = 'INSERT INTO users (username, usernumber, password) VALUES (?, ?, ?)';
        if ($stmt = mysqli_prepare($link, $sql)) {
            $param_password = password_hash($password, PASSWORD_DEFAULT);
            mysqli_stmt_bind_param($stmt, 'sis', $username, $usernumber, $param_password);
            if (mysqli_stmt_execute($stmt)) {
                // Show modern success popup and redirect
                echo '
                <div class="success-popup" id="successPopup">
                    <div class="success-popup-content">
                        <div class="success-icon">✓</div>
                        <h2 class="success-title">Account Created Successfully!</h2>
                        <p class="success-subtitle">Welcome to Shubank! You will be redirected to login page in a moment.</p>
                    </div>
                </div>
                <script>
                    setTimeout(function(){ 
                        document.getElementById("successPopup").style.opacity = "0";
                        setTimeout(function(){ 
                            window.location.href="login.php"; 
                        }, 300);
                    }, 3000);
                </script>
                ';
                // Show popup over the form, do not exit so form remains visible
                return;
            } else {
                $register_err = 'Something went wrong. Please try again later.';
            }
            mysqli_stmt_close($stmt);
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Create Account - Shubank | Join the Platform</title>
    <meta name="description" content="Create your Shubank account to start your number prediction journey. Join thousands of users in India's most trusted prediction platform.">
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        /* Emoji font support */
        .emoji {
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Android Emoji", "EmojiSymbols", sans-serif;
            font-style: normal;
            font-variant: normal;
        }
        /* Professional Registration Page Styles */
        .register-container {
            min-height: 100vh;
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            position: relative;
            overflow: hidden;
        }

        .register-container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="dots" width="20" height="20" patternUnits="userSpaceOnUse"><circle cx="10" cy="10" r="1.5" fill="rgba(255,255,255,0.1)"/></pattern></defs><rect width="100" height="100" fill="url(%23dots)"/></svg>');
            opacity: 0.4;
        }

        .register-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            border-radius: 24px;
            padding: 48px;
            width: 100%;
            max-width: 520px;
            box-shadow: 
                0 20px 40px rgba(0, 0, 0, 0.1),
                0 15px 12px rgba(0, 0, 0, 0.08),
                inset 0 1px 0 rgba(255, 255, 255, 0.6);
            border: 1px solid rgba(255, 255, 255, 0.2);
            position: relative;
            z-index: 1;
        }

        .register-header {
            text-align: center;
            margin-bottom: 40px;
        }

        .register-logo {
            display: inline-flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 24px;
            text-decoration: none;
            color: #1a202c;
        }

        .register-logo .logo-icon {
            font-size: 32px;
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .register-logo .logo-text {
            font-size: 28px;
            font-weight: 700;
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .register-title {
            font-size: 32px;
            font-weight: 700;
            color: #1a202c;
            margin-bottom: 8px;
            font-family: 'Inter', sans-serif;
        }

        .register-subtitle {
            font-size: 16px;
            color: #718096;
            font-weight: 400;
            line-height: 1.5;
        }

        .professional-form {
            margin-bottom: 32px;
        }

        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
            margin-bottom: 24px;
        }

        .form-group {
            margin-bottom: 24px;
            position: relative;
            z-index: 1;
        }

        .form-label {
            display: block;
            font-weight: 600;
            color: #2d3748;
            margin-bottom: 8px;
            font-size: 14px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .form-input {
            width: 100%;
            padding: 16px 50px 16px 20px;
            border: 2px solid #e2e8f0;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 500;
            color: #2d3748;
            background: #ffffff;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-sizing: border-box;
            font-family: 'Inter', sans-serif;
        }

        .form-input:focus {
            outline: none;
            border-color: #4facfe;
            box-shadow: 0 0 0 3px rgba(79, 172, 254, 0.1);
            transform: translateY(-1px);
        }

        .form-input::placeholder {
            color: #a0aec0;
            font-weight: 400;
        }

        .form-input.valid {
            border-color: #48bb78;
            background: #f0fff4;
        }

        .form-input.invalid {
            border-color: #f56565;
            background: #fffafa;
        }

        .input-icon {
            position: absolute;
            right: 18px;
            top: 50%;
            transform: translateY(-50%);
            color: #a0aec0;
            font-size: 14px;
            pointer-events: none;
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Android Emoji", "EmojiSymbols", sans-serif;
            line-height: 1;
            z-index: 5;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .password-toggle {
            position: absolute;
            right: 18px;
            top: 34px;
            background: none;
            border: none;
            color: #a0aec0;
            cursor: pointer;
            font-size: 14px;
            padding: 2px;
            border-radius: 4px;
            transition: color 0.2s ease;
            font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Android Emoji", "EmojiSymbols", sans-serif;
            line-height: 1;
            z-index: 10;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 20px;
            height: 20px;
        }

        /* Specific positioning for confirm password field */
        .form-group:not(.password-group) .password-toggle {
            top: 50%;
            transform: translateY(-50%);
        }

        .password-toggle:hover {
            color: #4facfe;
        }

        .password-strength {
            margin-top: 8px;
            height: 4px;
            background: #e2e8f0;
            border-radius: 2px;
            overflow: hidden;
        }

        .password-strength-bar {
            height: 100%;
            width: 0%;
            transition: all 0.3s ease;
            border-radius: 2px;
        }

        .strength-weak { background: #f56565; width: 25%; }
        .strength-fair { background: #ed8936; width: 50%; }
        .strength-good { background: #38b2ac; width: 75%; }
        .strength-strong { background: #48bb78; width: 100%; }

        .password-requirements {
            margin-top: 12px;
            font-size: 13px;
            color: #718096;
        }

        .requirement {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 4px;
        }

        .requirement.met {
            color: #48bb78;
        }

        .register-button {
            width: 100%;
            padding: 18px 24px;
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
            color: white;
            border: none;
            border-radius: 12px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            overflow: hidden;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            font-family: 'Inter', sans-serif;
        }

        .register-button::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
            transition: left 0.6s ease;
        }

        .register-button:hover::before {
            left: 100%;
        }

        .register-button:hover {
            transform: translateY(-2px);
            box-shadow: 0 12px 24px rgba(79, 172, 254, 0.4);
        }

        .register-button:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        .register-links {
            text-align: center;
            margin-top: 32px;
        }

        .register-link {
            color: #4facfe;
            text-decoration: none;
            font-weight: 500;
            font-size: 14px;
            transition: all 0.2s ease;
            position: relative;
        }

        .register-link::after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: #4facfe;
            transition: width 0.3s ease;
        }

        .register-link:hover {
            color: #00f2fe;
        }

        .register-link:hover::after {
            width: 100%;
        }

        .error-message {
            background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
            color: #c53030;
            padding: 16px 20px;
            border-radius: 12px;
            margin-bottom: 24px;
            border: 1px solid #fc8181;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .success-message {
            background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%);
            color: #2f855a;
            padding: 16px 20px;
            border-radius: 12px;
            margin-bottom: 24px;
            border: 1px solid #68d391;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .terms-checkbox {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            margin-bottom: 24px;
            font-size: 14px;
            color: #4a5568;
            line-height: 1.5;
        }

        .terms-checkbox input[type="checkbox"] {
            margin-top: 3px;
            transform: scale(1.2);
            accent-color: #4facfe;
        }

        .benefits-section {
            background: rgba(79, 172, 254, 0.05);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 32px;
        }

        .benefits-title {
            font-size: 16px;
            font-weight: 600;
            color: #2d3748;
            margin-bottom: 16px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .benefit-item {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
            font-size: 14px;
            color: #4a5568;
        }

        .benefit-item > span:first-child {
            color: #48bb78;
            font-weight: bold;
            font-size: 16px;
        }

        .benefits-title > span:first-child {
            color: #4facfe;
            font-size: 18px;
        }

        .requirement > span:first-child {
            font-weight: bold;
            font-size: 14px;
            width: 16px;
            text-align: center;
        }

        .requirement.met > span:first-child {
            color: #48bb78;
        }

        .error-message > span:first-child {
            background: #c53030;
            color: white;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 12px;
            font-weight: bold;
            flex-shrink: 0;
        }

        .loading-overlay {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(255, 255, 255, 0.9);
            display: none;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
        }

        .spinner {
            width: 24px;
            height: 24px;
            border: 3px solid #e2e8f0;
            border-top: 3px solid #4facfe;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

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

        /* Success Popup Styles */
        .success-popup {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.6);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 10000;
            animation: fadeIn 0.3s ease;
        }

        .success-popup-content {
            background: white;
            border-radius: 20px;
            padding: 48px 40px;
            text-align: center;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
            animation: scaleIn 0.4s ease;
            max-width: 400px;
            width: 90%;
        }

        .success-icon {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 24px;
            font-size: 40px;
            color: white;
            animation: checkmark 0.6s ease 0.3s both;
        }

        .success-title {
            font-size: 24px;
            font-weight: 700;
            color: #1a202c;
            margin-bottom: 16px;
        }

        .success-subtitle {
            font-size: 16px;
            color: #718096;
            margin-bottom: 32px;
        }

        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }

        @keyframes scaleIn {
            from { transform: scale(0.8); opacity: 0; }
            to { transform: scale(1); opacity: 1; }
        }

        @keyframes checkmark {
            from { transform: scale(0); }
            to { transform: scale(1); }
        }

        /* Responsive Design */
        @media (max-width: 768px) {
            .register-card {
                padding: 32px 24px;
                margin: 20px;
                border-radius: 16px;
            }

            .register-title {
                font-size: 28px;
            }

            .form-row {
                grid-template-columns: 1fr;
                gap: 0;
            }
        }

        @media (max-width: 480px) {
            .register-container {
                padding: 16px;
            }

            .register-card {
                padding: 24px 20px;
            }

            .register-title {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
    <div class="register-container">
        <div class="register-card">
            <div class="register-header">
                <a href="index.php" class="register-logo">
                    <span class="logo-icon">🏆</span>
                    <span class="logo-text">Shubank</span>
                </a>
                <h1 class="register-title">Create Your Account</h1>
                <p class="register-subtitle">Join thousands of users in India's most trusted number prediction platform</p>
            </div>

            <div class="benefits-section">
                <div class="benefits-title">
                    <span class="emoji">🎯</span>
                    <span>Why Choose Shubank?</span>
                </div>
                <div class="benefit-item">
                    <span class="emoji">✅</span>
                    <span>Real-time market updates and predictions</span>
                </div>
                <div class="benefit-item">
                    <span class="emoji">✅</span>
                    <span>Secure transactions and data protection</span>
                </div>
                <div class="benefit-item">
                    <span class="emoji">✅</span>
                    <span>24/7 customer support and assistance</span>
                </div>
                <div class="benefit-item">
                    <span class="emoji">✅</span>
                    <span>Instant withdrawals and deposits</span>
                </div>
            </div>

            <div id="js-errors">
                <?php
                if (!empty($register_err)) echo '<div class="error-message"><span>!</span><span>' . $register_err . '</span></div>';
                if (!empty($username_err)) echo '<div class="error-message"><span>!</span><span>' . $username_err . '</span></div>';
                if (!empty($usernumber_err)) echo '<div class="error-message"><span>!</span><span>' . $usernumber_err . '</span></div>';
                if (!empty($password_err)) echo '<div class="error-message"><span>!</span><span>' . $password_err . '</span></div>';
                if (!empty($repassword_err)) echo '<div class="error-message"><span>!</span><span>' . $repassword_err . '</span></div>';
                ?>
            </div>

            <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post" class="professional-form" id="registerForm">
                <div class="form-row">
                    <div class="form-group">
                        <label for="username" class="form-label">Username</label>
                        <input 
                            type="text" 
                            name="username" 
                            id="username" 
                            class="form-input"
                            placeholder="Choose a unique username"
                            value="<?php echo htmlspecialchars($username); ?>"
                            required
                            autocomplete="username"
                        >
                        <span class="input-icon emoji">👤</span>
                    </div>

                    <div class="form-group">
                        <label for="usernumber" class="form-label">Phone Number</label>
                        <input 
                            type="tel" 
                            name="usernumber" 
                            id="usernumber" 
                            class="form-input"
                            placeholder="Enter your phone number"
                            value="<?php echo htmlspecialchars($usernumber); ?>"
                            required
                            autocomplete="tel"
                        >
                        <span class="input-icon emoji">📱</span>
                    </div>
                </div>

                <div class="form-group password-group">
                    <label for="password" class="form-label">Password</label>
                    <input 
                        type="password" 
                        name="password" 
                        id="password" 
                        class="form-input"
                        placeholder="Create a strong password"
                        required
                        autocomplete="new-password"
                    >
                    <button type="button" class="password-toggle" onclick="togglePassword('password')">
                        <span id="toggleIcon1" class="emoji">👁️</span>
                    </button>
                    <div class="password-strength">
                        <div class="password-strength-bar" id="strengthBar"></div>
                    </div>
                    <div class="password-requirements" id="passwordRequirements">
                        <div class="requirement" id="lengthReq">
                            <span class="emoji">❌</span>
                            <span>At least 6 characters</span>
                        </div>
                        <div class="requirement" id="numberReq">
                            <span class="emoji">❌</span>
                            <span>Contains a number</span>
                        </div>
                        <div class="requirement" id="specialReq">
                            <span class="emoji">❌</span>
                            <span>Contains special character</span>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label for="repassword" class="form-label">Confirm Password</label>
                    <input 
                        type="password" 
                        name="repassword" 
                        id="repassword" 
                        class="form-input"
                        placeholder="Confirm your password"
                        required
                        autocomplete="new-password"
                    >
                    <button type="button" class="password-toggle" onclick="togglePassword('repassword')">
                        <span id="toggleIcon2" class="emoji">👁️</span>
                    </button>
                </div>

                <div class="terms-checkbox">
                    <input type="checkbox" id="terms" required>
                    <label for="terms">
                        I agree to the <a href="#" class="register-link">Terms of Service</a> and 
                        <a href="#" class="register-link">Privacy Policy</a>. I confirm that I am 18+ years old.
                    </label>
                </div>

                <button type="submit" class="register-button" id="registerBtn">
                    <span id="registerText">Create Account Securely</span>
                    <div class="loading-overlay" id="loadingOverlay">
                        <div class="spinner"></div>
                    </div>
                </button>
            </form>

            <div class="register-links">
                <span>Already have an account? </span>
                <a href="login.php" class="register-link">» Sign In Here</a>
            </div>
        </div>
    </div>

    <script>
        // Password visibility toggle
        function togglePassword(fieldId) {
            const passwordField = document.getElementById(fieldId);
            const toggleIcon = document.getElementById(fieldId === 'password' ? 'toggleIcon1' : 'toggleIcon2');
            
            if (passwordField.type === 'password') {
                passwordField.type = 'text';
                toggleIcon.textContent = '🙈';
            } else {
                passwordField.type = 'password';
                toggleIcon.textContent = '👁️';
            }
        }

        // Password strength checker
        function checkPasswordStrength(password) {
            let strength = 0;
            const requirements = {
                length: password.length >= 6,
                number: /\d/.test(password),
                special: /[!@#$%^&*(),.?":{}|<>]/.test(password)
            };

            if (requirements.length) strength++;
            if (requirements.number) strength++;
            if (requirements.special) strength++;
            if (password.length >= 8) strength++;

            return { strength, requirements };
        }

        // Update password requirements
        document.getElementById('password').addEventListener('input', function() {
            const password = this.value;
            const { strength, requirements } = checkPasswordStrength(password);
            const strengthBar = document.getElementById('strengthBar');
            
            // Update strength bar
            strengthBar.className = 'password-strength-bar';
            if (strength === 1) strengthBar.classList.add('strength-weak');
            else if (strength === 2) strengthBar.classList.add('strength-fair');
            else if (strength === 3) strengthBar.classList.add('strength-good');
            else if (strength >= 4) strengthBar.classList.add('strength-strong');

            // Update requirements
            document.getElementById('lengthReq').className = 'requirement' + (requirements.length ? ' met' : '');
            document.getElementById('lengthReq').querySelector('span').textContent = requirements.length ? '✅' : '❌';
            
            document.getElementById('numberReq').className = 'requirement' + (requirements.number ? ' met' : '');
            document.getElementById('numberReq').querySelector('span').textContent = requirements.number ? '✅' : '❌';
            
            document.getElementById('specialReq').className = 'requirement' + (requirements.special ? ' met' : '');
            document.getElementById('specialReq').querySelector('span').textContent = requirements.special ? '✅' : '❌';
        });

        // Form validation
        function validateRegisterForm() {
            let username = document.getElementById('username').value.trim();
            let usernumber = document.getElementById('usernumber').value.trim();
            let password = document.getElementById('password').value;
            let repassword = document.getElementById('repassword').value;
            let terms = document.getElementById('terms').checked;
            let errors = [];

            if (username.length < 3) {
                errors.push("Username must be at least 3 characters.");
            }

            if (!/^\d{10}$/.test(usernumber)) {
                errors.push("Phone number must be 10 digits.");
            }

            if (password.length < 6) {
                errors.push("Password must have at least 6 characters.");
            }

            if (password !== repassword) {
                errors.push("Passwords do not match.");
            }

            if (!terms) {
                errors.push("Please accept the terms and conditions.");
            }

            let errorBox = document.getElementById('js-errors');
            if (errors.length > 0) {
                errorBox.innerHTML = errors.map(e => `<div class="error-message"><span>!</span><span>${e}</span></div>`).join('');
                return false;
            }
            errorBox.innerHTML = '';
            return true;
        }

        // Form submission with loading state
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            if (!validateRegisterForm()) {
                e.preventDefault();
                return;
            }

            const registerBtn = document.getElementById('registerBtn');
            const registerText = document.getElementById('registerText');
            const loadingOverlay = document.getElementById('loadingOverlay');
            
            registerText.style.opacity = '0.7';
            loadingOverlay.style.display = 'flex';
            registerBtn.style.pointerEvents = 'none';
        });

        // Real-time validation
        document.querySelectorAll('.form-input').forEach(input => {
            input.addEventListener('blur', function() {
                if (this.value.trim()) {
                    this.classList.add('valid');
                    this.classList.remove('invalid');
                } else {
                    this.classList.add('invalid');
                    this.classList.remove('valid');
                }
            });
        });

        // Auto-focus first input
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('username').focus();
        });
    </script>
</body>
</html>
