/*==================================================
THEME VARIABLES
==================================================*/
:root {
    --bg: #fff5f7;
    --main: #ff758f;
    --button: #ff4d6d;
    --buttonHover: #c9184a;
    --letter: #ffffff;
    --envelope: #ffb3c1;
    --text: #4a2e35;
    --text-muted: #8c5e6a;
    --shadow: rgba(255, 77, 109, 0.15);
    --gold: #d4af37;
}

/*==================================================
BASE & RESET STYLES
==================================================*/
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/*==================================================
BACKGROUND ANIMATIONS (FLOATING HEARTS)
==================================================*/
#hearts-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.floating-heart {
    position: absolute;
    bottom: -20px;
    color: var(--main);
    opacity: 0.6;
    animation: floatUp linear forwards;
    user-select: none;
}

@keyframes floatUp {
    0% {
        transform: translateY(0) rotate(0deg) scale(0.8);
        opacity: 0.7;
    }
    50% {
        opacity: 0.9;
    }
    100% {
        transform: translateY(-105vh) rotate(360deg) scale(1.2);
        opacity: 0;
    }
}

/*==================================================
SCREEN & CONTAINER TRANSITIONS
==================================================*/
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 10;
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

.screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* UI Cards */
.card {
    background: var(--letter);
    border-radius: 24px;
    padding: 40px 30px;
    box-shadow: 0 15px 35px var(--shadow);
    text-align: center;
    width: 100%;
    max-width: 440px;
    position: relative;
    z-index: 2;
    transition: transform 0.3s ease;
}

/* Buttons */
.btn {
    border: none;
    outline: none;
    padding: 14px 28px;
    border-radius: 50px;
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-block;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--button);
    color: #ffffff;
    box-shadow: 0 8px 20px rgba(255, 77, 109, 0.3);
}

.btn-primary:hover {
    background-color: var(--buttonHover);
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 12px 24px rgba(201, 24, 74, 0.4);
}

.btn-primary:active {
    transform: translateY(1px) scale(0.98);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid #ffccd5;
    margin-top: 10px;
}

.btn-secondary:hover {
    background-color: #fff0f3;
    color: var(--buttonHover);
}

/*==================================================
STEP 1: PASSWORD PAGE
==================================================*/
.password-card {
    animation: fadeIn 0.8s ease-out;
}

.heart-icon-header {
    font-size: 2.5rem;
    margin-bottom: 10px;
    animation: pulse 1.5s infinite alternate;
}

.title {
    font-family: 'Playfair Display', serif;
    font-size: 2.2rem;
    color: var(--text);
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 25px;
}

.input-group {
    margin-bottom: 15px;
}

#password-input {
    width: 100%;
    padding: 14px 20px;
    border: 2px solid #ffccd5;
    border-radius: 50px;
    font-size: 1.1rem;
    text-align: center;
    outline: none;
    transition: all 0.3s ease;
    background: #fff0f3;
    color: var(--text);
    letter-spacing: 2px;
}

#password-input:focus {
    border-color: var(--main);
    background: #ffffff;
    box-shadow: 0 0 12px rgba(255, 117, 143, 0.3);
}

.error-message {
    color: var(--buttonHover);
    font-size: 0.88rem;
    font-weight: 500;
    min-height: 22px;
    margin-bottom: 10px;
}

/* Shake animation for wrong password */
.shake {
    animation: shakeAnim 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

@keyframes shakeAnim {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.15); }
}

/*==================================================
STEP 2: ENVELOPE
==================================================*/
.envelope-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.envelope-instruction {
    font-family: 'Playfair Display', serif;
    color: var(--text);
    font-size: 1.6rem;
    margin-bottom: 30px;
    animation: pulse 1.5s infinite alternate;
}

.envelope {
    position: relative;
    width: 300px;
    height: 200px;
    background-color: var(--envelope);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    box-shadow: 0 15px 35px var(--shadow);
    cursor: pointer;
    transition: transform 0.3s ease;
}

.envelope:hover {
    transform: translateY(-5px);
}

/* Envelope Flap Top */
.flap-top {
    position: absolute;
    top: 0;
    left: 0;
    border-left: 150px solid transparent;
    border-right: 150px solid transparent;
    border-top: 110px solid #ff9ebb;
    transform-origin: top;
    transition: transform 0.6s ease 0.2s, z-index 0.2s ease 0.2s;
    z-index: 4;
}

/* Envelope Pocket (Front body) */
.pocket {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left: 150px solid #ffccd5;
    border-right: 150px solid #ffccd5;
    border-bottom: 100px solid #ff8fa3;
    border-top: 100px solid transparent;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    z-index: 3;
}

