/* ── Variables ── */
:root {
  --cream:        #FAF8F5;
  --border:       #E2D9D0;
  --text:         #1C1410;
  --text-mid:     #54463D;
  --text-light:   #7E6F67;
  --accent:       #C8603A;
  --accent-hover: #A84D2C;
  --sidebar-w:    240px;
  --gap:          72px;
  --max-w:        1060px;
  --nav-h:        0px;

  /* Typography */
  --font-ui:      'Inter', system-ui, -apple-system, sans-serif;
  --font-reading: 'Source Serif 4', ui-serif, 'New York', 'Times New Roman', Georgia, serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; scroll-padding-top: 24px; }

body {
  font-family: var(--font-ui);
  background: var(--cream);
  color: var(--text);
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-optical-sizing: auto;
}

::selection {
  background: var(--accent);
  color: var(--cream);
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 3px;
}
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* In-paragraph links should be discoverable without hover. */
.bio a,
.entry-meta a {
  text-decoration: underline;
  text-decoration-color: rgba(200, 96, 58, 0.45);
  text-underline-offset: 3px;
}
.bio a:hover,
.entry-meta a:hover {
  text-decoration-color: var(--accent-hover);
}

/* ── Avatar ── */
.avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  margin-bottom: 18px;
  display: block;
  border: 1px solid var(--border);
  box-shadow:
    0 0 0 4px var(--bg),
    0 0 0 5px rgba(200, 96, 58, 0.38),
    0 2px 10px rgba(28, 20, 16, 0.10);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.avatar:hover {
  transform: scale(1.045) rotate(1deg);
  box-shadow:
    0 0 0 4px var(--bg),
    0 0 0 5px rgba(200, 96, 58, 0.6),
    0 6px 18px rgba(28, 20, 16, 0.14);
}

/* ── Two-column layout ── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  column-gap: var(--gap);
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 64px 40px 80px;
  align-items: start;
}

/* ── Sidebar ── */
.sidebar {
  position: sticky;
  top: 48px;
}

.sidebar h1 {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.62rem;
  font-weight: 550;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.2;
}

.zh-name {
  font-family: "Source Serif 4", "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 1.02rem;
  letter-spacing: 0.42em;
  margin-right: -0.42em; /* optically recenter wide-tracked CJK */
  color: var(--text);
  margin-bottom: 10px;
}

.role {
  font-size: 0.88rem;
  color: var(--text-mid);
  line-height: 1.5;
}

.role.focus {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 0.92rem;
  color: var(--accent);
  margin-top: 2px;
}

.affil {
  font-size: 0.88rem;
  color: var(--text-mid);
  margin-top: 10px;
  line-height: 1.6;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  counter-reset: nav;
}

.side-nav a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 0.88rem;
  color: var(--text-mid);
  padding: 4px 0;
  transition: color 0.15s, transform 0.2s ease;
}
.side-nav a::before {
  counter-increment: nav;
  content: counter(nav, decimal-leading-zero);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  color: var(--text-light);
  transition: color 0.15s;
}
.side-nav a:hover {
  color: var(--accent);
  text-decoration: none;
  transform: translateX(3px);
}
.side-nav a:hover::before { color: var(--accent); }
.side-nav a.active { color: var(--accent); font-weight: 500; }
.side-nav a.active::before { color: var(--accent); }

.contact-list {
  list-style: none;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.contact-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.contact-list svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  margin-top: 3px;
  color: rgba(200, 96, 58, 0.55);
  transition: color 0.15s;
}
.contact-list li:hover svg { color: var(--accent); }

.contact-list a {
  font-size: 0.84rem;
  color: var(--text-mid);
  word-break: break-all;
  line-height: 1.4;
}
.contact-list a:hover { color: var(--accent); text-decoration: none; }

/* ── Main ── */
main {
  min-width: 0; /* prevent grid blowout */
}

/* ── Bio ── */
.bio {
  font-family: var(--font-reading);
  font-size: 1.12rem;
  color: var(--text);
  line-height: 1.9;
  margin-bottom: 22px;
}
.bio em {
  color: var(--accent);
  font-style: italic;
  font-weight: 400;
}

.interests-line {
  font-family: var(--font-reading);
  font-size: 1rem;
  color: var(--text-mid);
  line-height: 1.8;
}
.interests-line .label {
  font-family: var(--font-ui);
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

/* ── HR ── */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 44px 0;
}

/* ── Section headings ── */
h2 {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 22px;
}
h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Generic entry (research, education) ── */
.entry {
  margin-bottom: 28px;
}
.entry-title {
  font-family: var(--font-reading);
  font-size: 1.08rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.45;
}
.entry-meta {
  font-family: var(--font-reading);
  font-size: 0.95rem;
  color: var(--text-mid);
}

/* ── Entry resource links (Code / Report) ── */
.entry-links {
  font-size: 0.88rem;
  margin-top: 3px;
  color: var(--text-light);
}

/* ── Entry bullet lists ── */
.entry ul {
  margin: 7px 0 0 18px;
  font-size: 0.95rem;
  color: var(--text-mid);
  line-height: 1.7;
}
.entry li { margin-bottom: 4px; }
.entry li::marker { color: var(--accent); }

