/* ============================================================
   SEM Lab — stylesheet
   Design tokens live in :root. Change colours/fonts there.
   ============================================================ */

:root {
  /* ---- Palette ---- */
  --ink:         #1a1f2b;   /* near-black slate, primary text */
  --paper:       #fbfaf7;   /* warm off-white background */
  --accent:      #3d348b;   /* deep indigo */
  --accent-dark: #2a2560;
  --accent-soft: #e2e0f2;   /* pale indigo wash */
  --muted:       #3f4654;   /* secondary text (darkened for readability) */
  --line:        #e6e3dc;   /* hairline rules / borders */
  --paper-2:     #f3f1ea;   /* alternate section background */

  /* ---- Type ---- */
  --font-display: "Newsreader", Georgia, serif;
  --font-body:    "Inter", system-ui, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, monospace;

  /* ---- Layout ---- */
  --measure: 1160px;        /* max content width */
  --gutter: clamp(1.25rem, 5vw, 4rem);
}

/* ---- Reset-ish ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent-dark); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }

/* ---- Utilities ---- */
.wrap { max-width: var(--measure); margin-inline: auto; padding-inline: var(--gutter); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1rem;
}
.serif { font-family: var(--font-display); }

/* ---- Headings ---- */
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 500; line-height: 1.12; color: var(--ink); }
h1 { font-size: clamp(2.4rem, 5vw, 3.6rem); letter-spacing: -0.01em; }
h2 { font-size: clamp(1.8rem, 3.4vw, 2.6rem); letter-spacing: -0.01em; margin-top: 0; }
h3 { font-size: 1.3rem; }
p { margin: 0 0 1.1rem; }

/* ============================================================
   Header / navigation
   ============================================================ */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding-block: 1rem;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  font-family: var(--font-display);
  font-size: 1.35rem; font-weight: 600; letter-spacing: -0.01em;
  color: var(--ink); text-decoration: none;
}
.brand:hover { color: var(--accent); }
.brand-mark { height: 34px; width: auto; max-width: none; object-fit: contain; display: block; }
.nav-links { display: flex; gap: 1.6rem; align-items: center; list-style: none; margin: 0; padding: 0; }
.nav-links a {
  font-size: 0.9rem; color: var(--ink); text-decoration: none;
  padding-block: 0.25rem; position: relative;
}
.nav-links a::after {
  content: ""; position: absolute; left: 0; bottom: -2px;
  width: 0; height: 1.5px; background: var(--accent); transition: width 0.22s ease;
}
.nav-links a:hover::after, .nav-links a[aria-current="true"]::after { width: 100%; }

/* Mobile nav toggle */
.nav-toggle { display: none; background: none; border: 0; cursor: pointer; padding: 0.5rem; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: var(--ink); margin: 4px 0; transition: 0.25s; }

/* ============================================================
   Hero
   ============================================================ */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.hero-inner {
  position: relative; z-index: 2;
  padding-block: clamp(5rem, 14vh, 9rem);
  max-width: 46rem;
}
.hero-affil { display: flex; flex-wrap: wrap; align-items: center; column-gap: 1.5rem; row-gap: 0.9rem; margin: 0 0 1.8rem; }
.affil-item { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; transition: opacity 0.2s; }
.affil-item:hover { opacity: 0.72; }
.affil-full { height: 36px; width: auto; object-fit: contain; }        /* Cambridge / CRUK CC lockups */
.affil-icon { height: 44px; width: auto; object-fit: contain; }        /* ECI magnifier icon */
.affil-label {
  font-family: var(--font-display); font-weight: 500; font-size: 1.12rem;
  line-height: 1.1; color: #1f2430; letter-spacing: 0.005em;
}
.hero h1 { margin: 0 0 0.6rem; }
.hero .tagline { font-family: var(--font-display); font-size: clamp(1.4rem, 2.6vw, 2rem); font-style: italic; color: var(--accent-dark); margin: 0 0 0.4rem; }
.hero .subtitle { font-family: var(--font-mono); font-size: 0.85rem; letter-spacing: 0.12em; color: var(--muted); margin: 0 0 2rem; }
.btn {
  display: inline-block; font-family: var(--font-mono); font-size: 0.8rem;
  letter-spacing: 0.08em; text-transform: uppercase; text-decoration: none;
  color: var(--paper); background: var(--accent); padding: 0.75rem 1.5rem;
  border-radius: 2px; transition: background 0.2s ease;
}
.btn:hover { background: var(--accent-dark); color: var(--paper); }

/* ============================================================
   Sections
   ============================================================ */
