/* 寒渊聚友阁 · 设计系统
   默认主题：极简白；设置内可切换「寒渊风」 */

:root,
html[data-theme="light"] {
  --bg: #f4f5f7;
  --bg-soft: #eceef1;
  --elev: #ffffff;
  --elev-2: #ffffff;
  --text: #14171c;
  --text-2: #6b7280;
  --text-3: #9aa1ac;
  --line: #e7e9ed;
  --line-soft: #f0f2f5;
  --brand: #2b4c7e;
  --brand-soft: #e8eef7;
  --brand-text: #ffffff;
  --danger: #d64545;
  --danger-soft: #fdecec;
  --success: #2f8f5b;
  --warn: #b7791f;
  --bubble-me: #2b4c7e;
  --bubble-me-text: #ffffff;
  --bubble-you: #ffffff;
  --bubble-you-text: #14171c;
  --gold: #b3894a;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .14);
  --radius: 14px;
  --radius-sm: 10px;
  --header-font: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --tab-h: 58px;
  --top-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme="hanyuan"] {
  --bg: #0a0e14;
  --bg-soft: #10161f;
  --elev: #131a24;
  --elev-2: #182130;
  --text: #e9e4d8;
  --text-2: #9aa3b2;
  --text-3: #6b7486;
  --line: #232c3a;
  --line-soft: #1a2230;
  --brand: #c9a961;
  --brand-soft: #1d2431;
  --brand-text: #0a0e14;
  --danger: #d97070;
  --danger-soft: #2a1a1c;
  --success: #6dbf8f;
  --warn: #d9b26a;
  --bubble-me: #2c3a2f;
  --bubble-me-text: #efe9da;
  --bubble-you: #171f2b;
  --bubble-you-text: #e9e4d8;
  --gold: #c9a961;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .6);
  --header-font: "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro SC", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
html[data-theme="hanyuan"] body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(201, 169, 97, .07), transparent 60%),
    var(--bg);
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--brand); text-decoration: none; }
img { max-width: 100%; }
ul { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
input, textarea { outline: none; }

/* ---------- 启动屏 ---------- */
.boot-screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  background: var(--bg); z-index: 9999;
}
.boot-mark {
  font-family: var(--header-font); font-size: 42px; letter-spacing: 12px;
  color: var(--text); padding-left: 12px;
}
html[data-theme="hanyuan"] .boot-mark { color: var(--gold); }
.boot-sub { font-size: 13px; letter-spacing: 8px; color: var(--text-3); padding-left: 8px; }
.boot-dots { display: flex; gap: 6px; margin-top: 28px; }
.boot-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--brand);
  opacity: .35; animation: bootPulse 1.1s infinite ease-in-out;
}
.boot-dots i:nth-child(2) { animation-delay: .15s; }
.boot-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bootPulse { 0%, 100% { opacity: .2; transform: scale(.85); } 50% { opacity: 1; transform: scale(1); } }

