:root {
    --primary-color: #7F5AF0;
    --primary-hover: #6B4AE5;
    --primary-glow: rgba(127, 90, 240, 0.5);
    --secondary-color: #2CB67D;
    --secondary-hover: #249A6A;
    --secondary-glow: rgba(44, 182, 125, 0.5);
    --background: #0f0f12;
    --surface: #242629;
    --text: #FFFFFE;
    --text-secondary: #94A1B2;
    --glass-bg: rgba(22, 22, 26, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.36);
    --nav-width: 80px;
    --mobile-nav-height: 70px;
    
    /* Slot Component Variables (工业级变量管理) */
    --slot-bg-surface: rgba(16, 16, 20, 0.4);
    --slot-bg-hover: rgba(255, 255, 255, 0.03);
    --slot-border-color: rgba(255, 255, 255, 0.05);
    --slot-glow-color: var(--primary-color);
    --slot-text-color: var(--text);
    --slot-label-color: var(--text-secondary);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Noto Sans SC', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

*::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

html, body {
    background-color: var(--background);
    min-height: 100vh;
    width: 100%;
    color: var(--text);
    overflow: hidden; /* 由 app-container 内部滚动 */
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3%3Ffilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    opacity: 0.035;
    pointer-events: none;
    z-index: 100;
}

/* 主容器布局 */
#app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(127, 90, 240, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(44, 182, 125, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 50% 80%, rgba(127, 90, 240, 0.1) 0%, transparent 50%);
    background-attachment: fixed;
}

/* 主导航栏 - 宽屏模式 (左侧) */
#main-nav {
    display: flex;
    background: rgba(18, 18, 22, 0.8);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    z-index: 1000;
    transition: all 0.3s ease;
}

/* 内容区域 */
#main-content {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    position: relative;
    padding: 0;
}

/* 视图通用样式 */
.view {
    display: none !important;
    width: 100%;
    min-height: 100%;
    padding: 40px 20px;
    animation: fadeIn 0.4s ease;
    position: relative;
    z-index: 1;
    /* 确保背景层不溢出 */
    overflow: hidden;
}

/* 抽卡视图背景层 - 调整层级策略，避免负值被遮挡 */
.gacha-ambient-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    filter: blur(20px) brightness(0.7);
    transform: scale(1.1);
    z-index: 0; /* 位于最底层 */
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
}

.gacha-ambient-bg.active {
    opacity: 1;
}

/* 确保内容在背景之上 */
.view > h1,
.view > .gacha-layout-wrapper {
    position: relative;
    z-index: 1;
}

.view.active {
    display: block !important;
}

h1 {
    text-align: center;
    font-weight: 800;
    font-size: clamp(2rem, 4vw, 3rem);
    margin-bottom: 10px;
    /* 修改标题颜色为纯白，以确保在复杂背景下的最高对比度 */
    color: rgba(255, 255, 255, 0.9);
    /* 添加多重文字阴影，增强立体感和可读性 */
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    letter-spacing: 2px; /* 增加字间距，提升大气感 */
    position: relative;
    z-index: 2;
}

.gacha-header {
    margin-bottom: clamp(30px, 4vw, 40px);
    text-align: center;
    position: relative;
    z-index: 2;
    /* 防止 Margin Collapse 导致的滚动定位问题 */
    padding-top: 1px;
    margin-top: -1px;
    /* 强制硬件加速，防止滚动时标题渲染丢失 */
    transform: translateZ(0);
}

.gacha-subtitle {
    color: var(--text-secondary);
    font-size: 16px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
    font-weight: 500;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

/* --- 抽卡页布局 --- */
.gacha-layout-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: relative;
}

.gacha-connector {
    display: none; /* 移动端默认隐藏 */
}

