/* ═══════════════════════════════════════════════════════════════
   n-tooltip.css — lightweight CSS-only tooltips for terminology.
   Usage:
     <abbr class="n-term" data-tooltip="PM2.5 = airborne particles
       smaller than 2.5 µm; penetrate deep into the lungs.">PM2.5</abbr>

   The tooltip bubble appears on hover / focus and is keyboard-accessible
   (the <abbr>/span is focusable via tabindex="0"). On mobile where
   :hover does not exist, :focus-within keeps the tooltip open on tap.
═══════════════════════════════════════════════════════════════ */

.n-term {
  position: relative;
  border-bottom: 1px dashed currentColor;
  cursor: help;
  text-decoration: none;
  padding: 0 0.05em;
  outline-offset: 2px;
}

.n-term:hover,
.n-term:focus {
  color: var(--n-accent-primary, #22d3ee);
}

/* Bubble */
.n-term::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  min-width: 200px;
  max-width: 320px;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: #1e293b;
  color: #f8fafc;
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: normal;
  text-align: left;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  z-index: 800;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

/* Arrow */
.n-term::before {
  content: '';
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translateX(-50%) translateY(4px);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #1e293b;
  opacity: 0;
  pointer-events: none;
  z-index: 801;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.n-term:hover::after,
.n-term:hover::before,
.n-term:focus::after,
.n-term:focus::before,
.n-term:focus-within::after,
.n-term:focus-within::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Light-theme bubble (dark pill flips to light text on dark — but use
   the same palette for consistency; bubble stays dark on purpose for
   high contrast regardless of page theme). */
body.theme-light .n-term::after { background: #0f172a; color: #f8fafc; }
body.theme-light .n-term::before { border-top-color: #0f172a; }

/* Right-side fallback for tooltips that would clip off-screen on the left */
.n-term.n-term--right::after,
.n-term.n-term--right::before {
  left: auto;
  right: 50%;
  transform: translateX(50%) translateY(4px);
}
.n-term.n-term--right:hover::after,
.n-term.n-term--right:hover::before,
.n-term.n-term--right:focus::after,
.n-term.n-term--right:focus::before {
  transform: translateX(50%) translateY(0);
}

/* Mobile: simplify (bubble stays below on tap to avoid overflow) */
@media (max-width: 640px) {
  .n-term::after { min-width: 180px; max-width: 260px; font-size: 0.72rem; }
}
