


  
  
  Оптимизированный огненный курсор
  
    .custom-cursor {
      pointer-events: none;
      position: fixed;
      z-index: 9999;
      top: 0;
      left: 0;
      transform: translate3d(0, 0, 0);
      display: block !important;
      will-change: transform;
    }

    .cursor-core {
      width: 20px;
      height: 20px;
      border-radius: 50%;
      background: radial-gradient(circle, #FFD700 20%, #FF4500 80%);
      position: absolute;
      transform: translate(-50%, -50%);
      transition: transform 0.15s ease;
      z-index: 10000;
      box-shadow: 
        0 0 15px #FF8C00,
        0 0 30px rgba(255, 69, 0, 0.7);
      animation: corePulse 1.5s infinite alternate;
    }

    .fire-tail {
      position: fixed;
      border-radius: 50%;
      z-index: 9998;
      pointer-events: none;
      background: radial-gradient(circle, #FF4500 40%, transparent 70%);
      opacity: 0.8;
      transform-origin: center;
      transform: translate3d(0, 0, 0);
    }

    @keyframes corePulse {
      0% { transform: translate(-50%, -50%) scale(1); }
      100% { transform: translate(-50%, -50%) scale(1.1); }
    }

    .cursor-hover .cursor-core {
      background: radial-gradient(circle, #00FFFF 20%, #0077FF 80%);
      box-shadow: 
        0 0 20px #00FFFF,
        0 0 35px rgba(0, 255, 255, 0.6);
    }

    .cursor-click .cursor-core {
      transform: translate(-50%, -50%) scale(0.8);
      background: radial-gradient(circle, #FF1493 30%, #FF0000 90%);
    }

    .cursor-burst {
      position: fixed;
      border-radius: 50%;
      z-index: 9997;
      pointer-events: none;
      background: radial-gradient(circle, #FF8C00 30%, transparent 80%);
      transform: translate(-50%, -50%) scale(0);
      opacity: 0;
    }

    .cursor-click .cursor-burst {
      animation: burstEffect 0.5s cubic-bezier(0.215, 0.610, 0.355, 1.000) forwards;
    }

    @keyframes burstEffect {
      0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
      90% { opacity: 0.7; }
      100% { transform: translate(-50%, -50%) scale(2.5); opacity: 0; }
    }

    @media (max-width: 768px), (hover: none) {
      .custom-cursor, .fire-tail, .cursor-burst {
        display: none !important;
      }
    }
  



function initFireCursor() {
  if (!matchMedia('(hover: hover)').matches) return;
  document.querySelectorAll('.custom-cursor, .fire-tail, .cursor-burst').forEach(el => el.remove());
  
  const cursorHTML = `
    
      
      
    
  `;
  document.body.insertAdjacentHTML('beforeend', cursorHTML);
  
  const TAIL_LENGTH = 5;
  const TAIL_DECAY = 0.15;
  const tailElements = [];
  
  for (let i = 0; i < TAIL_LENGTH; i++) {
    const tailPart = document.createElement('div');
    tailPart.className = 'fire-tail';
    const size = 18 - (i * 2.5);
    tailPart.style.width = `${size}px`;
    tailPart.style.height = `${size}px`;
    const opacity = 0.8 - (i * 0.15);
    tailPart.style.opacity = opacity;
    document.body.appendChild(tailPart);
    tailElements.push(tailPart);
  }

  const cursor = document.querySelector('.custom-cursor');
  const core = document.querySelector('.cursor-core');
  const burst = document.querySelector('.cursor-burst');
  
  let mouseX = innerWidth / 2;
  let mouseY = innerHeight / 2;
  
  const positionHistory = Array(TAIL_LENGTH).fill({x: mouseX, y: mouseY});
  
  const handleMouseMove = e => {
    mouseX = e.clientX;
    mouseY = e.clientY;
    core.style.left = `${mouseX}px`;
    core.style.top = `${mouseY}px`;
  };
  
  const updateFireTail = () => {
    positionHistory.unshift({x: mouseX, y: mouseY});
    positionHistory.pop();
    
    tailElements.forEach((tailPart, i) => {
      const pos = positionHistory[i];
      tailPart.style.left = `${pos.x}px`;
      tailPart.style.top = `${pos.y}px`;
      tailPart.style.transform = `scale(${1 - (i * TAIL_DECAY)})`;
    });
    
    requestAnimationFrame(updateFireTail);
  };
  
  const initHoverEvents = () => {
    const hoverSelectors = [
      'a', 'button', 'input', 'textarea', 'select',
      '.t-btn', '.t-link', '.t-store__btn'
    ];
    
    document.addEventListener('mouseover', e => {
      if (hoverSelectors.some(sel => e.target.matches(sel))) {
        cursor.classList.add('cursor-hover');
      }
    });
    
    document.addEventListener('mouseout', e => {
      if (hoverSelectors.some(sel => e.target.matches(sel))) {
        cursor.classList.remove('cursor-hover');
      }
    });
  };
  
  const initClickEvents = () => {
    document.addEventListener('mousedown', () => {
      cursor.classList.add('cursor-click');
      burst.style.left = `${mouseX}px`;
      burst.style.top = `${mouseY}px`;
    });
    
    document.addEventListener('mouseup', () => {
      cursor.classList.remove('cursor-click');
    });
  };
  
  const handleVisibility = isVisible => {
    cursor.style.opacity = isVisible ? '1' : '0';
    tailElements.forEach(t => t.style.opacity = isVisible ? '0.8' : '0');
  };
  
  document.body.style.cursor = 'none';
  core.style.left = `${mouseX}px`;
  core.style.top = `${mouseY}px`;
  
  tailElements.forEach(t => {
    t.style.left = `${mouseX}px`;
    t.style.top = `${mouseY}px`;
  });
  
  document.addEventListener('mouseleave', () => handleVisibility(false));
  document.addEventListener('mouseenter', () => handleVisibility(true));
  
  document.addEventListener('mousemove', handleMouseMove);
  requestAnimationFrame(updateFireTail);
  initHoverEvents();
  initClickEvents();
  
  return () => {
    document.removeEventListener('mousemove', handleMouseMove);
    document.body.style.cursor = '';
    cursor.remove();
    tailElements.forEach(t => t.remove());
  };
}

(function() {
  let cleanupFn = null;
  
  const init = () => {
    if (cleanupFn) cleanupFn();
    cleanupFn = initFireCursor();
  };
  
  if (document.readyState === 'complete') {
    init();
  } else {
    document.addEventListener('DOMContentLoaded', init);
  }
  
  if (window.Tilda?.Page) {
    const originalLoadPage = Tilda.Page.loadPage;
    
    Tilda.Page.loadPage = function(url, push, preventScroll) {
      return originalLoadPage(url, push, preventScroll).then(() => {
        setTimeout(init, 50);
      });
    };
  }
  
  window.addEventListener('hashchange', init);
})();


