:root {
    --primary-pink: #ff9a9e;
    --secondary-pink: #fecfef;
    --glass-bg: rgba(255, 255, 255, 0.2);
    --glass-border: rgba(255, 255, 255, 0.5);
    --text-color: #333;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: "Microsoft YaHei", -apple-system, sans-serif;
    background-color: #000;
}

/* Global Click Layer for generic navigation */
#global-click-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999; /* Highest */
    display: none;
}

.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    visibility: hidden;
    transition: opacity 1s ease, visibility 1s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none; /* Allow clicks to pass unless active */
}

.scene.active {
    opacity: 1;
    visibility: visible;
    z-index: 20;
    pointer-events: auto;
}

.hidden {
    display: none !important;
}

/* --- Scene 1: Login --- */
#scene-login {
    /* Background is shared now */
    background: transparent;
}

/* Shared Liquid Background - Win10 Style Pink Flow */
.liquid-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0; /* Changed from 1 to 0 to ensure it's behind but visible */
    /* Stronger contrast for more visible flow */
    background: linear-gradient(125deg, #ff9a9e, #fecfef, #c471ed, #f64f59, #fad0c4);
    background-size: 300% 300%;
    animation: gradientBG 10s ease infinite;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Add subtle blur overlay for "liquid" feel */
.liquid-bg::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Change radial gradient to be more uniform or just remove the center spot */
    background-image: radial-gradient(circle at 50% 50%, rgba(255,255,255,0.1), transparent 90%);
    opacity: 0.4;
}

.glass-container {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 2rem;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    width: 80%;
    max-width: 350px;
    z-index: 30;
}

.character-img img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 1rem;
    border: 3px solid white;
}

.dialog-box {
    width: 100%;
    text-align: center;
}

.dialog-box p {
    margin-bottom: 10px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.dialog-box input {
    padding: 10px;
    border-radius: 5px;
    border: none;
    width: 100%;
    margin-bottom: 15px;
    outline: none;
    text-align: center;
}

.btn-container {
    display: flex;
    justify-content: center;
    width: 100%;
}

.dialog-box button {
    padding: 8px 30px;
    border-radius: 5px;
    border: none;
    background: #fff;
    color: var(--primary-pink);
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s;
}

.dialog-box button:active {
    transform: scale(0.95);
}

.error-msg {
    color: red;
    font-size: 0.8rem;
    margin-top: 5px;
    height: 20px;
    text-shadow: 0 0 2px rgba(255,255,255,0.5);
}

/* --- Scene 2: Welcome --- */
#scene-welcome {
    /* Use shared bg or override? */
    /* User said: "Pink gradient, flow background" - matches Scene 1 liquid bg.
       The Win10 style usually is blue-ish, but user asked for pink.
       So we can rely on the shared .liquid-bg */
    background: transparent;
}

.welcome-text {
    font-size: 1.5rem;
    color: white;
    position: absolute;
    opacity: 0; /* Start hidden */
    transition: opacity 1s ease;
    text-align: center;
    line-height: 1.5;
    width: 80%;
    text-shadow: 0 2px 5px rgba(0,0,0,0.2);
    display: none; /* Removed from flow */
}

.welcome-text.active-text {
    display: block;
    opacity: 1;
}

.welcome-text.fade-out {
    opacity: 0;
}

.welcome-text.clickable {
    cursor: pointer;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 0.7; transform: scale(1); }
}

/* --- Scene 3: Letter & Photo Wall --- */
/* Background is shared liquid-bg initially, photos appear on top */

.photo-wall-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    overflow: hidden;
    z-index: -1; /* Behind envelope */
    pointer-events: none;
    /* Removed solid background color to let liquid bg show through */
    /* background: #222; */ 
}

.wall-img {
    width: 80px;
    height: 100px; 
    object-fit: cover;
    border: 3px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    opacity: 0;
    transform: scale(0.5);
    /* Slowed down speed to 1/2 -> doubled duration */
    transition: opacity 1s ease, transform 1s ease; 
    margin: 2px;
}

.wall-img.show {
    opacity: 1;
    transform: scale(1) rotate(var(--rotation));
}

/* Envelope Structure */
.envelope-container {
    position: relative;
    width: 350px; /* Wider */
    height: 240px; /* Taller */
    perspective: 1000px;
    z-index: 30;
    transition: transform 1s;
}

.envelope-body {
    position: relative;
    width: 100%;
    height: 100%;
    background: #d74444; /* Red envelope */
    transform-style: preserve-3d;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* The flap */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50%;
    background: #c0392b; /* Darker red */
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    transform-origin: top;
    transition: transform 0.8s ease;
    z-index: 50; /* Initially on top */
}

.envelope-container.open .envelope-flap {
    transform: rotateX(180deg);
    z-index: 1; /* Goes behind after opening */
}

