/* Base Styles */
html, body {
    height: 100%;
    background: linear-gradient(180deg, #0a1628 0%, #1a2a4a 30%, #2a4a6a 60%, #1a3a5a 100%);
    color: #f0f0f0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    overflow: hidden;
}

#app {
    position: relative;
    width: 100%;
    height: 100svh; /* Use svh for iOS compatibility */
    min-height: 100vh; /* Fallback for older browsers */
}

/* Screen Base */
.screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    transition: opacity 0.5s ease;
}

/* Screen Utility Classes */
.screen-active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    z-index: 2;
}

.screen-inactive {
    opacity: 0;
    pointer-events: none;
    visibility: visible;
    z-index: 1;
}

/* Intro Screen */
#intro-screen {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    text-align: center;
}

#intro-screen h1 {
    font-size: clamp(1rem, 2vw, 1.5rem);
    font-weight: 700;
    letter-spacing: 0.1em;  
    margin-bottom: 1.5rem;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
}

#intro-screen p {
    font-size: clamp(1.5rem, 3vw, 2rem);
    letter-spacing: 0.05em;
    margin-bottom: 3rem;
    color: #e0e0e0;
    opacity: 0.9;
}

.intro-hint {
    font-size: clamp(0.875rem, 2vw, 1rem);
    color: #b0b0b0;
    opacity: 0.7;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    animation: fadeInOut 2s ease-in-out infinite;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0.4; }
}

/* Main Screen */
#main-screen {
    overflow: hidden;
    /* Background removed - video background will show instead */
}

/* Video Background */
.video-background {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: -2;
    pointer-events: none;
    background: linear-gradient(180deg, #0a1628 0%, #1a2a4a 30%, #2a4a6a 60%, #1a3a5a 100%);
}

#background-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    min-width: 100%;
    min-height: 100%;
}

/* Fallback gradient overlay for better text readability (optional dimming) */
.video-background::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(10, 22, 40, 0.3) 0%, rgba(26, 42, 74, 0.2) 50%, rgba(42, 74, 106, 0.2) 100%);
    pointer-events: none;
}

/* Envelope Teaser */
#envelope-teaser {
    position: absolute;
    bottom: clamp(1.5rem, 4vw, 3rem);
    right: clamp(1rem, 4vw, 3rem);
    display: inline-flex;
    align-items: center;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    cursor: pointer;
    padding: clamp(0.6rem, 2vw, 0.75rem) clamp(1rem, 3vw, 1.25rem);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    z-index: 10;
    /* Ensure touch-friendly minimum size */
    min-height: 44px;
}

#envelope-teaser.hidden {
    display: none;
}

#envelope-teaser:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.envelope-image {
    width: clamp(50px, 6vw, 60px);
    height: clamp(35px, 4vw, 40px);
    background: linear-gradient(135deg, #d4a574 0%, #c8966a 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.envelope-image::before {
    content: '';
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: clamp(25px, 3vw, 30px) solid transparent;
    border-right: clamp(25px, 3vw, 30px) solid transparent;
    border-top: clamp(18px, 2vw, 20px) solid #b8865a;
}

.envelope-text {
    font-size: clamp(0.875rem, 2vw, 1rem);
    font-weight: 500;
    letter-spacing: 0.05em;
    color: #ffffff;
}

/* Envelope Stage - Overlay */
#envelope-stage {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    padding: 2rem;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

#envelope-stage.overlay-active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

#envelope-stage.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.envelope-container {
    position: relative;
    max-width: min(90vw, 600px);
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: clamp(1rem, 3vw, 1.5rem);
}

