/* ==========================================================================
   Freewd 社区网页版 · Material Design 3 风格样式
   色板以 #4C6EF5 为种子色展开（primary / container / surface 系列令牌）
   ========================================================================== */

:root {
  color-scheme: light dark;

  --md-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;

  /* ---------- MD3 亮色方案 ---------- */
  --md-primary: #1e56d6;
  --md-on-primary: #ffffff;
  --md-primary-container: #dbe1ff;
  --md-on-primary-container: #001849;
  --md-secondary-container: #dfe1f9;
  --md-on-secondary-container: #171b2c;
  --md-tertiary-container: #ffdf9e;
  --md-on-tertiary-container: #241a00;
  --md-error: #ba1a1a;
  --md-on-error: #ffffff;
  --md-error-container: #ffdad6;
  --md-on-error-container: #410002;
  --md-success: #146c2e;
  --md-on-success: #ffffff;

  --md-surface: #fdfbff;
  --md-surface-container-lowest: #ffffff;
  --md-surface-container-low: #f7f2fa;
  --md-surface-container: #f1ecf4;
  --md-surface-container-high: #ebe6ef;
  --md-surface-container-highest: #e5e1e9;
  --md-on-surface: #1b1b21;
  --md-on-surface-variant: #45464f;
  --md-outline: #767680;
  --md-outline-variant: #c6c5d0;
  --md-inverse-surface: #303036;
  --md-inverse-on-surface: #f3eff7;
  --md-scrim: rgba(0, 0, 0, .4);

  /* ---------- 形状 ---------- */
  --md-xs: 4px;
  --md-s: 8px;
  --md-m: 12px;
  --md-l: 16px;
  --md-xl: 28px;
  --md-full: 999px;

  /* ---------- 高度 ---------- */
  --md-elev-1: 0 1px 2px rgba(0, 0, 0, .13), 0 1px 3px 1px rgba(0, 0, 0, .07);
  --md-elev-2: 0 1px 2px rgba(0, 0, 0, .13), 0 2px 6px 2px rgba(0, 0, 0, .07);
  --md-elev-3: 0 4px 8px 3px rgba(0, 0, 0, .08), 0 1px 3px rgba(0, 0, 0, .13);
}

@media (prefers-color-scheme: dark) {
  :root {
    --md-primary: #b3c5ff;
    --md-on-primary: #002e69;
    --md-primary-container: #003ea8;
    --md-on-primary-container: #dbe1ff;
    --md-secondary-container: #3f4358;
    --md-on-secondary-container: #dfe1f9;
    --md-tertiary-container: #5b4300;
    --md-on-tertiary-container: #ffdf9e;
    --md-error: #ffb4ab;
    --md-on-error: #690005;
    --md-error-container: #93000a;
    --md-on-error-container: #ffdad6;
    --md-success: #7edc9a;
    --md-on-success: #00391a;

    --md-surface: #111318;
    --md-surface-container-lowest: #0c0e13;
    --md-surface-container-low: #191c22;
    --md-surface-container: #1d2026;
    --md-surface-container-high: #282a31;
    --md-surface-container-highest: #33353c;
    --md-on-surface: #e3e1ec;
    --md-on-surface-variant: #c6c5d0;
    --md-outline: #90909a;
    --md-outline-variant: #45464f;
    --md-inverse-surface: #e3e1ec;
    --md-inverse-on-surface: #303036;
    --md-scrim: rgba(0, 0, 0, .6);

    --md-elev-1: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px 1px rgba(0, 0, 0, .25);
    --md-elev-2: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 6px 2px rgba(0, 0, 0, .25);
    --md-elev-3: 0 4px 8px 3px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 400 15px/22px var(--md-font);
  color: var(--md-on-surface);
  background: var(--md-surface);
  -webkit-font-smoothing: antialiased;
  padding-bottom: 96px;
}

a { color: inherit; text-decoration: none; }
a:hover { color: var(--md-primary); }
img { max-width: 100%; display: block; }

.hidden { display: none !important; }

/* 视觉隐藏但可点击（用于文件选择等原生控件） */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

.icon { width: 24px; height: 24px; fill: currentColor; display: block; flex: none; }
.icon.sm { width: 18px; height: 18px; }

/* ------------------------------------------------------------ 顶部应用栏 */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--md-surface);
  border-bottom: 1px solid var(--md-outline-variant);
  padding-bottom: 10px;
}

