:root {
  --bg: #fbfaf6;
  --fg: #1c1c1c;
  --muted: #6a6a6a;
  --rule: #e2dfd4;
  --accent: #7a1f1f;
  --accent-hover: #a02828;
  --code-bg: #f1ede0;
  --serif: "Iowan Old Style", "Charter", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --measure: 38rem;
}

* { box-sizing: border-box; }

html { font-size: 17px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-feature-settings: "kern", "liga", "onum";
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main, header, footer {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.5rem;
}

header {
  padding-top: 4.5rem;
  padding-bottom: 2.5rem;
}

header h1 {
  font-family: var(--sans);
  font-size: 2.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
}

header .tagline {
  color: var(--muted);
  font-style: italic;
  margin: 0;
  font-size: 1.05rem;
}

main { padding-bottom: 4rem; }

section { margin: 3rem 0; }
section + section { border-top: 1px solid var(--rule); padding-top: 2.75rem; }

h2 {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 0 1.5rem;
}

h3 {
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  letter-spacing: -0.005em;
}

p { margin: 0 0 1.05rem; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(122, 31, 31, 0.25);
  transition: color 120ms ease, border-color 120ms ease;
}
a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

ul { padding-left: 1.2rem; margin: 0 0 1rem; }
li { margin-bottom: 0.4rem; }

code, kbd {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.05em 0.35em;
  border-radius: 3px;
}

/* --- Publications --- */
.papers {
  list-style: none;
  padding: 0;
  margin: 0;
}
.papers > li {
  display: grid;
  grid-template-columns: 3.2rem 1fr;
  gap: 1.25rem;
  padding: 1.1rem 0;
  border-top: 1px dotted var(--rule);
}
.papers > li:first-child { border-top: none; padding-top: 0; }
.paper-year {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  padding-top: 0.15rem;
}
.paper-title { font-weight: 600; }
.paper-authors { color: var(--muted); font-size: 0.95rem; font-style: italic; }
.paper-venue { color: var(--muted); font-size: 0.9rem; }
.paper-venue em { font-style: italic; }
.paper-links {
  font-family: var(--sans);
  font-size: 0.82rem;
  margin-top: 0.4rem;
}
.paper-links a {
  margin-right: 0.85rem;
  border-bottom: none;
  color: var(--accent);
}
.paper-links a:hover { text-decoration: underline; }

/* --- Software grid --- */
.repos {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem 2rem;
}
.repos li { margin: 0; }
.repos h3 { margin-bottom: 0.15rem; }
.repos h3 a { border-bottom: none; }
.repos h3 a:hover { border-bottom: 1px solid var(--accent-hover); }
.repos .meta {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.repos p {
  font-size: 0.95rem;
  margin: 0.3rem 0 0;
  color: #303030;
}

@media (max-width: 540px) {
  html { font-size: 16px; }
  header { padding-top: 3rem; }
  header h1 { font-size: 1.8rem; }
  .papers > li { grid-template-columns: 1fr; gap: 0.25rem; }
  .paper-year { padding-top: 0; }
  .repos { grid-template-columns: 1fr; }
}

/* --- Contact / footer --- */
.contact-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.4rem 1rem;
  font-family: var(--sans);
  font-size: 0.95rem;
}
.contact-list dt {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  padding-top: 0.15rem;
}
.contact-list dd { margin: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

footer {
  padding-top: 2.5rem;
  padding-bottom: 3rem;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.8rem;
  text-align: center;
  border-top: 1px solid var(--rule);
  margin-top: 3rem;
}

/* --- Easter egg: Dwight (full-page takeover) --- */
#dwight {
  display: none;
  margin: 0;
}
#dwight.show {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  align-items: center;
  justify-content: center;
  overflow: hidden;
  animation: dwight-bg 500ms ease both;
}
.dwight-stage {
  position: relative;
  display: inline-block;
}
#dwight pre {
  font-family: var(--mono);
  font-size: clamp(5px, min(1.45vh, 1.4vw), 18px);
  line-height: 1;
  color: #4a4a4a;
  background: transparent;
  margin: 0;
  padding: 0;
  white-space: pre;
}
#dwight.show pre {
  animation: dwight-reveal 4.5s cubic-bezier(.45,.05,.55,.95) 1s both;
  will-change: clip-path;
}
#dwight.show .dwight-stage::after {
  content: "";
  position: absolute;
  left: -50vw;
  right: -50vw;
  height: 2.4em;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(122, 31, 31, 0.0) 18%,
    rgba(122, 31, 31, 0.95) 50%,
    rgba(122, 31, 31, 0.0) 82%,
    transparent 100%
  );
  box-shadow: 0 0 60px rgba(122, 31, 31, 0.55);
  animation: dwight-line 4.5s cubic-bezier(.45,.05,.55,.95) 1s both;
  mix-blend-mode: multiply;
}
@keyframes dwight-bg {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes dwight-reveal {
  0%   { clip-path: inset(0 0 100% 0); }
  100% { clip-path: inset(0 0 0 0); }
}
@keyframes dwight-line {
  0%   { top: -2.4em; opacity: 0; }
  4%   { opacity: 1; }
  96%  { opacity: 1; }
  100% { top: calc(100% + 2.4em); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #dwight.show pre,
  #dwight.show .dwight-stage::after { animation: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161512;
    --fg: #e8e6df;
    --muted: #9c9890;
    --rule: #2e2c27;
    --accent: #d99a9a;
    --accent-hover: #ecb1b1;
    --code-bg: #25231e;
  }
  .repos p { color: #c2c0b8; }
  a { border-bottom-color: rgba(217, 154, 154, 0.3); }
  #dwight pre { color: #c0bdb4; }
  #dwight.show .dwight-stage::after {
    background: linear-gradient(to bottom,
      transparent 0%,
      rgba(217, 154, 154, 0.0) 20%,
      rgba(217, 154, 154, 0.85) 50%,
      rgba(217, 154, 154, 0.0) 80%,
      transparent 100%);
    box-shadow: 0 0 32px rgba(217, 154, 154, 0.55);
    mix-blend-mode: screen;
  }
}
