/*
  Glossary — Alphabetical term grid.
  Source: Figma 815:2659 (Frame 97711 for A group, repeated per letter).

  One block containing N letter groups. Each group:
    - Big green letter heading (New Science 60px, #20BA2F), 40px above the grid.
    - 3-column grid of white term cards (border-once + seam-border pattern
      — same treatment as .research-articles__grid).
    - Card = <a> with the term name (New Science SemiBold 20px, navy).
    - Hover state: dark navy bg, white text, green arrow (Figma 815:2745 "Q"
      section shows Quantum Advantage in this state).

  40px vertical rhythm both between (letter → grid) and between groups.

  Cards stack 2-col at ≤900px, 1-col at ≤600px.
*/

.glossary-term-grid {
  padding-inline: var(--space-inline);
  padding-block: var(--section-padding-block);
}

.glossary-term-grid__inner {
  max-width: var(--container-max);
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

.glossary-term-grid__group {
  display: flex;
  flex-direction: column;
  gap: 40px;
  /* Anchor offset so #glossary-a scroll lands below the sticky/overlapping nav.
     Adjust if nav height changes. */
  scroll-margin-top: 100px;
}

.glossary-term-grid__letter {
  font-family: var(--font-family-display);
  font-size: clamp(40px, 24px + 2.5vw, 60px);
  font-weight: var(--font-weight-semibold);
  line-height: 1.2;
  color: var(--color-green-2);
  margin: 0;
}

/* Per-card borders with collapsed seams — NOT the border-once wrapper used by
   .research-articles__grid. Figma 851:1644 outlines every cell individually, so
   the grid's outline follows the OCCUPIED cells: with a short final row (the "C"
   group is 5 terms → 3+2) the empty third slot gets no bottom edge and no right
   edge, and the last card keeps its own right border to close the box.

   A wrapper border can't express that — it would draw a full-width bottom rule
   straight under the empty slot. Hence border-on-each-card plus a -1px margin to
   overlap adjacent borders back down to a single 1px seam. */
.glossary-term-grid__grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 900px) {
  .glossary-term-grid__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .glossary-term-grid__grid {
    grid-template-columns: 1fr;
  }
}

.glossary-term-grid__card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 30px;
  background: var(--color-white);
  color: var(--color-navy-blue);
  text-decoration: none;
  font-family: var(--font-family-display);
  font-size: 20px;
  font-weight: var(--font-weight-semibold);
  line-height: 28px;
  /* Full outline on every card; seams collapse via the -1px margins below. */
  border: 1px solid var(--color-card-border);
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* Chevron/arrow icon inside the card, revealed on hover. */
.glossary-term-grid__card-arrow {
  flex: 0 0 auto;
  width: 14px;
  height: 5px;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.glossary-term-grid__card:hover,
.glossary-term-grid__card:focus-visible {
  background: var(--color-navy-blue);
  color: var(--color-white);
  outline: none;
}

.glossary-term-grid__card:hover .glossary-term-grid__card-arrow,
.glossary-term-grid__card:focus-visible .glossary-term-grid__card-arrow {
  opacity: 1;
  color: var(--color-green-2);
  transform: translateX(2px);
}

/* Seam collapse + corner radii.

   IMPORTANT: the grid items are the <li> wrappers, NOT .__card — the card is the
   li's only child, so :nth-child() on .__card always evaluates as position-1-of-1.
   That is what silently stripped every row divider before (`:nth-last-child(-n+3)`
   matched all cards). Always step through `> li`.

   Corners follow Figma 851:1644: top-left on the first card, top-right on the last
   card of row 1, bottom-left on the first card of the last row, and bottom-right
   ONLY when the final card actually lands in the last column. A short final row
   therefore ends square on the right — that's the design, not an oversight. */

/* --- Desktop (3 cols) --- */
@media (min-width: 901px) {
  .glossary-term-grid__grid > li:not(:nth-child(3n + 1)) {
    margin-left: -1px;
  }
  .glossary-term-grid__grid > li:nth-child(n + 4) {
    margin-top: -1px;
  }

  .glossary-term-grid__grid > li:first-child .glossary-term-grid__card {
    border-top-left-radius: 8px;
  }
  .glossary-term-grid__grid > li:nth-child(3) .glossary-term-grid__card,
  .glossary-term-grid__grid > li:nth-child(-n + 3):last-child .glossary-term-grid__card {
    border-top-right-radius: 8px;
  }
  .glossary-term-grid__grid > li:nth-child(3n + 1):nth-last-child(-n + 3) .glossary-term-grid__card {
    border-bottom-left-radius: 8px;
  }
  .glossary-term-grid__grid > li:nth-child(3n):last-child .glossary-term-grid__card {
    border-bottom-right-radius: 8px;
  }
}

/* --- Tablet (2 cols) --- */
@media (min-width: 601px) and (max-width: 900px) {
  .glossary-term-grid__grid > li:not(:nth-child(2n + 1)) {
    margin-left: -1px;
  }
  .glossary-term-grid__grid > li:nth-child(n + 3) {
    margin-top: -1px;
  }

  .glossary-term-grid__grid > li:first-child .glossary-term-grid__card {
    border-top-left-radius: 8px;
  }
  .glossary-term-grid__grid > li:nth-child(2) .glossary-term-grid__card,
  .glossary-term-grid__grid > li:nth-child(-n + 2):last-child .glossary-term-grid__card {
    border-top-right-radius: 8px;
  }
  .glossary-term-grid__grid > li:nth-child(2n + 1):nth-last-child(-n + 2) .glossary-term-grid__card {
    border-bottom-left-radius: 8px;
  }
  .glossary-term-grid__grid > li:nth-child(2n):last-child .glossary-term-grid__card {
    border-bottom-right-radius: 8px;
  }
}

/* --- Mobile (1 col): every card is its own full-width row --- */
@media (max-width: 600px) {
  .glossary-term-grid__grid > li:not(:first-child) {
    margin-top: -1px;
  }
  .glossary-term-grid__grid > li:first-child .glossary-term-grid__card {
    border-radius: 8px 8px 0 0;
  }
  .glossary-term-grid__grid > li:last-child .glossary-term-grid__card {
    border-radius: 0 0 8px 8px;
  }
  .glossary-term-grid__grid > li:only-child .glossary-term-grid__card {
    border-radius: 8px;
  }
}
