/* ==========================================================================
   Jiacheng Lu — personal homepage
   Editorial / research-lab aesthetic · bilingual EN / 中
   ========================================================================== */

/* ----- Reset ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
ul { margin: 0; padding: 0; list-style: none; }
h1, h2, h3 { margin: 0; font-weight: inherit; }
p { margin: 0; }

/* ----- Design tokens ---------------------------------------------------- */
:root {
  --bg: #FAF9F5;
  --surface: #F4F1E8;
  --fg: #262624;
  --muted: #8A877C;
  --rule: #E6E1D2;
  --accent: #CC785C;
  --accent-soft: rgba(204, 120, 92, 0.14);
  --scholar: #1967D2;

  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --serif-cjk: "Source Han Serif SC", "Noto Serif SC", "Songti SC", STSong, serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, "PingFang SC", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --maxw: 680px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

html[data-theme="dark"] {
  --bg: #1F1E1C;
  --surface: #26241F;
  --fg: #F4F2EB;
  --muted: #9F9C90;
  --rule: #37342D;
  --accent: #E08968;
  --accent-soft: rgba(224, 137, 104, 0.16);
  --scholar: #8AB4F8;
}

/* ----- Base ------------------------------------------------------------- */
html {
  background: var(--bg);
  color: var(--fg);
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.7;
  background: var(--bg);
  color: var(--fg);
  font-feature-settings: "kern", "liga";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 260ms var(--ease), color 260ms var(--ease);
}

html[lang^="zh"] body {
  font-family: var(--serif-cjk), var(--serif);
}

@media (min-width: 720px) {
  body { font-size: 18px; }
}

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

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

.icon-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ----- Layout ----------------------------------------------------------- */
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 24px 96px;
}

@media (min-width: 720px) {
  .wrap { padding: 32px 32px 128px; }
}

/* ----- Top header (toggles) -------------------------------------------- */
.site-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  margin-bottom: 56px;
  font-family: var(--sans);
  font-size: 13px;
}

@media (min-width: 720px) {
  .site-header { margin-bottom: 72px; }
}

.toggle {
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--muted);
  letter-spacing: 0.02em;
  transition: color 180ms var(--ease), border-color 180ms var(--ease);
}

.toggle:hover { color: var(--accent); border-color: var(--accent); }

.toggle-lang .lang { opacity: 0.4; transition: opacity 180ms var(--ease), color 180ms var(--ease); }
.toggle-lang .sep { margin: 0 6px; color: var(--rule); }
html[data-lang="en"] .toggle-lang .lang-en,
html[data-lang="cn"] .toggle-lang .lang-cn {
  opacity: 1;
  color: var(--fg);
}

/* ----- Bilingual visibility -------------------------------------------- */
.cn { display: none; }
html[data-lang="cn"] .en { display: none; }
html[data-lang="cn"] .cn { display: inline; }

.aka {
  font-style: normal;
  font-weight: 400;
  font-size: 0.58em;
  letter-spacing: 0;
  color: var(--muted);
  margin-left: 12px;
  vertical-align: 0.12em;
}
html[data-lang="cn"] .aka { margin-left: 10px; font-size: 0.52em; }

.toggle-theme .icon-sun,
.toggle-theme .icon-moon { display: inline-block; }
html[data-theme="dark"] .toggle-theme .icon-sun { display: none; }
html:not([data-theme="dark"]) .toggle-theme .icon-moon { display: none; }

/* ----- Hero ------------------------------------------------------------- */
.hero {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 20px;
  align-items: center;
  padding-bottom: 48px;
}

