/* SUDX controls: the button and the theme toggle, in every state. One file
   serves the site and every product that adopts the controls, so a change here
   reaches both. Load it after sudx-tokens.css. */
.sudx-button,
.sudx-theme-toggle {
  appearance: none;
  min-width: var(--sudx-target-min);
  min-height: var(--sudx-target-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sudx-space-2);
  border: 1px solid var(--sudx-border);
  border-radius: var(--sudx-radius);
  padding: 0 var(--sudx-space-4);
  font: var(--sudx-weight-medium) var(--sudx-size-body-md)/1 var(--sudx-font-sans);
  text-decoration: none;
  box-shadow: var(--sudx-shadow-active);
  cursor: pointer;
  /* Controls resolve between states instead of snapping. */
  transition:
    background-color var(--sudx-transition-control),
    border-color var(--sudx-transition-control),
    color var(--sudx-transition-control),
    box-shadow var(--sudx-transition-control),
    transform var(--sudx-transition-control);
}

.sudx-button--primary {
  border-color: var(--sudx-text);
  background: var(--sudx-text);
  color: var(--sudx-background);
}

.sudx-button--secondary,
.sudx-theme-toggle {
  background: var(--sudx-surface);
  color: var(--sudx-text);
}

/* Hover lifts ink a step toward the ground; clay is kept for links, focus and
   selection. */
.sudx-button--primary:hover {
  border-color: color-mix(in srgb, var(--sudx-text) 82%, var(--sudx-background));
  background: color-mix(in srgb, var(--sudx-text) 82%, var(--sudx-background));
}

.sudx-button--secondary:hover,
.sudx-theme-toggle:hover {
  border-color: var(--sudx-border-strong);
  background: var(--sudx-surface-quiet);
}

/* The marketing call to action: the same button as a full pill. */
.sudx-button--pill {
  border-radius: var(--sudx-radius-pill);
  padding-inline: var(--sudx-space-5);
}

.sudx-button:active,
.sudx-theme-toggle:active {
  transform: translateY(1px);
  box-shadow: none;
}

/* Unavailable recedes below the secondary button: a quiet well with a dashed
   edge, never a faded fill that can read brighter than the controls beside
   it. */
.sudx-button:disabled,
.sudx-button[aria-disabled="true"] {
  border-style: dashed;
  border-color: var(--sudx-border-strong);
  background: var(--sudx-surface-quiet);
  color: var(--sudx-text-tertiary);
  box-shadow: none;
  cursor: not-allowed;
}

/* The theme toggle is a circle: the glyph carries the meaning and the label
   stays for the accessibility tree, so the button never takes label width. */
.sudx-theme-toggle {
  width: var(--sudx-target-min);
  border-radius: var(--sudx-radius-pill);
  padding: 0;
}

.sudx-theme-toggle [data-theme-label] {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The half-moon shows the theme the press delivers, so it turns over when the
   dark theme is already in force. site.js sets aria-pressed=true in dark. */
.sudx-theme-toggle [aria-hidden="true"] {
  display: inline-block;
  transition: transform 260ms cubic-bezier(0.2, 0, 0.1, 1);
}

.sudx-theme-toggle[aria-pressed="true"] [aria-hidden="true"] {
  transform: rotate(180deg);
}

:where(.sudx-button, .sudx-theme-toggle):focus-visible {
  outline: 2px solid var(--sudx-accent);
  outline-offset: 2px;
}

/* Loading. A band of the SUDX 4x4 Bayer field (2px cells, 8px tile) sweeps across
   the control while it waits. Built from a CSS mask, so it inherits the button
   color and themes with it; no image, no WebGL. The label stays readable. */
.sudx-button[aria-busy="true"] {
  position: relative;
  cursor: progress;
  pointer-events: none;
}

.sudx-button[aria-busy="true"] > span {
  opacity: 0.62;
}

.sudx-button[aria-busy="true"]::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: currentColor;
  opacity: 0.9;
  -webkit-mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8' fill='%23000'><rect x='0' y='0' width='2' height='2'/><rect x='2' y='0' width='2' height='2'/><rect x='4' y='0' width='2' height='2'/><rect x='2' y='2' width='2' height='2'/><rect x='6' y='2' width='2' height='2'/><rect x='0' y='4' width='2' height='2'/><rect x='4' y='4' width='2' height='2'/><rect x='6' y='4' width='2' height='2'/><rect x='2' y='6' width='2' height='2'/><rect x='6' y='6' width='2' height='2'/></svg>"), linear-gradient(90deg, transparent 0%, #000 38%, #000 62%, transparent 100%);
  mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8' fill='%23000'><rect x='0' y='0' width='2' height='2'/><rect x='2' y='0' width='2' height='2'/><rect x='4' y='0' width='2' height='2'/><rect x='2' y='2' width='2' height='2'/><rect x='6' y='2' width='2' height='2'/><rect x='0' y='4' width='2' height='2'/><rect x='4' y='4' width='2' height='2'/><rect x='6' y='4' width='2' height='2'/><rect x='2' y='6' width='2' height='2'/><rect x='6' y='6' width='2' height='2'/></svg>"), linear-gradient(90deg, transparent 0%, #000 38%, #000 62%, transparent 100%);
  -webkit-mask-size: 8px 8px, 55% 100%;
  mask-size: 8px 8px, 55% 100%;
  -webkit-mask-repeat: repeat, no-repeat;
  mask-repeat: repeat, no-repeat;
  -webkit-mask-composite: source-in;
  mask-composite: intersect;
  animation: sudx-dither-sweep 1.15s linear infinite;
}

@keyframes sudx-dither-sweep {
  from {
    -webkit-mask-position: 0 0, -60% 0;
    mask-position: 0 0, -60% 0;
  }
  to {
    -webkit-mask-position: 0 0, 160% 0;
    mask-position: 0 0, 160% 0;
  }
}

/* Reduced motion holds a static, lower-density Bayer field: still clearly busy,
   no travel. */
@media (prefers-reduced-motion: reduce) {
  .sudx-button[aria-busy="true"]::after {
    -webkit-mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8' fill='%23000'><rect x='0' y='0' width='2' height='2'/><rect x='4' y='0' width='2' height='2'/><rect x='2' y='2' width='2' height='2'/><rect x='0' y='4' width='2' height='2'/><rect x='4' y='4' width='2' height='2'/><rect x='6' y='6' width='2' height='2'/></svg>");
    mask-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8' fill='%23000'><rect x='0' y='0' width='2' height='2'/><rect x='4' y='0' width='2' height='2'/><rect x='2' y='2' width='2' height='2'/><rect x='0' y='4' width='2' height='2'/><rect x='4' y='4' width='2' height='2'/><rect x='6' y='6' width='2' height='2'/></svg>");
    -webkit-mask-size: 8px 8px;
    mask-size: 8px 8px;
    animation: none;
    opacity: 0.5;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sudx-button,
  .sudx-theme-toggle,
  .sudx-theme-toggle [aria-hidden="true"] {
    transition-duration: 0.01ms;
  }
}
