/* ============================================================
   LETTER — Envelope & scroll letter styles
   ============================================================ */

/* ── Reset & base ── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg1:       #1c0012;
    --bg2:       #4a0025;
    --gold:      #c9922a;
    --gold-light:#e8c060;
    --cream:     #f5e6d0;
    --cream2:    #ecdbb8;
    --parchment: #f2e0bb;
    --burgundy:  #8b1a2a;
    --ink:       #3a2010;
}

html,
body {
    height: 100%;
    overflow: hidden;
    background: var(--bg1);
}

body {
    font-family: 'Cormorant Garamond', Georgia, serif;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Back button ── */
.back-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 400;
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: .8rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    text-decoration: none;
    color: rgba(232, 192, 96, .5);
    transition: color .2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.back-btn:hover {
    color: rgba(232, 192, 96, .9);
}

.back-btn::before {
    content: '←';
    font-size: 1rem;
}

/* ── Stars background ── */
#stars {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse at 50% 0%, #4a0025 0%, #1c0012 60%, #0d0008 100%);
}

.star {
    position: absolute;
    border-radius: 50%;
    background: #fff;
    animation: twinkle ease-in-out infinite;
}

/* ── Floating petals ── */
#petals {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.petal {
    position: absolute;
    border-radius: 50% 0 50% 0;
    animation: petal-fall linear infinite;
    opacity: 0;
}

/* ── Loading screen ── */
#loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    transition: opacity .9s ease;
}

#loading.out {
    opacity: 0;
    pointer-events: none;
}

.loader-ring {
    position: relative;
    width: 90px;
    height: 90px;
}

.loader-ring span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid transparent;
    animation: spin linear infinite;
}

.loader-ring span:nth-child(1) {
    border-top-color: var(--gold-light);
    border-right-color: rgba(232, 192, 96, .3);
    animation-duration: 1.5s;
}

.loader-ring span:nth-child(2) {
    inset: 10px;
    border-bottom-color: var(--burgundy);
    border-left-color: rgba(139, 26, 42, .4);
    animation-duration: 1s;
    animation-direction: reverse;
}

.loader-ring span:nth-child(3) {
    inset: 22px;
    border-top-color: var(--gold);
    animation-duration: .7s;
}

.loader-dot {
    position: absolute;
    inset: 38px;
    background: radial-gradient(circle at 40% 35%, var(--gold-light), var(--gold));
    border-radius: 50%;
    box-shadow: 0 0 20px rgba(232, 192, 96, .7);
    animation: pulse 1.5s ease-in-out infinite;
}

.loader-text {
    margin-top: 28px;
    color: rgba(232, 192, 96, .55);
    font-size: 11px;
    letter-spacing: 5px;
    text-transform: uppercase;
    animation: breathe 2s ease-in-out infinite;
}

/* ── Envelope scene ── */
#scene-envelope {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transition: opacity .9s ease;
    pointer-events: none;
}

#scene-envelope.visible {
    opacity: 1;
    pointer-events: all;
}

.env-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.envelope {
    width: 300px;
    height: 200px;
    position: relative;
    cursor: pointer;
    filter: drop-shadow(0 24px 48px rgba(0, 0, 0, .65));
    transition: transform .3s ease, filter .3s ease;
    -webkit-tap-highlight-color: transparent;
}

.envelope:active { transform: scale(.97); }

