/* Glossary tips — inline "?" chip that reveals a micro-definition.
 *
 * Reviewer's brief: "Every proprietary term needs a micro-definition
 * the first few times a user encounters it."
 *
 * Interaction model — accessible without JS:
 *   · hover the button       → tooltip appears (mouse)
 *   · Tab-focus the button   → tooltip appears (keyboard)
 *   · tap the button         → tooltip appears (mobile, native focus)
 *   · tap outside or Esc     → focus moves, tooltip hides
 *
 * The tooltip body is always in the DOM (aria-describedby target),
 * so screen readers always announce the definition — visibility is
 * purely a mouse/keyboard sighted-user affordance. */

.gloss {
  position: relative;
  display: inline-block;
  vertical-align: baseline;
  margin: 0 2px 0 4px;
  line-height: 1;
}

.gloss__btn {
  all: unset;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(139, 90, 43, 0.14);
  color: #6F4520;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  cursor: help;
  border: 1px solid rgba(139, 90, 43, 0.28);
  transition: background 0.15s, transform 0.15s;
  user-select: none;
  vertical-align: baseline;
  translate: 0 -2px;   /* nudge up so ? sits at cap-height, not baseline */
}

.gloss__btn:hover,
.gloss__btn:focus-visible {
  background: rgba(139, 90, 43, 0.24);
  transform: scale(1.06);
  outline: 2px solid rgba(139, 90, 43, 0.4);
  outline-offset: 1px;
}

/* ── Tooltip body ────────────────────────────────────────────────── */
.gloss__body {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 240px;
  max-width: 300px;
  padding: 10px 12px;
  background: #1A1612;
  color: #F1E9D0;
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(26, 22, 18, 0.28);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 12.5px;
  line-height: 1.4;
  letter-spacing: 0.005em;
  text-align: left;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s, visibility 0s 0.15s;
}

.gloss__body::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: #1A1612;
  border-radius: 1px;
}

/* Reveal on hover of the wrapper OR focus-within (keyboard/tap) */
.gloss:hover .gloss__body,
.gloss:focus-within .gloss__body {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.15s, visibility 0s;
}

/* Inside-tooltip typography */
.gloss__term {
  display: block;
  font-family: "Playfair Display", Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #F4EED9;
  margin-bottom: 4px;
}

.gloss__def {
  display: block;
  color: rgba(241, 233, 208, 0.86);
}

/* ── Screen-edge safety ──────────────────────────────────────────── */
/* Tooltip is centred by default; when it renders near the right edge
 * of a narrow parent it can overflow. Two escape hatches: */
.gloss--align-left  .gloss__body { left: 0; transform: none; }
.gloss--align-left  .gloss__body::before { left: 10px; transform: rotate(45deg); }

.gloss--align-right .gloss__body { left: auto; right: 0; transform: none; }
.gloss--align-right .gloss__body::before { left: auto; right: 10px; transform: rotate(45deg); }

/* ── Mobile ──────────────────────────────────────────────────────── */
/* On narrow viewports the fixed 300px tooltip can escape the screen;
 * cap it to the viewport minus a comfortable gutter. */
@media (max-width: 480px) {
  .gloss__body {
    min-width: 200px;
    max-width: min(280px, calc(100vw - 40px));
    font-size: 12px;
  }
}
