/* css/style.css */

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: "Microsoft YaHei", sans-serif;
    background-color: #000;
    color: #fff;
    position: relative;
    height: var(--app-height);
    position: fixed; /* 不让 body 跟随浏览器滚动 */
    width: 100%;
}

#canvas-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--app-height);
    z-index: 1;
}

/* --- 聊天框：容器 --- */
.chatbox {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 800px;
    background-color: transparent !important;
    display: flex;
    flex-direction: column;
    z-index: 30;
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    /* 关键：确保容器本身有高度上限，内部记录区才能滚动 */
    max-height: 80vh;
}

/* --- 切换按钮：极简扁平拉杆 --- */
#toggleChat {
    background: rgba(40, 40, 40, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    width: 60px;
    height: 10px;
    border-radius: 6px 6px 0 0;
    margin: 0 auto;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.8);
    font-size: 8px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

/* --- 聊天记录区域：滚动修复核心 --- */
.chatlog {
    flex: 1; /* 撑满剩余空间 */
    min-height: 0; /* 必须有这行，否则 flex 子元素无法内部滚动 */
    max-height: 27vh; /* 展开时的最大滚动高度 */
    padding: 15px 10px;
    overflow-y: auto !important; /* 强制开启滚动 */
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    opacity: 1;
    -webkit-overflow-scrolling: touch; /* 优化移动端滚动顺滑度 */
}

/* 隐藏滚动条但保留滚动功能（可选，看起来更干净） */
.chatlog::-webkit-scrollbar { width: 3px; }
.chatlog::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* 收起状态逻辑 */
.chatbox.collapsed .chatlog {
    max-height: 0;
    padding: 0 10px;
    opacity: 0;
    margin: 0;
    pointer-events: none;
}

/* --- 消息气泡统一极简黑 --- */
.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    background-color: rgba(0, 0, 0, 0.45) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.message.bot { align-self: flex-start; border-top-left-radius: 2px; }
.message.user { align-self: flex-end; border-top-right-radius: 2px; }

/* --- 🌟前情提要/系统消息：居中黑化版式 --- */
.message.system-info {
    align-self: center; /* 居中 */
    max-width: 90%;
    background-color: rgba(0, 0, 0, 0.3) !important; /* 更淡一点的黑 */
    border: 1px dashed rgba(255, 255, 255, 0.15) !important; /* 虚线边框增加系统感 */
    color: #aaa !important; /* 字体灰色 */
    font-size: 12px;
    text-align: center;
    padding: 8px 16px;
    margin: 10px 0;
    box-shadow: none;
}

/* --- 输入框区域 --- */
.inputbox {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(30, 30, 30, 0.7) !important;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-radius: 30px;
    padding: 6px 12px;
    border: 1px solid rgba(255,255,255,0.1);
    width: 100%;
}

#userInput {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: white;
    outline: none;
    font-size: 16px !important;
    height: 36px;
}

.inputbox button {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50% !important;
    border: none;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.inputbox button:nth-child(2) { background-color: #4CAF50; }
#stopButton { background-color: #d32f2f; }
.micButton { background-color: #2196F3; }
.micButton.listening { background-color: #f44336; animation: pulse 1.5s infinite; }

/* 消息工具栏微缩 (重听、重新生成) */
.message-toolbar {
    display: flex;
    gap: 8px;
    transform: scale(0.7);
    transform-origin: left top;
    height: 16px;
    margin-top: 4px;
}
.message-toolbar button {
    background: transparent !important;
    border: none !important;
    color: #888;
    cursor: pointer;
}

/* 编辑按钮微缩 */
.message.user button {
    transform: scale(0.6);
    transform-origin: right bottom;
    background: transparent !important;
    border: none !important;
    opacity: 0.6;
    cursor: pointer;
    margin-top: 5px;
}

/* 手机适配 */
@media (max-width: 700px) {
    body {
        /* 防止页面在键盘弹出时被顶起后可以上下滑动 */
        position: fixed;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }

    .chatbox {
        /* 键盘弹出时，bottom: 5px 可能会有问题 */
        /* 改用固定定位，并确保 z-index 足够高 */
        position: fixed;
        bottom: 10px; /* 距离底部留一点距离 */
        width: 96%;
    }
}

/* --- 1. 状态栏：共性基础样式 --- */
#ai-status {
    position: fixed;
    z-index: 1000;
    pointer-events: auto !important;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    display: flex;
    flex-direction: column;
    /* 默认设为 center，方便 full-bar 使用 */
    align-items: center; 
    transition: all 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    user-select: none;
    overflow: hidden;
}

/* --- 2. 模式一：左上角灵动岛胶囊 (Capsule) --- */
#ai-status.capsule {
    top: 20px;
    left: 20px;
    width: auto;
    min-width: 120px;
    padding: 6px 14px;
    border-radius: 18px;
    
    /* 灵动岛整体内容左对齐 */
    align-items: flex-start; 
}

/* 灵动岛模式下的主状态栏左对齐 */
#ai-status.capsule .status-main {
    justify-content: flex-start; 
    padding-left: 2px;
}

/* 灵动岛模式下的详情竖向左对齐 */
#ai-status.capsule .detail-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding-left: 2px; 
}

