:root {
  --bg: #f5f2ec;
  --bg-2: #ebe6dd;
  --ink: #2a2724;
  --ink-2: #5d5851;
  --ink-3: #8f8880;
  --rule: #d8d1c5;
  --accent: #7c8c79;
  --accent-2: #9a8a76;

  --bg-t: rgba(245, 242, 236, 0.82);

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --bg-2: #232120;
    --ink: #e9e3d9;
    --ink-2: #b5aea3;
    --ink-3: #807a71;
    --rule: #35322e;
    --accent: #9daa99;
    --accent-2: #b3a48f;
    --bg-t: rgba(27, 26, 24, 0.82);
  }
}

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

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color 120ms ease, text-decoration-color 120ms ease;
}
a:hover { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

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

.wrap {
  width: 100%;
  max-width: 41rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ---- Top bar: floats along as you read ---- */
.top {
  position: sticky;
  top: 10px;
  z-index: 3;
  padding-top: 0.9rem;    /* sides come from .wrap — a shorthand here would erase them */
  padding-bottom: 0.9rem;
  border-radius: 999px;
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.01em;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  transform: translateY(var(--bob, 0px));   /* the buoyancy, driven by scroll */
  transition: background-color 380ms ease, box-shadow 380ms ease;
}
.top.afloat {
  background: var(--bg-t);
  -webkit-backdrop-filter: blur(9px) saturate(1.05);
  backdrop-filter: blur(9px) saturate(1.05);
  box-shadow: 0 0 0 1px var(--rule);
}
section, article { scroll-margin-top: 4.2rem; }   /* anchors clear the floating bar */
.top .mark {
  text-decoration: none;
  color: var(--ink);
  font-weight: 500;
}
.mark .zh {
  font-family: "Noto Serif SC Name", "Songti SC", "Noto Serif CJK SC", "SimSun", serif;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink-3);
  margin-left: 0.4em;
  letter-spacing: 0.08em;
  transition: color 120ms ease;
}
.mark:hover .zh { color: var(--ink); }
.top nav { display: flex; gap: 1.25rem; }
.top nav a {
  text-decoration: none;
  color: var(--ink-3);
}
.top nav a:hover, .top nav a[aria-current="page"] { color: var(--ink); }

/* ---- Hero ---- */
.hero { padding: 6.5rem 0 3.5rem; }
h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.6rem, 7vw, 3.75rem);
  line-height: 1.02;
  letter-spacing: -0.015em;
  margin: 0 0 1.5rem;
  font-variation-settings: "opsz" 72;
}
.lede {
  font-size: clamp(1.25rem, 2.6vw, 1.45rem);
  line-height: 1.4;
  color: var(--ink-2);
  margin: 0 0 1.5rem;
  max-width: 34rem;
  font-weight: 300;
}
.lede a { color: var(--ink); }
.kicker {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-3);
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0;
}
.kicker span:not(:last-child)::after {
  content: "·";
  margin: 0 0.6rem;
  color: var(--rule);
}

/* ---- Sections ---- */
section { padding: 2.75rem 0; border-top: 1px solid var(--rule); }
.label {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-3);
  margin: 0 0 1.75rem;
}
.label a { text-decoration: none; }
.label .more { float: right; text-transform: none; letter-spacing: 0.01em; font-weight: 400; }
.about p { margin: 0 0 1.1rem; font-size: 1.1rem; max-width: 36rem; }
.about p:last-child { margin-bottom: 0; }

/* ---- Entries ---- */
.entry {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  column-gap: 1.5rem;
  row-gap: 0.15rem;
  padding: 0 0 2.25rem;
}
.entry:last-child { padding-bottom: 0; }
.when {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  padding-top: 0.42rem;
  white-space: nowrap;
}
.who {
  margin: 0;
  font-weight: 500;
  font-size: 1.32rem;
  line-height: 1.25;
  letter-spacing: -0.005em;
}
.who a { text-decoration: none; }
.who a:hover { text-decoration: underline; }
.role {
  margin: 0.15rem 0 0.7rem;
  font-style: italic;
  color: var(--ink-2);
  font-size: 1.02rem;
}
.desc { margin: 0; color: var(--ink-2); max-width: 32rem; }
.desc + .desc { margin-top: 0.75rem; }
.entry > .who, .entry > .role, .entry > .desc { grid-column: 2; }

/* ---- Writing list ---- */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  column-gap: 1.5rem;
  padding: 0 0 1.75rem;
}
.post-list li:last-child { padding-bottom: 0; }
.post-list .who { font-size: 1.25rem; }
.post-list .desc { margin-top: 0.35rem; }

