/* ==========================================================================
   Jérôme Guyot — site styles
   "Paper notebook": quiet palette, IBM Plex, lots of air.
   Sections: 1 tokens · 2 base · 3 header/footer · 4 home · 5 lists
             6 prose & reading pages · 7 utilities · 8 responsive · 9 print
   ========================================================================== */

/* 1. Design tokens ------------------------------------------------------- */

:root {
  --paper: #faf9f5;   /* background */
  --ink: #20394f;     /* headings */
  --body: #35424a;    /* body text */
  --soft: #646f78;    /* metadata (4.9:1 on paper, AA) */
  --rule: #d6dcd9;    /* thin lines */
  --link: #24577d;
  --link-line: #b7c7cf; /* underline under prose links */
  --amber: #b77a34;   /* accent: decoration + focus only, never body text */
  --mat: #eee5d5;     /* portrait backing */
  --wash: #f0f1eb;    /* code blocks */
  --motif: #335880;
  --tag-bg: #edf1f2;
  --tag-line: #cfdae0;
  --tag-text: #3e627a;

  /* Blog boxes: {: .theorem} {: .block} {: .example} {: .exercise} — line + background */
  --theorem-line: #b77a34;    --theorem-bg: #f6efe4;    /* amber */
  --definition-line: #24577d; --definition-bg: #edf2f6; /* ink blue */
  --example-line: #4d7a62;    --example-bg: #eef3ef;    /* sage */
  --exercise-line: #a4573d;   --exercise-bg: #f7eee9;   /* terracotta */
  --draft: #8a2f1d;           /* DRAFT banner + tag (local preview only) */

  --serif: "IBM Plex Serif", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;

  --page: 1020px;     /* max content width */
  --gutter: 28px;     /* side padding */
  --label-col: 190px; /* "label | content" sections */

  color-scheme: light;
}

/* Dark: chosen by the toggle, or by the system when JS is off. */
:root[data-theme="dark"] {
  --paper: #182731;
  --ink: #e6e9e6;
  --body: #ced5d7;
  --soft: #a0adb3;
  --rule: #3a4b55;
  --link: #b1cde1;
  --link-line: #4d6575;
  --amber: #dbad6c;
  --mat: #33424a;
  --wash: #22333d;
  --motif: #7f9bb3;
  --tag-bg: #243945;
  --tag-line: #435b68;
  --tag-text: #c0d6e2;
  --theorem-line: #dbad6c;    --theorem-bg: #2b3330;
  --definition-line: #8fb6d4; --definition-bg: #1f3442;
  --example-line: #8fbfa3;    --example-bg: #20342f;
  --exercise-line: #e09a7c;   --exercise-bg: #33302f;
  color-scheme: dark;
}
/* Same dark values, for visitors without JavaScript whose system is in dark mode. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --paper: #182731; --ink: #e6e9e6; --body: #ced5d7; --soft: #a0adb3;
    --rule: #3a4b55; --link: #b1cde1; --link-line: #4d6575; --amber: #dbad6c;
    --mat: #33424a; --wash: #22333d; --motif: #7f9bb3;
    --tag-bg: #243945; --tag-line: #435b68; --tag-text: #c0d6e2;
    --theorem-line: #dbad6c; --theorem-bg: #2b3330; --definition-line: #8fb6d4; --definition-bg: #1f3442;
    --example-line: #8fbfa3; --example-bg: #20342f; --exercise-line: #e09a7c; --exercise-bg: #33302f;
    color-scheme: dark;
  }
}

/* 2. Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--body);
  font: 16px/1.8 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 4px; }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 4px;
  border-radius: 2px;
}

h1, h2, h3 {
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 400;
  text-wrap: balance;
}
h1 { font-size: 48px; line-height: 1.2; letter-spacing: -1.8px; margin: 0 0 24px; }
h2 { font-size: 26px; line-height: 1.35; letter-spacing: -0.6px; margin: 0 0 20px; }
h3 { font-size: 22px; line-height: 1.4; letter-spacing: -0.35px; margin: 0 0 8px; }
p { margin: 0 0 20px; }

img { max-width: 100%; height: auto; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

/* 3. Header and footer --------------------------------------------------- */

.site-header,
.site-footer,
main {
  max-width: var(--page);
  margin: 0 auto;
  padding-inline: var(--gutter);
}

.site-header {
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 104px;
  border-bottom: 1px solid var(--rule);
}

.site-header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 30px;
  margin-right: auto;
  font-size: 14px;
}
.site-header nav a {
  position: relative;
  padding: 8px 0;
  color: var(--soft);
}
.site-header nav a:hover { color: var(--ink); text-decoration: none; }
.site-header nav a[aria-current="page"] { color: var(--ink); }
.site-header nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0; bottom: 1px;
  width: 18px; height: 2px;
  background: var(--amber);
}

