/* magnetic: the main button answers the pointer (pull, fill, halo). The motion is effect.js's; this file holds the
   knobs and draws the two layers the script puts inside the button (the fill, the halo). The button's own look, its
   hover colors and its press stay the site's. Every rule sits in :where(), so any rule of the page wins. */

:where([data-fx~="magnetic"]) {
  /* knobs */
  --magnetic-pull: 10;              /* pull: how far the button leans at most, in px, times the site's --fx-energy */
  --magnetic-radius: 60;            /* pull, halo: how far around the button it starts to answer, in px */
  --magnetic-label: 0.4;            /* pull: how much further the label leans, as a share of the button's own lean */
  --magnetic-stiffness: 230;        /* pull: the spring's pull back (times the site's --fx-pace, squared) */
  --magnetic-damping: 23;           /* pull: the spring's brake; lower swings more */
  --magnetic-dur: var(--fx-med);    /* fill: how long the fill takes, divided by the site's --fx-pace */
  --magnetic-size: 120px;           /* halo: the light's radius */
  --magnetic-glow: var(--fx-act);   /* halo: the light's color (a pale shade of it on the button, itself around it) */
  --magnetic-wash: 0.2;             /* halo: the light on the button's face, 0 to 0.3; lowered by itself to keep the label readable */
  /* --magnetic-fill and --magnetic-fill-on (fill): the fill's color and the label's color on it. Left unset, they are
     the part's own text color and the part's own ground, which read on each other as the part's text does. */
  position: relative;
  isolation: isolate;
}

/* pull: what is in the button leans a little further than the button (the script writes --_lx and --_ly). */
:where([data-fx~="magnetic"][data-fx-ready~="magnetic"]) > :where(:not(.fx-magnetic__layer)) { translate: var(--_lx, 0px) var(--_ly, 0px); }

/* The layers: over the button's own ground and border, under its label. */
:where(.fx-magnetic__layer) { position: absolute; inset: 0; z-index: -1; border-radius: inherit; pointer-events: none; }

/* fill: a circle that grows from where the pointer came in (--_ex, --_ey) to cover the button (--_d across). */
:where(.fx-magnetic__fill) { overflow: hidden; }
:where(.fx-magnetic__fill) > :where(i) {
  position: absolute; left: var(--_ex, 50%); top: var(--_ey, 50%); width: var(--_d, 240%); aspect-ratio: 1; border-radius: 50%;
  background: var(--_fill, var(--fx-on));
  transform: translate(-50%, -50%) scale(0);
  transition: transform calc(var(--magnetic-dur) / var(--fx-pace, 1)) var(--fx-ease);
}
:where([data-magnetic-in]) > :where(.fx-magnetic__fill) > :where(i) { transform: translate(-50%, -50%) scale(1); }

/* halo: a light at the pointer (--_hx, --_hy), as strong as the pointer is near (--_near): on the face, along the edge
   and around the button. A hover or the keyboard's focus alone lights it from the middle. */
:where([data-fx~="magnetic"][data-fx-preset="halo"]) { --_light: color-mix(in srgb, var(--magnetic-glow) 35%, var(--c-paper, #fff)); }
:where([data-fx~="magnetic"][data-fx-preset="halo"]:is(:hover, :focus-visible):not(:disabled, [aria-disabled="true"])) { --_near: 1; }
:where(.fx-magnetic__halo, .fx-magnetic__rim) { opacity: var(--_near, 0); transition: opacity var(--fx-fast) linear; }
:where(.fx-magnetic__halo) {
  background: radial-gradient(circle var(--magnetic-size) at var(--_hx, 50%) var(--_hy, 50%), color-mix(in srgb, var(--_light) calc(var(--_wash, 0.1) * 100%), transparent), transparent 72%);
  box-shadow: var(--_gx, 0px) var(--_gy, 0px) 28px -6px color-mix(in srgb, var(--magnetic-glow) 75%, transparent);
}
:where(.fx-magnetic__rim) {
  padding: 1.5px;
  background: radial-gradient(circle calc(var(--magnetic-size) * 0.8) at var(--_hx, 50%) var(--_hy, 50%), var(--_light), transparent 78%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}

/* Reduced motion: nothing follows the pointer (the script does not listen); fill and halo answer at once. */
@media (prefers-reduced-motion: reduce) {
  :where(.fx-magnetic__fill) > :where(i), :where(.fx-magnetic__halo, .fx-magnetic__rim) { transition: none; }
}
/* Windows' high contrast: the system draws the button. */
@media (forced-colors: active) {
  :where(.fx-magnetic__layer) { display: none; }
}
