/*
  Book chapter theme for engine.knowlu.me.
  Profile: W_SMALL 599px, W_MARGIN 900px, W_WIDE 1200px,
  LINE_MIN 45, LINE_MAX 90, TOL 2px, T_UI 200ms.
  Modes: small <=599, narrow 600-899, medium 900-1199, wide >=1200.
*/
:root {
  --ink: #1b1b1b;
  --ink-soft: #444;
  --ink-faint: #6b6b6b;
  --paper: #fffdf8;
  --tint: #f4f1e8;
  --rule: #d9d3c4;
  --link: #1450a0;
  --link-hover: #0a3470;
  --focus: #1450a0;
  --warn: #8a5a00;
  --info: #2f5d8a;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 52rem;
  --lh: 1.6;
  --t-ui: 150ms;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1.1875rem/var(--lh) var(--serif);
  font-optical-sizing: auto;
  overflow-wrap: break-word;
}

/* Visually hidden, available to assistive tech. */
.bk-vh {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.bk-skip {
  position: absolute; left: 1rem; top: -4rem; z-index: 10;
  padding: .5rem 1rem; background: var(--ink); color: #fff;
  font: 600 1rem/1.4 var(--sans); text-decoration: none;
}
.bk-skip:focus { top: 1rem; }

/* Links: underline at rest (non-colour cue), thicker on hover, visible focus ring. */
a { color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .18em; transition: color var(--t-ui), text-decoration-thickness var(--t-ui); }
a:hover { color: var(--link-hover); text-decoration-thickness: 2px; }
a:focus-visible, summary:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.bk-main:focus { outline: none; }

/* Page grid. Narrow and small: one column. */
.bk-page { display: block; max-width: calc(var(--measure) + 2.5rem); margin: 0 auto; padding: 0 1.25rem; }
.bk-main { min-width: 0; }
.bk-side, .bk-margin { display: none; }

/* Compact top navigation (narrow and small). */
.bk-top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: calc(var(--measure) + 2.5rem); margin: 0 auto; padding: .75rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  font: 600 1rem/1.3 var(--sans);
}
.bk-top__home { color: var(--ink); text-decoration: none; padding: .6rem 0; }
.bk-top__home:hover { text-decoration: underline; }
.bk-top__arrows { display: flex; gap: .25rem; }
.bk-arrow {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 2.75rem; min-height: 2.75rem; color: var(--ink); text-decoration: none; font-size: 1.25rem;
}
.bk-arrow:hover { background: var(--tint); }

/* Shared navigation content. */
.bk-nav__chapter { display: block; color: var(--ink); text-decoration: none; font: 700 1rem/1.35 var(--sans); margin: 0 0 .75rem; }
.bk-nav__chapter:hover { text-decoration: underline; }
.bk-nav__num { color: var(--ink-faint); font-variant-numeric: tabular-nums; margin-right: .25rem; }
.bk-nav__toc { list-style: none; margin: 0 0 1rem; padding: 0; font: 400 .9375rem/1.35 var(--sans); }
.bk-nav__toc li { margin: 0; }
.bk-nav__toc a { display: block; padding: .3rem 0; color: var(--ink-soft); text-decoration: none; }
.bk-nav__toc a:hover { color: var(--link-hover); text-decoration: underline; }
.bk-nav__pager { display: flex; flex-wrap: wrap; gap: .25rem 1rem; margin: 0; font: 600 .875rem/1.4 var(--sans); }
.bk-nav__pager a { display: inline-block; padding: .3rem 0; text-decoration: none; }
.bk-nav__pager a:hover { text-decoration: underline; }

