        :root {
            --app-visual-height: 100vh;
            --keyboard-inset: 0px;
            --chat-bg-height: 100vh;

            /* ==================================================================
               主题色 Token（channel 格式：R G B）
               供 Tailwind 的 rgb(var(--c-x) / <alpha-value>) 与 CSS 直接消费。
               换主题时只需覆写这里的 21 个变量，全站即时跟随；
               因为 Theme Engine 只旋转色相、保留每个 Token 原有的饱和度与亮度，
               所以任何主题下原有的对比度关系（WCAG 对比比）都保持不变。
               ================================================================== */
            --c-primary-50: 242 251 245;
            --c-primary-100: 226 247 234;
            --c-primary-200: 196 238 213;
            --c-primary-300: 151 223 183;
            --c-primary-400: 98 201 147;
            --c-primary-500: 52 170 114;
            --c-primary-600: 38 139 90;
            --c-primary-700: 31 111 73;
            --c-primary-800: 28 89 61;
            --c-primary-900: 23 73 51;
            --c-primary-950: 10 41 28;

            --c-gray-50: 248 250 248;
            --c-gray-100: 241 245 242;
            --c-gray-200: 227 234 229;
            --c-gray-300: 206 218 209;
            --c-gray-400: 148 167 154;
            --c-gray-500: 100 121 108;
            --c-gray-600: 76 94 83;
            --c-gray-700: 56 70 62;
            --c-gray-800: 35 44 39;
            --c-gray-900: 20 26 22;
        }

        @supports (height: 100dvh) {
            :root {
                --app-visual-height: 100dvh;
            }
        }

        html {
            height: 100%;
            -webkit-text-size-adjust: 100% !important;
            -moz-text-size-adjust: 100% !important;
            -ms-text-size-adjust: 100% !important;
            text-size-adjust: 100% !important;
        }

        [v-cloak] { display: none !important; }

        .embedded-loading-spinner {
            width: 2.8125rem;
            height: 2.8125rem;
            margin-bottom: 1rem;
            color: rgb(var(--c-primary-600));
            animation: generated-image-spinner-rotate 2s linear infinite;
        }

        .embedded-loading-spinner circle {
            fill: none;
            stroke: currentColor;
            stroke-linecap: round;
            animation: generated-image-spinner-dash 1.5s ease-in-out infinite;
        }

        .entry-transition {
            position: fixed;
            inset: 0;
            z-index: 9999;
            display: flex;
            align-items: center;
            justify-content: center;
            pointer-events: none;
            overflow: hidden;
            opacity: 0;
            visibility: hidden;
            background:
                radial-gradient(ellipse at 28% 20%, rgb(var(--c-primary-200) / 0.55) 0, transparent 55%),
                radial-gradient(ellipse at 78% 85%, rgba(254, 226, 226, 0.45) 0, transparent 50%),
                rgb(var(--c-gray-50));
            animation: entry-screen-out 0.65s cubic-bezier(0.4, 0, 0.2, 1) 1.55s backwards;
        }

        /* 自定义开屏背景：图片在下、白色纱幕在上，保证站名与书本标记任何图片下都清晰可读 */
        .entry-transition.has-custom-splash {
            background-image:
                linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0.82) 100%),
                var(--czg-splash-src);
            background-size: cover;
            background-position: center;
        }

        .entry-transition-brand {
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 24px;
            color: rgb(var(--c-primary-900));
            animation: entry-brand-in 0.85s cubic-bezier(0.16, 1, 0.3, 1) 0.08s backwards;
        }

        .entry-transition-book {
            position: relative;
            width: 80px;
            height: 60px;
            margin-bottom: 26px;
            color: rgb(var(--c-primary-600));
            perspective: 275px;
        }

        .entry-transition-book svg {
            display: block;
            width: 100%;
            height: 100%;
        }

        .entry-transition-book .entry-book-page {
            position: absolute;
            left: 50%;
            top: 0;
            width: 43.75%;
            height: 100%;
            overflow: visible;
            opacity: 0;
            transform-origin: left center;
            animation: entry-page-turn 1.2s cubic-bezier(0.45, 0, 0.35, 1) 0.18s backwards;
        }

        .entry-transition-logo {
            display: inline-flex;
            align-items: baseline;
            font-family: var(--app-font-serif) !important;
            line-height: 1;
        }

        /* 站点名称，文字由 site-config.js 注入 */
        .entry-logo-name {
            position: relative;
            font-size: clamp(1.75rem, 5.5vw, 2.25rem);
            font-weight: 600;
            letter-spacing: 0.1em;
        }

        .entry-logo-name::before,
        .entry-logo-name::after {
            content: '';
            position: absolute;
            left: 0;
            bottom: -4px;
            width: 100%;
            height: 3px;
            border-radius: 999px;
        }

        .entry-logo-name::before {
            background: rgb(var(--c-primary-100));
        }

        .entry-logo-name::after {
            background: linear-gradient(90deg, rgb(var(--c-primary-500)) 0%, rgb(var(--c-primary-400)) 65%, #f43f5e 100%);
            transform-origin: left center;
            animation: entry-progress-in 1.2s cubic-bezier(0.2, 0.6, 0.3, 1) 0.35s backwards;
        }

        @keyframes entry-brand-in {
            from { opacity: 0; transform: translateY(36px); }
            to { opacity: 1; transform: none; }
        }

        @keyframes entry-progress-in {
            from { transform: scaleX(0); }
            to { transform: none; }
        }

        @keyframes entry-page-turn {
            0% { opacity: 0; transform: rotateY(0deg); }
            12%, 80% { opacity: 1; }
            100% { opacity: 0; transform: rotateY(-180deg); }
        }

        @keyframes entry-screen-out {
            from { opacity: 1; visibility: visible; }
            to { opacity: 0; visibility: hidden; }
        }

        @media (prefers-reduced-motion: reduce) {
            .entry-transition {
                animation: entry-screen-out 0.15s ease-out;
            }

            .entry-transition-brand,
            .entry-logo-name::after,
            .entry-transition-book .entry-book-page {
                animation: none;
            }
        }

        /* Desktop custom scrollbar */
        @media (min-width: 769px) {
            html,
            body,
            #app {
                overflow-x: hidden;
            }

            * {
                scrollbar-width: thin;
                scrollbar-color: rgba(203, 213, 225, 0.9) transparent;
            }

            ::-webkit-scrollbar {
                width: 10px;
                height: 0;
            }

            ::-webkit-scrollbar:horizontal {
                display: none;
                width: 0;
                height: 0;
            }

            ::-webkit-scrollbar-track,
            ::-webkit-scrollbar-corner {
                background: transparent;
            }

            ::-webkit-scrollbar-thumb {
                min-height: 48px;
                border: 3px solid transparent;
                border-radius: 999px;
                background: linear-gradient(180deg, rgba(241, 245, 249, 0.96), rgba(203, 213, 225, 0.92));
                background-clip: content-box;
            }

            ::-webkit-scrollbar-thumb:hover {
                background: linear-gradient(180deg, rgb(var(--c-primary-100) / 0.96), rgb(var(--c-primary-300) / 0.9));
                background-clip: content-box;
            }

            .custom-scrollbar {
                scrollbar-color: rgba(203, 213, 225, 0.86) transparent;
            }

            .custom-scrollbar::-webkit-scrollbar {
                width: 8px;
                height: 0;
            }

            .custom-scrollbar::-webkit-scrollbar-thumb {
                min-height: 36px;
                border-width: 2px;
                background: rgba(203, 213, 225, 0.9);
                background-clip: content-box;
            }

            .custom-scrollbar::-webkit-scrollbar-thumb:hover {
                background: rgb(var(--c-primary-400) / 0.85);
                background-clip: content-box;
            }

            .chat-input-scrollbar {
                scrollbar-color: transparent transparent;
            }

            .chat-input-scrollbar::-webkit-scrollbar {
                width: 6px;
                height: 0;
            }

            .chat-input-scrollbar::-webkit-scrollbar-thumb {
                background: transparent;
                border: 2px solid transparent;
                border-radius: 999px;
                background-clip: content-box;
            }

            .chat-input-scrollbar:hover,
            .chat-input-scrollbar:focus {
                scrollbar-color: rgba(203, 213, 225, 0.86) transparent;
            }

            .chat-input-scrollbar:hover::-webkit-scrollbar-thumb,
            .chat-input-scrollbar:focus::-webkit-scrollbar-thumb {
                background: rgba(203, 213, 225, 0.9);
                background-clip: content-box;
            }

            .markdown-body pre,
            .markdown-body table {
                scrollbar-width: none;
            }

            .markdown-body pre::-webkit-scrollbar,
            .markdown-body table::-webkit-scrollbar {
                display: none;
                width: 0;
                height: 0;
            }
        }

        :root {
            --app-font-modern: "Inter", "HarmonyOS Sans SC", "MiSans", "OPPO Sans", "Alibaba PuHuiTi 3.0", "Alibaba PuHuiTi", "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei UI", "Segoe UI", Arial, sans-serif;
            --app-font-system: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
            --app-font-serif: "Lora", "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", STSong, SimSun, Georgia, Cambria, "Times New Roman", Times, serif;
            --app-font-family: var(--app-font-modern);
            --navigation-font-weight: 500;
        }

        body {
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #f9fafb;
            color: #1f2937;
            font-family: var(--app-font-family) !important;
            font-size: 100% !important;
            font-weight: 500 !important;
            -webkit-text-size-adjust: 100% !important;
            -moz-text-size-adjust: 100% !important;
            -ms-text-size-adjust: 100% !important;
            text-size-adjust: 100% !important;
        }

        .font-normal {
            font-weight: 500 !important;
        }

        #app {
            font-family: var(--app-font-family) !important;
            height: var(--app-visual-height, 100%);
            min-height: 0;
        }

        :root[data-app-font="serif"] {
            --app-font-family: var(--app-font-serif);
            --navigation-font-weight: 600;
        }

        :root[data-app-font="modern"] {
            --app-font-family: var(--app-font-modern);
        }

        :root[data-app-font="system"] {
            --app-font-family: var(--app-font-system);
        }

        .app-logo,
        .app-logo *,
        .entry-transition-logo,
        .entry-transition-logo * {
            font-family: var(--app-font-serif) !important;
        }

        .app-native-fullscreen,
        html:fullscreen #app,
        html:-webkit-full-screen #app {
            width: 100vw;
            height: var(--app-visual-height, 100vh);
            background-color: #f9fafb;
        }

        .app-native-fullscreen .app-navigation-layer,
        .app-native-fullscreen .app-nav-trigger,
        html:fullscreen #app .app-navigation-layer,
        html:fullscreen #app .app-nav-trigger,
        html:-webkit-full-screen #app .app-navigation-layer,
        html:-webkit-full-screen #app .app-nav-trigger {
            display: none !important;
        }

        .app-native-fullscreen .app-main,
        html:fullscreen #app .app-main,
        html:-webkit-full-screen #app .app-main {
            width: 100vw;
            max-width: 100vw;
            flex: 1 1 auto;
        }

        /* A single glass navigation surface; no permanently occupied sidebar. */
        .app-nav-trigger--embedded,
        .app-navigation-panel {
            -webkit-backdrop-filter: blur(var(--navigation-blur, 24px)) saturate(155%) !important;
            backdrop-filter: blur(var(--navigation-blur, 24px)) saturate(155%) !important;
            background: linear-gradient(145deg, rgba(255, 255, 255, 0.86), rgba(245, 248, 253, 0.65) 65%, rgba(255, 255, 255, 0.76));
            border: 1px solid rgba(255, 255, 255, 0.75);
        }

        .app-nav-trigger {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex: 0 0 auto;
            margin-right: 12px;
            color: #6b7280;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            transition: color 0.15s ease;
        }

        .app-nav-trigger--chat {
            color: rgba(255, 255, 255, 0.8);
        }
        .app-nav-trigger--chat:hover { color: #fff; }

        .app-nav-trigger--embedded {
            position: absolute;
            left: 6px;
            top: 48%;
            z-index: 20;
            width: 38px;
            height: 38px;
            margin-right: 0;
            border-radius: 12px;
            color: #475569;
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), inset 0 -1px 0 rgba(100, 116, 139, 0.09), 0 8px 24px -14px rgba(15, 23, 42, 0.3);
            transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
        }
        .app-nav-trigger--embedded::before { content: ''; position: absolute; inset: -3px; }
        .app-nav-trigger--embedded svg { width: 21px; height: 21px; }

        .app-navigation-layer {
            position: fixed;
            inset: 0;
            z-index: 50;
        }

        .app-navigation-layer--centered {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .app-navigation-layer--centered .app-navigation-panel {
            position: relative;
            top: auto;
            left: auto;
            transform-origin: center;
        }

        .app-navigation-layer::before {
            content: '';
            position: absolute;
            inset: 0;
            background: rgba(15, 23, 42, 0.12);
            pointer-events: none;
        }

        .app-navigation-panel {
            position: absolute;
            top: 60px;
            left: 12px;
            display: flex;
            flex-direction: column;
            width: min(376px, calc(100vw - 24px));
            max-height: calc(var(--app-visual-height, 100dvh) - 24px);
            overflow: hidden;
            border-radius: 28px;
            color: #334155;
            outline: none;
            transform-origin: top left;
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.98), inset 0 -1px 0 rgba(255, 255, 255, 0.45),
                0 28px 72px -22px rgba(15, 23, 42, 0.32), 0 0 0 1px rgba(100, 116, 139, 0.1);
        }

        .app-navigation-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            flex-shrink: 0;
            padding: 18px 18px 12px 22px;
        }

        .app-navigation-brand { position: relative; display: inline-flex; align-items: center; }
        /* 下划线宽度跟随站名长度，不再写死 44px */
        .app-navigation-brand::after { content: ''; position: absolute; left: 0; right: 0; bottom: 1px; height: 2px; border-radius: 999px; background: linear-gradient(90deg, rgb(var(--c-primary-500)) 0%, rgb(var(--c-primary-400)) 60%, #f43f5e 100%); }
        .app-navigation-brand > span { font-size: 20px; font-weight: 800; letter-spacing: 0.1em; color: rgb(var(--c-primary-900)); }

        .app-navigation-close {
            display: grid;
            place-items: center;
            width: 32px;
            height: 32px;
            border-radius: 50%;
            background: transparent;
            box-shadow: none;
            color: #64748b;
            transition: color 0.2s, transform 0.2s;
        }
        .app-navigation-close svg { width: 18px; height: 18px; }
        .app-navigation-content { overflow-y: auto; overscroll-behavior: contain; min-height: 0; padding: 0 14px 16px; }
        .app-navigation-section + .app-navigation-section { margin-top: 15px; }
        .app-navigation-section h3 { margin: 0 8px 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.12em; color: #64748b; }
        .app-navigation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }

        .app-navigation-item {
            position: relative;
            display: flex;
            align-items: center;
            gap: 10px;
            min-width: 0;
            min-height: 54px;
            padding: 9px 11px;
            border: 1px solid transparent;
            border-radius: 17px;
            background: rgba(255, 255, 255, 0.35);
            font-size: 13px;
            font-weight: var(--navigation-font-weight);
            text-align: left;
            -webkit-tap-highlight-color: transparent;
            transition: background-color 0.2s, border-color 0.2s, color 0.2s, box-shadow 0.2s, transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .app-navigation-icon { display: grid; place-items: center; flex-shrink: 0; width: 29px; height: 29px; border-radius: 10px; color: rgb(var(--c-gray-500)); }
        .app-navigation-icon svg { width: 21px; height: 21px; }
        .app-navigation-item.is-current {
            color: rgb(var(--c-primary-700));
            background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgb(var(--c-primary-100) / 0.85));
            border-color: rgb(var(--c-primary-400) / 0.45);
            box-shadow: inset 0 -1px 0 rgb(var(--c-primary-600) / 0.12), 0 6px 16px -4px rgb(var(--c-primary-600) / 0.22);
        }
        .app-navigation-item.is-current .app-navigation-icon { color: rgb(var(--c-primary-600)); }
        .app-navigation-grid--online { grid-template-columns: repeat(3, minmax(0, 1fr)); }
        .app-navigation-grid--online .app-navigation-item { flex-direction: column; justify-content: center; gap: 5px; padding: 10px 4px; font-size: 12px; }
        .app-navigation-status { position: absolute; top: 10px; right: 10px; width: 5px; height: 5px; border-radius: 50%; background: rgb(var(--c-primary-500)); box-shadow: 0 0 6px rgb(var(--c-primary-500) / 0.6); }

        .app-navigation-user {
            display: flex;
            align-items: center;
            gap: 10px;
            flex-shrink: 0;
            margin: 0 14px 14px;
            padding: 10px 12px;
            border-radius: 18px;
            background: rgba(255, 255, 255, 0.55);
            border: 1px solid rgba(255, 255, 255, 0.75);
        }
        .app-navigation-user img, .app-navigation-avatar { width: 34px; height: 34px; border-radius: 12px; object-fit: cover; flex-shrink: 0; }
        .app-navigation-avatar { display: grid; place-items: center; background: linear-gradient(145deg, rgb(var(--c-primary-400)), rgb(var(--c-primary-700))); color: white; font-size: 15px; }
        .app-navigation-user > div { min-width: 0; }
        .app-navigation-user strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
        .app-navigation-user-mark { width: 24px; height: 3px; margin-left: auto; border-radius: 999px; background: rgb(var(--c-primary-500) / 0.28); }

        .app-nav-trigger:focus-visible, .app-navigation-item:focus-visible, .app-navigation-close:focus-visible { outline: 2px solid rgb(var(--c-primary-500)); outline-offset: 2px; }
        .app-nav-trigger:active, .app-navigation-item:active, .app-navigation-close:active { transform: scale(0.96); }
        @media (hover: hover) and (pointer: fine) {
            .app-nav-trigger--embedded:hover { transform: translateY(-1px); }
            .app-navigation-item:hover { background-color: rgb(var(--c-primary-50) / 0.85); border-color: rgb(var(--c-primary-300) / 0.5); }
            .app-navigation-close:hover { color: #334155; }
        }

        .app-navigation-enter-active::before, .app-navigation-leave-active::before { transition: opacity 0.25s ease; }
        .app-navigation-enter-active .app-navigation-panel { transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease; }
        .app-navigation-leave-active .app-navigation-panel { transition: transform 0.18s ease, opacity 0.16s ease; }
        .app-navigation-enter-from::before, .app-navigation-leave-to::before { opacity: 0; }
        .app-navigation-enter-from .app-navigation-panel, .app-navigation-leave-to .app-navigation-panel { opacity: 0; transform: translateY(-8px) scale(0.94); }

        @media (max-width: 768px) {
            .app-nav-trigger--embedded, .app-navigation-panel { --navigation-blur: 16px; }
            .app-navigation-panel { border-radius: 24px; }
        }
        @supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
            .app-nav-trigger--embedded, .app-navigation-panel { background: rgba(248, 250, 253, 0.98); }
        }
        @media (prefers-reduced-motion: reduce) {
            .app-nav-trigger, .app-navigation-item, .app-navigation-close,
            .app-navigation-enter-active::before, .app-navigation-leave-active::before,
            .app-navigation-enter-active .app-navigation-panel, .app-navigation-leave-active .app-navigation-panel { transition: none; }
        }

        .settings-collapse {
            display: grid;
            grid-template-rows: 0fr;
            opacity: 0;
            pointer-events: none;
            transition:
                grid-template-rows 0.36s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.2s ease;
        }

        .settings-collapse.is-open {
            grid-template-rows: 1fr;
            opacity: 1;
            pointer-events: auto;
        }

        .settings-collapse__inner {
            min-height: 0;
            overflow: hidden;
        }

        .settings-collapse__content {
            opacity: 0.72;
            transform: translateY(-0.375rem);
            transition:
                transform 0.36s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.24s ease;
        }

        .settings-collapse.is-open .settings-collapse__content {
            opacity: 1;
            transform: translateY(0);
        }

        .settings-collapse-trigger {
            transition:
                color 0.22s ease,
                background-color 0.22s ease,
                box-shadow 0.22s ease;
        }

        .settings-collapse-chevron {
            transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1) !important;
        }


        .segmented-switch {
            position: relative;
            display: flex;
            padding: 0.25rem;
            border-radius: 0.75rem;
            background: rgba(249, 250, 251, 0.6);
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
        }

        .segmented-switch__indicator {
            position: absolute;
            inset-block: 0.25rem;
            left: 0.25rem;
            z-index: 0;
            width: calc(50% - 0.25rem);
            border-radius: 0.5rem;
            background: #fff;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s ease-out;
            pointer-events: none;
        }

        .segmented-switch__indicator.is-right {
            transform: translateX(calc(100% + 0.125rem));
        }

        .segmented-switch--three .segmented-switch__indicator {
            width: calc(33.333% - 0.166rem);
        }

        .segmented-switch--three .segmented-switch__indicator.is-position-2 {
            transform: translateX(100%);
        }

        .segmented-switch--three .segmented-switch__indicator.is-position-3 {
            transform: translateX(200%);
        }

        .segmented-switch--four .segmented-switch__indicator {
            width: calc(25% - 0.125rem);
        }

        .segmented-switch--four .segmented-switch__indicator.is-position-2 {
            transform: translateX(100%);
        }

        .segmented-switch--four .segmented-switch__indicator.is-position-3 {
            transform: translateX(200%);
        }

        .segmented-switch--four .segmented-switch__indicator.is-position-4 {
            transform: translateX(300%);
        }

        .segmented-switch__option {
            position: relative;
            z-index: 10;
            display: flex;
            flex: 1 1 0;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 0.5rem 0;
            border-radius: 0.5rem;
            color: #6b7280;
            font-size: 0.875rem;
            font-weight: 700;
            line-height: 1.25rem;
            transition: color 0.2s ease;
        }

        .segmented-switch__option:not(.is-active):hover {
            color: #374151;
        }

        .segmented-switch__option.is-active {
            color: rgb(var(--c-primary-600));
        }

        .segmented-switch--compact .segmented-switch__option {
            font-size: 0.75rem;
            line-height: 1rem;
        }

        .segmented-switch--slim .segmented-switch__option {
            padding-block: 0.375rem;
        }

        .settings-fields {
            display: grid;
            border-top: 1px solid #f3f4f6;
        }

        .settings-field {
            position: relative;
            padding: 1rem 0;
            border-bottom: 1px solid #f3f4f6;
        }

        .settings-field:last-child {
            border-bottom: 0;
            padding-bottom: 0.25rem;
        }

        .settings-model-button {
            width: 100%;
            padding: 0.75rem 0.875rem;
            border: 1px solid #e5e7eb;
            border-radius: 0.75rem;
            background: #fff;
            color: #374151;
            font-size: 0.875rem;
            font-weight: 500;
            line-height: 1.25rem;
            text-align: left;
            cursor: pointer;
            transition: border-color 0.2s ease, box-shadow 0.2s ease;
        }

        .settings-model-button:hover,
        .settings-model-button:focus-visible {
            border-color: rgb(var(--c-primary-500));
            box-shadow: 0 0 0 3.5px rgb(var(--c-primary-500) / 0.18);
            outline: none;
        }

        .settings-icon-button {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0.625rem;
            border: 1px solid rgb(var(--c-primary-800) / 0.12);
            border-radius: 12px;
            background: rgba(255, 255, 255, 0.95);
            color: rgb(var(--c-gray-700));
            box-shadow: 0 1px 3px rgb(var(--c-primary-900) / 0.04);
            transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1),
                        background-color 0.2s ease,
                        border-color 0.2s ease,
                        color 0.2s ease,
                        box-shadow 0.2s ease;
        }

        .settings-icon-button:hover {
            transform: translateY(-1.5px);
            background: rgb(var(--c-primary-50));
            color: rgb(var(--c-primary-600));
            border-color: rgb(var(--c-primary-500) / 0.45);
            box-shadow: 0 4px 12px -2px rgb(var(--c-primary-600) / 0.18);
        }

        .settings-icon-button:active {
            transform: scale(0.96);
        }

        .settings-create-button {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 0.625rem 1rem;
            border: 1px solid rgb(var(--c-primary-500) / 0.3);
            border-radius: 12px;
            background: linear-gradient(180deg, rgb(var(--c-primary-500)) 0%, rgb(var(--c-primary-600)) 100%);
            color: #fff;
            font-weight: 600;
            box-shadow: 0 1px 2px rgb(var(--c-primary-900) / 0.12), 0 4px 12px -2px rgb(var(--c-primary-600) / 0.32);
            transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
        }

        .settings-create-button:hover {
            border-color: rgba(255, 255, 255, 0.3);
            background: linear-gradient(180deg, rgb(var(--c-primary-500)) 0%, rgb(var(--c-primary-500)) 100%);
            color: #fff;
            transform: translateY(-1.5px);
            box-shadow: 0 2px 4px rgb(var(--c-primary-900) / 0.14), 0 8px 18px -3px rgb(var(--c-primary-600) / 0.4);
        }

        .settings-create-button:active {
            transform: scale(0.97);
        }

        .generation-setting-card {
            display: flex;
            flex-direction: column;
            justify-content: center;
            padding: 1rem;
            border: 1px solid #f3f4f6;
            border-radius: 0.75rem;
            background: rgba(249, 250, 251, 0.6);
            transition: all 0.2s ease;
        }

        .generation-setting-card:hover {
            border-color: #e5e7eb;
            background: #fff;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
        }

        .model-setting-row {
            display: flex;
            align-items: center;
            padding: 0.75rem;
            border: 1px solid rgba(243, 244, 246, 0.8);
            border-radius: 0.75rem;
            background: #fff;
            box-shadow: 0 1px 2px rgba(243, 244, 246, 0.6);
            transition: all 0.2s ease;
        }

        .model-setting-row:hover {
            border-color: #e5e7eb;
            box-shadow: 0 4px 6px -1px rgba(243, 244, 246, 0.7), 0 2px 4px -2px rgba(243, 244, 246, 0.7);
        }

        .message-action-bar {
            gap: 0.125rem;
            padding: 0.0625rem 0.125rem;
            border-radius: 9999px;
            border: 1px solid rgba(255, 255, 255, 0.52);
            background: rgba(248, 250, 252, 0.56);
            box-shadow: 0 5px 14px -10px rgba(15, 23, 42, 0.5);
            backdrop-filter: blur(10px) saturate(115%);
            -webkit-backdrop-filter: blur(10px) saturate(115%);
        }

        .message-action-button {
            display: inline-flex;
            width: 1.75rem;
            height: 1.625rem;
            flex: none;
            align-items: center;
            justify-content: center;
            padding: 0;
            border: 0;
            border-radius: 9999px;
            background: transparent;
            color: rgba(75, 85, 99, 0.78);
            box-shadow: none;
            transition: color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;
        }

        .message-action-button:hover {
            color: rgb(var(--c-primary-600));
            background: rgba(255, 255, 255, 0.72);
            transform: translateY(-1px);
        }

        .message-action-button:active {
            transform: scale(0.94);
        }

        .message-style-filter-button {
            display: inline-flex;
            height: 1.625rem;
            flex: none;
            align-items: center;
            gap: 0.25rem;
            padding: 0 0.5rem;
            border: 0;
            border-radius: 9999px;
            background: transparent;
            color: rgba(75, 85, 99, 0.82);
            font-size: 0.625rem;
            font-weight: 700;
            white-space: nowrap;
            transition: color 0.18s ease, background-color 0.18s ease, transform 0.18s ease;
        }

        .message-style-filter-button.is-active {
            color: rgb(var(--c-primary-600));
            background: rgba(255, 255, 255, 0.78);
            outline: none;
        }

        .message-style-filter-button:active {
            transform: scale(0.97);
        }

        .message-style-filter-popover {
            max-width: calc(100vw - 1.5rem);
        }

        @media (max-width: 767px) {
            .message-style-filter-popover {
                transform: translateX(-65%);
            }
        }

        .message-action-button--danger:hover {
            color: #dc2626;
            background: rgba(254, 242, 242, 0.82);
        }

        @media (hover: none) {
            .message-action-button:hover,
            .message-action-button--danger:hover {
                color: rgba(75, 85, 99, 0.78);
                background: transparent;
                transform: none;
            }

            .message-action-button.is-tapped {
                animation: message-action-tap 0.24s ease;
            }
        }

        @keyframes message-action-tap {
            0%, 100% {
                color: rgba(75, 85, 99, 0.78);
                background: transparent;
                transform: none;
            }

            50% {
                color: rgb(var(--c-primary-600));
                background: rgba(255, 255, 255, 0.72);
                transform: translateY(-1px);
            }
        }

        .message-action-button:focus {
            color: rgb(var(--c-primary-600));
            background: rgba(255, 255, 255, 0.72);
            transform: translateY(-1px);
            outline: none;
        }

        .message-action-bar:focus-within {
            opacity: 1 !important;
        }

        .settings-page-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            margin-bottom: 1rem;
        }

        .settings-page-header,
        .character-management-header {
            width: 100%;
            max-width: 64rem;
            margin-inline: auto;
        }

        .management-page-heading {
            display: flex;
            align-items: center;
            min-height: 48px;
        }

        .management-view .app-nav-trigger {
            width: 40px;
            height: 40px;
            padding: 0;
            margin-right: 8px;
        }

        .management-view {
            --management-padding: 1rem;
            height: 100%;
            padding: var(--management-padding);
            overflow-y: auto;
            scrollbar-gutter: stable;
            animation: fadeIn 0.3s ease-out;
        }

        .management-page-heading h2 {
            white-space: nowrap;
        }

        .sortable-list {
            display: grid;
            gap: 12px;
        }

        .sortable-list-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            min-width: 0;
            min-height: 70px;
            padding: 14px 18px;
            border: 1px solid rgb(var(--c-gray-200) / 0.95);
            border-radius: 16px;
            background: rgba(255, 255, 255, 0.96);
            box-shadow: 0 2px 6px -1px rgb(var(--c-primary-900) / 0.04), 0 1px 2px rgb(var(--c-primary-900) / 0.02);
            overflow-anchor: none;
            transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
                        border-color 0.22s ease,
                        box-shadow 0.22s ease,
                        background-color 0.22s ease;
        }

        .sortable-list-item:hover {
            transform: translateY(-2px);
            border-color: rgb(var(--c-primary-500) / 0.45);
            background: #ffffff;
            box-shadow: 0 6px 18px -3px rgb(var(--c-primary-600) / 0.12), 0 2px 6px -1px rgb(var(--c-primary-900) / 0.04);
        }

        .sortable-item-main {
            display: flex;
            align-items: center;
            flex: 1;
            min-width: 0;
            margin-right: 16px;
        }

        .sortable-item-actions,
        .sortable-item-buttons {
            display: flex;
            align-items: center;
            flex-shrink: 0;
        }

        .sortable-item-actions {
            gap: 14px;
        }

        .sortable-item-actions > label {
            min-height: 36px;
        }

        .sortable-item-actions .settings-toggle {
            position: relative;
        }

        .sortable-item-buttons {
            gap: 4px;
            padding-left: 12px;
            border-left: 1px solid #edf0f4;
        }

        .sortable-list-item .item-action-button {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 36px;
            height: 36px;
            padding: 0;
        }

        .sortable-list-item .item-action-button svg {
            width: 18px;
            height: 18px;
        }

        .sortable-list-item .item-action-button:focus-visible,
        button.sortable-item-main:focus-visible {
            outline: 2px solid #a5b4fc;
            outline-offset: 2px;
        }

        .sortable-list-handle {
            display: flex;
            align-items: center;
            justify-content: center;
            flex: 0 0 32px;
            height: 36px;
            margin: -4px 8px -4px -4px;
            border-radius: 8px;
            color: #9ca3af;
            cursor: grab;
            touch-action: none;
            user-select: none;
            transition: color 160ms ease, background-color 160ms ease;
        }

        .sortable-list-handle:hover,
        .sortable-list-chosen .sortable-list-handle {
            color: #64748b;
            background: #f1f5f9;
        }

        .sortable-list-chosen {
            border-color: #cbd5e1;
        }

        .sortable-list-chosen .sortable-list-handle {
            cursor: grabbing;
        }

        .sortable-list-placeholder {
            opacity: 0.28;
            box-shadow: none;
        }

        .sortable-list-preview {
            opacity: 1 !important;
            border-color: #b9c5d6;
            box-shadow: 0 16px 36px -12px rgba(30, 41, 59, 0.3), 0 3px 10px rgba(30, 41, 59, 0.08);
            transition: none !important;
            will-change: transform;
        }

        .sortable-item-heading {
            display: flex;
            align-items: center;
            gap: 8px;
            min-width: 0;
        }

        .sortable-item-heading > h3 {
            min-width: 0;
            max-width: 100%;
            color: #334155;
            font-size: 15px;
            line-height: 22px;
            font-weight: 600;
        }

        .meta-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            gap: 4px;
            padding: 3px 8px;
            border: 1px solid var(--badge-border, #e2e8f0);
            border-radius: 7px;
            background: var(--badge-bg, #f8fafc);
            color: var(--badge-color, #64748b);
            box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
            font-size: 11px;
            font-weight: 600;
            line-height: 16px;
            white-space: nowrap;
        }

        .meta-badge--role {
            min-width: 70px;
            text-transform: uppercase;
            letter-spacing: 0.035em;
        }

        .meta-badge--system {
            --badge-color: #b44859;
            --badge-bg: #fff0f2;
            --badge-border: #f1cbd2;
        }

        .meta-badge--user,
        .meta-badge--memory {
            --badge-color: rgb(var(--c-primary-600));
            --badge-bg: rgb(var(--c-primary-50));
            --badge-border: rgb(var(--c-primary-200));
        }

        .meta-badge--assistant {
            --badge-color: #8051b0;
            --badge-bg: #f4edfc;
            --badge-border: #dfcef0;
        }

        .meta-badge--global {
            --badge-color: #4868b8;
            --badge-bg: #eef3ff;
            --badge-border: #cedafa;
        }

        .meta-badge--bound {
            --badge-color: #966a24;
            --badge-bg: #fff6e3;
            --badge-border: #efdab0;
        }

        .meta-badge--tool {
            --badge-color: #247d94;
            --badge-bg: #ecf8fc;
            --badge-border: #c0e3ed;
        }

        .message-placement {
            --badge-color: rgb(var(--c-primary-600));
            --badge-bg: rgb(var(--c-primary-50));
            --badge-border: rgb(var(--c-primary-200));
            position: relative;
            display: flex;
            align-items: center;
            flex: 1;
            gap: 8px;
            min-height: 40px;
            padding: 9px 12px;
            border: 1px solid #e2e8f0;
            border-radius: 10px;
            background: #fff;
            color: #64748b;
            cursor: pointer;
            user-select: none;
            transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
        }

        .message-placement:hover,
        .message-placement:focus-within {
            border-color: var(--badge-color);
        }

        .message-placement:focus-within {
            outline: 2px solid var(--badge-border);
            outline-offset: 2px;
        }

        .message-placement.is-selected {
            background: var(--badge-bg);
            border-color: var(--badge-border);
            color: var(--badge-color);
        }

        .message-placement-check {
            display: flex;
            align-items: center;
            justify-content: center;
            flex: 0 0 16px;
            height: 16px;
            border: 1px solid #cbd5e1;
            border-radius: 5px;
            background: #fff;
        }

        .message-placement.is-selected .message-placement-check {
            border-color: var(--badge-color);
            background: var(--badge-color);
        }

        @media (max-width: 767px) {
            .meta-badge--desktop {
                display: none;
            }

            .sortable-list {
                gap: 10px;
            }

            .sortable-list-item {
                min-height: 64px;
                padding: 12px;
            }

            .sortable-item-main {
                margin-right: 10px;
            }

            .sortable-list-handle {
                margin-right: 6px;
            }

            .sortable-item-heading > h3 {
                font-size: 14px;
                line-height: 21px;
            }

            .sortable-item-actions {
                gap: 8px;
            }

            .sortable-item-buttons {
                padding-left: 8px;
            }

            .sortable-list-item .item-action-button {
                width: 32px;
            }
        }

        @media (prefers-reduced-motion: reduce) {
            .sortable-list-item,
            .sortable-list-handle,
            .message-placement {
                transition: none;
            }
        }

        @media (max-width: 360px) {
            .management-page-heading h2 {
                font-size: 18px;
            }

            .settings-page-header .settings-icon-button,
            .settings-page-header .settings-create-button {
                padding: 7px;
            }
        }

        .memory-summary + .memory-summary {
            padding-top: 16px;
            border-top: 1px solid #e5e7eb;
        }

        .memory-compression {
            margin: 0 4px 20px;
            font-size: 12px;
            line-height: 18px;
            font-variant-numeric: tabular-nums;
        }

        .memory-compression strong { font-weight: 600; }
        .memory-compression__labels { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; }
        .memory-compression__labels > div { flex: 1; min-width: 0; }
        .memory-compression__labels span { white-space: nowrap; }
        .memory-compression__before { text-align: right; color: #64748b; }
        .memory-compression__after { color: rgb(var(--c-primary-700)); font-weight: 600; }

        .memory-compression__track { position: relative; height: 6px; border-radius: 999px; background: rgb(var(--c-primary-100)); }
        .memory-compression__fill { width: var(--summary-retained); height: 100%; border-radius: inherit; background: linear-gradient(90deg, rgb(var(--c-primary-500)), rgb(var(--c-primary-400))); }
        .memory-compression__marker-before,
        .memory-compression__marker-after { position: absolute; top: -4px; width: 2px; height: 14px; border-radius: 2px; }
        .memory-compression__marker-before { right: -1px; background: rgb(var(--c-gray-400)); }
        .memory-compression__marker-after { left: var(--summary-retained); background: rgb(var(--c-primary-600)); transform: translateX(-50%); }

        .settings-section-heading {
            display: flex;
            align-items: center;
            margin-bottom: 1rem;
            color: #9ca3af;
            font-size: 0.75rem;
            line-height: 1rem;
            font-weight: 700;
            letter-spacing: 0.05em;
            text-transform: uppercase;
        }

        .compact-modal-panel {
            position: relative;
            z-index: 10;
            display: flex;
            width: 100%;
            max-width: 24rem;
            flex-direction: column;
            overflow: hidden;
            border: 1px solid #e5e7eb;
            border-radius: 0.75rem;
            background: #fff;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
            transition: all 0.15s ease;
        }

        .item-action-button {
            padding: 0.5rem;
            border-radius: 0.5rem;
            color: #9ca3af;
            transition: color 0.15s ease, background-color 0.15s ease;
        }

        .item-action-button--edit:hover {
            background: rgb(var(--c-primary-50));
            color: rgb(var(--c-primary-600));
        }

        .item-action-button--delete:hover {
            background: #fef2f2;
            color: #dc2626;
        }

        .pagination-button {
            display: flex;
            align-items: center;
            gap: 0.25rem;
            padding: 0.375rem 0.625rem;
            border: 1px solid #e5e7eb;
            border-radius: 0.5rem;
            background: #fff;
            color: #6b7280;
            font-size: 0.75rem;
            line-height: 1rem;
            font-weight: 500;
            transition: color 0.15s ease, border-color 0.15s ease;
        }

        .pagination-button:hover:not(:disabled) {
            border-color: rgb(var(--c-primary-200));
            color: rgb(var(--c-primary-600));
        }

        .pagination-button:disabled {
            cursor: not-allowed;
            opacity: 0.4;
        }


        .settings-toggle {
            width: 2.75rem;
            height: 1.5rem;
            border-radius: 999px;
            background: #e5e7eb;
            transition: background-color 0.2s ease, box-shadow 0.2s ease;
        }

        .settings-toggle::after {
            content: '';
            position: absolute;
            top: 0.125rem;
            left: 0.125rem;
            width: 1.25rem;
            height: 1.25rem;
            border: 1px solid #d1d5db;
            border-radius: 999px;
            background: #fff;
            transition: none;
        }

        .settings-toggle-input:focus-visible + .settings-toggle {
            box-shadow: 0 0 0 2px rgb(var(--c-primary-300));
        }

        .settings-toggle-input:checked + .settings-toggle {
            background: rgb(var(--c-primary-600));
        }

        .settings-toggle-input:checked + .settings-toggle::after {
            border-color: #fff;
            transform: translateX(100%);
        }

        .settings-toggle--compact {
            width: 2.5rem;
            height: 1.375rem;
        }

        .settings-toggle--compact::after {
            top: 0.1875rem;
            left: 0.1875rem;
            width: 1rem;
            height: 1rem;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
        }

        .settings-toggle-input:checked + .settings-toggle--compact {
            background: linear-gradient(to right, rgb(var(--c-primary-500)), rgb(var(--c-primary-600)));
        }

        .settings-toggle-input:checked + .settings-toggle--indigo {
            background: #6366f1;
        }

        .settings-toggle-input:checked + .settings-toggle--solid {
            background: rgb(var(--c-primary-600));
        }

        .settings-toggle-input:checked + .settings-toggle--compact::after {
            transform: translateX(1.125rem);
        }

        label:active .settings-toggle::after,
        label:focus-within .settings-toggle::after {
            transition: all 0.2s ease;
        }

        .editor-modal-header {
            display: flex;
            flex-shrink: 0;
            align-items: center;
            justify-content: space-between;
            padding: 1rem;
            border-bottom: 1px solid #f3f4f6;
            background: rgba(249, 250, 251, 0.8);
            backdrop-filter: blur(4px);
        }

        .modal-close-button {
            padding: 0.5rem;
            border-radius: 999px;
            color: #9ca3af;
            transition: all 0.15s ease;
        }

        .modal-close-button:hover {
            background: #f3f4f6;
            color: #4b5563;
        }

        .modal-primary-button {
            display: flex;
            align-items: center;
            padding: 0.625rem 1.5rem;
            border-radius: 0.75rem;
            background: rgb(var(--c-primary-600));
            color: #fff;
            font-size: 0.875rem;
            line-height: 1.25rem;
            font-weight: 700;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
            transition: all 0.15s ease;
        }

        .modal-primary-button:hover {
            background: rgb(var(--c-primary-700));
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
        }

        .modal-primary-button:active {
            transform: scale(0.95);
        }

        .modal-secondary-button {
            padding: 0.625rem 1.25rem;
            border: 1px solid #e5e7eb;
            border-radius: 0.75rem;
            background: #fff;
            color: #374151;
            font-size: 0.875rem;
            line-height: 1.25rem;
            font-weight: 500;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
            transition: all 0.15s ease;
        }

        .modal-secondary-button:hover {
            background: #f3f4f6;
        }

        .modal-secondary-button:active {
            transform: scale(0.95);
        }

        .choice-card {
            display: flex;
            align-items: center;
            padding: 1rem;
            border: 1px solid #f3f4f6;
            border-radius: 0.75rem;
            background: #f9fafb;
            color: #374151;
            cursor: pointer;
            text-align: left;
            transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
        }

        .choice-card:hover {
            border-color: rgb(var(--c-primary-200));
            background: rgb(var(--c-primary-50));
            color: rgb(var(--c-primary-700));
        }

        .choice-card__icon {
            display: flex;
            width: 2.5rem;
            height: 2.5rem;
            margin-right: 1rem;
            flex-shrink: 0;
            align-items: center;
            justify-content: center;
            border-radius: 0.5rem;
            background: #fff;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
            transition: transform 0.15s ease;
        }

        .choice-card:hover .choice-card__icon {
            transform: scale(1.1);
        }

        .settings-help-trigger {
            display: inline-flex;
            width: 0.9375rem;
            height: 0.9375rem;
            margin-left: 0.25rem;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            border: 1px solid #e5e7eb;
            border-radius: 999px;
            background: #fff;
            color: #9ca3af;
            transition: color 0.16s ease, border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
        }

        .settings-help-trigger svg {
            width: 0.9375rem;
            height: 0.9375rem;
        }

        .settings-help-trigger:hover {
            color: rgb(var(--c-primary-600));
            border-color: rgb(var(--c-primary-200));
            background: rgb(var(--c-primary-50));
        }

        .settings-help-trigger.is-open {
            color: rgb(var(--c-primary-700));
            border-color: rgb(var(--c-primary-300));
            background: rgb(var(--c-primary-100));
            box-shadow: 0 1px 2px rgb(var(--c-primary-600) / 0.12);
        }

        .settings-help-trigger:focus-visible {
            outline: 2px solid rgb(var(--c-primary-500) / 0.28);
            outline-offset: 1px;
        }

        .settings-help-popover {
            position: absolute;
            left: 0;
            top: 1.5rem;
            z-index: 30;
            width: 16rem;
            max-width: calc(100vw - 4rem);
            padding: 0.625rem 0.75rem;
            border: 1px solid rgb(var(--c-primary-100));
            border-radius: 0.75rem;
            background: rgba(255, 255, 255, 0.98);
            color: #4b5563;
            font-size: 0.6875rem;
            font-weight: 400;
            line-height: 1.55;
            box-shadow: 0 12px 28px -14px rgb(var(--c-primary-600) / 0.35);
            animation: settings-help-in 0.16s ease-out both;
        }

        .settings-help-popover.is-above {
            top: auto;
            bottom: 1.5rem;
        }

        .memory-mode-help-popover {
            top: 2.25rem;
            text-align: left;
        }

        .memory-mode-help-popover.is-right {
            right: 0;
            left: auto;
        }

        .token-usage-help-popover {
            top: calc(100% + 0.5rem);
            left: 0.75rem;
        }

.token-usage-help-popover.is-right {
            right: 0.75rem;
            left: auto;
        }

        .settings-help-popover-content {
            display: block;
            padding-left: 0.5rem;
            border-left: 2px solid rgb(var(--c-primary-400));
        }

        @keyframes settings-help-in {
            from { opacity: 0; transform: translateY(-2px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @media (prefers-reduced-motion: reduce) {
            .settings-collapse,
            .settings-collapse__content,
            .settings-collapse-chevron,
            .segmented-switch__indicator,
            .character-deck__item,
            .character-card--deck,
            .character-deck__arrow,
            .character-deck__enter,
            .character-backdrop-enter-active,
            .character-backdrop-leave-active,
            .dropdown-enter-active,
            .dropdown-leave-active,
            .desc-panel-chevron {
                transition-duration: 0.01ms !important;
                transition-delay: 0s !important;
            }

            .settings-help-popover {
                animation: none;
            }

            .character-deck--opening .character-deck__item { animation-duration: 0.01ms !important; }
        }

        @media (min-width: 768px) {
            .message-action-button {
                width: 1.875rem;
                height: 1.75rem;
            }

            .message-style-filter-button {
                height: 1.75rem;
            }


            .editor-modal-header {
                padding: 1.25rem;
            }

            .settings-page-header {
                margin-bottom: 1.5rem;
            }

            .management-view {
                --management-padding: 1.5rem;
            }
        }

        @media (min-width: 640px) and (orientation: landscape) {
            .management-view:not(.character-management--deck) > * {
                max-width: 64rem;
                margin-inline: auto;
            }
        }

        /* Markdown Body Layout Reset for Full-width Content */
        .message-content-wrapper {
            min-width: 0;
            max-width: 100%;
            overflow-wrap: anywhere;
            word-break: break-word;
        }

        .message-content-wrapper.has-user-images > .markdown-body > *:first-child {
            padding-top: 0.4rem;
        }

        .message-content-wrapper.has-user-images > .markdown-body > *:last-child {
            padding-bottom: 0.55rem;
        }

        .chat-quick-panel .settings-toggle--compact {
            position: relative;
        }

        .chat-quick-panel .settings-toggle-input:checked + .settings-toggle--compact::after {
            left: calc(100% - 1.1875rem);
            transform: none;
        }

        .chat-quick-panel .compact-range {
            height: 20px;
            margin: 0;
            background: linear-gradient(#dbe4f0, #dbe4f0) center / 100% 3px no-repeat;
        }

        .chat-model-slots > .segmented-switch__indicator {
            inset-block-end: auto;
            width: calc(100% - 0.5rem);
            height: calc((100% - 1.25rem) / 3);
            transform: translateY(calc(var(--slot-index, 0) * (100% + 0.375rem)));
        }

        .compact-range::-webkit-slider-thumb {
            width: 13px;
            height: 13px;
            border-radius: 999px;
            -webkit-appearance: none;
            appearance: none;
            background: rgb(var(--c-primary-500));
        }

        .compact-range::-moz-range-thumb {
            width: 13px;
            height: 13px;
            border: 0;
            border-radius: 999px;
            background: rgb(var(--c-primary-500));
        }

        .markdown-body {
            display: flex;
            flex-direction: column;
            min-width: 0;
            max-width: 100%;
            overflow-wrap: anywhere;
            word-break: break-word;
        }

        /* Default padding for text elements */
        .markdown-body > * {
            min-width: 0;
            max-width: 100%;
            overflow-wrap: anywhere;
            word-break: break-word;
            padding-left: 0.9rem;
            padding-right: 0.8rem;
            margin-bottom: 0.75em;
            text-align: left;
        }

        /* Top/Bottom padding simulation */
        .markdown-body > *:first-child { padding-top: 0.75rem; }
        .markdown-body > *:last-child { padding-bottom: 0.75rem; margin-bottom: 0; }

        /* Full-width elements (iframe) */
        .markdown-body > iframe,
        .markdown-body > .html-card-container {
            width: 100%;
            min-width: 100%;
            align-self: stretch;
            padding: 0 !important;
            margin-left: 0 !important;
            margin-right: 0 !important;
            max-width: none;
            overflow: hidden !important;
        }

        .markdown-body > .html-card-container > iframe {
            display: block;
            width: 100% !important;
            min-width: 0;
        }

        /* Standalone HTML may use 100vw; keep its root inside the chat bubble. */
        .markdown-body > style:first-child ~ :not(style):not(script) {
            min-width: 0 !important;
            max-width: 100% !important;
        }

        .markdown-body p { color: inherit; }
        .markdown-body ul { list-style-type: disc; margin-left: 1.5em; color: inherit; }
        .markdown-body ol { list-style-type: decimal; margin-left: 1.5em; color: inherit; }
        .markdown-body code { background-color: #f1f5f9; padding: 0.2em 0.45em; border-radius: 0.5em; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; color: rgb(var(--c-primary-600)); font-size: 0.9em; }
        .markdown-body pre { background-color: #f8fafc; padding: 1.25em; border-radius: 1rem; overflow-x: auto; border: 1px solid #e2e8f0; margin-left: 0.5rem; margin-right: 0.5rem; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
        .markdown-body pre code { background-color: transparent; padding: 0; color: #1f2937; border-radius: 0; }
        .markdown-body blockquote { border-left: 4px solid #e5e7eb; padding-left: 1em; color: #6b7280; margin-left: 0.5rem; margin-right: 0.5rem; border-radius: 0 0.5rem 0.5rem 0; }

        /* Enhanced Markdown Styles */
        .markdown-body strong { font-weight: 700; color: inherit; }
        .markdown-body em { font-style: italic; }
        .markdown-body h1 { font-size: 1.5em; font-weight: 700; margin-top: 1em; margin-bottom: 0.5em; line-height: 1.2; color: inherit; }
        .markdown-body h2 { font-size: 1.25em; font-weight: 600; margin-top: 1em; margin-bottom: 0.5em; line-height: 1.25; color: inherit; }
        .markdown-body h3 { font-size: 1.1em; font-weight: 600; margin-top: 1em; margin-bottom: 0.5em; line-height: 1.3; color: inherit; }
        .markdown-body h4 { font-weight: 600; margin-top: 1em; margin-bottom: 0.5em; color: inherit; }
        .markdown-body a { color: rgb(var(--c-primary-600)); text-decoration: underline; text-underline-offset: 2px; overflow-wrap: anywhere; word-break: break-word; }
        .markdown-body a:hover { color: rgb(var(--c-primary-700)); }
        .markdown-body hr { border: 0; border-top: 1px solid #e5e7eb; margin: 1.5em 0.5rem; height: 1px; }
        .markdown-body table { width: auto; border-collapse: collapse; margin: 0 0.5rem 1em 0.5rem; display: block; overflow-x: auto; }
        .markdown-body th, .markdown-body td { border: 1px solid #e5e7eb; padding: 0.5em 0.75em; text-align: left; }
        .markdown-body th { background-color: #f9fafb; font-weight: 600; }
        .markdown-body del { text-decoration: line-through; color: inherit; opacity: 0.7; }

        .generated-image-card {
            position: relative;
        }

        .generated-image-reroll {
            position: absolute;
            right: 0.65rem;
            bottom: 0.65rem;
            z-index: 4;
            display: inline-flex;
            width: 2.1rem;
            height: 2.1rem;
            align-items: center;
            justify-content: center;
            margin: 0;
            padding: 0 !important;
            border: 0;
            background: transparent;
            color: #fff;
            cursor: pointer;
            opacity: 1;
            filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.55));
            transition: opacity 160ms ease;
        }

        .generated-image-reroll svg {
            width: 1.3rem;
            height: 1.3rem;
        }

        .generated-image-progress {
            position: absolute;
            inset: 0;
            z-index: 3;
            display: none;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 0.75rem;
            padding: 1.5rem;
            color: #fff;
            background: rgba(15, 23, 42, 0.18);
            backdrop-filter: blur(4px);
            pointer-events: none;
        }

        .generated-image-card.is-generating {
            min-height: 220px;
        }

        .generated-image-card.is-generating .generated-image-progress,
        .generated-image-card.is-generation-error .generated-image-progress {
            display: flex;
        }

        .generated-image-progress-label {
            font-size: 0.875rem;
            font-weight: 600;
            text-shadow: 0 1px 3px rgba(15, 23, 42, 0.45);
        }

        .generated-image-progress-track {
            width: min(72%, 320px);
            height: 5px;
            overflow: hidden;
            border-radius: 999px;
            background: rgba(255, 255, 255, 0.28);
        }

        .generated-image-progress-bar {
            display: block;
            width: 0;
            height: 100%;
            border-radius: inherit;
            background: #fff;
            transition: width 170ms linear;
        }

        .generated-image-card.is-generation-error .generated-image-spinner,
        .generated-image-card.is-generation-error .generated-image-progress-track {
            display: none;
        }

        .generated-image-spinner {
            width: 72px;
            height: 72px;
            animation: generated-image-spinner-rotate 2s linear infinite;
        }

        .generated-image-spinner-path {
            stroke: #fff;
            stroke-linecap: round;
            animation: generated-image-spinner-dash 1.5s ease-in-out infinite;
        }

        .character-switch-spinner {
            width: 2.75rem;
            height: 2.75rem;
        }

        .generated-image-card.is-generating .generated-image-reroll,
        .generated-image-card.is-rerolling .generated-image-reroll {
            pointer-events: none;
            opacity: 0;
        }

        @keyframes generated-image-spinner-rotate {
            100% { transform: rotate(360deg); }
        }

        @keyframes generated-image-spinner-dash {
            0% {
                stroke-dasharray: 1, 150;
                stroke-dashoffset: 0;
            }
            50% {
                stroke-dasharray: 90, 150;
                stroke-dashoffset: -35;
            }
            100% {
                stroke-dasharray: 90, 150;
                stroke-dashoffset: -124;
            }
        }

        .response-error-text {
            color: #dc2626;
            font-weight: 700;
            white-space: pre-wrap;
            overflow-wrap: anywhere;
            word-break: break-word;
        }

        /* Specific fix for immersive container from regex */
        .markdown-body div[style*="rgba(20, 10, 20, 0.7)"] {
            color: #ffffff !important;
            white-space: pre-wrap; /* Kept pre-wrap strictly for this known regex */
        }



        .msg-bubble-glass {
            background-color: rgba(255, 255, 255, 0.88) !important;
        }

        .message-edit-group {
            width: 100%;
            max-width: 100%;
        }



        .desc-panel-stat-number {
            font-variant-numeric: tabular-nums;
            font-feature-settings: "tnum" 1;
            letter-spacing: 0.01em;
        }



        @media (min-width: 769px) {
            .standard-message-row {
                justify-content: center !important;
            }

            .centered-message-shell {
                width: 50vw;
                max-width: 50vw !important;
            }

            .immersive-message-row {
                justify-content: center !important;
            }

            .immersive-message-shell {
                justify-content: center;
            }

            .immersive-message-column {
                align-items: flex-start !important;
                width: 100%;
            }

            .immersive-message-shell.flex-row-reverse .immersive-message-column {
                align-items: flex-end !important;
            }

            .immersive-message-column > .group:not(.message-edit-group) {
                width: fit-content;
                max-width: 100%;
            }

            .immersive-message-column > .group.w-full {
                width: 100%;
            }

            .immersive-message-column .active-tool-waiting {
                width: fit-content;
                min-width: 9.5rem;
                max-width: 100%;
            }

        }

        /* Mobile optimizations */
        @media (max-width: 768px) {
            .immersive-message-row > .immersive-message-shell {
                max-width: 100%;
            }

            html,
            body,
            #app {
                height: var(--app-visual-height, 100dvh) !important;
                min-height: 0 !important;
                overflow: hidden !important;
                overscroll-behavior: none;
            }

            .app-main,
            .chat-view-root {
                min-height: 0 !important;
                height: var(--app-visual-height, 100dvh) !important;
            }

            .char-bg-blur {
                top: -1rem !important;
                right: -1rem !important;
                bottom: auto !important;
                left: -1rem !important;
                height: calc(var(--chat-bg-height, var(--app-visual-height, 100dvh)) + 2rem) !important;
                transition: none !important;
                background-position: center center !important;
                background-size: cover !important;
                backface-visibility: hidden;
                contain: paint;
            }

            .mobile-keyboard-active .app-main,
            .mobile-keyboard-active .chat-view-root,
            .mobile-keyboard-active .input-area-mobile,
            .mobile-keyboard-active .input-island,
            .mobile-keyboard-active .char-bg-blur {
                transition: none !important;
                animation: none !important;
            }

            .mobile-keyboard-active .char-bg-blur {
                will-change: auto !important;
            }

            /* Hide scrollbar for Chrome, Safari and Opera */
            ::-webkit-scrollbar,
            .custom-scrollbar::-webkit-scrollbar {
                display: none !important;
                width: 0 !important;
                height: 0 !important;
            }

            /* Hide scrollbar for IE, Edge and Firefox + Global kill-switch for backdrop-filter on mobile */
            * {
                -ms-overflow-style: none !important;  /* IE and Edge */
                scrollbar-width: none !important;  /* Firefox */
                backdrop-filter: none !important;
                -webkit-backdrop-filter: none !important;
                -webkit-overflow-scrolling: touch !important;
            }

            /* Disable Tailwind blur-* classes (filter: blur) on mobile, except .char-bg-blur */
            [class*="blur-"]:not(.char-bg-blur) {
                filter: none !important;
            }

            /* Preserve filter blur ONLY for character card background layer */
            .char-bg-blur {
                filter: blur(2px) !important;
            }

            /* ===== Compensate: Replace blur with solid/high-opacity backgrounds ===== */

            /* Toast notifications */
            .toast-item {
                background-color: rgba(255, 255, 255, 0.97) !important;
            }


            /* Description panel overlay */
            .desc-panel-overlay {
                background-color: rgba(0, 0, 0, 0.12) !important;
            }

            /* Description panel itself */
            .desc-panel {
                background-color: rgba(255, 255, 255, 0.97) !important;
            }

            /* Close button in description panel */
            .desc-close-btn:hover {
                background-color: rgba(255, 255, 255, 0.75) !important;
            }

            /* Message name tags */
            .msg-name-tag {
                background-color: rgba(255, 255, 255, 0.7) !important;
            }

            /* Typing indicator bubble */
            .typing-bubble {
                background-color: rgba(255, 255, 255, 0.88) !important;
            }

            /* Typing indicator timer badge */
            .typing-timer-badge {
                background-color: rgba(255, 255, 255, 0.7) !important;
            }

            /* Input area container (mobile bottom bar) */
            .input-area-mobile {
                bottom: var(--keyboard-inset, 0px) !important;
                background-color: transparent !important;
                border-top: none !important;
            }

            /* Input area inner island */
            .input-island {
                background-color: rgba(255, 255, 255, 0.9) !important;
                border: 1px solid rgba(255, 255, 255, 0.45) !important;
                border-radius: 1.5rem !important;
                box-shadow: 0 10px 28px -12px rgba(15, 23, 42, 0.35), 0 1px 2px rgba(15, 23, 42, 0.08) !important;
                -webkit-box-shadow: 0 10px 28px -12px rgba(15, 23, 42, 0.35), 0 1px 2px rgba(15, 23, 42, 0.08) !important;
                --tw-ring-offset-shadow: 0 0 #0000 !important;
                --tw-ring-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04) !important;
                --tw-shadow: 0 10px 28px -12px rgba(15, 23, 42, 0.35), 0 1px 2px rgba(15, 23, 42, 0.08) !important;
                --tw-shadow-colored: 0 10px 28px -12px var(--tw-shadow-color), 0 1px 2px var(--tw-shadow-color) !important;
            }

            /* World Info Footer */
            .wi-footer {
                background-color: rgba(249, 250, 251, 0.95) !important;
            }
        }


        .glass-stabilize {
            will-change: backdrop-filter, transform, opacity;
            -webkit-font-smoothing: subpixel-antialiased;
        }


        /* Elegant Message Entrance Animation */
        .animate-message-in {
            animation: message-in-elegant 0.32s cubic-bezier(0.22, 0.61, 0.36, 1) backwards;
        }

        .animate-message-fade-in {
            animation: message-fade-in 0.35s ease-out backwards;
        }

        @keyframes message-in-elegant {
            0% {
                opacity: 0;
                transform: translateY(28px);
            }
            100% {
                opacity: 1;
                transform: translateY(0);
            }
        }

        @keyframes message-fade-in {
            0% {
                opacity: 0;
            }
            100% {
                opacity: 1;
            }
        }

        .typing-indicator {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 4px 8px;
        }
        .typing-indicator span {
            display: block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: rgb(var(--c-primary-500));
            opacity: 0.6;
            animation: typing 1.4s infinite ease-in-out both;
        }

        .typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
        .typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
        .typing-indicator span:nth-child(3) { animation-delay: 0s; }

        @keyframes typing {
            0%, 80%, 100% { opacity: 0.35; }
            40% { opacity: 1; }
        }

        /* Toast Transitions */
        .toast-stack {
            position: relative;
        }

        .toast-item {
            will-change: transform, opacity;
            transform-origin: top center;
        }

        .list-enter-active,
        .list-leave-active {
            transition:
                opacity 0.26s cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .list-move {
            transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
        }

        .list-leave-active {
            position: absolute;
            z-index: 0;
        }

        .list-enter-from,
        .list-leave-to {
            opacity: 0;
            transform: translateY(-10px) scale(0.98);
        }

        /* Character description panel */
        .dropdown-enter-active,
        .dropdown-leave-active {
            transition:
                opacity 0.28s cubic-bezier(0.22, 0.61, 0.36, 1),
                transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
            will-change: opacity, transform;
            backface-visibility: hidden;
        }

        .dropdown-enter-from,
        .dropdown-leave-to {
            opacity: 0;
            transform: translate3d(0, -0.75rem, 0) scale(0.98);
        }

        .dropdown-enter-to,
        .dropdown-leave-from {
            opacity: 1;
            transform: translate3d(0, 0, 0) scale(1);
        }

        .desc-panel-chevron {
            transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
        }

/* Fade Animation */
.fixed.inset-0.animate-fade-in {
    animation-duration: 0.32s;
    animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
}

.fade-enter-active,
.fade-leave-active {
transition: opacity 0.3s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}

        /* Update Notification Styles */
        .update-content .markdown-body {
            line-height: 1.5 !important;
            letter-spacing: 0.05em !important;
        }
        .update-content .markdown-body > * {
            margin-bottom: 1em !important;
        }
        .update-content .markdown-body li {
            margin-top: 0.5em !important;
            margin-bottom: 0.5em !important;
        }

        /* Performance Optimization for Character Cards */
        .char-grid-item {
            content-visibility: auto;
            contain-intrinsic-size: 1px 300px; /* Rough estimate of card height */
        }

        .character-card-cover {
            transition: transform 400ms cubic-bezier(0.4, 0, 0.2, 1);
        }

        .char-grid-item.is-cover-zoomed .character-card-cover {
            transform: scale(1.1);
        }

        .char-grid-item.is-card-pressing {
            transform: scale(0.94);
            transition-duration: 120ms;
        }

        .char-grid-item.is-card-releasing {
            transform: scale(1);
            transition-duration: 180ms;
        }

        /* Character selection deck: reuse the existing card and its management actions. */
        .character-management--deck {
            padding: 0;
        }

        .character-management--deck > .character-management-content {
            min-height: 100%;
            padding: var(--management-padding);
            position: relative;
            isolation: isolate;
            container-type: inline-size;
            display: flex;
            flex-direction: column;
        }

        .character-deck {
            --deck-easing: cubic-bezier(0.22, 0.72, 0.18, 1);
            --deck-card-width: clamp(240px, min(32cqw, calc((100dvh - 240px) / 1.5)), 560px);
            --deck-spread: 50%;
            display: flex;
            flex: 1 0 auto;
            flex-direction: column;
            justify-content: center;
            width: 100%;
            padding: 4px 0 20px;
        }

        .character-deck:focus-visible { outline: 2px solid rgb(var(--c-primary-300)); outline-offset: -3px; }
        .character-deck__backdrop { position: absolute; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; background: #dde4ee; }
        .character-deck__backdrop img { position: absolute; width: 100%; height: 100%; object-fit: cover; filter: blur(38px) saturate(1.05); opacity: 1; transform: scale(1.12); will-change: opacity; }
        .character-deck__backdrop::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(248, 250, 252, 0.65), rgba(248, 250, 252, 0.04) 45%, rgba(248, 250, 252, 0.28)); }
        .character-backdrop-enter-active, .character-backdrop-leave-active { transition: opacity 0.85s var(--deck-easing); }
        .character-backdrop-enter-from, .character-backdrop-leave-to { opacity: 0 !important; }
        .character-deck__stage {
            position: relative;
            height: calc(var(--deck-card-width) * 1.5 + 42px);
            flex-shrink: 0;
            overflow-x: clip;
            perspective: 1600px;
            touch-action: pan-y pinch-zoom;
            user-select: none;
            cursor: grab;
        }

        .character-deck__item {
            position: absolute;
            top: 8px;
            left: 50%;
            width: var(--deck-card-width);
            height: calc(var(--deck-card-width) * 1.5);
            transform-origin: center 65%;
            transform: translateX(calc(-50% + var(--deck-offset) * var(--deck-spread)))
                translateY(calc(var(--deck-depth) * 10px)) rotateY(calc(var(--deck-offset) * -10deg))
                rotateZ(calc(var(--deck-offset) * 3deg)) scale(calc(1 - var(--deck-depth) * 0.1));
            opacity: calc(1 - var(--deck-depth) * 0.18);
            filter: blur(calc(var(--deck-depth) * 1.6px)) saturate(calc(1 - var(--deck-depth) * 0.12));
            /* 层级立即跟随选中卡片，不能参与渐变，否则退到侧面的卡片会短暂盖住主卡。 */
            transition: transform 0.7s var(--deck-easing), opacity 0.7s var(--deck-easing), filter 0.7s var(--deck-easing);
            will-change: transform, opacity, filter;
        }

        .character-deck--opening .character-deck__item { animation: character-deck-open 0.75s var(--deck-easing) both; }
        @keyframes character-deck-open {
            from { transform: translateX(-50%) translateY(16px) rotateY(0deg) rotateZ(0deg) scale(0.92); }
        }
        .character-deck__stage.is-dragging { cursor: grabbing; }
        .character-deck__stage.is-dragging .character-deck__item { transition: none; }
        .character-deck__stage.is-importing { overflow: hidden; }
        .character-deck__stage.is-importing .character-deck__item.is-focused { transition: none; }
        .character-deck-enter-from, .character-deck-leave-to { opacity: 0; }
        .character-deck-leave-active { pointer-events: none; }
        .character-card--deck {
            height: 100%;
            content-visibility: visible;
            border-radius: 22px;
            border: 0;
            background: #1e293b;
            box-shadow: 0 18px 38px -16px rgba(15, 23, 42, 0.45);
            transition: box-shadow 0.7s var(--deck-easing);
        }

        .is-focused > .character-card--deck { box-shadow: 0 24px 48px -20px rgba(15, 23, 42, 0.5); }
        .character-card--deck::after {
            content: '';
            position: absolute;
            inset: 0;
            z-index: 30;
            border-radius: inherit;
            border: 1px solid rgba(15, 23, 42, 0.4);
            box-shadow: inset 0 1px rgba(255, 255, 255, 0.38), inset 1px 0 rgba(255, 255, 255, 0.12), inset 0 -1px rgba(15, 23, 42, 0.24);
            pointer-events: none;
        }
        .character-deck__placeholder {
            position: absolute;
            inset: 0;
            display: grid;
            place-items: center;
            color: rgba(255, 255, 255, 0.55);
            font-size: 112px;
            font-weight: 800;
            background: radial-gradient(ellipse at 25% 15%, #94a3b8, transparent 65%), linear-gradient(145deg, #475569, #172554);
        }

        .character-card--deck .character-card-name { font-size: clamp(18px, 2vw, 24px); line-height: 1.35; white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
        .character-card--deck > .absolute.bottom-0 { padding: 22px 18px; }
        .character-card--deck .text-\[8px\] { font-size: 10px; }
        .character-card--deck button { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; background: rgba(15, 23, 42, 0.4); }
        .character-card--deck button:hover { background: rgba(15, 23, 42, 0.72); }
        .character-card--deck > .absolute.top-3.right-3 { transition: opacity 0.25s ease; }
        .character-deck__item:not(.is-focused) .character-card--deck > .absolute.top-3.right-3 { opacity: 0; }
        .character-deck__peek { position: absolute; inset: 0; width: 100%; border-radius: 22px; cursor: pointer; }
        .character-deck__peek:focus-visible { outline: 3px solid rgb(var(--c-primary-400)); outline-offset: 3px; }
        .character-deck__navigation { display: grid; grid-template-columns: 46px minmax(0, 1fr) 46px; gap: 20px; align-items: center; width: min(100%, 360px); padding: 0 16px; margin: 0 auto; }
        .character-deck__arrow, .character-deck__enter { display: flex; align-items: center; justify-content: center; height: 46px; border: 1px solid rgba(203, 213, 225, 0.65); transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease; }
        .character-deck__arrow { border-radius: 50%; color: #64748b; background: rgba(255, 255, 255, 0.8); box-shadow: 0 4px 12px -6px rgba(15, 23, 42, 0.18); }
        .character-deck__arrow svg { width: 21px; height: 21px; }
        .character-deck__arrow:hover:not(:disabled) { color: rgb(var(--c-primary-600)); background: rgb(var(--c-primary-50)); transform: translateY(-2px); }
        .character-deck__enter { gap: 18px; border-radius: 16px; border-color: rgba(255, 255, 255, 0.25); background: var(--deck-button-bg, rgb(100, 116, 139)); color: var(--deck-button-text, #fff); font-size: 14px; font-weight: 600; letter-spacing: 0.06em; box-shadow: 0 8px 20px -10px rgba(15, 23, 42, 0.35), inset 0 1px rgba(255, 255, 255, 0.15); transition: transform 0.2s ease, filter 0.2s ease, background-color 0.7s var(--deck-easing), color 0.7s var(--deck-easing); }
        .character-deck__enter svg { width: 18px; height: 18px; }
        .character-deck__enter:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-2px); }
        .character-deck__navigation button:disabled { opacity: 0.45; cursor: default; }

        @media (max-width: 767px) {
            .character-deck { --deck-card-width: min(84cqw, 380px, max(220px, calc((100dvh - 250px) / 1.5))); --deck-spread: 44%; }
            .character-deck__stage { margin-inline: -1rem; }
            .character-deck__backdrop img { filter: blur(25px) saturate(1.05); }
            .character-deck__navigation { gap: 16px; max-width: 340px; margin-top: 12px; }
            .character-card--deck > .absolute.bottom-0 { padding: 18px 14px; }
        }

        /* Chain of Thought (CoT) UI - Enhanced */
        .cot-ui {
            background-color: #ffffff;
            border: 1px solid #e2e8f0;
            border-radius: 0.75rem;
            margin: 0.5rem 0.25rem;
            padding: 0 !important;
            overflow: hidden;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            width: calc(100% - 0.5rem);
            min-width: 0;
        }

        .cot-ui.is-open {
            background: #ffffff;
            border-color: rgb(var(--c-primary-200));
            box-shadow: 0 4px 12px -2px rgb(var(--c-primary-500) / 0.1), 0 2px 6px -2px rgb(var(--c-primary-500) / 0.05);
            margin-top: 0.75rem;
            margin-bottom: 0.75rem;
        }

        .cot-header {
            padding: 0.6rem 0.8rem;
            cursor: pointer;
            font-size: 0.85rem;
            font-weight: 600;
            color: #64748b;
            display: flex;
            align-items: center;
            user-select: none;
            background-color: #ffffff;
            transition: all 0.2s;
            border-radius: 0.75rem;
        }

        .cot-header:hover {
            background-color: rgba(241, 245, 249, 0.8);
            color: rgb(var(--c-primary-500));
        }

        .cot-ui.is-open .cot-header {
            color: rgb(var(--c-primary-600));
            background-color: rgb(var(--c-primary-50));
            border-bottom-left-radius: 0;
            border-bottom-right-radius: 0;
        }

        .thinking-summary-dots {
            width: 0.875rem;
            height: 0.875rem;
            color: rgb(var(--c-primary-500));
            gap: 3px;
        }

        .thinking-summary-dots i {
            width: 5px;
            height: 5px;
            animation-name: thinking-summary-dot;
        }

        @keyframes thinking-summary-dot {
            0%, 80%, 100% {
                opacity: 0.2;
                transform: translateY(0) scale(0.82);
            }
            40% {
                opacity: 1;
                transform: translateY(-2px) scale(1.18);
            }
        }

        .thinking-summary-bulb {
            color: #f59e0b;
        }

        /* Grid Animation for Smooth Height Transition */
        .cot-body {
            display: grid;
            grid-template-rows: 0fr;
            transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .cot-body.is-open {
            grid-template-rows: 1fr;
        }

        .cot-inner {
            overflow: hidden;
        }

        .chevron {
            transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .cot-ui.is-open .chevron {
            transform: rotate(180deg);
        }

        /* CoT Tree List Style */
        .native-thinking-body .markdown-body ul {
            list-style: none !important;
            padding-left: 0.5rem !important;
            margin-left: 0.25rem !important;
        }
        .native-thinking-body .markdown-body ul > li {
            position: relative;
            padding-left: 1.25rem;
            margin-bottom: 0.25rem;
        }
        /* Vertical connecting line */
        .native-thinking-body .markdown-body ul > li::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 2px;
            background-color: #cbd5e1;
        }
        /* Stop vertical line for last item */
        .native-thinking-body .markdown-body ul > li:last-child::before {
            height: 0.65em;
        }
        /* Horizontal indicator line */
        .native-thinking-body .markdown-body ul > li::after {
            content: '';
            position: absolute;
            left: 0;
            top: 0.65em;
            width: 0.8rem;
            height: 2px;
            background-color: #cbd5e1;
        }

        /* Native model reasoning UI */
        .native-thinking-wrapper {
            width: 100%;
            margin: 0;
        }

        .native-thinking-card {
            margin-top: 0.5rem;
            margin-bottom: 0.5rem;
        }

        .summary-timeline-card,
        .summary-timeline-card.is-open {
            margin: 0.25rem 0.1rem 0.35rem;
            width: calc(100% - 0.2rem);
        }

        .native-thinking-header {
            width: 100%;
            border: 0;
            text-align: left;
            font: inherit;
            appearance: none;
            -webkit-appearance: none;
        }

        .native-thinking-card.is-live {
            border-color: rgb(var(--c-primary-200));
            box-shadow: 0 4px 12px -2px rgb(var(--c-primary-500) / 0.1), 0 2px 6px -2px rgb(var(--c-primary-500) / 0.05);
        }

        .native-thinking-card.is-live .native-thinking-body {
            transition: none;
        }

        .native-thinking-body .markdown-body > * {
            padding-left: 0.4rem !important;
            padding-right: 0.4rem !important;
        }

        .native-thinking-card.is-open .chevron {
            transform: rotate(180deg);
        }

        .timeline-tool-title-flow {
            position: absolute;
            inset: 0 auto auto 0;
            max-width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            pointer-events: none;
            font: inherit;
            color: transparent !important;
            opacity: 0.85;
            background-image: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.98) 50%, transparent 100%);
            background-size: 72px 100%;
            background-repeat: no-repeat;
            -webkit-background-clip: text;
            background-clip: text;
            animation: timeline-tool-title-flow 1.65s infinite;
        }

        @keyframes timeline-tool-title-flow {
            0% {
                background-position: -72px 50%;
                animation-timing-function: cubic-bezier(0.22, 0.72, 0.18, 1);
            }
            72% {
                background-position: calc(100% + 72px) 50%;
            }
            100% {
                background-position: calc(100% + 72px) 50%;
            }
        }

        .timeline-step-count {
            display: inline-block;
            margin-left: 0.5rem;
            min-width: 4.75em;
            font-variant-numeric: tabular-nums;
            font-weight: 400;
            opacity: 0.55;
            text-align: left;
            white-space: nowrap;
        }

        .timeline-step-title-row {
            position: relative;
            display: inline-flex;
            align-items: baseline;
            min-width: 0;
            max-width: 100%;
        }

        .timeline-step-title-text {
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .timeline-thinking-detail {
            max-height: min(55vh, 34rem);
            overflow-y: auto !important;
            overflow-x: hidden !important;
            overscroll-behavior: contain;
        }

        .tool-call-detail {
            display: flex;
            flex-direction: column;
            gap: 0.55rem;
            color: #334155;
            font-size: 0.78rem;
            font-family: inherit !important;
        }

        .tool-call-detail pre,
        .tool-call-detail code {
            font-family: inherit !important;
        }

        .tool-description-preview {
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }

        .active-tool-waiting {
            min-height: 5rem;
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            padding: 1.25rem 0.75rem 1rem;
        }

/* Lightweight live-state indicators */
@keyframes live-dot {
    0%, 80%, 100% { opacity: 0.35; }
    40% { opacity: 1; }
}

.live-dots,
.ui-build-dots {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    gap: 4px;
}

.live-dots i,
.ui-build-dots i {
    display: block;
    border-radius: 999px;
    background: currentColor;
    animation: live-dot 1.25s ease-in-out infinite;
}

.live-dots i {
    width: 4px;
    height: 4px;
}

.ui-build-dots {
    color: rgb(var(--c-primary-500));
    gap: 8px;
    min-height: 3rem;
}

.ui-build-dots i {
    width: 10px;
    height: 10px;
}

.live-dots i:nth-child(2),
.ui-build-dots i:nth-child(2) {
    animation-delay: 0.15s;
}

.live-dots i:nth-child(3),
.ui-build-dots i:nth-child(3) {
    animation-delay: 0.3s;
}

/* --- Scroll Reveal Animations for Chat Bubbles --- */
.scroll-reveal-left {
    opacity: 0;
    transform: translateX(-150px);
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform, opacity;
}

.scroll-reveal-right {
    opacity: 0;
    transform: translateX(150px);
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform, opacity;
}

.scroll-reveal-center {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
    transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform, opacity;
}

.reveal-active,
.scroll-reveal-container[data-revealed="true"] {
    opacity: 1 !important;
    transform: translate3d(0, 0, 0) scale(1) !important;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .scroll-reveal-left, .scroll-reveal-right, .scroll-reveal-center {
        transform: none !important;
        transition: opacity 0.3s ease !important;
    }
}

/* UI template render safety */
.ui-template-render,
.ui-template-preview {
    width: 100%;
    max-width: 100%;
}
.ui-template-render {
    display: block;
    align-self: stretch;
    min-width: 0;
}
.ui-template-render > iframe,
.ui-template-render > .html-card-container,
.ui-template-preview > iframe,
.ui-template-preview > .html-card-container {
    width: 100%;
    min-width: 100%;
    align-self: stretch;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none;
    overflow: hidden !important;
}

.ui-template-render > .html-card-container > iframe,
.ui-template-preview > .html-card-container > iframe {
    display: block;
    width: 100% !important;
    min-width: 0;
    border: 0 !important;
    margin: 0 !important;
}

.ui-template-render .bottom-safe {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}
.ui-template-render *,
.ui-template-render *::before,
.ui-template-render *::after,
.ui-template-preview *,
.ui-template-preview *::before,
.ui-template-preview *::after {
    box-sizing: border-box;
    max-width: 100%;
}
.ui-template-render img,
.ui-template-preview img,
.ui-template-render svg,
.ui-template-preview svg {
    max-width: 100%;
    height: auto;
}
.ui-template-message-block {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    gap: 0.75rem;
    width: 100%;
    padding-left: 0;
    padding-right: 0;
}
.ui-template-message-block-top {
    padding-top: 0;
}
.ui-template-message-block-bottom {
    padding-bottom: 0;
}
.ui-template-message-block + .native-thinking-wrapper,
.ui-template-message-block + .markdown-body {
    margin-top: 0;
}
.ui-template-pending-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    min-height: 4.25rem;
    padding: 0.8rem 0.95rem;
    color: #334155;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 255, 0.92)),
        linear-gradient(90deg, rgba(79, 70, 229, 0.05), rgba(14, 165, 233, 0.04));
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 0.95rem;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.85);
    overflow: hidden;
}

.ui-template-pending-icon {
    position: relative;
    z-index: 1;
    width: 2.35rem;
    height: 2.35rem;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 0.8rem;
    color: #4f46e5;
    background: rgba(238, 242, 255, 0.9);
    border: 1px solid rgba(129, 140, 248, 0.24);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.ui-template-pending-icon svg {
    width: 1.1rem;
    height: 1.1rem;
}

.ui-template-pending-icon .live-dots {
    position: absolute;
    right: -0.12rem;
    bottom: -0.12rem;
    width: 1.1rem;
    height: 0.7rem;
    gap: 2px;
    color: #0ea5e9;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(14, 165, 233, 0.18);
    border-radius: 999px;
    box-shadow: 0 3px 8px rgba(14, 165, 233, 0.1);
}

.ui-template-pending-icon .live-dots i {
    width: 3px;
    height: 3px;
}

.ui-template-pending-content {
    position: relative;
    z-index: 1;
    flex: 1;
    min-width: 0;
}

.ui-template-pending-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.ui-template-pending-title {
    font-size: 0.95rem;
    line-height: 1.2;
    font-weight: 800;
    color: #1e293b;
}

@media (max-width: 520px) {
    .ui-template-pending-card {
        align-items: center;
        padding: 0.78rem 0.85rem;
    }

    .ui-template-pending-icon {
        width: 2.25rem;
        height: 2.25rem;
        border-radius: 0.75rem;
    }

    .ui-template-pending-row {
        gap: 0.45rem;
    }

}

@media (max-width: 768px) and (orientation: portrait) {
    #active-tools-list .tool-description-preview {
        display: none;
    }
}

.usage-roll-enter-active,
.usage-roll-leave-active {
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.24s ease;
    will-change: transform, opacity;
}

.usage-roll-enter-from {
    opacity: 0;
    transform: translateY(75%);
}

.usage-roll-leave-to {
    opacity: 0;
    transform: translateY(-75%);
}

@media (prefers-reduced-motion: reduce) {
    .usage-roll-enter-active,
    .usage-roll-leave-active {
        transition: none;
    }
}

.story-route-modal-body {
    display: flex;
    flex: 1;
    min-height: 0;
    padding: 20px 24px 24px;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
}

.story-route-map-panel {
    display: flex;
    min-height: 0;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #e3eaf3;
    border-radius: 16px;
    background: #fff;
}

.story-route-map-scroll {
    display: flex;
    min-height: 0;
    flex: 1;
    overflow: auto;
    overscroll-behavior: contain;
    background: #fbfdff;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.story-route-map-scroll.is-dragging,
.story-route-map-scroll.is-dragging * {
    cursor: grabbing !important;
}

.story-route-map-scroll.is-single-route {
    align-items: center;
    justify-content: center;
}

.story-route-canvas {
    position: relative;
    flex: 0 0 auto;
    margin: 0 auto;
    background-color: #fbfdff;
    background-image: radial-gradient(circle, rgba(148, 163, 184, 0.24) 1px, transparent 1px);
    background-size: 20px 20px;
}

.story-route-links {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.story-route-link {
    fill: none;
    stroke: #dbe4ef;
    stroke-width: 2;
    stroke-linecap: round;
    transition: stroke 180ms ease, stroke-width 180ms ease;
}

.story-route-link.is-active {
    stroke: rgb(var(--c-primary-300));
    stroke-width: 2.5;
}

.story-route-link.is-selected {
    stroke: rgb(var(--c-primary-600));
    stroke-width: 3;
}

.story-route-node {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 124px;
    height: 64px;
    padding: 9px 10px;
    border: 1px solid #dbe4ef;
    border-radius: 14px;
    color: #334155;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.07);
    text-align: center;
    transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.story-route-node:hover {
    z-index: 2;
    transform: translateY(-2px);
    border-color: rgb(var(--c-primary-300));
    box-shadow: 0 12px 25px rgb(var(--c-primary-600) / 0.12);
}

.story-route-node:focus-visible {
    outline: 3px solid rgb(var(--c-primary-500) / 0.22);
    outline-offset: 3px;
}

.story-route-node.is-on-route {
    border-color: rgb(var(--c-primary-200));
}

.story-route-node.is-selected {
    z-index: 1;
    border-color: rgb(var(--c-primary-600));
    background: rgb(var(--c-primary-50));
    box-shadow: 0 12px 28px rgb(var(--c-primary-600) / 0.16);
}

.story-route-node-checkpoint {
    position: absolute;
    top: 0;
    left: 50%;
    width: 12px;
    height: 12px;
    border: 2px solid #fff;
    border-radius: 3px;
    background: #cbd5e1;
    box-shadow: 0 0 0 1px #cbd5e1;
    transform: translate(-50%, -50%) rotate(45deg);
    transition: background 180ms ease, box-shadow 180ms ease;
}

.story-route-node.is-on-route .story-route-node-checkpoint {
    background: rgb(var(--c-primary-400));
    box-shadow: 0 0 0 1px rgb(var(--c-primary-400));
}

.story-route-node.is-on-selected-route .story-route-node-checkpoint {
    background: rgb(var(--c-primary-600));
    box-shadow: 0 0 0 1px rgb(var(--c-primary-600));
}

.story-route-node.is-selected .story-route-node-checkpoint {
    background: rgb(var(--c-primary-600));
    box-shadow: 0 0 0 1px rgb(var(--c-primary-600)), 0 0 0 5px rgb(var(--c-primary-600) / 0.12);
}

.story-route-node-copy {
    display: flex;
    width: 100%;
    min-width: 0;
    flex: 1;
    align-items: center;
    flex-direction: column;
    overflow: hidden;
}

.story-route-node-type {
    color: #94a3b8;
    font-size: 9px;
    line-height: 1;
    font-weight: 800;
    letter-spacing: 0.12em;
}

.story-route-node-copy strong {
    display: block;
    width: 100%;
    max-width: 100%;
    margin-top: 0;
    overflow: hidden;
    color: #1e293b;
    font-size: 14px;
    line-height: 1.15;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-route-node-type + strong {
    margin-top: 4px;
}

.story-route-node-copy small {
    margin-top: 4px;
    overflow: hidden;
    color: #64748b;
    font-size: 10px;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-route-node-current {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 3px 6px;
    border-radius: 999px;
    color: #fff;
    background: rgb(var(--c-primary-600));
    font-size: 9px;
    line-height: 1;
    font-weight: 800;
}

.story-route-enter-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    gap: 5px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: rgb(var(--c-primary-600));
    background: #fff;
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.story-route-enter-button:hover {
    border-color: rgb(var(--c-primary-200));
    background: rgb(var(--c-primary-50));
}

.story-route-enter-button:active {
    transform: scale(0.97);
}

.story-route-enter-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.story-route-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
    gap: 8px;
    flex-wrap: nowrap;
    padding-top: 14px;
}

.story-route-edit-button,
.story-route-delete-button {
    display: inline-flex;
    height: 36px;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 0 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.story-route-edit-button {
    border: 1px solid transparent;
    color: rgb(var(--c-primary-600));
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.story-route-edit-button:hover:not(:disabled) {
    border-color: rgb(var(--c-primary-200));
    background: rgb(var(--c-primary-50));
}

.story-route-delete-button {
    border: 1px solid transparent;
    color: #dc2626;
    background: #fff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.story-route-delete-button:hover:not(:disabled) {
    border-color: #fca5a5;
    background: #fef2f2;
}

.story-route-edit-button:active:not(:disabled),
.story-route-delete-button:active:not(:disabled) {
    transform: scale(0.97);
}

.story-route-edit-button:disabled,
.story-route-delete-button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

@media (max-width: 640px) {
    .story-route-modal-body {
        padding: 14px;
    }

    .story-route-actions {
        width: 100%;
    }

    .story-route-actions button {
        min-width: 0;
        flex: 1;
        height: 32px;
        padding: 0 10px;
        font-size: 12px;
    }

}

/* ==========================================================================
   ===== Spring Sonata (春之歌) Modern Visual & Interaction Enhancement Layer =====
   Designed by Diana (Design System Architect & UI Designer)
   ========================================================================== */

:root {
    --spring-primary: rgb(var(--c-primary-500));
    --spring-primary-hover: rgb(var(--c-primary-600));
    --spring-primary-deep: rgb(var(--c-primary-700));
    --spring-primary-light: rgb(var(--c-primary-50));
    --spring-primary-tint: rgb(var(--c-primary-100));
    --spring-border-subtle: rgb(var(--c-primary-800) / 0.08);
    --spring-border-hover: rgb(var(--c-primary-500) / 0.4);
    --spring-card-bg: rgba(255, 255, 255, 0.96);
    --spring-shadow-sm: 0 2px 4px -1px rgb(var(--c-primary-900) / 0.04), 0 1px 2px rgb(var(--c-primary-900) / 0.02);
    --spring-shadow-md: 0 4px 14px -2px rgb(var(--c-primary-900) / 0.06), 0 2px 6px -1px rgb(var(--c-primary-900) / 0.03);
    --spring-shadow-lg: 0 12px 32px -6px rgb(var(--c-primary-900) / 0.09), 0 4px 12px -2px rgb(var(--c-primary-900) / 0.04);
    --spring-shadow-float: 0 20px 48px -10px rgb(var(--c-primary-900) / 0.14), 0 8px 16px -4px rgb(var(--c-primary-900) / 0.05);
    --spring-glow: 0 0 0 3.5px rgb(var(--c-primary-500) / 0.16);
    --ease-spring: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* 全局基底温润春意漫反射 */
body {
    background-color: rgb(var(--c-gray-50)) !important;
    background-image: 
        radial-gradient(at 0% 0%, rgb(var(--c-primary-100) / 0.45) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(254, 242, 242, 0.35) 0px, transparent 50%),
        radial-gradient(at 50% 50%, rgb(var(--c-primary-50) / 0.3) 0px, transparent 50%) !important;
    background-attachment: fixed !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 页面主内容区域背景 */
.app-main {
    background: transparent !important;
}

/* ===== 核心卡片重构与打磨 ===== */
/* 通用卡片与容器：具有柔和春山多层微阴影与 1px 微发光边框 */
.character-card,
.template-card,
.session-card,
.preset-card,
.world-info-card,
.regex-script-card,
.settings-section-card {
    position: relative;
    background: var(--spring-card-bg) !important;
    border: 1px solid rgb(var(--c-gray-200) / 0.9) !important;
    border-radius: 18px !important;
    box-shadow: var(--spring-shadow-sm) !important;
    transition: transform 0.26s var(--ease-spring), 
                box-shadow 0.26s var(--ease-spring), 
                border-color 0.26s ease !important;
}

/* 卡片悬停微浮与边缘润泽 */
.character-card:hover,
.template-card:hover,
.preset-card:hover,
.world-info-card:hover,
.regex-script-card:hover {
    transform: translateY(-2.5px) !important;
    border-color: var(--spring-border-hover) !important;
    box-shadow: var(--spring-shadow-md) !important;
}

/* 角色选择卡片轮播（Deck）质感升级 */
.character-card--deck {
    border-radius: 24px !important;
    border: 1px solid rgba(255, 255, 255, 0.7) !important;
    box-shadow: 0 16px 40px -12px rgb(var(--c-primary-900) / 0.2), 0 4px 12px -2px rgb(var(--c-primary-900) / 0.08) !important;
}

/* ===== 按钮系统升级 ===== */
/* 主按钮：春翠微渐变、内嵌微发光、轻弹按压交互 */
button.bg-primary-500,
button.bg-primary-600,
.modal-primary-button,
.btn-spring-primary {
    background: linear-gradient(180deg, rgb(var(--c-primary-500)) 0%, rgb(var(--c-primary-600)) 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.22) !important;
    box-shadow: 0 1px 2px rgb(var(--c-primary-900) / 0.12), 0 4px 12px -2px rgb(var(--c-primary-600) / 0.35) !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    border-radius: 12px !important;
    transition: transform 0.2s var(--ease-spring), 
                box-shadow 0.2s var(--ease-spring), 
                filter 0.2s ease !important;
}

button.bg-primary-500:hover,
button.bg-primary-600:hover,
.modal-primary-button:hover,
.btn-spring-primary:hover {
    background: linear-gradient(180deg, rgb(var(--c-primary-500)) 0%, rgb(var(--c-primary-500)) 100%) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 4px rgb(var(--c-primary-900) / 0.14), 0 8px 20px -3px rgb(var(--c-primary-600) / 0.42) !important;
}

button.bg-primary-500:active,
button.bg-primary-600:active,
.modal-primary-button:active,
.btn-spring-primary:active {
    transform: scale(0.97) translateY(0) !important;
    box-shadow: 0 1px 2px rgb(var(--c-primary-900) / 0.2), inset 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

/* 次级与图标按钮 */
button.border-gray-300:hover,
button.border-gray-200:hover {
    border-color: rgb(var(--c-primary-400) / 0.5) !important;
    background-color: var(--spring-primary-light) !important;
    color: var(--spring-primary-deep) !important;
}

/* 导出、导入、编辑、删除等功能小按钮美化 */
.item-action-button,
button[title="导出"],
button[title="导入"],
button[title="新建"],
button[title="设置"] {
    border-radius: 10px !important;
    transition: all 0.2s var(--ease-spring) !important;
}

button[title="导出"]:hover,
button[title="导入"]:hover {
    background-color: var(--spring-primary-light) !important;
    color: var(--spring-primary) !important;
    transform: translateY(-1px) !important;
}

/* ===== 输入框与表单控件美化 ===== */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea,
select {
    border: 1px solid rgb(var(--c-gray-300) / 0.85) !important;
    border-radius: 12px !important;
    background-color: rgba(255, 255, 255, 0.95) !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease !important;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
textarea:focus,
select:focus {
    outline: none !important;
    border-color: var(--spring-primary) !important;
    box-shadow: var(--spring-glow) !important;
    background-color: #ffffff !important;
}

/* 滑块控件微调 */
input[type="range"]::-webkit-slider-thumb {
    background: var(--spring-primary) !important;
    box-shadow: 0 1px 3px rgb(var(--c-primary-900) / 0.3), 0 0 0 2px #fff !important;
    transition: transform 0.15s ease !important;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15) !important;
}

/* ===== 底部对话输入岛（Input Island）与打字反馈 ===== */
.input-island {
    background-color: rgba(255, 255, 255, 0.92) !important;
    -webkit-backdrop-filter: blur(24px) saturate(160%) !important;
    backdrop-filter: blur(24px) saturate(160%) !important;
    border: 1px solid rgba(255, 255, 255, 0.85) !important;
    border-radius: 1.75rem !important;
    box-shadow: 0 14px 36px -12px rgb(var(--c-primary-900) / 0.18), 
                0 2px 6px rgb(var(--c-primary-900) / 0.04),
                inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
    transition: box-shadow 0.24s var(--ease-spring), border-color 0.24s ease !important;
}

.input-island:focus-within {
    border-color: rgb(var(--c-primary-400) / 0.5) !important;
    box-shadow: 0 16px 42px -10px rgb(var(--c-primary-600) / 0.24), 
                0 0 0 3px rgb(var(--c-primary-500) / 0.12),
                inset 0 1px 0 rgba(255, 255, 255, 1) !important;
}

/* 打字动画小球 */
.typing-dot {
    background: var(--spring-primary) !important;
}
.typing-dot:nth-child(2) {
    background: rgb(var(--c-primary-400)) !important;
}
.typing-dot:nth-child(3) {
    background: #f43f5e !important; /* 樱粉一抹，如初春缀花 */
}

/* ===== 模态框与弹窗（Modal & Dialog）极致通透 ===== */
.modal-overlay,
div[class*="fixed"][class*="inset-0"][class*="bg-black"],
div[class*="fixed"][class*="inset-0"][class*="bg-gray-900"] {
    -webkit-backdrop-filter: blur(10px) saturate(120%) !important;
    backdrop-filter: blur(10px) saturate(120%) !important;
    background-color: rgb(var(--c-primary-950) / 0.4) !important;
}

/* 弹窗面板容器 */
.modal-container,
div[class*="bg-white"][class*="rounded-2xl"][class*="shadow-xl"],
div[class*="bg-white"][class*="rounded-2xl"][class*="shadow-2xl"] {
    border: 1px solid rgba(255, 255, 255, 0.85) !important;
    box-shadow: 0 24px 64px -16px rgb(var(--c-primary-900) / 0.22), 
                0 4px 16px -2px rgb(var(--c-primary-900) / 0.08) !important;
    border-radius: 22px !important;
}

/* ===== Toast 提示条质感升级 ===== */
.toast-item {
    border-radius: 9999px !important;
    -webkit-backdrop-filter: blur(20px) saturate(150%) !important;
    backdrop-filter: blur(20px) saturate(150%) !important;
    box-shadow: 0 14px 34px -8px rgb(var(--c-primary-900) / 0.18), 0 2px 6px rgb(var(--c-primary-900) / 0.06) !important;
    border: 1px solid rgba(255, 255, 255, 0.75) !important;
    transition: all 0.3s var(--ease-spring) !important;
}

/* ===== 状态胶囊与微标 ===== */
.badge-spring,
span[class*="bg-primary-100"] {
    background-color: var(--spring-primary-tint) !important;
    color: var(--spring-primary-deep) !important;
    border: 1px solid rgb(var(--c-primary-500) / 0.2) !important;
    border-radius: 9999px !important;
    font-weight: 600 !important;
}

/* ===== 移动端触控优化 ===== */
@media (max-width: 640px) {
    .character-card,
    .preset-card,
    .template-card {
        border-radius: 16px !important;
    }

    /* 移动端保证触控舒适度 */
    button, input, select {
        -webkit-tap-highlight-color: transparent;
    }
}


/* ================================================================
   暗夜留声机（聊天工具栏内嵌播放器）
   ================================================================ */
@keyframes music-spin-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* 触发按钮上的唱片图标：播放中持续旋转 */
.music-player .music-spin {
    animation: music-spin-rotate 3s linear infinite;
}

/* 触发按钮右上角播放指示点 */
.music-player .music-play-dot {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: rgb(var(--c-primary-500));
    border: 1.5px solid #fff;
    animation: music-play-dot-pulse 1.6s ease-in-out infinite;
}
@keyframes music-play-dot-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.75; }
}

/* 黑胶唱片：默认静止，播放中旋转 */
.music-vinyl {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    background:
        radial-gradient(circle at 50% 50%, rgb(var(--c-primary-900)) 0 21%, transparent 22%),
        repeating-radial-gradient(circle at 50% 50%, #1f2937 0 2px, #111827 2px 4px);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 4px 10px -2px rgb(var(--c-primary-900) / 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.music-vinyl.is-playing {
    animation: music-spin-rotate 4s linear infinite;
}
.music-vinyl__label {
    width: 15px;
    height: 15px;
    border-radius: 999px;
    background: rgb(var(--c-primary-500));
    box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.25);
}

/* 进度条 */
.music-progress-track {
    flex: 1;
    height: 14px;
    display: flex;
    align-items: center;
    cursor: pointer;
    position: relative;
}
.music-progress-track::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 5px;
    border-radius: 999px;
    background: rgb(var(--c-gray-200));
}
.music-progress-fill {
    position: relative;
    height: 5px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgb(var(--c-primary-400)), rgb(var(--c-primary-600)));
    display: flex;
    align-items: center;
    justify-content: flex-end;
    transition: width 0.15s linear;
}
.music-progress-thumb {
    width: 11px;
    height: 11px;
    border-radius: 999px;
    background: #fff;
    border: 2.5px solid rgb(var(--c-primary-600));
    box-shadow: 0 1px 3px rgb(var(--c-primary-900) / 0.25);
    margin-right: -6px;
}

/* 控制按钮 */
.music-ctrl {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    transition: all 0.15s ease;
}
.music-ctrl:hover {
    color: rgb(var(--c-primary-600));
    background: rgb(var(--c-primary-50));
}
.music-ctrl:active { transform: scale(0.92); }

/* 歌单正在播放的律动条 */
.music-playing-bars {
    display: inline-flex;
    align-items: flex-end;
    gap: 1.5px;
    height: 11px;
}
.music-playing-bars i {
    width: 2.5px;
    border-radius: 1px;
    background: rgb(var(--c-primary-500));
    animation: music-bar-bounce 0.9s ease-in-out infinite;
}
.music-playing-bars i:nth-child(1) { height: 6px; animation-delay: 0s; }
.music-playing-bars i:nth-child(2) { height: 11px; animation-delay: 0.22s; }
.music-playing-bars i:nth-child(3) { height: 8px; animation-delay: 0.44s; }
@keyframes music-bar-bounce {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

@media (prefers-reduced-motion: reduce) {
    .music-player .music-spin,
    .music-vinyl.is-playing,
    .music-playing-bars i,
    .music-player .music-play-dot {
        animation: none;
    }
}

/* 拖拽排序的幽灵占位 */
.music-drag-ghost {
    opacity: 0.35;
    background: rgb(var(--c-primary-50)) !important;
    border: 1px dashed rgb(var(--c-primary-300));
    border-radius: 8px;
}

/* ================================================================
   留声机悬浮窗全平台响应式定位与视口安全适配 (Desktop / Mobile / Landscape)
   ================================================================ */
.music-panel {
    z-index: 50;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

/* 桌面端大屏环境（宽度 >= 640px 且高度 > 540px）：锚定工具栏按钮上方，左对齐，气泡形态 */
@media (min-width: 640px) and (min-height: 541px) {
    .music-panel {
        position: absolute;
        bottom: 100%;
        left: 0;
        margin-bottom: 0.625rem; /* 10px */
        width: 21.5rem;
        max-width: calc(100vw - 2rem);
        max-height: min(34rem, calc(100vh - 12rem));
        transform-origin: bottom left;
    }
}

/* 移动视口与矮屏环境（宽度 < 640px 或 高度 <= 540px，如手机竖屏、横屏与虚拟键盘弹起）：Fixed 居中与视口安全防护 */
@media (max-width: 639px), (max-height: 540px) {
    .music-panel {
        position: fixed !important;
        left: 0.75rem !important;
        right: 0.75rem !important;
        margin-inline: auto !important;
        width: calc(100vw - 1.5rem) !important;
        max-width: 22rem !important;
        bottom: calc(var(--keyboard-inset, 0px) + 5.75rem + env(safe-area-inset-bottom, 0px)) !important;
        max-height: calc(100vh - var(--keyboard-inset, 0px) - 6.75rem - env(safe-area-inset-top, 0.5rem) - env(safe-area-inset-bottom, 0px)) !important;
        max-height: calc(100dvh - var(--keyboard-inset, 0px) - 6.75rem - env(safe-area-inset-top, 0.5rem) - env(safe-area-inset-bottom, 0px)) !important;
        transform-origin: bottom center !important;
        box-shadow: 0 16px 40px -8px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(0, 0, 0, 0.06) !important;
    }
}

/* 矮屏 / 横屏模式（视口高度受限）：紧凑排版与垂直安全保护，确保不顶出视口 */
@media (max-height: 540px) {
    .music-panel {
        padding: 0.625rem !important; /* 紧凑内边距 */
        bottom: calc(var(--keyboard-inset, 0px) + 5rem + env(safe-area-inset-bottom, 0px)) !important;
        max-height: calc(100vh - var(--keyboard-inset, 0px) - 5.5rem - env(safe-area-inset-top, 0.5rem) - 0.25rem) !important;
        max-height: calc(100dvh - var(--keyboard-inset, 0px) - 5.5rem - env(safe-area-inset-top, 0.5rem) - 0.25rem) !important;
    }
    .music-panel .music-hero-section {
        padding-top: 0.25rem !important;
        padding-bottom: 0.25rem !important;
    }
    .music-panel .music-vinyl {
        width: 36px !important;
        height: 36px !important;
    }
    .music-panel .music-ctrl-section {
        padding-top: 0.25rem !important;
        padding-bottom: 0.25rem !important;
    }
    .music-panel .music-playlist-box {
        max-height: 7.5rem !important;
    }
}

/* 移动端触摸拖拽把手防滚动冲突与安全触摸区 */
.music-drag-handle {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

