/* ========== 基础重置 ========== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: 'Microsoft YaHei', 'PingFang SC', sans-serif;
    background: radial-gradient(ellipse at 20% 50%, #1a0a3e 0%, #0a0a2a 40%, #020010 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* 星河背景 */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(2px 2px at 10% 20%, rgba(255,255,255,0.9), transparent),
        radial-gradient(2px 2px at 25% 45%, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 40% 15%, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 55% 60%, rgba(255,255,255,0.7), transparent),
        radial-gradient(2px 2px at 70% 30%, rgba(255,255,255,0.9), transparent),
        radial-gradient(1px 1px at 85% 55%, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 15% 75%, rgba(255,255,255,0.8), transparent),
        radial-gradient(2px 2px at 50% 80%, rgba(255,255,255,0.5), transparent),
        radial-gradient(1px 1px at 75% 70%, rgba(255,255,255,0.7), transparent),
        radial-gradient(1px 1px at 30% 10%, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 90% 10%, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 5% 50%, rgba(255,255,255,0.5), transparent),
        radial-gradient(1px 1px at 60% 5%, rgba(255,255,255,0.7), transparent),
        radial-gradient(1px 1px at 35% 90%, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 80% 85%, rgba(255,255,255,0.5), transparent),
        radial-gradient(1px 1px at 45% 40%, rgba(255,255,255,0.9), transparent),
        radial-gradient(1px 1px at 20% 65%, rgba(255,255,255,0.4), transparent),
        radial-gradient(1px 1px at 65% 50%, rgba(255,255,255,0.7), transparent),
        radial-gradient(2px 2px at 95% 40%, rgba(255,255,255,0.8), transparent),
        radial-gradient(1px 1px at 50% 25%, rgba(255,255,255,0.5), transparent);
    background-size: 200px 200px;
    animation: starTwinkle 4s ease-in-out infinite alternate;
}

body::after {
    content: '';
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(3px 3px at 20% 30%, rgba(180,200,255,1), transparent),
        radial-gradient(3px 3px at 60% 20%, rgba(200,220,255,0.9), transparent),
        radial-gradient(2px 2px at 80% 70%, rgba(180,200,255,0.8), transparent),
        radial-gradient(3px 3px at 40% 80%, rgba(200,220,255,0.9), transparent),
        radial-gradient(2px 2px at 10% 60%, rgba(180,200,255,0.7), transparent),
        radial-gradient(3px 3px at 70% 45%, rgba(200,220,255,1), transparent),
        radial-gradient(2px 2px at 90% 25%, rgba(180,200,255,0.8), transparent),
        radial-gradient(2px 2px at 30% 55%, rgba(200,220,255,0.6), transparent),
        radial-gradient(3px 3px at 50% 10%, rgba(180,200,255,0.9), transparent),
        radial-gradient(2px 2px at 15% 85%, rgba(200,220,255,0.7), transparent);
    background-size: 300px 300px;
    animation: starTwinkle 3s ease-in-out infinite alternate-reverse;
}

@keyframes starTwinkle {
    0% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* 星云效果 */
.star-nebula {
    position: fixed;
    top: -20%; left: -10%;
    width: 60%; height: 60%;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse at 50% 50%, rgba(100,50,180,0.15) 0%, transparent 70%);
    border-radius: 50%;
    animation: nebulaDrift 12s ease-in-out infinite;
}

.star-nebula2 {
    position: fixed;
    bottom: -20%; right: -10%;
    width: 50%; height: 50%;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse at 50% 50%, rgba(30,80,180,0.12) 0%, transparent 70%);
    border-radius: 50%;
    animation: nebulaDrift 15s ease-in-out infinite reverse;
}

@keyframes nebulaDrift {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(2%, -1%) scale(1.05); }
    50% { transform: translate(-1%, 1%) scale(0.95); }
    75% { transform: translate(1%, 2%) scale(1.03); }
}

/* ========== 画布背景 ========== */
#bgCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

/* ========== 主容器 ========== */
.container {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    padding: 20px;
    pointer-events: none;
}

.container > * {
    pointer-events: auto;
}

/* ========== 信封 ========== */
.envelope-wrapper {
    position: relative;
    cursor: pointer;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.6s ease;
}

.envelope-wrapper:hover {
    transform: scale(1.05);
}

