/* Everything About Design: web edition.
   Visual world: a swatch book. Plain paper, black ink, hairline rules, one ink-blue for links,
   and one chip color per part (16 hues around the wheel) that marks where the reader is.
   Reading settings live in CSS custom properties set on <html> by the early script in each page. */

:root {
  --fs: 19px;            /* reading text size */
  --lh: 1.65;            /* reading line height */
  --measure: 36em;       /* reading column width */
  --sb-w: 296px;
  --bar-h: 52px;
  --ui: "Schibsted Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 4px;

  /* light: neutral paper, not cream */
  --bg: #f6f6f3;
  --bg-side: #f6f6f3;
  --bg-raise: #ffffff;
  --bg-hover: #ebebe6;
  --text: #141413;
  --text-2: #4b4b46;
  --text-3: #66665e;
  --rule: #dcdcd5;
  --accent: #2b3fd0;
  --accent-soft: #e3e6fa;
  --box: #eeeee9;
  --mark: #fde68a;
  --shadow: 0 12px 32px -8px rgba(20, 20, 19, .18), 0 2px 6px rgba(20, 20, 19, .06);
  --img-filter: none;
  color-scheme: light;
}

:root[data-theme="sepia"] {
  --bg: #f4ecdc;
  --bg-side: #f4ecdc;
  --bg-raise: #fbf6ea;
  --bg-hover: #e9dec6;
  --text: #2f261a;
  --text-2: #594a34;
  --text-3: #6a5a41;
  --rule: #dccdb0;
  --accent: #2f429c;
  --accent-soft: #e4dccb;
  --box: #ece2cc;
  --mark: #f5cf6a;
  --img-filter: sepia(.12);
}

:root[data-theme="dark"] {
  --bg: #121212;
  --bg-side: #121212;
  --bg-raise: #1c1c1b;
  --bg-hover: #262624;
  --text: #ecece7;
  --text-2: #b6b6ae;
  --text-3: #96968d;
  --rule: #2d2d2a;
  --accent: #9eabff;
  --accent-soft: #1f2442;
  --box: #1a1a19;
  --mark: #5c4a0b;
  --shadow: 0 14px 36px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .35);
  --img-filter: brightness(.9);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #121212;
    --bg-side: #121212;
    --bg-raise: #1c1c1b;
    --bg-hover: #262624;
    --text: #ecece7;
    --text-2: #b6b6ae;
    --text-3: #96968d;
    --rule: #2d2d2a;
    --accent: #9eabff;
    --accent-soft: #1f2442;
    --box: #1a1a19;
    --mark: #5c4a0b;
    --shadow: 0 14px 36px -8px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .35);
    --img-filter: brightness(.9);
    color-scheme: dark;
  }
}

/* part color: a chip and a text-safe ink, worked out wherever a part hue (--h) is set:
   on <body> for a chapter page, on each part in the contents, on pager links, on spectrum chips */
:root, [style*="--h"] { --chip: oklch(.7 .15 var(--h, 265)); --pink: oklch(.47 .16 var(--h, 265)); }
:root[data-theme="dark"], :root[data-theme="dark"] [style*="--h"] { --chip: oklch(.72 .14 var(--h, 265)); --pink: oklch(.8 .12 var(--h, 265)); }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"], :root[data-theme="auto"] [style*="--h"] { --chip: oklch(.72 .14 var(--h, 265)); --pink: oklch(.8 .12 var(--h, 265)); }
}

