.prs-tooltip {
  --tip-bg: var(--prs-c-gray-900);
  --tip-fg: var(--prs-c-white);
  --tip-off: calc(100% + 0.5rem);
  --tip-tail: calc(100% + 0.25rem);
  
  display: inline-block;
  position: relative;

  & > .prs-tooltip-content,&[data-tip]:before {
    padding: 0.5rem 1rem;
    width: max-content;
    max-width: 20rem;
    background-color: var(--tip-bg);
    color: var(--tip-fg);
    font-size: 1rem;
    line-height: 24px;
    text-align: center;
    white-space: normal;
    pointer-events: none;
    position: absolute;
    z-index: 2;
    content: attr(data-tip);
    opacity: 0;
    border-radius: 0.25rem;

    @media (min-width: 768px) {
      padding: 0.25rem 1rem;
      font-size: 0.75rem;
      line-height: 18px;
    }
  }

  &:after {
    width: 1rem;
    height: 0.5rem;
    background-color: var(--tip-bg);
    display: block;
    position: absolute;
    pointer-events: none;
    content: "";
    opacity: 0;
    clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  }

  @media (prefers-reduced-motion: no-preference) {
    & > .prs-tooltip-content, &[data-tip]:before, &:after {
      transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1) 75ms, transform 0.2s cubic-bezier(0.4, 0, 0.2, 1) 75ms;
    }
  }

  &:is([data-tip]:not([data-tip=""]), :has(.prs-tooltip-content:not(:empty))) {
    &.prs-tooltip-open, &:hover, &:has(:focus-visible) {
      & > .prs-tooltip-content, &[data-tip]:before, &:after {
        --tip-pos: 0rem;
        opacity: 1;
        @media (prefers-reduced-motion: no-preference) {
          transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1) 0s, transform 0.2s cubic-bezier(0.4, 0, 0.2, 1) 0s;
        }
      }
    }
  }
}

.prs-tooltip,.prs-tooltip-top {
  & > .prs-tooltip-content, &[data-tip]:before {
    inset: auto auto calc(var(--tip-off) + 0.25rem) 50%;
    transform: translateX(-50%) translateY(var(--tip-pos, 0.25rem));
  }
  &:after {
    inset: auto auto var(--tip-tail) 50%;
    transform: translateX(-50%) translateY(var(--tip-pos, 0.25rem));
  }
}

.prs-tooltip-bottom {
  & > .prs-tooltip-content, &[data-tip]:before {
    inset: calc(var(--tip-off) + 0.25rem) auto auto 50%;
    transform: translateX(-50%) translateY(var(--tip-pos, -0.25rem));
  }

  &:after {
    inset: var(--tip-tail) auto auto 50%;
    transform: translateX(-50%) translateY(var(--tip-pos, -0.25rem)) rotate(180deg);
  }
}

.prs-tooltip-left {
  & > .prs-tooltip-content, &[data-tip]:before {
    inset: 50% var(--tip-off) auto auto;
    transform: translateX(calc(var(--tip-pos, 0.25rem) - 0.25rem)) translateY(-50%);
  }
  &:after {
    inset: 50% calc(var(--tip-tail) - 0.25rem) auto auto;
    transform: translateX(var(--tip-pos, 0.25rem)) translateY(-50%) rotate(-90deg);
  }
}

.prs-tooltip-right {
  & > .prs-tooltip-content, &[data-tip]:before {
    inset: 50% auto auto var(--tip-off);
    transform: translateX(calc(var(--tip-pos, -0.25rem) + 0.25rem)) translateY(-50%);
  }
  &:after {
    inset: 50% auto auto calc(var(--tip-tail) - 0.25rem);
    transform: translateX(var(--tip-pos, -0.25rem)) translateY(-50%) rotate(90deg);
  }
}
