/* ==========================================================
   栈道社区 · 论坛化改版
   加载顺序：app-m3.css → app-theme.css → app-forum.css
   这层只做“论坛信息架构 + 密度 + 侧栏”，不改动 App 的 MD3 配色体系。
   ========================================================== */

/* ---------- 通用：论坛排版与卡片密度 ---------- */
.app-main .forum-home-head,
.app-main .forum-board-head {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 28px;
    margin: 16px 0 0;
    padding: 20px 22px 18px;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .30);
    border-radius: 14px;
    background:
        radial-gradient(120% 150% at 100% 0%, rgba(var(--mdui-color-primary), .11), transparent 56%),
        linear-gradient(180deg, rgba(var(--mdui-color-surface-container-low), .72), rgba(var(--mdui-color-surface), .92));
    overflow: hidden;
}
.app-main .forum-home-head::after,
.app-main .forum-board-head::after {
    content: "";
    position: absolute;
    right: -54px;
    top: -72px;
    width: 210px;
    height: 210px;
    border-radius: 50%;
    border: 1px solid rgba(var(--mdui-color-primary), .14);
    pointer-events: none;
}
.forum-head-copy { min-width: 0; position: relative; z-index: 1; }
.forum-head-kicker {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 7px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .2px;
    color: rgba(var(--mdui-color-primary), .90);
}
.forum-head-kicker mdui-icon { font-size: 16px; }
.forum-head-live {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 4px;
    padding-left: 10px;
    border-left: 1px solid rgba(var(--mdui-color-outline-variant), .40);
    color: rgba(var(--mdui-color-on-surface), .50);
    font-weight: 500;
}
.forum-head-live i,
.forum-live-dot i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22a06b;
    box-shadow: 0 0 0 3px rgba(34, 160, 107, .12);
}
.forum-head-copy h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1.18;
    font-weight: 700;
    letter-spacing: -.8px;
    color: rgb(var(--mdui-color-on-surface));
}
.forum-head-copy p {
    max-width: 640px;
    margin: 8px 0 0;
    font-size: 13px;
    line-height: 1.65;
    color: rgba(var(--mdui-color-on-surface), .58);
}
.forum-head-stats {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: stretch;
    flex: 0 0 auto;
    min-height: 58px;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .28);
    border-radius: 10px;
    background: rgba(var(--mdui-color-surface), .66);
    backdrop-filter: blur(10px);
}
.forum-head-stats > span {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 76px;
    padding: 8px 15px;
    border-right: 1px solid rgba(var(--mdui-color-outline-variant), .22);
}
.forum-head-stats > span:last-child { border-right: 0; }
.forum-head-stats b {
    font-size: 22px;
    line-height: 1.1;
    font-weight: 700;
    letter-spacing: -.4px;
    color: rgb(var(--mdui-color-on-surface));
}
.forum-head-stats small {
    margin-top: 3px;
    font-size: 10.5px;
    letter-spacing: .4px;
    color: rgba(var(--mdui-color-on-surface), .48);
}

