
<?php
require_once __DIR__ . '/config.php';

$domains = [];

foreach ($TARGET_DOMAINS as $url) {
    $parts = parse_url($url);

    if (
        is_array($parts) &&
        ($parts['scheme'] ?? '') === 'https' &&
        !empty($parts['host']) &&
        !isset($parts['user']) &&
        !isset($parts['pass'])
    ) {
        $domains[] = $url;
    }
}

if (!$domains) {
    http_response_code(503);
    exit('接続先が設定されていません。');
}

$destination = $domains[random_int(0, count($domains) - 1)];
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>アクセス確認</title>

<style>
* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #f5f7fa;
    font-family: Arial, sans-serif;
    color: #202124;
}

.card {
    width: calc(100% - 32px);
    max-width: 420px;
    padding: 38px 28px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,.04);
}

.logo {
    font-size: 38px;
    color: #2563eb;
}

h2 {
    font-size: 22px;
    margin: 18px 0 12px;
}

.description {
    color: #777;
    font-size: 14px;
    line-height: 1.8;
}

.confirm {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 28px 0;
    padding: 17px;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
}

.confirm input {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

button {
    width: 100%;
    padding: 13px;
    background: #2563eb;
    color: white;
    border: 0;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
}

button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

#status {
    font-size: 13px;
    color: #666;
    min-height: 20px;
    margin-top: 18px;
}

.footer {
    margin-top: 25px;
    color: #aaa;
    font-size: 11px;
}
</style>
</head>

<body>

<div class="card">

    <div class="logo">◈</div>

    <h2>アクセス確認</h2>

    <div class="description">
        続行するには、確認を完了してください。
    </div>

    <label class="confirm">
        <input type="checkbox" id="confirm">
        <span>確認しました</span>
    </label>

    <button id="continue" disabled>
        続行する
    </button>

    <div id="status">
        確認をお待ちしています。
    </div>

    <div class="footer">
        Secure Access
    </div>

</div>

<script>
const checkbox = document.getElementById('confirm');
const button = document.getElementById('continue');
const status = document.getElementById('status');

checkbox.addEventListener('change', function() {
    button.disabled = !this.checked;

    status.textContent = this.checked
        ? '確認が完了しました。続行できます。'
        : '確認をお待ちしています。';
});

button.addEventListener('click', function() {
    if (!checkbox.checked) return;

    status.textContent = 'ページを移動しています...';

    window.location.href = <?= json_encode(
        $destination,
        JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT
    ) ?>;
});
</script>

</body>
</html>
