r
    qualityRange.addEventListener('input', () => {
      qualityValue.textContent = qualityRange.value;
      updateImage();
    });

    // Toggle handler
    viewToggle.addEventListener('click', () => {
      viewToggle.classList.toggle('active');
      updateDisplayedImage();
      updatePreviewHint();
    });

    // Download button handler
    downloadBtn.addEventListener('click', () => {
      if (optimizedSrc) {
        const link = document.createElement('a');
        link.download = 'optimized-im