/* 根据用户描述：抽卡是默认tab，进入该tab后 `div` 这个组件是立绘展示区，紧贴着左边的tab，然后这个组件右侧是 `div` `div` `button` */
@media screen and (min-width: 769px) {
    /* 宽屏下移除子元素阴影，消除接缝处的割裂感 */
    .gacha-layout-wrapper {
        flex-direction: row;
        align-items: stretch; /* 等高拉伸 */
        justify-content: center; /* 内容居中 */
        padding-top: 40px;
        gap: 0; /* 无缝衔接 */
        /* 移除 drop-shadow 以彻底消除中间可能的阴影扩散 */
        filter: none;
    }

    /* 移除连接器样式 */
    .gacha-connector {
        display: none;
    }

    .gacha-controls-side, .gacha-display-side {
        flex: 1 1 450px; /* 增加基础宽度，避免初始过窄 */
        min-width: 0;    /* 防止内容撑开容器导致抖动 */
    }

    .gacha-display-side {
        /* position: sticky; 移除 sticky，改用 flex stretch */
        /* top: 0; */
        justify-content: flex-start;
    }

    /* 宽屏下移除单独的卡片阴影和层级，实现平滑对接 */
    .control-panel, .character-card {
        box-shadow: none !important;
    }
    
    .control-panel {
        z-index: auto; /* 移除层级 */
        margin-right: 0; /* 移除负边距，不再重叠 */
        border-right: none; /* 移除右边框，只保留右侧卡片的左边框作为分割线 */
    }
}

/* 角色卡胶囊化设计 */
.character-card, .control-panel {
    width: 100%;
    /* max-width: 450px; 移除，由 flex 控制，或者保留但统一 */
    background: rgba(30, 30, 40, 0.7);
    border-radius: 20px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 1; /* 强制填满高度 */
    height: 100%; /* 确保填满容器 */
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); /* 增加投影增强立体感 */
    transition: all 0.3s ease;
}

.control-panel {
    padding: 0; /* 移除内边距，让按钮通栏 */
    gap: 0; /* 由子元素 padding 控制间距 */
    /* 左侧面板特殊样式：向右对接 */
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.02); /* 弱化分割线 */
    margin-right: -1px; /* 消除双重边框 */
    z-index: 2; /* 确保分割线清晰 */
}

.control-panel .tab-container {
    padding: 30px 30px 0;
    width: 100%;
}

/* 
 * Slot Machine Component (重构版)
 * 采用高性能渲染与 CSS 变量管理
 */
.slot-machine {
    padding: 0 30px 20px;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px; /* 恢复固定间距，防止上下太空 */
}

/* 扁平化风格回归 */
.slot-reel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    /* 核心修改：让每个词条组件在垂直方向上都能弹性伸缩，平分父容器高度 */
    flex: 1;
    position: relative;
    overflow: hidden;
    transition: background 0.3s ease;
}

.slot-reel:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* 移除装饰性细节 */
.slot-reel::before {
    display: none;
}

