/* ═══════════════════════════════════════════════════════════
   RESEARCH INDEX — periodic-table grid
   Loaded only from index.html.

   Design: a dense grid of small tiles. Each tile shows just its
   prefix and title, subtly tinted by category. Hover → tile
   scales 1.5x, fills with full category color, reveals details.
   Click → soft depression before navigation.

   Easing: ease-out-expo throughout, no bounce.
   Color: only paper / ink / ink-soft / accent — no new hues.
   Grid: auto-fill, 180px tiles, tight gap. ~36 tiles fit in
   one screen on a typical desktop.
   ═══════════════════════════════════════════════════════════ */

/* ═══════════════════════════════════════════════════════════
   CATEGORY PALETTE
   Four categories + ATLAS, all derived from existing tokens.
   ═══════════════════════════════════════════════════════════ */
.research-index {
  /* M = neutral working models (cool, technical) */
  --cat-m-tint: color-mix(in oklab, var(--paper) 95%, var(--ink) 5%);
  --cat-m-fill: color-mix(in oklab, var(--ink) 92%, var(--accent) 8%);

  /* S = warm data stories (editorial argument) */
  --cat-s-tint: color-mix(in oklab, var(--paper) 91%, var(--accent) 9%);
  --cat-s-fill: color-mix(in oklab, var(--accent) 60%, var(--ink) 40%);

  /* P = full red paper anatomies (the deepest, freshest reads) */
  --cat-p-tint: color-mix(in oklab, var(--paper) 84%, var(--accent) 16%);
  --cat-p-fill: var(--accent);

  /* A = soft graphite algorithm primers (the textbook) */
  --cat-a-tint: color-mix(in oklab, var(--paper) 94%, var(--ink-soft) 6%);
  --cat-a-fill: color-mix(in oklab, var(--ink-soft) 70%, var(--ink) 30%);

  /* ATLAS = inverted (always assertive — it's the index) */
  --cat-atlas-tint: var(--ink);
  --cat-atlas-fill: var(--accent);
}

/* ═══════════════════════════════════════════════════════════
   INTRO
   ═══════════════════════════════════════════════════════════ */
.research-intro {
  max-width: 720px;
  margin: 0 0 28px;
}
.research-intro p {
  margin-top: 16px;
  font-family: 'Newsreader', serif;
  font-weight: 300;
  font-size: 17px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 60ch;
}

/* ═══════════════════════════════════════════════════════════
   TOOLBAR — chip filters + search + count
   ═══════════════════════════════════════════════════════════ */
.research-toolbar {
  margin: 0 0 32px;
  padding: 14px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  font-family: 'DM Mono', ui-monospace, monospace;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px 24px;
}

.research-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.research-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid color-mix(in oklab, var(--ink) 26%, transparent);
  background: transparent;
  color: var(--ink);
  padding: 6px 12px;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 220ms cubic-bezier(0.19, 1, 0.22, 1),
    border-color 220ms cubic-bezier(0.19, 1, 0.22, 1),
    color 220ms cubic-bezier(0.19, 1, 0.22, 1);
}
.research-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.research-chip.is-active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.research-chip .chip-count {
  display: inline-block;
  padding: 0 5px;
  font-size: 9px;
  letter-spacing: 0.06em;
  background: color-mix(in oklab, var(--ink) 8%, transparent);
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.research-chip.is-active .chip-count {
  background: color-mix(in oklab, var(--paper) 18%, transparent);
  color: color-mix(in oklab, var(--paper) 80%, transparent);
}

.research-search {
  position: relative;
  flex: 0 1 240px;
  min-width: 200px;
}
.research-search input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid color-mix(in oklab, var(--ink) 22%, transparent);
  padding: 5px 0 5px 22px;
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color 220ms cubic-bezier(0.19, 1, 0.22, 1);
}
.research-search input:focus {
  border-bottom-color: var(--accent);
}
.research-search input::placeholder {
  color: var(--ink-dim);
  font-style: italic;
}
.research-search .research-search-icon {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-65%);
  opacity: 0.5;
  pointer-events: none;
}

