/* Journal-Style Animations - WEEK3 Implementation */

/* Page Transition Animations */
@keyframes pageFlip {
    0% {
        transform: rotateY(-90deg);
        opacity: 0;
    }
    50% {
        transform: rotateY(-45deg);
        opacity: 0.5;
    }
    100% {
        transform: rotateY(0deg);
        opacity: 1;
    }
}

@keyframes slideInFromRight {
    0% {
        transform: translateX(100%);
        opacity: 0;
    }
    60% {
        transform: translateX(-10px);
    }
    80% {
        transform: translateX(5px);
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInFromLeft {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    60% {
        transform: translateX(10px);
    }
    80% {
        transform: translateX(-5px);
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes fadeInScale {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }
    50% {
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes handDrawnCircle {
    0% {
        stroke-dashoffset: 1000;
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    100% {
        stroke-dashoffset: 0;
        opacity: 1;
    }
}

@keyframes writingEffect {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 100% 50%;
    }
}

@keyframes stickyNotePeel {
    0% {
        transform: rotate(-0.5deg) scale(1);
    }
    50% {
        transform: rotate(-2deg) scale(1.02);
    }
    100% {
        transform: rotate(-0.5deg) scale(1);
    }
}

@keyframes tapeAttach {
    0% {
        transform: translateX(-50%) rotate(-180deg) scale(0);
        opacity: 0;
    }
    100% {
        transform: translateX(-50%) rotate(-2deg) scale(1);
        opacity: 1;
    }
}

@keyframes paperclipAttach {
    0% {
        transform: rotate(0deg) translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: rotate(10deg) translateY(0);
        opacity: 1;
    }
}

@keyframes floatingGentle {
    0%, 100% {
        transform: translateY(0px) rotate(-0.5deg);
    }
    50% {
        transform: translateY(-3px) rotate(0.5deg);
    }
}

@keyframes gentleWiggle {
    0%, 100% {
        transform: rotate(-0.5deg);
    }
    50% {
        transform: rotate(0.5deg);
    }
}

@keyframes progressFill {
    0% {
        width: 0%;
    }
    100% {
        width: var(--target-width, 20%);
    }
}

@keyframes countdownPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0);
    }
    50% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes inkBlot {
    0% {
        transform: scale(0);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 0;
    }
}

@keyframes bookmarkFlip {
    0% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(90deg);
    }
    100% {
        transform: rotateY(0deg);
    }
}

/* Quiz Container Animations */
.quiz-container {
    animation: bounceIn 0.8s ease-out;
    transform-style: preserve-3d;
    perspective: 1000px;
}

.quiz-question {
    animation: slideInFromRight 0.6s ease-out;
}

.quiz-options .quiz-option {
    opacity: 0;
    animation: fadeInScale 0.5s ease-out forwards;
}

.quiz-options .quiz-option:nth-child(1) { animation-delay: 0.1s; }
.quiz-options .quiz-option:nth-child(2) { animation-delay: 0.2s; }
.quiz-options .quiz-option:nth-child(3) { animation-delay: 0.3s; }
.quiz-options .quiz-option:nth-child(4) { animation-delay: 0.4s; }
.quiz-options .quiz-option:nth-child(5) { animation-delay: 0.5s; }

/* Question Transition Animation */
.question-transition-enter {
    animation: slideInFromRight 0.6s ease-out;
}

.question-transition-exit {
    animation: slideInFromLeft 0.6s ease-out;
}

/* Progress Bar Animation */
.progress-bar {
    animation: progressFill 1s ease-out;
}

.progress-dot {
    transition: all 0.3s ease;
}

.progress-dot.current {
    animation: countdownPulse 2s infinite;
}

.progress-dot.active {
    animation: bounceIn 0.5s ease-out;
}

/* Interactive Elements Animations */
.quiz-option {
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.quiz-option::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    background: linear-gradient(45deg, transparent, rgba(255, 127, 80, 0.1), transparent);
    border-radius: inherit;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.quiz-option:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(139, 69, 19, 0.15);
}

.quiz-option:hover::before {
    opacity: 1;
}

.quiz-option.selected {
    animation: bounceIn 0.4s ease-out;
    border-color: var(--accent-color);
    background: linear-gradient(145deg, rgba(255, 127, 80, 0.05), rgba(255, 107, 53, 0.02));
}

.quiz-option.selected::after {
    content: '✓';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: var(--accent-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    animation: bounceIn 0.3s ease-out;
}

/* Button Animations */
.journal-button,
.cta-button,
.quiz-back,
.quiz-next {
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
}

.journal-button::before,
.cta-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.6s ease;
}

.journal-button:hover::before,
.cta-button:hover::before {
    left: 100%;
}

.journal-button:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 8px 20px rgba(139, 69, 19, 0.2);
}

.journal-button:active {
    transform: translateY(0) scale(0.98);
}

/* Journal Card Animations */
.journal-card {
    animation: bounceIn 0.8s ease-out;
    transition: all 0.3s ease;
}

.journal-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(139, 69, 19, 0.15);
}