/* Envelope Body - Responsive with clamp() */
.envelope-body {
    width: 100%;
    /* Use clamp() for smooth scaling: min 180px, ideal 30vw, max 300px */
    max-width: clamp(180px, 30vw, 300px);
    /* Use aspect-ratio to prevent distortion - maintains 300:181 ratio */
    aspect-ratio: 300 / 181;
    height: auto;
    /* CSS variable for flap scaling - scales with envelope width */
    --envelope-width: clamp(180px, 30vw, 300px);
    background: linear-gradient(135deg, #d4a574 0%, #c8966a 100%);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px 6px 3px 3px;
    position: relative;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    perspective: 1000px;
    transform-style: preserve-3d;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.envelope-body.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* Envelope Flap */
.envelope-flap {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    /* Scale flap proportionally with envelope body - base: 151px of 300px = 50.33% */
    border-left: calc(var(--envelope-width) * 0.5033) solid transparent;
    border-right: calc(var(--envelope-width) * 0.5033) solid transparent;
    /* border-top: 48px of 300px = 16% */
    border-top: calc(var(--envelope-width) * 0.16) solid #b8865a;
    transform-origin: 50% 0;
    z-index: 2;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    transform-style: preserve-3d;
    backface-visibility: visible;
    transition: opacity 0.5s ease;
}

.envelope-flap.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Envelope Inner Shadow */
.envelope-inner-shadow {
    position: absolute;
    inset: 5px;
    border: 1.5px solid rgba(0, 0, 0, 0.1);
    border-radius: 3px;
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.5s ease;
}

.envelope-inner-shadow.hidden {
    opacity: 0;
}

/* Letter
 * ============================================================================
 * ROOT CAUSE ANALYSIS (for documented layout issues):
 * 
 * (a) WRONG CONTAINER SIZING: Previously had min-height: 800px + aspect-ratio: 3/2
 *     which inflated the container far beyond the actual image dimensions,
 *     creating empty transparent space around the letter.png.
 * 
 * (b) OBJECT-FIT CONTAIN + UNDERSIZED IMAGE: The image was set to width: 70%; 
 *     height: 70% with object-fit: contain, causing letterboxing and padding
 *     inside an already oversized container.
 * 
 * (c) BOX-SHADOW ON CONTAINER: Applied box-shadow to .letter container made
 *     the rectangular bounding box visible around the transparent PNG.
 *     FIX: Use filter: drop-shadow() on .letter-image instead to follow PNG shape.
 * 
 * (d) GSAP INLINE TRANSFORMS: GSAP applies transform via inline styles.
 *     The old .letter-hidden had transform: translateX(-50%) translateY(20px)
 *     which conflicted with centering. FIX: Use CSS positioning for base layout,
 *     let GSAP only animate relative changes (y, opacity).
 * 
 * (e) MOBILE HEIGHT MISMATCH (FIXED): CSS Grid with both image and content in
 *     same grid area caused content padding/flex layout to influence grid cell
 *     sizing differently on viewports, creating height mismatch between article
 *     and image. FIX: Image defines wrapper size (normal flow), content is
 *     absolutely positioned with inset:0, wrapper has overflow:hidden.
 * ============================================================================
 */

/* ===== iPhone Letter Sizing Fix ===== */
/* 
 * ROOT CAUSE: CSS Grid layout with both image and content in same grid area
 * caused content's padding and flex layout to affect grid cell sizing,
 * creating height mismatch between article.letter and img.letter-image on
 * some iPhone viewports.
 * 
 * FIX: 
 * - Removed CSS Grid (display:grid, grid-template-areas, grid-area)
 * - Wrapper uses position:relative (already absolute for positioning)
 * - Image stays in normal flow (width:100%, height:auto, display:block)
 * - Content positioned absolutely (position:absolute, inset:0) so it doesn't
 *   affect wrapper sizing
 * - Added overflow:hidden to wrapper as hard safety net
 * - Result: wrapper height ALWAYS matches image height, text never escapes
 */

.letter {
    position: absolute;
    /* Position letter above envelope - adjusted for natural sizing */
    top: -30%;
    left: 50%;
    /* Base transform for centering - GSAP will add translateY on top */
    transform: translate(-50%, -50%);
    
    /* Let the image dictate size - use clamp() for better phone sizing */
    /* Increased min from 250px to 280px for better phone visibility */
    max-width: clamp(280px, 55vw, 551px);
    width: auto;

    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 6px;
    overflow: hidden; /* Hard safety net: prevents text from escaping image bounds */
    
    z-index: 1;
    transition: opacity 0.4s ease;
    
    /* REMOVED: box-shadow here caused visible rectangle around transparent PNG
     * Shadow is now applied via filter: drop-shadow on .letter-image */
}

.letter-image {
    /* Image in normal flow - wrapper size matches image size */
    width: 100%;
    height: auto;
    display: block;
    
    /* drop-shadow follows the PNG transparency - no rectangular box */
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.35));
}

/* Letter Content Overlay
 * Absolutely positioned on top of image - does NOT affect wrapper sizing.
 * Padding creates margins inside the "paper" boundaries.
 */
.letter-content {
    position: absolute;
    inset: 0; /* Covers entire wrapper/image area */
    
    /* Constrain content to image boundaries */
    overflow: hidden;
    
    /* Padding keeps text within the "paper" margins */
    padding: clamp(1.5rem, 8%, 3rem) clamp(1.25rem, 6%, 2.5rem);
    padding-top: clamp(2rem, 12%, 4rem); /* More top padding for header area */
    
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    text-align: left;
    
    color: #2c2c2c;
    font-size: clamp(0.85rem, 2.5vw, 1.05rem);
    line-height: 1.5;
    
    z-index: 1;
    pointer-events: none; /* Allow clicks to pass through to parent */
}

