/* ===== HanYue Ai 小酒馆 — CSS (手机优先 + 桌面端大卡) ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #13131a;
  --bg-card: #1a1a24;
  --bg-input: #1e1e2a;
  --bg-overlay: rgba(0,0,0,0.7);
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-glow: rgba(139,92,246,0.3);
  --border: rgba(255,255,255,0.06);
  --border-focus: rgba(139,92,246,0.5);
  --success: #10b981;
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-card: 0 4px 20px rgba(0,0,0,0.3);
  --shadow-float: 0 8px 40px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
  --font: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --nav-height: 60px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%; width: 100%; font-family: var(--font);
  background: var(--bg-primary); color: var(--text-primary);
  overflow: hidden; -webkit-tap-highlight-color: transparent;
}

/* ===== 页面系统 ===== */
.page {
  display: none; position: fixed; inset: 0; z-index: 50;
  overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  flex-direction: column;
}
.page.active { display: flex; }

/* Tab 页（在主容器内切换）*/
#mainApp { display: none; position: fixed; inset: 0; flex-direction: column; }
#mainApp.visible { display: flex; }
.tab-page { display: none; flex: 1; flex-direction: column; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding-bottom: var(--nav-height); }
.tab-page.active { display: flex; }

/* ===== 登录页 ===== */
.login-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: radial-gradient(ellipse at 50% 30%, rgba(139,92,246,0.15), transparent 70%);
}
.login-logo { font-size: 64px; margin-bottom: 12px; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-10px)} }
.login-title { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: var(--text-secondary); margin-bottom: 32px; }
.login-form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-form input {
  width: 100%; padding: 14px 16px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 16px; outline: none;
}
.login-form input:focus { border-color: var(--border-focus); }
.login-error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 20px; text-align: center; }

/* ===== 按钮 ===== */
.btn-primary {
  padding: 14px 24px; border: none; border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: white; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: all var(--transition);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-large { width: 100%; padding: 16px; font-size: 17px; border-radius: var(--radius-lg); }
.btn-icon {
  width: 40px; height: 40px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-primary); font-size: 20px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.btn-icon:hover { background: rgba(255,255,255,0.08); }
.btn-small {
  padding: 4px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--accent); font-size: 13px; cursor: pointer;
}

/* ===== 底部导航栏 ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: var(--nav-height);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(10,10,15,0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-around;
}
.nav-item {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}
.nav-item.active { color: var(--accent); }
.nav-item .nav-icon { font-size: 22px; }
.nav-item .nav-label { font-size: 11px; }
.nav-create .nav-icon {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  font-size: 18px; color: white; margin-top: -8px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(139,92,246,0.28);
}

/* ===== 浏览页顶栏 ===== */
.browse-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(10,10,15,0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.browse-top-row,
.browse-filter-row,
.browse-tags-row,
.char-grid,
.empty-state {
  width: min(100%, 1240px);
  margin-left: auto;
  margin-right: auto;
}
.browse-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.browse-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.browse-logo {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  box-shadow: 0 8px 20px rgba(139,92,246,0.28);
  font-size: 18px;
  flex-shrink: 0;
}
.browse-brand-text { min-width: 0; }
.browse-title { font-size: 16px; font-weight: 700; line-height: 1.15; }
.browse-subtitle { margin-top: 2px; color: var(--text-secondary); font-size: 11px; }
.browse-top-actions {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}
.browse-search-inline {
  flex: 1;
  min-width: 180px;
  max-width: 520px;
  height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border);
}
.browse-search-icon {
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
}
.browse-search-inline input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.browse-filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.browse-filter-row::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: rgba(26,26,36,0.96);
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-chip.active {
  background: rgba(139,92,246,0.16);
  border-color: rgba(139,92,246,0.36);
  color: #ddd6fe;
}
.filter-chip-fav.active {
  background: rgba(250,204,21,0.16);
  border-color: rgba(250,204,21,0.3);
  color: #facc15;
}
.browse-tags-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.browse-tags {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 1px;
  transition: max-height var(--transition);
}
.browse-tags.collapsed {
  max-height: 38px;
  overflow: hidden;
}
.browse-tags.expanded {
  max-height: 180px;
  overflow: hidden;
}
.browse-tags-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(20,20,28,0.96);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.tag-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.tag-btn.active {
  background: rgba(139,92,246,0.14);
  color: white;
  border-color: rgba(139,92,246,0.38);
}
.browse-search-inline:focus-within { border-color: var(--border-focus); }

