:root {
  --bg: #0f0f16;
  --bg-soft: #171722;
  --panel: #1c1c28;
  --line: #2a2a3a;
  --text: #ececf2;
  --muted: #8a8a9a;
  --accent: #e5567a;
  --accent-2: #7b5cff;
  --bubble-me: linear-gradient(135deg, #e5567a, #ff7a99);
  --bubble-her: #23232f;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --tabbar-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* 头像通用 */
.avatar { border-radius: 14px; background-size: cover; background-position: center; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700;
  background-color: #333; background-image: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.avatar.sm { width: 40px; height: 40px; border-radius: 12px; font-size: 15px; }
.avatar.msg { width: 34px; height: 34px; border-radius: 11px; font-size: 14px; }
.avatar.lg { width: 92px; height: 92px; border-radius: 28px; font-size: 34px; }

/* ---------- 登录 ---------- */
.auth-screen { display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 80% at 50% 0%, #241826, var(--bg) 60%); padding: 24px; }
.auth-card { width: 100%; max-width: 360px; }
.brand { text-align: center; margin-bottom: 28px; }
.brand-avatar { width: 76px; height: 76px; border-radius: 24px; margin: 0 auto 14px;
  display: grid; place-items: center; font-size: 34px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 10px 30px rgba(229,86,122,.35); }
.brand-name { font-size: 24px; font-weight: 700; }
.brand-sub { color: var(--muted); margin-top: 4px; font-size: 13px; }
.tabs { display: flex; gap: 8px; background: var(--bg-soft); padding: 5px; border-radius: 14px; margin-bottom: 16px; }
.tab { flex: 1; padding: 10px; border: 0; background: transparent; color: var(--muted); border-radius: 10px; font-size: 15px; }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form input { padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); font-size: 16px; outline: none; }
.form input:focus { border-color: var(--accent); }
.err { color: #ff6b6b; font-size: 13px; min-height: 16px; padding: 0 4px; }
.btn-primary { padding: 15px; border: 0; border-radius: 14px; color: #fff; font-size: 16px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); margin-top: 4px; }
.btn-primary:active { opacity: .85; }

/* ---------- 主体/视图 ---------- */
.app-shell { display: flex; flex-direction: column; }
.view { position: absolute; inset: 0 0 var(--tabbar-h) 0; display: flex; flex-direction: column; }
.page-header { padding: calc(var(--safe-top) + 14px) 18px 10px; }
.page-header h2 { margin: 0; font-size: 22px; }

/* ---------- 聊天 ---------- */
.chat-header { display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  background: rgba(18,18,26,.9); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.peer { display: flex; align-items: center; gap: 10px; }
.peer-name { font-size: 16px; font-weight: 600; }
.peer-status { font-size: 12px; color: #57d38c; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.model-select { max-width: 130px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--muted); font-size: 12px; }
.icon-btn { width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); font-size: 17px; }

.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; max-width: 100%; }
.row.me { justify-content: flex-end; }
.bubble { max-width: 76%; padding: 11px 14px; border-radius: 18px; font-size: 15.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; }
.row.her .bubble { background: var(--bubble-her); border-bottom-left-radius: 6px; }
.row.me .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 6px; }
.typing .bubble { color: var(--muted); }
.dots span { animation: blink 1.2s infinite both; }
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px;
  background: rgba(18,18,26,.95); border-top: 1px solid var(--line); }
#input { flex: 1; resize: none; max-height: 120px; padding: 11px 14px; font-size: 16px;
  border-radius: 20px; border: 1px solid var(--line); background: var(--bg-soft);
  color: var(--text); outline: none; font-family: inherit; }
#input:focus { border-color: var(--accent); }
.send-btn { width: 42px; height: 42px; flex: none; border: 0; border-radius: 50%; color: #fff; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.send-btn:disabled { opacity: .4; }

/* ---------- 角色广场 ---------- */
.role-grid { flex: 1; overflow-y: auto; padding: 6px 14px 20px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.role-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.role-cover { width: 100%; aspect-ratio: 1/1; background-size: cover; background-position: center;
  background-image: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center;
  font-size: 44px; font-weight: 700; color: #fff; }
.role-info { padding: 10px 12px 12px; }
.role-name { font-size: 16px; font-weight: 700; }
.role-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.chip { font-size: 11px; color: var(--accent); background: rgba(229,86,122,.13); padding: 2px 8px; border-radius: 20px; }
.role-btn { display: block; width: calc(100% - 24px); margin: 0 12px 12px; padding: 9px; border: 0; border-radius: 11px;
  color: #fff; font-size: 14px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.role-card.active { border-color: var(--accent); }

/* ---------- 我的 ---------- */
.me-body { flex: 1; overflow-y: auto; padding: 6px 18px 24px; display: flex; flex-direction: column; gap: 18px; }
.me-card { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 20px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }
.me-name-wrap { display: flex; gap: 8px; align-items: center; width: 100%; max-width: 260px; }
.me-nickname { flex: 1; text-align: center; padding: 9px 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--text); font-size: 16px; outline: none; }
.me-nickname:focus { border-color: var(--accent); }
.mini-btn { padding: 9px 14px; border: 0; border-radius: 11px; color: #fff; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.me-phone { color: var(--muted); font-size: 13px; }
.me-list { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.me-row { display: flex; justify-content: space-between; align-items: center; padding: 15px 16px; color: var(--muted); font-size: 15px; }
.me-row + .me-row { border-top: 1px solid var(--line); }
.me-row b { color: var(--text); }
.me-row.btn { color: var(--text); }
.me-row .arrow { color: var(--muted); font-size: 20px; }
.btn-ghost { padding: 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font-size: 15px; }
.btn-ghost.danger { color: #ff6b6b; }
.me-tip { color: var(--muted); font-size: 12px; text-align: center; line-height: 1.6; }

/* ---------- 底部导航 ---------- */
.tabbar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--tabbar-h);
  padding-bottom: var(--safe-bottom); display: flex; background: rgba(18,18,26,.96);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line); }
.tabbtn { flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; }
.tabbtn .ti { font-size: 20px; filter: grayscale(1) opacity(.7); }
.tabbtn.active { color: var(--accent); }
.tabbtn.active .ti { filter: none; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; display: flex; align-items: flex-end; }
.modal-panel { width: 100%; background: var(--panel); border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(var(--safe-bottom) + 20px); display: flex; flex-direction: column; gap: 14px; max-height: 82vh; }
.modal-title { font-size: 17px; font-weight: 700; text-align: center; }
.upload-btn { text-align: center; padding: 14px; border-radius: 14px; color: #fff; font-size: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.preset-hint { text-align: center; color: var(--muted); font-size: 13px; }
.preset-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; overflow-y: auto; }
.preset-grid img { width: 100%; aspect-ratio: 1/1; border-radius: 14px; object-fit: cover; border: 2px solid transparent; }
.preset-grid img:active { border-color: var(--accent); }
