/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: #eaeaea; /* Light grey background */
    font-family: 'Montserrat', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Prevent body double scroll when modal is open */
    padding: 20px;
    transition: background-color 0.8s ease;
}

.app-container {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
}

/* Background Branches Animation Container */
.bg-branches-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0; /* Placed completely in the background */
    overflow: hidden;
}

.bg-branch {
    position: absolute;
    background-image: url('includes/ramo.png');
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
    pointer-events: none;
    animation: float-fade-branch 12s forwards ease-in-out;
}

@keyframes float-fade-branch {
    0% {
        opacity: 0;
        transform: scale(0.8) rotate(var(--rot-start));
    }
    35%, 50% {
        opacity: var(--max-op);
        transform: scale(1) rotate(var(--rot-mid));
    }
    100% {
        opacity: 0;
        transform: scale(0.8) rotate(var(--rot-end));
    }
}

/* Instruction Text */
.instruction {
    font-family: 'Pinyon Script', cursive;
    font-size: 2.1rem;
    color: #6c7566;
    text-align: center;
    margin-top: 20px;
    letter-spacing: 0.5px;
    opacity: 0.75;
    animation: pulse-light-discrete 2.5s infinite ease-in-out;
    transition: opacity 0.5s ease;
    z-index: 10;
    font-weight: normal;
}

@keyframes pulse-light-discrete {
    0%, 100% { opacity: 0.5; transform: scale(0.99); }
    50% { opacity: 0.85; transform: scale(1.01); }
}

/* Envelope Container */
.envelope-wrapper {
    position: relative;
    width: 100%;
    height: 400px;
    perspective: 1500px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.envelope {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 520px;
    height: 350px;
    background-color: #4b5b3f; /* Olive Green Base */
    border-radius: 0 0 12px 12px;
    box-shadow: 
        0 15px 35px rgba(0,0,0,0.18),
        0 5px 15px rgba(0,0,0,0.08);
    z-index: 5;
    transition: transform 1s cubic-bezier(0.19, 1, 0.22, 1), opacity 1s ease;
}

/* Envelope Flap (Abraço) */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 175px;
    background-color: #586b4b; /* Slightly lighter olive green */
    clip-path: polygon(0 0, 50% 100%, 100% 0);
    transform-origin: top;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 8;
}

/* Envelope Pocket */
.envelope-pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 210px;
    background-color: #4b5b3f;
    clip-path: polygon(0 100%, 0 0, 50% 50%, 100% 0, 100% 100%);
    border-radius: 0 0 12px 12px;
    z-index: 7;
}

.envelope-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #3e4c34;
    border-radius: 0 0 12px 12px;
    z-index: 1;
}

/* Wax Seal */
.wax-seal {
    position: absolute;
    top: 170px;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 108px;
    height: 108px;
    background: radial-gradient(circle at 35% 35%, #b63725 0%, #8c2417 65%, #62170f 100%);
    border-radius: 50% 48% 52% 49% / 48% 51% 49% 52%;
    box-shadow: 
        0 8px 20px rgba(0,0,0,0.38),
        inset 0 3px 6px rgba(255,255,255,0.2),
        inset 0 -5px 10px rgba(0,0,0,0.55),
        0 0 0 5px rgba(140, 36, 23, 0.2);
    cursor: pointer;
    z-index: 9;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
}

.wax-seal:hover {
    transform: translate(-50%, -50%) scale(1.08) rotate(3deg);
}

.wax-seal-inner {
    width: 82px;
    height: 82px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.12);
    background: radial-gradient(circle, #ab3121 0%, #841e12 100%);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.seal-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    filter: brightness(0) invert(1) opacity(0.95);
    transform: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.5));
}

/* Seal Falling Animation */
.wax-seal.fall {
    animation: seal-drop 1.2s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
}

@keyframes seal-drop {
    0% {
        transform: translate(-50%, -50%) rotate(0deg);
        opacity: 1;
    }
    40% {
        transform: translate(-50%, 150px) rotate(45deg);
        opacity: 0.9;
    }
    100% {
        transform: translate(-50%, 450px) rotate(180deg);
        opacity: 0;
    }
}

