/* Global Styles */
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;500;600;700&family=Marck+Script&family=Montserrat+Armenian:ital,wght@0,400;0,700;0,900;1,400&family=Noto+Serif+Armenian:wght@300;400;700&display=swap');

/* Armenian Handwriting Fonts */
@font-face {
    font-family: 'Tumanian Handwriting';
    src: url('https://db.onlinewebfonts.com/t/18e478546132485e94dfda9434850c95.woff2') format('woff2');
}

@font-face {
    font-family: 'ArTarumianBarak';
    src: url('https://db.onlinewebfonts.com/t/c8d80909779e0a3fed803def0a3d73ea.woff2') format('woff2');
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow-x: hidden;
    /* Prevent horizontal scroll at root */
}

body {
    overflow-x: hidden;
    font-family: 'Montserrat Armenian', sans-serif;
}

.bg-fixed {
    position: fixed;
    top: -5%;
    left: -5%;
    width: 110%;
    height: 110%;
    background-image: url('../assets/background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: -1;
    pointer-events: none;
}

* {
    box-sizing: border-box;
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 20px;
}

/* Language Switcher */
.lang-switcher-container {
    width: 800px;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    z-index: 110;
}

.lang-switcher {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 8px 16px;
    border-radius: 30px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 10px;
}

@media (max-width: 820px) {
    .lang-switcher-container {
        width: 100%;
        max-width: 800px;
        transform: scale(0.85);
        margin-bottom: 10px;
    }
}

@media (max-width: 600px) and (orientation: portrait) {
    .lang-switcher-container {
        position: absolute;
        top: 20px;
        left: 20px;
        width: auto;
        transform: none;
        margin-bottom: 0;
    }
}

.lang-btn {
    border: none;
    background: none;
    color: #888;
    font-weight: 400;
    cursor: pointer;
    font-size: 0.9rem;
}

.lang-btn.active {
    color: #1a3c8e;
    font-weight: 800;
}

/* Envelope Container */
.envelope-wrapper {
    position: relative;
    width: 1200px;
    /* High-res native width */
    height: 780px;
    /* High-res native height */
    perspective: 2500px;
    /* Enhanced depth for large scale */
    z-index: 50;
    /* Responsive Scaling */
    transform-origin: center center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    /* Smooth orientation transition */
}

/* --- RECALIBRATED RESPONSIVE TIERS for 1200px BASE --- */

/* Tablet / Standard Mobile Landscape */
@media (max-width: 820px) {
    .envelope-wrapper {
        transform: scale(0.65);
        /* Fits 1200px base into tablet width */
    }
}

/* Mobile Portrait - Vertical (tall) */
@media (max-width: 600px) and (orientation: portrait) {
    .app-container {
        padding: 0;
        justify-content: center;
        overflow: hidden;
    }

    .envelope-wrapper {
        transform: rotate(90deg) scale(0.31);
        /* Mathematical fit for 375px-390px screens */
        max-width: none;
        max-height: none;
    }
}

/* Larger Phones (Pro Max, Plus) Portrait */
@media (max-width: 600px) and (min-width: 400px) and (orientation: portrait) {
    .envelope-wrapper {
        transform: rotate(90deg) scale(0.34);
    }
}

/* Small Mobile Portrait */
@media (max-width: 380px) and (orientation: portrait) {
    .envelope-wrapper {
        transform: rotate(90deg) scale(0.30);
    }
}

/* Universal Landscape Optimizations */
@media (orientation: landscape) {
    .app-container {
        padding: 0;
        height: 100vh;
        min-height: -webkit-fill-available;
        overflow: hidden;
        position: relative;
        display: block;
    }

    .lang-switcher-container {
        position: absolute;
        top: 25px;
        left: 25px;
        width: auto;
        margin-bottom: 0;
        transform: scale(1.0);
        transform-origin: top left;
        z-index: 1000;
    }

    .envelope-wrapper {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0.9);
        /* Dominant but safe desktop view (~1080px wide) */
        margin: 0 !important;
        transform-origin: center center;
    }
}

/* Massive Scaling for Wide Screens */
@media (min-width: 1500px) and (orientation: landscape) {
    .envelope-wrapper {
        transform: translate(-50%, -50%) scale(1.1);
        /* Full resolution usage */
    }
}

/* Specific scaling for phone-sized landscape */
@media (max-width: 950px) and (orientation: landscape) {
    .envelope-wrapper {
        transform: translate(-50%, -50%) scale(0.48);
    }

    .lang-switcher-container {
        transform: scale(0.7);
    }
}