/* 列表标题行 */
.app-main .forum-feed-head {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 !important;
    padding: 16px 2px 10px !important;
    border-bottom: 0 !important;
}
.forum-feed-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.forum-feed-title strong {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -.2px;
    color: rgb(var(--mdui-color-on-surface));
}
.forum-feed-title span {
    font-size: 11.5px;
    color: rgba(var(--mdui-color-on-surface), .42);
}
.forum-sort {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border-radius: 8px;
    background: rgba(var(--mdui-color-on-surface), .045);
}
.forum-sort a {
    display: inline-flex;
    align-items: center;
    height: 26px;
    padding: 0 11px;
    border-radius: 6px;
    color: rgba(var(--mdui-color-on-surface), .55);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease;
}
.forum-sort a:hover { color: rgb(var(--mdui-color-on-surface)); background: rgba(var(--mdui-color-on-surface), .06); }
.forum-sort a.active {
    background: rgb(var(--mdui-color-surface));
    color: rgb(var(--mdui-color-primary));
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

/* 帖子流：更密的论坛行，去掉“内容卡片流”的松垮感 */
.app-main .app-feed { padding-top: 0 !important; }
.app-main .app-post-card {
    position: relative;
    border-radius: 10px !important;
    border-bottom: 0 !important;
    border-left: 2px solid transparent !important;
    margin-bottom: 2px;
    padding: 15px 14px 13px 16px !important;
    transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.app-main .app-post-card:hover {
    background: rgba(var(--mdui-color-primary), .045) !important;
    border-left-color: rgba(var(--mdui-color-primary), .55) !important;
    box-shadow: inset 0 0 0 1px rgba(var(--mdui-color-primary), .08);
}
.app-main .app-post-card .app-post-tags { margin-bottom: 7px; gap: 5px; }
.app-main .app-post-card h2 {
    margin: 0;
    font-size: 16.5px !important;
    line-height: 1.48 !important;
    font-weight: 650 !important;
    letter-spacing: -.15px;
}
.app-main .app-post-card p {
    margin: 5px 0 0;
    font-size: 12.5px !important;
    line-height: 1.62 !important;
    color: rgba(var(--mdui-color-on-surface), .72) !important;
    -webkit-line-clamp: 2;
}
.app-main .app-post-meta {
    padding-top: 9px !important;
    gap: 7px !important;
}
.app-main .app-post-meta .meta-avatar {
    width: 21px;
    height: 21px;
    border-radius: 50%;
    margin-right: 1px;
}
.app-main .app-post-meta .meta-author { font-size: 11.5px !important; color: rgba(var(--mdui-color-on-surface), .62) !important; }
.app-main .app-post-meta .meta-time {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-left: auto;
    font-size: 11px;
    color: rgba(var(--mdui-color-on-surface), .40);
    white-space: nowrap;
}
.app-main .app-post-meta .meta-time mdui-icon { font-size: 13px; opacity: .8; }
.app-main .app-post-meta .meta-stat { font-size: 10.5px !important; color: rgba(var(--mdui-color-on-surface), .68) !important; }
.app-main .app-post-meta .meta-stat mdui-icon { font-size: 13px !important; }

/* 分类/标签 pill 更克制 */
.app-main .app-pill {
    height: 20px !important;
    padding: 0 7px !important;
    border-radius: 5px !important;
    font-size: 10.5px !important;
    letter-spacing: .1px;
}

/* ---------- 桌面右侧社区栏 ---------- */
.forum-rail { display: none; }
@media (min-width: 1280px) {
    .app-main.has-forum-rail {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) 280px;
        gap: 24px;
        align-items: start;
    }
    .app-main.has-forum-rail > .page-content { grid-column: 1; min-width: 0; }
    .forum-rail {
        grid-column: 2;
        position: sticky;
        top: 84px;
        align-self: start;
        display: flex;
        flex-direction: column;
        gap: 12px;
        max-height: calc(100vh - 100px);
        padding-bottom: 26px;
        overflow: auto;
        scrollbar-width: none;
    }
    .forum-rail::-webkit-scrollbar { width: 0; height: 0; }

    .forum-card {
        border: 1px solid rgba(var(--mdui-color-outline-variant), .42);
        border-radius: 12px;
        background: rgb(var(--mdui-color-surface-container-low));
        overflow: hidden;
    }
    .forum-card-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        min-height: 40px;
        padding: 10px 13px;
        border-bottom: 1px solid rgba(var(--mdui-color-outline-variant), .30);
        font-size: 12px;
        font-weight: 700;
        letter-spacing: .3px;
        color: rgb(var(--mdui-color-on-surface));
    }
    .forum-card-head a {
        font-size: 10.5px;
        font-weight: 500;
        color: rgba(var(--mdui-color-on-surface), .46);
        text-decoration: none;
    }
    .forum-card-head a:hover { color: rgb(var(--mdui-color-primary)); }
    .forum-live-dot {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        font-size: 10px;
        font-weight: 500;
        color: rgba(var(--mdui-color-on-surface), .45);
    }
    .forum-rail-stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1px;
        background: rgba(var(--mdui-color-outline-variant), .24);
    }
    .forum-rail-stats > div {
        display: flex;
        flex-direction: column;
        padding: 11px 13px 10px;
        background: rgb(var(--mdui-color-surface-container-low));
    }
    .forum-rail-stats b {
        font-size: 20px;
        line-height: 1.1;
        font-weight: 700;
        letter-spacing: -.4px;
        color: rgb(var(--mdui-color-on-surface));
    }
    .forum-rail-stats span {
        margin-top: 3px;
        font-size: 10px;
        color: rgba(var(--mdui-color-on-surface), .44);
    }
    .forum-hot-list { display: flex; flex-direction: column; padding: 5px 0 7px; }
    .forum-hot-item {
        display: grid;
        grid-template-columns: 20px minmax(0, 1fr) auto;
        align-items: center;
        gap: 7px;
        padding: 7px 12px;
        text-decoration: none;
        color: inherit;
    }
    .forum-hot-item:hover { background: rgba(var(--mdui-color-on-surface), .045); }
    .forum-hot-rank {
        font-size: 10px;
        font-weight: 800;
        text-align: center;
        color: rgba(var(--mdui-color-on-surface), .30);
        font-variant-numeric: tabular-nums;
    }
    .forum-hot-item:nth-child(-n+3) .forum-hot-rank { color: rgb(var(--mdui-color-primary)); }
    .forum-hot-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
    .forum-hot-body strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 12px;
        font-weight: 550;
        line-height: 1.35;
        color: rgb(var(--mdui-color-on-surface));
    }
    .forum-hot-body small {
        font-size: 9.5px;
        color: rgba(var(--mdui-color-on-surface), .40);
    }
    .forum-hot-heat {
        font-size: 9px;
        color: rgba(var(--mdui-color-on-surface), .30);
        white-space: nowrap;
    }
    .forum-people { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: rgba(var(--mdui-color-outline-variant), .22); }
    .forum-person {
        display: flex;
        align-items: center;
        gap: 7px;
        min-width: 0;
        padding: 9px 11px;
        background: rgb(var(--mdui-color-surface-container-low));
        text-decoration: none;
        color: inherit;
    }
    .forum-person:hover { background: rgba(var(--mdui-color-primary), .055); }
    .forum-person img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; flex: 0 0 24px; background: rgba(var(--mdui-color-on-surface), .06); }
    .forum-person span { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
    .forum-person strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10.5px; font-weight: 600; color: rgba(var(--mdui-color-on-surface), .74); }
    .forum-person small { font-size: 9px; color: rgba(var(--mdui-color-on-surface), .38); }
    .forum-rail-note {
        padding: 11px 13px;
        border: 1px dashed rgba(var(--mdui-color-outline-variant), .58);
        border-radius: 10px;
        font-size: 10px;
        line-height: 1.65;
        color: rgba(var(--mdui-color-on-surface), .40);
    }
    .forum-rail-note b { color: rgba(var(--mdui-color-on-surface), .60); font-weight: 600; }

    /* 帖子详情在侧栏旁边放宽，正文保持可读行宽 */
    body.page-post .app-main.has-forum-rail .app-detail { max-width: none; margin: 0; padding: 20px 0 100px; }
    body.page-post .app-main.has-forum-rail .app-reply-bar { left: 36px; right: 328px; width: auto; max-width: none; }

    /* 帖子里已经有自己的长文阅读节奏，侧栏只做社区上下文，不再抢注意力 */
    body.page-post .forum-rail .forum-card:first-child { display: none; }
}

