/* ==========================================================================
   COLOR PALETTE (RECOLORED NAVY THEME):
   #112A46 — dominant main background (deep navy)
   #E1E8F0 — light cream / text main (primary text, button backgrounds, photo borders)
   #FCF7DF — warm accent (sand/butter highlights, line 2 accent, hover states)
   #557392 — muted slate blue (date, line 3 accent, subtle borders)
   #0A1B2E — deep abyss dark navy (button text, contrast badges, deep shadows)
   ========================================================================== */

:root {
    --bg-main: #112A46;
    --text-main: #E1E8F0;
    --cream: #E1E8F0;
    --warm-accent: #FCF7DF;
    --muted-blue: #557392;
    --deep-blue: #112A46;
    --dark-burgundy: #0A1B2E;

    --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(225, 232, 240, 0.12);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(85, 115, 146, 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(225, 232, 240, 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(252, 247, 223, 0.16);
    border-color: rgba(252, 247, 223, 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 (RESPONSIVE & ZERO-COLLISION FIT)
   ========================================================================== */
.letter-container {
    width: 100%;
    height: 100%;
    height: 100dvh;
    background-color: var(--bg-main);
    padding: clamp(0.75rem, 2vh, 1.75rem) clamp(0.6rem, 2.5vw, 1.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;
    box-sizing: border-box;
}

/* Custom subtle scrollbar */
.letter-container::-webkit-scrollbar {
    width: 4px;
}
.letter-container::-webkit-scrollbar-track {
    background: transparent;
}
.letter-container::-webkit-scrollbar-thumb {
    background: rgba(225, 232, 240, 0.2);
    border-radius: 999px;
}
.letter-container::-webkit-scrollbar-thumb:hover {
    background: rgba(225, 232, 240, 0.4);
}

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

.letter-wrapper {
    width: 100%;
    max-width: 720px;
    margin: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    padding-top: clamp(2rem, 4.5vh, 2.6rem);
    padding-bottom: clamp(1.75rem, 3.5vh, 2.25rem);
    box-sizing: border-box;
}

/* Back Button */
.back-button {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    background: rgba(225, 232, 240, 0.12);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border: 1px solid rgba(85, 115, 146, 0.35);
    border-radius: 999px;
    outline: none;
    font-family: var(--font-sans);
    font-size: clamp(0.72rem, 1.8vh, 0.8rem);
    font-weight: 500;
    color: var(--cream);
    cursor: pointer;
    padding: 0.32rem 0.7rem;
    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(225, 232, 240, 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;
    box-sizing: border-box;
}

.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.45rem, 1.3vh, 0.9rem);
    letter-spacing: 0.03em;
    opacity: 0.9;
}

.letter-body {
    font-family: var(--font-serif);
    font-size: clamp(0.8125rem, 1.95vh, 0.94rem);
    line-height: clamp(1.42, 2.25vh, 1.6);
    font-weight: 400;
    color: var(--cream);
}

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

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

/* Photos */
.photo-wrapper {
    opacity: 0;
    transition: opacity 0.8s ease 0.2s;
    z-index: 3;
    position: absolute;
    user-select: none;
    box-sizing: border-box;
}

.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: 2.5px solid var(--cream);
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.letter-photo:hover {
    transform: scale(1.05) rotate(0deg) !important;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}

/* Responsive Positions for Photos & Safe Letter Clearance */
@media (max-width: 540px) {
    .photo-top-right {
        top: 0;
        right: 0;
        width: 48px;
    }

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

    .photo-bottom-left {
        bottom: 0;
        left: 0;
        width: 48px;
    }

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

    /* Safe clear padding ensures text NEVER overlaps top-right or bottom-left photo */
    .letter-column {
        padding-left: 54px;
        padding-right: 54px;
    }

    .back-button {
        top: -4px;
        left: 0;
        font-size: 0.72rem;
        padding: 0.28rem 0.6rem;
    }
}

@media (min-width: 541px) and (max-width: 767px) {
    .photo-top-right {
        top: 8px;
        right: 4px;
        width: 68px;
    }

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

    .photo-bottom-left {
        bottom: 8px;
        left: 4px;
        width: 68px;
    }

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

    .letter-column {
        padding-left: 78px;
        padding-right: 78px;
    }
}

@media (min-width: 768px) {
    .photo-top-right {
        top: 20px;
        right: 0;
        width: clamp(95px, 12.5vw, 118px);
    }

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

    .photo-bottom-left {
        bottom: 20px;
        left: 0;
        width: clamp(95px, 12.5vw, 118px);
    }

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

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

/* Extra compact height handling for landscape or very small screens */
@media (max-height: 580px) {
    .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: 42px;
    }
}

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