/* ============================================================
   Hanlong Chen — hanlongchen.com
   "Ink & Cobalt" — Apple-scale minimalism in a biostatistician's
   own voice: navy ink on navy-cast paper, one cobalt accent that
   is present at rest, and a mono metadata voice.

   Deliberately NOT Apple: no SF stack, no Apple tracking ladder,
   no 980px grid, left-aligned heroes, numbered eyebrows.
   ============================================================ */

/* ============ Tokens ============ */
:root {
  color-scheme: light;
  --bg: #fbfcfe;              /* navy-cast paper, not pure white */
  --text: #1b2436;            /* navy ink, not Apple near-black */
  --text-2: #545e72;
  --text-3: #626c80;
  --hairline: rgba(27, 36, 54, 0.14);
  --accent: #1e56c8;          /* cobalt, deeper than Apple azure */
  --nav-bg: rgba(251, 252, 254, 0.78);
  --selection: rgba(30, 86, 200, 0.16);

  --font-display: 'Avenir Next', 'Segoe UI Variable Display', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-text: 'Segoe UI Variable Text', 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, 'JetBrains Mono', 'Roboto Mono', monospace;

  --container: 78rem;
  --pad-x: clamp(1.25rem, 5vw, 2.5rem);
  --section-gap: clamp(4.5rem, 11vw, 8rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0c1120;            /* deep navy, not pure black */
    --text: #e9edf5;
    --text-2: #aab4c6;
    --text-3: #8b95a8;
    --hairline: rgba(233, 237, 245, 0.20);
    --accent: #7ea6ff;
    --nav-bg: rgba(12, 17, 32, 0.74);
    --selection: rgba(126, 166, 255, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1120;
  --text: #e9edf5;
  --text-2: #aab4c6;
  --text-3: #8b95a8;
  --hairline: rgba(233, 237, 245, 0.20);
  --accent: #7ea6ff;
  --nav-bg: rgba(12, 17, 32, 0.74);
  --selection: rgba(126, 166, 255, 0.25);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fbfcfe;
  --text: #1b2436;
  --text-2: #545e72;
  --text-3: #626c80;
  --hairline: rgba(27, 36, 54, 0.14);
  --accent: #1e56c8;
  --nav-bg: rgba(251, 252, 254, 0.78);
  --selection: rgba(30, 86, 200, 0.16);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: 4.5rem;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 1.0625rem;
  line-height: 1.6;
  overflow-wrap: break-word;
}

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

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent);
  transition: text-decoration-color 0.2s ease;
}
a:hover { text-decoration-color: var(--accent); }

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

h1, h2, h3 {
  font-family: var(--font-display);
  text-wrap: balance;
}

ul, ol { list-style: none; }

.container {
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--pad-x);
}

.skip-link {
  position: absolute;
  left: 1rem; top: -4rem;
  z-index: 20;
  background: var(--bg);
  color: var(--accent);
  padding: 0.5rem 0.875rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 0.75rem; }

main:focus { outline: none; }

.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;
}

/* ============ Header / Nav ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--nav-bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--hairline);
}

@supports not ((backdrop-filter: blur(14px)) or (-webkit-backdrop-filter: blur(14px))) {
  .site-header { background: var(--bg); }
}

.site-header nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 3.25rem;
}

.brand {
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--text);
  text-decoration: none;
  /* the links never shrink, so the wordmark ellipsizes rather than
     letting the row overflow on a narrow phone */
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-links {
  flex: none;
  display: flex;
  align-items: center;
  gap: clamp(0.85rem, 2.6vw, 1.6rem);
}

.nav-links a {
  font-size: 0.8125rem;
  color: var(--text-2);
  text-decoration: none;
  transition: color 0.2s ease;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); }
.nav-links a[aria-current="page"] { color: var(--text); font-weight: 600; }

.theme-toggle {
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hairline);
  border-radius: 50%;
  background: none;
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg { width: 0.875rem; height: 0.875rem; display: block; }