.dimension-label {
    color: var(--text-secondary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
    font-weight: 600;
    opacity: 0.9;
    text-shadow: none;
    padding-bottom: 0;
    border: none;
}

.slot-item {
    /* 扁平化深色背景 */
    background-color: rgba(0, 0, 0, 0.25);
    background-image: none;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: none;
    
    padding: 10px;
    border-radius: 8px;
    height: 72px; /* 增加高度，使视觉更饱满 */
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    
    /* 恢复清晰字体 */
    font-family: 'Noto Sans SC', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

/* 移除反光 */
.slot-item::after {
    display: none;
}

.slot-item.spinning span {
    display: block;
    color: var(--text);
    text-shadow: none;
    /* 移除闪烁动画，保持常亮 */
    opacity: 1;
    filter: none;
}

/* 移除 textFlash 动画定义 */

/* 宽屏适配优化 */
@media screen and (min-width: 769px) {
    .slot-reel {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 25px;
        padding: 20px 30px;
        min-height: auto;
    }

    .dimension-label {
        width: clamp(70px, 6vw, 100px);
        min-width: 70px;
        text-align: center; /* 恢复居中对齐 */
        margin-right: 15px;
        font-size: clamp(14px, 1vw, 18px);
        display: block;
        padding: 0;
        border: none;
    }

    .slot-item {
        flex: 1;
        /* 核心修改：移除 clamp，改为高度 100% 自动撑满父容器 */
        height: 100%;
        border-radius: 8px;
        font-size: clamp(18px, 1.5vw, 26px);
        background-color: rgba(0, 0, 0, 0.25);
        box-shadow: none;
    }
}

.generate-button {
        width: 100%;
        margin: 0;
        border-radius: 0;
        border-bottom-left-radius: 20px; /* 左下圆角 */
        border-bottom-right-radius: 0;   /* 右下直角 */
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: none; /* 移除悬浮投影，改为沉浸式 */
        padding: 15px 24px; /* 与右侧按钮保持高度一致 */
        background: var(--primary-color); /* 纯色背景或保持渐变 */
        position: relative;
        font-size: 16px; /* 字体大小统一 */
        font-weight: 700;
        color: white;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .generate-button::before {
        display: none; /* 移除流光动画，保持纯净 */
    }

    .generate-button:hover:not(:disabled) {
        transform: none; /* 移除位移，保持通栏稳固感 */
        background: var(--primary-hover);
        box-shadow: none;
    }

/* 统一右侧按钮样式，实现镜像对称 */
    .start-chat-btn {
        width: 100%;
        margin: 0;
        border-radius: 0;
        border-bottom-left-radius: 0;   /* 左下直角 */
        border-bottom-right-radius: 20px; /* 右下圆角 */
        border: none;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        box-shadow: none;
        padding: 15px 24px;
        background: var(--secondary-color);
        position: relative;
        font-size: 16px; /* 字体大小统一 */
        font-weight: 700;
        color: white;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .start-chat-btn:disabled {
        background: rgba(255, 255, 255, 0.05);
        color: rgba(255, 255, 255, 0.3);
        cursor: not-allowed;
        border-top-color: transparent;
    }

    .start-chat-btn:hover:not(:disabled) {
        transform: none;
        background: var(--secondary-hover);
        box-shadow: 0 0 20px var(--secondary-glow);
    }

.character-card {
    /* 右侧面板特殊样式：接收对接 */
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.02);
}

/* 移动端恢复圆角 */
@media screen and (max-width: 768px) {
    .control-panel, .character-card {
        border-radius: 20px; /* 移动端保持全圆角 */
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
        border-left: 1px solid var(--glass-border);
        border-right: 1px solid var(--glass-border);
        flex: auto; /* 移动端高度自适应 */
        height: auto;
    }
    
    .gacha-layout-wrapper {
        gap: 20px; /* 移动端恢复间距 */
    }
    
    .control-panel {
        margin-right: 0;
    }

    .slot-machine {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* 限制最大宽度，防止在大屏下太宽 */
.gacha-controls-side, .gacha-display-side {
    flex: 1;
    max-width: 500px; /* 保持一致的最大宽度 */
    width: 100%;
    display: flex;
    flex-direction: column; /* 确保子元素高度撑满 */
}

/* 移动端特殊处理 */
@media screen and (max-width: 768px) {
    .gacha-controls-side, .gacha-display-side {
        max-width: 100%; /* 移动端占满 */
    }
    
    .control-panel, .character-card {
        height: auto; /* 移动端高度自适应 */
    }
}

.card-image-container {
    width: 100%;
    aspect-ratio: 3/4;
    background: rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden; /* 防止光团溢出 */
}

.generated-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* 极淡的磨砂玻璃背景，透出下层的光团 */
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(20px); /* 强模糊，让光团看起来更柔和 */
    gap: 15px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.5s ease;
    z-index: 2; /* 在光团之上 */
}

/* 光团容器 */
.ambient-blobs {
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
}

/* 基础光团样式 */
.blob {
    position: absolute;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    
    /* 核心修复：始终使用 offset-path 定位，消除状态切换时的位置跳动 */
    offset-path: ellipse(60% 65% at 50% 50%);
    offset-anchor: center;
    top: 0;
    left: 0;
    
    transition: all 1s ease;
}

.blob-1 {
    background: var(--primary-color);
    /* 静态位置：左下角 (约135度，37.5%) */
    offset-distance: 37.5%;
    animation: blob-breathe 8s infinite alternate;
}

.blob-2 {
    background: var(--secondary-color);
    /* 静态位置：右上角 (约315度，87.5%) */
    offset-distance: 87.5%;
    animation: blob-breathe 10s infinite alternate-reverse;
}

/* 呼吸动画 (默认状态) */
@keyframes blob-breathe {
    /* 仅微调缩放和透明度，不再改变位移，避免与 offset-path 冲突 */
    0% { transform: scale(1); opacity: 0.2; }
    100% { transform: scale(1.2); opacity: 0.4; }
}

/* 生成中状态 - 光团椭圆轨迹追逐 */
.card-image-container.generating .ambient-blobs {
    animation: none;
}

.card-image-container.generating .blob {
    opacity: 0.3; 
    filter: blur(80px);
    /* 尺寸和路径继承自基础样式，无需重复定义 */
    
    /* 确保从角落平滑过渡到轨道 */
    transition: all 1s ease;
}

.card-image-container.generating .blob-1 {
    /* Blob 1 (左下) 从约 135度 (37.5%) 位置开始 */
    /* 持续加速：使用长动画覆盖等待期，配合 cubic-bezier 实现从静止到极速的持续加速 */
    animation: orbit-accelerate-1 20s cubic-bezier(0.5, 0, 1, 1) forwards;
}

.card-image-container.generating .blob-2 {
    /* Blob 2 (右上) 从约 315度 (87.5%) 位置开始 */
    animation: orbit-accelerate-2 20s cubic-bezier(0.5, 0, 1, 1) forwards;
}

@keyframes orbit-accelerate-1 {
    from { offset-distance: 37.5%; }
    to   { offset-distance: 2037.5%; } /* 20圈 */
}

@keyframes orbit-accelerate-2 {
    from { offset-distance: 87.5%; }
    to   { offset-distance: 2087.5%; } /* 20圈 */
}

/* 状态类：光团收拢消失 */
.card-image-container.blob-fade-out .ambient-blobs {
    /* 核心效果：整体容器向中心缩小至 0，配合旋转实现"吸入"感 */
    transform: scale(0) rotate(45deg); 
    opacity: 0;
    /* 大幅加快收拢速度：从 0.8s 缩短至 0.4s */
    transition: transform 0.4s ease-in, opacity 0.4s ease-in;
}

.card-image-container.blob-fade-out .blob {
    /* 保持光团可见，直到随容器完全收缩消失 */
    opacity: 0.3 !important;
    /* 移除之前的 opacity transition，防止冲突 */
    transition: none; 
}

/* 加载状态样式优化 */
.loading-animation,
.card-loading {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
}

.loading-icon {
    font-size: 24px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.8; }
    100% { transform: scale(1); opacity: 1; }
}

.loading-text {
    font-size: 15px;
    color: var(--text-secondary);
    font-weight: 500;
}

.card-placeholder-icon {
    font-size: 48px;
    opacity: 0.5;
}

.card-placeholder-content {
    text-align: center;
}

.card-text {
    flex: 1; /* 占据剩余空间，将按钮推到底部 */
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 80px; /* 预留高度 */
    display: flex;
    align-items: center; /* 内容垂直居中 */
    justify-content: center; /* 内容水平居中（如果是 placeholder） */
}

.card-text:not(.placeholder-text) {
    display: block; /* 有内容时恢复块级显示 */
    justify-content: flex-start;
}

.placeholder-text {
    color: var(--text-secondary);
    font-style: italic;
    opacity: 0.6;
    text-align: center;
}

.action {
    color: var(--text-secondary);
    font-style: italic;
    opacity: 0.8;
}

    /* 移除旧的按钮样式定义 */
.nav-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    z-index: 1;
}

.nav-item:hover {
    color: var(--text);
    transform: translateY(-2px);
}

.nav-item.active {
    color: var(--text);
}

.nav-item.active .nav-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 0 8px var(--primary-glow));
}