.letter-content h2 {
    margin-bottom: 0; /* flush with the line below */
    line-height: 1;
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    font-weight: 600;
    color: #1a1a1a;
}

.letter-subline {
    margin: 0;
    margin-top: -0.15em;
    padding: 0;
    line-height: 1;
    display: block;
}

.letter-content p {
    margin: 2.4em 0 0;
    color: #333;
    /* Prevent text overflow - use line-clamp as safety net */
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 8; /* Limit to 8 lines max, adjust as needed */
    line-clamp: 8; /* Standard property for future compatibility */
    max-height: calc(1.5em * 8); /* Fallback: line-height * max-lines */
}

.cn-vertical{
  margin: 1.2em 0 0;
  writing-mode: vertical-rl;
  text-orientation: upright;

  /* відстань між стовпчиками (лініями) */
  line-height: 1.5;     /* зменшуй/збільшуй */
  
  /* вирівнювання праворуч */
  align-self: flex-end;
}


/* Hidden state for letter - simple opacity + pointer-events
 * GSAP handles the y-transform animation separately
 */
.letter-hidden {
    opacity: 0;
    pointer-events: none;
}

/* Visible state (added by JS) */
.letter-visible {
    pointer-events: auto;
}

/* Envelope Hint */
.envelope-hint {
    font-size: clamp(0.75rem, 1.5vw, 0.875rem);
    color: rgba(255, 255, 255, 0.8);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    text-align: center;
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    border-radius: 20px;
    display: inline-block;
    animation: fadeInOut 2s ease-in-out infinite;
    pointer-events: none;
    font-weight: 500;
}

/* Replay Button - Responsive with clamp() */
.replay-button {
    position: absolute;
    top: clamp(1rem, 3vw, 2rem);
    right: clamp(1rem, 3vw, 2rem);
    padding: clamp(0.65rem, 2vw, 0.6rem) clamp(1.2rem, 3.5vw, 1.6rem);
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1.6px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    color: #ffffff;
    font-size: clamp(0.65rem, 1.8vw, 0.7rem);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    /* Ensure touch-friendly minimum size (iOS/Android standard) */
    min-width: 48px;
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.replay-button.visible {
    opacity: 1;
    pointer-events: auto;
}

.replay-button:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.replay-button:active {
    transform: translateY(0);
}

/* Responsive - Tablet */
@media (max-width: 1024px) {
    #intro-screen h1 {
        font-size: clamp(1.75rem, 3.5vw, 2.4rem);
    }

    #intro-screen p {
        font-size: clamp(0.95rem, 2vw, 1.15rem);
    }

    .envelope-container {
        max-width: min(85vw, 550px);
    }

    .envelope-body {
        /* Slightly smaller on tablets */
        max-width: clamp(170px, 28vw, 280px);
        --envelope-width: clamp(170px, 28vw, 280px);
    }

    .letter {
        /* Larger on tablets for better visibility */
        max-width: clamp(270px, 52vw, 497px);
    }
}

/* iPad Air - 5% bigger letter (calculated from default size, not tablet size) */
@media (min-width: 820px) and (max-width: 1023px) {
    .letter {
        /* 5% bigger than default size (280px -> 294px, 55vw -> 58vw, 551px -> 579px) */
        max-width: clamp(294px, 58vw, 579px);
    }
}

/* iPad Pro - 10% bigger letter (calculated from default size, not tablet size) */
@media (min-width: 1024px) and (max-width: 1366px) {
    .letter {
        /* 10% bigger than default size (280px -> 308px, 55vw -> 61vw, 551px -> 606px) */
        max-width: clamp(308px, 61vw, 606px);
    }
}

