(function initMyronCreativeRuntime(global) {
  "use strict";

  var reducedMotion = !!(global.matchMedia && global.matchMedia("(prefers-reduced-motion: reduce)").matches);
  var behaviors = {};
  var parallaxSections = [];
  var textParallaxSections = [];
  var particleInstances = [];
  var rafId = null;
  var textParallaxListening = false;
  var textParallaxRafPending = false;

  // ─── Public API ────────────────────────────────────────────────────────────

  function registerBehavior(componentId, fn) {
    if (typeof componentId === "string" && typeof fn === "function") {
      behaviors[componentId] = fn;
    }
  }

  // ─── Utilities ─────────────────────────────────────────────────────────────

  function parseParams(section) {
    var raw = section.getAttribute("data-mc-params");
    if (!raw) return {};
    try { return JSON.parse(raw); } catch (e) { return {}; }
  }

  function parseJsonAttr(el, attr) {
    var raw = el.getAttribute(attr);
    if (!raw) return {};
    try { return JSON.parse(raw); } catch (e) { return {}; }
  }

  function resolveColor(hex, fallback) {
    return (typeof hex === "string" && /^#[0-9a-f]{3,8}$/i.test(hex)) ? hex : fallback;
  }

  function clamp(val, min, max) {
    return Math.min(Math.max(Number(val) || 0, min), max);
  }

  function findHeadline(section) {
    return section.querySelector('[data-myron-edit-slot="headline"], h1, h2, h3');
  }

  function directRenderableChildren(container) {
    return Array.prototype.filter.call(container.children || [], function (child) {
      return child.nodeType === 1 && !child.classList.contains("mc-scene");
    });
  }

  function findCardContainer(section) {
    var direct = directRenderableChildren(section).filter(function (child) {
      return !child.matches(".myron-feature-grid__inner, .myron-testimonial-grid__inner");
    });
    if (direct.length >= 2) {
      return { container: section, cards: direct };
    }

    var nested = section.querySelector(
      ".myron-feature-grid__items, .myron-services-grid__items, .myron-testimonial-grid__items, .myron-product-grid__items, [role=\"list\"]"
    );
    if (!nested) return null;
    var cards = directRenderableChildren(nested);
    return cards.length >= 2 ? { container: nested, cards: cards } : null;
  }

  // ─── Motion profiles ───────────────────────────────────────────────────────

  function applyFadeUp(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 600, 100, 2000);
    var delay = clamp(params.delay || 0, 0, 2000);
    var distance = clamp(params.distance || 40, 10, 120);
    section.style.setProperty("--mc-fade-up-duration", duration + "ms");
    section.style.setProperty("--mc-fade-up-delay", delay + "ms");
    section.style.setProperty("--mc-fade-up-distance", distance + "px");
    section.classList.add("mc-motion--fade-up");
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  function applySlideIn(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 500, 100, 2000);
    var delay = clamp(params.delay || 0, 0, 2000);
    var distance = clamp(params.distance || 60, 10, 200);
    var direction = params.direction === "right" ? "right" : "left";
    section.style.setProperty("--mc-slide-duration", duration + "ms");
    section.style.setProperty("--mc-slide-delay", delay + "ms");
    section.style.setProperty("--mc-slide-distance", (direction === "right" ? "" : "-") + distance + "px");
    section.classList.add("mc-motion--slide-in");
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  function applyStagger(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 500, 100, 2000);
    var delay = clamp(params.delay || 0, 0, 1000);
    var stagger = clamp(params.stagger || 120, 30, 500);
    section.classList.add("mc-motion--stagger");
    observeReveal(section, function () {
      var children = section.children;
      for (var i = 0; i < children.length; i++) {
        var child = children[i];
        child.style.setProperty("--mc-stagger-duration", duration + "ms");
        child.style.setProperty("--mc-stagger-delay", (delay + i * stagger) + "ms");
        child.classList.add("mc-stagger-child");
      }
      section.classList.add("mc-motion--revealed");
    });
  }

  function applyZoomIn(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 500, 100, 2000);
    var delay = clamp(params.delay || 0, 0, 2000);
    section.style.setProperty("--mc-zoom-duration", duration + "ms");
    section.style.setProperty("--mc-zoom-delay", delay + "ms");
    section.classList.add("mc-motion--zoom-in");
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  function clearWillChangeAfterReveal(section, duration, delay) {
    var cleared = false;
    function clear() {
      if (cleared) return;
      cleared = true;
      section.style.willChange = "";
      section.removeEventListener("transitionend", clear);
    }
    section.addEventListener("transitionend", clear);
    global.setTimeout(clear, duration + delay + 120);
  }

  function applyBlurIn(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 600, 200, 1500);
    var delay = clamp(params.delay || 0, 0, 2000);
    section.style.setProperty("--mc-blur-in-duration", duration + "ms");
    section.style.setProperty("--mc-blur-in-delay", delay + "ms");
    section.style.willChange = "filter, opacity";
    section.classList.add("mc-motion--blur-in");
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
      clearWillChangeAfterReveal(section, duration, delay);
    });
  }

  function applyFlipUp(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 700, 300, 1500);
    var delay = clamp(params.delay || 0, 0, 2000);
    var angle = clamp(params.angle || 15, 5, 30);
    section.style.setProperty("--mc-flip-duration", duration + "ms");
    section.style.setProperty("--mc-flip-delay", delay + "ms");
    section.style.setProperty("--mc-flip-angle", angle + "deg");
    section.style.setProperty("--mc-flip-perspective", "600px");
    section.classList.add("mc-motion--flip-up");
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  function applyScalePop(section, params) {
    if (reducedMotion) return;
    var duration = clamp(params.duration || 500, 200, 1200);
    var delay = clamp(params.delay || 0, 0, 2000);
    var startScale = clamp(params.startScale || 0.85, 0.6, 0.95);
    section.style.setProperty("--mc-scale-pop-duration", duration + "ms");
    section.style.setProperty("--mc-scale-pop-delay", delay + "ms");
    section.style.setProperty("--mc-scale-pop-start", String(startScale));
    section.classList.add("mc-motion--scale-pop");
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  function applyParallaxBg(section, params) {
    if (reducedMotion) return;
    var intensity = clamp(params.intensity || 0.2, 0.05, 0.5);
    section.dataset.mcParallaxIntensity = String(intensity);
    parallaxSections.push(section);
    updateParallax(section, intensity);
  }

  function parseCountTarget(original) {
    var match = String(original || "").match(/([+\-]?)([$\u20ac\u00a3\u00a5]?)(\d[\d,]*(?:\.\d+)?)([%+]?)/);
    if (!match) return null;
    var numeric = match[3].replace(/,/g, "");
    var absoluteTarget = Number(numeric);
    if (!Number.isFinite(absoluteTarget)) return null;
    var sign = match[1] === "-" ? -1 : 1;
    var decimals = numeric.indexOf(".") >= 0 ? numeric.split(".")[1].length : 0;
    return {
      match: match[0],
      target: absoluteTarget * sign,
      showPlus: match[1] === "+",
      currency: match[2] || "",
      useCommas: match[3].indexOf(",") >= 0,
      decimals: decimals,
      suffix: match[4] || "",
      original: String(original || "")
    };
  }

  function formatCountValue(value, spec) {
    var sign = value < 0 ? "-" : (spec.showPlus ? "+" : "");
    var text = Math.abs(value).toFixed(spec.decimals);
    if (spec.useCommas) {
      var parts = text.split(".");
      parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
      text = parts.join(".");
    }
    return sign + spec.currency + text + spec.suffix;
  }

  function findCountTargets(section) {
    var explicit = Array.prototype.slice.call(section.querySelectorAll("[data-mc-count-target]"));
    if (explicit.length > 0) {
      return explicit.map(function (el) {
        var original = el.textContent || "";
        var spec = parseCountTarget(original);
        return spec ? { node: el, original: original, spec: spec, textNode: false } : null;
      }).filter(Boolean);
    }

    var filter = global.NodeFilter;
    if (!filter) return [];
    var walker = global.document.createTreeWalker(section, filter.SHOW_TEXT, {
      acceptNode: function (node) {
        return parseCountTarget(node.nodeValue || "") ? filter.FILTER_ACCEPT : filter.FILTER_REJECT;
      }
    });
    var node = walker.nextNode();
    if (!node) return [];
    var originalText = node.nodeValue || "";
    var spec = parseCountTarget(originalText);
    return spec ? [{ node: node, original: originalText, spec: spec, textNode: true }] : [];
  }

  function setCountText(target, value) {
    var next = target.original.replace(target.spec.match, formatCountValue(value, target.spec));
    if (target.textNode) {
      target.node.nodeValue = next;
    } else {
      target.node.textContent = next;
    }
  }

  function restoreCountText(target) {
    if (target.textNode) {
      target.node.nodeValue = target.original;
    } else {
      target.node.textContent = target.original;
    }
  }

  function applyCountUp(section, params) {
    if (!section || section.dataset.mcCountUpApplied === "true") return;
    var targets = findCountTargets(section);
    if (targets.length === 0) return;
    section.dataset.mcCountUpApplied = "true";

    if (reducedMotion) {
      targets.forEach(restoreCountText);
      return;
    }

    var duration = clamp(params.duration || 1800, 500, 4000);
    var delay = clamp(params.delay || 0, 0, 2000);
    observeReveal(section, function () {
      global.setTimeout(function () {
        var startedAt = global.performance && global.performance.now ? global.performance.now() : Date.now();
        function tick(now) {
          now = now || Date.now();
          var elapsed = Math.min(Math.max(now - startedAt, 0), duration);
          var t = elapsed / duration;
          var eased = 1 - ((1 - t) * (1 - t));
          targets.forEach(function (target) {
            setCountText(target, target.spec.target * eased);
          });
          if (elapsed < duration) {
            global.requestAnimationFrame(tick);
            return;
          }
          targets.forEach(restoreCountText);
        }
        targets.forEach(function (target) { setCountText(target, 0); });
        global.requestAnimationFrame(tick);
      }, delay);
    });
  }

  function applyTypewriterHeadline(section, params) {
    if (reducedMotion) return;
    var headline = findHeadline(section);
    if (!headline || headline.dataset.mcTypewriterApplied === "true") return;
    headline.dataset.mcTypewriterApplied = "true";
    var original = headline.textContent || "";
    if (!original.trim()) return;
    var speed = clamp(params.speed || 40, 10, 120);
    var delay = clamp(params.delay || 0, 0, 2000);
    var cursorText = typeof params.cursor === "string" && params.cursor !== "" ? params.cursor : "|";
    observeReveal(section, function () {
      headline.textContent = "";
      var cursor = global.document.createElement("span");
      cursor.className = "mc-cursor";
      cursor.textContent = cursorText;
      headline.appendChild(cursor);
      var index = 0;
      global.setTimeout(function typeNext() {
        if (index < original.length) {
          cursor.insertAdjacentText("beforebegin", original.charAt(index));
          index++;
          global.setTimeout(typeNext, speed);
          return;
        }
        cursor.remove();
      }, delay);
    });
  }

  function applyRotateWords(section, params) {
    var headline = findHeadline(section);
    if (!headline || headline.dataset.mcRotateApplied === "true") return;
    var words = (headline.textContent || "").split("|").map(function (part) { return part.trim(); }).filter(Boolean);
    if (words.length === 0) return;
    headline.textContent = words[0];
    if (reducedMotion || words.length === 1) return;
    headline.dataset.mcRotateApplied = "true";
    var interval = clamp(params.interval || 2500, 800, 10000);
    var transition = params.transition === "fade" ? "fade" : "slide";
    var span = global.document.createElement("span");
    span.className = "mc-rotate-words mc-rotate-words--" + transition;
    span.textContent = words[0];
    headline.textContent = "";
    headline.appendChild(span);
    var index = 0;
    global.setInterval(function () {
      index = (index + 1) % words.length;
      span.dataset.state = "changing";
      global.setTimeout(function () {
        span.textContent = words[index];
        span.dataset.state = "shown";
      }, 180);
    }, interval);
  }

  function applyShutterReveal(section, params) {
    if (reducedMotion) return;
    var direction = ["top", "left", "center"].indexOf(params.direction) >= 0 ? params.direction : "top";
    var duration = clamp(params.duration || 700, 300, 2000);
    var delay = clamp(params.delay || 0, 0, 2000);
    section.style.setProperty("--mc-shutter-duration", duration + "ms");
    section.style.setProperty("--mc-shutter-delay", delay + "ms");
    section.classList.add("mc-motion--shutter-reveal", "mc-motion--shutter-" + direction);
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  function applySplitLines(section, params) {
    if (reducedMotion) return;
    var headline = findHeadline(section);
    if (!headline || headline.dataset.mcSplitApplied === "true") return;
    var text = headline.textContent || "";
    if (!text.trim()) return;
    headline.dataset.mcSplitApplied = "true";
    var splitBy = params.splitBy === "line" ? "line" : "word";
    var duration = clamp(params.duration || 600, 200, 2000);
    var stagger = clamp(params.stagger || 80, 20, 400);
    var delay = clamp(params.delay || 0, 0, 2000);
    var parts = splitBy === "line" ? text.split(/\s*[|]\s*/).filter(Boolean) : text.split(/\s+/).filter(Boolean);
    headline.textContent = "";
    parts.forEach(function (part, index) {
      var wrapper = global.document.createElement("span");
      wrapper.className = "mc-split-line-wrapper";
      var inner = global.document.createElement("span");
      inner.className = "mc-split-word";
      inner.textContent = part;
      inner.style.setProperty("--mc-split-duration", duration + "ms");
      inner.style.setProperty("--mc-split-delay", (delay + index * stagger) + "ms");
      wrapper.appendChild(inner);
      headline.appendChild(wrapper);
      if (splitBy === "word") {
        headline.appendChild(global.document.createTextNode(" "));
      }
    });
    observeReveal(section, function () {
      section.classList.add("mc-motion--revealed");
    });
  }

  // ─── IntersectionObserver ──────────────────────────────────────────────────

  var io = null;
  var ioCallbacks = [];

  function getIO() {
    if (!io && global.IntersectionObserver) {
      io = new global.IntersectionObserver(function (entries) {
        entries.forEach(function (entry) {
          if (!entry.isIntersecting) return;
          for (var i = 0; i < ioCallbacks.length; i++) {
            if (ioCallbacks[i].el === entry.target) {
              ioCallbacks[i].fn();
              io.unobserve(entry.target);
              ioCallbacks.splice(i, 1);
              break;
            }
          }
        });
      }, { threshold: 0.12, rootMargin: "0px 0px -60px 0px" });
    }
    return io;
  }

  function observeReveal(el, fn) {
    var observer = getIO();
    if (!observer) { fn(); return; }
    ioCallbacks.push({ el: el, fn: fn });
    observer.observe(el);
  }

  // ─── Scroll / rAF ──────────────────────────────────────────────────────────

  function updateParallax(section, intensity) {
    var rect = section.getBoundingClientRect();
    var center = rect.top + rect.height / 2;
    var viewCenter = global.innerHeight / 2;
    var offset = (center - viewCenter) * intensity;
    section.style.setProperty("--mc-parallax-offset", offset.toFixed(2) + "px");
  }

  function updateTextParallax(section, intensity) {
    var rect = section.getBoundingClientRect();
    var center = rect.top + rect.height / 2;
    var viewCenter = global.innerHeight / 2;
    var offset = (center - viewCenter) * intensity;
    section.style.setProperty("--mc-parallax-img-offset", offset.toFixed(2) + "px");
  }

  function updateTextParallaxSections() {
    for (var i = 0; i < textParallaxSections.length; i++) {
      var s = textParallaxSections[i];
      updateTextParallax(s, parseFloat(s.dataset.mcTextParallaxIntensity || "0.2"));
    }
  }

  function requestTextParallaxUpdate() {
    if (textParallaxRafPending) return;
    textParallaxRafPending = true;
    global.requestAnimationFrame(function () {
      textParallaxRafPending = false;
      updateTextParallaxSections();
    });
  }

  function ensureTextParallaxListener() {
    if (textParallaxListening) return;
    textParallaxListening = true;
    global.addEventListener("scroll", requestTextParallaxUpdate, { passive: true });
    global.addEventListener("resize", requestTextParallaxUpdate);
  }

  function applyTextParallaxScroll(section, params) {
    if (!section || reducedMotion || section.dataset.mcTextParallaxApplied === "true") return;
    var computed = global.getComputedStyle(section);
    var backgroundImage = computed.backgroundImage || "";
    if (backgroundImage === "" || backgroundImage === "none") return;
    var intensity = clamp(params.intensity || 0.2, 0.05, 0.4);
    section.dataset.mcTextParallaxApplied = "true";
    section.dataset.mcTextParallaxIntensity = String(intensity);
    section.style.setProperty("--mc-parallax-img-image", backgroundImage);
    section.style.setProperty("--mc-parallax-img-size", computed.backgroundSize || "cover");
    section.style.setProperty("--mc-parallax-img-position", computed.backgroundPosition || "center");
    section.style.setProperty("--mc-parallax-img-repeat", computed.backgroundRepeat || "no-repeat");
    section.style.backgroundImage = "none";
    section.classList.add("mc-motion--text-parallax-scroll");
    textParallaxSections.push(section);
    updateTextParallax(section, intensity);
    ensureTextParallaxListener();
  }

  function onScroll() {
    for (var i = 0; i < parallaxSections.length; i++) {
      var s = parallaxSections[i];
      updateParallax(s, parseFloat(s.dataset.mcParallaxIntensity || "0.2"));
    }
    for (var j = 0; j < particleInstances.length; j++) {
      particleInstances[j].resize();
    }
  }

  function startRaf() {
    if (rafId !== null || (parallaxSections.length === 0 && particleInstances.length === 0)) return;
    function tick() {
      onScroll();
      rafId = global.requestAnimationFrame(tick);
    }
    global.addEventListener("scroll", onScroll, { passive: true });
    rafId = global.requestAnimationFrame(tick);
  }

  // ─── Scene backgrounds ─────────────────────────────────────────────────────

  function injectScene(section, sceneId, params) {
    if (reducedMotion && sceneId === "canvas-particles") {
      return;
    }
    var wrapper = global.document.createElement("div");
    wrapper.className = "mc-scene mc-scene--" + sceneId;
    wrapper.setAttribute("aria-hidden", "true");
    wrapper.setAttribute("data-mc-scene-type", sceneId);

    if (sceneId === "gradient-flow") {
      injectGradientFlow(wrapper, params);
    } else if (sceneId === "gradient-bloom") {
      injectGradientBloom(wrapper, params);
    } else if (sceneId === "aurora-mesh") {
      injectAuroraMesh(wrapper, params);
    } else if (sceneId === "dot-grid") {
      injectDotGrid(wrapper, params);
    } else if (sceneId === "noise-overlay") {
      injectNoiseOverlay(wrapper, params);
    } else if (sceneId === "canvas-particles") {
      injectCanvasParticles(section, wrapper, params);
    } else if (sceneId === "card-laser-grid") {
      injectCardLaserGrid(section, wrapper, params);
    } else if (sceneId === "card-ekg-pulse") {
      injectCardEkgPulse(wrapper, params);
    } else if (sceneId === "card-geo-rotator") {
      injectCardGeoRotator(wrapper, params);
    }

    section.insertBefore(wrapper, section.firstChild);
  }

  function injectGradientFlow(wrapper, params) {
    var colorA = resolveColor(params.colorA, "var(--myron-color-accent, #6366f1)");
    var colorB = resolveColor(params.colorB, "var(--myron-color-surface-alt, #a5b4fc)");
    var duration = clamp(params.duration || 12, 4, 60);
    var styles = [
      "position:absolute;inset:0;z-index:0;pointer-events:none;",
      "background:linear-gradient(135deg," + colorA + " 0%," + colorB + " 50%," + colorA + " 100%);",
      "background-size:200% 200%;"
    ];
    if (!reducedMotion) {
      styles.push("animation:mc-gradient-flow " + duration + "s ease infinite;");
    }
    wrapper.style.cssText = styles.join("");
  }

  function injectGradientBloom(wrapper, params) {
    var colorA = resolveColor(params.colorA, "var(--myron-color-accent, #6366f1)");
    var intensity = clamp(params.intensity || 0.5, 0.3, 1.0);
    var blur = clamp(params.blur || 20, 0, 80);
    var stop = Math.round(18 + intensity * 34);
    wrapper.style.cssText = [
      "position:absolute;inset:0;z-index:0;pointer-events:none;",
      "background:radial-gradient(ellipse at 50% 100%," + colorA + " 0%, color-mix(in srgb," + colorA + " 45%, transparent) " + stop + "%, transparent 72%);",
      "filter:blur(" + blur + "px);",
      "transform:translateY(" + Math.round(blur / 3) + "px);"
    ].join("");
  }

  function injectAuroraMesh(wrapper, params) {
    var colorA = resolveColor(params.colorA, "var(--myron-color-accent, #6366f1)");
    var colorB = resolveColor(params.colorB, "var(--myron-color-surface-alt, #a5b4fc)");
    var duration = clamp(params.duration || 20, 8, 60);
    wrapper.style.cssText = [
      "position:absolute;inset:-18%;z-index:0;pointer-events:none;",
      "background:",
      "radial-gradient(circle at 20% 30%," + colorA + " 0%, transparent 32%),",
      "radial-gradient(circle at 78% 28%," + colorB + " 0%, transparent 30%),",
      "conic-gradient(from 130deg at 50% 50%," + colorA + ", transparent, " + colorB + ", transparent, " + colorA + ");",
      "background-size:140% 140%;",
      "opacity:0.72;",
      reducedMotion ? "" : "animation:mc-aurora-drift " + duration + "s ease-in-out infinite alternate;"
    ].join("");
  }

  function injectDotGrid(wrapper, params) {
    var spacing = clamp(params.spacing || 24, 10, 60);
    var rawColor = typeof params.dotColor === "string" && params.dotColor !== "" ? params.dotColor : null;
    var color = rawColor ? rawColor : "currentColor";
    var opacity = clamp(params.opacity || 0.15, 0.02, 0.5);
    wrapper.style.cssText = [
      "position:absolute;inset:0;z-index:0;pointer-events:none;",
      "opacity:" + opacity + ";",
      "background-image:radial-gradient(circle," + color + " 1px,transparent 1px);",
      "background-size:" + spacing + "px " + spacing + "px;"
    ].join("");
  }

  function injectNoiseOverlay(wrapper, params) {
    var opacity = clamp(params.opacity || 0.04, 0.01, 0.12);
    var frequency = clamp(params.frequency || 0.65, 0.1, 2.0);
    var filterId = "mc-noise-" + Math.random().toString(36).slice(2, 8);
    var svg = [
      '<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%"',
      ' style="position:absolute;inset:0;z-index:0;pointer-events:none;opacity:' + opacity + '">',
      '<filter id="' + filterId + '">',
      '<feTurbulence type="fractalNoise" baseFrequency="' + frequency + '" numOctaves="4" stitchTiles="stitch"/>',
      '<feColorMatrix type="saturate" values="0"/>',
      '</filter>',
      '<rect width="100%" height="100%" filter="url(#' + filterId + ')"/>',
      '</svg>'
    ].join("");
    wrapper.style.cssText = "position:absolute;inset:0;z-index:0;pointer-events:none;";
    wrapper.innerHTML = svg;
  }

  function injectCanvasParticles(section, wrapper, params) {
    if (reducedMotion) return;
    var count = Math.min(Math.max(parseInt(params.count, 10) || 40, 10), 60);
    var rawColor = typeof params.color === "string" && params.color !== "" ? params.color : null;
    var speed = clamp(params.speed || 0.5, 0.1, 2.0);

    var canvas = global.document.createElement("canvas");
    canvas.setAttribute("aria-hidden", "true");
    canvas.style.cssText = "position:absolute;inset:0;z-index:0;pointer-events:none;width:100%;height:100%;";
    wrapper.style.cssText = "position:absolute;inset:0;z-index:0;pointer-events:none;overflow:hidden;";
    wrapper.appendChild(canvas);

    var ctx = canvas.getContext("2d");
    if (!ctx) return;

    var particles = [];

    function resizeCanvas() {
      canvas.width = section.offsetWidth;
      canvas.height = section.offsetHeight;
    }

    function resolvedColor() {
      if (rawColor) return rawColor;
      var computed = getComputedStyle(section).getPropertyValue("--myron-color-text").trim();
      return computed || "#888888";
    }

    function initParticles() {
      resizeCanvas();
      particles = [];
      for (var i = 0; i < count; i++) {
        particles.push({
          x: Math.random() * canvas.width,
          y: Math.random() * canvas.height,
          r: Math.random() * 1.5 + 0.5,
          vx: (Math.random() - 0.5) * speed,
          vy: (Math.random() - 0.5) * speed,
          alpha: Math.random() * 0.4 + 0.1
        });
      }
    }

    function drawParticles() {
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      var color = resolvedColor();
      for (var i = 0; i < particles.length; i++) {
        var p = particles[i];
        p.x = (p.x + p.vx + canvas.width) % canvas.width;
        p.y = (p.y + p.vy + canvas.height) % canvas.height;
        ctx.beginPath();
        ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
        ctx.fillStyle = color;
        ctx.globalAlpha = p.alpha;
        ctx.fill();
      }
      ctx.globalAlpha = 1;
    }

    initParticles();

    particleInstances.push({
      draw: drawParticles,
      resize: function () {
        if (canvas.width !== section.offsetWidth || canvas.height !== section.offsetHeight) {
          initParticles();
        }
      }
    });

    (function animateParticles() {
      drawParticles();
      global.requestAnimationFrame(animateParticles);
    })();
  }

  function injectCardLaserGrid(section, wrapper, params) {
    var spacing = clamp(params.dotSpacing || 28, 12, 80);
    var scanSpeed = clamp(params.scanSpeed || 1.5, 0.2, 5);
    var dotColor = typeof params.dotColor === "string" && params.dotColor !== "" ? params.dotColor : "";
    var laserColor = typeof params.laserColor === "string" && params.laserColor !== "" ? params.laserColor : "";
    var canvas = global.document.createElement("canvas");
    canvas.setAttribute("aria-hidden", "true");
    canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;pointer-events:none;";
    wrapper.style.cssText = "position:absolute;inset:0;z-index:0;pointer-events:none;overflow:hidden;";
    wrapper.appendChild(canvas);

    var ctx = canvas.getContext("2d");
    if (!ctx) return;
    var width = 0;
    var height = 0;

    function computedColor(name, fallback) {
      var value = global.getComputedStyle(section).getPropertyValue(name).trim();
      return value || fallback;
    }

    function resizeCanvas() {
      var rect = section.getBoundingClientRect();
      width = Math.max(1, Math.round(rect.width || section.offsetWidth || 1));
      height = Math.max(1, Math.round(rect.height || section.offsetHeight || 1));
      var ratio = Math.max(1, global.devicePixelRatio || 1);
      canvas.width = Math.round(width * ratio);
      canvas.height = Math.round(height * ratio);
      canvas.style.width = width + "px";
      canvas.style.height = height + "px";
      ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
    }

    function drawGrid() {
      ctx.clearRect(0, 0, width, height);
      ctx.fillStyle = dotColor || computedColor("--myron-color-text", "#64748b");
      ctx.globalAlpha = 0.22;
      for (var y = spacing / 2; y < height; y += spacing) {
        for (var x = spacing / 2; x < width; x += spacing) {
          ctx.beginPath();
          ctx.arc(x, y, 1.2, 0, Math.PI * 2);
          ctx.fill();
        }
      }
      ctx.globalAlpha = 1;
    }

    function drawLaser(y) {
      var color = laserColor || computedColor("--myron-color-accent", "#6366f1");
      var gradient = ctx.createLinearGradient(0, y, 0, y + 24);
      gradient.addColorStop(0, "transparent");
      gradient.addColorStop(0.45, color);
      gradient.addColorStop(1, "transparent");
      ctx.fillStyle = gradient;
      ctx.globalAlpha = 0.85;
      ctx.fillRect(0, y - 12, width, 24);
      ctx.globalAlpha = 1;
    }

    function render(now) {
      drawGrid();
      if (!reducedMotion) {
        drawLaser(((now / 1000) * scanSpeed * 80) % Math.max(height, 1));
        global.requestAnimationFrame(render);
      }
    }

    resizeCanvas();
    if (global.ResizeObserver) {
      new global.ResizeObserver(function () {
        resizeCanvas();
        if (reducedMotion) drawGrid();
      }).observe(section);
    } else {
      global.addEventListener("resize", function () {
        resizeCanvas();
        if (reducedMotion) drawGrid();
      });
    }
    reducedMotion ? drawGrid() : global.requestAnimationFrame(render);
  }

  function injectCardEkgPulse(wrapper, params) {
    var lineColor = typeof params.lineColor === "string" && params.lineColor !== "" ? params.lineColor : "var(--myron-color-accent, #6366f1)";
    var duration = clamp(params.duration || 3, 1, 12);
    wrapper.style.cssText = "position:absolute;inset:0;z-index:0;pointer-events:none;overflow:hidden;";
    wrapper.style.setProperty("--mc-ekg-color", lineColor);
    wrapper.style.setProperty("--mc-ekg-duration", duration + "s");
    wrapper.innerHTML = [
      '<svg class="mc-ekg-pulse" viewBox="0 0 1200 260" preserveAspectRatio="none" aria-hidden="true" focusable="false">',
      '<path class="mc-ekg-pulse__path" pathLength="1" d="M0 150 H120 L154 150 L184 92 L226 212 L268 68 L306 150 H430 L466 150 L492 118 L528 182 L566 150 H706 L736 150 L764 96 L806 210 L848 72 L888 150 H1200"/>',
      '</svg>'
    ].join("");
    if (reducedMotion) {
      wrapper.classList.add("mc-scene--reduced-motion");
    }
  }

  function injectCardGeoRotator(wrapper, params) {
    var strokeColor = typeof params.strokeColor === "string" && params.strokeColor !== "" ? params.strokeColor : "var(--myron-color-text, #0f172a)";
    var opacity = clamp(params.opacity || 0.08, 0.02, 0.24);
    var duration = clamp(params.duration || 40, 8, 120);
    wrapper.style.cssText = "position:absolute;inset:0;z-index:0;pointer-events:none;overflow:hidden;";
    wrapper.style.setProperty("--mc-geo-color", strokeColor);
    wrapper.style.setProperty("--mc-geo-opacity", String(opacity));
    wrapper.style.setProperty("--mc-geo-duration", duration + "s");
    wrapper.innerHTML = [
      '<svg class="mc-geo-rotator" viewBox="0 0 600 600" aria-hidden="true" focusable="false">',
      '<g class="mc-geo-rotator__motif">',
      '<circle cx="300" cy="300" r="210"/>',
      '<circle cx="300" cy="300" r="145"/>',
      '<path d="M300 72 L497 414 H103 Z"/>',
      '<path d="M300 528 L103 186 H497 Z"/>',
      '<path d="M90 300 H510 M300 90 V510"/>',
      '</g>',
      '</svg>'
    ].join("");
    if (reducedMotion) {
      wrapper.classList.add("mc-scene--reduced-motion");
    }
  }

  // ─── Hero behaviors ───────────────────────────────────────────────────────

  function applyScrolljackHero(section, params) {
    if (!section || section.dataset.mcScrolljackApplied === "true") return;
    var states = section.querySelectorAll("[data-mc-scrolljack-state]");
    if (states.length < 2) return;
    section.dataset.mcScrolljackApplied = "true";
    if (reducedMotion) {
      section.classList.add("myron-scrolljack-hero--reduced");
      for (var reducedIndex = 1; reducedIndex < states.length; reducedIndex++) {
        states[reducedIndex].setAttribute("hidden", "hidden");
      }
      return;
    }

    var transition = params.transition === "slide" ? "slide" : "fade";
    var outer = global.document.createElement("div");
    outer.className = "myron-scrolljack-hero-shell myron-scrolljack-hero-shell--" + transition;
    outer.style.setProperty("--mc-scrolljack-states", String(states.length));
    section.parentNode.insertBefore(outer, section);
    outer.appendChild(section);
    section.classList.add("myron-scrolljack-hero--sticky");

    function activate(index) {
      for (var i = 0; i < states.length; i++) {
        states[i].classList.toggle("is-active", i === index);
        states[i].setAttribute("aria-hidden", i === index ? "false" : "true");
      }
    }

    function update() {
      var rect = outer.getBoundingClientRect();
      var scrollable = Math.max(1, outer.offsetHeight - global.innerHeight);
      var progress = Math.min(Math.max(-rect.top / scrollable, 0), 1);
      var active = Math.min(states.length - 1, Math.floor(progress * states.length));
      activate(active);
    }

    activate(0);
    global.addEventListener("scroll", update, { passive: true });
    global.addEventListener("resize", update);
    update();
  }

  // ─── Feature card creatives ───────────────────────────────────────────────

  function applyCardShuffler(section, params) {
    if (!section || section.dataset.mcCardShufflerApplied === "true") return;
    var match = findCardContainer(section);
    if (!match) return;
    section.dataset.mcCardShufflerApplied = "true";
    section.classList.add("mc-card-shuffler");
    match.container.classList.add("mc-card-shuffler__stack");

    function assignDepth() {
      var cards = directRenderableChildren(match.container);
      match.container.style.setProperty("--mc-card-shuffler-count", String(cards.length));
      cards.forEach(function (card, index) {
        card.classList.add("mc-card-shuffler__item");
        card.style.setProperty("--mc-card-shuffler-index", String(index));
        card.style.setProperty("--mc-card-shuffler-depth", String(cards.length - index));
      });
    }

    assignDepth();
    if (reducedMotion) {
      section.classList.add("mc-card-shuffler--reduced");
      return;
    }

    var interval = clamp(params.interval || 3000, 800, 20000);
    observeReveal(section, function () {
      global.setInterval(function () {
        var cards = directRenderableChildren(match.container);
        if (cards.length < 2) return;
        match.container.insertBefore(cards[cards.length - 1], cards[0]);
        assignDepth();
      }, interval);
    });
  }

  function applyCardTypewriter(section, params) {
    if (!section || section.dataset.mcCardTypewriterApplied === "true") return;
    var source = section.querySelector("[data-mc-typewriter-source], [data-myron-edit-slot=\"body\"], [data-myron-edit-slot=\"description\"], p");
    if (!source) return;
    var original = (source.textContent || "").trim();
    if (original === "") return;
    var lines = original.split("|").map(function (line) { return line.trim(); }).filter(Boolean);
    if (lines.length === 0) return;
    section.dataset.mcCardTypewriterApplied = "true";

    if (reducedMotion || lines.length === 1) {
      source.textContent = lines[0];
      return;
    }

    var speed = clamp(params.speed || 40, 10, 200);
    var pause = clamp(params.pause || 1200, 300, 6000);
    var eraseSpeed = Math.max(15, Math.round(speed * 0.55));
    section.classList.add("mc-card-typewriter");
    source.classList.add("mc-typewriter");
    source.textContent = "";

    var label = global.document.createElement("span");
    label.className = "mc-typewriter__label";
    label.innerHTML = '<span class="mc-typewriter__dot" aria-hidden="true"></span><span>Live Feed</span>';
    var output = global.document.createElement("span");
    output.className = "mc-typewriter__output";
    var cursor = global.document.createElement("span");
    cursor.className = "mc-typewriter__cursor";
    cursor.setAttribute("aria-hidden", "true");
    cursor.textContent = "|";
    source.appendChild(label);
    source.appendChild(output);
    source.appendChild(cursor);

    observeReveal(section, function () {
      var lineIndex = 0;
      var charIndex = 0;
      var erasing = false;
      function tick() {
        var current = lines[lineIndex];
        if (!erasing) {
          output.textContent = current.slice(0, charIndex + 1);
          charIndex++;
          if (charIndex >= current.length) {
            erasing = true;
            global.setTimeout(tick, pause);
            return;
          }
          global.setTimeout(tick, speed);
          return;
        }
        output.textContent = current.slice(0, Math.max(charIndex - 1, 0));
        charIndex--;
        if (charIndex <= 0) {
          erasing = false;
          lineIndex = (lineIndex + 1) % lines.length;
          global.setTimeout(tick, speed);
          return;
        }
        global.setTimeout(tick, eraseSpeed);
      }
      tick();
    });
  }

  function applyCardProtocolStacker(section) {
    if (!section || section.dataset.mcProtocolStackerApplied === "true") return;
    var match = findCardContainer(section);
    if (!match) return;
    section.dataset.mcProtocolStackerApplied = "true";
    section.classList.add("mc-protocol-stack");
    match.container.classList.add("mc-protocol-stack__cards");
    var cards = directRenderableChildren(match.container);
    match.container.style.setProperty("--mc-protocol-card-count", String(cards.length));
    cards.forEach(function (card, index) {
      card.classList.add("mc-protocol-card");
      card.style.setProperty("--mc-protocol-card-index", String(index));
    });

    if (reducedMotion) {
      section.classList.add("mc-protocol-stack--reduced");
      return;
    }

    function updateStack() {
      var rect = match.container.getBoundingClientRect();
      var step = Math.max(global.innerHeight, 1);
      var active = Math.min(cards.length - 1, Math.max(0, Math.floor((-rect.top + step * 0.45) / step)));
      cards.forEach(function (card, index) {
        card.classList.toggle("mc-protocol-card--buried", index < active);
        card.classList.toggle("mc-protocol-card--active", index === active);
      });
    }

    global.addEventListener("scroll", updateStack, { passive: true });
    global.addEventListener("resize", updateStack);
    updateStack();
  }

  // ─── Site navigation creatives ─────────────────────────────────────────────

  function findFirstBodySection(header) {
    var root = header.closest(".myron-site") || global.document;
    return root.querySelector(".myron-site__canvas section, .myron-site__canvas article, main section, main article");
  }

  function applyFloatingNav(header, params) {
    if (!header || header.dataset.mcNavApplied === "floating-nav") return;
    header.dataset.mcNavApplied = "floating-nav";
    var radius = ["pill", "lg", "md", "sm", "none"].indexOf(params.navRadius) >= 0 ? params.navRadius : "pill";
    header.classList.add("mc-nav--radius-" + radius);
    var hero = findFirstBodySection(header);

    function setScrolled(scrolled) {
      header.classList.toggle("mc-nav--scrolled", !!scrolled);
    }

    function updateFromGeometry() {
      if (!hero) {
        setScrolled(global.scrollY > 8);
        return;
      }
      var rect = hero.getBoundingClientRect();
      setScrolled(rect.bottom <= header.offsetHeight);
    }

    if (hero && global.IntersectionObserver) {
      var observer = new global.IntersectionObserver(function () {
        updateFromGeometry();
      }, { threshold: [0, 0.01, 1] });
      observer.observe(hero);
    }

    global.addEventListener("scroll", updateFromGeometry, { passive: true });
    global.addEventListener("resize", updateFromGeometry);
    updateFromGeometry();
  }

  function applyStickyCompactNav(header) {
    if (!header || header.dataset.mcNavApplied === "sticky-compact-nav") return;
    header.dataset.mcNavApplied = "sticky-compact-nav";
    var hero = findFirstBodySection(header);

    function updateCompact() {
      if (!hero) {
        header.classList.toggle("mc-nav--compact", global.scrollY > 8);
        return;
      }
      var rect = hero.getBoundingClientRect();
      header.classList.toggle("mc-nav--compact", rect.bottom <= header.offsetHeight);
    }

    global.addEventListener("scroll", updateCompact, { passive: true });
    global.addEventListener("resize", updateCompact);
    updateCompact();
  }

  // ─── Site button creatives ────────────────────────────────────────────────

  function findPublicButtons(page) {
    return Array.prototype.slice.call(page.querySelectorAll(".myron-button, .myron-btn")).filter(function (button) {
      return !button.disabled && button.getAttribute("aria-disabled") !== "true";
    });
  }

  function applyMagneticButtons(page, params) {
    if (!page || page.dataset.mcButtonApplied === "btn-magnetic-follow" || reducedMotion) return;
    if (!global.matchMedia || !global.matchMedia("(pointer: fine)").matches) return;

    var buttons = findPublicButtons(page);
    if (buttons.length === 0) return;

    page.dataset.mcButtonApplied = "btn-magnetic-follow";
    var strength = clamp(params.strength || 0.4, 0.1, 0.8);
    var threshold = 140;

    function resetButton(button) {
      button.style.transform = "";
    }

    function onMouseMove(event) {
      buttons.forEach(function (button) {
        var rect = button.getBoundingClientRect();
        var centerX = rect.left + rect.width / 2;
        var centerY = rect.top + rect.height / 2;
        var deltaX = event.clientX - centerX;
        var deltaY = event.clientY - centerY;
        var distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

        if (distance > threshold) {
          resetButton(button);
          return;
        }

        var pull = (1 - distance / threshold) * strength;
        button.style.transform = "translate(" + (deltaX * pull).toFixed(2) + "px, " + (deltaY * pull).toFixed(2) + "px)";
      });
    }

    function onUnload() {
      global.document.removeEventListener("mousemove", onMouseMove);
      buttons.forEach(resetButton);
    }

    global.document.addEventListener("mousemove", onMouseMove, { passive: true });
    global.addEventListener("beforeunload", onUnload, { once: true });
  }

  function applyBorderTraceButtons(page) {
    if (!page || page.dataset.mcButtonApplied === "btn-border-trace" || reducedMotion) return;

    var buttons = findPublicButtons(page);
    if (buttons.length === 0) return;

    page.dataset.mcButtonApplied = "btn-border-trace";
    var namespace = "http://www.w3.org/2000/svg";
    var cleanups = [];

    function numericRadius(value) {
      var match = String(value || "").match(/[0-9.]+/);
      return match ? Number(match[0]) || 0 : 0;
    }

    function syncRect(button, svg, rect) {
      var bounds = button.getBoundingClientRect();
      var width = Math.max(Math.round(bounds.width), 1);
      var height = Math.max(Math.round(bounds.height), 1);
      var radius = Math.min(numericRadius(global.getComputedStyle(button).borderRadius), Math.max(width, height) / 2);
      var inset = 1.5;
      var rectWidth = Math.max(width - inset * 2, 1);
      var rectHeight = Math.max(height - inset * 2, 1);
      var perimeter = (rectWidth + rectHeight) * 2;

      svg.setAttribute("viewBox", "0 0 " + width + " " + height);
      rect.setAttribute("x", String(inset));
      rect.setAttribute("y", String(inset));
      rect.setAttribute("width", String(rectWidth));
      rect.setAttribute("height", String(rectHeight));
      rect.setAttribute("rx", String(Math.max(radius - inset, 0)));
      rect.style.setProperty("--mc-btn-border-trace-length", perimeter.toFixed(2));
    }

    buttons.forEach(function (button) {
      if (button.querySelector(".mc-btn-border-trace-svg")) return;

      var svg = global.document.createElementNS(namespace, "svg");
      var rect = global.document.createElementNS(namespace, "rect");
      var enter = function () { button.classList.add("mc-btn-border-trace--hover"); };
      var leave = function () { button.classList.remove("mc-btn-border-trace--hover"); };
      var resize = function () { syncRect(button, svg, rect); };

      svg.classList.add("mc-btn-border-trace-svg");
      svg.setAttribute("aria-hidden", "true");
      svg.setAttribute("focusable", "false");
      rect.classList.add("mc-btn-border-trace__rect");
      svg.appendChild(rect);
      button.appendChild(svg);
      syncRect(button, svg, rect);

      button.addEventListener("mouseenter", enter);
      button.addEventListener("mouseleave", leave);
      global.addEventListener("resize", resize);
      cleanups.push(function () {
        button.removeEventListener("mouseenter", enter);
        button.removeEventListener("mouseleave", leave);
        global.removeEventListener("resize", resize);
        svg.remove();
      });
    });

    global.addEventListener("beforeunload", function () {
      cleanups.forEach(function (cleanup) { cleanup(); });
    }, { once: true });
  }

  // ─── Dispatch ──────────────────────────────────────────────────────────────

  var motionDispatch = {
    "fade-up":              applyFadeUp,
    "slide-in":             applySlideIn,
    "stagger":              applyStagger,
    "zoom-in":              applyZoomIn,
    "blur-in":              applyBlurIn,
    "flip-up":              applyFlipUp,
    "scale-pop":            applyScalePop,
    "parallax-bg":          applyParallaxBg,
    "count-up":             applyCountUp,
    "text-parallax-scroll": applyTextParallaxScroll,
    "typewriter-headline":  applyTypewriterHeadline,
    "rotate-words":         applyRotateWords,
    "shutter-reveal":       applyShutterReveal,
    "split-lines":          applySplitLines
  };

  var heroDispatch = {
    "scrolljack-hero": applyScrolljackHero
  };

  var navDispatch = {
    "floating-nav": applyFloatingNav,
    "sticky-compact-nav": applyStickyCompactNav
  };

  var buttonDispatch = {
    "btn-magnetic-follow": applyMagneticButtons,
    "btn-border-trace": applyBorderTraceButtons
  };

  function init() {
    var motionSections = global.document.querySelectorAll("[data-mc-motion]");
    var sceneSections  = global.document.querySelectorAll("[data-mc-scene]");
    var behaviorSections = global.document.querySelectorAll("[data-mc-hero], [data-myron-component-id]");
    var navHeaders     = global.document.querySelectorAll("[data-mc-nav-style]");
    var buttonPages    = global.document.querySelectorAll("[data-mc-btn-style]");

    motionSections.forEach(function (section) {
      var profile = section.getAttribute("data-mc-motion");
      var params  = parseParams(section);
      var fn = motionDispatch[profile];
      if (typeof fn === "function") {
        fn(section, params);
      }
    });

    sceneSections.forEach(function (section) {
      var sceneId = section.getAttribute("data-mc-scene");
      var params  = parseParams(section);
      injectScene(section, sceneId, params);
    });

    behaviorSections.forEach(function (section) {
      var params = parseParams(section);
      var heroId = section.getAttribute("data-mc-hero") || section.getAttribute("data-myron-component-id") || "";
      var heroFn = heroDispatch[heroId];
      if (typeof heroFn === "function") {
        heroFn(section, params);
      }
      var componentId = section.getAttribute("data-myron-component-id") || "";
      var behaviorId = behaviors[componentId] ? componentId : (behaviors[heroId] ? heroId : "");
      if (behaviorId !== "") {
        behaviors[behaviorId](section, params);
      }
    });

    navHeaders.forEach(function (header) {
      var navStyle = header.getAttribute("data-mc-nav-style") || "";
      var navFn = navDispatch[navStyle];
      if (typeof navFn === "function") {
        navFn(header, parseJsonAttr(header, "data-mc-nav-params"));
      }
    });

    buttonPages.forEach(function (page) {
      var buttonStyle = page.getAttribute("data-mc-btn-style") || "";
      var buttonFn = buttonDispatch[buttonStyle];
      if (typeof buttonFn === "function") {
        buttonFn(page, parseJsonAttr(page, "data-mc-btn-params"));
      }
    });

    if (parallaxSections.length > 0 || particleInstances.length > 0) {
      startRaf();
    }
  }

  registerBehavior("scrolljack-hero", applyScrolljackHero);
  registerBehavior("card-shuffler", applyCardShuffler);
  registerBehavior("card-typewriter", applyCardTypewriter);
  registerBehavior("card-protocol-stacker", applyCardProtocolStacker);

  // ─── Boot ──────────────────────────────────────────────────────────────────

  if (global.document.readyState === "loading") {
    global.document.addEventListener("DOMContentLoaded", init, { once: true });
  } else {
    init();
  }

  global.mcRuntime = { registerBehavior: registerBehavior };

}(window));
