@font-face {
    font-family: 'Ma Shan Zheng';
    src: url('../fonts/MaShanZheng.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Long Cang';
    src: url('../fonts/LongCang.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --red-dark: #2b0808;
    --red-main: #8a1c1c;
    --gold: #eebb86;
    --gold-light: #fff5e0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    height: 100%;
    overflow: hidden;
    background: var(--red-dark);
    color: var(--gold);
    font-family: 'Long Cang', cursive; /* Global Handwriting Style */
}

/* Background Canvas: Fireworks & Stars */
#canvas-bg {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 0;
    pointer-events: none;
}

/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: #2b0808;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 1s ease, visibility 1s ease;
}
#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
}
.loading-content {
    text-align: center;
    color: var(--gold);
}
.loading-text {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.5rem;
    margin-bottom: 20px;
    letter-spacing: 2px;
    animation: pulse-text 1.5s infinite alternate;
}
.loading-bar {
    width: 200px;
    height: 4px;
    background: rgba(238, 187, 134, 0.2);
    border-radius: 2px;
    margin: 0 auto;
    overflow: hidden;
}
.loading-progress {
    width: 0%;
    height: 100%;
    background: var(--gold);
    border-radius: 2px;
    animation: progress-fill 2s ease-out forwards;
    box-shadow: 0 0 10px var(--gold);
}
@keyframes pulse-text {
    from { opacity: 0.6; }
    to { opacity: 1; text-shadow: 0 0 10px var(--gold); }
}
@keyframes progress-fill {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 90%; } /* Leave 10% for JS to complete */
}

/* Scroll Container */
.container {
    height: 100vh;
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scroll-behavior: smooth;
    z-index: 10;
    position: relative;
}

.page {
    height: 100vh;
    width: 100%;
    scroll-snap-align: start;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at 50% 30%, rgba(138, 28, 28, 0.4) 0%, rgba(43, 8, 8, 0.9) 80%);
}

/* Texture Overlay */
.texture-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 1;
}

/* Decoration Elements */
.decoration {
    position: absolute;
    opacity: 0.6;
    pointer-events: none;
    z-index: 2;
}

/* Flower SVG Animation */
.flower {
    fill: none;
    stroke: var(--gold);
    stroke-width: 1;
    animation: bloom 3s infinite alternate;
}
@keyframes bloom {
    0% { stroke-dasharray: 0 100; opacity: 0.3; }
    100% { stroke-dasharray: 100 0; opacity: 0.8; }
}

/* Scattered Text Class (Core Visual) */
.text-piece {
    position: absolute;
    opacity: 0; /* Initially hidden */
    transform: translateY(20px) rotate(-2deg);
    transition: all 1s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-shadow: 0 2px 10px rgba(0,0,0,0.5);
    z-index: 5;
}

.page.active .text-piece {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
}

/* --- Page 1: Cover --- */
#p1 .t-main {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 4rem;
    top: 25%; left: 10%;
    color: #fff;
    /* Golden stroke effect */
    text-shadow: 
        -1px -1px 0 var(--gold),  
         1px -1px 0 var(--gold),
        -1px  1px 0 var(--gold),
         1px  1px 0 var(--gold),
         0 0 10px rgba(238, 187, 134, 0.5); /* Soft glow */
    padding: 20px; /* Space for border */
}

/* Animated Border for New Year Text */
#p1 .anim-border::before {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    border: 3px solid var(--gold);
    box-shadow: 0 0 20px rgba(238, 187, 134, 0.8), inset 0 0 20px rgba(238, 187, 134, 0.5);
    border-radius: 10px;
    animation: border-pulse 2s infinite alternate ease-in-out;
    pointer-events: none;
    z-index: -1;
}

@keyframes border-pulse {
    0% { transform: scale(1); opacity: 0.6; box-shadow: 0 0 10px rgba(238, 187, 134, 0.5); }
    100% { transform: scale(1.05); opacity: 1; box-shadow: 0 0 30px rgba(238, 187, 134, 0.9); }
}

#p1 .t-sub {
    font-size: 1.5rem;
    top: 45%; right: 15%;
    writing-mode: vertical-rl; /* Vertical writing mode */
}
#p1 .stamp {
    position: absolute;
    bottom: 15%; left: 50%;
    transform: translateX(-50%) scale(2);
    border: 2px solid var(--red-main);
    color: var(--red-main);
    background: rgba(255,255,255,0.9);
    padding: 5px 10px;
    font-family: 'Ma Shan Zheng';
    border-radius: 4px;
    box-shadow: 0 0 15px var(--red-main);
}

/* --- Page 2: Response to "Peanut" & Hand-drawing --- */
#p2 .p2-top-content {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    transition: transform 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

#p2.expanded .p2-top-content {
    transform: translateY(-20%);
}

