/* ==========================================================================
   COLOR PALETTE (DEEP BLUE THEME - MODERN & MASKULIN):
   #3E4B8E — dominant main background (deep blue)
   #FFF4EB — cream (primary text, button backgrounds, photo borders)
   #F6E0B6 — warm accent (sand highlights, line 2 accent, hover states)
   #A5BCC9 — muted blue (date, line 3 accent, subtle borders)
   #3D1534 — dark burgundy (button text, contrast badges, deep shadows)
   ========================================================================== */

:root {
    --bg-main: #3E4B8E;
    --text-main: #FFF4EB;
    --cream: #FFF4EB;
    --warm-accent: #F6E0B6;
    --muted-blue: #A5BCC9;
    --deep-blue: #3E4B8E;
    --dark-burgundy: #3D1534;

    --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Reset & Box Sizing */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-serif);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    width: 100%;
}

body {
    background-color: var(--bg-main);
    height: 100%;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    position: relative;
}

::selection {
    background-color: var(--warm-accent);
    color: var(--dark-burgundy);
}

/* ==========================================================================
   COMPACT FLOATING MUSIC TOGGLE (MINIMALIST & SIMPLE)
   ========================================================================== */
.music-toggle {
    position: fixed;
    top: clamp(0.75rem, 2vh, 1.25rem);
    right: clamp(0.75rem, 2vw, 1.25rem);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 244, 235, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(165, 188, 201, 0.35);
    color: var(--cream);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    transition: all 0.25s ease;
    user-select: none;
    padding: 0;
    opacity: 0.65;
}

.music-toggle:hover {
    opacity: 1;
    background: rgba(255, 244, 235, 0.22);
    border-color: var(--warm-accent);
    color: var(--warm-accent);
    transform: scale(1.08);
}

.music-toggle:active {
    transform: scale(0.92);
}

.music-toggle.is-playing {
    opacity: 1;
    background: rgba(246, 224, 182, 0.16);
    border-color: rgba(246, 224, 182, 0.7);
    color: var(--warm-accent);
}

.music-toggle.is-playing .music-disc {
    animation: spinDisc 6s linear infinite;
}

.music-disc {
    display: block;
    transform-origin: center;
}

@keyframes spinDisc {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ==========================================================================
   STATE 1: OPENING SCREEN (NO-SCROLL, FULL VIEWPORT)
   ========================================================================== */
.opening-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    height: 100dvh;
    width: 100%;
    padding: 1.5rem;
    background-color: var(--bg-main);
    transition: opacity 0.45s ease, visibility 0.45s ease;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
}

.opening-container.is-leaving {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.opening-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    max-width: 480px;
    width: 100%;
}

.opening-line {
    font-family: var(--font-serif);
    font-size: clamp(1.2rem, 3.2vh, 1.55rem);
    font-weight: 400;
    line-height: 1.5;
    color: var(--cream);
    margin-bottom: clamp(0.75rem, 2vh, 1.25rem);
    opacity: 0;
    will-change: opacity;
    letter-spacing: -0.01em;
}

.opening-line.line-1 {
    animation: simpleFadeIn 0.7s ease-out 0.2s forwards;
}

.opening-line.line-2 {
    font-style: italic;
    color: var(--warm-accent);
    animation: simpleFadeIn 0.7s ease-out 1.0s forwards;
}

.opening-line.line-3 {
    color: var(--muted-blue);
    animation: simpleFadeIn 0.7s ease-out 1.9s forwards;
    margin-bottom: clamp(1.75rem, 4vh, 2.75rem);
}

.open-button {
    appearance: none;
    background: var(--cream);
    border: 1px solid var(--warm-accent);
    border-radius: 999px;
    outline: none;
    color: var(--dark-burgundy);
    font-family: var(--font-sans);
    font-size: clamp(0.875rem, 2.2vh, 0.95rem);
    font-weight: 600;
    letter-spacing: 0.04em;
    cursor: pointer;
    padding: 0.5rem 1.45rem;
    opacity: 0;
    will-change: opacity;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
    animation: simpleFadeIn 0.7s ease-out 2.9s forwards;
    transition: all 0.2s ease;
}

