/* Public controls share a short interaction cue; existing component colors and layout stay in charge. */
:root {
  --kld-control-edge: #268b81;
  --kld-control-glow: rgba(16, 139, 125, .17);
  --kld-control-focus: #086d78;
  --kld-control-shadow: rgba(17, 71, 71, .16);
}
:root[data-theme="dark"], .ps-footer, .ip-footer {
  --kld-control-edge: #77dbcc;
  --kld-control-glow: rgba(74, 207, 187, .24);
  --kld-control-focus: #9ceee5;
  --kld-control-shadow: rgba(0, 20, 22, .3);
}
@media (prefers-color-scheme: dark) {
  .kld-guide, :root:not([data-theme]) .ed {
    --kld-control-edge: #77dbcc;
    --kld-control-glow: rgba(74, 207, 187, .24);
    --kld-control-focus: #9ceee5;
  }
}

/* Only operable controls take feedback. Keep the existing hit boxes, menu panels and tooltip anchors. */
/* Use nesting so every input modality and disabled-state guard uses the same selector. */
body :is(button, input:is([type="submit"], [type="button"], [type="reset"]), [role="button"], [role="tab"], summary,
  .kl-choice, .kld-guide .regions a, .kld-guide .language-grid a, .kld-guide .action,
  a:is(.button, .primary, .secondary, .ps-join, .pf-primary, .pf-outline, .pf-text-link, .rt-primary, .mc-primary,
    .cb-primary, .pdir-action, .cr-action, .cr-secondary, .ed-project, .ps-icon, .bn-action, .pf-doc-action,
    .ps-signin, .mc-text-link, .md-prefill, .fo-link),
  .ip-links a, .ed-controls a, .ed-source a, .ed-share a, .kld-footer-share a,
  .ps-nav > a, .ip-nav > a, .ed-primary > a, .bn-sections a, .bn-pages a):not(:disabled, [disabled], [aria-disabled="true"], [inert] *, .kl-choice:has(:disabled)) {
  &:focus-visible {
    outline: 2px solid var(--kld-control-focus);
    outline-offset: 3px;
  }
  @media (prefers-reduced-motion: reduce) {
    transition-duration: 0s;
  }
  @media screen and (pointer: coarse) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(39, 163, 143, .22);
  }
  @media screen and (hover: hover) and (pointer: fine) {
    &:hover {
      box-shadow: inset 0 -2px 0 var(--kld-control-edge), inset 0 0 0 1px var(--kld-control-glow);
    }
  }
  @media screen and (prefers-reduced-motion: no-preference) {
    transition: box-shadow 180ms ease-out, background-color 160ms ease-out, border-color 160ms ease-out,
      color 160ms ease-out, translate 150ms ease-out, scale 110ms ease-out;
  }
  &:active {
    box-shadow: inset 0 0 0 2px var(--kld-control-edge);
  }
}

/* A single scan and a short row of illuminated ticks mark high-emphasis actions. */
:is(.ps-join, .pf-primary, .mc-primary, .cb-primary, .rt-primary, .ka-submit, .kl-save, .ed-project, .kld-guide .action) {
  position: relative;
  @media screen and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
    &:not(:disabled, [aria-disabled="true"]):hover {
      translate: 0 -2px;
      box-shadow: inset 0 -2px 0 var(--kld-control-edge), 0 3px 9px var(--kld-control-shadow);
    }
    &:not(:disabled, [aria-disabled="true"]):hover::after {
      content: "";
      position: absolute;
      pointer-events: none;
      inset: 0;
      border-radius: inherit;
      background-image: linear-gradient(105deg, transparent 38%, rgba(124, 255, 226, .11) 47%,
        rgba(215, 255, 246, .32) 50%, transparent 57%),
        repeating-linear-gradient(90deg, rgba(152, 245, 225, .74) 0 2px, transparent 2px 5px);
      background-repeat: no-repeat;
      background-size: 75% 100%, 20px 1px;
      animation: kld-control-scan 440ms ease-out both;
    }
    &:not(:disabled, [aria-disabled="true"]):active { translate: 0 0; }
  }
}
@keyframes kld-control-scan {
  from { background-position: -310% 0, 12% calc(100% - 3px); opacity: 0; }
  22% { opacity: 1; }
  74% { opacity: 1; }
  to { background-position: 420% 0, 88% calc(100% - 3px); opacity: 0; }
}

@media screen and (hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference) {
  :is(.ed-share a, .kld-footer-share a, .ps-icon, .kl-close, .bn-action) > svg {
    transition: translate 160ms ease-out;
  }
  :is(.ed-share a, .kld-footer-share a, .ps-icon, .kl-close, .bn-action):not(:disabled,[aria-disabled="true"]):hover > svg {
    translate: 0 -1.5px;
  }
}
@media screen and (hover: none) and (prefers-reduced-motion: no-preference) {
  :is(button, .ps-join, .pf-primary, .kld-guide .action, .ed-share a, .kld-footer-share a):not(:disabled,[aria-disabled="true"]):active {
    scale: .98;
  }
}
@media (forced-colors: active) {
  body :is(button, input[type="submit"], [role="tab"], [role="button"], summary, a[href]):focus-visible {
    outline: 2px solid Highlight;
    outline-offset: 3px;
  }
}