/* Tape Animation */
.tape::after {
    animation: tapeAttach 0.6s ease-out;
}

.tape:hover::after {
    animation: gentleWiggle 2s infinite;
}

/* Sticky Note Animation */
.sticky-note {
    animation: stickyNotePeel 4s ease-in-out infinite;
}

.sticky-note:hover {
    animation-duration: 1s;
}

/* Paperclip Animation */
.paperclip {
    animation: paperclipAttach 0.8s ease-out;
}

/* Floating Elements */
.floating-element {
    animation: floatingGentle 3s ease-in-out infinite;
}

.decoration-dots,
.decoration-stars {
    animation: floatingGentle 4s ease-in-out infinite;
}

.decoration-stars {
    animation-delay: 2s;
}

/* Writing Effect Animation */
.writing-effect {
    position: relative;
    overflow: hidden;
}

.writing-effect::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(139, 69, 19, 0.1), transparent);
    background-size: 200% 100%;
    animation: writingEffect 2s linear infinite;
}

/* Results Page Animations */
.recommendation-card {
    opacity: 0;
    animation: fadeInScale 0.6s ease-out forwards;
}

.recommendation-card:nth-child(1) { animation-delay: 0.1s; }
.recommendation-card:nth-child(2) { animation-delay: 0.2s; }
.recommendation-card:nth-child(3) { animation-delay: 0.3s; }

.recommendation-card.best-match {
    animation: bounceIn 0.8s ease-out;
}

.best-match-badge {
    animation: bounceIn 0.5s ease-out;
}

.score-circle {
    animation: bounceIn 0.6s ease-out;
}

/* Loading Animation */
.loading-spinner {
    animation: spin 1s linear infinite, bounceIn 0.5s ease-out;
}

/* Error Message Animation */
.error-message {
    animation: shake 0.6s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Success Animation */
@keyframes successSparkle {
    0%, 100% {
        opacity: 0;
        transform: scale(0) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1) rotate(180deg);
    }
}

.success-animation::before,
.success-animation::after {
    content: '✨';
    position: absolute;
    animation: successSparkle 1s ease-out;
}

.success-animation::before {
    top: -10px;
    left: -10px;
}

.success-animation::after {
    top: -10px;
    right: -10px;
    animation-delay: 0.3s;
}

/* Progress Timer Animation */
.timer-icon {
    animation: countdownPulse 2s infinite;
}

/* Hand-drawn Circle Animation */
.hand-drawn-circle {
    position: relative;
}

.hand-drawn-circle::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #FF7F50;
    border-radius: 25px;
    opacity: 0.8;
}

/* Responsive Animation Adjustments */
@media (max-width: 768px) {
    .quiz-container {
        animation-duration: 0.6s;
    }
    
    .quiz-option {
        animation-duration: 0.4s;
    }
    
    .quiz-option:nth-child(1) { animation-delay: 0.05s; }
    .quiz-option:nth-child(2) { animation-delay: 0.1s; }
    .quiz-option:nth-child(3) { animation-delay: 0.15s; }
    .quiz-option:nth-child(4) { animation-delay: 0.2s; }
    .quiz-option:nth-child(5) { animation-delay: 0.25s; }
    
    .journal-button:hover {
        transform: translateY(-1px) scale(1.02);
    }
    
    .floating-element {
        animation-duration: 2s;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .floating-element {
        animation: none !important;
    }
    
    .timer-icon,
    .progress-dot.current {
        animation: none !important;
    }
}

/* Performance Optimizations */
.gpu-accelerated {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

.will-change-transform {
    will-change: transform;
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}

/* Custom Easing Functions */
.custom-ease-out {
    animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.custom-ease-in-out {
    animation-timing-function: cubic-bezier(0.645, 0.045, 0.355, 1);
}

.journal-ease {
    animation-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
}