/* --- Letter Page Styles --- */

/* --- Base Layout --- */
body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: radial-gradient(ellipse at center, #2a2a2a 0%, #1a1a1a 70%);
    overflow-x: hidden;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    box-shadow: inset 0 0 200px rgba(0, 0, 0, 0.8);
    z-index: 1;
}

/* --- Back Button --- */
.back-button {
    position: fixed;
    top: 25px;
    left: 25px;
    color: #e8dcc8;
    text-decoration: none;
    font-size: 1.5rem;
    font-family: 'Creepster', cursive;
    background-color: #2d2820;
    padding: 10px 20px;
    border-radius: 3px;
    border: 2px solid #4a3f35;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.6),
        inset 0 0 20px rgba(0, 0, 0, 0.3);
    transform: rotate(-4deg);
    transition: all 0.3s ease;
    z-index: 100;
}

.back-button:hover {
    transform: rotate(0deg) scale(1.05);
    border-color: #ff6b35;
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(255, 107, 53, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.3);
    color: #ffd7a8;
}

.back-button:focus-visible {
    outline: 3px solid #ff6b35;
    outline-offset: 2px;
}

/* --- Floating Heart Particles --- */
.hearts-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 2;
}

.heart {
    position: absolute;
    width: 20px;
    height: 20px;
    background-image: url('../assets/pink_heart.png');
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
    animation: float-heart 15s infinite ease-in-out;
}

.heart:nth-child(1) { left: 10%; animation-delay: 0s; }
.heart:nth-child(2) { left: 25%; animation-delay: 3s; }
.heart:nth-child(3) { left: 45%; animation-delay: 6s; }
.heart:nth-child(4) { left: 65%; animation-delay: 9s; }
.heart:nth-child(5) { left: 80%; animation-delay: 12s; }
.heart:nth-child(6) { left: 90%; animation-delay: 2s; }

@keyframes float-heart {
    0% {
        transform: translateY(100vh) scale(0.5) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 0.6;
    }
    90% {
        opacity: 0.6;
    }
    100% {
        transform: translateY(-100px) scale(1.2) rotate(360deg);
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .heart {
        animation: none;
        display: none;
    }
}

/* --- Envelope Scene Container --- */
.envelope-scene {
    position: relative;
    width: 90vw;
    max-width: 700px;
    height: 90vh;
    max-height: 700px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.spotlight {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 120%;
    height: 120%;
    background: radial-gradient(circle, rgba(255, 107, 53, 0.15) 0%, transparent 60%);
    pointer-events: none;
    z-index: -1;
}

/* --- Envelope Container --- */
.envelope-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.envelope-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.8s ease-in-out;
}

.envelope-closed {
    opacity: 1;
    z-index: 2;
}

.envelope-open {
    opacity: 0;
    z-index: 1;
}

.envelope-seal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20%;
    max-width: 120px;
    height: auto;
    cursor: pointer;
    z-index: 15;
    transition: all 0.3s ease;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}

.envelope-seal:hover {
    filter: drop-shadow(0 4px 12px rgba(255, 107, 53, 0.6))
            drop-shadow(0 0 20px rgba(255, 107, 53, 0.4));
    transform: translate(-50%, -50%) scale(1.05);
}

.envelope-seal:focus-visible {
    outline: 3px solid #ff6b35;
    outline-offset: 5px;
    border-radius: 50%;
}

/* --- Animation State Classes --- */

.envelope-seal.fade-out {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
    pointer-events: none;
}

.envelope-closed.hidden {
    opacity: 0;
}

.envelope-open.visible {
    opacity: 1;
}

/* --- The Letter - Unfold Animation --- */

.letter {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.3);
    transform-origin: center center;
    width: 85%;
    max-width: 750px;
    height: auto;
    z-index: 10;
    opacity: 0;
    transition:
        top 1s ease-out,
        transform 1s cubic-bezier(0.34, 1.56, 0.64, 1),
        opacity 0.8s ease-out;
}

