/* ============ netwiki 主题 ============ */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #23262b;
  --muted: #6b7280;
  --border: #e3e6ea;
  --link: #1a5fb4;
  --link-visited: #6b4bb8;
  --missing: #b3261e;
  --accent: #1a5fb4;
  --code-bg: #f4f5f7;
  --mark: #fff3a3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .04);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --surface: #1c1f25;
    --text: #e6e8eb;
    --muted: #9aa1ac;
    --border: #2c313a;
    --link: #7cb0ff;
    --link-visited: #b79cff;
    --missing: #ff8a80;
    --accent: #7cb0ff;
    --code-bg: #22262e;
    --mark: #6b5b1f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.75 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1180px, 100% - 32px); margin: 0 auto; }

/* ---------- 头部 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #8e7bff));
  color: #fff; font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; letter-spacing: .3px; }
.brand-text small { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.top-nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.top-nav a { color: var(--muted); text-decoration: none; }
.top-nav a:hover { color: var(--link); }

/* ---------- 布局 ---------- */
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 28px;
  padding: 24px 0 56px;
  align-items: start;
}

/* ---------- 侧栏 ---------- */
.sidebar { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card-title {
  margin: 0 0 8px; font-size: 13px; font-weight: 700;
  color: var(--muted); letter-spacing: .08em; text-transform: uppercase;
}
.page-list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.page-list li { padding: 3px 0; }

/* ---------- 目录 ---------- */
.toc { font-size: 14px; }
.toc-title {
  font-size: 13px; font-weight: 700; color: var(--muted);
  letter-spacing: .08em; margin-bottom: 8px; text-transform: uppercase;
}
.toc ul { list-style: none; margin: 0; padding-left: 0; }
.toc ul ul { padding-left: 14px; border-left: 1px solid var(--border); margin-left: 4px; }
.toc li { margin: 2px 0; }
.toc a {
  display: block; padding: 2px 6px; border-radius: 6px;
  color: var(--muted); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.toc a:hover { background: var(--code-bg); color: var(--link); }
.toc a.is-active { color: var(--link); font-weight: 600; background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- 正文 ---------- */
.content { min-width: 0; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--link); }

.mw-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px 36px;
  box-shadow: var(--shadow);
  overflow-wrap: break-word;
}

.mw-body h1 {
  font-size: 28px; line-height: 1.35; margin: .2em 0 .6em;
  padding-bottom: .35em; border-bottom: 1px solid var(--border);
}
.mw-body h2 {
  font-size: 21px; margin: 1.6em 0 .6em;
  padding-bottom: .3em; border-bottom: 1px solid var(--border);
}
.mw-body h3 { font-size: 18px; margin: 1.4em 0 .5em; }
.mw-body h4, .mw-body h5, .mw-body h6 { font-size: 16px; margin: 1.2em 0 .5em; }
.mw-body h1:hover .anchor, .mw-body h2:hover .anchor,
.mw-body h3:hover .anchor, .mw-body h4:hover .anchor { opacity: 1; }
.anchor {
  opacity: 0; float: left; margin-left: -.8em; padding-right: .25em;
  color: var(--muted); text-decoration: none; font-weight: 400;
  transition: opacity .15s;
}

.mw-body p { margin: .75em 0; }
.mw-body a { color: var(--link); text-decoration: none; }
.mw-body a:hover { text-decoration: underline; }
.mw-body a:visited { color: var(--link-visited); }
.mw-body a.ext::after { content: "↗"; font-size: .8em; opacity: .6; margin-left: 2px; }
a.wikilink.is-missing, .mw-body a.is-missing { color: var(--missing); }
a.wikilink.is-current { font-weight: 700; color: var(--link); }

.mw-body ul, .mw-body ol { margin: .6em 0; padding-left: 1.6em; }
.mw-body li { margin: .15em 0; }
.mw-body li > ul, .mw-body li > ol { margin: .2em 0; }
li.task-item { list-style: none; margin-left: -1.3em; }
input.task { margin-right: 4px; vertical-align: -1px; }

.mw-body blockquote {
  margin: 1em 0; padding: .4em 1em;
  border-left: 3px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
  color: var(--muted); border-radius: 0 8px 8px 0;
}
.mw-body blockquote blockquote { margin: .6em 0; }

.mw-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.8em 0; }

.mw-body code {
  background: var(--code-bg); border-radius: 5px;
  padding: .15em .38em; font-size: .9em; font-family: var(--mono);
}
.mw-body pre {
  position: relative;
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 14px; overflow: auto; margin: 1em 0;
}
.mw-body pre code { background: none; padding: 0; font-size: 13.5px; line-height: 1.6; }

/* 代码块：语言标签 + 复制按钮 */
.mw-body pre[data-label]::before {
  content: attr(data-label);
  position: absolute; top: 0; right: 12px;
  font: 11px/1 var(--mono); color: var(--muted);
  padding-top: 6px; letter-spacing: .05em; text-transform: uppercase;
}
.copy-btn {
  position: absolute; bottom: 8px; right: 8px;
  opacity: 0; transition: opacity .15s;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); border-radius: 6px;
  padding: 2px 8px; font-size: 12px; cursor: pointer;
}
.mw-body pre:hover .copy-btn { opacity: 1; }
.copy-btn:focus-visible { opacity: 1; }

