:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #1b2430;
  --muted: #5b6572;
  --line: #d9dee6;
  --accent: #0e6bd6;
  --accent-soft: #eaf3ff;
  --warn: #a13b12;
  --warn-soft: #fff1e8;
  --code-bg: #101623;
  --code-ink: #e6e9ef;
  --code-muted: #9aa7b8;
  --radius: 8px;
  --content-max: 60rem;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, "Microsoft YaHei",
    "PingFang SC", sans-serif;
  font-size: 18px;
  line-height: 1.8;
  letter-spacing: 0;
}

.wrap {
  width: min(100% - 2.5rem, 56rem);
  margin: 0 auto;
}

.layout.wrap {
  width: min(100% - 2.5rem, 76rem);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

.content {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 84px;
  max-height: calc(100vh - 104px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  scrollbar-width: thin;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.88rem;
}

.sidebar-head button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
}

.sidebar-head button:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.sidebar nav ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.sidebar nav li {
  margin: 0;
}

.sidebar nav a {
  display: block;
  padding: 0.34rem 0.55rem;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.4;
}

.sidebar nav a:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.sidebar nav a.active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 650;
}

.sidebar-float {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(16, 22, 35, 0.14);
  cursor: pointer;
}

.sidebar-float .bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}

.sidebar-collapsed .layout {
  /* Single-column: the hidden sidebar no longer participates in grid
     auto-placement, so keeping a 0-wide first column would make the
     remaining item (the content) auto-place into that 0-width column
     and crush the whole page. */
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.sidebar-collapsed .sidebar {
  display: none;
}

.sidebar-collapsed .sidebar-float,
.sidebar-open .sidebar-float {
  display: flex;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.site-header .wrap {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  min-width: 0;
}

.brand strong {
  font-size: 1.02rem;
  white-space: nowrap;
}

.brand span {
  color: var(--muted);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
  flex: none;
}

.lang-switch a {
  display: block;
  padding: 0.38rem 0.85rem;
  font-size: 0.86rem;
  color: var(--muted);
  text-decoration: none;
}

.lang-switch a.active {
  color: var(--surface);
  background: var(--accent);
}

.lang-switch a:not(.active):hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.hero {
  padding: 4.5rem 0 1rem;
}

.hero .kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 1rem;
}

.hero h1 {
  margin: 0 0 1rem;
  font-size: clamp(2rem, 5vw, 3rem);
  line-height: 1.16;
  letter-spacing: 0;
  max-width: 24ch;
}

.lede {
  margin: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: 1.13rem;
}

.key-points {
  margin: 2rem 0 0;
  padding: 1.2rem 1.4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.key-points h2 {
  margin: 0 0 0.7rem;
  padding: 0;
  border: 0;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.key-points ul {
  margin: 0;
  padding-left: 1.2rem;
  max-width: 100%;
}

.key-points li {
  margin: 0.35rem 0;
}

.meta {
  margin-top: 1.6rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta a {
  color: var(--accent);
  text-decoration: none;
}

article {
  max-width: var(--content-max);
  margin: 0 auto;
  padding-top: 2rem;
}

h2 {
  margin: 4rem 0 1.1rem;
  padding: 0 0 0.7rem 0.85rem;
  border-left: 4px solid var(--accent);
  border-bottom: 1px solid var(--line);
  font-size: 1.85rem;
  line-height: 1.25;
  scroll-margin-top: 84px;
}

h3 {
  margin: 2.6rem 0 0.8rem;
  font-size: 1.3rem;
  line-height: 1.35;
  scroll-margin-top: 84px;
}

p {
  margin: 0.9rem 0;
  max-width: 100%;
}

h2 + p,
h3 + p {
  font-size: 1.08rem;
  color: #263244;
  font-weight: 550;
}

section {
  scroll-margin-top: 84px;
}

ul,
ol {
  padding-left: 1.4rem;
  max-width: 100%;
}

li {
  margin: 0.35rem 0;
}

strong {
  font-weight: 650;
}

code {
  font-family: Consolas, "Cascadia Mono", Menlo, monospace;
  font-size: 0.9em;
  background: #e9edf2;
  border-radius: 4px;
  padding: 0.08em 0.34em;
}

pre {
  margin: 1.4rem 0;
  padding: 1.15rem 1.25rem;
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: var(--radius);
  overflow: auto;
  font-size: 0.88rem;
  line-height: 1.55;
}

pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  /* Long blocks (the appendix single-file copy) scroll inside the code
     element so the copy button stays pinned to the pre corner. */
  display: block;
  max-height: 75vh;
  overflow: auto;
}

pre .copy {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  border: 1px solid rgba(230, 233, 239, 0.28);
  border-radius: 6px;
  background: rgba(16, 22, 35, 0.8);
  color: var(--code-ink);
  font-size: 0.74rem;
  line-height: 1;
  padding: 0.34rem 0.55rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

pre:hover .copy,
pre .copy:focus-visible {
  opacity: 1;
}

pre .cmt {
  color: var(--code-muted);
}

.tok-cmt {
  color: #8b98a9;
  font-style: italic;
}

.tok-str {
  color: #7ee0a3;
}

.tok-num {
  color: #f0a46b;
}

.tok-kw {
  color: #7cb8ff;
  font-weight: 600;
}

.tok-fn {
  color: #f2c879;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.97rem;
  background: var(--surface);
}

th,
td {
  border: 1px solid var(--line);
  padding: 0.6rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f0f3f7;
  font-weight: 650;
}

blockquote {
  margin: 1.6rem 0;
  padding: 1rem 1.2rem;
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent-soft);
  font-size: 1.05rem;
}

blockquote.warn {
  border-left-color: var(--warn);
  background: var(--warn-soft);
}

.toc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin: 1.5rem 0 2rem;
}

.toc h2 {
  margin: 0 0 0.7rem;
  padding: 0;
  border: 0;
  font-size: 1.02rem;
}

.toc ol {
  margin: 0;
  columns: 2;
  column-gap: 2.6rem;
  padding-left: 1.3rem;
}

.toc li {
  break-inside: avoid;
  margin: 0.4rem 0;
}

.toc a {
  color: var(--ink);
  text-decoration: none;
}

.toc a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.diagram {
  margin: 1.3rem 0;
  white-space: pre;
}

details {
  margin: 1.4rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

summary {
  cursor: pointer;
  padding: 0.9rem 1.1rem;
  font-weight: 650;
  user-select: none;
}

details[open] summary {
  border-bottom: 1px solid var(--line);
}

details pre {
  margin: 0;
  border-radius: 0;
  max-height: 32rem;
}

.note {
  margin: 1.2rem 0;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface);
  color: var(--muted);
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1.4rem 0;
}

.links a {
  display: inline-block;
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}

.links a:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--accent);
  z-index: 30;
}

.footer {
  margin-top: 4.5rem;
  border-top: 1px solid var(--line);
  padding: 2.2rem 0 3rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

@media (max-width: 680px) {
  body {
    font-size: 16px;
  }

  .wrap {
    width: min(100% - 2rem, 56rem);
  }

  .site-header .wrap {
    min-height: 58px;
  }

  .brand span {
    display: none;
  }

  .hero {
    padding-top: 3rem;
  }

  .toc ol {
    columns: 1;
  }

  pre {
    font-size: 0.8rem;
  }
}

@media (max-width: 1023px) {
  .layout.wrap {
    display: block;
    width: min(100% - 2rem, 56rem);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    max-height: none;
    border-radius: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 60;
  }

  .sidebar-open .sidebar {
    transform: none;
    box-shadow: 0 0 60px rgba(16, 22, 35, 0.28);
  }

  .sidebar-float {
    display: flex;
  }

  .sidebar-collapsed .sidebar-float {
    display: flex;
  }
}
