/* blog.hanxiao.run — reader styles.
   One text column, figures that may break out of it, everything else in the margins. */

@font-face { font-family: "Source Serif 4"; src: url(fonts/source-serif-4-normal.woff2) format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Serif 4"; src: url(fonts/source-serif-4-italic.woff2) format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "Source Sans 3"; src: url(fonts/source-sans-3-normal.woff2) format("woff2"); font-weight: 200 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Source Sans 3"; src: url(fonts/source-sans-3-italic.woff2) format("woff2"); font-weight: 200 900; font-style: italic; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url(fonts/jetbrains-mono-normal.woff2) format("woff2"); font-weight: 100 800; font-style: normal; font-display: swap; }

:root {
  --paper: #EDF3F9;
  --sheet: #F7FAFD;
  --ink: #15233B;
  --ink-2: #33445F;
  --muted: #5B6C86;
  --rule: #CBD9E8;
  --rule-soft: #DCE6F1;
  --accent: #2B67C0;
  --accent-soft: rgba(43, 103, 192, 0.08);

  /* Figure palette. Articles use these and nothing else, so every figure belongs to the same family. */
  --c1: #2B67C0;  /* cobalt  */
  --c2: #D9822B;  /* amber   */
  --c3: #2A9D8F;  /* teal    */
  --c4: #7A5CC2;  /* violet  */
  --c5: #C2410C;  /* rust    */
  --c6: #8A9AB0;  /* slate   */

  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: "Source Sans 3", -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --text: 680px;
  --wide: 980px;
  --full: 1240px;
  --gutter: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); color: var(--ink); -webkit-text-size-adjust: 100%; scroll-padding-top: 24px; }
body {
  margin: 0; min-height: 100vh;
  font: 400 19px/1.65 var(--sans);
  font-feature-settings: "kern", "liga", "onum" 0;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
main { flex: 1; position: relative; }
::selection { background: rgba(43, 103, 192, 0.18); }

a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(43, 103, 192, 0.3); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-color: currentColor; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

/* ---------------------------------------------------------------- ambient ---- */

.field { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; }
.progress {
  position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 50;
  background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); opacity: 0.7;
}

/* --------------------------------------------------------------- masthead ---- */

.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  max-width: var(--full); width: 100%; margin: 0 auto; padding: 22px var(--gutter);
  font: 500 15px/1 var(--sans); letter-spacing: 0.01em;
}
.masthead .wordmark { display: inline-flex; align-items: center; gap: 11px; font: 600 18px/1 var(--serif); color: var(--ink); text-decoration: none; letter-spacing: -0.005em; }
.masthead .mark { width: 34px; height: 34px; flex: none; overflow: visible; }
.masthead .mark .plane { transition: transform .45s cubic-bezier(.2,.7,.2,1); }
.masthead .mark .grid circle { transition: opacity .45s; }
.masthead .wordmark:hover .plane { transform: translate(1.6px, -1.6px); }
.masthead .wordmark:hover .grid circle:nth-child(6) { opacity: 1; }
.masthead nav { display: flex; gap: 22px; }
.masthead nav a { color: var(--muted); text-decoration: none; }
.masthead nav a:hover { color: var(--ink); }

.sitefoot {
  display: flex; justify-content: space-between; gap: 16px;
  max-width: var(--full); width: 100%; margin: 96px auto 0; padding: 22px var(--gutter) 34px;
  border-top: 1px solid var(--rule-soft);
  font: 400 14px/1.4 var(--sans); color: var(--muted);
}
.sitefoot a { color: inherit; }

/* ------------------------------------------------------------------ index ---- */

.index { max-width: var(--full); width: 100%; margin: 0 auto; padding: 0 var(--gutter); }
.index-head { max-width: 760px; margin: 72px 0 88px calc(min(220px, 18vw)); }
.index-head h1 { font: 500 clamp(40px, 6vw, 64px)/1.02 var(--serif); letter-spacing: -0.02em; margin: 0 0 18px; }
.index-head p { font: 400 21px/1.5 var(--sans); color: var(--ink-2); margin: 0; max-width: 34em; }
.index .empty { margin-left: calc(min(220px, 18vw)); color: var(--muted); }

