:root {
  --bg: #fbfaf7;
  --text: #1c1b19;
  --muted: #6b6862;
  --rule: #e4e1da;
  --accent: #0e7470;
  --code-bg: #f1efe9;
  --serif: "Source Serif 4", Charter, Georgia, serif;
  --sans: "Inter Tight", -apple-system, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --fig-mid: #9a968e;
  color-scheme: light;
}
/* dark: follows the OS unless the toggle chose light; or forced by the toggle */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514; --text: #e8e5df; --muted: #9a968e; --rule: #2e2c29; --accent: #4fbfb3; --code-bg: #211f1d;
    --fig-mid: #6f6b64; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161514; --text: #e8e5df; --muted: #9a968e; --rule: #2e2c29; --accent: #4fbfb3; --code-bg: #211f1d;
  --fig-mid: #6f6b64; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto;
  max-width: 44rem;
  padding: 0 1rem;
  background: var(--bg);
  color: var(--text);
  font: 400 1.125rem/1.6 var(--serif);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
/* links inside running text are underlined, so they read as links on cream paper */
.intro p:not(.links) a, article p a, article li a, article td a {
  text-decoration: underline 1px;
  text-underline-offset: 0.15em;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

/* header / footer */
header.site, footer.site {
  display: flex; justify-content: space-between; align-items: baseline;
  font: 400 0.9rem/1.4 var(--sans);
}
header.site { padding: 2rem 0 3rem; }
header.site .home { color: var(--text); font-weight: 600; }
body:has(.intro) header.site .home { visibility: hidden; }  /* home page has the name as h1 */
header.site nav { display: flex; align-items: center; }
header.site nav a { margin-left: 1.25rem; color: var(--muted); }
.theme-toggle {
  margin-left: 1rem; padding: 0.25rem; border: 0; background: none; color: var(--muted); cursor: pointer;
  display: inline-flex; line-height: 0;
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg { width: 1.2rem; height: 1.2rem; }
footer.site { margin: 5rem 0 2rem; padding-top: 1rem; border-top: 1px solid var(--rule); color: var(--muted); }
footer.site a { color: var(--muted); }

/* type: sans headings, serif text */
h1 { font: 700 2.4rem/1.1 var(--sans); letter-spacing: -0.02em; margin: 0 0 1rem; }
h2 {
  font: 600 1.15rem/1.3 var(--sans); letter-spacing: -0.005em;
  margin: 3.5rem 0 1.25rem; padding-top: 1rem; border-top: 1px solid var(--rule);
}
article h2 { font: 650 1.45rem/1.25 var(--sans); letter-spacing: -0.01em; border: 0; padding: 0; margin: 3rem 0 0.75rem; }
article h3 { font: 600 1.1rem/1.35 var(--sans); margin: 2rem 0 0.2rem; }
article h3 a { color: inherit; }
article h3 + .meta { margin-bottom: 0.75rem; }
p, ul, ol { margin: 0 0 1.1rem; }
ul, ol { padding-left: 1.25rem; }
li { margin-bottom: 0.35rem; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }
blockquote { margin: 1.5rem 0; padding-left: 1rem; border-left: 2px solid var(--rule); color: var(--muted); }
code { font: 0.85em var(--mono); background: var(--code-bg); padding: 0.1em 0.3em; border-radius: 3px; }
pre { background: var(--code-bg); padding: 1rem; overflow-x: auto; border-radius: 4px; font-size: 0.85rem; }
pre code { background: none; padding: 0; }
img, video, svg { max-width: 100%; height: auto; }
figure { margin: 2.5rem 0; }
figcaption { font: 0.85rem/1.5 var(--sans); color: var(--muted); margin-top: 0.6rem; }
article img { display: block; margin: 1.5rem auto; border-radius: 4px; }
/* several images side by side: <div class="gallery"><img ...><img ...></div> */
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.5rem; margin: 1.5rem 0; }
.gallery img { margin: 0; width: 100%; height: 100%; object-fit: cover; }
/* figure or image wider than the text column: <figure class="wide"> or ![](x.svg){: .wide} */
.wide { width: min(64rem, 100vw - 2rem); max-width: none; margin-left: 50%; transform: translateX(-50%); }
table { border-collapse: collapse; width: 100%; font: 0.9rem/1.5 var(--sans); margin: 1.5rem 0; display: block; overflow-x: auto; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.4rem 0.75rem 0.4rem 0; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; }
.footnote { font-size: 0.9rem; color: var(--muted); }

/* small sans meta text */
.meta, .links, .date { font: 400 0.875rem/1.5 var(--sans); color: var(--muted); }
/* post type: a small pill after the title */
.type {
  display: inline-block; margin-left: 0.35rem; padding: 0 0.45rem; vertical-align: 0.1em;
  font: 500 0.7rem/1.5 var(--sans); color: var(--muted); border: 1px solid var(--rule); border-radius: 999px; white-space: nowrap;
}
/* blog filter chips */
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0 0 0.5rem; }
.chip {
  font: 500 0.8rem/1 var(--sans); color: var(--muted); background: none; cursor: pointer;
  border: 1px solid var(--rule); border-radius: 999px; padding: 0.4rem 0.8rem;
}
.chip:hover { color: var(--text); border-color: var(--muted); }
.chip.active { color: var(--bg); background: var(--text); border-color: var(--text); }
section.year h2 { margin-top: 2.25rem; }
ul.posts li[hidden], section.year[hidden] { display: none; }
.date { font-variant-numeric: tabular-nums; }

