:root {
    --background-color: #f0f0f0;
    --shadow-color: rgba(0,0,0,0.2);
    --card-drop-shadow-color: rgba(0,0,0,0.4); 
    --text-color: #666;
    
    /* Updated button colors */
    --button-start-color: #e3d2cc; /* Your requested light brown/beige */
    --button-end-color: #d1bfb8;   /* Slightly darker shade for gradient */
    --button-text-color: #000000;  /* Black text as requested */
    --button-shadow-color: rgba(0,0,0,0.3);

    /* Define core content aspect ratio (3:2) */
    --content-aspect-ratio: 1.5; /* 3 / 2 */
    
    font-size: 16px; /* Base font size for rem units */
}

/* Responsive font sizing */
@media (max-width: 768px) {
    :root { font-size: 14px; }
}
@media (max-width: 480px) {
    :root { font-size: 11px; }
}

body {
    margin: 0;
    padding: 1.5rem; /* Consistent padding around the entire viewport */
    overflow: hidden; /* Prevent any scrollbars */
    display: flex;
    flex-direction: column; /* Stack container, instructions, button vertically */
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--background-color);
    font-family: 'Georgia', serif;
    perspective: 1000px; /* For 3D transformations */
    cursor: pointer;
    box-sizing: border-box; /* Include padding in element's total size */
}

.container {
    position: relative;
    width: 100%; /* Take full available width of parent (body's padded area) */
    max-width: 600px; /* Max width for desktop */
    aspect-ratio: var(--content-aspect-ratio); /* Maintain 3:2 aspect ratio */
    
    /* Ensure it scales down if height is limiting factor */
    max-height: calc(100vh - (2 * 1.5rem)); /* Max height is viewport height minus double body padding */
    max-height: min(calc(100vh - (2 * 1.5rem)), calc(600px / var(--content-aspect-ratio)));

    box-sizing: border-box;
    border-radius: 0.625rem;
    box-shadow: 0 0.625rem 1.25rem var(--shadow-color);
    transition: transform 0.8s ease-out, box-shadow 0.8s ease-out;
    margin-bottom: 1rem; /* Space below container for instructions/button */
}

/* Children elements fill the container */
.envelope,
.card {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.envelope {
    transition: transform 0.8s ease-out; 
    z-index: 10;
    display: flex; 
    justify-content: center;
    align-items: center;
    overflow: hidden; 
}

.envelope-graphic {
    width: 100%;
    height: 100%;
    object-fit: contain; 
    object-position: center;
}

/* Card Initial State */
.card {
    position: absolute;
    width: 80%; /* Card is 80% of envelope width */
    aspect-ratio: var(--content-aspect-ratio); /* Card maintains 3:2 aspect ratio */
    
    left: 50%;
    top: 50%; 
    transform: translate(-50%, -50%) translateY(50px) scale(0.8); 
    opacity: 0;
    transition: transform 1s ease-in-out, opacity 0.8s ease-in-out;
    z-index: 5;
    transform-style: preserve-3d; 
    display: flex; 
    justify-content: center;
    align-items: center;
}

.card img {
    position: absolute; 
    width: 150%;
    height: 110%;
    border-radius: 0.5rem; 
    backface-visibility: hidden; 
    object-fit: contain; 
    object-position: center; 
    filter: drop-shadow(0 0.3125rem 0.625rem var(--card-drop-shadow-color)); 
}

.card-front {
    transform: rotateY(0deg);
    z-index: 2;
}

.card-back {
    transform: rotateY(180deg); 
    z-index: 1;
}

/* Instruction Text - Global positioning */
.instruction-text {
    text-align: center;
    color: var(--text-color);
    font-size: 1.125rem; 
    transition: opacity 0.5s ease-in-out;
    margin: 0; /* Remove default paragraph margins */
    pointer-events: none; /* Make text non-clickable so clicks go through to body */
}

/* Ensure initial instruction is visible and flip instruction is hidden by default */
.instruction-text.initial-instruction {
    opacity: 1; 
}

.instruction-text.flip-instruction {
    opacity: 0;
}


/* Photo Button Container - Global positioning */
.photo-button-container {
    text-align: center;
    opacity: 0;
    transform: translateY(20px); /* Start slightly lower */
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
    pointer-events: none; /* Make it non-interactive when hidden */
    margin-top: 1rem; /* Space between card and button */
}

.photo-button {
    display: inline-block; 
    /* Gradient Background */
    background: linear-gradient(to bottom, var(--button-start-color), var(--button-end-color));
    color: var(--button-text-color);
    padding: 0.8em 1.5em; 
    border-radius: 0.4rem;
    text-decoration: none; 
    font-size: 1.1em; 
    font-weight: 600; /* Slightly heavier font weight */
    letter-spacing: 0.03em; /* Slight letter spacing for better readability */
    
    /* More refined shadow */
    box-shadow: 0 4px 10px var(--button-shadow-color);
    border: none; /* Remove default button border */
    cursor: pointer;
    margin-bottom: 0.5rem; 
    transition: background 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease; /* Smooth transitions */
}

.photo-button:hover {
    /* Adjusted hover colors to be a slightly darker shade of the requested color */
    background: linear-gradient(to bottom, #d1bfb8, #bba79f); 
    transform: translateY(-2px) scale(1.02); /* Lift and slightly enlarge */
    box-shadow: 0 6px 15px rgba(0,0,0,0.4); /* More pronounced shadow on hover */
}

.photo-password {
    color: var(--text-color);
    font-size: 0.9em; 
    margin-top: 0;
    margin-bottom: 0; 
}


/* --- State Management --- */

/* STATE 0: Envelope closed (initial) */
.container.card-initial .envelope {
    animation: pulse 2s infinite ease-in-out;
}

/* STATE 1: Envelope opened, card revealing */
.container.card-out .envelope {
    transform: translateY(-20px); 
}
.container.card-out .card {
    transform: translate(-50%, -50%) translateY(-100px) scale(1);
    opacity: 1;
    z-index: 15; 
}
.container.card-out .instruction-text.initial-instruction {
    opacity: 0; 
}
.container.card-out .instruction-text.flip-instruction {
    opacity: 1; 
}
/* Ensure button is hidden when card is just 'out' */
.container.card-out .photo-button-container {
    opacity: 0;
    pointer-events: none;
}


/* STATE 2: Card flipped to back */
.container.card-flipped .card {
    transform: translate(-50%, -50%) translateY(-100px) scale(1) rotateY(180deg);
}
.container.card-flipped .instruction-text.flip-instruction {
    opacity: 0; 
}
/* Show the photo button ONLY when the card is flipped */
.container.card-flipped .photo-button-container {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto; 
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}