.year { display: grid; grid-template-columns: min(220px, 18vw) 1fr; border-top: 1px solid var(--rule); padding-top: 18px; margin-bottom: 40px; }
.year-label { font: 500 14px/1.6 var(--mono); color: var(--muted); margin: 6px 0 0; letter-spacing: 0.04em; }
.entries { list-style: none; margin: 0; padding: 0; }
.entry a { display: grid; grid-template-columns: 220px 1fr; gap: 32px; padding: 18px 0 30px; color: inherit; text-decoration: none; }
.entry + .entry a { border-top: 1px solid var(--rule-soft); padding-top: 30px; }
.entry .thumb {
  aspect-ratio: 16 / 10; border-radius: 4px; overflow: hidden;
  background: var(--sheet); border: 1px solid var(--rule-soft);
  display: grid; place-items: center;
  transition: border-color .25s, transform .4s cubic-bezier(.2,.7,.2,1);
}
.entry .thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb-blank { width: 40%; height: 1px; background: var(--rule); }
.entry time { font: 500 13px/1 var(--mono); color: var(--muted); letter-spacing: 0.02em; }
.entry h3 { font: 600 26px/1.18 var(--serif); letter-spacing: -0.01em; margin: 10px 0 10px; color: var(--ink); transition: color .2s; }
.entry p { margin: 0 0 10px; color: var(--ink-2); font-size: 17.5px; line-height: 1.55; max-width: 40em; }
.entry .authors { font-size: 15px; color: var(--muted); }
.entry a:hover h3 { color: var(--accent); }
.entry a:hover .thumb { border-color: var(--rule); transform: translateY(-2px); }

/* ------------------------------------------------------------------- post ---- */

.post { width: 100%; padding: 0 var(--gutter); }
.post-head, .post .toc, .post .body, .endmatter { max-width: var(--text); margin-left: auto; margin-right: auto; }

