<?php
require_once 'admin/config.php';
try {
    $db = new PDO('mysql:host=localhost;dbname=erniinrk_solo', 'erniinrk_solo', 'Kelentit123@');
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}
$bulanIndo = [
    'January' => 'Januari', 'February' => 'Februari', 'March' => 'Maret',
    'April' => 'April', 'May' => 'Mei', 'June' => 'Juni',
    'July' => 'Juli', 'August' => 'Agustus', 'September' => 'September',
    'October' => 'Oktober', 'November' => 'November', 'December' => 'Desember'
];
function calculateCountdown($last_draw_date, $result_time, $result_end_time = null) {
    if (!$result_time) return 0;
    $now = new DateTime();
    if (!$result_end_time) {
        $result_end_time = date('H:i:s', strtotime($result_time . ' +1 hour'));
    }
    $result_time_today = new DateTime($now->format('Y-m-d') . ' ' . $result_time);
    $result_end_time_today = new DateTime($now->format('Y-m-d') . ' ' . $result_end_time);
    if ($now > $result_time_today && $now < $result_end_time_today) {
        return 0;
    }
    if ($now > $result_end_time_today) {
        $result_time_today->modify('+1 day');
    }
    return max(0, $result_time_today->getTimestamp() - $now->getTimestamp());
}
function shouldShowCountdown($last_result, $result_time, $result_end_time = null) {
    $now = new DateTime();
    if (!$result_end_time) {
        $result_end_time = date('H:i:s', strtotime($result_time . ' +1 hour'));
    }
    $result_time_today = new DateTime($now->format('Y-m-d') . ' ' . $result_time);
    $result_end_time_today = new DateTime($now->format('Y-m-d') . ' ' . $result_end_time);
    if ($now > $result_end_time_today) return true;
    if (!$last_result) return true;
    $last_draw = new DateTime($last_result['draw_date'] . ' ' . $last_result['result_time']);
    return $last_draw < $result_time_today;
}
function formatDisplayDate($date, $bulanIndo) {
    if (!$date) return ['day' => '--', 'month' => '--', 'year' => '--', 'full' => '--'];
    $timestamp = strtotime($date);
    $dayName = ['Sunday'=>'Minggu','Monday'=>'Senin','Tuesday'=>'Selasa','Wednesday'=>'Rabu','Thursday'=>'Kamis','Friday'=>'Jumat','Saturday'=>'Sabtu'];
    return [
        'day' => date('d', $timestamp),
        'month' => $bulanIndo[date('F', $timestamp)] ?? date('F', $timestamp),
        'year' => date('Y', $timestamp),
        'full' => ($dayName[date('l', $timestamp)] ?? date('l', $timestamp)) . ', ' . date('d', $timestamp) . ' ' . ($bulanIndo[date('F', $timestamp)] ?? date('F', $timestamp)) . ' ' . date('Y', $timestamp)
    ];
}
$page = isset($_GET['page']) ? max(1, (int)$_GET['page']) : 1;
$per_page = 12;
$offset = ($page - 1) * $per_page;
try {
    $stmt = $db->query("DESCRIBE markets");
    $columns = $stmt->fetchAll(PDO::FETCH_COLUMN);
    if (in_array('status', $columns) && in_array('display_order', $columns)) {
        $market_query = "SELECT * FROM markets WHERE status = 1 ORDER BY display_order ASC, market_name ASC";
    } elseif (in_array('status', $columns)) {
        $market_query = "SELECT * FROM markets WHERE status = 1 ORDER BY market_name ASC";
    } else {
        $market_query = "SELECT * FROM markets ORDER BY market_name ASC";
    }
    $stmt = $db->prepare($market_query);
    $stmt->execute();
    $all_markets = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
    $stmt = $db->prepare("SELECT * FROM markets ORDER BY market_name ASC");
    $stmt->execute();
    $all_markets = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
foreach ($all_markets as &$market) {
    if (empty($market['display_name'])) $market['display_name'] = strtoupper($market['market_name']);
    if (empty($market['color_theme'])) $market['color_theme'] = 'color-1';
    if (empty($market['result_time'])) $market['result_time'] = '15:30:00';
}
unset($market);
$primary_market = $all_markets[0] ?? null;
$total_rows = 0;
$total_pages = 1;
$histories = [];
$latest = null;
if ($primary_market) {
    $stmt = $db->prepare("SELECT * FROM lottery_results WHERE market = ? ORDER BY draw_date DESC, created_at DESC LIMIT 1");
    $stmt->execute([$primary_market['market_name']]);
    $latest = $stmt->fetch(PDO::FETCH_ASSOC);
    $countStmt = $db->prepare("SELECT COUNT(*) FROM lottery_results WHERE market = ?");
    $countStmt->execute([$primary_market['market_name']]);
    $total_rows = (int)$countStmt->fetchColumn();
    $total_pages = max(1, (int)ceil($total_rows / $per_page));
    if ($page > $total_pages) {
        $page = $total_pages;
        $offset = ($page - 1) * $per_page;
    }
    $stmt = $db->prepare("SELECT * FROM lottery_results WHERE market = ? ORDER BY draw_date DESC LIMIT ? OFFSET ?");
    $stmt->bindValue(1, $primary_market['market_name'], PDO::PARAM_STR);
    $stmt->bindValue(2, $per_page, PDO::PARAM_INT);
    $stmt->bindValue(3, $offset, PDO::PARAM_INT);
    $stmt->execute();
    $histories = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
$result_time = $primary_market['result_time'] ?? '15:30:00';
$result_end_time = $primary_market['result_end_time'] ?? date('H:i:s', strtotime($result_time . ' +1 hour'));
$show_countdown = shouldShowCountdown($latest, $result_time, $result_end_time);
$countdown_seconds = calculateCountdown($latest['draw_date'] ?? null, $result_time, $result_end_time);
$now = new DateTime();
$result_time_today = new DateTime($now->format('Y-m-d') . ' ' . $result_time);
$result_end_time_today = new DateTime($now->format('Y-m-d') . ' ' . $result_end_time);
$is_calculating = ($now > $result_time_today && $now < $result_end_time_today);
$display_date = formatDisplayDate($latest['draw_date'] ?? null, $bulanIndo);
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>SOLO POOLS â€¢ Hasil Harian</title>
    <link href="https://pastijepe.online/assets/img/iconsolopools.avif" rel="icon"/>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Cinzel:wght@500;600;700;800&family=Philosopher:wght@400;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --sogan-dark: #2C1810;
            --sogan: #3E2723;
            --sogan-mid: #5C3A21;
            --sogan-light: #8D6E63;
            --emas: #D4AF37;
            --emas-tua: #B8860B;
            --gading: #f5e6c8;
            --cream: #faf6f0;
        }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Philosopher', 'Segoe UI', system-ui, sans-serif;
            background:
                linear-gradient(180deg, rgba(44,24,16,0.85) 0%, rgba(62,39,35,0.75) 40%),
                url('https://pastijepe.online/assets/img/solo.avif') center/cover no-repeat;
            color: #333;
            line-height: 1.5;
        }
        .batik-sogan {
            background-color: var(--sogan);
            background-image:
                radial-gradient(circle at 25% 25%, rgba(212,175,55,0.15) 0%, transparent 40%),
                radial-gradient(circle at 75% 75%, rgba(212,175,55,0.12) 0%, transparent 40%),
                radial-gradient(circle at 75% 25%, rgba(141,110,99,0.25) 0%, transparent 35%),
                radial-gradient(circle at 25% 75%, rgba(141,110,99,0.25) 0%, transparent 35%),
                repeating-linear-gradient(45deg, transparent, transparent 12px, rgba(212,175,55,0.08) 12px, rgba(212,175,55,0.08) 14px),
                repeating-linear-gradient(-45deg, transparent, transparent 18px, rgba(92,58,33,0.35) 18px, rgba(92,58,33,0.35) 20px);
            background-size: 80px 80px, 80px 80px, 80px 80px, 80px 80px, 40px 40px, 50px 50px;
            animation: batikMove 28s linear infinite;
        }
        @keyframes batikMove {
            0% { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
            100% { background-position: 80px 80px, -80px -80px, 80px -80px, -80px 80px, 40px 40px, -50px 50px; }
        }
        .shimmer-gold { position: relative; overflow: hidden; }
        .shimmer-gold::after {
            content: '';
            position: absolute;
            top: 0; left: -100%;
            width: 60%; height: 100%;
            background: linear-gradient(90deg, transparent, rgba(212,175,55,0.25), transparent);
            animation: shimmer 4.5s ease-in-out infinite;
        }
        @keyframes shimmer {
            0% { left: -100%; }
            50% { left: 120%; }
            100% { left: 120%; }
        }

        .navbar {
            background: linear-gradient(90deg, #2C1810 0%, #3E2723 50%, #2C1810 100%);
            padding: 0 20px; height: 80px;
            display: flex; align-items: center; justify-content: space-between;
            position: sticky; top: 0; z-index: 1000;
            box-shadow: 0 4px 24px rgba(0,0,0,0.45);
            border-bottom: 3px solid var(--emas);
            overflow: visible;
        }
        .navbar.batik-sogan { background-blend-mode: overlay; }
        .navbar-logo {
            display: flex;
            align-items: center;
            gap: 10px;
            text-decoration: none;
            position: relative;
            z-index: 2;
            background: linear-gradient(ellipse at center, rgba(245,230,200,0.22) 0%, transparent 72%);
            padding: 6px 14px;
            border-radius: 8px;
        }
        .navbar-logo img {
            height: 100%;
            width: 100%;
            max-width: 260px;
            object-fit: contain;
            transition: filter 0.3s ease, transform 0.3s ease;
        }
        .navbar-logo:hover img {
            transform: scale(1.05);
        }
        .navbar-menu {
            display: flex;
            gap: 8px;
            align-items: center;
            position: relative;
            z-index: 2;
        }
        .navbar-menu a {
            font-family: 'Philosopher', sans-serif;
            color: var(--gading);
            text-decoration: none;
            padding: 8px 16px;
            border-radius: 6px;
            font-size: 0.88rem;
            font-weight: 700;
            background: rgba(212,175,55,0.12);
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        .navbar-menu a:hover {
            background: var(--emas);
            color: var(--sogan-dark);
            border-color: var(--emas-tua);
            transform: translateY(-1px);
        }
        .navbar-menu .lang {
            background: var(--emas);
            color: var(--sogan-dark);
            border-color: var(--emas-tua);
        }

        .hamburger {
            display: none;
            flex-direction: column;
            justify-content: center;
            gap: 5px;
            width: 44px;
            height: 44px;
            background: rgba(212,175,55,0.15);
            border: 1px solid rgba(212,175,55,0.45);
            border-radius: 8px;
            cursor: pointer;
            padding: 10px;
            z-index: 1003;
            transition: all 0.3s ease;
        }
        .hamburger:hover {
            background: var(--emas);
        }
        .hamburger span {
            display: block;
            width: 100%;
            height: 2.5px;
            background: var(--emas);
            border-radius: 2px;
            transition: all 0.3s ease;
        }
        .hamburger:hover span {
            background: var(--sogan-dark);
        }
        .hamburger.active span:nth-child(1) {
            transform: translateY(7.5px) rotate(45deg);
        }
        .hamburger.active span:nth-child(2) {
            opacity: 0;
        }
        .hamburger.active span:nth-child(3) {
            transform: translateY(-7.5px) rotate(-45deg);
        }

        .sidebar-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.55);
            z-index: 1001;
            opacity: 0;
            visibility: hidden;
            transition: all 0.3s ease;
        }
        .sidebar-overlay.active {
            opacity: 1;
            visibility: visible;
        }

        .mobile-sidebar {
            position: fixed;
            top: 0;
            right: -290px;
            width: 280px;
            height: 100%;
            background: linear-gradient(180deg, #2C1810 0%, #3E2723 100%);
            z-index: 1002;
            box-shadow: -10px 0 35px rgba(0,0,0,0.45);
            transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
            display: flex;
            flex-direction: column;
            border-left: 3px solid var(--emas);
            overflow-y: auto;
        }
        .mobile-sidebar.active {
            right: 0;
        }
        .sidebar-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 20px 22px;
            border-bottom: 1px solid rgba(212,175,55,0.3);
            background: rgba(0,0,0,0.15);
        }
        .sidebar-title {
            font-family: 'Cinzel', serif;
            color: var(--emas);
            font-size: 1.15rem;
            font-weight: 700;
            letter-spacing: 2px;
        }
        .sidebar-close {
            background: rgba(212,175,55,0.15);
            border: 1px solid rgba(212,175,55,0.4);
            color: var(--emas);
            width: 38px;
            height: 38px;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            font-size: 1.1rem;
            transition: all 0.25s ease;
        }
        .sidebar-close:hover {
            background: var(--emas);
            color: var(--sogan-dark);
        }
        .sidebar-menu {
            display: flex;
            flex-direction: column;
            padding: 20px 16px;
            gap: 10px;
        }
        .sidebar-menu a {
            display: flex;
            align-items: center;
            gap: 14px;
            padding: 14px 18px;
            color: var(--gading);
            text-decoration: none;
            font-family: 'Philosopher', sans-serif;
            font-size: 1rem;
            font-weight: 700;
            border-radius: 10px;
            background: rgba(212,175,55,0.08);
            border: 1px solid transparent;
            transition: all 0.25s ease;
        }
        .sidebar-menu a i {
            width: 22px;
            text-align: center;
            color: var(--emas);
            font-size: 1.05rem;
        }
        .sidebar-menu a:hover {
            background: var(--emas);
            color: var(--sogan-dark);
            border-color: var(--emas-tua);
            transform: translateX(-4px);
        }
        .sidebar-menu a:hover i {
            color: var(--sogan-dark);
        }

        .hero {
            position: relative;
            height: 300px;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
        }
        .hero-content {
            text-align: center;
            position: relative;
            z-index: 2;
            padding: 20px;
        }
        .hero h1 {
            font-family: 'Cinzel', serif;
            color: var(--emas);
            font-size: 2.3rem;
            font-weight: 800;
            text-shadow: 0 3px 18px rgba(0,0,0,0.7);
            letter-spacing: 3px;
            margin-bottom: 8px;
        }
        .hero h2 {
            font-family: 'Philosopher', sans-serif;
            color: var(--gading);
            font-size: 1.45rem;
            font-weight: 700;
            text-shadow: 0 2px 12px rgba(0,0,0,0.6);
            letter-spacing: 1px;
        }

        .main-result {
            max-width: 780px;
            margin: -45px auto 30px;
            position: relative;
            z-index: 10;
            background: #fff;
            border-radius: 14px;
            overflow: hidden;
            box-shadow: 0 18px 45px rgba(44,24,16,0.3);
            border: 1px solid #e8d5b7;
        }
        .result-header {
            background: linear-gradient(90deg, #3E2723, #5C3A21, #3E2723);
            color: #fff;
            padding: 16px 24px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 10px;
            border-bottom: 3px solid var(--emas);
            position: relative;
            overflow: hidden;
        }
        .result-header.batik-sogan { background-blend-mode: soft-light; }
        .result-header h3 {
            font-family: 'Cinzel', serif;
            font-size: 1.35rem;
            font-weight: 700;
            letter-spacing: 1.5px;
            position: relative;
            z-index: 2;
        }
        .result-header .date {
            font-family: 'Philosopher', sans-serif;
            font-size: 0.95rem;
            color: var(--gading);
            position: relative;
            z-index: 2;
        }
        .result-balls-main {
            display: flex;
            justify-content: center;
            gap: 16px;
            padding: 30px 20px;
            background: linear-gradient(180deg, #2C1810 0%, #3E2723 100%);
        }
        .ball {
            width: 74px;
            height: 74px;
            border-radius: 50%;
            background: radial-gradient(circle at 30% 25%, #fff 0%, #D4AF37 45%, #B8860B 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Cinzel', serif;
            font-size: 2.25rem;
            font-weight: 800;
            color: #1a1a1a;
            box-shadow: 0 8px 28px rgba(212,175,55,0.5), inset -5px -5px 16px rgba(0,0,0,0.28);
            position: relative;
            transition: transform 0.3s ease;
        }
        .ball::after {
            content: '';
            position: absolute;
            top: 12%;
            left: 22%;
            width: 28%;
            height: 18%;
            background: radial-gradient(ellipse, rgba(255,255,255,0.75), transparent);
            border-radius: 50%;
        }
        .ball.empty {
            background: radial-gradient(circle at 30% 25%, #6D4C41, #3E2723);
            color: #a1887f;
            box-shadow: none;
        }
        .ball.calculating {
            animation: spinBall 0.55s ease-in-out infinite alternate;
        }
        @keyframes spinBall {
            from { transform: scale(1) rotate(-5deg); }
            to { transform: scale(1.07) rotate(5deg); }
        }
        .sub-prizes {
            display: grid;
            grid-template-columns: 1fr 1fr;
            background: var(--cream);
        }
        .sub-prize {
            padding: 18px 16px;
            text-align: center;
            border: 1px solid #e8d5b7;
        }
        .sub-prize h4 {
            font-family: 'Cinzel', serif;
            font-size: 0.95rem;
            color: var(--sogan-mid);
            margin-bottom: 12px;
            font-weight: 700;
            letter-spacing: 1px;
            text-transform: uppercase;
        }
        .sub-prize .balls {
            display: flex;
            justify-content: center;
            gap: 8px;
        }
        .sub-prize .ball {
            width: 48px;
            height: 48px;
            font-size: 1.4rem;
        }

        .countdown-box {
            max-width: 780px;
            margin: 0 auto 30px;
            background: linear-gradient(90deg, #2C1810, #3E2723);
            border-radius: 12px;
            padding: 18px 24px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 16px;
            box-shadow: 0 8px 28px rgba(0,0,0,0.25);
            color: #fff;
            border: 2px solid var(--emas);
            position: relative;
            overflow: hidden;
        }
        .countdown-info h4 {
            font-family: 'Cinzel', serif;
            font-size: 1.05rem;
            color: var(--emas);
            margin-bottom: 4px;
            letter-spacing: 0.5px;
        }
        .countdown-info p {
            font-size: 0.88rem;
            color: var(--gading);
            opacity: 0.95;
        }
        .countdown-timer {
            display: flex;
            gap: 7px;
            font-family: 'Cinzel', serif;
        }
        .countdown-timer span {
            background: linear-gradient(180deg, #D4AF37, #B8860B);
            color: var(--sogan-dark);
            font-size: 1.65rem;
            font-weight: 800;
            padding: 7px 11px;
            border-radius: 8px;
            min-width: 44px;
            text-align: center;
            box-shadow: 0 4px 12px rgba(212,175,55,0.4);
        }

        .history-section {
            max-width: 1100px;
            margin: 0 auto 40px;
            padding: 0 16px;
        }
        .history-title {
            text-align: center;
            background: linear-gradient(90deg, #2C1810, #3E2723, #2C1810);
            color: var(--emas);
            padding: 16px;
            border-radius: 12px 12px 0 0;
            font-family: 'Cinzel', serif;
            font-size: 1.2rem;
            font-weight: 700;
            letter-spacing: 2px;
            border-bottom: 3px solid var(--emas);
            position: relative;
            overflow: hidden;
        }
        .history-title.batik-sogan { background-blend-mode: soft-light; }
        .history-info {
            text-align: center;
            background: #fff;
            padding: 11px;
            font-size: 0.88rem;
            color: var(--sogan-mid);
            border-bottom: 1px solid #e8d5b7;
            font-family: 'Philosopher', sans-serif;
        }
        .history-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 16px;
            background: #fff;
            padding: 20px;
            box-shadow: 0 8px 28px rgba(44,24,16,0.12);
        }
        .history-card {
            border: 1px solid #e8d5b7;
            border-radius: 12px;
            overflow: hidden;
            transition: transform 0.25s ease, box-shadow 0.25s ease;
        }
        .history-card:hover {
            transform: translateY(-3px);
            box-shadow: 0 10px 25px rgba(92,58,33,0.18);
        }
        .history-card-header {
            background: linear-gradient(90deg, #3E2723, #5C3A21);
            color: var(--emas);
            padding: 13px 16px;
            text-align: center;
        }
        .history-card-header h5 {
            font-family: 'Cinzel', serif;
            font-size: 0.95rem;
            font-weight: 700;
            letter-spacing: 0.5px;
        }
        .history-card-body {
            padding: 16px;
            background: var(--cream);
        }
        .history-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 9px 0;
            border-bottom: 1px solid #e8d5b7;
        }
        .history-row:last-child { border-bottom: none; }
        .history-row .label {
            font-family: 'Philosopher', sans-serif;
            font-size: 0.88rem;
            font-weight: 700;
            color: var(--sogan-mid);
        }
        .history-row .balls {
            display: flex;
            gap: 5px;
        }
        .history-row .ball {
            width: 34px;
            height: 34px;
            font-size: 1rem;
        }

        .pagination-wrap {
            background: #fff;
            padding: 16px 20px 22px;
            border-radius: 0 0 12px 12px;
            box-shadow: 0 8px 28px rgba(44,24,16,0.1);
        }
        .pagination {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 6px;
            flex-wrap: wrap;
            list-style: none;
            margin: 0;
            padding: 0;
        }
        .pagination a, .pagination span {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            min-width: 38px;
            height: 38px;
            padding: 0 12px;
            border-radius: 8px;
            font-family: 'Cinzel', serif;
            font-size: 0.9rem;
            font-weight: 600;
            text-decoration: none;
            transition: all 0.25s;
        }
        .pagination a {
            background: #f5e6c8;
            color: var(--sogan);
        }
        .pagination a:hover {
            background: var(--emas);
            color: var(--sogan-dark);
        }
        .pagination .active span {
            background: linear-gradient(90deg, #3E2723, #5C3A21);
            color: var(--emas);
        }
        .pagination .disabled span {
            background: #f0e6d8;
            color: #a1887f;
            cursor: not-allowed;
        }
        .pagination .dots span {
            background: transparent;
            color: var(--sogan-light);
        }

        .partners-section {
            max-width: 1100px;
            margin: 0 auto 40px;
            padding: 0 16px;
        }
        .partners-inner {
            background: #fff;
            border-radius: 14px;
            overflow: hidden;
            box-shadow: 0 12px 35px rgba(44,24,16,0.18);
            border: 1px solid #e8d5b7;
        }
        .partners-title {
            text-align: center;
            background: linear-gradient(90deg, #2C1810, #3E2723, #2C1810);
            padding: 18px 16px;
            border-bottom: 3px solid var(--emas);
            position: relative;
            overflow: hidden;
        }
        .partners-title.batik-sogan { background-blend-mode: soft-light; }
        .partners-title .gold-text {
            font-family: 'Cinzel', serif;
            font-size: 1.2rem;
            font-weight: 700;
            letter-spacing: 2px;
            color: var(--emas);
            display: inline-flex;
            align-items: center;
            gap: 12px;
            position: relative;
            z-index: 2;
        }
        .partners-title .gold-text i {
            font-size: 1rem;
            opacity: 0.9;
        }
        .partners-grid {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 16px;
            padding: 28px 24px;
            background: var(--cream);
        }
        .partner-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            text-decoration: none;
            background: #fff;
            border: 1px solid #e8d5b7;
            border-radius: 12px;
            padding: 20px 14px 16px;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        .partner-item:hover {
            transform: translateY(-5px);
            box-shadow: 0 12px 28px rgba(92,58,33,0.2);
            border-color: var(--emas);
        }
        .partner-item:hover .partner-badge {
            background: var(--emas);
            color: var(--sogan-dark);
        }
        .partner-logo {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background: linear-gradient(145deg, #fff, #f5e6c8);
            border: 2px solid var(--emas);
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            margin-bottom: 12px;
            box-shadow: 0 4px 14px rgba(212,175,55,0.25);
        }
        .partner-logo img {
            width: 70%;
            height: 70%;
            object-fit: contain;
        }
        .partner-name {
            font-family: 'Cinzel', serif;
            font-size: 0.85rem;
            font-weight: 700;
            color: var(--sogan);
            letter-spacing: 0.5px;
            text-align: center;
            margin-bottom: 8px;
        }
        .partner-badge {
            font-family: 'Philosopher', sans-serif;
            font-size: 0.72rem;
            font-weight: 700;
            background: linear-gradient(90deg, #3E2723, #5C3A21);
            color: var(--emas);
            padding: 3px 10px;
            border-radius: 20px;
            letter-spacing: 0.3px;
            transition: all 0.3s ease;
        }

        .about-box {
            max-width: 780px;
            margin: 0 auto 40px;
            background: linear-gradient(90deg, #2C1810, #3E2723);
            border-radius: 12px;
            padding: 28px 28px 24px;
            box-shadow: 0 8px 28px rgba(0,0,0,0.25);
            color: #fff;
            border: 2px solid var(--emas);
            position: relative;
            overflow: hidden;
        }
        .about-box h2 {
            font-family: 'Cinzel', serif;
            color: var(--emas);
            font-size: 1.35rem;
            margin-bottom: 12px;
            letter-spacing: 1px;
        }
        .about-box h3 {
            font-family: 'Cinzel', serif;
            color: var(--emas);
            font-size: 1.05rem;
            margin: 18px 0 8px;
            letter-spacing: 0.5px;
        }
        .about-box p {
            font-family: 'Philosopher', sans-serif;
            color: var(--gading);
            font-size: 0.92rem;
            line-height: 1.7;
            margin-bottom: 8px;
        }
        .about-box ul {
            margin: 8px 0 8px 20px;
            color: var(--gading);
            font-family: 'Philosopher', sans-serif;
            font-size: 0.92rem;
            line-height: 1.8;
        }
        .about-box ul li { margin-bottom: 4px; }

        footer {
            background: var(--sogan-dark);
            color: rgba(245,230,200,0.75);
            text-align: center;
            padding: 26px 16px;
            font-size: 0.88rem;
            border-top: 3px solid var(--emas);
            font-family: 'Philosopher', sans-serif;
        }
        footer p { margin: 5px 0; }

        @media (max-width: 900px) {
            .partners-grid { grid-template-columns: repeat(3, 1fr); }
        }

        @media (max-width: 768px) {
            .navbar {
                height: 68px;
                padding: 0 14px;
            }
            .navbar-logo {
                padding: 4px 8px;
            }
            .navbar-logo img {
                height: 100%;
                width: 100%;
            }

            .navbar-menu {
                display: none !important;
            }
            .hamburger {
                display: flex;
            }

            .hero { height: 240px; }
            .hero h1 { font-size: 1.55rem; letter-spacing: 1.5px; }
            .hero h2 { font-size: 1.1rem; }
            .main-result { margin: -35px 12px 24px; }
            .ball { width: 58px; height: 58px; font-size: 1.7rem; }
            .sub-prizes { grid-template-columns: 1fr; }
            .countdown-box {
                margin: 0 12px 24px;
                flex-direction: column;
                text-align: center;
            }
            .countdown-timer span {
                font-size: 1.35rem;
                min-width: 38px;
            }
            .history-row .ball {
                width: 30px;
                height: 30px;
                font-size: 0.9rem;
            }
            .partners-grid {
                grid-template-columns: repeat(2, 1fr);
                gap: 12px;
                padding: 20px 14px;
            }
            .partner-logo { width: 70px; height: 70px; }
            .about-box {
                margin: 0 12px 30px;
                padding: 22px 18px;
            }
        }

        @media (max-width: 480px) {
            .ball { width: 50px; height: 50px; font-size: 1.5rem; }
            .result-balls-main { gap: 10px; padding: 22px 12px; }
            .partners-grid { grid-template-columns: 1fr 1fr; }
            .partner-name { font-size: 0.78rem; }
            .partners-title .gold-text {
                font-size: 1rem;
                gap: 8px;
                letter-spacing: 1px;
            }
            .mobile-sidebar {
                width: 260px;
                right: -270px;
            }
        }
    </style>
</head>
<body>

    <nav class="navbar batik-sogan shimmer-gold">
        <a href="index.php" class="navbar-logo">
            <img src="https://pastijepe.online/assets/img/logosolopools.avif" alt="SOLO POOLS">
        </a>

        <div class="navbar-menu">
            <a href="index.php" class="lang"><i class="fas fa-home"></i> <span>BERANDA</span></a>
            <a href="live.php" class="lang"><i class="fas fa-broadcast-tower"></i> <span>UNDIAN LANGSUNG</span></a>
            <a href="/history" class="lang"><i class="fas fa-history"></i> <span>RIWAYAT</span></a>
        </div>

        <button class="hamburger" id="hamburgerBtn" aria-label="Buka Menu">
            <span></span>
            <span></span>
            <span></span>
        </button>
    </nav>

    <div class="sidebar-overlay" id="sidebarOverlay"></div>

    <aside class="mobile-sidebar" id="mobileSidebar">
        <div class="sidebar-header">
            <span class="sidebar-title">MENU</span>
            <button class="sidebar-close" id="sidebarClose" aria-label="Tutup Menu">
                <i class="fas fa-times"></i>
            </button>
        </div>
        <nav class="sidebar-menu">
            <a href="index.php"><i class="fas fa-home"></i> BERANDA</a>
            <a href="live.php"><i class="fas fa-broadcast-tower"></i> UNDIAN LANGSUNG</a>
            <a href="/history"><i class="fas fa-history"></i> RIWAYAT</a>
        </nav>
    </aside>

    <section class="hero">
        <div class="hero-content">
            <h1>Selamat Datang di SOLOPOOLS</h1>
            <h2>
                SOLOPOOLS merupakan pasaran lottery yang menghadirkan pengalaman bermain
                dengan sistem modern
            </h2>
        </div>
    </section>

    <div class="main-result">
        <div class="result-header batik-sogan shimmer-gold">
            <h3>1st Prize POOL</h3>
            <div class="date"><?= $display_date['full'] ?></div>
        </div>
        <div class="result-balls-main" id="mainBalls" data-calculating="<?= $is_calculating ? '1' : '0' ?>">
            <?php
            $digits = [];
            if ($latest && !empty($latest['first_prize']) && !$is_calculating) {
                $digits = str_split($latest['first_prize']);
            }
            for ($i = 0; $i < 4; $i++):
                $digit = $digits[$i] ?? '?';
                $extraClass = $is_calculating ? 'calculating' : (empty($digits) ? 'empty' : '');
            ?>
                <div class="ball <?= $extraClass ?>" data-index="<?= $i ?>">
                    <?= htmlspecialchars($digit) ?>
                </div>
            <?php endfor; ?>
        </div>
        <div class="sub-prizes">
            <div class="sub-prize">
                <h4>2nd Prize</h4>
                <div class="balls" id="secondBalls" data-calculating="<?= $is_calculating ? '1' : '0' ?>">
                    <?php
                    $secondDigits = [];
                    if ($latest && !empty($latest['second_prize']) && !$is_calculating) {
                        $secondDigits = str_split($latest['second_prize']);
                    }
                    for ($i = 0; $i < 4; $i++):
                        $digit = $secondDigits[$i] ?? '?';
                        $extraClass = $is_calculating ? 'calculating' : (empty($secondDigits) ? 'empty' : '');
                    ?>
                        <div class="ball <?= $extraClass ?>" data-index="<?= $i ?>">
                            <?= htmlspecialchars($digit) ?>
                        </div>
                    <?php endfor; ?>
                </div>
            </div>
            <div class="sub-prize">
                <h4>3rd Prize</h4>
                <div class="balls" id="thirdBalls" data-calculating="<?= $is_calculating ? '1' : '0' ?>">
                    <?php
                    $thirdDigits = [];
                    if ($latest && !empty($latest['third_prize']) && !$is_calculating) {
                        $thirdDigits = str_split($latest['third_prize']);
                    }
                    for ($i = 0; $i < 4; $i++):
                        $digit = $thirdDigits[$i] ?? '?';
                        $extraClass = $is_calculating ? 'calculating' : (empty($thirdDigits) ? 'empty' : '');
                    ?>
                        <div class="ball <?= $extraClass ?>" data-index="<?= $i ?>">
                            <?= htmlspecialchars($digit) ?>
                        </div>
                    <?php endfor; ?>
                </div>
            </div>
        </div>
    </div>

    <div class="countdown-box shimmer-gold">
        <div class="countdown-info">
            <h4><i class="fas fa-clock"></i> Hitung Mundur Undian Langsung</h4>
            <p>
                <?php if ($is_calculating): ?>
                    Sedang proses pengundian...
                <?php elseif ($show_countdown && $countdown_seconds > 0): ?>
                    Undian akan dimulai pada waktu yang ditentukan
                <?php else: ?>
                    Menunggu hasil berikutnya
                <?php endif; ?>
            </p>
        </div>
        <div class="countdown-timer" id="countdown" data-seconds="<?= $is_calculating ? 0 : $countdown_seconds ?>">
            <span class="h">00</span>
            <span class="m">00</span>
            <span class="s">00</span>
        </div>
    </div>

    <section class="partners-section">
        <div class="partners-inner">
            <div class="partners-title batik-sogan shimmer-gold">
                <span class="gold-text">
                    <i class="fas fa-handshake"></i>
                    OFFICIAL PARTNERS
                    <i class="fas fa-handshake"></i>
                </span>
            </div>
            <div class="partners-grid">
                <a href="https://jagal.ink/ernita4d" target="_blank" rel="noopener noreferrer" class="partner-item">
                    <div class="partner-logo">
                        <img src="https://i.ibb.co/wFS6Zbhr/ernita4d.webp" alt="ERNITA4D">
                    </div>
                    <div class="partner-name">ERNITA4D</div>
                    <span class="partner-badge">â˜… Trusted</span>
                </a>
                <a href="https://jagal.ink/sumpah-jitu" target="_blank" rel="noopener noreferrer" class="partner-item">
                    <div class="partner-logo">
                        <img src="https://i.ibb.co/b5BcTCxk/logo-1.png" alt="SUMPAHJITU">
                    </div>
                    <div class="partner-name">SUMPAHJITU</div>
                    <span class="partner-badge">â˜… Trusted</span>
                </a>
                <a href="https://jagal.ink/cici-jitu" target="_blank" rel="noopener noreferrer" class="partner-item">
                    <div class="partner-logo">
                        <img src="https://i.ibb.co/MDyZMnPs/cicijitu.png" alt="CICIJITU">
                    </div>
                    <div class="partner-name">CICIJITU</div>
                    <span class="partner-badge">â˜… Trusted</span>
                </a>
                <a href="https://jagal.ink/pencari-4d" target="_blank" rel="noopener noreferrer" class="partner-item">
                    <div class="partner-logo">
                        <img src="https://i.ibb.co/C3skMnpR/logopencari4d.png" alt="PENCARI4D">
                    </div>
                    <div class="partner-name">PENCARI4D</div>
                    <span class="partner-badge">â˜… Trusted</span>
                </a>
                <a href="https://jagal.ink/penulis-4d" target="_blank" rel="noopener noreferrer" class="partner-item">
                    <div class="partner-logo">
                        <img src="https://i.ibb.co/XfJyqPgD/penulis4d.png" alt="PENULIS4D">
                    </div>
                    <div class="partner-name">PENULIS4D</div>
                    <span class="partner-badge">â˜… Trusted</span>
                </a>
            </div>
        </div>
    </section>

    <div class="about-box shimmer-gold">
        <h3>Mengapa Memilih SOLOPOOLS?</h3>
        <ul>
            <li>Sistem lottery yang cepat dan responsif.</li>
            <li>Result tersedia secara tepat waktu.</li>
            <li>Tampilan website modern dan mudah digunakan.</li>
            <li>Akses stabil di desktop maupun perangkat mobile.</li>
            <li>Informasi pasaran yang selalu diperbarui.</li>
            <li>Didukung layanan pelanggan yang siap membantu.</li>
        </ul>
        <h3>Komitmen SOLOPOOLS</h3>
        <p>
            SOLOPOOLS terus berinovasi untuk menghadirkan pengalaman terbaik bagi
            seluruh pengguna. Dengan mengutamakan kualitas sistem, kecepatan akses,
            serta kenyamanan dalam setiap layanan, kami berupaya menjadi pilihan
            utama bagi para pecinta lottery.
        </p>
        <h3>Visi</h3>
        <p>
            Menjadi pasaran lottery yang terpercaya, inovatif, dan memberikan
            pengalaman terbaik melalui sistem yang aman, cepat, serta berkualitas.
        </p>
        <h3>Misi</h3>
        <ul>
            <li>Menyediakan layanan lottery dengan kualitas terbaik.</li>
            <li>Menghadirkan sistem yang stabil dan mudah diakses.</li>
            <li>Menyajikan informasi result secara cepat dan akurat.</li>
            <li>Terus meningkatkan kualitas pelayanan kepada seluruh pengguna.</li>
        </ul>
    </div>

    <footer>
        <p>Must be 18+ â€¢ Play responsibly</p>
        <p>Â© 2026 SOLO POOLS. All Rights Reserved.</p>
    </footer>

    <script>
        const hamburgerBtn = document.getElementById('hamburgerBtn');
        const mobileSidebar = document.getElementById('mobileSidebar');
        const sidebarOverlay = document.getElementById('sidebarOverlay');
        const sidebarClose = document.getElementById('sidebarClose');

        function openSidebar() {
            mobileSidebar.classList.add('active');
            sidebarOverlay.classList.add('active');
            hamburgerBtn.classList.add('active');
            document.body.style.overflow = 'hidden';
        }

        function closeSidebar() {
            mobileSidebar.classList.remove('active');
            sidebarOverlay.classList.remove('active');
            hamburgerBtn.classList.remove('active');
            document.body.style.overflow = '';
        }

        hamburgerBtn.addEventListener('click', () => {
            if (mobileSidebar.classList.contains('active')) {
                closeSidebar();
            } else {
                openSidebar();
            }
        });

        sidebarClose.addEventListener('click', closeSidebar);
        sidebarOverlay.addEventListener('click', closeSidebar);

        document.querySelectorAll('.sidebar-menu a').forEach(link => {
            link.addEventListener('click', closeSidebar);
        });

        function startCountdown() {
            const el = document.getElementById('countdown');
            if (!el) return;
            let timeLeft = parseInt(el.getAttribute('data-seconds')) || 0;
            const hEl = el.querySelector('.h');
            const mEl = el.querySelector('.m');
            const sEl = el.querySelector('.s');
            if (timeLeft <= 0) {
                hEl.textContent = '00';
                mEl.textContent = '00';
                sEl.textContent = '00';
                return;
            }
            const timer = setInterval(() => {
                if (timeLeft <= 0) {
                    clearInterval(timer);
                    location.reload();
                    return;
                }
                const h = Math.floor(timeLeft / 3600);
                const m = Math.floor((timeLeft % 3600) / 60);
                const s = timeLeft % 60;
                hEl.textContent = h.toString().padStart(2, '0');
                mEl.textContent = m.toString().padStart(2, '0');
                sEl.textContent = s.toString().padStart(2, '0');
                timeLeft--;
            }, 1000);
        }

        function startScrambleAnimation() {
            function scrambleBalls(containerId) {
                const container = document.getElementById(containerId);
                if (!container || container.getAttribute('data-calculating') !== '1') return;
                const balls = container.querySelectorAll('.ball');
                if (!balls.length) return;
                balls.forEach((ball, index) => {
                    ball.classList.add('scrambling');
                    const speed = 70 + (index * 18);
                    setInterval(() => {
                        const randomDigit = Math.floor(Math.random() * 10);
                        ball.textContent = randomDigit;
                        if (Math.random() > 0.9) {
                            ball.style.filter = 'blur(0px)';
                            setTimeout(() => { ball.style.filter = 'blur(0.5px)'; }, 70);
                        }
                    }, speed);
                });
            }
            scrambleBalls('mainBalls');
            scrambleBalls('secondBalls');
            scrambleBalls('thirdBalls');
        }

        document.addEventListener('DOMContentLoaded', () => {
            startCountdown();
            startScrambleAnimation();
   
            const isCalculating = document.getElementById('mainBalls')?.getAttribute('data-calculating') === '1';
   
            if (isCalculating) {
                setTimeout(() => location.reload(), 3000);
            } else {
                setTimeout(() => location.reload(), 60000);
            }
        });
    </script>
</body>
</html>