.app-bar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 64px;
}

.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.brand-mark {
  width: 32px; height: 32px; border-radius: var(--md-s);
  object-fit: cover; flex: none;
}
.brand-logo {
  width: 32px; height: 32px; border-radius: var(--md-s); flex: none;
  display: none; place-items: center;
  background: linear-gradient(135deg, #4c6ef5, #7f5cff);
  color: #fff; font-weight: 700; font-size: 18px;
}
.app-bar-title {
  font: 400 22px/28px var(--md-font);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.app-bar-actions { display: flex; align-items: center; gap: 4px; flex: none; }
.user-area { display: flex; align-items: center; }

.icon-btn {
  position: relative;
  width: 40px; height: 40px; padding: 0;
  display: inline-grid; place-items: center;
  border: none; border-radius: 50%;
  background: transparent; color: var(--md-on-surface-variant);
  cursor: pointer; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn::before {
  content: ""; position: absolute; inset: 0;
  background: currentColor; opacity: 0; transition: opacity .12s;
}
.icon-btn:hover::before { opacity: .08; }
.icon-btn:active::before { opacity: .12; }

/* MD3 搜索栏 */
.search-wrap { padding-top: 2px; }
.search-bar {
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 18px;
  border-radius: var(--md-full);
  background: var(--md-surface-container-high);
  color: var(--md-on-surface-variant);
}
.search-bar:focus-within { box-shadow: inset 0 0 0 2px var(--md-primary); }
.search-bar input {
  flex: 1; min-width: 0;
  border: none; outline: none; background: transparent;
  color: var(--md-on-surface);
  font: 400 16px/24px var(--md-font);
}

/* MD3 图标按钮上的徽标 */
.badge {
  position: absolute; top: 5px; right: 5px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--md-s);
  background: var(--md-error); color: var(--md-on-error);
  font: 500 11px/16px var(--md-font); text-align: center;
}

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

.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 24px;
  border: none; border-radius: var(--md-full);
  background: transparent; color: var(--md-primary);
  font: 500 14px/20px var(--md-font); letter-spacing: .1px;
  cursor: pointer; white-space: nowrap;
  --state: currentColor;
  transition: box-shadow .15s, background-color .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn::before {
  content: ""; position: absolute; inset: 0;
  background: var(--state); opacity: 0; transition: opacity .12s;
  pointer-events: none;
}
.btn:hover::before { opacity: .08; }
.btn:active::before { opacity: .12; }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn:disabled::before { opacity: 0; }
.btn .icon { width: 18px; height: 18px; }

.btn.primary {
  background: var(--md-primary); color: var(--md-on-primary);
  --state: var(--md-on-primary);
  box-shadow: var(--md-elev-1);
}
.btn.primary:hover { box-shadow: var(--md-elev-2); }
.btn.ghost {
  border: 1px solid var(--md-outline);
  color: var(--md-primary);
  padding: 0 23px;
}
.btn.danger {
  background: var(--md-error-container); color: var(--md-on-error-container);
  --state: var(--md-on-error-container);
}
.btn.sm { height: 32px; padding: 0 14px; font: 500 13px/18px var(--md-font); }
.btn.sm.ghost { padding: 0 13px; }
.btn.icon { width: 40px; height: 40px; padding: 0; }

.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible,
.input:focus-visible, .textarea:focus-visible, .like:focus-visible,
.fab:focus-visible, .link-btn:focus-visible {
  outline: 2px solid var(--md-primary); outline-offset: 2px;
}

/* 扩展 FAB */
.fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 30;
  display: inline-flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 20px;
  border-radius: var(--md-l);
  background: var(--md-primary-container); color: var(--md-on-primary-container);
  font: 500 15px/24px var(--md-font);
  box-shadow: var(--md-elev-3);
  overflow: hidden; position: fixed;
  transition: box-shadow .15s, transform .1s;
}
.fab::before {
  content: ""; position: absolute; inset: 0;
  background: currentColor; opacity: 0; transition: opacity .12s;
}
.fab:hover::before { opacity: .08; }
.fab:active { transform: scale(.98); }
.fab .icon { position: relative; }
.fab span { position: relative; }
@media (max-width: 600px) {
  .fab { right: 16px; bottom: 16px; }
}

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

.card {
  background: var(--md-surface-container-low);
  border-radius: var(--md-m);
  box-shadow: var(--md-elev-1);
  border: none;
}

.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 22px 4px 12px;
  font: 500 16px/24px var(--md-font);
  color: var(--md-on-surface);
}
.section-title .muted { font-weight: 400; }

