/*
 * 柠檬 AI 用户前端统一视觉层
 * 卡片 14-16px，控件 9-10px，单一柠檬黄绿强调色。
 */
:root {
    --ui-page: #f3f5ee;
    --ui-surface: #fcfdf9;
    --ui-surface-muted: #f6f7f2;
    --ui-surface-strong: #e9eddf;
    --ui-text: #22271e;
    --ui-text-soft: #6d7467;
    --ui-text-faint: #989f91;
    --ui-border: #dfe4d8;
    --ui-border-strong: #cfd6c6;
    --ui-accent: #dce96b;
    --ui-accent-hover: #e8f27c;
    --ui-accent-ink: #2b3518;
    --ui-accent-deep: #65751a;
    --ui-deep: #28331d;
    --ui-danger: #a9493e;
    --ui-shadow-sm: 0 7px 22px rgba(54, 64, 42, 0.07);
    --ui-shadow-md: 0 18px 48px rgba(54, 64, 42, 0.11);
    --ui-radius-card: 16px;
    --ui-radius-control: 10px;
    --ui-header-height: 64px;
}

html {
    color-scheme: light dark;
    background: var(--ui-page);
}

body {
    background: var(--ui-page);
    color: var(--ui-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:active,
.btn:active,
a.nav-balance:active {
    transform: translateY(1px);
}

:focus-visible {
    outline: 3px solid rgba(164, 182, 37, 0.34);
    outline-offset: 2px;
}

/* 全站顶栏 */
.header {
    height: var(--ui-header-height);
    border-bottom: 1px solid rgba(207, 214, 198, 0.9);
    background: rgba(252, 253, 249, 0.9);
    box-shadow: none;
    backdrop-filter: blur(18px) saturate(135%);
    -webkit-backdrop-filter: blur(18px) saturate(135%);
}

.navbar {
    width: min(1440px, 100%);
    height: var(--ui-header-height);
    padding: 0 28px;
}

.nav-left {
    gap: 24px;
}

.brand-link {
    gap: 10px;
    color: var(--ui-text);
}

.brand-link span {
    font-size: 17px;
    font-weight: 780;
    letter-spacing: -0.035em;
}

.logo img {
    width: 38px;
    height: 38px;
}

.nav-items {
    align-items: center;
    gap: 5px;
}

.nav-item {
    flex-direction: row;
    min-height: 40px;
    gap: 8px;
    padding: 0 13px;
    border-radius: var(--ui-radius-control);
    color: var(--ui-text-soft);
    transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.nav-item i {
    margin: 0;
    font-size: 14px;
}

.nav-item span {
    font-size: 13px;
    font-weight: 650;
}

.nav-item:hover,
.nav-item.active {
    background: #eef2d8;
    color: #5c6c16;
}

.nav-right {
    gap: 9px;
}

.notification-nav-button {
    position: relative;
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    flex: none;
    color: var(--ui-text-soft);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface);
    text-decoration: none !important;
}
.notification-nav-button:hover,
.notification-nav-button:focus,
.notification-nav-button.active { color: #5c6c16; border-color: #cfd89a; background: #f2f5dc; text-decoration: none !important; }
.notification-nav-button > i {
    display: block;
    line-height: 1;
    text-decoration: none !important;
}
.notification-nav-button > span,
.notification-count {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    padding: 0 5px;
    color: #fff;
    background: #a84b42;
    border: 2px solid var(--ui-surface);
    border-radius: 99px;
    font-size: 8px;
    font-weight: 800;
}
.dropdown-item[data-notification-link] { position: relative; }
.dropdown-item .notification-count { position: static; margin-left: auto; border: 0; }

[data-notification-count][hidden] {
    display: none !important;
}

.notification-nav-button > .notification-dot,
.studio-notification-link > .notification-dot {
    top: -3px;
    right: -3px;
    width: 10px;
    min-width: 10px;
    height: 10px;
    padding: 0;
    border-width: 2px;
    font-size: 0;
}

.nav-balance {
    min-height: 38px;
    padding: 0 11px;
    border-color: #d9dda6;
    border-radius: var(--ui-radius-control);
    background: #f8f8e6;
    color: var(--ui-accent-ink);
}

.nav-balance:hover {
    border-color: #bfc85c;
    background: #f2f5cd;
}

.nav-balance-icon {
    width: 22px;
    height: 22px;
}

.nav-balance-label {
    color: #747b52;
}

.nav-balance strong {
    color: var(--ui-accent-ink);
    font-size: 14px;
    font-weight: 780;
}

.user-avatar {
    appearance: none;
    min-height: 42px;
    padding: 4px 7px;
    border: 1px solid transparent;
    border-radius: var(--ui-radius-control);
    background: transparent;
    color: inherit;
    font: inherit;
}

.user-avatar:hover {
    border-color: var(--ui-border);
    background: var(--ui-surface-muted);
}

.user-avatar img {
    width: 34px;
    height: 34px;
}

.user-avatar img,
.dropdown-avatar,
.sidebar-avatar,
.identity-avatar {
    padding: 0;
    border: 0;
    background: transparent;
    object-fit: cover;
    clip-path: circle(48% at 50% 50%);
}

.nav-username {
    color: var(--ui-text);
}

.user-dropdown {
    width: 268px;
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: 14px;
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-md);
}

.dropdown-header {
    padding: 18px;
    border-color: var(--ui-border);
}

.dropdown-avatar {
    border: 0;
    background: transparent;
}

.username {
    color: var(--ui-text);
    font-weight: 720;
}

.user-level,
.account-state {
    color: var(--ui-text-soft);
}

.account-state {
    margin-top: 2px;
    font-size: 12px;
}

.dropdown-divider {
    background: var(--ui-border);
}

.dropdown-item {
    width: 100%;
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ui-text-soft);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.dropdown-item:hover,
.dropdown-item.active {
    background: #f0f3df;
    color: #637319;
}

.dropdown-item i {
    color: inherit;
}

.guest-nav-actions {
    gap: 8px;
}

.guest-identity {
    color: var(--ui-text-soft);
}

.guest-login-link,
.guest-register-link {
    min-height: 38px;
    padding: 0 14px;
    border-radius: var(--ui-radius-control);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 680;
    text-decoration: none;
}

.guest-login-link {
    border: 1px solid var(--ui-border);
    background: var(--ui-surface);
    color: var(--ui-text);
}

.guest-register-link {
    border: 1px solid var(--ui-deep);
    background: var(--ui-deep);
    color: #f4f7e8;
}

/* 首页 */
.home-page {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 8% 12%, rgba(220, 233, 107, 0.16), transparent 28rem),
        var(--ui-page);
}

.category-nav {
    position: relative;
    padding: 18px 0 16px;
    border-color: var(--ui-border);
    background: rgba(252, 253, 249, 0.76);
}

.category-buttons,
.tags,
.main-content {
    width: min(1440px, 100%);
    padding-inline: 28px;
}

.category-buttons {
    gap: 7px;
    margin-bottom: 11px;
}

.category-btn {
    min-height: 36px;
    padding: 0 14px;
    border-color: var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface);
    color: var(--ui-text-soft);
    font-size: 13px;
    font-weight: 650;
    transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.category-btn:hover,
.category-btn.active {
    border-color: #c5cf62;
    background: var(--ui-accent);
    color: var(--ui-accent-ink);
}

.tags {
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.tags::-webkit-scrollbar {
    display: none;
}

.tag {
    min-height: 29px;
    padding: 0 10px;
    border-color: transparent;
    border-radius: 8px;
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
    font-size: 12px;
}

.tag:hover,
.tag.active {
    border-color: var(--ui-border-strong);
    background: var(--ui-surface-strong);
    color: var(--ui-text);
}

.main-content {
    padding-top: 34px;
    padding-bottom: 70px;
}

.home-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 25px;
}

.home-heading h1 {
    margin: 0;
    color: var(--ui-text);
    font-size: clamp(30px, 4vw, 43px);
    font-weight: 820;
    letter-spacing: -0.055em;
    line-height: 1;
}

.home-heading p {
    margin: 10px 0 0;
    color: var(--ui-text-soft);
    font-size: 14px;
}

.home-heading-mark {
    display: grid;
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border: 1px solid #dcdfa6;
    border-radius: 50%;
    background: #f8f8e7;
    place-items: center;
}

.home-heading-mark img {
    width: 32px;
    height: 32px;
}

.cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}

.card {
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-card);
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-sm);
    transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.card:hover {
    border-color: #cbd29d;
    box-shadow: 0 15px 36px rgba(54, 64, 42, 0.13);
    transform: translateY(-3px);
}

.card-image {
    position: relative;
    height: auto;
    aspect-ratio: 3 / 4;
    background: var(--ui-surface-muted);
}

.community-source-badge {
    position: absolute;
    top: 12px;
    left: 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 9px;
    color: #fff;
    background: rgba(38, 50, 31, .8);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 9px;
    backdrop-filter: blur(8px);
    font-size: 11px;
    font-weight: 750;
}

