/* ==========================================
   ChatRPG — Poe Style Light + Cyber Purple + Neon Dark
   ========================================== */

/* ---------- 浅色（默认）— Poe 风格 ---------- */
:root {
    --bg-base: #f5f5f5;
    --bg-surface: #ffffff;
    --bg-elevated: #f0f0f0;
    --bg-hover: #e8e8e8;

    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #999;

    --neon-cyan: #6c5ce7;
    --neon-magenta: #e84393;
    --neon-purple: #a855f7;
    --neon-blue: #4f46e5;
    --neon-green: #00b894;

    --accent-primary: #6c5ce7;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, #6c5ce7, #a855f7);

    --border-color: rgba(0,0,0,0.08);
    --border-hover: rgba(0,0,0,0.16);
    --card-bg: #ffffff;
    --card-bg-hover: #fafafa;

    --glow-cyan: 0 0 16px rgba(108,92,231,0.12);
    --glow-magenta: 0 0 16px rgba(232,67,147,0.12);
    --glow-purple: 0 0 16px rgba(168,85,247,0.12);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

    --color-action: #6b7280;
    --color-dialog: #1a1a2e;
    --color-thought: #9ca3af;
    --color-narration: #4b5563;

    --name-user-color: #6c5ce7;
    --name-assistant-color: #e84393;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-bubble: 18px;

    --scrollbar-thumb: rgba(0,0,0,0.12);
    --scrollbar-hover: rgba(0,0,0,0.22);

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;

    --code-bg: #f0f1f5;
    --code-inline-bg: rgba(108,92,231,0.07);
    --code-inline-color: #5a4bd0;
    --msg-hover-bg: rgba(0,0,0,0.02);
    --quote-bg: rgba(108,92,231,0.05);
    --tag-cyan-bg: rgba(108,92,231,0.08);
    --tag-cyan-border: rgba(108,92,231,0.18);
    --tag-magenta-bg: rgba(232,67,147,0.08);
    --tag-magenta-border: rgba(232,67,147,0.18);
    --tag-purple-bg: rgba(168,85,247,0.08);
    --tag-purple-border: rgba(168,85,247,0.18);
    --tag-blue-bg: rgba(79,70,229,0.08);
    --tag-blue-border: rgba(79,70,229,0.18);
    --tag-green-bg: rgba(0,184,148,0.08);
    --tag-green-border: rgba(0,184,148,0.18);

    /* 气泡颜色 */
    --bubble-ai-bg: #ffffff;
    --bubble-ai-border: rgba(0,0,0,0.06);
    --bubble-user-bg: #6c5ce7;
    --bubble-user-text: #ffffff;
}

/* ---------- 赛博紫 ---------- */
[data-theme="cyber-purple"] {
    --bg-base: #191926;
    --bg-surface: #1e1e2e;
    --bg-elevated: #232136;
    --bg-hover: #2a2a3e;

    --text-primary: #e0def4;
    --text-secondary: #a09cb8;
    --text-muted: #8a86a0;

    --neon-cyan: #c4a7e7;
    --neon-magenta: #eb6f92;
    --neon-purple: #c4a7e7;
    --neon-blue: #9ccfd8;
    --neon-green: #31748f;

    --accent-primary: #c4a7e7;
    --accent-secondary: #eb6f92;
    --accent-gradient: linear-gradient(135deg, #c4a7e7, #eb6f92);

    --border-color: rgba(196,167,231,0.1);
    --border-hover: rgba(196,167,231,0.2);
    --card-bg: rgba(196,167,231,0.04);
    --card-bg-hover: rgba(196,167,231,0.08);

    --glow-cyan: 0 0 16px rgba(196,167,231,0.15);
    --glow-magenta: 0 0 16px rgba(235,111,146,0.15);
    --glow-purple: 0 0 16px rgba(196,167,231,0.15);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);

    --color-action: #908caa;
    --color-dialog: #e0def4;
    --color-thought: #6e6a86;
    --color-narration: #c4b5d4;

    --name-user-color: #9ccfd8;
    --name-assistant-color: #eb6f92;

    --scrollbar-thumb: rgba(196,167,231,0.12);
    --scrollbar-hover: rgba(196,167,231,0.22);

    --code-bg: #1a1a2e;
    --code-inline-bg: rgba(196,167,231,0.1);
    --code-inline-color: #c4a7e7;
    --msg-hover-bg: rgba(196,167,231,0.03);
    --quote-bg: rgba(196,167,231,0.06);
    --tag-cyan-bg: rgba(156,207,216,0.1);
    --tag-cyan-border: rgba(156,207,216,0.2);
    --tag-magenta-bg: rgba(235,111,146,0.1);
    --tag-magenta-border: rgba(235,111,146,0.2);
    --tag-purple-bg: rgba(196,167,231,0.1);
    --tag-purple-border: rgba(196,167,231,0.2);
    --tag-blue-bg: rgba(156,207,216,0.1);
    --tag-blue-border: rgba(156,207,216,0.2);
    --tag-green-bg: rgba(49,116,143,0.1);
    --tag-green-border: rgba(49,116,143,0.2);

    --bubble-ai-bg: #252538;
    --bubble-ai-border: rgba(196,167,231,0.12);
    --bubble-user-bg: #c4a7e7;
    --bubble-user-text: #1e1e2e;
}

