:root {
  color-scheme: light;
  --canvas: #f6f4ee;
  --paper: #fffefa;
  --paper-muted: #f0ede4;
  --ink: #1e2926;
  --ink-soft: #56615d;
  --ink-faint: #7b847f;
  --line: #dedbd1;
  --line-soft: #ebe8df;
  --jade: #176858;
  --jade-deep: #0e4d42;
  --jade-soft: #e2f0ea;
  --gold: #a9792d;
  --danger: #9d3f35;
  --danger-soft: #f8ebe8;
  --shadow: 0 18px 50px rgb(35 42 39 / 9%);
  --sidebar-width: 286px;
  --outline-width: 238px;
  --topbar-height: 72px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: fixed;
  z-index: 50;
  inset: 0 0 auto 0;
  height: var(--topbar-height);
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(280px, 560px) 1fr;
  align-items: center;
  gap: 24px;
  padding: 0 30px;
  background: rgb(255 254 250 / 94%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  width: max-content;
  text-decoration: none;
}

.brand-copy {
  display: grid;
  gap: 1px;
  line-height: 1.1;
}

.brand-copy strong {
  font-family: var(--font-serif);
  font-size: 18px;
  letter-spacing: .08em;
}

.brand-copy small {
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: .14em;
}

.search-trigger {
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  color: var(--ink-faint);
  background: var(--paper-muted);
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  text-align: left;
  transition: border-color .18s ease, background .18s ease;
}

.search-trigger:hover {
  background: var(--paper);
  border-color: var(--line);
}

.search-trigger > span:nth-child(2) {
  flex: 1;
}

.search-trigger kbd {
  padding: 3px 7px;
  color: var(--ink-faint);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 1px 0 var(--line);
  font-size: 11px;
}

.search-icon {
  position: relative;
  width: 16px;
  height: 16px;
  display: inline-block;
  flex: 0 0 16px;
  border: 1.8px solid currentColor;
  border-radius: 50%;
}

.search-icon::after {
  position: absolute;
  content: "";
  width: 7px;
  height: 1.8px;
  right: -5px;
  bottom: -3px;
  background: currentColor;
  border-radius: 2px;
  transform: rotate(45deg);
}

.menu-button {
  display: none;
}

.sidebar {
  position: fixed;
  z-index: 30;
  inset: var(--topbar-height) auto 0 0;
  width: var(--sidebar-width);
  background: #f1efe7;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.sidebar-inner {
  min-height: 100%;
  padding: 30px 22px 26px 30px;
}

.sidebar-label,
.outline-label {
  margin: 0 0 12px;
  color: var(--ink-faint);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .16em;
  text-transform: uppercase;
}

.chapter-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 39px;
  margin: 2px 0;
  padding: 8px 12px;
  color: var(--ink-soft);
  border-radius: 9px;
  text-decoration: none;
  font-size: 14px;
  transition: color .15s ease, background .15s ease;
}

.chapter-link:hover {
  color: var(--jade-deep);
  background: rgb(255 255 255 / 65%);
}

.chapter-link.active {
  color: var(--jade-deep);
  background: var(--paper);
  box-shadow: 0 1px 3px rgb(35 42 39 / 6%);
  font-weight: 700;
}

.chapter-link.active::before {
  position: absolute;
  content: "";
  left: 0;
  width: 3px;
  height: 20px;
  background: var(--jade);
  border-radius: 0 3px 3px 0;
}

