:root {
  color-scheme: light;
  --bg: #f7f2ea;
  --paper: #fffaf2;
  --text: #241d16;
  --muted: #766b5f;
  --soft: #a09180;
  --line: rgba(43, 34, 25, 0.14);
  --accent: #8c5c32;
  --accent-soft: #efe3d2;
  --shadow: rgba(45, 32, 18, 0.08);
  --max: 980px;
  --serif: Georgia, "Times New Roman", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #161411;
  --paper: #1f1b17;
  --text: #f3eadc;
  --muted: #c2b5a3;
  --soft: #928574;
  --line: rgba(243, 234, 220, 0.16);
  --accent: #d0a064;
  --accent-soft: rgba(208, 160, 100, 0.14);
  --shadow: rgba(0, 0, 0, 0.26);
}

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

html { scroll-behavior: smooth; overflow-x: hidden; }

body {
  min-width: 320px;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    linear-gradient(90deg,
      transparent 0,
      transparent calc(50% - 490px),
      rgba(140, 92, 50, 0.045) calc(50% - 490px),
      rgba(140, 92, 50, 0.045) calc(50% - 489px),
      transparent calc(50% - 489px)
    ),
    var(--bg);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.72;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  transition: color 320ms ease, background 320ms ease;
}

a {
  color: inherit;
  text-decoration-color: color-mix(in srgb, var(--accent) 38%, transparent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}
a:hover { color: var(--accent); text-decoration-color: currentColor; }

img { max-width: 100%; height: auto; display: block; }

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

/* ── Language toggle ── */
html[lang="en"] [lang="zh"] { display: none; }
html[lang="zh"] [lang="en"] { display: none; }

/* ── Header ── */
.site-header {
  position: sticky; top: 0; z-index: 20;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  transition: background 320ms ease, border-color 320ms ease;
}
.header-inner {
  display: grid;
  width: min(calc(100% - 44px), var(--max));
  min-height: 68px;
  grid-template-columns: 1fr auto auto;
  align-items: center; gap: 28px;
  margin: 0 auto;
}
.brand {
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.18rem; font-weight: 700;
}
.top-nav {
  display: flex; gap: 18px;
  color: var(--muted);
  font-size: 0.88rem; font-weight: 600;
}
.top-nav a { text-decoration: none; flex: 0 0 auto; position: relative; }
.top-nav a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 1.5px;
  background: currentColor; transform: scaleX(0); transform-origin: left center;
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}
.top-nav a:hover::after,
.top-nav a[aria-current="page"]::after { transform: scaleX(1); }
.top-nav a[aria-current="page"] { color: var(--text); }

.theme-toggle {
  display: grid; width: 34px; height: 34px; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  color: var(--text); background: transparent; cursor: pointer;
  transition: color 260ms ease, border-color 260ms ease, background 260ms ease;
}
.theme-icon {
  width: 14px; height: 14px; border-radius: 50%; background: currentColor;
  box-shadow: inset -5px -5px 0 color-mix(in srgb, var(--paper) 96%, transparent);
  transition: box-shadow 260ms ease;
}
[data-theme="dark"] .theme-icon { box-shadow: none; }

/* ── Language switch in nav ── */
.lang-switch {
  display: flex; gap: 6px;
  font-size: 0.82rem; font-weight: 600;
  color: var(--muted);
}
.lang-switch a { text-decoration: none; color: var(--muted); }
.lang-switch a:hover { color: var(--accent); }

/* ── Page shell ── */
.page-shell, .site-footer {
  width: min(calc(100% - 44px), var(--max));
  margin: 0 auto;
}

