[data-selection] {
  position: relative;
  isolation: isolate;
  --selection-fill: var(--color-primary-soft);
  --selection-border: transparent;
}

.choices, .segmented {
  --selection-fill: var(--color-surface);
  --selection-border: var(--color-border);
}

[data-selection]:not([data-selection-ready]) > :is([aria-current="page"], [aria-pressed="true"], [aria-selected="true"], label:has(input:checked), li:has(input:checked)) {
  background: var(--selection-fill);
}

[data-selection-ready]::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  z-index: -1;
  pointer-events: none;
  box-sizing: border-box;
  width: var(--selection-width);
  height: var(--selection-height);
  border: 1px solid var(--selection-border);
  border-radius: var(--radius-control);
  background: var(--selection-fill);
  transform: translate(var(--selection-x), var(--selection-y));
}

[data-selection-ready]:not([data-selection-resizing])::before {
  transition: transform var(--motion-base) var(--motion-ease),
    width var(--motion-base) var(--motion-ease),
    height var(--motion-base) var(--motion-ease);
}

.main-nav[data-selection-ready] > :is(a[aria-current="page"], button[aria-pressed="true"]) { background: transparent; }

/* Prevent gray active border/background flash before the sliding indicator glides over */
[data-selection] > :is(button, a):active:not(:disabled) {
  border-color: transparent;
  background: transparent;
}
[data-selection] > :is(button, a):focus:not(:focus-visible) {
  outline: none;
}

@media (forced-colors: active) {
  [data-selection-ready]::before { border-color: Highlight; }
}