.theme-toggle {
  display: grid;
  place-items: center;
  width: 40px; height: 40px; /* comfortable touch target */
  margin-right: -11px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink);
}
.theme-toggle:hover { background: var(--wash); }
:root[data-theme="dark"] .theme-toggle svg { transform: rotate(180deg); }
.theme-toggle svg { transition: transform 0.3s ease; }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px 24px;
  margin-top: 40px;
  padding-block: 26px 36px;
  border-top: 1px solid var(--rule);
  font-size: 13px;
  color: var(--soft);
}
.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  margin: 0; padding: 0;
  list-style: none;
}
.footer-note { flex-basis: 100%; margin: 0; }   /* the analytics line, on its own row */
.site-footer a { color: var(--soft); }
.site-footer a:hover { color: var(--link); }

main { min-height: 60vh; }

/* 4. Home ---------------------------------------------------------------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 45px;
  align-items: center;
  padding: 66px 0 70px;
  min-height: 420px;
}
.hero-discipline {
  margin-bottom: 16px;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: var(--soft);
}
.hero h1 {
  margin-bottom: 20px;
  font-size: 62px;
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -2.5px;
}
.hero-research {
  margin-bottom: 14px;
  font-size: 21px;
  line-height: 1.55;
  letter-spacing: -0.3px;
  color: var(--ink);
}
.hero-research span { display: block; } /* one line per item in site.yml */
.hero-position {
  margin-bottom: 26px;
  font-size: 15px;
  color: var(--body);
}
.hero-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin: 0; padding: 0;
  list-style: none;
  font-size: 13px;
}
.hero-contact a {
  display: inline-block;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--rule);
  overflow-wrap: anywhere;
}
.hero-contact a:hover { border-color: var(--amber); text-decoration: none; }

/* Portrait offset on a beige mat, with the polar-grid motif behind. */
.hero-portrait {
  position: relative;
  width: 300px;
  height: 290px;
}
.portrait {
  position: absolute;
  z-index: 2;
  top: 0; left: 17px;
  width: 210px; height: 250px;
  object-fit: cover;
  background: var(--mat);
}
.portrait-mat {
  position: absolute;
  top: 18px; left: 34px;
  width: 214px; height: 250px;
  background: var(--mat);
}
.portrait-motif {
  position: absolute;
  z-index: 1;
  right: -14px; bottom: -14px;
  width: 230px; height: 212px;
  color: var(--motif);
  opacity: 0.6;
}

/* "Label | content" sections below the hero. */
.split {
  display: grid;
  grid-template-columns: var(--label-col) minmax(0, 1fr);
  gap: 35px;
  padding: 42px 0 40px;
  border-top: 1px solid var(--rule);
}
.split-label h2 { margin-bottom: 10px; font-size: 26px; }
.more-link { font-size: 13px; color: var(--soft); }
.more-link span { margin-left: 8px; color: var(--amber); transition: margin 0.2s; }
.more-link:hover { color: var(--link); text-decoration: none; }
.more-link:hover span { margin-left: 12px; }

/* 5. Entry lists (home, archives, CV) ------------------------------------ */

.entries { min-width: 0; }

.entry {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  padding: 26px 0;
  border-bottom: 1px solid var(--rule);
  break-inside: avoid;
}
.entry:first-child { padding-top: 0; }
.entry:last-child { padding-bottom: 0; border-bottom: 0; }

.entry-year {
  margin: 0;
  padding-top: 3px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--soft);
}
.entry-title { margin: 0 0 6px; max-width: 620px; font-size: 22px; }
.entry-title a { color: var(--ink); }
.entry-title a:hover { color: var(--link); text-decoration: none; }
.entry--blog .entry-title { font-style: italic; font-size: 24px; }

.entry-authors,
.entry-summary { margin: 0 0 4px; font-size: 14px; line-height: 1.6; color: var(--soft); }
.entry-venue { margin: 0 0 4px; font-size: 14px; line-height: 1.6; }

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 10px; padding: 0;
  list-style: none;
}
.tag {
  padding: 1px 8px;
  border: 1px solid var(--tag-line);
  border-radius: 3px;
  background: var(--tag-bg);
  color: var(--tag-text);
  font-size: 12px;
  line-height: 1.6;
}

.resources {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 10px 0 0; padding: 0;
  list-style: none;
  font-size: 13px;
}
.resources a {
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 4px;
}
.resources a:hover { text-decoration-color: var(--amber); }

/* 6. Prose and reading pages --------------------------------------------- */

