:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-muted: #f5f5f4;
  --border: #e7e5e4;
  --text: #1c1917;
  --text-secondary: #44403c;
  --text-muted: #78716c;
  --accent: #d97706;
  --accent-hover: #b45309;
  --accent-soft: #fef3c7;
  --accent-text: #92400e;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.04), 0 8px 22px rgba(28, 25, 23, 0.04);
}

html[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-muted: #0f172a;
  --border: #334155;
  --text: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #fbbf24;
  --accent-hover: #fcd34d;
  --accent-soft: rgba(251, 191, 36, 0.16);
  --accent-text: #fde68a;
  --danger: #f87171;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

.page.wide {
  max-width: 1200px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}

.brand-icon {
  width: 34px;
  height: 34px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  padding: 5px 8px;
  border-radius: 8px;
}

.nav-link:hover {
  color: var(--accent);
  background: var(--surface);
}

.btn-primary {
  border: none;
  background: var(--accent);
  color: #ffffff;
  border-radius: 9px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

html[data-theme="dark"] .btn-primary {
  color: #0f172a;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 9px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* 首页筛选与文章列表 */
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.chip.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: transparent;
  font-weight: 600;
}

.search-input {
  min-width: 220px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.posts-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.post-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.16s ease, border-color 0.16s ease;
}

.post-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.post-card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.cat-pill {
  background: var(--accent-soft);
  color: var(--accent-text);
  padding: 1px 8px;
  border-radius: 999px;
  font-weight: 600;
}

.post-card-title {
  margin: 8px 0 6px;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.35;
}

.post-card-summary {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.tag-pill {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-muted);
  padding: 1px 8px;
  border-radius: 6px;
}

/* 阅读页布局 */
.article-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 28px;
  align-items: start;
}

.article-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 30px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.article-title {
  margin: 10px 0 8px;
  font-size: 28px;
  line-height: 1.3;
}

.article-actions {
  display: flex;
  gap: 8px;
  margin: 14px 0 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.toc-box {
  position: sticky;
  top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.toc-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.toc-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.toc-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  line-height: 1.4;
}

.toc-link:hover {
  color: var(--accent);
}

.toc-link.lv2 {
  padding-left: 10px;
}

.toc-link.lv3 {
  padding-left: 20px;
}

/* Markdown 正文 */
.md-body {
  font-size: 16px;
  line-height: 1.8;
  word-break: break-word;
}

.md-body h1,
.md-body h2,
.md-body h3 {
  margin: 22px 0 10px;
  line-height: 1.35;
}

.md-body h1 {
  font-size: 22px;
}

.md-body h2 {
  font-size: 19px;
}

.md-body h3 {
  font-size: 17px;
}

.md-body p {
  margin: 0 0 14px;
}

.md-body blockquote {
  margin: 14px 0;
  padding: 8px 14px;
  border-left: 4px solid var(--accent);
  background: var(--surface-muted);
  color: var(--text-secondary);
  border-radius: 0 10px 10px 0;
}

.md-body ul,
.md-body ol {
  margin: 0 0 14px;
  padding-left: 22px;
}

.md-body a {
  color: var(--accent);
}

.md-body img {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin: 10px 0;
  display: block;
}

.md-body code {
  background: var(--surface-muted);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.code-wrap {
  position: relative;
  margin: 14px 0;
}

.code-wrap pre {
  margin: 0;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
}

.code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

/* 后台写作 */
.admin-grid {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.admin-post-btn {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  font-family: inherit;
}

.admin-post-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.admin-post-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-post-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.editor-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.editor-meta .full {
  grid-column: 1 / -1;
}

.input,
.textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

.input:focus,
.textarea:focus {
  border-color: var(--accent);
}

.split-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.editor-pane {
  min-height: 380px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

.preview-pane {
  min-height: 380px;
  max-height: 620px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--bg);
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin: 8px 0 0;
}

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: #1c1917;
  color: #ffffff;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  pointer-events: none;
}

html[data-theme="dark"] .toast {
  background: #f1f5f9;
  color: #0f172a;
}

@media (max-width: 860px) {
  .article-layout,
  .admin-grid,
  .split-editor {
    grid-template-columns: 1fr;
  }

  .toc-box {
    position: static;
  }

  .article-card {
    padding: 20px 18px;
  }
}