/* 灵动岛模式下的分割线左对齐 */
#ai-status.capsule .divider {
    width: 90%;
    margin: 5px 0;
}

/* --- 3. 模式二：顶部全宽窄条 (Full-bar) --- */
#ai-status.full-bar {
    top: 0;
    left: 0;
    width: 100%;
    min-height: 30px;
    padding-top: 10px;
    padding-bottom: 6px;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    
    /* 保持长条模式居中 */
    align-items: center; 
    justify-content: flex-start;
}

#ai-status.full-bar .status-main {
    justify-content: center;
}

#ai-status.full-bar .detail-row {
    flex-direction: row;
    justify-content: center;
    gap: 20px;
}

/* --- 4. 内部通用布局 --- */
.status-main {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: 100%;
    flex-shrink: 0;
}

#status-detail {
    max-height: 0;
    opacity: 0;
    width: 100%;
    overflow: hidden;
    transition: all 0.4s ease;
}

#status-detail.show {
    opacity: 1;
}

/* 如果是长条模式，展开高度小一点 */
#ai-status.full-bar #status-detail.show {
    max-height: 60px;
}

/* 如果是胶囊模式（竖排），展开高度大一点 */
#ai-status.capsule #status-detail.show {
    max-height: 80px; 
}

.detail-row {
    display: flex;
    width: 100%;
}

.divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 5px auto;
}

.detail-item {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis; /* 文字太长自动显示省略号 */
}

/* --- 圆点与动画 --- */
.status-dot { display: none; width: 6px; height: 6px; border-radius: 50%; }
.status-online .status-dot { display: inline-block; background-color: #4CAF50; animation: status-pulse 2s infinite; }
@keyframes status-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* 常驻好感度小标签 */
#affection-mini {
    font-size: 10px;
    color: #ff4d4f;
    margin-left: 5px;
    opacity: 0.8;
}

/* 按钮行排列 */
.action-row {
    display: flex;
    gap: 15px;
    margin-top: 8px;
    justify-content: center;
    width: 100%;
}

.action-btn {
    font-size: 11px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    color: #aaa;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    transform: translateY(-1px);
}

/* 针对长条模式的适配 */
#ai-status.full-bar .action-row {
    justify-content: center;
}

/* 日记浮窗遮罩 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none; /* 默认隐藏 */
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 { margin: 0; font-size: 16px; color: #ff4d4f; }

/* 日记条目样式 */
.diary-item {
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    transition: background 0.3s;
    display: flex;
    justify-content: space-between;
}
.diary-item:hover { background: rgba(255,255,255,0.05); }
.diary-item .date-tag { color: #fff; font-weight: bold; }
.diary-item .arrow { color: #555; }

.hidden { display: none; }

/* 日记浮窗基础布局 */
.modal-content {
    background: rgba(20, 20, 20, 0.95);
    width: 90%;
    max-width: 500px;
    height: 70vh; /* 固定浮窗总高度 */
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    position: relative; /* 为按钮定位提供参考 */
    overflow: hidden;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0; /* 移除内边距，让滚动条靠边 */
}

#diary-list {
    width: 100%;
}

#diary-viewer {
    padding: 25px;
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* ✨ 确保内容左对齐 */
    justify-content: flex-start; /* ✨ 确保内容从顶部开始排 */
    min-height: 100%;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

/* 右上角关闭按钮 UI */
.close-btn {
    background: rgba(255, 255, 255, 0.05); /* 极淡的背景 */
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #888;
    width: 28px;
    height: 28px;
    border-radius: 50%; /* 圆形 */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.3s ease;
    line-height: 1;
    padding-bottom: 2px; /* 视觉微调 */
}

.close-btn:hover {
    background: rgba(255, 77, 79, 0.2); /* 悬停时淡淡的红色 */
    color: #ff4d4f;
    border-color: rgba(255, 77, 79, 0.3);
    transform: rotate(90deg); /* 旋转动画 */
}

/* 日记文本区样式 */
#diary-content {
    line-height: 1.8;
    color: #ccc;
    font-style: normal;
    font-size: 15px;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    width: 100%;
    flex-grow: 0;
}

/* 标题横线样式 */
.diary-header-line {
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    width: 100%;
    margin: 8px 0;
}

/* 返回列表按钮随页面滚动 */
.back-btn {
    position: relative;
    display: block;

    /* 把上方剩下的所有空间都吃掉 */
    margin-top: auto;

    /* 按钮和正文之间至少留出 40px 的呼吸感，防止紧贴 */
    padding-top: 0;
    margin-top: 60px !important;

    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    padding: 8px 30px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    width: fit-content;
    align-self: center; /* 按钮自己在中间 */
    margin-bottom: 10px;
}