/* ── Intro ── */
.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 238px;
  gap: 52px; align-items: start;
  padding: 58px 0 50px;
  border-bottom: 1px solid var(--line);
}
.intro-copy { min-width: 0; max-width: 660px; }
.kicker {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}
h1, h2, h3, h4 { margin: 0; font-family: var(--serif); letter-spacing: 0; }
h1 {
  font-size: clamp(2.35rem, 5.4vw, 3.9rem);
  font-weight: 700; line-height: 1.02;
}
.name-cn {
  display: block; margin-top: 12px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 1.05rem; font-weight: 500;
  letter-spacing: 0.18em;
}
h2 { margin-bottom: 24px; font-size: clamp(1.42rem, 2.6vw, 1.9rem); font-weight: 700; line-height: 1.1; }
h3 { font-size: 1.16rem; font-weight: 700; line-height: 1.22; }
p { margin: 0; color: var(--muted); overflow-wrap: break-word; }
p + p { margin-top: 14px; }
.intro-cn { margin-top: 24px; color: var(--text); font-size: 1.02rem; }

.link-row {
  display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 22px;
}
.link-row a { color: var(--accent); font-weight: 650; position: relative; text-decoration: none; }
.link-row a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 1.5px;
  background: currentColor; transform: scaleX(0); transform-origin: left center;
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}
.link-row a:hover::after { transform: scaleX(1); }

/* ── Portrait ── */
.portrait { margin: 0; max-width: 100%; }
.portrait-img {
  display: block; width: 238px; aspect-ratio: 4 / 5;
  object-fit: cover; object-position: center 48%;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--paper);
  box-shadow: 0 18px 42px var(--shadow);
  filter: saturate(0.92) contrast(0.98) brightness(0.9);
}

/* ── Sections ── */
.section {
  padding: 46px 0;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 88px;
}

/* ── Education ── */
.education-entry {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 30px; align-items: start;
  padding-top: 14px; border-top: 1px solid var(--line);
}
.education-period {
  margin: 0;
  color: var(--accent);
  font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase;
}
.education-body h3 { margin-bottom: 6px; }
.education-body h3 a { text-decoration: none; }
.education-affiliation { margin-bottom: 12px; }
.education-affiliation a { color: var(--accent); font-weight: 650; }

/* ── Research / Interests ── */
.research-head {
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: 12px 18px; margin-bottom: 28px; padding-bottom: 16px;
  border-bottom: 2px solid var(--accent);
}
.research-head h2 { margin: 0; }
.research-umbrella {
  color: var(--accent);
  font-family: var(--serif);
  font-size: clamp(1.32rem, 2.3vw, 1.72rem);
  font-weight: 600;
}
.research-umbrella::before {
  content: "\00B7"; margin-right: 16px;
  color: var(--soft); font-weight: 400;
}

.research-directions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 30px;
}
.research-directions article { padding-top: 14px; border-top: 2px solid var(--accent-soft); }
.research-directions h3 { margin-top: 8px; }
.research-directions p:not(.direction-label) { margin-top: 10px; }
.direction-label {
  margin: 0;
  color: var(--accent);
  font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.09em; text-transform: uppercase;
}