.research-readout {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: 0 0 auto;
}
.research-readout strong {
  color: var(--ink);
  font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════
   THE GRID
   ═══════════════════════════════════════════════════════════ */
.tile-grid {
  display: grid;
  /* Compressed Apr 2026 — was minmax(180px, 1fr). Smaller cards
     reduce wall-of-text density; full description still on hover. */
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 5px;
  padding: 18px 0;
  /* Allow the grid container to overflow its scaled children */
  overflow: visible;
}

@media (max-width: 720px) {
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 4px; }
}

/* ═══════════════════════════════════════════════════════════
   THE TILE
   ═══════════════════════════════════════════════════════════ */
.tile {
  /* Per-tile vars overridden via [data-cat] below */
  --tint: var(--cat-m-tint);
  --fill: var(--cat-m-fill);

  position: relative;
  /* squarer + tighter padding so tiles take less vertical room */
  aspect-ratio: 4 / 3;
  padding: 9px 11px 9px;
  background: var(--tint);
  color: var(--ink);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 6px;
  border: 1px solid color-mix(in oklab, var(--ink) 12%, transparent);
  /* overflow visible so the absolute-positioned detail panel can extend below */
  overflow: visible;
  isolation: isolate;

  transform-origin: center center;
  transform: scale(1);
  z-index: 1;

  transition:
    transform 320ms cubic-bezier(0.19, 1, 0.22, 1),
    background 240ms cubic-bezier(0.19, 1, 0.22, 1),
    color 240ms cubic-bezier(0.19, 1, 0.22, 1),
    border-color 240ms cubic-bezier(0.19, 1, 0.22, 1),
    box-shadow 320ms cubic-bezier(0.19, 1, 0.22, 1);

  /* Pre-paint reveal: stagger via --idx set in JS */
  animation: tile-in 520ms cubic-bezier(0.19, 1, 0.22, 1) backwards;
  animation-delay: calc(var(--idx, 0) * 14ms);

  will-change: transform;
}

@keyframes tile-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Per-category tints + fills */
.tile[data-cat="m"] { --tint: var(--cat-m-tint); --fill: var(--cat-m-fill); }
.tile[data-cat="s"] { --tint: var(--cat-s-tint); --fill: var(--cat-s-fill); }
.tile[data-cat="p"] { --tint: var(--cat-p-tint); --fill: var(--cat-p-fill); }
.tile[data-cat="a"] { --tint: var(--cat-a-tint); --fill: var(--cat-a-fill); }
.tile[data-cat="atlas"] {
  --tint: var(--cat-atlas-tint);
  --fill: var(--cat-atlas-fill);
  color: var(--paper);  /* Atlas is dark by default */
  border-color: var(--ink);
}
.tile[data-cat="atlas"] .tile-fig {
  color: var(--accent);
}
.tile[data-cat="atlas"] .tile-name {
  color: var(--paper);
}

/* Hover: scale up, fill with category color, reveal details */
.tile:hover,
.tile:focus-visible {
  transform: scale(1.5);
  background: var(--fill);
  color: var(--paper);
  border-color: var(--fill);
  box-shadow:
    0 18px 40px -12px color-mix(in oklab, var(--ink) 35%, transparent),
    0 4px 12px -4px color-mix(in oklab, var(--ink) 25%, transparent);
  z-index: 100;
  outline: none;
}

/* Click: brief depression mid-hover */
.tile:active {
  transform: scale(1.46);
  transition-duration: 90ms;
}

/* Tile content elements */
.tile-fig {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--accent);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  transition: color 240ms cubic-bezier(0.19, 1, 0.22, 1);
}
.tile:hover .tile-fig,
.tile:focus-visible .tile-fig {
  color: color-mix(in oklab, var(--paper) 85%, transparent);
}
.tile[data-cat="p"]:hover .tile-fig {
  color: var(--paper);  /* full white on red */
}

