/* ---------------------------------------------------------------------------
   Matthew Willetts — personal site
   Serif prose (Newsreader) on warm paper, Inter for interface text,
   deep teal accent. Generous whitespace, no clutter.
--------------------------------------------------------------------------- */

:root {
  --paper:       #fcfbf8;
  --ink:         #1f2328;
  --ink-soft:    #4b5158;
  --muted:       #767d86;
  --accent:      #0e6a5d;
  --accent-dark: #0a4f46;
  --accent-tint: #eaf3f1;
  --rule:        #e7e4dd;
  --card:        #ffffff;
  --header-bg:   color-mix(in srgb, var(--paper) 92%, white);
  --code-bg:     #f4f2ec;
  --inline-code: rgba(0,0,0,.05);
  --row-stripe:  rgba(0,0,0,.025);
  --shadow-1:    rgba(0,0,0,.08);
  --shadow-2:    rgba(0,0,0,.25);
  --anchor-offset: 3.6rem;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
}

html[data-theme="dark"] {
  --paper:       #121416;
  --ink:         #e8e3da;
  --ink-soft:    #c2bab0;
  --muted:       #8f989f;
  --accent:      #75cdbf;
  --accent-dark: #a1e4d9;
  --accent-tint: rgba(117, 205, 191, .14);
  --rule:        #30363c;
  --card:        #181b1f;
  --header-bg:   rgba(18, 20, 22, .88);
  --code-bg:     #191d21;
  --inline-code: rgba(255,255,255,.07);
  --row-stripe:  rgba(255,255,255,.035);
  --shadow-1:    rgba(0,0,0,.20);
  --shadow-2:    rgba(0,0,0,.55);
  color-scheme: dark;
}

html.theme-transition,
html.theme-transition * {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  scroll-padding-top: var(--anchor-offset);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  max-width: 50rem;
  margin: 0 auto;
  padding: 0 1.25rem;
}
.container.narrow { max-width: 44rem; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color .12s ease;
}
a:hover { color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; }

::selection { background: var(--accent-tint); }

/* ----- header ------------------------------------------------------------ */

.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--header-bg);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(6px);
}
.site-header nav {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-top: .9rem;
  padding-bottom: .9rem;
}
.site-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: .01em;
  color: var(--ink);
}
.site-name:hover { color: var(--accent); text-decoration: none; }
.site-nav {
  font-family: var(--sans);
  font-size: .85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 1.4rem;
  white-space: nowrap;
}
.site-nav a {
  color: var(--ink-soft);
}
.site-nav a:hover { color: var(--accent); text-decoration: none; }

.theme-toggle {
  --toggle-size: 1.45rem;
  appearance: none;
  width: var(--toggle-size);
  height: var(--toggle-size);
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--card);
  color: var(--ink-soft);
  display: inline-grid;
  place-items: center;
  padding: 0;
  margin: 0 0 0 -.25rem;
  cursor: pointer;
  flex: 0 0 auto;
}
.theme-toggle:hover {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--rule));
  background: var(--accent-tint);
}
.theme-toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 3px;
}
.theme-icon {
  display: none;
  width: .78rem;
  height: .78rem;
  position: relative;
}
html[data-theme-setting="system"] .theme-icon-system,
html[data-theme-setting="light"] .theme-icon-light,
html[data-theme-setting="dark"] .theme-icon-dark {
  display: block;
}
.theme-icon-system {
  border: 1.6px solid currentColor;
  border-radius: 50%;
}
.theme-icon-system::after {
  content: "";
  position: absolute;
  inset: 2px 0 2px 50%;
  border-left: 1.6px solid currentColor;
}
.theme-icon-light {
  border: 1.6px solid currentColor;
  border-radius: 50%;
  box-shadow:
    0 -.31rem 0 -.04rem currentColor,
    0 .31rem 0 -.04rem currentColor,
    .31rem 0 0 -.04rem currentColor,
    -.31rem 0 0 -.04rem currentColor;
}
.theme-icon-dark {
  border-radius: 50%;
  box-shadow: inset -.26rem -.05rem 0 0 currentColor;
}

