/* ============================================================
   zhouAI · 黑白主题
   ------------------------------------------------------------
   · 只有黑与白：没有任何彩色，层级全部靠 明度 / 边框 / 字重 表达
   · 默认跟随系统（prefers-color-scheme），可在「设置 → 选择主题」里
     强制指定 浅色 / 深色
   · body 上的 .light-mode / .dark-mode 由 JS 控制；两者都没有时跟随系统
   ============================================================ */

/* ---------- 1. 设计变量 ---------- */

:root {
    /* 浅色（默认） */
    --bg:            #ffffff;
    --bg-soft:       #fafafa;
    --surface:       #f5f5f5;
    --surface-2:     #ededed;
    --border:        #e4e4e4;
    --border-strong: #d0d0d0;

    --text:          #101010;
    --text-2:        #565656;
    --text-3:        #6b6b6b;

    --invert-bg:     #101010;
    --invert-text:   #ffffff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .08);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .16);

    --radius:    14px;
    --radius-lg: 20px;
    --radius-pill: 999px;

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
            "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

    --header-h: 56px;
    --composer-h: 104px;

    /* 侧边栏展开时，主内容让出的宽度（仅桌面端生效，见文件末尾） */
    --sidebar-w: 0px;

    --speed: .18s;
}

/* 深色：显式选择 */
body.dark-mode {
    --bg:            #0a0a0a;
    --bg-soft:       #101010;
    --surface:       #161616;
    --surface-2:     #1e1e1e;
    --border:        #262626;
    --border-strong: #3a3a3a;

    --text:          #f4f4f4;
    --text-2:        #a6a6a6;
    --text-3:        #8a8a8a;

    --invert-bg:     #f4f4f4;
    --invert-text:   #0a0a0a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .7);
}

/* 跟随系统：没有显式选择时才生效 */
@media (prefers-color-scheme: dark) {
    body:not(.light-mode):not(.dark-mode) {
        --bg:            #0a0a0a;
        --bg-soft:       #101010;
        --surface:       #161616;
        --surface-2:     #1e1e1e;
        --border:        #262626;
        --border-strong: #3a3a3a;

        --text:          #f4f4f4;
        --text-2:        #a6a6a6;
        --text-3:        #8a8a8a;

        --invert-bg:     #f4f4f4;
        --invert-text:   #0a0a0a;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .5);
        --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
        --shadow-lg: 0 24px 60px rgba(0, 0, 0, .7);
    }
}

/* ---------- 2. 基础 ---------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    transition: background var(--speed), color var(--speed);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid var(--bg);
    border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--text); }
img { max-width: 100%; }

/* 背景装饰：黑白主题下只留极淡的一层，不再有彩色光晕 */
.bg-flow,
.bg-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}
.bg-flow { background: var(--bg); }
.bg-glow { display: none; }

/* 布局工具类（JS 会动态加这些 class） */
.flex { display: flex; }
.justify-end { justify-content: flex-end; }
.justify-start { justify-content: flex-start; }

.msg-appear { animation: msgIn .22s ease-out; }
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- 3. 顶栏 ---------- */

header.glass,
header {
    position: fixed;
    top: 0;
    left: var(--sidebar-w);
    right: 0;
    z-index: 50;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 .9rem;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
    transition: left var(--speed) ease;
}

header .brand {
    font-weight: 650;
    font-size: 1rem;
    letter-spacing: -.01em;
    white-space: nowrap;
}

.header-left {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex: 1;
    min-width: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-shrink: 0;
}

.history-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-2);
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 1rem;
    transition: var(--speed);
}
.history-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }

.theme-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-2);
    border: 1px solid transparent;
    border-radius: 10px;
    transition: var(--speed);
}
.theme-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.theme-btn svg { width: 17px; height: 17px; }

.qianbai-display {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .18rem .55rem;
    font-size: .75rem;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    white-space: nowrap;
}
.qianbai-icon { color: var(--text-3); }
#qianbaiBalance { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.model-badge {
    display: inline-block;
    padding: .18rem .55rem;
    font-size: .72rem;
    font-weight: 500;
    color: var(--text-2);
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    white-space: nowrap;
}

