/* Import your custom font */
@font-face {
    font-family: 'MyCustomFont'; /* Updated name to match your custom font */
    src: url('../fonts/myfont.ttf') format('truetype'); /* Changed to point to your TTF file */
    font-weight: normal;
    font-style: normal;
}

/* Apply box-sizing globally to all elements */
* {
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: #dff3ff; /* Soft light blue background */
    font-family: 'MyCustomFont', sans-serif; /* Updated to use your custom font */
    overflow: hidden; /* Hide scrollbars if letter expands */
}

.container {
    perspective: 1000px; /* For 3D effects if you add them */
}

.envelope-wrapper {
    position: relative;
    margin: 30px;
}

/* Redesigned envelope - pure white with no diamond */
.envelope {
    width: 350px;
    height: 220px;
    background-color: #ffffff; /* White envelope */
    border: 1px solid #dedede;
    border-radius: 5px;
    position: relative;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    /* Add subtle texture for realism */
    background-image: 
        linear-gradient(to right, rgba(0,0,0,0.01) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0,0,0,0.01) 1px, transparent 1px);
    background-size: 10px 10px;
}

/* Make diagonal lines more visible to emphasize the seal's function */
.envelope .diagonal-line-left {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
}

.envelope .diagonal-line-left::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 140%;
    background: transparent;
    border-top: 1px solid rgba(0,0,0,0.12); /* Slightly darker for visibility */
    transform: rotate(45deg);
    transform-origin: top left;
}

/* Right diagonal fold line */
.envelope .diagonal-line-right {
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 1;
}

.envelope .diagonal-line-right::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 140%;
    background: transparent;
    border-top: 1px solid rgba(0,0,0,0.12); /* Slightly darker for visibility */
    transform: rotate(-45deg);
    transform-origin: top right;
}

/* Subtle shading for the envelope sides */
.envelope .side-shading-left {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0.02), transparent);
    z-index: 1;
}

.envelope .side-shading-right {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 50%;
    height: 100%;
    background: linear-gradient(to left, rgba(0,0,0,0.02), transparent);
    z-index: 1;
}

/* Stamp/seal positioned to cover the intersection of diagonal lines */
.stamp {
    width: 70px; /* Slightly larger for emphasis */
    height: 70px;
    position: absolute;
    /* Position lower to cover the intersection point of diagonal lines */
    top: 80%; /* Moved substantially lower to ensure it covers the diagonal intersection */
    left: 50%;
    transform: translate(-50%, -50%);
    cursor: pointer;
    border-radius: 50%;
    z-index: 5; /* Ensure it's above the diagonal lines */
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25); /* Enhanced shadow for "holding" effect */
}

/* When using an image for stamp */
.stamp img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Add a subtle animation to draw attention to the stamp */
.stamp:hover {
    transform: translate(-50%, -50%) scale(1.05); /* Keep same position while scaling */
    transition: transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Letter styling with flip functionality */
.letter {
    width: 320px;
    height: 450px; /* Fixed height to match previous size */
    position: absolute;
    top: 70%;
    left: 50%;
    transform: translate(-50%, 0) scale(1, 0.33);
    transform-origin: center top;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-out, visibility 0s 0.3s;
    z-index: 10;
    perspective: 1200px;
}

/* Container for the flippable letter */
.letter-flip-container {
    width: 100%;
    height: 100%; /* Full height of parent */
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s;
}

/* Front side of the letter */
.letter-front {
    position: absolute;
    width: 100%;
    height: 100%; /* Full height of container */
    backface-visibility: hidden;
    overflow-y: auto;
    background-color: #ffffff;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    background-image: 
        linear-gradient(to right, rgba(0,0,0,0.006) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0,0,0,0.006) 1px, transparent 1px);
    background-size: 24px 24px;
    border: none;
    padding: 30px;
    border-radius: 2px;
    /* Create folding sections */
    display: flex;
    flex-direction: column;
}

/* Back side of the letter */
.letter-back {
    position: absolute;
    width: 100%;
    height: 100%; /* Full height of container */
    backface-visibility: hidden;
    transform: rotateY(180deg);
    background-color: #ffffff;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    border-radius: 2px;
    padding: 30px;
    /* Subtle paper texture for the back */
    background-image: 
        linear-gradient(to right, rgba(0,0,0,0.003) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0,0,0,0.003) 1px, transparent 1px);
    background-size: 24px 24px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Style for the back of letter image */
