/* A neutral reading theme. Public custom properties are the customization surface. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #252933;
  --muted: #616b7a;
  --line: #e3e7ed;
  --accent: #285fc5;
  --code: #f5f7fa;
  --surface: #edf3ff;
  --selection: #dce8ff;
  --shade: rgb(16 24 40 / 32%);
  --font-ui: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", sans-serif;
  --font-reading: var(--font-ui);
  --font-code: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", monospace;
  --book-width: 1440px;
  --navigation-width: 280px;
  --reading-width: 750px;
  --header-height: 60px;
  --content-top: 28px;
  font: 16px/1.6 var(--font-ui);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #15171b;
    --fg: #e3e7ef;
    --muted: #a3adbd;
    --line: #303640;
    --accent: #9abbff;
    --code: #1e2229;
    --surface: #202b40;
    --selection: #2e4265;
    --shade: rgb(0 0 0 / 56%);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15171b;
  --fg: #e3e7ef;
  --muted: #a3adbd;
  --line: #303640;
  --accent: #9abbff;
  --code: #1e2229;
  --surface: #202b40;
  --selection: #2e4265;
  --shade: rgb(0 0 0 / 56%);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scrollbar-gutter: stable; }
body { display: flex; flex-direction: column; min-height: 100dvh; margin: 0; background: var(--bg); color: var(--fg); }
::selection { background: var(--selection); color: var(--fg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: .2em; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
svg { max-width: 100%; }

/* Book identity comes from its title; chrome remains visually restrained. */
.book-header { flex-shrink: 0; position: sticky; top: 0; z-index: 10; background: var(--bg); }
.header-inner, .book-layout {
  width: min(var(--book-width), calc(100% - 48px));
  margin-inline: auto;
}
.header-inner {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}
.book-brand { flex: 1; min-width: 0; color: var(--fg); font-size: 1.0625rem; font-weight: 600; overflow-wrap: anywhere; }
.book-brand:hover { text-decoration: none; color: var(--accent); }
.text-button {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
}
.text-button:hover { color: var(--accent); background: var(--code); }
#theme-toggle { display: none; }
.js #theme-toggle { display: inline-flex; }
#nav-toggle, #nav-close { display: none; }
.outline-hide, .mobile-outline[open] .outline-show { display: none; }
.mobile-outline[open] .outline-hide { display: inline; }
.reading-progress { display: none; position: fixed; inset: 0 0 auto; height: 2px; z-index: 30; pointer-events: none; }
.js .reading-progress { display: block; }
.reading-progress span { display: block; height: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; }
.skip-link { position: fixed; top: 12px; left: 16px; z-index: 40; padding: 10px 16px; background: var(--bg); border: 1px solid var(--accent); transform: translateY(-180%); }
.skip-link:focus { transform: translateY(0); }

