// A hidden screen reader texts for readers, focus elements for
// vision impaired and other useful a11y CSS hacks.

// Text meant only for screen readers.
%screen-reader-text,
.screen-reader-text {
  border: 0;
  clip: rect(1px, 1px, 1px, 1px);
  // doiuse-disable
  clip-path: inset(50%);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;

  // Many screen reader and browser combinations announce broken words as they would appear visually.
  // stylelint-disable-next-line declaration-no-important, max-line-length
  word-wrap: normal !important;

  &.skip-link {
    margin: 5px;

    &:focus {
      // stylelint-disable-next-line sh-waqar/declaration-use-variable
      color: currentColor;
    }
  }

  &:focus {
    background-color: var(--color-white);
    border-radius: 0;
    box-shadow: 0 0 2px 2px rgb(22 22 22 / .6);
    clip: auto;
    clip-path: none;
    display: block;
    font-size: 1.7rem;
    font-weight: var(--font-weight-bold);
    height: auto;
    left: 5px;
    line-height: normal;
    padding: 15px 23px 14px;
    text-decoration: none;
    top: 5px;
    width: auto;
    z-index: 100000; // Above WP toolbar.
  }
}

// Suppress focus ring on for mouse and touch users for visual reasons
// stylelint-disable-next-line a11y/no-outline-none
[data-whatinput="mouse"] *:focus,
[data-whatinput="touch"] *:focus {
  outline: none;
}

// Visually distinct focus color on keyboard
[data-whatinput="keyboard"] {

  // Make sure every focusable element has opacity 100%
  a:focus,
  input:focus,
  button:focus,
  select:focus,
  textarea:focus,
  div[tabindex]:focus {
    opacity: 1;
  }

  .global-link {
    transition: none;
  }

  // A bit better focus for large elements
  a.global-link:focus {
    outline-offset: 5px;
    outline-style: solid;
    outline-width: 4px;
    transition: outline-offset .25s ease;
  }
}

// Add icon to external links
a.is-external-link {
  align-items: center;
  display: inline-flex;
  justify-content: space-between;

  &::after {
    background-image: url('../../svg/external-link.svg');
    background-position: right center;
    background-repeat: no-repeat;
    background-size: 14px 14px;
    content: '';
    display: inline-flex;
    height: 14px;
    margin-left: 5px;
    margin-right: 2px;
    position: relative;
    right: 0;
    top: 0;
    transition: all .18s ease-in-out;
    width: 14px;
  }
}

// Do not use external links indicators in decorative areas
// stylelint-disable-next-line a11y/no-display-none
a.is-external-link.global-link::after,
a.is-external-link.no-external-link-indicator::after {
  display: none;
}

// Define here the upsell blocks that have overlay link areas
// inside them
// These should always have overflow visible, because otherwise
// the outline will not be visible outside the element
// .block.block-three-upsells .container,
// body .block .container .col {
//   overflow: visible;
// }

// Make focus a little more engaging
// @source https://twitter.com/argyleink/status/1387072095159406596
// @link https://codepen.io/argyleink/pen/JjEzeLp
@media (prefers-reduced-motion: no-preference) {
  :focus,
  *:focus,
  [data-whatinput="keyboard"] :focus,
  [data-whatinput="keyboard"] a:focus {
    outline-offset: 5px;
    transition: outline-offset .25s ease;
  }
}
