.math-copy-block {
  position: relative;
}

.math-copy-btn {
  align-items: center;
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--sec-text-color);
  cursor: pointer;
  display: flex;
  height: 2.5rem;
  inset-inline-end: 0.1rem;
  justify-content: center;
  margin: 0;
  padding: 0;
  position: absolute;
  top: 0.1rem;
  touch-action: manipulation;
  width: 2.5rem;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
}

.math-copy-icon {
  align-items: center;
  background: var(--board-bg-color);
  border: 1px solid var(--line-color);
  border-radius: 0.38rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  display: flex;
  font-size: 0.78rem !important;
  height: 1.75rem;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.16s ease, color 0.16s ease, border-color 0.16s ease;
  width: 1.75rem;
}

.math-copy-block:hover .math-copy-icon,
.math-copy-btn:focus-visible .math-copy-icon,
.math-copy-btn.is-copied .math-copy-icon,
.math-copy-btn.is-copy-error .math-copy-icon {
  opacity: 0.9;
}

.math-copy-btn:hover .math-copy-icon,
.math-copy-btn:focus-visible .math-copy-icon {
  border-color: var(--post-link-color);
  color: var(--post-link-color);
}

.math-copy-btn:focus-visible {
  outline: 2px solid var(--post-link-color);
  outline-offset: -5px;
}

.math-copy-btn.is-copied .math-copy-icon {
  color: #16a34a;
}

.math-copy-btn.is-copy-error .math-copy-icon {
  color: #dc2626;
}

.math-copy-status {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

/* Touch screens have no hover state: keep a small cue visible while retaining
   a 44px tap target. The visual footprint stays 28px so formulas remain clear. */
@media (hover: none), (pointer: coarse) {
  .math-copy-btn {
    height: 2.75rem;
    width: 2.75rem;
  }

  .math-copy-icon {
    opacity: 0.56;
  }

  .math-copy-btn:active .math-copy-icon {
    opacity: 1;
  }
}

@media print {
  .math-copy-btn {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .math-copy-icon {
    transition: none;
  }
}
