/* =========================================================
   Silent_Fish社区 · 样式表
   思路：先把「设计变量」集中定义，后面全部引用变量。
   以后想换配色，只改这一块，全站跟着变 —— 这就是「设计系统」。
   ========================================================= */

:root {
  --bg:          #f4f1ea;   /* 页面底色：暖纸白 */
  --surface:     #fffdf8;   /* 卡片表面 */
  --ink:         #1b1a17;   /* 正文墨色 */
  --ink-2:       #57514a;   /* 次要文字 */
  --muted:       #8b8378;   /* 弱化文字（时间、计数） */
  --line:        rgba(27, 26, 23, .09);
  --accent:      #a8432b;   /* 主色：陶土红 */
  --accent-soft: #f7e8e2;

  --radius:      16px;
  --shadow:      0 1px 2px rgba(27, 26, 23, .04),
                 0 10px 26px -16px rgba(27, 26, 23, .35);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

/* 键盘操作时的焦点圈：统一成品牌色，别用浏览器默认的黑色粗圈
   （鼠标点击不会触发 :focus-visible，所以不会影响观感） */
:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 65%, transparent);
  outline-offset: 2px;
}

/* 兜底规则：只要元素带了 hidden 属性，就真的不显示。
   为什么需要它？因为浏览器默认的 [hidden] { display: none } 只是「建议样式」，
   优先级极低。只要你自己写了 .field { display: flex }，就把 hidden 覆盖掉了 ——
   我上面就踩了这个坑（登录框里本该隐藏的「昵称」字段被显示出来了）。 */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  /* 给底部留出 iPhone 安全区 */
  padding-bottom: env(safe-area-inset-bottom);
}

/* 屏幕阅读器专用：视觉上隐藏，但读屏软件能读到 */
.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;
}

/* ================= 顶栏 ================= */

.topbar {
  position: sticky;          /* 滚动时贴在顶部 */
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 20px 14px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  /* 名字变长了：字号收一点、字距几乎去掉，
     否则在 360px 宽的手机上会顶到右边的按钮 */
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;          /* 允许它被压缩，不把别人挤出去 */
}

/* 名字太长时显示省略号，而不是换行或撑破 */
.brand-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 品牌名后面的小红点，纯装饰。flex: none = 永远不参与压缩 */
.brand-dot {
  flex: none;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  margin-top: 6px;
}

/* ================= 布局容器 ================= */

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 22px 20px 80px;
}

/* ================= 按钮 ================= */

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  transition: transform .12s ease, background .18s ease, opacity .18s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.96); }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #963a25; }
.btn-primary:disabled {
  opacity: .38;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-2);
}
.btn-ghost:hover { background: rgba(27, 26, 23, .04); }

/* ================= 写一条 ================= */

.composer {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  transition: border-color .18s ease, box-shadow .18s ease;
}
/* :focus-within —— 里面的输入框获得焦点时，整个卡片高亮 */
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}

.composer textarea {
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font: inherit;
  color: var(--ink);
  line-height: 1.7;
  min-height: 76px;
}
.composer textarea::placeholder { color: var(--muted); }

.composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 8px;
}

/* 左边一组：图片按钮 + 字数 */
.composer-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-left: -10px;      /* 让图标左边缘和文字对齐 */
  border: 0;
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
  -webkit-tap-highlight-color: transparent;
}
.tool-btn:hover { background: rgba(27, 26, 23, .05); color: var(--ink-2); }
.tool-btn svg { width: 17px; height: 17px; display: block; }
.tool-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ================= 待发布的图片 ================= */

.image-preview {
  position: relative;
  margin-top: 10px;
  width: fit-content;
  max-width: 100%;
}

.image-preview img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.image-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(27, 26, 23, .62);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.image-remove:hover { background: rgba(27, 26, 23, .85); }

.hint {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ================= 信息流标题 ================= */

.feed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 30px 2px 12px;
}
.feed-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .16em;
  color: var(--muted);
  text-transform: uppercase;
}
.muted { font-size: 12px; color: var(--muted); }

/* ================= 帖子卡片 ================= */

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

.post {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 8px;
  box-shadow: var(--shadow);
}

/* 只有「刚出现的新卡片」才播放入场动画。
   首屏不播（内容直接就在，不拖沓），点赞后重绘也不会让整页卡片再抖一遍。 */
.post.is-new {
  animation: rise .32s cubic-bezier(.2, .7, .3, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.post-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

/* 头像：用名字首字 + 名字算出来的色相，省掉上传图片 */
.avatar {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 600;
  user-select: none;
}

.who {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  min-width: 0;
}
.who strong {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.who time {
  font-size: 12px;
  color: var(--muted);
}

.post-text {
  margin: 0 0 12px;
  white-space: pre-wrap;     /* 保留用户输入的换行 */
  overflow-wrap: anywhere;   /* 超长英文/链接不会撑破卡片 */
  color: var(--ink-2);
  font-size: 15.5px;
}

/* 配图。
   用 aspect-ratio 会裁切，所以这里用 max-height + object-fit: cover：
   横图不会撑满一屏，竖图也不会被拉成长条。 */
.post-image {
  display: block;
  width: 100%;
  max-height: 460px;
  object-fit: cover;
  margin-bottom: 12px;
  border-radius: 12px;
  background: #f0ece5;
}

/* 图片加载时先占位，避免内容跳一下 */
.post-image[loading] { min-height: 120px; }

.post-foot {
  display: flex;
  gap: 4px;
  margin-left: -8px;
  padding-bottom: 4px;
}

/* 每个小操作按钮：图标 + 数字 */
.act {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
  -webkit-tap-highlight-color: transparent;
}
.act:hover { background: rgba(27, 26, 23, .05); color: var(--ink-2); }
.act svg { width: 17px; height: 17px; display: block; }

/* 已点赞状态：心形填充 + 变红。class 由 JS 控制 */
.act.is-active { color: var(--accent); }
.act.is-active svg { fill: currentColor; }
.act.is-active:hover { background: var(--accent-soft); }

/* 点下去时心形弹一下 */
.act.pop svg { animation: pop .32s ease; }
@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.32); }
  100% { transform: scale(1); }
}