/* Height-based refined scaling for landscape (Older/shorter screens) */
@media (orientation: landscape) and (max-height: 500px) {
    .envelope-wrapper {
        transform: translate(-50%, -50%) scale(0.5);
    }
}

@media (orientation: landscape) and (max-height: 420px) {
    .envelope-wrapper {
        transform: translate(-50%, -50%) scale(0.42);
    }
}

@media (orientation: landscape) and (max-height: 360px) {
    .envelope-wrapper {
        transform: translate(-50%, -50%) scale(0.38);
    }
}

/* Back Side (Form) */
/* Back Side (Form) */
.envelope-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    /* Safari */
    backface-visibility: hidden;
    background: #fff;
    transform: rotateY(180deg);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

/* Border Image Styling */
.back-border-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    /* Force fill to match container exactly */
    pointer-events: none;
    z-index: 1;
}

/* Back Flip Button */
.back-flip-btn {
    position: absolute;
    top: 30px;
    right: 30px;
    /* Top right corner */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #1a3c8e;
    color: white;
    font-size: 2rem;
    border: none;
    cursor: pointer;
    z-index: 100;
    /* Above everything */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    line-height: 1;
}

.back-flip-btn:hover {
    background: #132d6e;
    transform: scale(1.1);
}

/* Back Side Background (Remove old method) */
/* .envelope-back::before removed */

.envelope {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.envelope.open {
    transform: rotateY(-180deg);
}

/* Front Side */
.envelope-front {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    /* Safari */
    backface-visibility: hidden;
    background: #fff;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    cursor: default;
}

/* Front Side Content (using provided asset) */
.front-side-img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    /* Changed from cover to fill to correct border */
    pointer-events: none;
}

/* Invisible Front Flip Button Overlay */
.front-flip-btn-overlay {
    position: absolute;
    bottom: 45px;
    /* 30 * 1.5 */
    right: 75px;
    /* 50 * 1.5 */
    width: 300px;
    /* 200 * 1.5 */
    height: 105px;
    /* 70 * 1.5 */
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 200;
    /* Ensure it stays above everything on front */
}

/* Invisible Confirm Button Overlay (Keeping for reference or later use) */
.confirm-btn-overlay {
    position: absolute;
    bottom: 30px;
    right: 50px;
    width: 200px;
    height: 50px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 100;
}

/* RSVP Form Container */
.v30-rsvp-container {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 85px 100px;
    /* Enhanced proportions for 1200px base */
    z-index: 10;
    display: flex;
    flex-direction: column;
}

/* Hide old grid */
.v30-rsvp-grid {
    display: none;
}