.prose { max-width: 700px; font-size: 16px; line-height: 1.85; }
.prose p { margin-bottom: 18px; }
.prose > :last-child { margin-bottom: 0; }
.prose a {
  text-decoration: underline;
  text-decoration-color: var(--link-line);
  text-underline-offset: 3px;
}
.prose a:hover { text-decoration-color: var(--amber); }
.prose strong { font-weight: 600; color: var(--ink); }
.prose h2 { margin-top: 40px; font-size: 29px; }
.prose h3 { margin-top: 30px; }
.prose blockquote {
  margin: 28px 0;
  padding: 2px 0 2px 22px;
  border-left: 2px solid var(--amber);
  color: var(--ink);
}
.prose pre {
  overflow-x: auto;
  padding: 18px;
  background: var(--wash);
  font: 13px/1.7 var(--mono);
}
.prose code { font-family: var(--mono); font-size: 0.88em; overflow-wrap: anywhere; }
.prose hr { margin: 36px 0; border: 0; border-top: 1px solid var(--rule); }

.reading { max-width: 740px; margin: 0 auto; padding: 50px 0 60px; }
.reading h1 { font-size: 44px; line-height: 1.25; margin-bottom: 16px; }
.eyebrow { margin-bottom: 14px; font-size: 13px; color: var(--soft); }

.back-link { display: inline-block; margin-bottom: 32px; font-size: 13px; color: var(--soft); }
.back-link:hover { color: var(--link); }
.article-labels { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 16px; }
.article-labels .tags { margin: 0; }
.article-date { font-size: 13px; color: var(--soft); }
.article-meta { margin-bottom: 4px; font-size: 16px; color: var(--soft); }
.article-venue { margin-bottom: 0; font-size: 15px; }
.article-lead { font-size: 18px; line-height: 1.6; color: var(--ink); }
.reading > .resources { margin: 16px 0 8px; font-size: 14px; }
.reading > .prose { margin-top: 34px; max-width: none; }
.small-heading {
  margin: 0 0 8px;
  font: 600 12px/1.6 var(--sans);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--soft);
}
.prose .small-heading { margin-top: 0; font-size: 12px; }

.presentations { margin: 22px 0 4px; }
.presentations ul { margin: 0; padding-left: 18px; font-size: 15px; }
.presentations .meta { color: var(--soft); }

.citation { margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--rule); font-size: 14px; }
.citation summary { cursor: pointer; color: var(--link); }
.citation pre {
  overflow-x: auto;
  margin: 14px 0 10px;
  padding: 16px 18px;
  background: var(--wash);
  font: 12.5px/1.65 var(--mono);
}
.copy-button, .text-button {
  padding: 0 0 3px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  color: var(--link);
  font-size: 13px;
}
.copy-button:hover, .text-button:hover { border-color: var(--amber); }
.copy-status { margin-left: 10px; font-size: 13px; color: var(--soft); }

/* Figures: images from Markdown; a "title" becomes the caption. */
.prose figure { margin: 30px 0; text-align: center; }
.prose figure img { display: block; margin: 0 auto; border-radius: 3px; }
.prose figcaption { margin-top: 10px; font-size: 14px; color: var(--soft); }
/* Drawings with transparent backgrounds stay readable on the dark page. */
:root[data-theme="dark"] .prose figure img { background: #f4f2ec; }

/* Theorem / definition / example / exercise boxes ({: .theorem} etc.) */
.box {
  --box-line: var(--rule);
  --box-bg: var(--wash);
  margin: 28px 0;
  padding: 16px 22px;
  border-left: 3px solid var(--box-line);
  border-radius: 0 4px 4px 0;
  background: var(--box-bg);
}
.box > :first-child { margin-top: 0; }
.box > :last-child { margin-bottom: 0; }
.box p { margin-bottom: 12px; }
.box figure { margin: 18px 0; }
.box--theorem    { --box-line: var(--theorem-line);    --box-bg: var(--theorem-bg); }
.box--definition { --box-line: var(--definition-line); --box-bg: var(--definition-bg); }
.box--example    { --box-line: var(--example-line);    --box-bg: var(--example-bg); }
.box--exercise   { --box-line: var(--exercise-line);   --box-bg: var(--exercise-bg); }
.box--remark     { --box-line: var(--soft); }
.box--display {
  border-left: 0;
  border-radius: 4px;
  text-align: center;
  font-size: 1.08em;
  overflow-x: auto;
}

/* Long display equations scroll instead of overflowing on phones. */
mjx-container[display="true"] { max-width: 100%; overflow-x: auto; overflow-y: hidden; }

/* Archive pages ----------------------------------------------------------- */

.page-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 16px 30px;
  padding: 56px 0 30px;
}
.page-heading h1 { margin: 0; }
.list-tools { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--soft); }
.list-tools input {
  width: 240px;
  max-width: 60vw;
  padding: 7px 2px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}
.list-tools input:focus-visible { outline-offset: 2px; border-color: var(--amber); }
.archive { padding-bottom: 40px; }
.archive .entry { grid-template-columns: 90px minmax(0, 1fr); padding: 30px 0; }
.archive .entry:first-child { padding-top: 0; }
.empty { color: var(--soft); }

