<?php

require_once __DIR__ . '/env.php';
loadEnvFile(__DIR__ . '/.env');

$site_name = htmlspecialchars(envValue('SPLASH_SITE_NAME', 'Server Splashpage'), ENT_QUOTES, 'UTF-8');
$subtitle = htmlspecialchars(envValue('SPLASH_SUBTITLE', 'Server is reachable'), ENT_QUOTES, 'UTF-8');
$home_url = htmlspecialchars(envValue('SPLASH_HOME_URL', 'https://projectie.com'), ENT_QUOTES, 'UTF-8');
$home_label = htmlspecialchars(envValue('SPLASH_HOME_LABEL', 'projectie.com'), ENT_QUOTES, 'UTF-8');

?><!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?php echo $site_name; ?></title>
    <meta name="description" content="Internal server splash page">
    <style>
        :root {
            --bg: #101220;
            --card: #191d31;
            --text: #f7f8ff;
            --muted: rgba(247, 248, 255, 0.75);
            --line: rgba(247, 248, 255, 0.12);
            --accent: #8dd3ff;
        }

        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            min-height: 100vh;
            display: grid;
            place-items: center;
            background:
                radial-gradient(circle at 15% 20%, rgba(141, 211, 255, 0.2), transparent 40%),
                radial-gradient(circle at 85% 80%, rgba(151, 255, 196, 0.13), transparent 35%),
                var(--bg);
            color: var(--text);
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            padding: 24px;
        }

        .panel {
            width: min(860px, 100%);
            border: 1px solid var(--line);
            border-radius: 18px;
            background: linear-gradient(180deg, rgba(25, 29, 49, 0.95), rgba(25, 29, 49, 0.88));
            backdrop-filter: blur(4px);
            padding: 28px;
            box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
        }

        h1 {
            margin: 0;
            font-size: clamp(32px, 6vw, 54px);
            line-height: 1.08;
            letter-spacing: -0.02em;
        }

        .subtitle {
            margin-top: 10px;
            color: var(--muted);
            font-size: 18px;
        }

        .rows {
            margin-top: 24px;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 12px;
        }

        .item {
            border: 1px solid var(--line);
            border-radius: 12px;
            padding: 12px 14px;
        }

        .label {
            display: block;
            margin-bottom: 8px;
            color: var(--muted);
            font-size: 12px;
            letter-spacing: 0.06em;
            text-transform: uppercase;
        }

        .value {
            margin: 0;
            font-size: 14px;
            word-break: break-word;
        }

        .links {
            margin-top: 22px;
        }

        .links a {
            color: var(--accent);
            text-decoration: none;
            font-weight: 600;
            font-size: 14px;
        }

        .links a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
<main class="panel">
    <h1><?php echo $site_name; ?></h1>
    <div class="subtitle"><?php echo $subtitle; ?></div>

    <section class="rows">
        <article class="item">
            <span class="label">Host</span>
            <p class="value" id="host">-</p>
        </article>
        <article class="item">
            <span class="label">Path</span>
            <p class="value" id="path">-</p>
        </article>
        <article class="item">
            <span class="label">Current UTC</span>
            <p class="value" id="time">-</p>
        </article>
        <article class="item">
            <span class="label">Status</span>
            <p class="value">Public splash page - no private data exposed.</p>
        </article>
    </section>

    <div class="links">
        <a href="<?php echo $home_url; ?>" rel="noopener noreferrer"><?php echo $home_label; ?></a>
    </div>
</main>

<script>
(function () {
    var hostEl = document.getElementById('host');
    var pathEl = document.getElementById('path');
    var timeEl = document.getElementById('time');

    if (hostEl) {
        hostEl.textContent = window.location.host;
    }

    if (pathEl) {
        pathEl.textContent = window.location.pathname;
    }

    function renderTime() {
        if (!timeEl) {
            return;
        }

        var now = new Date();
        timeEl.textContent = now.toISOString().replace('T', ' ').replace('Z', ' UTC');
    }

    renderTime();
    setInterval(renderTime, 1000);
})();
</script>
</body>
</html>