/* Chapter navigation and the current page outline frame the reading column. */
.book-layout {
  --navigation-min-width: 240px;
  --navigation-max-width: 420px;
  /* Reserve 480px for reading, 180px for the outline and two 24px gaps. */
  --navigation-content-space: 708px;
  --navigation-track: clamp(var(--navigation-min-width), var(--navigation-user-width, var(--navigation-width)), min(var(--navigation-max-width), calc(100% - var(--navigation-content-space))));
  flex: 1;
  display: grid;
  grid-template-columns: var(--navigation-track) minmax(0, 1fr) 180px;
  grid-template-rows: 1fr auto;
  gap: 24px;
  align-items: start;
}
.book-layout:not(:has(.page-outline)) {
  --navigation-content-space: 504px;
  grid-template-columns: var(--navigation-track) minmax(0, 1fr);
}
.book-navigation, .page-outline {
  position: sticky;
  top: calc(var(--header-height) + var(--content-top));
  max-height: calc(100dvh - var(--header-height) - var(--content-top));
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-gutter: stable;
  padding-block: 0 24px;
  font-size: .875rem;
}
.book-navigation { --nav-label-padding: 5px; grid-column: 1; grid-row: 1; padding-right: 12px; border-right: 1px solid var(--line); }
.page-outline { grid-column: 3; grid-row: 1; }
.navigation-resize { display: none; }
.js .navigation-resize {
  display: flex;
  align-items: center;
  justify-content: center;
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  align-self: stretch;
  position: sticky;
  top: calc(var(--header-height) + var(--content-top));
  width: 12px;
  max-height: calc(100dvh - var(--header-height) - var(--content-top));
  transform: translateX(12px);
  border-radius: 4px;
  cursor: col-resize;
  touch-action: none;
}
.navigation-resize::after { content: ""; width: 3px; height: 32px; border-radius: 2px; background: var(--muted); opacity: .5; }
.navigation-resize:hover, .navigation-resize:focus-visible, .nav-resizing .navigation-resize { background: var(--surface); }
.navigation-resize:hover::after, .navigation-resize:focus-visible::after, .nav-resizing .navigation-resize::after { background: var(--accent); opacity: 1; }
.nav-resizing, .nav-resizing * { cursor: col-resize !important; user-select: none !important; }
.rail-heading { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; background: var(--bg); }
.rail-label { margin: 0 0 12px; color: var(--muted); font-size: .6875rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.navigation-tree, .nav-children, .outline-list { list-style: none; margin: 0; padding: 0; }
.nav-part { margin: 28px 10px 10px; font-size: .875rem; font-weight: 700; line-height: 1.5; letter-spacing: .02em; color: var(--fg); }
.nav-part:first-child { margin-top: 0; }
.nav-separator { margin: 14px 10px; }
.nav-separator hr { margin: 0; border: 0; border-top: 1px solid var(--line); }
.nav-item { position: relative; margin-block: 2px; }
.nav-item > a, .nav-label > a, .nav-chapter, .nav-draft { display: block; padding: var(--nav-label-padding) 10px; border-radius: 5px; border-left: 1px solid transparent; color: var(--muted); overflow-wrap: anywhere; }
.nav-item > a, .nav-label > a { color: var(--fg); }
.nav-item > a:hover, .nav-label > a:hover { color: var(--fg); background: var(--code); text-decoration: none; }
.nav-item > [aria-current="page"], .nav-label > [aria-current="page"] { color: var(--accent); border-left-color: var(--accent); background: var(--surface); font-weight: 600; }
.nav-label { display: flex; align-items: flex-start; min-height: 32px; padding-right: 28px; }
.nav-label > a, .nav-label > .nav-chapter, .nav-label > .nav-draft { flex: 1; min-width: 0; }
.nav-disclosure { position: absolute; top: 0; right: 0; display: flex; width: 28px; min-height: 32px; border-radius: 5px; cursor: pointer; list-style: none; }
.nav-disclosure::-webkit-details-marker { display: none; }
.nav-disclosure::after { content: ""; width: 12px; height: 1.6em; margin: var(--nav-label-padding) 8px 0; background: var(--muted); mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M4 2l4 4-4 4' fill='none' stroke='black' stroke-width='1.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px 12px no-repeat; }
.nav-branch[open] > .nav-disclosure::after { transform: rotate(90deg); }
.nav-disclosure:hover::after { background: var(--fg); }
.nav-children { margin: 3px 0 6px 5px; padding-left: 6px; border-left: 1px solid var(--line); }
.outline-list a { display: block; padding: 4px 0 4px 12px; border-left: 1px solid var(--line); color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.outline-list a:hover { color: var(--fg); text-decoration: none; }
.outline-list [aria-current="location"] { color: var(--accent); border-left-color: var(--accent); }
.outline-list [data-level="1"] { font-weight: 600; }
.outline-list [data-level="3"] a { padding-left: 24px; }
.outline-list [data-level="4"] a { padding-left: 32px; }
.outline-list [data-level="5"] a { padding-left: 40px; }
.outline-list [data-level="6"] a { padding-left: 48px; }
.mobile-outline { display: none; }

/* Reference-sized typography, with a little extra leading for CJK text. */
#page-content { grid-column: 2; grid-row: 1; min-width: 0; width: 100%; max-width: var(--reading-width); justify-self: start; padding-block: var(--content-top) 56px; scroll-margin-top: calc(var(--header-height) + 24px); }
.breadcrumbs { margin-bottom: 18px; font-size: .75rem; color: var(--muted); }
.breadcrumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 10px; padding: 0; margin: 0; }
.breadcrumbs li { min-width: 0; overflow-wrap: anywhere; }
.breadcrumbs li + li::before { content: "/"; margin-right: 10px; color: var(--muted); }
.breadcrumbs a { color: var(--muted); }
.prose { font: 1rem/1.6 var(--font-reading); overflow-wrap: anywhere; }
.prose :is(h1, h2, h3, h4, h5, h6, [id], [role="heading"]), .code-block { scroll-margin-top: calc(var(--header-height) + 24px); }
.prose :is(h1, h2, h3, h4, h5, h6) { color: var(--fg); font-weight: 650; line-height: 1.35; text-wrap: balance; }
.prose h1 { margin: 0 0 20px; font-size: 2rem; line-height: 1.3; letter-spacing: -.025em; }
.prose h2 { margin: 2em 0 .7em; padding-bottom: .3em; border-bottom: 1px solid var(--line); font-size: 1.5rem; letter-spacing: -.015em; }
.prose h3 { margin: 1.75em 0 .6em; font-size: 1.17rem; }
.prose :is(h4, h5, h6) { margin: 1.5em 0 .6em; font-size: 1rem; }
.prose h5 { font-size: .875rem; }
.prose h6 { font-size: .8125rem; }
.prose :is(p, .notist-paragraph) { margin: 0 0 1em; }
.prose a { text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: .2em; text-decoration-thickness: 1px; }
.prose a:hover { text-decoration-color: var(--accent); }
.prose :is(ul, ol) { padding-left: 1.5em; margin: .75em 0 1em; }
.prose li { padding-left: .2em; margin-block: .125em; }
.prose li::marker { color: var(--muted); }
.prose li > p { margin-bottom: .25em; }
.prose li :is(ul, ol) { margin-block: .4em; }
.prose strong { font-weight: 700; }
.prose hr { width: 100%; margin: 2em 0; border: 0; border-top: 1px solid var(--line); }
.prose :is(blockquote, .notist-callout) { margin: 1.25em 0; padding: 4px 0 4px 18px; border-left: 2px solid var(--accent); color: var(--muted); }
.prose :is(blockquote, .notist-callout) > :last-child { margin-bottom: 0; }
.prose .notist-callout { padding: 12px 18px; background: var(--surface); color: var(--fg); font-size: 1rem; }
.prose :is(img, video) { display: block; max-width: 100%; height: auto; margin-block: 1.25em; }
.prose figure { margin: 1.25em 0; }
.prose figcaption { margin-top: 8px; color: var(--muted); font: .8125rem/1.6 var(--font-ui); text-align: center; }
.prose :is(iframe, canvas) { max-width: 100%; }
.prose :is(dt, dd) { margin-block: .5em; }
.prose dt { font-weight: 600; }
.prose dd { margin-left: 1.5em; }

/* Code remains selectable and horizontally scrollable, even on narrow screens. */
.prose code { padding: .15em .35em; border-radius: 6px; background: var(--code); font: .875em/1.6 var(--font-code); }
.prose pre { margin: 1.25em 0; padding: 16px 18px; border: 1px solid var(--line); border-radius: 4px; background: var(--code); overflow: auto; overscroll-behavior-x: contain; tab-size: 4; font-size: .875rem; line-height: 1.6; }
.prose pre code { padding: 0; background: none; font: inherit; font-family: var(--font-code); white-space: pre; overflow-wrap: normal; }
.code-block { min-width: 0; margin: 1.25em 0; border: 1px solid var(--line); border-radius: 4px; background: var(--code); }
.code-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 10px 4px 18px; border-bottom: 1px solid var(--line); font: .6875rem/1.6 var(--font-ui); color: var(--muted); }
.code-language { letter-spacing: .06em; text-transform: uppercase; }
.copy-code { min-height: 32px; padding: 4px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: .75rem; }
.copy-code:hover { color: var(--accent); background: var(--bg); }
.prose .code-block pre { margin: 0; border: 0; border-radius: 0; background: none; }
.prose table { display: block; width: 100%; overflow: auto; margin: 1.25em 0; border-collapse: collapse; font: .875rem/1.7 var(--font-ui); }
.prose :is(td, th) { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose :is(td, th) > :last-child { margin-bottom: 0; }
.prose th { border-top: 1px solid var(--line); color: var(--fg); font-weight: 600; background: var(--surface); }
.prose tbody tr:last-child td { border-bottom-color: var(--line); }
.prose .footnotes { margin-top: 2em; padding-top: 1em; border-top: 1px solid var(--line); color: var(--muted); font-size: .875rem; }

.adjacent { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--line); }
.adjacent-link { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; color: var(--fg); overflow-wrap: anywhere; }
.adjacent-link:hover { text-decoration: none; color: var(--accent); }
.adjacent-label { color: var(--muted); font-size: .6875rem; letter-spacing: .08em; text-transform: uppercase; }
.adjacent-title { font: 1rem/1.5 var(--font-reading); }
.adjacent-link.next { grid-column: 2; text-align: right; align-items: flex-end; }
.book-footer { grid-column: 2; width: 100%; max-width: var(--reading-width); justify-self: start; display: flex; justify-content: space-between; gap: 24px; padding-block: 16px 24px; border-top: 1px solid var(--line); font-size: .75rem; color: var(--muted); }
.book-footer a { color: var(--muted); }
.footer-brand { color: var(--fg); }
.nav-backdrop { position: fixed; inset: 0; z-index: 19; background: var(--shade); }