/* ---------- 霓虹暗色 ---------- */
[data-theme="neon-dark"] {
    --bg-base: #0a0a0f;
    --bg-surface: #12121a;
    --bg-elevated: #1a1a2e;
    --bg-hover: #22223a;

    --text-primary: #e0e0e8;
    --text-secondary: #a0a0b8;
    --text-muted: #7a7a90;

    --neon-cyan: #00f0ff;
    --neon-magenta: #ff2d78;
    --neon-purple: #a855f7;
    --neon-blue: #6366f1;
    --neon-green: #00ff88;

    --accent-primary: #00f0ff;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, #00f0ff, #a855f7);

    --border-color: rgba(255,255,255,0.06);
    --border-hover: rgba(255,255,255,0.12);
    --card-bg: rgba(255,255,255,0.03);
    --card-bg-hover: rgba(255,255,255,0.06);

    --glow-cyan: 0 0 20px rgba(0,240,255,0.15), 0 0 40px rgba(0,240,255,0.05);
    --glow-magenta: 0 0 20px rgba(255,45,120,0.15), 0 0 40px rgba(255,45,120,0.05);
    --glow-purple: 0 0 20px rgba(168,85,247,0.15), 0 0 40px rgba(168,85,247,0.05);
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);

    --color-action: #8888a0;
    --color-dialog: #e0e0e8;
    --color-thought: #555568;
    --color-narration: #b0b0c0;

    --name-user-color: #00f0ff;
    --name-assistant-color: #ff2d78;

    --scrollbar-thumb: rgba(255,255,255,0.08);
    --scrollbar-hover: rgba(255,255,255,0.15);

    --code-bg: #1a1a2e;
    --code-inline-bg: rgba(0,240,255,0.06);
    --code-inline-color: #00f0ff;
    --msg-hover-bg: rgba(255,255,255,0.02);
    --quote-bg: rgba(168,85,247,0.06);
    --tag-cyan-bg: rgba(0,240,255,0.08);
    --tag-cyan-border: rgba(0,240,255,0.15);
    --tag-magenta-bg: rgba(255,45,120,0.08);
    --tag-magenta-border: rgba(255,45,120,0.15);
    --tag-purple-bg: rgba(168,85,247,0.08);
    --tag-purple-border: rgba(168,85,247,0.15);
    --tag-blue-bg: rgba(99,102,241,0.08);
    --tag-blue-border: rgba(99,102,241,0.15);
    --tag-green-bg: rgba(0,255,136,0.08);
    --tag-green-border: rgba(0,255,136,0.15);

    --bubble-ai-bg: #1a1a28;
    --bubble-ai-border: rgba(255,255,255,0.06);
    --bubble-user-bg: #00f0ff;
    --bubble-user-text: #0a0a0f;
}