/* ---------- 桌面：整体画布更紧凑，论坛不需要巨型圆角纸 ---------- */
@media (min-width: 960px) {
    body:is(.page-home,.page-category,.page-search,.page-tags,.page-post) {
        background:
            radial-gradient(1200px 600px at 8% -10%, rgba(var(--mdui-color-primary), .055), transparent 60%),
            rgb(var(--mdui-color-surface-container-low)) !important;
    }
    body:is(.page-home,.page-category,.page-search,.page-tags,.page-post) .app-main {
        margin: 10px 12px 20px !important;
        padding: 0 30px 40px !important;
        border-radius: 16px !important;
        min-height: calc(100vh - 94px) !important;
    }
    body:is(.page-home,.page-category,.page-search,.page-tags,.page-post) .app-topbar {
        padding: 0 40px !important;
    }
    body:is(.page-home,.page-category) .app-topbar::before {
        content: "社区";
        font-size: 21px !important;
        font-weight: 650 !important;
    }
    body:is(.page-home,.page-category) .app-topbar::after {
        content: "论坛";
        margin-left: 9px;
        padding: 2px 6px;
        border: 1px solid rgba(var(--mdui-color-primary), .22);
        border-radius: 4px;
        font-size: 9px;
        font-weight: 600;
        letter-spacing: .8px;
        color: rgba(var(--mdui-color-primary), .80);
        transform: translateY(1px);
    }

    /* 桌面导航：发现入口 + 更紧凑的板块列表 */
    .rail-explore {
        display: flex;
        flex-direction: column;
        gap: 2px;
        margin: 2px 0 4px;
        padding: 8px 0 10px;
        border-bottom: 1px solid rgba(var(--mdui-color-outline-variant), .16);
    }
    .rail-explore > span {
        margin: 0 10px 6px;
        font-size: 10px;
        letter-spacing: .8px;
        color: rgba(var(--mdui-color-on-surface), .38);
    }
    .rail-explore a {
        display: flex;
        align-items: center;
        height: 30px;
        padding: 0 10px;
        border-radius: 6px;
        color: rgba(var(--mdui-color-on-surface), .60);
        font-size: 12px;
        text-decoration: none;
    }
    .rail-explore a:hover { background: rgba(var(--mdui-color-on-surface), .045); color: rgb(var(--mdui-color-on-surface)); }
    .rail-explore a.active {
        background: rgba(var(--mdui-color-primary), .095);
        color: rgb(var(--mdui-color-primary));
        font-weight: 600;
    }
    .rail-boards { margin-top: 8px; padding-top: 10px; }
    .rail-boards a { height: 28px; }
    .rail-boards a.active {
        background: rgba(var(--mdui-color-primary), .095);
        color: rgb(var(--mdui-color-primary));
        font-weight: 600;
    }
    .rail-kicker { margin-bottom: 5px; font-size: 10px; letter-spacing: .8px; }
}

/* ---------- 移动端：砍掉大 hero，首屏直接进帖子 ---------- */
@media (max-width: 959px) {
    body:is(.page-home,.page-category) .app-searchwrap,
    body.page-category .app-searchwrap { margin-top: 2px; }

    .app-main .forum-home-head,
    .app-main .forum-board-head {
        display: block;
        margin: 12px 14px 0;
        padding: 15px 15px 13px;
        border-radius: 12px;
        gap: 0;
    }
    .forum-head-kicker { margin-bottom: 5px; font-size: 10.5px; }
    .forum-head-live { font-size: 10px; }
    .forum-head-copy h1 { font-size: 23px; letter-spacing: -.5px; }
    .forum-head-copy p { margin-top: 5px; font-size: 11.5px; line-height: 1.55; }
    .forum-head-stats {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        width: 100%;
        min-height: 0;
        margin-top: 12px;
        border-radius: 9px;
    }
    .forum-head-stats > span { min-width: 0; padding: 7px 10px; }
    .forum-head-stats b { font-size: 17px; }
    .forum-head-stats small { font-size: 9px; }

    .app-main .forum-feed-head {
        padding: 13px 16px 8px !important;
        gap: 10px;
    }
    .forum-feed-title strong { font-size: 14.5px; }
    .forum-feed-title span { display: none; }
    .forum-sort { flex: 0 0 auto; overflow: auto; scrollbar-width: none; }
    .forum-sort::-webkit-scrollbar { display: none; }
    .forum-sort a { height: 25px; padding: 0 9px; font-size: 11px; }

    .app-main .app-post-card {
        margin: 0 10px 2px !important;
        padding: 13px 10px 12px 12px !important;
        border-radius: 8px !important;
    }
    .app-main .app-post-card h2 { font-size: 15.5px !important; line-height: 1.5 !important; }
    .app-main .app-post-card p { margin-top: 4px; font-size: 12px !important; line-height: 1.55 !important; }
    .app-main .app-post-meta { padding-top: 8px !important; }
    .app-main .app-post-meta .meta-time { font-size: 10px; }
    .app-main .app-post-card .app-post-tags { margin-bottom: 6px; overflow: hidden; }
}

