<?php
session_start();

$error = '';



if ($_SERVER['REQUEST_METHOD'] === 'POST' && array_key_exists("username", $_POST)) {
    $username = trim($_POST['username'] ?? '');
    $password = trim($_POST['password'] ?? '');

    if ($username === 'admin' && $password === 'Poikokar1!') {
        $_SESSION['authenticated'] = true;
        header('Location: edit.php');
        exit;
    } else {
        $error = 'Invalid username or password.';
        session_destroy();
    }
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Creator Login</title>
    <link rel="icon" href="data:,">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --bg: #0f1115;
            --panel: #161a22;
            --border: #2a2f3d;
            --accent: #ff4d6d;
            --text: #e8eaf0;
            --muted: #8a90a3;
        }
        body {
            background-color: var(--bg);
            color: var(--text);
            font-family: 'Inter', sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .login-box {
            background: var(--panel);
            border: 1px solid var(--border);
            border-radius: 16px;
            padding: 40px;
            width: 100%;
            max-width: 400px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.5);
        }
        .form-control {
            background: rgba(255, 255, 255, 0.05);
            border: 1px solid var(--border);
            color: var(--text);
            padding: 12px;
        }
        .form-control:focus {
            background: rgba(255, 255, 255, 0.08);
            border-color: var(--accent);
            color: var(--text);
            box-shadow: none;
        }
        .btn-primary {
            background-color: var(--accent);
            border: none;
            padding: 12px;
            font-weight: 600;
        }
        .btn-primary:hover {
            background-color: #ff3355;
        }
        .text-muted {
            color: var(--muted) !important;
        }
    </style>
</head>
<body>

<div class="container d-flex justify-content-center">
    <div class="login-box">
        <h3 class="text-center mb-4 fw-bold">Exclusive Access</h3>
        
        <?php if ($error): ?>
            <div class="alert alert-danger text-center p-2 mb-4" style="background: rgba(255,0,0,0.1); border: 1px solid rgba(255,0,0,0.3); color: #ff6b6b; font-size: 14px;">
                <?= htmlspecialchars($error) ?>
            </div>
        <?php endif; ?>
        <?php if (!empty($_SESSION['authenticated'])): ?>
            <div style="position: absolute; top: 20px; right: 20px; z-index: 100;">
                <a href="logout.php"
                   class="btn btn-sm"
                   style="border-radius: 10px; padding: 6px 16px; background-color: #ff4d6d; border: none; color: #e8eaf0; font-weight: 600;">
                    Logout
                </a>
            </div>
        <?php endif; ?>

        <form method="POST" action="">
            <div class="mb-3">
                <label class="form-label text-muted small">Username</label>
                <input type="text" name="username" class="form-control" required autocomplete="off">
            </div>
            <div class="mb-4">
                <label class="form-label text-muted small">Password</label>
                <input type="password" name="password" class="form-control" required>
            </div>
            <button type="submit" class="btn btn-primary w-100">Unlock Profile</button>
        </form>
    </div>
</div>

</body>
</html>