/* home */
.intro .lead { font-size: 1.3rem; line-height: 1.45; }
.intro .portrait { float: right; width: 8.5rem; height: 8.5rem; object-fit: cover; border-radius: 50%; margin: 0.25rem 0 1rem 1.5rem; }
.intro .links { margin-top: 1.75rem; font-size: 0.95rem; display: flex; flex-wrap: wrap; column-gap: 1rem; }
.intro .links a { margin-right: 0; }
.links a { margin-right: 1rem; white-space: nowrap; }
.entry .links a { margin-right: 0.75rem; }
.pubs .entry { margin-bottom: 1.4rem; font-size: 1rem; line-height: 1.5; }
.pubs .ptitle { color: var(--text); font-weight: 600; }
.pubs .ptitle:hover { color: var(--accent); }
.pubs .venue { font-style: italic; color: var(--muted); }
.pubs .paper { display: grid; grid-template-columns: 10.5rem 1fr; gap: 1.25rem; align-items: start; margin-bottom: 1.75rem; }
.pubs .thumb { width: 100%; border: 1px solid var(--rule); border-radius: 6px; line-height: 0; }
.pubs .thumb svg { width: 100%; height: auto; }

/* post lists */
ul.posts { list-style: none; padding: 0; }
ul.posts li { display: flex; gap: 1rem; margin-bottom: 0.9rem; }
ul.posts .date { flex: 0 0 6.5rem; padding-top: 0.2rem; }
ul.posts .desc { display: block; font-size: 0.95rem; color: var(--muted); margin-top: 0.15rem; }