/* The pocket (front) */
.envelope-pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Front pocket shape */
    background: linear-gradient(to top left, #c0392b 50%, transparent 50%),
                linear-gradient(to top right, #c0392b 50%, transparent 50%);
    z-index: 40; /* Above letter initially */
    pointer-events: none;
}

/* The letter */
.letter-paper {
    position: absolute;
    width: 90%;
    height: 90%;
    background: #fff;
    padding: 5px;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    /* Start inside */
    bottom: 5px;
    z-index: 10; 
    /* Changed transition: removed transform/width/height transitions to allow instant swap or handle via keyframes if needed, 
       but for now let's keep transform. We need to animate width/height/left too if we change them. */
    transition: all 1.5s ease; 
    transform: translateY(0);
    overflow: hidden;
}

.envelope-container.letter-out .letter-paper {
    /* 
       Fix: Center on screen with A4 Aspect Ratio (Portrait)
       Scale: Fits within 85% of viewport width/height, maintaining A4 shape.
       This ensures text is as large as possible without distorting ratio or blocking full bg.
    */
    position: fixed;
    top: 50%;
    left: 50%;
    bottom: auto;
    right: auto;
    
    /* A4 Ratio: 210mm / 297mm = ~0.707 */
    /* Set max dimensions */
    width: 85vw; 
    max-width: 500px; /* Cap for desktop */
    
    /* Force A4 aspect ratio */
    aspect-ratio: 210 / 297;
    
    /* Constraint height to viewport too, allowing width to shrink if needed to keep ratio */
    max-height: 85vh;
    height: auto; 
    
    transform: translate(-50%, -50%);
    
    z-index: 999;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    border-radius: 2px;
}

.letter-content {
    width: 100%;
    height: 100%;
    overflow-y: auto; /* Allow scrolling for text */
    position: relative;
    font-family: 'Ma Shan Zheng', 'KaiTi', serif; /* Handwritten style for letter */
    color: #333;
    padding: 20px; /* Inner padding */
    background: url('https://www.transparenttextures.com/patterns/paper-fibers.png'); /* Optional texture */
}

.letter-text-container p {
    margin-bottom: 10px;
    line-height: 1.6;
    font-size: 1rem; /* Base size, adjustable */
}

.letter-footer {
    margin-top: 30px;
    text-align: right;
    font-weight: bold;
}

/* Mobile optimization */
@media (max-width: 480px) {
    .letter-text-container p {
        font-size: 0.9rem;
    }
}

.continue-hint {
    position: absolute;
    bottom: 30px;
    right: 30px;
    color: #fff;
    font-weight: bold;
    font-size: 1.2rem;
    text-shadow: 0 0 10px #ff007f;
    animation: pulse 1.5s infinite;
    cursor: pointer;
    z-index: 100;
}

/* --- Scene 4: Gift --- */
#scene-gift {
    background: transparent; /* Shows Photo Wall behind */
}

.gift-box-container {
    position: relative;
    width: 150px;
    height: 150px;
    cursor: pointer;
    z-index: 50;
}

.gift-body {
    width: 100%;
    height: 100%;
    background: #e74c3c;
    position: absolute;
    bottom: 0;
    border-radius: 5px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
    z-index: 10;
}

.gift-body::before {
    content: '';
    position: absolute;
    width: 20%;
    height: 100%;
    background: #f1c40f;
    left: 40%;
}

.gift-lid {
    width: 110%;
    height: 25%;
    background: #c0392b;
    position: absolute;
    top: 0;
    left: -5%;
    border-radius: 5px;
    transition: transform 0.8s ease, opacity 0.5s;
    z-index: 20;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.gift-lid::before {
    content: '';
    position: absolute;
    width: 20%;
    height: 100%;
    background: #f1c40f;
    left: 40%;
}

/* Open State */
.gift-box-container.open .gift-lid {
    transform: translateY(-60px) rotate(-30deg);
    opacity: 0;
}

.gift-item {
    position: absolute;
    width: 100px;
    left: 25px; /* Center in 150px box */
    bottom: 0;
    z-index: 5; /* Inside box initially */
    opacity: 0;
    transition: transform 2s ease, opacity 1s ease;
}

.gift-box-container.open .gift-item {
    opacity: 1;
    transform: translateY(-120px); /* Float up */
    /* Keep z-index lower than gift-body (10) so it looks like it comes from inside */
    z-index: 5; 
}

.gift-text {
    margin-top: 150px; /* Clear the box */
    background: rgba(255,255,255,0.8);
    padding: 15px;
    border-radius: 10px;
    animation: floatUp 1s forwards;
    z-index: 60;
}

@keyframes floatUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.equip-msg {
    color: #e67e22;
    font-weight: bold;
    text-align: center;
}

/* --- Scene 5: Cake --- */
#scene-cake {
    background: #000;
    color: #fff;
}

.cake-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    opacity: 0;
    transition: opacity 2s;
}

.cake-container.visible {
    opacity: 1;
}

.cake-gif {
    width: 250px;
    height: auto;
    margin-bottom: 20px;
}

.cake-hint {
    font-size: 1.2rem;
    color: #ccc;
    animation: pulse 2s infinite;
}

/* --- Scene 6: Final --- */
#scene-final {
    justify-content: flex-start;
    padding-top: 15vh;
}

.photo-wall-dimmed {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6); /* Uniform dimming */
    z-index: -1;
}

.final-text-container {
    width: 85%;
    text-align: center;
    color: #fff;
    z-index: 10;
}

.final-line {
    opacity: 0;
    transform: translateY(-20px);
    transition: all 1s ease;
    margin-bottom: 12px;
    font-size: 1.1rem;
    line-height: 1.6;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.final-line.show {
    opacity: 1;
    transform: translateY(0);
}

.signature {
    font-family: 'Ma Shan Zheng', 'KaiTi', 'SimKai', cursive, serif; /* Fallbacks */
    font-size: 2.5rem;
    color: #fff;
    margin-top: 30px;
    align-self: flex-end;
    margin-right: 40px;
    opacity: 0;
    transition: opacity 2s;
    transform: rotate(-5deg);
}

.signature.show {
    opacity: 1;
}

#confetti-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}