/* typefaces */
:root { --read-font: Literata, Georgia, serif; }
:root[data-font="sourceserif"] { --read-font: "Source Serif 4", Georgia, serif; }
:root[data-font="charter"] { --read-font: Charter, "Bitstream Charter", "Iowan Old Style", "Sitka Text", Cambria, Georgia, serif; }
:root[data-font="inter"] { --read-font: Inter, system-ui, sans-serif; }
:root[data-font="atkinson"] { --read-font: "Atkinson Hyperlegible", system-ui, sans-serif; }
:root[data-font="system"] { --read-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

/* ------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 16px); scrollbar-color: color-mix(in srgb, var(--text) 28%, transparent) transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  caret-color: var(--accent);
}
::selection { background: color-mix(in srgb, var(--accent) 24%, transparent); color: inherit; }
a { color: inherit; }
button { font: inherit; color: inherit; }
kbd {
  display: inline-block; min-width: 1.75em;
  font: 500 11.5px/1 var(--ui); text-align: center;
  padding: 4px 5px 3px;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 3px;
  color: var(--text-2);
  background: var(--bg-raise);
}
.ic { flex: none; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--bg-raise); padding: 8px 12px; border-radius: var(--radius); }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.chip { display: inline-block; flex: none; width: 9px; height: 9px; background: var(--chip); border-radius: 1px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  border: 0; border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn[aria-expanded="true"] { background: var(--bg-hover); color: var(--text); }
.icon-btn.aa { font: 600 16px/1 var(--read-font); letter-spacing: -.02em; width: auto; padding: 0 10px; }

/* ------------------------------------------------------------ layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0;
  flex: none;
  width: var(--sb-w); height: 100vh;
  display: flex; flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--rule);
}
.main-col { flex: 1; min-width: 0; }
html.sb-hidden .sidebar { display: none; }
.scrim { display: none; }

/* sidebar head: the title and the 16-chip spectrum that serves as the book's mark */
.sb-head { padding: 18px 16px 12px; }
.brand { display: block; text-decoration: none; padding: 0 2px 14px; }
.brand > span:first-child { display: block; font-weight: 750; font-size: 15px; letter-spacing: -.02em; line-height: 1.2; }
.spectrum { display: grid; grid-template-columns: repeat(16, 1fr); gap: 2px; margin-top: 9px; }
.spectrum i { height: 5px; background: var(--chip); }
.search {
  position: relative;
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 8px 0 10px;
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--text-3);
}
.search:focus-within { border-color: var(--text); }
.search .ic { width: 16px; height: 16px; }
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font: 14px var(--ui); color: var(--text);
}
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { display: none; }

/* contents tree */
.toc { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 6px 8px 40px; scrollbar-width: thin; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.part > summary {
  list-style: none;
  display: grid; grid-template-columns: 9px 22px 1fr auto; align-items: baseline; column-gap: 8px;
  padding: 8px 8px 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
}
.part > summary::-webkit-details-marker { display: none; }
.part > summary:hover { background: var(--bg-hover); }
/* chips and arrows sit on the first line of a title, so a title that wraps keeps them at the top */
.part > summary .chip { align-self: start; margin-top: calc((13.5px * 1.3 - 9px) / 2); }
.part .pn { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-3); }
.part .pt { font-size: 13.5px; font-weight: 600; line-height: 1.3; letter-spacing: -.005em; }
.part .pc { align-self: start; margin-top: calc((13.5px * 1.3 - 15px) / 2); width: 15px; height: 15px; color: var(--text-3); transition: transform .15s; }
.part[open] > summary .pc { transform: rotate(90deg); }
.part[open] > summary .pn { color: var(--pink); }
.chs { padding: 0 0 8px 10px !important; }
.ch .row { display: flex; align-items: flex-start; }
.tw, .tw-pad { flex: none; width: 24px; height: 30px; }
.tw {
  display: grid; place-items: center;
  border: 0; background: none; padding: 0;
  color: var(--text-3); cursor: pointer; border-radius: var(--radius);
}
.tw:hover { color: var(--text); background: var(--bg-hover); }
.tw .ic { width: 14px; height: 14px; transition: transform .15s; }
.tw[aria-expanded="true"] .ic { transform: rotate(90deg); }
.ch .row > a {
  flex: 1; min-width: 0;
  display: flex; gap: 8px; align-items: baseline;
  padding: 5px 8px 5px 2px;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13.5px; line-height: 1.35;
  color: var(--text-2);
}
.ch .row > a:hover { background: var(--bg-hover); color: var(--text); }
.ch .num { flex: none; min-width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-3); font-size: 12px; }
.ch .t { flex: 1; }
.ch.current .row > a { color: var(--text); font-weight: 600; background: var(--bg-hover); }
.ch.current .num { color: var(--pink); font-weight: 650; }
.ic.done { display: none; width: 14px; height: 14px; color: var(--text-3); align-self: center; }
.is-read .ic.done { display: block; }
.sub { margin: 2px 0 6px 33px !important; border-left: 1px solid var(--rule); }
.sub a {
  display: block;
  padding: 4px 8px 4px 12px; margin-left: -1px;
  border-left: 1px solid transparent;
  font-size: 12.8px; line-height: 1.35;
  text-decoration: none; color: var(--text-2);
}
.sub a:hover { color: var(--text); }
.sub a.active { color: var(--text); border-left-color: var(--text); font-weight: 600; }
.ref { margin-top: 10px; padding: 12px 10px 0; border-top: 1px solid var(--rule); }
.ref-h { margin: 0 0 4px; font-size: 12px; font-weight: 600; color: var(--text-3); }
.ref a { display: block; padding: 5px 8px; margin: 0 -8px; border-radius: var(--radius); text-decoration: none; font-size: 13.5px; color: var(--text-2); }
.ref a:hover { background: var(--bg-hover); color: var(--text); }