.hero-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--rule);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.hero-name {
  font-size: 30px;
  line-height: 1.12;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.hero-name .name-cn {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.68em;
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0;
  vertical-align: 0.08em;
}

.hero-tagline {
  margin-top: 6px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.5;
}

@media (min-width: 720px) {
  .hero {
    grid-template-columns: 80px 1fr;
    gap: 24px;
    padding-bottom: 64px;
  }
  .hero-avatar { width: 80px; height: 80px; }
  .hero-name { font-size: 36px; }
  .hero-tagline { font-size: 15.5px; }
}

/* ----- Sections --------------------------------------------------------- */
.section {
  border-top: 1px solid var(--rule);
  padding: 44px 0;
}

@media (min-width: 720px) {
  .section { padding: 60px 0; }
}

.section-label {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -0.005em;
  color: var(--fg);
  margin: 0 0 28px;
  text-transform: none;
}

.section-label::before {
  content: "";
  display: block;
  width: 3px;
  height: 24px;
  background: var(--accent);
  border-radius: 2px;
  flex-shrink: 0;
}

html[lang^="zh"] .section-label {
  font-family: var(--serif-cjk), var(--serif);
  letter-spacing: 0.01em;
}

@media (min-width: 720px) {
  .section-label {
    font-size: 30px;
    gap: 18px;
    margin: 0 0 36px;
  }
  .section-label::before { height: 28px; width: 3px; }
}

.section > p + p { margin-top: 14px; }

.section-subhead {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 36px 0 14px;
}

/* ----- Row list (Education) -------------------------------------------- */
.rows { display: flex; flex-direction: column; gap: 18px; }

.row {
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 20px;
  align-items: baseline;
}

.row-year {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  font-feature-settings: "tnum";
  letter-spacing: 0.02em;
}

.row-title { font-weight: 500; line-height: 1.5; }

.row-meta {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.55;
}

@media (max-width: 540px) {
  .row { grid-template-columns: 1fr; gap: 2px; }
}

/* ----- Publications ---------------------------------------------------- */
.pubs { display: flex; flex-direction: column; gap: 26px; }

.pub {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 20px;
  align-items: baseline;
}

.pub-year {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--muted);
  font-feature-settings: "tnum";
  padding-top: 2px;
}

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

.pub-title {
  font-weight: 500;
  line-height: 1.42;
  margin-bottom: 6px;
}

.pub-authors {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 4px;
}

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

.pub-venue {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.pub-venue .tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  vertical-align: 1px;
}

.pub-links {
  margin-top: 6px;
  font-family: var(--sans);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 30px;
}

.pub-links a {
  color: var(--muted);
  transition: color 160ms var(--ease);
}
.pub-links a::before { content: "↗ "; opacity: 0.55; }
.pub-links a:hover { color: var(--accent); }

.scholar-cite {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 5px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), background-color 160ms var(--ease);
}

.scholar-cite svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.scholar-cite:hover,
.scholar-cite:focus-visible {
  color: var(--scholar);
  border-color: var(--scholar);
  background: color-mix(in srgb, var(--scholar) 8%, transparent);
}

.scholar-cite::after {
  content: attr(data-tooltip-en);
  position: absolute;
  z-index: 10;
  top: calc(100% + 7px);
  left: -5px;
  width: max-content;
  max-width: min(220px, calc(100vw - 48px));
  padding: 5px 8px;
  color: var(--bg);
  background: var(--fg);
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: opacity 140ms var(--ease), transform 140ms var(--ease), visibility 140ms;
}

html[data-lang="cn"] .scholar-cite::after { content: attr(data-tooltip-cn); }
.scholar-cite:hover::after,
.scholar-cite:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.pub-footnote {
  margin-top: 28px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  line-height: 1.65;
}

@media (max-width: 540px) {
  .pub { grid-template-columns: 1fr; gap: 4px; }
  .pub-year { padding-top: 0; }
}

/* ----- Citation dialog ------------------------------------------------- */
.cite-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(20, 18, 14, 0.24);
  overflow: auto;
}

.cite-dialog::backdrop {
  background: rgba(20, 18, 14, 0.52);
  backdrop-filter: blur(2px);
}

.cite-dialog-inner { padding: 24px; }

.cite-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.cite-dialog-source {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--scholar);
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.3;
}

.cite-dialog-source svg,
.cite-scholar-link svg {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: currentColor;
}

