(function($) {
  document.addEventListener('DOMContentLoaded', function() {
    const forms = document.querySelectorAll('[data-gf-form-id]');

    forms.forEach(function(form) {
      const wrapper = form.closest('[data-gf-form-id]');
      if (!wrapper) {
        return;
      }

      const cursor = document.createElement('div');
      cursor.className = 'pixel-grid-odyssey-cursor';
      cursor.style.position = 'absolute';
      cursor.style.width = '36px';
      cursor.style.height = '36px';
      cursor.style.border = '2px solid rgba(0, 247, 255, 0.6)';
      cursor.style.borderRadius = '50%';
      cursor.style.pointerEvents = 'none';
      cursor.style.opacity = '0';
      cursor.style.transition = 'opacity 0.3s ease';
      cursor.style.mixBlendMode = 'screen';
      cursor.style.zIndex = '2';
      form.style.position = 'relative';
      form.appendChild(cursor);

      form.addEventListener('mousemove', function(e) {
        const rect = form.getBoundingClientRect();
        cursor.style.opacity = '1';
        cursor.style.transform = `translate(${e.clientX - rect.left - 18}px, ${e.clientY - rect.top - 18}px)`;
      });

      form.addEventListener('mouseleave', function() {
        cursor.style.opacity = '0';
      });

      const fields = form.querySelectorAll('[data-gf-field-type]');
      fields.forEach(function(field, index) {
        field.style.setProperty('--pixel-pulse-delay', `${index * 60}ms`);
        field.classList.add('pixel-grid-odyssey-field');
      });
    });
  });
})(window.jQuery);
