/* =============================================================
   Academic personal site — "reading room" stylesheet
   Type: Spectral (serif, display) + Inter (sans, body/UI)
   Theme: cool paper + ink, with a full dark variant.
   ============================================================= */

/* ---- Design tokens -------------------------------------------------- */
:root {
  --paper:      #f5f5f3;
  --surface:    #ffffff;
  --ink:        #1c1e22;
  --muted:      #696c74;
  --faint:      #9a9da3;
  --line:       #e4e4df;
  --line-soft:  #eeeeea;
  --accent:     #2e4b8b;
  --accent-ink: #21386b;

  --rail:       72px;   /* width of the year margin */
  --measure:    68ch;   /* reading measure cap      */
  --gap:        2rem;

  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --step:  cubic-bezier(0.4, 0, 0.2, 1);
}

/* Follow the OS by default; only flip when no explicit choice is stored */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:     #17181b;
    --surface:   #1e2024;
    --ink:       #e7e7e3;
    --muted:     #a0a3ab;
    --faint:     #71747c;
    --line:      #2c2e34;
    --line-soft: #24262b;
    --accent:    #9db2e6;
    --accent-ink:#b7c6ee;
  }
}
/* Explicit user override */
:root[data-theme="dark"] {
  --paper:     #17181b;
  --surface:   #1e2024;
  --ink:       #e7e7e3;
  --muted:     #a0a3ab;
  --faint:     #71747c;
  --line:      #2c2e34;
  --line-soft: #24262b;
  --accent:    #9db2e6;
  --accent-ink:#b7c6ee;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 5.5rem;   /* clear the sticky nav on anchor jumps */
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }

sup { font-size: 0.7em; line-height: 0; }
b, strong { font-weight: 600; }

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

/* ---- Layout --------------------------------------------------------- */
.wrap {
  width: 100%;
  max-width: 860px;
  margin-inline: auto;
  padding-inline: 1.5rem;
}

.section { padding-block: 3.25rem; border-top: 1px solid var(--line-soft); }
.section:first-of-type { border-top: 0; }

.section__head {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.55rem;
  letter-spacing: -0.01em;
  margin: 0 0 1.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.prose { max-width: var(--measure); }
.prose p { margin: 0 0 1rem; }
.prose p:last-child { margin-bottom: 0; }

/* =====================================================================
   Top navigation
   ===================================================================== */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav__inner {
  max-width: 860px;
  margin-inline: auto;
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.nav__brand {
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 500;
  color: var(--ink);
  margin-right: auto;
  white-space: nowrap;
}
.nav__brand:hover { text-decoration: none; color: var(--ink); }
.nav__links {
  display: flex;
  gap: 1.15rem;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav__links a {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
  padding: 0.2rem 0;
  position: relative;
  transition: color 0.15s var(--step);
}
.nav__links a:hover { color: var(--ink); text-decoration: none; }
.nav__links a.is-active { color: var(--accent); }
.nav__links a.is-active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -0.65rem;
  height: 2px;
  background: var(--accent);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s var(--step), border-color 0.15s var(--step);
}
.theme-toggle:hover { color: var(--ink); border-color: var(--muted); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-sun  { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* =====================================================================
   Hero
   ===================================================================== */
.hero { padding-block: 3rem 3.25rem; }
.hero__inner {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}
.hero__photo {
  flex: 0 0 auto;
  width: 200px; height: 250px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.hero__name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.15rem, 1.4rem + 3vw, 3rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0.1rem 0 0.5rem;
}
.hero__title { margin: 0; color: var(--ink); }
.hero__affil { margin: 0.1rem 0 0; color: var(--muted); }
.hero__contact {
  margin: 0.85rem 0 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}
.hero__email { color: var(--muted); }
.hero__email:hover { color: var(--accent); }
.hero__social { display: inline-flex; gap: 0.35rem; }
.iconlink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  color: var(--muted);
  border-radius: 6px;
  transition: color 0.15s var(--step), background 0.15s var(--step);
}
.iconlink:hover { color: var(--accent); background: var(--line-soft); text-decoration: none; }
.iconlink svg { width: 18px; height: 18px; fill: currentColor; }

/* Optional recruiting callout (enable in HTML) */
.callout {
  margin-top: 2rem;
  padding: 1rem 1.25rem;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--surface);
  max-width: var(--measure);
}
.callout p { margin: 0 0 0.5rem; }
.callout p:last-child { margin-bottom: 0; }

/* =====================================================================
   Publications — the year-rail bibliography (signature element)
   ===================================================================== */
.pub-controls {
  display: inline-flex;
  margin-bottom: 2rem;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
  background: var(--surface);
  gap: 2px;
}
.pub-controls button {
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
  padding: 0.32rem 0.95rem;
  cursor: pointer;
  transition: color 0.15s var(--step), background 0.15s var(--step);
}
.pub-controls button:hover { color: var(--ink); }
.pub-controls button.is-active { color: var(--paper); background: var(--ink); }

.pub-note { color: var(--muted); font-size: 0.92rem; margin: -0.75rem 0 1.75rem; }

.pane { display: none; }
.pane.is-active { display: block; }

.pub-year {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  gap: var(--gap);
  padding-block: 1.6rem;
  border-top: 1px solid var(--line-soft);
}
.pub-year:first-child { border-top: 0; padding-top: 0.25rem; }
.pub-year__label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  padding-top: 0.2rem;
  position: sticky;
  top: 5rem;
  height: fit-content;
}
.pub-year__entries { display: flex; flex-direction: column; gap: 1.6rem; }

.entry__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.1rem;
  line-height: 1.32;
  margin: 0 0 0.3rem;
  color: var(--ink);
}
.entry__authors { margin: 0 0 0.15rem; font-size: 0.95rem; }
.entry__venue { margin: 0; font-size: 0.9rem; font-style: italic; color: var(--muted); }
.entry__links { margin: 0.6rem 0 0; display: flex; flex-wrap: wrap; gap: 0.4rem; }