#usernameDisplay {
    font-size: .8rem;
    color: var(--text-2);
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#userAvatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--invert-bg);
    color: var(--invert-text);
    font-size: .8rem;
    font-weight: 600;
    border: 1px solid var(--border);
    cursor: pointer;
}
#userAvatar img { width: 100%; height: 100%; object-fit: cover; }

#loginBtn { padding: .3rem .85rem; font-size: .8rem; }

/* ---------- 4. 侧边栏 ---------- */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: 288px;
    max-width: 84vw;
    display: flex;
    flex-direction: column;
    background: var(--bg-soft);
    border-right: 1px solid var(--border);
    transform: translateX(-102%);
    transition: transform var(--speed) ease;
    box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: none; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-2);
}

.sidebar-new-btn {
    padding: .3rem .8rem;
    font-size: .78rem;
    font-weight: 500;
    color: var(--invert-text);
    background: var(--invert-bg);
    border: 1px solid var(--invert-bg);
    border-radius: var(--radius-pill);
    transition: var(--speed);
}
.sidebar-new-btn:hover { opacity: .85; }

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: .6rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.conversation-item {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: .1rem;
    padding: .6rem .75rem;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--speed);
    min-width: 0;
}
.conversation-item:hover { background: var(--surface); border-color: var(--border); }
.conversation-item.active {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.conversation-title {
    font-size: .86rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 1.6rem;
}
.conversation-model {
    font-size: .7rem;
    color: var(--text-3);
}

.conv-menu-btn {
    position: absolute;
    top: 50%;
    right: .5rem;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-3);
    opacity: 0;
    transition: var(--speed);
}
.conversation-item:hover .conv-menu-btn { opacity: 1; }
.conv-menu-btn:hover { background: var(--surface-2); color: var(--text); }

.conv-menu,
.dropdown-menu {
    position: absolute;
    z-index: 80;
    min-width: 132px;
    padding: .3rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
}

/* 用户菜单（点头像弹出的那个）挂在顶栏右下方。
   这里必须显式写 top / right：
   菜单是被 append 进 #userSection 的，而它是 flex + align-items:center，
   绝对定位子元素若只靠"静态位置"，就会按中线对齐 —— 菜单一高就整个往上顶，
   「设置 / 上传头像」会跑到屏幕外面点不到。 .conv-menu 由 JS 设了 fixed 定位，
   不受影响。 */
.dropdown-menu {
    top: calc(var(--header-h) + .45rem);
    right: .9rem;
    left: auto;
    max-width: calc(100vw - 1.8rem);
    animation: msgIn .14s ease-out;
}

.conv-menu-item,
.dropdown-item {
    display: block;
    width: 100%;
    padding: .4rem .6rem;
    font-size: .8rem;
    text-align: left;
    color: var(--text);
    background: transparent;
    border: none;
    border-radius: 7px;
    transition: var(--speed);
}
.conv-menu-item:hover,
.dropdown-item:hover { background: var(--surface); }

.dropdown-divider {
    height: 1px;
    margin: .3rem .2rem;
    background: var(--border);
}

/* 空状态 */
.empty-hint {
    padding: 2.5rem 1rem;
    text-align: center;
    font-size: .85rem;
    color: var(--text-3);
}

/* ---------- 5. 聊天区 ---------- */

.scroll-area,
#chatContainer {
    position: fixed;
    top: var(--header-h);
    left: var(--sidebar-w);
    right: 0;
    bottom: var(--composer-h);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--bg);
    transition: left var(--speed) ease;
}

#chatMessages {
    max-width: 780px;
    margin: 0 auto;
    padding: 1.1rem 1rem 1.6rem;
    display: flex;
    flex-direction: column;
    gap: .9rem;
}