.community-source-badge i { color: #d2e85e; }
.pending-review-card { box-shadow: inset 0 0 0 1px #d6bc69; }
.pending-review-card .community-source-badge { background: rgba(104, 78, 26, .88); }
.pending-review-card .community-source-badge i { color: #ffe28a; }

.card-image::after {
    position: absolute;
    inset: auto 0 0;
    height: 24%;
    background: linear-gradient(transparent, rgba(24, 29, 19, 0.18));
    content: "";
    pointer-events: none;
}

.card-image img {
    transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}

.card:hover .card-image img {
    transform: scale(1.025);
}

.card-content {
    padding: 16px 16px 15px;
}

.card-title {
    margin-bottom: 7px;
    color: var(--ui-text);
    font-size: 16px;
    font-weight: 730;
    letter-spacing: -0.018em;
}

.card-description {
    margin-bottom: 14px;
    color: var(--ui-text-soft);
    font-size: 13px;
    line-height: 1.55;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.card-stats,
.fire-count,
.author-name,
.publish-time {
    color: var(--ui-text-faint);
}

.author-avatar {
    border: 1px solid var(--ui-border);
}

/* 通用弹窗与角色详情 */
.modal {
    background: rgba(25, 30, 20, 0.62);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
}

.modal-content {
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-card);
    background: var(--ui-surface);
    box-shadow: 0 26px 80px rgba(31, 38, 24, 0.25);
}

.modal-header {
    padding: 19px 22px;
    border-color: var(--ui-border);
}

.modal-header h2,
.character-description h3 {
    color: var(--ui-text);
}

.modal-body {
    padding: 22px;
}

.close {
    color: var(--ui-text-soft);
}

.close:hover {
    color: var(--ui-text);
}

.btn {
    min-height: 40px;
    padding: 0 17px;
    border-radius: var(--ui-radius-control);
    font-weight: 680;
}

.btn-primary {
    background: var(--ui-deep);
    color: #f5f8e8;
}

.btn-primary:hover {
    background: #354225;
}

.btn-secondary,
.character-modal .favorite-btn {
    border-color: var(--ui-border);
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
}

.character-modal {
    max-width: 900px;
}

.character-image img {
    border-radius: 12px;
}

.stat-item {
    border: 1px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface-muted);
}

.stat-label,
.character-description p {
    color: var(--ui-text-soft);
}

.stat-value {
    color: var(--ui-text);
}

.guest-auth-prompt {
    max-width: 430px;
    padding: 32px;
    text-align: center;
}

.guest-auth-avatar {
    border: 1px solid #dcdda8;
    border-radius: 50%;
    background: #f8f8e7;
}

.guest-auth-prompt h2 {
    color: var(--ui-text);
}

.guest-auth-prompt p,
.guest-auth-login {
    color: var(--ui-text-soft);
}

/* 聊天 */
.chat-page {
    background: var(--ui-page);
}

.chat-page .chat-container {
    height: calc(100dvh - var(--ui-header-height));
    background: var(--ui-border);
    gap: 1px;
}

.chat-page .chat-sidebar {
    width: 292px;
    border: 0;
    background: var(--ui-surface-muted);
}

.chat-page .sidebar-header,
.chat-page .chat-actions {
    border-color: var(--ui-border);
}

.chat-page .search-chat {
    min-height: 40px;
    padding: 0 13px;
    border-color: var(--ui-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface);
}

.chat-page .search-chat i,
.chat-page .chat-search-input::placeholder {
    color: var(--ui-text-faint);
}

.chat-page .chat-search-input {
    color: var(--ui-text);
}

.chat-page .action-btn,
.chat-page .chat-settings-btn,
.chat-page .settings-btn {
    border: 1px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface);
    color: var(--ui-text-soft);
}

.chat-page .action-btn:hover,
.chat-page .chat-settings-btn:hover,
.chat-page .settings-btn:hover {
    border-color: var(--ui-border-strong);
    background: var(--ui-surface-strong);
    color: var(--ui-text);
}

.chat-page .chat-action-btn {
    min-height: 42px;
    padding: 0 13px;
    border-color: var(--ui-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface);
    color: var(--ui-text);
    font-weight: 650;
}

.chat-page .chat-action-btn:hover {
    border-color: #c7d067;
    background: #f2f4dd;
}

.chat-page .chat-list {
    padding: 8px 10px 14px;
}

.chat-page .chat-item {
    margin-bottom: 4px;
    padding: 11px;
    border: 1px solid transparent;
    border-radius: 11px;
}

.chat-page .chat-item:hover {
    background: var(--ui-surface);
}

.chat-page .chat-item.active {
    border-color: #d8dda5;
    border-left-color: #aab73d;
    background: #f1f4db;
}

.chat-page .chat-name {
    color: var(--ui-text);
    font-weight: 680;
}

.chat-page .chat-preview {
    color: var(--ui-text-faint);
}

.chat-page .chat-main {
    background:
        radial-gradient(circle at 90% 4%, rgba(220, 233, 107, 0.1), transparent 21rem),
        var(--ui-surface);
}

.chat-page .chat-main.has-character-backdrop {
    background:
        linear-gradient(rgba(252, 253, 249, 0.72), rgba(252, 253, 249, 0.72)),
        var(--chat-character-image) center center / cover no-repeat,
        radial-gradient(circle at 90% 4%, rgba(220, 233, 107, 0.1), transparent 21rem),
        var(--ui-surface);
}

.chat-page .chat-messages {
    padding: 66px clamp(18px, 4vw, 62px) 28px;
    background: transparent;
}

.chat-empty-state {
    display: flex;
    width: min(430px, 100%);
    min-height: 100%;
    margin: 0 auto;
    padding: 40px 20px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.chat-empty-state img {
    width: 72px;
    height: 72px;
    padding: 5px;
    border: 1px solid #dcdda8;
    border-radius: 50%;
    background: #f8f8e7;
}

.chat-empty-state h2 {
    margin: 20px 0 0;
    color: var(--ui-text);
    font-size: 24px;
    font-weight: 770;
    letter-spacing: -0.035em;
}

.chat-empty-state p {
    max-width: 36ch;
    margin: 9px 0 0;
    color: var(--ui-text-soft);
    font-size: 13px;
    line-height: 1.65;
}

.chat-empty-state a {
    display: inline-flex;
    min-height: 40px;
    margin-top: 19px;
    padding: 0 16px;
    align-items: center;
    justify-content: center;
    border-radius: var(--ui-radius-control);
    background: var(--ui-deep);
    color: #f4f7e8;
    font-size: 13px;
    font-weight: 680;
    text-decoration: none;
}

.chat-page .message {
    max-width: min(84%, 900px);
    margin-bottom: 18px;
}

.chat-page .message-avatar {
    width: 40px;
    height: 40px;
    margin-right: 14px;
}

.chat-page .message-avatar img {
    width: 40px;
    height: 40px;
    border: 1px solid var(--ui-border);
    background: var(--ui-surface-muted);
}

.chat-page .chat-item .chat-avatar img {
    width: 46px;
    height: 46px;
}

.chat-page .message-content {
    border: 1px solid var(--ui-border);
    border-radius: 13px;
    background: var(--ui-surface-muted);
    box-shadow: none;
    color: var(--ui-text);
}

.chat-page .message.user-message .message-content {
    border-color: var(--ui-deep);
    background: var(--ui-deep);
    color: #f3f6e8;
}

.chat-page .message.system-message .message-content {
    border-color: var(--ui-border);
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
}

.chat-page .message-text {
    font-size: 17px;
    line-height: 1.72;
}

.chat-page .quote-highlight {
    color: #e39a16 !important;
}

.chat-page .message-actions .action-btn {
    border-color: transparent;
    background: transparent;
}

.chat-page .chat-input-area {
    padding: 15px clamp(18px, 4vw, 62px) calc(15px + env(safe-area-inset-bottom));
    border-color: var(--ui-border);
    background: rgba(252, 253, 249, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.chat-page .message-input-container {
    width: min(900px, 100%);
    min-height: 54px;
    margin: 0 auto;
    padding: 7px 8px 7px 16px;
    border: 1px solid var(--ui-border-strong);
    border-radius: 14px;
    background: var(--ui-surface);
    box-shadow: 0 8px 25px rgba(54, 64, 42, 0.07);
}

.chat-page .message-input-container:focus-within {
    border-color: #aeba3e;
    background: var(--ui-surface);
    box-shadow: 0 0 0 3px rgba(174, 186, 62, 0.17), 0 8px 25px rgba(54, 64, 42, 0.08);
}

.chat-page .message-input {
    color: var(--ui-text);
    font-size: 15px;
}

.chat-page .message-input::placeholder {
    color: var(--ui-text-faint);
}

.chat-page .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--ui-deep);
    color: #f4f7e8;
}

.chat-page .send-btn:hover {
    background: #354225;
    transform: none;
}

.chat-page .send-btn:disabled {
    background: var(--ui-surface-strong);
    color: var(--ui-text-faint);
}

.chat-page .chat-settings {
    border-color: var(--ui-border);
    background: var(--ui-surface-muted);
}

.chat-page .settings-header,
.chat-page .setting-group {
    border-color: var(--ui-border);
}

.chat-page .settings-header h3,
.chat-page .setting-label,
.chat-page .mobile-setting-group-title {
    color: var(--ui-text);
}

.chat-page .setting-input,
.chat-page .mobile-session-input,
.chat-page .mobile-setting-input,
.chat-page .edit-textarea {
    border-color: var(--ui-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface);
    color: var(--ui-text);
}

.chat-page .toggle-switch input:checked + .toggle-slider,
.chat-page .mobile-toggle-switch input:checked + .mobile-toggle-slider {
    background: #aeba3e;
}

.chat-page .session-btn {
    border-radius: var(--ui-radius-control);
}

.chat-page .mobile-character-panel,
.chat-page .mobile-settings-panel {
    background: var(--ui-surface);
    color: var(--ui-text);
}

/* 登录、注册、找回与重置 */
.login-page,
.register-page {
    min-height: 100dvh;
    padding: 28px;
    background:
        radial-gradient(circle at 12% 15%, rgba(220, 233, 107, 0.2), transparent 30rem),
        var(--ui-page);
}

.login-container {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
    width: min(960px, 100%);
    max-width: none;
    min-height: 620px;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: 20px;
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-md);
}

.auth-side {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 42px;
    background:
        radial-gradient(circle at 100% 0, rgba(220, 233, 107, 0.23), transparent 21rem),
        var(--ui-deep);
    color: #f3f6e7;
}

.auth-side-brand {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 10px;
    color: #f3f6e7;
    font-size: 17px;
    font-weight: 780;
    text-decoration: none;
}

.auth-side-brand img {
    width: 42px;
    height: 42px;
    padding: 2px;
    border: 1px solid rgba(236, 242, 180, 0.35);
    border-radius: 50%;
    background: rgba(248, 249, 229, 0.12);
}

.auth-side-copy {
    max-width: 430px;
}

.auth-side-copy h1 {
    margin: 0;
    color: #f5f7eb;
    font-size: clamp(36px, 4vw, 50px);
    font-weight: 820;
    letter-spacing: -0.065em;
    line-height: 1.02;
}

.auth-side-copy p {
    max-width: 32ch;
    margin: 17px 0 0;
    color: #c8cfb9;
    font-size: 14px;
    line-height: 1.7;
}

.auth-side-link {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    gap: 9px;
    color: #d8dec9;
    font-size: 13px;
    font-weight: 650;
    text-decoration: none;
}

.auth-side-link:hover {
    color: var(--ui-accent);
}

.login-card {
    align-self: center;
    width: 100%;
    max-width: none;
    padding: 48px;
    border: 0;
    border-radius: 0;
    background: var(--ui-surface);
    box-shadow: none;
    animation: none;
}

.login-header {
    margin-bottom: 29px;
    text-align: left;
}

.auth-brand-avatar {
    width: 58px;
    height: 58px;
    margin: 0 0 18px;
    padding: 4px;
    border: 1px solid #dcdda8;
    border-radius: 50%;
    background: #f8f8e7;
}

.login-header h2 {
    margin-bottom: 7px;
    color: var(--ui-text);
    font-size: 30px;
    font-weight: 790;
    letter-spacing: -0.045em;
}

.login-header .subtitle {
    margin: 0;
    color: var(--ui-text-soft);
}

.login-form .form-group {
    margin-bottom: 18px;
}

.login-form .form-group label {
    margin-bottom: 7px;
    color: var(--ui-text);
    font-size: 13px;
    font-weight: 680;
}

.login-form .form-group input {
    min-height: 46px;
    padding: 0 13px;
    border: 1px solid var(--ui-border-strong);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface-muted);
    color: var(--ui-text);
    font-size: 15px;
}

.login-form .form-group input::placeholder {
    color: var(--ui-text-faint);
}

.login-form .form-group input:focus {
    border-color: #aeba3e;
    box-shadow: 0 0 0 3px rgba(174, 186, 62, 0.17);
}

.form-helper,
.account-recovery-note {
    color: var(--ui-text-soft);
}

.form-options {
    margin-bottom: 23px;
}

.checkbox-label {
    color: var(--ui-text-soft);
}

.checkmark {
    border-color: var(--ui-border-strong);
    background: var(--ui-surface);
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    border-color: #9eac32;
    background: #9eac32;
}

.forgot-password,
.register-link a {
    color: #667718;
    font-weight: 650;
}

.forgot-password:hover,
.register-link a:hover {
    color: #526112;
}

.login-btn,
.register-btn {
    min-height: 46px;
    margin: 4px 0 18px;
    padding: 0 16px;
    border-radius: var(--ui-radius-control);
    background: var(--ui-deep);
    color: #f5f8e9;
    font-size: 15px;
    font-weight: 720;
}

.login-btn:hover,
.register-btn:hover {
    background: #354225;
}

.register-link {
    color: var(--ui-text-soft);
}

.generated-username-field {
    grid-template-columns: minmax(0, 1fr) 78px;
}

.generated-username-field input[readonly] {
    background: var(--ui-surface-strong);
    color: var(--ui-text);
}

.regenerate-username-btn {
    border-color: var(--ui-border-strong);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface);
    color: var(--ui-text);
}

.regenerate-username-btn:hover {
    border-color: #aeba3e;
    color: #5f7016;
}

.error-message,
.success-message {
    border: 1px solid;
    border-left-width: 1px;
    border-radius: var(--ui-radius-control);
}

.error-message {
    border-color: #e2b2ac;
    background: #fff3f1;
    color: #914137;
}

.success-message {
    border-color: #bad3ac;
    background: #f0f7eb;
    color: #4c742f;
}

/* 账户中心与独立充值页衔接 */
.account-page,
.payment-main {
    background:
        radial-gradient(circle at 8% 12%, rgba(220, 233, 107, 0.16), transparent 28rem),
        var(--ui-page);
}

.account-page .identity-panel,
.account-page .records-panel,
.account-page .security-panel {
    border-color: var(--ui-border);
    background: var(--ui-surface);
}

.account-page .wallet-panel {
    background: var(--ui-deep);
}

.account-page .wallet-recharge {
    background: var(--ui-accent);
    color: var(--ui-accent-ink);
}