/* top bar */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  height: var(--bar-h);
  padding: 0 10px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.scrolled .bar { border-bottom-color: var(--rule); }
.crumb { flex: 1; min-width: 0; margin: 0 0 0 4px; font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb a { text-decoration: none; }
.crumb a:hover { color: var(--text); }
.progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; pointer-events: none; }
.progress span { display: block; height: 100%; width: 0; background: var(--chip); transition: width .1s linear; }

/* ------------------------------------------------------------ reading column */
main { outline: none; }
.reader {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 28px 24px 40px;
  font-family: var(--read-font);
  font-size: var(--fs);
  line-height: var(--lh);
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
  hanging-punctuation: first;
  overflow-wrap: break-word;
}
:root[data-justify="1"] .reader p, :root[data-justify="1"] .reader li { text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
.reader p { margin: 0 0 1em; }
.reader strong { font-weight: 650; }
.reader a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: .18em; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.reader a:hover { text-decoration-color: currentColor; }
.reader a.url { overflow-wrap: anywhere; }

/* chapter opening: a big part-colored numeral, the title, then the part and reading time */
.ch-head { margin: 28px 0 2.6em; font-family: var(--ui); }
.ch-num {
  margin: 0 0 .1em !important;
  font: 800 clamp(72px, 11vw, 128px)/.82 var(--ui);
  letter-spacing: -.045em;
  color: var(--pink);
  font-variant-numeric: lining-nums tabular-nums;
}
.ch-head h1 { margin: 0; font: 700 2.05em/1.06 var(--ui); letter-spacing: -.03em; text-wrap: balance; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 1.1em 0 0 !important; font: 13.5px var(--ui); color: var(--text-2); }
.part-link { display: inline-flex; align-items: center; gap: 7px; color: var(--text-2) !important; text-decoration: none !important; }
.part-link:hover { color: var(--text) !important; }
.meta .dot { color: var(--text-3); }

.reader h2, .reader h3 { position: relative; font-family: var(--ui); font-weight: 650; letter-spacing: -.02em; text-wrap: balance; }
.reader h2 { font-size: 1.32em; line-height: 1.2; margin: 2.2em 0 .55em; }
.reader h3 { font-size: 1.04em; line-height: 1.3; margin: 1.8em 0 .45em; }
.anchor { position: absolute; left: -1.1em; width: 1em; color: var(--text-3) !important; text-decoration: none !important; opacity: 0; font-weight: 400; }
h2:hover .anchor, h3:hover .anchor, .anchor:focus-visible { opacity: 1; }
.reader :target { animation: flash 1.6s cubic-bezier(.16, 1, .3, 1); }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }

.reader ul, .reader ol { margin: 0 0 1em; padding-left: 1.3em; }
.reader li { margin: .3em 0; }
.reader li::marker { color: var(--text-3); }
.reader code { font-family: var(--mono); font-size: .84em; background: var(--box); padding: .1em .3em; border-radius: 3px; }
.reader pre { background: var(--box); padding: 14px 16px; border-radius: var(--radius); overflow-x: auto; line-height: 1.5; margin: 0 0 1.2em; }
.reader pre code { background: none; padding: 0; font-size: .8em; }

/* footnote references */
.fnref { line-height: 0; }
.fnref a {
  font: 600 .62em var(--ui);
  text-decoration: none;
  padding: 0 .15em;
  color: var(--accent);
  vertical-align: super;
}
.fn-pop {
  position: absolute; z-index: 40;
  max-width: min(420px, calc(100vw - 24px));
  padding: 12px 14px;
  background: var(--bg-raise); color: var(--text);
  border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: var(--shadow);
  font: 13.5px/1.5 var(--ui);
  overflow-wrap: anywhere;
}
.fn-pop a { color: var(--accent); }
.fn-pop .back { display: none; }