/* ----- footer ------------------------------------------------------------ */

.site-footer {
  margin-top: 5rem;
  border-top: 1px solid var(--rule);
  padding: 2rem 0 2.5rem;
  font-family: var(--sans);
  font-size: .85rem;
  color: var(--muted);
  text-align: center;
}
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--accent); }
.site-footer .sep { margin: 0 .6rem; color: var(--rule); }
.site-footer .colophon { margin-top: .4rem; font-size: .78rem; }

/* ----- home: hero --------------------------------------------------------- */

.hero {
  display: flex;
  gap: 2.5rem;
  align-items: flex-start;
  margin: 3.5rem 0 1rem;
}
.hero-text { flex: 1; }
.hero h1 {
  font-size: 2.6rem;
  font-weight: 500;
  letter-spacing: -.015em;
  margin: 0 0 .3rem;
  line-height: 1.1;
}
.hero .role {
  font-family: var(--sans);
  font-size: .95rem;
  color: var(--muted);
  margin: 0 0 1.4rem;
}
.hero-photo img {
  width: 150px;
  height: 180px;
  object-fit: cover;
  border-radius: 10px;
  box-shadow: 0 1px 2px var(--shadow-1), 0 8px 24px -12px var(--shadow-2);
}

/* ----- sections ----------------------------------------------------------- */

section { margin: 3.2rem 0; }
section[id],
.hero[id] {
  scroll-margin-top: var(--anchor-offset);
}

h2.section-title {
  font-family: var(--sans);
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 1.4rem;
  display: flex;
  align-items: center;
  gap: .9rem;
}
h2.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* ----- news --------------------------------------------------------------- */

.news { list-style: none; margin: 0; padding: 0; }
.news li {
  display: grid;
  grid-template-columns: 6.2rem 1fr;
  gap: 1rem;
  padding: .45rem 0;
  font-size: .95rem;
}
.news .date {
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 500;
  color: var(--muted);
  padding-top: .25rem;
  white-space: nowrap;
}

/* ----- publications -------------------------------------------------------- */

.pub {
  display: grid;
  grid-template-columns: 168px 1fr;
  gap: 1.4rem;
  align-items: center;
  padding: 1.05rem 0;
}
.pub + .pub { border-top: 1px solid var(--rule); }

.pub-thumb {
  display: block;
  width: 168px;
  height: 118px;
  object-fit: contain;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 6px;
  margin: 0;
  transition: transform .15s ease, box-shadow .15s ease;
}
a:hover > .pub-thumb {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px -14px rgba(0,0,0,.3);
}

.pub.no-thumb { grid-template-columns: 1fr; }

