/* ============================================
   THE AI VAULT: ESCAPE THE FUTURE
   Animations & Keyframes
   ============================================ */

/* ---- Screen Transitions ---- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ---- Room Enter/Exit ---- */
@keyframes roomEnter {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes roomExit {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(1.05) translateY(-20px);
    }
}

/* ---- Puzzle Feedback ---- */
@keyframes puzzleSuccess {
    0% { box-shadow: 0 0 0 0 var(--color-success); }
    50% { box-shadow: 0 0 40px 10px rgba(16, 185, 129, 0.4); }
    100% { box-shadow: 0 0 0 0 transparent; }
}

@keyframes puzzleFailure {
    0%, 100% { transform: translateX(0); }
    10% { transform: translateX(-8px); }
    30% { transform: translateX(8px); }
    50% { transform: translateX(-6px); }
    70% { transform: translateX(6px); }
    90% { transform: translateX(-2px); }
}

@keyframes correctPulse {
    0% {
        background-color: rgba(16, 185, 129, 0.2);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }
    50% {
        background-color: rgba(16, 185, 129, 0.1);
        box-shadow: 0 0 20px 5px rgba(16, 185, 129, 0.2);
    }
    100% {
        background-color: transparent;
        box-shadow: none;
    }
}

/* ---- UI Elements ---- */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes pulseGlow {
    0%, 100% {
        box-shadow: 0 0 5px rgba(var(--room-accent-rgb), 0.3);
    }
    50% {
        box-shadow: 0 0 25px rgba(var(--room-accent-rgb), 0.6);
    }
}

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

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ---- Typing Effect ---- */
@keyframes typing {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

.typing-effect {
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid var(--room-accent);
    animation:
        typing 2s steps(40) forwards,
        blink 0.7s step-end infinite;
}

/* ---- Glitch Effect (Room 5: Cyber) ---- */
@keyframes glitch {
    0% {
        clip-path: inset(40% 0 61% 0);
        transform: translate(-2px, 2px);
    }
    20% {
        clip-path: inset(92% 0 1% 0);
        transform: translate(1px, -3px);
    }
    40% {
        clip-path: inset(43% 0 1% 0);
        transform: translate(-1px, 3px);
    }
    60% {
        clip-path: inset(25% 0 58% 0);
        transform: translate(3px, 1px);
    }
    80% {
        clip-path: inset(54% 0 7% 0);
        transform: translate(-3px, -2px);
    }
    100% {
        clip-path: inset(58% 0 43% 0);
        transform: translate(2px, -1px);
    }
}

.glitch {
    position: relative;
}

.glitch::before,
.glitch::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.glitch::before {
    color: #ff0000;
    animation: glitch 3s infinite linear alternate-reverse;
    z-index: -1;
}

.glitch::after {
    color: #0000ff;
    animation: glitch 2s infinite linear alternate;
    z-index: -2;
}

/* ---- Starfield (Room 1: Space) ---- */
@keyframes twinkle {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* ---- Data Flow (Room 2: Food) ---- */
@keyframes dataFlow {
    0% {
        transform: translateY(-100%);
        opacity: 0;
    }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% {
        transform: translateY(100vh);
        opacity: 0;
    }
}

/* ---- Leaf Float (Room 4: Green) ---- */
@keyframes leafFloat {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 0.7;
    }
    50% {
        transform: translateY(-20px) rotate(15deg);
        opacity: 1;
    }
    100% {
        transform: translateY(0) rotate(0deg);
        opacity: 0.7;
    }
}

/* ---- Vault Lock (Meta Puzzle) ---- */
@keyframes lockTurn {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(90deg); }
}

@keyframes vaultOpen {
    0% {
        transform: perspective(800px) rotateY(0deg);
        box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.5);
    }
    100% {
        transform: perspective(800px) rotateY(-120deg);
        box-shadow: inset 0 0 100px rgba(var(--room-accent-rgb), 0.3);
    }
}

/* ---- Confetti (Victory) ---- */
@keyframes confettiFall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* ---- Loading Spinner ---- */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--room-accent);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

/* ---- Utility Classes ---- */
.animate-fade-in {
    animation: fadeIn var(--transition-normal) forwards;
}

.animate-slide-up {
    animation: fadeSlideUp var(--transition-slow) forwards;
}

.animate-float {
    animation: float 3s ease-in-out infinite;
}

.animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

.animate-pulse-glow {
    animation: pulseGlow 2s ease-in-out infinite;
}

/* Stagger children animations */
.stagger-children > * {
    opacity: 0;
    animation: fadeSlideUp var(--transition-slow) forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-children > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-children > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-children > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-children > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-children > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-children > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-children > *:nth-child(8) { animation-delay: 0.4s; }
