/* agent-from-zero: Tietou's world. White paper, ink line, grey wash, one red. Light only. */
:root {
  --paper: #ffffff;
  --ink: #1a1a1a;
  --grey: #6f6f6f;
  --pencil: #b4b4b0;
  --wash: #ececea;
  --red: #ce382e;
  --red-wash: #f8dedb;
  --hand: "LXGW WenKai", "Kaiti SC", "STKaiti", "KaiTi", serif;
  --body: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", system-ui, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  /* Unequal elliptical radii make a box read as drawn by hand, like the cells in the diagrams. */
  --wobble: 255px 14px 225px 14px / 14px 225px 14px 255px;
  --wobble-2: 18px 240px 16px 210px / 230px 14px 250px 16px;
  --wobble-small: 4px 9px 5px 8px / 8px 4px 9px 5px;
  --gutter: clamp(16px, 4vw, 56px);
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); scrollbar-color: var(--pencil) var(--paper); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); font-family: var(--body); font-size: 17px; line-height: 1.85; -webkit-font-smoothing: antialiased; }
::selection { background: var(--red-wash); color: var(--ink); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; border-radius: 4px; }
a { color: inherit; text-decoration-thickness: 1.5px; text-underline-offset: 5px; text-decoration-color: var(--pencil); }
a:hover { text-decoration-color: var(--red); }
h1, h2, h3, h4, .hand { font-family: var(--hand); font-weight: 700; text-wrap: balance; }
img { max-width: 100%; height: auto; }
/* Pose cut-outs have a white ground; multiply lets them stand on tinted paper. */
.cutout { mix-blend-mode: multiply; }

.skip { position: absolute; left: var(--gutter); top: -60px; padding: 6px 14px; background: var(--ink); color: var(--paper); border-radius: var(--wobble-small); }
.skip:focus { top: 10px; }

/* Top bar: the name, where this chapter sits, and the mini map. */
.bar { display: flex; align-items: center; gap: 12px 28px; flex-wrap: wrap; padding: 18px var(--gutter); border-bottom: 1.5px solid var(--ink); }
.bar .name { font-family: var(--mono); font-weight: 600; font-size: 15px; margin-right: auto; text-decoration: none; }
.here { margin: 0; font-family: var(--hand); font-size: 16px; line-height: 1.5; color: var(--grey); text-align: right; }
.here b { color: var(--red); font-weight: 700; }

/* The mini map is also the way back to the whole map on the homepage. */
.minimap { display: block; text-decoration: none; }
.minimap:hover > ol { background: var(--wash); }
.minimap ol { list-style: none; margin: 0; padding: 0; }
.minimap > ol { border: 1.5px solid var(--ink); border-radius: var(--wobble-2); padding: 3px 10px; }
.minimap .row { display: grid; grid-template-columns: 5.6em auto; align-items: center; padding: 3px 0; }
.minimap .row + .row { border-top: 1px solid var(--wash); }
.minimap .layer { font-family: var(--hand); font-size: 12px; line-height: 1.2; color: var(--grey); }
.minimap .cells { display: flex; gap: 4px; }
/* Names stay in the markup for screen readers and the tooltip; the cell itself is a swatch. */
.minimap .cell { width: 19px; height: 11px; overflow: hidden; white-space: nowrap; text-indent: 100%; font-size: 1px;
  border: 1px solid var(--ink); border-radius: var(--wobble-small); background: var(--wash); }
.minimap .cell.now { background: var(--red); border-color: var(--red); }
.minimap .cell.todo { background: transparent; border: 1px dashed var(--pencil); }
.minimap .cell.told { background: transparent; border: 1px dotted var(--pencil); }

/* Three columns: every chapter, the text, this chapter's sections. */
.page { display: grid; grid-template-columns: 15rem minmax(0, 72ch) 13.5rem; gap: 56px; justify-content: center; padding: 0 var(--gutter); }
.chapters-menu, .toc { position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto; scrollbar-width: thin; padding: 40px 0 32px; }

.chapters-menu summary { list-style: none; font-family: var(--hand); font-size: 15px; color: var(--grey); margin-bottom: 10px; cursor: pointer; }
.chapters-menu summary::-webkit-details-marker { display: none; }
.chapters-nav ol { list-style: none; margin: 0; padding: 0; }
.chapters-nav li { border-top: 1px solid var(--wash); }
.chapters-nav li:first-child { border-top: 1.5px solid var(--ink); }
.chapters-nav a, .chapters-nav .todo { display: block; padding: 8px 10px; line-height: 1.45; font-family: var(--hand); font-size: 17px; text-decoration: none; }
.chapters-nav .no { display: block; font-size: 13px; font-weight: 400; color: var(--grey); }
.chapters-nav a:hover { color: var(--red); }
.chapters-nav a[aria-current="page"] { background: var(--wash); border-radius: var(--wobble-small); font-weight: 700; }
.chapters-nav .todo { padding-top: 5px; padding-bottom: 5px; font-size: 15px; color: var(--grey); }
.chapters-nav .todo .no { color: var(--grey); }
.chapters-nav .todo + .todo, .chapters-nav li:not(.todo) + .todo { border-top: 1px dashed var(--pencil); }