section { padding-block: clamp(3.5rem, 8vh, 6rem); }
.section-alt { background: var(--paper-2); }
.lead {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(1.5rem, 3vw, 2.15rem); line-height: 1.35;
  max-width: 40ch;
}
.lead em { color: var(--accent-dark); font-style: italic; }

/* Mission block (centred, like reference sites) */
.mission { max-width: 54rem; margin-inline: auto; text-align: center; }
.mission .lead { max-width: none; margin-inline: auto; margin-bottom: 2rem; }
.mission .body { color: var(--muted); max-width: 42rem; margin-inline: auto; text-align: left; }

/* Research cards */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.75rem; margin-top: 2.5rem; }
.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 3px; padding: 1.75rem; transition: border-color 0.2s, transform 0.2s;
}
.card:hover { border-color: var(--accent-soft); transform: translateY(-2px); }
.card .num { font-family: var(--font-mono); font-size: 0.75rem; color: var(--accent); letter-spacing: 0.1em; }
.card h3 { margin: 0.5rem 0 0.6rem; }
.card p { color: var(--muted); font-size: 0.98rem; margin: 0; }

/* Group photo */
.figure { margin: 0; }
.figure img, .figure .placeholder { border-radius: 4px; border: 1px solid var(--line); }
.figure figcaption { font-size: 0.85rem; color: var(--muted); margin-top: 0.85rem; }
.figure figcaption strong { color: var(--ink); }

/* Stat row */
.stats { display: flex; flex-wrap: wrap; gap: 2.5rem; margin-top: 2.5rem; }
.stat .n { font-family: var(--font-display); font-size: 2.6rem; line-height: 1; color: var(--accent-dark); }
.stat .l { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-top: 0.4rem; }

/* ============================================================
   People
   ============================================================ */
.people-list { display: flex; flex-direction: column; margin-top: 2.5rem; }
.person {
  display: grid; grid-template-columns: 11rem 1fr; gap: 1.75rem; align-items: start;
  text-align: left; padding: 1.75rem 0; border-top: 1px solid var(--line);
}
.person .avatar {
  width: 11rem; aspect-ratio: 1; border-radius: 4px; overflow: hidden; border: 1px solid var(--line);
  background: var(--accent-soft); flex-shrink: 0;
}
.person .avatar img { width: 100%; height: 100%; object-fit: cover; }
.person .name { font-family: var(--font-display); font-size: 1.2rem; margin: 0; }
.person .role { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin: 0.25rem 0 0.5rem; }
.person .blurb { font-size: 0.95rem; color: var(--muted); margin: 0; max-width: 42rem; }
.person .links { margin-top: 0.6rem; font-size: 0.8rem; }
.person .links a { margin-right: 0.6rem; }

/* Home-page team preview: compact photo-on-top cards in a grid */
.people-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem 1.75rem; margin-top: 2.5rem; }
.person-card { text-align: left; }
.person-card .avatar {
  width: 100%; aspect-ratio: 1; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--line); background: var(--accent-soft); margin-bottom: 0.85rem;
}
.person-card .avatar img { width: 100%; height: 100%; object-fit: cover; }
.person-card .name { font-family: var(--font-display); font-size: 1.1rem; margin: 0; }
.person-card .role { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin: 0.2rem 0 0; }

/* ============================================================
   Publications
   ============================================================ */
.pub-list { list-style: none; padding: 0; margin: 2.5rem 0 0; }
.pub {
  padding: 1.4rem 0; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: 5.5rem 1fr; gap: 1.5rem;
}
.pub:last-child { border-bottom: 1px solid var(--line); }
.pub .year { font-family: var(--font-mono); font-size: 0.9rem; color: var(--accent); padding-top: 0.15rem; }
.pub .title { font-family: var(--font-display); font-size: 1.15rem; margin: 0 0 0.3rem; }
.pub .authors { font-size: 0.92rem; color: var(--muted); margin: 0 0 0.3rem; }
.pub .venue { font-size: 0.9rem; margin: 0; }
.pub .venue em { color: var(--ink); }
.pub .tags { margin-top: 0.5rem; }
.pub .tag {
  font-family: var(--font-mono); font-size: 0.68rem; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--accent-dark); background: var(--accent-soft);
  padding: 0.2rem 0.55rem; border-radius: 2px; margin-right: 0.4rem; text-decoration: none;
}
.pub .tag:hover { background: var(--accent); color: var(--paper); }

/* ============================================================
   Prose pages (research, teaching, contact)
   ============================================================ */
.prose { max-width: 46rem; }
.prose h2 { margin-top: 2.75rem; }
.prose h3 { margin-top: 2rem; color: var(--accent-dark); }
.prose ul { padding-left: 1.2rem; }
.prose li { margin-bottom: 0.5rem; }
.prose blockquote {
  border-left: 3px solid var(--accent); margin: 1.5rem 0; padding: 0.3rem 0 0.3rem 1.3rem;
  font-family: var(--font-display); font-style: italic; color: var(--accent-dark);
}
/* Research prose: slightly wider text column, with figures below each
   section constrained to the same width as the text and left-aligned. */
