/* ─────────────────────────────────────────────────────────────
   Theme tokens
   ───────────────────────────────────────────────────────────── */
:root {
  --content-width: 1375px;
  --sidebar-width: 264px;
  --radius: 14px;
  --font: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* Light theme — warm cream paper (#FAF8EE = rgb(250,248,238)) */
[data-theme="light"] {
  --bg: #faf8ee;
  --bg-alt: #f1eedd;
  --surface: #fffdf6;
  --border: #e3ddc9;
  --text: #2a2722;
  --text-muted: #6d675a;
  --accent: #5b54d6;
  --accent-hover: #4840c4;
  --accent-soft: rgba(91, 84, 214, 0.12);
  --accent-contrast: #ffffff;
  --button-bg: #f0edf9;
  --button-hover: #e6e0f3;
  --button-text: #554b78;
  --button-border: #c9c1df;
  --shadow: 0 1px 2px rgba(60, 50, 20, 0.05), 0 10px 30px rgba(60, 50, 20, 0.08);
}

[data-theme="dark"] {
  --bg: #14130f;
  --bg-alt: #1c1b16;
  --surface: #1d1c17;
  --border: #322f27;
  --text: #ece8df;
  --text-muted: #a39d8d;
  --accent: #a5b4fc;
  --accent-hover: #c3ccff;
  --accent-soft: rgba(165, 180, 252, 0.14);
  --accent-contrast: #14130f;
  --button-bg: #414b79;
  --button-hover: #515e91;
  --button-text: #f1f3ff;
  --button-border: #899bd3;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.4);
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  /* Flex column so the footer can be anchored to the bottom of the viewport
     even when the page content is short (sticky footer). */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 1.1rem;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background 0.25s ease, color 0.25s ease;
}

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button { font-weight: 700; }

h1, h2, h3, h4 { line-height: 1.25; font-weight: 700; letter-spacing: -0.02em; }

code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.12em 0.4em;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: 0.6rem 1rem;
  border-radius: 0 0 8px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; color: var(--accent-contrast); }

/* ─────────────────────────────────────────────────────────────
   Layout: main content + right sidebar
   ───────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  gap: 4rem;
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 0;
  /* Grow to fill remaining height so the footer is pushed to the bottom. */
  flex: 1 0 auto;
}
.layout__main { min-width: 0; }

/* Right-hand vertical navigation with portrait on top */
.sidebar {
  /* Desktop portrait size; compact layouts use the smaller sizes below. */
  --portrait-size: 234px;
  --portrait-compact-size: 117px;
  --portrait-phone-size: clamp(5.465rem, 25.502vw, 6.376rem);
  position: sticky;
  top: 2.5rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
}
.sidebar__portrait {
  display: block;
  width: var(--portrait-size);
  height: var(--portrait-size);
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--border);
  background: var(--bg-alt);
  transition: border-color 0.2s, transform 0.2s;
}
.sidebar__portrait:hover { border-color: var(--accent); transform: translateY(-2px); }
.sidebar__portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
  transform: scale(1.15);
  transform-origin: center 40%;
  display: block;
}
.sidebar__name { width: 100%; font-weight: 700; font-size: 1.155rem; margin: 0.9rem 0 0.15rem; }
.sidebar__role {
  width: 100%;
  color: var(--text-muted);
  font-size: 0.902rem;
  margin: 0 0 1.25rem;
  white-space: nowrap;
}

.sidebar__nav { display: flex; flex-direction: column; gap: 0.15rem; width: 100%; }
.sidebar__nav a {
  display: block;
  padding: 0.5rem 0 0.5rem 0.9rem;
  border-radius: 9px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 1.078rem;
  transition: background 0.15s, color 0.15s;
}
.sidebar__nav a:hover { background: var(--bg-alt); color: var(--text); }
.sidebar__nav a.is-active { color: var(--accent); background: var(--accent-soft); }

.sidebar__toggle { margin-top: 1.5rem; }

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--button-border);
  border-radius: 50%;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.theme-toggle:hover { background: var(--button-hover); transform: rotate(15deg); }
.theme-toggle__moon { display: none; }
[data-theme="dark"] .theme-toggle__sun { display: none; }
[data-theme="dark"] .theme-toggle__moon { display: block; }

