:root,
html[data-mode="light"] {
  color-scheme: light;
  --sheet: #f8f8f7;
  --vellum: #f0f0ee;
  --vellum-tab: #e8e8e5;
  --ink-primary: #0f0f0e;
  --ink-body: #1f1f1d;
  --ink-muted: #52524e;
  --accent: #b5381c;
  --accent-soft: rgba(181, 56, 28, 0.1);
  --rule: rgba(15, 15, 14, 0.12);
  --rule-strong: rgba(15, 15, 14, 0.22);
  --hl-bg: rgba(181, 56, 28, 0.09);
  --hl-border: #b5381c;
  --tip-border: #1c5e3a;
  --tip-bg: rgba(28, 94, 58, 0.06);
  --caution-border: #9c4a12;
  --caution-bg: rgba(156, 74, 18, 0.07);
  --note-border: #174b78;
  --note-bg: rgba(23, 75, 120, 0.055);
  --syn-kw: #a62e14;
  --syn-fn: #174b78;
  --syn-ty: #522b7d;
  --syn-str: #1c5e3a;
  --syn-cm: #555550;
  --syn-num: #8a3f10;
  --grain-opacity: 0.042;
  --grain-blend: multiply;
  --backdrop: rgba(15, 15, 14, 0.4);
  --popover-shadow: 0 14px 36px -8px rgba(15, 15, 14, 0.18), 0 2px 8px rgba(15, 15, 14, 0.08);
}

html[data-mode="dark"] {
  color-scheme: dark;
  --sheet: #161617;
  --vellum: #111112;
  --vellum-tab: #1c1c1e;
  --ink-primary: #f7f7f5;
  --ink-body: #ddddda;
  --ink-muted: #a5a5a0;
  --accent: #f27a5d;
  --accent-soft: rgba(242, 122, 93, 0.16);
  --rule: rgba(247, 247, 245, 0.12);
  --rule-strong: rgba(247, 247, 245, 0.22);
  --hl-bg: rgba(242, 122, 93, 0.14);
  --hl-border: #f27a5d;
  --tip-border: #92cfa4;
  --tip-bg: rgba(146, 207, 164, 0.08);
  --caution-border: #ebb47c;
  --caution-bg: rgba(235, 180, 124, 0.09);
  --note-border: #8ec0e8;
  --note-bg: rgba(142, 192, 232, 0.08);
  --syn-kw: #f58c73;
  --syn-fn: #8ec0e8;
  --syn-ty: #cdaef0;
  --syn-str: #92cfa4;
  --syn-cm: #9d9d98;
  --syn-num: #ebb47c;
  --grain-opacity: 0.028;
  --grain-blend: screen;
  --backdrop: rgba(5, 5, 6, 0.68);
  --popover-shadow: 0 18px 44px -8px rgba(0, 0, 0, 0.68), 0 2px 10px rgba(0, 0, 0, 0.42);
}

:root {
  --font-display:
    "Newsreader", "Songti SC", "STSong", "Noto Serif CJK SC", "PingFang HK", "PingFang TC", "Hiragino Mincho ProN", "Yu Mincho",
    "Apple SD Gothic Neo", "Noto Serif KR", Georgia, serif;
  --font-sans:
    "Inter", -apple-system, BlinkMacSystemFont, "PingFang SC", "PingFang HK", "PingFang TC", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --prose-lh: 1.8;
}

html[lang^="zh"],
html[lang="ja"],
html[lang="ko"] {
  --prose-lh: 1.88;
}

html[lang="ar"] {
  --font-display: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Geeza Pro", "Segoe UI", Tahoma, sans-serif;
  --font-sans: "IBM Plex Sans Arabic", "Noto Sans Arabic", "Geeza Pro", "Segoe UI", Tahoma, sans-serif;
  --font-mono:
    "JetBrains Mono", "IBM Plex Sans Arabic", "Noto Sans Arabic", ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --prose-lh: 1.92;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  isolation: isolate;
  margin: 0;
  min-height: 100vh;
  background-color: var(--sheet);
  color: var(--ink-body);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: var(--prose-lh);
  text-rendering: optimizeLegibility;
}

