/* tex.css - a light, TeX-document reading theme.
 *
 * These are long mathematical expositions: the reader follows derivations,
 * navigates by section number, and meets inline math in almost every
 * paragraph. So the page is set like a paper rather than like a blog.
 *
 *   body      IBM Plex Serif - shares a spine with the TeX faces MathJax
 *             renders, so inline math sits in the line instead of on top of it
 *   structure IBM Plex Mono   - headings, metadata, tags, controls
 *   accent    hyperref ink blue, the colour of a LaTeX \href
 *   signature sections numbered into the left margin, LaTeX-style
 */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Serif:ital,wght@0,400;0,600;1,400&display=swap');

:root{
  --bg:#f5f7f9;          /* cool paper, not warm cream */
  --surface:#ffffff;
  --fg:#14181e;
  --muted:#586172;
  --faint:#8a94a4;
  --rule:#dde3ea;
  --rule-soft:#e6ebf1;
  --accent:#1b3fa0;      /* hyperref ink blue */
  --accent-bg:#e9eefb;
  --code:#eceff4;
  --mark:#fff6d5;
  --serif:'IBM Plex Serif','Charter','Bitstream Charter',Georgia,'Times New Roman',serif;
  --mono:'IBM Plex Mono',ui-monospace,SFMono-Regular,'SF Mono',Menlo,Consolas,monospace;
  --measure:42rem;
  --gutter:5rem;
}

/* Dark companion: same structure, dimmed. The light setting above is the
 * designed one. Three states, in this order:
 *   1. no data-theme + system dark  -> dark   (follow the reader's OS)
 *   2. data-theme="light"           -> light  (explicit choice beats the OS)
 *   3. data-theme="dark"            -> dark   (explicit choice, light OS)
 * The :not() guard is what makes case 2 work.
 */
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#12151a; --surface:#171b22; --fg:#dde3ec; --muted:#98a2b3;
    --faint:#6b7484; --rule:#252b35; --rule-soft:#1f242c;
    --accent:#8fb0ff; --accent-bg:#1a2436; --code:#1c2129; --mark:#3a3320;
  }
}
:root[data-theme="dark"]{
  --bg:#12151a; --surface:#171b22; --fg:#dde3ec; --muted:#98a2b3;
  --faint:#6b7484; --rule:#252b35; --rule-soft:#1f242c;
  --accent:#8fb0ff; --accent-bg:#1a2436; --code:#1c2129; --mark:#3a3320;
}

*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{
  margin:0;
  background:var(--bg);
  color:var(--fg);
  font-family:var(--serif);
  font-size:18px;
  line-height:1.72;
  font-feature-settings:"kern" 1,"liga" 1;
  -webkit-font-smoothing:antialiased;
}
.wrap{max-width:var(--measure);margin:0 auto;padding:0 1.25rem 7rem}

a{color:var(--accent);text-underline-offset:2px;text-decoration-thickness:.06em}
a:hover{text-decoration-thickness:.12em}
:focus-visible{outline:2px solid var(--accent);outline-offset:3px;border-radius:2px}

/* ---------- colour-scheme toggle ---------- */
.scheme-toggle{
  position:fixed;
  top:.85rem;
  right:.85rem;
  z-index:50;
  padding:.28rem .5rem;
  font-family:var(--mono);
  font-size:.68rem;
  letter-spacing:.02em;
  line-height:1.4;
  color:var(--muted);
  background:var(--surface);
  border:1px solid var(--rule);
  border-radius:3px;
  cursor:pointer;
  opacity:.75;
}
.scheme-toggle:hover{opacity:1;color:var(--accent);border-color:var(--accent)}
.scheme-toggle:focus-visible{opacity:1}

/* ---------- index header ---------- */
header.site{padding:3.5rem 0 1.5rem;margin-bottom:2rem;border-bottom:1px solid var(--rule)}
header.site h1{
  margin:0 0 .6rem;
  font-family:var(--mono);
  font-size:1.35rem;
  font-weight:600;
  letter-spacing:-.02em;
}
header.site h1 a{color:var(--fg);text-decoration:none}
header.site h1 a:hover{color:var(--accent)}
header.site p{
  margin:.3rem 0;
  font-family:var(--mono);
  font-size:.79rem;
  line-height:1.6;
  color:var(--muted);
}

/* ---------- controls ---------- */
.controls{display:flex;gap:.55rem;flex-wrap:wrap;margin:0 0 1.1rem}
.controls input,.controls select{
  font-family:var(--mono);
  font-size:.82rem;
  padding:.5rem .65rem;
  color:var(--fg);
  background:var(--surface);
  border:1px solid var(--rule);
  border-radius:3px;
}
.controls input{flex:1;min-width:13rem}
.controls input::placeholder{color:var(--faint)}
.controls input:focus,.controls select:focus{border-color:var(--accent);outline:none}
.count{
  font-family:var(--mono);
  font-size:.75rem;
  color:var(--faint);
  margin-bottom:.9rem;
  letter-spacing:.02em;
}