.research-prose { max-width: 55rem; }
.research-prose img {
  width: 100%; max-width: 100%; height: auto; display: block;
  margin-block: 1.5rem;
  border-radius: 4px; border: 1px solid var(--line);
}

.page-head { border-bottom: 1px solid var(--line); padding-block: clamp(2.5rem,6vh,4rem) clamp(1.75rem,4vh,2.5rem); }
.page-head + section { padding-top: clamp(2rem,5vh,3rem); }
.page-head h1 { margin-bottom: 0.5rem; }
.page-head .kicker { color: var(--muted); max-width: 46rem; }

/* Contact card */
.contact-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 3rem; }
.contact-info dt { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin-top: 1.3rem; }
.contact-info dd { margin: 0.25rem 0 0; }
.contact-details { padding-bottom: 1rem; }
.contact-logo-section { padding-block: 0 4.5rem; }
.contact-logo-inner { display: flex; align-items: center; gap: 2.5rem; }
.contact-logo { height: 340px; width: auto; max-width: 100%; object-fit: contain; flex-shrink: 0; }
.contact-logo-text { border-left: 1px solid var(--line); padding-left: 2.5rem; }
.contact-logo-text .lab { font-family: var(--font-display); font-size: 2rem; margin: 0 0 0.5rem; }
.contact-logo-text p:not(.lab) { font-size: 1.1rem; color: var(--muted); margin: 0; }

/* ============================================================
   Footer
   ============================================================ */
.site-footer { border-top: 1px solid var(--line); background: var(--paper-2); }
.footer-inner { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 2rem; padding-block: 3.5rem; }
.footer-mark { height: 140px; width: auto; max-width: none; object-fit: contain; display: block; margin-bottom: 1rem; }
.site-footer .lab { font-family: var(--font-display); font-size: 1.25rem; margin: 0 0 0.5rem; }
.site-footer p { font-size: 0.9rem; color: var(--muted); margin: 0 0 0.4rem; }
.footer-col h4 { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 0.8rem; font-weight: 500; }
.footer-col a { display: block; font-size: 0.9rem; color: var(--ink); text-decoration: none; margin-bottom: 0.4rem; }
.footer-col a:hover { color: var(--accent); }
.footer-bottom { border-top: 1px solid var(--line); padding-block: 1.25rem; font-size: 0.8rem; color: var(--muted); display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem; }

/* ============================================================
   Gallery
   ============================================================ */