.feed { display: flex; flex-direction: column; gap: 12px; }

.post {
  padding: 16px;
  transition: box-shadow .18s, background-color .18s, transform .12s;
}
.post:hover { box-shadow: var(--md-elev-2); }

.post-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.post-head .meta { min-width: 0; }
.post-title { font: 500 18px/24px var(--md-font); margin: 6px 0 8px; word-break: break-word; }
.post-body { color: var(--md-on-surface-variant); white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.post-body.full { color: var(--md-on-surface); }
.post-body p { margin: 0 0 10px; }
.post-body p:last-child { margin-bottom: 0; }
.post-body strong { color: var(--md-on-surface); font-weight: 600; }
.post-body a { color: var(--md-primary); text-decoration: underline; text-underline-offset: 2px; }
.post-body img { border-radius: var(--md-s); margin: 8px 0; }
.post-body pre {
  background: var(--md-surface-container-highest);
  border-radius: var(--md-s); padding: 12px; overflow: auto;
  font-size: 13px; margin: 8px 0;
}
.post-body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; }
.post-body :not(pre) > code {
  background: var(--md-primary-container); color: var(--md-on-primary-container);
  padding: 1px 6px; border-radius: var(--md-xs);
}
.post-body blockquote {
  margin: 8px 0; padding: 2px 0 2px 12px;
  border-left: 3px solid var(--md-outline-variant);
  color: var(--md-on-surface-variant);
}
.post-body ul { margin: 8px 0; padding-left: 22px; }
.post-thumb {
  margin-top: 12px; border-radius: var(--md-m); overflow: hidden;
  background: var(--md-surface-container-highest); max-height: 360px;
}
.post-thumb img { width: 100%; object-fit: cover; }

.post-foot {
  display: flex; align-items: center; gap: 12px;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--md-outline-variant);
  color: var(--md-on-surface-variant); font: 400 13px/18px var(--md-font);
}
.post-foot .spacer { flex: 1; }

/* 点赞（assist chip 形态） */
.like {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px 0 10px;
  border: 1px solid var(--md-outline-variant); border-radius: var(--md-s);
  background: transparent; color: var(--md-on-surface-variant);
  font: 500 13px/18px var(--md-font); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, color .15s, border-color .15s;
}
.like .icon { width: 18px; height: 18px; }
.like:hover { background: var(--md-surface-container-high); }
.like.on {
  background: var(--md-error-container); color: var(--md-on-error-container);
  border-color: transparent;
}

/* ------------------------------------------------------------ 头像 */

.av {
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  overflow: hidden;
  background: var(--md-surface-container-highest);
  display: inline-grid; place-items: center;
}
.av.sm { width: 32px; height: 32px; }
.av.lg { width: 80px; height: 80px; }
.av img { grid-area: 1 / 1; width: 100%; height: 100%; object-fit: cover; display: block; }
.av .av-fallback {
  grid-area: 1 / 1; width: 100%; height: 100%;
  display: none; place-items: center;
  color: #fff; font: 600 16px/1 var(--md-font);
}
.av.sm .av-fallback { font-size: 13px; }
.av.lg .av-fallback { font-size: 30px; }

