/* ==========================================================================
   投稿板样式 —— 深色、无外部依赖
   ========================================================================== */

:root {
  --bg: #0b0f17;
  --bg-soft: #121826;
  --card: #161d2d;
  --card-hover: #1b2334;
  --border: #263147;
  --text: #e6ebf5;
  --muted: #8d9bb5;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.12);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --wrap: 1080px;
  --gap: 1.1rem;
}

* { box-sizing: border-box; }

/* 关键：CSS 里给元素设了 display（如 .login-wrap 的 grid、.preview 的 flex）
   会盖掉 hidden 属性默认的 display:none，导致「隐藏」的元素照样显示。
   这条规则让 hidden 属性始终生效。 */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(var(--wrap), 100% - 2.5rem); margin-inline: auto; }
.narrow { max-width: 680px; }

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

h1, h2 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.7rem, 4vw, 2.5rem); }
h2 { font-size: 1.35rem; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff; padding: .6rem 1rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* -------------------------------- 头部 -------------------------------- */

.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11, 15, 23, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

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

.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 600; }
.brand:hover { text-decoration: none; }

.brand-mark {
  display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff; font-size: .95rem;
}

.nav { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; }
.nav a { color: var(--muted); font-size: .93rem; }
.nav a:hover { color: var(--text); }
.nav-cta { color: var(--accent) !important; font-weight: 600; }
.nav-admin { opacity: .65; }

/* -------------------------------- 首屏 -------------------------------- */

.hero { padding: 3.2rem 0 2.2rem; text-align: center; }
.hero-sub { color: var(--muted); max-width: 46rem; margin: .6rem auto 1.4rem; }

.hero-actions { display: flex; gap: .75rem; justify-content: center; flex-wrap: wrap; }

.moderation-note {
  margin-top: 1.3rem; font-size: .87rem; color: var(--warn);
  background: rgba(251, 191, 36, .08);
  border: 1px solid rgba(251, 191, 36, .25);
  border-radius: 999px; padding: .4rem 1rem; display: inline-block;
}

.page-head { padding: 2.4rem 0 1.4rem; }
.page-head h1 { font-size: clamp(1.5rem, 3.5vw, 2rem); }
.page-head .hero-sub { margin-inline: 0; text-align: left; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .62rem 1.15rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-size: .93rem; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #3d7bf0; text-decoration: none; }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--card-hover); border-color: var(--accent); text-decoration: none; }

.btn-danger { background: transparent; border-color: rgba(248, 113, 113, .4); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, .12); }

.btn-sm { padding: .4rem .8rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* -------------------------------- 板块标签 -------------------------------- */

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin: 2.4rem 0 1.1rem;
}

.tabs { display: flex; gap: .45rem; flex-wrap: wrap; }

.tab {
  padding: .42rem .95rem; border-radius: 999px;
  border: 1px solid var(--border); background: transparent;
  color: var(--muted); font: inherit; font-size: .89rem; cursor: pointer;
}
.tab:hover { color: var(--text); border-color: var(--accent); }
.tab.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ------------------------------ 多列瀑布流 ------------------------------
 * 用 flex 列 + JS 按「当前最短列优先」分配，而不是 CSS column-count。
 * 原因：column-count 按顺序切分且不能拆分卡片，图文混排时高度差异大，
 * 会在某列底部留下大片空白（实测过）。最短列优先能让各列高度尽量齐平，
 * 且列内间距由 gap 统一控制，与列间距完全一致。
 * ---------------------------------------------------------------------- */

.masonry {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
}

.masonry-col {
  flex: 1 1 0;
  min-width: 0;              /* 允许收缩，避免长单词撑破列宽 */
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* -------------------------------- 标签 -------------------------------- */

.post-tags { display: flex; flex-wrap: wrap; gap: .4rem; }

.tag-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--bg-soft);
  color: var(--muted); font: inherit; font-size: .78rem; line-height: 1.5;
  cursor: pointer; transition: border-color .15s, color .15s, background .15s;
}
.tag-chip:hover { border-color: var(--accent); color: var(--accent); }
.tag-chip.is-active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
/* 静态标签（卡片展示、标签预览）：不可点 */
.tag-chip.is-static { cursor: default; }
.tag-chip.is-static:hover { border-color: var(--border); color: var(--muted); }

/* 后台里用颜色区分标签审核状态 */
.tag-chip.tag-approved { border-color: rgba(52, 211, 153, .4); color: var(--ok); }
.tag-chip.tag-pending  { border-color: rgba(251, 191, 36, .4); color: var(--warn); }
.tag-chip.tag-rejected { border-color: rgba(248, 113, 113, .4); color: var(--danger); }

.tag-count {
  padding: 0 .35rem; border-radius: 999px;
  background: rgba(255, 255, 255, .08); font-size: .72rem;
}