.letter.revealed {
    top: 20%;
    transform: translate(-50%, -20%) scale(1);
    opacity: 1;
}

.letter.glowing {
    filter: drop-shadow(0 0 30px rgba(255, 107, 53, 0.3));
}

/* --- Letter Content Container --- */
.letter-content {
    position: relative;
    width: 100%;
    padding: 40px 30px;
    box-sizing: border-box;
    background-color: #2d2820;
    background-image:
        /* Paper texture - fine grain */
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.03) 2px,
            rgba(0, 0, 0, 0.03) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.03) 2px,
            rgba(0, 0, 0, 0.03) 4px
        ),
        /* Coffee stains - scattered organic spots */
        radial-gradient(
            ellipse at 20% 30%,
            rgba(50, 40, 20, 0.15) 0%,
            transparent 40%
        ),
        radial-gradient(
            ellipse at 80% 70%,
            rgba(40, 30, 15, 0.1) 0%,
            transparent 35%
        ),
        radial-gradient(
            ellipse at 65% 15%,
            rgba(45, 35, 20, 0.12) 0%,
            transparent 30%
        ),
        /* Base gradient for depth */
        linear-gradient(
            135deg,
            #2d2820 0%,
            #2a251d 50%,
            #272218 100%
        );
    box-shadow:
        /* Dramatic multi-layer shadows */
        0 12px 24px rgba(0, 0, 0, 0.6),
        0 6px 12px rgba(0, 0, 0, 0.4),
        0 3px 6px rgba(0, 0, 0, 0.3),
        /* Inner shadow for depth */
        inset 0 0 60px rgba(0, 0, 0, 0.4),
        inset 0 0 20px rgba(0, 0, 0, 0.2);
    /* Torn edges using clip-path */
    clip-path: polygon(
        /* Top edge - organic tears */
        0% 2%, 3% 1%, 7% 2.5%, 12% 1%, 18% 2%, 23% 0.5%,
        29% 2%, 35% 1.5%, 42% 2.5%, 48% 1%, 54% 2%,
        61% 1.5%, 67% 2.5%, 73% 1%, 79% 2%, 85% 1.5%,
        91% 2%, 96% 1%, 100% 2%,
        /* Right edge */
        99% 8%, 100% 15%, 99.5% 22%, 100% 30%, 99% 38%,
        100% 46%, 99.5% 54%, 100% 62%, 99% 70%, 100% 78%,
        99.5% 86%, 100% 92%, 99% 98%,
        /* Bottom edge */
        96% 99%, 91% 98%, 85% 99.5%, 79% 98%, 73% 99%,
        67% 98.5%, 61% 99.5%, 54% 98%, 48% 99%, 42% 98.5%,
        35% 99.5%, 29% 98%, 23% 99%, 18% 98.5%, 12% 99%,
        7% 98.5%, 3% 99%, 0% 98%,
        /* Left edge */
        1% 92%, 0% 86%, 1.5% 78%, 0% 70%, 1% 62%,
        0% 54%, 1.5% 46%, 0% 38%, 1% 30%, 0% 22%,
        1.5% 15%, 0% 8%
    );
    border-radius: 4px;
    font-family: 'Crimson Text', serif;
    font-size: 1.25rem;
    line-height: 1.7;
    color: #e8dcc8;
    /* Enhanced texture and aged appearance */
    filter: contrast(1.08) brightness(0.92) saturate(0.95);
}

/* --- Letter Content Typography --- */
.letter-content p {
    margin: 0 0 15px 0;
    text-align: justify;
}

.letter-content p:last-child {
    margin-bottom: 0;
}

.letter-salutation {
    font-family: 'Dancing Script', cursive;
    font-size: 2.5rem;
    font-weight: 700;
    margin: 0 0 20px 0;
    color: #d4a574;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.letter-closing {
    margin-top: 20px !important;
    text-align: right;
    font-style: italic;
}