/* ── Project / Publication card ── */
.project-card {
  display: grid;
  grid-template-columns: 255px minmax(0, 1fr);
  gap: 28px; align-items: start;
}
.project-image {
  display: block; overflow: hidden;
  border: 1px solid var(--line); border-radius: 4px;
  background: var(--paper); text-decoration: none;
}
.project-image img {
  display: block; width: 100%; aspect-ratio: 4 / 3;
  object-fit: cover; padding: 0;
  filter: saturate(0.9) contrast(0.96) brightness(0.9);
}
.project-card h3 { max-width: 660px; }
.project-card .project-body > p:not(.venue) { margin-top: 12px; }
.venue {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.project-links {
  display: flex; gap: 14px; margin-top: 14px;
}
.project-links a { color: var(--accent); font-weight: 650; position: relative; text-decoration: none; }
.project-links a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -2px; height: 1.5px;
  background: currentColor; transform: scaleX(0); transform-origin: left center;
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
}
.project-links a:hover::after { transform: scaleX(1); }
.project-badges {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px;
}
.badge {
  display: inline-flex; align-items: center; width: fit-content;
  border-radius: 999px; padding: 3px 9px;
  border: 1px solid color-mix(in srgb, #7b8f69 36%, var(--line));
  color: color-mix(in srgb, #4d633f 78%, var(--text));
  background: color-mix(in srgb, #dfe9d5 58%, transparent);
  font-size: 0.76rem; font-weight: 650; line-height: 1.35;
}
[data-theme="dark"] .badge {
  border-color: color-mix(in srgb, #a8c091 42%, var(--line));
  color: #c9ddb4;
  background: color-mix(in srgb, #53653f 25%, transparent);
}

/* ── Competitions table ── */
.comp-table {
  border-top: 1px solid var(--line); margin-top: 8px;
}
.comp-table > div {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) 120px;
  gap: 22px; align-items: baseline;
  padding: 12px 14px; margin: 0 -14px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
  transition: background 220ms ease;
}
.comp-table > div:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.comp-table .comp-year { color: var(--muted); }
.comp-table .comp-name { color: var(--text); font-weight: 650; }
.comp-table .comp-result { color: var(--muted); text-align: right; }
.comp-table .comp-result-featured { color: #a46f21; font-weight: 720; }
[data-theme="dark"] .comp-table .comp-result-featured { color: #e3bd6e; }
.comp-table .comp-detail {
  display: block; margin-top: 3px;
  color: var(--muted); font-size: 0.86rem; font-weight: 400; line-height: 1.45;
}

/* ── Route cards (Links section) ── */
.route-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.route-card {
  display: grid; min-height: 86px; align-content: space-between;
  padding: 15px 16px;
  border: 1px solid var(--line); border-radius: 4px;
  color: inherit;
  background: color-mix(in srgb, var(--paper) 68%, transparent);
  text-decoration: none;
  transition: border-color 220ms ease, background 220ms ease, transform 220ms ease;
}
.route-card:hover, .route-card:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 46%, var(--line));
  color: var(--text);
  background: color-mix(in srgb, var(--accent-soft) 52%, var(--paper));
  transform: translateY(-2px);
}
.route-card span {
  color: var(--accent);
  font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.route-card strong { display: block; margin-top: 18px; overflow-wrap: anywhere; font-size: 0.94rem; font-weight: 650; }

/* ── Blog post list ── */
.post-list-section { border-bottom: 1px solid var(--line); padding: 46px 0; }
.post-list { list-style: none; padding: 0; border-top: 1px solid var(--line); }
.post-list li {
  padding: 14px 14px; margin: 0 -14px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
  transition: background 220ms ease;
}
.post-list li:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.post-list .post-date {
  color: var(--muted);
  font-size: 0.82rem; font-weight: 500;
}
.post-list a {
  display: block; margin-top: 2px;
  font-family: var(--serif);
  font-size: 1.08rem; font-weight: 700;
  text-decoration: none; color: var(--text);
}
.post-list a:hover { color: var(--accent); }
.post-list small {
  display: block; margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem; font-weight: 400;
  line-height: 1.5;
}

/* ── Blog article ── */
.article-hero { padding: 58px 0 34px; border-bottom: 1px solid var(--line); }
.article-hero h1 { max-width: 760px; }
.article-body { padding: 46px 0; max-width: 720px; margin: 0 auto; }
.article-body h2 { margin-top: 2em; }
.article-body h3 { margin-top: 1.6em; }
.article-body p { margin: 1em 0; }
.article-body ul, .article-body ol { margin: 0.75em 0; padding-left: 1.5em; color: var(--muted); }
.article-body li { margin: 0.3em 0; }
.article-body pre {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px 18px;
  overflow-x: auto;
  margin: 1em 0;
  font-size: 0.875rem; line-height: 1.55;
}
.article-body code {
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.88em;
  background: var(--accent-soft);
  padding: 0.12em 0.35em; border-radius: 3px;
}
.article-body pre code { background: none; padding: 0; border-radius: 0; }
.article-body hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }
.article-body blockquote {
  border-left: 3px solid var(--accent-soft);
  padding-left: 1em; margin: 1em 0;
  color: var(--text); font-style: italic;
}
.article-body table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.article-body th, .article-body td {
  border: 1px solid var(--line);
  padding: 0.5em 0.75em;
  text-align: left; vertical-align: top;
  font-size: 0.94rem;
}
.article-body th { background: var(--accent-soft); font-weight: 700; color: var(--text); }

/* ── CV ── */
.cv-page { padding: 58px 0 64px; }
.cv-header {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: 30px; align-items: end;
  padding-bottom: 30px; border-bottom: 2px solid var(--accent);
}
.cv-header h1 { margin-bottom: 10px; }
.cv-meta { color: var(--muted); font-size: 0.92rem; }
.cv-section { padding: 28px 0; border-bottom: 1px solid var(--line); }
.cv-section h2 { margin-bottom: 14px; }
.cv-row {
  display: grid;
  grid-template-columns: 138px minmax(0, 1fr);
  gap: 18px; padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.cv-row dt {
  color: var(--soft);
  font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding-top: 2px;
}
.cv-row dd { margin: 0; color: var(--text); }
.cv-row a { color: var(--accent); font-weight: 650; }
.cv-item + .cv-item { margin-top: 18px; }
.cv-item h3 { margin-bottom: 7px; }
.cv-item .venue { margin-bottom: 8px; }

/* ── Notes ── */
.notes-hero { padding: 58px 0 34px; border-bottom: 1px solid var(--line); }

/* ── Page hero (generic for about, etc.) ── */
.page-hero { padding: 58px 0 34px; border-bottom: 1px solid var(--line); }
.page-hero h1 { max-width: 760px; }
.page-hero > p { max-width: 620px; margin-top: 18px; }

/* ── Footer ── */
.site-footer {
  display: flex; justify-content: space-between; gap: 18px;
  padding: 24px 0 42px;
  border-top: 1px solid var(--line);
  color: var(--soft); font-size: 0.84rem;
}
.site-footer a { color: var(--soft); }

/* ── Section note ── */
.section-note { max-width: 840px; margin-bottom: 20px; }

/* ── About skills table ── */
.skills-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 30px;
}
.skills-grid article { padding-top: 14px; border-top: 2px solid var(--accent-soft); }
.skills-grid h3 { margin-top: 8px; }
.skills-grid ul { margin-top: 10px; padding-left: 1.2em; color: var(--muted); }
.skills-grid li { margin: 3px 0; font-size: 0.94rem; }

/* ── About contact ── */
.contact-section { padding-bottom: 0; border-bottom: 0; }

/* ── Scroll reveal ── */
@media (prefers-reduced-motion: no-preference) {
  .reveal {
    opacity: 0; transform: translateY(20px);
    transition: opacity 640ms ease, transform 640ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  .reveal.is-visible { opacity: 1; transform: none; }
}

/* ── Responsive ── */
@media (max-width: 820px) {
  .header-inner { grid-template-columns: 1fr auto; gap: 14px; }
  .top-nav {
    min-width: 0; max-width: 100%;
    grid-column: 1 / -1;
    overflow-x: auto; padding-bottom: 12px;
    scrollbar-width: none;
  }
  .top-nav::-webkit-scrollbar { display: none; }
  .intro, .project-card, .education-entry { grid-template-columns: 1fr; }
  .intro { gap: 28px; padding-top: 42px; }
  .portrait { order: -1; }
  .portrait-img { width: min(100%, 260px); }
  .research-directions, .skills-grid { grid-template-columns: 1fr; gap: 22px; }
  .route-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .comp-table > div { grid-template-columns: 1fr; gap: 2px; }
  .cv-header, .cv-row { grid-template-columns: 1fr; }
  .cv-row { gap: 4px; }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  .page-shell, .site-footer, .header-inner {
    width: calc(100dvw - 28px); max-width: calc(100dvw - 28px);
  }
  h1 { font-size: clamp(2.18rem, 12vw, 2.8rem); }
  .brand { font-size: 1.05rem; }
  .top-nav { gap: 14px; font-size: 0.84rem; }
  .section { padding: 36px 0; }
  .route-grid { grid-template-columns: 1fr; }
  .site-footer { flex-direction: column; }
}