.account-page .account-intro h1 {
    color: var(--ui-text);
}

.account-page .account-intro > p:last-child,
.account-page .identity-label,
.account-page .identity-meta {
    color: var(--ui-text-soft);
}

.payment-main .checkout-shell {
    color: var(--ui-text);
}

.payment-main .checkout-section,
.payment-main .summary-card {
    border-color: var(--ui-border);
    border-radius: var(--ui-radius-card);
    background: var(--ui-surface);
    box-shadow: var(--ui-shadow-sm);
}

.payment-main .amount-btn,
.payment-main .channel-card,
.payment-main .amount-input-wrap {
    border-color: var(--ui-border);
    border-radius: var(--ui-radius-control);
    background: var(--ui-surface-muted);
}

.payment-main .amount-btn.active,
.payment-main .channel-card.active {
    border-color: #b7c44d;
    background: #f2f4dc;
}

.payment-main .pay-btn {
    border-radius: var(--ui-radius-control);
    background: var(--ui-deep);
    color: #f5f8e9;
}

/* 充值弹窗 */
.payment-modal {
    background: rgba(25, 30, 20, 0.66);
}

.payment-dialog {
    border: 1px solid var(--ui-border);
    border-radius: 18px;
    background: var(--ui-surface);
    color: var(--ui-text);
    box-shadow: 0 28px 90px rgba(31, 38, 24, 0.29);
}

.payment-modal-header,
.payment-modal-footer {
    border-color: var(--ui-border);
    background: var(--ui-surface);
}

.payment-modal-header h2,
.payment-modal-section h3,
.payment-summary-title,
.payment-channel-name {
    color: var(--ui-text);
}

.payment-modal-header p,
.payment-plan-detail,
.payment-channel-desc,
.payment-custom-copy p {
    color: var(--ui-text-soft);
}

.payment-plan,
.payment-channel-option,
.payment-custom-input,
.payment-credit-summary {
    border-color: var(--ui-border);
    border-radius: 12px;
    background: var(--ui-surface-muted);
}

.payment-plan:hover,
.payment-plan.is-selected,
.payment-channel-option:has(input:checked) {
    border-color: #b6c348;
    background: #f2f4dc;
}

.payment-modal-submit {
    border-radius: var(--ui-radius-control);
    background: var(--ui-deep);
    color: #f5f8e9;
}

.payment-modal-submit:hover:not(:disabled) {
    background: #354225;
}

.payment-modal-close {
    border-color: var(--ui-border);
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
}

.payment-modal-error {
    border-radius: var(--ui-radius-control);
}

/* 侧边栏 */
.sidebar-overlay {
    background: rgba(25, 30, 20, 0.55);
}

.sidebar-panel {
    border-left: 1px solid var(--ui-border);
    background: var(--ui-surface);
    box-shadow: -18px 0 48px rgba(54, 64, 42, 0.14);
}

.sidebar-header {
    border-color: var(--ui-border);
}

.sidebar-username,
.sidebar-item {
    color: var(--ui-text);
}

.sidebar-user-level {
    color: var(--ui-text-soft);
}

.sidebar-item:hover,
.sidebar-item-blue {
    background: #f0f3df;
    color: #637319;
}

/* 响应式 */
@media (max-width: 900px) {
    .login-page,
    .register-page {
        padding: 18px;
    }

    .login-container {
        grid-template-columns: 1fr;
        width: min(520px, 100%);
        min-height: 0;
    }

    .auth-side {
        min-height: 190px;
        padding: 26px 30px;
    }

    .auth-side-copy h1 {
        font-size: 34px;
    }

    .auth-side-copy p {
        margin-top: 9px;
    }

    .auth-side-link {
        display: none;
    }

    .login-card {
        padding: 36px 30px;
    }
}

@media (max-width: 768px) {
    :root {
        --ui-header-height: 60px;
    }

    .header,
    .navbar {
        height: var(--ui-header-height);
    }

    .header {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .navbar {
        gap: 8px;
        padding: 0 10px;
    }

    .nav-left {
        flex: 1 1 auto;
        gap: 8px;
        min-width: 0;
    }

    .logo,
    .brand-link {
        flex: 0 0 auto;
    }

    .brand-link span,
    .nav-username,
    .nav-balance-label {
        display: none;
    }

    .logo img {
        width: 42px;
        height: 42px;
        transform: translateY(3px);
    }

    .nav-items {
        gap: 1px;
        overflow: visible;
    }

    .nav-item {
        min-width: 38px;
        min-height: 38px;
        justify-content: center;
        padding: 0 9px;
    }

    .nav-item span {
        display: none;
    }

    .nav-right {
        flex: 0 0 auto;
        gap: 5px;
        margin-left: auto;
    }

    .nav-right > .user-menu {
        order: 20;
    }

    .nav-balance {
        min-height: 36px;
        padding: 0 8px;
    }

    .user-avatar {
        min-width: 42px;
        min-height: 42px;
        justify-content: center;
        padding: 2px;
    }

    .user-avatar img {
        width: 36px;
        height: 36px;
    }

    .dropdown-arrow {
        display: none;
    }

    .guest-identity {
        display: none;
    }

    .guest-login-link,
    .guest-register-link {
        min-height: 36px;
        padding: 0 10px;
        font-size: 12px;
    }

    .category-nav {
        padding: 12px 0;
    }

    .category-buttons,
    .tags,
    .main-content {
        padding-inline: 14px;
    }

    .category-buttons {
        overflow-x: auto;
        scrollbar-width: none;
    }

    .category-buttons::-webkit-scrollbar {
        display: none;
    }

    .main-content {
        padding-top: 26px;
        padding-bottom: 46px;
    }

    .home-heading {
        margin-bottom: 20px;
    }

    .home-heading h1 {
        font-size: 32px;
    }

    .home-heading-mark {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }

    .cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }

    .cards-grid .card {
        display: block;
        min-width: 0;
        border-radius: 13px;
    }

    .cards-grid .card-image {
        width: 100%;
        height: auto;
        aspect-ratio: 3 / 4;
        flex: none;
        border-radius: 0;
    }

    .cards-grid .card-content {
        display: block;
        min-width: 0;
        padding: 12px;
    }

    .cards-grid .card-title {
        font-size: 14px;
        line-height: 1.4;
    }

    .cards-grid .card-description {
        font-size: 12px;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }

    .cards-grid .card-stats {
        gap: 8px;
        font-size: 10px;
    }

    .cards-grid .card-stats .author-info {
        min-width: 0;
    }

    .cards-grid .card-stats .author-name,
    .cards-grid .card-stats .publish-time {
        font-size: 10px;
    }

    .chat-page .chat-container {
        height: calc(100dvh - var(--ui-header-height));
    }

    .chat-page .chat-messages {
        padding: 58px 14px 18px;
    }

    .chat-page .message {
        max-width: 96%;
    }

    .chat-page .message.ai-message {
        margin-right: 4%;
    }

    .chat-page .message.user-message {
        margin-left: 8%;
    }

    .chat-page .message-avatar {
        width: 42px;
        height: 42px;
        margin-right: 10px;
    }

    .chat-page .message-avatar img {
        width: 42px;
        height: 42px;
    }

    .chat-page .chat-item .chat-avatar img {
        width: 32px;
        height: 32px;
    }

    .chat-page .message-text {
        font-size: 16px;
        line-height: 1.72;
    }

    .chat-page .chat-input-area {
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }

    .chat-page .message-input-container {
        min-height: 50px;
        border-radius: 13px;
    }

    #characterModal.modal.show {
        align-items: flex-start;
        padding: calc(16px + env(safe-area-inset-top)) 0 0;
    }

    #characterModal .modal-content.character-modal {
        height: calc((var(--vh, 1vh) * 100) - 16px - env(safe-area-inset-top));
        max-height: calc((var(--vh, 1vh) * 100) - 16px - env(safe-area-inset-top));
        padding-top: 0;
        border-radius: 16px 16px 0 0;
    }

    #characterModal .character-modal .modal-header {
        top: 0;
    }
}

@media (max-width: 520px) {
    .cards-grid .card-content {
        padding: 11px;
    }

    .cards-grid .card-description {
        margin-bottom: 10px;
    }

    .cards-grid .card-stats .author-avatar,
    .cards-grid .card-stats .publish-time {
        display: none;
    }

    .login-page,
    .register-page {
        align-items: flex-start;
        padding: 0;
        background: var(--ui-surface);
    }

    .login-container {
        min-height: 100dvh;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .auth-side {
        min-height: 150px;
        padding: 22px;
    }

    .auth-side-copy h1 {
        font-size: 28px;
    }

    .auth-side-copy p {
        font-size: 12px;
    }

    .auth-side-brand img {
        width: 36px;
        height: 36px;
    }

    .login-card {
        padding: 31px 22px 42px;
    }

    .auth-brand-avatar {
        width: 52px;
        height: 52px;
    }

    .login-header h2 {
        font-size: 27px;
    }

    .home-heading-mark {
        display: none;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --ui-page: #151812;
        --ui-surface: #1d2119;
        --ui-surface-muted: #24291f;
        --ui-surface-strong: #2d3327;
        --ui-text: #edf0e6;
        --ui-text-soft: #a9b0a1;
        --ui-text-faint: #7f8778;
        --ui-border: #363c31;
        --ui-border-strong: #485042;
        --ui-deep: #354421;
        --ui-accent-ink: #303918;
        --ui-shadow-sm: 0 8px 24px rgba(6, 8, 5, 0.2);
        --ui-shadow-md: 0 20px 55px rgba(6, 8, 5, 0.32);
    }

    .header {
        border-color: var(--ui-border);
        background: rgba(24, 28, 21, 0.91);
    }

    .nav-item:hover,
    .nav-item.active,
    .dropdown-item:hover,
    .dropdown-item.active,
    .sidebar-item:hover,
    .sidebar-item-blue {
        background: #2c321f;
        color: #dce86b;
    }

    .nav-balance,
    .home-heading-mark,
    .guest-auth-avatar,
    .auth-brand-avatar {
        border-color: #555d39;
        background: #2b311f;
    }

    .nav-balance:hover {
        border-color: #7c883c;
        background: #323923;
    }

    .nav-balance-label {
        color: #aeb58c;
    }

    .nav-balance strong {
        color: #edf2b9;
    }

    .category-nav {
        background: rgba(29, 33, 25, 0.78);
    }

    .category-btn:hover,
    .category-btn.active {
        border-color: #8c983c;
        background: #aeba3e;
        color: #1d2511;
    }

    .card-image::after {
        background: linear-gradient(transparent, rgba(10, 13, 8, 0.3));
    }

    .btn-primary,
    .login-btn,
    .register-btn,
    .payment-modal-submit,
    .payment-main .pay-btn {
        background: #aeba3e;
        color: #20270f;
    }

    .btn-primary:hover,
    .login-btn:hover,
    .register-btn:hover,
    .payment-modal-submit:hover:not(:disabled) {
        background: #bfca50;
    }

    .chat-page .chat-item.active,
    .chat-page .chat-action-btn:hover,
    .payment-plan.is-selected,
    .payment-channel-option:has(input:checked),
    .payment-main .amount-btn.active,
    .payment-main .channel-card.active {
        border-color: #596336;
        background: #2b311f;
    }

    .chat-page .message.user-message .message-content,
    .chat-page .send-btn {
        border-color: #4b5b2c;
        background: #3b4a27;
        color: #f1f4e7;
    }

    .chat-page .chat-input-area {
        background: rgba(29, 33, 25, 0.91);
    }

    .chat-page .chat-main.has-character-backdrop {
        background:
            linear-gradient(rgba(29, 33, 25, 0.76), rgba(29, 33, 25, 0.76)),
            var(--chat-character-image) center center / cover no-repeat,
            radial-gradient(circle at 90% 4%, rgba(220, 233, 107, 0.08), transparent 21rem),
            var(--ui-surface);
    }

    .auth-side {
        background:
            radial-gradient(circle at 100% 0, rgba(220, 233, 107, 0.12), transparent 21rem),
            #26311c;
    }

    .forgot-password,
    .register-link a {
        color: #d1dd63;
    }

    .error-message {
        border-color: #68403a;
        background: #36231f;
        color: #f0aaa1;
    }

    .success-message {
        border-color: #405b34;
        background: #20301d;
        color: #acd296;
    }
}

/* 社区叙事资源库与新版设置面板 */
.story-resource-launchers {
    display: grid;
    gap: 9px;
}

.story-setting-resource {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 16px;
    width: 100%;
    min-height: 74px;
    padding: 11px 12px;
    align-items: center;
    gap: 11px;
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    background: var(--ui-surface);
    color: var(--ui-text);
    cursor: pointer;
    text-align: left;
    transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.story-setting-resource:hover {
    border-color: #bec861;
    background: color-mix(in srgb, var(--ui-accent) 9%, var(--ui-surface));
    transform: translateY(-1px);
}

.story-setting-resource-icon,
.mobile-story-resource-icon {
    display: inline-flex;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--ui-surface-strong);
    color: var(--ui-accent-deep);
}

.story-setting-resource-copy {
    display: block;
    min-width: 0;
}

.story-setting-resource-copy small,
.story-setting-resource-copy strong,
.story-setting-resource-copy > span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-setting-resource-copy small {
    color: var(--ui-text-faint);
    font-size: 9px;
    font-weight: 720;
}

.story-setting-resource-copy strong {
    margin-top: 2px;
    font-size: 12px;
    font-weight: 760;
}

.story-setting-resource-copy > span {
    margin-top: 3px;
    color: var(--ui-text-soft);
    font-size: 9px;
}

.story-setting-resource > .fa-chevron-right {
    color: var(--ui-text-faint);
    font-size: 10px;
}

.story-resource-manager {
    width: min(1060px, 100%);
    max-width: 1060px;
    height: min(820px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.story-resource-manager > .modal-header {
    flex: 0 0 auto;
}

.resource-type-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 0 0 auto;
    padding: 14px 22px 0;
    gap: 9px;
}

.resource-type-switch button {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    min-height: 58px;
    padding: 9px 13px;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
    cursor: pointer;
    text-align: left;
}

.resource-type-switch button.active {
    border-color: #b9c451;
    background: color-mix(in srgb, var(--ui-accent) 13%, var(--ui-surface));
    color: var(--ui-text);
}

.resource-type-switch button > i {
    color: var(--ui-accent-deep);
    font-size: 17px;
    text-align: center;
}

.resource-type-switch strong,
.resource-type-switch small {
    display: block;
}

.resource-type-switch strong {
    font-size: 13px;
}

.resource-type-switch small {
    margin-top: 2px;
    color: var(--ui-text-faint);
    font-size: 10px;
}

.resource-browser-toolbar {
    display: grid;
    grid-template-columns: auto minmax(190px, 1fr) auto auto;
    flex: 0 0 auto;
    padding: 13px 22px;
    align-items: center;
    gap: 9px;
    border-bottom: 1px solid var(--ui-border);
}

.resource-scope-switch,
.resource-sort-switch {
    display: inline-grid;
    grid-auto-flow: column;
    padding: 3px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface-muted);
}

.resource-scope-switch button,
.resource-sort-switch button {
    min-height: 32px;
    padding: 0 11px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ui-text-soft);
    cursor: pointer;
    font-size: 10px;
    font-weight: 680;
    white-space: nowrap;
}