.chapter-number {
  min-width: 22px;
  color: var(--ink-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chapter-link.active .chapter-number {
  color: var(--jade);
}

.sidebar-note {
  display: flex;
  gap: 10px;
  margin-top: 26px;
  padding: 14px;
  color: var(--ink-soft);
  background: #e8e5da;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.65;
}

.sidebar-note p {
  margin: 0;
}

.note-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  margin-top: 6px;
  background: var(--gold);
  border-radius: 50%;
}

.sidebar-scrim {
  display: none;
}

.content-area {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
  margin-right: var(--outline-width);
  padding: calc(var(--topbar-height) + 60px) clamp(42px, 6vw, 94px) 64px;
}

.article {
  width: min(100%, 780px);
  margin: 0 auto;
}

.article h1,
.article h2,
.article h3 {
  color: var(--ink);
  font-family: var(--font-serif);
  font-weight: 700;
  scroll-margin-top: calc(var(--topbar-height) + 28px);
}

.article h1 {
  position: relative;
  margin: 0 0 36px;
  padding-bottom: 24px;
  font-size: clamp(34px, 5vw, 50px);
  line-height: 1.2;
  letter-spacing: .02em;
}

.article h1::after {
  position: absolute;
  content: "";
  left: 0;
  bottom: 0;
  width: 52px;
  height: 3px;
  background: var(--jade);
  border-radius: 3px;
}

.article h2 {
  margin: 48px 0 18px;
  padding-top: 2px;
  font-size: 25px;
  line-height: 1.4;
}

.article h3 {
  margin: 32px 0 12px;
  font-size: 19px;
}

.article p,
.article li {
  color: #37423e;
  font-size: 16px;
  line-height: 1.9;
}

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

.article ul,
.article ol {
  margin: 0 0 22px;
  padding-left: 24px;
}

.article li {
  margin: 6px 0;
  padding-left: 5px;
}

.article li::marker {
  color: var(--jade);
  font-weight: 700;
}

.article a {
  color: var(--jade);
  text-decoration-color: rgb(23 104 88 / 35%);
  text-underline-offset: 4px;
}

.article a:hover {
  color: var(--jade-deep);
  text-decoration-color: currentColor;
}

.article blockquote {
  margin: 0 0 28px;
  padding: 15px 18px;
  color: var(--ink-soft);
  background: var(--jade-soft);
  border-left: 3px solid var(--jade);
  border-radius: 0 10px 10px 0;
}

.article blockquote p {
  margin: 0;
  color: inherit;
  font-size: 14px;
}

.article code {
  padding: 2px 6px;
  color: var(--jade-deep);
  background: #e7eee9;
  border: 1px solid #d6e3dc;
  border-radius: 5px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: .88em;
}

.article pre {
  margin: 20px 0;
  padding: 18px;
  overflow: auto;
  color: #e8efe9;
  background: #1f2b27;
  border-radius: 12px;
}

.article pre code {
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
}

.table-wrap {
  margin: 22px 0 28px;
  overflow-x: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 5px 18px rgb(35 42 39 / 4%);
}

.article table {
  width: 100%;
  border-collapse: collapse;
  min-width: 460px;
}

.article th,
.article td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-soft);
  color: #38423f;
  text-align: left;
  font-size: 14px;
  line-height: 1.55;
}

.article th {
  color: var(--ink);
  background: #f1efe8;
  font-weight: 750;
}

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

.article th:not(:first-child),
.article td:not(:first-child) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.article > p:first-of-type strong {
  color: var(--danger);
}

.outline {
  position: fixed;
  inset: var(--topbar-height) 0 0 auto;
  width: var(--outline-width);
  padding: 50px 26px 24px 22px;
  overflow: auto;
}

.outline-inner {
  position: relative;
  padding-left: 16px;
  border-left: 1px solid var(--line);
}

.outline a {
  display: block;
  margin: 9px 0;
  color: var(--ink-faint);
  text-decoration: none;
  font-size: 12px;
  line-height: 1.55;
  transition: color .15s ease;
}

.outline a:hover,
.outline a.active {
  color: var(--jade);
}

.outline a.level-3 {
  padding-left: 10px;
}

.page-navigation {
  width: min(100%, 780px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 64px auto 0;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}

.page-nav-link {
  display: grid;
  gap: 6px;
  min-height: 78px;
  padding: 15px 17px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
  text-decoration: none;
  transition: border-color .16s ease, transform .16s ease;
}

.page-nav-link:hover {
  border-color: #a9c3b8;
  transform: translateY(-1px);
}

.page-nav-link.next {
  text-align: right;
}

.page-nav-link small {
  color: var(--ink-faint);
  font-size: 11px;
}

.page-nav-link strong {
  color: var(--jade-deep);
  font-family: var(--font-serif);
  font-size: 15px;
}

.site-footer {
  width: min(100%, 780px);
  margin: 44px auto 0;
  color: var(--ink-faint);
  text-align: center;
  font-size: 11px;
  line-height: 1.7;
}

.site-footer p {
  margin: 2px 0;
}

.search-dialog {
  width: min(700px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 64px));
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.search-dialog::backdrop {
  background: rgb(20 29 26 / 46%);
  backdrop-filter: blur(3px);
}

.search-panel {
  min-height: 240px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--line);
}

