/* ~jisifu — a working notebook, not a magazine.
 *
 * The chrome is a terminal: monospace, uppercase labels, hairline rules,
 * numbered sections, metadata in a left rail. The reading text is a serif,
 * because prose is what the site is for. One accent, used on chrome and
 * links only; no cards, no shadows, no rounded corners, no webfonts.
 *
 * This sheet is shared by every page and cached once. It styles the elements
 * markdown produces, so a page needs no class to look finished.
 */

:root {
  color-scheme: light dark;
  --paper: #f6f4ef;
  --ink: #131210;
  --muted: #6b665c;
  --rule: #d5cfc2;
  --surface: #ebe7de;
  --accent: #bc3418;
  --accent-ink: #872310;
  --line: var(--rule);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua",
    Georgia, "Times New Roman", serif;
  --gutter: clamp(1rem, 4vw, 2.75rem);
  --measure: 64ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0b0b0a;
    --ink: #efebe2;
    --muted: #8d877b;
    --rule: #272320;
    --surface: #161412;
    --accent: #ff7451;
    --accent-ink: #ff9b7f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1.0625rem/1.62 var(--serif);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* ------------------------------------------------------------------ chrome */

.skip {
  position: absolute;
  left: -999px;
  top: 0;
  padding: .55rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font: .8rem/1.4 var(--mono);
}
.skip:focus { left: var(--gutter); top: .6rem; z-index: 60; }

.masthead {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: .6rem 2rem;
  padding: 1.5rem var(--gutter) 1rem;
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  position: relative;
  z-index: 1;
  display: block;
  font: 600 clamp(2.4rem, 8.5vw, 5.6rem)/1 var(--mono);
  padding-top: .06em;
  letter-spacing: -.055em;
  text-decoration: none;
  color: var(--ink);
}
.wordmark .tilde { color: var(--accent); }
.wordmark:hover .tilde { color: var(--accent-ink); }

.mast-meta {
  position: relative;
  z-index: 1;
  margin: 0 0 .35rem;
  max-width: 30ch;
  text-align: right;
  color: var(--muted);
  font: .72rem/1.8 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.mast-meta b { color: var(--ink); font-weight: 400; }

nav.site {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: .1rem 1.8rem;
  padding: .65rem var(--gutter);
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  font: .72rem/1.9 var(--mono);
  letter-spacing: .13em;
  text-transform: uppercase;
}
nav.site a {
  color: var(--muted);
  text-decoration: none;
  padding: .05rem 0;
  border-bottom: 2px solid transparent;
}
nav.site { counter-reset: section; }
nav.site a::before {
  counter-increment: section;
  content: counter(section, decimal-leading-zero);
  color: var(--accent);
  margin-right: .8ch;
  opacity: .85;
}
nav.site a:hover { color: var(--ink); }
nav.site a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

main {
  padding: 2.2rem var(--gutter) 4.5rem;
  max-width: calc(var(--measure) + var(--gutter) * 2);
}

footer.site {
  border-top: 1px solid var(--rule);
  padding: 1.1rem var(--gutter) 2.4rem;
  color: var(--muted);
  font: .72rem/1.9 var(--mono);
  letter-spacing: .05em;
}
footer.site p { margin: 0 0 .7rem; }
footer.site a { color: var(--muted); }
footer.site a:hover { color: var(--accent); }
footer.site code { background: none; padding: 0; font-size: 1em; color: var(--muted); }

.colophon { margin-top: 1.6rem; font-size: .7rem; }

/* --------------------------------------------------------------- typography */

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -.018em;
  text-wrap: balance;
}

h1 { margin: 0 0 1.1rem; font-size: clamp(2.1rem, 1.2rem + 3.6vw, 3.5rem); }

/* Section labels are chrome, not prose: a hairline, a number, small caps. */
h2 {
  margin: 3rem 0 1rem;
  padding-top: .6rem;
  border-top: 1px solid var(--rule);
  font: 400 .74rem/1.5 var(--mono);
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
h2 .num { color: var(--accent); margin-right: 1.2ch; }

h3 { margin: 2.2rem 0 .45rem; font-size: 1.22rem; }
h4 { margin: 1.6rem 0 .3rem; font-size: 1rem; }

h1 .anchor, h2 .anchor, h3 .anchor, h4 .anchor {
  margin-left: .6ch;
  color: var(--accent);
  text-decoration: none;
  opacity: 0;
  font: 400 .72em/1 var(--mono);
}
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor,
.anchor:focus-visible { opacity: 1; }

p { margin: 0 0 .95em; max-width: var(--measure); text-wrap: pretty; }
small { font-size: .86em; color: var(--muted); }

a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: .05em;
  text-underline-offset: .16em;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
}
a:hover {
  color: var(--accent-ink);
  text-decoration-color: currentColor;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}

a:focus-visible, summary:focus-visible, input:focus-visible,
select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
main:focus { outline: none; }

hr { margin: 2.6rem 0; border: 0; border-top: 1px solid var(--rule); }

/* ------------------------------------------------------------------- entry */

/* Metadata sits in a left column, aligned with the first line of the body:
 * the page reads like a filed entry, not a centred article. */
.entry { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 3rem; }
.entry > * { min-width: 0; }

.rail {
  display: flex;
  flex-wrap: wrap;
  gap: .15rem 1.4rem;
  margin: 0 0 1rem;
  color: var(--muted);
  font: .72rem/1.8 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.rail .kind { color: var(--accent); }
.rail time { font-variant-numeric: tabular-nums; }

@media (min-width: 60rem) {
  main { max-width: none; }
  .entry { grid-template-columns: 11rem minmax(0, var(--measure)); }
  .entry .rail {
    display: block;
    margin: 0;
    padding: .5rem 1.4rem 0 0;
    text-align: right;
    border-right: 1px solid var(--rule);
  }
  .entry .rail > * { display: block; margin-bottom: .55rem; }
  .entry > .head, .entry > .prose { grid-column: 2; }
}

/* ------------------------------------------------------------ the ledger */

ol.ledger {
  list-style: none;
  margin: 0 0 1.8rem;
  padding: 0;
  border-top: 1px solid var(--rule);
}
ol.ledger li {
  display: grid;
  grid-template-columns: 2.4rem 6.4rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 1.1rem;
  padding: .55rem 0;
  border-bottom: 1px solid var(--rule);
  font: .78rem/1.5 var(--mono);
  letter-spacing: .04em;
}
ol.ledger li:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
ol.ledger .n { color: var(--accent); font-variant-numeric: tabular-nums; }
ol.ledger time { color: var(--muted); font-variant-numeric: tabular-nums; }
ol.ledger .title { font: 400 1.08rem/1.35 var(--serif); letter-spacing: 0; }
ol.ledger a { text-decoration: none; }
ol.ledger a:hover { text-decoration: underline; background: none; }
ol.ledger .tag {
  color: var(--muted);
  text-transform: uppercase;
  font-size: .68rem;
  letter-spacing: .1em;
}

@media (max-width: 46rem) {
  ol.ledger li { grid-template-columns: 2rem minmax(0, 1fr); gap: .15rem .9rem; padding: .7rem 0; }
  ol.ledger time { grid-column: 2; }
  ol.ledger a.title { grid-column: 2; }
  ol.ledger .tag { display: none; }
}

/* --------------------------------------------------------------- the lab */

.lab { margin: 2.2rem 0; }
.lab canvas {
  display: block;
  width: 100%;
  max-width: 640px;
  height: auto;
  border: 1px solid var(--rule);
  background: var(--surface);
  image-rendering: pixelated;
}
.lab-controls {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  margin: .9rem 0 .55rem;
  max-width: none;
}
.lab-controls button {
  font: .72rem/1.4 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  cursor: pointer;
  padding: .45em .8em;
}
.lab-controls button:hover { color: var(--accent); border-color: var(--accent); }
.lab-timing {
  margin: 0;
  max-width: none;
  color: var(--muted);
  font: .72rem/1.8 var(--mono);
}

/* The filter demo: a radio per category, and a selector that hides the rest. */
.lab-pick {
  display: inline-flex;
  align-items: center;
  gap: .4ch;
  font: .72rem/1.4 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}
.lab-pick input { accent-color: var(--accent); cursor: pointer; }
.lab-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  max-width: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 0 1.1rem;
}
.lab-cards li {
  display: flex;
  justify-content: space-between;
  gap: .8rem;
  margin: 0;
  padding: .4rem 0;
  border-bottom: 1px solid var(--rule);
  font: .8rem/1.5 var(--mono);
}
.lab-cards li span { color: var(--muted); text-align: right; }
.lab-filter:has(input[value="lang"]:checked) li:not([data-kind="lang"]),
.lab-filter:has(input[value="tool"]:checked) li:not([data-kind="tool"]) {
  display: none;
}

/* ---------------------------------------------------------------- prose bits */

ul, ol { margin: 0 0 1.2em; padding-left: 1.25em; }
li { margin: .28em 0; }
li::marker { color: var(--accent); }
li > ul, li > ol { margin: .3em 0 .1em; }

.task-list-item { list-style: none; margin-left: -1.1em; }
.task-list-item input { margin-right: .5ch; }

.standfirst {
  max-width: 54ch;
  margin: 0 0 2.4rem;
  font-size: clamp(1.12rem, .98rem + .6vw, 1.36rem);
  line-height: 1.52;
  text-wrap: pretty;
}

/* Other addresses for the same text: a footer line, not a card. */
.protocols {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem 1.8rem;
  margin: 2.6rem 0 0;
  padding-top: .7rem;
  border-top: 1px solid var(--rule);
  font: .72rem/1.9 var(--mono);
  letter-spacing: .06em;
  color: var(--muted);
}
.protocols a, .protocols code {
  font: inherit;
  color: var(--muted);
  background: none;
  padding: 0;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 40%, transparent);
}
.protocols a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* Form controls, wherever they appear: a rule, not a widget kit. */
select, input:not([type="range"]):not([type="checkbox"]), button, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: .35em .55em;
}
input[type="range"] { accent-color: var(--accent); }

