/* ============================================================
   yilunzhang.com — pure CSS, zero frameworks
   Design notes:
   - CSS custom properties (variables) drive theming; the
     prefers-color-scheme media query swaps them for dark mode.
   - Layout uses CSS Grid for the timeline and Flexbox for the
     header. No classes from any framework.
   ============================================================ */

:root {
  --bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --faint: #9ca3af;
  --accent: #dc2626;        /* medical red, from the CV — the "medicine" track */
  --accent-soft: #fef2f2;
  --accent2: #2563eb;       /* tech blue — the "building" track */
  --accent2-soft: #eff6ff;
  --rule: #e5e7eb;
  --code-bg: #f3f4f6;
  color-scheme: light;
}

/* Dark mode is opt-in via the theme toggle (saved in localStorage and
   applied by an inline script in <head> before paint). System
   prefers-color-scheme is intentionally NOT honored — default is light. */
:root[data-theme="dark"] {
  --bg: #0f1115;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --faint: #6b7280;
  --accent: #ef4444;
  --accent-soft: #1d1416;
  --accent2: #60a5fa;
  --accent2-soft: #11161f;
  --rule: #23272f;
  --code-bg: #1a1d23;
  color-scheme: dark;
}

body { transition: background-color .15s ease, color .15s ease; }

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}

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

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

header {
  display: flex;
  align-items: center;
  gap: 28px;
}

.avatar {
  width: 128px;
  height: 128px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  letter-spacing: -0.5px;
}

.tagline {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 1.05rem;
}

.social {
  display: flex;
  gap: 14px;
  align-items: center;
}

.social a,
.social button.theme-toggle {
  color: var(--faint);
  display: inline-flex;
  align-items: center;
}
.social a:hover,
.social button.theme-toggle:hover { color: var(--accent); }
.social svg { width: 22px; height: 22px; fill: currentColor; }

/* Light/dark theme toggle. Same shape as the social <a> icons so it sits
   naturally in the row (or in the blog-page top bar). The sun icon is
   only revealed when dark mode is active; the moon is the default. */
.theme-toggle {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  font: inherit;
}
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }

/* Top-of-page row on the blog index and post pages: crumb on the left,
   theme toggle on the right. */
.page-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-top .crumb { margin: 0; }
.page-top .theme-toggle { color: var(--faint); display: inline-flex; align-items: center; }
.page-top .theme-toggle:hover { color: var(--accent); }
.page-top .theme-toggle svg { width: 22px; height: 22px; fill: currentColor; }

/* ---------- EKG divider ---------- */

.ekg {
  display: block;
  width: 100%;
  height: 44px;
  margin: 28px 0 8px;
}

.ekg path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1400;
  stroke-dashoffset: 1400;
  animation: heartbeat 2.2s ease-out forwards;
}

@keyframes heartbeat {
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ekg path { animation: none; stroke-dashoffset: 0; }
}

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

section { margin-top: 56px; }

h2 {
  font-size: 1.15rem;
  margin: 0 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

h2::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

/* ---------- parallel timeline ----------
   How it works: the .timeline is a CSS Grid with 2 columns (one per
   track) and 31 rows, each row representing half a year from mid-2026
   (top) back to 2011 (bottom). Every card is pinned with grid-area:
   row-start / col-start / row-end / col-end, so a card's HEIGHT is its
   real duration, and concurrent chapters naturally sit side by side.
   On small screens the container switches to flexbox, the grid-area
   pins stop applying, and cards stack chronologically (DOM order). */

.timeline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto repeat(31, minmax(18px, auto));
  gap: 10px 14px;
}

.lane-h {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding-bottom: 4px;
}

.tag-med   { color: var(--accent); }
.tag-build { color: var(--accent2); }

.card {
  border-radius: 10px;
  border-left: 3px solid var(--rule);
  background: var(--code-bg);
  padding: 14px 16px;
  font-size: 0.93rem;
  line-height: 1.55;
  min-width: 0;
}

