/* ---- heading anchors: layout ---- */
/* Keeps section[id]'s existing scroll offset consistent for the new
   id targets (h2/h3/dt) added by heading-anchors.js */
h2[id], h3[id], dt[id] {
  scroll-margin-block-start: var(--space-4);
}

:root {
  --heading-anchor-size: 1.5rem;
  --heading-anchor-gap: 0.35em;
}

.heading-anchor {
  /* reset */
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin-block: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;

  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  /* "middle" centers on the Latin x-height, which sits below the
     visual center of Japanese glyphs; nudge up to match them */
  translate: 0 -0.12em;
  min-inline-size: var(--heading-anchor-size);
  min-block-size: var(--heading-anchor-size);

  /* net-zero inline footprint so the heading's own text wrapping
     is unaffected by the button being appended as its last child */
  margin-inline-start: var(--heading-anchor-gap);
  margin-inline-end: calc(-1 * (var(--heading-anchor-gap) + var(--heading-anchor-size)));

  opacity: 0;
  transition: opacity .15s;
}

@media (prefers-reduced-motion: reduce) {
  .heading-anchor {
    transition: none;
  }
}

:is(h2, h3, dt):hover > .heading-anchor,
.heading-anchor:focus-visible,
.heading-anchor.is-copied {
  opacity: 1;
}

.heading-anchor:focus-visible {
  outline: 2px solid var(--color-text);
  outline-offset: 2px;
}

/* ---- heading anchors: icon ---- */
.heading-anchor-icon-link,
.heading-anchor-icon-check {
  display: inline-flex;
}
.heading-anchor-icon-check {
  display: none;
}
.heading-anchor.is-copied .heading-anchor-icon-link {
  display: none;
}
.heading-anchor.is-copied .heading-anchor-icon-check {
  display: inline-flex;
}

.heading-anchor-icon-link svg,
.heading-anchor-icon-check svg {
  inline-size: max(0.75em, 16px);
  block-size: max(0.75em, 16px);
}

/* ---- heading anchors: tooltip ---- */
.heading-anchor-tip {
  position: absolute;
  inset-block-end: calc(100% + 0.3em);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: var(--fs-xs);
  line-height: var(--lh-tight);
  padding: 0.2em 0.6em;
  background: var(--color-text);
  color: var(--color-bg);
  opacity: 0;
  pointer-events: none;
}
.heading-anchor.is-copied .heading-anchor-tip {
  opacity: 1;
}

/* ---- heading anchors: live region (visually hidden) ---- */
.heading-anchor-status {
  position: fixed;
  inset: var(--space-1) auto auto var(--space-1);
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media print {
  .heading-anchor {
    display: none;
  }
}
