/* Research log — white watercolour paper, set in Manrope.
   The page is a sheet of cold-pressed paper: white, with a faint tooth
   drawn by an SVG light filter. On a desktop the column takes two
   thirds of the window: a narrow rail on the left for dates and
   section numbers, the text to its right. One ink colour
   (ultramarine); the only other watercolour touch is a dry brushstroke
   as a rule.
   Targets ox-html 9.7 with html5-fancy on.                            */

/* ---------- Fonts (self-hosted, latin subsets, variable) ---------- */

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/Manrope.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/IBMPlexMono-Medium.woff2") format("woff2");
}

/* ---------- Tokens ---------- */

:root {
  color-scheme: light;

  --paper:  #ffffff;
  --ink:    #1b1f27;
  --ink-2:  #636975;
  --ink-3:  #a2a7b0;
  --rule:   #ebebe8;
  --tint:   #f6f6f3;   /* code and tables */

  --accent: #2c4f93;   /* ultramarine */

  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --column:  100%;     /* share of the window the page takes */
  --rail:    0rem;     /* left rail for dates and numbers */
  --measure: 44rem;    /* longest line of running text */
  --gutter:  1.25rem;
  --radius:  0.375rem;

  /* Paper tooth: fractal noise lit from the upper left, kept close to white. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='320'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.075' numOctaves='4' seed='4' stitchTiles='stitch'/%3E%3CfeDiffuseLighting surfaceScale='1.3' lighting-color='%23fff'%3E%3CfeDistantLight azimuth='225' elevation='52'/%3E%3C/feDiffuseLighting%3E%3CfeComponentTransfer%3E%3CfeFuncR type='linear' slope='.07' intercept='.945'/%3E%3CfeFuncG type='linear' slope='.07' intercept='.945'/%3E%3CfeFuncB type='linear' slope='.07' intercept='.945'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='320' height='320' filter='url(%23g)'/%3E%3C/svg%3E");


  /* A dry brushstroke: a ragged band, broken up where the brush skipped. */
  --stroke: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 24' preserveAspectRatio='none'%3E%3Cfilter id='d' x='-5%25' y='-80%25' width='110%25' height='260%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.02 .3' numOctaves='3' seed='8' result='n'/%3E%3CfeDisplacementMap in='SourceGraphic' in2='n' scale='9' xChannelSelector='R' yChannelSelector='G' result='b'/%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.03 .9' numOctaves='2' seed='2' result='h'/%3E%3CfeColorMatrix in='h' type='matrix' values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 -3 2.3'/%3E%3CfeComposite in='b' operator='in'/%3E%3C/filter%3E%3Cpath d='M6 13 C 90 9, 200 15, 394 10 L 392 15 C 220 19, 100 14, 8 17 Z' fill='%23fff' filter='url(%23d)'/%3E%3C/svg%3E");
}

@media (min-width: 64rem) {
  :root { --column: 66.667vw; --rail: calc(var(--column) * 0.22); --gutter: 0rem; }
}

/* ---------- Page ---------- */

html {
  background: var(--grain), var(--paper);
  background-blend-mode: multiply, normal;
  -webkit-text-size-adjust: 100%;
}

body {
  width: var(--column);
  max-width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 var(--gutter);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  font-weight: 440;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: proportional-nums;
}

/* Everything but the nav sits right of the rail. */
#content, #postamble, .dateline { margin-left: var(--rail); }
#content { flex: 1; position: relative; }
#content > * { max-width: var(--measure); }
#content > section > *, #content section section > * { max-width: var(--measure); }

a {
  color: inherit;
  text-decoration: underline 1px var(--ink-3);
  text-underline-offset: 0.22em;
  transition: color 0.15s, text-decoration-color 0.15s;
}
a:hover { color: var(--accent); text-decoration-color: var(--accent); }

p { margin: 0 0 1.2rem; }
strong, b { font-weight: 700; }
sup, sub { line-height: 0; font-size: 0.72em; }
::selection { background: color-mix(in srgb, var(--accent) 18%, transparent); }