.envelope-wrapper:active {
    transform: scale(0.97);
}

.envelope-wrapper.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.6);
}

/* 点击波纹 */
.envelope-ripple {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 0;
}

.envelope-ripple.expand {
    animation: ripple 0.8s ease-out forwards;
}

@keyframes ripple {
    0% { width: 0; height: 0; opacity: 1; }
    100% { width: 400px; height: 400px; opacity: 0; }
}

/* 信封主体 */
.envelope {
    position: relative;
    width: 220px;
    height: 160px;
    animation: float 3s ease-in-out infinite;
    z-index: 1;
}

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

/* 信封背面 */
.envelope-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(160deg, #e8456b, #c0392b);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(255, 51, 102, 0.35);
    z-index: 0;
}

/* 信封内信件 */
.envelope-letter {
    position: absolute;
    bottom: 8px;
    left: 12px;
    right: 12px;
    height: 75px;
    background: linear-gradient(135deg, #fffdf7, #fff8f0);
    border-radius: 4px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.envelope.flipped .envelope-letter {
    transform: translateY(-120px) scale(0.9);
    opacity: 0;
}

.letter-content {
    text-align: center;
}

.letter-heart {
    font-size: 28px;
    color: #ff3366;
    animation: heartbeat 1.2s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.3); }
    30% { transform: scale(1); }
    45% { transform: scale(1.15); }
    60% { transform: scale(1); }
}

/* 信封正面 */
.envelope-body {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 105px;
    background: linear-gradient(160deg, #ff6b8a, #ff3366);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 40px rgba(255, 51, 102, 0.4);
    z-index: 2;
    overflow: hidden;
}

.envelope-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, transparent 40%, rgba(255,255,255,0.18) 50%, transparent 60%);
    animation: shine 2.5s ease-in-out infinite;
}

@keyframes shine {
    0%, 100% { transform: translateX(-100%); }
    50% { transform: translateX(100%); }
}

/* 信封火漆印章 */
.envelope-seal {
    position: absolute;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    background: radial-gradient(circle at 35% 35%, #ff6b8a, #c0392b);
    border-radius: 50%;
    z-index: 4;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.2);
    animation: sealPulse 2s ease-in-out infinite;
}

/* 封蜡上的CSS爱心 */
.envelope-seal::before,
.envelope-seal::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 10px;
    background: #fff;
    border-radius: 3px 3px 0 0;
    z-index: 1;
}

.envelope-seal::before {
    left: calc(50% + 4px);
    top: 50%;
    transform-origin: 0 100%;
    transform: translate(-50%, -50%) rotate(-45deg) translate(0, -100%);
}

.envelope-seal::after {
    left: calc(50% - 4px);
    top: 50%;
    transform-origin: 100% 100%;
    transform: translate(-50%, -50%) rotate(45deg) translate(0, -100%);
}

/* 信封上的爱心 - CSS绘制 */
.envelope-heart {
    position: relative;
    width: 30px;
    height: 30px;
    margin-bottom: 8px;
    z-index: 3;
    animation: heartBeat 1.2s ease-in-out infinite;
}

.envelope-heart::before,
.envelope-heart::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 26px;
    background: #fff;
    border-radius: 16px 16px 0 0;
}

.envelope-heart::before {
    left: 15px;
    top: 0;
    transform: rotate(-45deg);
    transform-origin: 0 100%;
}

.envelope-heart::after {
    left: 0;
    top: 0;
    transform: rotate(45deg);
    transform-origin: 100% 100%;
}

@keyframes heartBeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.15); }
    30% { transform: scale(1); }
    45% { transform: scale(1.1); }
    60% { transform: scale(1); }
}

@keyframes sealPulse {
    0%, 100% { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.2), 0 0 0 rgba(255, 51, 102, 0); }
    50% { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.2), 0 0 20px rgba(255, 51, 102, 0.5); }
}

.envelope-hint {
    position: absolute;
    bottom: 18px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    letter-spacing: 3px;
    animation: blink 1.5s ease-in-out infinite;
    z-index: 5;
}