@media (max-width: 768px) {
    #intro-screen h1 {
        font-size: clamp(1.5rem, 3.5vw, 2.2rem);
        margin-bottom: 1rem;
    }

    #intro-screen p {
        font-size: clamp(0.9rem, 2vw, 1.1rem);
        margin-bottom: 2rem;
    }

    .envelope-container {
        max-width: min(92vw, 500px);
        padding: clamp(0.75rem, 2vw, 1rem);
    }

    .envelope-body {
        /* Larger on mobile for better visibility */
        max-width: clamp(200px, 35vw, 260px);
        --envelope-width: clamp(200px, 35vw, 260px);
    }

    .letter {
        /* Increased min from 220px to 300px for better phone visibility */
        /* Made 5% bigger again: 315px -> 330px, 63vw -> 66vw, 470px -> 495px */
        max-width: clamp(330px, 66vw, 495px);
    }
    
    .letter-image {
        filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.3));
    }
    
    /* Larger text on mobile devices */
    .letter-content {
        font-size: clamp(1.1rem, 3.47vw, 1.33rem);
    }
    
    .letter-content h2 {
        font-size: clamp(1.45rem, 5.57vw, 1.85rem);
    }

    .envelope-hint {
        font-size: clamp(0.7rem, 2vw, 0.875rem);
        padding: clamp(0.5rem, 1.5vw, 0.6rem) clamp(0.8rem, 2.5vw, 1rem);
        margin-top: clamp(0.75rem, 2vw, 1rem);
    }

    .replay-button {
        /* Increased padding and font size for better touch targets */
        padding: clamp(0.7rem, 2.5vw, 0.6rem) clamp(1.3rem, 4vw, 1.6rem);
        font-size: clamp(0.7rem, 2vw, 0.7rem);
    }
}

/* iPad Mini - 5% bigger letter, 5% smaller text */
@media (min-width: 768px) and (max-width: 820px) {
    .letter {
        /* 5% bigger than phone size (330px -> 347px, 66vw -> 69vw, 495px -> 520px) */
        max-width: clamp(347px, 69vw, 520px);
    }
    
    .letter-content {
        /* 5% smaller text (1.1rem -> 1.05rem, 3.47vw -> 3.3vw, 1.33rem -> 1.26rem) */
        font-size: clamp(1.05rem, 3.3vw, 1.26rem);
    }
    
    .letter-content h2 {
        /* 5% smaller text (1.45rem -> 1.38rem, 5.57vw -> 5.3vw, 1.85rem -> 1.76rem) */
        font-size: clamp(1.38rem, 5.3vw, 1.76rem);
    }
}

@media (max-width: 480px) {
    section {
        padding: clamp(0.75rem, 2vw, 1rem);
    }

    #intro-screen h1 {
        font-size: clamp(1.4rem, 3.5vw, 2rem);
    }

    #intro-screen p {
        font-size: clamp(0.85rem, 1.8vw, 1rem);
    }

    .envelope-container {
        max-width: min(95vw, 450px);
        padding: clamp(0.5rem, 1.5vw, 0.75rem);
    }

    .envelope-body {
        /* Larger minimum for better visibility on small phones */
        max-width: clamp(220px, 40vw, 240px);
        --envelope-width: clamp(220px, 40vw, 240px);
    }

    .letter {
        /* Significantly increased min from 200px to 320px for better phone visibility */
        /* Reduced size for better fit on phones */
        width: clamp(320px, 75vw, 450px);
        max-width: clamp(320px, 75vw, 450px);
    }
    
    .letter-image {
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.25));
    }

    .envelope-hint {
        font-size: clamp(0.7rem, 2vw, 0.8rem);
        padding: clamp(0.5rem, 1.5vw, 0.6rem) clamp(0.8rem, 2.5vw, 1rem);
        margin-top: clamp(0.75rem, 2vw, 1rem);
    }

    .replay-button {
        /* Increased size for better touch targets on small phones */
        padding: clamp(0.75rem, 2.5vw, 0.6rem) clamp(1.4rem, 4.5vw, 1.6rem);
        font-size: clamp(0.7rem, 2.2vw, 0.7rem);
    }
}

/* ===== iPhone Responsive Fixes ===== */
/* Targets iPhone viewports: 393px (14 Pro/15/15 Pro), 414px (11), 430px (14 Pro Max/15 Plus/15 Pro Max) */