/* Sidebar collapses to a top bar on narrow screens */
@media (max-width: 946px) {
  .layout { grid-template-columns: 1fr; gap: 0; padding-top: 1.5rem; }
  .sidebar {
    position: static;
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
  }
  .sidebar__portrait { width: var(--portrait-compact-size); height: var(--portrait-compact-size); }
  .sidebar__name { width: 100%; margin: 0.5rem 0 0; }
  .sidebar__role { width: 100%; margin: 0 0 0.5rem; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; width: auto; }
  .sidebar__toggle { margin: 0 0 0 0.25rem; }
}

/* ─────────────────────────────────────────────────────────────
   Hero (home)
   ───────────────────────────────────────────────────────────── */
.hero { padding: 0.98rem 0 1.63rem; }
.hero__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.858rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 0.8rem;
}
.hero__title {
  /* Scales with viewport, clamped between 1.32rem and 2.64rem */
  font-size: clamp(1.32rem, 4.4vw, 2.64rem);
  margin: 0 0 1rem;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero__lead {
  font-size: clamp(1.155rem, 2.75vw, 1.375rem);
  color: var(--text-muted);
  max-width: 46ch;
  margin: 0 0 1.75rem;
}
.hero__actions { display: flex; flex-wrap: wrap; gap: 0.8rem; }
.hero__actions--home { padding-bottom: 50px; }

/* ─────────────────────────────────────────────────────────────
   Buttons
   ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 0.65rem 1.3rem;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1.023rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: var(--accent-hover); color: var(--accent-contrast); }
[data-theme="light"] .btn--primary {
  background: var(--button-bg);
  border-color: var(--button-border);
  color: var(--button-text);
}
[data-theme="light"] .btn--primary:hover { background: var(--button-hover); }
[data-theme="light"] .btn--cv {
  background: #c9bbe2;
  border-color: #a28bbb;
  color: #403653;
}
[data-theme="light"] .btn--cv:hover { background: #b9a7d9; }
.btn--ghost { background: var(--button-bg); border-color: var(--button-border); color: var(--button-text); }
.btn--ghost:hover { background: var(--button-hover); color: var(--button-text); }
.btn:focus-visible, .theme-toggle:focus-visible, .tag-chip:focus-visible, .page-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─────────────────────────────────────────────────────────────
   Sections & page headers
   ───────────────────────────────────────────────────────────── */
/* Page title sticks to the top of the viewport while scrolling, alongside
   the (already sticky) right-hand navigation. */
.page-head {
  --page-title-size: clamp(1.87rem, 4.4vw, 2.42rem);
  position: sticky;
  top: 0;
  z-index: 20;
  padding: 1.25rem 0 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.page-head h1 { font-size: var(--page-title-size); margin: 0 0 0.35rem; }
.page-head__sub { color: var(--text-muted); margin: 0; font-size: 1.045rem; }
/* Reserve 1.3 title blocks: heading line, padding, bottom margin, and border. */
.page-head--spacer {
  position: static;
  visibility: hidden;
  height: calc((var(--page-title-size) * 1.25 + 2.6rem + 1px) * 1.3);
}

.section { padding: 1.35rem 0; }
.cv-section { padding: 1.25rem 0; }
.hero { border-top: 0; }
.section__title { font-size: 1.54rem; margin: 0 0 0.75rem; display: inline-block; }
.section__title--sub { font-size: 1.21rem; }
.pub > .section__title--sub { margin-bottom: 0; }

/* About */
.about { display: grid; grid-template-columns: 1.5fr 1fr; gap: 2.5rem; }
.about__bio p { margin: 0 0 1rem; color: var(--text-muted); }
.about__bio p:first-child { color: var(--text); }
.skill-group { margin-bottom: 1.25rem; }
.skill-group__title {
  font-size: 0.858rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 0.55rem;
}
@media (max-width: 620px) { .about { grid-template-columns: 1fr; gap: 1.5rem; } }

/* Tags */
.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0; margin: 0; }
.tag {
  font-size: 0.935rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.tag--sm { font-size: 0.836rem; padding: 0.18rem 0.55rem; }
a.tag {
  font-weight: 700;
  background: var(--button-bg);
  border-color: var(--button-border);
  color: var(--button-text);
  transition: background 0.15s ease;
}
a.tag:hover { background: var(--button-hover); color: var(--button-text); }
a.tag:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─────────────────────────────────────────────────────────────
   Project / card grid (used on Research)
   ───────────────────────────────────────────────────────────── */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}
.card__title { font-size: 1.232rem; margin: 0; }
.card__desc { margin: 0; color: var(--text-muted); font-size: 1.034rem; flex-grow: 1; }
.card__links { display: flex; gap: 1.1rem; font-weight: 600; font-size: 0.99rem; margin-top: 0.2rem; }

/* ─────────────────────────────────────────────────────────────
   CV / Research / Teaching entries
   ───────────────────────────────────────────────────────────── */
.entry { padding: 0.8rem 0; }
.entry__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}
.entry__title { font-weight: 700; }
.entry__date { color: var(--text-muted); font-size: 0.968rem; white-space: nowrap; }
.entry__org { color: var(--accent); margin: 0.1rem 0 0.4rem; font-size: 1.045rem; }
.entry__desc { margin: 0; color: var(--text-muted); font-size: 1.045rem; }

