* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: radial-gradient(circle at center, #1b2735 0%, #090a0f 100%);
    color: #fff;
    font-family: 'Zcool KuaiLe', 'Ma Shan Zheng', cursive, sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

.container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* 打字机容器 */
.typing-container {
    position: absolute;
    z-index: 2;
    bottom: 25%; /* 提高位置，避开人物 */
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    height: 150px; /* 固定高度，约3行文字的高度 */
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /*文字从底部向上堆叠或者正常显示，这里我们用JS控制添加，所以justify-content: flex-end 让文字贴底比较好看，或者 flex-start */
    justify-content: flex-start; 
    align-items: center;
    pointer-events: none;
    text-align: center;
    overflow: hidden; /* 隐藏溢出 */
}

/* 动漫人物容器 */
.couple-container {
    position: absolute;
    bottom: 5%; /* 放在底部，稍微遮挡树干 */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-end;
    gap: 20px;
    z-index: 3; /* 在树和文字之上 */
    pointer-events: none;
}

.character {
    width: 80px;
    height: 120px;
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
}

.boy {
    animation: sway 3s ease-in-out infinite;
}

.girl {
    animation: sway 3s ease-in-out infinite reverse; /* 反向摇摆，感觉在互动 */
}

.heart {
    font-size: 2rem;
    color: #e74c3c;
    animation: heartbeat 1.5s ease-in-out infinite;
    margin-bottom: 60px; /* 让爱心飘在中间上方 */
}

@keyframes sway {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.3); opacity: 1; }
}

.typing-line {
    font-size: clamp(1.2rem, 4vw, 1.8rem); /* 响应式字体 */
    color: #fff;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.8), 2px 2px 2px rgba(0, 0, 0, 0.5);
    margin: 5px 0;
    opacity: 0;
    animation: fadeIn 0.5s forwards;
    min-height: 1.5em;
    font-family: 'Ma Shan Zheng', cursive;
    line-height: 1.5;
}

/* 字幕模式特定样式 */
.typing-line.subtitle-mode {
    font-size: clamp(1.5rem, 5vw, 2.2rem); /* 字幕模式稍微大一点 */
    background: rgba(0, 0, 0, 0.3); /* 半透明背景增加可读性 */
    padding: 5px 15px;
    border-radius: 20px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

.typing-line.fade-out {
    animation: fadeOut 0.5s forwards;
}

/* 聊天气泡触发器 */
.chat-trigger {
    position: absolute;
    top: -40px;
    left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
    z-index: 10;
    animation: bounce 2s infinite;
    pointer-events: auto; /* 关键修复：允许点击，覆盖父级的 none */
}

.bubble-text {
    background: #fff;
    color: #333;
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    position: relative;
    white-space: nowrap;
}

.bubble-text::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: #fff transparent transparent transparent;
}

@keyframes bounce {
    0%, 100% { transform: translate(-50%, 0); }
    50% { transform: translate(-50%, -10px); }
}

/* 微信风格聊天窗口 */
.wechat-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    height: 500px;
    background: #f5f5f5;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #000;
    font-family: sans-serif;
}

.wechat-header {
    height: 45px;
    background: #ededed;
    border-bottom: 1px solid #dcdcdc;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    font-size: 16px;
}

.back-btn {
    font-size: 20px;
    cursor: pointer;
    color: #000;
}

.wechat-title {
    font-weight: bold;
}

.wechat-menu {
    font-weight: bold;
    letter-spacing: 2px;
}

.wechat-messages {
    flex: 1;
    background: #f5f5f5;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    align-items: flex-start;
    max-width: 80%;
}

.message.received {
    align-self: flex-start;
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.avatar {
    width: 35px;
    height: 35px;
    background: #fff;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.message.received .avatar {
    margin-right: 10px;
}

.message.sent .avatar {
    margin-left: 10px;
    background: #a0e75a; /* 稍微深一点的绿色 */
}

.content {
    background: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.received .content {
    background: #fff;
}

.message.sent .content {
    background: #95ec69; /* 微信绿 */
}

.message.received .content::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 12px;
    border-width: 6px 6px 6px 0;
    border-style: solid;
    border-color: transparent #fff transparent transparent;
}

.message.sent .content::before {
    content: '';
    position: absolute;
    right: -6px;
    top: 12px;
    border-width: 6px 0 6px 6px;
    border-style: solid;
    border-color: transparent transparent transparent #95ec69;
}

.wechat-input-area {
    height: 50px;
    background: #f5f5f5;
    border-top: 1px solid #dcdcdc;
    display: flex;
    align-items: center;
    padding: 0 10px;
    gap: 10px;
}

#chatInput {
    flex: 1;
    height: 36px;
    border: none;
    border-radius: 4px;
    padding: 0 10px;
    font-size: 14px;
    outline: none;
    background: #fff;
}

#sendBtn {
    background: #95ec69;
    border: none;
    color: #000;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

#sendBtn:hover {
    background: #89d961;
}

#sendBtn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

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

@keyframes fadeOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-20px); }
}


.music-control {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 10;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.music-control:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.music-icon {
    color: #fff;
    width: 20px;
    height: 20px;
}

.music-playing .music-icon {
    animation: rotate 3s linear infinite;
    color: #2ecc71;
}

@keyframes float {
    0%, 100% {
        transform: translate(-50%, -50%);
    }
    50% {
        transform: translate(-50%, -55%);
    }
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes glowRed {
    from {
        text-shadow: 0 0 10px rgba(255, 77, 77, 0.5);
    }
    to {
        text-shadow: 0 0 20px rgba(255, 77, 77, 0.9), 0 0 30px rgba(255, 77, 77, 0.7);
    }
}

@keyframes glowGreen {
    from {
        text-shadow: 0 0 10px rgba(46, 204, 113, 0.5);
    }
    to {
        text-shadow: 0 0 20px rgba(46, 204, 113, 0.9), 0 0 30px rgba(46, 204, 113, 0.7);
    }
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .message-container {
        width: 90%;
    }
}