/* Form Layout */
.v30-rsvp-form {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.form-group {
    margin-bottom: 40px;
    /* More breathing room */
    border-bottom: 2px solid #a3c2e6;
    /* Lined paper look */
    padding-bottom: 10px;
}

.form-row {
    display: flex;
    align-items: baseline;
    gap: 15px;
}

.v30-rsvp-form label {
    font-size: 1.8rem;
    color: #444;
    font-family: 'Tumanian Handwriting', 'Caveat', cursive;
    font-weight: 400;
    opacity: 0.9;
    white-space: nowrap;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.lang-ru .v30-rsvp-form label {
    font-size: 1.8rem;
}

.v30-under-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 1.8rem;
    color: #444;
    font-family: 'Tumanian Handwriting', 'Caveat', cursive;
    font-weight: 400;
    opacity: 0.95;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.lang-ru .v30-under-input {
    font-size: 1.8rem;
}

.v30-under-input::placeholder {
    color: #ddd;
    font-size: 1.8rem;
    font-family: 'Tumanian Handwriting', 'Caveat', cursive;
    font-weight: 400;
}

.lang-ru .v30-under-input::placeholder {
    font-size: 1.8rem;
}

/* Upload Section */
.upload-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 15px;
    padding: 10px 0;
    border-bottom: 2px solid #a3c2e6;
}

.upload-label-text {
    font-size: 1.8rem;
    color: #444;
    font-family: 'Tumanian Handwriting', 'Caveat', cursive;
    font-weight: 400;
    opacity: 0.9;
    max-width: 65%;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.lang-ru .upload-label-text {
    font-size: 1.8rem;
}

.v30-btn-back-sm {
    background: #6c99c6;
    color: white;
    padding: 15px 35px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.8rem;
    font-weight: 700;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: inline-block;
}

/* Footer Section */
.footer-section {
    display: flex;
    align-items: flex-end;
    /* Align to bottom */
    justify-content: space-between;
    margin-top: 40px;
    padding-bottom: 10px;
}

.stamp-section {
    display: flex;
    align-items: flex-end;
    gap: 15px;
    z-index: 10;
}

.back-stamp {
    width: 100px;
    height: auto;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.dress-code {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    color: #444;
}

.dc-label {
    font-family: 'Montserrat Armenian', sans-serif;
    font-weight: 400;
    letter-spacing: 0.5px;
    color: #666;
    font-size: 1.0rem;
}

.dc-value {
    font-family: 'Noto Serif Armenian', serif;
    font-weight: 700;
    font-style: italic;
    color: #222;
    font-size: 1.0rem;
}

.v30-btn-back-lg {
    background: #1a3c8e;
    color: white;
    padding: 22px 75px;
    border-radius: 40px;
    font-size: 1.8rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    font-family: 'Montserrat Armenian', sans-serif;
    text-transform: uppercase;
    white-space: nowrap;
    transition: all 0.3s ease;
}

/* --- REFINED MOBILE RESPONSIVENESS (Structural Only) --- */
@media (max-width: 600px) {

    /* Font scaling is now handled by the .envelope-wrapper scale(0.31) transform */
    .footer-section {
        padding-bottom: 35px;
        /* Extra breathing room for mobile home bar */
    }
}

/* Critical Portrait Height Fix (Rotated Phones) */
@media (orientation: portrait) and (max-width: 600px) and (max-height: 900px) {
    .form-group {
        margin-bottom: 25px;
    }
}

.v30-btn-back-lg:hover {
    background: #132d6e;
    transform: translateY(-2px);
}

/* Success State */
.v30-success {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
}

.v30-success.visible {
    display: flex;
}

.v30-success h3 {
    font-size: 3rem;
    color: #1a3c8e;
    margin: 0;
}

.lang-ru .v30-success h3 {
    font-size: 3rem;
}

.v30-success p {
    font-size: 1.8rem;
    color: #1a3c8e;
    margin: 0;
}

.lang-ru .v30-success p {
    font-size: 1.8rem;
}

.v30-success button {
    margin: 0;
}

.final-message-box button {
    padding: 10px 40px;
    border: 2px solid #1a3c8e;
    background: white;
    color: #1a3c8e;
    border-radius: 30px;
    cursor: pointer;
}

/* Sent Animation */
@keyframes flyAway {
    0% {
        transform: rotateY(180deg) scale(1);
        opacity: 1;
    }

    100% {
        transform: rotateY(180deg) translate(2000px, -2000px) rotate(-45deg);
        opacity: 0;
    }
}

.envelope-wrapper.sent {
    animation: flyAway 1.5s ease-in forwards;
    pointer-events: none;
    /* Prevent clicks while flying */
}

/* Landscape Sent Animation */
@media (orientation: landscape) {
    @keyframes flyAwayLandscape {
        0% {
            transform: rotate(0deg) scale(0.7);
            opacity: 1;
        }

        100% {
            transform: rotate(0deg) scale(0.7) translate(100vw, -100vh);
            opacity: 0;
        }
    }

    .envelope-wrapper.sent {
        animation: flyAwayLandscape 1.5s ease-in forwards;
    }
}

/* Mobile Sent Animation Override (FORCE vertical) */
@media (max-width: 600px) and (orientation: portrait) {
    @keyframes flyAwayMobile {
        0% {
            transform: rotate(90deg) scale(0.7);
            opacity: 1;
        }

        100% {
            transform: rotate(90deg) scale(0.7) translate(100vh, -100vw);
            opacity: 0;
        }
    }

    .envelope-wrapper.sent {
        animation: flyAwayMobile 1.5s ease-in forwards;
    }
}


/* Final Message Overlay */
.final-message-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease-in;
    z-index: 200;
}

.final-message-container.visible {
    opacity: 1;
    pointer-events: auto;
}

.final-message-box {
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    text-align: center;
    max-width: 80%;
}

.final-message-box h3 {
    font-size: 2.5rem;
    color: #1a3c8e;
    margin-bottom: 10px;
    font-family: 'Noto Serif Armenian', serif;
}

.final-message-box p {
    font-size: 1.5rem;
    color: #333;
    font-family: 'Montserrat', sans-serif;
}

.admin-link {
    margin-top: auto;
    color: rgba(0, 0, 0, 0.1);
    text-decoration: none;
    font-size: 0.7rem;
    padding: 20px;
}

/* Responsive */