.tag-bar { display: flex; flex-wrap: wrap; gap: .4rem; }

.tag-preview, .tag-suggest {
  display: flex; flex-wrap: wrap; align-items: center; gap: .45rem;
  margin-top: .5rem;
}

/* ------------------------------ 筛选区 ------------------------------ */

.filters {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .95rem 1.1rem;
  display: flex; flex-direction: column; gap: .7rem;
}

.filter-row { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }

.filter-label {
  font-size: .82rem; color: var(--muted);
  flex: 0 0 auto; min-width: 3.2rem;
}

.search-wrap { position: relative; flex: 1 1 220px; max-width: 380px; }

.search-input {
  width: 100%; padding: .5rem 2.1rem .5rem .75rem;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 999px; color: var(--text); font: inherit; font-size: .88rem;
}
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.search-clear {
  position: absolute; right: .35rem; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; display: grid; place-items: center;
  border: none; border-radius: 50%; background: transparent;
  color: var(--muted); font-size: 1.05rem; line-height: 1; cursor: pointer;
}
.search-clear:hover { background: rgba(255, 255, 255, .08); color: var(--text); }

.filter-summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: .8rem; flex-wrap: wrap;
  margin: 1rem 0 0; padding: .5rem .9rem;
  background: var(--accent-soft); border: 1px solid rgba(79, 140, 255, .3);
  border-radius: 9px; font-size: .85rem; color: var(--accent);
}

/* ------------------------------ 后台视图切换 ------------------------------ */

.view-tabs {
  display: flex; gap: .3rem; margin: 1.4rem 0 1.1rem;
  border-bottom: 1px solid var(--border);
}

.view-tab {
  position: relative;
  padding: .6rem 1.1rem; border: none; background: transparent;
  color: var(--muted); font: inherit; font-size: .93rem; font-weight: 600;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.view-tab:hover { color: var(--text); }
.view-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.view-tab-badge {
  display: inline-block; margin-left: .35rem;
  padding: 0 .4rem; border-radius: 999px;
  background: var(--warn); color: #1a1206;
  font-size: .72rem; font-weight: 700;
}

/* 后台标签行 */
.admin-tag {
  display: flex; gap: 1rem; align-items: center;
  justify-content: space-between; flex-wrap: wrap;
  margin-bottom: .7rem;
}
.admin-tag-info { display: flex; flex-direction: column; gap: .45rem; min-width: 0; }
.admin-tag-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* -------------------------------- 卡片 -------------------------------- */

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem;
}

.post { display: flex; flex-direction: column; gap: .75rem; transition: border-color .15s; }
.post:hover { border-color: #33405c; }

.post-image {
  border-radius: 9px; overflow: hidden; background: var(--bg-soft);
  /* 固定宽高比：图片高度可预期，瀑布流列高更稳定，减少图片加载后的跳动 */
  aspect-ratio: 4 / 3;
}
.post-image img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------------------------- 可放大图片 ---------------------------- */

.zoomable { cursor: zoom-in; transition: filter .15s, transform .15s; }
.zoomable:hover { filter: brightness(1.06); }
.zoomable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------ 灯箱 ------------------------------
 * 遮罩层。注意卡片里的图是 object-fit: cover（被裁成 4:3），
 * 这里必须用 contain 才能显示完整画面——否则放大后仍是被裁的。
 * ------------------------------------------------------------------ */

.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(1rem, 4vw, 3rem);
  background: rgba(4, 7, 12, .92);
  backdrop-filter: blur(6px);
  cursor: zoom-out;
  animation: lightbox-in .16s ease-out;
}

@keyframes lightbox-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  /* contain：完整显示，不裁剪、不变形 */
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, .6);
  cursor: zoom-out;
  animation: lightbox-img-in .18s ease-out;
}

@keyframes lightbox-img-in {
  from { transform: scale(.96); opacity: .6; }
  to { transform: scale(1); opacity: 1; }
}

.lightbox-hint {
  position: absolute; bottom: 1.1rem; left: 50%; transform: translateX(-50%);
  margin: 0; padding: .35rem .9rem; border-radius: 999px;
  background: rgba(11, 15, 23, .8); border: 1px solid var(--border);
  color: var(--muted); font-size: .82rem; white-space: nowrap;
  pointer-events: none;
}

.lightbox-close {
  position: absolute; top: .9rem; right: 1.1rem;
  width: 40px; height: 40px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--border);
  background: rgba(11, 15, 23, .75); color: var(--text);
  font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.lightbox-close:hover { border-color: var(--accent); color: var(--accent); }

/* 灯箱打开时锁住页面滚动 */
body.no-scroll { overflow: hidden; }

/* 尊重「减少动态效果」偏好 */
@media (prefers-reduced-motion: reduce) {
  .lightbox, .lightbox-img { animation: none; }
}

