/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f2f4f6;
  --bg-hover: #e7ebef;
  --bg-card: #fbfcfd;
  --text: #141a24;
  --text-light: #5c6677;
  --accent: #1d4f91;
  --border: #d0d7e0;
  --border-strong: #a7b3c3;
  --code-bg: #e9edf2;
  --max-w: 54rem;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0f141b;
  --bg-hover: #161d27;
  --bg-card: #141b24;
  --text: #e4e8ee;
  --text-light: #8d97a8;
  --accent: #8fb3ff;
  --border: #2a3442;
  --border-strong: #46546a;
  --code-bg: #1a222d;
  color-scheme: dark;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-color: var(--border-strong);
  transition: color 0.15s, text-decoration-color 0.15s;
}
a:hover { color: var(--accent); text-decoration-color: var(--accent); text-decoration-thickness: 2px; }

p { margin-bottom: 1rem; }
strong { font-weight: 600; }
.muted { color: var(--text-light); font-weight: 400; }

/* ===== Page layout ===== */
.page {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 1rem;
}
@media (min-width: 768px) { .page { max-width: calc(var(--max-w) + 6rem); padding: 3rem; } }

/* ===== Header ===== */
.site-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.site-name {
  font-family: var(--font-serif);
  font-size: 1.875rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--text);
  text-decoration: none;
}
a.site-name:hover { color: var(--text); text-decoration: none; }

.header-links { display: flex; align-items: center; gap: 1rem; }
.header-links a { text-underline-offset: 8px; color: var(--text-light); }
.header-links a:hover { color: var(--text); text-decoration-color: var(--text); }

.header-links .icon-link { display: inline-flex; align-items: center; text-decoration: none; }
.header-links .icon-link:hover { color: var(--accent); }

.theme-toggle {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
  padding: 0.25rem;
}
.theme-toggle:hover { color: var(--text); }

/* ===== Intro ===== */
.intro {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}
.headshot {
  width: 128px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.bio { flex: 1; }

@media (max-width: 560px) {
  .intro { flex-direction: column; }
  .headshot { width: 120px; }
}

.prose { margin-top: 0.5rem; }

/* ===== Sections ===== */
section + section { margin-top: 2rem; }

.section-label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 0.25rem;
}
.section-label .muted { text-transform: none; letter-spacing: 0; }

/* ===== Timeline ===== */
.timeline {
  list-style: none;
  position: relative;
  margin-left: 0.5rem;
  padding: 1rem 0;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.timeline.compact { gap: 0.25rem; }

.timeline li { position: relative; }
.timeline li::before {
  content: '';
  position: absolute;
  left: -4px;
  top: 0.85rem;
  width: 7px;
  height: 7px;
  border-radius: 1px;
  background: var(--text);
  outline: 2px solid var(--bg);
}
.timeline.compact li::before { top: 0.7rem; }

.entry {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-left: 1.25rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.entry:hover {
  color: var(--text);
  text-decoration: none;
  border-color: var(--border-strong);
  box-shadow: 3px 3px 0 var(--border-strong);
}
.entry.featured { border-color: var(--text); box-shadow: 3px 3px 0 var(--text); }
.entry.featured:hover { box-shadow: 5px 5px 0 var(--text); }

.entry-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.entry-title { font-size: 0.8rem; font-weight: 600; line-height: 1.5; }
.entry-date { font-size: 0.75rem; color: var(--text-light); flex-shrink: 0; }
.entry-meta, .entry-venue, .entry-desc { font-size: 0.75rem; color: var(--text-light); line-height: 1.5; }
.entry-meta strong { color: var(--text); }
.entry-venue { font-style: italic; }

.compact .entry { border-color: transparent; background: none; }
.compact .entry:hover { border-color: transparent; box-shadow: none; background: var(--bg-hover); }

/* ===== Footer ===== */
.site-footer {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-light);
}

/* ===== Project detail pages ===== */
.container {
  max-width: calc(var(--max-w) + 6rem);
  margin: 0 auto;
  padding: 0 1rem;
}
@media (min-width: 768px) { .container { padding: 0 3rem; } }

.project-header { padding-top: 1rem; padding-bottom: 1rem; margin-bottom: 1rem; }
@media (min-width: 768px) { .project-header { padding-top: 3rem; } }
.project-header .site-name { font-size: 1.5rem; }

main { padding-bottom: 2rem; }
footer:not(.site-footer) { font-size: 0.75rem; color: var(--text-light); padding: 1rem 0 3rem; }
footer:not(.site-footer) .container { border-top: 1px solid var(--border); padding-top: 1rem; }

.project-content { line-height: 1.75; }
.project-content h1, .project-content h2, .project-content h3, .project-content h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.3;
}
.project-content h1 { font-size: 1.75rem; font-weight: 400; margin-bottom: 1rem; }
.project-content h2 { font-size: 1.35rem; margin: 2rem 0 0.75rem; }
.project-content h3 { font-size: 1.15rem; margin: 1.5rem 0 0.5rem; }
.project-content h4 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.project-content ul, .project-content ol { margin: 0 0 1rem 1.5rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

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

.image-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.image-row img { flex: 1 1 0; min-width: 0; }
.image-row img:only-child { max-width: 60%; margin: 0 auto; flex: none; }
.image-row.small img { flex: 1 1 120px; }

.image-row.center { justify-content: center; }
.image-row.center img { flex: 0 1 auto; max-width: 60%; }

/* Inner div wrappers (project5/6 captioned images) */
.image-row > div { flex: 1 1 0; min-width: 0; }
.image-row > div img { width: 100%; }
.image-row.small > div { flex: 1 1 120px; }

.caption {
  font-size: 0.75rem;
  color: var(--text-light);
  text-align: center;
  margin: 0.25rem 0 1.5rem;
  font-style: italic;
}

/* Code blocks */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 1rem 0;
}

code { font-family: var(--font-mono); font-size: 0.95em; }

p code, li code {
  background: var(--code-bg);
  padding: 0.1em 0.3em;
}

/* ===== Utility ===== */
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }

/* ===== MathJax overrides ===== */
.MathJax { font-size: 1em !important; }
mjx-container[display="true"] { overflow-x: auto; overflow-y: hidden; }

/* ===== Responsive images in rows ===== */
@media (max-width: 600px) {
  .image-row { flex-direction: column; }
  .image-row img { flex: 1 1 100%; }
  .image-row img:only-child { max-width: 100%; }
  .image-row.center img { max-width: 100%; }
}
