:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
  --max-width: 820px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

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

.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
}

/* header / footer */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.site-nav { display: flex; gap: 18px; font-size: 0.95rem; align-items: center; }
.site-nav a { color: var(--muted); }
.site-nav a:hover { color: var(--accent); text-decoration: none; }
.site-nav .nav-form { display: inline; margin: 0; }
.link-button {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.link-button:hover { color: var(--accent); }

.site-footer {
  margin-top: 60px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer .container { display: flex; justify-content: space-between; }
.muted { color: var(--muted); }

main { padding-top: 32px; min-height: 60vh; }

/* page title */
.page-title { font-size: 1.6rem; margin: 0 0 24px; }

/* post list */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-item { padding: 22px 0; border-bottom: 1px solid var(--border); }
.post-item:first-child { padding-top: 0; }
.post-item-title { margin: 0 0 8px; font-size: 1.3rem; }
.post-item-title a { color: var(--text); }
.post-item-title a:hover { color: var(--accent); text-decoration: none; }
.post-summary { margin: 10px 0 0; color: #374151; }

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

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 0.8rem;
  line-height: 1.6;
}
.tag:hover { text-decoration: none; background: #e0e7ff; }
.tag-lg { font-size: 0.95rem; padding: 5px 14px; }
.tag-count { color: var(--muted); }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 12px; }

/* pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 32px;
  font-size: 0.9rem;
}
.page-info { color: var(--muted); }

/* article */
.post-header { margin-bottom: 28px; }
.post-header h1 { margin: 0 0 10px; font-size: 2rem; line-height: 1.3; }
.post-content { font-size: 1.02rem; word-wrap: break-word; }
.post-content h1, .post-content h2, .post-content h3 { line-height: 1.35; margin: 1.6em 0 0.6em; }
.post-content p { margin: 0 0 1.1em; }
.post-content img { max-width: 100%; height: auto; border-radius: 8px; }
.post-content code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.post-content pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 16px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.55;
}
.post-content pre code { background: none; padding: 0; color: inherit; }
.post-content blockquote {
  margin: 1.2em 0;
  padding: 4px 16px;
  border-left: 4px solid var(--border);
  color: var(--muted);
  background: #fafafa;
}
.post-content table { border-collapse: collapse; width: 100%; margin: 1.2em 0; }
.post-content th, .post-content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.post-content th { background: #f9fafb; }
.post-content hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }

.draft-badge {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
}
.back-link { margin-top: 40px; font-size: 0.92rem; }

/* buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.5;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

/* forms */
label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 12px; }
input[type="text"], input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, textarea:focus { outline: 2px solid rgba(37, 99, 235, 0.35); border-color: var(--accent); }
.stack { display: flex; flex-direction: column; }
.form-error { color: var(--danger); font-size: 0.9rem; }

/* login */
.login-card {
  max-width: 360px;
  margin: 40px auto;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login-card h1 { margin: 0 0 20px; font-size: 1.4rem; }

/* admin */
.admin-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-actions { display: flex; gap: 10px; }
.inline { display: inline; }
.admin-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-table th, .admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.9rem; vertical-align: middle; }
.admin-table th { background: #f9fafb; font-weight: 600; color: var(--muted); }
.admin-table tr:last-child td { border-bottom: none; }
.cell-title { font-weight: 500; }
.nowrap { white-space: nowrap; }
.row-actions { white-space: nowrap; }
.row-actions form { margin-left: 8px; }
.row-actions button {
  border: none;
  background: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0;
  font-family: inherit;
}
.row-actions button:hover { text-decoration: underline; }
.row-actions button.danger { color: var(--danger); }

.badge { padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; }
.badge-pub { background: #dcfce7; color: #166534; }
.badge-draft { background: #f3f4f6; color: #4b5563; }

/* editor */
.editor-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; margin-bottom: 8px; }
.editor-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 12px 0; }
.editor-pane { display: flex; flex-direction: column; min-width: 0; }
.pane-label { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
#content_md {
  width: 100%;
  min-height: 460px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.6;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
}
.preview {
  min-height: 460px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-y: auto;
}
.editor-actions { display: flex; gap: 10px; margin-top: 8px; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* editor toolbar + upload */
.editor-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 10px 0 0; }
.editor-toolbar .muted { font-size: 0.85rem; }
.btn-sm { padding: 5px 12px; font-size: 0.85rem; }
.upload-status { font-size: 0.85rem; color: var(--muted); }
.upload-status.is-error { color: var(--danger); }
#content_md.drop-active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2); }

/* media library */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-top: 20px; }
.media-item { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.media-item img { width: 100%; height: 140px; object-fit: cover; display: block; background: #f3f4f6; }
.media-item figcaption { padding: 10px 12px; font-size: 0.82rem; display: flex; flex-direction: column; gap: 4px; }
.media-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.media-meta { color: var(--muted); }
.media-actions { display: flex; gap: 10px; align-items: center; margin-top: 2px; }
.media-actions button { border: none; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 0.82rem; font-family: inherit; }
.media-actions button:hover { text-decoration: underline; }
.media-actions button.danger { color: var(--danger); }

/* media toolbar */
.media-toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 8px; }
.media-toolbar input[type="search"] { flex: 1 1 200px; margin: 0; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; font-family: inherit; background: var(--surface); color: var(--text); }
.media-toolbar select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.9rem; font-family: inherit; background: var(--surface); color: var(--text); }
.media-toolbar .btn { align-self: center; }
.media-tags { margin-top: 2px; }
.media-refs { font-size: 0.78rem; }
.media-refs summary { cursor: pointer; color: var(--muted); }
.media-refs ul { margin: 6px 0 0; padding-left: 18px; }
.media-refs li { margin: 2px 0; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }
.modal-panel { position: relative; width: 100%; max-width: 900px; max-height: 80vh; overflow: auto; background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: 16px 20px 20px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-grid { margin-top: 0; }
.media-pick { display: flex; flex-direction: column; gap: 6px; padding: 0 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; overflow: hidden; text-align: left; font-family: inherit; }
.media-pick:hover { border-color: var(--accent); }
.media-pick img { width: 100%; height: 120px; object-fit: cover; display: block; background: #f3f4f6; }
.media-pick-name { font-size: 0.78rem; padding: 0 8px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 720px) {
  .editor-meta, .editor-split { grid-template-columns: 1fr; }
  .header-inner { height: auto; padding: 12px 20px; flex-direction: column; gap: 8px; }
  .post-header h1 { font-size: 1.6rem; }
}
