/* motion/thread.css — the thread (motion/thread.mjs). Load it only on pages that use data-m-thread.
   Tokens only. The page may set, on the run or above it:
     --m-thread-lane    where the line runs (default 50%; put it in the gutter on narrow screens)
     --m-thread-color   the line and its head (default the theme accent) */
[data-m-thread] {
  --_c: var(--m-thread-color, var(--ds-accent));
  position: relative; isolation: isolate;
}
/* everything the page puts in a run sits above the line; rings and the head sit above that */
[data-m-thread] > :not(.m-thread__svg, .m-thread__head, .m-thread__lane) { position: relative; z-index: 1; }
.m-thread__lane { position: absolute; top: 0; left: var(--m-thread-lane, 50%); width: 0; height: 0; pointer-events: none; }
.m-thread__svg { position: absolute; top: 0; left: 0; z-index: 0; overflow: visible; pointer-events: none; }
.m-thread__svg--over { z-index: 2; }
.m-thread__svg path { fill: none; stroke: var(--_c); stroke-linecap: round; stroke-linejoin: round; }
.m-thread__core { stroke-width: 2.5px; }
.m-thread__halo { stroke-width: 6px; opacity: .18; }
.m-thread__halo--wide { stroke-width: 13px; opacity: .08; }

/* the head: a small lit square with a wide soft glow */
.m-thread__head {
  position: absolute; top: 0; left: 0; z-index: 3; width: 12px; height: 12px; margin: -6px 0 0 -6px;
  border-radius: 2px; background: var(--_c); opacity: 0; pointer-events: none; will-change: transform, opacity;
}
.m-thread__head::before {
  content: ""; position: absolute; top: 50%; left: 50%; width: 260px; height: 260px; margin: -130px 0 0 -130px; border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--_c) 30%, transparent) 0%, color-mix(in srgb, var(--_c) 9%, transparent) 42%, transparent 70%);
}
.m-thread__head::after { content: ""; position: absolute; inset: 3px; background: color-mix(in srgb, var(--_c) 22%, var(--ds-ink)); }
@media (prefers-reduced-motion: reduce) { .m-thread__head { display: none; } }

/* the knot: three cards the tangle weaves through; thread.mjs moves them and sets --m-knot-face 0 → 1 */
[data-m-thread-knot] { position: relative; }
[data-m-thread-knot] > :not(.m-thread__svg, .m-thread__head, .m-knot__exit) { z-index: 1; }
[data-m-knot-card] { display: grid; }
[data-m-knot-on] [data-m-knot-card] { position: absolute; top: 0; left: 0; width: var(--m-knot-card, 31%); will-change: transform; }
[data-m-knot-before], [data-m-knot-after] { grid-area: 1 / 1; align-self: start; min-width: 0; }
[data-m-knot-before] { opacity: clamp(0, calc(1 - var(--m-knot-face, 0) * 1.6), 1); }
[data-m-knot-after] { opacity: var(--m-knot-face, 0); }
.m-knot__exit { position: absolute; left: 0; bottom: 0; width: 0; height: 0; }
/* no script: the knot shows its finished cards in the page's own flow (give [data-m-thread-knot] a grid) */
[data-m-thread-knot]:not([data-m-knot-on]) { --m-knot-face: 1; }