/* Medium: column + margin; collapsible nav lives in the margin. */
@media (min-width: 900px) {
  .bk-top { display: none; }
  .bk-page {
    display: grid; max-width: none;
    grid-template-columns: minmax(0, var(--measure)) minmax(11rem, 15rem);
    column-gap: 2.5rem; justify-content: center; padding: 0 2rem;
  }
  .bk-main { grid-column: 1; grid-row: 1; }
  .bk-margin { display: block; grid-column: 2; grid-row: 1; padding-top: 3.25rem; }
  .bk-float { position: sticky; top: 1rem; font-family: var(--sans); }
  .bk-float__btn {
    display: inline-flex; align-items: center; gap: .5rem; min-height: 2.75rem; padding: 0 .9rem;
    border: 1px solid var(--rule); border-radius: 4px; background: var(--paper);
    font: 600 .9375rem/1 var(--sans); cursor: pointer; list-style: none;
  }
  .bk-float__btn::-webkit-details-marker { display: none; }
  .bk-float__btn::before { content: "☰"; font-size: 1rem; }
  .bk-float[open] .bk-float__btn::before { content: "✕"; }
  .bk-float__btn:hover { background: var(--tint); }
  .bk-float__panel {
    margin-top: .5rem; padding: 1rem; background: var(--paper);
    border: 1px solid var(--rule); border-radius: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.08);
    max-height: calc(100vh - 6rem); overflow-y: auto;
    animation: bk-open var(--t-ui) ease-out;
  }
}
@keyframes bk-open { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* Wide: persistent sidebar | column | margin. */
@media (min-width: 1200px) {
  .bk-page { grid-template-columns: 14rem minmax(0, var(--measure)) minmax(10rem, 15rem); column-gap: 2.5rem; }
  .bk-side { grid-column: 1; grid-row: 1; }
  .bk-main { grid-column: 2; }
  .bk-margin { display: block; grid-column: 3; }
  .bk-float { display: none; }
  .bk-side {
    display: block; position: sticky; top: 0; align-self: start;
    max-height: 100vh; overflow-y: auto; padding: 2.5rem 0 2rem;
  }
  .bk-side__home { display: block; margin: 0 0 1.5rem; color: var(--ink); text-decoration: none; font: 700 1.0625rem/1.3 var(--sans); }
  .bk-side__home:hover { text-decoration: underline; }
}

/* Chapter header. */
.bk-chhead { padding: 2.5rem 0 1rem; }
.bk-chnum { margin: 0 0 .25rem; color: var(--ink-faint); font: 300 3.5rem/1 var(--sans); font-variant-numeric: lining-nums; }
.bk-title { margin: 0; font: 700 2.25rem/1.15 var(--sans); letter-spacing: -.01em; text-wrap: balance; }
@media (max-width: 599.98px) {
  .bk-page { padding: 0 1rem; }
  .bk-top { padding: .5rem 1rem; }
  .bk-chnum { font-size: 2.75rem; }
  .bk-title { font-size: 1.75rem; }
  body { font-size: 1.125rem; }
}

/* Body typography. */
.bk-body { counter-reset: bk-h2; }
.bk-body p, .bk-body ul, .bk-body ol { margin: 0 0 1rem; }
.bk-body ul, .bk-body ol { padding-left: 1.5rem; }
.bk-body li { margin: .25rem 0; }
.bk-body li > p { margin: 0; }
.bk-body strong { font-weight: 650; }

.bk-body h2, .bk-body h3, .bk-body h4 { position: relative; font-family: var(--sans); line-height: 1.25; scroll-margin-top: 1.5rem; }
.bk-body h2 { margin: 2.75rem 0 1rem; font-size: 1.625rem; font-weight: 700; counter-increment: bk-h2; counter-reset: bk-h3; }
.bk-body h3 { margin: 2.25rem 0 .75rem; font-size: 1.25rem; font-weight: 700; counter-increment: bk-h3; }
.bk-body h4 { margin: 1.75rem 0 .5rem; font-size: 1.0625rem; font-weight: 700; }
.bk-hlink { color: inherit; text-decoration: none; }
.bk-hlink:hover { text-decoration: underline; text-decoration-thickness: 1px; }
.bk-hlink::after {
  content: "#"; position: absolute; left: -1.25rem; top: 0; width: 1rem; text-align: center;
  color: var(--ink-faint); font-weight: 400; opacity: 0; transition: opacity var(--t-ui);
}
.bk-hlink:hover::after, .bk-hlink:focus-visible::after { opacity: 1; }
.bk--chapter .bk-body h2 > .bk-hlink::before { content: var(--chap) counter(bk-h2) "\a0\a0"; color: var(--ink-faint); font-weight: 500; }
.bk--chapter .bk-body h3 > .bk-hlink::before { content: var(--chap) counter(bk-h2) "." counter(bk-h3) "\a0\a0"; color: var(--ink-faint); font-weight: 500; }
@media (max-width: 599.98px) { .bk-hlink::after { left: auto; right: 100%; } }

/* Quotations. */
.bk-body blockquote {
  margin: 1.25rem 0; padding: .1rem 0 .1rem 1.25rem;
  border-left: 3px solid var(--rule); color: var(--ink-soft); font-size: .95em;
}
.bk-body blockquote p:last-child { margin-bottom: 0; }

/* Callouts: kind label + icon + border, not colour alone. */
.bk-body .callout { margin: 1.5rem 0; padding: .9rem 1.1rem; background: var(--tint); border-left: 4px solid var(--info); }
.bk-body .callout--warning { border-left-color: var(--warn); }
.bk-body .callout__header { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: 0 0 .4rem; font: 700 1rem/1.35 var(--sans); }
.bk-body .callout__icon { font-size: .95rem; }
.bk-kind { order: 1; text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; color: var(--info); }
.callout--warning .bk-kind { color: var(--warn); }
.bk-body .callout__icon { order: 0; }
.bk-body .callout__title { order: 2; flex-basis: 100%; }
.bk-body .callout__body p:last-child { margin-bottom: 0; }

/* Figures: never wider than the container nor 640px (2x source pixels for 1280px frames). */
.bk-fig { margin: 1.5rem 0; }
.bk-fig img { display: block; width: 100%; max-width: 40rem; height: auto; aspect-ratio: auto 1280 / 720; background: var(--tint); border: 1px solid var(--rule); }
.bk-fig figcaption { margin-top: .5rem; color: var(--ink-soft); font: italic 400 .9375rem/1.45 var(--serif); }
.bk-body img { max-width: 100%; height: auto; }

/* Code. */
.bk-body code { font-family: var(--mono); font-size: .82em; line-height: 1; padding: .05em .25em; background: var(--tint); border-radius: 3px; overflow-wrap: anywhere; }
.bk-body pre {
  margin: 1.25rem 0; padding: .9rem 1rem; background: var(--tint); border-left: 3px solid var(--rule);
  overflow-x: auto; font-size: 1rem; line-height: 1.5; tab-size: 4;
}
.bk-body pre code { padding: 0; background: none; font-size: .82em; line-height: inherit; overflow-wrap: normal; white-space: pre; }

/* Tables scroll inside their own box. */
.bk-table { margin: 1.25rem 0; overflow-x: auto; }
.bk-body table { width: 100%; border-collapse: collapse; font-size: .9375rem; line-height: 1.45; }
.bk-body th, .bk-body td { padding: .5rem .6rem; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
.bk-body th { font: 700 .875rem/1.35 var(--sans); border-bottom-width: 2px; }
.bk-body td { min-width: 7rem; }

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

/* Agent hand-off. */
.bk-agents { margin: 3rem 0 0; padding: 1.25rem 1.25rem 1rem; border: 1px solid var(--rule); border-radius: 4px; font-family: var(--sans); }
.bk-agents__h { margin: 0 0 .5rem; font-size: 1.125rem; }
.bk-agents__lead { margin: 0 0 1rem; font-size: .9375rem; line-height: 1.5; color: var(--ink-soft); }
.bk-agents__list { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; padding: 0; list-style: none; }
.bk-agent {
  display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0 1rem;
  border: 1px solid var(--rule); border-radius: 4px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9375rem;
}
.bk-agent:hover { background: var(--tint); border-color: var(--ink-faint); }
.bk-agents__status { min-height: 1.5rem; margin: .75rem 0 0; font-size: .9375rem; color: var(--ink-soft); }

/* Footer. */
.bk-foot { margin: 3rem 0 4rem; padding-top: 1.25rem; border-top: 1px solid var(--rule); font-family: var(--sans); }
.bk-foot__next { margin: 0 0 1rem; font-size: 1.125rem; font-weight: 700; }
.bk-foot__meta { margin: 0; font-size: .875rem; color: var(--ink-faint); }

/* Home page. */
.bk--home .bk-chhead { padding-top: 3rem; }
.bk--home .bk-title { font-size: 2.75rem; }

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

@media print {
  @page { margin: 18mm 16mm; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .bk-top, .bk-side, .bk-margin, .bk-skip, .bk-agents, .bk-hlink::after { display: none !important; }
  .bk-page { display: block; max-width: none; padding: 0; }
  a { color: #000; }
  .bk-body h2, .bk-body h3, .bk-body h4 { break-after: avoid; page-break-after: avoid; }
  .bk-fig, .bk-body pre, .bk-body blockquote, .bk-body .callout, .bk-body tr { break-inside: avoid; }
  .bk-body pre code { white-space: pre-wrap; }
  .bk-body pre, .bk-body code, .bk-body .callout { background: none; }
  .bk-body .callout { border: 1px solid #000; border-left-width: 4px; }
  .bk-table { overflow: visible; }
  .bk-chnum, .bk-nav__num, .bk-fig figcaption, .bk-foot__meta, .bk-body blockquote { color: #000; }
  p, li { orphans: 2; widows: 2; }
}

/* Chapter cover and home chapter cards. */
.bk-cover { margin: 0 0 2rem; }
.bk-cover img { max-width: 100%; }
.bk-cards { margin: 2.5rem 0 1rem; }
.bk-cards__h { margin: 0 0 1rem; font: 700 1.625rem/1.2 var(--sans); }
.bk-cards__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1.5rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); }
.bk-card__link { display: flex; flex-direction: column; gap: .375rem; height: 100%; padding: 0 0 1rem; color: inherit; text-decoration: none; border: 1px solid var(--rule); background: var(--paper, transparent); }
.bk-card__link:hover .bk-card__title, .bk-card__link:focus-visible .bk-card__title { text-decoration: underline; }
.bk-card__img { display: block; width: 100%; height: auto; aspect-ratio: 16 / 9; object-fit: cover; background: var(--tint); border-bottom: 1px solid var(--rule); }
.bk-card__num, .bk-card__title, .bk-card__desc { padding: 0 1rem; }
.bk-card__img + .bk-card__num { margin-top: .5rem; }
.bk-card__link > .bk-card__num:first-child { margin-top: 1rem; }
.bk-card__num { color: var(--ink-faint); font: 500 .875rem/1.3 var(--sans); }
.bk-card__title { font: 700 1.25rem/1.25 var(--sans); }
.bk-card__desc { color: var(--ink-soft); font-size: 1rem; line-height: 1.45; }
