/* ==========================================================================
   Gustau Camps-Valls — site stylesheet (v2, 2026)
   Palette "sage & clay" · Source Serif 4 + Inter · light / dark
   ========================================================================== */

:root {
  --bg: #f7f5f0;
  --surface: #efece4;
  --surface-2: #e6e2d7;
  --text: #1f2a2a;
  --muted: #5b6764;
  --accent: #3f6f62;          /* sage */
  --accent-strong: #2f574c;
  --accent-soft: rgba(63, 111, 98, .10);
  --clay: #975232;            /* text-safe clay */
  --clay-soft: #b0643f;       /* decorative clay */
  --line: #dcd7cc;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(31, 42, 42, .04), 0 8px 24px rgba(31, 42, 42, .06);

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --max: 1080px;
  --gutter: clamp(16px, 4vw, 32px);
  --radius: 14px;
  --header-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161c1b;
    --surface: #1e2625;
    --surface-2: #26302e;
    --text: #e7e4dc;
    --muted: #a3aca8;
    --accent: #8fbfae;
    --accent-strong: #b0d6c8;
    --accent-soft: rgba(143, 191, 174, .12);
    --clay: #d99a78;
    --clay-soft: #d99a78;
    --line: #2e3836;
    --on-accent: #161c1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161c1b;
  --surface: #1e2625;
  --surface-2: #26302e;
  --text: #e7e4dc;
  --muted: #a3aca8;
  --accent: #8fbfae;
  --accent-strong: #b0d6c8;
  --accent-soft: rgba(143, 191, 174, .12);
  --clay: #d99a78;
  --clay-soft: #d99a78;
  --line: #2e3836;
  --on-accent: #161c1b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 17px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(2.4rem, 5.5vw, 3.6rem); }
h2 { font-size: clamp(1.7rem, 3.4vw, 2.3rem); }
h3 { font-size: 1.2rem; font-weight: 600; letter-spacing: 0; }
h1 em, h2 em { font-style: italic; color: var(--accent); }
p { margin: 0 0 1em; }
ul, ol { margin: 0; padding: 0; list-style: none; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; padding: 8px 14px; background: var(--accent); color: var(--on-accent); border-radius: 8px; }
.skip-link:focus { top: 12px; }

.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
@supports not (background: color-mix(in srgb, red 50%, blue)) { .site-header { background: var(--bg); } }
.site-header .wrap { display: flex; align-items: center; gap: 1rem; min-height: var(--header-h); }
.brand { font-family: var(--serif); font-size: 1.15rem; color: var(--text); text-decoration: none; white-space: nowrap; margin-right: auto; }
.brand:hover { color: var(--accent); }
.nav { display: flex; gap: .25rem; }
.nav a {
  font-size: .875rem; font-weight: 500; color: var(--muted); text-decoration: none;
  padding: .4rem .7rem; border-radius: 999px; white-space: nowrap;
  transition: color .2s, background-color .2s;
}
.nav a:hover { color: var(--text); background: var(--accent-soft); }
.nav a[aria-current] { color: var(--accent); background: var(--accent-soft); }
.theme-toggle {
  flex: none; display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; }
/* light mode shows the moon (switch to dark); dark mode shows the sun */
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: none; }
}

@media (max-width: 820px) {
  html { scroll-padding-top: 120px; }
  .site-header .wrap { flex-wrap: wrap; gap: 0 .5rem; padding-top: .5rem; }
  .brand { order: 1; }
  .theme-toggle { order: 2; }
  .nav {
    order: 3; width: calc(100% + 2 * var(--gutter)); margin: .35rem calc(-1 * var(--gutter)) 0;
    padding: 0 var(--gutter) .55rem; overflow-x: auto; scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent);
    mask-image: linear-gradient(90deg, #000 85%, transparent);
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { background: var(--surface); }
}

/* ---------- sections ---------- */
main { display: block; }
.section { padding: clamp(3rem, 7vw, 5.5rem) 0; border-top: 1px solid var(--line); }
.section:first-child { border-top: 0; }
.section--tint { background: var(--surface); }
.eyebrow {
  display: inline-flex; align-items: center; gap: .6rem; margin-bottom: .8rem;
  font-size: .75rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--clay);
}
.eyebrow::before { content: ""; width: 22px; height: 1px; background: currentColor; }
.lead { font-size: 1.12rem; color: var(--muted); max-width: 62ch; }
.section-foot { margin-top: 2rem; display: flex; flex-wrap: wrap; gap: .75rem; }