@media (width < 1320px) {
  .book-layout { --navigation-content-space: 504px; grid-template-columns: var(--navigation-track) minmax(0, 1fr); }
  .page-outline { display: none; }
  .mobile-outline { display: block; margin-bottom: 18px; border-block: 1px solid var(--line); font-size: .8125rem; }
  .mobile-outline summary { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); cursor: pointer; list-style: none; }
  .mobile-outline summary::-webkit-details-marker { display: none; }
  .mobile-outline .outline-list { margin-block: 8px 12px; }
  .mobile-outline .outline-list a { min-height: 36px; padding-block: 6px; }
}

@media (max-width: 760px) {
  :root { --header-height: 56px; --content-top: 20px; }
  .header-inner, .book-layout { width: calc(100% - 40px); }
  .header-inner { gap: 10px; }
  .book-brand { font-size: .9375rem; }
  .book-layout { display: flex; flex-direction: column; gap: 0; align-items: stretch; }
  .js .navigation-resize { display: none; }
  #page-content { flex: 1; padding-bottom: 40px; }
  .breadcrumbs { margin-bottom: 16px; font-size: .6875rem; }
  .prose pre { padding: 14px 16px; }
  .code-toolbar { padding-left: 16px; }
  .adjacent { gap: 20px; margin-top: 32px; }
  .book-footer { padding-bottom: 20px; }
  /* Without JavaScript the contents are an ordinary, fully usable block. */
  .book-navigation { --nav-label-padding: 8px; position: static; max-height: none; padding: 16px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .js #nav-toggle, .js #nav-close { display: inline-flex; }
  .js .book-navigation { display: none; position: fixed; inset: 0 auto 0 0; z-index: 20; width: min(340px, calc(100% - 48px)); max-height: none; height: 100dvh; padding: 0 20px 20px; border-right: 1px solid var(--line); border-bottom: 0; background: var(--bg); }
  .js body.nav-open .book-navigation { display: block; }
  .js body.nav-open { overflow: hidden; }
  .js .rail-heading { margin-bottom: 12px; padding-block: 12px 4px; }
  .js .rail-heading .rail-label { margin: 0; }
  .book-navigation .nav-item > a, .book-navigation .nav-label > a { min-height: 44px; }
  .book-navigation .nav-label { min-height: 44px; }
}

@media (prefers-reduced-motion: no-preference) {
  .text-button, .nav-item > a, .copy-code { transition: color 150ms ease, background-color 150ms ease; }
}

@media print {
  :root, :root[data-theme] {
    color-scheme: light;
    --bg: #fff;
    --fg: #000;
    --muted: #444;
    --line: #ccc;
    --accent: #000;
    --code: #f4f4f4;
    --surface: #f4f4f4;
  }
  body { display: block; min-height: 0; background: white; color: black; }
  .book-header, .book-navigation, .navigation-resize, .page-outline, .mobile-outline, .breadcrumbs, .adjacent, .book-footer, .reading-progress, .nav-backdrop, .skip-link, .code-toolbar { display: none !important; }
  .book-layout { display: block; width: 100%; }
  #page-content { padding: 0; }
  .prose { color: black; font-size: 11pt; }
  .prose :is(h1, h2, h3, h4, h5, h6) { color: black; break-after: avoid; }
  .prose :is(pre, code, th, .notist-callout) { background: #f4f4f4; color: black; }
  .prose pre { white-space: pre-wrap; }
  .prose pre code { white-space: pre-wrap; overflow-wrap: anywhere; }
  .prose table { display: table; overflow: visible; }
  .prose :is(table, pre, img, blockquote) { break-inside: avoid; }
  .prose a { color: black; }
}
