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

if(isset($_POST['mc_username'])) {
    $username = trim($_POST['mc_username']);
    if(strlen($username) >= 3 && strlen($username) <= 16 && preg_match('/^[a-zA-Z0-9_]+$/', $username)) {
        // Optional: Check if username exists on Mojang (uncomment if you want real check)
        // $data = @file_get_contents("https://api.mojang.com/users/profiles/minecraft/$username");
        // if($data === false) { $error = "Player not found!"; goto end; }

        $_SESSION['mc_username'] = $username;
        header("Location: index.php");
        exit;
    } else {
        $error = "Invalid username!";
    }
}
end:
?>
<!DOCTYPE html>
<html>
<head>
    <title>Login • Reckon Store</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body{background:#0a0a1a;color:#0f0;font-family:courier;display:flex;align-items:center;justify-content:center;height:100vh;margin:0}
        .box{background:#111;padding:40px;border:3px solid #0f0;border-radius:15px;width:400px;text-align:center;box-shadow:0 0 40px #0f03}
        input{width:100%;padding:15px;margin:10px 0;background:#000;border:2px solid #0f0;color:#0f0;font-size:18px}
        button{width:100%;padding:15px;background:#0f0;color:#000;font-weight:bold;border:none;cursor:pointer;font-size:18px}
        .error{color:#f00;margin:10px 0}
    </style>
</head>
<body>
<div class="box">
    <h1>LOGIN TO STORE</h1>
    <p>Enter your Minecraft username</p>
    <?php if(isset($error)) echo "<div class='error'>$error</div>"; ?>
    <form method="POST">
        <input type="text" name="mc_username" placeholder="Steve" required autofocus>
        <button type="submit">LOGIN</button>
    </form>
    <br>
    <a href="index.php" style="color:#0f0">← Back to Store</a>
</div>
</body>
</html>