.pub-title {
  font-size: 1.04rem;
  font-weight: 500;
  line-height: 1.35;
  margin: 0 0 .15rem;
}
.pub-authors {
  font-size: .88rem;
  color: var(--ink-soft);
  margin: 0 0 .35rem;
  line-height: 1.45;
}
.pub-authors b { font-weight: 600; color: var(--ink); }
.pub-meta {
  font-family: var(--sans);
  font-size: .76rem;
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
}
.chip {
  display: inline-block;
  padding: .14rem .55rem;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--accent-dark);
  font-weight: 500;
  letter-spacing: .02em;
}
.chip.hot { background: var(--accent); color: #fff; }
.pub-meta a {
  color: var(--muted);
  font-weight: 500;
}
.pub-meta a:hover { color: var(--accent); }
/* venue chips that link to the official proceedings page */
a.chip { color: var(--accent-dark); }
a.chip:hover {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}
a.chip.hot { color: #fff; }
a.chip.hot:hover { background: var(--accent-dark); }

.equal-note {
  font-family: var(--sans);
  font-size: .76rem;
  color: var(--muted);
  margin-top: .8rem;
}

/* ----- notes --------------------------------------------------------------- */

.notes-intro {
  margin: 3.2rem 0 2.2rem;
}
.notes-intro h1 {
  font-size: 2.35rem;
  font-weight: 500;
  line-height: 1.12;
  letter-spacing: -.01em;
  margin: 0 0 .65rem;
}
.notes-intro p {
  color: var(--ink-soft);
  max-width: 42rem;
}
.note-list {
  display: grid;
  gap: .95rem;
}
.note-card {
  border-top: 1px solid var(--rule);
  padding: 1rem 0 1.05rem;
}
.note-card h3 {
  font-size: 1.14rem;
  font-weight: 500;
  line-height: 1.3;
  margin: 0 0 .25rem;
}
.note-card p {
  margin: .2rem 0 0;
  font-size: .95rem;
  color: var(--ink-soft);
}
.note-card .note-card-meta,
.note-meta,
.note-links,
.note-kicker {
  font-family: var(--sans);
  font-size: .78rem;
  color: var(--muted);
}
.note-card .note-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  align-items: center;
  margin-top: .45rem;
}
.note-card .note-card-meta a,
.note-links a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.55rem;
  padding: .13rem .55rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--card);
  font-weight: 500;
  color: var(--ink-soft);
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
  transition: color .12s ease, border-color .12s ease, background .12s ease, box-shadow .12s ease;
}
.note-card .note-card-meta a:hover,
.note-links a:hover {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--rule));
  background: var(--accent-tint);
  text-decoration: none;
  box-shadow: 0 2px 8px -6px rgba(0,0,0,.35);
}
.note-kicker {
  margin: 0 0 .55rem;
  font-weight: 500;
}
.note-meta {
  margin: -.1rem 0 1rem;
}
.note-meta .sep {
  color: var(--rule);
  margin: 0 .45rem;
}
.note-links {
  display: flex;
  gap: .75rem;
  margin: -0.35rem 0 2.1rem;
}

/* ----- software ------------------------------------------------------------ */

.software p { margin: .2rem 0 0; font-size: .98rem; }

/* ----- blog list ------------------------------------------------------------ */

.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li { padding: 1.1rem 0; }
.post-list li + li { border-top: 1px solid var(--rule); }
.post-list .date {
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 500;
  color: var(--muted);
  display: block;
  margin-bottom: .15rem;
}
.post-list .title {
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.3;
}
.post-list .excerpt {
  margin: .3rem 0 0;
  font-size: .95rem;
  color: var(--ink-soft);
}

/* ----- posts ----------------------------------------------------------------- */

article.post { margin-top: 3rem; }

article.post h1 {
  font-size: 2.1rem;
  font-weight: 500;
  letter-spacing: -.01em;
  line-height: 1.18;
  margin: 0 0 .4rem;
}
.post-date {
  font-family: var(--sans);
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: 2.2rem;
}

article.post h1, article.post h2, article.post h3 {
  font-family: var(--serif);
}
article.post h2 {
  font-size: 1.45rem;
  font-weight: 600;
  margin: 2.6rem 0 .8rem;
}
article.post h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 2rem 0 .6rem;
}

article.post blockquote {
  margin: 1.8rem 0;
  padding: 1rem 1.4rem;
  background: var(--accent-tint);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  font-size: 1.02rem;
}
article.post blockquote p { margin: 0; }

article.post img {
  max-width: 100%;
  /* never distort: if the box is clamped while a height attribute holds it
     open, scale uniformly within the box instead of stretching */
  object-fit: contain;
  display: block;
  margin: 1.6rem auto;
  border-radius: 6px;
}
/* dark mode: white-background figures sit on a card plate, glare dialled down */
html[data-theme="dark"] article.post img {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 14px;
  filter: brightness(.9);
}
img[src*='#left']   { float: left; margin-right: 1rem; }
img[src*='#right']  { float: right; margin-left: 1rem; }
img[src*='#center'] { display: block; margin-left: auto; margin-right: auto; }