#p2 .card-display {
    width: 280px; /* 增加宽度 */
    height: 180px; /* 减小高度，变为横版 */
    background: rgba(255,255,255,0.1);
    border: 2px dashed var(--gold);
    display: inline-block; /* Changed to inline-block for centering */
    margin-bottom: 20px;
    position: relative;
    transform: rotate(-5deg);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    /* 修复空隙和颜色 */
    color: var(--gold);
    box-sizing: border-box; 
    line-height: 180px; /* 垂直居中占位符文字 */
}

#p2 .card-display img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* 填满 */
    display: none; /* Hide if src is empty */
}

#p2 .card-placeholder-text {
    font-size: 0.8rem;
    color: var(--gold); /* 确保文字是金色 */
    text-align: center;
    padding: 0;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    line-height: 1.5;
}

#p2 .t-1 { 
    position: relative; 
    font-size: 1.4rem; 
    margin-bottom: 20px; 
    text-align: center;
}

#p2 .p2-bottom-content {
    position: absolute;
    bottom: 15%; /* 向上移动 (0 -> 5%) */
    left: 0; width: 100%; height: 50%;
    opacity: 0;
    transform: translateY(30px);
    transition: all 1.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 5;
    pointer-events: none; /* Prevent clicking when hidden */
}

#p2.expanded .p2-bottom-content {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#p2 .t-2 { 
    position: absolute; 
    bottom: 15%; 
    left: 10%; 
    width: 80%;
    font-size: 1.2rem; 
    color: var(--gold-light); 
    text-align: right; 
}

#p2 .icon-code {
    position: absolute;
    bottom: 35%; /* 向上移动 (25% -> 35%) */
    right: 10%;
    font-family: monospace;
    opacity: 0.3;
    font-size: 4rem;
    transform: rotate(15deg);
}

/* --- Page 3 & Thanks Page: Centered Text --- */
#p3 .t-center, #p-thanks .t-center {
    top: 35%; width: 100%; text-align: center;
    font-size: 2rem; font-family: 'Ma Shan Zheng';
    line-height: 1.8;
}

/* 针对 Thanks Page 第一段文字的特殊调整 */
#p-thanks .t-thanks-msg-1 {
    top: 20% !important; /* 向上移动 */
    font-size: 1.7rem !important; /* 字体再小一点 (1.5rem -> 1.2rem) */
}

/* Simulate twinkling star text */
.glowing-text {
    text-shadow: 0 0 10px var(--gold), 0 0 20px var(--red-main);
    animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
    from { text-shadow: 0 0 5px var(--gold); }
    to { text-shadow: 0 0 20px var(--gold), 0 0 30px var(--red-main); }
}

/* --- Page 4: Signature --- */
#p4 .t-end {
    top: 15%; left: 50%;
    transform: translateX(-50%);
    font-size: 1.5rem;
    text-align: center;
}
#p4 .photo-frame {
    position: absolute;
    top: 35%; left: 50%;
    transform: translateX(-50%);
    width: 150px; height: 150px;
    border-radius: 50%;
    border: 3px solid var(--gold);
    overflow: hidden;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 20px rgba(238, 187, 134, 0.3);
}
#p4 .photo-frame img {
    width: 100%; height: 100%; object-fit: cover;
}
#p4 .signature {
    position: absolute;
    top: 58%; left: 50%;
    transform: translateX(-50%);
    font-size: 1.2rem;
    color: var(--gold);
    font-family: 'Ma Shan Zheng';
    letter-spacing: 2px;
}
#p4 .code-box {
    position: absolute;
    bottom: 15%; width: 80%; left: 10%;
    background: rgba(0,0,0,0.6); /* Darker for better contrast */
    padding: 20px;
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: #f8f8f2;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

/* Music Button */
.music-btn {
    position: fixed;
    top: 20px; right: 20px;
    width: 30px; height: 30px;
    z-index: 100;
    animation: spin 6s linear infinite;
    cursor: pointer;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Arrow Down */
.arrow-down {
    position: absolute;
    bottom: 20px; left: 50%; transform: translateX(-50%);
    color: var(--gold); opacity: 0.5;
    animation: float 2s infinite;
    font-size: 1.5rem;
}
@keyframes float { 50% { transform: translate(-50%, -10px); } }

/* --- Candle Animation for Thanks Page --- */
#p-thanks .candle-wrapper {
    position: absolute;
    bottom: 15%; /* 向下移动一点 (从25% -> 15%) */
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    width: 100px; height: 150px;
    z-index: 1;
    opacity: 0;
    transition: opacity 1.5s ease-in;
}

#p-thanks.active .candle-wrapper {
    opacity: 1;
}