.card p { margin: 0 0 8px; }
.card p:last-child { margin-bottom: 0; }

.card .when {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--faint);
}

.card .org  { font-weight: 600; }
.card .role { color: var(--muted); }

.card.med   { border-left-color: var(--accent);  background: var(--accent-soft); }
.card.build { border-left-color: var(--accent2); background: var(--accent2-soft); }

.card.merged {
  border-left: 3px solid var(--accent);
  border-right: 3px solid var(--accent2);
  background: linear-gradient(90deg, var(--accent-soft), var(--accent2-soft));
}

.lane-tag { display: none; }   /* revealed on mobile, where lanes collapse */

/* grid-area: row-start / col-start / row-end / col-end
   row r covers the half-year starting at 2026.5 − (r − 1) · 0.5 */
.tl-atropos  { grid-area:  2 / 1 /  3 / 3; }  /* 2025 – now, both lanes */
.tl-sinai    { grid-area:  3 / 1 /  4 / 2; }  /* 2025 */
.tl-mgh      { grid-area:  3 / 2 /  9 / 3; }  /* 2023 – 2025 */
.tl-rutgers  { grid-area:  4 / 1 /  6 / 2; }  /* 2024 – 2025 */
.tl-tufts    { grid-area:  6 / 1 / 20 / 2; }  /* 2017 – 2024 */
.tl-hms      { grid-area:  9 / 2 / 15 / 3; }  /* 2020 – 2023 */
.tl-surgibox { grid-area: 15 / 2 / 19 / 3; }  /* 2018 – 2020 */
.tl-einstein { grid-area: 20 / 2 / 22 / 3; }  /* 2016 – 2017 */
.tl-minerva  { grid-area: 22 / 1 / 24 / 2; }  /* 2015 – 2016 */
.tl-union    { grid-area: 24 / 1 / 32 / 2; }  /* 2011 – 2015 */
.tl-nymc     { grid-area: 29 / 2 / 33 / 3; }  /* 2009 – 2013 */

/* ---------- writing / blog lists ---------- */

.post-list { list-style: none; padding: 0; margin: 0; }

.post-list li {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 16px;
  padding: 10px 0;
}

.post-list .date {
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  padding-top: 2px;
  white-space: nowrap;
}

.post-list .desc {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 2px 0 0;
}

/* ---------- talks & publications ---------- */

.pub-list { list-style: none; padding: 0; margin: 0; }

.pub-list li {
  padding: 12px 0;
  border-top: 1px solid var(--rule);
}
.pub-list li:first-child { border-top: none; }

.pub-list .venue {
  color: var(--faint);
  font-size: 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- misc ---------- */

.note {
  color: var(--muted);
  font-size: 0.95rem;
}

ul.plain { padding-left: 1.2em; margin: 0; }
ul.plain li { margin-bottom: 8px; }

/* ---------- blog post pages ---------- */

.post-header h1 { font-size: 1.7rem; margin-bottom: 6px; }

.post-meta {
  color: var(--faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.post-body { margin-top: 32px; }
.post-body h2 { margin-top: 40px; }
.post-body img { max-width: 100%; border-radius: 8px; }

.post-body code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.post-body pre {
  background: var(--code-bg);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.5;
}
.post-body pre code { background: none; padding: 0; }

.post-body blockquote {
  margin: 0;
  padding-left: 16px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.crumb {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

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

footer {
  margin-top: 80px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  color: var(--faint);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- mobile ---------- */

@media (max-width: 600px) {
  .container { padding: 32px 18px 60px; }

  header { flex-direction: column; text-align: center; gap: 18px; }
  .social { justify-content: center; }

  /* collapse the parallel timeline into one chronological column */
  .timeline { display: flex; flex-direction: column; gap: 12px; }
  .lane-h { display: none; }
  .lane-tag {
    display: inline;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    margin-left: 8px;
  }

  .post-list li { grid-template-columns: 1fr; gap: 2px; }
}