.nav-item.active .nav-label {
    color: var(--primary-color);
    font-weight: 700;
}

.nav-item.active::after {
    content: '';
    position: absolute;
    background: var(--primary-color);
    border-radius: 4px;
    box-shadow: 0 0 15px var(--primary-glow);
}

.nav-icon {
    font-size: 24px;
    transition: all 0.3s ease;
    filter: grayscale(1) opacity(0.6);
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
    filter: grayscale(0) opacity(1);
}

.nav-label {
    font-size: 12px;
    font-weight: 500;
    transition: all 0.3s ease;
}

/* --- 响应式布局切换 --- */
@media screen and (min-width: 769px) {
    #main-nav {
        width: var(--nav-width);
        height: 100%;
        flex-direction: column;
        padding: 40px 0;
        gap: 40px;
    }

    /* 宽屏下的顺序：抽卡、聊天、历史 */
    .nav-item[data-tab="gacha"] { order: 1; }
    .nav-item[data-tab="chat"] { order: 2; }
    .nav-item[data-tab="history"] { order: 3; }

    .nav-item.active::after {
        right: 0;
        top: 20%;
        bottom: 20%;
        width: 3px;
    }

    /* 宽屏下的抽卡页布局：左右结构 */
    /* .gacha-layout-wrapper {
        flex-direction: row;
        align-items: flex-start;
        padding-top: 40px;
    } */

    /* .gacha-display-side {
        position: sticky;
        top: 0;
    } */

    h1 {
        grid-column: 1 / -1;
        width: 100%;
    }
}

