/* spotlight: one light for a grid of cards (edge, wash, reveal). effect.js writes where the pointer is on each card
   (--_x, --_y) and puts one layer in each card (i.fx-spot__light); this file holds the knobs and draws the light.
   The cards themselves stay the site's. Every rule sits in :where(), so any rule of the page wins. */

:where([data-fx~="spotlight"]) {
  /* knobs */
  --spot-size: 300px;              /* the light's radius */
  --spot-color: var(--fx-tint);    /* the light's color: the brand as it reads on this ground */
  --spot-strength: 0.16;           /* wash: 0 to 0.5, the light on the cards' faces (times the site's --fx-energy; lowered by itself to keep the text readable) */
  --spot-edge: 1.5px;              /* edge: the lit border's width */
  --spot-cell: 18px;               /* reveal: the pattern's pitch (the mark is drawn at this size) */
  --spot-ink: 0.3;                 /* reveal: 0 to 1, how strongly the pattern is drawn (lowered by itself to keep the text readable) */
}
:where([data-fx~="spotlight"]) :where([data-spot]) {
  position: relative;
  isolation: isolate;
  /* where the light rests when no pointer sets it: near one corner */
  --_x: 22%;
  --_y: 0%;
}
/* The keyboard's focus puts the light on the focused card, from the middle of its top edge. */
:where([data-fx~="spotlight"]) :where([data-spot]:is(:focus-visible, :has(:focus-visible))) { --_x: 50%; --_y: 0%; }

:where(.fx-spot__light) {
  position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  opacity: 0;
  transition: opacity var(--fx-med) linear;
}
:where([data-fx~="spotlight"][data-spot-on]) :where(.fx-spot__light),
:where([data-fx~="spotlight"]) :where([data-spot]:is(:focus-visible, :has(:focus-visible))) > :where(.fx-spot__light) {
  opacity: 1;
  transition-duration: var(--fx-fast);
}

/* edge: a ring as wide as --spot-edge just inside the card's border, lit where the pointer is near. */
:where([data-fx~="spotlight"]:not([data-fx-preset]), [data-fx~="spotlight"][data-fx-preset="edge"]) :where(.fx-spot__light) {
  z-index: 4;
  padding: var(--spot-edge);
  background: radial-gradient(circle var(--spot-size) at var(--_x) var(--_y), var(--spot-color), transparent 72%);
  -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);
}

/* wash: a pool of light on the card's face, under its words. --_a is the strength the script found safe (--_ink is
   the same for reveal's pattern). */
:where([data-fx~="spotlight"][data-fx-preset="wash"]) :where(.fx-spot__light) {
  z-index: -1;
  background: radial-gradient(circle var(--spot-size) at var(--_x) var(--_y), color-mix(in srgb, var(--spot-color) calc(var(--_a, 0.08) * 100%), transparent), transparent 72%);
}

/* reveal: a pattern in the light's color, seen only inside the light. Two masks: the light, and the pattern.
   A pattern with one layer fills the other with a clear gradient, never with none: Firefox draws nothing at all
   when one layer of a mask is none. */
:where([data-fx~="spotlight"][data-fx-preset="reveal"]) {
  --_none: linear-gradient(#0000 0 0);
  --_p1: radial-gradient(circle at 50% 50%, #000 1.3px, transparent 2px);
  --_p2: var(--_none);
}
:where([data-fx~="spotlight"][data-fx-preset="reveal"][data-spot-pattern="grid"]) {
  --_p1: linear-gradient(#000 1px, transparent 1px);
  --_p2: linear-gradient(90deg, #000 1px, transparent 1px);
}
:where([data-fx~="spotlight"][data-fx-preset="reveal"][data-mark]) {
  --_p1: var(--_mark, var(--_none));
  --_p2: var(--_none);
}
:where([data-fx~="spotlight"][data-fx-preset="reveal"]) :where(.fx-spot__light) {
  z-index: -1;
  background-color: color-mix(in srgb, var(--spot-color) calc(var(--_ink, 0.2) * 100%), transparent);
  -webkit-mask-image: radial-gradient(circle var(--spot-size) at var(--_x) var(--_y), #000, transparent 72%), var(--_p1), var(--_p2);
  -webkit-mask-size: auto, var(--spot-cell) var(--spot-cell), var(--spot-cell) var(--spot-cell);
  -webkit-mask-composite: source-in, source-over;
  mask-image: radial-gradient(circle var(--spot-size) at var(--_x) var(--_y), #000, transparent 72%), var(--_p1), var(--_p2);
  mask-size: auto, var(--spot-cell) var(--spot-cell), var(--spot-cell) var(--spot-cell);
  mask-composite: intersect, add;
}

/* A touch screen has no pointer to follow: the light rests at one corner of each card. */
@media (hover: none) {
  :where(.fx-spot__light) { opacity: 0.85; }
}
/* Reduced motion: nothing follows the pointer (the script does not listen). The light rests at each card's corner
   and comes to the middle of the card under the pointer or the focus, at once. */
@media (prefers-reduced-motion: reduce) {
  :where(.fx-spot__light) { opacity: 0.6; transition: none; }
  :where([data-fx~="spotlight"]) :where([data-spot]:hover) { --_x: 50%; --_y: 0%; }
  :where([data-fx~="spotlight"]) :where([data-spot]:is(:hover, :focus-visible, :has(:focus-visible))) > :where(.fx-spot__light) { opacity: 1; }
}
/* Windows' high contrast: no light. */
@media (forced-colors: active) {
  :where(.fx-spot__light) { display: none; }
}