.back-letter-image {
    max-width: 85%;
    max-height: 85%;
    object-fit: contain;
    display: block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border-radius: 4px;
    z-index: 5;
}

/* Flipped state for the letter */
.letter-flip-container.flipped {
    transform: rotateY(180deg);
}

/* Corner indicator for flipping */
.flip-corner {
    position: absolute;
    top: 0;
    right: 0;
    width: 30px;
    height: 30px;
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.05) 50%);
    cursor: pointer;
    z-index: 15;
    transition: background 0.3s;
}

.flip-corner:hover {
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.15) 50%);
}

/* Back corner indicator */
.back-corner {
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.05) 50%);
}

.back-corner:hover {
    background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,0.15) 50%);
}

/* Animation states and other letter styles */
.envelope-wrapper.open .letter {
    opacity: 1;
    visibility: visible;
    animation: letterOut 1.2s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transition: opacity 0.3s ease-out;
}

.envelope-wrapper.open .letter-fold-top {
    animation: unfoldTop 0.8s 0.4s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.envelope-wrapper.open .letter-fold-middle {
    animation: unfoldMiddle 0.8s 0.6s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.envelope-wrapper.open .letter-fold-bottom {
    animation: unfoldBottom 0.8s 0.8s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Update the letterOut animation to position the letter higher up */
@keyframes letterOut {
    0% {
        top: 70%;
        transform: translate(-50%, 0) scale(1, 0.33);
    }
    60% {
        top:-50%; /* Changed from 40% to 25% to position letter higher */
        transform: translate(-10%, 0) scale(1, 0.33);
    }
    100% {
        top: -80%; /* Changed from 40% to 25% to position letter higher */
        transform: translate(-50%, 0) scale(1, 1);
    }
}

/* Unfolding animations */
@keyframes unfoldTop {
    from { transform: rotateX(180deg); }
    to { transform: rotateX(0deg); }
}

@keyframes unfoldMiddle {
    from { transform: rotateX(180deg); }
    to { transform: rotateX(0deg); }
}

@keyframes unfoldBottom {
    from { transform: rotateX(0deg); }
    to { transform: rotateX(0deg); }
}

/* Style for the content inside the letter */
.letter-content {
    color: #333333; /* Dark brown text for readability */
    line-height: 1.6;
    min-height: 400px; /* Ensure there's enough height for the folding effect */
}

.letter-content h1 {
    color: #333333; /* Cute pink for heading */
    font-size: 1.5em;
    margin-top: 0;
}

.letter-content p {
    margin-bottom: 1em;
}

.editable-field {
    outline: 1px dashed rgba(255, 102, 153, 0.55);
    outline-offset: 3px;
    border-radius: 3px;
    cursor: text;
}

.editable-field:focus {
    outline: 2px solid rgba(255, 102, 153, 0.85);
    background: rgba(255, 240, 246, 0.8);
}

/* Hide envelope when letter is open */
.envelope-wrapper.open .envelope {
    opacity: 0.3;
    transition: opacity 0.5s ease-out 0.3s;
}

/* Heart-shaped container for back of letter image */
.heart-container {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
}

.heart-container::before,
.heart-container::after {
  content: "";
  position: absolute;
  top: 0;
  width: 100px;
  height: 160px;
  border-radius: 100px 100px 0 0;
  background: rgba(255, 192, 203, 0.8); /* Light pink with transparency */
}

.heart-container::before {
  left: 50px;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
}

.heart-container::after {
  left: 50px;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

.heart-container img {
  position: relative;
  width: 80%;
  height: 80%;
  margin: 10%;
  z-index: 1;
  object-fit: cover;
  border-radius: 10px;
}

/* Birthday Greeting Styles */
.birthday-greeting {
    font-family: 'Comic Sans MS', 'Marker Felt', cursive;
    font-size: 2.5rem;
    color: #ff6699;
    text-align: center;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    transform: rotate(-5deg);
    position: relative;
    z-index: 10; /* Lower than letterbox */
    animation: bounce 1.5s infinite alternate;
    padding: 20px 0;
}

/* Bounce animation for the greeting */
@keyframes bounce {
    from {
        transform: translateY(0) rotate(-5deg);
    }
    to {
        transform: translateY(-10px) rotate(-5deg);
    }
}

/* Balloon animation styles */
.balloon {
  position: fixed;
  width: 120px; /* Doubled from 60px to 120px */
  height: auto;
  z-index: 100;
  bottom: -100px;
  opacity: 0;
  pointer-events: none;
  animation: float-up 10s linear forwards;
}

.balloon.left {
  left: 5%;
}

.balloon.right {
  right: 5%;
}

@keyframes float-up {
  0% {
    bottom: -100px;
    opacity: 0;
    transform: translateX(0) rotate(-5deg);
  }
  10% {
    opacity: 1;
  }
  25% {
    transform: translateX(15px) rotate(5deg);
  }
  50% {
    transform: translateX(-15px) rotate(-5deg);
  }
  75% {
    transform: translateX(15px) rotate(5deg);
  }
  90% {
    opacity: 1;
  }
  100% {
    bottom: 100vh;
    opacity: 0;
    transform: translateX(0) rotate(5deg);
  }
}

/* Additional balloon variants for staggered animation */
.balloon:nth-child(2n) {
  animation-duration: 12s;
  animation-delay: 0.5s;
}

.balloon:nth-child(3n) {
  animation-duration: 11s;
  animation-delay: 1s;
}

.balloon:nth-child(4n) {
  animation-duration: 13s;
  animation-delay: 1.5s;
}

/* Letterbox Styles - Old Cardboard Box Design */
.letterbox-wrapper {
    position: absolute;
    right: -100px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 100;
}

.letterbox-button {
    width: 70px;
    height: 50px;
    border: 2px solid #8b6914;
    border-radius: 8px;
    background: linear-gradient(145deg, #d4af37, #b8941f);
    background-image: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 2px,
            rgba(139, 105, 20, 0.1) 2px,
            rgba(139, 105, 20, 0.1) 4px
        );
    color: #5d4e37;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 
        0 4px 8px rgba(139, 105, 20, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Add cardboard texture lines */
.letterbox-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(0deg, rgba(139, 105, 20, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(139, 105, 20, 0.1) 1px, transparent 1px);
    background-size: 8px 8px;
    border-radius: 6px;
    pointer-events: none;
}

.letterbox-button:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 
        0 6px 12px rgba(139, 105, 20, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    background: linear-gradient(145deg, #dbb942, #c49e23);
}

/* Letterbox Container - now at root level */
.letterbox-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 9999; /* Ensure it's above everything */
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(4px);
    padding: 15px;
    box-sizing: border-box;
    pointer-events: none; /* Initially doesn't capture clicks */
}

.letterbox-container.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto; /* Captures clicks when visible */
}

.letterbox-content {
    background: #f4e4bc;
    background-image: 
        radial-gradient(circle at 20% 50%, rgba(139, 105, 20, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(139, 105, 20, 0.1) 0%, transparent 50%),
        linear-gradient(0deg, rgba(139, 105, 20, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(139, 105, 20, 0.05) 1px, transparent 1px);
    background-size: 100px 100px, 100px 100px, 12px 12px, 12px 12px;
    border: 4px solid #8b6914;
    border-radius: 10px;
    width: 90%;
    max-width: 750px;
    height: 85%;
    max-height: 650px;
    min-height: 450px;
    min-width: 300px;
    overflow: hidden;
    box-shadow: 
        0 20px 40px rgba(0, 0, 0, 0.5),
        inset 0 1px 0 rgba(255, 255, 255, 0.3),
        inset 0 -1px 0 rgba(139, 105, 20, 0.3);
    display: flex;
    flex-direction: column;
    position: relative;
    margin: auto;
    box-sizing: border-box;
    animation: popup 0.4s ease-out;
}

@keyframes popup {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.letterbox-header {
    background: linear-gradient(145deg, #8b6914, #6d5411);
    background-image: 
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 3px,
            rgba(0, 0, 0, 0.1) 3px,
            rgba(0, 0, 0, 0.1) 6px
        );
    color: #f4e4bc;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #5d4e37;
    position: relative;
    flex-shrink: 0;
}

/* Add tape effect to header */
.letterbox-header::after {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 6px;
    background: linear-gradient(90deg, #d4af37, #b8941f, #d4af37);
    border-radius: 3px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.letterbox-header h3 {
    margin: 0;
    font-size: 1.6rem;
    font-family: 'Times New Roman', serif;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 1px;
}

.close-btn {
    background: rgba(244, 228, 188, 0.2);
    border: 1px solid #8b6914;
    color: #f4e4bc;
    font-size: 20px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-weight: bold;
}

.close-btn:hover {
    background: rgba(244, 228, 188, 0.4);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.stored-letters {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: rgba(255, 255, 255, 0.15);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
    justify-items: center;
    align-content: start;
    min-height: 0;
}

.letterbox-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 18px 20px;
    border-top: 2px solid rgba(93, 78, 55, 0.25);
    background: rgba(139, 105, 20, 0.12);
    flex-shrink: 0;
}

.action-btn {
    border: 2px solid #8b6914;
    border-radius: 6px;
    background: #fff7df;
    color: #5d4e37;
    cursor: pointer;
    font-family: 'Times New Roman', serif;
    font-size: 0.9rem;
    font-weight: bold;
    padding: 12px 18px;
    transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.action-btn:hover {
    background: #fff1c2;
    box-shadow: 0 4px 8px rgba(93, 78, 55, 0.18);
    transform: translateY(-1px);
}

/* Improved envelope styling */
.mini-envelope {
    width: 130px;
    height: 85px;
    position: relative;
    cursor: pointer;
    transition: all 0.3s ease;
    transform-style: preserve-3d;
    z-index: 1;
}

.mini-envelope:hover {
    transform: translateY(-5px) scale(1.08);
    filter: brightness(1.15);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    z-index: 2;
}

.mini-envelope:active {
    transform: translateY(-2px) scale(1.05);
}

.mini-envelope-body {
    width: 100%;
    height: 100%;
    background: linear-gradient(145deg, #ffffff, #f5f5f5);
    border: 2px solid #ccc;
    border-radius: 6px;
    position: relative;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.mini-envelope-flap {
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 65px solid transparent;
    border-right: 65px solid transparent;
    border-top: 35px solid #e8e8e8;
    z-index: 2;
    border-radius: 2px 2px 0 0;
}

.mini-stamp {
    position: absolute;
    top: 7px;
    right: 7px;
    width: 18px;
    height: 18px;
    background: linear-gradient(145deg, #ff6b6b, #ff5252);
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 3;
}

.envelope-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    z-index: 3;
    background: rgba(255, 255, 255, 0.7);
    padding: 4px;
    border-radius: 3px;
}

.envelope-title {
    font-size: 11px;
    font-weight: bold;
    color: #333;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: 'Times New Roman', serif;
    text-align: center;
}

.envelope-date {
    font-size: 9px;
    color: #666;
    font-family: 'Courier New', monospace;
    text-align: center;
}

/* Remove button styles that are no longer needed */
.envelope-actions,
.open-letter-btn,
.delete-letter-btn {
    display: none;
}

/* Hide old styles that are no longer needed */
.stored-letter-item,
.letter-preview,
.letter-timestamp,
.letter-snippet,
.letter-actions,
.load-letter-btn {
    display: none;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 768px) {
    .letterbox-content {
        width: 95%;
        height: 95%;
        max-height: 95vh;
        max-width: 650px;
        padding: 0;
    }
    
    .stored-letters {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 10px;
        padding: 12px;
    }
    
    .mini-envelope {
        width: 90px;
        height: 60px;
    }
    
    .mini-envelope-flap {
        border-left: 45px solid transparent;
        border-right: 45px solid transparent;
        border-top: 25px solid #e8e8e8;
    }
    
    .letterbox-header {
        padding: 15px;
    }
    
    .letterbox-actions {
        padding: 15px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .action-btn {
        padding: 10px 16px;
        font-size: 0.75rem;
        flex: 1;
        min-width: 120px;
    }
}

@media (max-width: 480px) {
    .letterbox-content {
        width: 98%;
        height: 98%;
        border-radius: 4px;
    }
    
    .letterbox-container {
        padding: 4px;
    }
    
    .stored-letters {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 8px;
        padding: 10px;
    }
    
    .mini-envelope {
        width: 80px;
        height: 50px;
    }
    
    .mini-envelope-flap {
        border-left: 40px solid transparent;
        border-right: 40px solid transparent;
        border-top: 20px solid #e8e8e8;
    }
    
    /* ...existing responsive styles... */
}

/* ...existing code... */
