/* =============================================================
   CoMPhy Lab · Bridge Layer
   Loaded after tokens.css AND after styles.css, so its :root
   declarations win the cascade over the legacy --color-* names
   defined in styles.css.

   Purpose:
   1. Map legacy --color-*, --font-*, --shadow-* names declared in
      styles.css onto the new design-system tokens from tokens.css,
      so legacy pages pick up the new palette without rewrites.
   2. Scope the paper background + grid overlay declared in
      tokens.css so blog/project pages can opt out with body.no-grid.
   3. Declare design-system component primitives that the homepage,
      team page, research page, and per-paper microsites reuse
      (panel, eyebrow, lede, chip, btn-ghost, paper-card, news-row,
      team-tile, .visually-hidden helper).
   ============================================================= */

/* --- 1. Legacy variable bridge (light theme) ---------------- */
:root {
  /* Core palette */
  --color-primary: var(--c-brand-blue);
  --color-secondary: var(--c-paper-tint);
  --color-heading-h1: var(--c-brand-purple);
  --color-heading-h2: var(--c-brand-blue);
  --color-heading-h3: var(--fg-strong);
  --color-text: var(--fg-1);
  --color-background: var(--c-paper);
  --color-link: var(--c-accent-teal);
  --color-link-hover: var(--c-accent-teal-hover);

  /* Accents re-aliased to new tokens */
  --color-strong: var(--c-accent-coral);
  --color-blue-bright: var(--c-accent-violet);
  --color-blue-darker: var(--hero-grad-4);
  --color-red-bright: var(--c-accent-red);

  /* Typography — legacy names point at new stacks */
  --font-primary: var(--t-sans);
  --font-display: var(--t-display);

  /* Hero gradient legacy aliases */
  --intro-title-gradient-1: var(--hero-grad-1);
  --intro-title-gradient-2: var(--hero-grad-2);
  --intro-title-gradient-3: var(--hero-grad-3);
  --intro-title-gradient-4: var(--hero-grad-4);

  /* Footer bridge — paper-tint, not dark slab */
  --footer-bg: var(--c-paper-tint);
  --footer-text: var(--fg-1);
  --footer-link: var(--fg-1);
  --edit-link-text: var(--fg-2);
  --edit-link-border: var(--c-border);
  --edit-link-bg-hover: rgba(37, 76, 74, 0.08);
  --edit-link-border-hover: var(--c-accent-teal);
  --icon-color-footer-social: var(--fg-2);
}

/* --- 2. Legacy variable bridge (dark theme) -----------------
   Also runs a palette audit pass:
   - Paper lifted off near-black to a softer charcoal so the UI
     doesn't feel like a terminal. Warm hue preserved.
   - Surfaces get more separation (paper → tint → strong) so
     cards and panels visibly sit above the background.
   - Borders bumped from 0.08 → 0.14 alpha for visibility.
   - Hero gradient stops lifted for readability on dark (the
     light-mode stops go invisible against warm-black paper). */
:root[data-theme="dark"] {
  /* Softer dark surfaces — tracks closer to GitHub/Notion dark
     (~#181818) than near-black, while keeping the warm tint. */
  --c-paper:          #1b1814;
  --c-paper-tint:     #241f18;
  --c-surface-strong: #2b251d;
  --c-surface-glass:  rgba(43, 37, 29, 0.78);

  /* More visible separation lines. */
  --c-border:         rgba(248, 244, 236, 0.14);
  --c-border-strong:  rgba(248, 244, 236, 0.22);

  /* Hero wordmark gradient — brighter stops that don't disappear
     against the warm dark paper. */
  --hero-grad-1: #ff9388;
  --hero-grad-2: #cf75d3;
  --hero-grad-3: #8eaaff;
  --hero-grad-4: #7864cc;

  /* Legacy aliases */
  --color-primary: #8fb8ff;
  --color-background: var(--c-paper);
  --color-text: var(--fg-1);
  --color-heading-h1: #d99adc;
  --color-heading-h2: #8fb8ff;
  --color-heading-h3: var(--fg-strong);
  --color-link: var(--c-accent-teal);
  --color-link-hover: var(--c-accent-teal-hover);
  --color-strong: #f96;
  --footer-bg: var(--c-paper-tint);
  --footer-text: var(--fg-1);
  --footer-link: var(--fg-1);
  --edit-link-text: var(--fg-2);
  --edit-link-border: var(--c-border);
  --edit-link-bg-hover: rgba(106, 194, 189, 0.12);
  --edit-link-border-hover: var(--c-accent-teal);
  --icon-color-footer-social: var(--fg-2);
}

