:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --fg: #1e293b;
  --ink: #0b1424;
  --muted: #64748b;
  --faint: #93a1b5;
  --line: #e3e8f0;
  --line-strong: #cfd8e6;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eef4ff;
  --night-a: #0b1424;
  --night-b: #12203a;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .05), 0 14px 30px -18px rgba(15, 23, 42, .28);
}

* { box-sizing: border-box; }

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

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

a { color: var(--accent); }
a:hover { color: var(--accent-strong); }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .45);
  outline-offset: 2px;
}

.icon { width: 18px; height: 18px; display: block; }

.wrap { width: min(100% - 2rem, 980px); margin-inline: auto; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; background: #fff; color: var(--fg); padding: .5rem 1rem; z-index: 40; border-radius: 8px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 顶栏 ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(170deg, var(--night-a), var(--night-b));
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  box-shadow: 0 8px 26px -20px rgba(2, 8, 23, .9);
}

.header-inner { display: flex; align-items: center; gap: 1rem; min-height: 62px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: #f3f7ff;
  text-decoration: none;
  font-weight: 650;
  font-size: 1.02rem;
  letter-spacing: .015em;
  white-space: nowrap;
}
.brand:hover { color: #fff; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 10px;
  background: linear-gradient(140deg, #60a5fa, #22d3ee);
  color: #06121f;
  box-shadow: 0 6px 16px -8px rgba(96, 165, 250, .95);
}

.nav { display: flex; align-items: center; gap: .15rem; margin-left: auto; flex-wrap: wrap; }
.nav a, .nav .link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .35rem .72rem;
  color: rgba(226, 235, 250, .68);
  text-decoration: none;
  border: 0;
  border-radius: 9px;
  background: none;
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.nav a:hover, .nav .link-button:hover { color: #fff; background: rgba(255, 255, 255, .09); }
.nav a.is-active {
  color: #fff;
  background: rgba(96, 165, 250, .16);
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, .38);
}
.inline-form { display: inline; margin: 0; }

.site-footer {
  color: var(--faint);
  font-size: .82rem;
  padding: 2.5rem 0 calc(2.5rem + env(safe-area-inset-bottom));
  text-align: center;
}

/* ---------- 通用排版 ---------- */

.page-head { margin: 2.25rem 0 1.25rem; }
.page-title {
  font-size: clamp(1.45rem, 2.6vw, 1.9rem);
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -.015em;
  margin: 0;
  overflow-wrap: anywhere;
}
.page-sub { margin: .4rem 0 0; color: var(--muted); font-size: .9rem; }

h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: .01em; margin: 2rem 0 .75rem; color: #24334a; }

.crumbs {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
  font-size: .86rem;
  color: var(--muted);
  margin: 1.5rem 0 0;
}
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: #c3cddc; }

.meta { color: var(--muted); font-size: .84rem; }
.empty {
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 2rem 1.25rem;
  text-align: center;
}

/* ---------- 搜索 ---------- */

.search {
  display: flex;
  align-items: center;
  gap: .5rem;
  max-width: 660px;
  padding: .3rem .35rem .3rem .95rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, .12); }
.search-icon { color: var(--faint); display: inline-flex; flex: none; }
.search input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 .2rem;
  border: 0;
  background: none;
  font: inherit;
  color: var(--fg);
  outline: none;
}
.search input::placeholder { color: var(--faint); }
.search .button { border-radius: 999px; min-height: 40px; padding-inline: 1.15rem; }

