:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #fffdfa;
  --surface-strong: #ffffff;
  --ink: #1d2528;
  --muted: #667277;
  --line: #d7d6ce;
  --accent: #1f6b62;
  --accent-soft: #dcebe7;
  --danger: #9b4d24;
  --shadow: 0 12px 30px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.65;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #ece8df;
  padding: 20px 16px;
}

.brand {
  margin-bottom: 18px;
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
}

.brand-meta,
.doc-section,
.drawer-kicker {
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 13px;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.panel-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 14px;
}

.tab-button,
.nav-toggle,
.drawer-actions button,
.drawer-actions a,
.toolbar-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
}

.tab-button {
  padding: 8px 10px;
}

.tab-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.nav-panel {
  display: none;
}

.nav-panel.active {
  display: block;
}

.section-block {
  margin-bottom: 16px;
}

.section-title {
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.nav-item,
.term-item,
.related-item {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
}

.nav-item:hover,
.term-item:hover,
.related-item:hover,
.nav-item.active {
  background: rgba(31, 107, 98, 0.12);
}

.item-title {
  display: block;
  font-size: 14px;
  font-weight: 650;
}

.item-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.reader {
  min-width: 0;
}

.reader-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 244, 239, 0.95);
  padding: 12px 26px;
  backdrop-filter: blur(10px);
}

.nav-toggle {
  display: none;
  padding: 9px 12px;
}

.doc-heading {
  min-width: 0;
}

.doc-heading h1 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.toolbar-link {
  min-width: 52px;
  padding: 8px 10px;
  text-align: center;
}

.toolbar-link.disabled {
  pointer-events: none;
  opacity: 0.4;
}

.article {
  max-width: 980px;
  margin: 0 auto;
  padding: 34px 34px 96px;
}

.article h1,
.article h2,
.article h3,
.article h4 {
  line-height: 1.3;
}

.article h1 {
  margin: 0 0 20px;
  font-size: 30px;
}

.article h2 {
  margin: 34px 0 14px;
  font-size: 22px;
}

.article h3 {
  margin: 26px 0 12px;
  font-size: 18px;
}

.article p {
  margin: 12px 0;
}

.article a {
  color: var(--accent);
  text-underline-offset: 3px;
}

.article code {
  border-radius: 5px;
  background: #ece8df;
  padding: 2px 5px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 18px 0 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #ece8df;
  font-weight: 700;
}

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

.term-link {
  display: inline;
  border: 0;
  border-bottom: 1px dotted var(--accent);
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
}

.term-link:hover {
  color: #0f4d44;
}

.term-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 10;
  width: min(420px, 100vw);
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
  transform: translateX(105%);
  transition: transform 180ms ease;
}

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

.drawer-close {
  float: right;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.term-drawer h2 {
  clear: both;
  margin: 18px 0 10px;
  font-size: 24px;
}

.alias-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 18px 0;
}

.alias-list span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6f4ef;
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
}

.drawer-actions {
  display: flex;
  gap: 8px;
  margin: 18px 0 26px;
}

.drawer-actions button,
.drawer-actions a {
  padding: 9px 11px;
}

.related h3 {
  margin: 22px 0 10px;
  color: var(--muted);
  font-size: 14px;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 22px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(340px, 86vw);
    transform: translateX(-104%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

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

  .reader-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    min-height: 66px;
    padding: 10px 14px;
  }

  .nav-toggle {
    display: inline-block;
  }

  .doc-heading h1 {
    font-size: 16px;
  }

  .toolbar-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
  }

  .toolbar-link {
    min-width: 42px;
    padding: 7px 8px;
    font-size: 12px;
  }

  .article {
    padding: 24px 18px 76px;
  }

  .article h1 {
    font-size: 24px;
  }

  table {
    min-width: 680px;
  }
}
