<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NUMBER KING - 60 Sec Live</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{background:#0a0a0a;color:#FFD700;font-family:Arial,sans-serif;padding:10px}
.box{max-width:400px;margin:auto}
.header{text-align:center;padding:10px;font-size:22px;font-weight:900}
.card{background:#1a1a1a;border:1px solid #FFD700;border-radius:14px;padding:14px;margin:12px 0}
.timer{background:#FFD700;color:#000;padding:14px;border-radius:10px;text-align:center;font-weight:900;font-size:26px;letter-spacing:1px}
.grid{display:grid;grid-template-columns:repeat(4,1fr);gap:10px;margin-top:12px}
.num{background:#222;border:1.5px solid #FFD700;color:#FFD700;padding:18px 0;text-align:center;border-radius:10px;font-size:22px;font-weight:900;cursor:pointer}
.num.sel{background:#FFD700;color:#000}
.btn{width:100%;padding:14px;background:linear-gradient(90deg,#FFD700,#FFA500);border:none;border-radius:10px;font-weight:900;font-size:16px;color:#000;margin-top:12px;cursor:pointer}
.hrow{display:flex;justify-content:space-between;background:#000;border:1px dashed #555;padding:10px;border-radius:8px;margin:5px 0;font-size:13px;color:#fff}
.hrow b{color:#FFD700;font-size:15px}
.note{text-align:center;font-size:12px;color:#888;margin-top:8px}
</style>
</head>
<body>
<div class="box">
<div class="header">👑 NUMBER KING 👑</div>

<div class="card timer">⏱️ <span id="timer">00:60</span> | Round <span id="round">1</span></div>

<div class="card">
<div style="display:flex;justify-content:space-between;align-items:center"><b>Choose Number (1-12)</b><span id="choice" style="color:#fff;font-size:20px;font-weight:bold">--</span></div>
<div class="grid" id="grid"></div>
<button class="btn" onclick="confirmBtn()">CONFIRM</button>
<div class="note">60 second live - Admin result debe</div>
</div>

<div class="card">
<b>🔴 Last Result</b>
<div id="last" class="hrow"><span>Waiting for result...</span><span>--</span></div>
</div>

<div class="card">
<b>📜 History - Koita Somoy Koto Result</b>
<div id="history" style="margin-top:8px">
<div class="hrow" style="color:#FFD700;border-color:#FFD700"><span>Time</span><span>Round</span><span>Result</span></div>
<div style="text-align:center;color:#666;padding:10px">No result yet</div>
</div>
</div>

</div>

<script>
let sel = null;
let grid = document.getElementById('grid');

for(let i=1;i<=12;i++){
let d = document.createElement('div');
d.className = 'num';
d.innerText = i;
d.onclick = ()=>{
document.querySelectorAll('.num').forEach(e=>e.classList.remove('sel'));
d.classList.add('sel');
sel = i;
document.getElementById('choice').innerText = i;
};
grid.appendChild(d);
}

function confirmBtn(){
if(!sel){ alert('1-12 theke 1ta number nao'); return; }
alert('Round '+document.getElementById('round').innerText+' te '+sel+' confirm holo!');
}

// 60 SEC - Ghorir time diye SAME live time User + Admin
function getRoundInfo(){
let now = new Date();
let totalSec = now.getHours()*3600 + now.getMinutes()*60 + now.getSeconds();
let round = Math.floor(totalSec/60)+1;
let left = 60 - now.getSeconds();
return {round, left};
}

function showHistory(){
let h = JSON.parse(localStorage.getItem('nk_history')||'[]');
if(h.length==0) return;
let html = '<div class="hrow" style="color:#FFD700;border-color:#FFD700"><span>Time</span><span>Round</span><span>Result</span></div>';
h.forEach(x=>{
html += `<div class="hrow"><span>${x.time}</span><span>R${x.round}</span><span><b>${x.result}</b></span></div>`;
});
document.getElementById('history').innerHTML = html;
document.getElementById('last').innerHTML = `<span>${h[0].time} | R${h[0].round}</span><span><b style="font-size:18px">${h[0].result}</b></span>`;
}

let lastRound = getRoundInfo().round;

setInterval(()=>{
let info = getRoundInfo();
document.getElementById('timer').innerText = '00:' + (info.left<10?'0':'') + info.left;
document.getElementById('round').innerText = info.round;

if(info.round !== lastRound){
let result = localStorage.getItem('nk_admin_result');
let finalResult = result ? result : 'CANCELLED';
let now = new Date();
let timeStr = now.toLocaleTimeString();
let hist = JSON.parse(localStorage.getItem('nk_history')||'[]');
hist.unshift({time:timeStr, round:lastRound, result:finalResult});
if(hist.length>50) hist.pop();
localStorage.setItem('nk_history', JSON.stringify(hist));
localStorage.removeItem('nk_admin_result');
lastRound = info.round;
sel = null;
document.getElementById('choice').innerText = '--';
document.querySelectorAll('.num').forEach(e=>e.classList.remove('sel'));
}
showHistory();
},1000);

showHistory();
</script>
</body>
</html>