/* The Tessera Book: a bar on top, the chapters on the left, one reading
   column. Terracotta and ink come from the logo. */
:root {
  --paper: #fbfaf7;
  --side: #f3f0ea;
  --ink: #1f2a37;
  --muted: #5d6673;
  --line: #e2ddd3;
  --accent: #a54a24;
  --accent-soft: #f6e7df;
  --code-bg: #f4f1eb;
  --code-fg: #1f2a37;
  --code-line: #e6e0d5;
  --inline-bg: #efebe3;
  --term-bg: #1f2a37;
  --term-fg: #e8ebef;
  --term-muted: #9aa5b3;
  --k: #a54a24;
  --s: #3d7a3a;
  --i: #8a5a00;
  --n: #7b3fa0;
  --t: #1d5f8c;
  --f: #283b8f;
  --c: #7d8590;
  --cap-fg: #8a4b00;
  --cap-bg: #fbe9c8;
  --err: #ff8f80;
  --warn: #ffd27a;
  --ok: #8fdcab;
  --loc: #8ec5ff;
  --logo-ink: #1f2a37;

  --f-body: Charter, "Bitstream Charter", "Iowan Old Style", "Sitka Text", Cambria, Georgia, serif;
  --f-ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14181e; --side: #191e25; --ink: #e4e7eb; --muted: #9ba3ae; --line: #2a313b;
    --accent: #e48a5e; --accent-soft: #33221a;
    --code-bg: #1b2028; --code-fg: #dfe3e8; --code-line: #2a313b; --inline-bg: #232a33;
    --term-bg: #0e1116;
    --k: #f0946b; --s: #a8d58c; --i: #ffd479; --n: #d7a6f2; --t: #7cc7e8; --f: #9db8ff; --c: #8590a0;
    --cap-fg: #ffd479; --cap-bg: rgba(255, 212, 121, .13);
    --logo-ink: #c9d1db;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #14181e; --side: #191e25; --ink: #e4e7eb; --muted: #9ba3ae; --line: #2a313b;
  --accent: #e48a5e; --accent-soft: #33221a;
  --code-bg: #1b2028; --code-fg: #dfe3e8; --code-line: #2a313b; --inline-bg: #232a33;
  --term-bg: #0e1116;
  --k: #f0946b; --s: #a8d58c; --i: #ffd479; --n: #d7a6f2; --t: #7cc7e8; --f: #9db8ff; --c: #8590a0;
  --cap-fg: #ffd479; --cap-bg: rgba(255, 212, 121, .13);
  --logo-ink: #c9d1db;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 72px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 400 18px/1.65 var(--f-body); }
a { color: var(--accent); text-underline-offset: 2px; text-decoration-thickness: 1px; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 12px; top: 12px; z-index: 20; background: var(--paper); padding: 6px 10px; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 10; height: 56px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  font-family: var(--f-ui);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 650; font-size: 17px; letter-spacing: -.01em; margin-right: auto; }
.logo svg { display: block; width: 30px; height: 30px; }
.logo [fill="#1F2A37"], .logo [fill="#1f2a37"] { fill: var(--logo-ink); }
.bar button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.bar button:hover { background: var(--accent-soft); color: var(--ink); }
.bar button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.menu { display: none !important; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px); overflow-y: auto;
  background: var(--side); border-right: 1px solid var(--line);
  padding: 20px 12px 40px; font: 14.5px/1.4 var(--f-ui);
}
.sidebar ol { list-style: none; margin: 0; padding: 0; }
.sidebar > ol > li { margin: 1px 0; }
.sidebar a { display: flex; gap: 8px; padding: 6px 10px; border-radius: 6px; color: var(--muted); text-decoration: none; }
.sidebar a:hover { color: var(--ink); background: var(--accent-soft); }
.sidebar a.here { color: var(--ink); background: var(--accent-soft); font-weight: 600; }
.sidebar .no { min-width: 1.6em; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; }
.sidebar a.here .no { color: var(--accent); }
.sidebar .part { margin: 18px 10px 6px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.sidebar .sections { margin: 2px 0 8px 34px; border-left: 1px solid var(--line); }
.sidebar .sections a { padding: 3px 10px; font-size: 13.5px; border-radius: 0 6px 6px 0; }

main { min-width: 0; padding: 32px max(20px, env(safe-area-inset-right)) 80px max(20px, env(safe-area-inset-left)); }
article, .pager { max-width: 760px; margin: 0 auto; }

/* ---------- text ---------- */
header.title { margin: 8px 0 28px; }
.kicker { display: block; font: 600 13px/1 var(--f-ui); letter-spacing: .1em; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; }
h1 { font: 700 clamp(32px, 5vw, 44px)/1.1 var(--f-ui); letter-spacing: -.025em; margin: 0; text-wrap: balance; }
h2 { font: 700 26px/1.2 var(--f-ui); letter-spacing: -.015em; margin: 48px 0 14px; text-wrap: balance; }
h3 { font: 650 20px/1.3 var(--f-ui); margin: 32px 0 10px; }
h2 .anchor, h3 .anchor { color: inherit; text-decoration: none; }
h2 .anchor:hover::after, h3 .anchor:hover::after { content: " #"; color: var(--muted); }
p, ul, ol, figure, pre, aside, .table { margin: 0 0 18px; }
article ul, article ol { padding-left: 1.4em; }
li { margin: 4px 0; }
strong { font-weight: 650; }
code { font: .86em var(--f-mono); background: var(--inline-bg); padding: .1em .32em; border-radius: 4px; overflow-wrap: anywhere; }
aside.note { border-left: 3px solid var(--accent); background: var(--accent-soft); padding: 12px 16px; border-radius: 0 8px 8px 0; font-size: 16.5px; }
aside.note p { margin: 0; }

/* ---------- code ---------- */
pre { background: var(--code-bg); color: var(--code-fg); border: 1px solid var(--code-line); border-radius: 8px; padding: 14px 16px; overflow-x: auto; font: 14px/1.55 var(--f-mono); tab-size: 4; }
pre code { background: none; padding: 0; font-size: inherit; border-radius: 0; overflow-wrap: normal; }
figure pre { margin: 0; }
figure { display: grid; gap: 6px; min-width: 0; }
figcaption { font: 14px/1.45 var(--f-ui); color: var(--muted); }
figcaption b { color: var(--ink); font-weight: 600; }
figcaption .file { font: 12.5px var(--f-mono); white-space: nowrap; margin-left: 4px; }
figure.fails pre { border-color: #c96b4a; border-left-width: 4px; }
.badge { justify-self: start; font: 600 12.5px/1 var(--f-ui); color: #fff; background: #b4532a; padding: 5px 9px; border-radius: 5px; }
.k { color: var(--k); }
.s { color: var(--s); }
.i { color: var(--i); }
.n { color: var(--n); }
.t { color: var(--t); }
.f { color: var(--f); }
.c { color: var(--c); font-style: italic; }
.cap { color: var(--cap-fg); background: var(--cap-bg); border-radius: 3px; padding: 0 2px; }

pre.term { background: var(--term-bg); color: var(--term-fg); border-color: var(--term-bg); }
pre.term .prompt { color: var(--term-muted); user-select: none; }
pre.term .cmd { color: #fff; font-weight: 600; }
pre.term .err { color: var(--err); font-weight: 600; }
pre.term .warn { color: var(--warn); font-weight: 600; }
pre.term .ok { color: var(--ok); }
pre.term .loc { color: var(--loc); }
pre.term .note { color: var(--term-muted); font-weight: 600; }

.table { overflow-x: auto; }
table { border-collapse: collapse; font: 15.5px/1.45 var(--f-ui); min-width: 100%; }
th, td { text-align: left; vertical-align: top; padding: 7px 12px 7px 0; border-bottom: 1px solid var(--line); }
th { font-weight: 600; }
td code, th code { font-size: .88em; }

/* ---------- previous and next ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--line); font-family: var(--f-ui); }
.pager a { display: grid; gap: 2px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 15.5px; }
.pager a:hover { border-color: var(--accent); }
.pager a span { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.pager .next { text-align: right; }

/* ---------- small screens: the chapters slide in over the text ---------- */
@media (max-width: 900px) {
  .menu { display: grid !important; }
  .layout { display: block; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; height: auto; width: min(320px, 86vw); z-index: 9;
    transform: translateX(-102%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .18);
  }
  body.open .sidebar { transform: none; }
  main { padding-top: 20px; }
  body { font-size: 17px; }
  pre { font-size: 13px; padding: 12px; border-radius: 6px; }
  h2 { margin-top: 40px; }
}
@media (max-width: 520px) {
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
  figcaption .file { white-space: normal; overflow-wrap: anywhere; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
@media print {
  .bar, .sidebar, .pager { display: none; }
  .layout { display: block; }
}
