:root {
    --bg: #FFF0F5; /* Lavender Blush */
    --accent: #E6A8D7; /* Soft Pink */
    --accent-dark: #ff5fdc; 
    --paper: #FEFEFA; /* Snow */
    --text: #5D4E60;
    --heart: #FF6666;
    --envelope-color: #FFB7B2;
    --envelope-flap: #FF9E99;
    --envelope-shadow: rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden; /* Prevent scrolling during puzzle */
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* UTILS */
.hidden {
    display: none !important;
}

/* LANDING & ENVELOPE */
#landing {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s;
}

.envelope-container {
    position: relative;
    cursor: pointer;
    animation: bounceIn 2s ease-out;
}

.envelope {
    width: 300px;
    height: 200px;
    background-color: var(--envelope-color);
    position: relative;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 10px 20px var(--envelope-shadow);
    z-index: 1;
}

.flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 150px solid transparent;
    border-right: 150px solid transparent;
    border-top: 110px solid var(--envelope-flap);
    transform-origin: top;
    transition: transform 0.6s ease-in-out;
    z-index: 3;
}

.pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 150px solid var(--envelope-color);
    border-right: 150px solid var(--envelope-color);
    border-bottom: 100px solid transparent; /* This creates the pocket look via stacking */
    /* Cheat: visually simple pocket */
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    z-index: 2;
    /* Redo pocket with clip-path or simple overlay */
    background: conic-gradient(from 180deg at 50% 100%, var(--envelope-color) 0deg, var(--envelope-flap) 180deg);
    /* Simple CSS triangle approach often better */
}

/* Better envelope structure for animation */
.envelope {
    overflow: hidden; /* hides letter initially if deep */
    overflow: visible;
}
.pocket {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 0; 
    height: 0; 
    border-left: 150px solid transparent;
    border-right: 150px solid transparent;
    border-bottom: 100px solid #FFCac5; /* Slightly lighter for contrast */
    z-index: 2;
}

.letter {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    height: 90%;
    background: var(--paper);
    transition: bottom 0.5s ease-out, transform 0.5s ease-out;
    z-index: 1; /* Inside pocket */
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 5px 5px 0 0;
    padding: 20px;
}

.letter p {
    font-family: 'Dancing Script', cursive;
    font-size: 1.5rem;
}

.heart-seal {
    position: absolute;
    top: 50%; /* Adjusted by flap height */
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    z-index: 4;
    transition: opacity 0.3s;
    top: 100px; /* approximates flap tip */
}

.click-hint {
    margin-top: 50px;
    font-size: 0.9rem;
    opacity: 0.7;
    animation: pulse 1.5s infinite;
}

/* OPEN STATE */
.envelope-container.open .flap {
    transform: rotateX(180deg);
    z-index: 0;
}

.envelope-container.open .letter {
    bottom: 120px; /* Slide up */
    transform: translateX(-50%) scale(1.1);
    z-index: 5;
    transition-delay: 0.4s;
}

.envelope-container.open .heart-seal {
    opacity: 0;
}

/* PUZZLE SECTION */
#puzzle-section {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    animation: fadeIn 1s;
}

#puzzle-section header {
    margin-bottom: 20px;
}

h1 {
    font-family: 'Dancing Script', cursive;
    color: var(--accent-dark);
    margin-bottom: 5px;
}

.game-area {
    width: 100%;
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden; /* Contain pieces */
}

#puzzle-container {
    /* Dimensions set by JS */
    position: relative;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    background: rgba(255,255,255,0.5);
    border: 2px dashed var(--accent);
}

.puzzle-piece {
    position: absolute;
    cursor: grab;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
    transition: transform 0.1s, box-shadow 0.1s;
    /* touch-action: none; IMPORTANT for drag */
    touch-action: none;
    z-index: 10;
}

.puzzle-piece.dragging {
    cursor: grabbing;
    z-index: 100;
    transform: scale(1.05);
    box-shadow: 5px 10px 15px rgba(0,0,0,0.3);
}

.puzzle-piece.snapped {
    z-index: 1;
    pointer-events: none; /* Lock it */
    box-shadow: none;
    border: none;
    transition: top 0.3s, left 0.3s;
}

/* WIN SCREEN */
#win-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    animation: fadeIn 1s;
    z-index: 200;
}

.win-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.full-image-container {
    margin-bottom: 20px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    /* border: 5px solid white; */
    border-radius: 5px;
    line-height: 0;
}

#full-image {
    max-width: 100%;
    max-height: 40vh;
    display: block;
    border-radius: 5px;
}

.poem-card {
    background: var(--paper);
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    max-width: 500px;
    transform: translateY(50px);
    opacity: 0;
    animation: slideUp 1s forwards 0.5s;
    position: relative;
    border: 1px solid #eee;
}