/* ==========================================
   Base
   ========================================== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    font-size: 15px;
    background: var(--bg-base);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    transition: background-color var(--transition-normal), color var(--transition-normal);
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* 可滚动区域恢复触摸滚动 */
.modal-body,
.modal,
.history-dropdown,
.char-dropdown,
.char-dropdown-list,
.settings-detail,
.model-profile-list,
.settings-worldbook-tab,
.settings-char-list {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

/* 消息内容允许文本选中 */
.message-content {
    -webkit-user-select: text;
    user-select: text;
}
html {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }

::selection { background: rgba(108,92,231,0.15); color: var(--text-primary); }

/* ==========================================
   SVG Icon System
   ========================================== */
.icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex-shrink: 0; }
.icon svg { width: 100%; height: 100%; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.icon-sm { width: 16px; height: 16px; }

/* ==========================================
   Page System + Page Transitions
   ========================================== */
.page {
    position: fixed; inset: 0; display: flex; flex-direction: column;
    will-change: transform, opacity;
    overflow: hidden;
}
.page.hidden { display: none !important; }

/* Forward: start → chat */
@keyframes pageSlideInRight {
    from { transform: translateX(40px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes pageSlideOutLeft {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(-40px); opacity: 0; }
}

/* Backward: chat → start */
@keyframes pageSlideInLeft {
    from { transform: translateX(-40px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes pageSlideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(40px); opacity: 0; }
}

.page-enter-forward { animation: pageSlideInRight 0.28s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.page-exit-forward { animation: pageSlideOutLeft 0.28s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.page-enter-backward { animation: pageSlideInLeft 0.28s cubic-bezier(0.4, 0, 0.2, 1) forwards; }
.page-exit-backward { animation: pageSlideOutRight 0.28s cubic-bezier(0.4, 0, 0.2, 1) forwards; }

/* ==========================================
   Page 1: Home (角色选择主页)
   ========================================== */
.home-container { flex: 1; display: flex; flex-direction: column; align-items: center; overflow-y: auto; padding: 60px 24px 32px; }
.home-header { text-align: center; margin-bottom: 48px; }

.home-logo {
    font-size: 36px;
    color: var(--accent-primary);
    text-shadow: 0 0 20px color-mix(in srgb, var(--accent-primary) 40%, transparent);
    margin-bottom: 12px; line-height: 1;
}

.home-title {
    font-size: 32px; font-weight: 700; letter-spacing: 6px; text-transform: uppercase;
    background: var(--accent-gradient);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
    margin-bottom: 12px;
}

.home-subtitle { color: var(--text-secondary); font-size: 14px; letter-spacing: 1px; }

.home-chars {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px; width: 100%; max-width: 800px; margin-bottom: 32px;
}

.char-card {
    background: var(--card-bg); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); padding: 24px 20px 20px;
    cursor: pointer; transition: all var(--transition-normal);
    position: relative; overflow: hidden; text-align: center;
    box-shadow: var(--shadow-sm);
}
.char-card:hover { border-color: var(--char-color, var(--border-hover)); background: var(--card-bg-hover); box-shadow: var(--shadow-md), 0 0 16px color-mix(in srgb, var(--char-color, var(--accent-primary)) 15%, transparent); }

.char-card-avatar {
    width: 56px; height: 56px; border-radius: 50%;
    margin: 0 auto 14px; display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}
.char-card-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.char-card-name { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text-primary); }
.char-card-desc {
    font-size: 12px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 10px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.char-card-tags { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

.tag { font-size: 10px; padding: 2px 8px; border-radius: 4px; font-weight: 600; letter-spacing: 0.3px; border: 1px solid transparent; }
.tag-cyan { background: var(--tag-cyan-bg); color: var(--neon-cyan); border-color: var(--tag-cyan-border); }
.tag-magenta { background: var(--tag-magenta-bg); color: var(--neon-magenta); border-color: var(--tag-magenta-border); }
.tag-purple { background: var(--tag-purple-bg); color: var(--neon-purple); border-color: var(--tag-purple-border); }
.tag-blue { background: var(--tag-blue-bg); color: var(--neon-blue); border-color: var(--tag-blue-border); }
.tag-green { background: var(--tag-green-bg); color: var(--neon-green); border-color: var(--tag-green-border); }

.char-card-actions { display: flex; gap: 4px; justify-content: center; margin-top: 10px; opacity: 0; transition: opacity var(--transition-fast); }
.char-card:hover .char-card-actions { opacity: 1; }
.char-card-actions .btn-icon-sm {
    width: 28px; height: 28px; border: none; background: var(--bg-elevated);
    color: var(--text-muted); cursor: pointer; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; font-size: 13px;
    transition: all var(--transition-fast);
}
.char-card-actions .btn-icon-sm:hover { background: var(--bg-hover); color: var(--text-primary); }

.home-footer { display: flex; align-items: center; gap: 16px; margin-top: 8px; }

.btn-create {
    padding: 12px 28px; border: 1px dashed var(--border-hover); background: transparent;
    color: var(--text-secondary); cursor: pointer; border-radius: var(--radius-md);
    font-size: 14px; font-family: inherit; font-weight: 500;
    transition: all var(--transition-normal); display: flex; align-items: center; gap: 8px;
}
.btn-create:hover { border-style: solid; border-color: var(--accent-primary); color: var(--accent-primary); box-shadow: var(--glow-cyan); }
.btn-create-icon { font-size: 18px; font-weight: 300; line-height: 1; }

.home-actions { display: flex; gap: 4px; }
.btn-icon-home {
    width: 36px; height: 36px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; transition: all var(--transition-fast);
}
.btn-icon-home:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* ==========================================
   Page 2: Chat
   ========================================== */
.page-chat {
    background: var(--bg-surface);
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: -1px 0 0 var(--border-color), 1px 0 0 var(--border-color), var(--shadow-lg);
}

.chat-top-bar {
    display: flex; align-items: center; gap: 12px; padding: 0 16px;
    height: 52px; border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface); flex-shrink: 0; position: relative; z-index: 10;
}

.btn-back {
    width: 36px; height: 36px; border: none; background: transparent;
    color: var(--text-secondary); cursor: pointer; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; transition: all var(--transition-fast);
}
.btn-back:hover { background: var(--bg-elevated); color: var(--text-primary); }

.chat-char-info { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }

.chat-char-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600; color: #fff; flex-shrink: 0; position: relative;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}
.chat-char-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.online-dot {
    position: absolute; bottom: -1px; right: -1px; width: 10px; height: 10px;
    border-radius: 50%; background: var(--neon-green);
    border: 2px solid var(--bg-surface);
    box-shadow: 0 0 6px color-mix(in srgb, var(--neon-green) 50%, transparent);
}

.chat-char-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-top-actions { display: flex; gap: 4px; }
.btn-icon-chat {
    width: 36px; height: 36px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; transition: all var(--transition-fast);
}
.btn-icon-chat:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* History Dropdown */
.history-dropdown {
    position: absolute; top: 52px; right: 16px; width: 300px; max-height: 400px;
    overflow-y: auto; background: var(--bg-surface);
    border: 1px solid var(--border-color); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); z-index: 20; animation: dropIn 0.15s ease;
}
@keyframes dropIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

.history-dropdown-header {
    padding: 12px 16px 8px; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}
.history-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; cursor: pointer; transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-color);
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--bg-hover); }
.history-item.active { background: color-mix(in srgb, var(--accent-primary) 8%, transparent); }
.history-item-info { flex: 1; min-width: 0; }
.history-item-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-time { font-size: 11px; color: var(--text-muted); }
.history-item-delete {
    width: 24px; height: 24px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; border-radius: 4px;
    display: flex; align-items: center; justify-content: center; font-size: 14px;
    opacity: 0; transition: all var(--transition-fast);
}
.history-item:hover .history-item-delete { opacity: 1; }
.history-item-delete:hover { color: var(--neon-magenta); background: var(--tag-magenta-bg); }
.history-empty { padding: 32px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Character Dropdown */
.char-dropdown {
    position: absolute; top: 52px; left: 16px; width: 380px; max-height: 480px;
    overflow: hidden; background: var(--bg-surface);
    border: 1px solid var(--border-color); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); z-index: 20; animation: dropIn 0.15s ease;
    display: flex; flex-direction: column;
}

.char-dropdown-search {
    padding: 12px 14px 8px; flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}
.char-dropdown-search input {
    width: 100%; padding: 8px 12px; border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); background: var(--bg-elevated);
    color: var(--text-primary); font-size: 13px; font-family: inherit; outline: none;
    transition: border-color var(--transition-fast);
}
.char-dropdown-search input::placeholder { color: var(--text-muted); }
.char-dropdown-search input:focus { border-color: var(--accent-primary); box-shadow: var(--glow-cyan); }

.char-dropdown-list {
    overflow-y: auto; flex: 1; padding: 6px 8px;
}

.char-dropdown-empty {
    padding: 28px 16px; text-align: center; color: var(--text-muted); font-size: 13px;
}

.char-card-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 12px; cursor: pointer; border-radius: var(--radius-sm);
    transition: all var(--transition-fast); position: relative;
    border: 1px solid transparent;
}
.char-card-item:hover {
    background: var(--card-bg-hover); border-color: var(--border-color);
    transform: translateY(-1px); box-shadow: var(--shadow-sm);
}
.char-card-item.active {
    background: color-mix(in srgb, var(--accent-primary) 6%, transparent);
    border-color: color-mix(in srgb, var(--accent-primary) 20%, transparent);
}

.char-card-item-avatar {
    width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 700; color: #fff;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    box-shadow: 0 0 8px color-mix(in srgb, var(--accent-primary) 15%, transparent);
    transition: box-shadow var(--transition-fast);
}
.char-card-item-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.char-card-item:hover .char-card-item-avatar {
    box-shadow: 0 0 16px color-mix(in srgb, var(--accent-primary) 25%, transparent);
}

