:root {
  --tooltip-background-color-light: var(--fontra-theme-marker) black;
  --tooltip-background-color-dark: white;
  --tooltip-background-color: var(
    --tooltip-background-color-light,
    var(--tooltip-background-color-dark)
  );

  --tooltip-foreground-color-light: var(--fontra-theme-marker) white;
  --tooltip-foreground-color-dark: black;
  --tooltip-foreground-color: var(
    --tooltip-foreground-color-light,
    var(--tooltip-foreground-color-dark)
  );

  --tooltip-delay: 650ms;
  --tooltip-duration: 6s;
  --tooltip-arrow-size: 7px;
  --tooltip-max-width: 200px;
}

[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::before {
  content: attr(data-tooltip);
  width: max-content;
  max-width: var(--tooltip-max-width);
  font-size: 0.9rem;
  font-weight: normal;
  line-height: normal;
  text-align: center;
  position: absolute;
  display: block;
  border-radius: 4px;
  padding: 8px;
  color: var(--tooltip-foreground-color);
  background: var(--tooltip-background-color);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  animation-name: disappear;
  animation-delay: var(--tooltip-delay);
  animation-duration: var(--tooltip-duration);
}

[data-tooltip]:hover::after {
  content: "";
  position: absolute;
  display: block;
  left: 50%;
  width: 0;
  height: 0;
  bottom: 100%;
  margin-left: calc(var(--tooltip-arrow-size) * -1);
  border: 1px solid black;
  border-color: var(--tooltip-background-color) transparent transparent transparent;
  border-width: var(--tooltip-arrow-size) var(--tooltip-arrow-size) 0;
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  animation-name: disappear;
  animation-delay: var(--tooltip-delay);
  animation-duration: var(--tooltip-duration);
}

[data-tooltipposition="top-left"]:hover::before {
  transform: translateY(calc(-100% - var(--tooltip-arrow-size)))
    translateX(calc(var(--tooltip-arrow-size) * -1));
}

[data-tooltipposition="top"]:hover::before {
  right: 50%;
  transform: translateX(50%) translateY(calc(-100% - var(--tooltip-arrow-size)));
}

[data-tooltipposition="top-right"]:hover::before {
  right: calc(var(--tooltip-arrow-size) * -1);
  transform: translateY(calc(-100% - var(--tooltip-arrow-size)));
}

[data-tooltipposition="right"]:hover::before {
  top: 50%;
  left: calc(100% + var(--tooltip-arrow-size));
  transform: translateY(-50%);
}

[data-tooltipposition="right"]:hover::after {
  top: 50%;
  left: 100%;
  border-style: solid;
  border-top: var(--tooltip-arrow-size) solid transparent;
  border-bottom: var(--tooltip-arrow-size) solid transparent;
  border-right: var(--tooltip-arrow-size) solid var(--tooltip-background-color);
  border-left: 0;
  transform: translateY(-50%);
  margin-left: 0;
}

[data-tooltipposition="bottom-right"]:hover::before {
  right: calc(var(--tooltip-arrow-size) * -1);
  top: calc(100% + var(--tooltip-arrow-size));
}

[data-tooltipposition="bottom-right"]:hover::after {
  border-right: var(--tooltip-arrow-size) solid transparent;
  border-left: var(--tooltip-arrow-size) solid transparent;
  border-bottom: var(--tooltip-arrow-size) solid var(--tooltip-background-color);
  border-top: 0;
  left: 100%;
  top: 100%;
  margin-left: calc(var(--tooltip-arrow-size) * -2);
}

[data-tooltipposition="bottom"]:hover::before {
  transform: translateX(50%);
  right: 50%;
  top: calc(100% + var(--tooltip-arrow-size));
}

[data-tooltipposition="bottom"]:hover::after {
  border-right: var(--tooltip-arrow-size) solid transparent;
  border-left: var(--tooltip-arrow-size) solid transparent;
  border-bottom: var(--tooltip-arrow-size) solid var(--tooltip-background-color);
  border-top: 0;
  top: 100%;
}

[data-tooltipposition="bottom-left"]:hover::before {
  left: calc(var(--tooltip-arrow-size) * -1);
  top: calc(100% + var(--tooltip-arrow-size));
}

[data-tooltipposition="bottom-left"]:hover::after {
  border-right: var(--tooltip-arrow-size) solid transparent;
  border-left: var(--tooltip-arrow-size) solid transparent;
  border-bottom: var(--tooltip-arrow-size) solid var(--tooltip-background-color);
  border-top: 0;
  left: 100%;
  top: 100%;
  margin-left: calc(var(--tooltip-arrow-size) * -2);
}

[data-tooltipposition="left"]:hover::before {
  right: calc(100% + var(--tooltip-arrow-size));
  transform: translateY(-50%);
  top: 50%;
}

[data-tooltipposition="left"]:hover::after {
  border-style: solid;
  border-top: var(--tooltip-arrow-size) solid transparent;
  border-bottom: var(--tooltip-arrow-size) solid transparent;
  border-left: var(--tooltip-arrow-size) solid var(--tooltip-background-color);
  border-right: 0;
  right: 100%;
  left: initial;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 0;
}

/* no tooltip when the parent is being clicked on */
[data-tooltip]:active::before {
  opacity: 0;
  animation-name: none;
}

[data-tooltip]:active::after {
  opacity: 0;
  animation-name: none;
}

@keyframes disappear {
  0% {
    opacity: 1;
  }
  95% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion) {
  [data-tooltip]:hover::before {
    opacity: 1;
    animation: none;
  }
  [data-tooltip]:hover::after {
    opacity: 1;
    animation: none;
  }
}