/* figures */
figure { margin: 2em 0; }
figure img {
  display: block; max-width: 100%; height: auto; max-height: 75vh;
  margin: 0 auto;
  border-radius: 2px;
  cursor: zoom-in;
  filter: var(--img-filter);
}
figcaption { margin-top: .8em; font: 13.5px/1.5 var(--ui); color: var(--text-2); }
figcaption em { font-style: italic; }
.fig-label { font-weight: 650; color: var(--text); margin-right: .2em; }
.credit { margin: .35em 0 0 !important; font-size: 12px; color: var(--text-3); }
.credit a { color: inherit !important; }
.placeholder .ph, .ph { border: 1px dashed var(--rule); border-radius: var(--radius); padding: 10px 14px; }
.ph-kind { font: 600 13px/1.3 var(--ui); color: var(--text-2); }
.ph-desc { margin: 0 !important; font: 13.5px/1.55 var(--ui); color: var(--text-2); }

/* boxes: a full hairline frame; the kind of box reads as the start of its title */
.box {
  margin: 1.8em 0;
  padding: 1.1em 1.3em .3em;
  background: var(--box);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  font-size: .93em;
}
.box-confused { background: color-mix(in srgb, var(--accent) 5%, var(--bg)); border-color: color-mix(in srgb, var(--accent) 22%, var(--rule)); }
.box-title { margin: 0 0 .5em !important; font: 650 1.02em/1.35 var(--ui); letter-spacing: -.01em; }
.box-kind { color: var(--accent); }
.box-profile .box-kind { color: var(--text-2); }

/* tables */
.table-wrap { overflow-x: auto; margin: 1.5em 0; }
table { border-collapse: collapse; width: 100%; font: 14px/1.45 var(--ui); font-variant-numeric: tabular-nums; }
th, td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--rule); }
th { font-weight: 650; color: var(--text); border-bottom: 1px solid var(--text); }

/* end matter */
ul.see-also { list-style: none; padding: 0; columns: 2 16em; column-gap: 2em; font-size: .92em; }
ul.see-also li { break-inside: avoid; margin: .2em 0; }
ul.see-also a { text-decoration: none; }
ul.see-also .num { display: inline-block; min-width: 1.8em; color: var(--text-3); font-variant-numeric: lining-nums tabular-nums; }
ul.sources, .notes ol { font: 13.5px/1.55 var(--ui); color: var(--text-2); }
ul.sources li, .notes li { margin: .45em 0; }
.notes { margin-top: 2.5em; padding-top: 1em; border-top: 1px solid var(--rule); }
.notes h2 { font-size: 1.05em !important; margin-top: .5em !important; }
.notes .back { text-decoration: none; margin-left: .2em; }
.end-mark { height: 1px; }