/* ============ Eyebrows — the numbered system ============ */
.eyebrow {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}
.eyebrow .idx {
  color: var(--accent);
  font-weight: 600;
  margin-right: 0.35em;
}

/* ============ Page hero (interior pages) ============ */
.page-hero {
  padding-top: clamp(3.5rem, 9vh, 6rem);
  padding-bottom: clamp(2.5rem, 6vw, 3.75rem);
  display: grid;
  gap: 1.125rem;
  justify-items: start;
}

.page-hero h1 {
  font-size: clamp(2.5rem, 7.5vw, 3.75rem);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.06;
}

.page-hero .lede {
  max-width: 74ch;
  font-size: clamp(1.0625rem, 1.6vw, 1.1875rem);
  line-height: 1.55;
  color: var(--text-2);
}

/* ============ Home hero — the whole home page ============ */
.home-hero {
  padding-top: clamp(4.5rem, 14vh, 8.5rem);
  padding-bottom: var(--section-gap);
  display: grid;
  gap: 1.75rem;
  justify-items: start;
}

.home-intro {
  width: 100%;
  max-width: 66ch;
  display: grid;
  gap: 1.25rem;
  font-size: clamp(1.0625rem, 1.7vw, 1.25rem);
  line-height: 1.65;
  color: var(--text-2);
}

.home-hero .interests {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.04em;
  line-height: 1.7;
  color: var(--text-3);
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.75rem;
  margin-top: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ============ Sections ============ */
.section {
  padding-bottom: var(--section-gap);
  scroll-margin-top: 4.5rem;
}

.section-inner {
  display: grid;
  gap: clamp(1.5rem, 3vw, 2.25rem);
}

.section-head {
  display: grid;
  gap: 0.5rem;
}

.section-head h2 {
  font-size: clamp(1.625rem, 4vw, 2.125rem);
  font-weight: 700;
  letter-spacing: -0.012em;
  line-height: 1.15;
}

/* ============ Research ============ */
.projects { display: grid; grid-template-columns: minmax(0, 1fr); }

/* research.html puts .projects straight inside .section, with no .section-inner
   above it, so it needs that gap back */
.section > .projects { padding-top: clamp(1.5rem, 3vw, 2.25rem); }

.project {
  padding-block: clamp(1.75rem, 3vw, 2.5rem);
  display: grid;
  gap: 0.5rem;
}

.project + .project { border-top: 1px solid var(--hairline); }
.project:first-child { padding-top: 0.25rem; }

.project-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1.5rem;
  align-items: baseline;
}

.project .project-title {
  font-family: var(--font-display);
  font-size: 1.3125rem;
  font-weight: 600;
  letter-spacing: -0.008em;
  line-height: 1.3;
  max-width: 58ch;
}

.project .period {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
}

.project .venue {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--text-2);
}

.project .desc {
  max-width: 78ch;
  color: var(--text-2);
  margin-top: 0.25rem;
}

.project--done .project-title { font-size: 1.125rem; color: var(--text-2); }
.project--done .venue { color: var(--text-3); }

/* ============ Working papers ============ */
.papers-list {
  counter-reset: paper;
  display: grid;
  gap: clamp(1.75rem, 3vw, 2.25rem);
  max-width: 64rem;
}

.papers-list > li {
  counter-increment: paper;
  display: grid;
  grid-template-columns: 2.75rem minmax(0, 1fr);
  column-gap: 0.75rem;
}

.papers-list > li::before {
  content: counter(paper, decimal-leading-zero);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.6;
  padding-top: 0.15em;
}

.authors {
  max-width: 78ch;
  font-size: 0.9375rem;
  color: var(--text-2);
  line-height: 1.55;
}

.authors strong {
  color: var(--text);
  font-weight: 600;
}

.status {
  margin-top: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.7;
  color: var(--text);
}
.status::before {
  content: "";
  display: inline-block;
  width: 0.375rem;
  height: 0.375rem;
  margin-right: 0.7em;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 0.12em;
}

