let countdown = 3;
let countdownInterval;

const startButton = document.getElementById('startButton');
const countdownDisplay = document.getElementById('countdown');
const resultDisplay = document.getElementById('result');
const boxes = document.querySelectorAll('.box');

boxes.forEach((box, index) => {
  box.addEventListener('click', () => {
    if (index === 0) {
      clearInterval(countdownInterval);
      resultDisplay.textContent = '当たり！';
    } else {
      resultDisplay.textContent = '失敗';
    }
  });
});

startButton.addEventListener('click', () => {
  startButton.disabled = true;
  countdown = 3;
  countdownDisplay.textContent = `${countdown}秒前`;

  countdownInterval = setInterval(() => {
    countdown--;
    if (countdown === 0) {
      clearInterval(countdownInterval);
      resultDisplay.textContent = '大爆破!!ドカーン!!';
    } else {
      countdownDisplay.textContent = `${countdown}秒前`;
    }
  }, 1000);
});