@keyframes blink {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* ========== 打字机文字 ========== */
.love-content {
    position: absolute;
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    opacity: 0;
    transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.love-content.show {
    opacity: 1;
    transform: translateX(-50%) scale(1);
    pointer-events: auto;
}

.love-message {
    color: rgba(255, 255, 255, 0.9);
    font-size: 17px;
    line-height: 2;
    min-height: 30px;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(255, 51, 102, 0.3);
}

.love-message .cursor {
    display: inline-block;
    width: 2px;
    height: 18px;
    background: #ff6b8a;
    margin-left: 4px;
    animation: cursorBlink 0.8s infinite;
    vertical-align: middle;
}

/* 历史消息列表 */
.love-history {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    overflow: hidden;
}

.love-history-item {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    letter-spacing: 1px;
    text-shadow: 0 0 6px rgba(255, 51, 102, 0.2);
    animation: historyIn 0.5s ease-out forwards;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.love-history-item.fading {
    animation: historyFadeOut 0.3s ease-in forwards;
}

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

@keyframes historyFadeOut {
    from {
        opacity: 1;
        max-height: 30px;
    }
    to {
        opacity: 0;
        max-height: 0;
        margin: 0;
    }
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* 显示原文按钮 */
.btn-show-all {
    display: block;
    margin: 10px auto 0;
    padding: 8px 24px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
}

.btn-show-all:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

/* 全部原文显示 */
.all-texts {
    margin-top: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-height: 50vh;
    overflow-y: auto;
    text-align: left;
}

.all-texts p {
    color: rgba(255, 255, 255, 0.85);
    font-size: 15px;
    line-height: 2;
    letter-spacing: 1px;
    margin: 0;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* ========== 底部按钮 ========== */
.bottom-actions {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: flex;
    gap: 20px;
    opacity: 0;
    transition: all 0.6s ease 0.5s;
    pointer-events: none;
}

.bottom-actions.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.btn-action {
    padding: 14px 36px;
    border: none;
    border-radius: 50px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    letter-spacing: 2px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(135deg, #ff6b8a, #ff3366);
    box-shadow: 0 8px 25px rgba(255, 51, 102, 0.4);
}

.btn-action:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 35px rgba(255, 51, 102, 0.6);
}

.btn-action:active {
    transform: translateY(0);
}

.btn-run {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
    color: rgba(255, 255, 255, 0.7);
}

.btn-voice {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-voice:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-voice.active {
    background: rgba(100, 200, 255, 0.2);
    border-color: rgba(100, 200, 255, 0.5);
}

.btn-music {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-music:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
}

.btn-music.playing {
    background: rgba(255, 107, 138, 0.2);
    border-color: rgba(255, 107, 138, 0.5);
    animation: musicPulse 1.5s ease-in-out infinite;
}

@keyframes musicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 138, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 107, 138, 0); }
}

.btn-run:hover {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 25px rgba(255, 255, 255, 0.1);
}

/* ========== Toast 提示 ========== */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 30px 50px;
    border-radius: 20px;
    font-size: 22px;
    letter-spacing: 3px;
    z-index: 100;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.toast.show {
    transform: translate(-50%, -50%) scale(1);
}

/* ========== 响应式 ========== */
@media (max-width: 480px) {
    .love-message {
        font-size: 15px;
    }

    .btn-action {
        padding: 12px 28px;
        font-size: 16px;
    }

    .bottom-actions {
        gap: 15px;
        bottom: 40px;
    }

    .envelope {
        width: 180px;
        height: 132px;
    }

    .envelope-body {
        height: 86px;
    }

    .envelope-letter {
        height: 60px;
        left: 10px;
        right: 10px;
        bottom: 6px;
    }

    .envelope-seal {
        width: 32px;
        height: 32px;
        top: 12px;
    }

    .envelope-seal::after {
        font-size: 14px;
    }

    .envelope-hint {
        font-size: 11px;
        bottom: 14px;
    }
}

/* ========== 爱心点击弹出文字 ========== */
.love-popup {
    position: fixed;
    transform: translate(-50%, -50%);
    color: #ff6b8a;
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 1px;
    background: none;
    pointer-events: none;
    z-index: 200;
    animation: popupBounce 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    text-shadow: 0 0 10px rgba(255, 107, 138, 0.6), 0 0 20px rgba(255, 107, 138, 0.3);
    white-space: nowrap;
    max-width: 80vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

.love-popup.fade-out {
    animation: popupFadeOut 1.5s ease forwards;
}

@keyframes popupBounce {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3);
    }
    60% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

@keyframes popupFadeOut {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(-60px) scale(1.5);
    }
}