:root {
  color-scheme: light;
  --bg: #f5f4ee;
  --card: #fffefa;
  --ink: #202a25;
  --muted: #526057;
  --accent: #275943;
  --accent-wash: #e8efe7;
  --line: #dbe1d7;
  --rule: #a4b3a5;
  --fs: 17px;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --serif: "LXGW WenKai", "Kaiti SC", STKaiti, "Songti SC", SimSun, serif;
  --side: clamp(18px, 4vw, 48px);
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); font: 16px/1.65 var(--sans); }
a { color: var(--accent); text-underline-offset: .2em; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { background: #d5e4d7; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 70; transform: translateY(-150%); background: var(--card); padding: 8px 14px; }
.skip-link:focus { transform: none; }

.site-head { background: var(--card); border-bottom: 1px solid var(--line); }
.head-inner {
  max-width: 1240px; min-height: 72px; margin: auto; padding: 10px var(--side);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: inline-flex; align-items: center; flex: none; gap: 10px; color: var(--ink); font-size: 19px; font-weight: 700; text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 3px; background: var(--accent); border-radius: 9px; }
.brand-mark i { width: 3px; height: 16px; background: #fffefa; border-radius: 1px; }
.brand-mark i:nth-child(2) { height: 19px; }
.brand-mark i:last-child { transform: rotate(-14deg); height: 14px; }
.head-nav, .form-actions { display: flex; align-items: center; gap: 8px; }
.button, .toolbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  min-height: 42px; padding: 7px 15px; color: var(--accent); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; font: 600 14px/1.4 var(--sans);
  text-decoration: none; white-space: nowrap;
}
.button:hover, .toolbtn:hover { background: var(--accent-wash); border-color: var(--rule); }
.button.primary { background: var(--accent); color: #fffefa; border-color: var(--accent); }
.button.primary:hover { background: #194432; }
.button.quiet { background: transparent; border-color: transparent; color: var(--muted); }
.button.quiet:hover { background: var(--accent-wash); color: var(--accent); }

.list-wrap { max-width: 1100px; margin: auto; padding: 46px var(--side) 80px; }
.library-head {
  padding: clamp(24px, 5vw, 52px); border-radius: 20px;
  background: linear-gradient(112deg, #e2ebdf, #edf1e9 72%, #f5f5ee);
  border: 1px solid #d9e4d7;
}
.library-head h1 { margin: 0 0 20px; font: 700 clamp(32px, 5vw, 52px)/1.2 var(--serif); }
.search { display: flex; justify-content: space-between; gap: 6px; width: min(100%, 520px); padding: 5px; border: 1px solid var(--rule); border-radius: 11px; background: var(--card); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.search input { flex: 1; min-width: 0; border: 0; border-radius: 6px; padding: 7px 11px; background: transparent; }
.search input:focus { outline: none; }
.search .button { min-width: 72px; }
.list-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 27px 0 12px; color: var(--muted); font-size: 14px; }
.list-meta p { margin: 0; overflow-wrap: anywhere; }
.list-meta a { flex: none; }
.card-list { display: grid; gap: 14px; }
.card, .empty { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: clamp(20px, 4vw, 32px); }
.card h2 { margin: 0; font: 700 clamp(22px, 3vw, 29px)/1.45 var(--serif); overflow-wrap: anywhere; }
.card-title { color: var(--ink); text-decoration: none; }
.card-title:hover { color: var(--accent); text-decoration: underline; }
.tag { display: inline-block; margin-bottom: 9px; padding: 3px 10px; border-radius: 18px; background: var(--accent-wash); color: var(--accent); font-size: 12px; font-weight: 650; }
.excerpt { color: var(--muted); font-size: 15px; margin: 9px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.meta { display: flex; flex-wrap: wrap; gap: 3px 13px; color: var(--muted); font: 13px/1.65 var(--sans); }
.card .meta { margin-top: 14px; }
.meta > * + *::before { content: "·"; margin-right: 13px; color: var(--muted); }
.empty { text-align: center; padding-block: 48px; }
.empty h2 { margin: 0 0 12px; font-size: 20px; }
.empty p { margin: 0; color: var(--muted); }

#progress { position: fixed; inset: 0 auto auto 0; height: 3px; width: 0; background: var(--accent); z-index: 60; }
.layout {
  display: grid; grid-template-columns: minmax(0, 820px); align-items: start; justify-content: center;
  max-width: 1240px; margin: auto; padding: 36px var(--side) 90px;
}
.layout.has-toc { grid-template-columns: minmax(0, 820px) minmax(195px, 240px); gap: clamp(24px, 3vw, 38px); }
.article {
  min-width: 0; padding: clamp(24px, 4vw, 50px); background: var(--card);
  border: 1px solid var(--line); border-radius: 17px; font: var(--fs)/1.85 var(--serif); overflow-wrap: anywhere;
}
.article-head { margin-bottom: 26px; }
.back-link { color: var(--accent); font: 600 14px/1.5 var(--sans); text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.article h1 { margin: 16px 0 11px; font-size: clamp(28px, 4vw, 42px); line-height: 1.35; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 17px; }
.toolbtn { min-height: 40px; padding-inline: 12px; }
.clipboard-field { position: fixed; top: 0; left: 0; opacity: 0; }
.source-card { background: #f1f5ed; border: 1px solid var(--line); border-radius: 10px; padding: 12px 17px; margin-bottom: 28px; }
.srow { display: grid; grid-template-columns: 4.6em minmax(0, 1fr); gap: 8px; padding: 7px 0; font-size: .95em; line-height: 1.65; }
.srow + .srow { border-top: 1px solid var(--line); }
.sval > :first-child { margin-top: 0; }
.sval > :last-child { margin-bottom: 0; }
.skey { color: var(--accent); font-weight: 700; }
.article-body > :first-child { margin-top: 0; }
.article-body > :last-child { margin-bottom: 0; }
.article-body [id] { scroll-margin-top: 26px; }
.article-body p { margin: 0 0 1.15em; }
.article-body h2 { font-size: 1.42em; line-height: 1.45; margin: 1.85em 0 .65em; padding-top: .75em; border-top: 1px solid var(--line); }
.article-body h3 { font-size: 1.2em; line-height: 1.5; margin: 1.45em 0 .6em; }
.article-body hr { border: 0; border-top: 1px solid var(--line); margin-block: 2em; }
.article-body blockquote { margin: 1.2em 0; padding: .75em 1em; border-left: 3px solid var(--rule); background: #f1f5ed; }
.article-body blockquote > :last-child { margin-bottom: 0; }
.article-body ul, .article-body ol { margin: 0 0 1.15em; padding-inline-start: 1.4em; }
.article-body li { margin: .35em 0; }
.article-body li::marker { color: var(--accent); }
.article-body code { font: .83em/1.6 "SF Mono", Menlo, Consolas, monospace; background: #edf0e9; border-radius: 4px; padding: 2px 5px; }
.article-body pre { padding: 14px 16px; overflow-x: auto; background: #edf0e9; border: 1px solid var(--line); border-radius: 8px; }
.article-body pre code { background: none; padding: 0; }
.article table { width: 100%; border-collapse: collapse; font-size: .94em; }
.article :is(th, td) { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
.article thead { background: #edf2ea; }
.tablewrap { overflow-x: auto; margin: 1.2em 0; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: .15em 0; }
.article img { display: block; max-width: 100%; height: auto; margin: auto; background: white; border-radius: 6px; }
.article img[role="button"], .article figure a img { cursor: zoom-in; }
.article figure { margin: 28px 0; text-align: center; }
.article figcaption { color: var(--muted); font-size: .9em; margin-top: 8px; }

.toc {
  position: sticky; top: 24px; max-height: calc(100dvh - 48px); overflow: auto; scrollbar-width: thin;
  padding: 16px 11px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.toc-title { margin: 0 9px 7px; color: var(--ink); font-size: 14px; font-weight: 700; }
.toc a, .toc-mobile a { display: block; padding: 7px 9px; border-radius: 6px; color: var(--muted); font: 14px/1.45 var(--sans); text-decoration: none; overflow-wrap: anywhere; }
.toc a.l3, .toc-mobile a.l3 { padding-left: 22px; font-size: 13px; }
.toc a:hover, .toc-mobile a:hover, .toc a[aria-current="location"] { color: var(--accent); background: var(--accent-wash); }
.toc a[aria-current="location"] { box-shadow: inset 2px 0 var(--accent); }
.toc-mobile { display: none; margin-bottom: 23px; border: 1px solid var(--line); border-radius: 9px; }
.toc-mobile summary { padding: 10px 13px; cursor: pointer; color: var(--accent); font: 650 14px/1.6 var(--sans); }
.toc-body { padding: 0 7px 8px; }
.pager { display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid var(--line); margin-top: 36px; padding-top: 16px; font-size: .95em; }
.pager a { max-width: 49%; }
.pager .next { margin-left: auto; text-align: right; }
.files { margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--line); }
.files-title { margin: 0 0 6px; font-weight: 700; }
.files a { display: block; padding-block: 4px; }
#totop { display: none; position: fixed; bottom: max(17px, env(safe-area-inset-bottom)); right: 17px; z-index: 50; width: 44px; height: 44px; border: 1px solid var(--rule); border-radius: 50%; background: var(--card); color: var(--accent); font-size: 20px; box-shadow: 0 2px 10px #202a251a; }
#totop.show { display: block; }
#lightbox { position: fixed; max-width: min(92vw, 1440px); max-height: 92vh; padding: 0; border: 0; border-radius: 10px; background: transparent; }
#lightbox::backdrop { background: #122017ec; }
#lightbox img { display: block; max-width: 100%; max-height: 90vh; object-fit: contain; }
.lightbox-close { position: absolute; top: 8px; right: 8px; width: 42px; height: 42px; border: 1px solid var(--rule); border-radius: 50%; background: var(--card); color: var(--accent); font-size: 24px; line-height: 1; }

.form-wrap { max-width: 870px; margin: auto; padding: 42px var(--side) 80px; }
.form-wrap h1 { margin: 10px 0 20px; font: 700 34px/1.3 var(--serif); }
.form-wrap form { padding: clamp(18px, 4vw, 28px); border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.form-wrap label { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 650; }
.form-wrap input, .form-wrap textarea { display: block; width: 100%; margin-bottom: 17px; padding: 10px 13px; background: #fff; border: 1px solid var(--rule); border-radius: 8px; }
.form-wrap textarea { min-height: 320px; resize: vertical; line-height: 1.7; }
.hint { color: var(--muted); font-size: 13px; margin: -5px 0 18px; }
.err { color: #9a3b26; margin: 0 0 12px; font-size: 14px; }
.login-page { min-height: 100vh; display: grid; align-items: center; padding: var(--side); }
.login-wrap { width: min(100%, 430px); padding: clamp(22px, 5vw, 38px); border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.login-wrap h1 { margin-top: 22px; }
.login-wrap form { border: 0; padding: 0; }
.login-wrap button { width: 100%; }

@media (max-width: 880px) {
  .layout.has-toc { grid-template-columns: minmax(0, 820px); gap: 0; }
  .toc { display: none; }
  .toc-mobile { display: block; }
}
@media (max-width: 520px) {
  .head-inner { min-height: 62px; }
  .brand { gap: 7px; font-size: 17px; }
  .brand-mark { width: 29px; height: 29px; }
  .head-nav { gap: 2px; }
  .head-nav .button { min-height: 44px; padding-inline: 8px; }
  .list-wrap, .layout { padding-top: 23px; }
  .library-head { border-radius: 15px; }
  .search .button { min-width: 60px; }
  .layout { padding-inline: 0; }
  .article { border: 0; border-radius: 0; padding: 21px var(--side) 34px; }
  .article h1 { font-size: 27px; }
  .toolbtn { min-height: 44px; }
  .srow { grid-template-columns: 1fr; gap: 0; }
}
@media print {
  body { background: #fff; }
  .site-head, .skip-link, #progress, .toolbar, .toc, .toc-mobile, #totop, #lightbox, .back-link, .pager { display: none !important; }
  .layout, .layout.has-toc { display: block; max-width: none; padding: 0; }
  .article { border: 0; padding: 0; }
  .article h1, .article h2, .article h3 { break-after: avoid; }
}
