/* The hover/focus-revealed copy button on every rendered Markdown code
   block (wrap_code_blocks, src/widgets/markdown.rs). Loaded only on a page
   that has at least one .sf-code block (inject_code_copy_assets,
   src/render/service.rs). Colors alias the site's branding tokens
   (_site_branding_head.html) with neutral fallbacks, so the button reads in
   light and dark without any theme change. */

.sf-code {
    position: relative;
}

.sf-code-copy {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    color: var(--site-body-text, #1f2933);
    background: var(--site-surface-tint, #e5e7eb);
    border: 1px solid var(--site-muted-text, #6b7280);
    border-radius: 0.375rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, background-color 0.15s ease;
}

.sf-code-copy svg {
    width: 16px;
    height: 16px;
    flex: none;
}

/* Hidden until hover or keyboard focus lands anywhere in the block, or the
   button itself holds focus; a touch device cannot hover, so it always
   shows the button. */
.sf-code:hover .sf-code-copy,
.sf-code:focus-within .sf-code-copy,
.sf-code-copy:focus {
    opacity: 1;
}

@media (hover: none) {
    .sf-code-copy {
        opacity: 1;
    }
}

.sf-code-copy:hover,
.sf-code-copy:focus {
    background: var(--site-emphasis-background, #d1d5db);
}

@media (prefers-color-scheme: dark) {
    .sf-code-copy {
        color: var(--site-body-text-on-dark-surface, #e5e7eb);
        background: var(--site-dark-surface, #1f2937);
        border-color: var(--site-muted-text-on-dark-surface, #9ca3af);
    }

    .sf-code-copy:hover,
    .sf-code-copy:focus {
        background: #374151;
    }
}

/* Visually hidden but still read by a screen reader: the aria-live region
   code-copy.js announces "Copied" through. */
.sf-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}