.toc-title { margin: 0 0 10px; font-family: var(--hand); font-size: 15px; color: var(--grey); }
.sections ol { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 1.5px solid var(--ink); }
.sections li { font-size: 13.5px; line-height: 1.45; padding: 4px 0; }
.sections .level-3 { padding-left: 1em; }
.sections .level-3 a { color: var(--grey); }
.sections a { text-decoration: none; }
.sections a:hover { color: var(--ink); text-decoration: underline; text-decoration-color: var(--red); }

/* The text column. */
.text { min-width: 0; padding: 48px 0 24px; }
.lost { max-width: 72ch; margin: 0 auto; padding-left: var(--gutter); padding-right: var(--gutter); }
.chapter-head { margin-bottom: 40px; }
.chapter-head .label { margin: 0; font-family: var(--hand); font-size: 20px; color: var(--grey); }
.chapter-head h1 { margin: 0; font-size: clamp(32px, 4.2vw, 50px); line-height: 1.2; }
.text h2 { font-size: 30px; line-height: 1.3; margin: 2.4em 0 0.6em; }
.text h2::before { content: ""; display: block; width: 44px; height: 3px; margin-bottom: 18px; background: var(--ink); border-radius: var(--wobble-small); }
.text h3 { font-size: 22px; line-height: 1.4; margin: 2em 0 0.4em; }
.text h2, .text h3 { scroll-margin-top: 24px; }
.text p, .text ul, .text ol { margin: 0 0 1.1em; }
.text ul, .text ol { padding-left: 1.4em; }
.text li + li { margin-top: 0.3em; }
.text strong { font-weight: 600; }
.text p > img { display: block; margin: 2em auto; }
/* Generated pictures are 254-white; lift them to the page's white. Diagrams are SVG and already white. */
.text img[src$=".png"] { filter: brightness(1.02); }

.text code { font-family: var(--mono); font-size: 0.84em; font-variant-ligatures: none; }
.text :not(pre) > code { background: var(--wash); padding: 0.12em 0.36em; border-radius: var(--wobble-small); overflow-wrap: anywhere; }
.text pre { margin: 1.4em 0 1.6em; padding: 16px 20px; overflow-x: auto; scrollbar-width: thin; font-size: 14.5px; line-height: 1.65;
  border-radius: 14px 225px 14px 255px / 255px 14px 225px 14px; }
.text pre code { font-size: inherit; }
.text pre { tab-size: 4; }
/* Terminal output and file lists sit on the wash; code to type sits on paper inside an ink line. */
.text pre:not(.chroma) { background: var(--wash); }
.text pre.chroma { background: var(--paper); border: 1.5px solid var(--ink); }

/* Code colours: ink, grey and red only. Comments grey, removed lines red, added lines on the wash. */
.chroma { color: var(--ink); }
.chroma > code { display: inline-block; min-width: 100%; }
.chroma .line { display: block; margin: 0 -20px; padding: 0 20px; }
.chroma .k, .chroma .kd, .chroma .kn, .chroma .kr { font-weight: 700; }
.chroma .c, .chroma .c1, .chroma .cm, .chroma .ch, .chroma .cs, .chroma .cp, .chroma .cpf { color: var(--grey); }
.chroma .gd { color: var(--red); }
.chroma .gu, .chroma .gh { color: var(--grey); }
.chroma .line:has(.gi:not(:empty)) { background: var(--wash); }

.text table { display: block; max-width: 100%; overflow-x: auto; scrollbar-width: thin; border-collapse: collapse; margin: 1.4em 0 1.8em; font-size: 15.5px; line-height: 1.6; }
.text th { font-family: var(--hand); font-size: 16.5px; text-align: left; border-bottom: 1.5px solid var(--ink); }
.text th, .text td { padding: 8px 14px; vertical-align: top; }
.text th:first-child, .text td:first-child { padding-left: 0; }
.text td { border-bottom: 1px solid var(--wash); }
/* Identifiers in a table keep whole; the table scrolls in its own box instead. */
.text td code, .text th code { white-space: nowrap; overflow-wrap: normal; }