/* ---------- buttons & tags ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem;
  padding: .6rem 1.1rem; border-radius: 999px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--on-accent);
  font-size: .9rem; font-weight: 500; text-decoration: none; line-height: 1.2;
  transition: background-color .2s, color .2s, border-color .2s, transform .2s;
}
.btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); transform: translateY(-1px); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn--ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn svg { width: 15px; height: 15px; }
.tags { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag {
  display: inline-block; padding: .22rem .65rem; border-radius: 999px;
  font-size: .78rem; font-weight: 500; color: var(--accent);
  background: var(--accent-soft); border: 1px solid transparent; text-decoration: none;
}
a.tag:hover { border-color: var(--accent); }

/* ---------- hero ---------- */
.hero { padding: clamp(2.5rem, 7vw, 5rem) 0 clamp(2.5rem, 6vw, 4rem); }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: clamp(2rem, 5vw, 4rem); align-items: center; }
.hero h1 { margin-bottom: .25em; }
.hero .role { font-size: 1.05rem; font-weight: 500; color: var(--muted); margin-bottom: 1.4rem; }
.hero .bio { font-family: var(--serif); font-size: clamp(1.15rem, 2vw, 1.32rem); line-height: 1.55; max-width: 36em; }
.hero .actions { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1.6rem 0 1.4rem; }
.portrait { position: relative; justify-self: center; width: min(100%, 380px); }
.portrait img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 50% 50% 46% 54% / 55% 48% 52% 45%; box-shadow: var(--shadow); }
.portrait::before {
  content: ""; position: absolute; inset: -14px -14px 14px 14px; z-index: -1;
  border-radius: 48% 52% 55% 45% / 50% 46% 54% 50%; background: var(--accent-soft); border: 1px solid var(--line);
}
.portrait::after {
  content: ""; position: absolute; width: 18%; aspect-ratio: 1; right: 4%; top: 2%;
  border-radius: 50%; background: var(--clay-soft); opacity: .85;
}
@media (max-width: 760px) {
  .hero-grid { grid-template-columns: 1fr; }
  .portrait { grid-row: 1; width: 168px; justify-self: start; }
  .portrait::before { inset: -8px -8px 8px 8px; }
}

/* current roles */
.roles { display: grid; gap: .35rem; font-size: .93rem; color: var(--text); }
.roles li { position: relative; padding-left: 1.1rem; }
.roles li::before { content: ""; position: absolute; left: 0; top: .62em; width: 6px; height: 6px; border-radius: 50%; background: var(--clay-soft); }
.roles a { color: inherit; text-decoration-color: var(--line); }
.roles a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* stats  (b or strong both work: some HTML editors rewrite <b> as <strong>) */
.stats dd { margin: 0; line-height: 1.35; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; margin-top: clamp(2rem, 5vw, 3rem); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stat { background: var(--bg); padding: 1rem 1.1rem; box-shadow: 0 0 0 1px var(--line); }
@media (min-width: 561px) and (max-width: 900px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr 1fr; } .stat:last-child:nth-child(odd) { grid-column: 1 / -1; } }
.stat b, .stat strong { display: block; font: 400 1.7rem/1.1 var(--serif); color: var(--accent); }
.stat span { font-size: .82rem; color: var(--muted); }