.who { font-weight: 500; color: var(--md-on-surface); }
.muted { color: var(--md-on-surface-variant); font-size: 13px; }
.dot { margin: 0 6px; color: var(--md-on-surface-variant); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: var(--md-s);
  background: var(--md-secondary-container); color: var(--md-on-secondary-container);
  font: 500 12px/18px var(--md-font);
}
.tag.warn { background: var(--md-error-container); color: var(--md-on-error-container); }

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

.field { margin-bottom: 16px; }
.field label {
  display: block; margin-bottom: 6px;
  font: 500 12px/16px var(--md-font); letter-spacing: .4px;
  color: var(--md-on-surface-variant);
}
.input, .textarea {
  width: 100%; padding: 13px 16px;
  border: none; border-bottom: 1px solid var(--md-on-surface-variant);
  border-radius: var(--md-xs) var(--md-xs) 0 0;
  background: var(--md-surface-container-highest);
  color: var(--md-on-surface);
  font: 400 16px/24px var(--md-font);
  outline: none;
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.input::placeholder, .textarea::placeholder { color: var(--md-on-surface-variant); }
.input:focus, .textarea:focus {
  border-bottom: 2px solid var(--md-primary);
  padding-bottom: 12px;
}
.textarea { resize: vertical; min-height: 148px; line-height: 1.7; }
.hint { margin-top: 6px; font: 400 12px/16px var(--md-font); color: var(--md-on-surface-variant); }

.switches { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 8px 0 18px; }
.switch {
  display: inline-flex; align-items: center; gap: 10px;
  font: 400 14px/20px var(--md-font); color: var(--md-on-surface-variant);
  cursor: pointer; user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative; flex: none;
  width: 52px; height: 32px; border-radius: var(--md-full);
  border: 2px solid var(--md-outline);
  background: var(--md-surface-container-highest);
  transition: background-color .18s, border-color .18s;
}
.switch-thumb {
  position: absolute; top: 50%; left: 6px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--md-outline);
  transform: translateY(-50%);
  display: grid; place-items: center;
  color: transparent;
  transition: left .18s, width .18s, height .18s, background-color .18s;
}
.switch-thumb .icon { width: 14px; height: 14px; }
.switch input:checked + .switch-track {
  background: var(--md-primary); border-color: var(--md-primary);
}
.switch input:checked + .switch-track .switch-thumb {
  left: 24px; width: 24px; height: 24px;
  background: var(--md-on-primary); color: var(--md-primary);
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--md-primary); outline-offset: 2px;
}

.composer-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.composer-actions .spacer { flex: 1; }

.upload-preview { position: relative; margin-top: 12px; }
.upload-preview img {
  max-height: 260px; border-radius: var(--md-m);
  background: var(--md-surface-container-highest);
}
.upload-preview .btn { position: absolute; top: 8px; right: 8px; }

/* ------------------------------------------------------------ 资料 / 列表 */

.profile { display: flex; gap: 20px; align-items: center; padding: 20px; flex-wrap: wrap; }
.profile .info { flex: 1; min-width: 180px; }
.profile h1 { margin: 0 0 4px; font: 400 24px/32px var(--md-font); }

.stats { display: flex; gap: 26px; margin-top: 14px; flex-wrap: wrap; }
.stats div { font: 400 12px/16px var(--md-font); color: var(--md-on-surface-variant); letter-spacing: .4px; }
.stats b { display: block; font: 500 20px/26px var(--md-font); color: var(--md-on-surface); }

.user-card {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  transition: box-shadow .18s;
}
.user-card:hover { box-shadow: var(--md-elev-2); }
.user-card .info { flex: 1; min-width: 0; }

