@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes glow {
    0% {
        box-shadow: 0 0 5px #00aaff, 0 0 10px #00aaff;
    }

    50% {
        box-shadow: 0 0 20px #00aaff, 0 0 30px #00aaff;
    }

    100% {
        box-shadow: 0 0 5px #00aaff, 0 0 10px #00aaff;
    }
}

body {
    font-family: 'Roboto Mono', monospace;
    background-color: #0a0a1a;
    background-image: radial-gradient(circle at center, #1a2a4a 0%, #0a0a1a 70%);
    color: #e0e0e0;
    margin: 0;
    padding: 20px;
    height: 100vh;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
}

/* Jarvis容器 - 放在左侧1/5处 */
#ai-face-container {
    position: fixed;
    left: 20%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 220px;
    height: 220px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(0, 170, 255, 0.05) 0%, rgba(0, 170, 255, 0) 70%);
    border: 2px solid var(--glow-color-primary, #00aaff);
    box-shadow: 0 0 20px var(--glow-color-primary, #00aaff), inset 0 0 10px var(--glow-color-primary, #00aaff);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3em;
    color: var(--glow-color-secondary, #00ffff);
    text-shadow: 0 0 10px var(--glow-color-secondary, #00ffff);
    transition: all 0.3s ease-in-out;
    --glow-color-primary: #e0e0e0;
    --glow-color-secondary: #ffffff;
    overflow: hidden;
    z-index: 1000;
}

/* 人脸特征元素 */
.face-features {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

/* 眼睛 */
.eye {
    position: absolute;
    width: 12px;
    height: 8px;
    background: var(--glow-color-primary, #00aaff);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--glow-color-primary, #00aaff);
    top: 35%;
}

.eye.left {
    left: 35%;
    animation: blink 4s infinite ease-in-out;
}

.eye.right {
    right: 35%;
    animation: blink 4s infinite ease-in-out 0.1s;
}

/* 嘴巴 */
.mouth {
    position: absolute;
    width: 20px;
    height: 4px;
    border: 1px solid var(--glow-color-secondary, #00ffff);
    border-radius: 0 0 20px 20px;
    border-top: none;
    left: 50%;
    top: 60%;
    transform: translateX(-50%);
    box-shadow: 0 0 6px var(--glow-color-secondary, #00ffff);
}

/* Jarvis 5层嵌套圆环 */
.jarvis-layer {
    position: absolute;
    border-radius: 50%;
    border: 1px solid;
    opacity: 0.6;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.3s ease;
}

.layer-1 {
    width: 100%;
    height: 100%;
    border-color: var(--glow-color-primary, #00aaff);
    box-shadow: 0 0 15px var(--glow-color-primary, #00aaff);
    border-width: 2px;
}

.layer-2 {
    width: 85%;
    height: 85%;
    border-color: var(--glow-color-secondary, #00ffff);
    box-shadow: 0 0 12px var(--glow-color-secondary, #00ffff);
    border-width: 1.5px;
}

.layer-3 {
    width: 70%;
    height: 70%;
    border-color: var(--glow-color-primary, #00aaff);
    box-shadow: 0 0 10px var(--glow-color-primary, #00aaff);
    border-width: 1px;
}

.layer-4 {
    width: 55%;
    height: 55%;
    border-color: var(--glow-color-secondary, #00ffff);
    box-shadow: 0 0 8px var(--glow-color-secondary, #00ffff);
    border-width: 1px;
}

.layer-5 {
    width: 40%;
    height: 40%;
    border-color: var(--glow-color-primary, #00aaff);
    box-shadow: 0 0 5px var(--glow-color-primary, #00aaff);
    border-width: 0.5px;
}

/* === 人脸波动动画 === */

/* 眨眼动画 */
@keyframes blink {

    0%,
    90%,
    100% {
        height: 8px;
        opacity: 1;
    }

    95% {
        height: 1px;
        opacity: 0.7;
    }
}

/* 呼吸波动 - 模拟胸腔起伏 */
@keyframes breathing {
    0% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(1.02);
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

/* 心跳波动 */
@keyframes heartbeat {
    0% {
        transform: translate(-50%, -50%) scale(1);
    }

    14% {
        transform: translate(-50%, -50%) scale(1.05);
    }

    28% {
        transform: translate(-50%, -50%) scale(1);
    }

    42% {
        transform: translate(-50%, -50%) scale(1.05);
    }

    70% {
        transform: translate(-50%, -50%) scale(1);
    }
}

/* 面部表情波动 - 圆环变形 */
@keyframes facial-expression {
    0% {
        border-radius: 50%;
    }

    25% {
        border-radius: 45% 55% 50% 50%;
    }

    50% {
        border-radius: 50% 50% 45% 55%;
    }

    75% {
        border-radius: 55% 45% 50% 50%;
    }

    100% {
        border-radius: 50%;
    }
}

/* 说话时嘴部动画 */
@keyframes talking-mouth {
    0% {
        width: 20px;
        height: 4px;
        border-radius: 0 0 20px 20px;
    }

    25% {
        width: 16px;
        height: 8px;
        border-radius: 50%;
    }

    50% {
        width: 24px;
        height: 6px;
        border-radius: 0 0 15px 15px;
    }

    75% {
        width: 18px;
        height: 10px;
        border-radius: 50%;
    }

    100% {
        width: 20px;
        height: 4px;
        border-radius: 0 0 20px 20px;
    }
}

/* 思考时的波纹效果 */
@keyframes thinking-ripple {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.1);
        opacity: 0.8;
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
}

/* 情感波动 - 不同层级的异步变化 */
@keyframes emotion-wave-1 {
    0% {
        transform: translate(-50%, -50%) rotate(0deg) scale(1);
    }

    33% {
        transform: translate(-50%, -50%) rotate(120deg) scale(1.03);
    }

    66% {
        transform: translate(-50%, -50%) rotate(240deg) scale(0.98);
    }

    100% {
        transform: translate(-50%, -50%) rotate(360deg) scale(1);
    }
}

@keyframes emotion-wave-2 {
    0% {
        transform: translate(-50%, -50%) rotate(0deg) scale(1);
    }

    25% {
        transform: translate(-50%, -50%) rotate(-90deg) scale(1.05);
    }

    50% {
        transform: translate(-50%, -50%) rotate(-180deg) scale(0.96);
    }

    75% {
        transform: translate(-50%, -50%) rotate(-270deg) scale(1.04);
    }

    100% {
        transform: translate(-50%, -50%) rotate(-360deg) scale(1);
    }
}

/* === 状态动画应用 === */

/* 默认状态（休息/呼吸） */
#ai-face-container.state-finished {
    animation: breathing 4s ease-in-out infinite;
}

#ai-face-container.state-finished .layer-1 {
    animation: emotion-wave-1 8s ease-in-out infinite;
}

#ai-face-container.state-finished .layer-2 {
    animation: emotion-wave-2 10s ease-in-out infinite;
}

#ai-face-container.state-finished .layer-3 {
    animation: facial-expression 6s ease-in-out infinite;
}

#ai-face-container.state-finished .layer-4 {
    animation: thinking-ripple 5s ease-in-out infinite;
}

#ai-face-container.state-finished .layer-5 {
    animation: emotion-wave-1 7s ease-in-out infinite reverse;
}

/* 用户提问状态（专注聆听） */
#ai-face-container.state-user-asking {
    animation: heartbeat 1.5s ease-in-out infinite;
}

#ai-face-container.state-user-asking .layer-1 {
    animation: thinking-ripple 2s ease-in-out infinite;
}

#ai-face-container.state-user-asking .layer-2 {
    animation: emotion-wave-1 1.8s ease-in-out infinite;
}

#ai-face-container.state-user-asking .layer-3 {
    animation: emotion-wave-2 2.2s ease-in-out infinite;
}

#ai-face-container.state-user-asking .layer-4 {
    animation: facial-expression 1.6s ease-in-out infinite;
}

#ai-face-container.state-user-asking .layer-5 {
    animation: thinking-ripple 1.4s ease-in-out infinite;
}

/* AI回复状态（说话） */
#ai-face-container.state-ai-replying {
    animation: breathing 2s ease-in-out infinite;
}

#ai-face-container.state-ai-replying .mouth {
    animation: talking-mouth 0.8s ease-in-out infinite;
}

#ai-face-container.state-ai-replying .layer-1 {
    animation: emotion-wave-1 1.5s ease-in-out infinite;
}

#ai-face-container.state-ai-replying .layer-2 {
    animation: emotion-wave-2 1.2s ease-in-out infinite;
}

#ai-face-container.state-ai-replying .layer-3 {
    animation: facial-expression 2s ease-in-out infinite;
}