.table-wrap { overflow-x: auto; margin: 1em 0; }
.mw-body table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.mw-body th, .mw-body td { border: 1px solid var(--border); padding: 7px 12px; }
.mw-body th { background: var(--code-bg); font-weight: 600; text-align: left; }
.mw-body tbody tr:nth-child(even) { background: color-mix(in srgb, var(--code-bg) 55%, transparent); }

.mw-body mark { background: var(--mark); color: inherit; padding: 0 .15em; border-radius: 3px; }
.mw-body img { max-width: 100%; height: auto; border-radius: 8px; }
.mw-body kbd {
  font-family: var(--mono); font-size: .85em;
  border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; background: var(--code-bg);
}

.mw-body .toc {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 16px; margin: 1em 0 1.4em;
  max-width: 340px;
}

.mw-body details {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; margin: 1em 0; background: var(--code-bg);
}
.mw-body summary { cursor: pointer; font-weight: 600; }

/* ---------- 脚注 ---------- */
.footnotes { margin-top: 2em; font-size: 14px; color: var(--muted); }
.footnotes ol { padding-left: 1.4em; }
.footnotes li { margin: .3em 0; }
.fnback { text-decoration: none; }

/* ---------- 分类 ---------- */
.categories { margin-top: 16px; font-size: 14px; color: var(--muted); }
.cat {
  display: inline-block; margin-right: 6px; padding: 2px 10px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--link); text-decoration: none;
}
.cat:hover { background: var(--code-bg); }

.missing-tip { color: var(--muted); }

/* ---------- 页脚 ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 18px 0 32px; font-size: 13px; color: var(--muted); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.site-footer a { color: var(--muted); }

/* ---------- 小组件 ---------- */
.to-top {
  position: fixed; right: 18px; bottom: 24px; z-index: 30;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 18px; cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding-top: 16px; }
  .sidebar { position: static; order: 2; }
  .mw-body { padding: 20px 18px 28px; }
  .mw-body h1 { font-size: 24px; }
}

/* ---------- 分区目录（侧栏） ---------- */
.ns-group { border-top: 1px solid var(--border); padding: 6px 0 2px; }
.ns-group:first-of-type { border-top: 0; }
.ns-group > summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px;
  padding: 4px 0; font-size: 14px;
}
.ns-group > summary::-webkit-details-marker { display: none; }
.ns-group > summary::before {
  content: "▸"; color: var(--muted); font-size: 11px; transition: transform .15s;
}
.ns-group[open] > summary::before { content: "▾"; }
.ns-name { font-weight: 600; }
.ns-code {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  background: var(--code-bg); border-radius: 4px; padding: 1px 5px;
}
.ns-count {
  margin-left: auto; font-size: 11px; color: var(--muted);
  background: var(--code-bg); border-radius: 999px; padding: 1px 7px;
}
.ns-group .page-list { padding-left: 14px; margin-top: 4px; }

/* ---------- 条目资源清单 ---------- */
.asset-list li { display: flex; align-items: baseline; gap: 8px; }
.asset-list small { color: var(--muted); font-size: 11px; font-family: var(--mono); }

/* ---------- 全部条目目录页 ---------- */
.mw-body h2 .ns-code { font-size: 12px; vertical-align: 2px; }
.index-table { font-size: 14px; }
.index-table td:first-child { font-weight: 600; }
.index-table td:not(:first-child) { color: var(--muted); white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------- 条目头图 ---------- */
.mw-body img { display: block; margin: .4em 0 1em; }

/* ---------- 新建入口 ---------- */
.new-link {
  display: inline-block; margin-bottom: 8px;
  font-size: 13px; color: var(--link); text-decoration: none;
  border: 1px dashed var(--border); border-radius: 999px; padding: 3px 12px;
}
.new-link:hover { background: var(--code-bg); text-decoration: none; }
.top-nav .new-link { border-style: solid; padding: 3px 10px; }
.ns-new { margin-top: 4px; font-size: 12px; opacity: .75; }
.ns-new a { color: var(--muted); text-decoration: none; }
.ns-new a:hover { color: var(--link); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 6px 14px; font-size: 14px;
  text-decoration: none; cursor: pointer; line-height: 1.5;
}
.btn:hover { background: var(--code-bg); text-decoration: none; }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-mini { padding: 2px 9px; font-size: 12px; border-radius: 6px; }

/* ---------- 表单 ---------- */
.new-form {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin: 1.2em 0;
}
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; max-width: 460px; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font-size: 15px; background: var(--surface); color: var(--text);
  font-family: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); }