/* --- 3. Body background + grid overlay scoping -------------- */
/* tokens.css sets body { background: var(--c-paper) } and body::before
   grid overlay. We keep both, but let individual pages opt out with
   class="no-grid" for e.g. printable pages or future microsites. */
body.no-grid:before { display: none; }

/* The preloader/loader element in the layout should not sit on paper */
#preloader { background: var(--c-paper); }

/* --- 4. Type-system baseline (non-homepage pages) ----------- */
/* tokens.css already styles h1–h4 as Fraunces/Source-Serif, and body
   as Plex Sans. But legacy pages declare their own h2/h3 rules with
   gradient backgrounds inherited from styles.css — those are now
   neutralised where they would clash with the new look. */
body { font-family: var(--t-sans); color: var(--fg-1); }

/* styles.css applies Cormorant Garamond (the display font) to every
   h1–h6 sitewide. Cormorant is a calligraphic serif and reads as
   italicky even when upright — fine for the homepage wordmark, wrong
   for every other heading. Override back to Fraunces (tokens default)
   everywhere except the hero wordmark which carries its own class. */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--t-serif);
  font-style: normal;
}

/* --- 5. Design-system primitives (lifted from the style guide) --- */
.panel {
  background: var(--c-surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  box-shadow: var(--shadow-soft);
}

.card {
  background: var(--c-surface-strong);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
}

.eyebrow {
  font-family: var(--t-sans);
  font-size: var(--t-eyebrow);
  font-weight: var(--t-weight-semi);
  letter-spacing: var(--t-track-wide);
  text-transform: uppercase;
  color: var(--c-brand-purple);
}

:root[data-theme="dark"] .eyebrow { color: #c09bc4; }

.lede {
  font-size: var(--t-body-lg);
  line-height: 1.55;
  color: var(--fg-1);
  max-width: var(--maxw-read);
}

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: color-mix(in srgb, var(--fg-strong) 5%, transparent);
  color: var(--fg-1);
  border: 1px solid var(--c-border);
  border-radius: var(--r-pill);
  font-family: var(--t-sans);
  font-weight: var(--t-weight-med);
  font-size: 12px;
  letter-spacing: 0.02em;
  line-height: 1.6;
}

.chip--brand {
  background: color-mix(in srgb, var(--c-brand-purple) 10%, transparent);
  color: var(--c-brand-purple);
  border-color: color-mix(in srgb, var(--c-brand-purple) 22%, transparent);
}

.chip--blue {
  background: color-mix(in srgb, var(--c-brand-blue) 10%, transparent);
  color: var(--c-brand-blue);
  border-color: color-mix(in srgb, var(--c-brand-blue) 22%, transparent);
}

.chip--coral {
  background: color-mix(in srgb, var(--c-accent-coral) 10%, transparent);
  color: var(--c-accent-coral);
  border-color: color-mix(in srgb, var(--c-accent-coral) 22%, transparent);
}

:root[data-theme="dark"] .chip--brand { color: #d99adc; }

:root[data-theme="dark"] .chip--blue  { color: #8fb8ff; }

:root[data-theme="dark"] .chip--coral { color: #f96; }

/* Buttons — tokens.css ships .btn, .btn-ghost, .btn-pill. Keep the
   full button border while suppressing legacy link underlines. */
.btn, .btn-ghost, .btn-pill { text-decoration: none; }

/* Copyable helper */
.copyable { font-family: var(--t-mono); cursor: copy; }

/* Visually-hidden helper (used for legacy-SEO H1 fallback) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- 6. Logo tile + partner-mark helper ---------------------- */
.invert-on-light { filter: invert(1) brightness(0.4); }

:root[data-theme="dark"] .invert-on-light { filter: none; }

/* --- 7. Neutralise legacy site-footer dark slab ------------- */
/* styles.css gives .site-footer a near-black background + white
   text, with white social icons. Our paper footer takes over in
   _layouts/default.html, but pages that still render the old
   footer shell (if any) inherit paper colours here. */
.site-footer {
  background: var(--c-paper-tint);
  color: var(--fg-1);
  border-top: 1px solid var(--c-border);
}

.site-footer a { color: var(--fg-1); }

.site-footer a:hover { color: var(--c-accent-teal); }

.site-footer i { color: var(--fg-2); }

/* --- 8. News-row primitive (shared with /news archive) ------ */
.news-row {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: var(--s-4);
  align-items: start;
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--c-border);
}

.news-row:last-child { border-bottom: 0; }

.news-row__date {
  display: grid;
  text-align: center;
  padding: var(--s-2);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--c-brand-purple) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--c-brand-purple) 15%, transparent);
}