#ai-face-container.state-ai-replying .layer-4 {
    animation: thinking-ripple 1.8s ease-in-out infinite;
}

#ai-face-container.state-ai-replying .layer-5 {
    animation: emotion-wave-2 1s ease-in-out infinite reverse;
}

/* 错误状态（不安/紧张） */
#ai-face-container.state-error {
    animation: heartbeat 0.8s ease-in-out infinite;
}

#ai-face-container.state-error .layer-1,
#ai-face-container.state-error .layer-2,
#ai-face-container.state-error .layer-3,
#ai-face-container.state-error .layer-4,
#ai-face-container.state-error .layer-5 {
    animation: thinking-ripple 0.6s ease-in-out infinite;
}

/* 状态颜色 */
#ai-face-container.state-user-asking {
    --glow-color-primary: #007bff;
    --glow-color-secondary: #00bfff;
}

#ai-face-container.state-ai-replying {
    --glow-color-primary: #28a745;
    --glow-color-secondary: #28ff45;
}

#ai-face-container.state-finished {
    --glow-color-primary: #ffc107;
    --glow-color-secondary: #ffff00;
}

#ai-face-container.state-error {
    --glow-color-primary: #dc3545;
    --glow-color-secondary: #ff0000;
}

/* 聊天容器 - 放在右侧 */
.chat-container {
    width: 100%;
    max-width: 750px;
    height: 90vh;
    max-height: 850px;
    background-color: rgba(10, 20, 35, 0.75);
    border: 1px solid var(--glow-color-primary, #00aaff);
    border-radius: 12px;
    box-shadow: 0 0 25px var(--glow-color-secondary, rgba(0, 170, 255, 0.5)), inset 0 0 15px var(--glow-color-primary, rgba(0, 170, 255, 0.2));
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-left: auto;
    margin-right: 5%;
}

/* 脉冲发光效果 */
@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 20px var(--glow-color-primary), inset 0 0 10px var(--glow-color-primary);
        transform: translate(-50%, -50%) scale(1);
    }

    100% {
        box-shadow: 0 0 40px var(--glow-color-secondary), inset 0 0 20px var(--glow-color-secondary);
        transform: translate(-50%, -50%) scale(1.05);
    }
}