/* ===== 角色卡片网格 ===== */
.char-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 10px 12px 20px;
  flex: 1;
  position: relative;
  z-index: 1;
}
@media (min-width: 640px) {
  .char-grid { grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 8px 20px 20px; }
}
@media (min-width: 1024px) {
  .browse-header { padding: 12px 20px 10px; }
  .char-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; padding: 10px 24px 24px; }
}
@media (min-width: 1400px) {
  .char-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 768px) {
  .browse-top-row {
    flex-wrap: wrap;
    align-items: stretch;
  }
  .browse-top-actions {
    width: 100%;
  }
  .browse-search-inline {
    max-width: none;
  }
}
@media (max-width: 520px) {
  .browse-header {
    gap: 8px;
    padding: 8px 10px 6px;
  }
  .browse-logo {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 16px;
  }
  .browse-title { font-size: 14px; }
  .browse-subtitle { font-size: 10px; }
  .browse-top-actions { gap: 6px; }
  .browse-search-inline { height: 36px; }
  .filter-chip {
    padding: 7px 12px;
    font-size: 12px;
  }
  .browse-tags-toggle { padding: 7px 9px; }
  .char-grid { padding: 8px 10px 18px; }
}

.char-card {
  position: relative; border-radius: var(--radius-lg); overflow: hidden;
  background: var(--bg-card); cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  aspect-ratio: 3/4; animation: fadeInUp 0.4s ease both;
}
.char-card:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 8px 30px rgba(0,0,0,0.4); }
@keyframes fadeInUp { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }

.char-card-img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.char-card-placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 56px; background: linear-gradient(135deg, #1e1e2e, #2a2a3e); position: absolute; inset: 0;
}
.char-card-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.9));
  padding: 48px 14px 14px;
}
.char-card-name { font-size: 16px; font-weight: 600; color: white; text-shadow: 0 1px 4px rgba(0,0,0,0.5); }
.char-card-desc {
  font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.4;
}
.char-card-tags { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.char-card-tag {
  font-size: 10px; padding: 2px 8px; border-radius: 10px;
  background: rgba(139,92,246,0.3); color: rgba(255,255,255,0.85);
}

.char-card-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}
.char-card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}
.char-card-hot {
  font-size: 10px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(248, 153, 72, 0.3);
  color: #fed7aa;
}
.char-card-fav {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: none;
  background: rgba(15,23,42,0.7);
  color: rgba(249,250,251,0.7);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.char-card-fav.favorite {
  background: rgba(250,204,21,0.18);
  color: #facc15;
}

/* ===== 空状态 ===== */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 60px 24px; color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 15px; }

