:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #2b2f3a;
  --text2: #6b7280;
  --primary: #5b6cff;
  --primary-dark: #4753e6;
  --danger: #ef4444;
  --border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30, 35, 60, .08);
  --shadow-lg: 0 10px 40px rgba(30, 35, 60, .16);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}
button { font-family: inherit; cursor: pointer; border: none; }
input, textarea { font-family: inherit; outline: none; }

/* ===== 顶栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,.9); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 24px;
  padding: 0 28px; height: 60px;
}
.logo { font-size: 20px; font-weight: 800; color: var(--primary); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav button {
  background: none; padding: 8px 16px; border-radius: 10px;
  font-size: 15px; color: var(--text2); font-weight: 500; transition: .15s;
}
.nav button:hover { background: #eef0ff; color: var(--primary); }
.nav button.active { background: var(--primary); color: #fff; }
.user-area { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; color: #fff;
  background: linear-gradient(135deg, #5b6cff, #9f5bff);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
}
.username { font-size: 14px; font-weight: 600; }
.btn {
  padding: 8px 18px; border-radius: 10px; font-size: 14px; font-weight: 600; transition: .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: #eef0ff; color: var(--primary); }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }

/* ===== 主区域 ===== */
.container { max-width: 1280px; margin: 0 auto; padding: 24px 28px 80px; }

/* 统计条 */
.stats-bar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px; margin-bottom: 22px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 4px;
}
.stat-card .num { font-size: 24px; font-weight: 800; color: var(--primary); }
.stat-card .label { font-size: 13px; color: var(--text2); }