.gallery-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 2.5rem; }
.gallery-item {
  aspect-ratio: 4/3; border-radius: 4px; overflow: hidden; border: 1px solid var(--line);
  background: linear-gradient(135deg, #eeedf6, var(--accent-soft));
  display: flex; align-items: flex-end; position: relative;
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item .cap {
  position: absolute; inset: auto 0 0 0; padding: 0.6rem 0.8rem;
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.05em;
  color: #4a4590; background: linear-gradient(transparent, rgba(255,255,255,0.7));
}

/* ============================================================
   News
   ============================================================ */
.news-list { list-style: none; padding: 0; margin: 2.5rem 0 0; }
.news-item { padding: 1.5rem 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 8rem 1fr; gap: 1.5rem; }
.news-item:last-child { border-bottom: 1px solid var(--line); }
.news-item .date { font-family: var(--font-mono); font-size: 0.8rem; color: var(--accent); padding-top: 0.2rem; }
.news-item h3 { margin: 0 0 0.4rem; }
.news-item p { color: var(--muted); margin: 0; font-size: 0.98rem; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .contact-grid, .footer-inner { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
  .people-preview { grid-template-columns: repeat(2, 1fr); }
  .contact-logo-inner { flex-direction: column; text-align: center; }
  .contact-logo { height: 200px; }
  .contact-logo-text { border-left: none; padding-left: 0; }
}
@media (max-width: 640px) {
  .nav-toggle { display: block; }
  .nav-links {
    position: absolute; top: 100%; right: 0; left: 0;
    flex-direction: column; align-items: flex-start; gap: 0;
    background: var(--paper); border-bottom: 1px solid var(--line);
    padding: 0.5rem var(--gutter); max-height: 0; overflow: hidden; transition: max-height 0.28s ease;
  }
  .nav-links.open { max-height: 30rem; }
  .nav-links li { width: 100%; }
  .nav-links a { display: block; padding-block: 0.7rem; width: 100%; }
  .grid-3 { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: 1fr; }
  .pub { grid-template-columns: 1fr; gap: 0.4rem; }
  .news-item { grid-template-columns: 1fr; gap: 0.3rem; }
  .stats { gap: 1.5rem; }
  .person { grid-template-columns: 1fr; }
  .person .avatar { width: 7rem; }
  .people-preview { grid-template-columns: repeat(2, 1fr); gap: 1.5rem 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* Visible keyboard focus */
a:focus-visible, button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px;
}

/* ============================================================
   Data-motif decorations (SEM Lab design additions)
   Pairs with /js/sem-decor.js. Atmospheric, low-contrast SVG
   backdrops that echo the lab's own figure types.
   ============================================================ */
/* ============================================================
   SEM Lab — data-motif decoration layer
   Append to main.css.  Pairs with /js/sem-decor.js.
   Atmospheric, low-contrast backdrops that never touch text.
   ============================================================ */
.decor { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.decor svg { width: 100%; height: 100%; display: block; }

/* --- Placements ------------------------------------------------ */
/* Hero: lineage fanning from the left, a faint fishplot flowing behind */
.hero .decor--lineage { opacity: 0.45; }
.hero .decor--fish    { opacity: 0.16; z-index: 0; }

/* Page headers (research / software) */
.page-head { position: relative; overflow: hidden; }
.page-head .decor--fish  { opacity: 0.24; }
.page-head .decor--clone { opacity: 0.42; display: flex; justify-content: flex-end; }
.page-head .decor--clone svg { width: min(560px, 60%); margin-inline-end: -6%; }
.page-head > .wrap { position: relative; z-index: 2; }

/* Section flourishes: a cloneMap bleeding off one edge */
.decor--clone-edge { opacity: 0.34; display: flex; align-items: center; justify-content: flex-end; }
.decor--clone-edge svg { width: min(520px, 46%); margin-inline-end: -8%; }
.decor--dna { opacity: 0.14; align-items: flex-end; }

/* Real (recoloured) cloneMap images bleeding off a page-header edge */
.decor--clone-img { display: flex; align-items: center; }
.decor--clone-img.decor--right { justify-content: flex-end; }
.decor--clone-img.decor--left  { justify-content: flex-start; }
.decor--clone-img img {
  width: min(430px, 42%); height: auto; opacity: 0.3;
  mix-blend-mode: multiply;
}
.decor--clone-img.decor--right img { margin-inline-end: -7%; }
.decor--clone-img.decor--left  img { margin-inline-start: -7%; }
@media (max-width: 640px) { .decor--clone-img img { opacity: 0.2; width: 58%; } }

/* Sections that host a scattered background cloneMap need a positioning
   context, with their content lifted above it. */
.decor-host { position: relative; overflow: hidden; }
.decor-host > .wrap { position: relative; z-index: 1; }

/* A single faint cloneMap bleeding off an edge, at an explicit vertical
   offset down a long page — very low-key, never competes with content. */
.decor--scatter {
  position: absolute; inset: auto 0 auto 0; height: 34rem; z-index: 0;
  pointer-events: none; display: flex; align-items: center;
}
.decor--scatter.decor--right { justify-content: flex-end; }
.decor--scatter.decor--left  { justify-content: flex-start; }
.decor--scatter img { width: min(460px, 40%); height: auto; opacity: 0.2; mix-blend-mode: multiply; }
.decor--scatter.decor--right img { margin-inline-end: -7%; }
.decor--scatter.decor--left  img { margin-inline-start: -7%; }
@media (max-width: 640px) { .decor--scatter { display: none; } }


/* --- Motion (subtle; disabled for reduced-motion) -------------- */
/* NB: clone/fish colour is carried by each path's fill-opacity, NOT the
   animation — motifs stay fully visible even when animation isn't ticking. */
.fp-band { animation: fp-drift var(--dur, 30s) var(--d, 0s) ease-in-out infinite alternate; }
.cm-node { animation: cm-breathe 8s var(--d, 0s) ease-in-out infinite alternate; }
.decor .ln { stroke-dasharray: 640; stroke-dashoffset: 640; animation: ln-draw 2.6s ease forwards; }
.decor .nd { opacity: 0; animation: nd-in 0.6s ease forwards; animation-delay: 1.8s; }

@keyframes fp-drift  { from { transform: translateX(-10px); } to { transform: translateX(14px); } }
@keyframes cm-breathe{ 0% { transform: scale(0.992); } 100% { transform: scale(1.012); } }
@keyframes ln-draw   { to { stroke-dashoffset: 0; } }
@keyframes nd-in     { to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .fp-band, .cm-node, .decor .ln, .decor .nd { animation: none; }
  .decor .ln { stroke-dashoffset: 0; }
  .decor .nd { opacity: 1; }
}