.catgirl-notice {
    align-self: center;
    padding: .35rem .8rem;
    font-size: .72rem;
    color: var(--text-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
}

/* 气泡 */
.bubble-user,
.bubble-ai {
    max-width: min(78%, 620px);
    padding: .7rem .95rem;
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    animation: msgIn .22s ease-out;
}

/* 用户：实心反色，一眼区分 */
.bubble-user {
    background: var(--invert-bg);
    color: var(--invert-text);
    border: 1px solid var(--invert-bg);
    border-bottom-right-radius: 6px;
}

/* 带图片的气泡：反色实心底会把图片框成一块黑板，改用浅底更好看 */
.bubble-user:has(img) {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    padding: .55rem .6rem .5rem;
}

/* AI：留白 + 边框，适合长时间阅读 */
.bubble-ai {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

.bubble-description {
    align-self: flex-start;
    max-width: min(78%, 620px);
    padding: .45rem .8rem;
    font-size: .75rem;
    color: var(--text-3);
    background: transparent;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-pill);
}

.bubble-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: .55rem;
    padding-top: .5rem;
    border-top: 1px solid var(--border);
}

.disclaimer {
    font-size: .68rem;
    color: var(--text-3);
}

.msg-actions {
    display: flex;
    gap: .3rem;
    margin-left: auto;
}

.action-btn {
    padding: .18rem .55rem;
    font-size: .7rem;
    color: var(--text-2);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    transition: var(--speed);
    user-select: none;
    cursor: pointer;
}
.action-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* Markdown 正文 */
.markdown > *:first-child { margin-top: 0; }
.markdown > *:last-child { margin-bottom: 0; }
.markdown p { margin: .45em 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 {
    margin: .9em 0 .4em;
    line-height: 1.35;
    font-weight: 650;
}
.markdown h1 { font-size: 1.25em; }
.markdown h2 { font-size: 1.15em; }
.markdown h3 { font-size: 1.05em; }
.markdown ul, .markdown ol { margin: .45em 0 .45em 1.3em; }
.markdown li { margin: .18em 0; }
.markdown a { text-decoration: underline; text-underline-offset: 2px; }
.markdown blockquote {
    margin: .6em 0;
    padding: .2em .9em;
    border-left: 2px solid var(--border-strong);
    color: var(--text-2);
}
.markdown code {
    font-family: var(--mono);
    font-size: .87em;
    padding: .12em .38em;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.markdown pre {
    position: relative;
    margin: .6em 0;
    padding: .8rem .9rem;
    overflow-x: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.markdown pre code {
    padding: 0;
    background: transparent;
    border: none;
    font-size: .85em;
    line-height: 1.6;
}
.markdown table {
    width: 100%;
    margin: .6em 0;
    border-collapse: collapse;
    font-size: .9em;
}
.markdown th, .markdown td {
    padding: .4rem .6rem;
    border: 1px solid var(--border);
    text-align: left;
}
.markdown th { background: var(--surface-2); font-weight: 600; }
.markdown hr { margin: .9em 0; border: none; border-top: 1px solid var(--border); }

/* 代码复制按钮 */
.code-copy {
    position: absolute;
    top: .4rem;
    right: .4rem;
    padding: .15rem .5rem;
    font-size: .68rem;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    opacity: 0;
    transition: var(--speed);
}
.markdown pre:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--text); border-color: var(--border-strong); }

.generated-image {
    display: block;
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: zoom-in;
}

.img-download-link {
    font-size: .72rem;
    color: var(--text-2);
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}
.img-download-link:hover { color: var(--text); }

/* 强调数字（浅白币余额等）：黑白主题下用字重而不是颜色来强调 */
.accent-strong {
    font-weight: 650;
    color: var(--text);
}

/* 思考中 */
.thinking-pulse {
    display: inline-block;
    animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: .25; }
}
.thinking-timer { color: var(--text-3); }

.bubble-ai.thinking {
    background: var(--surface);
    color: var(--text-2);
}

