/* ===========================================================================
   Mensch Lab — /lab and /lab/<study>

   Two surfaces share this sheet:
     1. /lab            the index: LAB spinner, filters, study/tool cards
     2. /lab/<study>    a single-viewport, game-menu style research page

   Everything here leans on tokens.css. No new colours are invented; the two
   studies differ only by --study-accent, set per page.
   =========================================================================== */

/* ─────────────────────────────────────────────────────────────────────────
   SHARED
   ───────────────────────────────────────────────────────────────────────── */

.lab-eyebrow {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}

/* the shared pill button, matching .about-btn on Home but usable on any bed */
.lab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 48px;
  padding: 0 var(--space-6);
  background: var(--glass);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink-strong);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.lab-btn:hover { background: rgba(255,255,255,.16); transform: translateY(-2px); }
.lab-btn--accent { background: var(--accent); border-color: var(--accent); color: var(--ink-on-accent); }
.lab-btn--accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--ink-on-accent); }

/* ─────────────────────────────────────────────────────────────────────────
   /lab — INDEX SECTION
   ───────────────────────────────────────────────────────────────────────── */

#lab-soil { position: fixed; inset: 0; z-index: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
#lab-main { position: relative; z-index: 1; }

/* Near-full-bleed: the two cards should read as a wide pair filling the screen,
   so the gutter is a slim fixed margin rather than a centred 1280px column.
   The max-width is a backstop for very large displays only. */
#lab-index {
  position: relative;
  padding: clamp(70px, 11vh, 130px) clamp(16px, 2.5vw, 44px) clamp(90px, 14vh, 170px);
  max-width: 2100px;
  margin: 0 auto;
}
/* With the hero gone the index is the first thing on the page, so it takes
   over the hero's job of clearing the fixed nav. */
.lab-index--solo {
  padding-top: clamp(120px, 17vh, 190px);
}

.lab-index-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-4);
  margin-bottom: clamp(40px, 6vh, 72px);
}

/* the second, smaller spinner — same frames, so it costs no extra download */
#lab-index-spinner {
  width: min(30vw, 180px);
  min-width: 120px;
  aspect-ratio: 900 / 557;
}

.lab-index-copy {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  line-height: var(--leading-body);
  color: var(--ink-muted);
  max-width: 62ch;
  margin: 0;
  text-wrap: pretty;
}

/* ── filters ── */
.lab-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.lab-filter {
  appearance: none;
  position: relative;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-2xs);
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  padding: 6px var(--space-4);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
/* the pill is drawn small, but the hit area still honours the 44px target */
.lab-filter::after { content: ''; position: absolute; inset: -9px 0; }
.lab-filter:hover { color: var(--ink-strong); border-color: var(--hairline-strong); }
.lab-filter[aria-pressed="true"] {
  color: var(--ink-on-accent);
  background: var(--accent);
  border-color: var(--accent);
}

.lab-count {
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: center;
  margin: var(--space-5) 0 0;
}

/* ── cards ──
   Full-width and stacked on mobile; two across from 860px up. The 1200x630
   proportion is held by aspect-ratio on wide screens, and released on narrow
   ones where a 1.9:1 box would squash the copy into an unreadable strip. */
.lab-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(16px, 2.2vw, 28px);
  margin-top: var(--space-8);
}
@media (min-width: 860px) {
  .lab-grid { grid-template-columns: repeat(2, 1fr); }
}

.lab-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 260px;
  padding: clamp(20px, 2.6vw, 46px);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  background: var(--scrim-soft);
  backdrop-filter: var(--blur-chrome);
  -webkit-backdrop-filter: var(--blur-chrome);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: border-color var(--dur-ui) var(--ease), transform var(--dur-ui) var(--ease), background var(--dur-ui) var(--ease);
}
@media (min-width: 860px) {
  .lab-card { aspect-ratio: 1200 / 630; min-height: 0; }
}
.lab-card:hover {
  border-color: var(--hairline-strong);
  background: rgba(0,0,0,.28);
  transform: translateY(-3px);
}
.lab-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* hidden by the filter — display:none rather than opacity so the grid reflows */
.lab-card[hidden] { display: none; }

