:root {
    --pink-bg: #fce4ec;
    --pink-main: #ff85a2;
}

body {
    margin: 0; padding: 0;
    background-color: var(--pink-bg);
    font-family: 'Arial', sans-serif;
    overflow: hidden;
}

.screen {
   background: linear-gradient(180deg, #f0a3b2 0%, #d88697 100%);
    top: 0; left: 0;
   width: 100vw;
    height: 100vh;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.screen.active { display: flex; animation: fadeIn 1s ease; }

/* Hiệu ứng bay (Trái tim & Ảnh) */
.floating-item {
    position: absolute;
    bottom: -150px;
    pointer-events: none;
    animation: flyUp linear forwards;
    z-index: 1;
}

@keyframes flyUp {
    0% { transform: translateY(0) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(-120vh) rotate(360deg); opacity: 0; }
}

/* Kiểu ảnh Polaroid bay */
.polaroid {
    width: 80px;           /* Thu nhỏ ảnh bay trên điện thoại */
    padding: 5px 5px 15px 5px;
}


@media (min-width: 768px) {
    .polaroid { width: 120px; } /* Trên máy tính thì ảnh to hơn */
}

/* Hộp đăng nhập & Thiệp */
.login-box, .card {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
}

.shadow { box-shadow: 0 10px 25px rgba(255, 133, 162, 0.3); }

.avatar { width: 100px; height: 100px; border-radius: 50%; border: 4px solid var(--pink-main); }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }

.numpad button {
    padding: 15px; border: none; background: var(--pink-main);
    color: white; border-radius: 10px; font-weight: bold; cursor: pointer;
}

.btn-open {
    padding: 12px 30px; background: var(--pink-main); color: white;
    border: none; border-radius: 25px; font-size: 1.1rem; cursor: pointer;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
/* Kiểu dáng cho bao thư */


.envelope {
    position: absolute;
    width: 100%; height: 100%;
    background: #ff85a2; /* Màu hồng đậm hơn nền */
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

/* Nắp bao thư */
.envelope::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    border-left: 150px solid transparent;
    border-right: 150px solid transparent;
    border-top: 100px solid #ffb1c1; /* Màu nắp thư */
    transition: transform 0.5s;
    transform-origin: top;
    z-index: 2;
}

/* Tờ thư bên trong */


/* Hiệu ứng khi thư mở */
.letter-container.open .envelope::before {
    transform: rotateX(180deg);
    z-index: 0; /* Đẩy nắp thư ra sau để thấy tờ giấy */
}

.letter-container.open .card-letter {
    transform: translate(-50%, -150px); /* Kéo tờ giấy lên trên */
    height: auto;
    min-height: 250px;
}


.letter-content p {
    font-size: 0.95rem;
    color: #ff4d6d;
    line-height: 1.5;
    margin: 8px 0;
    font-weight: bold;
}
/* Layout căn giữa thiệp và nút đóng */
.wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    z-index: 100;
}

.letter-container {
    position: relative;
    width: 350px;
    height: 230px;
    perspective: 1000px;
}

.envelope {
    position: absolute;
    width: 100%; height: 100%;
    background: #ffb1c1;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    z-index: 2;
}

/* Nắp thư có màu đậm hơn */
.envelope::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    border-left: 175px solid transparent;
    border-right: 175px solid transparent;
    border-top: 130px solid #ff85a2;
    transform-origin: top;
    transition: transform 0.6s ease;
    z-index: 4;
}

/* Nội dung tờ thư */
.card-letter {
    position: absolute;
    bottom: 10px;
    left: 10px;
    width: 300px;
    height: 180px;
    background-color: #fffafa;
    border-radius: 5px;
    z-index: 2; /* Nằm dưới mặt trước khi đóng */
    transition: transform 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

#wish-display {
    font-family: 'Dancing Script', cursive; /* Font viết tay */
    font-size: 1.3rem;
    color: #b03a4e;
    text-align: center;
    line-height: 1.5;
    transition: opacity 0.3s ease; /* Hiệu ứng mờ dần khi đổi chữ */
}

/* Hiệu ứng khi mở thiệp */
.envelope-wrapper {
    position: relative;
    width: 90vw;           /* Chuyển từ 320px cố định sang 90% chiều rộng màn hình */
    max-width: 300px;      /* Giới hạn tối đa để không quá to trên máy tính */
    height: 200px;
    background-color: #ffb1c1;
    border-radius: 0 0 10px 10px;
    cursor: pointer;
    z-index: 100;
    margin: 0 auto;        /* Căn giữa */
}
.letter-content p {
    font-family: 'Dancing Script', cursive; /* Font viết tay */
    font-size: 1.5rem;
    color: #e91e63;
    text-align: center;
    margin: 0;
}

/* Hiệu ứng khi mở */
.letter-container.open .envelope::before {
    transform: rotateX(180deg);
    z-index: 0;
}

.letter-container.open .card-letter {
    transform: translate(-50%, -140px);
    z-index: 3;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.05);
}