#ai-face-container.talking-animation {
    animation: pulse-glow 1.5s infinite alternate;
}

/* 加载动画 */
.loading-spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #00aaff;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    margin: 5px;
    display: inline-block;
    vertical-align: middle;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 聊天容器样式 */
.chat-header {
    background: linear-gradient(to bottom, rgba(0, 170, 255, 0.2), rgba(0, 170, 255, 0));
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid #00aaff;
}

.chat-header h2 {
    margin: 0;
    font-size: 1.4em;
    color: #ffffff;
    text-shadow: 0 0 5px #fff, 0 0 10px #00aaff;
}

.chat-box {
    flex-grow: 1;
    padding: 15px;
    /* 减少从20px匃15px */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* 减少从15px匃10px */
}

.chat-box::-webkit-scrollbar {
    width: 8px;
}

.chat-box::-webkit-scrollbar-track {
    background: transparent;
}

.chat-box::-webkit-scrollbar-thumb {
    background-color: rgba(0, 170, 255, 0.5);
    border-radius: 4px;
    border: 1px solid rgba(0, 170, 255, 0.8);
}

.message {
    display: flex;
    max-width: 75%;
    padding: 8px 12px;
    /* 减少padding从12px 18px到8px 12px */
    border-radius: 10px;
    line-height: 1.4;
    /* 减少行间距从1.6到1.4 */
    border: 1px solid transparent;
    animation: fadeIn 0.4s ease-out;
}

.message div {
    box-sizing: border-box;
    margin: 0;
    white-space: pre-wrap;
}

.message.sent {
    background-color: rgba(0, 170, 255, 0.2);
    border-color: rgba(0, 170, 255, 0.6);
    color: #cceeff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message.received {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
    color: #e0e0e0;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-input {
    padding: 15px;
    border-top: 1px solid #00aaff;
}

