(function () {
  const COUNTER_DURATION = 2000;

  fetch("https://counter.bug-dev-mail.workers.dev")
    .then(r => r.text())
    .then(count => {
      const target = parseInt(count, 10);
      const el = document.getElementById("counter");
      const start = performance.now();

      function tick(now) {
        const t = Math.min((now - start) / COUNTER_DURATION, 1);
        const eased = 1 - Math.pow(1 - t, 3);
        const current = Math.round(eased * target);
        el.textContent = String(current).padStart(7, '0');
        if (t < 1) requestAnimationFrame(tick);
      }

      requestAnimationFrame(tick);
    });
})();