.letter-signature {
    font-family: 'Dancing Script', cursive;
    font-size: 2rem;
    font-weight: 700;
    display: block;
    margin-top: 10px;
    color: #d4a574;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .envelope-scene {
        width: 95vw;
        height: auto;
        padding: 20px 0;
    }

    .envelope-container {
        max-width: 90vw;
    }

    .envelope-seal {
        width: 25%;
        max-width: 100px;
    }

    .letter {
        width: 90%;
        max-width: 90vw;
    }

    .letter.revealed {
        top: 50%;
        transform: translate(-50%, -50%) scale(1);
    }

    .letter-content {
        padding: 30px 20px;
        font-size: 1rem;
        max-height: 75vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .letter-salutation {
        font-size: 2rem;
        margin-bottom: 15px;
    }

    .letter-signature {
        font-size: 1.5rem;
    }

    .back-button {
        top: 15px;
        left: 15px;
        font-size: 1.2rem;
        padding: 8px 16px;
    }
}

@media (max-width: 480px) {
    .letter {
        width: 95%;
    }

    .letter.revealed {
        top: 50%;
        transform: translate(-50%, -50%) scale(1);
    }

    .letter-content {
        padding: 25px 15px;
        font-size: 0.95rem;
        line-height: 1.6;
        max-height: 80vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .letter-salutation {
        font-size: 1.75rem;
        margin-bottom: 10px;
    }

    .letter-signature {
        font-size: 1.4rem;
    }
}

/* --- Reduced Motion Accessibility --- */
@media (prefers-reduced-motion: reduce) {
    /* Disable transforms and use simple fade-in instead */
    .envelope-seal,
    .envelope-image {
        transition: opacity 0.3s ease-out;
    }

    .letter {
        transition: opacity 0.5s ease-out;
        transform: translate(-50%, -50%) !important;
    }

    /* Skip the unfold animation, just fade in at final position */
    .letter.revealed {
        top: 20%;
        opacity: 1;
    }

    .spotlight {
        animation: none;
    }

        .spider-container {
        display: none;
    }
}

/* --- Cute Spider with Bow --- */

/* --- Spider Container & Web String --- */
.spider-container {
    position: fixed;
    top: -100px; /* Hidden above viewport initially */
    right: 50px;
    z-index: 50; /* Above everything except back button */
    transform: translateY(0);
    transition: none; /* Will be animated via keyframes */
}

.spider-container::before {
    content: '';
    position: absolute;
    bottom: 100%; /* Extends upward from spider */
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 200px; /* Extends well above viewport */
    background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.9) 0%,
        rgba(255, 255, 255, 0.8) 50%,
        rgba(255, 255, 255, 0.7) 100%
    );
    box-shadow: 0 0 4px rgba(255, 255, 255, 0.5);
    pointer-events: none;
}