@media (max-width: 430px) {
    /* Ensure full viewport height on iOS */
    #app {
        height: 100svh;
        min-height: -webkit-fill-available; /* iOS Safari fallback */
    }
    
    .screen {
        min-height: 100svh;
        min-height: -webkit-fill-available;
        padding: clamp(1rem, 3vw, 2rem);
    }
    
    /* Envelope container adjustments for iPhone */
    .envelope-container {
        max-width: min(92vw, 450px);
        padding: clamp(0.5rem, 2vw, 1rem);
        gap: clamp(1rem, 3vw, 1.5rem);
    }
    
    /* Envelope body - larger for better visibility on iPhone */
    .envelope-body {
        max-width: clamp(230px, 42vw, 250px);
        --envelope-width: clamp(230px, 42vw, 250px);
    }
    
    /* Letter sizing - significantly larger for iPhone screens */
    .letter {
        /* Reduced size for better fit on iPhone - using 75vw for reasonable sizing */
        /* On 430px screen: 75vw = 322.5px (reasonable size) */
        width: clamp(300px, 75vw, 420px);
        max-width: clamp(300px, 75vw, 420px);
        /* Adjust top position for better fit on smaller screens */
        top: -25%;
    }
    
    /* Letter content - tighter padding on small screens, ensure no overflow */
    .letter-content {
        padding: clamp(1rem, 6%, 2rem) clamp(1rem, 5%, 2rem);
        padding-top: clamp(1.5rem, 10%, 3rem);
        font-size: clamp(1.1rem, 3.47vw, 1.33rem);
    }
    
    .letter-content h2 {
        font-size: clamp(1.45rem, 5.78vw, 1.8rem);
    }
    
    .letter-content p {
        /* Reduce line-clamp on very small screens if needed */
        -webkit-line-clamp: 6;
        line-clamp: 6; /* Standard property for future compatibility */
        max-height: calc(1.5em * 6);
        margin-top: clamp(1.5em, 4vw, 2.4em);
    }
    
    /* Envelope hint - better sizing for touch */
    .envelope-hint {
        font-size: clamp(0.7rem, 2vw, 0.8rem);
        padding: clamp(0.5rem, 1.5vw, 0.6rem) clamp(0.8rem, 2.5vw, 1rem);
        margin-top: clamp(0.75rem, 2vw, 1rem);
    }
    
    /* Touch-friendly button sizes - increased for better usability */
    .replay-button {
        padding: clamp(0.8rem, 2.5vw, 0.6rem) clamp(1.5rem, 4.5vw, 1.6rem);
        font-size: clamp(0.7rem, 2.2vw, 0.7rem);
        /* Ensure touch target is at least 48x48px (increased from 44px) */
        min-width: 48px;
        min-height: 48px;
    }
    
    /* Envelope teaser - touch-friendly with increased size */
    #envelope-teaser {
        padding: clamp(0.7rem, 2.5vw, 0.75rem) clamp(1.1rem, 3.5vw, 1.25rem);
    }
    
    /* Replace hover with active for touch devices */
    #envelope-teaser:active {
        background: rgba(255, 255, 255, 0.15);
        transform: translateY(-2px);
    }
    
    .replay-button:active {
        background: rgba(255, 255, 255, 0.25);
        border-color: rgba(255, 255, 255, 0.5);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
}

/* Specific adjustments for smaller iPhone widths (393px - 14 Pro, 15, 15 Pro) */
@media (max-width: 393px) {
    .letter {
        /* Increased min from 350px to 320px for better visibility */
        /* Reduced size for better fit on small iPhones */
        width: clamp(300px, 75vw, 400px);
        max-width: clamp(300px, 75vw, 400px);
        top: -20%; /* Less negative offset for smaller screens */
    }
    
    .envelope-body {
        /* Larger minimum for better visibility */
        max-width: clamp(220px, 42vw, 240px);
        --envelope-width: clamp(220px, 42vw, 240px);
    }
    
    .letter-content {
        font-size: clamp(1.05rem, 3.36vw, 1.27rem);
        padding: clamp(0.9rem, 5%, 1.8rem) clamp(0.9rem, 4.5%, 1.8rem);
        padding-top: clamp(1.3rem, 9%, 2.5rem);
    }
    
    .letter-content h2 {
        font-size: clamp(1.39rem, 5.57vw, 1.73rem);
    }
    
    .replay-button {
        /* Ensure buttons are large enough on smallest iPhones */
        padding: clamp(0.8rem, 2.5vw, 0.6rem) clamp(1.5rem, 4.5vw, 1.6rem);
        font-size: clamp(0.7rem, 2.2vw, 0.7rem);
    }
}

/* Landscape orientation adjustments for iPhone */
@media (max-width: 932px) and (max-height: 430px) and (orientation: landscape) {
    .envelope-container {
        max-width: clamp(70%, 75vw, 80%);
        padding: clamp(0.5rem, 1.5vw, 1rem);
    }
    
    .letter {
        /* Made 10% bigger again on phones for landscape: 91vw -> 100vw, 545px -> 600px */
        max-width: min(100vw, 600px);
        top: -15%; /* Adjust for landscape */
    }
    
    .letter-content p {
        -webkit-line-clamp: 4; /* Fewer lines in landscape */
        line-clamp: 4; /* Standard property for future compatibility */
        max-height: calc(1.5em * 4);
    }
}

