.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%) scale(0.9);
  transform-origin: bottom center;
  background: oklch(from var(--foreground) l c h / 0.8);
  color: var(--primary-foreground);
  font-size: 0.75rem;
  line-height: 1;
  white-space: nowrap;
  padding: 8px 8px;
  border-radius: 4px;
  pointer-events: none;
  opacity: 0;
  z-index: 1000;
}

@media (hover: hover) {
  .tooltip:hover::after,
  .tooltip:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

.tooltip[data-tooltip-hidden]::after {
  opacity: 0 !important;
  transform: translateX(-50%) scale(1) !important;
}

@media (max-width: 1100px) {
  /* Alignment variants for small screens */
  .tooltip[data-align="left"]::after {
    left: 0;
    right: auto;
    transform: translateX(0) scale(0.9);
    transform-origin: bottom left;
  }

  .tooltip[data-align="right"]::after {
    left: auto;
    right: 0;
    transform: translateX(0) scale(0.9);
    transform-origin: bottom right;
  }
}

/* Below its element, for controls at the top of the screen (the top bar), where a tooltip above would be cut off.
   There it is the only visible name of an icon (the compass), so its text takes the page's color, which turns dark
   with the pill in the dark theme (the white of the other tooltips is unreadable on a light pill). */
.tooltip[data-placement="below"]::after {
  top: calc(100% + 5px);
  bottom: auto;
  transform-origin: top center;
  color: var(--background);
}
