/* ==========================================================================
   Copy button on code blocks — every <pre><code>…</code></pre> gets one
   (moey.js adds it). It sits in the top corner and stays there while long
   code scrolls sideways; shown on hover / focus, always on touch screens.
   data-moey-copy="false" on the <pre> or a parent: no button.
   data-moey-copy on a <pre> without <code>: a button anyway.
   Event: moey:copy (detail.text)
   ========================================================================== */

pre:has(> .code-copy) { position: relative; }
.code-copy {
  position: sticky;
  top: 0;
  left: calc(100% - 2rem);          /* pinned to the right edge, even when the code scrolls */
  z-index: 1;
  display: grid;
  float: right;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: -.5rem -.625rem -2rem .5rem;   /* takes no room: the code flows as if it weren't there */
  font: inherit;
  color: var(--mo-fg-3);
  cursor: pointer;
  background: color-mix(in oklab, var(--mo-bg-raised) 88%, transparent);
  border: 0;
  border-radius: var(--mo-radius-control);
  opacity: 0;
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-reduced-motion: no-preference) {
  .code-copy { transition: opacity var(--mo-duration), color var(--mo-duration), background-color var(--mo-duration); }
}
.code-copy > svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.code-copy > .code-copy-done { display: none; }
pre:hover > .code-copy,
.code-copy:focus-visible,
.code-copy.is-copied { opacity: 1; }
@media (hover: none) { .code-copy { opacity: .85; } }
.code-copy:hover { color: var(--mo-fg-body); background: var(--mo-bg-raised); }
.code-copy:focus-visible { outline: var(--mo-focus-ring-width) solid var(--mo-theme-focus-ring); outline-offset: -2px; }
.code-copy.is-copied { color: var(--mo-green-fg); }
.code-copy.is-copied > .code-copy-icon { display: none; }
.code-copy.is-copied > .code-copy-done { display: block; }