.pub-list { padding-left: 1.2rem; margin: 0; display: flex; flex-direction: column; gap: 0.875rem; }
.pub { line-height: 1.5; }
.pub__title { font-weight: 600; display: block; }
.pub__year { font-weight: 400; }
.pub__meta { white-space: nowrap; }
.pub__title-link { display: inline-block; margin-left: 0.25rem; }
.pub__authors { color: var(--text-muted); font-size: 1.012rem; }
.pub__venue { font-style: italic; color: var(--text-muted); font-size: 1.012rem; }
.pub__separator { font-style: normal; }
.pub__links { font-size: 0.968rem; }
.pub__awards {
  list-style-type: "\2192\00a0";
  margin: 0.5rem 0 0;
  padding-left: 1.4rem;
  color: var(--text-muted);
  font-size: 1.012rem;
}

/* Collapsible per-paper synopsis / abstract.
   The two buttons live in .pub__toggles; their panels are siblings *after*
   that row, so an expanding panel is structurally incapable of moving either
   button. Panels carry `hidden`; main.js flips it, one panel per paper. */
.pub__toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.45rem; }
.synopsis__btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.902rem;
  font-weight: 700;
  color: var(--button-text);
  background: var(--button-bg);
  border: 1px solid var(--button-border);
  border-radius: 999px;
  padding: 0.1rem 0.65rem;
  transition: background 0.15s ease;
}
.synopsis__btn::before { content: "\25B8"; font-size: 0.75em; }
.synopsis__btn[aria-expanded="true"]::before { content: "\25BE"; }
.synopsis__btn:hover, .synopsis__btn[aria-expanded="true"] { background: var(--button-hover); }
.synopsis__btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.synopsis__text {
  text-align: justify;
  margin: 0.5rem 0 0;
  max-width: 90%;
  color: var(--text-muted);
  font-size: 1.012rem;
  line-height: 1.5;
}

/* CV page helpers */
.cv-subhead { font-size: 1.1rem; margin: 1.5rem 0 0.4rem; }
.cv-subhead:first-child { margin-top: 0; }
.cv-subhead__org { font-weight: 400; color: var(--text-muted); }
.course-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.3rem 0;
}
.course-row__term { color: var(--text-muted); font-size: 0.968rem; white-space: nowrap; }
.cv-list { list-style: none; padding: 0; margin: 0; }
.cv-list > li { padding: 0.3rem 0; }
.cv-bullets { margin: 0.5rem 0 0; padding-left: 1.2rem; color: var(--text-muted); font-size: 1.045rem; }
.cv-bullets li { margin-bottom: 0.35rem; }
.cv-inline { margin: 0; color: var(--text-muted); }

/* ─────────────────────────────────────────────────────────────
   Posts: search, tag filter, list
   ───────────────────────────────────────────────────────────── */
