:root {
  --dsh-accent: #2455a4;
  --dsh-accent-strong: #173a75;
  --dsh-accent-soft: #eaf2ff;
  --dsh-rule: #ccd7e8;
  --dsh-muted: #5e6b7d;
  --dsh-code: #f5f7fa;
  --dsh-header: #243b61;
  --dsh-figure-bg: #ffffff;
}

[data-md-color-scheme="slate"] {
  --md-default-bg-color: #1b1c20;
  --md-default-fg-color: rgba(240, 241, 243, 0.92);
  --md-code-bg-color: #202226;
  --md-typeset-color: rgba(240, 241, 243, 0.92);
  --dsh-accent: #70a7ff;
  --dsh-accent-strong: #9fc5ff;
  --dsh-accent-soft: #20242c;
  --dsh-rule: #3d424b;
  --dsh-muted: #b8bdc6;
  --dsh-code: #202226;
  --dsh-header: #181a1f;
  --dsh-figure-bg: #ffffff;
}

body,
input {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* 顶栏保留功能入口，颜色退到内容之后。 */
.md-header {
  background: var(--dsh-header);
  box-shadow: 0 1px 0 rgb(15 23 42 / 16%);
}

.md-header__title {
  font-weight: 650;
}

.xiaota-maintainer-badge {
  background: #d9a441;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 999px;
  color: #17233a;
  flex: 0 0 auto;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  margin: 0 0.35rem;
  padding: 0.38rem 0.55rem;
  white-space: nowrap;
}

.xiaota-edition-note {
  align-items: center;
  background: linear-gradient(110deg, rgb(36 59 97 / 8%), rgb(217 164 65 / 12%));
  border: 1px solid rgb(217 164 65 / 55%);
  border-radius: 0.35rem;
  display: flex;
  gap: 0.65rem;
  margin: 0 0 1.5rem;
  padding: 0.75rem 0.9rem;
}

.xiaota-edition-note strong {
  color: #9a6411;
  flex: 0 0 auto;
}

.xiaota-edition-note span {
  color: var(--dsh-muted);
  font-size: 0.72rem;
}

.md-grid {
  max-width: 78rem;
}

.md-typeset {
  font-size: 0.78rem;
  line-height: 1.82;
}

.md-typeset h1 {
  color: var(--md-typeset-color);
  font-weight: 720;
  letter-spacing: -0.02em;
}

.md-typeset h2 {
  border-bottom: 1px solid var(--dsh-rule);
  padding-bottom: 0.35rem;
}

.md-typeset img {
  display: block;
  height: auto;
  margin: 1.1rem auto 0.45rem;
  max-width: 100%;
}

/* 给界面截图和矢量图一个稳定的浅色画布，避免深色模式下突兀。 */
.md-typeset img.book-figure-image {
  background: var(--dsh-figure-bg);
  border-radius: 0.55rem;
  box-sizing: border-box;
  padding: clamp(0.25rem, 0.7vw, 0.55rem);
}

/* 表格块居中；表头和短标签列居中，说明文字继续左对齐。 */
.md-typeset__scrollwrap:has(> .md-typeset__table) {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}

.md-typeset__scrollwrap > .md-typeset__table {
  margin-left: auto;
  margin-right: auto;
  text-align: left;
}

.md-typeset > table:not([class]) {
  margin-left: auto;
  margin-right: auto;
}

.md-typeset table:not([class]) th,
.md-typeset table:not([class]) td {
  vertical-align: middle;
}

.md-typeset table:not([class]) thead th:not([align]),
.md-typeset table:not([class]) tbody td:first-child:not([align]) {
  text-align: center;
}

/* 竖向界面截图保持接近真实面板的尺度，避免在宽屏上被异常放大。 */
.md-typeset img.book-portrait-screenshot {
  max-width: 18rem;
}

/* README 首页沿用 GitHub 的徽章横排方式，不改变正文图片的统一尺度。 */
.md-typeset .readme-page > div[align="center"] > img,
.md-typeset .readme-page > div[align="center"] > a > img {
  display: inline-block;
  margin: 0.2rem 0.08rem;
  width: auto;
}

.md-typeset .prompt-title {
  color: var(--md-primary-fg-color);
  font-size: 0.9em;
  font-weight: 600;
}

.md-typeset blockquote:has(.prompt-title) p:not(:first-child) {
  white-space: pre-line;
}

/* 顶栏保留仓库入口，但不占用一整块横向空间。 */
.md-header__source {
  margin-left: 0.3rem;
  width: auto;
}

.md-header__source .md-source {
  padding-left: 0.45rem;
  padding-right: 0.45rem;
  width: auto;
}

.md-header__source .md-source__repository {
  display: none;
}

.book-header-logo {
  cursor: default;
}

.md-nav--primary .book-nav-title {
  color: var(--md-default-fg-color);
  text-decoration: none;
}

.md-nav--primary .book-nav-title:hover,
.md-nav--primary .book-nav-title:focus-visible {
  color: var(--dsh-accent);
}

/* 顶栏按钮使用即时可见的站内提示，不依赖浏览器延迟显示 title。 */
.md-header [data-book-tooltip] {
  position: relative;
}

.md-header [data-book-tooltip]::after {
  background: var(--md-default-fg-color);
  border-radius: 0.12rem;
  box-shadow: var(--md-shadow-z1);
  color: var(--md-default-bg-color);
  content: attr(data-book-tooltip);
  font-size: 0.64rem;
  font-weight: 400;
  left: 50%;
  line-height: 1.2;
  opacity: 0;
  padding: 0.35rem 0.45rem;
  pointer-events: none;
  position: absolute;
  top: calc(100% + 0.35rem);
  transform: translateX(-50%);
  transition: opacity 120ms ease;
  visibility: hidden;
  white-space: nowrap;
  z-index: 5;
}

.md-header [data-book-tooltip]:hover::after,
.md-header [data-book-tooltip]:focus-visible::after {
  opacity: 1;
  visibility: visible;
}

.md-header .book-header-logo::after {
  left: 0;
  transform: none;
}

.md-header label[for="__drawer"]::after {
  left: 0;
  transform: none;
}

.md-header__source .md-source::after {
  left: auto;
  right: 0;
  transform: none;
}

.md-header__inner .book-sidebar-toggle {
  display: none;
}

.book-sidebar-toggle__icon {
  display: block;
  height: 1.2rem;
  width: 1.2rem;
}

.book-sidebar-toggle__icon > svg {
  display: block;
  height: 100%;
  width: 100%;
}

.book-sidebar-toggle__icon--expand,
html.book-sidebar-collapsed .book-sidebar-toggle__icon--collapse {
  display: none;
}

html.book-sidebar-collapsed .book-sidebar-toggle__icon--expand {
  display: block;
}

/* “部分”只作为目录分隔标题，所有章节始终显示。 */
.book-nav-group {
  margin: 6px 0;
}

.book-nav-group__title {
  color: var(--md-default-fg-color);
  display: block;
  font-size: 15px;
  font-weight: 800;
  line-height: 30px;
  margin: 0;
  padding: 0;
}

.book-nav-group__list {
  margin: 0;
  padding: 0;
}

.book-nav-group__list > .md-nav__item {
  box-sizing: border-box;
  margin: 6px 0;
  padding-left: 15px;
}

.book-nav-group__list > .md-nav__item > .md-nav__link {
  font-size: 14px;
  line-height: 30px;
  margin: 0;
  padding: 0;
}

/* Material 在窄屏目录中默认给每一项加边框，这里改回书籍目录的平铺样式。 */
.md-nav--primary .book-nav-group,
.md-nav--primary .book-nav-group__list > .md-nav__item {
  border-top: 0;
}

/* 隐藏章节目录的滚动条外观，同时保留滚轮和触控滚动。 */
.md-sidebar--primary .md-sidebar__scrollwrap,
.md-sidebar--primary .md-nav--primary > .md-nav__list {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.md-sidebar--primary .md-sidebar__scrollwrap::-webkit-scrollbar,
.md-sidebar--primary .md-nav--primary > .md-nav__list::-webkit-scrollbar {
  height: 0;
  width: 0;
}

@media screen and (min-width: 76.25em) {
  .md-header__inner .book-sidebar-toggle {
    display: block;
  }

  html.book-sidebar-collapsed .md-sidebar--primary {
    display: none;
  }

  .md-sidebar--primary {
    width: 15rem;
  }

  [dir="ltr"] .md-sidebar--primary .md-sidebar__inner {
    padding-right: 0.6rem;
  }

  [dir="rtl"] .md-sidebar--primary .md-sidebar__inner {
    padding-left: 0.6rem;
  }

  .book-nav-group__list > .md-nav__item {
    padding-left: 3px;
  }
}

/* 页脚保留版权与前后章导航，弱化模板署名区域的视觉重量。 */
.md-footer-meta {
  background: var(--md-default-bg-color);
  border-top: 1px solid var(--dsh-rule);
}

.md-footer-meta .md-copyright {
  color: var(--dsh-muted);
}

/* 低于 Material 桌面断点时统一使用加宽的抽屉目录。 */
@media screen and (max-width: 76.234375em) {
  :root {
    --dsh-drawer-width: min(15rem, 82vw);
  }

  html:has([data-md-toggle="drawer"]:checked),
  body:has([data-md-toggle="drawer"]:checked) {
    overflow: hidden;
  }

  .md-sidebar--primary .md-nav__list {
    overscroll-behavior-y: contain;
  }

  .md-sidebar--primary .md-nav--primary > .md-nav__list {
    overflow-x: hidden;
  }

  /* 所有章节统一预留目录图标列，避免当前章节切换时标题重新换行。 */
  .book-nav-group__list > .md-nav__item > .md-nav__link {
    box-sizing: border-box;
    padding-inline-end: 28px;
    position: relative;
  }

  .book-nav-group__list
    > .md-nav__item
    > label.md-nav__link--active
    .md-nav__icon {
    height: 20px;
    inset-inline-end: 4px;
    margin: 0;
    position: absolute;
    top: 5px;
    width: 20px;
  }

  .md-overlay {
    overscroll-behavior: none;
    touch-action: none;
  }

  [dir="ltr"] .md-sidebar--primary {
    left: calc(-1 * var(--dsh-drawer-width));
  }

  [dir="rtl"] .md-sidebar--primary {
    right: calc(-1 * var(--dsh-drawer-width));
  }

  .md-sidebar--primary {
    width: var(--dsh-drawer-width);
  }

  [data-md-toggle="drawer"]:checked ~ .md-container .md-sidebar--primary {
    transform: translateX(var(--dsh-drawer-width));
  }

  [dir="rtl"]
    [data-md-toggle="drawer"]:checked
    ~ .md-container
    .md-sidebar--primary {
    transform: translateX(calc(-1 * var(--dsh-drawer-width)));
  }

  .md-nav--primary > .md-nav__title {
    min-height: 5.6rem;
    white-space: normal;
  }
}

.md-typeset figure.book-figure {
  margin: 1.6rem auto;
  max-width: 100%;
  text-align: center;
}

/* 单图占满正文宽度，使图片百分比相对正文区域生效。 */
.md-typeset figure.book-figure:not(.book-figure-grid) {
  width: 100%;
}

/* figure 自己已经提供段落间距，避免图片和外层 p 再重复留白。 */
.md-typeset figure.book-figure > p {
  margin: 0;
}

.md-typeset figure.book-figure img {
  margin: 0 auto;
}

.md-typeset .book-figure-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.md-typeset .book-figure-grid figcaption {
  grid-column: 1 / -1;
}

.md-typeset .book-figure-grid img {
  margin: 0 auto;
  width: 88%;
}

.md-typeset .book-figure-item {
  align-items: center;
  display: flex;
  flex-direction: column;
}

.md-typeset .book-figure-item > p {
  margin: 0;
  text-align: center;
  width: 100%;
}

.md-typeset .book-figure-note {
  color: var(--dsh-muted);
  font-size: 0.68rem;
  line-height: 1.55;
  margin-top: 0.35rem;
}

.md-typeset figcaption {
  color: var(--dsh-muted);
  font-size: 0.68rem;
  font-style: normal;
  line-height: 1.55;
  margin-top: 0.65rem;
}

.md-typeset .book-figure-number {
  color: var(--md-primary-fg-color);
  font-weight: 600;
  margin-right: 0.25em;
}

@media screen and (max-width: 44rem) {
  .xiaota-maintainer-badge {
    display: none;
  }

  .xiaota-edition-note {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.2rem;
  }

  .md-typeset img.book-technical-figure {
    height: auto !important;
    width: 100% !important;
  }

  .md-typeset img.book-portrait-screenshot {
    width: min(72%, 18rem) !important;
  }

  .md-typeset .book-figure-grid {
    grid-template-columns: 1fr;
  }
}