/* ── Project demo gallery ── */
.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.demo-grid figure { margin: 0; }
.demo-grid a { display: block; }
.demo-grid img {
  width: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.demo-grid a:hover img {
  box-shadow: 0 6px 18px rgba(28, 20, 16, 0.14);
  transform: translateY(-2px);
}
.demo-grid .span-all { grid-column: 1 / -1; }
.demo-grid .span-all img {
  max-width: 92%;
  margin: 0 auto;
}
.demo-grid figcaption {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Publications ── */
.pub { margin-bottom: 20px; }
.pub-title {
  font-family: var(--font-reading);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.6;
  margin-bottom: 6px;
}
.pub-authors {
  font-family: var(--font-reading);
  font-size: 0.9rem;
  color: var(--text-mid);
  margin-bottom: 2px;
  line-height: 1.65;
}
.pub-venue {
  font-family: var(--font-reading);
  font-size: 0.9rem;
  color: var(--text-mid);
}
.pub-note {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-light);
}

/* ── Skills ── */
.skills-table {
  border-collapse: collapse;
  font-size: 0.95rem;
}
.skills-table td {
  padding: 4px 0;
  vertical-align: top;
}
.skills-table td:first-child {
  width: 110px;
  color: var(--text-mid);
  padding-right: 16px;
  white-space: nowrap;
}

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 20px;
  font-size: 0.84rem;
  color: var(--text-light);
}
footer a { color: var(--text-light); }
footer a:hover { color: var(--accent); text-decoration: none; }

/* ── Mobile: collapse to single column ── */
@media (max-width: 700px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 36px 24px 64px;
    row-gap: 36px;
  }
  .sidebar {
    position: static;
  }
  .sidebar h1 { font-size: 1.5rem; }
  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 16px;
  }
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: rgba(28, 20, 16, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  cursor: zoom-out;
}
.lightbox.open {
  opacity: 1;
  visibility: visible;
}
.lightbox img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
  transform: scale(0.96);
  transition: transform 0.25s ease;
  cursor: default;
}
.lightbox.open img { transform: scale(1); }
.lightbox-caption {
  max-width: 80vw;
  font-size: 0.85rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
}
.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.28); }
.demo-grid figure a { cursor: zoom-in; }

/* ── Home: compact entry list with project link ── */
.project-link {
  display: inline-block;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.02em;
  text-decoration: none;
  transition: color 0.15s, transform 0.2s ease;
}
.entry-linkrow {
  margin-top: 4px;
}
.entry-linkrow .project-link:hover {
  color: var(--accent-hover);
  transform: translateX(2px);
}
.project-link:hover {
  color: var(--accent-hover);
}

/* ── Project detail page ── */
.project-wrap {
  max-width: 800px;
  margin: 0 auto;
  padding: 60px 36px 90px;
}

.back-link {
  display: inline-block;
  font-size: 0.84rem;
  color: var(--text-light);
  margin-bottom: 34px;
  transition: color 0.15s, transform 0.2s ease;
}
.back-link:hover { color: var(--accent); text-decoration: none; transform: translateX(-3px); }

.project-title {
  font-family: var(--font-reading);
  font-size: 2.05rem;
  font-weight: 600;
  letter-spacing: -0.018em;
  line-height: 1.28;
  color: var(--text);
  margin-bottom: 14px;
}

.project-meta {
  font-size: 0.92rem;
  color: var(--text-mid);
  line-height: 1.65;
}

.project-links {
  font-size: 0.9rem;
  margin-top: 10px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  color: var(--text-light);
}
.project-links a { color: var(--accent); font-weight: 500; }
.project-links a:hover { color: var(--accent-hover); }

.project-page section { margin-top: 46px; }

.project-page section h2 {
  font-family: var(--font-reading);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
  margin-bottom: 14px;
}
.project-page section h2::before {
  content: "";
  flex: 0 0 22px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.75;
}
.project-page section h2::after { background: var(--border); }

.project-page section p {
  font-size: 0.97rem;
  line-height: 1.78;
  color: var(--text-mid);
}
.project-page section p strong { color: var(--text); }
.project-page section em { color: var(--text); }

/* scrolling gallery: every figure spans full width */
.project-page .demo-grid {
  grid-template-columns: 1fr;
  gap: 28px;
  margin-top: 18px;
}
.project-page .demo-grid .span-all img,
.project-page .demo-grid img { max-width: 100%; }
.project-page .demo-grid figcaption {
  font-size: 0.82rem;
  text-align: center;
  margin-top: 7px;
}

@media (max-width: 700px) {
  .project-wrap { padding: 40px 22px 64px; }
  .project-title { font-size: 1.6rem; }
}

/* ── Home: brief intro for entries without a project page ── */
.entry-brief {
  font-size: 0.92rem;
  color: var(--text-mid);
  line-height: 1.65;
  margin-top: 4px;
  max-width: 90%;
}

/* ── Home: project entry — compact thumbnail beside meta-only content ── */
.project-entry {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}
.entry-thumb {
  display: grid;
  gap: 8px;
}
.entry-thumb a { display: block; }
.entry-thumb img {
  width: 100%;
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.entry-thumb a:hover img {
  box-shadow: 0 6px 18px rgba(28, 20, 16, 0.14);
  transform: translateY(-2px);
}
.entry-body { min-width: 0; }

.entry-desc {
  font-family: var(--font-reading);
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.62;
  margin-top: 8px;
}

@media (max-width: 700px) {
  .project-entry {
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: start;
  }
  .entry-thumb {
    width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}