.posts-controls { margin: 0.75rem 0 1rem; }
.posts-search {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.posts-search__icon { flex: 0 0 20px; }
.posts-search:focus-within { outline: 2px solid var(--accent); outline-offset: 4px; }
.search-input {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 1rem;
  padding: 0.5rem 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { outline: none; }

.posts-topics { margin-top: 1rem; }
.posts-topics__label { color: var(--text-muted); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; margin: 0 0 0.35rem; }
.tag-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 0.65rem; }
.tag-chip {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 400;
  padding: 0.4rem 0.4rem;
  min-height: 2.25rem;
  border-radius: 0;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.tag-chip:hover { color: var(--accent); }
.tag-chip.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

.post-list { list-style: none; padding: 0; margin: 0; }
.post-item { margin: 0; }
.post-item[hidden] { display: none; }
.post-entry { padding: 1.375rem 0; border-bottom: 1px solid var(--border); }
.post-entry__summary {
  position: relative;
  display: block;
  list-style: none;
  padding-right: 2.5rem;
  cursor: pointer;
}
.post-entry__summary::-webkit-details-marker { display: none; }
.post-entry__summary:focus-visible, .post-entry__read:focus-visible { outline: 2px solid var(--accent); outline-offset: 5px; }
.post-entry__title { font-size: 1.125rem; font-weight: 500; line-height: 1.35; letter-spacing: 0; margin: 0; }
.post-entry__summary:hover .post-entry__title { color: var(--accent); }
.post-entry__meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.5rem; color: var(--text-muted); font-size: 0.8125rem; margin-top: 0.45rem; }
.post-entry__meta time { white-space: nowrap; }
.post-entry__indicator { position: absolute; top: 0.1rem; right: 0; width: 1.375rem; height: 1.375rem; color: var(--text-muted); }
.post-entry__indicator::before, .post-entry__indicator::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.75rem;
  height: 1.5px;
  background: currentColor;
  transform: translate(-50%, -50%);
}
.post-entry__indicator::after { transform: translate(-50%, -50%) rotate(90deg); }
.post-entry[open] .post-entry__indicator::after { display: none; }
.post-entry__excerpt {
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.55;
  max-width: 66ch;
  margin: 0.875rem 0 0;
}
.post-entry__read { display: inline-block; font-size: 0.875rem; margin-top: 0.65rem; }
.post-entry__read:hover { text-decoration: underline; text-underline-offset: 3px; }
.post-empty { color: var(--text-muted); text-align: center; padding: 2rem 0; }
.post-empty[hidden] { display: none; }
.tag-chip[hidden], .posts-pagination[hidden] { display: none; }
.post-results { color: var(--text-muted); font-size: 0.8125rem; margin: 1.25rem 0 0; padding: 0 0 0.85rem; border-bottom: 1px solid var(--border); scroll-margin-top: 6.5rem; }
.posts-pagination { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.4rem; margin: 1.5rem 0; }
.page-button { font: inherit; font-size: 0.875rem; font-weight: 400; color: var(--text-muted); background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; min-width: 2.5rem; padding: 0.5rem 0.8rem; cursor: pointer; transition: color 0.15s ease; }
.page-button:hover:not(:disabled):not([aria-current="page"]) { color: var(--accent); }
.page-button[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.page-button:disabled { opacity: 0.45; cursor: default; }
.page-gap { padding: 0 0.25rem; }

/* ─────────────────────────────────────────────────────────────
   Single post typography
   ───────────────────────────────────────────────────────────── */
.post-head { padding: 1.5rem 0 1rem; border-bottom: 1px solid var(--border); margin-bottom: 2rem; }
.post-head__title { font-size: clamp(2.09rem, 5.5vw, 2.86rem); margin: 0 0 0.6rem; }
.post-head__meta { color: var(--text-muted); font-size: 0.99rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.post-body { font-size: 1.155rem; text-align: justify; }
.post-body h2 { font-size: 1.65rem; margin: 2rem 0 0.75rem; }
.post-body h3 { font-size: 1.32rem; margin: 1.5rem 0 0.6rem; }
.post-body p { margin: 0 0 0.99rem; }
.post-body a { text-decoration: underline; text-underline-offset: 2px; }
.post-body ul, .post-body ol { margin: 0 0 1.1rem; padding-left: 1.4rem; }
.post-body li { margin-bottom: 0.4rem; }
.post-body img { max-width: 100%; height: auto; border-radius: 10px; }
.post-body .note-diagram { margin: 1.5rem 0; text-align: center; }
.post-body .note-diagram__canvas { max-width: 100%; overflow-x: auto; padding: 0.4rem 0; }
.post-body .note-diagram__canvas a { display: block; width: fit-content; max-width: 100%; margin: 0 auto; }
.post-body .note-diagram img {
  display: block;
  width: var(--diagram-width);
  min-width: var(--diagram-min-width);
  max-width: 100%;
  background: #fff;
  border-radius: 4px;
}
.post-body .note-diagram figcaption {
  max-width: 48rem;
  margin: 0.6rem auto 0;
  font-size: 0.9em;
  line-height: 1.5;
  text-align: left;
  color: var(--text-muted);
}
.post-body blockquote {
  margin: 1.5rem 0;
  padding: 0.5rem 1.2rem;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
  font-style: italic;
}
.post-body pre {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: 0.99rem;
}
.post-body pre code { background: none; border: 0; padding: 0; }
.post-body hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
.post-back { margin-top: 2.5rem; font-weight: 600; }

/* ─────────────────────────────────────────────────────────────
   Footer
   ───────────────────────────────────────────────────────────── */
.footer { border-top: 1px solid var(--border); margin-top: 3rem; padding: 2rem 0; flex-shrink: 0; }
.footer__inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}
.footer__copy { margin: 0; color: var(--text-muted); font-size: 0.99rem; }

/* Display equations are independent blocks, so justification only stretches
   ordinary prose lines. Wide equations scroll within the article on phones. */
.post-body { text-align-last: auto; overflow-wrap: break-word; }
.post-body .math.display { display: block; margin: 0.99rem 0; overflow-x: auto; overflow-y: hidden; text-align: center; padding: 0.2rem 0; }
.post-body mjx-container[display="true"] { margin: 0.6em 0; }
.post-body .math.inline { display: inline; overflow-wrap: normal; }
.post-body .note-series, .post-body .note-related { text-align: left; font-size: 0.92em; margin-top: 1.5rem; }
.post-body .csl-entry { text-align: left; margin-bottom: 0.65rem; }
.post-body .note-reading { text-align: left; font-size: 0.92em; }
/* Keep MathJax's own baseline and glyph metrics. Padding and middle-aligned
   wrappers inflate every line containing a fraction or stacked relation. */
.post-body mjx-container:not([display="true"]) { padding: 0; }
.post-body .math.inline.math-inline-scroll { display: block; max-width: 100%; margin: 0.65rem 0; overflow-x: auto; overflow-y: hidden; text-align: left; }
.post-body table { display: block; max-width: 100%; overflow-x: auto; text-align: left; }
.post-body th, .post-body td { padding: 0.25rem 0.9rem; vertical-align: top; }
.post-body th:first-child, .post-body td:first-child { padding-left: 0; }
@media (max-width: 640px) {
  .post-body { text-align: left; }
  .course-row { flex-direction: column; align-items: flex-start; gap: 0.2rem; }
  .course-row__term { white-space: normal; }
}

/* Compact phone layout; also cover touch devices in landscape while the
   sidebar is above the content. Widths use CSS pixels, independent of density. */
@media (max-width: 640px), (max-width: 946px) and (hover: none) and (pointer: coarse) {
  .layout {
    align-content: start;
    padding: 1rem clamp(1rem, 4.5vw, 1.5rem) 0;
  }
  .footer__inner { padding-inline: clamp(1rem, 4.5vw, 1.5rem); }

  .sidebar {
    display: grid;
    grid-template-columns: var(--portrait-phone-size) minmax(0, 1fr) 2.75rem;
    grid-template-areas:
      "portrait name name"
      "portrait role role"
      "nav nav toggle";
    align-items: start;
    gap: 0.25rem 0.75rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    text-align: left;
  }
  .sidebar__portrait {
    grid-area: portrait;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
  }
  .sidebar__name { grid-area: name; margin: 0; overflow-wrap: anywhere; }
  .sidebar__role {
    grid-area: role;
    min-width: 0;
    margin: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .sidebar__nav {
    grid-area: nav;
    min-width: 0;
    justify-content: flex-start;
    gap: 0.25rem;
    margin-top: 0.5rem;
  }
  .sidebar__nav a { font-size: 1rem; padding: 0.5rem 0.375rem; }
  .sidebar__toggle { grid-area: toggle; margin: 0.5rem 0 0; }
  .theme-toggle { width: 2.75rem; height: 2.75rem; min-width: 44px; min-height: 44px; }

  .page-head--spacer { display: none; }
  .hero__actions--home { padding-bottom: 1.25rem; }
  .synopsis__text { max-width: 100%; text-align: left; }

  .sidebar__nav a, .synopsis__btn, .pub__toggles a, .pub__title-link, .tag-chip, .page-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
  }
  .pub__toggles { gap: 0.5rem; }
}