/* ---- Publication ---- */
.pub { max-width: 36rem; }
.pub .title {
  margin: 0 0 0.4rem;
  font-size: 1.32rem;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.005em;
}
.pub .authors { margin: 0 0 0.6rem; color: var(--ink-2); font-size: 1rem; }
.pub .authors b { font-weight: 500; color: var(--ink); }
.pub .venue {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-3);
  margin: 0 0 0.9rem;
}
.pub .venue em { font-style: normal; color: var(--accent-2); }
.pub .desc { margin-bottom: 0.9rem; }
.links {
  font-family: var(--sans);
  font-size: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.entry .links { grid-column: 2; margin-top: 0.9rem; }
.patents { margin-top: 2.25rem; }
.patents li { padding-bottom: 0.5rem; }

/* ---- Contact ---- */
.contact ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  row-gap: 0.55rem;
  column-gap: 1.5rem;
}
.contact li { display: contents; }
.contact .k {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-3);
  padding-top: 0.25rem;
}
.contact .v { font-size: 1.05rem; }

/* ---- Article pages ---- */
.article-head { padding: 5rem 0 2.5rem; }
.article-head .label { margin-bottom: 1.25rem; }
.article-head h1 {
  font-size: clamp(2.1rem, 5.2vw, 2.9rem);
  line-height: 1.1;
  margin-bottom: 1.25rem;
  max-width: 36rem;
}
.article-head .byline {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--ink-3);
  margin: 0;
}
.article-head .byline a { color: var(--ink-2); }

.prose { padding: 0 0 3.5rem; font-size: 1.1rem; line-height: 1.68; }
.prose > * { max-width: 36rem; }
.prose p { margin: 0 0 1.25rem; }
.prose h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 2.75rem 0 1rem;
}
.prose h2:first-child { margin-top: 0; }
.prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose ul, .prose ol { margin: 0 0 1.25rem; padding-left: 1.4rem; }
.prose li { margin: 0 0 0.45rem; padding-left: 0.25rem; }
.prose li::marker { color: var(--ink-3); }
.prose blockquote {
  margin: 1.5rem 0;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 2px solid var(--accent);
  color: var(--ink-2);
}
.prose blockquote p:last-child { margin-bottom: 0; }
.prose code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--bg-2);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
.prose .arrow { color: var(--ink-3); }
.prose .coda { margin-top: 2.25rem; }

.article-foot {
  border-top: 1px solid var(--rule);
  padding: 2rem 0 3rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.article-foot a { text-decoration: none; color: var(--ink-2); }
.article-foot a:hover { color: var(--accent); }

/* ---- Footer ---- */
footer {
  margin-top: auto;
  padding-top: 3rem;      /* sides come from .wrap */
  padding-bottom: 2.5rem;
  border-top: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--ink-3);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  html { font-size: 16px; }
  .hero { padding: 4.5rem 0 2.75rem; }
  .article-head { padding: 3.5rem 0 2rem; }
  /* one-line floating pill, inset from the screen edges; text stays on the
     page column (10px margin + reduced padding = the wrap's 1.5rem) */
  .top {
    flex-wrap: nowrap;
    align-items: center;
    width: auto;             /* .wrap's 100% would fight the margins */
    margin: 0 10px;
    top: 8px;
    padding: 0.7rem calc(1.5rem - 10px);
    font-size: 0.75rem;
    gap: 0.75rem;
  }
  .top .mark { white-space: nowrap; flex-shrink: 0; }
  .mark .zh { font-size: 0.8rem; margin-left: 0.3em; letter-spacing: 0.05em; }
  .top nav { gap: 0.85rem; flex-shrink: 0; }
  .top nav a { padding: 0.3rem 0; }
  .entry, .post-list li { grid-template-columns: 1fr; row-gap: 0.1rem; }
  .entry > .who, .entry > .role, .entry > .desc, .entry > .links { grid-column: 1; }
  .when { padding-top: 0; margin-bottom: 0.3rem; }
  .contact ul { grid-template-columns: 1fr; row-gap: 0.15rem; }
  .contact .k { padding-top: 0.6rem; }
  .contact li:first-child .k { padding-top: 0; }
  .label .more { float: none; display: block; margin-top: 0.4rem; }
}

@media (max-width: 374px) {
  /* the very narrowest screens: the pill keeps its one line */
  .mark .zh { display: none; }
}

/* ---- the cursor: a query ring that floats after a precise dot ---- */
html.cur, html.cur * { cursor: none !important; }
.cur-dot, .cur-ring {
  position: fixed; left: 0; top: 0; z-index: 90;
  pointer-events: none;
  opacity: 0;
  will-change: transform;
}
.cur-dot {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent);
  transition: opacity 200ms ease;
}
.cur-ring {
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--ink-3);
  transition: opacity 240ms ease, border-color 180ms ease;
}
.cur-ring.hot { border-color: var(--accent); }
@media (hover: none), (pointer: coarse) { .cur-dot, .cur-ring { display: none !important; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  a { transition: none; }
  .top { transition: none; }
}