/* State 1: Flap Opens */
.envelope-wrapper.open-flap .envelope-flap {
    transform: rotateX(180deg);
    z-index: 2;
}

/* Scrollable fixed modal container (Robust flex configuration for mobile scroll) */
.invitation-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Aligns to top if item overflows, preventing clipping */
    padding: 30px 15px;
    z-index: 12;
    pointer-events: none;
    -webkit-overflow-scrolling: touch; /* High performance mobile momentum scrolling */
}

/* Invitation Card */
.invitation-card {
    position: relative; /* Flow inside the modal */
    width: 100%;
    max-width: 440px;
    height: auto;
    background-color: #fdfaf2; /* Palha (Parchment/Straw) color */
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.18);
    opacity: 0;
    transform: translateY(120px) scale(0.94);
    transition: 
        transform 1.2s cubic-bezier(0.19, 1, 0.22, 1),
        opacity 0.9s ease;
    pointer-events: none;
    overflow: hidden;
    padding: 24px;
    margin: auto; /* Vertically and horizontally centers when item is smaller than screen */
}

/* Paper texture simulation */
.paper-texture {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.04;
    background-image: radial-gradient(#000 10%, transparent 10%), radial-gradient(#000 10%, transparent 10%);
    background-size: 6px 6px;
    background-position: 0 0, 3px 3px;
}

/* Global Trigger Class: Show Invitation */
body.show-invitation .invitation-modal {
    pointer-events: auto;
}

body.show-invitation .invitation-card {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Keep open envelope visible as a background element */
body.show-invitation .envelope {
    opacity: 0.22;
    transform: translate(-50%, 60px) scale(0.92);
    pointer-events: none;
}

body.show-invitation {
    background-color: #f4f4f4;
}

/* Card Content Styling */
.card-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 2;
}

.invitation-image-container {
    width: 100%;
    margin-bottom: 25px;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.06);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.invitation-image {
    width: 100%;
    height: auto;
    display: block;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    margin-bottom: 35px;
}

.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    padding: 14px 20px;
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.3s ease;
    text-align: center;
}

.btn-action {
    background-color: #4b5b3f;
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(75, 91, 63, 0.2);
}

.btn-action:hover {
    background-color: #5a6e4c;
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(75, 91, 63, 0.3);
}

/* Music Controls Footer (No Title, Circular Icon-Only Buttons) */
.music-controls {
    width: 100%;
    border-top: 1px solid rgba(75, 91, 63, 0.15);
    padding-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.music-buttons {
    display: flex;
    justify-content: center;
    gap: 16px;
    width: 100%;
}

.btn-music {
    background: none;
    border: 1px solid rgba(75, 91, 63, 0.45);
    color: #4b5b3f;
    width: 44px; /* Fixed square dimensions for circle */
    height: 44px;
    border-radius: 50%; /* Perfect circle */
    cursor: pointer;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-music:hover {
    background-color: rgba(75, 91, 63, 0.08);
    border-color: #4b5b3f;
    transform: scale(1.08);
}

.btn-music .icon {
    width: 20px; /* Slightly larger icon */
    height: 20px;
    fill: currentColor;
}

.hidden {
    display: none;
}

/* Responsiveness adjustments */
@media (max-width: 540px) {
    .envelope {
        width: 95%;
        max-width: none;
        height: 290px;
    }
    
    .envelope-flap {
        height: 145px;
    }
    
    .envelope-pocket {
        height: 175px;
    }
    
    .wax-seal {
        top: 135px;
        width: 95px;
        height: 95px;
    }
    
    .wax-seal-inner {
        width: 72px;
        height: 72px;
    }
    
    .seal-logo {
        width: 60px;
        height: 60px;
    }
    
    body.show-invitation .envelope {
        transform: translate(-50%, 30px) scale(0.92);
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .app-container {
        padding: 20px 0;
    }

    .envelope-wrapper {
        height: 350px;
    }

    .invitation-modal {
        padding: 20px 10px;
        align-items: flex-start;
    }
    
    .invitation-card {
        padding: 18px;
        width: 96%;
    }
    
    .instruction {
        font-size: 1.8rem;
        margin-top: 20px;
    }
}