/* ---------- 布局 ---------- */
.app-root { min-height: 100%; }
.shell {
  max-width: 620px; margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  background: var(--bg); position: relative; display: flex; flex-direction: column;
}
@media (min-width: 900px) {
  body { background: var(--bg-soft); }
  html[data-theme="hanyuan"] body { background:
    radial-gradient(900px 500px at 50% 0%, rgba(201,169,97,.06), transparent 65%), #070a0f; }
  .shell {
    max-width: 560px; min-height: calc(100vh - 48px); height: calc(100vh - 48px);
    margin: 24px auto; border-radius: 22px; overflow: hidden;
    border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  }
}

.topbar {
  height: var(--top-h); flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--elev); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
}
.topbar .title { font-size: 17px; font-weight: 600; flex: 1; text-align: center; line-height: 1.15; }
.topbar .title-sub { font-size: 11px; color: var(--text-3); font-weight: 400; margin-top: 1px; }
html[data-theme="hanyuan"] .topbar { background: linear-gradient(180deg, #131a24, #0f151e); }
html[data-theme="hanyuan"] .topbar .title { font-family: var(--header-font); letter-spacing: 3px; color: var(--gold); }
.topbar .side { min-width: 64px; display: flex; align-items: center; gap: 6px; }
.topbar .side.right { justify-content: flex-end; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center;
  justify-content: center; color: var(--text); font-size: 18px;
}
.icon-btn:active { background: var(--bg-soft); }
.icon-btn.ghost { opacity: .8; }

.page { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page.no-scroll { overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.tabbar {
  flex: 0 0 auto; display: flex; background: var(--elev); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); z-index: 30;
}
html[data-theme="hanyuan"] .tabbar { background: linear-gradient(180deg, #101720, #0c1118); }
.tab {
  flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: var(--text-3); font-size: 11px; position: relative;
}
.tab .tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--brand); }
html[data-theme="hanyuan"] .tab.active { color: var(--gold); }
.tab .badge { position: absolute; top: 6px; left: calc(50% + 8px); }
.badge {
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: var(--danger);
  color: #fff; font-size: 11px; line-height: 17px; text-align: center; font-weight: 600;
}
.badge.dot { min-width: 8px; width: 8px; height: 8px; padding: 0; border-radius: 50%; }

/* ---------- 通用组件 ---------- */
.card { background: var(--elev); border-radius: var(--radius); box-shadow: var(--shadow); }
html[data-theme="hanyuan"] .card { border: 1px solid var(--line); box-shadow: none; }
.section { margin: 12px 12px 0; }
.section-title {
  font-size: 12px; color: var(--text-3); padding: 14px 6px 8px; letter-spacing: .5px;
}
.list { background: var(--elev); border-radius: var(--radius); overflow: hidden; }
html[data-theme="hanyuan"] .list { border: 1px solid var(--line); }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; position: relative;
  min-height: 56px;
}
.row + .row::before {
  content: ""; position: absolute; left: 62px; right: 0; top: 0; height: 1px; background: var(--line-soft);
}
.row.tappable:active { background: var(--bg-soft); }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-size: 15px; font-weight: 500; }
.row .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { font-size: 11.5px; color: var(--text-3); text-align: right; }
.row .chev { color: var(--text-3); font-size: 15px; }
.row.compact { min-height: 44px; padding: 9px 14px; }

.avatar {
  width: 42px; height: 42px; border-radius: 12px; flex: 0 0 auto; object-fit: cover;
  display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 600;
  background: var(--brand-soft); color: var(--brand); overflow: hidden;
}
html[data-theme="hanyuan"] .avatar { background: #1b2432; color: var(--gold); border: 1px solid #2a3446; }
.avatar.lg { width: 64px; height: 64px; border-radius: 18px; font-size: 22px; }
.avatar.sm { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.avatar.xs { width: 24px; height: 24px; border-radius: 7px; font-size: 11px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 46px; padding: 0 18px; border-radius: 12px; background: var(--brand);
  color: var(--brand-text); font-size: 15px; font-weight: 600; width: 100%;
  transition: transform .06s ease, opacity .2s;
}
.btn:active { transform: scale(.985); opacity: .92; }
.btn:disabled { opacity: .45; }
.btn.secondary { background: var(--bg-soft); color: var(--text); }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { height: 34px; padding: 0 14px; font-size: 13.5px; border-radius: 9px; width: auto; }
.btn.xs { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; width: auto; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin: 0 0 6px 2px; }
.input {
  width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--elev); padding: 0 14px; font-size: 15px; color: var(--text);
}
.input:focus { border-color: var(--brand); }
textarea.input { height: auto; min-height: 88px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; }
.hint { font-size: 12px; color: var(--text-3); margin: 6px 2px 0; }
.error-text { color: var(--danger); font-size: 12.5px; margin: 8px 2px 0; min-height: 18px; }

.switch { position: relative; width: 46px; height: 27px; flex: 0 0 auto; }
.switch input { display: none; }
.switch .track {
  position: absolute; inset: 0; background: var(--bg-soft); border-radius: 999px; transition: .2s;
  border: 1px solid var(--line);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: .2s;
}
.switch input:checked + .track { background: var(--brand); border-color: var(--brand); }
.switch input:checked + .track::after { transform: translateX(19px); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); font-size: 11.5px; font-weight: 500;
}
.chip.gray { background: var(--bg-soft); color: var(--text-2); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }

.empty {
  padding: 60px 30px; text-align: center; color: var(--text-3); font-size: 13.5px;
}
.empty .big { font-size: 40px; margin-bottom: 12px; opacity: .35; }

/* ---------- 消息列表 ---------- */
.conv {
  display: flex; gap: 12px; padding: 12px 14px; align-items: center; position: relative;
  background: var(--elev);
}
.conv:active { background: var(--bg-soft); }
.conv + .conv::before {
  content: ""; position: absolute; left: 68px; right: 0; top: 0; height: 1px; background: var(--line-soft);
}
.conv .body { flex: 1; min-width: 0; }
.conv .head { display: flex; align-items: baseline; gap: 6px; }
.conv .title { font-size: 15.5px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 11.5px; color: var(--text-3); }
.conv .preview {
  font-size: 13px; color: var(--text-3); margin-top: 3px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 5px;
}
.conv .right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.pin-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); }