.lab-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); }
.lab-card-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(26px, 3vw, 52px);
  line-height: var(--leading-tight);
  letter-spacing: var(--track-display);
  color: var(--ink-strong);
  margin: 0;
  text-wrap: balance;
}
.lab-card-title .uf { font-family: var(--font-black); font-weight: 700; }

.lab-card-arrow {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-circle);
  color: var(--ink-soft);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.lab-card:hover .lab-card-arrow { color: var(--accent); border-color: var(--accent-ring); transform: translate(2px, -2px); }

.lab-card-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-5);
  margin-top: var(--space-6);
}
.lab-card-copy {
  font-family: var(--font-body);
  font-size: clamp(14px, 1.05vw, 18px);
  line-height: var(--leading-body);
  color: var(--ink-muted);
  max-width: 48ch;
  margin: 0;
  text-wrap: pretty;
}
.lab-card-pills { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; flex: none; }
.lab-pill {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-3xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  padding: 4px var(--space-3);
  white-space: nowrap;
}
.lab-pill--research { color: var(--lime); border-color: rgba(187,238,47,.34); }
.lab-pill--tools { color: var(--sky); border-color: rgba(91,189,228,.34); }

/* ── a card whose destination isn't live yet ──
   [data-soon] cards stay clickable; the click is answered by this pill and an
   error blip (see the soon-handler on /lab) instead of a navigation. */
.lab-soon-pill {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(.92);
  padding: var(--space-2) var(--space-5);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-on-accent);
  background: var(--accent);
  border-radius: var(--radius-pill);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.lab-card.is-soon .lab-soon-pill { opacity: 1; transform: translate(-50%, -50%) scale(1); }
@media (prefers-reduced-motion: reduce) {
  .lab-soon-pill { transition: opacity var(--dur-fast) var(--ease); transform: translate(-50%, -50%); }
  .lab-card.is-soon .lab-soon-pill { transform: translate(-50%, -50%); }
}

@media (max-width: 599px) {
  .lab-card-bottom { flex-direction: column; align-items: flex-start; gap: var(--space-4); }
  .lab-card-pills { justify-content: flex-start; }
}

/* ─────────────────────────────────────────────────────────────────────────
   /lab/<study> — the single-viewport research page

   Layout is a three-row grid pinned to the viewport: header, tabs, body.
   The body is a two-column split — a rail that never changes, and a panel
   that swaps with the active tab. Only the panel scrolls.
   ───────────────────────────────────────────────────────────────────────── */

body.study-page { overflow: hidden; }
/* the shared footer is injected by web-chrome.js on every page; this surface
   is a fixed single screen, so it has nowhere to go. */
body.study-page #site-footer { display: none; }

#study-soil { position: fixed; inset: 0; z-index: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
/* Shows through if WebGL is unavailable or still compiling, so the page never
   flashes bare canvas colour. Each study sets its own via --study-bed. */
body.study-page { background: var(--study-bed, var(--canvas)); }

.study {
  position: relative;
  z-index: 1;
  height: 100svh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: clamp(72px, 9vh, 104px) clamp(14px, 3.2vw, 40px) clamp(14px, 2.4vh, 28px);
  box-sizing: border-box;
  gap: var(--space-3);
}

/* ── header ── */
.study-head {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--hairline);
}
.study-head-mark { height: 15px; width: auto; display: block; flex: none; opacity: .9; }
.study-head-div { width: 1px; height: 16px; background: var(--hairline-strong); flex: none; }
.study-head-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-sm);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-strong);
  margin: 0;
  white-space: nowrap;
}
.study-head-spacer { flex: 1; }
.study-live {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--text-3xs);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--study-accent, var(--accent));
  flex: none;
}
.study-live i {
  width: 6px; height: 6px; border-radius: var(--radius-circle);
  background: currentColor; display: inline-block;
  animation: study-pulse 2.4s var(--ease) infinite;
}
@keyframes study-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .study-live i { animation: none; } }

