<?php

$flag 
getenv("FLAG") ?: "CTL{FAKE_FLAG}";

$storedHash "0e450520220368636321766937191006";

$message "";

if (isset(
$_GET['show_source'])) {
    
highlight_file(__FILE__);
    exit;
}

if (
$_SERVER['REQUEST_METHOD'] === 'POST') {
    
$username $_POST['username'] ?? '';
    
$password $_POST['password'] ?? '';

    if (
$username !== "admin") {
        
$message renderError("๐Ÿฆ Unknown trainer account.");
    } elseif (
md5($password) == $storedHash) {
        
$message renderJournal($flag);
    } else {
        
$message renderError("๐Ÿ”ฅ Access denied. The training journal remains locked.");
    }
}

function 
renderError(string $text): string
{
    return 
'<div class="alert error">' htmlspecialchars($text) . '</div>';
}

function 
renderJournal(string $flag): string
{
    return 
'
        <div class="alert success">
            <h2>๐Ÿ“– Private Training Journal</h2>
            <p><strong>Day 1337</strong></p>
            <p>Simba finally jumped through the flaming hoop without hesitation.</p>
            <p>The audience went wild. More advanced exercises will begin next week.</p>
            <hr>
            <p>
                <strong>Secret Circus Note:</strong><br>
                <code>' 
htmlspecialchars($flag) . '</code>
            </p>
        </div>'
;
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>The Lion Tamer's Journal</title>

    <style>
        :root {
            --orange: #e67e22;
            --orange-dark: #b55310;
            --gold: #ffb347;
            --cream: #fff7e8;
            --brown: #4a2b12;
            --danger-bg: #fdecea;
            --danger-text: #922b21;
            --success-bg: #eafaf1;
            --success-text: #145a32;
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            min-height: 100vh;
            font-family: Arial, Helvetica, sans-serif;
            color: var(--brown);
            background:
                radial-gradient(circle at top left, rgba(255, 214, 128, 0.9), transparent 35%),
                linear-gradient(135deg, #ffb347, #ff8c00 45%, #7a3200);
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 24px;
        }

        .card {
            width: 560px;
            max-width: 100%;
            background: rgba(255, 255, 255, 0.96);
            border: 2px solid rgba(255, 255, 255, 0.5);
            border-radius: 24px;
            padding: 36px;
            box-shadow: 0 20px 60px rgba(60, 25, 0, 0.45);
        }

        .logo {
            text-align: center;
            font-size: 76px;
            line-height: 1;
            margin-bottom: 12px;
        }

        h1 {
            text-align: center;
            color: var(--orange-dark);
            margin: 0 0 8px;
            font-size: 30px;
        }

        .subtitle {
            text-align: center;
            color: #7b5b39;
            margin-bottom: 24px;
        }

        .notice {
            background: var(--cream);
            border-left: 6px solid var(--orange);
            border-radius: 14px;
            padding: 16px;
            margin-bottom: 22px;
            line-height: 1.4;
        }

        label {
            display: block;
            font-weight: bold;
            margin-top: 14px;
            margin-bottom: 6px;
        }

        input {
            width: 100%;
            padding: 14px;
            border: 2px solid #f5cba7;
            border-radius: 12px;
            font-size: 16px;
        }

        input:focus {
            outline: none;
            border-color: var(--orange);
            box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.18);
        }

        button {
            width: 100%;
            margin-top: 20px;
            padding: 15px;
            border: none;
            border-radius: 12px;
            background: linear-gradient(135deg, var(--orange), var(--orange-dark));
            color: white;
            font-size: 18px;
            font-weight: bold;
            cursor: pointer;
        }

        button:hover {
            filter: brightness(1.05);
        }

        .alert {
            margin-top: 22px;
            padding: 18px;
            border-radius: 14px;
            line-height: 1.45;
        }

        .success {
            background: var(--success-bg);
            color: var(--success-text);
        }

        .error {
            background: var(--danger-bg);
            color: var(--danger-text);
        }

        .source-link {
            display: block;
            margin-top: 22px;
            text-align: center;
            color: var(--orange-dark);
            font-size: 14px;
            text-decoration: none;
            font-weight: bold;
        }

        .source-link:hover {
            text-decoration: underline;
        }

        .footer {
            margin-top: 18px;
            text-align: center;
            color: #8a6f55;
            font-size: 12px;
        }

        code {
            display: inline-block;
            margin-top: 6px;
            padding: 8px 10px;
            background: rgba(255, 255, 255, 0.8);
            border-radius: 8px;
            font-weight: bold;
        }

        hr {
            border: none;
            border-top: 1px solid rgba(20, 90, 50, 0.25);
            margin: 16px 0;
        }
    </style>
</head>
<body>
    <main class="card">
        <div class="logo">๐Ÿฆ๐ŸŽช</div>

        <h1>The Lion Tamer's Journal</h1>

        <div class="subtitle">
            Circus Grand Savannah ยท Private Staff Area
        </div>

        <div class="notice">
            Only the head lion tamer may access the private training journal.<br>
            Authorized account: <strong>admin</strong>
        </div>

        <form method="POST" autocomplete="off">
            <label for="username">Trainer account</label>
            <input id="username" name="username" placeholder="admin" required>

            <label for="password">Secret passphrase</label>
            <input id="password" type="password" name="password" placeholder="Enter passphrase" required>

            <button type="submit">๐Ÿฆ Access Training Journal</button>
        </form>

        <?php echo $message?>

        <a class="source-link" href="?show_source=1">Show source</a>

        <div class="footer">
            Circus Grand Savannah ยท Internal Staff Portal
        </div>
    </main>
</body>
</html>