/* 滚动到底部按钮 */
.scroll-down {
    position: fixed;
    left: calc(50% + var(--sidebar-w) / 2);
    bottom: calc(var(--composer-h) + .6rem);
    z-index: 40;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateX(-50%) translateY(6px);
    color: var(--text-2);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition: var(--speed), left var(--speed) ease;
}
.scroll-down.visible { opacity: 1; pointer-events: auto; transform: translateX(-50%); }
.scroll-down:hover { color: var(--text); border-color: var(--border-strong); }
.scroll-down svg { width: 15px; height: 15px; }

/* ---------- 6. 底部输入区 ---------- */

.composer,
footer {
    position: fixed;
    left: var(--sidebar-w);
    right: 0;
    bottom: 0;
    z-index: 45;
    background: color-mix(in srgb, var(--bg) 92%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--border);
    padding: .6rem max(1rem, calc((100% - 780px) / 2)) .8rem;
    transition: left var(--speed) ease;
}

.composer-row {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.composer-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    margin-bottom: .45rem;
    min-height: 26px;
}

.chat-input,
.input-field {
    flex: 1;
    min-width: 0;
    padding: .75rem 1rem;
    font-size: .92rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    outline: none;
    transition: var(--speed);
}
.chat-input::placeholder,
.input-field::placeholder { color: var(--text-3); }
.chat-input:focus,
.input-field:focus {
    background: var(--bg);
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent);
}
.chat-input:disabled,
.input-field:disabled { opacity: .6; cursor: not-allowed; }

.send-btn {
    flex-shrink: 0;
    height: 44px;
    padding: 0 1.4rem;
    font-size: .88rem;
    font-weight: 550;
    color: var(--invert-text);
    background: var(--invert-bg);
    border: 1px solid var(--invert-bg);
    border-radius: var(--radius-pill);
    white-space: nowrap;
    transition: var(--speed);
}
.send-btn:hover:not(:disabled) { opacity: .86; }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }

.upload-btn,
.toolbar-btn {
    flex-shrink: 0;
    padding: .4rem .85rem;
    font-size: .75rem;
    color: var(--text-2);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    white-space: nowrap;
    transition: var(--speed);
}
.upload-btn:hover,
.toolbar-btn:hover { color: var(--text); background: var(--surface); border-color: var(--border-strong); }

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-left: auto;
    flex-wrap: wrap;
}
.toolbar-preview {
    display: flex;
    align-items: center;
    min-height: 26px;
}
.preview-wrap {
    position: relative;
    display: none;
}
.preview-wrap.has-image { display: inline-block; }
.preview-wrap img {
    display: block;
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}
.remove-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 17px;
    height: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .6rem;
    line-height: 1;
    color: var(--invert-text);
    background: var(--invert-bg);
    border: none;
    border-radius: 50%;
}

.stop-btn {
    padding: .4rem .9rem;
    font-size: .75rem;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    transition: var(--speed);
}
.stop-btn:hover { background: var(--surface); }

/* 生成按钮的加载态 */
.gen-btn-loading,
.oauth-btn-loading { opacity: .6; pointer-events: none; }

/* ---------- 7. 模态框 ---------- */

.modal-mask {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--speed), visibility var(--speed);
}
.modal-mask.active,
.modal-mask.open { opacity: 1; visibility: visible; }

.modal-card {
    width: 100%;
    max-width: 440px;
    max-height: 86vh;
    overflow-y: auto;
    padding: 1.4rem 1.5rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform: translateY(8px) scale(.99);
    transition: transform var(--speed);
}
.modal-mask.active .modal-card { transform: none; }

.modal-card-wide { max-width: 560px; }
.modal-card h3 {
    margin-bottom: .9rem;
    font-size: 1.02rem;
    font-weight: 650;
    letter-spacing: -.01em;
}
.modal-card p { font-size: .86rem; color: var(--text-2); }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    margin-top: 1.1rem;
}

.modal-btn {
    padding: .5rem 1.1rem;
    font-size: .84rem;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: var(--speed);
}
.modal-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }

.modal-btn-primary {
    color: var(--invert-text);
    background: var(--invert-bg);
    border-color: var(--invert-bg);
}
.modal-btn-primary:hover { background: var(--invert-bg); border-color: var(--invert-bg); opacity: .86; }