/* Nút Đóng kẹo ngọt */
#close-btn {
    padding: 10px 45px;
    background: #ffb1c1;
    color: white;
    border: none;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    opacity: 0;
    transition: 0.5s;
    box-shadow: 0 5px 15px rgba(255, 177, 193, 0.4);
}

.letter-container.open + #close-btn { opacity: 1; }
#wish-display {
    font-family: 'Dancing Script', cursive; /* Font viết tay từ Google Fonts */
    font-size: 1.3rem;
    color: #b03a4e;
    text-align: center;
    line-height: 1.5;
    margin: 0;
    transition: opacity 0.3s ease; /* Hiệu ứng mượt khi đổi chữ */
}

.card-letter {
    cursor: pointer; /* Hiển thị bàn tay để người dùng biết là click được */
    display: flex;
    align-items: center;
    justify-content: center;
}
.envelope-wrapper {
    position: relative;
    width: 320px;
    height: 220px;
    background-color: #ffb1c1;
    border-radius: 0 0 10px 10px;
    cursor: pointer;
    z-index: 100;
}

/* Nắp thư nhọn màu đậm hơn */
.lid {
    position: absolute;
    top: 0; left: 0;
    width: 0; height: 0;
    /* Sử dụng phép tính để nắp luôn khớp với chiều rộng bao thư */
    border-left: 45vw solid transparent; 
    border-right: 45vw solid transparent;
    border-top: 110px solid #ff85a2;
    transform-origin: top;
    transition: transform 0.6s ease;
    z-index: 4;
}
@media (min-width: 334px) {
    .lid {
        border-left: 150px solid transparent;
        border-right: 150px solid transparent;
    }
}

.card-letter {
    position: absolute;
    bottom: 5px;
    left: 5%;              /* Cách đều hai bên */
    width: 90%;            /* Co giãn theo bao thư */
    height: 170px;
    background-color: #fffafa;
    border-radius: 5px;
    z-index: 2;
    transition: transform 0.6s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
    box-sizing: border-box;
}
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;              /* Thu nhỏ khoảng cách một chút */
    margin-top: 15px;
}
#wish-display {
    font-family: 'Dancing Script', cursive;
    font-size: 1.3rem;
    color: #b03a4e;
    text-align: center;
    line-height: 1.5;
    margin: 0;
    transition: opacity 0.3s ease; /* Hiệu ứng mượt khi đổi chữ */
}

/* Hiệu ứng khi mở nắp và đẩy thư lên */
.envelope-wrapper.open .lid {
    transform: rotateX(180deg);
    z-index: 0;
}

.envelope-wrapper.open .card-letter {
    transform: translateY(-130px);
    z-index: 5;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.1);
}
#wish-display {
    font-family: 'Dancing Script', cursive;
    font-size: 1.3rem;
    color: #b03a4e;
    text-align: center;
    line-height: 1.5;
    margin: 0;
    /* Hiệu ứng mượt mà khi đổi chữ */
    transition: opacity 0.3s ease-in-out; 
    cursor: pointer;
    user-select: none; /* Ngăn bôi đen chữ khi click nhanh */
}

.card-letter {
    display: flex;
    align-items: center;
    justify-content: center;
}
@keyframes flyUp {
    0% { transform: translateY(0) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(-120vh) rotate(360deg); opacity: 0; }
}

/* Kiểu ảnh Polaroid bay */
.polaroid {
    width: 120px;
    background: white;
    padding: 10px 10px 25px 10px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    border-radius: 2px;
}

.polaroid img { width: 100%; height: 120px; object-fit: cover; }

/* Hộp đăng nhập & Thiệp */
.login-box, .card {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
}

.shadow { box-shadow: 0 10px 25px rgba(255, 133, 162, 0.3); }

.avatar { width: 100px; height: 100px; border-radius: 50%; border: 4px solid var(--pink-main); }

.numpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 20px; }

.numpad button {
    padding: 12px;         /* Giảm padding để nút không quá cao trên màn hình lùn */
    font-size: 1.1rem;      /* Chữ to rõ ràng */
    border: none;
    background: var(--pink-main);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    touch-action: manipulation; /* Tối ưu cho việc chạm (touch) */
}

.btn-open {
    padding: 12px 30px; background: var(--pink-main); color: white;
    border: none; border-radius: 25px; font-size: 1.1rem; cursor: pointer;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.letter-content {
    transition: opacity 0.3s ease; /* Hiệu ứng ẩn hiện chữ nhanh hơn hiệu ứng trượt của thư */
    opacity: 0; /* Mặc định là ẩn chữ */
}

/* Khi thư mở, hiện chữ lên */
.envelope-wrapper.open .letter-content {
    opacity: 1;
}   
.floating-item .polaroid {
    /* Thêm xoay nhẹ ngẫu nhiên cho mỗi tấm ảnh */
    transform: rotate(calc(-15deg + 30 * var(--random-rotate, 0.5)));
}