/* post page: Distill-like title block */
.title-block { margin-bottom: 2.75rem; }
.title-block h1 { font-size: 2.6rem; margin-bottom: 0.9rem; }
.title-block .dek { font-size: 1.25rem; line-height: 1.45; color: var(--muted); margin-bottom: 1.75rem; }
.byline {
  display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; gap: 0.75rem 1.5rem;
  padding: 0.9rem 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  font: 400 0.9rem/1.4 var(--sans); font-variant-numeric: tabular-nums;
}
.byline span { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.15rem; }
.byline a { color: var(--text); }
.post-footer { margin-top: 3rem; padding-top: 1rem; border-top: 1px solid var(--rule); font: 0.9rem var(--sans); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* heading rail on posts (toc.js): dashes left of the text, titles on hover */
html { scroll-behavior: smooth; }
article h2, article h3 { scroll-margin-top: 1.5rem; }
.toc { display: none; }
@media (min-width: 1180px) {
  .toc {
    display: flex; flex-direction: column; gap: 0.15rem;
    position: fixed; top: 50%; transform: translateY(-50%);
    left: max(1rem, calc(50% - 22rem - 15rem)); width: 13rem;
    font: 400 0.8rem/1.3 var(--sans);
  }
  .toc a { display: flex; align-items: center; gap: 0.6rem; padding: 0.2rem 0; color: var(--muted); text-decoration: none; }
  .toc i { flex: none; width: 0.9rem; height: 2px; border-radius: 1px; background: var(--muted); opacity: .45; transition: width .15s, opacity .15s; }
  .toc a.sub i { width: 0.5rem; margin-left: 0.4rem; }
  .toc span { opacity: 0; transition: opacity .15s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .toc:hover span { opacity: 1; }
  .toc a:hover { color: var(--text); }
  .toc a.active { color: var(--accent); }
  .toc a.active i { background: var(--accent); opacity: 1; width: 1.4rem; }
  .toc a.sub.active i { width: 0.9rem; }
}

@media (max-width: 540px) {
  body { font-size: 1.05rem; }
  h1, .title-block h1 { font-size: 1.9rem; }
  .intro .lead, .title-block .dek { font-size: 1.15rem; }
  header.site { padding: 1.25rem 0 2rem; }
  .intro .links { column-gap: 0.75rem; }  /* six links fit one line at 375px */
  .intro .portrait { width: 5.5rem; height: 5.5rem; margin-left: 1rem; }
  .pubs .paper { grid-template-columns: 1fr; gap: 0.6rem; }
  .pubs .thumb { width: 13rem; }
  .byline { grid-template-columns: repeat(2, auto); justify-content: start; gap: 0.75rem 2.5rem; }
  ul.posts li { flex-direction: column; gap: 0; }
  ul.posts .date { flex: none; padding: 0; }
}

/* inlined SVG figure: <img class="svg" src="/fig/x.svg">; add "wide" to break out of the text column */
article .svg { margin-top: 1.5rem; margin-bottom: 0.4rem; line-height: 0; }
article .svg svg { width: 100%; height: auto; }

/* company card under a company heading: device drawing + facts.
   <div class="cocard"><img class="svg dev" src="/fig/china/dev-x.svg"><dl>...</dl></div> */
.cocard { display: grid; grid-template-columns: 6rem 1fr; gap: 0.25rem 1.1rem; align-items: center;
  margin: 0.5rem 0 1rem; padding: 0.6rem 1rem 0.6rem 0.4rem; border: 1px solid var(--rule); border-radius: 6px; }
article .cocard .svg { margin: 0; }
.cocard dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 0.05rem 0.9rem; font: 0.85rem/1.45 var(--sans); }
.cocard dt { color: var(--muted); }
.cocard dd { margin: 0; }
.cocard .note { grid-column: 1 / -1; color: var(--text); padding-top: 0.25rem; margin: 0; font-size: 0.95rem; line-height: 1.5; }
.cocards { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.75rem; margin: 0.75rem 0 1.25rem; }
.cocards .cocard { grid-template-columns: 1fr; margin: 0; padding: 0.4rem 0.9rem 0.8rem; align-content: start; }
.cocards .cocard .svg { width: 5.5rem; }
.cocards .cocard h4 { margin: 0; font: 600 1rem/1.3 var(--sans); }
.cocards .cocard h4 a { color: inherit; }
/* how much public evidence: peer-reviewed paper / preprint / company claims / nothing in humans */
.ev::before { content: ""; display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; margin-right: 0.4rem;
  vertical-align: 0.02em; background: var(--fig-mid); }
.ev.paper::before { background: var(--accent); }
.ev.pre::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--accent); }
.ev.none::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--fig-mid); }
@media (max-width: 540px) { .cocard { grid-template-columns: 4.5rem 1fr; gap: 0.25rem 0.75rem; } }

/* appendix, Distill-style: the "References" section and everything after it is small sans and muted */
article h2#references { font: 600 1rem/1.4 var(--sans); color: var(--muted); border-top: 1px solid var(--rule); padding-top: 1.5rem; margin-top: 3.5rem; }
article h2#references ~ * { font: 400 0.8rem/1.6 var(--sans); color: var(--muted); }
article h2#references ~ p { margin: 1rem 0 0.25rem; }
article h2#references ~ p strong { color: var(--text); font-weight: 600; }
article h2#references ~ ul { padding-left: 1.1rem; margin: 0 0 0.5rem; }
article h2#references ~ ul li { margin: 0.1rem 0; }
article h2#references ~ .post-footer { font-size: 0.875rem; }