.study-exit {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--text-3xs);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--glass);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  text-decoration: none;
  flex: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.study-exit:hover { background: rgba(255,255,255,.16); color: var(--ink-strong); }

/* ── tab strip ──
   Seven tabs won't fit a phone, so the strip scrolls sideways rather than
   wrapping onto a second line and stealing height from the panel. */
.study-tabs {
  display: flex;
  gap: clamp(4px, 1.4vw, 22px);
  padding: 0 var(--space-2);
  border-bottom: 1px solid var(--hairline);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.study-tabs::-webkit-scrollbar { display: none; }

.study-tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--space-2) var(--space-2) var(--space-3);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  white-space: nowrap;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-xs);
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.study-tab:hover { color: var(--ink); }
.study-tab[aria-selected="true"] {
  color: var(--ink-strong);
  border-bottom-color: var(--study-accent, var(--accent));
}
.study-tab-n { font-size: var(--text-3xs); color: var(--ink-faint); font-weight: 500; }
.study-tab[aria-selected="true"] .study-tab-n { color: var(--study-accent, var(--accent)); }
.study-tab:disabled { opacity: .38; cursor: default; }
.study-tab:focus-visible { outline: 2px solid var(--study-accent, var(--accent)); outline-offset: -2px; }

/* ── body split ── */
.study-body {
  display: grid;
  grid-template-columns: minmax(230px, 260px) minmax(0, 1fr);
  gap: clamp(14px, 2vw, 28px);
  min-height: 0;
  padding-top: var(--space-2);
}

/* ── the persistent rail ── */
.study-rail {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--scrim);
  backdrop-filter: var(--blur-chrome);
  -webkit-backdrop-filter: var(--blur-chrome);
  scrollbar-width: thin;
}

/* The 3D issue mark (bolt / apple), shared with the About page's problem cards.
   No plate behind it — these are rendered with their own lighting and shadow,
   so a bordered tile would read as a sticker stuck on the panel. */
.study-glyph {
  width: 84px;
  height: auto;
  display: block;
  flex: none;
  margin-bottom: calc(var(--space-1) * -1);
  filter: drop-shadow(0 6px 16px rgba(5,4,2,.55));
}
.study-rail-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-2xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--track-display);
  color: var(--ink-strong);
  margin: 0;
}
.study-rail-status {
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0;
}

/* the stat block — the Atk / Spd / Stun grid, counted from the live dataset */
.study-stats {
  display: grid;
  gap: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--hairline);
  margin: 0;
}
.study-stat { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.study-stat dt {
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-soft);
}
.study-stat dd {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
  line-height: 1;
  color: var(--ink-strong);
  margin: 0;
  font-variant-numeric: tabular-nums;
}

/* study-progress meter — the quality bar from the reference */
.study-meter { padding-top: var(--space-4); border-top: 1px solid var(--hairline); }
.study-meter-label {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: var(--space-2);
}
.study-meter-track {
  height: 8px;
  border-radius: var(--radius-pill);
  background: rgba(0,0,0,.4);
  border: 1px solid var(--hairline);
  overflow: hidden;
}
.study-meter-fill {
  height: 100%;
  background: var(--study-accent, var(--accent));
  border-radius: var(--radius-pill);
}

.study-rail-cta { margin-top: auto; padding-top: var(--space-4); }
.study-rail-cta .lab-btn { width: 100%; min-height: 42px; font-size: var(--text-3xs); }

/* ── the swapping panel ── */
.study-panel {
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5) clamp(16px, 2vw, 28px) var(--space-6);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--scrim);
  backdrop-filter: var(--blur-chrome);
  -webkit-backdrop-filter: var(--blur-chrome);
  scrollbar-width: thin;
}
.study-panel:focus-visible { outline: 2px solid var(--study-accent, var(--accent)); outline-offset: -2px; }

.study-section + .study-section { margin-top: var(--space-7); }
.study-section-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-2xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--study-accent, var(--accent));
  margin: 0 0 var(--space-4);
}
.study-section-head::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--hairline);
}

