/* ==========================================================================
   Rui Zhang — personal site
   Card-on-grey academic layout: fixed dark navbar, sticky profile rail,
   white content cards.
   ========================================================================== */

:root {
  --bg:          #f8f9fa;
  --card:        #ffffff;
  --card-head:   #fcfcfd;
  --nav:         #343a40;
  --nav-ink:     #ced4da;
  --nav-ink-on:  #ffffff;

  --ink:         #212529;
  --ink-soft:    #495057;
  --ink-faint:   #6c757d;
  --rule:        #e9ecef;
  --rule-strong: #dee2e6;

  --link:        #0069d9;
  --link-hover:  #003d80;
  --teal:        #17a2b8;
  --teal-wash:   #e7f6f8;

  --radius:      12px;
  --shadow:      0 2px 4px rgba(0, 0, 0, .075);

  --sans:  "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --head:  "Fira Sans", "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  --mono:  "Source Code Pro", "SFMono-Regular", Menlo, Consolas, monospace;

  --rail:  240px;
  --shell: 1080px;
  --navh:  56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #15171a;
    --card:        #1e2126;
    --card-head:   #23272d;
    --nav:         #0e1013;
    --nav-ink:     #adb5bd;
    --nav-ink-on:  #ffffff;

    --ink:         #e7eaed;
    --ink-soft:    #b3bac1;
    --ink-faint:   #868e96;
    --rule:        #2c3138;
    --rule-strong: #363c44;

    --link:        #61aaf2;
    --link-hover:  #8ec5ff;
    --teal:        #3bc9db;
    --teal-wash:   #10333a;

    --shadow:      0 2px 4px rgba(0, 0, 0, .35);
  }
}

:root[data-theme="dark"] {
  --bg:          #15171a;
  --card:        #1e2126;
  --card-head:   #23272d;
  --nav:         #0e1013;
  --nav-ink:     #adb5bd;
  --nav-ink-on:  #ffffff;

  --ink:         #e7eaed;
  --ink-soft:    #b3bac1;
  --ink-faint:   #868e96;
  --rule:        #2c3138;
  --rule-strong: #363c44;

  --link:        #61aaf2;
  --link-hover:  #8ec5ff;
  --teal:        #3bc9db;
  --teal-wash:   #10333a;

  --shadow:      0 2px 4px rgba(0, 0, 0, .35);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--navh) + 16px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

/* ========================================================== top navbar === */

.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--navh);
  background: var(--nav);
  z-index: 50;
}

.topnav-inner {
  max-width: var(--shell);
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand {
  font-family: var(--head);
  font-size: 17px;
  font-weight: 600;
  color: var(--nav-ink-on);
  margin-right: auto;
  letter-spacing: -.01em;
  white-space: nowrap;
}
.brand:hover { color: var(--nav-ink-on); text-decoration: none; }

.topnav-links {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.topnav-links::-webkit-scrollbar { display: none; }

.topnav-links a {
  color: var(--nav-ink);
  font-size: 14px;
  font-weight: 400;
  padding: 6px 11px;
  border-radius: 6px;
  white-space: nowrap;
  transition: color .15s, background .15s;
}
.topnav-links a:hover {
  color: var(--nav-ink-on);
  background: rgba(255, 255, 255, .09);
  text-decoration: none;
}

/* ============================================================== layout === */

.shell {
  max-width: var(--shell);
  margin: 0 auto;
  padding: calc(var(--navh) + 24px) 20px 56px;
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  gap: 24px;
  align-items: start;
}

.rail { position: sticky; top: calc(var(--navh) + 24px); }

.stack { display: grid; gap: 24px; min-width: 0; }

/* =============================================================== cards === */

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 13px 22px;
  background: var(--card-head);
  border-bottom: 1px solid var(--rule);
  font-family: var(--head);
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
}
.card-head svg {
  width: 15px;
  height: 15px;
  fill: var(--ink-faint);
  flex: none;
}

.card-body { padding: 22px; }

/* ======================================================= profile rail === */

.profile { text-align: center; padding: 20px 18px 18px; }

.portrait {
  width: 138px;
  height: 166px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  display: block;
  margin: 0 auto 14px;
}

.profile h1 {
  font-family: var(--head);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.015em;
  margin: 0 0 8px;
  color: var(--ink);
}

.profile p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.profile p.role { font-weight: 600; color: var(--ink); }

.profile .email {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--link);
  margin-top: 10px;
  word-break: break-all;
}

.socials {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 14px;
}
.socials a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  color: var(--ink-faint);
  transition: color .15s, background .15s;
}
.socials a:hover { color: var(--link); background: var(--bg); }
.socials svg { width: 16px; height: 16px; fill: currentColor; }

/* ================================================================ prose === */

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

.worked { margin: 0 0 13px; padding-left: 20px; }
.worked li { margin-bottom: 7px; color: var(--ink-soft); }
.worked li:last-child { margin-bottom: 0; }
.worked li::marker { color: var(--ink-faint); }