/* ===== 聊天记录页 ===== */
.history-list { padding: 12px 16px; }
.history-card {
  display: flex; gap: 14px; padding: 14px; background: var(--bg-card);
  border-radius: var(--radius-md); margin-bottom: 10px; cursor: pointer;
  border: 1px solid var(--border); transition: all var(--transition);
  align-items: center;
}
.history-card:hover { border-color: rgba(139,92,246,0.3); background: rgba(139,92,246,0.05); }
.history-avatar {
  width: 52px; height: 52px; border-radius: var(--radius-sm); overflow: hidden; flex-shrink: 0;
}
.history-avatar img { width: 100%; height: 100%; object-fit: cover; }
.history-avatar-letter {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: linear-gradient(135deg, #2a2a3e, #3a3a4e);
}
.history-info { flex: 1; min-width: 0; }
.history-name { font-size: 15px; font-weight: 600; }
.history-session { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.history-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.history-delete {
  width: 36px; height: 36px; border: none; border-radius: var(--radius-sm);
  background: rgba(239,68,68,0.1); color: var(--danger); font-size: 16px;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}

/* ===== 角色详情页 ===== */
#detailPage {
  background: var(--bg-primary);
}
.detail-bg {
  position: fixed; inset: 0; z-index: 0;
  background-size: cover; background-position: center top;
  filter: blur(20px) brightness(0.3); transform: scale(1.1);
}
.detail-content {
  position: relative; z-index: 1; padding: 0 20px 40px;
  display: flex; flex-direction: column; align-items: center; min-height: 100vh;
}
.detail-back {
  align-self: flex-start; margin: 12px 0; padding: 8px 16px;
  border: none; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1); backdrop-filter: blur(8px);
  color: white; font-size: 15px; cursor: pointer;
}
.detail-avatar {
  width: 200px; height: 260px; border-radius: var(--radius-lg);
  overflow: hidden; margin-bottom: 16px;
  box-shadow: var(--shadow-float); border: 2px solid rgba(255,255,255,0.1);
}
.detail-avatar img { width: 100%; height: 100%; object-fit: cover; }
.detail-avatar .placeholder {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 64px; background: linear-gradient(135deg, #1e1e2e, #2a2a3e);
}
.detail-name { font-size: 24px; font-weight: 700; margin-bottom: 4px; text-align: center; }
.detail-creator { color: var(--text-secondary); font-size: 14px; margin-bottom: 12px; }
.detail-tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 16px; }
.detail-tags .tag-btn { font-size: 12px; padding: 4px 12px; cursor: default; }
.detail-desc {
  width: 100%; max-width: 500px;
  background: rgba(255,255,255,0.05); backdrop-filter: blur(8px);
  border-radius: var(--radius-md); padding: 16px;
  font-size: 14px; line-height: 1.7; color: var(--text-secondary);
  margin-bottom: 24px; white-space: pre-wrap;
}
.detail-meta {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.detail-meta-item {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(15,23,42,0.85);
  border: 1px solid rgba(148,163,184,0.5);
}
.detail-actions { width: 100%; max-width: 500px; }
.detail-fav-btn.favorite {
  border-color: rgba(250,204,21,0.8);
  background: rgba(250,204,21,0.12);
  color: #facc15;
}
.detail-sessions { width: 100%; max-width: 500px; margin-top: 24px; }
.detail-sessions h4 { font-size: 14px; color: var(--text-muted); margin-bottom: 8px; }
.session-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer;
  transition: background var(--transition);
}
.session-item:hover { background: rgba(255,255,255,0.1); }
.session-item-title { font-size: 14px; }
.session-item-count { font-size: 12px; color: var(--text-muted); }
.session-item-delete, .session-item-rename {
  background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 14px; padding: 4px;
}
.session-item-rename:hover { color: var(--accent); }
.session-item-actions { display: flex; gap: 4px; flex-shrink: 0; }
.session-rename-input {
  flex: 1; padding: 6px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-focus); background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; font-family: var(--font);
  outline: none; min-width: 0;
}
.session-rename-actions { display: flex; gap: 4px; }
.session-rename-actions button {
  padding: 4px 10px; border: none; border-radius: var(--radius-sm);
  font-size: 12px; cursor: pointer;
}
.session-rename-save { background: var(--accent); color: white; }
.session-rename-cancel { background: rgba(255,255,255,0.08); color: var(--text-secondary); }

