/* Glossary styles.
 *
 * Two independent parts:
 *   1. The marked term and its bubble, loaded on ARTICLE pages by the blog
 *      layout. This is the part that must not shift layout.
 *   2. The /glossary/ page itself, loaded by the glossary layout.
 *
 * Colours are homepage-v3.css variables, so light and dark mode follow the
 * site theme through body.dark with no separate dark rules needed here.
 */

/* ------------------------------------------------------------------ */
/* 1. Marked terms and the hover bubble (article pages)                */
/* ------------------------------------------------------------------ */

/* Dotted underline is the long-established convention for a definition, and it
 * changes no layout geometry, so nothing reflows when the script runs on idle.
 * Inherited colour, deliberately not link teal: these are not navigation.
 *
 * Scoped to [data-glossary-scope] for specificity, not for scope. The blog
 * layout sets `.blog-article-content a { color: var(--accent-primary);
 * text-decoration: underline }` in an inline <style> block. That selector and a
 * bare `a.gloss` both score (0,1,1), and the inline block comes later in the
 * document than this linked stylesheet, so it wins the tie: marked terms render
 * in link teal with a solid underline, indistinguishable from a real inline
 * link like "Article 3". Adding the attribute selector raises this to (0,2,1)
 * and settles it. Every marked term is inside that element by construction,
 * since glossary.js only walks within it. */
[data-glossary-scope] a.gloss,
a.gloss {
  color: inherit;
  text-decoration: underline dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  cursor: help;
}
[data-glossary-scope] a.gloss:hover,
[data-glossary-scope] a.gloss:focus-visible,
a.gloss:hover,
a.gloss:focus-visible {
  color: inherit;
  text-decoration-style: solid;
}
[data-glossary-scope] a.gloss:focus-visible,
a.gloss:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

#gloss-pop {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  max-width: 22rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--surface, #fff);
  color: var(--text, #14181f);
  border: 1px solid var(--rule, rgba(0, 0, 0, .1));
  box-shadow: 0 8px 28px rgba(0, 0, 0, .14);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.9rem;
  line-height: 1.5;
}
#gloss-pop[hidden] { display: none; }

.gloss-pop-term {
  margin: 0 0 .35rem;
  font-weight: 600;
  font-size: .82rem;
  letter-spacing: .01em;
  color: var(--text-strong);
}
.gloss-pop-body { margin: 0 0 .6rem; color: var(--text); }
.gloss-pop-body[hidden] { display: none; }

.gloss-pop-actions {
  display: flex;
  align-items: baseline;
  gap: .85rem;
  margin: 0;
}
.gloss-pop-more {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.gloss-pop-more[hidden] { display: none; }

/* Expanded state ------------------------------------------------------
   Wider and taller than the 40-word bubble, but capped: entries run to a
   median of 62 words, so this rarely scrolls. When it does, the bubble
   scrolls rather than growing past the viewport. */
#gloss-pop.is-expanded {
  max-width: 26rem;
  max-height: min(70vh, 32rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-top: .5rem;
}

.gloss-pop-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  min-height: 0;
}
#gloss-pop:not(.is-expanded) .gloss-pop-bar { display: none; }

.gloss-pop-back,
.gloss-pop-close {
  appearance: none;
  background: none;
  border: 0;
  padding: .15rem .25rem;
  font: inherit;
  font-size: .78rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}
.gloss-pop-back:hover,
.gloss-pop-close:hover { color: var(--text-strong); }
.gloss-pop-back[hidden],
.gloss-pop-close[hidden] { display: none; }
.gloss-pop-close {
  margin-left: auto;
  font-size: 1.1rem;
  line-height: 1;
}

.gloss-pop-full[hidden] { display: none; }
.gloss-pop-long p {
  margin: 0 0 .6rem;
  color: var(--text);
  font-size: .88rem;
  line-height: 1.6;
}
.gloss-pop-long p:last-child { margin-bottom: .6rem; }
.gloss-pop-long code {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  font-size: .85em;
  background: var(--surface-2);
  padding: .1em .3em;
  border-radius: 4px;
}

.gloss-pop-see {
  margin: 0 0 .5rem;
  font-size: .8rem;
  color: var(--text-muted);
}
.gloss-pop-see[hidden] { display: none; }
.gloss-pop-see a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft, rgba(61, 189, 177, .4));
}
.gloss-pop-see a:hover { border-bottom-color: currentColor; }

.gloss-pop-meta {
  margin: 0 0 .7rem;
  padding-top: .55rem;
  border-top: 1px solid var(--rule);
  font-size: .72rem;
  color: var(--text-muted);
}
.gloss-pop-meta a { color: var(--text-muted); text-decoration: underline; }
.gloss-pop-meta a:hover { color: var(--accent); }