/* ---------- news ---------- */
.news { display: grid; gap: 0; border-top: 1px solid var(--line); }
.news li { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: 1rem; padding: 1rem 0; border-bottom: 1px solid var(--line); }
.news time { font-size: .82rem; font-weight: 600; color: var(--clay); padding-top: .15rem; letter-spacing: .02em; }
.news p { margin: 0; }
@media (max-width: 560px) { .news li { grid-template-columns: 1fr; gap: .2rem; } }

/* ---------- cards ---------- */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.grid--wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.card {
  position: relative; display: flex; flex-direction: column; gap: .5rem;
  padding: 1.35rem 1.35rem 1.25rem; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.section--tint .card { background: var(--bg); }
.card h3 { margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }
.card .icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.card .icon svg { width: 20px; height: 20px; }
a.card { color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow); }
.card .more { margin-top: auto; padding-top: .4rem; font-size: .85rem; font-weight: 500; color: var(--accent); }
.card .meta { font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--clay); }

/* vision quote */
.vision { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: clamp(1.5rem, 5vw, 4rem); margin-bottom: 2.5rem; }
.vision blockquote { align-self: start; margin: 0; padding-left: 1.2rem; border-left: 2px solid var(--clay-soft); font: italic 400 clamp(1.25rem, 2.4vw, 1.6rem)/1.45 var(--serif); }
@media (max-width: 760px) { .vision { grid-template-columns: 1fr; } }

/* ---------- timeline ---------- */
.timeline { position: relative; margin-top: 2.5rem; padding-left: 1.6rem; }
.timeline::before { content: ""; position: absolute; left: 5px; top: .5rem; bottom: .5rem; width: 1px; background: var(--line); }
.timeline li { position: relative; padding-bottom: 1.6rem; }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: calc(-1.6rem + 1px); top: .45rem; width: 9px; height: 9px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--accent);
}
.timeline li:last-child::before { background: var(--accent); }
.timeline .when { font-size: .78rem; font-weight: 600; letter-spacing: .06em; color: var(--clay); text-transform: uppercase; }
.timeline h3 { margin: .15rem 0 .25rem; }
.timeline p { margin: 0; color: var(--muted); max-width: 70ch; }

/* ---------- paper list ---------- */
.papers { border-top: 1px solid var(--line); }
.papers li { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.papers .venue { font-size: .8rem; font-weight: 600; color: var(--clay); letter-spacing: .02em; }
.papers .title { display: block; font: 400 1.12rem/1.4 var(--serif); color: var(--text); text-decoration: none; margin: .1rem 0 .2rem; }
.papers a.title:hover { color: var(--accent); }
.papers a.title::after { content: " ↗"; font-family: var(--sans); font-size: .8em; color: var(--accent); opacity: 0; transition: opacity .2s; }
.papers a.title:hover::after { opacity: 1; }
.papers .authors { display: block; font-size: .88rem; color: var(--muted); }
.papers .title + .authors + .venue { display: block; margin-top: .15rem; font-weight: 500; }
.papers .authors b, .papers .authors strong { color: var(--text); font-weight: 600; }
.papers .note { font-size: .9rem; color: var(--muted); margin: .25rem 0 0; }

/* ---------- two-column lists (honours, positions) ---------- */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 1.5rem clamp(2rem, 5vw, 4rem); }
.col-title { font-size: .78rem; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding-bottom: .6rem; border-bottom: 1px solid var(--line); margin-bottom: .4rem; }
.dl li { display: grid; grid-template-columns: 5.2rem minmax(0, 1fr); gap: .8rem; padding: .6rem 0; border-bottom: 1px dashed var(--line); }
.dl li:last-child { border-bottom: 0; }
.dl .y { font-size: .85rem; font-weight: 600; color: var(--clay); padding-top: .1rem; font-variant-numeric: tabular-nums; }
.dl .what { font-weight: 500; }
.dl .who { display: block; font-size: .88rem; color: var(--muted); }
.dl a { color: inherit; text-decoration-color: var(--line); }
.dl a:hover { color: var(--accent); text-decoration-color: var(--accent); }

