:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --raised: #eef0f2;
  --ink: #1d2126;
  --muted: #5f6672;
  --line: #dde0e4;
  --accent: #0b6bcb;
  --accent-soft: #e3eefc;
  --warn: #9a6700;
  --warn-soft: #fdf3d7;
  --shadow: rgba(15, 20, 30, 0.14);
  --radius: 6px;
  --sidebar-w: 296px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #1e2023;
  --panel: #26282c;
  --raised: #2d3035;
  --ink: #e3e5e8;
  --muted: #969ba3;
  --line: #383b41;
  --accent: #4c9aff;
  --accent-soft: #1c2b40;
  --warn: #d9a441;
  --warn-soft: #33281a;
  --shadow: rgba(0, 0, 0, 0.5);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e2023;
    --panel: #26282c;
    --raised: #2d3035;
    --ink: #e3e5e8;
    --muted: #969ba3;
    --line: #383b41;
    --accent: #4c9aff;
    --accent-soft: #1c2b40;
    --warn: #d9a441;
    --warn-soft: #33281a;
    --shadow: rgba(0, 0, 0, 0.5);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 20px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent); color: #fff; }

.shell { display: flex; min-height: 100vh; }

/* ---------------------------------------------------------------- sidebar */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 20px 16px 40px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.brand { display: block; margin-bottom: 16px; color: var(--ink); }
.brand strong { display: block; font-size: 17px; letter-spacing: -0.01em; }
.brand span { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.brand:hover { text-decoration: none; }

.searchbox { position: relative; margin-bottom: 8px; }
#q {
  width: 100%;
  padding: 8px 30px 8px 10px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
#q::placeholder { color: var(--muted); }
#q:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#q::-webkit-search-cancel-button { display: none; }
.kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font: 11px/1 var(--mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 3px 5px;
  pointer-events: none;
}
#q:focus ~ .kbd { display: none; }

.hint { font-size: 11px; color: var(--muted); margin: 0 0 12px; display: flex; gap: 10px; }
.hint span { white-space: nowrap; }
.hint b { font-family: var(--mono); font-weight: 400; color: var(--ink); }

/* ------------------------------------------------------------ search list */

#results { display: none; margin-bottom: 20px; }
#results.on { display: block; }
#nav.off { display: none; }
.rescount { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 4px 2px 8px; }
.result {
  display: block;
  padding: 6px 8px;
  border-radius: 4px;
  border-left: 2px solid transparent;
}
.result:hover { background: var(--raised); text-decoration: none; }
.result.active { background: var(--accent-soft); border-left-color: var(--accent); }
.result b { display: block; font-size: 14px; color: var(--ink); font-weight: 500; }
.result b mark { background: none; color: var(--accent); font-weight: 700; }
.result span { display: block; font-size: 11px; color: var(--muted); }
.result em { font-style: normal; font-size: 11px; color: var(--muted); display: block; margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result em mark { background: none; color: var(--ink); }
.noresult { font-size: 13px; color: var(--muted); padding: 10px 8px; }

/* --------------------------------------------------------- preview popup */

.preview {
  position: fixed;
  left: calc(var(--sidebar-w) + 14px);
  width: 330px;
  max-height: 78vh;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 44px var(--shadow);
  padding: 16px 18px;
  z-index: 40;
  display: none;
  pointer-events: none;
}
.preview.on { display: block; }
.preview .pv-crumb { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.preview .pv-title { font-size: 17px; font-weight: 600; margin: 3px 0 8px; line-height: 1.25; }
.preview .pv-chips { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 10px; }
.preview img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 10px; display: block; }
.preview .pv-ex { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 0; }
.preview .pv-ex mark { background: var(--accent-soft); color: var(--ink); }
.preview .pv-meta { font-size: 11px; color: var(--muted); margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); }
@media (max-width: 1100px) { .preview { display: none !important; } }

/* --------------------------------------------------------------- nav tree */

nav .sec { margin-bottom: 2px; }
nav .sechead {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px 4px 0;
  margin: 6px 0 2px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
nav .sechead a { color: inherit; flex: 1 1 auto; min-width: 0; padding: 2px 4px; border-radius: 4px; }
nav .sechead a:hover { color: var(--ink); background: var(--raised); text-decoration: none; }
nav .sechead .tw {
  width: 18px; height: 18px; flex: 0 0 18px;
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--muted); font-size: 10px; line-height: 1;
  transition: transform 0.12s ease; border-radius: 3px;
}
nav .sechead .tw:hover { color: var(--ink); background: var(--raised); }
nav .sec.closed .sechead .tw { transform: rotate(-90deg); }
nav .sechead .n { font-weight: 400; letter-spacing: 0; opacity: 0.6; padding-left: 4px; }
nav .sechead.here { color: var(--ink); }
nav .sec.closed .secbody { display: none; }
nav .secbody { padding-bottom: 4px; }
nav h3 { font-size: 11px; color: var(--muted); margin: 8px 0 3px 22px; font-weight: 500; opacity: 0.85; }
nav ul { list-style: none; margin: 0; padding: 0; }
nav li a {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 8px 3px 22px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.4;
}
nav li a > .ico { margin-left: -14px; }
nav li a:hover { background: var(--raised); text-decoration: none; }
nav li a.current { background: var(--accent); color: #fff; }
nav li a.stub { color: var(--muted); }
nav li a.stub::after {
  content: "stub";
  margin-left: auto;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
  padding-left: 6px;
  flex: 0 0 auto;
}
nav li a.current.stub::after { color: #fff; opacity: 0.85; }

/* ----------------------------------------------------------------- icons */

.ico {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border-radius: 3px;
  object-fit: contain;
  vertical-align: -4px;
}
.ico.big { width: 26px; height: 26px; flex: 0 0 26px; border-radius: 4px; }
.card li .ico { margin-right: 6px; }
.result .ico { float: left; margin: 2px 8px 0 0; }
.titlerow { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.titlerow h1 { margin: 0; }
.pageicon {
  width: 54px; height: 54px; flex: 0 0 54px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  object-fit: contain;
  padding: 3px;
}

.recent { margin-bottom: 6px; }
.recent .sechead { cursor: default; }
.recent .sechead:hover { background: none; color: var(--muted); }

/* ---------------------------------------------------------------- content */

main { flex: 1; min-width: 0; display: flex; justify-content: center; gap: 34px; }
article { width: 100%; max-width: 780px; padding: 44px 40px 100px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
h1 { font-size: 32px; line-height: 1.2; margin: 0 0 10px; letter-spacing: -0.02em; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 26px; }
.chip {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}
.chip.src { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.chip.stub { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
a.chip:hover { text-decoration: none; background: var(--accent); color: #fff; }

.body h2 { font-size: 22px; margin: 34px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.body h3 { font-size: 17px; margin: 26px 0 8px; }
.body h4 { font-size: 15px; margin: 20px 0 6px; color: var(--muted); }
.body p { margin: 0 0 14px; }
.body ul, .body ol { margin: 0 0 14px; padding-left: 22px; }
.body li { margin-bottom: 4px; }
.body img { max-width: 100%; height: auto; border-radius: var(--radius); border: 1px solid var(--line); display: block; margin: 14px 0; }
.body hr { border: 0; border-top: 1px solid var(--line); margin: 28px 0; }
.body code { font-family: var(--mono); font-size: 0.88em; background: var(--panel); padding: 1px 5px; border-radius: 4px; }
.body pre { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; overflow-x: auto; }
.body pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.body blockquote { margin: 0 0 16px; padding: 2px 0 2px 16px; border-left: 3px solid var(--line); color: var(--muted); }
.body a.lightbox { display: block; }
.body a.lightbox:hover img { border-color: var(--accent); }

.anchor { opacity: 0; margin-left: 8px; color: var(--muted); font-weight: 400; text-decoration: none; }
h1:hover .anchor, h2:hover .anchor, h3:hover .anchor, h4:hover .anchor { opacity: 1; }
:target { scroll-margin-top: 20px; }

.table-wrap { overflow-x: auto; margin: 0 0 18px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { border: 1px solid var(--line); padding: 8px 11px; text-align: left; vertical-align: top; }
th { background: var(--panel); font-weight: 600; }

.callout { border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--panel); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 18px; }
.callout-title { font-weight: 600; font-size: 14px; margin-bottom: 6px; display: flex; gap: 8px; align-items: baseline; }
.callout-icon { color: var(--accent); }
.callout-body > :last-child { margin-bottom: 0; }
.callout-warning, .callout-important, .callout-danger { border-left-color: var(--warn); }
.callout-warning .callout-icon, .callout-important .callout-icon, .callout-danger .callout-icon { color: var(--warn); }

.missing { color: var(--muted); border-bottom: 1px dotted var(--muted); cursor: help; }

/* ---------------------------------------------------------------- gallery */

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 0 0 24px; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; margin: 0; background: var(--panel); aspect-ratio: 1; object-fit: contain; padding: 8px; }
.gallery figcaption { font-size: 11px; color: var(--muted); margin-top: 5px; font-family: var(--mono); word-break: break-word; }

/* --------------------------------------------------------- section index */

.grouplist { margin: 0 0 30px; }
.grouplist h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); border: 0; margin: 26px 0 8px; padding: 0; }
.grouplist ul { list-style: none; margin: 0; padding: 0; }
.grouplist li { border-bottom: 1px solid var(--line); padding: 8px 2px; display: flex; align-items: baseline; gap: 10px; }
.grouplist li:last-child { border-bottom: 0; }
.grouplist li .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ------------------------------------------------------- on-page contents */

.toc { width: 214px; flex: 0 0 214px; position: sticky; top: 0; align-self: flex-start; padding: 50px 20px 40px 0; max-height: 100vh; overflow-y: auto; }
.toc h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li a { display: block; font-size: 13px; line-height: 1.4; padding: 3px 0 3px 10px; color: var(--muted); border-left: 2px solid var(--line); }
.toc li a:hover { color: var(--ink); border-left-color: var(--accent); text-decoration: none; }
.toc li a.here { color: var(--ink); border-left-color: var(--accent); }
.toc li.sub a { padding-left: 22px; font-size: 12px; }
@media (max-width: 1180px) { .toc { display: none; } }

/* ------------------------------------------------------------ page footer */

.pagefoot { margin-top: 56px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }
.pagefoot h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 8px; }
.pagefoot ul { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 6px 14px; }
.srcline { color: var(--muted); font-size: 12px; font-family: var(--mono); word-break: break-all; }

.seq { display: flex; gap: 12px; margin: 40px 0 0; }
.seq a {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--panel);
}
.seq a:hover { border-color: var(--accent); text-decoration: none; }
.seq a span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.seq a b { display: block; font-size: 14px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seq a.next { text-align: right; }

#top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  display: none;
  z-index: 30;
}
#top.on { display: block; }
#top:hover { color: var(--ink); border-color: var(--accent); }

/* ------------------------------------------------------------------- home */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin: 26px 0 40px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; background: var(--panel); }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.card ul { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.card li { margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .count { color: var(--muted); font-size: 12px; font-weight: 400; }
.stats { display: flex; gap: 28px; flex-wrap: wrap; margin: 18px 0 0; padding: 0; list-style: none; }
.stats b { display: block; font-size: 26px; line-height: 1.1; }
.stats span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; }

/* -------------------------------------------------------------- lightbox */

#lb { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: none; align-items: center; justify-content: center; padding: 40px; z-index: 60; cursor: zoom-out; }
#lb.on { display: flex; }
#lb img { max-width: 100%; max-height: 100%; border-radius: var(--radius); }

.menu-btn { display: none; }

/* ------------------------------------------------------------ theme toggle */

.sidefoot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidefoot a { font-size: 12px; color: var(--muted); }
.sidefoot a:hover { color: var(--accent); }
#theme {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  border-radius: var(--radius);
  font: inherit;
  font-size: 12px;
  padding: 4px 9px;
  cursor: pointer;
  white-space: nowrap;
}
#theme:hover { color: var(--ink); border-color: var(--accent); }

/* ------------------------------------------------- project-accuracy notice */

.notice {
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  background: var(--warn-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 0 0 20px;
  font-size: 14px;
}
.notice b { color: var(--warn); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; height: auto; width: 100%; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav, .sidebar #results, .sidebar .hint { display: none; }
  .sidebar.open nav { display: block; }
  .sidebar.open #results.on { display: block; }
  .sidebar.open nav.off { display: none; }
  .menu-btn { display: block; width: 100%; margin-top: 10px; padding: 7px; font: inherit; font-size: 13px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; }
  article { padding: 28px 20px 80px; }
  h1 { font-size: 26px; }
  .seq { flex-direction: column; }
  .seq a.next { text-align: left; }
}