.modal-btn-cancel {
    color: var(--text-2);
    background: transparent;
}
.modal-btn-cancel:hover { color: var(--text); background: var(--surface); }

.icon-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    font-size: 1rem;
    line-height: 1;
    color: var(--text-3);
    background: transparent;
    border: none;
    border-radius: 8px;
    transition: var(--speed);
}
.icon-close:hover { color: var(--text); background: var(--surface); }

.form-error {
    min-height: 1.1rem;
    margin-bottom: .35rem;
    font-size: .76rem;
    color: var(--text);
    font-weight: 500;
}

.link-muted {
    font-size: .72rem;
    color: var(--text-3);
    background: none;
    border: none;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: var(--speed);
}
.link-muted:hover { color: var(--text); }

/* 主题选择 */
.theme-select-container {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.theme-option {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .7rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--speed);
}
.theme-option:hover { background: var(--surface); border-color: var(--border-strong); }
.theme-option.selected {
    background: var(--surface);
    border-color: var(--text);
    box-shadow: 0 0 0 1px var(--text);
}
.theme-preview {
    width: 42px;
    height: 32px;
    flex-shrink: 0;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
}
.theme-preview-default {
    background: linear-gradient(90deg, #ffffff 0 50%, #0a0a0a 50% 100%);
}
.theme-preview-light { background: #ffffff; }
.theme-preview-dark  { background: #0a0a0a; }
.theme-label { font-size: .86rem; font-weight: 550; }
.theme-desc  { font-size: .72rem; color: var(--text-3); }

/* 模型选择 */
.model-select-container {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.model-card {
    padding: .7rem .85rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: var(--speed);
}
.model-card:hover { background: var(--surface); border-color: var(--border-strong); }
.model-card.selected { background: var(--surface); border-color: var(--text); box-shadow: 0 0 0 1px var(--text); }
.model-name { font-size: .88rem; font-weight: 600; }
.model-desc { font-size: .75rem; color: var(--text-3); margin-top: .1rem; }

/* 签到 */
.sign-reward {
    margin: .35rem 0;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
}

/* 赞助 / 公告 */
.sponsor-title { font-size: 1.02rem; font-weight: 650; }
.sponsor-desc { font-size: .84rem; color: var(--text-2); margin-bottom: .8rem; }
.sponsor-image {
    display: block;
    width: 100%;
    max-width: 260px;
    margin: 0 auto .8rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.sponsor-tip { font-size: .74rem; color: var(--text-3); text-align: center; }

/* 下面几个 class 是 JS 动态拼进 DOM 的，之前没有样式，统一补上 */
.sponsor-card,
.announcement-card,
.sign-modal { /* 继承 .modal-mask / .modal-box 的外观 */ }

.notification-title {
    font-size: .88rem;
    font-weight: 600;
    color: var(--text);
}
.notification-content {
    font-size: .82rem;
    line-height: 1.7;
    color: var(--text-2);
    white-space: pre-wrap;
}
.notification-time {
    display: block;
    margin-top: .25rem;
    font-size: .7rem;
    color: var(--text-3);
}

.announcement-title {
    font-size: 1rem;
    font-weight: 650;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .6rem;
}
.announcement-body {
    font-size: .86rem;
    line-height: 1.75;
    color: var(--text-2);
    max-height: 46vh;
    overflow-y: auto;
    white-space: pre-wrap;
}
.announcement-footer {
    margin-top: .8rem;
    font-size: .7rem;
    color: var(--text-3);
    text-align: center;
}

.quota-info {
    font-size: .86rem;
    line-height: 1.8;
    color: var(--text-2);
}

/* 分享 */
.share-platforms {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .5rem;
    margin: .7rem 0;
}
.share-platform-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .3rem;
    padding: .6rem .3rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: var(--speed);
}
.share-platform-btn:hover { background: var(--surface); border-color: var(--border-strong); }
.share-platform-btn .icon-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: grayscale(1);
}
.share-platform-btn .label { font-size: .7rem; color: var(--text-2); }

.share-divider {
    height: 1px;
    margin: .8rem 0;
    background: var(--border);
}
.share-link-row { display: flex; gap: .4rem; }
.share-link-row input {
    flex: 1;
    min-width: 0;
    padding: .5rem .7rem;
    font-size: .78rem;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
}
.btn {
    padding: .5rem .9rem;
    font-size: .78rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    transition: var(--speed);
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }

/* 登录 / 注册 */
.auth-form-group { margin-bottom: .7rem; }
.auth-form-group label {
    display: block;
    margin-bottom: .25rem;
    font-size: .78rem;
    color: var(--text-2);
}
.auth-form-group input {
    width: 100%;
    padding: .55rem .8rem;
    font-size: .88rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    transition: var(--speed);
}
.auth-form-group input:focus {
    background: var(--bg);
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent);
}

.auth-actions { display: flex; flex-direction: column; gap: .5rem; margin-top: .9rem; }
.oauth-btn { display: block; width: 100%; text-align: center; text-decoration: none; }
.auth-switch {
    margin-top: .2rem;
    padding: .45rem;
    font-size: .8rem;
    text-align: center;
    color: var(--text-2);
    background: transparent;
    border: 1px dashed var(--border-strong);
    border-radius: 10px;
    transition: var(--speed);
}
.auth-switch:hover { color: var(--text); background: var(--surface); }

.auth-footer {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: .8rem;
    border-top: 1px solid var(--border);
    font-size: .74rem;
}
.auth-footer a { color: var(--text-3); text-decoration: none; }
.auth-footer a:hover { color: var(--text); text-decoration: underline; }

.auth-avatar-area { display: flex; align-items: center; gap: .8rem; }
.auth-avatar-preview,
.avatar-preview {
    width: 54px;
    height: 54px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-weight: 600;
    color: var(--invert-text);
    background: var(--invert-bg);
    border-radius: 50%;
}
.auth-avatar-preview img,
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.auth-avatar-upload { flex: 1; min-width: 0; }

/* ---------- 文件选择控件 ----------
   浏览器默认的 <input type="file"> 是一块系统样式控件，
   放在黑白界面里很扎眼。这里把它藏起来（仍可聚焦、仍可被 label 触发），
   外面用 .file-btn / .file-name 自己画一套。 */
.file-field {
    position: relative;
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}
.file-field input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}
.file-btn {
    flex-shrink: 0;
    padding: .42rem 1rem;
    font-size: .78rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: var(--speed);
}
.file-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.file-field input[type="file"]:focus-visible + .file-btn {
    border-color: var(--text);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 12%, transparent);
}
.file-name {
    min-width: 0;
    flex: 1;
    font-size: .76rem;
    color: var(--text-2);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-label {
    display: block;
    margin-bottom: .3rem;
    font-size: .78rem;
    color: var(--text-2);
}
.file-hint {
    margin: .45rem 0 .2rem;
    font-size: .72rem;
    color: var(--text-3);
}
.auth-avatar-hint { font-size: .7rem; color: var(--text-3); }

/* 预览代码块 */
.preview-pre {
    margin: .8rem 0;
    padding: .8rem;
    max-height: 240px;
    overflow: auto;
    font-family: var(--mono);
    font-size: .78rem;
    line-height: 1.6;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- 8. 设置 ---------- */

.settings-avatar {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding-bottom: .9rem;
    border-bottom: 1px solid var(--border);
}
.settings-avatar-img {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-weight: 600;
    color: var(--invert-text);
    background: var(--invert-bg);
    border-radius: 50%;
}
.settings-avatar-img img { width: 100%; height: 100%; object-fit: cover; }
.settings-avatar-info { min-width: 0; }
.settings-avatar-name {
    font-size: .95rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.change-avatar-btn {
    margin-top: .25rem;
    padding: .25rem .7rem;
    font-size: .74rem;
    color: var(--text-2);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    transition: var(--speed);
}
.change-avatar-btn:hover { color: var(--text); background: var(--surface); border-color: var(--border-strong); }

.settings-tabs {
    display: flex;
    gap: .3rem;
    margin: 1rem 0 .9rem;
    padding: .25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.settings-tab {
    flex: 1;
    padding: .45rem;
    font-size: .82rem;
    color: var(--text-2);
    background: transparent;
    border: none;
    border-radius: 9px;
    transition: var(--speed);
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
    color: var(--text);
    background: var(--bg);
    box-shadow: var(--shadow-sm);
    font-weight: 550;
}

.settings-panel { display: none; }
.settings-panel.active { display: block; }

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .8rem;
    padding: .65rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .86rem;
}
.setting-row:last-of-type { border-bottom: none; }

.font-size-group {
    display: flex;
    gap: .25rem;
    padding: .2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.font-size-btn {
    padding: .25rem .7rem;
    font-size: .76rem;
    color: var(--text-2);
    background: transparent;
    border: none;
    border-radius: 7px;
    transition: var(--speed);
}
.font-size-btn:hover { color: var(--text); }
.font-size-btn.active {
    color: var(--text);
    background: var(--bg);
    box-shadow: var(--shadow-sm);
    font-weight: 550;
}

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    inset: 0;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: var(--speed);
}
.slider::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--bg);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
    transition: var(--speed);
}
.switch input:checked + .slider { background: var(--invert-bg); border-color: var(--invert-bg); }
.switch input:checked + .slider::before { transform: translateX(18px); background: var(--invert-text); }

.account-form { display: flex; flex-direction: column; gap: .55rem; }
.account-form input,
.account-form textarea {
    width: 100%;
    padding: .55rem .8rem;
    font-size: .86rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
    resize: vertical;
    transition: var(--speed);
}
.account-form input:focus,
.account-form textarea:focus {
    background: var(--bg);
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent);
}