/* --- Spider Structure --- */
.spider {
    position: relative;
    width: 50px;
    height: 45px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.spider-body {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 35px;
    height: 35px;
    background: linear-gradient(135deg, #2a1a3a 0%, #1a0a2a 100%); /* Dark purple */
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    z-index: 1; /* Body on top of legs */
}

.spider-eye {
    position: absolute;
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    top: 12px;
    box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.3);
}

.spider-eye-left {
    left: 8px;
}

.spider-eye-right {
    right: 8px;
}

.spider-eye::after {
    content: '';
    position: absolute;
    width: 4px;
    height: 4px;
    background: #000;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -30%); /* Slightly upward for that "looking up" effect */
}

.spider-blush {
    position: absolute;
    width: 6px;
    height: 5px;
    background: rgba(255, 182, 193, 0.6); /* Light pink */
    border-radius: 50%;
    top: 20px;
}

.spider-blush-left {
    left: 3px;
}

.spider-blush-right {
    right: 3px;
}

.spider-bow {
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    background: #ffb6c1;
    border-radius: 50%;
    z-index: 2;
}

.spider-bow::before,
.spider-bow::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

.spider-bow::before {
    border-width: 5px 0 5px 6px;
    border-color: transparent transparent transparent #ffb6c1;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
}

.spider-bow::after {
    border-width: 5px 6px 5px 0;
    border-color: transparent #ffb6c1 transparent transparent;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
}

/* --- Spider Legs --- */
.spider-legs {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.leg {
    position: absolute;
    width: 30px;
    height: 3px;
    background: linear-gradient(135deg, #2a1a3a 0%, #1a0a2a 100%); /* Match spider body */
    border-radius: 1px;
}

/* Left side legs - extend from left side of body */
.leg-1 {
    top: 30%;
    left: 0;
    width: 35px; /* Longer for steeper angle */
    transform-origin: right center;
    transform: rotate(-50deg);
}
.leg-2 {
    top: 40%;
    left: 0;
    transform-origin: right center;
    transform: rotate(-25deg);
}
.leg-3 {
    top: 60%;
    left: 0;
    transform-origin: right center;
    transform: rotate(25deg);
}
.leg-4 {
    top: 70%;
    left: 0;
    width: 35px; /* Longer for steeper angle */
    transform-origin: right center;
    transform: rotate(50deg);
}

/* Right side legs - extend from right side of body */
.leg-5 {
    top: 30%;
    right: 0;
    width: 35px; /* Longer for steeper angle */
    transform-origin: left center;
    transform: rotate(50deg);
}
.leg-6 {
    top: 40%;
    right: 0;
    transform-origin: left center;
    transform: rotate(25deg);
}
.leg-7 {
    top: 60%;
    right: 0;
    transform-origin: left center;
    transform: rotate(-25deg);
}
.leg-8 {
    top: 70%;
    right: 0;
    width: 35px; /* Longer for steeper angle */
    transform-origin: left center;
    transform: rotate(-50deg);
}

/* --- Spider Animations --- */

@keyframes spider-descend {
    0% {
        transform: translateY(0);
    }
    100% {
        transform: translateY(180px); /* Final position: 80px from top of viewport */
    }
}

@keyframes spider-bob {
    0%, 100% {
        transform: translateY(180px);
    }
    50% {
        transform: translateY(188px); /* 8px downward bob */
    }
}

.spider-container.descending {
    animation: spider-descend 3s ease-in-out forwards;
}

.spider-container.bobbing {
    animation: spider-bob 4s ease-in-out infinite;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .spider-container {
        right: 30px;
        top: -80px;
    }

    .spider {
        width: 40px;
        height: 36px;
    }

    .spider-body {
        width: 28px;
        height: 28px;
    }

    .spider-eye {
        width: 6px;
        height: 6px;
        top: 10px;
    }

    .spider-eye-left {
        left: 6px;
    }

    .spider-eye-right {
        right: 6px;
    }

    .leg {
        width: 14px;
    }

    @keyframes spider-descend {
        0% {
            transform: translateY(0);
        }
        100% {
            transform: translateY(140px);
        }
    }

    @keyframes spider-bob {
        0%, 100% {
            transform: translateY(140px);
        }
        50% {
            transform: translateY(148px);
        }
    }
}

@media (max-width: 480px) {
    .spider-container {
        right: 15px;
    }
}

/* --- Vintage TV Photo Rotator --- */

/* --- TV Container --- */
.vintage-tv-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 450px; /* Increased size - using more of the 1024x1024 resolution */
    height: auto;
    z-index: 45; /* Below spider (50) but above most other elements */
    pointer-events: none; /* Non-interactive */
}

/* --- TV Screen (where photos appear) --- */
.tv-screen {
    position: absolute;
    top: 22%;
    left: 27%;
    width: 54%;
    height: 45%;
    background: #000;
    overflow: hidden;
    border-radius: 8% / 10%; /* Elliptical radius for curved CRT screen */
    z-index: 1;
    box-shadow:
        inset 0 0 20px rgba(100, 200, 255, 0.2),
        0 0 15px rgba(100, 200, 255, 0.3);
}

/* --- Individual Photo Slides --- */
.tv-photo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    height: 90%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.8s ease-in-out;
}

.tv-photo.active {
    opacity: 1;
}

/* --- TV Frame Overlay --- */
.tv-frame {
    position: relative;
    width: 100%;
    height: auto;
    display: block;
    z-index: 2;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.4));
}