.resource-scope-switch button.active,
.resource-sort-switch button.active {
    background: var(--ui-surface);
    color: var(--ui-text);
    box-shadow: 0 2px 8px rgba(54, 64, 42, .08);
}

.resource-library-search {
    display: flex;
    min-height: 40px;
    padding: 0 12px;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    color: var(--ui-text-faint);
}

.resource-library-search input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ui-text);
    font-size: 11px;
}

.resource-owner-actions {
    display: flex;
    gap: 6px;
}

.resource-owner-actions[hidden],
.resource-sort-switch[hidden] {
    display: none;
}

.resource-owner-actions button {
    min-height: 38px;
    padding: 0 11px;
    border: 1px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface);
    color: var(--ui-text);
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
    white-space: nowrap;
}

.resource-owner-actions #newStoryResource {
    border-color: var(--ui-deep);
    background: var(--ui-deep);
    color: #f5f8e8;
}

.resource-library-status {
    min-height: 25px;
    padding: 8px 22px 0;
    color: var(--ui-text-faint);
    font-size: 10px;
}

.resource-market-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px 22px 24px;
    align-content: start;
    overflow-y: auto;
    gap: 10px;
}

.resource-market-card {
    min-width: 0;
    position: relative;
    border: 1px solid var(--ui-border);
    border-radius: 13px;
    background: var(--ui-surface-muted);
    overflow: hidden;
    transition: transform 160ms ease, border-color 160ms ease;
}

.resource-market-card:hover {
    border-color: var(--ui-border-strong);
    transform: translateY(-1px);
}

.resource-market-card.selected {
    border-color: #aeba3e;
    box-shadow: inset 0 0 0 1px rgba(174, 186, 62, .2);
}

.resource-market-select {
    display: block;
    width: 100%;
    min-height: 174px;
    padding: 15px;
    border: 0;
    background: transparent;
    color: var(--ui-text);
    cursor: pointer;
    text-align: left;
}

.resource-market-card-topline,
.resource-market-meta {
    display: flex;
    align-items: center;
}

.resource-market-card-topline {
    padding-right: 28px;
    justify-content: space-between;
    gap: 8px;
}

.resource-market-card-topline span {
    color: var(--ui-accent-deep);
    font-size: 9px;
    font-weight: 760;
}

.resource-market-card-topline em {
    color: var(--ui-text-faint);
    font-size: 9px;
    font-style: normal;
}

.resource-market-card.selected .resource-market-card-topline em {
    color: var(--ui-accent-deep);
    font-weight: 740;
}

