/* ═══════════════════════════════════════════════════════════
   css/page-transition.css
   Magical transition overlay between index ↔ poem reader.
   The light comes FROM the poem card and folds BACK to it.
   ═══════════════════════════════════════════════════════════ */

/* ── Transition overlay (always in DOM, hidden until triggered) ── */
.page-transition-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
}

.page-transition-overlay.active {
    pointer-events: all;
    opacity: 1;
    visibility: visible;
}

/* ── The golden ripple that expands from the click origin ── */
.transition-ripple {
    position: absolute;
    border-radius: 50%;
    /* origin set dynamically via JS */
    width: 0;
    height: 0;
    background: radial-gradient(
        circle,
        rgba(238, 198, 67, 0.18) 0%,
        rgba(238, 198, 67, 0.08) 35%,
        rgba(10, 10, 12, 0.95) 70%,
        rgba(3, 3, 4, 1) 100%
    );
    transform: translate(-50%, -50%) scale(0);
    transition: none;
}

.page-transition-overlay.active .transition-ripple {
    animation: rippleExpand 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.page-transition-overlay.active.returning .transition-ripple {
    animation: rippleCollapse 1.0s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes rippleExpand {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    60% {
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

@keyframes rippleCollapse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    40% {
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

/* ── The warm veil that covers everything at peak ── */
.transition-veil {
    position: absolute;
    inset: 0;
    background: var(--bg-color, #030304);
    opacity: 0;
}

.page-transition-overlay.active .transition-veil {
    animation: veilIn 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.page-transition-overlay.active.returning .transition-veil {
    animation: veilOut 1.0s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes veilIn {
    0%   { opacity: 0; }
    50%  { opacity: 0; }
    80%  { opacity: 1; }
    100% { opacity: 1; }
}

@keyframes veilOut {
    0%   { opacity: 1; }
    20%  { opacity: 1; }
    60%  { opacity: 0; }
    100% { opacity: 0; }
}

/* ── Particle canvas for the floating motes ── */
.transition-particles {
    position: absolute;
    inset: 0;
    z-index: 2;
}

/* ── Central glow that pulses at the midpoint ── */
.transition-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 300px;
    height: 300px;
    transform: translate(-50%, -50%) scale(0);
    border-radius: 50%;
    background: radial-gradient(
        circle,
        rgba(238, 198, 67, 0.25) 0%,
        rgba(238, 198, 67, 0.08) 40%,
        transparent 70%
    );
    opacity: 0;
    z-index: 3;
    filter: blur(30px);
}

.page-transition-overlay.active .transition-glow {
    animation: glowPulse 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.page-transition-overlay.active.returning .transition-glow {
    animation: glowFade 1.0s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

@keyframes glowPulse {
    0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    40%  { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    65%  { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    85%  { transform: translate(-50%, -50%) scale(1.5); opacity: 0.6; }
    100% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}

@keyframes glowFade {
    0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
    30%  { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
    60%  { transform: translate(-50%, -50%) scale(0.8); opacity: 0.5; }
    100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}

/* ── Poem title whisper (shown briefly during transition) ── */
.transition-title {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 4;
    text-align: center;
    opacity: 0;
    pointer-events: none;
}

.transition-title h3 {
    font-family: var(--font-heading, Georgia, serif);
    font-size: 2.5rem;
    font-weight: normal;
    color: var(--primary-color, #eec643);
    text-shadow: 0 0 40px rgba(238, 198, 67, 0.4);
    letter-spacing: 3px;
    margin: 0;
    opacity: 0;
    transform: translateY(10px);
}

.transition-title span {
    display: block;
    margin-top: 0.8rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: var(--text-secondary, #a0a0a0);
    opacity: 0;
    transform: translateY(8px);
}

.page-transition-overlay.active .transition-title h3 {
    animation: titleReveal 1.1s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.page-transition-overlay.active .transition-title span {
    animation: titleReveal 1.1s cubic-bezier(0.22, 1, 0.36, 1) 0.15s forwards;
}

.page-transition-overlay.active.returning .transition-title h3 {
    animation: titleFade 1.0s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

.page-transition-overlay.active.returning .transition-title span {
    animation: titleFade 1.0s cubic-bezier(0.55, 0, 1, 0.45) 0.08s forwards;
}

@keyframes titleReveal {
    0%   { opacity: 0; transform: translateY(10px); }
    45%  { opacity: 0; transform: translateY(10px); }
    65%  { opacity: 1; transform: translateY(0); }
    85%  { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-5px); }
}

@keyframes titleFade {
    0%   { opacity: 0; transform: translateY(-5px); }
    15%  { opacity: 1; transform: translateY(0); }
    50%  { opacity: 1; transform: translateY(0); }
    70%  { opacity: 0; transform: translateY(8px); }
    100% { opacity: 0; transform: translateY(10px); }
}

/* ── Page content fade-out / fade-in ── */
body.page-exiting > *:not(.page-transition-overlay):not(#particles-canvas) {
    transition: opacity 0.5s ease, filter 0.5s ease, transform 0.5s ease;
    opacity: 0;
    filter: blur(3px);
    transform: scale(0.98);
}

body.page-entering > *:not(.page-transition-overlay):not(#particles-canvas) {
    opacity: 0;
    filter: blur(3px);
    transform: scale(0.98) translateY(15px);
}

body.page-entering.page-revealed > *:not(.page-transition-overlay):not(#particles-canvas) {
    transition: opacity 0.7s ease 0.1s, filter 0.7s ease 0.1s, transform 0.7s ease 0.1s;
    opacity: 1;
    filter: blur(0);
    transform: scale(1) translateY(0);
}
