.code-copy-wrapper {
  position: relative;
  margin-bottom: 1rem;
  background: #f6f8fa;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgb(0 0 0 / 10%);
}

/* 给按钮预留空间，避免遮住代码 */
.code-copy-wrapper > pre {
  box-sizing: border-box;
  margin: 0;
  padding: 16px 60px 16px 16px;
  overflow-x: auto;

  background: transparent;
  border: 0;
  border-radius: inherit;
}

.code-copy-wrapper > pre > code {
  padding: 0;
  background: transparent;
  border: 0;
}

/* 默认隐藏 */
.code-copy-button {
  position: absolute;
  top: 8px;
  right: 8px;

  display: grid;
  place-items: center;
  box-sizing: border-box;
  width: 34px;
  height: 34px;
  padding: 7px;

  color: #393a34;
  background: #f6f8fa;
  border: 1px solid #dadde1;
  border-radius: 7px;

  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}

/* 移入代码框，或键盘聚焦时显示 */
.code-copy-wrapper:hover .code-copy-button,
.code-copy-wrapper:focus-within .code-copy-button {
  opacity: 1;
  pointer-events: auto;
}

.code-copy-button:hover {
  border-color: #999;
}

.code-copy-button:focus-visible {
  outline: 2px solid #3578e5;
  outline-offset: 2px;
}

.code-copy-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.code-copy-button.is-copied {
  color: #008647;
}

/* 隐藏播报文字，但保留给屏幕阅读器 */
.code-copy-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* 触摸设备没有鼠标悬浮，始终显示按钮 */
@media (hover: none) {
  .code-copy-button {
    opacity: 1;
    pointer-events: auto;
  }
}

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

@media print {
  .code-copy-button {
    display: none;
  }
}