/* ---------- index list ---------- */
ul.posts{list-style:none;margin:0;padding:0}
ul.posts li{padding:.8rem 0;border-bottom:1px solid var(--rule-soft)}
ul.posts li:hover{background:linear-gradient(90deg,var(--accent-bg),transparent 60%)}
ul.posts a.t{
  display:inline-block;
  font-size:1.02rem;
  font-weight:600;
  line-height:1.4;
  color:var(--fg);
  text-decoration:none;
}
ul.posts a.t:hover{color:var(--accent);text-decoration:underline}
.meta{
  display:flex;
  gap:.5rem;
  flex-wrap:wrap;
  align-items:center;
  margin-top:.3rem;
  font-family:var(--mono);
  font-size:.72rem;
  color:var(--faint);
}
.meta > span:first-child{font-variant-numeric:tabular-nums;color:var(--muted)}
/* How math-heavy a piece is, straight from the source - the one number a
   reader of this archive actually wants before opening anything. */
.eq{color:var(--accent);opacity:.85}
.tag{
  padding:.05rem .4rem;
  background:var(--code);
  border-radius:2px;
  font-size:.69rem;
  color:var(--muted);
}

/* ---------- article ---------- */
.nav{margin:0 0 1.75rem;padding-top:1.75rem;font-family:var(--mono);font-size:.78rem}
.nav a{text-decoration:none}
.nav a:hover{text-decoration:underline}

article h1{
  margin:0 0 .6rem;
  font-family:var(--mono);
  font-size:1.6rem;
  font-weight:600;
  line-height:1.28;
  letter-spacing:-.025em;
}
.byline{
  margin:0 0 2rem;
  padding-bottom:1.1rem;
  border-bottom:1px solid var(--rule);
  font-family:var(--mono);
  font-size:.75rem;
  line-height:1.75;
  color:var(--faint);
}
.byline .zh{
  display:block;
  margin-bottom:.4rem;
  font-family:var(--serif);
  font-size:.98rem;
  color:var(--muted);
}

/* Signature: sections numbered into the margin, as a paper would.
   These articles genuinely are sequential expositions whose sections get
   referred to by number, so the numbering carries information. */
article{counter-reset:sec}
article h2{
  counter-increment:sec;
  position:relative;
  margin:2.75rem 0 .75rem;
  font-family:var(--mono);
  font-size:1.02rem;
  font-weight:600;
  letter-spacing:-.01em;
  line-height:1.4;
}
article h2::before{
  content:"§" counter(sec);
  position:absolute;
  left:calc(-1 * var(--gutter));
  width:calc(var(--gutter) - 1.25rem);
  text-align:right;
  font-weight:400;
  font-size:.82em;
  color:var(--faint);
  font-variant-numeric:tabular-nums;
}
article h3{
  margin:2rem 0 .5rem;
  font-family:var(--mono);
  font-size:.92rem;
  font-weight:600;
  color:var(--muted);
}

article p{margin:1.1rem 0}
article img{display:block;max-width:100%;height:auto;margin:1.6rem auto;border:1px solid var(--rule);border-radius:2px}
article ul,article ol{padding-left:1.4rem}
article li{margin:.35rem 0}

blockquote{
  margin:1.4rem 0;
  padding:.1rem 0 .1rem 1.1rem;
  border-left:2px solid var(--rule);
  color:var(--muted);
}

pre{
  margin:1.4rem 0;
  padding:.9rem 1rem;
  background:var(--code);
  border:1px solid var(--rule-soft);
  border-radius:3px;
  overflow-x:auto;
  font-family:var(--mono);
  font-size:.8rem;
  line-height:1.6;
}
code{
  padding:.08rem .3rem;
  background:var(--code);
  border-radius:2px;
  font-family:var(--mono);
  font-size:.84em;
}
pre code{padding:0;background:none;font-size:inherit}

/* Display equations scroll inside their own box; the page never does. */
mjx-container[display="true"]{
  overflow-x:auto;
  overflow-y:hidden;
  max-width:100%;
  padding:.45rem 0;
}
mjx-container{font-size:1.02em}

table{border-collapse:collapse;width:100%;margin:1.4rem 0;font-size:.88rem;display:block;overflow-x:auto}
th,td{border:1px solid var(--rule);padding:.35rem .6rem;text-align:left}
th{background:var(--code);font-family:var(--mono);font-size:.78rem;font-weight:600}

/* Anchor targets for the original Chinese section links. */
.anchor{display:block;position:relative;top:-1.5rem;visibility:hidden}

.orig{
  margin-top:3.5rem;
  padding:1rem 1.1rem;
  background:var(--surface);
  border:1px solid var(--rule);
  border-left:2px solid var(--accent);
  border-radius:3px;
  font-family:var(--mono);
  font-size:.74rem;
  line-height:1.7;
  color:var(--muted);
}

/* ---------- responsive ---------- */
@media (max-width: 62rem){
  /* No room for a margin gutter: set the section number inline. */
  article h2::before{
    position:static;
    display:inline;
    width:auto;
    margin-right:.5rem;
    text-align:left;
  }
}
@media (max-width: 34rem){
  body{font-size:17px;line-height:1.68}
  .wrap{padding:0 1rem 4rem}
  header.site{padding-top:2.25rem}
  article h1{font-size:1.35rem}
  .controls input{min-width:100%}
}

@media (prefers-reduced-motion: reduce){
  *{animation:none !important;transition:none !important;scroll-behavior:auto !important}
}

@media print{
  body{background:#fff;color:#000;font-size:11pt}
  .controls,.nav,.count,.scheme-toggle{display:none}
  a{color:#000;text-decoration:underline}
}