/* pager: two plain links under a hairline */
.pager {
  display: grid; grid-template-columns: 1fr 1fr; gap: 24px;
  max-width: calc(var(--measure) + 48px);
  margin: 0 auto; padding: 0 24px 80px;
}
.pager::before { content: ""; grid-column: 1 / -1; border-top: 1px solid var(--rule); margin-bottom: 4px; }
.pg {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 6px 0;
  text-decoration: none; font-size: 15px; font-weight: 600; line-height: 1.3; letter-spacing: -.01em;
  color: var(--text);
}
.pg small { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 400; color: var(--text-3); margin-bottom: 4px; letter-spacing: 0; }
.pg small::before { content: ""; width: 9px; height: 9px; background: var(--chip); border-radius: 1px; }
.pg.next small { justify-content: flex-end; }
.pg:hover span { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.pg.next { justify-content: flex-end; text-align: right; grid-column: 2; }
.pg .ic { color: var(--text-3); margin-top: 22px; }

/* ------------------------------------------------------------ home */
.is-home .bar .crumb::before { content: ""; }
.home .hero { position: relative; max-width: 1120px; margin: 0 auto; padding: 12px 24px 0; }
.home .hero img { display: block; width: 100%; height: auto; border-radius: 2px; cursor: default; max-height: none; filter: none; }
.hero-text {
  position: absolute; left: 0; right: 0; top: 0;
  padding: 6.5% 8.5% 0;
  color: #141413;
  font-family: var(--ui);
}
.hero-text h1 { margin: 0; font: 800 clamp(30px, 5.6vw, 68px)/.95 var(--ui); letter-spacing: -.045em; }
.hero-text .subtitle { margin: .55em 0 0; font: 500 clamp(14px, 1.65vw, 20px)/1.3 var(--ui); letter-spacing: -.01em; color: #3d3d38; }
.byline { margin: 1.1em 0 0; font: 400 clamp(11.5px, 1.05vw, 13.5px)/1.55 var(--ui); color: #3d3d38; }
.byline a { color: #141413; font-weight: 600; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; text-decoration-color: rgba(20, 20, 19, .35); }
.byline a:hover { text-decoration-color: #141413; }
/* cover B: collage on the right, title on the blank left side */
.hero-b { display: none; }
:root[data-cover="b"] .hero-b { display: block; }
:root[data-cover="b"] .hero-a:has(+ .hero-b) { display: none; }
.hero-b .hero-text { right: auto; width: 36%; padding: 0 0 0 5%; top: 18%; }
.hero-b .hero-text h1 { font-size: clamp(22px, 3.7vw, 48px); }
.hero-b .hero-text .subtitle { font-size: clamp(13px, 1.35vw, 17px); }
@media (max-width: 640px) {
  .hero-text { position: static; padding: 18px 4px 20px; color: var(--text); }
  .hero-text .subtitle, .byline { color: var(--text-2); }
  .byline a { color: var(--text); text-decoration-color: color-mix(in srgb, var(--text) 35%, transparent); }
  .hero-b img { aspect-ratio: 4 / 5; object-fit: cover; object-position: 78% 50%; }
  .hero-b .hero-text { width: auto; padding: 18px 4px 20px; }
}
.cover-switch { max-width: 1120px; margin: 10px auto 0; padding: 0 24px; display: flex; justify-content: flex-end; gap: 6px; }
.cover-switch button {
  width: 46px; height: 31px; padding: 2px;
  border: 1px solid var(--rule); border-radius: 3px;
  background: var(--bg-raise); cursor: pointer; opacity: .7;
}
.cover-switch button:hover { opacity: 1; }
.cover-switch button[aria-pressed="true"] { opacity: 1; border-color: var(--text); }
.cover-switch img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: 1px; }
.home-body { padding-top: 32px; padding-bottom: 8px; }
.home-body .small { font-size: .85em; color: var(--text-2); }
.cta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 1.8em; font-family: var(--ui); }
.btn {
  display: inline-flex; align-items: center;
  height: 42px; padding: 0 18px;
  border: 1px solid var(--text); border-radius: var(--radius);
  font: 600 14.5px var(--ui); text-decoration: none !important;
  color: var(--text) !important;
  transition: background-color .15s, color .15s;
}
.btn:hover { background: var(--text); color: var(--bg) !important; }
.btn.primary { background: var(--text); color: var(--bg) !important; }
.btn.primary:hover { background: color-mix(in srgb, var(--text) 82%, var(--bg)); }
.read-count { margin: 0 0 0 6px !important; font-size: 13px; color: var(--text-2); }

/* contents: a typeset index, two columns of parts on wide screens */
.contents {
  max-width: 1120px; margin: 0 auto; padding: 24px 24px 96px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); column-gap: 56px;
  font-family: var(--ui);
}
.contents-h { grid-column: 1 / -1; margin: 0 0 8px; font: 800 clamp(30px, 4vw, 44px)/1 var(--ui); letter-spacing: -.04em; }
.part-row { padding: 18px 0 14px; border-top: 1px solid var(--rule); scroll-margin-top: 70px; }
.part-row h3 { display: grid; grid-template-columns: 11px 30px 1fr; align-items: baseline; column-gap: 10px; margin: 0 0 10px; font-size: 17px; font-weight: 650; line-height: 1.25; letter-spacing: -.02em; }
.part-row h3 .chip { width: 11px; height: 11px; align-self: start; margin-top: calc((17px * 1.25 - 11px) / 2); transition: transform .25s cubic-bezier(.16, 1, .3, 1); }
.part-row:hover h3 .chip { transform: scale(1.35); }
.part-row .pn { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--pink); }
.part-row ol, .part-row ul { list-style: none; margin: 0; padding: 0 0 0 51px; }
.part-row li a { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; font-size: 14.5px; line-height: 1.35; color: var(--text-2); text-decoration: none; }
.part-row li a:hover { color: var(--text); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.part-row .num { min-width: 1.6em; text-align: right; font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.part-row .ic.done { margin-left: auto; }
.ref-row h3 { grid-template-columns: 1fr; }
.ref-row ul { padding-left: 0; }

/* ------------------------------------------------------------ reference pages */
.refpage .filter {
  width: 100%; height: 40px; padding: 0 12px; margin-bottom: 14px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--bg-raise); color: var(--text); font: 15px var(--ui);
}
.refpage .filter:focus { outline: none; border-color: var(--text); }
.letters { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 20px; font: 600 13px var(--ui); }
.letters a { min-width: 28px; padding: 5px 7px; text-align: center; border-radius: var(--radius); text-decoration: none; }
.letters a:hover { background: var(--bg-hover); }
.gloss { margin: 0; }
.gloss .entry { padding: .7em 0; border-bottom: 1px solid var(--rule); scroll-margin-top: 70px; }
.gloss dt { font-family: var(--ui); font-weight: 650; letter-spacing: -.01em; }
.gloss .dates { font-weight: 400; color: var(--text-3); font-size: .9em; }
.gloss dd { margin: .2em 0 0; font-size: .95em; }
.where { display: block; margin-top: .3em; font: 12.5px/1.5 var(--ui); color: var(--text-3); }
.where a { color: var(--text-2) !important; }
.pairs { list-style: none; padding: 0 !important; }
.pairs li { padding: .55em 0; border-bottom: 1px solid var(--rule); margin: 0 !important; }
.pairs a { text-decoration: none; font: 650 1.02em/1.3 var(--ui); letter-spacing: -.01em; color: var(--text) !important; }
.pairs a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: .2em; }
.credits { list-style: none; padding: 0 !important; font: 13.5px/1.5 var(--ui); }
.credits li { display: flex; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--rule); margin: 0 !important; }
.credits img { flex: none; width: 72px; height: 72px; object-fit: cover; border-radius: 2px; filter: var(--img-filter); }
.credits p { margin: 0 0 .2em !important; color: var(--text-2); }
.credits .ct { color: var(--text); font-weight: 600; }
.credits a { overflow-wrap: anywhere; }
.entry[hidden], .pairs li[hidden] { display: none; }