/* 工具条 */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.search-box {
  flex: 1; min-width: 200px; max-width: 360px; display: flex; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; height: 40px;
}
.search-box input { border: none; flex: 1; font-size: 14px; background: none; }
.sort-tabs { display: flex; background: var(--card); border-radius: 10px; padding: 3px; border: 1px solid var(--border); }
.sort-tabs button { padding: 6px 16px; border-radius: 8px; background: none; font-size: 14px; color: var(--text2); }
.sort-tabs button.active { background: var(--primary); color: #fff; }

/* 标签筛选 */
.tag-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.tag-chip {
  padding: 5px 14px; border-radius: 999px; font-size: 13px;
  background: var(--card); border: 1px solid var(--border); color: var(--text2); transition: .15s;
}
.tag-chip:hover { border-color: var(--primary); color: var(--primary); }
.tag-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ===== 瀑布流照片墙 ===== */
.masonry { column-count: 5; column-gap: 16px; }
@media (max-width: 1200px) { .masonry { column-count: 4; } }
@media (max-width: 960px)  { .masonry { column-count: 3; } }
@media (max-width: 680px)  { .masonry { column-count: 2; } }
.photo-img-wrap { position: relative; }
.album-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(20, 24, 40, .68); color: #fff; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: 999px; backdrop-filter: blur(4px);
}
/* 相册翻页条 */
.album-nav { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.album-nav span { font-size: 13px; font-weight: 800; color: var(--primary); }
.photo-card {
  break-inside: avoid; margin-bottom: 16px; background: var(--card);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .18s, box-shadow .18s;
}
.photo-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.photo-card img { width: 100%; display: block; }
.photo-info { padding: 12px 14px; }
.photo-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-meta { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text2); }
.like-btn { display: flex; align-items: center; gap: 4px; background: none; color: var(--text2); font-size: 13px; padding: 2px 4px; border-radius: 6px; }
.like-btn.liked { color: var(--danger); font-weight: 700; }
.photo-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.mini-tag { font-size: 12px; color: var(--primary); background: #eef0ff; padding: 2px 8px; border-radius: 999px; }
.empty-state { column-span: all; text-align: center; color: var(--text2); padding: 80px 0; font-size: 15px; }

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 24, 40, .5); z-index: 100;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; padding: 26px;
  animation: pop .2s ease;
}
.modal.wide { max-width: 900px; padding: 0; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h3 { font-size: 19px; margin-bottom: 18px; }
.modal-close { float: right; background: none; font-size: 20px; color: var(--text2); line-height: 1; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; font-weight: 600; }
.form-group input, .form-group textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; background: #fafafa; transition: .15s;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--primary); background: #fff; }
.form-group textarea { resize: vertical; min-height: 70px; }
.form-hint { font-size: 12px; color: #9ca3af; margin-top: 4px; }
.form-error { color: var(--danger); font-size: 13px; margin: 8px 0; min-height: 18px; }
.auth-tabs { display: flex; background: #f1f2f7; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.auth-tabs button { flex: 1; padding: 8px; border-radius: 8px; background: none; font-size: 14px; font-weight: 600; color: var(--text2); }
.auth-tabs button.active { background: #fff; color: var(--primary); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* 照片详情弹窗 */
.detail-wrap { display: grid; grid-template-columns: 1fr 340px; min-height: 480px; }
.detail-img-side { background: #14161f; display: flex; align-items: center; justify-content: center; border-radius: 18px 0 0 18px; overflow: hidden; }
.detail-img-side img { max-width: 100%; max-height: 78vh; object-fit: contain; }
.detail-info { padding: 24px; display: flex; flex-direction: column; max-height: 78vh; }
.detail-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.detail-desc { font-size: 14px; color: var(--text2); margin-bottom: 10px; white-space: pre-wrap; }
.detail-byline { font-size: 13px; color: var(--text2); margin-bottom: 12px; }
.detail-actions { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.comment-list { flex: 1; overflow-y: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.comment-item { padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.comment-head { display: flex; justify-content: space-between; margin-bottom: 3px; }
.comment-head .who { font-weight: 700; font-size: 13px; color: var(--primary); }
.comment-head .when { font-size: 12px; color: #b0b4bf; }
.comment-del { background: none; color: #c2c6d0; font-size: 12px; }
.comment-del:hover { color: var(--danger); }
.comment-input-row { display: flex; gap: 8px; margin-top: 12px; }
.comment-input-row input { flex: 1; border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; font-size: 14px; }
@media (max-width: 760px) {
  .detail-wrap { grid-template-columns: 1fr; }
  .detail-img-side { border-radius: 18px 18px 0 0; }
}

/* 上传预览 */
.upload-preview { max-height: 200px; border-radius: 10px; margin-bottom: 12px; display: none; max-width: 100%; object-fit: contain; }
.sel-count {
  font-size: 13px; color: var(--primary); background: #eef0ff;
  border-radius: 8px; padding: 8px 12px; margin: 8px 0; word-break: break-all;
}

/* ===== 排行榜 ===== */
.rank-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.rank-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.rank-card h3 { font-size: 16px; margin-bottom: 14px; }
.rank-item { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.rank-item:last-child { border-bottom: none; }
.rank-no { width: 26px; height: 26px; border-radius: 8px; background: #eef0ff; color: var(--primary); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 13px; flex-shrink: 0; }
.rank-item:nth-child(1) .rank-no { background: #fef3c7; color: #d97706; }
.rank-item:nth-child(2) .rank-no { background: #e5e7eb; color: #6b7280; }
.rank-item:nth-child(3) .rank-no { background: #ffedd5; color: #ea580c; }
.rank-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }
.rank-main { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { font-weight: 800; color: var(--primary); }

/* ===== 留言板 ===== */
.board-wrap { max-width: 720px; margin: 0 auto; }
.message-form { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 20px; }
.message-form textarea { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 14px; min-height: 80px; resize: vertical; }
.message-item { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 12px; }
.message-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.message-who { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.message-time { font-size: 12px; color: #b0b4bf; }
.message-content { font-size: 14px; white-space: pre-wrap; }

/* ===== 个人中心 / 管理 ===== */
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel h3 { font-size: 16px; margin-bottom: 14px; }
.invite-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.invite-code { font-family: Consolas, monospace; font-weight: 700; letter-spacing: 1px; }
.invite-used { color: #9ca3af; font-size: 12px; }
.invite-badge { font-size: 12px; padding: 2px 10px; border-radius: 999px; }
.invite-badge.ok { background: #dcfce7; color: #16a34a; }
.invite-badge.used { background: #f3f4f6; color: #9ca3af; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 28px; }
.pager button { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 7px 16px; font-size: 14px; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager span { font-size: 14px; color: var(--text2); }

/* toast */
#toast {
  position: fixed; bottom: 32px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #2b2f3a; color: #fff; padding: 11px 22px; border-radius: 12px;
  font-size: 14px; opacity: 0; transition: .25s; z-index: 200; pointer-events: none;
  box-shadow: var(--shadow-lg); max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.hidden { display: none !important; }
.loading { text-align: center; padding: 60px; color: var(--text2); font-size: 14px; }

/* ===== 手机端底部导航 & 悬浮上传按钮 ===== */
.tabbar { display: none; }
.fab { display: none; }

/* ===== 移动端适配（主场景：手机） ===== */
@media (max-width: 640px) {
  /* 顶栏精简 */
  .topbar { padding: 0 14px; height: 52px; gap: 10px; }
  .logo { font-size: 17px; }
  .topbar .nav { display: none; }
  .username { display: none; } /* 只留头像，省空间 */

  /* 底部标签栏 */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    background: rgba(255,255,255,.96); backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
  }
  .tabbar button {
    flex: 1; background: none; display: flex; flex-direction: column;
    align-items: center; gap: 1px; padding: 5px 0; font-size: 11px; color: var(--text2);
  }
  .tabbar .tb-icon { font-size: 20px; line-height: 1.1; }
  .tabbar button.active { color: var(--primary); font-weight: 700; }

  /* 悬浮上传按钮（右下角，避让标签栏） */
  .fab {
    display: flex; align-items: center; justify-content: center;
    position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom));
    width: 56px; height: 56px; border-radius: 50%; z-index: 55;
    background: linear-gradient(135deg, var(--primary), #9f5bff);
    color: #fff; font-size: 24px; box-shadow: 0 6px 20px rgba(91,108,255,.45);
    transition: transform .15s;
  }
  .fab:active { transform: scale(.92); }
  #uploadBtn { display: none; } /* 顶栏的上传按钮在手机上收进悬浮按钮 */

  /* 主区域留出标签栏空间 */
  .container { padding: 14px 12px calc(90px + env(safe-area-inset-bottom)); }

  /* 统计条紧凑 */
  .stats-bar { gap: 8px; margin-bottom: 14px; }
  .stat-card { padding: 10px 12px; border-radius: 10px; }
  .stat-card .num { font-size: 19px; }
  .stat-card .label { font-size: 12px; }

  /* 工具条 */
  .toolbar { gap: 8px; margin-bottom: 12px; }
  .search-box { height: 38px; min-width: 0; }
  .sort-tabs button { padding: 6px 12px; font-size: 13px; }
  .tag-chips { margin-bottom: 14px; }

  /* 照片卡片更大点击区 */
  .photo-info { padding: 10px 12px 12px; }
  .photo-title { font-size: 14px; }
  .like-btn { padding: 6px 8px; font-size: 14px; margin: -6px 0; }

  /* 弹窗 → 底部抽屉样式 */
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%; border-radius: 18px 18px 0 0; max-height: 88vh;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
    animation: slideup .22s ease;
  }
  @keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

  /* 照片详情 → 全屏 */
  .modal.wide { max-width: 100%; height: 100dvh; max-height: 100dvh; border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
  .detail-wrap { grid-template-columns: 1fr; height: 100dvh; }
  .detail-img-side { border-radius: 0; height: 44dvh; flex-shrink: 0; }
  .detail-img-side img { max-height: 44dvh; }
  .detail-info { max-height: none; flex: 1; padding: 16px; }
  .comment-list { flex: 1; }
  .modal-close { position: absolute; top: 10px; right: 10px; z-index: 5;
    background: rgba(0,0,0,.35); color: #fff; width: 34px; height: 34px; border-radius: 50%; font-size: 16px; }
  #detailModal .modal-close { background: rgba(255,255,255,.18); backdrop-filter: blur(4px); }

  /* 评论输入条固定在详情底部 */
  .comment-input-row input { padding: 11px 14px; font-size: 16px; } /* 16px 防 iOS 自动放大 */

  /* 表单输入 16px 防 iOS 聚焦缩放 */
  .form-group input, .form-group textarea, .search-box input, .message-form textarea { font-size: 16px; }

  /* 排行 / 个人中心 / 留言板 */
  .rank-grid, .profile-grid { grid-template-columns: 1fr; gap: 12px; }
  .panel { padding: 16px; }
  .board-wrap { max-width: 100%; }
  .pager { margin-top: 18px; }
  .pager button { padding: 9px 20px; }

  /* toast 上移避开标签栏 */
  #toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