.news-row__day {
  font-family: var(--t-serif);
  font-size: 26px;
  font-weight: 700;
  color: var(--c-brand-purple);
  line-height: 1;
}

:root[data-theme="dark"] .news-row__day { color: #d99adc; }

.news-row__mo {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: var(--t-track-wide);
  color: var(--fg-2);
  margin-top: 4px;
}

.news-row__kicker {
  font-size: var(--t-eyebrow);
  font-weight: var(--t-weight-semi);
  color: var(--c-brand-blue);
  letter-spacing: var(--t-track-wide);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.news-row__body p {
  font-size: var(--t-body);
  line-height: 1.55;
  color: var(--fg-1);
  margin: 0;
}

/* --- 9. Paper-card primitive (for per-paper lists) ---------- */
.paper-card {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: var(--s-4);
  align-items: start;
  padding: var(--s-5);
  background: var(--c-surface-strong);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.paper-card__thumb {
  aspect-ratio: 3 / 4;
  background: linear-gradient(145deg, var(--c-brand-purple), var(--c-brand-blue));
  border-radius: var(--r-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--t-display);
  font-size: 22px;
}

.paper-card__thumb img { width: 100%; height: 100%; object-fit: cover; }

.paper-card__meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--s-2); }

.paper-card__title {
  font-family: var(--t-serif);
  font-size: var(--t-body-lg);
  font-weight: 600;
  color: var(--fg-strong);
  line-height: 1.3;
  margin-bottom: var(--s-2);
}

.paper-card__authors { font-size: var(--t-small); color: var(--fg-2); line-height: 1.55; margin-bottom: var(--s-3); }

.paper-card__links { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* --- 10. Team-tile primitive (used on /team and homepage) --- */
.team-tile {
  display: grid;
  gap: var(--s-2);
  padding: var(--s-4);
  background: var(--c-surface-strong);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.team-tile__avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--c-brand-purple), var(--c-accent-coral));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--t-serif);
  font-weight: 600;
  font-size: 24px;
}

.team-tile__name { font-family: var(--t-serif); font-weight: 600; color: var(--fg-strong); }

.team-tile__role { font-size: var(--t-small); color: var(--fg-2); }

@media (max-width: 820px) {
  .news-row { grid-template-columns: 70px 1fr; }

  .news-row > *:last-child { grid-column: 1 / -1; }

  .paper-card { grid-template-columns: 80px 1fr; }
}