/* --------------------------------------------------------------------- code */

code {
  font: .86em/1.5 var(--mono);
  background: var(--surface);
  padding: .1em .35em;
}
pre {
  margin: 1.6rem 0;
  padding: .85rem 1rem;
  background: var(--surface);
  border-left: 2px solid var(--accent);
  overflow-x: auto;
  font: .82rem/1.55 var(--mono);
  tab-size: 2;
  scrollbar-width: thin;
}
pre code { background: none; padding: 0; font-size: 1em; }

blockquote {
  margin: 1.8rem 0;
  padding-left: 1.1rem;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-style: italic;
}
blockquote p { margin: 0 0 .5em; }
blockquote p:last-child { margin-bottom: 0; }

.table-wrap { margin: 1.5rem 0 2rem; overflow-x: auto; }

table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: .45em .9em .45em 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
  overflow-wrap: break-word;
}
th {
  font: 400 .68rem/1.6 var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom-color: var(--ink);
}

details { margin: 1rem 0; }
details > summary {
  cursor: pointer;
  padding: .3em 0;
  list-style: none;
  font-weight: 600;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: "[+]";
  margin-right: .9ch;
  color: var(--accent);
  font: 400 .8em/1 var(--mono);
}
details[open] > summary::before { content: "[-]"; }
details[open] > summary { margin-bottom: .4rem; }
details > summary:hover { color: var(--accent); }
details details > summary { font-weight: 500; }