.resource-market-select > strong {
    display: block;
    margin-top: 11px;
    padding-right: 24px;
    overflow: hidden;
    font-size: 14px;
    font-weight: 760;
    letter-spacing: -.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resource-market-select > p {
    display: -webkit-box;
    min-height: 35px;
    margin: 6px 0 13px;
    overflow: hidden;
    color: var(--ui-text-soft);
    font-size: 10px;
    line-height: 1.65;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

.resource-market-meta {
    flex-wrap: wrap;
    gap: 5px 12px;
    color: var(--ui-text-faint);
    font-size: 9px;
}

.resource-market-meta i {
    width: 11px;
    color: var(--ui-text-soft);
}

.resource-market-edit {
    width: 30px;
    height: 30px;
    position: absolute;
    top: 10px;
    right: 10px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    color: var(--ui-text-soft);
    cursor: pointer;
}

.resource-market-edit:hover {
    border-color: #aeba3e;
    color: var(--ui-accent-deep);
}

.resource-library-empty {
    grid-column: 1 / -1;
    display: flex;
    min-height: 270px;
    padding: 30px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.resource-library-empty > i {
    width: 50px;
    height: 50px;
    padding-top: 16px;
    border-radius: 12px;
    background: var(--ui-surface-strong);
    color: var(--ui-accent-deep);
}

.resource-library-empty strong {
    margin-top: 14px;
    color: var(--ui-text);
    font-size: 14px;
}

.resource-library-empty p {
    max-width: 34ch;
    margin: 6px 0 0;
    color: var(--ui-text-soft);
    font-size: 11px;
    line-height: 1.6;
}

.resource-publish-toggle {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    padding: 12px;
    align-items: start;
    gap: 9px;
    border: 1px solid var(--ui-border);
    border-radius: 11px;
    background: color-mix(in srgb, var(--ui-accent) 8%, var(--ui-surface));
    cursor: pointer;
}

.resource-publish-toggle input {
    margin-top: 2px;
    accent-color: #74831e;
}

.resource-publish-toggle > span {
    margin: 0;
}

.resource-publish-toggle strong,
.resource-publish-toggle small {
    display: block;
}

.resource-publish-toggle strong {
    color: var(--ui-text);
    font-size: 11px;
}

.resource-publish-toggle small {
    margin-top: 3px;
    color: var(--ui-text-soft);
    font-size: 10px;
    font-weight: 400;
}

@media (max-width: 768px) {
    .mobile-settings-overlay,
    .mobile-settings-overlay.show {
        top: 0 !important;
        bottom: 0;
        z-index: 3000;
        padding: 0;
    }

    .mobile-settings-panel {
        background: var(--ui-page);
        box-shadow: none;
    }

    .mobile-settings-header {
        min-height: 76px;
        height: auto;
        padding: calc(15px + env(safe-area-inset-top)) 18px 14px;
        align-items: center;
        border-color: var(--ui-border);
        background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
        box-shadow: none;
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
    }

    .mobile-settings-header h2,
    .mobile-settings-header p {
        margin: 0;
    }

    .mobile-settings-header h2 {
        color: var(--ui-text);
        font-size: 19px;
        font-weight: 770;
        letter-spacing: -.025em;
    }

    .mobile-settings-header p {
        margin-top: 3px;
        color: var(--ui-text-faint);
        font-size: 10px;
    }

    .mobile-settings-close {
        width: 38px;
        height: 38px;
        border: 1px solid var(--ui-border);
        border-radius: 10px;
        background: var(--ui-surface);
        color: var(--ui-text-soft);
    }

    .mobile-settings-content {
        display: grid;
        align-content: start;
        padding: 16px 16px calc(100px + env(safe-area-inset-bottom));
        gap: 14px;
    }

    .mobile-story-resource-section,
    .mobile-settings-sheet {
        padding: 14px;
        border: 1px solid var(--ui-border);
        border-radius: 14px;
        background: var(--ui-surface);
    }

    .mobile-story-resource-section > h3,
    .mobile-settings-sheet > h3 {
        margin: 0 0 11px;
        color: var(--ui-text);
        font-size: 12px;
        font-weight: 760;
    }

    .mobile-story-resource-card {
        display: grid;
        grid-template-columns: 42px minmax(0, 1fr) 14px;
        width: 100%;
        min-height: 68px;
        padding: 9px 4px;
        align-items: center;
        gap: 10px;
        border: 0;
        border-bottom: 1px solid var(--ui-border);
        background: transparent;
        color: var(--ui-text);
        cursor: pointer;
        text-align: left;
    }

    .mobile-story-resource-card:last-child {
        border-bottom: 0;
    }

    .mobile-story-resource-card > span:nth-child(2) {
        min-width: 0;
    }

    .mobile-story-resource-card small,
    .mobile-story-resource-card strong,
    .mobile-story-resource-card em {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-story-resource-card small {
        color: var(--ui-text-faint);
        font-size: 9px;
    }

    .mobile-story-resource-card strong {
        margin-top: 2px;
        font-size: 13px;
    }

    .mobile-story-resource-card em {
        margin-top: 3px;
        color: var(--ui-text-soft);
        font-size: 9px;
        font-style: normal;
    }

    .mobile-story-resource-card > .fa-chevron-right {
        color: var(--ui-text-faint);
        font-size: 10px;
    }

    .mobile-settings-sheet {
        display: grid;
        gap: 12px;
    }

    .mobile-settings-field {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(120px, 1.35fr);
        min-height: 48px;
        align-items: center;
        gap: 10px;
    }

    .mobile-settings-field > span {
        color: var(--ui-text-soft);
        font-size: 11px;
        font-weight: 650;
    }

    .mobile-settings-field .mobile-session-input,
    .mobile-settings-field .mobile-setting-input {
        min-height: 40px;
        padding: 0 11px;
        border-color: var(--ui-border);
        border-radius: 9px;
        background: var(--ui-surface-muted);
        color: var(--ui-text);
        font-size: 13px;
    }

    .mobile-settings-toggle-row {
        display: flex;
        min-height: 48px;
        align-items: center;
        justify-content: space-between;
        color: var(--ui-text-soft);
        font-size: 11px;
        font-weight: 650;
    }

    .mobile-settings-toggle-row i {
        width: 18px;
        color: var(--ui-accent-deep);
    }

    .mobile-toggle-switch {
        width: 44px;
        height: 24px;
    }

    .mobile-toggle-slider:before {
        width: 18px;
        height: 18px;
    }

    .mobile-toggle-switch input:checked + .mobile-toggle-slider:before {
        transform: translateX(20px);
    }

    .mobile-settings-quick-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 9px;
    }

    .mobile-settings-quick-actions .mobile-setting-item {
        min-height: 48px;
        padding: 0 12px;
        justify-content: center;
        gap: 8px;
        border: 1px solid var(--ui-border);
        border-radius: 11px;
        background: var(--ui-surface);
        color: var(--ui-text);
        font-size: 11px;
        font-weight: 680;
    }

    .mobile-settings-quick-actions .mobile-setting-item i {
        color: var(--ui-accent-deep);
    }

    .mobile-delete-session-footer {
        position: absolute;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
        border-color: var(--ui-border);
        background: color-mix(in srgb, var(--ui-surface) 95%, transparent);
        box-shadow: 0 -8px 22px rgba(54, 64, 42, .06);
        backdrop-filter: blur(14px);
        -webkit-backdrop-filter: blur(14px);
    }

    .mobile-delete-session-btn {
        min-height: 44px;
        border: 1px solid color-mix(in srgb, var(--ui-danger) 32%, var(--ui-border));
        border-radius: 11px;
        background: var(--ui-surface);
        color: var(--ui-danger);
        box-shadow: none;
    }

    .story-resource-manager {
        height: 100dvh;
        max-height: 100dvh;
    }

    .story-resource-manager > .modal-header {
        padding: calc(16px + env(safe-area-inset-top)) 17px 13px;
    }

    .story-resource-manager .modal-header p {
        max-width: 30ch;
        font-size: 10px;
    }

    .resource-type-switch {
        padding: 10px 14px 0;
        gap: 7px;
    }

    .resource-type-switch button {
        grid-template-columns: 30px minmax(0, 1fr);
        min-height: 52px;
        padding: 7px 9px;
        gap: 6px;
    }

    .resource-type-switch button > i {
        font-size: 14px;
    }

    .resource-type-switch strong {
        font-size: 12px;
    }

    .resource-type-switch small {
        display: none;
    }

    .resource-browser-toolbar {
        grid-template-columns: 1fr 1fr;
        padding: 10px 14px;
        gap: 8px;
    }

    .resource-scope-switch {
        grid-column: 1 / -1;
        width: 100%;
    }

    .resource-scope-switch button {
        width: 100%;
    }

    .resource-library-search {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    .resource-sort-switch,
    .resource-owner-actions {
        width: 100%;
    }

    .resource-sort-switch button,
    .resource-owner-actions button {
        flex: 1;
        width: 100%;
    }

    .resource-owner-actions {
        grid-column: 1 / -1;
    }

    .resource-library-status {
        padding: 7px 14px 0;
    }

    .resource-market-grid {
        grid-template-columns: 1fr;
        padding: 8px 14px calc(24px + env(safe-area-inset-bottom));
    }

    .resource-market-select {
        min-height: 154px;
        padding: 14px;
    }
}

@media (prefers-color-scheme: dark) {
    .resource-market-card,
    .resource-type-switch button,
    .mobile-story-resource-section,
    .mobile-settings-sheet {
        background: var(--ui-surface-muted);
    }

    .resource-market-card.selected,
    .resource-type-switch button.active,
    .resource-publish-toggle {
        border-color: #65722f;
        background: #2b311f;
    }
}

@media (prefers-reduced-motion: reduce) {
    .story-setting-resource,
    .resource-market-card {
        transition: none;
    }
}

/* 叙事工作台：角色、预设、世界书与富文本输出 */
body.modal-open {
    overflow: hidden;
}

.chat-page .chat-header {
    position: relative;
    inset: auto;
    z-index: 12;
    display: flex;
    width: 100%;
    min-height: 76px;
    padding: 12px clamp(18px, 3vw, 38px);
    align-items: center;
    gap: 20px;
    border-bottom: 1px solid var(--ui-border);
    background: color-mix(in srgb, var(--ui-surface) 91%, transparent);
    backdrop-filter: blur(18px) saturate(130%);
    -webkit-backdrop-filter: blur(18px) saturate(130%);
}

.story-header-identity {
    display: flex;
    min-width: 184px;
    align-items: center;
    gap: 11px;
}

.story-header-identity img {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border: 1px solid var(--ui-border-strong);
    border-radius: 12px;
    background: var(--ui-surface-strong);
}

.story-header-identity h1,
.story-header-identity p {
    margin: 0;
}

.story-header-identity h1 {
    overflow: hidden;
    color: var(--ui-text);
    font-size: 15px;
    font-weight: 760;
    letter-spacing: -0.015em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-header-identity p {
    margin-top: 2px;
    color: var(--ui-text-faint);
    font-size: 11px;
}

.active-context-dock {
    display: flex;
    min-width: 0;
    margin-left: auto;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.context-chip {
    display: grid;
    min-height: 42px;
    padding: 6px 12px 6px 36px;
    position: relative;
    border: 1px solid var(--ui-border);
    border-radius: 11px;
    background: var(--ui-surface-muted);
    color: var(--ui-text);
    cursor: pointer;
    text-align: left;
    transition: border-color 160ms ease, background-color 160ms ease;
}

.context-chip:hover {
    border-color: #bdc75d;
    background: #f1f4dc;
}

.context-chip i {
    position: absolute;
    top: 13px;
    left: 13px;
    color: var(--ui-accent-deep);
    font-size: 13px;
}

.context-chip span {
    color: var(--ui-text-faint);
    font-size: 9px;
    font-weight: 760;
    letter-spacing: .08em;
    line-height: 1.2;
    text-transform: uppercase;
}

.context-chip strong {
    max-width: 170px;
    overflow: hidden;
    font-size: 11px;
    font-weight: 680;
    line-height: 1.4;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-page .chat-header .chat-settings-btn {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    position: static;
    z-index: auto;
}

.chat-page .chat-messages {
    padding-top: 34px;
}

.chat-page .message {
    width: min(880px, 88%);
    max-width: min(880px, 88%);
    margin-bottom: 26px;
}

.chat-page .message.ai-message .message-content {
    min-width: min(680px, 100%);
    padding: 17px 19px;
    border: 1px solid var(--ui-border);
    border-radius: 15px;
    background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
    box-shadow: 0 10px 28px rgba(54, 64, 42, 0.055);
}

.chat-page .message.ai-message .message-avatar {
    width: 36px;
    height: 36px;
}

.chat-page .message.ai-message .message-avatar img {
    border: 1px solid var(--ui-border-strong);
    border-radius: 10px;
}

.chat-page .message-text {
    margin: 0;
    color: var(--ui-text);
    font-size: 15px;
    line-height: 1.85;
}

.chat-page .message-text > :first-child {
    margin-top: 0;
}

.chat-page .message-text > :last-child {
    margin-bottom: 0;
}

.chat-page .message-text p {
    margin: 0 0 1em;
}

.chat-page .message-text blockquote {
    margin: 16px 0;
    padding: 10px 14px;
    border-left: 3px solid #aeba3e;
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
}

.chat-page .message-text ul,
.chat-page .message-text ol {
    margin: 12px 0;
    padding-left: 22px;
}

.chat-page .message-text details {
    margin: 14px 0;
    padding: 10px 13px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface-muted);
}

.chat-page .message-text summary {
    color: var(--ui-text);
    font-weight: 680;
    cursor: pointer;
}

.chat-page .message-text pre,
.chat-page .message-text code {
    border-radius: 6px;
    background: var(--ui-deep);
    color: #eef2df;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.chat-page .message-text code {
    padding: 2px 5px;
    font-size: .88em;
}

.chat-page .message-text pre {
    max-width: 100%;
    padding: 14px;
    overflow: auto;
    line-height: 1.65;
}

.chat-page .message-text pre code {
    padding: 0;
}

.chat-page .message-text table {
    width: 100%;
    margin: 16px 0;
    border-collapse: collapse;
    font-size: 13px;
}

.chat-page .message-text th,
.chat-page .message-text td {
    padding: 8px 10px;
    border: 1px solid var(--ui-border);
    text-align: left;
}

.chat-page .message-text th {
    background: var(--ui-surface-strong);
}

.chat-page .message-text img {
    display: block;
    max-width: min(100%, 680px);
    max-height: 560px;
    margin: 16px 0;
    object-fit: contain;
    border: 1px solid var(--ui-border);
    border-radius: 12px;
}

.lemon-callout,
.lemon-location,
.lemon-note,
.lemon-status,
.lemon-panel,
.rich-choice-panel {
    margin: 15px 0;
    padding: 13px 15px;
    border: 1px solid var(--ui-border);
    border-radius: 11px;
    background: var(--ui-surface-muted);
}

.lemon-location {
    border-left: 3px solid #89972e;
}

.lemon-note {
    background: color-mix(in srgb, var(--ui-accent) 12%, var(--ui-surface));
}

.lemon-status {
    display: inline-block;
    padding: 5px 9px;
    border-radius: 999px;
    color: var(--ui-accent-deep);
    font-size: 12px;
    font-weight: 700;
}

.rich-choice-panel h4 {
    margin: 0 0 9px;
    color: var(--ui-text-soft);
    font-size: 11px;
    letter-spacing: .08em;
}

.rich-choice-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.rich-choice-button {
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    color: var(--ui-text);
    cursor: pointer;
    text-align: left;
}

.rich-choice-button:hover {
    border-color: #aeba3e;
    background: #f2f4dd;
}

.chat-page .chat-settings.show {
    width: min(380px, 34vw);
    min-width: 340px;
}

.chat-page .settings-header {
    min-width: 340px;
    padding: 18px 20px;
    align-items: flex-start;
    background: var(--ui-surface);
}

.chat-page .settings-header h3 {
    font-size: 17px;
    letter-spacing: -.02em;
}

.chat-page .settings-header p {
    max-width: 28ch;
    margin: 4px 0 0;
    color: var(--ui-text-faint);
    font-size: 11px;
    line-height: 1.5;
}

.chat-page .settings-content {
    min-width: 340px;
    padding: 14px 16px 30px;
}

.chat-page .setting-group {
    margin: 0;
    padding: 17px 4px;
    border-bottom: 1px solid var(--ui-border);
}

.setting-section-heading,
.mobile-setting-group-heading {
    display: flex;
    margin-bottom: 10px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.setting-section-heading > span,
.setting-section-heading > label {
    margin: 0;
    color: var(--ui-text);
    font-size: 12px;
    font-weight: 760;
}

.text-action,
.danger-text-action,
.mobile-setting-group-heading button {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--ui-accent-deep);
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
}

.danger-text-action {
    color: var(--ui-danger);
}

.active-character-card {
    display: flex;
    padding: 11px;
    align-items: center;
    gap: 11px;
    border: 1px solid var(--ui-border);
    border-radius: 11px;
    background: var(--ui-surface);
}

.active-character-card img {
    width: 46px;
    height: 46px;
    object-fit: cover;
    border-radius: 10px;
}

.active-character-card strong,
.active-character-card small {
    display: block;
}

.active-character-card strong {
    color: var(--ui-text);
    font-size: 13px;
}

.active-character-card small,
.setting-helper {
    color: var(--ui-text-faint);
    font-size: 10px;
    line-height: 1.55;
}

.setting-helper {
    margin: 7px 1px 0;
}

.resource-select,
.mobile-setting-select {
    min-height: 40px;
    cursor: pointer;
}

.worldbook-selector-list {
    display: grid;
    gap: 7px;
}

.resource-check {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 28px;
    min-width: 0;
    padding: 9px 8px;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    cursor: pointer;
}

.resource-check:has(input:checked) {
    border-color: #cbd274;
    background: color-mix(in srgb, var(--ui-accent) 11%, var(--ui-surface));
}

.resource-check input {
    accent-color: #74831e;
}

.resource-check-copy {
    min-width: 0;
}

.resource-check-copy strong,
.resource-check-copy small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resource-check-copy strong {
    color: var(--ui-text);
    font-size: 11px;
}

.resource-check-copy small {
    margin-top: 2px;
    color: var(--ui-text-faint);
    font-size: 9px;
}

.resource-inline-edit {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--ui-text-faint);
    cursor: pointer;
}

.resource-inline-edit:hover {
    background: var(--ui-surface-strong);
    color: var(--ui-text);
}

.output-capability-note {
    display: flex;
    margin: 0;
    padding: 11px;
    gap: 10px;
    border: 1px solid #d8dda5;
    border-radius: 10px;
    background: color-mix(in srgb, var(--ui-accent) 10%, var(--ui-surface));
}

.output-capability-note i {
    margin-top: 2px;
    color: var(--ui-accent-deep);
}

.output-capability-note strong,
.output-capability-note p {
    display: block;
    margin: 0;
}

.output-capability-note strong {
    color: var(--ui-text);
    font-size: 11px;
}

.output-capability-note p {
    margin-top: 3px;
    color: var(--ui-text-soft);
    font-size: 10px;
    line-height: 1.55;
}

.story-resource-modal,
.resource-editor-modal {
    z-index: 4100;
    padding: 24px;
}

.resource-editor-modal {
    z-index: 4200;
}

.story-resource-manager,
.resource-editor-shell {
    width: min(900px, 100%);
    max-width: 900px;
    max-height: min(820px, calc(100dvh - 48px));
    overflow: auto;
}

.resource-editor-shell {
    width: min(980px, 100%);
    max-width: 980px;
    height: min(760px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.story-resource-manager .modal-header,
.resource-editor-shell .modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.story-resource-manager .modal-header p {
    margin: 4px 0 0;
    color: var(--ui-text-soft);
    font-size: 12px;
}

.icon-close {
    width: 34px;
    height: 34px;
    border: 1px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface-muted);
    color: var(--ui-text-soft);
    cursor: pointer;
}

.resource-manager-actions {
    display: flex;
    padding: 16px 22px;
    gap: 8px;
    border-bottom: 1px solid var(--ui-border);
}

.resource-manager-actions button {
    min-height: 38px;
    padding: 0 13px;
    border: 1px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface-muted);
    color: var(--ui-text);
    cursor: pointer;
    font-size: 12px;
    font-weight: 680;
}

.resource-manager-actions button:first-child {
    border-color: var(--ui-deep);
    background: var(--ui-deep);
    color: #f5f8e8;
}

.story-resource-library {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 20px 22px 24px;
    gap: 10px;
}

.resource-library-item {
    display: flex;
    min-width: 0;
    padding: 15px;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    background: var(--ui-surface-muted);
}

.resource-library-item > div {
    min-width: 0;
}

.resource-library-item span,
.resource-library-item strong,
.resource-library-item p {
    display: block;
}

.resource-library-item span {
    color: var(--ui-accent-deep);
    font-size: 9px;
    font-weight: 780;
    letter-spacing: .07em;
}

.resource-library-item strong {
    margin-top: 5px;
    color: var(--ui-text);
    font-size: 14px;
}

.resource-library-item p {
    margin: 5px 0 0;
    color: var(--ui-text-soft);
    font-size: 11px;
    line-height: 1.55;
}

.resource-library-item button {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--ui-border);
    border-radius: 8px;
    background: var(--ui-surface);
    color: var(--ui-text);
    cursor: pointer;
    font-size: 10px;
}

.resource-editor-grid {
    display: grid;
    grid-template-columns: minmax(0, .7fr) minmax(0, 1.3fr);
    padding: 20px 22px;
    gap: 16px;
    overflow-y: auto;
}

.resource-editor-grid label > span,
.resource-editor-wide > span {
    display: block;
    margin-bottom: 6px;
    color: var(--ui-text-soft);
    font-size: 11px;
    font-weight: 700;
}

.resource-editor-wide {
    grid-column: 1 / -1;
}

.worldbook-fields {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 12px;
}

.worldbook-fields[hidden] {
    display: none;
}

.resource-constant-toggle {
    display: flex;
    min-height: 40px;
    padding: 0 11px;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface-muted);
    cursor: pointer;
}

.resource-constant-toggle > span {
    margin: 0 !important;
}

.resource-content-editor {
    width: 100%;
    min-height: 340px;
    padding: 15px;
    resize: vertical;
    border: 1px solid var(--ui-border-strong);
    border-radius: 11px;
    outline: 0;
    background: var(--ui-surface);
    color: var(--ui-text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.65;
}

.resource-content-editor:focus {
    border-color: #aeba3e;
    box-shadow: 0 0 0 3px rgba(174, 186, 62, .15);
}

.resource-editor-grid small {
    display: block;
    margin-top: 5px;
    color: var(--ui-text-faint);
    font-size: 10px;
}

.resource-editor-actions {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    padding: 14px 22px 20px;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--ui-border);
}

@media (max-width: 1180px) and (min-width: 769px) {
    .chat-page .chat-sidebar {
        width: 248px;
    }

    .context-chip span {
        display: none;
    }

    .context-chip {
        display: flex;
        min-height: 38px;
        padding: 0 10px 0 34px;
        align-items: center;
    }

    .context-chip i {
        top: 12px;
    }
}

@media (max-width: 768px) {
    .chat-page .chat-header {
        display: none;
    }

    .chat-page .chat-messages {
        padding-top: 18px;
    }

    .chat-page .message {
        width: 94%;
        max-width: 94%;
    }

    .chat-page .message.ai-message .message-content {
        min-width: 0;
        padding: 13px 14px;
    }

    .chat-page .message.ai-message .message-avatar {
        width: 30px;
        height: 30px;
        margin-right: 8px;
    }

    .chat-page .message-text {
        padding: 0;
        font-size: 15px;
        line-height: 1.8;
    }

    .rich-choice-list,
    .story-resource-library,
    .resource-editor-grid {
        grid-template-columns: 1fr;
    }

    .resource-editor-wide {
        grid-column: auto;
    }

    .mobile-resource-control {
        padding: 8px 12px;
    }

    .mobile-setting-select {
        width: 100%;
        border: 1px solid var(--ui-border);
        border-radius: 10px;
        background: var(--ui-surface);
        color: var(--ui-text);
    }

    .mobile-worldbook-list {
        padding: 0 12px 12px;
    }

    .mobile-setting-group-heading {
        padding: 0 16px;
    }

    .story-resource-modal,
    .resource-editor-modal {
        padding: 0;
        align-items: stretch;
    }

    .story-resource-manager,
    .resource-editor-shell {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .resource-manager-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .worldbook-fields {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .resource-content-editor {
        min-height: 42dvh;
    }
}

@media (prefers-color-scheme: dark) {
    .context-chip:hover,
    .rich-choice-button:hover {
        border-color: #71802f;
        background: #303720;
    }

    .chat-page .message.ai-message .message-content {
        background: rgba(29, 33, 25, .94);
        box-shadow: 0 12px 30px rgba(3, 5, 2, .18);
    }

    .resource-check:has(input:checked),
    .output-capability-note,
    .lemon-note {
        border-color: #515b31;
        background: #2b311f;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .header,
    .chat-page .chat-input-area {
        background: var(--ui-surface);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }
}

/* 聊天剧情选择器与浮动输入坞 */
.chat-page .chat-input-area {
    padding: 12px clamp(18px, 4vw, 62px) calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid rgba(207, 214, 198, 0.78);
    background: rgba(246, 248, 241, 0.86);
    box-shadow: 0 -12px 34px rgba(47, 57, 37, 0.05);
}

.chat-page .story-choices {
    width: min(900px, 100%);
    margin: 0 auto 10px;
    opacity: 0;
    transform: translateY(7px);
}

.chat-page .story-choices[hidden] {
    display: none;
}

.chat-page .story-choices.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.chat-page .story-choices-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 7px;
    padding: 0 2px;
}

.chat-page .story-choices-heading span {
    color: var(--ui-text);
    font-size: 13px;
    font-weight: 720;
    letter-spacing: -0.01em;
}

.chat-page .story-choices-heading small {
    color: var(--ui-text-faint);
    font-size: 11px;
}

.chat-page .story-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
}

.chat-page .story-choice {
    min-width: 0;
    min-height: 45px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border: 1px solid rgba(207, 214, 198, 0.94);
    border-radius: 12px;
    background: rgba(252, 253, 249, 0.9);
    color: var(--ui-text);
    box-shadow: 0 5px 16px rgba(54, 64, 42, 0.045);
    cursor: pointer;
    text-align: left;
}

.chat-page .story-choice span {
    min-width: 0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    font-size: 13px;
    line-height: 1.45;
}

.chat-page .story-choice i {
    flex: 0 0 auto;
    color: #8d9b39;
    font-size: 10px;
    transform: rotate(-24deg);
}

.chat-page .story-choice:hover {
    border-color: #b7c05a;
    background: #fbfddd;
    box-shadow: 0 7px 20px rgba(107, 120, 34, 0.1);
}

.chat-page .story-choice:active {
    transform: translateY(1px);
}

.chat-page .message-input-container {
    width: min(900px, 100%);
    min-height: 52px;
    align-items: flex-end;
    gap: 8px;
    margin: 0 auto;
    padding: 5px 6px 5px 14px;
    border: 1px solid rgba(184, 193, 172, 0.96);
    border-radius: 17px;
    background: rgba(252, 253, 249, 0.96);
    box-shadow: 0 10px 28px rgba(47, 57, 37, 0.09);
}

.chat-page .message-input-container:focus-within {
    border-color: #aeba3e;
    background: var(--ui-surface);
    box-shadow: 0 0 0 3px rgba(174, 186, 62, 0.15), 0 12px 30px rgba(47, 57, 37, 0.1);
}

.chat-page .message-input {
    min-height: 40px;
    max-height: 140px;
    padding: 8px 4px;
    color: var(--ui-text);
    font-size: 15px;
    line-height: 1.55;
}

.chat-page .message-input:focus,
.chat-page .message-input:focus-visible {
    border: 0;
    outline: none;
    outline-offset: 0;
    background: transparent;
    box-shadow: none;
}

.chat-page .message-input::placeholder {
    color: #969e8f;
}

.chat-page .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--ui-deep);
    color: #f4f7e8;
    box-shadow: none;
}

.chat-page .send-btn:hover:not(:disabled) {
    background: #3b4929;
    transform: translateY(-1px);
}

.chat-page .send-btn:disabled {
    background: #e7eadf;
    color: #a5ab9d;
    opacity: 1;
}

.chat-page .message.user-message .message-block {
    align-items: flex-end;
}

.chat-page .message.user-message .message-content {
    width: fit-content;
    max-width: 100%;
    border: 0;
    border-radius: 15px 15px 5px 15px;
    background: var(--ui-deep);
    box-shadow: none;
}

.chat-page .message.user-message .message-text {
    width: fit-content;
    max-width: 100%;
    margin: 0;
    border: 0;
    border-radius: inherit;
    background: transparent;
    box-shadow: none;
    color: #f3f6e8;
}

@media (prefers-reduced-motion: no-preference) {
    .chat-page .story-choices {
        transition: opacity 180ms ease, transform 180ms ease;
    }

    .chat-page .story-choice,
    .chat-page .send-btn {
        transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
    }
}

@media (max-width: 768px) {
    .chat-page .chat-input-area {
        padding: 9px 10px calc(10px + env(safe-area-inset-bottom));
    }

    .chat-page .story-choices {
        margin-bottom: 8px;
    }

    .chat-page .story-choices-heading {
        margin-bottom: 6px;
    }

    .chat-page .story-choices-heading span {
        font-size: 12px;
    }

    .chat-page .story-choices-heading small {
        font-size: 10px;
    }

    .chat-page .story-choice-grid {
        gap: 6px;
    }

    .chat-page .story-choice {
        min-height: 48px;
        padding: 8px 9px;
        border-radius: 11px;
    }

    .chat-page .story-choice span {
        font-size: 12px;
        line-height: 1.4;
    }

    .chat-page .message-input-container {
        min-height: 48px;
        padding: 4px 4px 4px 12px;
        border-radius: 15px;
    }

    .chat-page .message-input {
        min-height: 38px;
        padding: 4px 3px 10px;
        border-radius: 0;
        font-size: 16px;
        line-height: 24px;
    }

    .chat-page .send-btn {
        width: 38px;
        height: 38px;
        border-radius: 11px;
    }

    .chat-page .message.user-message .message-content {
        padding: 0;
        background: transparent;
    }

    .chat-page .message.user-message .message-text {
        padding: 10px 14px;
        border-radius: 15px 15px 5px 15px;
        background: var(--ui-deep);
        line-height: 1.65;
    }

    .chat-page .chat-input-area.keyboard-active .story-choices {
        display: none;
    }
}

@media (prefers-color-scheme: dark) {
    .chat-page .chat-input-area {
        border-color: rgba(72, 80, 66, 0.82);
        background: rgba(24, 28, 21, 0.88);
        box-shadow: 0 -14px 38px rgba(5, 7, 4, 0.2);
    }

    .chat-page .story-choice {
        border-color: #42493b;
        background: rgba(32, 37, 28, 0.94);
        box-shadow: 0 6px 18px rgba(6, 8, 5, 0.16);
    }

    .chat-page .story-choice:hover {
        border-color: #748034;
        background: #2b311f;
    }

    .chat-page .story-choice i {
        color: #c9d656;
    }

    .chat-page .message-input-container {
        border-color: #485042;
        background: rgba(29, 33, 25, 0.96);
        box-shadow: 0 12px 30px rgba(6, 8, 5, 0.26);
    }

    .chat-page .message-input::placeholder {
        color: #7f8778;
    }

    .chat-page .send-btn:disabled {
        background: #30362b;
        color: #737b6d;
    }
}

/* 资源库最终层级，确保新市场布局覆盖旧编辑器样式 */
.story-resource-manager {
    width: min(1060px, 100%);
    max-width: 1060px;
    height: min(820px, calc(100dvh - 48px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.story-resource-library.resource-market-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 1 1 auto;
    min-height: 0;
    padding: 10px 22px 24px;
    align-content: start;
    overflow-y: auto;
    gap: 10px;
}

.resource-editor-grid .resource-publish-toggle > span {
    margin: 0;
}

@media (max-width: 768px) {
    .story-resource-manager {
        width: 100%;
        height: 100dvh;
        max-width: none;
        max-height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .story-resource-library.resource-market-grid {
        grid-template-columns: 1fr;
        padding: 8px 14px calc(24px + env(safe-area-inset-bottom));
    }

    .story-resource-library.resource-market-grid .resource-market-card {
        min-height: 156px;
    }

    .story-resource-library.resource-market-grid .resource-market-select {
        min-height: 154px;
    }
}

@media (min-width: 769px) {
    .chat-page .mobile-settings-overlay,
    .chat-page .mobile-character-overlay,
    .chat-page .chat-mobile-settings-btn {
        display: none !important;
    }
}

/* 角色详情弹层：主视觉、阅读区和操作栏各自稳定，不再互相挤压 */
#characterModal.modal {
    padding: 24px;
    box-sizing: border-box;
    overscroll-behavior: contain;
}

#characterModal .character-modal {
    width: min(960px, calc(100% - 48px));
    max-width: 960px;
    height: min(760px, calc(100dvh - 48px));
    max-height: calc(100dvh - 48px);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 18px;
}

#characterModal .character-modal-header {
    position: relative;
    top: auto;
    min-height: 64px;
    padding: 12px 16px 12px 22px;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--ui-border);
    background: rgba(252, 253, 249, 0.96);
    box-shadow: none;
    z-index: 3;
}

#characterModal .character-modal-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

#characterModal .character-modal-mark {
    width: 34px;
    height: 34px;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--ui-surface-strong);
    color: var(--ui-accent-deep);
    font-size: 14px;
}

