:root {
    --bg-color: #f5f5dc;
    /* Beige */
    --envelope-color: #e6dac3;
    --paper-color: #f0e6d2;
    /* Darker, more vintage paper color */
    --text-color: #3e2723;
    /* Dark brown for better contrast */
    --accent-color: #d4af37;
    /* Gold-ish */
    --font-handwriting: 'Reenie Beanie', cursive;
    /* More natural, messy handwriting */
    --font-serif: 'Playfair Display', serif;
}

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

body {
    font-family: var(--font-serif);
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('assets/bougainvillea_bg.png');
    background-size: cover;
    background-position: center;
    opacity: 0.3;
    z-index: -1;
    pointer-events: none;
}

.experience-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    min-height: 100vh;
    height: 100vh;
    /* Enforce viewport height initially */
    overflow: hidden;
    /* Prevent scrolling initially */
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

/* Password Protection Overlay */
.password-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(245, 245, 220, 0.98) 0%, rgba(230, 218, 195, 0.98) 100%);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.8s ease, visibility 0.8s ease;
}

.password-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.password-container {
    background: rgba(255, 255, 255, 0.9);
    padding: 50px 40px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-width: 450px;
    width: 90%;
    text-align: center;
    border: 2px solid rgba(212, 175, 55, 0.3);
}

.password-title {
    font-family: var(--font-serif);
    font-size: 2.5rem;
    color: var(--text-color);
    margin-bottom: 15px;
    font-weight: 700;
    letter-spacing: 1px;
}

.password-subtitle {
    font-family: var(--font-handwriting);
    font-size: 1.5rem;
    color: #795548;
    margin-bottom: 30px;
    opacity: 0.9;
}

.password-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 15px;
}

.password-input {
    padding: 15px 20px;
    font-size: 1.1rem;
    border: 2px solid rgba(212, 175, 55, 0.4);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.8);
    color: var(--text-color);
    font-family: var(--font-serif);
    transition: all 0.3s ease;
    outline: none;
}

.password-input:focus {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.1);
}

.password-input::placeholder {
    color: rgba(62, 39, 35, 0.5);
    font-style: italic;
}

.password-submit {
    padding: 15px 30px;
    font-size: 1.2rem;
    font-family: var(--font-serif);
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, #d4af37 0%, #c9a227 100%);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
    letter-spacing: 1px;
}

.password-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.4);
    background: linear-gradient(135deg, #e0bb3d 0%, #d4af37 100%);
}

.password-submit:active {
    transform: translateY(0);
}

.password-error {
    color: #c62828;
    font-family: var(--font-serif);
    font-size: 0.95rem;
    min-height: 20px;
    margin-top: 5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.password-error.show {
    opacity: 1;
}


/* Envelope Styles */
.envelope-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 350px;
    /* Mobile first size */
    height: 250px;
    z-index: 10;
    transition: transform 1s ease, opacity 1s ease;
    cursor: pointer;
}

.envelope-body {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: url('assets/envelope_texture.png');
    background-size: cover;
    background-color: var(--envelope-color);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transform-style: preserve-3d;
}

.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 175px solid transparent;
    border-right: 175px solid transparent;
    border-top: 140px solid #dccbb1;
    /* Slightly darker for flap */
    transform-origin: top;
    z-index: 5;
    transition: transform 0.8s ease 0.5s;
    /* Delay opening */
}

.envelope-container.open .envelope-flap {
    transform: rotateX(180deg);
    z-index: 1;
}

.wax-seal {
    position: absolute;
    top: 90px;
    /* Position over the flap tip */
    z-index: 6;
    width: 80px;
    height: 80px;
    transition: transform 0.3s ease, opacity 0.5s ease;
    cursor: pointer;
}

.wax-seal img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.3));
}

.wax-seal:hover {
    transform: scale(1.1);
}

.envelope-container.open .wax-seal {
    opacity: 0;
    pointer-events: none;
}

.envelope-details {
    width: 100%;
    height: 100%;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-family: var(--font-handwriting);
    font-size: 1.2rem;
    color: #5d4037;
    z-index: 4;
    /* Below flap */
}

.recipient-info {
    align-self: center;
    text-align: center;
    margin-top: 40px;
}

.sender-info {
    align-self: flex-start;
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Letter Styles */
.letter-container {
    position: relative;
    width: 90%;
    max-width: 600px;
    margin: 50px auto;
    opacity: 0;
    transform: translateY(50px) scale(0.9);
    transition: opacity 1s ease 1s, transform 1s ease 1s;
    /* Delay appearance */
    z-index: 5;
}

.letter-container.hidden {
    display: none;
}

.letter-container.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.letter-paper {
    background-color: #f4e4bc;
    /* Warm beige */
    padding: 40px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    min-height: 80vh;
    border: 1px solid #e6d2a0;
    /* Subtle border for definition */
}

.letter-content {
    font-family: var(--font-handwriting);
    font-size: 1.8rem;
    /* Increased size for readability with this font */
    line-height: 1.6;
    color: #3e2723;
}

.letter-content p {
    margin-bottom: 1.5rem;
    line-height: 1.8;
    color: #2c1810;
}

.letter-image {
    display: block;
    max-width: 90%;
    height: auto;
    margin: 1.5rem auto;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border: 8px solid white;
    transform: rotate(-2deg);
    transition: transform 0.3s ease;
}

.letter-image:nth-of-type(even) {
    transform: rotate(2deg);
}

.letter-image:hover {
    transform: scale(1.02) rotate(0deg);
    z-index: 10;
}

.date {
    text-align: right;
    margin-bottom: 30px;
    font-family: var(--font-serif);
    font-size: 1rem;
    color: #795548;
}

.salutation {
    font-size: 1.8rem;
    font-weight: bold;
}

.closing,
.signature {
    text-align: right;
    margin-top: 40px;
}

.signature {
    font-size: 2rem;
    font-weight: bold;
}

/* Photo Placeholders */
.photo-placeholder {
    margin: 30px 0;
    padding: 10px;
    background: #fff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    transform: rotate(-2deg);
    transition: transform 0.3s ease;
    opacity: 0;
    /* Initially hidden for scroll animation */
    transform: translateY(20px) rotate(-2deg);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.photo-placeholder:nth-of-type(even) {
    transform: rotate(2deg);
    transform: translateY(20px) rotate(2deg);
}

.photo-placeholder.show {
    opacity: 1;
    transform: translateY(0) rotate(-2deg);
}

.photo-placeholder:nth-of-type(even).show {
    transform: translateY(0) rotate(2deg);
}

.placeholder-inner {
    width: 100%;
    height: 250px;
    background-color: #eee;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #888;
    font-family: var(--font-serif);
    border: 1px dashed #ccc;
}

.caption {
    text-align: center;
    margin-top: 10px;
    font-family: var(--font-handwriting);
    font-size: 1.2rem;
    color: #555;
}

/* Shake Animation for Password Error */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-10px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(10px);
    }
}

/* Responsive */
@media (min-width: 768px) {
    .envelope-container {
        width: 500px;
        height: 350px;
    }

    .envelope-flap {
        border-left-width: 250px;
        border-right-width: 250px;
        border-top-width: 200px;
    }

    .wax-seal {
        top: 140px;
    }
}