.char-card-item-info { flex: 1; min-width: 0; }
.char-card-item-name {
    font-size: 14px; font-weight: 600; color: var(--text-primary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 2px;
}
.char-card-item-desc {
    font-size: 11px; color: var(--text-muted); line-height: 1.4;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 4px;
}
.char-card-item-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.char-card-item-tags .tag { font-size: 9px; padding: 1px 6px; }

.char-card-item-actions {
    display: flex; align-items: center; gap: 4px; flex-shrink: 0;
}
.char-card-item-active {
    font-size: 10px; font-weight: 600; color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 10%, transparent);
    padding: 2px 8px; border-radius: 4px; letter-spacing: 0.3px;
}
.char-card-item-actions .btn-icon-sm {
    width: 28px; height: 28px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; font-size: 13px;
    opacity: 0; transition: all var(--transition-fast); flex-shrink: 0;
}
.char-card-item:hover .btn-icon-sm { opacity: 1; }
.char-card-item-actions .btn-icon-sm:hover { background: var(--bg-hover); color: var(--text-primary); }

.char-dropdown-create {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 12px; cursor: pointer; border-top: 1px solid var(--border-color);
    color: var(--text-muted); font-size: 13px; font-weight: 500;
    transition: all var(--transition-fast); flex-shrink: 0;
}
.char-dropdown-create:hover { background: var(--bg-elevated); color: var(--accent-primary); }
.char-dropdown-create-icon {
    width: 24px; height: 24px; border: 1px dashed var(--border-hover);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 300; transition: all var(--transition-fast);
}
.char-dropdown-create:hover .char-dropdown-create-icon {
    border-color: var(--accent-primary); color: var(--accent-primary);
    border-style: solid;
}

/* Clickable char info area */
.chat-char-info { cursor: pointer; border-radius: var(--radius-sm); padding: 2px 6px; margin-left: -6px; transition: background var(--transition-fast); }
.chat-char-info:hover { background: var(--bg-elevated); }

/* Back to start page */
#btn-back { display: flex; }

/* ==========================================
   Start Page (起始页 — 极简居中)
   ========================================== */
.page-start {
    background: var(--bg-surface);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    max-width: 760px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    box-shadow: -1px 0 0 var(--border-color), 1px 0 0 var(--border-color), var(--shadow-lg);
}

.start-container {
    max-width: none;
    margin: 0 auto;
    padding: 0 32px 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100%;
}

/* 右上角工具栏 */
.start-toolbar {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 16px 0 0;
    flex-shrink: 0;
}

/* 品牌区 — 垂直居中 */
.start-header {
    text-align: center;
    padding: 0;
    margin-top: auto;
    margin-bottom: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.start-logo {
    font-size: 48px;
    margin-bottom: 10px;
    line-height: 1;
    text-shadow: 0 0 30px color-mix(in srgb, var(--accent-primary) 30%, transparent);
}

.start-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 6px;
    text-transform: uppercase;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.start-greeting {
    color: var(--text-secondary);
    font-size: 15px;
}

/* 最近对话提示（一行） */
.start-last-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    margin-bottom: 24px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    max-width: 100%;
    font-size: 13px;
    color: var(--text-secondary);
}
.start-last-chat:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.start-last-chat-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}
.start-last-chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}
.start-last-chat-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.start-last-chat-time {
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 12px;
}

/* 角色横向滚动条 */
.start-chars-scroll {
    display: flex;
    gap: 20px;
    overflow-x: auto;
    padding: 16px 8px 24px;
    width: 100%;
    flex-shrink: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x;
    scrollbar-width: none;
}
.start-chars-scroll::-webkit-scrollbar { display: none; }

.start-char-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    cursor: pointer;
    transition: all var(--transition-normal);
    padding: 4px;
}

.start-char-item:hover {
    transform: translateY(-4px);
}
.start-char-item:hover .start-char-avatar {
    transform: scale(1.12);
    box-shadow: 0 0 24px color-mix(in srgb, var(--accent-primary) 30%, transparent),
                0 0 48px color-mix(in srgb, var(--accent-primary) 10%, transparent);
}
.start-char-item:active .start-char-avatar {
    transform: scale(0.95);
    transition-duration: 0.1s;
}

.start-char-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    box-shadow: 0 0 12px color-mix(in srgb, var(--accent-primary) 10%, transparent);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}
.start-char-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.start-char-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 72px;
    transition: color var(--transition-fast);
}
.start-char-item:hover .start-char-name {
    color: var(--text-primary);
}

/* 创建角色按钮 */
.start-char-create .start-char-avatar {
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 26px;
    font-weight: 300;
    box-shadow: none;
    border: 2px dashed var(--border-color);
    transition: all var(--transition-normal);
}
.start-char-create:hover .start-char-avatar {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: var(--glow-cyan);
}

/* Start page mobile */
@media (max-width: 768px) {
    .start-container { padding: 0 16px 24px; }
    .start-toolbar { padding: 12px 0 0; }
    .start-header { min-height: 160px; }
    .start-logo { font-size: 36px; }
    .start-title { font-size: 24px; letter-spacing: 3px; }
    .start-char-avatar { width: 52px; height: 52px; font-size: 18px; }
    .start-char-name { font-size: 11px; max-width: 60px; }
    .start-chars-scroll { gap: 16px; padding: 12px 4px 20px; }
}

/* ==========================================
   Chat Messages — Poe 气泡风格
   ========================================== */