html[data-mode="dark"] body {
  -webkit-font-smoothing: antialiased;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  opacity: var(--grain-opacity);
  mix-blend-mode: var(--grain-blend);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  background-repeat: repeat;
}

::selection {
  background: var(--accent-soft);
  color: var(--ink-primary);
}

.rail-brand:focus-visible,
.rail-link:focus-visible,
.rail-tool:focus-visible,
.theme-opt:focus-visible,
.lang-option:focus-visible,
.p-tab:focus-visible,
.p-tree-file:focus-visible,
.p-copy:focus-visible,
.chapter-pager-link:focus-visible,
.mobile-brand:focus-visible,
.mobile-btn:focus-visible,
.search-close:focus-visible,
.search-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Mobile Header Bar & Drawer Backdrop (Hidden on Desktop) */

.mobile-bar {
  display: none;
}

.rail-backdrop {
  display: none;
}

.rail-backdrop[hidden] {
  display: none;
}

/* Borderless Paper Shell */

.doc-shell {
  max-width: 1536px;
  margin: 0 auto;
  padding: 56px clamp(28px, 4vw, 56px) 104px;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: clamp(40px, 4.5vw, 72px);
}

/* Transparent Left Index Rail */

.doc-rail {
  position: sticky;
  top: 56px;
  align-self: start;
  max-height: calc(100vh - 88px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 10;
}

.rail-brand {
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--ink-primary);
  text-decoration: none;
  line-height: 1.3;
  transition: color 120ms ease;
}

.rail-brand strong {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.rail-brand:hover {
  color: var(--accent);
}

.rail-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-inline-end: 4px;
}

.rail-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.rail-group-title {
  margin: 0;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.rail-item {
  margin: 0;
}

.rail-link {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-block: 4px;
  padding-inline-start: 10px;
  border-inline-start: 2px solid transparent;
  color: var(--ink-body);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.45;
  transition:
    color 120ms ease,
    border-color 120ms ease;
}

.rail-link:hover {
  color: var(--ink-primary);
}

.rail-link.is-current {
  border-inline-start-color: var(--accent);
  color: var(--ink-primary);
  font-weight: 600;
}

.rail-num {
  flex-shrink: 0;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.rail-link.is-current .rail-num {
  color: var(--accent);
}

.rail-title {
  min-width: 0;
}

/* Rail Footer Tools & Upward Language Popover */

.rail-foot {
  flex-shrink: 0;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.rail-foot-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.theme-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--vellum);
}

.theme-opt {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    color 120ms ease,
    background-color 120ms ease;
}

.theme-opt:hover {
  color: var(--ink-primary);
}

html[data-theme-pref="auto"] .theme-opt[data-theme-set="auto"],
html[data-theme-pref="light"] .theme-opt[data-theme-set="light"],
html[data-theme-pref="dark"] .theme-opt[data-theme-set="dark"] {
  background: var(--sheet);
  color: var(--ink-primary);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(15, 15, 14, 0.08);
}

html[data-mode="dark"][data-theme-pref="auto"] .theme-opt[data-theme-set="auto"],
html[data-mode="dark"][data-theme-pref="light"] .theme-opt[data-theme-set="light"],
html[data-mode="dark"][data-theme-pref="dark"] .theme-opt[data-theme-set="dark"] {
  background: var(--vellum-tab);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.rail-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--ink-body);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: color 120ms ease;
}

.rail-tool:hover {
  color: var(--ink-primary);
}

.rail-tool kbd {
  padding: 0 5px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--vellum);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.lang-menu {
  position: relative;
}

.lang-summary {
  list-style: none;
}

.lang-summary::-webkit-details-marker {
  display: none;
}

.lang-summary::after {
  content: "▴";
  font-size: 10px;
  color: var(--ink-muted);
}

.lang-menu[open] .lang-summary {
  color: var(--ink-primary);
}

.lang-list {
  position: absolute;
  bottom: calc(100% + 6px);
  inset-inline-start: 0;
  z-index: 60;
  min-width: 196px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  box-shadow: var(--popover-shadow);
}

