/* Compose-letter call-to-action + modal form */

/* CTA button in vault head */
.compose-cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--pink-300), var(--rose-deep));
    color: white;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: .04em;
    border: 1px solid rgba(178, 88, 103, .35);
    box-shadow:
        0 1px 0 rgba(255,255,255,.45) inset,
        0 8px 22px -8px rgba(178, 88, 103, .55);
    cursor: pointer;
    transition: transform var(--t-fast), box-shadow var(--t-fast), filter var(--t-fast);
    user-select: none;
}
.compose-cta:hover {
    transform: translateY(-2px);
    filter: brightness(1.05);
    box-shadow:
        0 1px 0 rgba(255,255,255,.55) inset,
        0 12px 28px -8px rgba(178, 88, 103, .65);
}
.compose-cta:active { transform: translateY(0); }
.compose-cta svg { display: block; }

/* When the current user is Hins, the CTA flips blue (he's writing TO Rania,
   but the affordance reads as his accent colour so the duo feel is balanced). */
body[data-current-role="hins"] .compose-cta {
    background: linear-gradient(135deg, var(--hins-blue-soft), var(--hins-blue));
    border-color: rgba(58, 109, 171, .35);
    box-shadow:
        0 1px 0 rgba(255,255,255,.45) inset,
        0 8px 22px -8px rgba(48, 80, 130, .55);
}
body[data-current-role="hins"] .compose-cta:hover {
    box-shadow:
        0 1px 0 rgba(255,255,255,.55) inset,
        0 12px 28px -8px rgba(48, 80, 130, .65);
}

/* Compose modal paper */
.compose-paper {
    width: min(640px, 100%);
}

/* Top controls row — writing-language toggle on the left, close on the right.
   We deliberately *override* the sticky behaviour inherited from .modal-controls:
   when composing, having "You're writing in…" pinned to the top while the body
   scrolls feels like a bossy header. Let it scroll away with the rest. */
.compose-controls {
    position: static;
    gap: 14px;
    padding-bottom: 8px;
    margin-bottom: 4px;
    background: none;
}
.compose-lang-pick {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.compose-lang-hint {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--ink-faint);
    font-weight: 500;
}
/* The language toggle reuses the existing .letter-lang pill styles. */
.compose-lang button { font-weight: 600; }

/* Header (now below the controls row) */
.compose-header {
    margin-bottom: 18px;
    display: flex; flex-direction: column; gap: 4px;
}
.compose-header .eyebrow {
    margin: 0;
    font-family: 'Fraunces', serif;
    font-style: italic;
    font-size: 1.25rem;
    color: var(--ink);
    text-transform: none;
    letter-spacing: 0;
}
.compose-to-line {
    margin: 0;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--ink-faint);
}
.compose-to-line strong {
    font-family: 'Caveat', cursive;
    font-style: normal;
    font-weight: 500;
    font-size: 1.15rem;
    margin-left: 4px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--rose-deep);
    vertical-align: -2px;
}
body[data-current-role="hins"] .compose-to-line strong { color: var(--hins-blue); }

.compose-form {
    display: flex; flex-direction: column;
    gap: 18px;
}
.compose-sub {
    margin: 0 0 4px;
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 1.05rem;
    color: var(--ink-soft);
}

.compose-field {
    display: flex; flex-direction: column; gap: 6px;
}
.compose-label {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--ink-faint);
    font-weight: 500;
}
.compose-field input,
.compose-field textarea {
    width: 100%;
    background: rgba(255,255,255,.7);
    border: 1px solid var(--paper-edge);
    border-radius: 12px;
    padding: 12px 14px;
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.08rem;
    line-height: 1.55;
    color: var(--ink);
    transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
    resize: vertical;
}
.compose-field textarea {
    min-height: 220px;
    font-family: 'Cormorant Garamond', serif;
}
.compose-field input:focus,
.compose-field textarea:focus {
    outline: none;
    border-color: var(--pink-300);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(217, 122, 139, .18);
}
body[data-current-role="hins"] .compose-field input:focus,
body[data-current-role="hins"] .compose-field textarea:focus {
    border-color: var(--hins-blue-soft);
    box-shadow: 0 0 0 3px rgba(58, 109, 171, .18);
}