.search-box input {
  flex: 1;
  min-width: 0;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 17px;
}

.search-box button {
  padding: 6px 9px;
  color: var(--ink-soft);
  background: var(--paper-muted);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
}

.search-status {
  padding: 14px 20px 8px;
  color: var(--ink-faint);
  font-size: 12px;
}

.search-results {
  max-height: 540px;
  padding: 6px 10px 14px;
  overflow: auto;
}

.search-result {
  display: block;
  padding: 13px 14px;
  border-radius: 10px;
  text-decoration: none;
}

.search-result:hover,
.search-result:focus {
  background: var(--jade-soft);
  outline: 0;
}

.search-result strong {
  display: block;
  margin-bottom: 5px;
  color: var(--jade-deep);
  font-size: 14px;
}

.search-result p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.65;
}

.search-result mark {
  color: inherit;
  background: #f2dfa9;
  border-radius: 2px;
}

.empty-search {
  padding: 40px 20px;
  color: var(--ink-faint);
  text-align: center;
  font-size: 14px;
}

.loading-state {
  display: grid;
  gap: 16px;
}

.loading-state span {
  height: 18px;
  background: linear-gradient(90deg, #ebe8df 20%, #f6f4ee 50%, #ebe8df 80%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: loading 1.2s linear infinite;
}

.loading-state span:first-child {
  width: 55%;
  height: 50px;
}

.loading-state span:last-child {
  width: 84%;
}

.error-state {
  padding: 24px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #ebc9c3;
  border-radius: 12px;
}

@keyframes loading {
  to { background-position: -200% 0; }
}

@media (max-width: 1180px) {
  :root {
    --outline-width: 0px;
  }

  .outline {
    display: none;
  }

  .topbar {
    grid-template-columns: var(--sidebar-width) minmax(260px, 520px) 1fr;
  }
}

@media (max-width: 820px) {
  :root {
    --topbar-height: 64px;
  }

  .topbar {
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    padding: 0 16px;
  }

  .menu-button {
    width: 38px;
    height: 38px;
    display: grid;
    place-content: center;
    gap: 4px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 8px;
  }

  .menu-button span {
    width: 18px;
    height: 1.5px;
    background: var(--ink);
    border-radius: 2px;
  }

  .brand-copy small {
    display: none;
  }

  .search-trigger {
    width: 38px;
    height: 38px;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 0;
  }

  .search-trigger > span:nth-child(2),
  .search-trigger kbd {
    display: none;
  }

  .sidebar {
    z-index: 70;
    inset: 0 auto 0 0;
    width: min(310px, calc(100vw - 52px));
    padding-top: 14px;
    box-shadow: 18px 0 50px rgb(16 26 22 / 18%);
    transform: translateX(-105%);
    transition: transform .22s ease;
  }

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

  .sidebar-inner {
    padding: 22px 18px;
  }

  .sidebar-scrim {
    position: fixed;
    z-index: 65;
    inset: 0;
    display: block;
    visibility: hidden;
    opacity: 0;
    background: rgb(20 29 26 / 38%);
    border: 0;
    transition: opacity .2s ease, visibility .2s ease;
  }

  .sidebar-scrim.visible {
    visibility: visible;
    opacity: 1;
  }

  .content-area {
    margin: 0;
    padding: calc(var(--topbar-height) + 38px) 22px 48px;
  }

  .article h1 {
    margin-bottom: 28px;
    font-size: 34px;
  }

  .article h2 {
    margin-top: 40px;
    font-size: 22px;
  }

  .article p,
  .article li {
    font-size: 15px;
    line-height: 1.85;
  }
}

@media (max-width: 520px) {
  .brand-copy strong {
    font-size: 16px;
  }

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

  .page-nav-link.next {
    text-align: left;
  }

  .search-dialog {
    width: 100vw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .search-results {
    max-height: calc(100dvh - 116px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
