/**
 * Preview Colour Extension - HTML mark and copy tooltip
 *
 * @author Mickaël Canouil
 *
 * The mark is a button, so `all: unset` removes its own chrome and keeps it
 * looking like a glyph in the text, with or without Bootstrap. The glyph keeps
 * its colour inline, because the colour is the data it shows. The button takes the
 * colour of the text around it, so the focus ring in `currentColor` has the
 * contrast of the text rather than of the colour shown.
 * The tooltip takes its colours, radius, font, and shadow from the page theme:
 * the Bootstrap 5 custom properties on an HTML page, the Reveal.js theme
 * properties on a slide deck, and the system colours elsewhere. It is the
 * inverse of the page, as a Bootstrap tooltip is, so it follows the colour
 * scheme that the page shows.
 */

.preview-colour {
  all: unset;
  position: relative;
  font-size: 0.8lh;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.preview-colour:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
  border-radius: 0.125rem;
}

.preview-colour-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/*
 * The tooltip is drawn after the mark, from its `data-tooltip` attribute. The
 * mark is often inside inline code, and a theme rule on `code span` cannot
 * match a pseudo-element. `all: initial` stops the tooltip from inheriting the
 * font and text styles of the code. It keeps the colour scheme of the page, so
 * the system colours resolve as the page shows them.
 */
.preview-colour[data-tooltip]::after {
  all: initial;
  color-scheme: inherit;
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1080;
  padding: 0.25rem 0.5rem;
  background: var(--bs-body-color, var(--r-main-color, CanvasText));
  color: var(--bs-body-bg, var(--r-background-color, Canvas));
  border-radius: var(--bs-border-radius, 0.375rem);
  box-shadow: var(--bs-box-shadow-sm, 0 0.125rem 0.25rem rgb(0 0 0 / 7.5%));
  font-family: var(--bs-body-font-family, var(--r-main-font, system-ui, sans-serif));
  font-size: 0.75rem;
  line-height: 1.5;
  white-space: nowrap;
  pointer-events: none;
}