.candle {
    width: 34px;
    height: 100px;
    position: absolute;
    bottom: 0;
    left: 50%;
    margin-left: -17px;
    background: linear-gradient(to bottom, #eebb86 0%, #8a1c1c 100%);
    border-radius: 3px;
    box-shadow: inset 0 -10px 10px -5px rgba(0,0,0,0.4);
}

.wick {
    position: absolute;
    top: -10px;
    left: 50%;
    width: 2px;
    height: 10px;
    background: #333;
    margin-left: -1px;
}

.flame {
    width: 20px;
    height: 40px; /* Reduced height */
    margin: 0px auto;
    position: relative;
    top: -45px; /* Adjust top */
    left: 1px;
    animation: move 3s infinite, move-left 3s infinite;
    transform-origin: 50% 90%;
}

.flame .top {
    width: 20px;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    background: white;
    border-top-left-radius: 500%;
    border-top-right-radius: 500%;
    border-bottom-left-radius: 100px;
    border-bottom-right-radius: 100px;
    box-shadow: 
        0 0 15px rgba(255,255,255,0.5), /* Inner white glow */
        0 -10px 20px rgba(255, 200, 0, 0.4), /* Outer yellow glow */
        0 -20px 40px rgba(255, 100, 0, 0.3); /* Outer orange glow */
    z-index: 3;
    transform-origin: 50% 90%;
    animation: flicker 3s infinite ease-in-out;
}

.flame .shadows {
    position: absolute;
    left: 50%;
    top: 0;
    width: 0;
    height: 60px;
    border-radius: 50%;
    box-shadow: 
        0 5px 20px 15px rgba(255, 200, 0, 0.3),
        0 0px 50px 25px rgba(255, 100, 0, 0.2),
        0 -20px 80px 40px rgba(255, 0, 0, 0.1);
    transform: translateX(-50%);
    z-index: 1;
    animation: glow-pulse 3s infinite ease-in-out;
}

.flame .middle {
    width: 14px; /* Slightly narrower */
    height: 70%; /* Shorter */
    position: absolute;
    top: 20%;
    left: 3px;
    background: rgba(255, 200, 0, 0.6); /* More transparent */
    border-top-left-radius: 500%;
    border-top-right-radius: 500%;
    border-bottom-left-radius: 100px;
    border-bottom-right-radius: 100px;
    box-shadow: 0 0 15px 0 rgba(255, 200, 0, 0.4);
    z-index: 4;
}

.flame .bottom {
    width: 6px; /* Narrower */
    height: 25%; /* Shorter */
    position: absolute;
    bottom: 5%;
    left: 7px;
    background: rgba(0, 0, 255, 0.2); /* Very subtle blue base */
    border-radius: 50%;
    box-shadow: 0 0 8px 3px rgba(0, 0, 255, 0.2);
    z-index: 5;
    opacity: 0.7;
}

.glow-effect {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 
        0 0 40px 20px rgba(255, 200, 0, 0.2),
        0 0 80px 40px rgba(255, 100, 0, 0.1);
    animation: glow-pulse 3s infinite;
}

@keyframes move {
    0% { transform: skewX(2deg) skewY(5deg); }
    50% { transform: skewX(-2deg) skewY(0deg); }
    100% { transform: skewX(2deg) skewY(5deg); }
}

@keyframes move-left {
    50% { transform: skewX(3deg); }
}

@keyframes flicker {
    0% { transform: scale(1); opacity: 0.9; }
    25% { transform: scale(1.05); opacity: 1; }
    50% { transform: scale(0.95); opacity: 0.8; }
    75% { transform: scale(1.02); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; }
}

@keyframes glow-pulse {
    0% { opacity: 0.6; transform: translateX(-50%) scale(1); }
    50% { opacity: 0.9; transform: translateX(-50%) scale(1.1); }
    100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
}

/* Music Modal */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: none; /* JS will toggle this */
    justify-content: center;
    align-items: center;
    z-index: 200;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: rgba(43, 8, 8, 0.95);
    padding: 30px 40px;
    border: 2px solid var(--gold);
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 0 20px rgba(238, 187, 134, 0.3);
    animation: modalPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-content p {
    font-size: 1.5rem;
    color: var(--gold);
    margin-bottom: 25px;
    font-family: 'Ma Shan Zheng';
}

.modal-buttons button {
    padding: 8px 25px;
    margin: 0 10px;
    border: 1px solid var(--gold);
    background: transparent;
    color: var(--gold);
    font-size: 1.1rem;
    font-family: 'Long Cang';
    cursor: pointer;
    transition: all 0.3s;
    border-radius: 4px;
}

.modal-buttons button:hover, .modal-buttons button:active {
    background: var(--gold);
    color: var(--red-dark);
    box-shadow: 0 0 10px var(--gold);
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}