.lang-option {
  display: block;
  padding: 6px 10px;
  border-radius: 3px;
  color: var(--ink-body);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.45;
  text-decoration: none;
}

.lang-option:hover {
  background: var(--vellum);
  color: var(--ink-primary);
}

.lang-option.is-current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

/* Linear Reading Column */

.doc-article {
  min-width: 0;
}

.chapter-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--rule);
}

.chapter-eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.chapter-title {
  margin: 0;
  color: var(--ink-primary);
  font-family: var(--font-display);
  font-size: clamp(2rem, 3vw, 2.65rem);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -0.02em;
}

.doc-sections {
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.doc-section {
  scroll-margin-top: 32px;
}

.doc-section > :first-child {
  margin-top: 0;
}

.doc-section > :last-child {
  margin-bottom: 0;
}

.doc-section h2 {
  margin: 8px 0 14px;
  color: var(--ink-primary);
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 500;
  line-height: 1.28;
  letter-spacing: -0.015em;
  scroll-margin-top: 32px;
}

.doc-section h3 {
  margin: 26px 0 10px;
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 1.08rem;
  font-weight: 600;
  line-height: 1.4;
  scroll-margin-top: 32px;
}

.doc-section h4 {
  margin: 20px 0 8px;
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  scroll-margin-top: 32px;
}

.doc-section p {
  margin: 0 0 16px;
}

.doc-section strong {
  color: var(--ink-primary);
  font-weight: 600;
}

.doc-section a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.doc-section a:hover {
  color: var(--ink-primary);
}

.doc-section ul,
.doc-section ol {
  margin: 0 0 18px;
  padding-inline-start: 1.4rem;
}

.doc-section li {
  margin-bottom: 6px;
}

.doc-section li > p {
  margin-bottom: 6px;
}

.doc-section code {
  padding: 1.5px 5px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--vellum);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 0.84em;
}

.doc-section code,
.callout code {
  direction: ltr;
  unicode-bidi: isolate;
}

.doc-section blockquote {
  margin: 18px 0;
  padding-block: 4px;
  padding-inline-start: 16px;
  border-inline-start: 2px solid var(--rule-strong);
  color: var(--ink-muted);
}

.doc-section hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 28px 0;
}

/* Clean Editorial GFM Tables */

.doc-section table {
  width: 100%;
  margin: 20px 0;
  border-collapse: collapse;
  font-size: 0.92rem;
  line-height: 1.55;
}

.doc-section th {
  padding: 8px 10px;
  text-align: start;
  border-bottom: 1.5px solid var(--rule-strong);
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
}

.doc-section td {
  padding: 9px 10px;
  vertical-align: top;
  border-bottom: 1px solid var(--rule);
}

/* Editorial Left-Border Callouts */

.callout {
  margin: 20px 0;
  padding: 11px 16px;
  border-inline-start: 3px solid var(--note-border);
  background: var(--note-bg);
  border-radius: 0 4px 4px 0;
}

html[dir="rtl"] .callout {
  border-radius: 4px 0 0 4px;
}

.callout-tip {
  border-inline-start-color: var(--tip-border);
  background: var(--tip-bg);
}

.callout-caution {
  border-inline-start-color: var(--caution-border);
  background: var(--caution-bg);
}

.callout-title {
  margin: 0 0 4px;
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.callout-body > :first-child {
  margin-top: 0;
}

.callout-body > :last-child {
  margin-bottom: 0;
}

/* Inline Paper Code Blocks */

.paper-code {
  margin: 22px 0;
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  background: var(--vellum);
  overflow: hidden;
  direction: ltr;
  text-align: left;
}

.callout-body .paper-code {
  margin: 12px 0 4px;
}

.p-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 36px;
  padding: 4px 6px 4px 14px;
  background: var(--vellum-tab);
  border-bottom: 1px solid var(--rule);
}

.p-filename {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-primary);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}

.paper-code-tabs .p-head {
  padding: 0 6px 0 8px;
  gap: 8px;
}