.env-body {
    position: absolute;
    inset: 0;
    background: linear-gradient(160deg, var(--cream) 0%, var(--cream2) 60%, #d9c59a 100%);
    border-radius: 3px 3px 6px 6px;
    overflow: hidden;
}

.env-left, .env-right, .env-bl, .env-br {
    position: absolute;
    width: 0;
    height: 0;
}

.env-left  { border-top: 100px solid #e6d3b0;  border-right: 150px solid transparent; top: 0; left: 0;  z-index: 2; }
.env-right { border-top: 100px solid #d9c89a;  border-left:  150px solid transparent; top: 0; right: 0; z-index: 2; }
.env-bl    { border-bottom: 103px solid #c8b080; border-right: 150px solid transparent; bottom: 0; left: 0;  z-index: 2; }
.env-br    { border-bottom: 103px solid #bea670; border-left:  150px solid transparent; bottom: 0; right: 0; z-index: 2; }

.env-flap {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 0;
    border-top:   108px solid #deca9e;
    border-left:  150px solid transparent;
    border-right: 150px solid transparent;
    transform-origin: top center;
    transform-style: preserve-3d;
    z-index: 6;
    transition: transform .9s cubic-bezier(.4, 0, .2, 1);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .2));
}

.envelope.opened .env-flap {
    transform: perspective(600px) rotateX(-180deg);
}

.photo-peek {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    width: 170px;
    height: 120px;
    z-index: 4;
    opacity: 0;
    pointer-events: none;
    transition: top .7s cubic-bezier(.34, 1.56, .64, 1), opacity .5s ease;
}

.photo-peek.show {
    top: -48px;
    opacity: 1;
    pointer-events: all;
    cursor: pointer;
}

.photo-peek img,
.photo-peek .ph-placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 3px;
    border: 3px solid var(--cream);
    box-shadow: 0 8px 30px rgba(0, 0, 0, .55);
    display: block;
}

.ph-placeholder {
    background: linear-gradient(135deg, #c9707f 0%, #e8a0af 40%, #f5c6d0 70%, #fde8cc 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 44px;
}

/* ── Wax seal ── */
.seal {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -55%);
    z-index: 8;
    cursor: pointer;
    transition: transform .4s ease, opacity .4s ease;
}

.seal.break { animation: seal-shatter .55s ease forwards; }

.seal-outer {
    position: relative;
    width: 82px; height: 82px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seal-ring {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px dashed rgba(201, 146, 42, .35);
    animation: spin 30s linear infinite;
}

.seal-wax {
    width: 78px; height: 78px;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 28%, #c0392b 0%, #8b1a2a 55%, #5c0d18 100%);
    box-shadow:
        0 4px 18px rgba(0, 0, 0, .5),
        inset 0 2px 5px rgba(255, 160, 130, .18),
        0 0 0 3px rgba(139, 26, 42, .6),
        0 0 0 5px rgba(90, 15, 25, .35);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    position: relative;
}

.seal-wax::before {
    content: '';
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 1px solid rgba(255, 160, 130, .2);
}

.seal-icon  { font-size: 22px; line-height: 1; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }
.seal-label {
    font-family: 'Great Vibes', cursive;
    font-size: 12px;
    color: rgba(255, 220, 200, .88);
    letter-spacing: .5px;
    margin-top: 1px;
    text-shadow: 0 1px 3px rgba(0,0,0,.5);
}

.tap-hint {
    margin-top: 22px;
    color: rgba(232, 192, 96, .45);
    font-size: 11px;
    letter-spacing: 3px;
    text-transform: uppercase;
    animation: breathe 2.5s ease-in-out infinite;
}

/* ── Photo overlay ── */
#scene-photo {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: rgba(0, 0, 0, 0);
    z-index: 50;
    pointer-events: none;
    transition: background .55s ease;
}

#scene-photo.active {
    background: rgba(10, 0, 6, .88);
    pointer-events: all;
    cursor: pointer;
}

.photo-big {
    width: min(84vw, 360px);
    max-height: 65vh;
    object-fit: cover;
    border-radius: 6px;
    border: 3px solid rgba(245, 230, 208, .75);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .7), 0 0 0 1px rgba(201, 146, 42, .2);
    transform: scale(0) rotate(-4deg);
    opacity: 0;
    transition: transform .65s cubic-bezier(.34, 1.56, .64, 1), opacity .5s ease;
}

#scene-photo.active .photo-big {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

.photo-sub-hint {
    margin-top: 18px;
    color: rgba(232, 192, 96, .55);
    font-size: 11px;
    letter-spacing: 3px;
    text-transform: uppercase;
    opacity: 0;
    transition: opacity .5s ease .5s;
}

#scene-photo.active .photo-sub-hint { opacity: 1; }

/* ── Scroll / letter scene ── */
#scene-scroll {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0 20px;
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity .9s ease;
    overflow: hidden;
}

#scene-scroll.visible {
    opacity: 1;
    pointer-events: all;
}

.scroll-wrap {
    width: min(91vw, 360px);
    position: relative;
}