@media (max-width: 480px) {
  #gloss-pop { max-width: calc(100vw - 24px); }
  #gloss-pop.is-expanded {
    max-width: calc(100vw - 24px);
    max-height: 72vh;
  }
}

/* The bubble is an interaction, not content. It should never print, and the
 * dotted underline only adds noise on paper. */
@media print {
  a.gloss { text-decoration: none; }
  #gloss-pop { display: none; }
}

/* Respect reduced-motion: the bubble has no transition to begin with, but keep
 * any future additions honest. */
@media (prefers-reduced-motion: reduce) {
  #gloss-pop { transition: none !important; }
}

/* ------------------------------------------------------------------ */
/* 2. The /glossary/ page                                              */
/* ------------------------------------------------------------------ */

.glossary-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 10rem 2rem 8rem;
}

.glossary-header {
  margin-bottom: 2.5rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--accent-soft, rgba(61, 189, 177, .25));
}
.glossary-header h1 {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: normal;
  color: var(--text-strong);
  margin-bottom: 0.75rem;
}
.glossary-intro {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text);
  margin: 0 0 .75rem;
  max-width: 62ch;
}
.glossary-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
}

/* Controls ---------------------------------------------------------- */

.glossary-controls {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  padding: 1rem 0 .85rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 1rem;
}
.glossary-search-label {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
#glossary-search {
  width: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: 9px;
  padding: .7rem .9rem;
}
#glossary-search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.glossary-cats {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .7rem;
}
.glossary-cats button {
  appearance: none;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: .8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .35rem .8rem;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.glossary-cats button:hover { color: var(--text-strong); }
.glossary-cats button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.glossary-resultnote {
  font-size: .75rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: .6rem 0 0;
}

/* Entries ----------------------------------------------------------- */

.glossary-section { padding-top: 2rem; }
.glossary-section[hidden] { display: none; }
.glossary-section h2 {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: normal;
  color: var(--text-strong);
  margin: 0 0 .25rem;
  display: flex;
  align-items: baseline;
  gap: .6rem;
}
.glossary-n {
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: .05em;
}

.glossary-entry {
  padding: 1.35rem 0 1.15rem;
  border-bottom: 1px solid var(--rule);
  /* Offset the anchor target so an arriving #term-x link is not hidden under
     the fixed header and the sticky search bar. */
  scroll-margin-top: 170px;
}
.glossary-entry[hidden] { display: none; }

/* Brief highlight when a reader arrives from an article tooltip, so the entry
   they asked for is obvious among its neighbours. */
.glossary-entry--targeted {
  background: var(--accent-soft, rgba(61, 189, 177, .12));
  border-radius: 8px;
  padding-left: .9rem;
  padding-right: .9rem;
}
@media (prefers-reduced-motion: no-preference) {
  .glossary-entry { transition: background .35s ease; }
}

.glossary-entry h3 {
  font-family: 'Outfit', 'Inter', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: normal;
  color: var(--text-strong);
  margin: 0 0 .5rem;
}
.glossary-expansion {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: .35rem;
}

.glossary-definition {
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
}
.glossary-definition p { margin: 0 0 .75rem; }
.glossary-definition p:last-child { margin-bottom: 0; }
.glossary-definition code {
  font-family: 'JetBrains Mono', ui-monospace, Menlo, Consolas, monospace;
  font-size: .85em;
  background: var(--surface-2);
  padding: .1em .35em;
  border-radius: 4px;
}

.glossary-see-also {
  margin: .8rem 0 0;
  font-size: .875rem;
  color: var(--text-muted);
}
.glossary-see-also a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent-soft, rgba(61, 189, 177, .4));
}
.glossary-see-also a:hover { border-bottom-color: currentColor; }

.glossary-meta {
  margin: .7rem 0 0;
  font-size: .78rem;
  color: var(--text-muted);
}
.glossary-meta a { color: var(--text-muted); text-decoration: underline; }
.glossary-meta a:hover { color: var(--accent); }

/* Empty state and footnote ------------------------------------------ */

.glossary-empty {
  padding: 2.5rem 0;
  text-align: center;
  color: var(--text-muted);
}
.glossary-empty[hidden] { display: none; }
#glossary-reset {
  appearance: none;
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

.glossary-footnote {
  margin-top: 3rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  font-size: .9rem;
  line-height: 1.7;
  color: var(--text);
}
.glossary-footnote p { margin: 0; }
.glossary-footnote a { color: var(--accent); }

@media (max-width: 768px) {
  .glossary-container { padding: 7rem 1rem 4rem; }
  .glossary-header h1 { font-size: 1.85rem; }
  .glossary-entry { scroll-margin-top: 150px; }
}
