:root {
  color-scheme: light;
  --bg: #fffdf9;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-soft: #fbf8f3;
  --line: #e9e3da;
  --line-soft: #f1ece5;
  --text: #282521;
  --muted: #756f67;
  --muted-light: #9b948b;
  --accent: #a85b13;
  --accent-soft: #fff1df;
  --accent-border: #f0ceb0;
  --shadow: 0 14px 40px rgba(74, 55, 34, 0.08);
  --topbar-height: 68px;
  --sidebar-width: 268px;
  --toc-width: 230px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-height) + 24px);
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

.topbar {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto 0;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(260px, 620px) 1fr;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(233, 227, 218, 0.88);
  background: rgba(255, 253, 249, 0.88);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  backdrop-filter: blur(18px) saturate(160%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.brand-logo {
  display: block;
  width: 116px;
  height: auto;
  object-fit: contain;
}

.brand-divider {
  width: 1px;
  height: 20px;
  background: var(--line);
}

.brand-name {
  color: #4f4942;
}

.search-wrap {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.78);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.search-wrap:focus-within {
  border-color: var(--accent-border);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(168, 91, 19, 0.08);
}

.search-wrap svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--muted-light);
  stroke-width: 1.8;
  stroke-linecap: round;
}

.search-wrap input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

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

.search-wrap kbd {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface-soft);
  color: var(--muted-light);
  font: 11px/1.4 inherit;
}

.back-link {
  justify-self: end;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  transition: color 0.2s;
}

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

.topbar-actions {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 18px;
}

.language-picker {
  position: relative;
}

.language-button {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.language-button:hover,
.language-button:focus-visible,
.language-picker.open .language-button {
  outline: 0;
  background: var(--surface-soft);
  color: var(--accent);
}

.language-button > svg:first-child {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.45;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.language-chevron {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s;
}

.language-picker.open .language-chevron {
  transform: rotate(180deg);
}

.language-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 8px);
  right: 0;
  width: 150px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
}

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

.language-option {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.language-option:hover,
.language-option:focus-visible {
  outline: 0;
  background: var(--surface-soft);
  color: var(--text);
}

.language-option.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}

.language-check {
  opacity: 0;
}

.language-option.active .language-check {
  opacity: 1;
}

.menu-button {
  display: none;
  width: 38px;
  height: 38px;
  padding: 9px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.menu-button span {
  display: block;
  width: 19px;
  height: 1.5px;
  margin: 4px 0;
  background: var(--text);
  transform-origin: center;
  transition: transform 0.2s ease, opacity 0.15s ease;
}

.page-shell {
  min-height: 100vh;
  padding-top: var(--topbar-height);
}

.sidebar {
  position: fixed;
  z-index: 40;
  inset: var(--topbar-height) auto 0 0;
  width: var(--sidebar-width);
  padding: 30px 20px 24px 28px;
  border-right: 1px solid var(--line-soft);
  background: rgba(251, 248, 243, 0.7);
}

.sidebar-title,
.toc-title {
  margin: 0 10px 12px;
  color: var(--muted-light);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 11px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 550;
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.page-icon {
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
}

.page-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar-note {
  position: absolute;
  bottom: 26px;
  left: 38px;
  color: var(--muted-light);
  font-size: 12px;
}

.content-wrap {
  width: min(760px, calc(100vw - var(--sidebar-width) - var(--toc-width) - 88px));
  margin: 0 auto;
  padding: 58px 0 46px;
}

.document {
  min-height: 65vh;
  font-size: 16px;
  line-height: 1.82;
}

.document h1,
.document h2,
.document h3 {
  color: #211e1a;
  font-weight: 720;
  letter-spacing: -0.022em;
}

.document h1 {
  margin: 0 0 24px;
  font-size: clamp(32px, 4vw, 42px);
  line-height: 1.25;
}

.document h2 {
  margin: 58px 0 18px;
  padding-top: 4px;
  font-size: 25px;
  line-height: 1.4;
}

.document h3 {
  margin: 34px 0 12px;
  font-size: 19px;
  line-height: 1.5;
}

.document p {
  margin: 0 0 18px;
}

.document ol,
.document ul {
  margin: 0 0 24px;
  padding-left: 1.5em;
}

.document li {
  margin: 8px 0;
  padding-left: 0.25em;
}

.document li::marker {
  color: var(--accent);
  font-weight: 650;
}

.document strong {
  color: #3b2a1d;
  font-weight: 700;
}

.document hr {
  height: 1px;
  margin: 34px 0;
  border: 0;
  background: var(--line);
}

.document blockquote {
  margin: 24px 0;
  padding: 14px 18px;
  border-left: 3px solid var(--accent-border);
  border-radius: 0 10px 10px 0;
  background: var(--surface-soft);
  color: var(--muted);
}

.document code {
  padding: 2px 5px;
  border: 1px solid var(--line-soft);
  border-radius: 5px;
  background: var(--surface-soft);
  color: #8a4810;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.document pre {
  margin: 24px 0;
  padding: 18px 20px;
  overflow: auto;
  border: 1px solid #ded7cd;
  border-radius: 12px;
  background: #24211e;
  box-shadow: 0 10px 28px rgba(50, 38, 26, 0.1);
  color: #f5eee5;
  font: 13px/1.65 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  tab-size: 2;
  white-space: pre;
}

.document pre code {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.table-scroll {
  margin: 26px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 8px 26px rgba(74, 55, 34, 0.04);
}

.document table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.65;
}

.document th,
.document td {
  padding: 13px 15px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}

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

.document th {
  background: var(--surface-soft);
  color: #4d463e;
  font-weight: 650;
}

.document em {
  color: var(--muted);
}

.document mark {
  padding: 1px 2px;
  border-radius: 3px;
  background: #ffe29f;
  color: inherit;
}

.loading-state {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted-light);
  font-size: 14px;
}

.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  to { opacity: 0.25; transform: scale(0.72); }
}

