/* glossary.css — inline jargon term + popover tooltip
 *
 * Markup contract (rendered by glossary.py jinja_filter):
 *   <span class="term" tabindex="0" role="button" aria-haspopup="true"
 *         aria-expanded="false" data-explain="..." data-glossary-anchor="..."
 *         data-raw="...">Label<span class="term-i" aria-hidden="true">i</span></span>
 *
 * One single popover element is shared across all terms (created lazily by JS).
 */

/* ---- Inline term -------------------------------------------------------- */

.term {
  display: inline;
  position: relative;
  border-bottom: 1px dashed var(--text-muted, #888);
  cursor: help;
  color: inherit;
  padding: 0 1px;
  border-radius: 2px;
  transition: background-color 0.12s ease-out, color 0.12s ease-out;
  -webkit-tap-highlight-color: transparent;
}

.term:hover,
.term:focus-visible,
.term[aria-expanded="true"] {
  background: rgba(64, 156, 255, 0.10);
  border-bottom-color: var(--accent-blue, #409cff);
  color: var(--text-primary, inherit);
  outline: none;
}

[data-theme="light"] .term:hover,
[data-theme="light"] .term:focus-visible,
[data-theme="light"] .term[aria-expanded="true"] {
  background: rgba(64, 110, 200, 0.12);
}

.term:focus-visible {
  outline: 2px solid var(--accent-blue, #409cff);
  outline-offset: 1px;
}

/* Any element opted-in via [data-explain] (eg. .mil-badge) gets the cursor
 * affordance and focus ring without inheriting the dotted-underline + 'i' icon. */
[data-explain]:not(.term) {
  cursor: help;
  -webkit-tap-highlight-color: transparent;
}
[data-explain]:not(.term):focus-visible {
  outline: 2px solid var(--accent-blue, #409cff);
  outline-offset: 2px;
}
[data-explain]:not(.term)[aria-expanded="true"] {
  filter: brightness(1.08);
}

.term-i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95em;
  height: 0.95em;
  margin-left: 3px;
  font-size: 0.62em;
  font-style: normal;
  font-weight: 700;
  line-height: 1;
  border-radius: 50%;
  background: var(--text-muted, #888);
  color: var(--bg-card, #1a1a1a);
  vertical-align: 0.18em;
  font-family: Georgia, serif;
  transition: background-color 0.12s ease-out;
}

.term:hover .term-i,
.term:focus-visible .term-i,
.term[aria-expanded="true"] .term-i {
  background: var(--accent-blue, #409cff);
  color: #fff;
}

/* ---- Shared popover ----------------------------------------------------- */

.term-popover {
  position: fixed;
  z-index: 9999;
  max-width: 320px;
  min-width: 180px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--bg-card, #1c1f24);
  color: var(--text-primary, #f1f1f1);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  font-size: 0.86rem;
  line-height: 1.45;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.14s ease-out, transform 0.14s ease-out;
  visibility: hidden;
}

[data-theme="light"] .term-popover {
  box-shadow: 0 8px 22px rgba(20, 30, 60, 0.18), 0 1px 4px rgba(20, 30, 60, 0.10);
}

.term-popover[data-open="true"] {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

.term-popover__label {
  font-weight: 700;
  font-size: 0.92rem;
  margin: 0 0 4px 0;
  color: var(--text-primary, inherit);
}

.term-popover__short {
  margin: 0 0 8px 0;
  color: var(--text-secondary, var(--text-primary, inherit));
}

.term-popover__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--border, rgba(255, 255, 255, 0.08));
  font-size: 0.76rem;
  color: var(--text-muted, #888);
}

.term-popover__raw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(128, 128, 128, 0.18);
  color: var(--text-muted, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.term-popover__more {
  color: var(--accent-blue, #409cff);
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}

.term-popover__more:hover,
.term-popover__more:focus-visible {
  text-decoration: underline;
  outline: none;
}

/* Arrow */
.term-popover__arrow {
  position: absolute;
  width: 10px;
  height: 10px;
  background: inherit;
  border-left: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  transform: rotate(45deg);
  pointer-events: none;
}

.term-popover[data-placement="bottom"] .term-popover__arrow {
  top: -6px;
}

.term-popover[data-placement="top"] .term-popover__arrow {
  bottom: -6px;
  border-left: none;
  border-top: none;
  border-right: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.12));
}

/* Reduced motion: no transitions */
@media (prefers-reduced-motion: reduce) {
  .term,
  .term-i,
  .term-popover {
    transition: none !important;
  }
  .term-popover {
    transform: none !important;
  }
}

[data-motion="off"] .term,
[data-motion="off"] .term-i,
[data-motion="off"] .term-popover {
  transition: none !important;
}

[data-motion="off"] .term-popover {
  transform: none !important;
}

/* ---- /glossary page styling -------------------------------------------- */

.glossary-page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.glossary-page h1 {
  font-size: 2em;
  margin: 0 0 6px 0;
}

.glossary-page__intro {
  color: var(--text-muted, #888);
  margin: 0 0 28px 0;
  max-width: 70ch;
}

.glossary-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 0 22px;
  border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  margin-bottom: 28px;
}

.glossary-toc a {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(64, 156, 255, 0.10);
  color: var(--accent-blue, #409cff);
  text-decoration: none;
  font-size: 0.84em;
  border: 1px solid rgba(64, 156, 255, 0.25);
}

.glossary-toc a:hover,
.glossary-toc a:focus-visible {
  background: rgba(64, 156, 255, 0.20);
  outline: none;
}

.glossary-section {
  margin: 0 0 36px 0;
  scroll-margin-top: 90px;
}

.glossary-section h2 {
  font-size: 1.3em;
  margin: 0 0 4px 0;
}

.glossary-section__intro {
  color: var(--text-muted, #888);
  margin: 0 0 16px 0;
  max-width: 75ch;
  font-size: 0.92em;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.glossary-entry {
  padding: 14px 16px;
  border: 1px solid var(--border, rgba(255, 255, 255, 0.10));
  border-radius: 10px;
  background: var(--bg-card, transparent);
  scroll-margin-top: 100px;
  transition: border-color 0.18s ease-out, transform 0.18s ease-out;
}

.glossary-entry:target {
  border-color: var(--accent-blue, #409cff);
  box-shadow: 0 0 0 3px rgba(64, 156, 255, 0.20);
}

.glossary-entry__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.glossary-entry__label {
  font-weight: 700;
  font-size: 0.98em;
  color: var(--text-primary, inherit);
}

.glossary-entry__code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72em;
  padding: 1px 6px;
  border-radius: 3px;
  background: rgba(128, 128, 128, 0.18);
  color: var(--text-muted, #888);
  white-space: nowrap;
}

.glossary-entry__short {
  margin: 0;
  color: var(--text-secondary, var(--text-primary, inherit));
  font-size: 0.88em;
  line-height: 1.45;
}

.glossary-entry__long {
  margin: 8px 0 0 0;
  color: var(--text-muted, #888);
  font-size: 0.84em;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .term-popover {
    max-width: calc(100vw - 32px);
    left: 16px !important;
    right: 16px !important;
    width: auto !important;
  }
  .term-popover__arrow {
    display: none;
  }
}