@media screen and (max-width: 768px) {
    /* 聊天详情页激活时隐藏底部导航 */
    body.chat-detail-active #main-nav {
        display: none;
    }

    body.chat-detail-active #main-content {
        padding-bottom: 0;
    }

    #main-nav {
        width: 100%;
        height: var(--mobile-nav-height);
        flex-direction: row;
        position: fixed;
        bottom: 0;
        left: 0;
        padding: 0;
        justify-content: space-around;
        border-right: none;
        border-top: 1px solid var(--glass-border);
    }

    /* 移动端调整 */
    #main-content {
        /* 保持底部导航栏的高度留白 */
        padding-bottom: var(--mobile-nav-height);
    }

    .nav-item.active::after {
        top: 0;
        left: 20%;
        right: 20%;
        height: 3px;
    }

    .view {
        /* 减少底部内边距，因为 main-content 已经有了 padding-bottom */
        padding: 20px 15px 10px;
        /* 移除 overflow: hidden 以避免移动端滚动时标题渲染被裁剪的问题 */
        /* 背景溢出问题通过 gacha-ambient-bg 自身的控制或接受轻微溢出 */
        overflow: visible;
    }

    /* 针对移动端特殊处理背景层，防止溢出导致横向滚动 */
    .view .gacha-ambient-bg {
        /* 限制背景层大小，避免因 scale 撑大容器 */
        max-width: 100vw;
        overflow: hidden; 
        left: 50%;
        transform: translateX(-50%) scale(1.1); /* 保持放大效果但居中定位 */
        width: 100vw; /* 强制宽度 */
    }
}

/* 聊天视图特殊处理 */
#view-chat.active {
    display: flex !important;
}

#view-chat {
    padding: 0;
    height: 100vh;
    display: none; /* 默认隐藏 */
    overflow: hidden;
}

.chat-list-sidebar {
    width: 320px;
    height: 100%;
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.sidebar-header {
    padding: 25px 20px;
    border-bottom: 1px solid var(--glass-border);
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 1px;
}

.chat-list-items {
    flex: 1;
    overflow-y: auto;
}

.chat-list-item {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    position: relative; /* 为指示器定位 */
}

.chat-list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-list-item.active {
    background: rgba(127, 90, 240, 0.1);
    /* border-left: 4px solid var(--primary-color); 已移除，改用伪元素 */
}

.chat-item-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface);
    border: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.chat-list-item.active .chat-item-avatar {
    border-color: var(--primary-color);
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 5px;
    color: var(--text);
}

