:root {
  --bg: #f3f6f6;
  --surface: #ffffff;
  --surface-soft: #eaf0ef;
  --surface-strong: #dfe8e6;
  --ink: #18282d;
  --ink-soft: #445a60;
  --muted: #6a7b7f;
  --line: #d4dfdd;
  --line-strong: #b7c7c4;
  --accent: #d95b42;
  --accent-strong: #b7432f;
  --accent-soft: #fae9e4;
  --teal: #0c746c;
  --teal-soft: #dcefeb;
  --code-bg: #142428;
  --code-ink: #edf5f3;
  --code-muted: #91aaa6;
  --shadow: 0 18px 50px rgba(25, 48, 52, 0.09);
  --radius: 8px;
  --content-width: 900px;
  --sidebar-width: 276px;
}

[data-theme="dark"] {
  --bg: #101819;
  --surface: #172224;
  --surface-soft: #1c292b;
  --surface-strong: #263538;
  --ink: #edf4f2;
  --ink-soft: #c2d0cd;
  --muted: #94a8a5;
  --line: #304043;
  --line-strong: #42575a;
  --accent: #ff8169;
  --accent-strong: #ffa08d;
  --accent-soft: #3a2522;
  --teal: #62c6bc;
  --teal-soft: #17312e;
  --code-bg: #0b1214;
  --code-ink: #edf5f3;
  --code-muted: #8fa7a3;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  text-rendering: optimizeLegibility;
}

body.nav-open {
  overflow: hidden;
}

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

a {
  color: var(--teal);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

a:hover {
  color: var(--accent-strong);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--teal) 55%, transparent);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  height: 3px;
  background: transparent;
  pointer-events: none;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px max(22px, calc((100vw - 1440px) / 2 + 22px));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

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

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 800;
}

.brand-copy {
  display: grid;
  gap: 0;
  line-height: 1.25;
}

.brand-copy strong {
  font-size: 0.96rem;
}

.brand-copy small {
  color: var(--muted);
  font-size: 0.73rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.text-button,
.menu-button {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}

.text-button:hover,
.menu-button:hover {
  border-color: var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.menu-button {
  display: none;
  border-color: var(--line);
  background: var(--surface);
}

.site-layout {
  display: grid;
  width: min(1440px, 100%);
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 68px;
  align-self: start;
  height: calc(100vh - 68px);
  overflow-y: auto;
  padding: 24px 18px 24px 22px;
  border-right: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.sidebar-search {
  margin-bottom: 22px;
}

.sidebar-search label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
}

.sidebar-search input {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

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

.search-empty {
  margin: 8px 2px 0;
  color: var(--accent);
  font-size: 0.8rem;
}

.nav-group + .nav-group {
  margin-top: 22px;
}

.nav-group h2 {
  margin: 0 0 7px 9px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-link {
  display: grid;
  min-height: 38px;
  align-items: baseline;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--ink-soft);
  grid-template-columns: 26px minmax(0, 1fr);
  text-decoration: none;
  transition: background-color 140ms ease, color 140ms ease;
}

.nav-link:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.nav-link.is-active {
  background: var(--teal-soft);
  color: var(--ink);
  font-weight: 700;
}

.nav-number {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
}

.nav-link.is-active .nav-number {
  color: var(--teal);
}

.course-progress-panel {
  margin-top: 26px;
  padding: 14px 9px 4px;
  border-top: 1px solid var(--line);
}

.course-progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
}

.course-progress-heading strong {
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, monospace;
}

.course-progress-track {
  height: 5px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-strong);
}

.course-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--teal);
  transition: width 200ms ease;
}

.main-content {
  width: min(100%, calc(var(--content-width) + 120px));
  margin: 0 auto;
  padding: 34px 60px 64px;
}

.page-kicker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.page-kicker span:first-child {
  color: var(--accent-strong);
}

.home-hero {
  display: grid;
  align-items: center;
  gap: clamp(28px, 5vw, 64px);
  margin: 4px 0 54px;
  padding-bottom: 44px;
  border-bottom: 1px solid var(--line);
  grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
}