.tile-name {
  font-family: 'Newsreader', serif;
  font-weight: 400;
  font-size: 13px;
  line-height: 1.15;
  letter-spacing: -0.01em;
  margin: 6px 0 0;

  /* Two-line clamp by default */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 240ms cubic-bezier(0.19, 1, 0.22, 1);
}
.tile:hover .tile-name,
.tile:focus-visible .tile-name {
  color: var(--paper);
}
.tile[data-cat="atlas"] .tile-name {
  font-style: italic;
}

/* The detail panel is positioned absolutely below the tile so it can be
   any height without clipping or affecting the grid layout. On hover it
   slides into view as a contiguous extension of the colored card. */
.tile-detail {
  position: absolute;
  top: 100%;
  left: -1px;   /* align with tile border */
  right: -1px;
  background: var(--fill);
  color: var(--paper);
  padding: 12px 14px 14px;
  border: 1px solid var(--fill);
  border-top: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  pointer-events: none;
  transition:
    opacity 240ms cubic-bezier(0.19, 1, 0.22, 1),
    transform 280ms cubic-bezier(0.19, 1, 0.22, 1),
    visibility 0s linear 240ms;
}
.tile-detail-inner {
  /* No-op now — kept so existing markup works; content paints inside .tile-detail */
}

.tile:hover .tile-detail,
.tile:focus-visible .tile-detail {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
  transition-delay: 0s;
}

.tile-line {
  font-family: 'Newsreader', serif;
  font-weight: 300;
  font-style: italic;
  font-size: 11.5px;
  line-height: 1.4;
  margin: 0;
  color: color-mix(in oklab, var(--paper) 88%, transparent);

  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-meta-row {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.tile-metric {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: color-mix(in oklab, var(--paper) 60%, transparent);
  margin: 0;
  font-variant-numeric: tabular-nums;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-arrow {
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: color-mix(in oklab, var(--paper) 80%, transparent);
  flex-shrink: 0;
}

/* Hide tiles that don't match active filter or search */
.tile.is-filtered-out {
  display: none;
}

/* When the user navigates away (click triggered), the tile expands further
   and fades — this gives a satisfying "zooming into the page" effect that
   completes just as the new page loads. */
.tile.is-launching {
  transform: scale(1.8);
  opacity: 0;
  transition:
    transform 380ms cubic-bezier(0.19, 1, 0.22, 1),
    opacity 380ms cubic-bezier(0.19, 1, 0.22, 1);
  pointer-events: none;
  z-index: 200;
}

/* ═══════════════════════════════════════════════════════════
   EMPTY STATE
   ═══════════════════════════════════════════════════════════ */
.research-empty {
  display: none;
  margin: 80px auto;
  max-width: 480px;
  text-align: center;
  font-family: 'Newsreader', serif;
  font-style: italic;
  font-weight: 300;
  font-size: 22px;
  line-height: 1.4;
  color: var(--ink-dim);
}
.research-empty.is-visible { display: block; }

/* ═══════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .tile {
    animation: none;
    transition: background 200ms ease, color 200ms ease, border-color 200ms ease;
  }
  .tile:hover,
  .tile:focus-visible {
    transform: none;
    box-shadow: none;
  }
  .tile-detail {
    transition: opacity 150ms ease;
  }
  .tile.is-launching {
    transform: none;
  }
}

/* ═══════════════════════════════════════════════════════════
   MASTHEAD RESEARCH DROPDOWN — keep wider panel + counts
   ═══════════════════════════════════════════════════════════ */
.nav-dropdown-menu.nav-research {
  min-width: 280px;
}
.nav-dropdown-menu.nav-research .cat-count {
  display: inline-block;
  margin-left: 8px;
  padding: 0 6px;
  font-size: 9px;
  letter-spacing: 0.08em;
  background: color-mix(in oklab, var(--ink) 8%, transparent);
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
  vertical-align: 1px;
}
.nav-dropdown-menu.nav-research .nav-research-all {
  border-bottom: 1px solid color-mix(in oklab, var(--ink) 18%, transparent);
  padding-bottom: 12px;
  margin-bottom: 6px;
  font-weight: 500;
}