#characterModal .character-modal-header h2 {
    display: block;
    margin: 0;
    color: var(--ui-text);
    font-size: 16px;
    font-weight: 760;
    letter-spacing: -0.02em;
}

#characterModal .character-modal-close {
    width: 40px;
    height: 40px;
    min-width: 40px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 11px;
    background: transparent;
    color: var(--ui-text-soft);
    font-size: 18px;
    line-height: 1;
}

#characterModal .character-modal-close:hover {
    border-color: var(--ui-border);
    background: var(--ui-surface-muted);
    color: var(--ui-text);
}

#characterModal .character-modal-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

#characterModal .modal-body {
    padding: 28px;
}

#characterModal .character-detail {
    display: grid;
    grid-template-columns: minmax(260px, 0.82fr) minmax(0, 1.18fr);
    align-items: start;
    gap: 34px;
}

#characterModal .character-image {
    width: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--ui-border);
    border-radius: 14px;
    background: var(--ui-surface-strong);
    box-shadow: 0 18px 44px rgba(39, 48, 29, 0.12);
}

#characterModal .character-image img {
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    display: block;
    object-fit: cover;
    object-position: top center;
    border-radius: 0;
    box-shadow: none;
}

#characterModal .character-info {
    min-width: 0;
    padding: 4px 0 12px;
}