.open-button:hover,
.open-button:focus-visible {
    background: var(--warm-accent);
    color: var(--dark-burgundy);
    border-color: var(--cream);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.open-button:active {
    transform: translateY(0);
    opacity: 0.9;
}

/* ==========================================================================
   STATE 2: LETTER SCREEN (NO-OVERLAP RESPONSIVE EDITORIAL FIT)
   ========================================================================== */
.letter-container {
    width: 100%;
    height: 100%;
    height: 100dvh;
    background-color: var(--bg-main);
    padding: clamp(0.75rem, 2.5vh, 2rem) clamp(0.85rem, 3.5vw, 2.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.letter-container.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.letter-wrapper {
    width: 100%;
    max-width: 760px;
    margin: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
}

/* Back Button */
.back-button {
    position: absolute;
    top: clamp(0.25rem, 1.5vh, 1rem);
    left: clamp(0.25rem, 1.5vw, 1rem);
    z-index: 50;
    background: rgba(255, 244, 235, 0.12);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(165, 188, 201, 0.35);
    border-radius: 999px;
    outline: none;
    font-family: var(--font-sans);
    font-size: clamp(0.75rem, 1.8vh, 0.82rem);
    font-weight: 500;
    color: var(--cream);
    cursor: pointer;
    padding: 0.35rem 0.75rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.back-button:hover,
.back-button:focus-visible {
    background: rgba(255, 244, 235, 0.24);
    color: var(--warm-accent);
    border-color: var(--warm-accent);
    transform: translateX(-2px);
}

/* Central Letter Column */
.letter-column {
    max-width: 440px;
    width: 100%;
    margin: 0 auto;
    text-align: left;
    position: relative;
    z-index: 2;
}

.letter-date {
    display: block;
    font-family: var(--font-sans);
    font-size: clamp(0.72rem, 1.7vh, 0.8125rem);
    font-weight: 600;
    color: var(--warm-accent);
    margin-bottom: clamp(0.5rem, 1.5vh, 1.15rem);
    letter-spacing: 0.03em;
    opacity: 0.9;
}

.letter-body {
    font-family: var(--font-serif);
    font-size: clamp(0.82rem, 2vh, 0.96rem);
    line-height: clamp(1.4, 2.3vh, 1.62);
    font-weight: 400;
    color: var(--cream);
}

.letter-body p {
    margin-bottom: clamp(0.32rem, 1.1vh, 0.8rem);
}

.letter-body p:last-child {
    margin-bottom: 0;
    color: var(--warm-accent);
}

/* Photos */
.photo-wrapper {
    opacity: 0;
    transition: opacity 0.8s ease 0.2s, transform 0.3s ease;
    z-index: 1;
}

.letter-container.is-visible .photo-wrapper {
    opacity: 1;
}

.letter-photo {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 5;
    object-fit: cover;
    background-color: var(--dark-burgundy);
    border: 3px solid var(--cream);
    border-radius: 3px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   RESPONSIVE LAYOUT (NO-OVERLAP GUARANTEED)
   ========================================================================== */

/* 1. Mobile Phones (<= 640px) - Photos sit gracefully in natural flow without covering text */
@media (max-width: 640px) {
    .letter-container {
        align-items: flex-start;
        padding: 1.25rem 1rem 2.5rem;
    }

    .letter-wrapper {
        max-width: 100%;
        padding-top: 2.75rem;
        gap: 1.2rem;
    }

    .back-button {
        top: 0;
        left: 0;
    }

    .letter-column {
        max-width: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    .photo-wrapper {
        position: static;
        pointer-events: auto;
        user-select: none;
    }

    .photo-top-right {
        align-self: flex-end;
        width: clamp(60px, 18vw, 76px);
        margin-top: -1.75rem;
        margin-bottom: -0.5rem;
    }

    .photo-top-right .letter-photo {
        transform: rotate(2.5deg);
    }

    .photo-bottom-left {
        align-self: flex-start;
        width: clamp(60px, 18vw, 76px);
        margin-top: 0.5rem;
    }

    .photo-bottom-left .letter-photo {
        transform: rotate(-2.2deg);
    }
}

/* 2. Tablet (641px - 767px) - Flanking photos outside central column */
@media (min-width: 641px) and (max-width: 767px) {
    .letter-wrapper {
        max-width: 640px;
        padding: 2rem 0;
    }

    .letter-column {
        max-width: 380px;
        margin: 0 auto;
    }

    .photo-wrapper {
        position: absolute;
        pointer-events: none;
        user-select: none;
    }

    .photo-top-right {
        top: 1rem;
        right: 0;
        width: 85px;
    }

    .photo-top-right .letter-photo {
        transform: rotate(2deg);
    }

    .photo-bottom-left {
        bottom: 1rem;
        left: 0;
        width: 85px;
    }

    .photo-bottom-left .letter-photo {
        transform: rotate(-2deg);
    }
}

/* 3. Desktop (>= 768px) - Full flanking layout with generous margins */
@media (min-width: 768px) {
    .letter-wrapper {
        max-width: 760px;
        min-height: min(100%, 640px);
        padding: 1.5rem 0;
    }

    .letter-column {
        max-width: 440px;
        margin: 0 auto;
    }

    .photo-wrapper {
        position: absolute;
        pointer-events: none;
        user-select: none;
    }

    .photo-top-right {
        top: 3%;
        right: 0;
        width: clamp(100px, 13vw, 125px);
    }

    .photo-top-right .letter-photo {
        transform: rotate(2.5deg);
    }

    .photo-bottom-left {
        bottom: 3%;
        left: 0;
        width: clamp(100px, 13vw, 125px);
    }

    .photo-bottom-left .letter-photo {
        transform: rotate(-2deg);
    }
}

/* Extra compact height handling for landscape screens */
@media (max-height: 580px) and (min-width: 641px) {
    .letter-body {
        font-size: 0.76rem;
        line-height: 1.35;
    }
    .letter-body p {
        margin-bottom: 0.22rem;
    }
    .letter-date {
        margin-bottom: 0.3rem;
    }
    .photo-top-right, .photo-bottom-left {
        width: 65px;
    }
}

/* ==========================================================================
   ANIMATIONS & REDUCED MOTION
   ========================================================================== */
@keyframes simpleFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        animation-delay: 0ms !important;
    }

    .opening-line,
    .open-button,
    .photo-wrapper {
        opacity: 1 !important;
    }

    .letter-container {
        opacity: 1 !important;
        transform: none !important;
    }
}
