(function () {
  if (window.__rpSkeletonBooted) return;
  window.__rpSkeletonBooted = true;

  function createOverlay() {
    if (document.getElementById('rpSkeletonOverlay')) return;
    var overlay = document.createElement('div');
    overlay.id = 'rpSkeletonOverlay';
    overlay.className = 'rp-skeleton-overlay';
    overlay.innerHTML =
      '<div class="rp-skeleton-card" aria-hidden="true">' +
      '<div class="rp-sk-avatar"></div>' +
      '<div class="rp-sk-line w-80"></div>' +
      '<div class="rp-sk-line w-60"></div>' +
      '<div class="rp-sk-pill"></div>' +
      '<div class="rp-sk-pill"></div>' +
      '<div class="rp-sk-line w-50"></div>' +
      '<div class="rp-sk-line w-40"></div>' +
      '</div>';
    document.body.appendChild(overlay);
  }

  function hideOverlay() {
    var overlay = document.getElementById('rpSkeletonOverlay');
    if (!overlay) return;
    overlay.classList.add('is-hidden');
    setTimeout(function () {
      if (overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay);
    }, 260);
  }

  function onReady() {
    createOverlay();
    setTimeout(hideOverlay, 220);
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', onReady, { once: true });
  } else {
    onReady();
  }

  window.addEventListener('pageshow', function () {
    setTimeout(hideOverlay, 120);
  });
})();