.p-tabs {
  display: flex;
  align-items: stretch;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.p-tabs::-webkit-scrollbar {
  display: none;
}

.p-tab {
  position: relative;
  flex-shrink: 0;
  padding: 8px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition:
    color 120ms ease,
    border-color 120ms ease;
}

.p-tab:hover {
  color: var(--ink-primary);
}

.p-tab.is-active {
  color: var(--ink-primary);
  border-bottom-color: var(--accent);
}

.p-copy {
  flex-shrink: 0;
  margin: 0;
  padding: 3px 9px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: var(--sheet);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition:
    color 120ms ease,
    border-color 120ms ease;
}

.p-copy:hover,
.p-copy.is-copied {
  color: var(--accent);
  border-color: var(--accent);
}

.p-tree-layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.p-tree {
  padding: 8px 0;
  background: var(--sheet);
  border-right: 1px solid var(--rule);
  overflow: auto;
  max-height: 540px;
  scrollbar-width: thin;
}

.paper-code .p-tree-list,
.paper-code .p-tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
  padding-inline-start: 0;
}

.paper-code .p-tree-branch,
.paper-code .p-tree-leaf {
  margin: 0;
}

.p-tree-dir {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px 4px calc(10px + var(--depth, 0) * 12px);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.45;
  white-space: nowrap;
  user-select: none;
}

.p-tree-glyph {
  flex-shrink: 0;
  width: 10px;
  font-size: 10px;
  text-align: center;
  color: var(--ink-muted);
}

.p-tree-file {
  display: block;
  width: 100%;
  padding: 4px 10px 4px calc(24px + var(--depth, 0) * 12px);
  border: 0;
  border-left: 2px solid transparent;
  background: transparent;
  color: var(--ink-body);
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.45;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition:
    color 120ms ease,
    background-color 120ms ease,
    border-color 120ms ease;
}

.p-tree-file:hover {
  background: var(--vellum);
  color: var(--ink-primary);
}

.p-tree-file.is-active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--ink-primary);
  font-weight: 500;
}

.p-panels {
  min-width: 0;
}

.p-pre {
  display: none;
  margin: 0;
  padding: 14px 0;
  max-height: 540px;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.72;
  color: var(--ink-primary);
  tab-size: 2;
}

.p-pre.is-active {
  display: block;
}

.pl {
  display: block;
  min-width: max-content;
  padding: 0 18px 0 14px;
  border-left: 2px solid transparent;
}

.pl.hl {
  background: var(--hl-bg);
  border-left-color: var(--hl-border);
}

.pln {
  display: inline-block;
  min-width: 2.1em;
  padding-right: 1em;
  text-align: right;
  color: var(--ink-muted);
  opacity: 0.85;
  user-select: none;
}

.kw {
  color: var(--syn-kw);
}

.fn {
  color: var(--syn-fn);
}

.ty {
  color: var(--syn-ty);
}

.str {
  color: var(--syn-str);
}

.cm {
  color: var(--syn-cm);
  font-style: italic;
}

.num {
  color: var(--syn-num);
}

/* Chapter Pager */

.chapter-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.chapter-pager-link {
  color: var(--ink-primary);
  text-decoration: none;
  transition: color 120ms ease;
}

.chapter-pager-link:hover {
  color: var(--accent);
}

.chapter-pager-next {
  margin-inline-start: auto;
  text-align: end;
}

.chapter-pager-spacer {
  display: inline-block;
  min-width: 1px;
}

/* Search Modal (⌘K) */

.search-modal {
  width: min(620px, calc(100vw - 32px));
  margin: 10vh auto auto;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 6px;
  background: var(--sheet);
  color: var(--ink-body);
  box-shadow: var(--popover-shadow);
}

.search-modal::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.search-dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: 74vh;
}

.search-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--rule);
}

.search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 0.98rem;
  line-height: 1.4;
  outline: none;
}

.search-input::placeholder {
  color: var(--ink-muted);
}

.search-close {
  padding: 3px 8px;
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  background: var(--vellum);
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
}

