/* Highlight Button: a vanilla port of radiumcoders' "Highlight Button" on 21st.dev (MIT).
   A soft blurred spot follows the pointer, a 1px border fades in on hover, and a click bursts an
   elliptical ripple from the click point. Decorates an existing <button> or <a class="button">; the
   effect layers are aria-hidden and ignore the pointer. Values below are the original's compiled ones.

   Per-instance colours arrive as custom properties set from highlight-button.js (CSSOM, CSP-safe):
     --fx-hl-color / --fx-hl-color-dark     the spot and ripple colour
     --fx-hl-border / --fx-hl-border-dark   the hover border colour
     --fx-hl-size                           the spot diameter (original: 56px)
   Unset, they fall back to the original defaults: currentColor at 55% and 58%. */

/* Zero-specificity defaults so the host's own rules win (position, border width/colour at rest). */
:where(.fx-highlight) {
  position: relative;
  border: 1px solid transparent; /* the original adds a 1px border on hover; reserving it here avoids a 2px layout jump */
  box-shadow: 0 1px 3px 0 #0000001a, 0 1px 2px -1px #0000001a; /* Tailwind shadow-sm, as on the original; a host shadow wins */
}

.fx-highlight {
  --fx-hl-c: var(--fx-hl-color, color-mix(in oklab, currentColor 55%, transparent));
  --fx-hl-b: var(--fx-hl-border, color-mix(in oklab, currentColor 58%, transparent));
  isolation: isolate; /* the layers sit at z-index -1: above the host's background, below its text */
  overflow: hidden;
  /* transition-[border-color,box-shadow,transform] 150ms cubic-bezier(.4,0,.2,1); background kept for hosts that fade it.
     The border snaps off on leave (the original drops its border width), so border-color only eases in. */
  transition-property: border-color, box-shadow, transform, background-color;
  transition-duration: 0s, 150ms, 150ms, 150ms;
  transition-timing-function: cubic-bezier(.4, 0, .2, 1);
}

/* Dark theme: explicit data-theme="dark", or the system preference when the page is not pinned to light. */
:root[data-theme="dark"] .fx-highlight {
  --fx-hl-c: var(--fx-hl-color-dark, var(--fx-hl-color, color-mix(in oklab, currentColor 55%, transparent)));
  --fx-hl-b: var(--fx-hl-border-dark, var(--fx-hl-border, color-mix(in oklab, currentColor 58%, transparent)));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .fx-highlight {
    --fx-hl-c: var(--fx-hl-color-dark, var(--fx-hl-color, color-mix(in oklab, currentColor 55%, transparent)));
    --fx-hl-b: var(--fx-hl-border-dark, var(--fx-hl-border, color-mix(in oklab, currentColor 58%, transparent)));
  }
}

/* Hover (pointer), touch press, and keyboard focus all light the border. */
.fx-highlight.is-hl-on,
.fx-highlight:focus-visible {
  border-color: var(--fx-hl-b);
  transition-duration: 150ms;
}

/* The effect layer: fills the padding box behind the content. */
.fx-hl {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

/* The original's always-on wash: bg-current/[0.04]. */
.fx-hl__wash {
  position: absolute;
  inset: 0;
  background-color: color-mix(in oklab, currentColor 4%, transparent);
}

/* The spot: 56px circle, blur(24px), centred on the pointer. It pops in and out with no fade, as in the original. */
.fx-hl__glow {
  position: absolute;
  left: var(--fx-hl-x, 50%);
  top: var(--fx-hl-y, 50%);
  inline-size: var(--fx-hl-size, 56px);
  block-size: var(--fx-hl-size, 56px);
  border-radius: 9999px;
  background-color: var(--fx-hl-c);
  filter: blur(24px);
  transform: translate(-50%, -50%);
  transition: transform 100ms cubic-bezier(0, 0, .2, 1);
  opacity: 0;
}
.fx-highlight.is-hl-on:not(.is-hl-clicked) .fx-hl__glow { opacity: 1; }

/* Keyboard focus without a pointer on it: the spot rests at the centre. */
.fx-highlight:focus-visible:not(.is-hl-on):not(.is-hl-clicked) .fx-hl__glow {
  left: 50%;
  top: 50%;
  opacity: 1;
}

/* The click ripple: an ellipse growing from 0 to 200% of the button while fading out, 0.6s ease-out. */
.fx-hl__ripple {
  position: absolute;
  left: var(--fx-hl-rx, 50%);
  top: var(--fx-hl-ry, 50%);
  inline-size: 0;
  block-size: 0;
  border-radius: 9999px;
  background-color: var(--fx-hl-c);
  transform: translate(-50%, -50%);
  animation: fx-hl-ripple .6s ease-out forwards;
}
@keyframes fx-hl-ripple {
  0% { opacity: 1; inline-size: 0; block-size: 0; }
  to { opacity: 0; inline-size: 200%; block-size: 200%; }
}

/* RTL: left/top above are physical pointer coordinates measured from the box's left edge, so they stay
   correct when the page is mirrored; nothing else here depends on direction. */

/* Reduced motion: a calm still version. The spot rests at the centre and does not follow; no ripple. */
@media (prefers-reduced-motion: reduce) {
  .fx-highlight { transition-duration: 0s; }
  .fx-highlight .fx-hl__glow { left: 50%; top: 50%; transition: none; }
  .fx-highlight.is-hl-clicked.is-hl-on .fx-hl__glow { opacity: 1; }
  .fx-hl__ripple { display: none; }
}
