abbr[data-bw-acronym] {
  position: relative;
  cursor: help;
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: .16em;
}

abbr[data-bw-acronym]:focus {
  border-radius: .2rem;
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* The bubble floats clear of the word, so a pointer crossing that strip would
   leave the acronym and close the help before it arrived. This transparent strip
   spans the gap on whichever side the bubble was placed. It is inert until the
   bubble is shown, and it never paints. */
abbr[data-bw-acronym]::before {
  content: "";
  position: absolute;
  z-index: 999;
  left: var(--bw-acronym-left, 50%);
  width: var(--bw-acronym-width, 100%);
  height: var(--bw-acronym-bridge, .6rem);
  top: var(--bw-acronym-bridge-top, auto);
  bottom: var(--bw-acronym-bridge-bottom, 100%);
  background: transparent;
  /* Inert off-screen bridge boxes must not enlarge the page scroll area. */
  display: none;
  pointer-events: none;
}

abbr[data-bw-acronym][data-bw-open]::before {
  display: block;
  pointer-events: auto;
}

abbr[data-bw-acronym]::after {
  position: absolute;
  z-index: 1000;
  /* The script clamps the bubble inside the viewport and flips it below the
     trigger near the top of the page. These defaults apply without it. */
  bottom: var(--bw-acronym-bottom, calc(100% + .45rem));
  top: var(--bw-acronym-top, auto);
  left: var(--bw-acronym-left, 50%);
  width: var(--bw-acronym-width, max-content);
  max-width: var(--bw-acronym-max-width, min(22rem, 80vw));
  padding: .45rem .6rem;
  border: 1px solid #cbd5e1;
  border-radius: .4rem;
  background: #fff;
  box-shadow: 0 4px 18px rgb(15 23 42 / 18%);
  color: #0f172a;
  /* Opacity alone leaves an invisible wide bubble in the scrollable layout.
     Generate it only while active, including CSS-only hover/focus without JS. */
  content: none;
  font: 500 .82rem/1.35 system-ui, sans-serif;
  /* opacity:0 alone still contributes to horizontal scrollWidth on phones. */
  display: none;
  opacity: 0;
  transform: translateY(.25rem);
  transition: opacity .12s ease, transform .12s ease;
  white-space: normal;
}

/* The bubble is interactive while shown so a reader can move the pointer onto
   it without losing the help. It is inert the rest of the time. */
abbr[data-bw-acronym][data-bw-open]:not([data-bw-dismissed])::after,
abbr[data-bw-acronym]:is(:hover, :focus, :focus-visible):not([data-bw-dismissed])::after {
  content: attr(data-expansion);
  display: block;
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

abbr[data-bw-acronym][data-bw-dismissed]::after {
  display: none;
  opacity: 0;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  abbr[data-bw-acronym]::after {
    border-color: #475569;
    background: #0f172a;
    color: #f8fafc;
    box-shadow: 0 4px 18px rgb(0 0 0 / 45%);
  }
}

@media (prefers-reduced-motion: reduce) {
  abbr[data-bw-acronym]::after { transition: none; }
}
