* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@import url('https://fonts.googleapis.com/css2?family=Kalam:wght@400;700&display=swap');

body {
    font-family: 'Kalam', 'Comic Sans MS', 'Marker Felt', 'Bradley Hand', sans-serif;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.container {
    text-align: center;
    position: relative;
    z-index: 1;
}

.title {
    color: #8b4b7d;
    font-size: 2.5rem;
    margin-bottom: 3rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    animation: bounce 2s ease-in-out infinite;
}

@keyframes bounce {

    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-10px);
    }

    60% {
        transform: translateY(-5px);
    }
}

.envelope {
    position: relative;
    width: 500px;
    height: 350px;
    margin: 0 auto;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.envelope:hover {
    transform: scale(1.02);
}

.envelope-top {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 300px;
    background: linear-gradient(145deg, #fff8e1, #ffecb3);
    border: 3px solid #d7b899;
    border-radius: 10px 10px 10px 10px;
    transform-origin: top center;
    z-index: 3;
    cursor: pointer;
}

.envelope-top::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 250px solid transparent;
    border-right: 250px solid transparent;
    border-top: 150px solid #ffecb3;
    transform: translateX(-50%);
    border-radius: 10px;
    transform-origin: top center;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.envelope-top::after {
    content: '💕';
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    z-index: 4;
}

.envelope.opened .envelope-top::before {
    transform: translateX(-50%) rotateX(-180deg) translateY(3px);
}

.envelope-bottom {
    position: absolute;
    top: 5px;
    left: 10px;
    width: 95%;
    height: 0;
    border-left: 200px solid transparent;
    border-right: 200px solid transparent;
    border-top: 120px solid #fafafa;
    border-bottom: none;
    z-index: 3;
    visibility: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
}

.envelope-bottom:hover {
    filter: brightness(0.99);
}

.paper {
    position: absolute;
    width: 480px;
    height: auto;
    min-height: 500px;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
    cursor: grab;
    transition: all 0.3s ease;
    opacity: 0;
    transform-style: preserve-3d;
    perspective: 1000px;
}

.paper-front,
.paper-back {
    position: absolute;
    width: 100%;
    height: 100%;
    background: #fafafa;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    background-image:
        linear-gradient(90deg, rgba(255, 192, 203, 0.1) 0px, transparent 1px),
        linear-gradient(rgba(255, 192, 203, 0.1) 0px, transparent 1px);
    background-size: 25px 25px;
    backface-visibility: hidden;
    transition: transform 0.8s ease-in-out;
}

.paper-back {
    transform: rotateY(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f8f8;
}

.paper.flipped .paper-front {
    transform: rotateY(-180deg);
}

.paper.flipped .paper-back {
    transform: rotateY(0deg);
}

.paper-image {
    width: 90%;
    height: 90%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    overflow: hidden;
}

.paper-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.flip-button {
    position: absolute;
    bottom: 15px;
    right: 15px;
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #ff6b9d, #d63384);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(214, 51, 132, 0.3);
    transition: all 0.3s ease;
    z-index: 10;
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
}

.paper.visible .flip-button {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.flip-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(214, 51, 132, 0.4);
    background: linear-gradient(135deg, #ff8fab, #e83e8c);
}

.flip-button:active {
    transform: scale(0.95);
}

.paper.visible {
    opacity: 1;
    top: 20px;
    z-index: 5;
}

.paper:active {
    cursor: grabbing;
}

.paper.dragged-out {
    transform: translateX(-50%) translateY(200px) scale(1.1);
    z-index: 10;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
}

.paper-content {
    padding: 2rem;
    color: #333;
    line-height: 1.6;
    font-size: 0.95rem;
    opacity: 0;
    transition: opacity 0.5s ease;
    box-sizing: border-box;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.paper.dragged-out .paper-front .paper-content {
    opacity: 1;
}

.paper.fully-revealed {
    transform: translateX(-50%) translateY(-50px) scale(1);
    z-index: 10;
    opacity: 1;
}

.paper.fully-revealed .paper-front .paper-content {
    opacity: 1;
}

.envelope-bottom.transformed-to-paper {
    /* Transform the triangular envelope bottom into a rectangular paper shape */
    border: none !important;
    background: #fafafa !important;
    border: 2px solid #e0e0e0 !important;
    border-radius: 8px !important;
    width: 480px !important;
    min-height: 500px !important;
    max-height: 80vh !important;
    overflow-y: auto !important;
    top: 20px !important;
    left: 50% !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
    background-image:
        linear-gradient(90deg, rgba(255, 192, 203, 0.1) 0px, transparent 1px),
        linear-gradient(rgba(255, 192, 203, 0.1) 0px, transparent 1px) !important;
    background-size: 25px 25px !important;
    z-index: 6 !important;
    cursor: grab !important;
    /* Remove the transform !important to allow JavaScript dragging */
}

.envelope-bottom.transformed-to-paper:active {
    cursor: grabbing !important;
}

.paper-content h2 {
    color: #d81b60;
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.paper-content p {
    margin-bottom: 1rem;
    text-align: left;
}

.signature {
    text-align: right;
    font-style: italic;
    color: #8b4b7d;
    margin-top: 2rem;
    margin-bottom: 4rem;
    font-weight: bold;
}

/* Custom scrollbar for paper */
.paper::-webkit-scrollbar {
    width: 8px;
}

.paper::-webkit-scrollbar-track {
    background: rgba(255, 192, 203, 0.1);
    border-radius: 4px;
}

.paper::-webkit-scrollbar-thumb {
    background: rgba(216, 27, 96, 0.3);
    border-radius: 4px;
}

.paper::-webkit-scrollbar-thumb:hover {
    background: rgba(216, 27, 96, 0.5);
}

.instruction {
    margin-top: 2rem;
    color: #8b4b7d;
    font-size: 1.2rem;
    font-weight: bold;
    animation: pulse 2s infinite;
}

.drag-instruction {
    margin-top: 1rem;
    color: #d81b60;
    font-size: 1.1rem;
    font-weight: bold;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }

    100% {
        opacity: 1;
    }
}

/* Decorative elements */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(255, 182, 193, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 218, 225, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(255, 240, 245, 0.2) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* Floating hearts animation */
@keyframes float {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

.heart {
    position: fixed;
    color: #ff69b4;
    font-size: 1.5rem;
    animation: float 6s linear infinite;
    pointer-events: none;
    z-index: 0;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    .envelope {
        width: 350px;
        height: 260px;
    }

    .envelope-top {
        height: 225px;
    }

    .envelope-top::before {
        border-left: 175px solid transparent;
        border-right: 175px solid transparent;
        border-top: 110px solid #ffecb3;
    }

    .envelope-bottom {
        top: 4px;
        left: 7px;
        width: 95%;
        border-left: 140px solid transparent;
        border-right: 140px solid transparent;
        border-top: 84px solid #fafafa;
    }

    .paper {
        width: 340px;
        height: auto;
        min-height: 450px;
    }

    .envelope-bottom.transformed-to-paper {
        width: 340px !important;
        min-height: 450px !important;
    }

    .flip-button {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
        bottom: 10px;
        right: 10px;
    }

    .title {
        font-size: 1.8rem;
        margin-bottom: 2rem;
    }

    .paper-content {
        padding: 1.5rem;
        font-size: 0.9rem;
    }

    .signature {
        margin-bottom: 3rem;
    }

    .paper-content h2 {
        font-size: 1.5rem;
    }
}

/* Mobile error overlay styles */
#mobile-error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a52 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    font-family: 'Comic Sans MS', cursive, sans-serif;
}

.mobile-error-content {
    background: white;
    padding: 3rem 2rem;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: errorBounce 0.6s ease-out;
}

.mobile-error-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: pulse 2s infinite;
}

.mobile-error-content h2 {
    color: #d32f2f;
    font-size: 1.5rem;
    margin-bottom: 1rem;
    font-weight: bold;
}

.mobile-error-content p {
    color: #555;
    font-size: 1rem;
    margin-bottom: 0.8rem;
    line-height: 1.4;
}

.mobile-error-heart {
    font-size: 2rem;
    margin-top: 1.5rem;
    animation: heartBeat 1.5s ease-in-out infinite;
}

@keyframes errorBounce {
    0% {
        transform: scale(0.3) rotate(-10deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.05) rotate(2deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes heartBeat {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}