/* ==========================================================================
   COLOR PALETTE (GOLDEN GLOW & ROSE MADDER THEME - SWAPPED):
   #FCE39D — Golden Glow (dominant main background)
   #E62833 — Rose Madder (primary text, borders, button backgrounds)
   #C91E28 — rich ruby accent (date, line 2 accent, last paragraph highlight)
   #FFF2CE — soft light gold (button text, contrast badge)
   ========================================================================== */

:root {
    --bg-main: #FCE39D;
    --text-main: #E62833;
    --cream: #E62833;
    --warm-accent: #C91E28;
    --muted-blue: rgba(230, 40, 51, 0.78);
    --golden-glow: #FCE39D;
    --rose-madder: #E62833;
    --dark-burgundy: #FFF2CE;

    --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-madder);
    color: var(--golden-glow);
}

/* ==========================================================================
   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(230, 40, 51, 0.10);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(230, 40, 51, 0.35);
    color: var(--rose-madder);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(230, 40, 51, 0.15);
    transition: all 0.25s ease;
    user-select: none;
    padding: 0;
    opacity: 0.82;
}

.music-toggle:hover {
    opacity: 1;
    background: rgba(230, 40, 51, 0.20);
    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(230, 40, 51, 0.18);
    border-color: rgba(230, 40, 51, 0.85);
    color: var(--rose-madder);
}

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

.music-icon {
    display: block;
    pointer-events: none;
}

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

/* ==========================================================================
   STATE 1: OPENING SCREEN
   ========================================================================== */
.opening-container {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1.25rem, 4vh, 2.5rem) clamp(1rem, 4vw, 2.5rem);
    background-color: var(--bg-main);
    z-index: 10;
    opacity: 1;
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

.opening-container.is-leaving {
    opacity: 0;
    transform: scale(0.98);
    pointer-events: none;
}

.opening-content {
    text-align: center;
    max-width: 420px;
    margin: 0 auto;
}

.opening-line {
    font-size: clamp(1.15rem, 3.2vh, 1.45rem);
    line-height: 1.45;
    font-weight: 400;
    letter-spacing: -0.01em;
    margin-bottom: clamp(0.2rem, 0.8vh, 0.45rem);
    opacity: 0;
    will-change: opacity, transform;
}

.opening-line.line-1 {
    color: var(--rose-madder);
    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(--rose-madder);
    border: 1px solid var(--rose-madder);
    border-radius: 999px;
    outline: none;
    color: var(--golden-glow);
    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(230, 40, 51, 0.28);
    animation: simpleFadeIn 0.7s ease-out 2.9s forwards;
    transition: all 0.2s ease;
}

.open-button:hover,
.open-button:focus-visible {
    background: #C91E28;
    color: #FFF2CE;
    border-color: #C91E28;
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(230, 40, 51, 0.35);
}

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

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

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

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

/* Back Button */
.back-button {
    position: fixed;
    top: clamp(0.75rem, 2vh, 1.25rem);
    left: clamp(0.75rem, 2vw, 1.25rem);
    z-index: 100;
    background: rgba(230, 40, 51, 0.10);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(230, 40, 51, 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(--rose-madder);
    cursor: pointer;
    padding: 0.38rem 0.85rem;
    box-shadow: 0 2px 8px rgba(230, 40, 51, 0.15);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.back-button:hover,
.back-button:focus-visible {
    background: rgba(230, 40, 51, 0.20);
    color: var(--warm-accent);
    border-color: var(--warm-accent);
    transform: translateX(-2px);
}

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

.letter-date {
    display: block;
    font-family: var(--font-sans);
    font-size: clamp(0.85rem, 2vh, 1rem);
    font-weight: 600;
    color: var(--warm-accent);
    margin-bottom: clamp(0.75rem, 1.8vh, 1.25rem);
    letter-spacing: 0.02em;
    opacity: 0.95;
    text-transform: none;
}

.letter-body {
    font-family: var(--font-serif);
    font-size: clamp(0.88rem, 2.1vh, 1.02rem);
    line-height: clamp(1.48, 2.4vh, 1.68);
    font-weight: 400;
    color: var(--rose-madder);
}

.letter-body p {
    margin-bottom: clamp(0.6rem, 1.5vh, 1rem);
}

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

/* Photos: Signature Corner Placement (Top-Right and Bottom-Left) */
.photo-wrapper {
    position: absolute;
    opacity: 0;
    transition: opacity 0.8s ease 0.2s;
    z-index: 1;
    pointer-events: none;
    user-select: none;
}

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

.letter-photo {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    background-color: var(--golden-glow);
    border: 3px solid var(--rose-madder);
    border-radius: 4px;
    box-shadow: 0 8px 24px rgba(230, 40, 51, 0.25);
}

/* KANAN ATAS */
.photo-top-right {
    top: clamp(0.5rem, 1.5vh, 1.25rem);
    right: clamp(0.5rem, 2vw, 1.25rem);
}

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

/* KIRI BAWAH */
.photo-bottom-left {
    bottom: clamp(0.5rem, 1.5vh, 1.25rem);
    left: clamp(0.5rem, 2vw, 1.25rem);
}

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

/* Responsive Corner Positioning with Zero Text Overlap */
@media (max-width: 859px) {
    .letter-wrapper {
        padding-top: clamp(180px, 24vh, 215px);
        padding-bottom: clamp(160px, 22vh, 195px);
    }

    .letter-column {
        width: 100%;
        max-width: 440px;
        margin: 0 auto;
        padding: 0 clamp(0.75rem, 3vw, 1.25rem);
    }

    .photo-top-right {
        top: 56px;
        right: clamp(0.75rem, 3vw, 1.25rem);
        width: clamp(68px, 18vw, 84px);
    }

    .photo-bottom-left {
        bottom: 16px;
        left: clamp(0.75rem, 3vw, 1.25rem);
        width: clamp(68px, 18vw, 84px);
    }
}

@media (min-width: 860px) {
    .letter-wrapper {
        max-width: 880px;
        padding-top: 3.5rem;
        padding-bottom: 3.5rem;
    }

    .letter-column {
        max-width: 470px;
        margin: 0 auto;
        padding: 2.5rem 0;
    }

    .photo-top-right {
        top: 10%;
        right: 20px;
        width: clamp(120px, 12vw, 140px);
    }

    .photo-bottom-left {
        bottom: 10%;
        left: 20px;
        width: clamp(120px, 12vw, 140px);
    }
}

/* Extra compact height handling for landscape or very small screens */
@media (max-height: 580px) {
    .opening-line {
        font-size: 1.05rem;
        margin-bottom: 0.2rem;
    }

    .opening-line.line-3 {
        margin-bottom: 1.2rem;
    }

    .open-button {
        padding: 0.35rem 1.1rem;
        font-size: 0.82rem;
    }

    .letter-date {
        margin-bottom: 0.4rem;
    }

    .letter-body {
        font-size: 0.84rem;
        line-height: 1.45;
    }

    .letter-body p {
        margin-bottom: 0.45rem;
    }
}

/* ==========================================================================
   ANIMATIONS & REDUCED MOTION
   ========================================================================== */
@keyframes simpleFadeIn {
    0% {
        opacity: 0;
        transform: translateY(5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

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