/* 危险操作（删除）：平时和普通操作一样淡，点第一次才变红 */
.act-danger {
  margin-left: auto;          /* 推到这一行的最右边 */
}
.act-danger:hover {
  color: #a4271f;
  background: #fdecea;
}
.act-danger.is-arming {
  color: #a4271f;
  background: #fdecea;
  font-weight: 600;
}

/* 评论右上角的「删除」，更小更轻 */
.link-danger {
  margin-left: auto;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: 11.5px;
  color: var(--muted);
  cursor: pointer;
}
.link-danger:hover { color: #a4271f; }
.link-danger.is-arming { color: #a4271f; font-weight: 600; }

/* 删除时的淡出，让它「消失」而不是「突然没了」 */
.post.is-removing {
  opacity: 0;
  transform: scale(.98);
  transition: opacity .16s ease, transform .16s ease;
}

/* ================= 评论区 ================= */

/* 展开时淡入一下，避免「唰」地跳出来 */
.thread {
  margin-top: 2px;
  padding: 13px 0 6px;
  border-top: 1px solid var(--line);
  animation: fadeIn .18s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.comment {
  display: flex;
  gap: 9px;
}

.avatar-xs {
  width: 26px;
  height: 26px;
  font-size: 11px;
}

.comment-body {
  flex: 1;
  min-width: 0;   /* 没有这行，长单词会把弹性格子撑破 */
}

.comment-meta {
  display: flex;
  align-items: baseline;
  gap: 7px;
}
.comment-meta strong { font-size: 13px; font-weight: 600; }
.comment-meta time { font-size: 11.5px; color: var(--muted); }

.comment-text {
  margin: 2px 0 0;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thread-empty {
  margin: 0;
  padding: 2px 0 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.thread-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.thread-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.thread-form input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.btn-xs {
  padding: 9px 15px;
  font-size: 13px;
  border-radius: 10px;
}

/* 评论区展开时，评论图标变深一点，表示「这个开着了」 */
.act.is-open { color: var(--ink-2); }

/* ================= 连不上后端 ================= */

.feed-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 34px 20px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed color-mix(in srgb, var(--accent) 35%, var(--line));
  border-radius: var(--radius);
}

.feed-error-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.feed-error-detail {
  margin: 0;
  max-width: 92%;
  font-size: 13px;
  line-height: 1.65;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ================= 空状态 ================= */

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 48px 0;
}

/* ================= 提示条 ================= */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  background: rgba(27, 26, 23, .92);
  color: #fff;
  font-size: 13.5px;
  padding: 10px 18px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 48px);
  text-align: center;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ================= 小屏微调 ================= */

@media (max-width: 560px) {
  .wrap { padding: 16px 14px 72px; }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .post { padding: 14px 15px 6px; }
  .post-text { font-size: 15px; }
}

/* ================= 顶栏：登录状态 ================= */

.user-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;            /* 按钮永远完整显示，被压缩的只会是左边的名字 */
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-2);
  max-width: 40vw;
}
.user-chip span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 12px;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
}

/* 本地模式下顶栏右侧的小标签 */
.local-badge {
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ================= 本地模式提示条 ================= */

.mode-banner {
  margin: 0 0 14px;
  padding: 10px 13px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #8a6a3f;
  background: #fbf3e4;
  border: 1px solid #f0e0c4;
  border-radius: 12px;
}

/* 未登录时，输入区看起来像「被锁住」，但依然可以点 */
.composer.is-locked { opacity: .9; }
.composer.is-locked textarea { cursor: pointer; }

/* ================= 登录 / 注册弹层 ================= */

.sheet {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  max-width: 100%;
  max-height: 100%;
}

/* ::backdrop 是弹窗背后那层，浏览器原生提供，不用自己写遮罩 div */
.sheet::backdrop {
  background: rgba(27, 26, 23, .42);
  backdrop-filter: blur(2px);
}

.sheet[open] .sheet-body {
  animation: sheetIn .24s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes sheetIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.sheet-body {
  width: min(400px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px 22px 18px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: 0 24px 60px -20px rgba(27, 26, 23, .5);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sheet-head h2 {
  margin: 0;
  font-size: 19px;
  letter-spacing: .02em;
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.icon-btn:hover { background: rgba(27, 26, 23, .06); }

.sheet-sub {
  margin: -6px 0 2px;
  font-size: 13px;
  color: var(--muted);
}

/* 表单字段：label 包住 input，点文字也能聚焦到输入框 */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-2);
}
.field input {
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  padding: 11px 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.field input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input:disabled {
  background: #f6f3ee;
  color: var(--muted);
}

.form-error {
  margin: 0;
  padding: 9px 12px;
  font-size: 13px;
  color: #a4271f;
  background: #fdecea;
  border-radius: 10px;
}

.mode-note {
  margin: 0;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.65;
  color: #8a6a3f;
  background: #fbf3e4;
  border: 1px solid #f0e0c4;
  border-radius: 10px;
}

.btn-block {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.link-btn {
  background: none;
  border: 0;
  padding: 2px;
  font: inherit;
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

/* 手机上从底部升起，像原生 App 的 sheet */
@media (max-width: 560px) {
  .sheet {
    margin: auto 0 0;
    width: 100%;
  }
  .sheet-body {
    width: 100%;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
  }
}

/* 尊重用户的「减少动效」系统设置 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