/* ---------- 按钮 ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 44px;
  padding: .55rem 1.15rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
}
.button:hover { background: var(--accent-strong); color: #fff; }
.button:active { transform: translateY(1px); }
.button-secondary { background: #eef2f8; color: #26364f; font-weight: 550; }
.button-secondary:hover { background: #e3e9f3; color: #16233a; }
.button-block { width: 100%; min-height: 48px; }

/* ---------- 分类 ---------- */

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: .75rem;
  margin-bottom: .5rem;
}
.category-card {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  color: var(--fg);
  text-decoration: none;
  transition: transform .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.category-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  color: var(--fg);
}
.cat-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: -.02em;
}
.cat-0 .cat-avatar { background: #e8efff; color: #1d4ed8; }
.cat-1 .cat-avatar { background: #e4f7ef; color: #0f7a5a; }
.cat-2 .cat-avatar { background: #fdf1e5; color: #b45309; }
.cat-3 .cat-avatar { background: #f0ecff; color: #6d28d9; }
.category-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.category-count {
  flex: none;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: #f1f5fb;
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
}

/* ---------- 列表 ---------- */

.topic-list {
  list-style: none;
  margin: 0;
  padding: .35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.topic-list li + li .row { box-shadow: inset 0 1px 0 #f1f4f9; }
.row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .78rem .85rem;
  border-radius: var(--radius-sm);
  color: inherit;
  text-decoration: none;
  transition: background .14s ease;
}
.row:hover { background: #f5f8fd; color: inherit; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.row-title { font-weight: 600; color: var(--fg); overflow-wrap: anywhere; }
.row:hover .row-title { color: var(--accent); }
.row-meta { font-size: .8rem; color: var(--muted); }
.row-arrow { flex: none; color: #c6d1e0; transition: transform .14s ease, color .14s ease; }
.row-arrow::after {
  content: "";
  display: block;
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-top: 2px solid currentColor;
  transform: rotate(45deg);
}
.row:hover .row-arrow { transform: translateX(2px); color: var(--accent); }

.trash-row { display: flex; align-items: center; gap: .4rem; padding-right: .5rem; }
.trash-row .row { flex: 1; min-width: 0; }
.trash-row .link-button {
  flex: none;
  min-height: 38px;
  padding: .3rem .85rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: .86rem;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.trash-row .link-button:hover { border-color: #c7d9fb; background: var(--accent-soft); color: var(--accent-strong); }

/* ---------- 文章 ---------- */

.topic-head { margin: 1.6rem 0 1.15rem; }
.topic-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: .75rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .2rem .62rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2f9;
  color: var(--muted);
  font-size: .78rem;
  text-decoration: none;
  white-space: nowrap;
}
a.chip:hover { border-color: #c7d9fb; background: var(--accent-soft); color: var(--accent-strong); }
.chip-accent { background: var(--accent-soft); border-color: #cddffb; color: var(--accent-strong); }

.post-stack { display: grid; gap: 1rem; }
.post {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.35rem 1.5rem 1.5rem;
}
.post-meta {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  padding-bottom: .8rem;
  margin-bottom: .9rem;
  border-bottom: 1px dashed var(--line);
  color: var(--muted);
  font-size: .8rem;
}
.post-kind {
  padding: .1rem .5rem;
  border-radius: 6px;
  background: #eef4ff;
  color: #1d4ed8;
  font-weight: 600;
  font-size: .75rem;
}
.post-body { font-size: 1rem; line-height: 1.85; overflow-wrap: anywhere; }
.post-body p { margin: .65rem 0; }
.post-body a { color: var(--accent); text-underline-offset: 2px; }
.post-body img.bb-image {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 1rem 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}
.post-body pre {
  padding: 1rem 1.1rem;
  background: #0c1727;
  border: 1px solid #1c2b45;
  border-radius: 12px;
  color: #dbe6f7;
  font-size: .88rem;
  line-height: 1.65;
  overflow: auto;
}
.post-body code { font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace; }
.post-body :not(pre) > code {
  padding: .12rem .38rem;
  border-radius: 6px;
  background: #eef2f8;
  color: #b42318;
  font-size: .9em;
}
.post-body blockquote {
  margin: 1rem 0;
  padding: .55rem 1rem;
  border-left: 3px solid #bcd0ee;
  border-radius: 0 10px 10px 0;
  background: #f7fafe;
  color: #3b4a61;
}
.post-body ul, .post-body ol { padding-left: 1.35rem; }

.bb-attachment {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  max-width: 100%;
  padding: .18rem .55rem;
  background: #f1f5fb;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #274472;
  font-size: .88em;
  text-decoration: none;
  vertical-align: middle;
}
.bb-attachment .bb-name {
  max-width: 18em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bb-ext {
  flex: none;
  padding: 0 .3rem;
  border-radius: 4px;
  background: #dbe6f8;
  color: #274472;
  font-size: .72em;
  font-weight: 700;
  letter-spacing: .04em;
}
.bb-attachment:hover { background: var(--accent-soft); border-color: #c7d9fb; color: var(--accent-strong); }
.bb-attachment-missing {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: .88rem;
}
.tag {
  padding: .05rem .5rem;
  border: 1px solid #e6d6b8;
  border-radius: 999px;
  background: #fdf8ee;
  color: #8a6212;
  font-size: .72rem;
}

/* ---------- 附件 ---------- */

.files { margin-top: 2rem; }
.files ul {
  list-style: none;
  margin: 0;
  padding: .35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.files li {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .68rem .85rem;
  border-radius: var(--radius-sm);
}
.files li + li { box-shadow: inset 0 1px 0 #f1f4f9; }
.file-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 9px;
  background: #eef2f9;
  color: #4b5f7d;
}
.file-icon.is-image { background: #e8f6ef; color: #0f7a5a; }
.file-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.file-text a { color: var(--fg); font-weight: 600; text-decoration: none; word-break: break-all; }
.file-text a:hover { color: var(--accent); }
.file-meta { color: var(--muted); font-size: .8rem; }
.files .empty-line { color: var(--muted); font-size: .88rem; }

/* ---------- 操作条 ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin: 1.75rem 0 0;
}
.actions .link-button {
  min-height: 44px;
  padding: .5rem .9rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.actions .link-button:hover { border-color: #f0c2bd; background: var(--danger-bg); color: var(--danger); }

/* ---------- 提示 ---------- */

.flash {
  padding: .8rem 1rem;
  margin: 0 0 1.25rem;
  border: 1px solid #cddffb;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: #1e40af;
}
.flash-error { border-color: #f6cfcb; border-left-color: var(--danger); background: var(--danger-bg); color: var(--danger); }

/* ---------- 表单 ---------- */

.editor {
  display: grid;
  gap: .55rem;
  padding: 1.4rem 1.5rem 1.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.editor h2 { margin: 0 0 .4rem; }
.editor label { margin-top: .35rem; font-size: .9rem; font-weight: 600; color: #33445e; }
.editor input, .editor select, .editor textarea {
  width: 100%;
  min-height: 44px;
  padding: .6rem .75rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--fg);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.editor input:focus, .editor select:focus, .editor textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .1);
  outline: none;
}
.editor textarea {
  min-height: 280px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Microsoft YaHei", monospace;
  font-size: .93rem;
  line-height: 1.65;
}
.editor-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin: .35rem 0 .55rem; }
.editor button[type=submit] { justify-self: start; }
.editor-note { margin: 0 0 .35rem; color: var(--muted); font-size: .85rem; }

/* ---------- 登录 ---------- */

body.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.15rem calc(2.5rem + env(safe-area-inset-bottom));
  background: #0a1220;
  color: #e8eefb;
  overflow-x: hidden;
}
body.auth-page::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(880px 520px at 12% -12%, rgba(59, 130, 246, .38), transparent 62%),
    radial-gradient(680px 420px at 104% 2%, rgba(34, 211, 238, .20), transparent 58%),
    radial-gradient(760px 520px at 48% 118%, rgba(99, 102, 241, .24), transparent 62%);
}
body.auth-page::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(circle at 50% 38%, #000 0%, transparent 76%);
  mask-image: radial-gradient(circle at 50% 38%, #000 0%, transparent 76%);
}

.auth { position: relative; z-index: 1; width: 100%; max-width: 404px; }
.auth-card {
  padding: 2rem 1.8rem 1.9rem;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 34px 80px -34px rgba(2, 8, 23, .9), 0 0 0 1px rgba(255, 255, 255, .07);
  color: var(--fg);
}
.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .7rem;
  margin-bottom: 1.5rem;
}
.auth-brand .brand-mark { width: 46px; height: 46px; border-radius: 14px; }
.auth-brand .brand-mark .icon { width: 24px; height: 24px; }
.auth-brand strong { font-size: 1.15rem; font-weight: 700; letter-spacing: .02em; color: var(--ink); }
.auth-sub { margin: -.9rem 0 1.5rem; text-align: center; color: var(--muted); font-size: .84rem; }
.auth-form { display: grid; gap: .9rem; }
.field { display: grid; gap: .3rem; }
.field label { font-size: .8rem; font-weight: 650; letter-spacing: .04em; color: #4a5a72; }
.field input {
  width: 100%;
  min-height: 48px;
  padding: .65rem .8rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fbfcfe;
  color: var(--fg);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.field input:focus { background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, .12); outline: none; }
.field-pass { position: relative; }
.field-pass input { padding-right: 3rem; }
.pass-toggle {
  position: absolute;
  top: 50%;
  right: .35rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--faint);
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.pass-toggle:hover { background: #f1f5fb; color: var(--muted); }
.pass-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.pass-toggle .eye-open, .pass-toggle .eye-closed { display: flex; }
.pass-toggle .eye-closed { display: none; }
.pass-toggle[aria-pressed="true"] .eye-open { display: none; }
.pass-toggle[aria-pressed="true"] .eye-closed { display: block; }
.auth-card .button { margin-top: .35rem; }
.auth-card .flash { margin-bottom: .9rem; }

/* ---------- 响应式 ---------- */

@media (max-width: 900px) {
  .wrap { width: min(100% - 1.6rem, 980px); }
  .category-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 720px) {
  .header-inner { gap: .55rem; min-height: 56px; }
  .brand { font-size: .98rem; gap: .5rem; }
  .brand-mark { width: 27px; height: 27px; border-radius: 9px; }
  .nav {
    flex: 1;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    margin-left: .15rem;
    padding-bottom: 2px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a, .nav .link-button { padding: .3rem .55rem; font-size: .9rem; }
  .page-head { margin: 1.6rem 0 1rem; }
  .search { max-width: none; margin-bottom: 1.6rem; }
  .category-grid { grid-template-columns: 1fr; gap: .6rem; }
  .post { padding: 1.1rem 1.15rem 1.25rem; }
  .editor { padding: 1.1rem 1.15rem 1.25rem; }
  .editor textarea { min-height: 240px; }
  .files li { padding: .6rem .7rem; }
  .trash-row { padding-right: .35rem; }
  body.auth-page { padding-top: 1.5rem; }
  .auth-card { padding: 1.7rem 1.35rem 1.6rem; border-radius: 18px; }
}

@media (max-width: 480px) {
  .wrap { width: min(100% - 1.25rem, 980px); }
  .post-body { font-size: .97rem; line-height: 1.8; }
  .post-body pre { padding: .85rem .9rem; font-size: .82rem; border-radius: 10px; }
  .actions .button, .actions .link-button { flex: 1 1 auto; justify-content: center; }
  .search { padding-left: .8rem; }
  .search .button { padding-inline: .95rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .category-card:hover, .row:hover .row-arrow, .button:active { transform: none; }
}
