:root {
  --blue: #1467b3;
  --blue-dark: #0c4f8f;
  --blue-soft: #edf5fc;
  --ink: #17233d;
  --muted: #68758a;
  --line: #dbe3ec;
  --paper: #fff;
  --canvas: #f3f6f9;
  --gold: #e8b347;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

html { min-width: 320px; scroll-behavior: smooth; }

body { margin: 0; overflow: hidden; background: var(--canvas); }

.document-header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 28px;
  color: #fff;
  border-bottom: 3px solid var(--gold);
  background: linear-gradient(105deg, #093f72, #1467b3 68%, #0d568f);
}

.document-brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.document-mark { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; font-family: Georgia, "Songti SC", serif; font-size: 22px; border: 1px solid rgba(255,255,255,.58); border-radius: 4px; background: rgba(255,255,255,.1); }
.document-brand p { margin: 0 0 1px; color: rgba(255,255,255,.7); font-size: 11px; letter-spacing: .13em; }
.document-brand strong { display: block; overflow: hidden; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 600; letter-spacing: .04em; text-overflow: ellipsis; white-space: nowrap; }

.document-header-actions { display: flex; align-items: center; gap: 14px; }
.document-header-actions span { color: rgba(255,255,255,.76); font-size: 13px; }
.document-header-actions a { padding: 7px 13px; color: #fff; font-size: 13px; font-weight: 600; text-decoration: none; border: 1px solid rgba(255,255,255,.58); border-radius: 4px; background: rgba(255,255,255,.08); }
.document-header-actions a:hover { background: rgba(255,255,255,.18); }
.document-header-actions a:focus-visible { outline: 3px solid rgba(255,255,255,.4); outline-offset: 2px; }

.document-layout {
  height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: 252px minmax(560px, 1fr) 308px;
  overflow: hidden;
}

.document-sidebar {
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #f8fafc;
  scrollbar-width: thin;
}

.toc-sidebar { padding: 26px 18px 34px; border-right: 1px solid var(--line); }
.variables-sidebar { padding: 26px 16px 34px; border-left: 1px solid var(--line); }

.sidebar-heading { margin: 0 4px 18px; padding-bottom: 13px; border-bottom: 2px solid var(--blue); }
.sidebar-heading span { color: #8491a3; font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.sidebar-heading h2 { margin: 2px 0 0; color: #25324a; font-size: 17px; }

.document-toc { display: grid; gap: 2px; }
.document-toc a { position: relative; display: block; padding: 7px 9px; color: #56647a; font-size: 12px; line-height: 1.45; text-decoration: none; border-radius: 4px; }
.document-toc a.level-3 { padding-top: 5px; padding-bottom: 5px; padding-left: 22px; color: #768296; font-size: 11px; }
.document-toc a:hover { color: var(--blue-dark); background: #eaf2f9; }
.document-toc a.active { color: var(--blue-dark); font-weight: 700; background: #e5f0fa; }
.document-toc a.active::before { content: ""; position: absolute; top: 7px; bottom: 7px; left: 0; width: 3px; border-radius: 2px; background: var(--blue); }

.article-pane { position: relative; min-width: 0; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; background: #eef2f6; scrollbar-width: thin; }
.reading-progress { position: sticky; z-index: 8; top: 0; width: 100%; height: 3px; background: rgba(20,103,179,.1); }
.reading-progress span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--gold), var(--blue)); transition: width .08s linear; }

.method-article { width: min(920px, calc(100% - 54px)); margin: 26px auto 56px; padding: 46px 58px 70px; color: #26334a; font-size: 15px; line-height: 1.82; background: var(--paper); border: 1px solid var(--line); box-shadow: 0 12px 34px rgba(28, 50, 78, .07); }
.method-article > h1 { margin: 0 0 26px; padding-bottom: 18px; color: #142b48; font-family: Georgia, "Songti SC", serif; font-size: clamp(27px, 3vw, 36px); font-weight: 600; line-height: 1.35; border-bottom: 1px solid var(--line); }
.method-article h2, .method-article h3 { position: relative; scroll-margin-top: 20px; color: #18385e; line-height: 1.45; }
.method-article h2 { margin: 48px 0 18px; padding: 10px 0 10px 15px; font-size: 23px; border-left: 4px solid var(--blue); background: linear-gradient(90deg, var(--blue-soft), transparent 78%); }
.method-article h3 { margin: 31px 0 13px; padding-bottom: 7px; font-size: 18px; border-bottom: 1px solid #e7ecf2; }
.method-article h2:first-of-type { margin-top: 30px; }
.heading-anchor { margin-left: 8px; color: #aab4c1; font-size: .72em; font-weight: 400; text-decoration: none; opacity: 0; }
.method-article h2:hover .heading-anchor, .method-article h3:hover .heading-anchor, .heading-anchor:focus { opacity: 1; }

.method-article p { margin: 11px 0; }
.method-article strong { color: #173f6d; }
.method-article a { color: var(--blue); }
.method-article ul, .method-article ol { margin: 12px 0; padding-left: 1.6em; }
.method-article li { margin: 5px 0; padding-left: 3px; }
.method-article blockquote { margin: 17px 0 25px; padding: 13px 17px; color: #5e6d82; font-size: 13px; border-left: 3px solid var(--gold); background: #fffbef; }
.method-article blockquote p { margin: 2px 0; }
.method-article code { padding: 2px 5px; color: #304c6d; font-family: "SFMono-Regular", Consolas, monospace; font-size: .9em; border-radius: 3px; background: #edf2f7; }

.method-article table { width: 100%; margin: 17px 0 24px; border-collapse: collapse; font-size: 13px; line-height: 1.55; }
.method-article th, .method-article td { padding: 10px 12px; text-align: left; vertical-align: top; border: 1px solid #dce3eb; }
.method-article th { color: #32445d; font-weight: 700; background: #edf3f8; }
.method-article tbody tr:nth-child(even) { background: #fafbfd; }
.method-article tbody tr:hover { background: #f2f7fb; }

.math-block { max-width: 100%; margin: 19px 0; padding: 14px 18px; overflow-x: auto; text-align: center; border: 1px solid #e3e9f0; border-radius: 4px; background: #fbfcfe; }
.math-inline { white-space: nowrap; }
.katex { color: #162d49; font-size: 1.02em; }
.math-block .katex { font-size: 1.12em; }

.mermaid { margin: 22px 0 30px; padding: 24px 16px; overflow-x: auto; text-align: center; border: 1px solid #d9e4ee; border-radius: 5px; background: #f8fbfe; }
.mermaid svg { width: 100%; min-width: 680px; height: auto; }
.diagram-error { padding: 16px; color: #9f342d; border: 1px solid #e5b4af; background: #fff5f4; }

.variables-intro { margin: -4px 4px 14px; color: #738095; font-size: 11px; line-height: 1.6; }
.variables-table-wrap { overflow: hidden; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.variables-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 11px; }
.variables-table th, .variables-table td { padding: 7px 8px; text-align: left; vertical-align: top; line-height: 1.45; border-bottom: 1px solid #e6ebf1; }
.variables-table th { color: #536278; font-size: 10px; letter-spacing: .06em; background: #edf3f8; }
.variables-table th:first-child, .variables-table td:first-child { width: 82px; text-align: center; }
.variables-table tr:last-child td { border-bottom: 0; }
.variables-table tbody tr:hover { background: #f3f8fc; }
.variables-table td:first-child { color: #173f6d; font-size: 12px; }
.variables-table .katex { font-size: 1em; }

@media (max-width: 1240px) {
  .document-layout { grid-template-columns: 224px minmax(520px, 1fr) 268px; }
  .method-article { width: calc(100% - 34px); padding-right: 38px; padding-left: 38px; }
}

@media (max-width: 940px) {
  body { overflow: auto; }
  .document-header { position: sticky; z-index: 20; top: 0; height: 68px; padding: 0 16px; }
  .document-brand p, .document-header-actions span { display: none; }
  .document-brand strong { font-size: 18px; }
  .document-layout { height: auto; display: block; overflow: visible; }
  .document-sidebar, .article-pane { overflow: visible; }
  .toc-sidebar, .variables-sidebar { margin: 14px; padding: 16px; border: 1px solid var(--line); }
  .document-toc { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .document-toc a.level-3 { display: none; }
  .article-pane { background: transparent; }
  .reading-progress { top: 68px; }
  .method-article { width: calc(100% - 28px); margin: 14px; padding: 32px 24px 48px; }
  .variables-sidebar { margin-bottom: 36px; }
}

@media (max-width: 580px) {
  .document-mark { width: 34px; height: 34px; flex-basis: 34px; font-size: 18px; }
  .document-header-actions a { padding: 6px 9px; font-size: 12px; }
  .document-toc { grid-template-columns: 1fr; }
  .method-article { padding-right: 17px; padding-left: 17px; font-size: 14px; }
  .method-article h2 { font-size: 20px; }
  .method-article h3 { font-size: 17px; }
  .method-article table { display: block; overflow-x: auto; white-space: nowrap; }
}

@media print {
  body { overflow: visible; background: #fff; }
  .document-header, .document-sidebar, .reading-progress { display: none; }
  .document-layout { height: auto; display: block; }
  .article-pane { overflow: visible; background: #fff; }
  .method-article { width: auto; margin: 0; padding: 0; border: 0; box-shadow: none; }
  .method-article h2, .method-article h3 { break-after: avoid; }
  .method-article table, .math-block, .mermaid { break-inside: avoid; }
}

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