/* equal-contribution and corresponding-author marks */
.mark {
  font-size: 0.7em;
  vertical-align: super;
  line-height: 0;
  color: var(--text-3);
}
.lede .mark { vertical-align: baseline; font-size: 0.85em; }

/* ============ Talks ============ */
.talk { display: grid; gap: 0.625rem; max-width: 64rem; }

.talk .talk-title {
  font-family: var(--font-display);
  font-size: 1.3125rem;
  font-weight: 600;
  letter-spacing: -0.008em;
  line-height: 1.35;
  max-width: 58ch;
}

.talk .venue {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--text-3);
  max-width: 78ch;
}

.talk .abstract { max-width: 74ch; color: var(--text-2); }

/* the one button pattern on the site */
.cta {
  justify-self: start;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--hairline);
  border-radius: 0.375rem;
  padding: 0.5rem 0.875rem;
  transition: border-color 0.2s ease, color 0.2s ease;
}
.cta:hover { border-color: var(--accent); color: var(--accent); }

/* ============ Teaching ============ */
.course-list { max-width: 60rem; }

.course-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.2rem 1.5rem;
  font-size: 1rem;
  color: var(--text-2);
  padding-block: 0.625rem;
  border-top: 1px solid var(--hairline);
}
.course-list li:last-child { border-bottom: 1px solid var(--hairline); }

.course-list .term {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--text-3);
  white-space: nowrap;
}

/* ============ Pagination ============ */
.pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding-block: 1.5rem;
  border-top: 1px solid var(--hairline);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

/* ============ Footer ============ */
.site-footer {
  border-top: 1px solid var(--hairline);
  padding-block: 2.25rem 3.25rem;
}

.foot-inner { display: grid; gap: 1.1rem; }

.foot-skills {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-3);
}

.foot-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.75rem;
  font-size: 0.875rem;
}

.foot-links a { color: var(--text-2); text-decoration: none; }
.foot-links a:hover { color: var(--accent); }

.copyright {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  color: var(--text-3);
}

/* ============ Motion ============ */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }

  .js .reveal {
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.6s cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 0.6s cubic-bezier(0.22, 0.61, 0.36, 1);
  }

  .js .reveal.is-in {
    opacity: 1;
    transform: translateY(0);
  }

  .js .home-hero .reveal:nth-child(2),
  .js .page-hero .reveal:nth-child(2) { transition-delay: 70ms; }
  .js .home-hero .reveal:nth-child(3),
  .js .page-hero .reveal:nth-child(3) { transition-delay: 140ms; }
  .js .home-hero .reveal:nth-child(4) { transition-delay: 210ms; }
}

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

/* ============ Responsive ============ */
/* the nav is one non-wrapping row, so it tightens in steps down to 320px */
@media (max-width: 640px) {
  /* the date drops under the title rather than squeezing it */
  .project-head {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 0.15rem;
  }
}

@media (max-width: 620px) {
  .nav-links { gap: 0.75rem; }
  .nav-links a { font-size: 0.75rem; }
}

@media (max-width: 480px) {
  /* the wordmark on the left already goes home */
  .nav-links a[href="index.html"] { display: none; }
  .brand { font-size: 0.875rem; }
  .nav-links { gap: 0.7rem; }
}

@media (max-width: 440px) {
  .papers-list > li { grid-template-columns: 2.25rem minmax(0, 1fr); }
}

@media (max-width: 400px) {
  .brand { font-size: 0.8125rem; }
  .nav-links { gap: 0.6rem; }
  .nav-links a { font-size: 0.6875rem; }
}

@media (max-width: 340px) {
  .brand { font-size: 0.75rem; }
  .nav-links { gap: 0.5rem; }
  .nav-links a { font-size: 0.625rem; }
  .theme-toggle { width: 1.5rem; height: 1.5rem; }
}