/* ===== 聊天页 ===== */
#chatPage {
  background: var(--bg-primary);
}
.chat-bg {
  position: fixed; inset: 0; z-index: 0;
  background-size: cover; background-position: center; opacity: 0.15;
  pointer-events: none;
}
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; position: sticky; top: 0; z-index: 10;
  background: rgba(10,10,15,0.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.chat-back { font-size: 20px; background: none; border: none; color: var(--text-primary); cursor: pointer; padding: 4px 8px; }
.chat-header-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.chat-header-avatar { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; flex-shrink: 0; }
.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-name { font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-header-actions { display: flex; gap: 2px; align-items: center; }

/* 聊天内模型选择器 */
.chat-model-select {
  padding: 4px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 12px; font-family: var(--font);
  outline: none; max-width: 160px; appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='8' height='5' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238888a0' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center;
  padding-right: 20px;
}
.chat-model-select:focus { border-color: var(--border-focus); }
@media (max-width: 480px) { .chat-model-select { max-width: 100px; font-size: 11px; } }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px; position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: 16px; -webkit-overflow-scrolling: touch;
}
.msg { display: flex; flex-direction: column; max-width: 85%; animation: fadeInUp 0.3s ease; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }
.msg-bubble {
  padding: 12px 16px; border-radius: var(--radius-lg);
  font-size: 15px; line-height: 1.7; word-break: break-word; white-space: pre-wrap;
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: white; border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
  background: var(--bg-card); color: var(--text-primary);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.msg-actions { display: flex; gap: 8px; margin-top: 4px; opacity: 0; transition: opacity var(--transition); }
.msg:hover .msg-actions, .msg.touch-active .msg-actions { opacity: 1; }
.msg.user .msg-actions { justify-content: flex-end; }
.msg-action-btn {
  font-size: 12px; color: var(--text-muted); background: none; border: none;
  cursor: pointer; padding: 2px 6px;
}
.msg-action-btn:hover { color: var(--text-primary); }
.msg-edit-area {
  width: 100%; min-height: 60px; padding: 10px; border-radius: var(--radius-sm);
  background: var(--bg-input); border: 1px solid var(--border-focus);
  color: var(--text-primary); font-size: 15px; line-height: 1.6;
  font-family: var(--font); resize: vertical; outline: none;
}
.msg-edit-actions { display: flex; gap: 8px; margin-top: 6px; }
.msg-edit-save { padding: 4px 14px; border: none; border-radius: var(--radius-sm); background: var(--accent); color: white; font-size: 13px; cursor: pointer; }
.msg-edit-cancel { padding: 4px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: transparent; color: var(--text-secondary); font-size: 13px; cursor: pointer; }
.typing-indicator { align-self: flex-start; padding: 12px 16px; background: var(--bg-card); border-radius: var(--radius-lg); border: 1px solid var(--border); }
.typing-dots { display: flex; gap: 4px; }
.typing-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: typing 1.4s infinite; display: inline-block; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }
.chat-input-area {
  display: flex; gap: 8px; padding: 12px 16px;
  background: rgba(10,10,15,0.95); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border); position: relative; z-index: 10;
}
.chat-input-area textarea {
  flex: 1; padding: 10px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 15px; font-family: var(--font);
  resize: none; outline: none; max-height: 120px;
}
.chat-input-area textarea:focus { border-color: var(--border-focus); }
.chat-send-btn {
  width: 44px; height: 44px; border: none; border-radius: var(--radius-md);
  background: var(--accent); color: white; font-size: 18px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* ===== 创建页 ===== */
.create-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; position: sticky; top: 0; z-index: 10;
  background: rgba(10,10,15,0.95); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.create-header h2 { font-size: 18px; }
.create-form, .settings-form { padding: 20px 16px 40px; max-width: 600px; margin: 0 auto; width: 100%; }
.create-avatar-upload { display: flex; justify-content: center; margin-bottom: 24px; }
.create-avatar-preview {
  width: 140px; height: 180px; border-radius: var(--radius-lg);
  border: 2px dashed var(--border); display: flex; align-items: center;
  justify-content: center; cursor: pointer; overflow: hidden;
  color: var(--text-muted); font-size: 14px; text-align: center;
}
.create-avatar-preview:hover { border-color: var(--accent); }
.create-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group .hint { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.required { color: var(--danger); }
.form-group input, .form-group textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 15px; font-family: var(--font);
  outline: none; transition: border var(--transition);
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--border-focus); }
.form-group textarea { resize: vertical; line-height: 1.6; }
.form-select {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 15px; font-family: var(--font);
  outline: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238888a0' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.form-row { display: flex; align-items: center; }
.toggle-label { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text-primary); cursor: pointer; }
.toggle-label input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.alt-greeting-item { display: flex; gap: 8px; margin-bottom: 8px; align-items: flex-start; }
.alt-greeting-item textarea {
  flex: 1; padding: 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text-primary); font-size: 14px; font-family: var(--font);
  resize: vertical; outline: none; min-height: 60px;
}
.alt-greeting-remove {
  width: 32px; height: 32px; border: none; border-radius: var(--radius-sm);
  background: rgba(239,68,68,0.2); color: var(--danger); cursor: pointer; font-size: 16px; flex-shrink: 0; margin-top: 4px;
}

