<?php
$fortunes = [
    '大吉' => '#e74c3c', // Red
    '中吉' => '#e67e22', // Orange
    '小吉' => '#f1c40f', // Yellow
    '吉' => '#27ae60',   // Green
    '半吉' => '#2ecc71', // Light Green
    '末吉' => '#3498db', // Blue
    '末小吉' => '#2980b9',// Dark Blue
    '凶' => '#9b59b6',   // Purple
    '小凶' => '#8e44ad', // Dark Purple
    '半凶' => '#34495e', // Dark Gray
    '末凶' => '#2c3e50', // Darker Gray
    '大凶' => '#000000'  // Black
];
$fortune_keys = array_keys($fortunes);

if (isset($_COOKIE['daily_fortune'])) {
    $result = $_COOKIE['daily_fortune'];
    $is_new = false;
} else {
    $result = $fortune_keys[array_rand($fortune_keys)];
    $expire = strtotime('tomorrow 00:00:00');
    setcookie('daily_fortune', $result, $expire);
    $is_new = true;
}

$color = isset($fortunes[$result]) ? $fortunes[$result] : '#333';
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>今日のおみくじ</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f5f5f5;
            font-family: 'Helvetica Neue', Arial, sans-serif;
            color: #333;
        }
        .container {
            text-align: center;
            background: white;
            padding: 40px;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0,0,0,0.1);
        }
        .title {
            font-size: 24px;
            margin-bottom: 20px;
            color: #555;
        }
        .fortune {
            font-size: 64px;
            font-weight: bold;
            margin: 20px 0;
            color: <?php echo $color; ?>;
        }
        .subtext {
            font-size: 14px;
            color: #888;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="title">あなたの今日の運勢は…</div>
        <div class="fortune"><?php echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8'); ?></div>
        <div class="subtext">
            <?php if ($is_new): ?>
                新しく引きました！今日一日、この結果です。
            <?php else: ?>
                （今日の運勢は既に決まっています）
            <?php endif; ?>
        </div>
    </div>
</body>
</html>
