/* ==========================================================================
   COLOR PALETTE:
   #3B3F49 — dominant main background (dark slate charcoal)
   #E8EBEC — off-white cream (primary text, button backgrounds, photo borders)
   #A64459 — rose wine accent (selection, active highlights)
   #B0C9CD — muted sage blue (date, subtle accents, borders)
   #D4DFE1 — soft ice cyan (line 2 accent, secondary highlights, hover states)
   ========================================================================== */

:root {
    --bg-main: #3B3F49;
    --text-main: #E8EBEC;
    --cream: #E8EBEC;
    --warm-accent: #D4DFE1;
    --rose-accent: #A64459;
    --muted-blue: #B0C9CD;
    --soft-ice: #D4DFE1;
    --deep-blue: #3B3F49;
    --dark-burgundy: #3B3F49;

    --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(--rose-accent);
    color: var(--cream);
}

/* ==========================================================================
   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(232, 235, 236, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(176, 201, 205, 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.75;
}

.music-toggle:hover {
    opacity: 1;
    background: rgba(232, 235, 236, 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(166, 68, 89, 0.25);
    border-color: rgba(166, 68, 89, 0.7);
    color: var(--cream);
}

.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(--muted-blue);
    border-radius: 999px;
    outline: none;
    color: var(--bg-main);
    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.25);
    animation: simpleFadeIn 0.7s ease-out 2.9s forwards;
    transition: all 0.2s ease;
}

.open-button:hover,
.open-button:focus-visible {
    background: var(--soft-ice);
    color: var(--bg-main);
    border-color: var(--cream);
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

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

/* ==========================================================================
   STATE 2: LETTER SCREEN
   ========================================================================== */
.letter-container {
    width: 100%;
    height: 100%;
    height: 100dvh;
    background-color: var(--bg-main);
    padding: 0 clamp(0.75rem, 3vw, 2rem);
    display: flex;
    align-items: flex-start;
    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::-webkit-scrollbar {
    width: 4px;
}

.letter-container::-webkit-scrollbar-thumb {
    background: rgba(232, 235, 236, 0.2);
    border-radius: 4px;
}

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

.letter-wrapper {
    width: 100%;
    max-width: 880px;
    min-height: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    padding-top: clamp(3.5rem, 7vh, 4.5rem);
    padding-bottom: clamp(3rem, 6vh, 4.5rem);
}

/* Back Button (Fixed at top-left) */
.back-button {
    position: fixed;
    top: clamp(0.75rem, 2vh, 1.25rem);
    left: clamp(0.75rem, 2vw, 1.25rem);
    z-index: 100;
    background: rgba(232, 235, 236, 0.12);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(176, 201, 205, 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.18);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.back-button:hover,
.back-button:focus-visible {
    background: rgba(232, 235, 236, 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(--muted-blue);
    margin-bottom: clamp(0.5rem, 1.5vh, 1.15rem);
    letter-spacing: 0.03em;
    opacity: 0.95;
}

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

.letter-body p {
    margin-bottom: clamp(0.4rem, 1.2vh, 0.85rem);
}

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

/* Photos */
.photo-wrapper {
    opacity: 0;
    transition: opacity 0.8s ease 0.2s;
    z-index: 2;
    user-select: none;
}

.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(--bg-main);
    border: 3px solid var(--cream);
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* Responsive Positions for Photos (Guaranteed No Overlap) */
@media (max-width: 767px) {
    .letter-wrapper {
        max-width: 460px;
        padding-top: clamp(3.25rem, 6vh, 4.25rem);
        padding-bottom: clamp(2.5rem, 5vh, 3.5rem);
    }

    .photo-top-right {
        position: relative;
        top: auto;
        right: auto;
        align-self: flex-end;
        width: clamp(90px, 26vw, 120px);
        margin-bottom: 1.25rem;
        margin-right: 0.5rem;
    }

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

    .photo-bottom-left {
        position: relative;
        bottom: auto;
        left: auto;
        align-self: flex-start;
        width: clamp(90px, 26vw, 120px);
        margin-top: 1.75rem;
        margin-left: 0.5rem;
    }

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

    .letter-column {
        padding: 0 0.5rem;
    }
}

@media (min-width: 768px) {
    .photo-top-right {
        position: absolute;
        top: clamp(1rem, 6vh, 3rem);
        right: 0;
        width: clamp(110px, 13vw, 140px);
    }

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

    .photo-bottom-left {
        position: absolute;
        bottom: clamp(1rem, 6vh, 3rem);
        left: 0;
        width: clamp(110px, 13vw, 140px);
    }

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

/* Extra compact height handling for landscape */
@media (max-height: 580px) and (min-width: 768px) {
    .letter-body {
        font-size: 0.78rem;
        line-height: 1.4;
    }
    .letter-body p {
        margin-bottom: 0.25rem;
    }
    .letter-date {
        margin-bottom: 0.35rem;
    }
    .photo-top-right, .photo-bottom-left {
        width: clamp(80px, 10vw, 105px);
    }
}

/* ==========================================================================
   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;
    }
}