.notice { display: flex; gap: 14px; padding: 14px 16px; align-items: flex-start; }
.notice + .notice { border-top: 1px solid var(--md-outline-variant); }
.notice .body { flex: 1; min-width: 0; }
.notice .preview { color: var(--md-on-surface-variant); white-space: pre-wrap; word-break: break-word; }
.notice.unread { background: var(--md-secondary-container); }

.comment { display: flex; gap: 14px; padding: 14px 0; }
.comment + .comment { border-top: 1px solid var(--md-outline-variant); }
.comment .body { flex: 1; min-width: 0; }
.comment .content { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 22px 0; }

.empty { padding: 48px 20px; text-align: center; color: var(--md-on-surface-variant); }
.empty .big { font-size: 34px; margin-bottom: 10px; }

.loading { padding: 44px; text-align: center; color: var(--md-on-surface-variant); }

.skeleton {
  height: 112px; border-radius: var(--md-m);
  background: linear-gradient(90deg, var(--md-surface-container-low) 25%,
    var(--md-surface-container-high) 37%, var(--md-surface-container-low) 63%);
  background-size: 400% 100%;
  animation: md-shimmer 1.4s ease-in-out infinite;
}
@keyframes md-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px;
  border: 1px solid var(--md-outline-variant); border-radius: var(--md-s);
  background: transparent; color: var(--md-on-surface-variant);
  font: 500 13px/18px var(--md-font); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, color .15s, border-color .15s;
}
.chip:hover { background: var(--md-surface-container-high); }
.chip.on {
  background: var(--md-secondary-container); color: var(--md-on-secondary-container);
  border-color: transparent;
}

/* ------------------------------------------------------------ 对话框 */

.modal-mask {
  position: fixed; inset: 0; z-index: 60;
  background: var(--md-scrim);
  display: grid; place-items: center; padding: 20px;
  animation: md-fade .15s ease-out;
}
.modal {
  width: 100%; max-width: 420px; max-height: 86vh; overflow: auto;
  background: var(--md-surface-container-high);
  border-radius: var(--md-xl);
  padding: 24px;
  box-shadow: var(--md-elev-3);
  animation: md-pop .18s cubic-bezier(.2, 0, 0, 1);
}
.modal h2 { margin: 0 0 8px; font: 400 24px/32px var(--md-font); }
.modal .sub { margin: 0 0 22px; font: 400 14px/20px var(--md-font); color: var(--md-on-surface-variant); }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.modal-actions .spacer { flex: 1; }
@keyframes md-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes md-pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

.link-btn {
  position: relative; overflow: hidden;
  height: 32px; padding: 0 12px;
  border: none; border-radius: var(--md-full); background: transparent;
  color: var(--md-primary); font: 500 13px/18px var(--md-font); cursor: pointer;
}
.link-btn:hover { background: var(--md-surface-container-highest); }

/* ------------------------------------------------------------ 提示条（Snackbar） */

.snackbar-root {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.snackbar {
  background: var(--md-inverse-surface); color: var(--md-inverse-on-surface);
  border-radius: var(--md-xs);
  padding: 14px 16px;
  font: 400 14px/20px var(--md-font);
  white-space: pre-line;
  box-shadow: var(--md-elev-3);
  animation: md-snack .18s cubic-bezier(.2, 0, 0, 1);
}
.snackbar.ok { background: var(--md-success); color: var(--md-on-success); }
.snackbar.err { background: var(--md-error); color: var(--md-on-error); }
@keyframes md-snack { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ 波纹（Ripple） */

.ripple-ink {
  position: absolute; border-radius: 50%;
  background: currentColor; opacity: .18;
  transform: translate(-50%, -50%) scale(0);
  animation: md-ripple .5s ease-out forwards;
  pointer-events: none;
}
@keyframes md-ripple {
  to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

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

.footer {
  padding: 28px 16px 24px;
  color: var(--md-on-surface-variant);
  font: 400 12px/16px var(--md-font);
  display: flex; gap: 4px; justify-content: center; align-items: center; flex-wrap: wrap;
}

@media (max-width: 560px) {
  .hide-sm { display: none !important; }
  .app-bar-title { font-size: 18px; }
}
