:root {
  --bg: #fbfaf8;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #646d76;
  --line: #e3e0da;
  --accent: #2f6f4f;
  --accent-soft: #eef4f0;
  --code-bg: #f4f2ee;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181a;
    --panel: #1d2023;
    --text: #e6e3de;
    --muted: #9aa3ad;
    --line: #2e3338;
    --accent: #7fb894;
    --accent-soft: #232c27;
    --code-bg: #24282c;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 600; font-size: 15px; color: var(--text); }
.topbar nav { display: flex; gap: 16px; font-size: 14px; }
.topbar nav a { color: var(--muted); }
.topbar nav a:hover { color: var(--accent); }

main {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-head h1 { font-size: 22px; margin: 0; }
.count { color: var(--muted); font-size: 13px; }

.doc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.doc-item {
  padding: 16px 14px;
  border-bottom: 1px solid var(--line);
  border-radius: 6px;
  transition: background 0.12s;
}
.doc-item:hover { background: var(--accent-soft); }
.doc-item > a { font-size: 17px; font-weight: 550; color: var(--text); }
.doc-item > a:hover { text-decoration: none; color: var(--accent); }
.doc-item p { margin: 6px 0 8px; color: var(--muted); font-size: 14px; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.tag {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  color: var(--muted);
}
.empty { padding: 40px 14px; color: var(--muted); text-align: center; }

.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.doc-head h1 { font-size: 28px; margin: 0 0 8px; line-height: 1.3; }
.doc-actions { flex: none; }

.btn, .btn-ghost, .btn-primary {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 7px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.btn:hover, .btn-ghost:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.9; text-decoration: none; }

.badge {
  font-size: 11px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* Markdown 正文 */
.markdown { margin-top: 24px; }
.markdown h1, .markdown h2, .markdown h3 { line-height: 1.35; margin: 1.8em 0 0.6em; }
.markdown h1 { font-size: 26px; }
.markdown h2 { font-size: 21px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.markdown h3 { font-size: 17px; }
.markdown p { margin: 0.9em 0; }
.markdown ul, .markdown ol { padding-left: 1.5em; }
.markdown li { margin: 0.3em 0; }
.markdown blockquote {
  margin: 1em 0;
  padding: 2px 16px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--muted);
}
.markdown code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
}
.markdown pre {
  background: var(--code-bg);
  padding: 14px 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
}
.markdown pre code { background: none; padding: 0; font-size: inherit; }
.markdown .raw-html { color: var(--muted); font-size: 12px; }
.markdown img { max-width: 100%; border-radius: var(--radius); }
.markdown table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 14px; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; }
.markdown th { background: var(--accent-soft); }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 2em 0; }

/* 编辑器 */
.editor { display: flex; flex-direction: column; gap: 16px; }
.editor label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.editor input[type="text"], .editor input:not([type]), .editor input[name="title"], .editor input[name="slug"], .editor input[name="tags"] {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.editor-body { display: grid; gap: 12px; }
.pane { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  background: var(--accent-soft);
}
.pane-head button { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; font-family: inherit; }

#editorInput {
  border: 0;
  padding: 14px 16px;
  min-height: 460px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.65;
  background: var(--panel);
  color: var(--text);
  outline: none;
  width: 100%;
}

.preview-pane .markdown { margin: 0; padding: 14px 16px; min-height: 460px; }

@media (min-width: 1000px) {
  main { max-width: 1200px; }
  .editor-body { grid-template-columns: 1fr 1fr; }
  .pane.preview-pane { display: flex !important; }
}

.editor-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.inline { flex-direction: row !important; align-items: center; gap: 7px !important; }
.editor-submit { display: flex; gap: 10px; align-items: center; }

.error {
  margin: 0;
  padding: 10px 14px;
  border: 1px solid #d9534f;
  background: #fdf1f0;
  color: #a33;
  border-radius: 7px;
  font-size: 13px;
}
@media (prefers-color-scheme: dark) {
  .error { background: #2e1c1c; color: #e79c9c; border-color: #5a2e2e; }
}

.unlock { max-width: 380px; margin: 40px auto; display: flex; flex-direction: column; gap: 14px; }
.unlock h1 { font-size: 20px; margin: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }
.unlock input {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}
.unlock button { align-self: flex-start; }

.message { text-align: center; padding: 60px 20px; }
.message h1 { font-size: 22px; margin-bottom: 8px; }
.message p { color: var(--muted); }

.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