.chat-item-last-msg {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 详情画布区域 */
.chat-detail-view {
    flex: 1;
    height: 100%;
    position: relative;
    display: flex;
    align-items: stretch; /* 占满高度 */
    justify-content: center;
    background: transparent;
    overflow: hidden;
    z-index: 1; /* 确保自身有层级上下文 */
}

/* 全局氛围背景 (立绘全屏模糊背景) */
.chat-global-ambient {
    position: absolute;
    inset: 0;
    background-image: var(--chat-bg);
    background-size: cover;
    background-position: center;
    
    /* --- 手动调整区域 --- */
    /* 1. 调整模糊度: 修改 blur() 中的数值 (如 20px, 40px)，数值越大越模糊，越小越清晰 */
    /* 2. 调整明暗度: 修改 brightness() 中的数值 (0.1 - 1.0)，数值越大越亮，越小越暗 */
    filter: blur(10px) brightness(0.9) !important; 
    transform: scale(1.1);
    /* ------------------- */

    z-index: -1; /* 位于 chat-container 下方 */
    opacity: 0;
    transition: opacity 0.8s ease;
    pointer-events: none; /* 防止遮挡点击 */
}

.chat-detail-view.has-character .chat-global-ambient {
    opacity: 1;
    /* 强制在激活状态下也应用滤镜，防止 transition 过程中或结束后丢失 */
    filter: blur(10px) brightness(0.9) !important;
    transform: scale(1.1);
}

/* 贯通式对话容器 */
.chat-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center; /* 对话区水平居中 */
    background: transparent;
}

.chat-container.hidden {
    display: none !important;
}

.chat-main {
    width: 100%;
    max-width: min(850px, 75vh); /* 控制最宽比例，平衡视觉效果 */
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    background-image: var(--chat-bg);
    background-size: cover;
    background-position: center;
    backdrop-filter: none;
    border-left: 1px solid var(--glass-border);
    border-right: 1px solid var(--glass-border);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
}

/* 聊天气泡样式恢复 */
.message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.6;
    position: relative;
    margin-bottom: 4px;
    word-wrap: break-word;
}

.message.assistant {
    align-self: flex-start;
    background: rgba(30, 30, 35, 0.7);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom-left-radius: 4px;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.message.assistant .action {
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
    opacity: 1; /* 颜色已含透明度 */
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #6B46C1 0%, #805AD5 100%);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(107, 70, 193, 0.3);
}

.message.user .action {
    color: rgba(255, 255, 255, 0.7);
    font-style: italic;
    opacity: 1;
}

.chat-input-area {
    padding: 20px 30px;
    display: flex;
    gap: 15px;
    background: transparent;
    border-top: none;
    flex-shrink: 0;
    margin-bottom: 10px;
}

#chat-input {
    flex: 1;
    background: rgba(20, 20, 25, 0.8);
    border: 1px solid var(--glass-border);
    padding: 16px 24px;
    border-radius: 30px;
    color: white;
    outline: none;
    font-size: 15px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

#chat-input:focus {
    border-color: var(--primary-color);
    background: rgba(30, 30, 35, 0.95);
    box-shadow: 0 0 20px rgba(127, 90, 240, 0.2);
    transform: translateY(-2px);
}

.send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0 28px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(127, 90, 240, 0.3);
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(127, 90, 240, 0.5);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 聊天欢迎提示 */
.chat-welcome-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: var(--text-secondary);
    z-index: 1;
}

.welcome-icon {
    font-size: 72px;
    opacity: 0.15;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

.chat-welcome-placeholder p {
    font-size: 16px;
    letter-spacing: 1px;
}

.chat-header {
    padding: 15px 20px;
    background: linear-gradient(to bottom, rgba(18, 18, 22, 0.9) 0%, rgba(18, 18, 22, 0.0) 100%);
    border-bottom: none;
    display: none; /* 宽屏默认隐藏 */
    grid-template-columns: 60px 1fr 60px; /* 明确的三栏：返回、标题、占位 */
    align-items: center;
    flex-shrink: 0;
}

.chat-back-btn {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.chat-back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chat-header h3 {
    grid-column: 2;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    text-align: center;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-spacer {
    grid-column: 3;
}

.mobile-only {
    display: none !important;
}

@media screen and (max-width: 932px) {
    #view-chat {
        flex-direction: column;
    }
    
    .chat-list-sidebar {
        width: 100%;
        height: 100%;
    }

    .chat-detail-view {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        z-index: 2000;
        transform: translateX(100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        background: var(--background);
        padding: 0;
    }

    .chat-detail-view.active {
        transform: translateX(0);
    }

    .chat-global-ambient {
        display: none; /* 移动端对话框全屏，不再需要额外的环境背景 */
    }

    .chat-main {
        max-width: 100%;
        border: none;
        background-color: rgba(22, 22, 26, 0.4);
        background-image: linear-gradient(rgba(22, 22, 26, 0.4), rgba(22, 22, 26, 0.4)), var(--chat-bg);
        background-size: cover;
        background-position: center;
        backdrop-filter: blur(20px);
    }
    
    .chat-messages, .chat-input-area {
        padding-left: 20px;
        padding-right: 20px;
    }
    
    .chat-header {
        display: grid; /* 移动端恢复显示 */
    }

    .mobile-only {
        display: flex !important;
    }
}

/* --- 历史页重构样式 --- */
.history-view-container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 20px;
}

.history-header {
    margin-bottom: 40px;
    text-align: center;
}

.history-header h2 {
    font-size: clamp(2rem, 4vw, 3rem);
    font-weight: 800;
    margin-bottom: 10px;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    letter-spacing: 2px;
}

.history-subtitle {
    color: var(--text-secondary);
    font-size: 16px;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 260px));
    gap: 30px;
    width: 100%;
    align-items: start;
    justify-content: center;
}