.chat-container {
    flex: 1; overflow-y: auto; padding: 16px 0; scroll-behavior: smooth;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

/* ---- AI 消息（左侧气泡） ---- */
.message {
    display: flex; gap: 10px; padding: 6px 24px; position: relative;
    min-height: 24px; animation: msgIn 0.2s ease;
}
.message:hover { background: var(--msg-hover-bg); }
.message { position: relative; }
.message:not(.compact) { margin-top: 16px; }
.message.compact { margin-top: 2px; }

.message-body { flex: 1; min-width: 0; }
.message-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.message.compact .message-header { display: none; }
.message-name { font-weight: 600; font-size: 13px; cursor: pointer; }
.message-name:hover { text-decoration: underline; }
.message-name-user { color: var(--name-user-color); }
.message-assistant .message-name { color: var(--name-assistant-color); }
.message-time { font-size: 11px; color: var(--text-muted); }

/* AI 消息气泡 */
.message-assistant .message-content {
    background: var(--bubble-ai-bg); border: 1px solid var(--bubble-ai-border);
    border-radius: var(--radius-bubble); border-top-left-radius: 4px;
    padding: 10px 16px; line-height: 1.7; font-size: 14px;
    word-break: break-word; color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    display: inline-block; max-width: 100%;
}

/* 用户消息气泡（右侧，带颜色） */
.message-user {
    flex-direction: row-reverse;
}
.message-user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-user .message-header { flex-direction: row-reverse; }
.message-user .message-content {
    background: var(--bubble-user-bg); color: var(--bubble-user-text);
    border-radius: var(--radius-bubble); border-top-right-radius: 4px;
    padding: 10px 16px; line-height: 1.7; font-size: 14px;
    word-break: break-word; display: inline-block; max-width: 85%;
    box-shadow: var(--shadow-sm);
}

/* 气泡内 markdown 不需要额外背景 */
.message-user .message-content p,
.message-user .message-content code:not(pre code),
.message-user .message-content blockquote { color: inherit; }

.message-actions {
    display: flex; gap: 2px; position: absolute; right: 24px; top: -10px;
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: 6px; box-shadow: var(--shadow-md);
    opacity: 0; pointer-events: none; transition: opacity var(--transition-fast); z-index: 5;
    padding: 2px;
}
.message:hover .message-actions { opacity: 1; pointer-events: auto; }
.message-user .message-actions { right: auto; left: 24px; }
.message-actions.is-busy .btn-action:not(.is-loading) { opacity: 0.45; cursor: wait; }

.btn-action {
    min-height: 28px; padding: 5px 7px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; font-size: 12px;
    transition: all var(--transition-fast); display: flex; align-items: center; justify-content: center; gap: 4px;
    border-radius: 4px; font-family: inherit; white-space: nowrap;
}
.btn-action:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-action:disabled { cursor: not-allowed; }
.btn-action.is-loading { color: var(--accent-primary); background: color-mix(in srgb, var(--accent-primary) 10%, transparent); cursor: wait; }
.btn-action-label { font-size: 12px; line-height: 1; }

.message-feedback {
    margin-top: 8px;
    padding: 6px 9px;
    border: 1px solid var(--tag-cyan-border);
    border-radius: var(--radius-sm);
    background: var(--tag-cyan-bg);
    color: var(--neon-cyan);
    font-size: 12px;
    line-height: 1.4;
    display: inline-block;
}
.message-feedback-success {
    border-color: var(--tag-green-border);
    background: var(--tag-green-bg);
    color: var(--neon-green);
}
.message-feedback-error {
    border-color: var(--tag-magenta-border);
    background: var(--tag-magenta-bg);
    color: var(--neon-magenta);
}

/* RPG Format */
.rpg-action { font-style: italic; color: var(--color-action); background: var(--bg-elevated); padding: 1px 6px; border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.rpg-dialog { color: var(--color-dialog); font-weight: 500; border-left: 2px solid var(--accent-primary); padding-left: 6px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.rpg-thought {
    color: var(--color-thought);
    font-style: italic;
    display: inline-block;
    background: color-mix(in srgb, var(--neon-purple) 14%, transparent);
    border: 1px dashed color-mix(in srgb, var(--neon-purple) 30%, transparent);
    border-radius: 6px;
    padding: 2px 10px;
    font-size: 0.92em;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

/* ==========================================
   Markdown Styles
   ========================================== */
.message-content p { margin: 0 0 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3, .message-content h4 { font-weight: 600; margin: 14px 0 6px; line-height: 1.3; }
.message-content h1 { font-size: 1.3em; }
.message-content h2 { font-size: 1.2em; }
.message-content h3 { font-size: 1.1em; }
.message-content h1:first-child, .message-content h2:first-child, .message-content h3:first-child { margin-top: 0; }

.message-content a { color: var(--accent-primary); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color var(--transition-fast); }
.message-content a:hover { border-bottom-color: var(--accent-primary); }

.message-content ul, .message-content ol { margin: 6px 0; padding-left: 22px; }
.message-content li { margin-bottom: 2px; line-height: 1.5; }

.message-content blockquote {
    border-left: 2px solid var(--accent-secondary); margin: 8px 0; padding: 4px 12px;
    color: var(--text-secondary); background: var(--quote-bg); border-radius: 0 4px 4px 0;
}
.message-content blockquote p { margin-bottom: 4px; }
.message-content blockquote p:last-child { margin-bottom: 0; }
.message-content hr { border: none; height: 1px; background: var(--border-color); margin: 10px 0; }

.message-content code:not(pre code) {
    background: var(--code-inline-bg); padding: 1px 5px; border-radius: 3px;
    font-family: 'SF Mono', 'Consolas', 'Fira Code', monospace; font-size: 0.88em; color: var(--code-inline-color);
}

.message-content pre {
    position: relative; margin: 6px 0; border-radius: 6px; overflow: hidden;
    background: var(--code-bg); border: 1px solid var(--border-color);
}
.message-content pre code {
    display: block; padding: 12px 14px; overflow-x: auto;
    font-family: 'SF Mono', 'Consolas', 'Fira Code', monospace; font-size: 13px; line-height: 1.5; background: transparent;
}
.message-content pre code.hljs { background: transparent; }
.code-lang { position: absolute; top: 6px; left: 10px; font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; user-select: none; }
.code-copy-btn {
    position: absolute; top: 6px; right: 6px; padding: 4px 8px; border: none;
    background: var(--bg-hover); color: var(--text-muted); cursor: pointer; border-radius: 4px;
    font-size: 11px; font-family: inherit; transition: all var(--transition-fast); opacity: 0;
}
.message-content pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

.message-content table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: 13px; }
.message-content th, .message-content td { border: 1px solid var(--border-color); padding: 6px 10px; text-align: left; }
.message-content th { background: var(--bg-elevated); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; }
.message-content tr:nth-child(even) { background: var(--msg-hover-bg); }
.message-content img { max-width: 100%; border-radius: 6px; margin: 4px 0; }
.message-content strong { font-weight: 600; }

.cursor-blink { animation: blink 1s step-end infinite; color: var(--accent-primary); }
@keyframes blink { 50% { opacity: 0; } }

.typing-indicator { display: flex; gap: 4px; padding: 4px 0; align-items: center; }
.typing-indicator .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); opacity: 0.4; animation: typingBounce 1.4s infinite ease-in-out; }
.typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

.time-separator { display: flex; align-items: center; justify-content: center; margin: 20px 24px 8px; position: relative; }
.time-separator::before { content: ''; position: absolute; left: 0; right: 0; height: 1px; background: var(--border-color); }
.time-separator span { background: var(--bg-surface); padding: 0 12px; font-size: 11px; color: var(--text-muted); position: relative; z-index: 1; font-weight: 600; letter-spacing: 0.3px; }

/* ==========================================
   Input Area
   ========================================== */
.input-area {
    padding: 12px 16px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}

.reply-suggestions {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 8px 0 4px;
    animation: slideUp 0.2s ease;
    max-height: 142px;
    overflow-y: auto;
    position: relative;
}
.reply-suggestions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2px 4px;
}
.reply-suggestions-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}
.reply-suggestions-close {
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}
.reply-suggestions-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.reply-suggestion-btn {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: inherit;
    transition: all var(--transition-fast);
    line-height: 1.45;
    text-align: left;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    overflow-wrap: anywhere;
}
.reply-suggestion-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); box-shadow: var(--glow-cyan); }
.reply-suggestion-index {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg-elevated);
    color: var(--accent-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    margin-top: 1px;
}
.reply-suggestion-text {
    min-width: 0;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.reply-suggestion-empty {
    color: var(--text-muted);
    font-size: 12px;
    padding: 7px 10px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
}

.input-wrapper {
    display: flex; align-items: center; gap: 0;
    background: var(--bg-surface); border-radius: var(--radius-md);
    padding: 4px 6px 4px 16px; border: 1px solid var(--border-color); transition: all var(--transition-fast);
}
.input-wrapper:focus-within { border-color: var(--accent-primary); box-shadow: var(--glow-cyan); }
.input-wrapper textarea {
    flex: 1; border: none; background: transparent; color: var(--text-primary);
    font-size: 14px; font-family: inherit; resize: none; outline: none;
    max-height: 120px; min-height: 24px; line-height: 1.5; padding: 6px 0;
}
.input-wrapper textarea::placeholder { color: var(--text-muted); }

.btn-suggest {
    width: 32px; height: 32px; border: none; background: transparent;
    color: var(--text-muted); cursor: pointer; border-radius: 6px;
    display: flex; align-items: center; justify-content: center; transition: all var(--transition-fast); flex-shrink: 0;
}
.btn-suggest:hover { color: var(--accent-primary); }
.btn-suggest.loading { color: var(--accent-primary); animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.btn-send {
    width: 38px; height: 38px; min-width: 44px; min-height: 44px;
    border: none; background: var(--accent-gradient);
    color: #fff; cursor: pointer; border-radius: 10px; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition-fast); flex-shrink: 0;
    box-shadow: 0 0 10px color-mix(in srgb, var(--accent-primary) 20%, transparent);
}
.btn-send:hover { box-shadow: var(--glow-cyan); }
.btn-send:active { opacity: 0.85; }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; box-shadow: none; }

.btn-stop { background: linear-gradient(135deg, var(--neon-magenta), #ff6b6b) !important; box-shadow: 0 0 10px color-mix(in srgb, var(--neon-magenta) 20%, transparent) !important; }
.btn-stop:hover { box-shadow: var(--glow-magenta) !important; }

/* ==========================================
   Status Bar
   ========================================== */
.status-bar {
    display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 16px;
    border-top: 1px solid var(--border-color); background: var(--bg-surface); font-size: 11px; color: var(--text-muted);
}
.status-bar span:not(:last-child)::after { content: ' · '; margin-left: 8px; }

/* ==========================================
   Modal
   ========================================== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4);
    display: none; align-items: center; justify-content: center; z-index: 1000;
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-surface); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); width: 90%; max-width: 520px; max-height: 85vh;
    overflow-y: auto; box-shadow: var(--shadow-lg); animation: modalIn 0.2s ease;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between; padding: 16px 20px;
    border-bottom: 1px solid var(--border-color); position: sticky; top: 0;
    background: var(--bg-surface); z-index: 1; border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px; }

.settings-header {
    align-items: flex-start;
}
.settings-current {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.4;
}
.settings-version {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-elevated);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    vertical-align: middle;
    margin-left: 8px;
    letter-spacing: 0.3px;
}
.modal.modal-settings,
.modal:has(.settings-modal-body) {
    width: min(960px, 94vw);
    max-width: 960px;
}
.settings-modal-body {
    padding: 0;
    display: flex;
    flex-direction: column;
}
/* Settings Tabs */
.settings-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0;
    flex-shrink: 0;
}
.settings-tab {
    flex: 1;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
    text-align: center;
}
.settings-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}
.settings-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}
/* Characters Tab */
.settings-char-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px;
}
.settings-char-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    transition: all var(--transition-fast);
}
.settings-char-item:hover { border-color: var(--border-hover); }
.settings-char-item.active { border-color: var(--accent-primary); }
.settings-char-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 16px; font-weight: 700; color: #fff; overflow: hidden;
}
.settings-char-avatar img { width: 100%; height: 100%; object-fit: cover; }
.settings-char-info { flex: 1; min-width: 0; }
.settings-char-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.settings-char-desc { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-char-tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.settings-char-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.settings-char-active { font-size: 11px; color: var(--accent-primary); padding: 2px 6px; border: 1px solid var(--accent-primary); border-radius: var(--radius-sm); }
.settings-char-actions .btn-secondary { padding: 6px 10px; font-size: 12px; }
.settings-char-footer { padding: 0 16px 16px; display: flex; gap: 8px; }
/* Worldbook Tab inside Settings */
.settings-worldbook-tab { padding: 16px; }
.memory-settings-detail { width: 100%; padding: 20px; }
.memory-settings-detail textarea { width: 100%; }
.memory-meta { font-size: 12px; color: var(--text-muted); margin: -2px 0 10px; }
.memory-status {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 12px;
    font-size: 12px;
    color: var(--text-secondary);
}
.memory-status span,
.memory-status strong {
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    font-weight: 500;
}
.memory-status strong {
    color: var(--accent-primary);
    border-color: color-mix(in srgb, var(--accent-primary) 42%, var(--border-color));
}

.settings-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 560px;
}
.model-profile-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-elevated);
}
.model-profile-list {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
}
.model-profile-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-fast);
}
.model-profile-item:hover {
    border-color: var(--border-hover);
    background: var(--card-bg-hover);
}
.model-profile-item.active {
    border-color: var(--accent-primary);
    box-shadow: var(--glow-cyan);
}
.model-profile-name {
    font-size: 14px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.model-profile-meta,
.model-profile-provider {
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.model-profile-provider {
    color: var(--accent-primary);
}
.model-profile-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.model-profile-actions .btn-secondary:last-child {
    grid-column: 1 / -1;
}
.settings-detail {
    min-width: 0;
    max-height: calc(85vh - 57px);
    overflow-y: auto;
    padding: 20px;
}
.test-connection-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}
.model-test-result {
    min-height: 36px;
    padding: 9px 12px;
    border: 1px solid var(--border-color);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.model-test-result.loading {
    color: var(--accent-primary);
}
.model-test-result.success {
    border-color: var(--tag-green-border);
    background: var(--tag-green-bg);
    color: var(--neon-green);
}
.model-test-result.error {
    border-color: var(--tag-magenta-border);
    background: var(--tag-magenta-bg);
    color: var(--neon-magenta);
}
.settings-save-actions {
    position: sticky;
    bottom: -20px;
    padding-top: 16px;
    padding-bottom: 2px;
    background: linear-gradient(to bottom, transparent, var(--bg-surface) 24%);
}
.data-actions {
    justify-content: flex-start;
}

.form-section { margin-bottom: 24px; }
.form-section h3 { font-size: 11px; font-weight: 700; margin-bottom: 10px; color: var(--accent-primary); text-transform: uppercase; letter-spacing: 1px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.3px; }

.form-group input[type="text"],
.form-group input[type="url"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select,
.form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border-color);
    background: var(--bg-elevated); color: var(--text-primary);
    border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; outline: none; transition: all var(--transition-fast);
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus { border-color: var(--accent-primary); box-shadow: var(--glow-cyan); }
.form-group textarea { resize: vertical; min-height: 60px; }
.checkbox-row { display: flex !important; align-items: center; gap: 8px; min-height: 40px; text-transform: none !important; letter-spacing: 0 !important; }
.checkbox-row input { width: auto; }

.form-group input[type="range"] {
    width: 100%; height: 4px; -webkit-appearance: none; appearance: none;
    background: var(--bg-hover); border-radius: 2px; outline: none; cursor: pointer; margin-top: 4px;
}
.form-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
    background: var(--accent-primary); cursor: pointer; border: 2px solid var(--bg-surface);
    box-shadow: 0 0 6px color-mix(in srgb, var(--accent-primary) 30%, transparent);
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Avatar Upload */
.avatar-upload-row { display: flex; gap: 20px; align-items: flex-start; margin-bottom: 18px; }
.avatar-upload-area {
    width: 88px; height: 88px; border-radius: 50%; border: 2px dashed var(--border-color);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; position: relative; overflow: hidden; flex-shrink: 0;
    background: var(--bg-elevated); transition: all var(--transition-fast);
}
.avatar-upload-area:hover { border-color: var(--accent-primary); box-shadow: var(--glow-cyan); }
.avatar-upload-area img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-upload-placeholder {
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    color: var(--text-muted); font-size: 10px; text-align: center; line-height: 1.2;
}
.avatar-upload-placeholder .icon { width: 22px; height: 22px; opacity: 0.5; }
.avatar-upload-info { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.avatar-upload-info .form-group { margin-bottom: 0; }

/* Form Section Collapsible */
.form-section-toggle {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; padding: 8px 0; user-select: none;
}
.form-section-toggle h3 { margin-bottom: 0; }
.form-section-arrow {
    font-size: 12px; color: var(--text-muted); transition: transform var(--transition-fast);
}
.form-section.collapsed .form-section-content { display: none; }
.form-section.collapsed .form-section-arrow { transform: rotate(-90deg); }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }

.btn-primary {
    padding: 10px 20px; border: none; background: var(--accent-gradient);
    color: #fff; cursor: pointer; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; font-family: inherit; transition: all var(--transition-fast);
    box-shadow: 0 0 10px color-mix(in srgb, var(--accent-primary) 15%, transparent);
}
.btn-primary:hover { box-shadow: var(--glow-cyan); }

.btn-secondary {
    padding: 10px 20px; border: 1px solid var(--border-color); background: transparent;
    color: var(--text-secondary); cursor: pointer; border-radius: var(--radius-sm);
    font-size: 13px; font-family: inherit; transition: all var(--transition-fast);
}
.btn-secondary:hover { border-color: var(--border-hover); background: var(--bg-elevated); }

/* Worldbook */
.worldbook-toolbar { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.worldbook-toolbar .form-hint { margin: 0; flex: 1; }
.worldbook-list { display: flex; flex-direction: column; gap: 10px; }
.worldbook-empty {
    padding: 18px; border: 1px dashed var(--border-color); border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 13px; line-height: 1.6; background: var(--bg-elevated);
}
.worldbook-item {
    display: flex; gap: 12px; align-items: flex-start; justify-content: space-between;
    padding: 12px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    background: var(--bg-elevated);
}
.worldbook-item.disabled { opacity: 0.58; }
.worldbook-item-main { min-width: 0; flex: 1; }
.worldbook-title-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.worldbook-title-row strong { font-size: 14px; color: var(--text-primary); }
.worldbook-mode {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px;
    border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    font-size: 12px; color: var(--text-secondary); white-space: nowrap;
}
.worldbook-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; color: var(--text-muted); font-size: 12px; }
.worldbook-item p { margin: 0; color: var(--text-secondary); font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.worldbook-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.worldbook-actions .btn-secondary { padding: 7px 10px; }

.toggle-wrapper { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.toggle-label { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.toggle-switch { position: relative; width: 44px; height: 24px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track { position: absolute; inset: 0; background: var(--bg-hover); border-radius: 12px; transition: background var(--transition-fast); }
.toggle-switch input:checked + .toggle-track { background: var(--accent-primary); box-shadow: 0 0 8px color-mix(in srgb, var(--accent-primary) 30%, transparent); }
.toggle-track::after {
    content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
    background: #fff; top: 3px; left: 3px; transition: transform var(--transition-fast); box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-track::after { transform: translateX(20px); }

/* ==========================================
   Toast Notifications
   ========================================== */
.toast-container {
    position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%);
    z-index: 2000; display: flex; flex-direction: column; align-items: center; gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 10px 20px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500; font-family: inherit;
    animation: toastIn 0.25s ease, toastOut 0.3s ease 1.7s forwards;
    pointer-events: auto; white-space: nowrap;
    box-shadow: var(--shadow-md);
}
.toast-success { background: var(--tag-green-bg); color: var(--neon-green); border: 1px solid var(--tag-green-border); }
.toast-error { background: var(--tag-magenta-bg); color: var(--neon-magenta); border: 1px solid var(--tag-magenta-border); }
.toast-info { background: var(--tag-cyan-bg); color: var(--neon-cyan); border: 1px solid var(--tag-cyan-border); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-8px); } }

/* ==========================================
   Animations
   ========================================== */
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: scale(1); } }

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 768px) {
    .page-chat { max-width: none; box-shadow: none; }
    .page-start { max-width: none; box-shadow: none; }
    .home-container { padding: 40px 16px 24px; }
    .home-chars { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
    .home-title { font-size: 26px; letter-spacing: 4px; }

    /* ---- 移动端色块标签布局 ---- */
    .message { padding: 6px 12px 6px 24px; gap: 0; position: relative; }
    .message:not(.compact) { margin-top: 8px; }
    .message.compact { margin-top: 0; }

    /* AI 消息：无气泡，左对齐，色点标识 */
    .message-assistant { background: transparent; }
    .message-assistant::before {
        content: '';
        position: absolute;
        left: 10px;
        top: 12px;
        width: 8px; height: 8px;
        border-radius: 50%;
        background: var(--name-assistant-color);
        box-shadow: 0 0 6px color-mix(in srgb, var(--name-assistant-color) 50%, transparent);
    }
    .message-assistant.compact::before { top: 8px; }
    .message-assistant .message-content {
        background: none; border: none; border-radius: 0;
        padding: 0; box-shadow: none;
        font-size: 16px; line-height: 1.7;
        display: block; max-width: 100%;
    }
    .message-assistant .message-header { margin-bottom: 2px; }

    /* 用户消息：无气泡，右对齐，色点标识 */
    .message-user {
        flex-direction: row;
        background: transparent;
        padding: 6px 24px 6px 12px;
    }
    .message-user::after {
        content: '';
        position: absolute;
        right: 10px;
        top: 12px;
        width: 8px; height: 8px;
        border-radius: 50%;
        background: var(--name-user-color);
        box-shadow: 0 0 6px color-mix(in srgb, var(--name-user-color) 50%, transparent);
    }
    .message-user.compact::after { top: 8px; }
    .message-user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
    .message-user .message-header { flex-direction: row-reverse; }
    .message-user .message-content {
        background: none; color: var(--text-primary);
        border-radius: 0; padding: 0;
        font-size: 16px; line-height: 1.7;
        display: block; max-width: 100%;
        box-shadow: none; text-align: right;
    }
    /* 用户消息内 markdown 颜色恢复默认 */
    .message-user .message-content p,
    .message-user .message-content code:not(pre code),
    .message-user .message-content blockquote { color: revert; }

    /* 发言者切换时加大间距 */
    .message-assistant + .message-user,
    .message-user + .message-assistant {
        margin-top: 12px;
    }

    /* 消息操作按钮移动端常显 */
    .message-actions { opacity: 1; pointer-events: auto; position: static; background: none; border: none; box-shadow: none; margin-top: 4px; flex-wrap: wrap; max-width: 100%; }
    .btn-action { padding: 5px 6px; }
    .btn-action-label { display: none; }

    /* 输入框防 iOS 缩放 */
    .input-wrapper textarea { font-size: 16px; }
    .input-area { padding: 10px 8px 12px; }
    .reply-suggestions { gap: 6px; max-height: 132px; padding-top: 6px; }
    .reply-suggestion-btn { min-height: 40px; padding: 8px 10px; gap: 8px; font-size: 13px; }
    .reply-suggestion-index { width: 18px; height: 18px; font-size: 10px; }
    .chat-top-bar { padding: 0 10px; }
    .history-dropdown { right: 8px; width: calc(100vw - 16px); }
    .char-dropdown { left: 8px; width: calc(100vw - 16px); }
    .modal.modal-settings, .modal:has(.settings-modal-body) { width: 96%; max-width: 96%; }
    .settings-layout { grid-template-columns: 1fr; min-height: 0; }
    .model-profile-sidebar { border-right: none; border-bottom: 1px solid var(--border-color); }
    .model-profile-list { max-height: 220px; }
    .settings-detail { max-height: none; }
    .test-connection-row { grid-template-columns: 1fr; }
    .status-bar { display: none; }
}
@media (max-width: 480px) {
    .message { padding: 6px 8px 6px 20px; }
    .message-user { padding: 6px 20px 6px 8px; }
    .modal { width: 96%; max-height: 90vh; border-radius: 12px; }
    .home-chars { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1200px) {
    .page-chat { max-width: 780px; }
    .page-start { max-width: 780px; }
    .home-chars { max-width: 900px; }
}