/* 分类页的 .app-home-intro 在旧样式里有自己的 grid 规则，单独压掉 */
@media (min-width: 960px) {
    body.page-category .app-home-intro.forum-home-head {
        display: flex !important;
        grid-template-columns: none !important;
        grid-template-rows: none !important;
        gap: 24px !important;
        padding: 18px 22px 17px !important;
    }
    body.page-category .app-home-intro.forum-home-head .forum-head-stats {
        width: auto !important;
        margin-left: auto;
    }
}

.app-main .card {
    border-radius: 12px;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .42);
    box-shadow: none;
}
.app-main .card-header { padding: 13px 16px; border-bottom: 1px solid rgba(var(--mdui-color-outline-variant), .32); }
.app-main .card-title { font-size: 15px; }
.page-content.legacy-ui h1,
.page-content.legacy-ui h2 { letter-spacing: -.3px; }

/* 回到顶部：桌面论坛常驻小按钮 */
.forum-top-btn {
    position: fixed;
    right: 26px;
    bottom: 28px;
    z-index: 45;
    display: none;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .50);
    border-radius: 50%;
    background: rgba(var(--mdui-color-surface), .88);
    color: rgba(var(--mdui-color-on-surface), .64);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .10);
    backdrop-filter: blur(12px);
    cursor: pointer;
}
.forum-top-btn mdui-icon { font-size: 20px; }
.forum-top-btn.show { display: inline-flex; align-items: center; justify-content: center; }
@media (max-width: 959px) { .forum-top-btn { display: none !important; } }