.eyebrow {
  margin: 0 0 13px;
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-copy h1 {
  max-width: 650px;
  margin: 0;
  font-size: clamp(2.3rem, 4.6vw, 4.1rem);
  line-height: 1.08;
  letter-spacing: 0;
}

.hero-lead {
  max-width: 620px;
  margin: 22px 0 0;
  color: var(--ink-soft);
  font-size: 1.04rem;
  line-height: 1.8;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
}

.button-primary {
  background: var(--ink);
  color: var(--surface);
}

.button-primary:hover {
  background: var(--accent-strong);
  color: #ffffff;
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.button-secondary:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.hero-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin: 32px 0 0;
}

.hero-facts div {
  display: grid;
  gap: 2px;
}

.hero-facts dt {
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 800;
}

.hero-facts dd {
  margin: 0;
  color: var(--muted);
  font-size: 0.77rem;
}

.hero-visual {
  min-width: 0;
}

.code-window {
  overflow: hidden;
  border: 1px solid #2c4145;
  border-radius: var(--radius);
  background: var(--code-bg);
  box-shadow: var(--shadow);
}

.code-window-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #2b4044;
  color: var(--code-muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
}

.code-window pre {
  margin: 0;
  padding: 22px;
  overflow-x: auto;
  color: var(--code-ink);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.72;
  tab-size: 4;
}

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

.code-builtin {
  color: #76d7c9;
}

.code-string {
  color: #f5c67a;
}

.code-keyword {
  color: #ff927d;
}

.code-number {
  color: #b7a8ff;
}

.course-rail {
  display: grid;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.course-rail span {
  position: relative;
  padding: 11px 8px;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.course-rail span + span {
  border-left: 1px solid var(--line);
}

.course-rail span:first-child {
  color: var(--accent-strong);
  font-weight: 700;
}

.doc-content {
  min-width: 0;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.82;
}

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

.doc-content h1,
.doc-content h2,
.doc-content h3,
.doc-content h4 {
  position: relative;
  color: var(--ink);
  line-height: 1.3;
  letter-spacing: 0;
  scroll-margin-top: 92px;
}

.doc-content h1 {
  margin: 0 0 26px;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.18;
}

.doc-content h2 {
  margin: 62px 0 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 1.55rem;
}

.doc-content h3 {
  margin: 38px 0 14px;
  font-size: 1.18rem;
}

.doc-content h4 {
  margin: 28px 0 10px;
  font-size: 1.02rem;
}

.heading-anchor {
  margin-left: 8px;
  color: var(--muted);
  font-size: 0.72em;
  font-weight: 500;
  opacity: 0;
  text-decoration: none;
}

.doc-content h2:hover .heading-anchor,
.doc-content h3:hover .heading-anchor,
.doc-content h4:hover .heading-anchor,
.heading-anchor:focus {
  opacity: 1;
}

.doc-content p {
  margin: 0 0 1.05em;
}

.doc-content strong {
  color: var(--ink);
}

.doc-content ul,
.doc-content ol {
  margin: 0.5em 0 1.3em;
  padding-left: 1.45em;
}

.doc-content li {
  margin: 0.32em 0;
  padding-left: 0.12em;
}

.doc-content li::marker {
  color: var(--accent);
}

.doc-content li > p {
  margin-bottom: 0.5em;
}

.doc-content a {
  font-weight: 600;
}

.doc-content blockquote {
  margin: 24px 0;
  padding: 3px 0 3px 18px;
  border-left: 4px solid var(--accent);
  color: var(--ink-soft);
}

.doc-content blockquote p:last-child {
  margin-bottom: 0;
}

.doc-content code {
  padding: 0.14em 0.35em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.88em;
  overflow-wrap: anywhere;
}

.doc-content pre {
  position: relative;
  margin: 22px 0;
  padding: 21px 22px;
  overflow: auto;
  border: 1px solid #2a3f43;
  border-radius: var(--radius);
  background: var(--code-bg);
  color: var(--code-ink);
  font-size: 0.84rem;
  line-height: 1.7;
  tab-size: 4;
}

.doc-content pre code {
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
  overflow-wrap: normal;
}

.copy-code {
  position: absolute;
  top: 9px;
  right: 9px;
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid #42585c;
  border-radius: 5px;
  background: #203337;
  color: #dce9e6;
  font-size: 0.7rem;
  cursor: pointer;
}

.copy-code:hover {
  border-color: #6d8a8e;
  background: #2a4247;
}

.doc-content .table-wrap {
  width: 100%;
  margin: 22px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.doc-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.89rem;
  line-height: 1.55;
}

.doc-content thead {
  background: var(--surface-soft);
}

.doc-content th,
.doc-content td {
  min-width: 92px;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.doc-content th:last-child,
.doc-content td:last-child {
  border-right: 0;
}

.doc-content tr:last-child td {
  border-bottom: 0;
}

.doc-content th {
  color: var(--ink);
  font-weight: 750;
}

.doc-content input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0 6px 0 0;
  accent-color: var(--teal);
  vertical-align: -2px;
}

.doc-content hr {
  margin: 42px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.completion-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 54px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.completion-label,
.completion-copy {
  margin: 0;
}

.completion-label {
  color: var(--ink);
  font-weight: 750;
}

.completion-copy {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.83rem;
}

.completion-panel.is-complete {
  border-color: color-mix(in srgb, var(--teal) 45%, var(--line));
  background: var(--teal-soft);
}

.completion-panel.is-complete .button {
  border-color: var(--teal);
  color: var(--teal);
}

.page-pager {
  display: grid;
  gap: 16px;
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pager-link {
  display: grid;
  gap: 3px;
  min-height: 68px;
  align-content: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}

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

.pager-next {
  text-align: right;
}

.pager-label {
  color: var(--muted);
  font-size: 0.72rem;
}

.pager-link strong {
  font-size: 0.9rem;
}

.site-footer {
  margin-top: 56px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.site-footer p {
  margin: 0;
}

.site-footer p + p {
  margin-top: 4px;
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 1120px) {
  .main-content {
    padding-right: 38px;
    padding-left: 38px;
  }

  .home-hero {
    gap: 30px;
  }

  .hero-copy h1 {
    font-size: clamp(2.2rem, 4.7vw, 3.3rem);
  }
}

@media (max-width: 960px) {
  .site-header {
    padding-right: 18px;
    padding-left: 18px;
  }

  .brand-copy small {
    display: none;
  }

  .menu-button {
    display: inline-flex;
    align-items: center;
  }

  .site-layout {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 68px auto 0 0;
    z-index: 45;
    width: min(84vw, 320px);
    height: calc(100vh - 68px);
    border-right: 1px solid var(--line);
    background: var(--surface);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 68px 0 0;
    z-index: 40;
    display: block;
    background: rgba(7, 16, 18, 0.52);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.nav-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .main-content {
    width: min(100%, calc(var(--content-width) + 76px));
    padding: 30px 38px 58px;
  }

  .home-hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .hero-copy h1 {
    max-width: 720px;
  }

  .hero-visual {
    max-width: 620px;
  }
}

@media (max-width: 640px) {
  html {
    scroll-padding-top: 76px;
  }

  .site-header {
    min-height: 62px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
  }

  .brand-copy strong {
    font-size: 0.85rem;
  }

  .text-button[data-print] {
    display: none;
  }

  .text-button[data-theme-toggle] {
    padding-right: 8px;
    padding-left: 8px;
    font-size: 0.76rem;
  }

  .menu-button {
    min-height: 36px;
    padding: 6px 9px;
    font-size: 0.82rem;
  }

  .main-content {
    padding: 25px 20px 48px;
  }

  .page-kicker {
    margin-bottom: 17px;
    font-size: 0.72rem;
  }

  .home-hero {
    gap: 28px;
    margin-bottom: 40px;
    padding-bottom: 34px;
  }

  .hero-copy h1 {
    font-size: clamp(2.2rem, 11vw, 3rem);
  }

  .hero-lead {
    font-size: 0.96rem;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .hero-actions .button {
    width: 100%;
  }

  .hero-facts {
    gap: 18px;
  }

  .code-window pre {
    padding: 17px;
    font-size: 0.73rem;
  }

  .course-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .course-rail span:nth-child(3) {
    border-left: 0;
  }

  .course-rail span:nth-child(n + 3) {
    border-top: 1px solid var(--line);
  }

  .doc-content {
    font-size: 0.96rem;
    line-height: 1.76;
  }

  .doc-content h1 {
    font-size: 2rem;
  }

  .doc-content h2 {
    margin-top: 50px;
    font-size: 1.35rem;
  }

  .doc-content h3 {
    font-size: 1.1rem;
  }

  .doc-content pre {
    margin-right: -6px;
    margin-left: -6px;
    padding: 17px;
    font-size: 0.76rem;
  }

  .doc-content th,
  .doc-content td {
    padding: 9px 10px;
  }

  .completion-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .completion-panel .button {
    width: 100%;
  }

  .page-pager {
    grid-template-columns: 1fr;
  }

  .pager-next {
    text-align: left;
  }

  .pager-spacer {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media print {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-soft: #f3f3f3;
    --ink: #111111;
    --ink-soft: #222222;
    --muted: #555555;
    --line: #cccccc;
    --line-strong: #999999;
  }

  body {
    background: #ffffff;
    font-size: 11pt;
  }

  .site-header,
  .sidebar,
  .sidebar-backdrop,
  .reading-progress,
  .page-kicker,
  .completion-panel,
  .page-pager,
  .site-footer,
  .copy-code,
  .heading-anchor {
    display: none !important;
  }

  .site-layout {
    display: block;
  }

  .main-content {
    width: 100%;
    max-width: none;
    padding: 0;
  }

  .home-hero {
    grid-template-columns: 1fr;
    margin-bottom: 28px;
    padding-bottom: 24px;
  }

  .hero-visual {
    display: none;
  }

  .doc-content {
    color: #111111;
    font-size: 11pt;
    line-height: 1.58;
  }

  .doc-content h2 {
    break-after: avoid;
  }

  .doc-content pre,
  .doc-content .table-wrap {
    break-inside: avoid;
    box-shadow: none;
  }

  .doc-content pre {
    border-color: #999999;
    background: #f4f4f4;
    color: #111111;
  }

  .doc-content pre code {
    color: #111111;
  }
}
