/* ============================================================
   Zhengji Zhang — personal site
   Academic minimal. Light by default, dark on request.
   Edit the tokens in :root to restyle the whole page.
   ============================================================ */

:root {
  --bg:        #fdfdfc;
  --surface:   #f6f5f2;
  --text:      #1c1b19;
  --text-soft: #55524d;
  --text-dim:  #8a8681;
  --rule:      #e3e0da;
  --rule-firm: #ccc7bf;
  --link:      #1c1b19;
  --accent:    #8a3324;   /* muted oxide red — used sparingly */
  --pos:       #2f6b47;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans:  "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --measure: 42rem;   /* reading column */
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:        #14140f;
  --surface:   #1c1c17;
  --text:      #eceae4;
  --text-soft: #b6b2a9;
  --text-dim:  #858076;
  --rule:      #2e2e27;
  --rule-firm: #45443b;
  --link:      #eceae4;
  --accent:    #d98b74;
  --pos:       #7fb894;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg:        #14140f;
    --surface:   #1c1c17;
    --text:      #eceae4;
    --text-soft: #b6b2a9;
    --text-dim:  #858076;
    --rule:      #2e2e27;
    --rule-firm: #45443b;
    --link:      #eceae4;
    --accent:    #d98b74;
    --pos:       #7fb894;
    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .25s ease, color .25s ease;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(3.5rem, 9vw, 7rem) 1.5rem 5rem;
}

/* ---------- Typography base ---------- */

p { margin: 0 0 1.1em; color: var(--text-soft); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid var(--rule-firm);
  transition: border-color .18s ease, color .18s ease;
}
a:hover { border-bottom-color: var(--accent); color: var(--accent); }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.dim { color: var(--text-dim); }

/* ---------- Masthead ---------- */

.masthead {
  padding-bottom: 2.25rem;
  margin-bottom: 3rem;
  border-bottom: 1px solid var(--rule);
}

.name {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 7vw, 3.25rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0 0 .55rem;
  color: var(--text);
}

.affil {
  font-family: var(--serif);
  font-size: 1.06rem;
  font-style: italic;
  line-height: 1.5;
  color: var(--text-soft);
  margin: 0 0 1.4rem;
}

.links {
  font-size: .875rem;
  font-family: var(--mono);
  letter-spacing: .01em;
}
.links a { border-bottom-color: var(--rule); }
.links .sep { color: var(--text-dim); margin: 0 .55rem; }

/* ---------- Sections ---------- */

.section { margin-bottom: 3.5rem; }
.section:last-of-type { margin-bottom: 3rem; }

.section-title {
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 1.5rem;
  padding-bottom: .6rem;
  border-bottom: 1px solid var(--rule);
}

.lede {
  font-family: var(--serif);
  font-size: 1.22rem;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 1.2em;
}

/* ---------- Work entries ---------- */

.entry {
  padding-bottom: 2.6rem;
  margin-bottom: 2.6rem;
  border-bottom: 1px solid var(--rule);
}
.entry:last-child { border-bottom: 0; padding-bottom: 0; margin-bottom: 0; }

.entry__head { margin-bottom: .9rem; }

.entry__title {
  font-family: var(--serif);
  font-size: 1.42rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  margin: 0 0 .2rem;
}
.entry__title a { border-bottom-width: 0; }
.entry__title a:hover { border-bottom-width: 1px; }

.entry__meta {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--text-dim);
  margin: 0;
  letter-spacing: .01em;
}

/* Live-demo link on a work entry */

.entry__links {
  margin: .55rem 0 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: .25rem .6rem;
}

.demo-link {
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--accent);
  border-bottom: 1px solid currentColor;
  white-space: nowrap;
}
.demo-link::after { content: " \2197"; }
.demo-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

.demo-note {
  font-size: .76rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* ---------- Metric tables ---------- */

.metrics {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4rem 0 .9rem;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}

.metrics caption {
  caption-side: top;
  text-align: left;
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--text-dim);
  letter-spacing: .015em;
  padding-bottom: .65rem;
}

.metrics thead th {
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--rule-firm);
  padding: 0 0 .45rem;
  text-align: left;
}

.metrics th[scope="row"] {
  font-weight: 400;
  text-align: left;
  color: var(--text-soft);
  padding: .55rem 1rem .55rem 0;
  border-bottom: 1px solid var(--rule);
}

.metrics td {
  padding: .55rem 0;
  border-bottom: 1px solid var(--rule);
  color: var(--text-soft);
}

.metrics tbody tr:last-child th,
.metrics tbody tr:last-child td { border-bottom: 0; }

.metrics .num {
  font-family: var(--mono);
  text-align: right;
  white-space: nowrap;
  padding-left: 1.25rem;
}
.metrics thead .num { text-align: right; }

.metrics .unit {
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--text-dim);
  text-align: left;
  padding-left: .6rem;
  width: 1%;
  white-space: nowrap;
}

.metrics .pos  { color: var(--pos); }
.metrics .flat { color: var(--text-dim); }

.metrics tr.best th[scope="row"],
.metrics tr.best td { color: var(--text); font-weight: 500; }

.caveat {
  font-size: .855rem;
  line-height: 1.6;
  color: var(--text-dim);
  border-left: 2px solid var(--rule-firm);
  padding-left: .95rem;
  margin: 0 0 1.1em;
}

/* ---------- Award ---------- */

.award {
  font-size: .89rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: .8rem .95rem;
  margin: 0 0 1.1em;
  line-height: 1.55;
}

.award__tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .11em;
  color: var(--accent);
  border: 1px solid currentColor;
  border-radius: 2px;
  padding: .1rem .42rem;
  margin-right: .55rem;
  vertical-align: 1px;
}

/* ---------- Stack chips ---------- */

.stack {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem .5rem;
  padding: 0;
  margin: 1.1rem 0 0;
}
.stack li {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--text-dim);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: .16rem .5rem;
  white-space: nowrap;
}

/* ---------- Footer ---------- */

.footer {
  padding-top: 2rem;
  border-top: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: .76rem;
  color: var(--text-dim);
}
.footer p { color: inherit; margin: 0; }

/* ---------- Theme toggle ---------- */

.theme-toggle {
  position: fixed;
  top: 1.4rem;
  right: 1.4rem;
  z-index: 10;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text-dim);
  border: 1px solid var(--rule);
  border-radius: 50%;
  cursor: pointer;
  transition: color .18s ease, border-color .18s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--rule-firm); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.theme-toggle svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .ic-moon { display: none; }
html[data-theme="dark"] .theme-toggle .ic-sun  { display: none; }
html[data-theme="dark"] .theme-toggle .ic-moon { display: block; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .theme-toggle .ic-sun  { display: none; }
  html:not([data-theme="light"]) .theme-toggle .ic-moon { display: block; }
}

/* ---------- Small screens ---------- */

@media (max-width: 600px) {
  body { font-size: 16px; }
  .wrap { padding-top: 4rem; }
  .theme-toggle { top: 1rem; right: 1rem; }

  /* Let the wider ESG table scroll rather than squeeze the page */
  .metrics { display: block; overflow-x: auto; white-space: nowrap; }
  .metrics th[scope="row"] { white-space: normal; min-width: 11rem; }
}

/* ---------- Print ---------- */

@media print {
  .theme-toggle { display: none; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .wrap { max-width: none; padding: 0; }
  a { border-bottom: 0; }
}