hr {                           /* a dry brushstroke */
  border: 0;
  height: 0.55rem;
  width: 7rem;
  margin: 3rem 0;
  background: var(--accent);
  opacity: 0.55;
  -webkit-mask: var(--stroke) center / 100% 100% no-repeat;
          mask: var(--stroke) center / 100% 100% no-repeat;
}

/* ---------- Nav ---------- */

.site-nav {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 2.5rem 0 0;
  font-size: 0.9375rem;
  color: var(--ink-2);
}
.site-nav a { text-decoration: none; }
.site-name {
  font-weight: 750;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.site-links a { margin-left: 1.5rem; }

/* ---------- Title block ---------- */

#content { margin-top: 5.5rem; }
.dateline { margin-top: 5.5rem; margin-bottom: 0.9rem; }
.dateline time, ul.entries time {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
#preamble:has(.dateline) + #content { margin-top: 0; }

h1.title {
  margin: 0 0 3rem;
  font-size: clamp(2.1rem, 3.4vw, 3.25rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-wrap: balance;
}
.subtitle {
  display: block;
  margin-top: 0.75rem;
  font-size: 1.15rem;
  font-weight: 450;
  letter-spacing: -0.005em;
  color: var(--ink-2);
}

/* ---------- Home ---------- */

.lede {
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.5;
  letter-spacing: -0.012em;
  margin-bottom: 4rem;
  text-wrap: pretty;
}

ul.entries { list-style: none; margin: 0; padding: 0; position: relative; }
#content > ul.entries { max-width: none; }
ul.entries li {
  display: grid;
  grid-template-columns: 1fr;
  margin: 0;
  padding: 1.25rem 0;
  border-top: 1px solid var(--rule);
}
ul.entries li:last-child { border-bottom: 1px solid var(--rule); }
ul.entries > li::before { content: none; }
ul.entries time { line-height: 1.9rem; }
ul.entries a {
  font-size: 1.25rem;
  font-weight: 650;
  line-height: 1.35;
  letter-spacing: -0.015em;
  text-decoration: none;
}
ul.entries .entry-desc {
  margin-top: 0.25rem;
  font-size: 0.9688rem;
  color: var(--ink-2);
}

/* ---------- Headings ---------- */

h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
h2 { font-size: 1.5rem; margin: 3.5rem 0 1rem; letter-spacing: -0.022em; }
h3 { font-size: 1.1875rem; margin: 2.25rem 0 0.7rem; }
h4 { font-size: 1rem; font-weight: 650; color: var(--ink-2); margin: 1.75rem 0 0.5rem; }
h5, h6 { font-size: 1rem; margin: 1.5rem 0 0.5rem; }
#content > header + section > h2 { margin-top: 0; }

/* Section numbers sit in the rail. */
#content { counter-reset: sec; }
#content > section > h2 { counter-increment: sec; position: relative; }
#content > section > h2::before {
  content: counter(sec, decimal-leading-zero);
  margin-right: 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  vertical-align: 0.2em;
  font-variant-numeric: tabular-nums;
}

/* ---------- Table of contents ---------- */

#table-of-contents { margin: 0 0 3rem; font-size: 0.9375rem; }
#table-of-contents h2 { margin: 0 0 0.5rem; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); }
#table-of-contents h2::before { content: none; }
#text-table-of-contents ul { list-style: none; margin: 0; padding: 0; }
#text-table-of-contents ul ul { padding-left: 1rem; }
#text-table-of-contents li { margin: 0.2rem 0; }
#text-table-of-contents a { text-decoration: none; }

/* ---------- Lists ---------- */

ul, ol { margin: 0 0 1.2rem; padding-left: 1.3rem; }
li { margin-bottom: 0.35rem; }
li > p { margin-bottom: 0.5rem; }
li > ul, li > ol { margin-top: 0.35rem; margin-bottom: 0; }
li::marker { color: var(--ink-3); }
ol > li::marker { font-weight: 600; font-variant-numeric: tabular-nums; }
dt { font-weight: 700; }
dd { margin: 0.2rem 0 0.8rem 1.3rem; }

/* ---------- Figures, tables and code ---------- */

figure { margin: 2.75rem 0; }
figure img { display: block; max-width: 100%; height: auto; }
figcaption, caption {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--ink-2);
  text-align: left;
}
.figure-number, .table-number { font-weight: 650; color: var(--ink); }

table {
  width: 100%;
  margin: 2.25rem 0;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
caption { caption-side: top; margin: 0 0 0.6rem; }
thead th { border-bottom: 1.5px solid var(--ink); }
th { font-weight: 700; }
th, td { padding: 0.55rem 0.9rem 0.55rem 0; vertical-align: top; }
td { border-bottom: 1px solid var(--rule); }
tbody tr:last-child td { border-bottom: 0; }
.org-left { text-align: left; } .org-right { text-align: right; } .org-center { text-align: center; }

code, kbd, samp, pre { font-family: var(--mono); }
code {
  font-size: 0.86em;
  padding: 0.1em 0.3em;
  border-radius: 0.25em;
  background: var(--tint);
}
pre code { padding: 0; background: none; }
pre {
  margin: 0;
  padding: 1.15rem 1.4rem;
  border-radius: var(--radius);
  background: var(--tint);
  font-size: 0.8125rem;
  line-height: 1.7;
  overflow-x: auto;
  tab-size: 4;
}
.org-src-container, pre.example { margin: 1.75rem 0; }
label.org-src-name { display: block; margin-bottom: 0.4rem; font-size: 0.8125rem; font-weight: 600; color: var(--ink-2); }
.org-keyword, .org-builtin { color: var(--accent); font-weight: 500; }
.org-function-name { color: #8a4a2b; font-weight: 500; }
.org-string, .org-doc { color: #4b6b3a; }
.org-comment, .org-comment-delimiter { color: var(--ink-3); font-style: italic; }
.org-variable-name, .org-type { color: var(--ink); font-weight: 500; }
.org-constant, .org-preprocessor { color: #8a4a2b; }
.org-warning, .org-negation-char { color: #a33a2a; font-weight: 600; }

/* ---------- Quotes ---------- */

blockquote {
  margin: 2.5rem 0;
  padding: 0.25rem 0 0.25rem 1.5rem;
  border-left: 2px solid var(--ink);
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.6;
  letter-spacing: -0.008em;
}
blockquote p:last-child { margin-bottom: 0; }
.verse { white-space: pre-line; }

mjx-container[display="true"] { margin: 1.5rem 0 !important; overflow-x: auto; overflow-y: hidden; }

/* ---------- Footnotes ---------- */

.footref { text-decoration: none; color: var(--accent); }
#footnotes {
  margin-top: 4.5rem;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--ink-2);
}
#footnotes::before {           /* the same brushstroke as hr */
  content: "";
  display: block;
  width: 5.5rem; height: 0.5rem;
  margin-bottom: 1.5rem;
  background: var(--accent);
  opacity: 0.55;
  -webkit-mask: var(--stroke) center / 100% 100% no-repeat;
          mask: var(--stroke) center / 100% 100% no-repeat;
}
#footnotes h2.footnotes { display: none; }
.footdef { display: flex; gap: 0.6rem; margin-bottom: 0.75rem; }
.footdef > sup { line-height: 1.6; font-size: 0.8125rem; flex: 0 0 1rem; }
.footdef .footpara { display: inline; margin: 0; }

/* ---------- Footer ---------- */

#postamble { margin-top: 6rem; padding: 1.5rem 0 2.5rem; border-top: 1px solid var(--rule); }
.colophon { margin: 0; font-size: 0.8125rem; color: var(--ink-3); }
.colophon a { text-decoration: none; color: var(--ink-2); }

/* ---------- Desktop: dates and numbers move into the rail ---------- */

@media (min-width: 64rem) {
  .dateline { margin-left: 0; margin-bottom: 0; width: var(--rail); height: 0; padding-top: 1rem; }
  #preamble:has(.dateline) + #content { margin-top: 0; }

  ul.entries li { margin-left: calc(-1 * var(--rail)); grid-template-columns: var(--rail) 1fr; }
  ul.entries .entry-desc { grid-column: 2; }

  #content > section > h2::before {
    position: absolute;
    right: 100%;
    width: var(--rail);
    margin: 0;
    line-height: 1.95rem;
    vertical-align: 0;
  }

  #postamble { margin-left: 0; }
}