.doc-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 58px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  color: var(--muted-light);
  font-size: 12px;
}

.toc {
  position: fixed;
  top: calc(var(--topbar-height) + 52px);
  right: 30px;
  width: var(--toc-width);
  max-height: calc(100vh - var(--topbar-height) - 82px);
  overflow-y: auto;
  padding-left: 22px;
  border-left: 1px solid var(--line-soft);
}

.toc-title {
  margin-left: 0;
}

.toc a {
  display: block;
  margin: 0 0 8px;
  color: var(--muted-light);
  font-size: 12px;
  line-height: 1.5;
  text-decoration: none;
  transition: color 0.15s;
}

.toc a[data-level="3"] {
  padding-left: 11px;
}

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

.sidebar-overlay {
  display: none;
}

.search-status {
  position: fixed;
  z-index: 70;
  right: 24px;
  bottom: 24px;
  max-width: calc(100vw - 48px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--muted);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
}

.search-status.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: var(--sidebar-width) minmax(250px, 1fr) auto;
  }

  .content-wrap {
    width: min(760px, calc(100vw - var(--sidebar-width) - 72px));
    margin-left: calc(var(--sidebar-width) + 36px);
  }

  .toc {
    display: none;
  }
}

@media (max-width: 760px) {
  :root {
    --topbar-height: 60px;
  }

  .topbar {
    grid-template-columns: 38px 104px minmax(0, 1fr) 38px;
    gap: 8px;
    padding: 0 10px;
  }

  .menu-button {
    display: block;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .menu-button span:first-child {
    transform: translateY(5.5px) rotate(45deg);
  }

  body.sidebar-open .menu-button span:nth-child(2) {
    opacity: 0;
  }

  body.sidebar-open .menu-button span:last-child {
    transform: translateY(-5.5px) rotate(-45deg);
  }

  .brand-logo {
    width: 100px;
  }

  .brand-divider,
  .brand-name {
    display: none;
  }

  .brand {
    grid-column: 2;
  }

  .search-wrap {
    grid-column: 3;
    grid-row: 1;
  }

  .topbar-actions {
    grid-column: 4;
    grid-row: 1;
    gap: 0;
  }

  .language-button {
    width: 38px;
    justify-content: center;
    padding: 0;
  }

  .language-button > span,
  .language-chevron {
    display: none;
  }

  .language-menu {
    position: fixed;
    top: calc(var(--topbar-height) + 8px);
    right: 10px;
  }

  .search-wrap kbd,
  .back-link {
    display: none;
  }

  .sidebar {
    width: min(310px, 84vw);
    max-height: calc(100dvh - var(--topbar-height));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface-soft);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
    box-shadow: var(--shadow);
    will-change: transform;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition-delay: 0s;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    z-index: 35;
    inset: var(--topbar-height) 0 0;
    width: 100%;
    padding: 0;
    border: 0;
    background: rgba(42, 35, 28, 0.28);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.22s ease, visibility 0s linear 0.22s;
  }

  body.sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
  }

  .content-wrap {
    width: auto;
    margin: 0;
    padding: 38px 22px 34px;
  }

  .document {
    font-size: 15px;
    line-height: 1.78;
  }

  .document h1 {
    font-size: 30px;
  }

  .document h2 {
    margin-top: 46px;
    font-size: 22px;
  }

  .document h3 {
    font-size: 18px;
  }

  .doc-footer {
    flex-direction: column;
  }
}

@media (max-width: 430px) {
  .topbar {
    grid-template-columns: 38px 80px minmax(0, 1fr) 38px;
  }

  .brand-logo {
    width: 78px;
  }

  .search-wrap {
    padding: 0 9px;
  }
}

@media print {
  .topbar,
  .sidebar,
  .toc,
  .doc-footer,
  .search-status {
    display: none !important;
  }

  .page-shell {
    padding: 0;
  }

  .content-wrap {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .document {
    font-size: 11pt;
  }
}