/* ------------------------------------------------------------ search results */
.results {
  position: fixed; z-index: 60;
  top: 108px; left: 12px;
  width: min(560px, calc(100vw - 24px));
  max-height: min(70vh, 640px);
  display: flex; flex-direction: column;
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.results[hidden] { display: none; }
.res-list { overflow-y: auto; padding: 6px; margin: 0; list-style: none; scrollbar-width: thin; }
.res-list a {
  display: block; padding: 9px 12px; border-radius: var(--radius);
  text-decoration: none; color: var(--text);
}
.res-list li.on a { background: var(--bg-hover); }
.res-top { display: flex; gap: 8px; align-items: baseline; }
.res-kind { flex: none; font-size: 12px; font-weight: 500; color: var(--text-3); padding-top: 1px; min-width: 60px; }
.res-h { font-weight: 600; font-size: 14px; line-height: 1.35; }
.res-where { margin: 1px 0 0 68px; font-size: 12px; color: var(--text-3); }
.res-x { margin: 3px 0 0 68px; font-size: 12.8px; line-height: 1.45; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.results mark, .reader mark.hl { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.res-foot { padding: 8px 14px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--text-3); display: flex; gap: 12px; flex-wrap: wrap; }
.res-empty { padding: 18px 16px; color: var(--text-2); font-size: 14px; margin: 0; }

/* ------------------------------------------------------------ settings and shortcuts panels */
.settings, .keys-panel {
  position: fixed; z-index: 60;
  top: 56px; right: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100vh - 72px); overflow-y: auto;
  padding: 6px 18px 16px;
  background: var(--bg-raise);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.settings[hidden], .keys-panel[hidden] { display: none; }
.set-head { display: flex; align-items: center; justify-content: space-between; margin: 4px -8px 4px 0; }
.set-head p { margin: 0; font-weight: 650; font-size: 14px; letter-spacing: -.01em; }
.set-group { border: 0; padding: 0; margin: 10px 0 14px; }
.set-group legend, .set-range span { padding: 0; margin-bottom: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button, .fonts button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 8px 4px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  background: transparent; cursor: pointer; font-size: 12.5px;
}
.seg button:hover, .fonts button:hover { background: var(--bg-hover); }
.seg button[aria-pressed="true"], .fonts button[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.sw { width: 26px; height: 18px; border-radius: 2px; border: 1px solid rgba(0, 0, 0, .15); }
.sw-light { background: #f6f6f3; }
.sw-sepia { background: #f4ecdc; }
.sw-dark { background: #121212; }
.sw-auto { background: linear-gradient(135deg, #f6f6f3 50%, #121212 50%); }
.fonts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.fonts button { font-size: 15px; gap: 2px; padding: 9px 4px 7px; }
.fonts small { font: 11px var(--ui); color: var(--text-3); text-align: center; }
.set-range { display: block; margin: 0 0 12px; }
.set-range span { display: flex; justify-content: space-between; }
.set-range output { font-weight: 400; color: var(--text-3); font-variant-numeric: tabular-nums; }
.set-range input { width: 100%; accent-color: var(--text); }
.set-check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; margin: 4px 0 14px; }
.set-check input { accent-color: var(--text); width: 16px; height: 16px; }
.set-foot { display: flex; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--rule); }
.btn-text { border: 0; background: none; padding: 4px 0; cursor: pointer; font-size: 12.5px; color: var(--accent); }
.keylist { margin: 6px 0 0; }
.keylist div { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--rule); }
.keylist div:first-child { border-top: 0; }
.keylist dt { display: flex; gap: 4px; flex-wrap: wrap; }
.keylist dd { margin: 0; font-size: 13.5px; color: var(--text-2); }
.keys-note { margin: 10px 0 0; font-size: 12px; color: var(--text-3); }

/* ------------------------------------------------------------ lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: 24px;
  background: rgba(10, 10, 10, .9);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox figure { margin: 0; max-width: 100%; max-height: 100%; display: flex; flex-direction: column; align-items: center; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 120px); border-radius: 2px; cursor: zoom-out; filter: none; }
.lightbox figcaption { max-width: 760px; color: #ddd; text-align: center; }
.lightbox figcaption .fig-label { color: #fff; }
.lb-close { position: absolute; top: 12px; right: 12px; color: #fff; }
.lb-close:hover { background: rgba(255, 255, 255, .12); color: #fff; }

/* ------------------------------------------------------------ small screens */
@media (max-width: 959px) {
  .sidebar {
    position: fixed; z-index: 70; left: 0; top: 0;
    width: min(340px, 88vw);
    transform: translateX(-102%);
    transition: transform .28s cubic-bezier(.16, 1, .3, 1);
    box-shadow: var(--shadow);
  }
  html.sb-hidden .sidebar { display: flex; }
  .sb-open .sidebar { transform: none; }
  .sb-open .scrim { display: block; position: fixed; inset: 0; z-index: 65; background: rgba(0, 0, 0, .35); }
  .results { top: 104px; left: 12px; z-index: 75; }
  .reader { padding: 16px 18px 32px; }
  .anchor { display: none; }
  .pager { grid-template-columns: 1fr; padding: 0 18px 60px; gap: 8px; }
  .pg.next { grid-column: 1; justify-content: flex-start; text-align: left; }
  .pg.next small { justify-content: flex-start; }
  .home .hero { padding: 8px 12px 0; }
  .contents { padding: 16px 18px 60px; }
}
@media (max-width: 640px) {
  .fonts { grid-template-columns: repeat(2, 1fr); }
  .part-row ol, .part-row ul { padding-left: 0; }
  #keys-btn { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .part .pc, .tw .ic, .part-row h3 .chip, .toast, .btn { transition: none; }
  .reader :target { animation: none; background: var(--accent-soft); }
}

/* contents toolbar: expand/collapse all, reset read marks */
.toc-tools { display: flex; justify-content: space-between; gap: 6px; padding: 4px 10px 6px; border-bottom: 1px solid var(--rule); }
.tool {
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 8px; margin: 0;
  border: 0; border-radius: var(--radius); background: none;
  font: 500 12.5px var(--ui); color: var(--text-2); cursor: pointer;
}
.tool:hover { background: var(--bg-hover); color: var(--text); }
.tool .ic { width: 13px; height: 13px; }
.tool .when-open, .tool .when-closed { display: inline-flex; align-items: center; gap: 5px; }
#toc-expand .when-open, #toc-expand.all-open .when-closed { display: none; }
#toc-expand.all-open .when-open { display: inline-flex; }

/* ---------- text: hyphenation and better line breaks ---------- */
.reader p, .reader li, .reader dd {
  hyphens: auto; -webkit-hyphens: auto;
  hyphenate-limit-chars: 7 3 3;
  text-wrap: pretty;
}
.reader figcaption, .box p { text-wrap: pretty; }
.reader code, .reader a[href^="http"] { hyphens: manual; -webkit-hyphens: manual; }

/* ---------- diagrams ---------- */
:root { --d-c1:#2f6db5; --d-c2:#2e8a6e; --d-c3:#c4860f; --d-c4:#7a5bb5; --d-c1s:#dce8f6; --d-c2s:#d9efe6; --d-c3s:#f7e9c9; --d-c4s:#e8e1f4; }
:root[data-theme="dark"] { --d-c1:#7fb0ee; --d-c2:#6cc6a5; --d-c3:#e6b65a; --d-c4:#ae95e0; --d-c1s:#22344a; --d-c2s:#1f3a31; --d-c3s:#3d3220; --d-c4s:#2f2840; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] { --d-c1:#7fb0ee; --d-c2:#6cc6a5; --d-c3:#e6b65a; --d-c4:#ae95e0; --d-c1s:#22344a; --d-c2s:#1f3a31; --d-c3s:#3d3220; --d-c4s:#2f2840; }
}
.dg text{fill:var(--text)}.dg text:not([font-family]){font-family:var(--ui)}
.dg .f-ink{fill:var(--text)}.dg .f-ink2{fill:var(--text-2)}.dg .f-mute{fill:var(--text-3)}
.dg .f-rule{fill:var(--rule)}.dg .f-paper{fill:var(--bg-raise)}.dg .f-box{fill:var(--box)}
.dg .f-accent{fill:var(--accent)}.dg .f-accent-soft{fill:var(--accent-soft)}
.dg .f-c1{fill:var(--d-c1)}.dg .f-c2{fill:var(--d-c2)}.dg .f-c3{fill:var(--d-c3)}.dg .f-c4{fill:var(--d-c4)}
.dg .f-c1s{fill:var(--d-c1s)}.dg .f-c2s{fill:var(--d-c2s)}.dg .f-c3s{fill:var(--d-c3s)}.dg .f-c4s{fill:var(--d-c4s)}
.dg .f-none{fill:none}.dg .s-none{stroke:none}
.dg .s-ink{stroke:var(--text)}.dg .s-ink2{stroke:var(--text-2)}.dg .s-mute{stroke:var(--text-3)}
.dg .s-rule{stroke:var(--rule)}.dg .s-accent{stroke:var(--accent)}
.dg .s-c1{stroke:var(--d-c1)}.dg .s-c2{stroke:var(--d-c2)}.dg .s-c3{stroke:var(--d-c3)}.dg .s-c4{stroke:var(--d-c4)}
.dg-fig { margin: 2.2em 0; }
.dg-wrap { cursor: zoom-in; }
.dg-wrap svg { display: block; width: 100%; height: auto; }
@media (max-width: 640px) {
  .dg-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; -webkit-overflow-scrolling: touch; }
  .dg-wrap svg { min-width: 560px; }
}
.lightbox .lb-svg { width: min(1100px, 100%); max-height: calc(100vh - 140px); overflow: auto; padding: 20px; background: var(--bg); border-radius: 6px; cursor: zoom-out; }
.lightbox .lb-svg svg { display: block; width: 100%; height: auto; }
.lightbox .lb-svg[hidden] { display: none; }

/* placeholders: one quiet line that opens */
.ph > summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; list-style: none; cursor: pointer; }
.ph > summary::-webkit-details-marker { display: none; }
.ph .ph-kind { margin: 0 !important; }
.ph-more { font: 13px var(--ui); color: var(--accent); }
.ph-more::after { content: " ▸"; }
.ph[open] .ph-more::after { content: " ▾"; }
.ph[open] .ph-desc { margin-top: .6em !important; }

/* glossary terms defined in other chapters */
.gl {
  text-decoration: underline dotted;
  text-decoration-color: color-mix(in srgb, var(--text) 45%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: .22em;
  cursor: help;
  border-radius: 2px;
}
.gl:hover, .gl:focus-visible, .gl.on { text-decoration-color: var(--accent); background: var(--accent-soft); outline: none; }
.gl-pop strong { font-weight: 650; }
.gl-pop .src { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--rule); font-size: 12.5px; }
.gl-pop .src a { text-decoration: none; }
.gl-pop .src a:hover { text-decoration: underline; }

/* cross-reference previews */
.xpop { max-width: min(360px, calc(100vw - 24px)); pointer-events: none; }
.xpop .xp-part { margin: 0 0 2px; font-size: 12px; color: var(--text-3); }
.xpop .xp-title { margin: 0 0 6px; font-size: 15px; font-weight: 650; line-height: 1.3; letter-spacing: -.01em; }
.xpop .xp-text { margin: 0; color: var(--text-2); font-family: var(--read-font); font-size: 14px; line-height: 1.5; }

/* time left in the chapter */
.time-left { flex: none; font: 12.5px var(--ui); color: var(--text-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.time-left:empty { display: none; }
@media (max-width: 420px) { .time-left { display: none; } }

/* section links */
.reader h2 .anchor, .reader h3 .anchor { cursor: copy; }
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60;
  transform: translate(-50%, 12px); opacity: 0;
  padding: 8px 14px; border-radius: var(--radius);
  background: var(--text); color: var(--bg);
  font: 500 13px var(--ui);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