/* ---------- 9. Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--composer-h) + 1.2rem);
    z-index: 300;
    padding: .5rem 1.1rem;
    font-size: .82rem;
    color: var(--invert-text);
    background: var(--invert-bg);
    border-radius: var(--radius-pill);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
    pointer-events: none;
    transition: var(--speed);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- 10. 窄屏适配 ---------- */

@media (max-width: 720px) {
    :root { --header-h: 52px; --composer-h: 108px; }

    body { font-size: 14.5px; }

    header { padding: 0 .65rem; gap: .35rem; }
    header .brand { font-size: .95rem; }
    #usernameDisplay { display: none !important; }
    .model-badge { display: none; }

    .bubble-user, .bubble-ai, .bubble-description { max-width: 88%; }

    #chatMessages { padding: .9rem .8rem 1.2rem; }

    .composer, footer { padding: .5rem .7rem .7rem; }
    .send-btn { padding: 0 1rem; height: 42px; }
    .chat-input { padding: .68rem .85rem; }

    .share-platforms { grid-template-columns: repeat(2, 1fr); }
    .modal-card { padding: 1.1rem 1rem; border-radius: 16px; }
    .modal-card-wide { max-width: 100%; }
    .toolbar-actions { gap: .3rem; }
}

@media (max-width: 420px) {
    .qianbai-display { padding: .14rem .45rem; font-size: .7rem; }
    .toolbar-btn, .upload-btn { padding: .35rem .6rem; font-size: .7rem; }
}

/* 尊重"减少动态效果"的系统设置 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* ---------- 11. 桌面端：侧边栏展开时把正文让开 ----------
   侧边栏本身是抽屉（覆盖式），在窄屏上这样最省地方；
   但桌面上如果继续盖住聊天区就很难受，所以 ≥900px 时让顶栏、
   聊天区、输入区一起右移。用 :has() 实现，不支持的浏览器会整条忽略，
   退化成原来的覆盖式抽屉，功能不受影响。 */
@media (min-width: 900px) {
    body:has(.sidebar.open) { --sidebar-w: 288px; }
}