.field-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint { font-size: 13px; }
.hint.good { color: #2e9e5b; }
.hint.bad { color: var(--missing); }
.form-error {
  background: color-mix(in srgb, var(--missing) 12%, transparent);
  border-left: 3px solid var(--missing); color: var(--missing);
  padding: 8px 12px; border-radius: 0 8px 8px 0; margin: 1em 0;
}
.chip-list { list-style: none; margin: .6em 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip-list li {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 12px; font-size: 14px; background: var(--surface);
  display: inline-flex; align-items: center; gap: 8px;
}
.chip-list small { color: var(--muted); font-size: 11px; }
.chip-list .danger { color: var(--missing); font-size: 12px; text-decoration: none; }

/* ---------- 编辑器 ---------- */
.mw-body.is-editor { padding: 0; background: none; border: 0; box-shadow: none; }
.editor {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); overflow: hidden;
}
.editor-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.editor-title { font-size: 15px; }
.editor-title small { display: block; font-size: 12px; font-family: var(--mono); }
.editor-tabs { display: flex; gap: 4px; }
.editor-tabs .tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 8px 8px 0 0; padding: 5px 14px; font-size: 13px; cursor: pointer;
}
.editor-tabs .tab.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px;
  padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--code-bg);
}
.editor-toolbar button {
  min-width: 34px; height: 30px; padding: 0 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 6px; font-size: 13px; cursor: pointer; font-family: inherit;
}
.editor-toolbar button:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.editor-main { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 0; }
.editor-body { min-width: 0; border-right: 1px solid var(--border); }
.editor-side { padding: 12px; background: var(--code-bg); display: flex; flex-direction: column; gap: 12px; }
.editor-side .card { box-shadow: none; }

.ed-visual, .ed-source {
  min-height: 420px; padding: 16px 20px; border: 0; outline: none;
  font: 15px/1.8 inherit; color: var(--text); background: var(--surface);
}
.ed-source {
  width: 100%; box-sizing: border-box; resize: vertical;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.7; tab-size: 2;
}
.ed-visual h1 { font-size: 24px; margin: .3em 0 .5em; border-bottom: 1px solid var(--border); padding-bottom: .2em; }
.ed-visual h2 { font-size: 20px; margin: 1.1em 0 .4em; border-bottom: 1px solid var(--border); padding-bottom: .2em; }
.ed-visual h3 { font-size: 17px; margin: 1em 0 .3em; }
.ed-visual p { margin: .5em 0; }
.ed-visual ul, .ed-visual ol { margin: .5em 0; padding-left: 1.5em; }
.ed-visual blockquote {
  margin: .6em 0; padding: .2em 1em; border-left: 3px solid var(--accent); color: var(--muted);
}
.ed-visual pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; overflow: auto;
  font-family: var(--mono); font-size: 13px; white-space: pre-wrap;
}
.ed-visual code { font-family: var(--mono); background: var(--code-bg); padding: .1em .3em; border-radius: 4px; }
.ed-visual pre code { background: none; padding: 0; }
.ed-visual table { border-collapse: collapse; width: 100%; margin: .6em 0; }
.ed-visual td, .ed-visual th { border: 1px solid var(--border); padding: 5px 9px; min-width: 60px; }
.ed-visual img { max-width: 100%; height: auto; border-radius: 6px; }
.ed-visual a { color: var(--link); }
.ed-visual mark { background: var(--mark); color: inherit; }
.ed-visual li.task-item { list-style: none; margin-left: -1.2em; }
.ed-visual.is-empty::before {
  content: attr(data-placeholder); color: var(--muted); position: absolute; pointer-events: none;
}
.editor-body { position: relative; }
.ed-preview { padding: 20px 24px; min-height: 420px; }

.editor-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 10px 14px; border-top: 1px solid var(--border); background: var(--code-bg);
}
.editor-status { margin-right: auto; font-size: 13px; }
.editor-status.bad { color: var(--missing); }

.drop {
  border: 1px dashed var(--border); border-radius: 8px; padding: 14px 10px;
  text-align: center; font-size: 13px; color: var(--muted); background: var(--surface);
}
.drop.is-over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.file-label { color: var(--link); cursor: pointer; text-decoration: underline; }
.file-label input { display: none; }
.tiny { font-size: 11.5px; line-height: 1.6; }
.asset-row {
  display: flex; align-items: center; gap: 6px; font-size: 13px;
  border-top: 1px solid var(--border); padding: 5px 0; flex-wrap: wrap;
}
.asset-row img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; }
.asset-row small { color: var(--muted); font-size: 11px; }
.asset-row .btn-mini { margin-left: auto; }
.tip-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; color: var(--muted); }
.tip-list li { padding: 3px 0; }
.tip-list code { background: var(--surface); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

@media (max-width: 900px) {
  .editor-main { grid-template-columns: minmax(0, 1fr); }
  .editor-body { border-right: 0; border-bottom: 1px solid var(--border); }
  .ed-visual, .ed-source, .ed-preview { min-height: 320px; }
}

/* ---------- 目录占位块（编辑器） ---------- */
.toc-ph {
  border: 1px dashed var(--accent); border-radius: 8px;
  padding: 8px 14px; margin: .6em 0; font-size: 13px;
  color: var(--muted); background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.toc-ph::before { content: "{{toc}} · "; font-family: var(--mono); }