/* (Old radio-style language picker removed — now uses the .letter-lang pill at the top.) */

.compose-actions {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.compose-cancel,
.compose-send {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px;
    border-radius: 999px;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    letter-spacing: .04em;
    font-weight: 500;
    cursor: pointer;
    transition: transform var(--t-fast), filter var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
    user-select: none;
}
.compose-cancel {
    background: rgba(255,255,255,.65);
    color: var(--ink-soft);
    border: 1px solid var(--hairline);
}
.compose-cancel:hover { background: #fff; color: var(--ink); }

.compose-send {
    background: linear-gradient(135deg, var(--pink-300), var(--rose-deep));
    color: white;
    border: 1px solid rgba(178, 88, 103, .35);
    box-shadow:
        0 1px 0 rgba(255,255,255,.45) inset,
        0 8px 22px -8px rgba(178, 88, 103, .55);
}
.compose-send:hover { transform: translateY(-2px); filter: brightness(1.05); }
.compose-send:active { transform: translateY(0); }
.compose-send[disabled] { opacity: .65; cursor: not-allowed; transform: none; }

body[data-current-role="hins"] .compose-send {
    background: linear-gradient(135deg, var(--hins-blue-soft), var(--hins-blue));
    border-color: rgba(58, 109, 171, .35);
    box-shadow:
        0 1px 0 rgba(255,255,255,.45) inset,
        0 8px 22px -8px rgba(48, 80, 130, .55);
}

.compose-error {
    color: #b25867;
    background: rgba(217, 122, 139, .08);
    border: 1px solid rgba(217, 122, 139, .25);
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.82rem;
    text-align: center;
}
.compose-translate-note {
    margin: 0;
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: 0.92rem;
    color: var(--ink-soft);
    display: flex; align-items: center; gap: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255,255,255,.5);
    border: 1px dashed var(--paper-edge);
}
.compose-translate-note .spinner {
    width: 12px; height: 12px;
    border: 2px solid rgba(178, 88, 103, .25);
    border-top-color: var(--rose-deep);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
body[data-current-role="hins"] .compose-translate-note .spinner {
    border-color: rgba(58, 109, 171, .25);
    border-top-color: var(--hins-blue);
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 760px) {
    .vault-head .right { width: 100%; }
    .vault-head .right .compose-cta { width: 100%; justify-content: center; }
    .compose-paper { padding: 26px 18px 22px; }
    .compose-actions { flex-direction: column-reverse; align-items: stretch; }
    .compose-actions .compose-cancel,
    .compose-actions .compose-send { width: 100%; justify-content: center; }
}

/* ==========================================================================
   SLIP-INTO-ENVELOPE overlay
   Plays AFTER the compose modal closes, as its own moment. A letter floats
   in from above, the envelope rises to meet it, the letter compresses and
   tucks inside, the flap closes with a wax seal, the envelope settles, then
   drifts up and away while a Caveat "Sent" caption fades in.

   Body-level / viewport-fixed so it's never clipped, with pointer-events
   off so clicks pass through to the page.
   ========================================================================== */
.slip-overlay {
    position: fixed;
    inset: 0;
    z-index: 90;            /* above the modal (z=60), below toasts (z=9999) */
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 22px;
    pointer-events: none;
    background: radial-gradient(60% 50% at 50% 50%,
        rgba(255, 248, 244, .55) 0%,
        rgba(255, 248, 244, 0) 70%);
    -webkit-backdrop-filter: blur(0.5px);
            backdrop-filter: blur(0.5px);
}
.slip-overlay.playing {
    display: flex;
    animation: slipVeilIn 240ms ease both,
               slipVeilOut 360ms ease 2200ms both;
}
@keyframes slipVeilIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes slipVeilOut { from { opacity: 1; } to { opacity: 0; } }

.slip-stage {
    position: relative;
    width: 280px;
    height: 220px;
    perspective: 900px;
    transform-style: preserve-3d;
}

/* ─── Letter ─────────────────────────────────────────────────────────── */
.slip-letter {
    position: absolute;
    left: 50%;
    top: 6px;
    width: 168px;
    height: 124px;
    margin-left: -84px;
    transform-origin: 50% 100%;
    background: linear-gradient(180deg, #ffffff 0%, #fff7f1 100%);
    border: 1px solid rgba(178, 88, 103, .16);
    border-radius: 6px;
    box-shadow:
        0 1px 0 rgba(255,255,255,.85) inset,
        0 22px 38px -20px rgba(146, 82, 106, .35),
        0 6px 14px -8px rgba(146, 82, 106, .2);
    z-index: 2;
    overflow: hidden;
    animation: slipLetter 2200ms cubic-bezier(.32,.72,.28,1) both;
}
/* Faux writing lines */
.slip-letter::before {
    content: '';
    position: absolute;
    left: 16px; right: 22px; top: 22px;
    height: 1px;
    background: linear-gradient(90deg, rgba(178,88,103,.5), rgba(178,88,103,.05));
    box-shadow:
        0 14px 0 rgba(120,90,90,.18),
        0 26px 0 rgba(120,90,90,.16),
        0 38px 0 rgba(120,90,90,.14),
        0 50px 0 rgba(120,90,90,.12),
        0 62px 0 rgba(120,90,90,.10);
}
/* Tiny salutation flourish in the corner */
.slip-letter::after {
    content: '';
    position: absolute;
    left: 16px; top: 8px;
    width: 28px; height: 4px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--rose-deep), rgba(178,88,103,.1));
    opacity: .55;
}
/* Crease that appears mid-fold for an actual paper-fold feel */
.slip-letter-fold {
    position: absolute;
    left: 0; right: 0;
    top: 50%;
    height: 1px;
    background: linear-gradient(90deg,
        rgba(178,88,103,0) 0%,
        rgba(178,88,103,.35) 18%,
        rgba(178,88,103,.55) 50%,
        rgba(178,88,103,.35) 82%,
        rgba(178,88,103,0) 100%);
    opacity: 0;
    animation: slipLetterFold 2200ms ease both;
}

/* ─── Envelope ───────────────────────────────────────────────────────── */
.slip-envelope {
    position: absolute;
    left: 50%;
    bottom: 14px;
    width: 220px;
    height: 138px;
    margin-left: -110px;
    z-index: 3;
    transform-origin: 50% 100%;
    animation: slipEnvelope 2200ms cubic-bezier(.32,.72,.28,1) both;
    will-change: transform, opacity;
}
/* Body of the envelope (back face — sits behind the letter) */
.slip-envelope-back {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(180deg, rgba(255,255,255,.6) 0%, rgba(255,255,255,0) 18%),
        linear-gradient(180deg, #fff5ef 0%, #fbe5e9 100%);
    border: 1px solid var(--paper-edge);
    border-radius: 8px;
    box-shadow: 0 22px 44px -22px rgba(146, 82, 106, .5);
    z-index: 1;
}
/* Front pocket of the envelope — sits IN FRONT of the letter so the
   letter visually disappears INTO the envelope as it slides down. */
.slip-envelope-front {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 62%;
    background:
        linear-gradient(180deg, rgba(255,255,255,.35) 0%, rgba(255,255,255,0) 18%),
        linear-gradient(180deg, #fbd5dc 0%, #f3aab8 100%);
    border-top: 1px solid rgba(178, 88, 103, .18);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    z-index: 4;
    /* The diagonal "fold lines" that meet in the middle on a real envelope */
    background-image:
        linear-gradient(132deg, transparent 49.6%, rgba(178,88,103,.10) 50%, transparent 50.4%),
        linear-gradient(228deg, transparent 49.6%, rgba(178,88,103,.10) 50%, transparent 50.4%),
        linear-gradient(180deg, rgba(255,255,255,.35) 0%, rgba(255,255,255,0) 18%),
        linear-gradient(180deg, #fbd5dc 0%, #f3aab8 100%);
    background-size: 50% 100%, 50% 100%, 100% 100%, 100% 100%;
    background-position: 0 0, 100% 0, 0 0, 0 0;
    background-repeat: no-repeat;
}
/* The flap — peeled wide open initially, closes near the end. */
.slip-envelope-flap {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 70%;
    background:
        linear-gradient(180deg, rgba(255,255,255,.55) 0%, rgba(255,255,255,0) 30%),
        linear-gradient(180deg, #fbd5dc 0%, #f6b8c6 100%);
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    transform-origin: 50% 0%;
    transform: rotateX(-180deg);
    border-bottom: 1px solid rgba(178, 88, 103, .14);
    z-index: 5;
    animation: slipFlap 700ms cubic-bezier(.34,1.56,.42,1) both;
    animation-delay: 1100ms;
    backface-visibility: hidden;
}
/* Wax seal that "stamps" on at the end. */
.slip-envelope-seal {
    position: absolute;
    bottom: 28px; left: 50%;
    width: 22px; height: 22px;
    margin-left: -11px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #f6b8c6 0%, var(--rose-deep) 75%, #8a3e4d 100%);
    box-shadow:
        0 1px 0 rgba(255,255,255,.5) inset,
        0 4px 10px -2px rgba(124, 58, 74, .55);
    z-index: 6;
    transform: scale(0) rotate(-12deg);
    opacity: 0;
    animation: slipSeal 480ms cubic-bezier(.34,1.7,.4,1) 1700ms both;
}
.slip-envelope-seal::before {
    content: '';
    position: absolute; inset: 3px;
    border-radius: 50%;
    border: 1px dashed rgba(255,255,255,.6);
}

/* ─── Sparkles trailing the envelope as it leaves ─────────────────── */
.slip-sparkles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 7;
}
.slip-sparkles span {
    position: absolute;
    width: 4px; height: 4px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff7e0 0%, #f6c46a 60%, transparent 75%);
    opacity: 0;
    animation: slipSparkle 1100ms ease-out both;
    animation-delay: 1900ms;
    filter: blur(.3px);
}
.slip-sparkles span:nth-child(1) { left: 30%;  top: 30%; }
.slip-sparkles span:nth-child(2) { left: 70%;  top: 28%; animation-delay: 1980ms; }
.slip-sparkles span:nth-child(3) { left: 22%;  top: 52%; animation-delay: 2050ms; }
.slip-sparkles span:nth-child(4) { left: 78%;  top: 50%; animation-delay: 2100ms; }
.slip-sparkles span:nth-child(5) { left: 44%;  top: 18%; animation-delay: 2150ms; width: 5px; height: 5px; }
.slip-sparkles span:nth-child(6) { left: 58%;  top: 42%; animation-delay: 2200ms; }

/* ─── "Sent" caption ─────────────────────────────────────────────────── */
.slip-text {
    margin: 0;
    font-family: 'Caveat', cursive;
    font-size: 1.65rem;
    color: var(--rose-deep);
    letter-spacing: .01em;
    text-shadow: 0 1px 0 rgba(255,255,255,.55);
    opacity: 0;
    transform: translateY(8px);
    animation: slipText 760ms cubic-bezier(.32,1.4,.36,1) 1500ms both;
}

/* ─── Choreography ───────────────────────────────────────────────────── */
@keyframes slipLetter {
    /* Drift in from above */
    0%   { transform: translate(0, -52px) rotate(-2deg) scaleY(1);    opacity: 0; }
    14%  { transform: translate(0, -28px) rotate(-1deg) scaleY(1);    opacity: 1; }
    /* Hover at envelope mouth, gently rotate level */
    32%  { transform: translate(0, -8px)  rotate(0)    scaleY(1);    opacity: 1; }
    /* Compress vertically (visual paper-fold) and start sliding down */
    52%  { transform: translate(0, 14px)  rotate(0)    scaleY(.5);   opacity: 1; }
    /* Continue sliding into envelope pocket */
    72%  { transform: translate(0, 50px)  rotate(0)    scaleY(.18);  opacity: .9; }
    /* Fully tucked in — fades behind the front pocket */
    86%  { transform: translate(0, 76px)  rotate(0)    scaleY(.04);  opacity: 0; }
    100% { transform: translate(0, 76px)  rotate(0)    scaleY(0);    opacity: 0; }
}
@keyframes slipLetterFold {
    0%, 36%   { opacity: 0; }
    50%       { opacity: .8; }
    66%, 100% { opacity: 0; }
}
@keyframes slipEnvelope {
    /* Rise up to catch the letter */
    0%   { transform: translate(0, 32px) scale(.92); opacity: 0; }
    16%  { transform: translate(0, 14px) scale(.96); opacity: 1; }
    32%  { transform: translate(0, 0)    scale(1);   opacity: 1; }
    /* Tiny breath while letter slides in */
    62%  { transform: translate(0, 0)    scale(1);   opacity: 1; }
    /* A small bounce when the flap snaps shut */
    78%  { transform: translate(0, -2px) scale(1.01); opacity: 1; }
    /* Float away — up & slightly off-axis like it's been sent */
    92%  { transform: translate(8px, -22px) rotate(1.5deg) scale(1.02); opacity: .9; }
    100% { transform: translate(18px, -68px) rotate(3deg) scale(1.05); opacity: 0; }
}
@keyframes slipFlap {
    0%   { transform: rotateX(-180deg); }
    /* Settle past closed for spring overshoot */
    72%  { transform: rotateX(6deg); }
    100% { transform: rotateX(0deg); }
}
@keyframes slipSeal {
    0%   { transform: scale(0)    rotate(-30deg); opacity: 0; }
    55%  { transform: scale(1.18) rotate(-6deg);  opacity: 1; }
    100% { transform: scale(1)    rotate(-9deg);  opacity: 1; }
}
@keyframes slipText {
    0%   { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}
@keyframes slipSparkle {
    0%   { opacity: 0; transform: translate(0,0) scale(.4); }
    35%  { opacity: 1; transform: translate(0,-12px) scale(1.1); }
    100% { opacity: 0; transform: translate(0,-32px) scale(.8); }
}

/* ─── Blue palette when Hins is composing ─────────────────────────────── */
body[data-current-role="hins"] .slip-envelope-back {
    background:
        linear-gradient(180deg, rgba(255,255,255,.6) 0%, rgba(255,255,255,0) 18%),
        linear-gradient(180deg, var(--hins-blue-tint) 0%, var(--hins-blue-pale) 100%);
    border-color: var(--hins-blue-edge);
    box-shadow: 0 22px 44px -22px rgba(48, 80, 130, .5);
}
body[data-current-role="hins"] .slip-envelope-front {
    background-image:
        linear-gradient(132deg, transparent 49.6%, rgba(48,80,130,.10) 50%, transparent 50.4%),
        linear-gradient(228deg, transparent 49.6%, rgba(48,80,130,.10) 50%, transparent 50.4%),
        linear-gradient(180deg, rgba(255,255,255,.3) 0%, rgba(255,255,255,0) 18%),
        linear-gradient(180deg, #c0d4ee 0%, #92b3df 100%);
    border-top-color: rgba(48, 80, 130, .18);
}
body[data-current-role="hins"] .slip-envelope-flap {
    background:
        linear-gradient(180deg, rgba(255,255,255,.55) 0%, rgba(255,255,255,0) 30%),
        linear-gradient(180deg, #cfe0f6 0%, #a7c4ea 100%);
    border-bottom-color: rgba(48, 80, 130, .14);
}
body[data-current-role="hins"] .slip-envelope-seal {
    background: radial-gradient(circle at 35% 30%, #a7c4ea 0%, var(--hins-blue) 75%, #234168 100%);
    box-shadow:
        0 1px 0 rgba(255,255,255,.5) inset,
        0 4px 10px -2px rgba(48, 80, 130, .55);
}
body[data-current-role="hins"] .slip-text { color: var(--hins-blue); }

@media (max-width: 540px) {
    .slip-stage { width: 230px; height: 190px; }
    .slip-letter   { width: 142px; height: 108px; margin-left: -71px; }
    .slip-envelope { width: 188px; height: 122px; margin-left: -94px; }
    .slip-text { font-size: 1.4rem; }
}

@media (prefers-reduced-motion: reduce) {
    .slip-overlay.playing {
        animation: slipVeilIn 100ms ease both, slipVeilOut 200ms ease 700ms both;
    }
    .slip-letter, .slip-envelope, .slip-envelope-flap,
    .slip-envelope-seal, .slip-letter-fold, .slip-text, .slip-sparkles span {
        animation-duration: 0.001ms !important;
        animation-delay: 0ms !important;
    }
}