#characterModal .character-title {
    display: block;
    margin: 0 0 22px;
    padding: 0;
    text-align: left;
    background: transparent;
}

#characterModal .character-title h3 {
    margin: 0;
    color: var(--ui-text);
    font-size: clamp(26px, 3vw, 38px);
    font-weight: 790;
    line-height: 1.18;
    letter-spacing: -0.045em;
    overflow-wrap: anywhere;
}

#characterModal .character-stats {
    margin: 0 0 28px;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    background: transparent;
}

#characterModal .stat-item {
    min-width: 0;
    min-height: 64px;
    padding: 11px 13px;
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    justify-content: initial;
    column-gap: 9px;
    row-gap: 2px;
    border: 1px solid var(--ui-border);
    border-radius: 11px;
    background: var(--ui-surface-muted);
}

#characterModal .stat-item:last-child {
    grid-column: 1 / -1;
    padding-bottom: 11px;
    border-bottom: 1px solid var(--ui-border);
}

#characterModal .stat-item > i {
    grid-column: 1;
    grid-row: 1 / 3;
    color: var(--ui-accent-deep);
    font-size: 14px;
    text-align: center;
}

#characterModal .stat-label {
    grid-column: 2;
    color: var(--ui-text-faint);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
}

#characterModal .stat-value {
    grid-column: 2;
    min-width: 0;
    overflow: hidden;
    color: var(--ui-text);
    font-size: 14px;
    font-weight: 680;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#characterModal .character-description {
    padding-top: 24px;
    border-top: 1px solid var(--ui-border);
    background: transparent;
}

#characterModal .character-description h3 {
    margin: 0 0 12px;
    color: var(--ui-text);
    font-size: 16px;
    font-weight: 740;
    letter-spacing: -0.015em;
}

#characterModal .character-description p {
    max-width: 62ch;
    margin: 0;
    color: var(--ui-text-soft);
    font-size: 15px;
    line-height: 1.85;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

#characterModal .character-actions {
    min-height: 82px;
    padding: 14px 20px;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid var(--ui-border);
    background: rgba(252, 253, 249, 0.97);
    box-shadow: 0 -12px 30px rgba(39, 48, 29, 0.04);
    z-index: 3;
}

#characterModal .character-actions .btn {
    min-height: 48px;
    margin: 0;
    padding: 0 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border-radius: 11px;
    font-size: 15px;
    font-weight: 720;
}

#characterModal .character-actions .favorite-btn {
    min-width: 112px;
    border: 1px solid var(--ui-border-strong);
    background: var(--ui-surface);
    color: var(--ui-text-soft);
}

#characterModal .character-actions .character-delete-btn {
    min-width: 96px;
    margin-right: auto;
    border: 1px solid #dfb6b0;
    background: #fff8f6;
    color: var(--ui-danger);
}

#characterModal .character-actions .character-delete-btn[hidden] {
    display: none;
}

#characterModal .character-actions .character-delete-btn:hover {
    border-color: #cc8f87;
    background: #fff0ed;
}

#characterModal .character-actions .favorite-btn:hover {
    border-color: #bcc6ad;
    background: var(--ui-surface-muted);
    color: var(--ui-text);
}

#characterModal .character-actions .favorite-btn.favorited {
    border-color: #d8a79e;
    background: #fff5f2;
    color: var(--ui-danger);
}

#characterModal .character-actions .start-chat-btn {
    min-width: 176px;
    border: 1px solid var(--ui-deep);
    background: var(--ui-deep);
    color: #f7faed;
    box-shadow: 0 9px 22px rgba(40, 51, 29, 0.18);
}

#characterModal .character-actions .start-chat-btn:hover {
    background: #354225;
}

#characterModal .character-actions .start-chat-btn i {
    font-size: 13px;
}

#characterModal .is-loading .stat-value,
#characterModal .is-loading .character-description p {
    opacity: 0.55;
}

@media (max-width: 768px) {
    #characterModal.modal,
    #characterModal.modal.show {
        top: var(--visual-viewport-offset-top, 0px);
        bottom: auto;
        width: 100%;
        height: var(--app-viewport-height, 100dvh);
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
        background: var(--ui-surface);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    #characterModal .modal-content.character-modal {
        width: 100%;
        height: var(--app-viewport-height, 100dvh);
        min-height: 0;
        max-width: none;
        max-height: var(--app-viewport-height, 100dvh);
        margin: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    #characterModal .character-modal-header {
        min-height: calc(58px + env(safe-area-inset-top));
        padding: max(10px, env(safe-area-inset-top)) 12px 10px 14px;
    }

    #characterModal .character-modal-mark {
        width: 32px;
        height: 32px;
        border-radius: 9px;
    }

    #characterModal .character-modal-close {
        width: 42px;
        height: 42px;
        min-width: 42px;
        border-color: var(--ui-border);
        background: var(--ui-surface-muted);
    }

    #characterModal .modal-body {
        padding: 16px 14px 26px;
    }

    #characterModal .character-detail {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    #characterModal .character-image {
        width: 100%;
        border-radius: 14px;
        box-shadow: 0 12px 34px rgba(39, 48, 29, 0.1);
    }

    #characterModal .character-image img {
        width: 100%;
        height: min(52svh, 460px);
        min-height: 300px;
        aspect-ratio: auto;
    }

    #characterModal .character-info {
        width: 100%;
        padding: 22px 2px 0;
    }

    #characterModal .character-title {
        margin-bottom: 18px;
        text-align: left;
    }

    #characterModal .character-title h3 {
        font-size: clamp(25px, 7.2vw, 32px);
        line-height: 1.2;
        white-space: normal;
    }

    #characterModal .character-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 22px;
    }

    #characterModal .stat-item {
        min-height: 62px;
        padding: 10px 11px;
    }

    #characterModal .stat-item:last-child {
        padding-bottom: 10px;
    }

    #characterModal .character-description {
        padding-top: 20px;
    }

    #characterModal .character-description p {
        max-width: none;
        font-size: 15px;
        line-height: 1.8;
    }

    #characterModal .character-actions {
        min-height: calc(76px + env(safe-area-inset-bottom));
        padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
        flex-direction: row;
        justify-content: stretch;
        gap: 10px;
    }

    #characterModal .character-actions .btn {
        min-height: 50px;
        padding-inline: 16px;
    }

    #characterModal .character-actions .favorite-btn {
        min-width: 104px;
        flex: 0 0 104px;
    }

    #characterModal .character-actions .character-delete-btn {
        min-width: 50px;
        flex: 0 0 50px;
        margin-right: 0;
        padding-inline: 0;
    }

    #characterModal .character-actions .character-delete-btn span {
        display: none;
    }

    #characterModal .character-actions .start-chat-btn {
        min-width: 0;
        flex: 1 1 auto;
    }
}

@media (max-width: 380px) {
    #characterModal .modal-body {
        padding-inline: 12px;
    }

    #characterModal .character-image img {
        min-height: 260px;
        height: 48svh;
    }

    #characterModal .character-actions {
        padding-inline: 10px;
    }

    #characterModal .character-actions .favorite-btn {
        min-width: 96px;
        padding-inline: 12px;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    #characterModal .character-image img {
        height: 68svh;
        min-height: 240px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #characterModal .character-modal,
    #characterModal.modal.show {
        animation: none;
    }
}

