/*
 * Page-load spinner — pure CSS, no JavaScript.
 *
 * How it works: clicking a link or button gives it focus (Chrome, Edge, Firefox), and it keeps
 * focus until the next page replaces this one. :focus:not(:focus-visible) means "focused by a
 * mouse/touch click" (keyboard Tab focus is :focus-visible, so tabbing never triggers it).
 * While such an element exists, :root:has() shows a blurred overlay with a spinning ring.
 *
 * Excluded: in-page anchors (#download, #close…), mailto:/tel:, new-tab links, disabled buttons,
 * and submit buttons of forms that fail HTML validation (the browser shows its own bubble and
 * never navigates). Clicking the overlay moves focus away, so it can never get stuck.
 * The overlay waits 150 ms before appearing, so instant page loads don't flash.
 */

:root:has(
  a[href]:not([href^="#"]):not([href^="mailto:"]):not([href^="tel:"]):not([target="_blank"]):not([download]):focus:not(:focus-visible),
  button:not(:disabled):not([aria-disabled="true"]):not(form:invalid button):focus:not(:focus-visible)
) {
  cursor: progress;
}

/* soft frosted backdrop (also swallows double-clicks → no duplicate submissions) */
:root:has(
  a[href]:not([href^="#"]):not([href^="mailto:"]):not([href^="tel:"]):not([target="_blank"]):not([download]):focus:not(:focus-visible),
  button:not(:disabled):not([aria-disabled="true"]):not(form:invalid button):focus:not(:focus-visible)
)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 2147483646;
  background: rgba(245, 247, 252, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  cursor: progress;
  animation: lm-fade-in 0.2s ease-out 0.15s both;
}

/* the gradient ring */
:root:has(
  a[href]:not([href^="#"]):not([href^="mailto:"]):not([href^="tel:"]):not([target="_blank"]):not([download]):focus:not(:focus-visible),
  button:not(:disabled):not([aria-disabled="true"]):not(form:invalid button):focus:not(:focus-visible)
)::after {
  content: "";
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 2147483647;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(79, 70, 229, 0) 0deg, #4f46e5 140deg, #7c3aed 250deg, #06b6d4 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  filter: drop-shadow(0 6px 18px rgba(79, 70, 229, 0.35));
  pointer-events: none;
  animation: lm-fade-in 0.2s ease-out 0.15s both, lm-spin 0.8s linear infinite;
}

@keyframes lm-spin {
  to { transform: rotate(360deg); }
}

@keyframes lm-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Loading feedback is essential motion — keep it, just calmer. */
@media (prefers-reduced-motion: reduce) {
  :root:has(
    a[href]:not([href^="#"]):not([href^="mailto:"]):not([href^="tel:"]):not([target="_blank"]):not([download]):focus:not(:focus-visible),
    button:not(:disabled):not([aria-disabled="true"]):not(form:invalid button):focus:not(:focus-visible)
  )::after {
    animation: lm-fade-in 0.2s ease-out 0.15s both, lm-spin 1.6s linear infinite;
  }
}

@media print {
  :root::before, :root::after { display: none !important; }
}
