:root {
  --tr-bg: #f4f5f7;
  --tr-card: #ffffff;
  --tr-primary: #3385ff;
  --tr-text: #1f2937;
  --tr-muted: #8590a6;
  --tr-line: #ebebeb;
  --tr-user: #2d64b3;
  --tr-link: #2b6cb0;
  --tr-lzl-bg: #f7f8fa;
}

/* 核心：全局禁止横向晃动溢出 */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* 彻底杜绝左右滑动晃动 */
  margin: 0;
  padding: 0;
  background: var(--tr-bg);
  color: var(--tr-text);
  font: 14px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y; /* 仅允许纵向滚动，禁止双击缩放手势 */
}

/* 顶部全局导航 */
.app-header {
  height: 54px;
  background: #fff;
  border-bottom: 1px solid var(--tr-line);
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}
.header-inner {
  max-width: 1060px;
  height: 100%;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--tr-primary);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.brand-icon { width: 20px; height: 20px; }

.search-section {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  max-width: 480px;
  justify-content: flex-end;
}
.tr-select {
  height: 32px;
  border: 1px solid var(--tr-line);
  border-radius: 6px;
  padding: 0 6px;
  background: #fff;
  outline: none;
  font-size: 12px;
  color: #4b5563;
  flex-shrink: 0;
}
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 260px;
}
.search-icon {
  position: absolute;
  left: 8px;
  width: 14px;
  height: 14px;
  color: #9ca3af;
}
.tr-input {
  height: 32px;
  width: 100%;
  border: 1px solid var(--tr-line);
  border-radius: 6px;
  padding: 0 8px 0 28px;
  font-size: 12px;
  outline: none;
  background: #fafafa;
}
.tr-input:focus {
  background: #fff;
  border-color: var(--tr-primary);
}

.app-main {
  max-width: 1060px;
  margin: 12px auto 30px;
  padding: 0 10px;
}

