@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(fonts/source-serif-4-latin-opsz-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(fonts/source-serif-4-latin-opsz-italic.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url(fonts/source-serif-4-latin-ext-opsz-normal.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url(fonts/source-serif-4-latin-ext-opsz-italic.woff2) format("woff2-variations");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;
  --bg: #ffffff;
  --ink: #000000;
  --muted: #4a4a4a;
  --link: #0000ee;
  --visited: #551a8b;
  --hi: #ffef00;
  --hatch: rgba(0, 0, 0, .14);
  --tint: rgba(0, 0, 238, .05);

  --serif: "Source Serif 4", "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --serif-zh: "Noto Serif SC", "Songti SC", "SimSun", "Source Serif 4", serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --measure: 42.5rem;
  --gap: 3rem;
  --margin: 15rem;
  --cols:
    [full-start] minmax(1rem, 1fr)
    [text-start] minmax(0, var(--measure)) [text-end]
    var(--gap)
    [margin-start] var(--margin) [margin-end]
    minmax(1rem, 1fr) [full-end];
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #000000;
    --ink: #ffffff;
    --muted: #b8b8b8;
    --link: #8fa8ff;
    --visited: #c79bff;
    --hatch: rgba(255, 255, 255, .2);
    --tint: rgba(143, 168, 255, .08);
  }
}
@media (max-width: 60rem) {
  :root {
    --cols: [full-start] 1rem [text-start margin-start] minmax(0, 1fr) [text-end margin-end] 1rem [full-end];
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.0625rem, .95rem + .4vw, 1.1875rem);
  line-height: 1.55;
  font-variant-numeric: oldstyle-nums proportional-nums;
  font-optical-sizing: auto;
  text-autospace: normal;
  -webkit-text-size-adjust: 100%;
  counter-reset: sn;
}
::selection { background: var(--hi); color: #000; }
img { max-width: 100%; height: auto; }

.grid { display: grid; grid-template-columns: var(--cols); }
.grid > * { grid-column: text; }
.grid > .wide { grid-column: text-start / margin-end; }
.grid > .full { grid-column: full; }

a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: .15em; }
a:visited { color: var(--visited); }
a:hover { background: var(--ink); color: var(--bg); text-decoration: none; }
:focus-visible { outline: 3px solid var(--hi); outline-offset: 0; background: var(--ink); color: var(--bg); }

.label {
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-variant-numeric: lining-nums tabular-nums;
}

/* header: a row of bordered cells */
.site-header { padding-top: 1.5rem; }
.site-header nav { display: flex; flex-wrap: wrap; border: 2px solid var(--ink); }
.site-header nav a {
  padding: .55rem .9rem;
  border-right: 2px solid var(--ink);
  color: var(--ink);
  text-decoration: none;
}
.site-header nav a:last-child { border-right: 0; }
.site-header nav a:hover { background: var(--ink); color: var(--bg); }
.site-header nav .home { flex: 1 1 auto; }
.site-header nav a:lang(zh) { font-family: var(--serif-zh); text-transform: none; letter-spacing: .1em; font-size: .8rem; }

/* main flow */
main { position: relative; isolation: isolate; min-height: 100svh; padding-block: 3.5rem 4rem; }
main > * + * { margin-top: 1.1em; }
main > .rails + * { margin-top: 0; }
main > h2 { margin-top: 3.2rem; }
main > h2 + * { margin-top: .9em; }
p { margin: 0; hyphens: auto; text-wrap: pretty; }

h1 {
  margin: 0;
  font-size: clamp(2.75rem, 1.5rem + 5vw, 5.25rem);
  font-weight: 800;
  line-height: .95;
  letter-spacing: -.035em;
  text-wrap: balance;
}
h2 {
  margin: 0;
  padding-top: .6rem;
  border-top: 4px solid var(--ink);
  font-size: 1.6em;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -.015em;
  text-wrap: balance;
}
h2 .anchor { float: right; margin-top: .35rem; font-family: var(--mono); font-size: .7rem; font-weight: 400; letter-spacing: 0; }
.kicker { color: var(--muted); }
.lede { font-size: 1.2em; line-height: 1.45; }

/* the grid, drawn: shaded text column, hatched margin, rail between */
.grid > .rails { grid-column: full; }
.rails {
  position: absolute;
  inset: 0;
  z-index: -1;
  display: grid;
  grid-template-columns: var(--cols);
  pointer-events: none;
}
.rails .r-text { grid-column: text; background: var(--tint); }
.rails .r-margin {
  grid-column: margin;
  margin-left: calc(var(--gap) / -2);
  border-left: 1px solid var(--ink);
  background: repeating-linear-gradient(135deg, var(--hatch) 0 1px, transparent 1px 8px);
}
@media (max-width: 60rem) { .rails .r-margin { border-left: 0; margin-left: 0; } }

/* sidenotes */
.sn-ref { counter-increment: sn; }
.sn-ref::after {
  content: "[" counter(sn) "]";
  font-family: var(--mono);
  font-size: .62em;
  font-weight: 700;
  vertical-align: super;
  line-height: 0;
  margin-left: .1em;
}
.sidenote, .marginnote {
  float: right;
  clear: right;
  width: var(--margin);
  margin-right: calc(-1 * (var(--margin) + var(--gap)));
  margin-bottom: 1rem;
  font-size: .8rem;
  line-height: 1.45;
  hyphens: manual;
}
.sidenote::before { content: "[" counter(sn) "] "; font-family: var(--mono); font-weight: 700; font-size: .9em; }
.marginnote { color: var(--muted); }
@media (max-width: 60rem) {
  .sidenote, .marginnote {
    float: none;
    display: block;
    width: auto;
    margin: .75em 0;
    padding: .5rem .75rem;
    border: 1px solid var(--ink);
    border-left-width: 4px;
  }
}

/* writing list: ruled rows */
.posts { list-style: none; padding: 0; margin-bottom: 0; border-top: 2px solid var(--ink); }
.posts li { display: grid; grid-template-columns: 6.5rem 1fr; gap: .2rem 1rem; padding-block: .75rem; border-bottom: 1px solid var(--ink); }
.posts time { padding-top: .35em; }
.posts a { font-weight: 700; font-size: 1.05em; }
.posts .summary { grid-column: 2; color: var(--muted); font-size: .92em; }

/* tables */
.table-wrap { overflow-x: auto; border: 2px solid var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: .88em; font-variant-numeric: lining-nums tabular-nums; }
th, td { text-align: left; vertical-align: top; padding: .55em .8em; border: 1px solid var(--ink); }
tr > :first-child { border-left: 0; }
tr > :last-child { border-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
th {
  background: var(--ink);
  color: var(--bg);
  border-top: 0;
  font-family: var(--mono);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* code */
code { font-family: var(--mono); font-size: .86em; }
pre {
  margin-bottom: 0;
  overflow-x: auto;
  background: var(--ink);
  color: var(--bg);
  padding: 1rem 1.1rem;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.6;
}
pre code { font-size: inherit; }

/* figures */
figure { margin: 0; }
figcaption { margin-top: .75rem; font-size: .85rem; color: var(--muted); }

/* chinese */
:lang(zh) { font-family: var(--serif-zh); line-height: 1.85; hyphens: manual; font-variant-numeric: lining-nums; }
h2:lang(zh) { line-height: 1.25; letter-spacing: .06em; }
.sidenote:lang(zh), :lang(zh) .sidenote, :lang(zh) .marginnote { line-height: 1.65; }

/* footer */
.site-footer { padding-bottom: 3rem; }
.site-footer dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); margin: 0; border: 2px solid var(--ink); }
.site-footer dl > div { padding: .6rem .8rem; border-right: 1px solid var(--ink); border-bottom: 1px solid var(--ink); margin-right: -1px; margin-bottom: -1px; }
.site-footer dt { color: var(--muted); }
.site-footer dd { margin: .2rem 0 0; font-size: .9rem; }