/* Drafts (only in the local preview) ------------------------------------- */

.draft-banner {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 9px var(--gutter);
  background: var(--draft);
  color: #fff;
  font-size: 14px;
  text-align: center;
}
.draft-banner code { font-size: 0.92em; }
.tag--draft { border-color: var(--draft); background: var(--draft); color: #fff; font-weight: 600; letter-spacing: 0.4px; }

/* CV --------------------------------------------------------------------- */

.cv-header { margin-bottom: 10px; }
.cv-name { margin-bottom: 2px; font-size: 16px; color: var(--ink); }
.cv-contact { margin-bottom: 10px; font-size: 14px; }
.cv-prose { max-width: none; font-size: 15.5px; line-height: 1.7; }
.cv-prose h2 {
  margin: 40px 0 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
  font-size: 26px;
}
.cv-prose h3 { margin: 20px 0 2px; font-size: 19px; }
.cv-prose h3 a { color: var(--ink); text-decoration: none; }
.cv-prose h3 a:hover { color: var(--link); }
.cv-prose p { margin-bottom: 0; }
.cv-prose h2 + p { margin-top: 14px; }
.cv-prose strong { font-weight: 600; }

/* 7. Utilities ----------------------------------------------------------- */

.skip-link {
  position: absolute;
  z-index: 10;
  top: -100px; left: 20px;
  padding: 10px 14px;
  background: var(--paper);
  color: var(--link);
}
.skip-link:focus { top: 10px; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] { display: none !important; }

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

/* 8. Responsive ---------------------------------------------------------- */

@media (max-width: 860px) {
  .hero { grid-template-columns: minmax(0, 1fr) 235px; gap: 24px; }
  .hero h1 { font-size: 50px; }
  .hero-research { font-size: 18px; }
  .hero-portrait { width: 230px; height: 250px; }
  .portrait { left: 0; width: 176px; height: 210px; }
  .portrait-mat { left: 14px; top: 14px; width: 180px; height: 210px; }
  .portrait-motif { width: 185px; height: 170px; right: -6px; bottom: 0; }
  .split { grid-template-columns: 150px minmax(0, 1fr); gap: 25px; }
}

@media (max-width: 640px) {
  :root { --gutter: 22px; }

  .site-header { min-height: 76px; gap: 12px; }
  .site-header nav { gap: 2px 18px; font-size: 14px; }

  /* Portrait goes above the text on phones; the name gets the full width. */
  .hero {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 36px 0 40px;
    min-height: 0;
  }
  .hero-portrait { order: -1; width: 170px; height: 196px; }
  .portrait { width: 140px; height: 167px; }
  .portrait-mat { left: 12px; top: 12px; width: 140px; height: 167px; }
  .portrait-motif { width: 140px; height: 130px; right: -10px; bottom: 0; }
  .hero h1 { font-size: 42px; letter-spacing: -1.5px; margin-bottom: 14px; }
  .hero-research { font-size: 18px; }

  .split { grid-template-columns: 1fr; gap: 14px; padding: 30px 0; }
  .split-label { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
  .split-label h2 { margin: 0; font-size: 24px; }

  .entry { grid-template-columns: 1fr; gap: 2px; padding: 22px 0; }
  .entry-title, .entry--blog .entry-title { font-size: 20px; }

  .prose { font-size: 15.5px; }
  .reading { padding: 34px 0 44px; }
  .reading h1 { font-size: 34px; letter-spacing: -1px; }
  .box { padding: 14px 16px; margin-inline: -4px; }

  .page-heading { padding: 36px 0 24px; }
  .page-heading h1 { font-size: 38px; }
  .list-tools { width: 100%; }
  .list-tools input { flex: 1; max-width: none; }
  .archive .entry { grid-template-columns: 1fr; padding: 24px 0; }
}

/* 9. Print (used for the CV PDF) ----------------------------------------- */

@media print {
  :root, :root[data-theme="dark"] {
    --paper: #fff; --ink: #000; --body: #000; --soft: #444;
    --rule: #aaa; --link: #000; --tag-bg: transparent; --tag-text: #444;
  }
  .site-header, .site-footer, .skip-link, .theme-toggle, .cv-actions, .back-link,
  .copy-button, .draft-banner { display: none; }
  main { max-width: none; padding: 0; }
  body { font-size: 10.5pt; line-height: 1.5; }
  .reading { max-width: none; padding: 0; }
  .reading h1 { font-size: 24pt; margin-bottom: 4pt; }
  .cv-prose h2 { margin-top: 16pt; font-size: 14pt; }
  .cv-prose h3 { margin-top: 8pt; font-size: 11.5pt; break-after: avoid; }
  a { color: inherit; text-decoration: none; }
  .box { background: none; border-left-color: #888; }
}