.chat-input form {
    display: flex;
    gap: 10px;
}

.chat-input input {
    flex-grow: 1;
    padding: 12px 18px;
    border: 1px solid #00aaff;
    border-radius: 20px;
    font-size: 1em;
    background-color: rgba(10, 20, 35, 0.8);
    color: #e0e0e0;
    font-family: 'Roboto Mono', monospace;
    transition: all 0.3s ease;
}

.chat-input input:focus {
    outline: none;
    border-color: #00ffff;
    box-shadow: 0 0 15px #00ffff;
}

.chat-input button {
    padding: 12px 20px;
    border: 1px solid #00aaff;
    background-color: transparent;
    color: #00aaff;
    border-radius: 20px;
    cursor: pointer;
    font-size: 1em;
    font-family: 'Roboto Mono', monospace;
    transition: all 0.3s ease;
    text-shadow: 0 0 5px #00aaff;
}

.chat-input button:hover,
.chat-input button:disabled {
    background-color: #00aaff;
    color: #0a0a1a;
    box-shadow: 0 0 20px #00aaff;
    text-shadow: none;
}

.chat-input button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 打字动画 */
@keyframes techy-char-appear {
    0% {
        opacity: 0;
        transform: scale(1.5);
        color: #00ffff;
        text-shadow: 0 0 15px #00ffff;
    }

    80% {
        opacity: 1;
        transform: scale(1);
        color: #00ffff;
        text-shadow: 0 0 15px #00ffff;
    }

    100% {
        opacity: 1;
        color: #e0e0e0;
        text-shadow: none;
    }
}

.techy-char {
    display: inline-block;
    animation: techy-char-appear 0.4s forwards;
}

/* Markdown内容优化样式 */
.message.received div p {
    margin: 0.2em 0;
    /* 减少从0.3em到0.2em */
    line-height: 1.2;
    /* 减少从1.3到1.2 */
}

.message.received div h1,
.message.received div h2,
.message.received div h3,
.message.received div h4,
.message.received div h5,
.message.received div h6 {
    margin: 0.1em 0 0.1em 0;
    /* 减少从0.4em 0 0.2em 0到0.3em 0 0.1em 0 */
    line-height: 1.1;
    /* 减少从1.2到1.1 */
}

.message.received div ul,
.message.received div ol {
    margin: 0;
    /* 与div保持一致 */
    padding-left: 0.8em;
    /* 进一步减少缩进 */
    line-height: 1.2;
    /* 与div保持一致的行高 */
}

.message.received div li {
    margin: 0;
    /* 与div保持一致，去除额外间距 */
    padding: 0;
    /* 去除padding */
    line-height: 1.2;
    /* 与div保持一致的行高 */
}

.message.received div pre {
    margin: 0.2em 0;
    /* 减少从0.3em到0.2em */
    padding: 0.3em;
    /* 减少从0.5em到0.3em */
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow-x: auto;
}

.message.received div code {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.05em 0.2em;
    /* 减少从0.1em 0.3em到0.05em 0.2em */
    border-radius: 3px;
}

.message.received div blockquote {
    margin: 0.2em 0;
    /* 减少从0.3em到0.2em */
    padding-left: 0.6em;
    /* 减少从0.8em到0.6em */
    border-left: 3px solid #00aaff;
}

/* 响应式设计 */
@media (max-width: 1400px) {
    .chat-container {
        max-width: 650px;
        margin-right: 3%;
    }

    #ai-face-container {
        width: 200px;
        height: 200px;
    }
}

@media (max-width: 1024px) {
    #ai-face-container {
        left: 15%;
        width: 180px;
        height: 180px;
        font-size: 2.5em;
    }

    .chat-container {
        max-width: 550px;
        margin-right: 2%;
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
        justify-content: center;
        padding: 10px;
    }

    #ai-face-container {
        position: relative;
        left: auto;
        top: auto;
        transform: none;
        width: 150px;
        height: 150px;
        font-size: 2em;
        margin-bottom: 20px;
    }

    .chat-container {
        margin: 0;
        max-width: 100%;
        height: 70vh;
    }
}