/* Letter Peek Inside Envelope */
.letter-preview {
    position: absolute;
    bottom: 15px;
    left: 5%;
    width: 90%;
    height: 160px;
    background: #ffffff;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1) 0.5s;
    z-index: 2;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.preview-text {
    font-family: 'Playfair Display', serif;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-style: italic;
}

.heart-seal {
    position: absolute;
    top: 85px;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.8rem;
    z-index: 5;
    transition: opacity 0.4s ease;
}

/* Opened Envelope State Animations */
.envelope.open .flap-top {
    transform: rotateX(180deg);
    z-index: 1;
}

.envelope.open .heart-seal {
    opacity: 0;
}

.envelope.open .letter-preview {
    transform: translateY(-100px);
}

/*==================================================
STEP 3 & 4: LETTER
==================================================*/
.letter-card {
    max-width: 680px;
    max-height: 85vh;
    overflow-y: auto;
    text-align: right;
    padding: 45px 40px;
    border: 1px solid #ffe6ea;
    background: #ffffff;
    box-shadow: 0 20px 40px var(--shadow);
}

.letter-title {
    font-family: 'Playfair Display', serif;
    color: var(--buttonHover);
    font-size: 2.2rem;
    margin-bottom: 25px;
    text-align: center;
}

.letter-body {
    font-family: 'Cairo', sans-serif; /* خط عربي أنيق وواضح */
    direction: rtl;
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text);
    white-space: pre-wrap;
    margin-bottom: 25px;
    min-height: 120px;
}

/* Typewriter Cursor Effect */
.letter-body::after {
    content: '|';
    animation: blink 0.7s infinite;
    color: var(--main);
    font-weight: 600;
}

.letter-body.typing-complete::after {
    display: none;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Signature Styling */
.signature-container {
    text-align: right;
    margin-top: 20px;
    padding-right: 20px;
    opacity: 0;
    transform: translateY(15px);
    transition: all 0.8s ease-out;
}

.signature-container.visible {
    opacity: 1;
    transform: translateY(0);
}

.signature {
    font-family: 'Amiri', serif;
    font-style: italic;
    font-size: 2.5rem;
    color: var(--buttonHover);
}

/* Letter Action Buttons */
.letter-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-top: 35px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

.letter-actions.visible {
    opacity: 1;
}

/*==================================================
STEP 6: PHOTO GALLERY
==================================================*/
#gallery-screen {
    z-index: 100;
}

.gallery-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(20, 10, 15, 0.88);
    backdrop-filter: blur(8px);
}

.gallery-container {
    position: relative;
    z-index: 101;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 900px;
    height: 100%;
    max-height: 90vh;
}

.gallery-counter {
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 15px;
    letter-spacing: 2px;
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 18px;
    border-radius: 30px;
}

.gallery-viewport {
    width: 100%;
    height: 65vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.gallery-viewport img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 12px;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Gallery Controls */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--button);
    transform: translateY(-50%) scale(1.1);
}

.prev-btn { left: 10px; }
.next-btn { right: 10px; }

.btn-close-gallery {
    margin-top: 25px;
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-close-gallery:hover {
    background: var(--button);
    border-color: var(--button);
}

/* Image Fade Animation */
.img-fade {
    opacity: 0;
    transform: scale(0.97);
}

/*==================================================
RESPONSIVE DESIGN
==================================================*/

/* Desktop & Laptop Refinements */
@media (min-width: 1024px) {
    .card {
        padding: 50px 45px;
    }
    .letter-card {
        padding: 60px 50px;
    }
    .prev-btn { left: -60px; }
    .next-btn { right: -60px; }
}

/* Tablet */
@media (max-width: 768px) {
    .title { font-size: 1.9rem; }
    .envelope { width: 280px; height: 180px; }
    .flap-top { border-left-width: 140px; border-right-width: 140px; border-top-width: 100px; }
    .pocket { border-left-width: 140px; border-right-width: 140px; border-bottom-width: 90px; border-top-width: 90px; }
    .signature { font-size: 2.5rem; }
    .gallery-viewport { height: 55vh; }
}

/* Mobile */
@media (max-width: 480px) {
    .card {
        padding: 35px 20px;
        border-radius: 20px;
    }
    .letter-card {
        padding: 35px 22px;
    }
    .title { font-size: 1.75rem; }
    .letter-title { font-size: 1.8rem; }
    .letter-body { font-size: 0.98rem; line-height: 1.7; }
    
    .envelope { width: 250px; height: 165px; }
    .flap-top { border-left-width: 125px; border-right-width: 125px; border-top-width: 90px; }
    .pocket { border-left-width: 125px; border-right-width: 125px; border-bottom-width: 80px; border-top-width: 80px; }
    .heart-seal { top: 75px; }
    
    .nav-btn {
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }
    .prev-btn { left: 5px; }
    .next-btn { right: 5px; }
    
    .signature { font-size: 2.2rem; }
}