/* --- Pulsing Screen Glow Effect --- */
@keyframes tv-glow {
    0%, 100% {
        box-shadow:
            inset 0 0 20px rgba(100, 200, 255, 0.2),
            0 0 15px rgba(100, 200, 255, 0.3);
    }
    50% {
        box-shadow:
            inset 0 0 25px rgba(100, 200, 255, 0.3),
            0 0 20px rgba(100, 200, 255, 0.4);
    }
}

.tv-screen {
    animation: tv-glow 4s ease-in-out infinite;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .vintage-tv-container {
        bottom: 15px;
        right: 15px;
        width: 350px;
    }
}

@media (max-width: 480px) {
    .vintage-tv-container {
        bottom: 10px;
        right: 10px;
        width: 280px;
    }
}

/* --- Reduced Motion Accessibility --- */
@media (prefers-reduced-motion: reduce) {
    .tv-screen {
        animation: none;
        box-shadow:
            inset 0 0 20px rgba(100, 200, 255, 0.2),
            0 0 15px rgba(100, 200, 255, 0.3);
    }

    .tv-photo {
        transition: opacity 0.3s ease-out;
    }
}

/* --- Video Modal --- */
.video-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-in-out;
}

.video-modal.active {
    opacity: 1;
    pointer-events: all;
}

.video-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 10, 0.95);
    cursor: pointer;
}

.video-modal-content {
    position: relative;
    width: 90%;
    max-width: 900px;
    aspect-ratio: 16 / 9;
    z-index: 1001;
    transform: scale(0.8);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.video-modal.active .video-modal-content {
    transform: scale(1);
}

.video-frame {
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    box-shadow:
        0 0 60px rgba(255, 107, 53, 0.3),
        0 20px 40px rgba(0, 0, 0, 0.8),
        inset 0 0 0 3px #2d2820,
        inset 0 0 0 6px #4a3f35;
    border: 2px solid #8b4513;
}

.video-close-btn {
    position: absolute;
    top: -50px;
    right: 0;
    width: 40px;
    height: 40px;
    background: #2d2820;
    border: 2px solid #8b4513;
    border-radius: 50%;
    color: #e8dcc8;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    box-shadow:
        0 4px 8px rgba(0, 0, 0, 0.6),
        inset 0 0 20px rgba(0, 0, 0, 0.3);
    z-index: 1002;
}

.video-close-btn:hover {
    background: #3a2f25;
    border-color: #ff6b35;
    color: #ffd7a8;
    transform: scale(1.1);
    box-shadow:
        0 6px 12px rgba(0, 0, 0, 0.8),
        0 0 20px rgba(255, 107, 53, 0.4),
        inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.video-close-btn:focus-visible {
    outline: 3px solid #ff6b35;
    outline-offset: 2px;
}

/* --- Responsive Design for Video Modal --- */
@media (max-width: 768px) {
    .video-modal-content {
        width: 95%;
    }

    .video-close-btn {
        top: -45px;
        width: 36px;
        height: 36px;
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .video-modal-content {
        width: 98%;
    }

    .video-close-btn {
        top: -40px;
        width: 32px;
        height: 32px;
        font-size: 18px;
    }

    .video-frame {
        border-radius: 4px;
    }
}

/* --- Reduced Motion for Video Modal --- */
@media (prefers-reduced-motion: reduce) {
    .video-modal,
    .video-modal-content {
        transition: opacity 0.2s ease-out;
    }

    .video-modal.active .video-modal-content {
        transform: scale(1);
    }
}