/* Previous and next chapter; Tietou points the way on. */
/* Prev on the left, next on the right, Tietou between them pointing at the next one. */
.pager { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: end; gap: 16px 20px; margin-top: 72px; padding-top: 32px; border-top: 1.5px solid var(--ink); }
.pager .prev { grid-column: 1; justify-self: start; }
.pager .guide { grid-column: 2; }
.pager .next { grid-column: 3; justify-self: end; }
.pager a, .pager .todo { display: flex; flex-direction: column; padding: 12px 22px 14px; border: 2px solid var(--ink); text-decoration: none; max-width: 100%; }
.pager .prev { border-radius: var(--wobble-2); }
.pager .next { border-radius: var(--wobble); }
.pager .dir { font-family: var(--hand); font-size: 15px; color: var(--grey); }
.pager .what { font-family: var(--hand); font-size: 20px; font-weight: 700; line-height: 1.35; }
.pager .prev .dir::before { content: "← "; }
.pager a.next .dir::after { content: " →"; }
.pager a:hover { background: var(--wash); }
.pager a:hover .what { color: var(--red); }
.pager .guide { width: auto; height: 76px; }
.pager .todo { border: 2px dashed var(--pencil); color: var(--grey); }
.pager .todo .what { font-weight: 400; }

.foot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px 28px; margin-top: 40px; padding: 40px var(--gutter); border-top: 1.5px solid var(--ink); color: var(--grey); font-size: 14.5px; }
.foot .hand { color: var(--ink); font-size: 17px; margin-right: auto; }
.foot a:hover { color: var(--ink); }

@media (max-width: 1180px) {
  .page { grid-template-columns: 14rem minmax(0, 72ch); gap: 44px; }
  .toc { display: none; }
}

@media (max-width: 900px) {
  body { font-size: 16.5px; }
  .bar { padding-top: 14px; padding-bottom: 14px; }
  .bar .name { flex-basis: 100%; }
  .here { text-align: left; flex: 1 1 12em; }
  .page { display: block; }
  .chapters-menu { position: static; max-height: none; overflow: visible; padding: 16px 0 0; }
  .chapters-menu summary { display: inline-block; cursor: pointer; padding: 4px 16px 5px; border: 1.5px solid var(--ink); border-radius: var(--wobble); color: var(--ink); font-size: 16px; }
  .chapters-menu summary::after { content: " ▾"; color: var(--grey); }
  .chapters-menu[open] summary::after { content: " ▴"; }
  .text { padding-top: 32px; }
  .text h2 { font-size: 26px; }
  .text h3 { font-size: 20px; }
  .text pre { padding: 14px 16px; font-size: 13.5px; }
  .chroma .line { margin: 0 -16px; padding: 0 16px; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager .prev, .pager .guide, .pager .next { grid-column: 1; }
  .pager .prev, .pager .next { justify-self: stretch; }
  .pager .guide { justify-self: end; height: 64px; margin: 8px 12px -12px 0; }
}

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

/* Search: a box in the top bar, and a hand-drawn list of hits under it. */
.search { position: relative; flex: 0 1 17rem; min-width: 11rem; }
/* With scripts on, the box keeps its place while hidden, so un-hiding it moves nothing (on a phone it is a row of its own). */
.js .search[hidden] { display: block; visibility: hidden; }
.search input { width: 100%; font: inherit; font-size: 15px; line-height: 1.4; padding: 6px 14px 7px; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: var(--wobble); appearance: none; }
.search input::placeholder { color: var(--grey); }
.search input::-webkit-search-cancel-button { appearance: none; }
.results { position: absolute; z-index: 10; top: calc(100% + 8px); left: 0; width: min(34rem, calc(100vw - 2 * var(--gutter))); max-height: 70vh; overflow-y: auto;
  padding: 4px 0; background: var(--paper); border: 2px solid var(--ink); border-radius: var(--wobble-2); }
.results[hidden] { display: none; }
.results .hits { list-style: none; margin: 0; padding: 0; }
.results li + li { border-top: 1px solid var(--wash); }
.results .status:empty { display: none; }
.results a { display: block; padding: 9px 18px; text-decoration: none; line-height: 1.55; font-size: 14.5px; }
.results a:hover, .results a:focus-visible { background: var(--wash); outline-offset: -3px; }
.results .where { display: block; font-family: var(--hand); font-size: 16px; font-weight: 700; }
.results .snippet { display: block; color: var(--grey); overflow-wrap: anywhere; }
.results mark { background: transparent; color: var(--red); font-weight: 700; }
.results .status { margin: 0; padding: 12px 18px; color: var(--grey); font-family: var(--hand); }

@media (max-width: 900px) {
  .search { flex: 1 1 100%; order: 1; }
  .here { order: 2; }
  .minimap { order: 3; }
}
