:root {
    --bg-color: #E8E6E1;
    /* Desk surface color */
    --envelope-color: #D6CFC7;
    --envelope-shadow: rgba(0, 0, 0, 0.15);
    --paper-color: #FDFBF7;
    /* Warm Paper */
    --ink-color: #2A2A2A;
    /* Dark Charcoal (High Contrast) */
    --text-muted: #6B6B6B;
    --wax-color: #C05555;
    --accent-green: #7A8B7D;
}

* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
}

body {
    background-color: var(--bg-color);
    font-family: 'Montserrat', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    overflow-y: visible;
    perspective: 1000px;
    padding: 1rem;
    opacity: 0;
animation: fadeInUp 0.8s ease forwards;
}

/* =========================================================
   WRITE MODE (Stationery Pad Look)
   ========================================================= */
   
   .container{
       
       
   }
   
   .logo{
       width: 50%;
       left: 24%;
       margin-bottom: 1rem;
       position: relative;
   }
   
.stationery-card {
    background: var(--paper-color);
    width: 100%;
    padding: 40px;
    border-radius: 4px;
    position: relative;
    
}

@keyframes fadeInUp {
    to {
        opacity: 1;
    }
}

.title-area {
    text-align: center;
    margin-bottom: 25px;
    color: var(--text-muted);
    font-size: 0.8rem;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.message-area {
    width: 100%;
    border: none;
    background: transparent;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1rem;
    color: var(--ink-color);
    min-height: 200px;
    resize: none;
    background-image: linear-gradient(transparent 95%, #E5E5E5 95%);
    background-size: 100% 2.4rem;
    line-height: 2.4rem;
}

.message-area::placeholder {
    color: #B0B0B0;
    font-style: italic;
}

.sender-input {
    width: 100%;
    border: none;
    border-bottom: 1px solid #DDD;
    padding: 10px 0;
    font-family: 'Dancing Script', cursive;
    font-size: 1.4rem;
    color: var(--ink-color);
    margin-top: 20px;
    background: transparent;
}

.sender-input::placeholder {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.9rem;
    color: #BBB;
}

.btn-seal {
    display: block;
    margin: 30px auto 0;
    background: var(--accent-green);
    color: white;
    border: none;
    padding: 12px 40px;
    border-radius: 50px;
    cursor: pointer;
    font-size: 0.9rem;
    letter-spacing: 1px;
    transition: transform 0.2s, background 0.2s;
}

.btn-seal:hover {
    transform: scale(0.98);
    background: #697a6c;
}

/* =========================================================
   READ MODE (Envelope Animation) - FIXED
   ========================================================= */

.envelope-container {
    position: relative;
    width: 320px;
    height: 220px;
    cursor: pointer;
    transition: transform 0.5s ease;
    overflow: visible;
    /* allow letter to appear outside the container when opened */
}

.envelope-container:hover {
    transform: translateY(-5px);
}

/* The Envelope Body */
.envelope {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--envelope-color);
    border-radius: 0 0 5px 5px;
    overflow: hidden; /* <-- مهم: يخفي الورقة أثناء الإغلاق */
    perspective: 800px;
    box-shadow: 0 8px 18px rgba(0,0,0,0.06);
}

/* The Flap (Triangle) */
.flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 160px solid transparent;
    border-right: 160px solid transparent;
    border-top: 110px solid #Cfc8c0;
    transform-origin: top center; /* أفضل للالتفاف */
    transform-style: preserve-3d;
    backface-visibility: hidden; /* يقلل الوميض عند الدوران */
    transition: transform 0.6s 0.1s ease-in-out, z-index 0.2s;
    z-index: 5;
}

/* The Pocket (Front triangles) */
.pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 160px solid var(--envelope-color);
    border-right: 160px solid var(--envelope-color);
    border-bottom: 120px solid #C4BDB5;
    border-top: 100px solid transparent;
    z-index: 3;
    border-radius: 0 0 5px 5px;
}

/* The Wax Seal */
.wax-seal {
    position: absolute;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    width: 35px;
    height: 35px;
    background: var(--wax-color);
    border-radius: 50%;
    z-index: 6;
    transition: opacity 0.4s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: rgba(0, 0, 0, 0.2);
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}

/* The Letter Inside */
/* الآن الورقة مبدئياً مخفية أسفل الظرف عبر translateY */
.letter {
    position: absolute;
    bottom: 0;
    left: 10px;
    width: calc(100% - 20px);
    max-width: 300px;
    height: 200px;
    background: var(--paper-color);
    padding: 20px;
    transform: translateY(120%); /* مخفية خارج الظرف أثناء الإغلاق */
    transition: transform 0.8s ease 0.45s, height 0.8s ease 0.45s, z-index 0s 0.45s;
    z-index: 1; /* خلف الغطاء مبدئياً */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-radius: 2px;
    box-shadow: 0 12px 30px rgba(0,0,0,0.06);
}

/* Letter Content Typography */
.letter-content {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.3rem;
    line-height: 1.8;
    color: var(--ink-color);
    flex-grow: 1;
    overflow-y: auto;
    opacity: 0;
    transition: opacity 0.45s 0.9s; /* يظهر بعد حركة الورقة */
}

.letter-footer {
    margin-top: 20px;
    text-align: right;
    font-family: 'Dancing Script', cursive;
    font-size: 1.4rem;
    color: var(--ink-color);
    opacity: 0;
    transition: opacity 0.45s 1.05s;
}

/* Animation States */
.open .flap {
    transform: rotateX(180deg);
    z-index: 0;
}

.open .wax-seal {
    opacity: 0;
}

/* عندما يفتح الظرف: ترتفع الورقة وتوسع ارتفاعها للقراءة */
.open .letter {
    transform: translateY(-40px); /* تصعد للعرض - اضبط القيمة حسب الحاجة */
    height: 380px;
    z-index: 4; /* أمام جسم الظرف */
}

/* محتوى الورقة وفوتر التوقيع يظهران بتلاشي */
.open .letter-content,
.open .letter-footer {
    opacity: 1;
}

/* Result Box (بعد القراءة) */
.result-overlay {
    margin-top: 20px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.link-box {
    background: white;
    padding: 10px;
    border: 1px solid #DDD;
    margin: 10px 0;
    user-select: all;
    color: #555;
    font-family: monospace;
}

/* Small screens adjustments */
@media (max-width: 360px) {
    .envelope-container {
        width: 300px;
        height: 210px;
    }
    
    .flap {
        border-left: 150px solid transparent;
        border-right: 150px solid transparent;
        border-top: 100px solid #Cfc8c0;
    }
    
    .pocket {
        border-left: 150px solid var(--envelope-color);
        border-right: 150px solid var(--envelope-color);
        border-bottom: 110px solid #C4BDB5;
    }
    
    .letter {
        max-width: 280px;
        left: 10px;
    }
}

footer {
    width: 100%;
    margin-top: 18px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    font-family: 'Cormorant Garamond', serif;
}

footer a {
    color: var(--text-muted);
}