:root {
  --primary: #4051b5;
  --primary-dark: #303f9f;
  --accent: #526cfe;
  --header-text: #ffffff;
  --background: #ffffff;
  --surface: #ffffff;
  --text: #2f2f33;
  --muted: #6b6b73;
  --border: #e6e6e9;
  --hover: rgba(64, 81, 181, 0.08);
  --code-bg: #f5f5f5;
  --footer: #2e303e;
  --shadow: 0 0.2rem 0.5rem rgba(0, 0, 0, 0.12);
  --header-height: 96px;
  --content-width: 1220px;
  --font: Roboto, "Noto Sans SC", "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 1.2rem);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--background);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.65;
  transition:
    color 0.2s ease,
    background-color 0.2s ease;
}

body.dark {
  --background: #1e2129;
  --surface: #1e2129;
  --text: #e8e8eb;
  --muted: #a8a8b0;
  --border: #383b45;
  --hover: rgba(120, 136, 255, 0.11);
  --code-bg: #252832;
  --footer: #14161c;
}

body.drawer-open {
  overflow: hidden;
}

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

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

svg {
  display: block;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 50%;
  padding: 0.65rem 1rem;
  color: white;
  background: #000;
  transform: translate(-50%, -120%);
  transition: transform 0.15s;
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

.top-header {
  position: sticky;
  z-index: 100;
  top: 0;
  color: var(--header-text);
  box-shadow: var(--shadow);
}

.header-main {
  height: 52px;
  background: var(--primary);
}

.header-inner,
.tabs-inner,
.page-layout,
.footer-inner {
  width: min(100% - 2rem, var(--content-width));
  margin-inline: auto;
}

.header-inner {
  display: flex;
  height: 100%;
  align-items: center;
}

.site-identity {
  display: flex;
  min-width: 0;
  flex: 1 1 auto;
  align-items: center;
  color: inherit;
  gap: 0.75rem;
}

.site-avatar {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  color: var(--primary);
  background: #fff;
  border-radius: 50%;
  font-size: 0.67rem;
  font-weight: 800;
}

.site-title {
  min-width: 0;
  overflow: hidden;
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-tools {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.1rem;
  margin-left: auto;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 50%;
  place-items: center;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: rgba(255, 255, 255, 0.12);
}

.menu-button {
  display: none;
  margin-right: 0.35rem;
}

.language-menu {
  position: relative;
}

.language-panel {
  position: absolute;
  top: 46px;
  right: 0;
  width: 168px;
  overflow: hidden;
  color: var(--text);
  background: var(--surface);
  border-radius: 0.15rem;
  box-shadow: 0 0.35rem 1rem rgba(0, 0, 0, 0.22);
}

.language-panel[hidden] {
  display: none;
}

.language-panel p {
  margin: 0;
  padding: 0.7rem 1rem 0.4rem;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
}

.language-panel button {
  display: block;
  width: 100%;
  padding: 0.65rem 1rem;
  cursor: pointer;
  color: var(--text);
  background: transparent;
  border: 0;
  text-align: left;
}

.language-panel button:hover,
.language-panel button[aria-pressed="true"] {
  color: var(--accent);
  background: var(--hover);
}

.dark-icon,
body.dark .light-icon {
  display: none;
}

body.dark .dark-icon {
  display: block;
}

.header-tabs {
  height: 44px;
  background: var(--primary-dark);
}

.tabs-inner {
  display: flex;
  height: 100%;
  align-items: stretch;
  padding-left: 3rem;
}

.header-tabs a {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 0.9rem;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.7rem;
  font-weight: 700;
}

.header-tabs a:hover,
.header-tabs a.active {
  color: #fff;
}

.header-tabs a.active::after {
  position: absolute;
  right: 0.9rem;
  bottom: 0;
  left: 0.9rem;
  height: 2px;
  background: #fff;
  content: "";
}

.page-layout {
  display: grid;
  min-height: calc(100vh - var(--header-height) - 170px);
  grid-template-columns: 220px minmax(0, 1fr) 180px;
  gap: 2.2rem;
}

.left-sidebar,
.right-sidebar {
  align-self: start;
  position: sticky;
  top: calc(var(--header-height) + 1.5rem);
  max-height: calc(100vh - var(--header-height) - 3rem);
  padding-top: 2.2rem;
  overflow-y: auto;
}

.primary-sidebar,
.toc {
  display: grid;
}

.primary-sidebar a,
.toc a {
  color: var(--text);
}

.sidebar-home {
  padding: 0.55rem 0.7rem;
  font-weight: 700;
}

.sidebar-home.active {
  color: var(--accent);
  background: var(--hover);
  border-radius: 0.15rem;
}

.sidebar-section {
  display: grid;
  margin-top: 0.8rem;
  padding-left: 0.7rem;
}

.sidebar-section p,
.toc p {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
}

.sidebar-section a {
  padding: 0.33rem 0.6rem;
  border-left: 1px solid var(--border);
  font-size: 0.73rem;
}

.sidebar-section a:hover,
.toc a:hover {
  color: var(--accent);
}

.article {
  min-width: 0;
  padding: 2.7rem 0 4rem;
}

.article h1,
.article h2,
.article h3 {
  color: var(--text);
  font-weight: 400;
  line-height: 1.3;
}

.article h1 {
  margin: 0 0 2rem;
  font-size: 2rem;
  letter-spacing: -0.02em;
  
}

.article h2 {
  margin: 2.25rem 0 1rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  font-size: 1.6rem;
}

.article h3 {
  margin: 1.7rem 0 0.65rem;
  font-size: 1.2rem;
}

.article p {
  margin: 0.8rem 0;
}

.article ul {
  margin: 0.6rem 0 1rem;
  padding-left: 1.35rem;
}

.article li {
  margin: 0.35rem 0;
}

.article strong {
  font-weight: 700;
}

.heading-anchor {
  margin-left: 0.25rem;
  opacity: 0;
  font-weight: 400;
  transition: opacity 0.15s;
}

.article h2:hover .heading-anchor,
.heading-anchor:focus-visible {
  opacity: 1;
}

.last-updated {
  margin-top: 4rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.toc {
  padding-left: 0.9rem;
  border-left: 1px solid var(--border);
}

.toc a {
  padding: 0.3rem 0;
  font-size: 0.69rem;
}

.toc a.active {
  color: var(--accent);
  font-weight: 700;
}

.back-to-top {
  display: flex;
  width: min(100% - 2rem, var(--content-width));
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
  margin: 0 auto 1.5rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.back-to-top:hover {
  color: var(--accent);
}

.back-to-top svg {
  width: 1rem;
  height: 1rem;
}

.site-footer {
  color: rgba(255, 255, 255, 0.78);
  background: var(--footer);
}

.footer-inner {
  display: flex;
  min-height: 92px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.67rem;
}

.drawer-overlay,
.mobile-drawer {
  display: none;
}

@media (max-width: 960px) {
  :root {
    --header-height: 52px;
  }

  .header-tabs,
  .left-sidebar,
  .right-sidebar {
    display: none;
  }

  .menu-button {
    display: grid;
  }

  .page-layout {
    display: block;
    width: min(100% - 2.5rem, 760px);
  }

  .article {
    padding-top: 2.25rem;
  }

  .drawer-overlay {
    position: fixed;
    z-index: 150;
    inset: 0;
    display: block;
    background: rgba(0, 0, 0, 0.54);
    opacity: 0;
    transition: opacity 0.2s;
  }

  .drawer-overlay[hidden] {
    display: none;
  }

  .drawer-overlay.visible {
    opacity: 1;
  }

  .mobile-drawer {
    position: fixed;
    z-index: 160;
    top: 0;
    bottom: 0;
    left: 0;
    display: block;
    width: min(320px, 84vw);
    overflow-y: auto;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0.2rem 0 1rem rgba(0, 0, 0, 0.25);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

  .mobile-drawer.open {
    transform: translateX(0);
  }

  .drawer-profile {
    display: grid;
    min-height: 150px;
    align-content: end;
    gap: 0.8rem;
    padding: 1.2rem;
    color: #fff;
    background: var(--primary);
  }

  .drawer-avatar {
    display: grid;
    width: 54px;
    height: 54px;
    place-items: center;
    color: var(--primary);
    background: #fff;
    border-radius: 50%;
    font-weight: 800;
  }

  .drawer-profile strong {
    font-size: 0.76rem;
  }

  .mobile-drawer nav {
    display: grid;
    padding: 0.7rem;
  }

  .mobile-drawer nav a {
    padding: 0.65rem 0.8rem;
    color: var(--text);
  }

  .mobile-drawer nav a:hover {
    color: var(--accent);
    background: var(--hover);
  }

  .mobile-drawer nav p {
    margin: 0.8rem 0.8rem 0.2rem;
    color: var(--muted);
    font-size: 0.67rem;
    font-weight: 700;
  }

  .drawer-home {
    color: var(--accent) !important;
    font-weight: 700;
  }
}

@media (max-width: 560px) {
  .header-inner {
    width: calc(100% - 0.8rem);
  }

  .site-avatar {
    display: none;
  }

  .site-title {
    max-width: none;
    font-size: 0.76rem;
  }

  .header-tools {
    gap: 0;
  }

  .icon-button {
    width: 36px;
  }

  .article h1 {
    font-size: 1.55rem;
  }

  .article h2 {
    font-size: 1.2rem;
  }

  .footer-inner {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 0.35rem;
  }
}

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

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


/* 隐藏第一张图中的左侧导航 */
.left-sidebar {
  display: none;
}

/* 删除左侧导航占用的空白列 */
.page-layout {
  grid-template-columns: minmax(0, 1fr) 200px;
}

/* 放大第二张图中的右侧目录 */
.toc p {
  font-size: 0.9rem;
}

.toc a {
  font-size: 1rem;
}

.site-footer {
  color: #ffffff;
  background: #000000;
}

html,
body {
  min-height: 100%;
}

body {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.page-layout {
  flex: 1;
}

.site-footer {
  width: 100%;
  margin-top: auto;
  color: #ffffff;
  background: #000000;
}

.footer-inner {
  min-height: 64px;
}



@media (min-width: 961px) {
  .footer-inner > span:first-child {
    position: relative;
    left: clamp(-180px, calc(38.125rem + 16px - 50vw), 0px);
  }
}


@media (min-width: 961px) {
  /* 调整顶部内容整体位置 */
  .header-inner,
  .tabs-inner {
    width: min(100% - 2rem, 61rem);
  }

  /* 放大标题 */
  .site-title {
    font-size: 1.25rem;
    font-weight: 700;
  }

  /* 放大左侧 AG 图标 */
  .site-avatar {
    width: 40px;
    height: 40px;
  }

  /* 调整上下两层高度 */
  .header-main {
    height: 64px;
  }

  .header-tabs {
    height: 52px;
  }

  /* 让“主页”和上方图标左侧对齐 */
  .tabs-inner {
    padding-left: 0;
  }

  .header-tabs a {
    padding: 0;
    margin-right: 2.3rem;
    font-size: 1rem;
  }

  .header-tabs a.active::after {
    right: 0;
    left: 0;
  }
}

@media (min-width: 961px) {
  /* 顶部标题和 AG 图标向左 */
  .site-identity {
    position: relative;
    left: clamp(-250px, calc(30.5rem + 16px - 50vw), 0px);
  }

  /* “主页”向左 */
  .tabs-inner {
    position: relative;
    left: clamp(-200px, calc(30.5rem + 16px - 50vw), 0px);
  }

  /* 语言按钮保持原位 */
  .header-inner {
    left: 0;
  }
}

/* Subtle motion effects */
.scroll-progress {
  position: fixed;
  z-index: 300;
  top: 0;
  right: 0;
  left: 0;
  height: 3px;
  pointer-events: none;
  background: linear-gradient(90deg, #8fd3ff, #ffffff, #b8c1ff);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.55);
  transform: scaleX(0);
  transform-origin: left center;
  will-change: transform;
}

.header-main {
  background: linear-gradient(110deg, #4051b5, #5265c9, #4051b5);
  background-size: 180% 180%;
  animation: header-gradient 14s ease-in-out infinite;
}

.site-avatar {
  transition:
    transform 0.28s ease,
    box-shadow 0.28s ease;
}

.site-identity:hover .site-avatar {
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.14);
  transform: rotate(-5deg) scale(1.06);
}

.site-title {
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.site-identity:hover .site-title {
  opacity: 0.92;
  transform: translateX(3px);
}

.motion-reveal {
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.62s ease var(--reveal-delay, 0ms),
    transform 0.62s ease var(--reveal-delay, 0ms);
}

.motion-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.toc a {
  position: relative;
  transition:
    color 0.2s ease,
    transform 0.2s ease;
}

.toc a:hover {
  transform: translateX(3px);
}

.toc a::before {
  position: absolute;
  top: 0.35rem;
  bottom: 0.35rem;
  left: -0.95rem;
  width: 2px;
  background: var(--accent);
  content: "";
  transform: scaleY(0);
  transform-origin: center;
  transition: transform 0.2s ease;
}

.toc a.active::before {
  transform: scaleY(1);
}

.article h2 {
  transition: border-color 0.25s ease;
}

.article h2:hover {
  border-color: rgba(82, 108, 254, 0.55);
}

@keyframes header-gradient {
  0%,
  100% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .header-main {
    animation: none;
  }

  .motion-reveal {
    opacity: 1;
    transform: none;
  }

  .site-avatar,
  .site-title,
  .toc a {
    transition: none;
  }
}

/* 隐藏桌面端右侧目录 */
.right-sidebar {
  display: none;
}

/* 删除目录原来占用的空白位置 */
@media (min-width: 961px) {
  .page-layout {
    width: min(100% - 2rem, 61rem);
    grid-template-columns: minmax(0, 1fr);
  }
}