@media (prefers-color-scheme: dark) {
    #characterModal .character-actions .character-delete-btn {
        border-color: #704c47;
        background: #332522;
        color: #efaaa0;
    }

    #characterModal .character-actions .character-delete-btn:hover {
        border-color: #98645c;
        background: #412a27;
    }
}

/* 角色回复气泡：外层只负责布局，正文层是唯一可见气泡。 */
.chat-page .message.ai-message {
    width: min(920px, 92%);
    max-width: min(920px, 92%);
    margin-right: auto;
    margin-bottom: 28px;
}

.chat-page .message.ai-message .message-main {
    width: 100%;
    align-items: flex-start;
}

.chat-page .message.ai-message .message-avatar {
    width: 42px;
    height: 42px;
    margin: 2px 13px 0 0;
}

.chat-page .message.ai-message .message-avatar img {
    width: 42px;
    height: 42px;
    border: 1px solid var(--ui-border-strong);
    border-radius: 13px;
    background: var(--ui-surface-muted);
    box-shadow: 0 6px 18px rgba(54, 64, 42, 0.1);
}

.chat-page .message.ai-message .message-block {
    min-width: 0;
    max-width: min(790px, calc(100% - 55px));
    align-items: flex-start;
}

.chat-page .message-speaker {
    max-width: 100%;
    margin: 0 0 7px 2px;
    overflow: hidden;
    color: #64731d;
    font-size: 12px;
    font-weight: 720;
    line-height: 1.25;
    letter-spacing: .01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-page .message.ai-message .message-content {
    width: 100%;
    max-width: 100%;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.chat-page .message.ai-message .message-text {
    display: flow-root;
    width: fit-content;
    max-width: 100%;
    margin: 0;
    padding: 17px 20px 18px;
    overflow-wrap: anywhere;
    border: 1px solid color-mix(in srgb, var(--ui-border) 88%, #b9c558);
    border-radius: 18px 18px 18px 6px;
    background: color-mix(in srgb, var(--ui-surface) 97%, var(--ui-accent) 3%);
    box-shadow:
        0 10px 28px rgba(54, 64, 42, 0.075),
        inset 0 1px 0 rgba(255, 255, 255, 0.72);
    color: var(--ui-text);
    font-size: 16px;
    line-height: 1.88;
    text-align: left;
}

.chat-page .message.ai-message .message-text:empty {
    display: none;
}

.chat-page .message.ai-message .message-text p {
    margin: 0 0 .9em;
}

.chat-page .message.ai-message .message-text h1,
.chat-page .message.ai-message .message-text h2,
.chat-page .message.ai-message .message-text h3,
.chat-page .message.ai-message .message-text h4 {
    margin: 1.2em 0 .55em;
    color: var(--ui-text);
    font-size: 1em;
    font-weight: 760;
    line-height: 1.45;
}

.chat-page .message.ai-message .message-text > :first-child {
    margin-top: 0;
}

.chat-page .message.ai-message .message-text > :last-child {
    margin-bottom: 0;
}

.chat-page .message.ai-message .message-text blockquote {
    margin: 15px 0;
    padding: 10px 13px;
    border: 0;
    border-radius: 10px;
    background: color-mix(in srgb, var(--ui-accent) 12%, var(--ui-surface-muted));
    color: var(--ui-text-soft);
}

.chat-page .message.ai-message .message-text a {
    color: #59691a;
    font-weight: 650;
    text-decoration-color: rgba(89, 105, 26, .38);
    text-underline-offset: 3px;
}

.chat-page .message.ai-message .message-text hr {
    height: 1px;
    margin: 18px 0;
    border: 0;
    background: var(--ui-border);
}

.chat-page .message.ai-message .message-text table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    -webkit-overflow-scrolling: touch;
}

.chat-page .message.ai-message .message-text pre {
    margin: 15px 0;
    border: 1px solid rgba(255, 255, 255, .08);
}

.chat-page .message.ai-message .message-actions {
    width: auto;
    min-height: 30px;
    margin: 5px 0 0 2px;
    gap: 2px;
    align-self: flex-start;
}

.chat-page .message.ai-message .message-actions .action-btn {
    width: 30px;
    min-width: 30px;
    height: 30px;
    border-radius: 9px;
    color: var(--ui-text-faint);
}

.chat-page .message.ai-message .message-actions .action-btn:hover,
.chat-page .message.ai-message .message-actions .action-btn:focus-visible {
    background: var(--ui-surface-strong);
    color: #59691a;
}

@media (max-width: 768px) {
    .chat-page .message.ai-message {
        width: 100%;
        max-width: 100%;
        margin-right: 0;
        margin-bottom: 22px;
    }

    .chat-page .message.ai-message .message-avatar {
        width: 34px;
        height: 34px;
        margin: 1px 9px 0 0;
    }

    .chat-page .message.ai-message .message-avatar img {
        width: 34px;
        height: 34px;
        border-radius: 11px;
        box-shadow: 0 4px 12px rgba(54, 64, 42, 0.09);
    }

    .chat-page .message.ai-message .message-block {
        max-width: calc(100% - 43px);
    }

    .chat-page .message-speaker {
        margin-bottom: 5px;
        font-size: 11px;
    }

    .chat-page .message.ai-message .message-content {
        padding: 0;
    }

    .chat-page .message.ai-message .message-text {
        padding: 13px 15px 14px;
        border-radius: 16px 16px 16px 5px;
        font-size: 15px;
        line-height: 1.82;
        box-shadow: 0 7px 20px rgba(54, 64, 42, 0.065), inset 0 1px 0 rgba(255, 255, 255, 0.68);
    }

    .chat-page .message.ai-message .message-actions {
        min-height: 0;
        margin-top: 4px;
    }

    .chat-page .message.ai-message.show-actions .message-actions {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (prefers-color-scheme: dark) {
    .chat-page .message-speaker {
        color: #c9d65a;
    }

    .chat-page .message.ai-message .message-avatar img {
        box-shadow: 0 7px 20px rgba(3, 5, 2, .24);
    }

    .chat-page .message.ai-message .message-text {
        border-color: #424a39;
        background: color-mix(in srgb, var(--ui-surface) 94%, var(--ui-accent) 6%);
        box-shadow: 0 12px 30px rgba(3, 5, 2, .22), inset 0 1px 0 rgba(255, 255, 255, .045);
    }

    .chat-page .message.ai-message .message-text blockquote {
        background: color-mix(in srgb, var(--ui-accent) 10%, var(--ui-surface-muted));
    }

    .chat-page .message.ai-message .message-text a,
    .chat-page .message.ai-message .message-actions .action-btn:hover,
    .chat-page .message.ai-message .message-actions .action-btn:focus-visible {
        color: #d4df72;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .chat-page .message.ai-message .message-text {
        background: var(--ui-surface);
    }
}

/* 顶栏通知面板，与账户下拉保持一致的轻量层级。 */
.notification-popover {
    position: fixed;
    z-index: 1600;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--ui-border-strong);
    border-radius: 16px;
    background: var(--ui-surface);
    color: var(--ui-text);
    box-shadow: 0 22px 60px rgba(38, 47, 29, 0.18);
}

.notification-popover[hidden] {
    display: none;
}

.notification-popover-header {
    min-height: 66px;
    padding: 12px 14px 11px 16px;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--ui-border);
}

.notification-popover-header > div {
    min-width: 0;
    display: grid;
    gap: 3px;
}

.notification-popover-header strong {
    color: var(--ui-text);
    font-size: 16px;
    font-weight: 780;
    line-height: 1.2;
}

.notification-popover-header span {
    color: var(--ui-text-faint);
    font-size: 11px;
}

.notification-popover-header button {
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--ui-border);
    border-radius: 9px;
    background: var(--ui-surface-muted);
    color: #5f6d1f;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.notification-popover-header button:hover:not(:disabled) {
    border-color: #c8d08e;
    background: #f2f5dc;
}

.notification-popover-header button:disabled {
    color: var(--ui-text-faint);
    cursor: default;
    opacity: .62;
}

.notification-popover-list {
    min-height: 110px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.notification-popover-item {
    width: 100%;
    min-height: 82px;
    padding: 13px 14px;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 14px;
    align-items: start;
    gap: 11px;
    border: 0;
    border-bottom: 1px solid var(--ui-border);
    border-radius: 0;
    background: var(--ui-surface);
    color: inherit;
    cursor: pointer;
    text-align: left;
}

.notification-popover-item:last-child {
    border-bottom: 0;
}

.notification-popover-item:hover,
.notification-popover-item:focus-visible {
    background: var(--ui-surface-muted);
}

.notification-popover-item.unread {
    background: color-mix(in srgb, var(--ui-accent) 8%, var(--ui-surface));
}

.notification-popover-item:disabled {
    cursor: wait;
    opacity: .68;
}

.notification-popover-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    background: var(--ui-surface-strong);
    color: var(--ui-accent-deep);
    font-size: 14px;
}

.notification-popover-item[data-type="character_approved"] .notification-popover-icon {
    background: #e4f1e5;
    color: #39734a;
}

.notification-popover-item[data-type="character_rejected"] .notification-popover-icon {
    background: #f8e7e3;
    color: #a34f45;
}

.notification-popover-copy {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.notification-popover-copy strong {
    overflow: hidden;
    color: var(--ui-text);
    font-size: 13px;
    font-weight: 740;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notification-popover-copy > span {
    display: -webkit-box;
    overflow: hidden;
    color: var(--ui-text-soft);
    font-size: 12px;
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.notification-popover-copy small {
    color: var(--ui-text-faint);
    font-size: 10px;
}

.notification-popover-status {
    min-height: 38px;
    display: grid;
    place-items: center;
    color: var(--ui-text-faint);
    font-size: 10px;
}

.notification-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #b4473f;
    box-shadow: 0 0 0 3px color-mix(in srgb, #b4473f 12%, transparent);
}

.notification-popover-state {
    min-height: 170px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: var(--ui-text-faint);
    font-size: 12px;
    text-align: center;
}

.notification-popover-state > i {
    margin-bottom: 3px;
    color: var(--ui-accent-deep);
    font-size: 21px;
}

.notification-popover-state strong {
    color: var(--ui-text-soft);
    font-size: 13px;
}

.notification-popover-state.error {
    color: var(--ui-danger);
}

.notification-popover-footer {
    min-height: 46px;
    padding: 7px 9px;
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    border-top: 1px solid var(--ui-border);
    background: var(--ui-surface-muted);
}

.notification-popover-footer a {
    width: 100%;
    min-height: 32px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 8px;
    color: var(--ui-text-soft);
    font-size: 11px;
    font-weight: 680;
    text-decoration: none;
}

.notification-popover-footer a:hover {
    background: var(--ui-surface-strong);
    color: var(--ui-text);
}

@media (max-width: 600px) {
    .notification-popover {
        border-radius: 15px;
        box-shadow: 0 18px 48px rgba(38, 47, 29, 0.2);
    }

    .notification-popover-item {
        min-height: 76px;
        padding: 12px;
        grid-template-columns: 36px minmax(0, 1fr) 12px;
        gap: 10px;
    }

    .notification-popover-icon {
        width: 36px;
        height: 36px;
    }
}

@media (prefers-color-scheme: dark) {
    .notification-popover {
        box-shadow: 0 24px 64px rgba(3, 5, 2, .4);
    }

    .notification-popover-header button {
        color: #cbd76b;
    }

    .notification-popover-header button:hover:not(:disabled),
    .notification-popover-item.unread {
        border-color: #586230;
        background: #2b311f;
    }

    .notification-popover-item[data-type="character_approved"] .notification-popover-icon {
        background: #263b2b;
        color: #8dce99;
    }

    .notification-popover-item[data-type="character_rejected"] .notification-popover-icon {
        background: #422b27;
        color: #efaaa0;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .notification-popover {
        animation: notificationPopoverIn 140ms ease-out;
        transform-origin: top right;
    }

    @keyframes notificationPopoverIn {
        from { opacity: 0; transform: translateY(-4px) scale(.985); }
        to { opacity: 1; transform: translateY(0) scale(1); }
    }
}
