/* 全站样式。颜色统一用变量，深色模式只需覆盖变量。 */
:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #f0f2f4;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e3e5e8;
  --accent: #2f7d4f;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff6dd;
  --warn-text: #7a5a00;
  --ok-bg: #e5f5ea;
  --ok-text: #1f6b3d;
  --code-bg: #f3f4f6;
  --radius: 8px;
  color-scheme: light;
}

/* 深色：跟随系统（未手动选择时），或手动选择 data-theme="dark" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b; --surface: #1f2226; --surface-2: #282c31; --text: #e3e5e8; --muted: #9aa1ab;
    --border: #30343a; --accent: #5fbf85; --accent-text: #10241a; --danger: #ef7b6d;
    --warn-bg: #3a3115; --warn-text: #f0d589; --ok-bg: #1c3526; --ok-text: #9ad9b1; --code-bg: #282c31;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181b; --surface: #1f2226; --surface-2: #282c31; --text: #e3e5e8; --muted: #9aa1ab;
  --border: #30343a; --accent: #5fbf85; --accent-text: #10241a; --danger: #ef7b6d;
  --warn-bg: #3a3115; --warn-text: #f0d589; --ok-bg: #1c3526; --ok-text: #9ad9b1; --code-bg: #282c31;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-wrap: anywhere;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin: 0 0 12px; font-size: 22px; line-height: 1.35; }
h2 { margin: 24px 0 12px; font-size: 17px; }
.muted { color: var(--muted); }
.hide { display: none !important; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }

/* ---- 页头 ---- */
.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; gap: 16px; min-height: 52px; }
.brand { font-size: 18px; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.search { flex: 1; max-width: 320px; }
.search input { width: 100%; padding: 6px 12px; border-radius: 999px; }
.nav { display: flex; align-items: center; gap: 14px; margin-left: auto; white-space: nowrap; }
.nav a { color: var(--muted); }
.nav a.btn { color: var(--accent-text); }
.nav-user { display: inline-flex; align-items: center; gap: 6px; }
.nav-bell { position: relative; }
.dot { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px; text-align: center; }

.main { flex: 1; padding-top: 16px; padding-bottom: 32px; }
.site-footer { padding: 16px 0; color: var(--muted); font-size: 13px; text-align: center; }

/* ---- 通用块 ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px 24px; }
.card + .card { margin-top: 16px; }
.narrow { max-width: 460px; margin: 24px auto; }
.mid { max-width: 820px; margin-left: auto; margin-right: auto; }

.notice, .flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; }
.notice { background: var(--warn-bg); color: var(--warn-text); }
.flash { background: var(--ok-bg); color: var(--ok-text); }
.form-error { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; background: var(--warn-bg); color: var(--danger); }

.badge { display: inline-block; padding: 0 7px; border-radius: 4px; font-size: 12px; line-height: 20px; font-weight: 500; vertical-align: middle; background: var(--surface-2); color: var(--muted); }
.badge-admin { background: var(--danger); color: #fff; }
.badge-mod { background: var(--accent); color: var(--accent-text); }
.badge-danger { background: var(--danger); color: #fff; }
.badge-pin { background: var(--warn-bg); color: var(--warn-text); }
.badge-star { background: var(--ok-bg); color: var(--ok-text); }

/* ---- 表单与按钮 ---- */
.form { display: flex; flex-direction: column; gap: 14px; margin: 12px 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.form small { font-weight: 400; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; min-height: 120px; line-height: 1.6; }
input[type="checkbox"], input[type="radio"] { width: auto; }

.btn {
  display: inline-block; font: inherit; font-weight: 500; cursor: pointer; text-align: center;
  background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent);
  border-radius: 6px; padding: 8px 18px;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-sm { padding: 3px 12px; font-size: 14px; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .6; cursor: default; }
.form .btn { align-self: flex-start; }
.inline { display: inline; }
.linklike { font: inherit; color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.nav .linklike { color: var(--muted); }
.linklike.danger { color: var(--danger); }

/* ---- 头像（默认：首字 + 底色） ---- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 28px; height: 28px; border-radius: 6px; color: #fff; font-weight: 600; font-size: 14px; line-height: 1;
}
.avatar-md .avatar { width: 40px; height: 40px; font-size: 18px; }
.avatar-lg .avatar { width: 72px; height: 72px; font-size: 32px; border-radius: 12px; }
.av-0 { background: #c0564b; } .av-1 { background: #c27a3a; } .av-2 { background: #a8892c; } .av-3 { background: #6f9a3a; }
.av-4 { background: #3f9a5e; } .av-5 { background: #2f9a8c; } .av-6 { background: #3489b3; } .av-7 { background: #4a6fc4; }
.av-8 { background: #6b5fc9; } .av-9 { background: #8e55bd; } .av-10 { background: #b34f9c; } .av-11 { background: #c04f72; }

/* ---- 个人主页 ---- */
.profile-head { display: flex; gap: 20px; align-items: flex-start; }
.profile-head h1 { margin-bottom: 4px; }
.profile-head p { margin: 4px 0; }
.bio { white-space: pre-wrap; }
.stats { display: flex; gap: 24px; flex-wrap: wrap; margin: 12px 0 0; padding: 0; list-style: none; }
.stats b { font-size: 18px; display: block; }
.stats span { color: var(--muted); font-size: 13px; }

/* ---- 两栏布局 ---- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.side .card { padding: 16px; }
.side h3 { margin: 0 0 10px; font-size: 15px; }
.side ul { margin: 0; padding: 0; list-style: none; }
.side li { padding: 3px 0; }
.side-user { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.side .btn { width: 100%; }
.side .btn + .btn, .side form + .btn, .side .btn + form { margin-top: 8px; }

/* ---- 板块导航与列表 ---- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 3px 12px; border-radius: 999px; color: var(--muted); }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tabs a.on { background: var(--accent); color: var(--accent-text); }
.list-card { padding: 0; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.sort a { color: var(--muted); margin-left: 12px; }
.sort a.on { color: var(--text); font-weight: 600; }

.post-list { margin: 0; padding: 0; list-style: none; }
.post-row { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.post-row:last-child { border-bottom: 0; }
.post-row .body { flex: 1; min-width: 0; }
.post-title { font-size: 16px; color: var(--text); font-weight: 500; }
.post-title:visited { color: var(--muted); }
.post-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 2px; }
.post-meta a { color: var(--muted); }
.count { flex: none; min-width: 36px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; text-align: center; }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

.pager { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 14px; }
.pager a, .pager span { padding: 3px 11px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface); }
.pager .on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.pager .gap { border: 0; background: none; }

/* ---- 帖子页 ---- */
.post-head { padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.post-head h1 { font-size: 24px; margin-bottom: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.actions .on { color: var(--danger); font-weight: 600; }
.mod-actions { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }

.comments { padding: 0; }
.comments > h2 { margin: 0; padding: 12px 20px; border-bottom: 1px solid var(--border); font-size: 15px; }
.comment { display: flex; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.comment:last-of-type { border-bottom: 0; }
.comment:target { background: var(--surface-2); }
.comment .body { flex: 1; min-width: 0; }
.comment-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 13px; color: var(--muted); }
.comment-meta .author { font-size: 14px; font-weight: 600; color: var(--text); }
.comment-meta .floor { margin-left: auto; color: var(--muted); }
.comment .actions { margin-top: 6px; }
.deleted { color: var(--muted); font-style: italic; }
.reply-box { padding: 16px 20px; border-top: 1px solid var(--border); }
.reply-box .form { margin: 0; }

/* ---- 用户发布的内容（Markdown 渲染结果） ---- */
.content { line-height: 1.75; }
.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p, .content ul, .content ol, .content pre, .content blockquote, .content table { margin: 0 0 12px; }
.content h1, .content h2, .content h3, .content h4 { margin: 20px 0 10px; font-size: 18px; line-height: 1.4; }
.content h3, .content h4 { font-size: 16px; }
.content img { max-width: 100%; height: auto; border-radius: 6px; }
.content code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font: 13px/1.5 ui-monospace, Consolas, "Courier New", monospace; }
.content pre { background: var(--code-bg); padding: 12px 14px; border-radius: 6px; overflow-x: auto; }
.content pre code { padding: 0; background: none; }
.content blockquote { padding: 6px 14px; border-left: 3px solid var(--border); color: var(--muted); background: var(--surface-2); border-radius: 0 6px 6px 0; }
.content blockquote > :last-child { margin-bottom: 0; }
.content table { border-collapse: collapse; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border); padding: 5px 10px; }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.content ul, .content ol { padding-left: 24px; }

/* ---- 通知、后台表格 ---- */
.rows { margin: 0; padding: 0; list-style: none; }
.rows li { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.rows li:last-child { border-bottom: 0; }
.rows li.unread { background: var(--ok-bg); }
.rows .excerpt { color: var(--muted); font-size: 14px; margin-top: 2px; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.table input, .table select { padding: 4px 8px; }
.row-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-form input, .row-form select { width: auto; }
.subnav { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.subnav a.on { color: var(--text); font-weight: 600; }

/* ---- 手机 ---- */
@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; }
  .list-card, .comments { padding: 0; }
  .container { padding: 0 10px; }
  .hide-sm { display: none; }
  .nav { gap: 10px; }
  /* 手机上搜索框单独占一行，避免被导航挤窄 */
  .header-inner { flex-wrap: wrap; row-gap: 6px; padding-top: 8px; padding-bottom: 8px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .post-row { padding: 10px 12px; }
  .comment { padding: 12px; gap: 10px; }
  .reply-box { padding: 12px; }
  .post-head h1 { font-size: 20px; }
  .profile-head { gap: 12px; }
  .avatar-lg .avatar { width: 56px; height: 56px; font-size: 24px; }
  input, textarea, select { font-size: 16px; } /* 避免 iOS 聚焦时自动放大页面 */
}