img, svg, video, iframe { max-width: 100%; height: auto; border: 0; }
figure { margin: 1.8rem 0; }
figcaption { margin-top: .5rem; color: var(--muted); font: .72rem/1.6 var(--mono); }

section.footnotes {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: .88rem;
  color: var(--muted);
}
.footnote-ref, .footnote-backref { text-decoration: none; }

/* ------------------------------------------------------------- pager/states */

.pager {
  display: flex;
  gap: 1.6rem;
  justify-content: space-between;
  margin: 0 0 1.2rem;
  font: .72rem/1.8 var(--mono);
  letter-spacing: .06em;
}
.pager a { text-decoration: none; color: var(--muted); }
.pager a:hover { color: var(--accent); }
.pager a[rel="next"] { text-align: right; }

main[aria-busy="true"] { opacity: .45; transition: opacity .1s linear; }
body.loading { cursor: progress; }

::selection { background: color-mix(in srgb, var(--accent) 30%, transparent); }

@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .14s; }

  @supports (animation-timeline: view()) {
    ol.ledger li, .entry > .head, .entry > .prose {
      animation: settle linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 24%;
    }
    @keyframes settle {
      from { opacity: .45; transform: translateY(9px); }
      to { opacity: 1; transform: none; }
    }
  }
}

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

@media (max-width: 34rem) {
  body { font-size: 1rem; }
  main { padding-top: 1.9rem; }
  .mast-meta { display: none; }
}

@media print {
  :root {
    --paper: #fff; --ink: #000; --muted: #444; --rule: #bbb;
    --surface: #f3f3f3; --accent: #000; --accent-ink: #000;
  }
  body { font-size: 11pt; }
  nav.site, footer.site, .pager, .skip, .anchor, .mast-meta { display: none; }
  main { padding: 0; max-width: none; }
  a { text-decoration: none; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: .8em; color: #444; }
  pre, blockquote, table, figure, details { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
  details:not([open]) > *:not(summary) { display: block; }
  details > summary::before { content: ""; }
  .entry { display: block; }
  .rail { display: flex; text-align: left; border: 0; padding: 0; }
}