.post-head { margin-top: 64px; margin-bottom: 40px; }
@media (min-width: 1100px) { .post-head h1, .post-head .dek { margin-right: -150px; } }
.post-head .kicker { display: flex; gap: 14px; font: 500 13px/1 var(--mono); color: var(--accent); letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 22px; }
.post-head h1 { font: 500 clamp(36px, 5.4vw, 56px)/1.06 var(--serif); letter-spacing: -0.022em; margin: 0; max-width: 18em; text-wrap: balance; }
.post-head .dek { font: 400 22px/1.45 var(--sans); color: var(--ink-2); margin: 20px 0 0; max-width: 36em; text-wrap: pretty; }
.byline {
  display: flex; flex-wrap: wrap; gap: 14px 56px;
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule);
  font-size: 16px; line-height: 1.5;
}
.byline h6 { font: 600 11.5px/1 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.byline .names { display: flex; flex-direction: column; }
.byline .author a { color: var(--ink); text-decoration: none; }
.byline .author a:hover { color: var(--accent); }
.byline sup { font-size: 0.7em; color: var(--muted); margin-left: 1px; }
.byline .updated { display: block; color: var(--muted); font-size: 14px; }

/* Table of contents: a block under the byline, or a quiet margin column on wide screens. */
.toc { margin-bottom: 48px; font-size: 15.5px; line-height: 1.45; }
.toc:empty { display: none; }
.toc h6 { font: 600 11.5px/1 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc li.h3 { padding-left: 14px; font-size: 14.5px; }
.toc a { display: block; padding: 3px 0 3px 12px; border-left: 1px solid var(--rule); color: var(--muted); text-decoration: none; transition: color .2s, border-color .2s; }
.toc a:hover { color: var(--ink); }
.toc a.active { color: var(--ink); border-left-color: var(--accent); }

@media (min-width: 1400px) {
  .post .toc {
    position: fixed; top: 96px; width: 200px; margin: 0;
    left: max(16px, calc(50vw - var(--text) / 2 - 150px - 230px));
    max-height: calc(100vh - 140px); overflow: auto;
    opacity: 0; pointer-events: none; transform: translateX(-6px);
    transition: opacity .4s, transform .4s;
  }
  .post .toc.show { opacity: 1; pointer-events: auto; transform: none; }
}

/* ------------------------------------------------------------- article body ---- */

.body { counter-reset: fig; }
.body > * { margin-top: 0; margin-bottom: 0; }
.body > * + * { margin-top: 1.05em; }
.body p { text-wrap: pretty; hyphens: auto; }
.body .lede { font-size: 21.5px; line-height: 1.55; color: var(--ink); }
.body h2 {
  font: 600 29px/1.2 var(--serif); letter-spacing: -0.012em;
  margin-top: 2.3em; margin-bottom: 0.1em; scroll-margin-top: 32px;
}
.body h3 { font: 600 21.5px/1.3 var(--serif); margin-top: 1.9em; scroll-margin-top: 32px; }
.body h4 { font: 600 17px/1.4 var(--sans); margin-top: 1.6em; }
.body h2 + *, .body h3 + *, .body h4 + * { margin-top: 0.6em; }
.body .anchor { margin-left: 0.35em; color: var(--rule); text-decoration: none; font-weight: 400; opacity: 0; transition: opacity .2s; }
.body :is(h2, h3):hover .anchor { opacity: 1; }
.body ul, .body ol { padding-left: 1.3em; }
.body li + li { margin-top: 0.35em; }
.body li::marker { color: var(--muted); }
.body strong { font-weight: 650; }
.body hr { border: 0; height: 1px; background: var(--rule); margin: 2.6em 0; }

.body blockquote { margin-left: 0; padding-left: 20px; border-left: 2px solid var(--rule); color: var(--ink-2); font-style: italic; }

.body code { font: 0.84em/1 var(--mono); background: rgba(43, 103, 192, 0.07); padding: 0.12em 0.32em; border-radius: 3px; }
.body pre {
  font: 13.5px/1.6 var(--mono); background: var(--sheet); border: 1px solid var(--rule-soft); border-radius: 4px;
  padding: 16px 18px; overflow-x: auto; tab-size: 2;
}
.body pre code { background: none; padding: 0; font-size: inherit; line-height: inherit; }

.body table { border-collapse: collapse; width: 100%; font-size: 16px; font-variant-numeric: tabular-nums; }
.body th { font-weight: 600; text-align: left; border-bottom: 1px solid var(--ink-2); padding: 6px 12px 6px 0; }
.body td { border-bottom: 1px solid var(--rule-soft); padding: 7px 12px 7px 0; }
.body .table-wrap { overflow-x: auto; }

.body .math-display, .body .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.body .katex { font-size: 1.05em; }

/* Break out of the column. */
.body .wide { width: min(var(--wide), 100vw - 2 * var(--gutter)); margin-left: calc(50% - min(var(--wide), 100vw - 2 * var(--gutter)) / 2); }
.body .full { width: min(var(--full), 100vw - 2 * var(--gutter)); margin-left: calc(50% - min(var(--full), 100vw - 2 * var(--gutter)) / 2); }

/* Figures */
.body figure { margin: 2.2em 0 2.2em; }
.body figure > .frame, .body figure:not(.bare) > svg, .body figure:not(.bare) > img, .body figure:not(.bare) > .widget {
  display: block; width: 100%; height: auto;
  background: var(--sheet); border: 1px solid var(--rule-soft); border-radius: 6px; padding: 22px;
}
.body figure.bare > svg, .body figure.bare > img { display: block; width: 100%; height: auto; }
.body figure.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.body figure.row > figcaption { grid-column: 1 / -1; }
.body figcaption { font-size: 15.5px; line-height: 1.5; color: var(--muted); margin-top: 12px; max-width: var(--text); text-wrap: pretty; }
.body figure.wide figcaption, .body figure.full figcaption { margin-left: calc((100% - min(100%, var(--text))) / 2); }
.body figcaption .fig-label { color: var(--ink); font-weight: 600; margin-right: 0.3em; }
.body a.xref-fig { white-space: nowrap; }

/* Figure text inherits the site typography, so SVG authors only set sizes. */
.body svg text { font-family: var(--sans); fill: var(--ink-2); }
.body svg .mono, .body svg text.mono { font-family: var(--mono); }
.body svg .serif, .body svg text.serif { font-family: var(--serif); }

/* Callouts and margin notes */
.body .callout {
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  padding: 16px 22px; border-radius: 0 4px 4px 0;
}
.body .callout > :first-child { margin-top: 0; }
.body .callout > * + * { margin-top: 0.7em; }
.body .callout .callout-title { font: 600 12px/1 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.body .callout ul { margin: 0.5em 0 0; }

.body aside, .body .marginnote { font-size: 15px; line-height: 1.5; color: var(--muted); }
@media (min-width: 1240px) {
  .body aside, .body .marginnote {
    float: right; clear: right; width: 220px; margin: 0.3em -260px 1em 0 !important;
    padding-left: 12px; border-left: 1px solid var(--rule);
  }
}
@media (max-width: 1239px) {
  .body aside, .body .marginnote { padding: 10px 14px; border-left: 2px solid var(--rule); }
}

/* Footnotes and citations, filled in by site.js */
d-footnote { display: none; }
.fn-ref, .cite-ref { position: relative; }
.fn-ref a, .cite-ref a { text-decoration: none; }
.fn-ref { font-size: 0.72em; vertical-align: super; line-height: 0; margin-left: 1px; font-feature-settings: "lnum"; }
.fn-ref a { color: var(--accent); font-weight: 600; padding: 0 1px; }
.cite-ref { white-space: nowrap; font-size: 0.86em; color: var(--accent); }
.cite-ref a { color: var(--accent); }
.hovercard {
  position: absolute; z-index: 40; width: min(360px, 90vw);
  background: #fff; color: var(--ink-2); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 10px 30px -12px rgba(21, 35, 59, 0.28);
  padding: 12px 15px; font: 400 15px/1.5 var(--sans);
  opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; pointer-events: none;
}
.hovercard.on { opacity: 1; transform: none; pointer-events: auto; }
.hovercard .ref-title { color: var(--ink); font-weight: 600; }

.endmatter { margin-top: 88px; padding-top: 6px; border-top: 1px solid var(--rule); font-size: 15.5px; line-height: 1.55; color: var(--ink-2); }
.endmatter h3 { font: 600 12px/1 var(--sans); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 32px 0 14px; }
.endmatter ol { padding-left: 1.6em; margin: 0; }
.endmatter li { margin-bottom: 0.55em; }
.endmatter li:target { background: var(--accent-soft); }
.endmatter .back { text-decoration: none; margin-left: 4px; }
.endmatter .ref-title { color: var(--ink); }
.cite-block pre { font: 12.5px/1.55 var(--mono); background: var(--sheet); border: 1px solid var(--rule-soft); border-radius: 4px; padding: 12px 14px; overflow-x: auto; }

/* ------------------------------------------------------------ interactives ---- */

.widget { font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.widget .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; margin-bottom: 14px; font-size: 14.5px; }
.widget label { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); }
.widget output, .widget .value { font: 500 13.5px/1 var(--mono); color: var(--ink); min-width: 3.5em; display: inline-block; }
.widget input[type=range] { accent-color: var(--accent); width: 160px; }
.widget button, .widget select {
  font: 500 14px/1 var(--sans); color: var(--ink); background: #fff;
  border: 1px solid var(--rule); border-radius: 4px; padding: 7px 12px; cursor: pointer;
}
.widget button:hover { border-color: var(--accent); color: var(--accent); }
.widget button[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.widget svg { display: block; width: 100%; height: auto; overflow: visible; }
.kit-tip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: #fff;
  font: 500 12.5px/1.35 var(--mono); padding: 5px 8px; border-radius: 3px; opacity: 0; transition: opacity .1s; white-space: nowrap;
}

/* Gentle entrance for figures as they scroll in. */
.js .body figure.reveal { opacity: 0; transform: translateY(10px); transition: opacity .7s ease, transform .7s cubic-bezier(.2,.7,.2,1); }
.js .body figure.reveal.in { opacity: 1; transform: none; }

/* ------------------------------------------------------------------ preview ---- */

.preview-ribbon {
  position: fixed; left: 14px; bottom: 14px; z-index: 70; display: flex; gap: 10px; align-items: center;
  font: 600 12px/1 var(--sans); letter-spacing: 0.04em; text-transform: uppercase;
  background: var(--ink); color: #fff; padding: 9px 12px; border-radius: 999px;
  box-shadow: 0 6px 18px -8px rgba(21,35,59,.5);
}
.preview-ribbon a { color: #9CC0F0; text-decoration: none; }

/* ----------------------------------------------------------------- narrow ---- */

@media (max-width: 760px) {
  :root { --gutter: 18px; }
  body { font-size: 17.5px; }
  .index-head { margin: 40px 0 56px; }
  .index .empty { margin-left: 0; }
  .year { grid-template-columns: 1fr; }
  .year-label { margin-bottom: 8px; }
  .entry a { grid-template-columns: 1fr; gap: 16px; }
  .entry .thumb { max-width: 420px; }
  .post-head { margin-top: 36px; }
  .post-head .dek { font-size: 19px; }
  .body .lede { font-size: 19.5px; }
  .body h2 { font-size: 25px; }
  .body figure:not(.bare) > svg, .body figure:not(.bare) > img, .body figure:not(.bare) > .widget, .body figure > .frame { padding: 12px; }
  .byline { gap: 14px 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .js .body figure.reveal { opacity: 1; transform: none; }
}

@media print {
  .field, .progress, .masthead nav, .toc, .preview-ribbon, .sitefoot { display: none !important; }
  html { background: #fff; }
}