/* projects */
.project .role { align-self: flex-start; }

/* ---------- page header (subpages) ---------- */
.page-head { padding: clamp(2.5rem, 7vw, 4.5rem) 0 clamp(1.5rem, 4vw, 2.5rem); }
.page-head h1 { margin-bottom: .3em; }
.page-head .lead { margin-bottom: 0; }
.toc { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: 1.4rem; }

/* ---------- publications page ---------- */
.pub-tools { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin: 1.5rem 0 .5rem; }
.pub-tools input {
  flex: 1 1 260px; min-width: 0; padding: .65rem 1rem; font: inherit; font-size: .95rem;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
}
.pub-tools input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pub-count { font-size: .85rem; color: var(--muted); }
.year-group h2 { font-size: 1.5rem; color: var(--accent); margin: 2.2rem 0 .3rem; position: sticky; top: var(--header-h); background: var(--bg); padding: .4rem 0; z-index: 2; }
.year-group[hidden] { display: none; }
.pub[hidden] { display: none; }
.year-jump { display: flex; flex-wrap: wrap; gap: .3rem; }
.year-jump a { font-size: .8rem; padding: .15rem .5rem; border-radius: 6px; text-decoration: none; color: var(--muted); background: var(--surface); }
.year-jump a:hover { color: var(--accent); }
@media (max-width: 820px) { .year-group h2 { top: 104px; } }

/* ---------- gallery ---------- */
.gallery { columns: 3 260px; column-gap: 1rem; }
.gallery figure { break-inside: avoid; margin: 0 0 1rem; }
.gallery a { display: block; border-radius: 10px; overflow: hidden; background: var(--surface); }
.gallery img { width: 100%; transition: transform .5s ease, opacity .3s; }
.gallery a:hover img { transform: scale(1.03); }
.gallery figcaption { padding: .5rem .2rem 0; font: italic 400 .98rem/1.45 var(--serif); color: var(--muted); }
.verse { display: block; }

.lightbox { width: min(96vw, 1100px); max-height: 94vh; padding: 0; border: 0; border-radius: var(--radius); background: var(--bg); color: var(--text); box-shadow: var(--shadow); }
.lightbox::backdrop { background: rgba(15, 20, 19, .82); }
.lightbox figure { margin: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; max-height: 94vh; }
.lightbox img { max-height: calc(94vh - 90px); width: auto; max-width: 100%; margin: 0 auto; object-fit: contain; }
.lightbox figcaption { padding: .8rem 4rem; text-align: center; font: italic 400 1.1rem/1.5 var(--serif); min-height: 3.4rem; }
.lb-btn {
  position: absolute; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; font-size: 1.1rem;
}
.lb-btn:hover { border-color: var(--accent); color: var(--accent); }
.lb-close { top: 10px; right: 10px; }
.lb-prev { left: 10px; bottom: 14px; }
.lb-next { right: 10px; bottom: 14px; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding: 3rem 0 2rem; font-size: .92rem; }
.footer-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 2rem; }
.site-footer address { font-style: normal; color: var(--muted); line-height: 1.7; }
.site-footer address strong { color: var(--text); font-weight: 600; }
.links { display: flex; flex-wrap: wrap; gap: .4rem .9rem; align-content: flex-start; }
.links a { color: var(--muted); text-decoration: none; font-weight: 500; }
.links a:hover { color: var(--accent); }
.funders { margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); }
.funders span + span::before { content: "·"; margin: 0 .5rem; opacity: .6; }
.copyright { margin-top: 1rem; font-size: .8rem; color: var(--muted); }
@media (max-width: 760px) { .footer-grid { grid-template-columns: 1fr; } }

/* ---------- motion (progressive) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .js .reveal { opacity: 0; transform: translateY(14px); transition: opacity .7s ease, transform .7s ease; }
  .js .reveal.in { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media print {
  .site-header, .theme-toggle, .site-footer .links, .pub-tools { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .section { padding: 1rem 0; }
}