/* ================================================================= news === */

.news { display: grid; grid-template-columns: 44px 1fr; }

.news-year {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
  padding: 11px 0 0;
}

.news-items { display: grid; }

.news-item {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
  font-size: 14.5px;
  color: var(--ink-soft);
}
/* Keep the rule between year groups; drop it only at the very bottom. */
.news:last-of-type .news-item:last-child { border-bottom: none; }

.news-item .txt { flex: 1; min-width: 0; }
.news-item strong { color: var(--ink); font-weight: 700; }

.news-item .when {
  font-family: var(--mono);
  font-size: 12px;
  font-style: italic;
  color: var(--ink-faint);
  white-space: nowrap;
  flex: none;
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
  background: var(--teal);
  border-radius: 5px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: 1px;
}

/* ============================================================ projects === */

.projects { display: grid; gap: 14px; }

.project {
  display: block;
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 15px 17px;
  color: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.project:hover {
  border-color: var(--link);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.project-head {
  display: flex;
  align-items: center;
  gap: 11px;
  flex-wrap: wrap;
  margin-bottom: 7px;
}

.project-logo { height: 19px; width: auto; display: block; flex: none; }

.project-stars {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-faint);
}

.project-role {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--teal);
}

.project p { font-size: 14.5px; color: var(--ink-soft); margin: 0; }

/* ======================================================== publications === */

.pub-note { font-size: 13.5px; color: var(--ink-faint); margin: 0 0 18px; }

.pub-group {
  display: grid;
  grid-template-columns: 44px 1fr;
  margin-bottom: 20px;
}
.pub-group:last-child { margin-bottom: 0; }

.pub-year {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-faint);
  margin: 2px 0 0;
  grid-row: 1 / span 99;
}

/* Each entry is figure + text. The <img> removes itself when the file is
   missing, and the column collapses so the text simply reflows full width. */
.pub {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: start;
  margin-bottom: 20px;
}
.pub:last-child { margin-bottom: 0; }

/* contain, not cover: these are architecture diagrams, and cropping one
   cuts the mechanism out of the picture. */
.pub-fig {
  width: 152px;
  height: 100px;
  object-fit: contain;
  padding: 5px;
  border: 1px solid var(--rule-strong);
  border-radius: 7px;
  background: #fff;
  display: block;
}

.pub-text { min-width: 0; }

.pub-title {
  font-family: var(--head);
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.35;
  margin: 0 0 3px;
  color: var(--ink);
}
.pub-title a { color: var(--ink); }
.pub-title a:hover { color: var(--link); }

.pub-authors { font-size: 13.5px; color: var(--ink-soft); margin: 0 0 4px; }
.pub-authors .me { color: var(--ink); font-weight: 700; }

.pub-venue { font-size: 13px; color: var(--ink-faint); margin: 0; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  padding: 0 6px;
  margin-right: 8px;
}

/* Peer-reviewed venues are called out; preprints stay neutral. */
.badge.accepted {
  color: #fff;
  background: var(--teal);
  border-color: var(--teal);
}

.pub-links { margin-top: 5px; display: flex; gap: 10px; flex-wrap: wrap; }
.pub-links a { font-size: 12.5px; font-weight: 600; }

/* ============================================================ services === */

.svc { display: grid; gap: 18px; }
.svc h3 {
  font-family: var(--head);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 7px;
}
.svc ul { margin: 0; padding-left: 20px; display: grid; gap: 5px; }
.svc li { font-size: 14.5px; color: var(--ink-soft); }
.svc li::marker { color: var(--ink-faint); }
.svc li strong { color: var(--ink); font-weight: 600; }

/* ============================================================== footer === */

footer {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 20px 36px;
  font-size: 12.5px;
  color: var(--ink-faint);
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

/* ========================================================== responsive === */

@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; gap: 20px; }
  .rail { position: static; }

  .profile {
    display: grid;
    grid-template-columns: 118px 1fr;
    gap: 18px;
    text-align: left;
    align-items: center;
  }
  .portrait { width: 118px; height: 142px; margin: 0; }
  .socials { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .brand { font-size: 15px; }
  .topnav-links a { padding: 6px 8px; font-size: 13.5px; }
  .card-body { padding: 18px; }
  .news { grid-template-columns: 36px 1fr; }
  .news-item { flex-direction: column; gap: 3px; }
  .pub-group { grid-template-columns: 1fr; }
  .pub { grid-template-columns: 1fr; gap: 10px; }
  .pub-fig { width: 100%; height: 170px; }
  .pub-year {
    grid-row: auto;
    margin: 0 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--rule);
  }
  .project-role { margin-left: 0; width: 100%; }
  .profile { grid-template-columns: 1fr; text-align: center; }
  .portrait { margin: 0 auto; }
  .socials { justify-content: center; }
}