.cite-dialog h2 {
  margin-top: 5px;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0;
}

.cite-dialog-close {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 5px;
  transition: color 160ms var(--ease), border-color 160ms var(--ease), background-color 160ms var(--ease);
}

.cite-dialog-close:hover {
  color: var(--fg);
  border-color: var(--muted);
  background: var(--surface);
}

.cite-dialog-close svg,
.copy-bibtex svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.copy-bibtex svg[hidden] { display: none; }

.cite-paper-title {
  margin-top: 20px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.45;
}

html[lang^="zh"] .cite-dialog h2,
html[lang^="zh"] .cite-paper-title {
  font-family: var(--serif-cjk), var(--serif);
}

.bibtex-block {
  max-height: 42vh;
  margin: 14px 0 0;
  padding: 16px;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow: auto;
  overflow-wrap: anywhere;
  tab-size: 2;
  -webkit-overflow-scrolling: touch;
}

.cite-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}

.cite-scholar-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--fg);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  transition: color 160ms var(--ease), border-color 160ms var(--ease);
}

.cite-scholar-link:hover {
  color: var(--scholar);
  border-color: var(--scholar);
}

.copy-bibtex {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 138px;
  min-height: 38px;
  padding: 8px 13px;
  color: var(--bg);
  background: var(--fg);
  border: 1px solid var(--fg);
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  transition: color 160ms var(--ease), background-color 160ms var(--ease), border-color 160ms var(--ease);
}

.copy-bibtex:hover {
  color: var(--bg);
  background: var(--fg);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.copy-bibtex.is-copied {
  color: #fff;
  background: #3E7A55;
  border-color: #3E7A55;
}

.copy-status {
  min-height: 17px;
  margin-top: 7px;
  color: var(--fg);
  font-family: var(--sans);
  font-size: 11.5px;
  line-height: 1.45;
  text-align: right;
}

@media (max-width: 540px) {
  .cite-dialog { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
  .cite-dialog-inner { padding: 20px; }
  .cite-dialog-actions { align-items: stretch; flex-direction: column-reverse; gap: 12px; }
  .cite-scholar-link { align-self: flex-start; }
  .copy-bibtex { width: 100%; }
  .copy-status { text-align: left; }
}

@media (prefers-reduced-motion: no-preference) {
  .cite-dialog[open] { animation: dialogEnter 180ms var(--ease); }
}

@keyframes dialogEnter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ----- Service groups --------------------------------------------------- */
.service-group { margin-bottom: 20px; }
.service-group:last-child { margin-bottom: 0; }

.service-label {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.service-body { line-height: 1.65; }
.service-body .venue { display: inline; }

/* ----- Contact ---------------------------------------------------------- */
.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
  font-family: var(--sans);
  font-size: 14.5px;
}

.contact-links li {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.contact-links .label {
  font-size: 11.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.contact-links a {
  color: var(--fg);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 1px;
  transition: border-color 180ms var(--ease), color 180ms var(--ease);
}
.contact-links a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ----- Footer ----------------------------------------------------------- */
.site-footer {
  border-top: 1px solid var(--rule);
  padding-top: 28px;
  margin-top: 40px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ----- Motion ----------------------------------------------------------- */
@media (prefers-reduced-motion: no-preference) {
  .reveal {
    opacity: 0;
    transform: translateY(8px);
    animation: fadeRise 520ms var(--ease) forwards;
  }
  .reveal:nth-child(1) { animation-delay: 40ms; }
  .reveal:nth-child(2) { animation-delay: 120ms; }
  .reveal:nth-child(3) { animation-delay: 200ms; }
  .reveal:nth-child(4) { animation-delay: 280ms; }
  .reveal:nth-child(5) { animation-delay: 360ms; }
  .reveal:nth-child(6) { animation-delay: 440ms; }
  .reveal:nth-child(7) { animation-delay: 520ms; }
}

@keyframes fadeRise {
  to { opacity: 1; transform: translateY(0); }
}