/* white-space: pre-wrap 让正文里的换行生效，同时保持纯文本语义 */
.post-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.post-meta {
  display: flex; flex-wrap: wrap; gap: .5rem .8rem;
  font-size: .82rem; color: var(--muted);
}
.post-author { color: var(--text); font-weight: 600; }

/* -------------------------------- 分页 / 状态 -------------------------------- */

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 2.2rem 0; }
.pager-info { color: var(--muted); font-size: .87rem; }

.empty, .loading, .error { text-align: center; color: var(--muted); padding: 2rem 0; }
.error { color: var(--danger); }

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

.form { display: flex; flex-direction: column; }

.field { margin-bottom: 1.15rem; display: flex; flex-direction: column; gap: .4rem; }
.field label { font-size: .9rem; font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; padding: .62rem .8rem;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 9px; color: var(--text); font: inherit; font-size: .94rem;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled { opacity: .5; cursor: not-allowed; }
textarea { resize: vertical; min-height: 100px; }

.hint { font-size: .82rem; color: var(--muted); margin: 0; }

.preview { display: flex; flex-direction: column; gap: .6rem; align-items: flex-start; }
.preview img { max-width: 100%; max-height: 240px; border-radius: 9px; border: 1px solid var(--border); }

/* -------------------------- 多图上传（每张一行） --------------------------
 * 每张图各自有独立的「标签」与「说明」输入框。
 * 提交后每张图成为一条独立投稿，所以按「一行一张图」布局。
 * ---------------------------------------------------------------------- */

.image-list { display: flex; flex-direction: column; gap: .75rem; margin-top: .3rem; }

.image-item {
  display: flex; gap: .8rem; align-items: flex-start;
  padding: .7rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg-soft);
}

.image-thumb {
  width: 92px; height: 92px; flex: 0 0 auto;
  object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg);
}

.image-item-fields { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .45rem; }

.image-item-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .6rem;
}
.image-item-name {
  font-size: .84rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 行内输入框比全局表单字段略紧凑，避免一张图占太多高度 */
.image-tags, .image-body {
  width: 100%; padding: .45rem .7rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font: inherit; font-size: .88rem;
}
.image-tags:focus, .image-body:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.image-tag-preview { margin-top: 0; }

@media (max-width: 560px) {
  .image-item { flex-direction: column; }
  .image-thumb { width: 100%; height: 150px; }
}

.form-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-top: .3rem; }
.form-msg { font-size: .88rem; color: var(--muted); }
.form-msg.is-ok { color: var(--ok); }
.form-msg.is-error { color: var(--danger); }

.success-card { margin-bottom: 1.2rem; border-color: rgba(52, 211, 153, .35); }
.success-card h2 { font-size: 1.15rem; color: var(--ok); }

/* -------------------------------- 页脚 -------------------------------- */

.site-footer {
  border-top: 1px solid var(--border); margin-top: 3rem; padding: 1.6rem 0;
  color: var(--muted); font-size: .87rem; text-align: center;
}
.site-footer p { margin: .2rem 0; }
.footer-link a { font-weight: 600; }

/* ============================== 后台 ============================== */

.admin-body { background: var(--bg); }

.login-wrap { display: grid; place-items: center; min-height: 100vh; padding: 2rem; }
.login-card { width: min(380px, 100%); text-align: center; }
.login-card h1 { font-size: 1.3rem; }
.login-card .btn { width: 100%; margin-top: .6rem; }

.stats {
  display: grid; gap: .9rem; margin: 1.6rem 0;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.stat {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem 1rem;
  display: flex; flex-direction: column; gap: .2rem;
}
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: .8rem; color: var(--muted); }
.stat.is-pending .stat-value { color: var(--warn); }
.stat.is-approved .stat-value { color: var(--ok); }

.search { max-width: 260px; }

.admin-post { display: flex; gap: 1rem; margin-bottom: 1rem; align-items: flex-start; flex-wrap: wrap; }
.admin-post-main { display: flex; gap: 1rem; flex: 1 1 380px; align-items: flex-start; }

.admin-post-image {
  width: 132px; height: 132px; flex: 0 0 auto;
  border-radius: 9px; overflow: hidden; background: var(--bg-soft);
}
.admin-post-image img { width: 100%; height: 100%; object-fit: cover; display: block; }

.admin-post-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: .5rem; }
.admin-post-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-start; }

.badge {
  padding: .12rem .55rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .78rem; font-weight: 600;
}

.reject-reason { margin: 0; font-size: .85rem; color: var(--danger); }
.ip-line { margin: 0; font-size: .78rem; color: var(--muted); font-family: ui-monospace, monospace; }

@media (max-width: 640px) {
  .admin-post-main { flex-direction: column; }
  .admin-post-image { width: 100%; height: 180px; }
  .header-inner { flex-wrap: wrap; }
}
