<style>
/* Footnote reference styling */
.has-footnote-tooltip {
  cursor: help;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* Footnote tooltip container */
#footnote-tooltip {
  position: fixed;
  max-width: min(420px, 80vw);
  padding: 0;
  font-size: 0.85em;
  line-height: 1.5;

  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  color: #222;

  z-index: 99998;
  opacity: 0;
  pointer-events: none;
  transform: translateY(4px);
  transition: opacity 0.12s ease-out, transform 0.12s ease-out;
}

#footnote-tooltip::after {
  content: "";
  position: absolute;
  top: -6px;
  left: var(--arrow-x, 20px); /* controlled from JS */
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #ffffff;
  filter: drop-shadow(0 -1px 1px rgba(0,0,0,0.15));
}

/* Arrow flipped when tooltip is above ref */
#footnote-tooltip.above::after {
  top: auto;
  bottom: -6px;
  border-bottom: none;
  border-top: 6px solid #ffffff;
  left: var(--arrow-x, 20px);
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15));
}


/* Visible state */
#footnote-tooltip.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Card layout: body scrolls, footer fixed */
#footnote-tooltip .footnote-card {
  max-height: min(260px, 60vh);
  display: flex;
  flex-direction: column;
}

/* Scrollable body */
#footnote-tooltip .footnote-card-body {
  padding: 0.75em 1em 0.5em 1em;
  overflow-y: auto;
}

/* Compact paragraphs */
#footnote-tooltip .footnote-card-body p {
  margin: 0.25em 0;
}

/* Links inside footnote card */
#footnote-tooltip .footnote-card-body a {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* External links get a small ↗ hint */
#footnote-tooltip .footnote-card-body a.footnote-link::after {
  content: " ↗";
  font-size: 0.85em;
}

/* Footer with "View full footnote" link (always visible) */
#footnote-tooltip .footnote-card-footer {
  padding: 0.35em 1em 0.6em 1em;
  border-top: 1px solid rgba(0,0,0,0.12);
  font-size: 0.8em;
  text-align: right;
  flex: 0 0 auto;
}

#footnote-tooltip .footnote-card-footer a {
  text-decoration: none;
  border-bottom: 1px solid rgba(0,0,0,0.3);
}

#footnote-tooltip .footnote-card-footer a:hover {
  border-bottom-color: rgba(0,0,0,0.7);
}
</style>

<div id="footnote-tooltip">
  <div class="footnote-card">
    <div class="footnote-card-body"></div>
    <div class="footnote-card-footer"></div>
  </div>
</div>