/* Info tab — the thesis */
.study-thesis {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(17px, 1.65vw, 23px);
  line-height: 1.34;
  letter-spacing: -.005em;
  color: var(--ink);
  margin: 0;
  max-width: 68ch;
  text-wrap: pretty;
}
.study-thesis strong { color: var(--ink-strong); font-weight: 600; }

/* Info tab — focus areas with their own small meters */
.study-focus { display: grid; gap: var(--space-3); margin: 0; }
.study-focus-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 62px; align-items: center; gap: var(--space-4); }
.study-focus-name {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--ink);
  min-width: 0;
}
/* Both are spans (they sit inside a grid row, and a bar is not a paragraph).
   The track gets blockified for free as a grid item; the fill does not — it
   needs display:block explicitly or width/height are ignored and it collapses. */
.study-focus-track { display: block; height: 6px; border-radius: var(--radius-pill); background: rgba(0,0,0,.4); border: 1px solid var(--hairline); overflow: hidden; }
.study-focus-fill { display: block; height: 100%; background: var(--study-accent, var(--accent)); border-radius: var(--radius-pill); }
.study-focus-stage {
  font-family: var(--font-body);
  font-size: var(--text-3xs);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-faint);
  text-align: right;
}

/* the shared card grid used by Resources / People / Brand / Orgs / Signals */
.study-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: var(--space-3);
}
.study-card {
  display: block;
  padding: var(--space-4);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: rgba(0,0,0,.34);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
a.study-card:hover { border-color: var(--hairline-strong); background: rgba(0,0,0,.5); transform: translateY(-2px); }
a.study-card:focus-visible { outline: 2px solid var(--study-accent, var(--accent)); outline-offset: 2px; }
.study-card-name {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  color: var(--ink-strong);
  margin: 0;
}
.study-card-name .ext { color: var(--ink-faint); font-size: .82em; }
.study-card-src {
  font-family: var(--font-body);
  font-size: var(--text-2xs);
  color: var(--lime);
  margin: var(--space-1) 0 0;
}
.study-card-desc {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  line-height: 1.45;
  color: var(--ink-soft);
  margin: var(--space-2) 0 0;
}

/* empty state for the tabs whose data hasn't landed yet */
.study-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
  min-height: 260px;
  padding: var(--space-8) var(--space-5);
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-md);
}
.study-empty-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-xl);
  color: var(--ink);
  margin: 0;
}
.study-empty-body {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  line-height: var(--leading-body);
  color: var(--ink-soft);
  max-width: 46ch;
  margin: 0;
}

/* ── responsive ──
   Below 900px the rail stops being a column and becomes a compact header
   band above the panel: identity and stats stay visible, the meter and CTA
   fold away so the panel keeps as much height as possible. */
@media (max-width: 899px) {
  .study { grid-template-rows: auto auto auto minmax(0, 1fr); }
  .study-body { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .study-rail {
    flex-direction: row;
    align-items: center;
    gap: var(--space-4);
    overflow-x: auto;
    overflow-y: hidden;
    padding: var(--space-3) var(--space-4);
    /* the band swipes sideways to reach the later stats; the scrollbar itself
       is chrome we don't want sitting across the middle of the page */
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .study-rail::-webkit-scrollbar { display: none; }
  .study-rail > * { flex: none; }
  .study-glyph { width: 42px; margin-bottom: 0; }
  .study-rail-title { font-size: var(--text-lg); }
  .study-stats {
    display: flex;
    gap: var(--space-5);
    padding-top: 0;
    border-top: none;
    border-left: 1px solid var(--hairline);
    padding-left: var(--space-4);
  }
  .study-stat { flex-direction: column; align-items: flex-start; gap: 0; }
  .study-stat dd { font-size: var(--text-base); }
  .study-meter, .study-rail-cta, .study-rail-status { display: none; }
  .study-focus-row { grid-template-columns: minmax(0, 1fr) 64px 54px; gap: var(--space-3); }
}

@media (max-width: 599px) {
  .study { padding-left: var(--space-3); padding-right: var(--space-3); }
  .study-head-title { font-size: var(--text-xs); }
  .study-cards { grid-template-columns: 1fr; }
  .study-thesis { font-size: var(--text-base); }
}