.search-close:hover {
  color: var(--ink-primary);
  border-color: var(--accent);
}

.search-results {
  overflow-y: auto;
  padding: 8px;
}

.search-item {
  display: block;
  padding: 10px 12px;
  border-radius: 4px;
  color: var(--ink-body);
  text-decoration: none;
}

.search-item:hover,
.search-item.is-selected {
  background: var(--vellum);
}

.search-item-chapter {
  display: block;
  margin-bottom: 2px;
  color: var(--ink-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}

.search-item-title {
  display: block;
  color: var(--ink-primary);
  font-weight: 500;
  font-size: 0.95rem;
  line-height: 1.4;
}

.search-item.is-selected .search-item-title {
  color: var(--accent);
}

.search-item-excerpt {
  display: block;
  margin-top: 3px;
  color: var(--ink-muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.search-hit {
  padding: 0 2px;
  border-radius: 2px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
}

html[dir="rtl"] .search-hit {
  padding: 0;
  font-weight: inherit;
}

.search-empty {
  margin: 0;
  padding: 24px 12px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

/* Responsive Single-Column Paper & Slide-Over Rail (<= 920px) */

@media (max-width: 920px) {
  .mobile-bar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    background: var(--sheet);
    border-bottom: 1px solid var(--rule);
  }

  .mobile-brand {
    color: var(--ink-primary);
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    text-decoration: none;
    white-space: nowrap;
  }

  .mobile-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mobile-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border: 1px solid var(--rule-strong);
    border-radius: 4px;
    background: var(--vellum);
    color: var(--ink-body);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition:
      color 120ms ease,
      border-color 120ms ease;
  }

  .mobile-btn:hover,
  .mobile-btn[aria-expanded="true"] {
    color: var(--ink-primary);
    border-color: var(--accent);
  }

  .mobile-btn kbd {
    padding: 0 4px;
    border: 1px solid var(--rule);
    border-radius: 3px;
    background: var(--sheet);
    color: var(--ink-muted);
    font-family: var(--font-mono);
    font-size: 10.5px;
  }

  .rail-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 65;
    background: var(--backdrop);
  }

  .doc-shell {
    grid-template-columns: minmax(0, 1fr);
    padding: 28px 20px 72px;
    gap: 0;
  }

  .doc-rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(300px, 86vw);
    max-height: 100vh;
    padding: 24px 22px;
    background: var(--sheet);
    border-right: 1px solid var(--rule-strong);
    z-index: 70;
    visibility: hidden;
    transform: translateX(-100%);
    transition:
      transform 180ms ease,
      visibility 0s linear 180ms;
  }

  .doc-rail.is-open {
    visibility: visible;
    box-shadow: var(--popover-shadow);
    transform: translateX(0);
    transition:
      transform 180ms ease,
      visibility 0s;
  }

  html[dir="rtl"] .doc-rail {
    inset: 0 0 0 auto;
    border-right: 0;
    border-left: 1px solid var(--rule-strong);
    transform: translateX(100%);
  }

  html[dir="rtl"] .doc-rail.is-open {
    transform: translateX(0);
  }

  .doc-section,
  .doc-section h2,
  .doc-section h3,
  .doc-section h4 {
    scroll-margin-top: 68px;
  }

  .p-pre {
    max-height: 440px;
  }

  .p-tree {
    max-height: 440px;
  }
}

@media (max-width: 640px) {
  .p-tree-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .p-tree {
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    max-height: 200px;
  }
}

@media (max-width: 560px) {
  .mobile-bar {
    padding: 10px 16px;
  }

  .mobile-btn kbd {
    display: none;
  }

  .doc-shell {
    padding: 22px 16px 64px;
  }

  .chapter-pager {
    flex-wrap: wrap;
  }
}

html[dir="rtl"] .rail-brand strong,
html[dir="rtl"] .rail-group-title,
html[dir="rtl"] .chapter-eyebrow,
html[dir="rtl"] .chapter-title,
html[dir="rtl"] .doc-section h2,
html[dir="rtl"] .mobile-brand {
  letter-spacing: 0;
}
