/* A copy button shows when the pointer is over its code block or panel or
   the keyboard focus is in it.  Devices without hover always show it. */
pre:has(> code),
.editor {
  position: relative;

  &:hover,
  &:has(:focus-visible) {
    & .copy-button {
      opacity: 1;
    }
  }
}

.copy-button {
  align-items: center;
  background-color: var(--bg);
  border-color: var(--fg);
  border-style: solid;
  border-width: 1px;
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  font-size: 1rem;
  font-weight: normal;
  gap: 0.4em;
  letter-spacing: normal;
  line-height: normal;
  opacity: 0;
  padding-block: 0.3em;
  padding-inline: 0.3em;
  padding: 0.5em 1em;
  position: absolute;
  right: 0.5em;
  text-decoration: none;
  text-transform: uppercase;
  top: 0.5em;
  transition-duration: 300ms;
  white-space: nowrap;

  &:hover {
    border-color: var(--footnote-highlight);
    color: var(--footnote-highlight);
  }

  &:hover,
  &:focus-visible {
    opacity: 1 !important;
  }

  &[aria-pressed='true'] {
    display: block;
    opacity: 1;
  }
}

/* After the rule above so it overrides its opacity. */
@media (hover: none) {
  .copy-button {
    opacity: 1;
  }
}
