:root {
  --bg: #f2f7fd;
  --card: #ffffff;
  --primary: #4a9dec;
  --primary-soft: #eaf3fd;
  --text: #1f2d3d;
  --text-sub: #8a97a8;
  --line: #e8eef5;
  --shadow: 0 2px 14px rgba(74, 157, 236, 0.08);
  --nav-h: 58px;
  --top-h: 54px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---------- 页面容器 ---------- */
.page {
  position: fixed;
  inset: 0;
  bottom: var(--nav-h);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.page.active { display: flex; }

/* ---------- 顶部栏 ---------- */
.top-bar {
  height: var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, #ffffff, #fbfdff);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}

.tabs { display: flex; gap: 24px; }
.tab {
  position: relative;
  background: none;
  border: none;
  font-size: 17px;
  font-weight: 500;
  color: var(--text-sub);
  padding: 6px 2px;
  cursor: pointer;
  transition: color .2s;
}
.tab.active { color: var(--text); font-weight: 700; }
.tab.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  width: 22px;
  height: 3px;
  border-radius: 3px;
  background: var(--primary);
}

.btn-post {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(74, 157, 236, 0.35);
  transition: transform .15s;
}
.btn-post:active { transform: scale(0.9); }

/* ---------- 帖子流 ---------- */
.feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.card-head { display: flex; align-items: center; gap: 10px; }
.card-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); object-fit: cover; }
.card-user { flex: 1; }
.card-name { font-size: 15px; font-weight: 600; }
.card-time { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.card-tag {
  font-size: 12px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 10px;
  border-radius: 20px;
}

.card-text {
  font-size: 15px;
  line-height: 1.6;
  margin: 10px 0;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* 媒体网格 */
.card-media {
  display: grid;
  gap: 6px;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 6px;
}
.card-media.g1 { grid-template-columns: 1fr; }
.card-media.g2 { grid-template-columns: 1fr 1fr; }
.card-media.g3, .card-media.g4 { grid-template-columns: repeat(3, 1fr); }
.card-media img, .card-media video {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: var(--primary-soft);
  display: block;
}
.card-media.g1 img, .card-media.g1 video { aspect-ratio: 4 / 3; }

/* 操作栏 */
.card-foot {
  display: flex;
  gap: 26px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.act {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-sub);
  background: none;
  border: none;
  cursor: pointer;
  transition: color .15s, transform .15s;
}
.act:active { transform: scale(0.9); }
.act.liked { color: #ff6b81; }
.act svg { width: 20px; height: 20px; }

/* ---------- 我的 ---------- */
.page-mine { overflow-y: auto; padding-top: env(safe-area-inset-top); }
.profile {
  background: linear-gradient(135deg, #4a9dec, #7bb8f0);
  color: #fff;
  padding: 28px 20px 20px;
  border-radius: 0 0 24px 24px;
}
.profile-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 62px; height: 62px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.6);
  background: #fff; object-fit: cover;
}
.profile-info { flex: 1; }
.nickname { font-size: 20px; font-weight: 700; }
.account { font-size: 13px; opacity: .85; margin-top: 4px; }
.edit-avatar {
  background: rgba(255,255,255,.22);
  border: 1px solid rgba(255,255,255,.5);
  color: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
}
.stats { display: flex; margin-top: 20px; }
.stat { flex: 1; text-align: center; }
.stat .num { display: block; font-size: 20px; font-weight: 700; }
.stat .lbl { font-size: 12px; opacity: .85; }

.menu {
  list-style: none;
  margin: 14px 12px;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.menu-item {
  display: flex;
  align-items: center;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .15s;
}
.menu-item:last-child { border-bottom: none; }
.menu-item:active { background: var(--primary-soft); }
.mi-icon { width: 26px; font-size: 17px; }
.mi-text { flex: 1; font-size: 15px; }
.mi-arrow { color: var(--text-sub); font-size: 20px; }

/* ---------- 底部导航 ---------- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 10;
}
.nav-item {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-sub);
  font-size: 11px;
  cursor: pointer;
  transition: color .2s;
}
.nav-item.active { color: var(--primary); }
.nav-item svg { width: 24px; height: 24px; }

/* ---------- 发帖弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(31, 45, 61, .4);
  display: none;
  align-items: flex-end;
  z-index: 100;
}
.modal.open { display: flex; }
.modal-panel {
  width: 100%;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideUp .3s ease;
  max-height: 88vh;
  overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(100%); } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-cancel { background: none; border: none; color: var(--text-sub); font-size: 15px; cursor: pointer; }
.modal-submit {
  background: var(--primary);
  border: none;
  color: #fff;
  padding: 7px 18px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}

.modal-body { padding: 16px; }
.post-category {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  margin-bottom: 12px;
  outline: none;
}
.post-text {
  width: 100%;
  min-height: 120px;
  border: none;
  resize: none;
  font-size: 16px;
  line-height: 1.6;
  background: transparent;
  outline: none;
  font-family: inherit;
}
.media-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.media-preview:empty { display: none; }
.mp-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--primary-soft);
}
.mp-item img, .mp-item video { width: 100%; height: 100%; object-fit: cover; }
.mp-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.post-actions {
  display: flex;
  gap: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.media-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--primary);
  cursor: pointer;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(31,45,61,.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty {
  text-align: center;
  color: var(--text-sub);
  padding: 60px 20px;
  font-size: 14px;
}

/* ---------- 图标兜底：确保 SVG 正常显示 ---------- */
.act svg,
.btn-post svg,
.nav-item svg {
  display: block;
  flex-shrink: 0;
}
.act.like svg { fill: currentColor; }

/* ---------- 图片全屏查看 ---------- */
.card-media img { cursor: zoom-in; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  animation: fade .2s ease;
}
.lightbox.open { display: flex; }
@keyframes fade { from { opacity: 0; } }
.lb-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  animation: zoomIn .25s ease;
}
@keyframes zoomIn { from { transform: scale(.85); opacity: .4; } }
.lb-close {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  z-index: 301;
}

/* ---------- 登录 / 注册 / 改密 表单 ---------- */
.auth-panel { max-height: none; }
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 14px 0;
  font-size: 15px;
  color: var(--text-sub);
  cursor: pointer;
  position: relative;
}
.auth-tab.active { color: var(--text); font-weight: 600; }
.auth-tab.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 26px;
  height: 3px;
  border-radius: 3px;
  background: var(--primary);
}

.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.field-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  background: var(--card);
  outline: none;
  transition: border-color .2s;
}
.field-input:focus { border-color: var(--primary); }

.auth-tip {
  font-size: 13px;
  color: #ff6b81;
  min-height: 18px;
  margin: -6px 0 10px;
}
.auth-submit {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(74, 157, 236, .3);
}
.auth-submit:active { transform: scale(.98); }

/* 退出登录按钮 */
.logout-btn {
  display: block;
  width: calc(100% - 24px);
  margin: 4px 12px 20px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: #ff6b81;
  font-size: 15px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