.history-card {
    max-width: 260px;
    width: 100%;
    border-radius: 15px;
    overflow: hidden;
    background: rgba(30, 30, 40, 0.7);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.history-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0,0,0,0.4), 0 0 15px var(--glass-border);
    border-color: rgba(255,255,255,0.2);
    z-index: 10;
}

@media screen and (max-width: 768px) {
    .history-grid {
        grid-template-columns: repeat(2, 1fr); /* 窄屏强制双列 */
        gap: 15px;
        align-items: start;
    }
}

.history-card img {
    width: 100%;
    height: auto;
    display: block;
}

/* 历史卡片细节修正 */
.history-card .history-info {
    padding: 12px 15px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
}

.history-card .history-info::before {
    content: '';
    position: absolute;
    left: 0;
    top: 15%;
    bottom: 15%;
    width: 3px;
    background: var(--primary-color);
    opacity: 0.5;
    border-radius: 0 2px 2px 0;
}

.history-card .history-date {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 500;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.history-card .history-tags-info {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    line-height: 1.4;
    font-weight: 300;
}

.history-card .character-description {
    padding: 12px 15px;
    font-size: 12px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.02);
}

.history-card .character-description .action {
    color: rgba(255, 255, 255, 0.4);
}

/* 统一空状态样式 */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 40px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    margin: 20px;
    border: 1px dashed var(--glass-border);
    min-height: 150px;
    width: calc(100% - 40px);
}

.empty-icon {
    font-size: 42px;
    opacity: 0.3;
    filter: grayscale(1);
    margin-bottom: 5px;
}

.empty-text {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    font-weight: 500;
}

.empty-action-btn {
    margin-top: 10px;
    padding: 8px 20px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(127, 90, 240, 0.3);
}

.empty-action-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(127, 90, 240, 0.5);
}

/* 历史列表特殊调整 */
#history-grid .empty-state {
    grid-column: 1 / -1;
    background: rgba(30, 30, 40, 0.4);
    width: 100%;
    margin: 0;
    min-height: 300px;
}

/* 错误提示样式 */
.card-error {
    position: absolute;
    inset: 0;
    display: none; /* 默认隐藏，由 JS 控制显示 */
}

.card-error-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    padding: 20px;
}

.card-error .error-icon {
    font-size: 48px;
    opacity: 0.8;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.card-error .error-message {
    color: #ff6b6b;
    font-size: 15px;
    text-align: center;
    font-weight: 500;
    line-height: 1.5;
    max-width: 80%;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* 模态框优化 */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal.show {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    max-width: 500px;
    width: 90%;
    background: var(--surface);
    border-radius: 20px;
    padding: 30px;
    border: 1px solid var(--glass-border);
}

/* 打字动画 */
.typing-indicator {
    display: flex;
    gap: 4px;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

@keyframes typing {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 1; }
}

/* --- 抽卡页组件样式恢复 --- */
.tab-container {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    justify-content: center;
    flex-wrap: wrap;
}

.tab-button {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 10px 18px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 13px;
    font-weight: 500;
}

.tab-button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.tab-button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(127, 90, 240, 0.3);
}

.control-panel .slot-machine {
    padding-bottom: 40px; /* 增加底部内边距，使内容与按钮保持距离 */
}


