/* ========================================
   ANIMATIONS & SPECIAL EFFECTS
   ======================================== */

/* Basic Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeInUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes cardSlideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes screenTransition {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

@keyframes progressPulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

@keyframes stepPulse {
    0%, 100% {
        box-shadow: 0 0 12px rgba(16, 185, 129, 0.6);
        transform: scale(1.4);
    }
    50% {
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.8);
        transform: scale(1.5);
    }
}

@keyframes rainbow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Image Generation Animations */
.magic-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: linear-gradient(45deg, var(--primary), rgba(255, 255, 255, 0.8));
    border-radius: 50%;
    animation: float 6s ease-in-out infinite;
    box-shadow: 0 0 6px var(--primary);
}

.particle:nth-child(2n) {
    background: linear-gradient(45deg, var(--success), rgba(255, 255, 255, 0.8));
    animation-duration: 8s;
    animation-delay: -2s;
    box-shadow: 0 0 8px var(--success);
}

.particle:nth-child(3n) {
    background: linear-gradient(45deg, var(--secondary), rgba(255, 255, 255, 0.8));
    animation-duration: 7s;
    animation-delay: -1s;
    box-shadow: 0 0 7px var(--secondary);
}

.particle:nth-child(4n) {
    width: 6px;
    height: 6px;
    background: linear-gradient(45deg, rgba(255, 255, 255, 0.9), rgba(255, 215, 0, 0.8));
    animation-duration: 5s;
    animation-delay: -3s;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.particle:nth-child(5n) {
    width: 10px;
    height: 10px;
    background: linear-gradient(45deg, #ff69b4, rgba(255, 255, 255, 0.8));
    animation-duration: 9s;
    animation-delay: -4s;
    box-shadow: 0 0 12px #ff69b4;
}

@keyframes float {
    0% {
        transform: translateY(60vh) translateX(0px) rotate(0deg) scale(0.9);
        opacity: 0.9;
    }
    15% {
        transform: translateY(20vh) translateX(8px) rotate(90deg) scale(1.2);
        opacity: 1;
    }
    30% {
        transform: translateY(40vh) translateX(-6px) rotate(180deg) scale(0.8);
        opacity: 1;
    }
    45% {
        transform: translateY(10vh) translateX(12px) rotate(270deg) scale(1.1);
        opacity: 1;
    }
    60% {
        transform: translateY(30vh) translateX(-10px) rotate(360deg) scale(0.9);
        opacity: 0.95;
    }
    75% {
        transform: translateY(15vh) translateX(6px) rotate(450deg) scale(1.0);
        opacity: 1;
    }
    90% {
        transform: translateY(25vh) translateX(-4px) rotate(540deg) scale(1.05);
        opacity: 1;
    }
    100% {
        transform: translateY(60vh) translateX(0px) rotate(630deg) scale(0.9);
        opacity: 0.9;
    }
}

.magic-wand {
    font-size: 64px;
    color: var(--primary);
    animation: paintStroke 3s ease-in-out infinite;
    margin: 20px 0 20px auto;
    display: block;
    position: relative;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.5));
}

.wand-sparkles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.sparkle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
    animation: sparkleFloat 2s ease-in-out infinite;
}

.sparkle:nth-child(1) {
    top: 20%;
    left: 80%;
    animation-delay: 0s;
}

.sparkle:nth-child(2) {
    top: 60%;
    left: 90%;
    animation-delay: 0.7s;
    background: var(--secondary);
}

.sparkle:nth-child(3) {
    top: 40%;
    left: 85%;
    animation-delay: 1.4s;
    background: rgba(255, 255, 255, 0.9);
}

@keyframes paintStroke {
    0%, 100% {
        transform: rotate(-15deg) scale(1) translateX(0);
    }
    25% {
        transform: rotate(10deg) scale(1.2) translateX(10px);
    }
    50% {
        transform: rotate(-5deg) scale(1.1) translateX(-5px);
    }
    75% {
        transform: rotate(5deg) scale(1.15) translateX(5px);
    }
}

@keyframes sparkleFloat {
    0%, 100% {
        transform: translateY(0) scale(0);
        opacity: 0;
    }
    50% {
        transform: translateY(-20px) scale(1);
        opacity: 1;
    }
}

/* Magical Portal Animation */
.magical-portal {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 20px auto;
    display: block;
}

.portal-ring {
    position: absolute;
    border-radius: 50%;
    border: 3px solid transparent;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.ring-1 {
    width: 120px;
    height: 120px;
    background: linear-gradient(45deg, #ff6b6b, #ffa500, #ffff00, #32cd32, #1e90ff, #9370db, #ff69b4);
    background-size: 400% 400%;
    animation: portalRotate 4s linear infinite, portalPulse 2s ease-in-out infinite;
    border: 4px solid rgba(255, 255, 255, 0.3);
}

.ring-2 {
    width: 90px;
    height: 90px;
    background: linear-gradient(45deg, #ff1493, #00ffff, #ffd700, #adff2f, #ff6347, #dda0dd, #98fb98);
    background-size: 400% 400%;
    animation: portalRotate 3s linear infinite reverse, portalPulse 2.5s ease-in-out infinite;
    border: 3px solid rgba(255, 255, 255, 0.4);
}

.ring-3 {
    width: 60px;
    height: 60px;
    background: linear-gradient(45deg, #ff4500, #00ced1, #daa520, #228b22, #dc143c, #ba55d3, #20b2aa);
    background-size: 400% 400%;
    animation: portalRotate 2s linear infinite, portalPulse 3s ease-in-out infinite;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.portal-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(255,255,255,0.9) 0%, rgba(255,215,0,0.8) 50%, rgba(255,69,0,0.6) 100%);
    border-radius: 50%;
    animation: centerGlow 1.5s ease-in-out infinite alternate;
}

.magic-spark {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #ffffff;
    border-radius: 50%;
    animation: sparkTwinkle 1s ease-in-out infinite;
}

.magic-spark:nth-child(1) {
    top: 10%;
    left: 20%;
    animation-delay: 0s;
}

.magic-spark:nth-child(2) {
    top: 70%;
    left: 80%;
    animation-delay: 0.3s;
}

.magic-spark:nth-child(3) {
    top: 30%;
    left: 70%;
    animation-delay: 0.6s;
}

.magic-spark:nth-child(4) {
    top: 80%;
    left: 30%;
    animation-delay: 0.9s;
}

@keyframes portalRotate {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes portalPulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.1); }
}

@keyframes centerGlow {
    0% { box-shadow: 0 0 10px rgba(255,215,0,0.5); }
    100% { box-shadow: 0 0 30px rgba(255,215,0,0.9), 0 0 50px rgba(255,69,0,0.7); }
}

@keyframes sparkTwinkle {
    0%, 100% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .main-content {
        padding: 16px;
    }

    .card {
        padding: 20px;
        margin-bottom: 16px;
    }

    .header-content {
        padding: 0;
    }

    .logo-text {
        font-size: 20px;
    }

    .character-grid, .image-grid {
        grid-template-columns: 1fr;
    }

    .pdf-grid {
        grid-template-columns: 1fr;
    }

    .image-actions {
        gap: 12px;
    }

    .prompt-input {
        min-height: 90px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .page-text textarea {
        min-height: 90px;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .image-actions {
        flex-direction: column;
    }

    .image-actions .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .card-header {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }

    .card-title {
        font-size: 20px;
    }

    .btn {
        padding: 14px 20px;
        font-size: 15px;
    }
}

/* Gentle pulse for fullscreen exit button */
@keyframes gentlePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 4px 20px rgba(255, 255, 255, 0.4);
    }
}