/* 排行榜移动端：去掉 0.4px 垂直溢出触发的无意义滚动条按钮 */
body.page-rank .tabs {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
body.page-rank .tabs::-webkit-scrollbar { display: none; width: 0; height: 0; }

/* 树洞颜色选择：隐藏移动端被放大的原生 radio，只留圆形色点 */
body.page-treehole input[name="treehole_color"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    opacity: 0;
    pointer-events: none;
}
body.page-treehole input[name="treehole_color"] + span {
    width: 24px !important;
    height: 24px !important;
    flex: 0 0 24px !important;
}

/* 树洞颜色：原生 radio 隐藏后，用外圈明确标出当前选中色 */
body.page-treehole input[name="treehole_color"]:checked + span {
    outline: 2px solid rgba(var(--mdui-color-on-surface), .55);
    outline-offset: 2px;
}
body.page-treehole input[name="treehole_color"]:focus-visible + span {
    outline: 2px solid rgb(var(--mdui-color-primary));
    outline-offset: 3px;
}

/* ============ 私信页：桌面恢复会话搜索，移动端做成收件箱 ============ */
@media (min-width: 769px) {
    body.page-messages .chat-search {
        display: block !important;
        padding: 0 !important;
        margin: 0 0 10px !important;
    }
    body.page-messages .chat-search input {
        height: 38px !important;
        padding: 0 14px !important;
        border-radius: 19px !important;
        font-size: 12.5px !important;
    }
    body.page-messages .app-msg-intro { padding: 0 4px !important; }
    body.page-messages .app-msg-intro .app-hero,
    body.page-messages .app-msg-intro .app-msg-stats { display: none !important; }
    body.page-messages .app-section-head { padding: 2px 0 8px !important; border: 0 !important; }
    body.page-messages .chat-new {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 32px !important;
        height: 32px !important;
        border-radius: 50% !important;
        border: 0 !important;
        background: rgb(var(--mdui-color-surface-container-high)) !important;
        color: rgb(var(--mdui-color-on-surface)) !important;
    }
    body.page-messages .chat-new:hover { color: rgb(var(--mdui-color-primary)) !important; }
    body.page-messages .chat-head { min-height: 58px !important; }
}

@media (max-width: 768px) {
    body.page-messages .chat-list {
        position: relative !important;
        padding: 10px 12px 0 !important;
    }
    body.page-messages .chat-list-head {
        position: absolute !important;
        top: 10px !important;
        right: 12px !important;
        z-index: 2 !important;
        display: flex !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 0 !important;
        background: transparent !important;
    }
    body.page-messages .chat-list-head h2 { display: none !important; }
    body.page-messages .chat-new {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 40px !important;
        height: 40px !important;
        border-radius: 50% !important;
        background: rgb(var(--mdui-color-surface-container-high)) !important;
        color: rgb(var(--mdui-color-on-surface)) !important;
        border: 0 !important;
    }
    body.page-messages .chat-search {
        display: block !important;
        padding: 0 96px 0 0 !important;
        margin: 0 0 12px !important;
    }
    body.page-messages .chat-search input {
        width: 100% !important;
        height: 40px !important;
        padding: 0 14px !important;
        border: 0 !important;
        border-radius: 20px !important;
        background: rgb(var(--mdui-color-surface-container-high)) !important;
        font-size: 13px !important;
        outline: 0 !important;
    }
    body.page-messages .app-msg-intro { padding: 0 !important; }
    body.page-messages .app-msg-hero { display: none !important; }
    body.page-messages .app-msg-stats {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        margin: 0 0 4px !important;
        padding: 0 !important;
    }
    body.page-messages .app-stat-card {
        min-height: 58px !important;
        padding: 9px 13px !important;
        border-radius: 14px !important;
    }
    body.page-messages .app-stat-label { font-size: 10.5px !important; gap: 5px !important; }
    body.page-messages .app-stat-value { font-size: 19px !important; margin-top: 2px !important; }
    body.page-messages .app-section-head {
        padding: 14px 4px 6px !important;
        border: 0 !important;
    }
    body.page-messages .chat-body {
        padding: 12px 12px 8px !important;
        scrollbar-width: thin;
        scrollbar-color: rgba(var(--mdui-color-on-surface), .18) transparent;
    }
    body.page-messages .chat-body::-webkit-scrollbar { width: 3px; }
    body.page-messages .chat-body::-webkit-scrollbar-thumb { background: rgba(var(--mdui-color-on-surface), .16); border-radius: 3px; }
    body.page-messages .chat-body::-webkit-scrollbar-track { background: transparent; }
}

@media (min-width: 769px) {
    body.page-messages .chat-body { scrollbar-width: thin; scrollbar-color: rgba(var(--mdui-color-on-surface), .18) transparent; }
}

/* 聊天区：固定瞬时滚动，避免图片/轮询重排时停在半路 */
body.page-messages .chat-body {
    scroll-behavior: auto !important;
    overflow-anchor: none !important;
}

/* 加密功能已关闭，聊天头不要再露出“加密”胶囊 */
body.page-messages .chat-head .key-chip { display: none !important; }

/* 图片/附件气泡：时间悬浮在图片右下角，加一层暗底保证可读 */
body.page-messages .bub:has(.msg-img) .meta {
    position: absolute !important;
    right: 8px !important;
    bottom: 8px !important;
    margin: 0 !important;
    padding: 2px 6px !important;
    color: rgba(255, 255, 255, .95) !important;
    background: rgba(10, 16, 24, .42) !important;
    border-radius: 6px !important;
    backdrop-filter: blur(6px);
}

body.page-messages .chat-search input:focus {
    box-shadow: 0 0 0 2px rgba(var(--mdui-color-primary), .28) !important;
}

/* ============ 聊天窗口：桌面沉浸式布局 ============ */
@media (min-width: 960px) {
    /* 私信会话页已经有自己的会话头，桌面不再保留重复的整页标题栏 */
    body.page-messages:has(.chat-shell.has-peer) .app-topbar {
        display: none !important;
    }
    body.page-messages:has(.chat-shell.has-peer) .page-content {
        height: calc(100dvh - 25px) !important;
        min-height: 0 !important;
    }
    body.page-messages .chat-shell.has-peer {
        height: 100% !important;
        max-height: none !important;
        border-radius: 18px !important;
        border-color: rgba(var(--mdui-color-outline-variant), .5) !important;
        box-shadow: 0 12px 34px rgba(15, 23, 42, .07) !important;
    }
    body.page-messages .chat-shell.has-peer .chat-head {
        height: 60px !important;
        min-height: 60px !important;
        padding: 0 20px !important;
        background: rgb(var(--mdui-color-surface-container-lowest)) !important;
    }
    body.page-messages .chat-shell.has-peer .chat-head .ph {
        width: 34px !important;
        height: 34px !important;
    }
    body.page-messages .chat-shell.has-peer .chat-head .chat-name {
        font-size: 14.5px !important;
    }
    body.page-messages .chat-shell.has-peer .chat-head .chat-status {
        font-size: 11px !important;
    }
    body.page-messages .chat-shell.has-peer .chat-body {
        padding: 24px 30px 16px !important;
        background:
            radial-gradient(1100px 480px at 82% -8%, rgba(var(--mdui-color-primary), .035), transparent 72%),
            rgb(var(--mdui-color-surface-container-lowest)) !important;
    }
    body.page-messages .chat-shell.has-peer .grp {
        max-width: 780px !important;
    }
    body.page-messages .chat-shell.has-peer .chat-composer {
        padding: 10px 20px 14px !important;
        background: rgb(var(--mdui-color-surface-container-lowest)) !important;
    }
}

/* ============ 气泡：拉开明暗层次，不再一片淡紫 ============ */
body.page-messages .grp.mine .bub {
    background: rgb(var(--mdui-color-primary)) !important;
    color: rgb(var(--mdui-color-on-primary)) !important;
    box-shadow: 0 2px 8px rgba(43, 70, 120, .14) !important;
}
body.page-messages .grp.other .bub {
    background: rgb(var(--mdui-color-surface-container)) !important;
    color: rgb(var(--mdui-color-on-surface)) !important;
    box-shadow: 0 1px 2px rgba(16, 24, 34, .05) !important;
}
body.page-messages .bub {
    border-radius: 16px !important;
    padding: 9px 13px !important;
}
body.page-messages .grp.mine .bub { border-radius: 16px 16px 4px 16px !important; }
body.page-messages .grp.other .bub { border-radius: 16px 16px 16px 4px !important; }
body.page-messages .grp.mine .bub .meta { color: rgba(var(--mdui-color-on-primary), .82) !important; }
body.page-messages .grp.other .bub .meta { color: rgba(var(--mdui-color-on-surface), .46) !important; }

/* 撤回提示收成一条轻量系统消息，不再占一整颗主色气泡 */
body.page-messages .grp.mine .bub.revoked,
body.page-messages .grp.other .bub.revoked {
    background: rgba(var(--mdui-color-on-surface), .06) !important;
    color: rgba(var(--mdui-color-on-surface), .46) !important;
    box-shadow: none !important;
    font-size: 12.5px !important;
    font-style: normal !important;
    line-height: 1.5 !important;
    padding: 5px 12px !important;
    border-radius: 999px !important;
    opacity: 1 !important;
}

/* 图片消息去掉厚重底色，只留图片本体和时间浮层 */
body.page-messages .bub:has(.msg-img) {
    padding: 0 !important;
    border-radius: 14px !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: hidden !important;
    line-height: 0 !important;
}
body.page-messages .bub:has(.msg-img) .msg-img {
    display: block !important;
    margin: 0 !important;
}
body.page-messages .bub:has(.msg-img) .msg-img img {
    border-radius: 14px !important;
    box-shadow: 0 3px 12px rgba(12, 18, 26, .16) !important;
}
body.page-messages .bub:has(.msg-img.multi) .msg-img {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 2px !important;
}

/* 输入区：焦点只亮一圈，不把整条输入框漂白 */
body.page-messages .chat-input:focus {
    box-shadow: 0 0 0 2px rgba(var(--mdui-color-primary), .16) !important;
}
body.page-messages .chat-input {
    caret-color: rgb(var(--mdui-color-primary));
    background: rgb(var(--mdui-color-surface-container-low)) !important;
    color: rgb(var(--mdui-color-on-surface)) !important;
}
body.page-messages .chat-input::placeholder {
    color: rgba(var(--mdui-color-on-surface), .42) !important;
}
body.page-messages .chat-body {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

/* 手机上让消息列更宽一点，长图和长文本不至于被挤成窄条 */
@media (max-width: 768px) {
    body.page-messages .chat-body .grp { max-width: 84% !important; }
    body.page-messages .bub:has(.msg-img) .msg-img img {
        max-width: min(300px, 72vw) !important;
    }
    body.page-messages .chat-composer {
        background: rgb(var(--mdui-color-surface-container-lowest)) !important;
    }
}

/* Load-more hint: JS sets inline .45, override for WCAG AA */
.app-feed-more { color: rgba(var(--mdui-color-on-surface), .68) !important; }


/* ==================== 2026-11-28 移动端布局 V2 ==================== */
@media (max-width: 959px) {
  /* 顶栏：缩短搜索，首屏多留 18px 给内容 */
  body:is(.page-home,.page-category) .app-topbar-row { height: 50px; padding: 0 15px; }
  body:is(.page-home,.page-category) .app-logo { width: 28px; height: 28px; border-radius: 8px; }
  body:is(.page-home,.page-category) .app-brand-name { font-size: 17px; letter-spacing: .8px; }
  body:is(.page-home,.page-category) .app-icon-btn { width: 36px; height: 36px; }
  body:is(.page-home,.page-category) .app-searchwrap { padding: 0 14px 6px; }
  body:is(.page-home,.page-category) .app-search {
    height: 44px; padding: 0 14px; gap: 8px; border-radius: 22px;
    background: rgb(var(--mdui-color-surface-container-low));
  }
  body:is(.page-home,.page-category) .app-search mdui-icon { font-size: 19px; }
  body:is(.page-home,.page-category) .app-search input { font-size: 13px; }

  /* 分类条：更短、更贴边，滑动时不切断圆角 */
  body:is(.page-home,.page-category) .app-chip-row {
    height: 50px; gap: 6px; padding: 6px 14px 8px;
    scroll-padding-inline: 14px;
    -webkit-overflow-scrolling: touch;
  }
  body:is(.page-home,.page-category) .app-chip {
    height: 30px; padding: 0 12px; font-size: 12px;
    background: rgb(var(--mdui-color-surface-container));
  }
  body:is(.page-home,.page-category) .app-chip.active { padding: 0 14px; }

  /* 手机端已在站内，不再用一条 68px 的下载横幅占首屏 */
  body:is(.page-home,.page-category) .app-eco-strip { display: none !important; }

  /* 讨论区抬头：从大 hero 压成一块信息板 */
  body:is(.page-home,.page-category) .app-home-intro { padding: 4px 14px 0; }
  body:is(.page-home,.page-category) .app-main .forum-home-head {
    display: block; margin: 0; padding: 14px 14px 12px;
    border-radius: 18px; gap: 0;
    background:
      radial-gradient(120% 160% at 100% 0%, rgba(var(--mdui-color-primary), .14), transparent 58%),
      linear-gradient(180deg, rgba(var(--mdui-color-surface-container), .86), rgba(var(--mdui-color-surface-container-low), .94));
    border-color: rgba(var(--mdui-color-outline-variant), .42);
  }
  body:is(.page-home,.page-category) .app-main .forum-home-head::after { width: 150px; height: 150px; right: -58px; top: -74px; }
  body:is(.page-home,.page-category) .forum-head-kicker { margin-bottom: 5px; font-size: 10.5px; gap: 6px; }
  body:is(.page-home,.page-category) .forum-live-dot { display: inline-flex; align-items: center; gap: 5px; }
  body:is(.page-home,.page-category) .forum-head-live { font-size: 10px; padding-left: 8px; }
  body:is(.page-home,.page-category) .forum-head-copy h1 { font-size: 22px; line-height: 1.22; letter-spacing: -.4px; }
  body:is(.page-home,.page-category) .forum-head-copy p {
    margin-top: 4px; font-size: 11.5px; line-height: 1.55;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  body:is(.page-home,.page-category) .forum-head-stats {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%; min-height: 0; margin-top: 11px; border-radius: 12px;
    background: rgba(var(--mdui-color-surface), .56);
  }
  body:is(.page-home,.page-category) .forum-head-stats > span { min-width: 0; padding: 7px 10px; }
  body:is(.page-home,.page-category) .forum-head-stats b { font-size: 18px; letter-spacing: -.2px; }
  body:is(.page-home,.page-category) .forum-head-stats small { margin-top: 2px; font-size: 9.5px; letter-spacing: .2px; }

  /* 帖子流标题 */
  body:is(.page-home,.page-category) .app-main .app-section-head {
    padding: 15px 4px 8px; margin: 0; border: 0; background: transparent;
  }
  body:is(.page-home,.page-category) .app-main .app-section-head strong { font-size: 14px; letter-spacing: -.1px; }
  body:is(.page-home,.page-category) .app-main .app-section-head span { font-size: 10.5px; color: rgba(var(--mdui-color-on-surface), .44); }

  /* 帖子卡：一屏能看到两张半，不再一张卡占满 */
  body:is(.page-home,.page-category) .app-feed { padding: 0 12px !important; }
  body:is(.page-home,.page-category) .app-feed .app-post-card {
    margin: 0 0 8px !important;
    padding: 13px 14px 11px !important;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .46) !important;
    border-left: 1px solid rgba(var(--mdui-color-outline-variant), .46) !important;
    border-radius: 16px !important;
    background: rgb(var(--mdui-color-surface-container-lowest)) !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .025);
  }
  body:is(.page-home,.page-category) .app-feed .app-post-card:active {
    background: rgb(var(--mdui-color-surface-container-low)) !important;
    transform: scale(.994);
  }
  body:is(.page-home,.page-category) .app-feed .app-post-card .app-post-tags { margin-bottom: 6px; gap: 5px; max-height: 22px; overflow: hidden; }
  body:is(.page-home,.page-category) .app-feed .app-post-card h2 {
    font-size: 16px !important; line-height: 1.42 !important; letter-spacing: -.2px;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  body:is(.page-home,.page-category) .app-feed .app-post-card p {
    margin-top: 4px !important; font-size: 12px !important; line-height: 1.58 !important;
    color: rgba(var(--mdui-color-on-surface), .56) !important;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  body:is(.page-home,.page-category) .app-feed .app-post-meta {
    margin-top: 9px !important; padding-top: 8px !important;
    border-top: 1px solid rgba(var(--mdui-color-outline-variant), .30);
  }
  body:is(.page-home,.page-category) .app-feed .app-post-meta .meta-avatar { width: 20px; height: 20px; }
  body:is(.page-home,.page-category) .app-feed .app-post-meta .meta-author { font-size: 10.5px !important; max-width: 36%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  body:is(.page-home,.page-category) .app-feed .app-post-meta .meta-stat { font-size: 10px !important; }
  body:is(.page-home,.page-category) .app-feed .app-post-meta .meta-stat mdui-icon { font-size: 12px !important; }

  /* 悬浮发帖按钮：贴右下，但不压住底栏 */
  body:is(.page-home,.page-category) .app-fab {
    width: 52px; height: 52px;
    right: 16px; bottom: calc(96px + env(safe-area-inset-bottom));
    box-shadow: 0 6px 18px rgba(0, 0, 0, .20);
  }
  body:is(.page-home,.page-category) .app-fab mdui-icon { font-size: 22px; }
}


/* active chip contrast fix */
@media (max-width: 959px){
  /* 选中分类：用 primary 而不是会把深色文字压在深色底上的 secondary-container */
  body:is(.page-home,.page-category) .app-chip.active {
    background: rgb(var(--mdui-color-primary)) !important;
    color: rgb(var(--mdui-color-on-primary)) !important;
    border-color: transparent !important;
  }
}

/* Desktop: 让新版头部单列铺满，避免旧的两栏网格留出 248px 空洞 */
@media (min-width: 960px) {
  body:is(.page-home,.page-category) .app-home-intro {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px 0 !important;
  }
}

@media (max-width: 959px){
  body:is(.page-home,.page-category) .app-section-head {
    margin: 0 14px !important;
    padding: 15px 0 8px !important;
  }
}

@media (max-width: 959px){
  body:is(.page-home,.page-category) .app-main {
    padding-bottom: calc(96px + env(safe-area-inset-bottom)) !important;
  }
}

/* ==========================================================
   2026-11-28 全站页面巡检修复
   暗色 legacy 空态 / 原生 select / 低对比主按钮 / 积分转账表单
   ========================================================== */
html:is(.mdui-theme-dark, .app-dark-effective) .legacy-ui .empty-state {
    background: rgba(var(--mdui-color-surface-container-high), .45) !important;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .26);
    color: rgba(var(--mdui-color-on-surface), .62) !important;
}
html:is(.mdui-theme-dark, .app-dark-effective) .legacy-ui select {
    background-color: rgba(var(--mdui-color-surface-container-lowest), .72) !important;
    color: rgb(var(--mdui-color-on-surface)) !important;
    border-color: rgba(var(--mdui-color-outline-variant), .40) !important;
}
html:is(.mdui-theme-dark, .app-dark-effective) .legacy-ui input[type="number"],
html:is(.mdui-theme-dark, .app-dark-effective) .legacy-ui input[type="color"],
html:is(.mdui-theme-dark, .app-dark-effective) .legacy-ui input[type="date"],
html:is(.mdui-theme-dark, .app-dark-effective) .legacy-ui input[type="time"] {
    background-color: rgba(var(--mdui-color-surface-container-lowest), .72) !important;
    color: rgb(var(--mdui-color-on-surface)) !important;
    border-color: rgba(var(--mdui-color-outline-variant), .40) !important;
}
html body .auth-btn:not(.auth-btn-ghost),
html body .app-open-btn {
    background: rgb(var(--mdui-color-primary)) !important;
    color: rgb(var(--mdui-color-on-primary)) !important;
}
html body .auth-btn:not(.auth-btn-ghost):hover {
    background: rgb(var(--mdui-color-primary)) !important;
    filter: brightness(.96);
}
html body .auth-step.on b {
    color: rgb(var(--mdui-color-on-primary)) !important;
}
html body .eco-btn.primary,
html body .eco-btn.primary mdui-icon,
html body .eco-btn.primary small {
    color: rgb(var(--mdui-color-on-primary)) !important;
}
html body .ok {
    color: rgb(var(--mdui-color-on-primary)) !important;
}
body.page-post .app-main {
    padding-bottom: 96px !important;
}
@media (max-width: 959px) {
    body.page-post .app-main {
        padding-bottom: 80px !important;
    }
}
html body input[name="item_color"] {
    width: 84px !important;
    height: 40px !important;
    padding: 4px !important;
}
.app-transfer {
    margin-top: 16px;
    padding: 16px;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .30);
    border-radius: 18px;
    background: rgba(var(--mdui-color-surface-container-low), .55);
}
.app-transfer h3 {
    margin: 0 0 6px;
    font-size: 16px;
    color: rgb(var(--mdui-color-on-surface));
}
.app-transfer .line {
    margin-bottom: 12px;
    font-size: 13px;
    color: rgba(var(--mdui-color-on-surface), .62);
}
.app-transfer form { display: grid; gap: 10px; max-width: 420px; }
.app-transfer input[type="number"],
.app-transfer input[type="text"] {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    height: 44px;
    padding: 0 14px;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .45) !important;
    border-radius: 12px;
    background: rgba(var(--mdui-color-surface-container-lowest), .75) !important;
    color: rgb(var(--mdui-color-on-surface)) !important;
    font-size: 14px;
    outline: none;
}
.app-transfer input:focus {
    border-color: rgba(var(--mdui-color-primary), .80);
    box-shadow: 0 0 0 3px rgba(var(--mdui-color-primary), .16);
}
.app-transfer button {
    width: 100%;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: rgb(var(--mdui-color-primary));
    color: rgb(var(--mdui-color-on-primary));
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.app-transfer button:disabled { opacity: .55; cursor: not-allowed; }

/* Remaining light-surface controls found by the second contrast pass */
.skip-link {
    color: rgb(var(--mdui-color-on-primary)) !important;
}
.pagination .page-btn {
    background: rgba(var(--mdui-color-surface-container-high), .55) !important;
    color: rgb(var(--mdui-color-on-surface)) !important;
    border: 1px solid rgba(var(--mdui-color-outline-variant), .5) !important;
}
.pagination .page-btn.active {
    background: rgb(var(--mdui-color-primary)) !important;
    color: rgb(var(--mdui-color-on-primary)) !important;
    border-color: transparent !important;
}
.zroom-tab.on {
    color: rgb(var(--mdui-color-on-primary)) !important;
}
.audit-center .bar button {
    color: rgb(var(--mdui-color-on-primary)) !important;
}

/* Quiz: light inline gradient and global input reset broke radios */
html:is(.mdui-theme-dark, .app-dark-effective) .page-quiz .card-body > div[style*="linear-gradient(135deg"] {
    background: linear-gradient(135deg, rgba(139, 92, 246, .18), rgba(99, 102, 241, .10)) !important;
}
.page-quiz input[type="radio"],
.page-quiz input[type="checkbox"] {
    appearance: auto !important;
    -webkit-appearance: auto !important;
    width: 18px !important;
    height: 18px !important;
    min-width: 18px !important;
    padding: 0 !important;
    margin: 0 2px 0 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    flex: 0 0 18px !important;
    accent-color: rgb(var(--mdui-color-primary));
}

/* Lucky draw wheel: legacy page hardcodes a near-white gradient */
html:is(.mdui-theme-dark, .app-dark-effective) .page-lucky .lucky-wheel {
    background: linear-gradient(135deg, rgba(37, 99, 235, .22), rgba(30, 41, 59, .38)) !important;
}

/* Keep primary controls readable in the light theme too */
.pagination .page-btn.active,
.zroom-tab.on {
    color: #102f60 !important;
}
html:not(.mdui-theme-dark):not(.app-dark-effective) .audit-center .bar button,
html:not(.mdui-theme-dark):not(.app-dark-effective) .skip-link {
    color: #fff !important;
}

/* Admin points adjustment: four inline columns collapse on phones */
@media (max-width: 959px) {
    .page-admin .card-body form[method="POST"] > div[style*="grid-template-columns:1fr 1fr 2fr auto"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }
    .page-admin .card-body form[method="POST"] > div[style*="grid-template-columns:1fr 1fr 2fr auto"] > .form-group:nth-child(3),
    .page-admin .card-body form[method="POST"] > div[style*="grid-template-columns:1fr 1fr 2fr auto"] > button {
        grid-column: 1 / -1 !important;
    }
    .page-admin .card-body form[method="POST"] > div[style*="grid-template-columns:1fr 1fr 2fr auto"] > button {
        width: 100% !important;
    }
}

/* Desktop post reply bar must stay in the main column, not cover the left rail */
@media (min-width: 1280px) {
    body.page-post .app-main.has-forum-rail .app-reply-bar {
        left: 244px;
        right: 328px;
    }
}