/* ---------- 聊天 ---------- */
.chat-wrap { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; height: 100%; background: var(--bg); }
html[data-theme="hanyuan"] .chat-wrap { background: #0a0e14; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 12px 12px 4px; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; }
.msg-row { display: flex; gap: 8px; margin-bottom: 14px; align-items: flex-start; }
.msg-row.me { flex-direction: row-reverse; }
.msg-col { max-width: 74%; display: flex; flex-direction: column; }
.msg-row.me .msg-col { align-items: flex-end; }
.msg-name { font-size: 11px; color: var(--text-3); margin: 0 4px 3px; }
.bubble {
  padding: 9px 12px; border-radius: 14px; font-size: 15px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap; position: relative;
  background: var(--bubble-you); color: var(--bubble-you-text);
  border-top-left-radius: 4px; box-shadow: var(--shadow);
}
.msg-row.me .bubble {
  background: var(--bubble-me); color: var(--bubble-me-text);
  border-top-left-radius: 14px; border-top-right-radius: 4px;
}
html[data-theme="hanyuan"] .bubble { border: 1px solid #232c3a; }
html[data-theme="hanyuan"] .msg-row.me .bubble { border-color: #3a4a3c; }
.bubble img, .bubble video { border-radius: 8px; display: block; max-width: 220px; max-height: 280px; }
.bubble.recalled { background: transparent !important; color: var(--text-3); font-size: 12px; box-shadow: none; border: none; }
.chat-time { text-align: center; font-size: 11px; color: var(--text-3); margin: 8px 0 14px; }
.sys-msg { text-align: center; font-size: 11.5px; color: var(--text-3); margin: 8px 0; }
.msg-status { font-size: 10.5px; color: var(--text-3); margin: 3px 4px 0; }

.composer {
  flex: 0 0 auto; border-top: 1px solid var(--line); background: var(--elev);
  padding: 8px 10px calc(8px + var(--safe-b)); display: flex; align-items: flex-end; gap: 6px;
}
html[data-theme="hanyuan"] .composer { background: #101720; }
.composer .input-like {
  flex: 1; min-height: 38px; max-height: 120px; overflow-y: auto; padding: 8px 12px;
  background: var(--bg); border-radius: 10px; border: 1px solid var(--line);
  font-size: 15px; line-height: 1.4; outline: none;
}
html[data-theme="hanyuan"] .composer .input-like { background: #0c1118; }
.composer .input-like:empty::before { content: attr(data-placeholder); color: var(--text-3); }
.composer .send-btn {
  height: 38px; padding: 0 14px; border-radius: 10px; background: var(--brand);
  color: var(--brand-text); font-weight: 600; font-size: 14px;
}
.composer .send-btn:disabled { opacity: .4; }
.composer .tool { width: 36px; height: 36px; border-radius: 9px; display: flex; align-items: center;
  justify-content: center; font-size: 19px; color: var(--text-2); }

.typing { font-size: 11.5px; color: var(--text-3); padding: 0 14px 6px; height: 16px; }

/* ---------- 弹层 ---------- */
.sheet-mask { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 200; animation: fadeIn .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 201; background: var(--elev);
  border-radius: 18px 18px 0 0; padding: 8px 0 calc(8px + var(--safe-b));
  max-height: 86vh; overflow-y: auto; animation: slideUp .22s cubic-bezier(.2, .8, .3, 1);
  max-width: 560px; margin: 0 auto;
}
.sheet-head { padding: 14px 18px 8px; font-size: 15px; font-weight: 600; text-align: center; }
.sheet-item {
  padding: 14px 20px; font-size: 15.5px; text-align: center; color: var(--text);
  border-top: 1px solid var(--line-soft);
}
.sheet-item:active { background: var(--bg-soft); }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel { color: var(--text-2); margin-top: 8px; border-top: none; }
.sheet-body { padding: 4px 18px 8px; }

.modal-mask { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); z-index: 300; display: flex;
  align-items: center; justify-content: center; padding: 24px; animation: fadeIn .16s ease; }
.modal {
  background: var(--elev); border-radius: 18px; width: 100%; max-width: 380px; padding: 22px 20px 16px;
  box-shadow: var(--shadow-lg); animation: popIn .2s cubic-bezier(.2, .8, .3, 1); max-height: 80vh; overflow-y: auto;
}
.modal h3 { font-size: 17px; margin-bottom: 8px; }
.modal .m-body { font-size: 14px; color: var(--text-2); white-space: pre-wrap; }
.modal .m-actions { display: flex; gap: 10px; margin-top: 18px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
@keyframes popIn { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.toast-root { position: fixed; left: 0; right: 0; bottom: calc(90px + var(--safe-b)); z-index: 400;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: rgba(20, 24, 31, .92); color: #fff; padding: 9px 16px; border-radius: 999px;
  font-size: 13.5px; max-width: 80%; animation: fadeIn .18s ease; backdrop-filter: blur(8px);
}
html[data-theme="hanyuan"] .toast { background: rgba(201, 169, 97, .92); color: #14171c; font-weight: 600; }

/* ---------- 登录 ---------- */
.auth-screen {
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  padding: 0 24px calc(24px + var(--safe-b)); justify-content: center;
  background: var(--bg);
}
html[data-theme="hanyuan"] .auth-screen {
  background: radial-gradient(600px 400px at 50% 12%, rgba(201,169,97,.12), transparent 70%), #080b11;
}
.auth-brand { text-align: center; margin-bottom: 34px; }
.auth-brand .mark {
  font-family: var(--header-font); font-size: 36px; letter-spacing: 10px;
  color: var(--text); padding-left: 10px;
}
html[data-theme="hanyuan"] .auth-brand .mark { color: var(--gold); text-shadow: 0 0 30px rgba(201,169,97,.25); }
.auth-brand .sub { font-size: 12px; letter-spacing: 6px; color: var(--text-3); margin-top: 8px; padding-left: 6px; }
.auth-tabs { display: flex; gap: 6px; background: var(--bg-soft); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.auth-tabs button {
  flex: 1; height: 38px; border-radius: 9px; font-size: 14px; color: var(--text-2); font-weight: 500;
}
.auth-tabs button.active { background: var(--elev); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
html[data-theme="hanyuan"] .auth-tabs button.active { background: #1b2432; color: var(--gold); box-shadow: none; border: 1px solid #2a3446; }
.auth-foot { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 22px; line-height: 1.7; }
.agree { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--text-2); margin: 4px 0 16px; }
.agree input { margin-top: 3px; width: 15px; height: 15px; accent-color: var(--brand); }

/* ---------- 详情页 ---------- */
.profile-head { display: flex; gap: 14px; align-items: center; padding: 18px 16px; }
.profile-head .n { font-size: 19px; font-weight: 600; }
.profile-head .h { font-size: 12.5px; color: var(--text-3); margin-top: 3px; font-variant-numeric: tabular-nums; }
.page-pad { padding-bottom: 24px; }

.tag-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* 管理员表格 */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--elev); border-radius: 12px; padding: 12px 10px; text-align: center; }
html[data-theme="hanyuan"] .stat { border: 1px solid var(--line); }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .4px; }
.copyable:active { opacity: .6; }

/* 主题选择 */
.theme-picker { display: flex; gap: 10px; }
.theme-card {
  flex: 1; border-radius: 12px; border: 2px solid var(--line); overflow: hidden; padding: 0;
  text-align: left; background: var(--elev);
}
.theme-card.active { border-color: var(--brand); }
.theme-card .prev { height: 62px; display: flex; align-items: flex-end; padding: 8px; gap: 4px; }
.theme-card .prev span { display: block; height: 8px; border-radius: 4px; flex: 1; }
.theme-card.light .prev { background: #f4f5f7; }
.theme-card.light .prev span { background: #2b4c7e; }
.theme-card.hanyuan .prev { background: #0b0f16; }
.theme-card.hanyuan .prev span { background: #c9a961; }
.theme-card .lbl { padding: 8px 10px; font-size: 12.5px; color: var(--text-2); }

/* 安全区 & 滚动条 */
@supports (padding: max(0px)) { .page { padding-bottom: max(0px, var(--safe-b)); } }
::-webkit-scrollbar { width: 0; height: 0; }

.skeleton { background: linear-gradient(90deg, var(--bg-soft), var(--line-soft), var(--bg-soft));
  background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.hidden { display: none !important; }
.muted { color: var(--text-3); }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt12 { margin-top: 12px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }
.flex { display: flex; } .gap8 { gap: 8px; } .between { justify-content: space-between; } .center-it { align-items: center; }
.wrap { flex-wrap: wrap; }