.tag {
  font-size: 0.775rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.14rem 0.55rem;
  transition: color 0.15s var(--step), border-color 0.15s var(--step);
}
.tag:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }

/* =====================================================================
   Publication references — used to point from Talks (or elsewhere) back
   to a specific Publications entry: hover preview + click-to-jump.
   ===================================================================== */
.pub-ref {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted var(--muted);
  cursor: pointer;
  transition: color 0.15s var(--step), border-color 0.15s var(--step);
}
.pub-ref:hover,
.pub-ref:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
}

.pub-tooltip {
  position: fixed;
  z-index: 100;
  width: 320px;
  max-width: calc(100vw - 2rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.16);
  padding: 0.9rem 1rem;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.14s var(--step), transform 0.14s var(--step);
}
.pub-tooltip.is-visible { opacity: 1; transform: translateY(0); }
.pub-tooltip__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 0.98rem;
  line-height: 1.32;
  margin: 0 0 0.32rem;
  color: var(--ink);
}
.pub-tooltip__meta { margin: 0.1rem 0 0; font-size: 0.82rem; color: var(--muted); }
.pub-tooltip__meta em { font-style: italic; }
.pub-tooltip__link {
  display: inline-block;
  margin-top: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
}

/* Touch devices: no hover, so skip the preview card — tap just jumps */
@media (hover: none) {
  .pub-tooltip { display: none; }
}

/* Momentary highlight when a reference jumps you to a Publications entry */
.entry {
  scroll-margin-top: 5.5rem;
  border-radius: 6px;
}
.entry.is-highlighted { animation: pubFlash 1.8s var(--step); }
@keyframes pubFlash {
  0%   { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 20%, transparent); }
  100% { box-shadow: 0 0 0 6px transparent; }
}

/* =====================================================================
   Log lists — Teaching, Talks (short label rail)
   ===================================================================== */
.log { --rail: 118px; display: flex; flex-direction: column; }
.log-item {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  gap: var(--gap);
  padding-block: 1.15rem;
  border-top: 1px solid var(--line-soft);
}
.log-item:first-child { border-top: 0; padding-top: 0.25rem; }
.log-item__when {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--faint);
  padding-top: 0.12rem;
}
.log-item__title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.06rem;
  margin: 0 0 0.15rem;
  color: var(--ink);
}
.log-item__meta { margin: 0; color: var(--muted); font-size: 0.94rem; }
.log-item__meta em { font-style: italic; }

/* =====================================================================
   CV / experience — time in the right margin
   ===================================================================== */
.cv { display: flex; flex-direction: column; }
.cv__pdf { margin: -0.75rem 0 1.75rem; color: var(--muted); font-size: 0.94rem; }
.cv-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1.5rem;
  padding-block: 1.05rem;
  border-top: 1px solid var(--line-soft);
  align-items: baseline;
}
.cv-item:first-child { border-top: 0; padding-top: 0.25rem; }
.cv-item__place { font-weight: 600; color: var(--ink); }
.cv-item__role { color: var(--ink); }
.cv-item__sub { color: var(--muted); font-size: 0.92rem; margin-top: 0.1rem; }
.cv-item__time {
  color: var(--faint);
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

/* =====================================================================
   Footer
   ===================================================================== */
.foot {
  border-top: 1px solid var(--line);
  padding-block: 2.25rem 3rem;
  color: var(--muted);
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
}
.foot__social { display: inline-flex; gap: 0.25rem; margin-left: auto; }

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 640px) {
  body { font-size: 1rem; }
  .nav__brand { font-size: 0.95rem; }
  .nav__links { gap: 0.85rem; }
  .nav__links a { font-size: 0.8rem; }

  .hero__inner { flex-direction: column; gap: 1.25rem; }
  .hero__photo { width: 116px; height: 116px; }

  /* Collapse every rail: label becomes a small heading above content */
  .pub-year,
  .log-item { grid-template-columns: 1fr; gap: 0.55rem; }
  .pub-year__label { position: static; top: auto; padding-top: 0; }
  .log { --rail: auto; }

  .cv-item { grid-template-columns: 1fr; gap: 0.2rem; }
  .cv-item__time { text-align: left; order: -1; }
}

@media (max-width: 460px) {
  .nav__links { display: none; }   /* keep the bar clean; anchors still work */
}