.scroll-rod {
    height: 38px;
    background: linear-gradient(90deg,
        #7a5510 0%, #c9922a 18%, #e8c060 38%, #d4a830 55%, #c09020 75%, #7a5510 100%);
    border-radius: 22px;
    position: relative;
    z-index: 3;
    box-shadow: 0 5px 18px rgba(0,0,0,.5), inset 0 1px 3px rgba(255,225,120,.35);
}

.scroll-rod::before,
.scroll-rod::after {
    content: '';
    position: absolute;
    width: 46px; height: 46px;
    top: 50%; transform: translateY(-50%);
    border-radius: 50%;
    background: radial-gradient(circle at 38% 35%, #d4a830, #8b6010 70%);
    box-shadow: 0 4px 12px rgba(0,0,0,.45), inset 0 1px 3px rgba(255,220,100,.25);
}

.scroll-rod::before { left: -8px; }
.scroll-rod::after  { right: -8px; }

.scroll-paper {
    background: linear-gradient(160deg, #fdf8ed 0%, var(--parchment) 40%, #f0d9a0 80%, var(--parchment) 100%);
    margin: -3px 12px;
    padding: 28px 22px 32px;
    position: relative;
    max-height: 58vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    clip-path: inset(0 0 100% 0);
    animation: unroll .9s cubic-bezier(.4, 0, .2, 1) .1s forwards;
}

.scroll-paper::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        transparent, transparent 28px,
        rgba(160, 130, 80, .12) 28px, rgba(160, 130, 80, .12) 29px);
    pointer-events: none;
}

.scroll-paper::-webkit-scrollbar       { width: 4px; }
.scroll-paper::-webkit-scrollbar-track { background: transparent; }
.scroll-paper::-webkit-scrollbar-thumb { background: rgba(160,130,80,.3); border-radius: 4px; }

/* ── Letter typography ── */
.letter-body { position: relative; z-index: 1; color: var(--ink); }

.letter-greeting {
    font-family: 'Great Vibes', cursive;
    font-size: 28px;
    color: var(--burgundy);
    text-align: center;
    margin-bottom: 16px;
    line-height: 1.2;
}

.letter-body p {
    font-size: 15.5px;
    line-height: 1.85;
    text-align: justify;
    margin-bottom: 14px;
    font-weight: 400;
}

.letter-closing {
    text-align: right;
    font-style: italic;
    color: var(--burgundy);
    font-size: 15px;
    margin-top: 12px;
    line-height: 1.7;
}

.letter-heart {
    text-align: center;
    font-size: 28px;
    margin-top: 10px;
    animation: heartbeat 1.6s ease-in-out infinite;
}

/* ── Particles ── */
.particle {
    position: fixed;
    border-radius: 50%;
    pointer-events: none;
    z-index: 300;
    animation: particle-fly linear forwards;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes twinkle {
    0%, 100% { opacity: .08; transform: scale(1); }
    50%       { opacity: .70; transform: scale(1.4); }
}

@keyframes petal-fall {
    0%   { transform: translateY(-30px) rotate(0deg);    opacity: 0; }
    8%   { opacity: .55; }
    92%  { opacity: .25; }
    100% { transform: translateY(110vh) rotate(800deg);  opacity: 0; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1);    opacity: .7; }
    50%       { transform: scale(1.25); opacity: 1;  }
}

@keyframes breathe {
    0%, 100% { opacity: .3;  }
    50%       { opacity: .85; }
}

@keyframes seal-shatter {
    0%   { transform: translate(-50%, -55%) scale(1)    rotate(0deg);  opacity: 1; }
    45%  { transform: translate(-50%, -55%) scale(1.18) rotate(8deg);  opacity: 1; }
    100% { transform: translate(-50%, -80%) scale(0)    rotate(25deg); opacity: 0; }
}

@keyframes unroll {
    from { clip-path: inset(0 0 100% 0); opacity: .4; }
    to   { clip-path: inset(0 0   0% 0); opacity: 1;  }
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1);    }
    25%       { transform: scale(1.18); }
    50%       { transform: scale(1);    }
    75%       { transform: scale(1.12); }
}

@keyframes particle-fly {
    0%   { opacity: 1; transform: translate(0, 0) scale(1); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}