.worldbook-placeholder {
  padding: 12px 12px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  background: rgba(15,23,42,0.85);
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.worldbook-placeholder p {
  margin: 0;
}
.worldbook-placeholder .btn-small[disabled] {
  opacity: 0.6;
  cursor: default;
}

/* ===== 弹层 ===== */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--bg-overlay);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from{opacity:0} to{opacity:1} }
.greeting-selector, .sessions-panel, .persona-panel {
  width: 100%; max-width: 500px; max-height: 75vh;
  background: var(--bg-secondary); border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow-y: auto; animation: slideUp 0.3s ease;
}
@keyframes slideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
.greeting-header, .sessions-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--bg-secondary);
}
.greeting-header h3, .sessions-header h3 { font-size: 17px; }
.greeting-close {
  width: 32px; height: 32px; border: none; border-radius: 50%;
  background: rgba(255,255,255,0.08); color: var(--text-primary); font-size: 16px; cursor: pointer;
}
.greeting-list, .persona-form { padding: 12px 16px; }
.greeting-item {
  padding: 14px 16px; border-radius: var(--radius-md);
  background: var(--bg-card); margin-bottom: 8px; cursor: pointer;
  border: 1px solid var(--border); transition: all var(--transition);
}
.greeting-item:hover { border-color: var(--accent); background: rgba(139,92,246,0.08); }
.greeting-item-label { font-size: 13px; color: var(--accent); font-weight: 500; margin-bottom: 4px; }
.greeting-item-preview { font-size: 14px; color: var(--text-secondary); line-height: 1.5; }
.sessions-list { padding: 12px; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 200; }
.toast {
  padding: 10px 20px; border-radius: var(--radius-md);
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 14px;
  box-shadow: var(--shadow-float); margin-bottom: 8px;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  white-space: nowrap;
}
.toast.error { border-color: rgba(239,68,68,0.3); background: rgba(239,68,68,0.15); }
@keyframes toastIn { from{opacity:0;transform:translateY(-10px)} to{opacity:1;transform:translateY(0)} }
@keyframes toastOut { to{opacity:0;transform:translateY(-10px)} }
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ===== 个人主页 ===== */
.profile-hero {
  position: relative; padding: 60px 20px 24px; text-align: center;
  background: linear-gradient(180deg, rgba(139,92,246,0.2), transparent);
  min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
}
.profile-bg-img {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  opacity: 0.3; z-index: 0;
}
.profile-info { position: relative; z-index: 1; }
.profile-avatar-wrap { position: relative; display: inline-block; margin-bottom: 12px; }
.profile-avatar {
  width: 80px; height: 80px; border-radius: 50%; overflow: hidden;
  border: 3px solid rgba(139,92,246,0.6); display: flex; align-items: center;
  justify-content: center; font-size: 36px; background: var(--bg-card);
  box-shadow: 0 0 20px rgba(139,92,246,0.3);
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-edit {
  position: absolute; bottom: 0; right: -4px; width: 28px; height: 28px;
  border-radius: 50%; border: 2px solid var(--bg-primary);
  background: var(--accent); font-size: 13px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
}
.profile-name { font-size: 20px; font-weight: 700; }
.profile-subname {
  font-size: 12px;
  color: rgba(232,232,240,0.72);
  margin-top: 6px;
}
.profile-id { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.profile-bg-edit {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  padding: 6px 12px; border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-sm); background: rgba(0,0,0,0.4);
  backdrop-filter: blur(8px); color: var(--text-secondary);
  font-size: 12px; cursor: pointer;
}

.profile-balance {
  margin: 16px; padding: 16px 20px; background: var(--bg-card);
  border-radius: var(--radius-md); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.balance-label { font-size: 14px; color: var(--text-secondary); }
.balance-value { font-size: 20px; font-weight: 700; color: var(--accent); }

.profile-section { padding: 16px; }
.profile-nickname-card {
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.profile-nickname-tip {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.profile-nickname-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.profile-nickname-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}
.profile-nickname-input:focus { border-color: var(--border-focus); }
.profile-nickname-meta {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}
.section-title {
  font-size: 16px; font-weight: 600; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.section-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.section-btn {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 8px; background: var(--bg-card); border-radius: var(--radius-md);
  border: 1px solid var(--border); color: var(--text-primary);
  font-size: 13px; cursor: pointer; transition: all var(--transition);
}
.section-btn span { font-size: 24px; }
.section-btn:hover { border-color: var(--accent); background: rgba(139,92,246,0.08); }

@media (max-width: 480px) {
  .profile-nickname-row {
    flex-direction: column;
  }

  .profile-nickname-row .btn-small {
    width: 100%;
    padding: 10px 12px;
  }
}

/* 个人设定列表 */
.persona-list { display: flex; flex-direction: column; gap: 8px; }
.persona-card {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--bg-card); border-radius: var(--radius-md);
  border: 1px solid var(--border); transition: all var(--transition);
}
.persona-card.default { border-color: rgba(139,92,246,0.4); background: rgba(139,92,246,0.05); }
.persona-card-info { flex: 1; min-width: 0; }
.persona-card-name { font-size: 15px; font-weight: 500; }
.persona-card-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.persona-card-tag { font-size: 10px; padding: 1px 6px; border-radius: 4px; background: var(--accent); color: white; }
.persona-card-actions { display: flex; gap: 4px; }
.persona-card-actions button {
  width: 30px; height: 30px; border: none; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05); color: var(--text-muted); font-size: 14px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* 身份选择（聊天前弹窗内列表）*/
.persona-select-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.persona-select-item {
  padding: 12px 14px; border-radius: var(--radius-md);
  background: var(--bg-card); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.persona-select-item:hover, .persona-select-item.selected {
  border-color: var(--accent); background: rgba(139,92,246,0.1);
}
.persona-select-item .ps-name { font-size: 14px; font-weight: 500; }
.persona-select-item .ps-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.persona-divider {
  text-align: center; font-size: 12px; color: var(--text-muted);
  padding: 8px 0; position: relative;
}
.persona-divider::before, .persona-divider::after {
  content: ''; position: absolute; top: 50%; width: 30%; height: 1px;
  background: var(--border);
}
.persona-divider::before { left: 0; }
.persona-divider::after { right: 0; }

/* 其他按钮 */
.btn-outline {
  padding: 14px 24px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: transparent; color: var(--text-secondary); font-size: 16px;
  font-weight: 500; cursor: pointer; transition: all var(--transition);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  width: 100%; padding: 14px; border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-md); background: rgba(239,68,68,0.1);
  color: var(--danger); font-size: 15px; cursor: pointer;
}
.create-actions { display: flex; gap: 10px; }
.create-actions .btn-large { flex: 1; }

/* settings in profile */
#settingsArea { padding: 0; }

/* ===== 角色管理按钮 ===== */
.detail-manage {
  width: 100%; max-width: 500px; display: flex; gap: 10px; margin-top: 12px;
}
.detail-manage button { flex: 1; }
.btn-danger-sm {
  padding: 12px 16px; border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-md); background: rgba(239,68,68,0.1);
  color: var(--danger); font-size: 14px; cursor: pointer;
  transition: all var(--transition);
}
.btn-danger-sm:hover { background: rgba(239,68,68,0.2); }

/* ===== 角色卡列表弹窗 ===== */
.char-list-content { padding: 12px 16px; }
.char-list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--bg-card); border-radius: var(--radius-md);
  border: 1px solid var(--border); margin-bottom: 8px;
  cursor: pointer; transition: all var(--transition);
}
.char-list-item:hover { border-color: rgba(139,92,246,0.3); background: rgba(139,92,246,0.05); }
.char-list-item-avatar {
  width: 48px; height: 48px; border-radius: var(--radius-sm);
  overflow: hidden; flex-shrink: 0; background: var(--bg-input);
  display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.char-list-item-avatar img { width: 100%; height: 100%; object-fit: cover; }
.char-list-item-info { flex: 1; min-width: 0; }
.char-list-item-name { font-size: 15px; font-weight: 500; }
.char-list-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.char-list-item-badge {
  font-size: 10px; padding: 2px 8px; border-radius: 10px;
  background: rgba(139,92,246,0.2); color: var(--accent);
}
.char-list-item-badge.draft { background: rgba(245,158,11,0.2); color: #f59e0b; }
.char-list-item-actions { display: flex; gap: 4px; }
.char-list-item-actions button {
  width: 32px; height: 32px; border: none; border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.05); color: var(--text-muted);
  font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.char-list-item-actions button:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
.char-list-item-actions button.delete-btn:hover { color: var(--danger); }