article.post table {
  margin: 1.6rem auto;
  border-collapse: collapse;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  /* wide tables scroll within themselves rather than the page */
  display: block;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}
/* image-grid tables (old posts): shrink images into equal columns instead */
article.post table:has(img) {
  display: table;
  width: 100%;
  table-layout: fixed;
}
article.post table:has(img) img {
  height: auto;
  width: auto;
  max-width: 100%;
}
article.post th {
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  padding: .35rem .8rem;
}
article.post td { padding: .3rem .8rem; }
article.post tr:nth-child(even) td { background: var(--row-stripe); }
article.post table img { margin: .3rem auto; }
article.post tr:nth-child(even) td:has(img) { background: transparent; }

article.post code {
  font-size: .85em;
  background: var(--inline-code);
  padding: .1em .35em;
  border-radius: 4px;
}
article.post pre {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  overflow-x: auto;
  font-size: .82rem;
  line-height: 1.5;
}
article.post pre code { background: none; padding: 0; }

article.post hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2.5rem 0;
}

/* long display equations scroll rather than overflow */
mjx-container[display="true"] {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 2px 0;
}
/* long inline equations scroll rather than pushing the page wide */
mjx-container:not([display="true"]) {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: middle;
}

.footnotes {
  margin-top: 3rem;
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
  font-size: .88rem;
  color: var(--ink-soft);
}

.back-link {
  font-family: var(--sans);
  font-size: .85rem;
  font-weight: 500;
  display: inline-block;
  margin-top: 2.5rem;
}

/* ----- responsive ------------------------------------------------------------- */

@media (max-width: 640px) {
  body { font-size: 17.5px; }
  .container { padding-left: 1rem; padding-right: 1rem; }
  .site-header nav {
    align-items: center;
    gap: .75rem;
  }
  .site-name {
    flex: 0 0 auto;
    font-size: .95rem;
  }
  .site-nav {
    flex: 0 1 auto;
    gap: .66rem;
    font-size: .74rem;
  }
  .theme-toggle { --toggle-size: 1.28rem; margin-left: -.18rem; }
  .hero {
    flex-direction: column-reverse;
    gap: 1.4rem;
    margin-top: 2.2rem;
  }
  .hero-photo img { width: 110px; height: 132px; }
  .hero h1 { font-size: 2.1rem; }
  .pub {
    grid-template-columns: 1fr;
    gap: .7rem;
  }
  .pub-thumb { width: 100%; max-width: 280px; height: auto; aspect-ratio: 3 / 2; }
  .news li { grid-template-columns: 4.6rem 1fr; gap: .7rem; }
}

@media (max-width: 380px) {
  .container { padding-left: .85rem; padding-right: .85rem; }
  .site-name { font-size: .88rem; }
  .site-nav {
    gap: .48rem;
    font-size: .68rem;
  }
  .theme-toggle { --toggle-size: 1.18rem; }
}

/* ----- table of contents (posts & notes), al-folio style ------------------- */

.toc {
  position: fixed;
  top: 6.5rem;
  left: calc(50% - 22rem - 17.5rem);
  width: 14rem;
  max-height: calc(100vh - 9rem);
  overflow-y: auto;
  font-family: var(--sans);
  font-size: .78rem;
  line-height: 1.45;
}
.toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 1px solid var(--rule);
}
.toc li { margin: 0; }
.toc a {
  display: block;
  padding: .22rem 0 .22rem .95rem;
  color: var(--muted);
  border-left: 2px solid transparent;
  margin-left: -1.5px;
}
.toc a:hover { color: var(--accent); text-decoration: none; }
.toc a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 500;
}
.toc .toc-l1 a { padding-left: 1.8rem; }
.toc .toc-l2 a { padding-left: 2.6rem; }

@media (max-width: 1280px) {
  .toc { display: none; }
}