.poem-card h2 {
    font-family: 'Dancing Script', cursive;
    color: var(--heart);
    margin-bottom: 15px;
}

.poem-text p {
    margin-bottom: 10px;
    line-height: 1.6;
    font-size: 1.1rem;
}

.signature {
    margin-top: 20px;
    font-style: italic;
    color: var(--accent-dark);
}

/* ANIMATIONS */
@keyframes bounceIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* REFERENCE IMAGE */
#reference-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 100px;
    background: white;
    padding: 5px;
    border-radius: 5px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 150;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text);
    /* Pop in animation defaults */
    transform: scale(0);
    opacity: 0;
}

#reference-container.visible {
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    60% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

#reference-container:hover {
    transform: scale(1.05) !important; /* Override animation fill */
}

#reference-container img {
    width: 100%;
    display: block;
    border-radius: 3px;
    margin-top: 5px;
}

/* MODAL */
#reference-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
    animation: fadeIn 0.3s;
}

#reference-modal .modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    text-align: center;
}

#reference-modal h2 {
    color: white;
    margin-bottom: 15px;
    font-family: 'Dancing Script', cursive;
    font-size: 2rem;
    text-shadow: 0 2px 5px rgba(0,0,0,0.5);
}

#reference-modal img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 5px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.close-modal {
    position: absolute;
    top: -40px;
    right: 0;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    font-weight: bold;
}

/* --- EXTENDED FLOW STYLES --- */

/* 1. GIFT REVEAL */
#gift-reveal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 200;
    animation: fadeIn 1s;
}

.framed-image {
    background: white;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    border: 1px solid #ddd;
    transform: rotate(-2deg);
    max-width: 80%;
    max-height: 60vh;
}

.framed-image img {
    max-width: 100%;
    max-height: 50vh;
    display: block;
}

/* 2. MESSAGES */
#message-sequence {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    text-align: center;
    padding: 20px;
}

.msg-container h1 {
    font-size: 3rem;
    color: var(--accent-dark);
}

.msg-container p {
    font-size: 1.5rem;
    margin-top: 20px;
    color: var(--text);
}

/* 3. LETTERS */
#letters-sequence {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.letters-container {
    display: flex;
    gap: 30px;
    margin-top: 50px;
    flex-wrap: wrap;
    justify-content: center;
}

.letter-icon {
    width: 80px;
    height: 60px;
    background: var(--paper);
    border: 2px solid var(--accent);
    position: relative;
    cursor: pointer;
    transition: transform 0.3s;
    box-shadow: 0 5px 10px rgba(0,0,0,0.1);
}

.letter-icon::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    border-left: 40px solid transparent;
    border-right: 40px solid transparent;
    border-top: 30px solid var(--accent-dark);
    opacity: 0.5;
}

.letter-icon:hover {
    transform: translateY(-10px) rotate(5deg);
}

/* POEM MODAL */
#poem-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
}

.paper-modal-content {
    background: var(--paper);
    padding: 40px;
    width: 90%;
    max-width: 500px;
    min-height: 300px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    position: relative;
    font-family: 'Dancing Script', cursive;
    font-size: 1.5rem;
    line-height: 1.6;
    background-image: linear-gradient(var(--paper) 95%, #eee 96%);
    background-size: 100% 30px; /* ruled lines effect */
}

.close-poem {
    position: absolute;
    top: 10px;
    right: 20px;
    font-size: 2rem;
    cursor: pointer;
    color: #aaa;
    font-family: sans-serif;
}

/* 4. PROPOSAL */
#proposal-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    text-align: center;
}

.buttons {
    margin-top: 50px;
    display: flex;
    gap: 30px;
}

button {
    padding: 15px 40px;
    font-size: 1.2rem;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    transition: transform 0.2s;
}

#btn-yes {
    background-color: var(--heart);
    color: white;
    font-weight: bold;
    box-shadow: 0 5px 15px rgba(255, 102, 102, 0.4);
}

#btn-yes:hover {
    transform: scale(1.1);
}

#btn-no {
    background-color: #ddd;
    color: #555;
}

/* 5. CREDITS */
#credits-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    color: white;
    z-index: 400;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.credits-wrapper {
    height: 100%;
    overflow: hidden;
    position: relative;
    width: 100%;
}

.credits-content {
    position: absolute;
    width: 100%;
    text-align: center;
    animation: scrollCredits 20s linear infinite;
}

@keyframes scrollCredits {
    0% { top: 100%; }
    100% { top: -200%; } /* Adjust depending on content length */
}

.credits-content h1 {
    font-size: 3rem;
    margin-bottom: 50px;
    color: var(--heart);
}

.credits-content p {
    font-size: 1.5rem;
    margin-bottom: 30px;
}

/* TOAST */
#toast-message {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 15px 25px;
    border-radius: 50px;
    z-index: 500;
    animation: slideInToast 0.5s ease-out;
}

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