/* 按钮通用 */
.tr-btn {
  border: 1px solid var(--tr-line);
  background: #fff;
  color: #374151;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tr-btn:active { background: #f3f4f6; }
.tr-btn-sm { padding: 3px 8px; font-size: 12px; }
.tr-btn-back { font-weight: 500; }

/* 帖子列表 */
.list-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 12px;
}
.view-title { margin: 0; font-size: 18px; font-weight: 700; }
.view-subtitle { font-size: 12px; color: var(--tr-muted); margin-top: 2px; display: block; }
.thread-grid { display: grid; gap: 8px; }
.thread-item-card {
  background: #fff;
  border: 1px solid var(--tr-line);
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
}
.thread-item-card:active { background: #fafafa; }
.thread-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.thread-item-card h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #111827;
  word-break: break-all;
}
.thread-item-footer {
  font-size: 12px;
  color: var(--tr-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* 帖子阅读页：固顶操作栏 */
.reader-sticky-bar {
  background: #fff;
  border: 1px solid var(--tr-line);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 60px;
  z-index: 90;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  margin-bottom: 10px;
  gap: 8px;
}
.sticky-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.thread-meta-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.badge-forum {
  background: #eff6ff;
  color: var(--tr-primary);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
}
.meta-heading {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sticky-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* 只看楼主 Switch */
.tr-switch-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}
.tr-switch-label input { display: none; }
.tr-switch-slider {
  width: 32px;
  height: 18px;
  background: #d1d5db;
  border-radius: 20px;
  position: relative;
  transition: 0.2s;
}
.tr-switch-slider::after {
  content: '';
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: 0.2s;
}
.tr-switch-label input:checked + .tr-switch-slider { background: var(--tr-primary); }
.tr-switch-label input:checked + .tr-switch-slider::after { transform: translateX(14px); }
.tr-switch-text { font-size: 12px; font-weight: 500; color: #4b5563; white-space: nowrap; }

.mini-pager {
  display: flex;
  align-items: center;
  gap: 3px;
  background: #f3f4f6;
  padding: 2px 5px;
  border-radius: 5px;
}
.btn-icon {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 0 3px;
  color: #4b5563;
  line-height: 1;
}
.pager-text { font-size: 11px; color: #6b7280; font-weight: 600; }

/* 楼层内容主体 */
.posts-wrapper {
  background: #fff;
  border: 1px solid var(--tr-line);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}
.tr-post-card {
  padding: 14px 16px;
  border-bottom: 1px solid #edf0f5;
  width: 100%;
}
.tr-post-card:last-child { border-bottom: none; }

.post-layout {
  display: flex;
  gap: 12px;
  width: 100%;
}
.post-avatar-box { flex-shrink: 0; }
.tr-avatar {
  width: 44px;
  height: 44px;
  border-radius: 4px;
  border: 2px solid #e1eedb;
  object-fit: cover;
  background: #fafafa;
  display: block;
}

.post-body {
  flex: 1;
  min-width: 0; /* 防止子元素把宽度撑大 */
}

/* 用户名与徽章 */
.post-user-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}
.tr-username {
  font-size: 14px;
  font-weight: 600;
  color: var(--tr-user);
}
.tr-badge {
  font-size: 10px;
  line-height: 1.1;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 500;
}
.badge-lz { border: 1px solid #9065ed; color: #9065ed; background: #fff; }
.badge-bawu { background: #2563eb; color: #fff; }
.badge-level { background: #f59e0b; color: #fff; }
.badge-extra { background: #3b82f6; color: #fff; }

/* 正文 */
.post-main-content {
  font-size: 14px;
  line-height: 1.7;
  color: #1f2937;
  word-break: break-word;
  white-space: pre-wrap;
}
.post-main-content img.emotion-img {
  vertical-align: middle;
  margin: 0 1px;
  width: 22px;
  height: 22px;
}

/* 图片适配：宽度饱满自适应，长图垂直完整展开，彻底消除窄条 */
.post-main-content img.content-img {
  max-width: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 4px;
  margin: 8px 0;
  cursor: zoom-in;
  border: 1px solid #edf0f5;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.post-main-content video {
  max-width: 100%;
  border-radius: 6px;
  margin: 8px 0;
}
.post-main-content audio {
  width: 100%;
  max-width: 320px;
  margin: 8px 0;
}

.thread-link {
  color: var(--tr-link);
  text-decoration: none;
  word-break: break-all;
}
.thread-link:active { text-decoration: underline; }

.post-signature {
  margin-top: 10px;
  padding-top: 6px;
  border-top: 1px dashed #f1f5f9;
  color: #94a3b8;
  font-size: 12px;
}

/* 楼层底部信息栏 */
.post-footer-row {
  margin-top: 12px;
  font-size: 12px;
  color: var(--tr-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.footer-stats-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.footer-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.footer-item svg { stroke: var(--tr-muted); }
.toggle-lzl-action {
  color: var(--tr-link);
  cursor: pointer;
  font-size: 12px;
  user-select: none;
  margin-left: auto;
}

/* 楼中楼气泡容器 */
.subpost-box-container {
  margin-top: 10px;
  background: var(--tr-lzl-bg);
  border-radius: 4px;
  padding: 10px 12px;
  width: 100%;
}
.subpost-list-wrap { display: flex; flex-direction: column; gap: 10px; }
.subpost-item {
  display: flex;
  gap: 10px;
  border-bottom: 1px dashed #e5e7eb;
  padding-bottom: 8px;
  width: 100%;
}
.subpost-item:last-child { border-bottom: none; padding-bottom: 0; }
.subpost-avatar {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid #e2e8f0;
}
.subpost-right { flex: 1; min-width: 0; font-size: 13px; line-height: 1.55; }
.subpost-header-line {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 2px;
}
.subpost-uname { font-weight: 600; color: var(--tr-user); }
.subpost-body-text { color: #1f2937; word-break: break-word; white-space: pre-wrap; }
.subpost-at-user { color: var(--tr-link); font-weight: 500; }
.subpost-footer-line {
  margin-top: 4px;
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 10px;
}
.icon-stat { display: inline-flex; align-items: center; gap: 2px; }
.icon-stat svg { stroke: #94a3b8; }

/* 底部翻页控制器 */
.reader-footer-pager {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.pager-info { font-size: 13px; color: #4b5563; }
.jump-wrap { display: flex; align-items: center; gap: 6px; }
.jump-wrap input {
  width: 44px;
  height: 28px;
  border: 1px solid var(--tr-line);
  border-radius: 4px;
  text-align: center;
  outline: none;
}

/* 全屏灯箱查看器 */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 10px;
  touch-action: none;
}
#lightbox[hidden] { display: none; }
.lightbox-content { position: relative; max-width: 100vw; max-height: 100vh; }
#lightboxImg {
  max-width: 96vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
}
.lightbox-close-btn {
  position: absolute;
  top: -36px;
  right: 0;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}

/* =======================================================
   移动端专属响应式断点（屏幕宽度 < 640px 时生效）
   ======================================================= */
@media screen and (max-width: 640px) {
  .app-header { height: 50px; }
  .header-inner { padding: 0 10px; }
  .brand-title { font-size: 15px; }
  .tr-select { max-width: 88px; font-size: 11px; padding: 0 2px; }
  
  .app-main {
    margin: 8px auto 20px;
    padding: 0 6px; /* 留出手机边距，内容撑满 */
  }

  /* 固顶栏改两行布局：上面放返回和标题，下面放操作，绝不撑破屏幕 */
  .reader-sticky-bar {
    top: 50px;
    padding: 8px 10px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .sticky-left {
    width: 100%;
    justify-content: flex-start;
  }
  .sticky-right {
    width: 100%;
    justify-content: space-between;
    border-top: 1px dashed #f1f5f9;
    padding-top: 6px;
  }

  /* 楼层卡片在手机端更紧凑 */
  .tr-post-card {
    padding: 12px 10px;
  }
  .post-layout {
    gap: 10px;
  }
  .tr-avatar {
    width: 38px;
    height: 38px;
  }
  .post-main-content {
    font-size: 14px;
    line-height: 1.65;
  }

  /* 底栏状态与时间折叠 */
  .post-footer-row {
    font-size: 11px;
    gap: 6px;
  }
  .footer-stats-left {
    gap: 8px;
  }

  /* 楼中楼卡片紧凑化 */
  .subpost-box-container {
    padding: 8px 10px;
  }
  .subpost-avatar {
    width: 28px;
    height: 28px;
  }
}