/* ============================================
   UI/UX ENHANCEMENTS - Smooth Experience
   ============================================ */

/* Smooth Micro-interactions */
button, a, input, textarea, select {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

button:hover, a:hover {
    transform: translateY(-2px);
}

button:active, a:active {
    transform: translateY(0);
}

/* Enhanced Challenge Cards */
.challenge-card {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transform-style: preserve-3d;
    perspective: 1000px;
}

.challenge-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
    transition: left 0.5s ease;
}

.challenge-card:hover::before {
    left: 100%;
}

.challenge-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 60px rgba(102, 126, 234, 0.4);
}

.challenge-card.solved {
    border-color: rgba(74, 222, 128, 0.3);
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.05) 0%, rgba(17, 24, 39, 0.7) 100%);
}

.challenge-card.solved::after {
    content: '✓';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #10b981, #059669);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    color: white;
    animation: checkmarkPop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes checkmarkPop {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    50% { transform: scale(1.2) rotate(10deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Modal Enhancements */
.modal-overlay {
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: fadeIn 0.3s ease-out;
}

.modal-overlay.active .modal {
    animation: modalSlideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalSlideUp {
    0% { transform: translateY(100px) scale(0.9); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.modal {
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(102, 126, 234, 0.5) transparent;
}

/* Input Field Enhancements */
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: rgba(102, 126, 234, 0.5);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), 0 0 20px rgba(102, 126, 234, 0.2);
    transform: scale(1.01);
}

input, textarea, select {
    transition: all 0.3s ease;
}

/* Badge Animations */
.badge {
    position: relative;
    overflow: hidden;
}

.badge::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.badge:hover::before {
    width: 200%;
    height: 200%;
}

/* Scoreboard Row Hover Effect */
.scoreboard-row {
    transition: all 0.3s ease;
    cursor: pointer;
}

.scoreboard-row:hover {
    background: rgba(102, 126, 234, 0.1);
    transform: translateX(8px);
    box-shadow: inset 4px 0 0 rgba(102, 126, 234, 0.5);
}

/* Rank Badge Enhancement */
.rank-badge {
    position: relative;
    transition: all 0.3s ease;
}

.rank-badge.rank-1,
.rank-badge.rank-2,
.rank-badge.rank-3 {
    animation: rankGlow 2s ease-in-out infinite;
}

.rank-badge.rank-1 {
    filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.6));
}

.rank-badge.rank-2 {
    filter: drop-shadow(0 0 8px rgba(192, 192, 192, 0.6));
}

.rank-badge.rank-3 {
    filter: drop-shadow(0 0 8px rgba(205, 127, 50, 0.6));
}

@keyframes rankGlow {
    0%, 100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.1); filter: brightness(1.2); }
}

/* Stats Card Enhancement */
.stat-card {
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(102, 126, 234, 0.1) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.5s ease;
}

.stat-card:hover::after {
    opacity: 1;
    animation: statGlow 2s ease-in-out infinite;
}

@keyframes statGlow {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(-25%, -25%); }
}

/* Button Ripple Effect */
.btn-primary, .btn-secondary, .btn-danger {
    position: relative;
    overflow: hidden;
}

.btn-primary::before, .btn-secondary::before, .btn-danger::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn-primary:active::before, .btn-secondary:active::before, .btn-danger:active::before {
    width: 300px;
    height: 300px;
}

/* Loading State for Buttons */
.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* Hint Card Enhancements */
.hint-card {
    transition: all 0.3s ease;
}

.hint-card:hover {
    transform: translateX(4px);
    border-color: rgba(102, 126, 234, 0.4);
}

.hint-locked {
    position: relative;
}

.hint-locked::before {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(255, 255, 255, 0.02) 10px,
        rgba(255, 255, 255, 0.02) 20px
    );
    pointer-events: none;
}

/* Flag Input Enhancement */
.flag-input {
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 0.5px;
}

.flag-input:focus {
    animation: flagInputFocus 0.3s ease;
}

@keyframes flagInputFocus {
    0% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4); }
    100% { box-shadow: 0 0 0 8px rgba(102, 126, 234, 0); }
}

/* Success/Error Message Animations */
.result-success {
    animation: successSlideIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.result-error {
    animation: errorShake 0.5s ease-in-out;
}

@keyframes successSlideIn {
    0% { transform: translateY(-20px) scale(0.8); opacity: 0; }
    50% { transform: translateY(5px) scale(1.05); }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

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

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Difficulty Indicator Enhancement */
.difficulty-dot {
    transition: all 0.3s ease;
}

.difficulty-dot.active {
    animation: difficultyPulse 2s ease-in-out infinite;
}

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

/* Floating Label Effect */
.floating-label {
    position: relative;
}

.floating-label input:focus ~ label,
.floating-label input:not(:placeholder-shown) ~ label {
    transform: translateY(-24px) scale(0.85);
    color: rgba(102, 126, 234, 0.8);
}

.floating-label label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    transition: all 0.3s ease;
}

/* Smooth Page Transitions */
.page-transition-enter {
    opacity: 0;
    transform: translateY(20px);
}

.page-transition-enter-active {
    opacity: 1;
    transform: translateY(0);
    transition: all 0.5s ease-out;
}

/* Enhanced Dropdown */
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23667eea'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

/* Card Flip Animation */
.flip-card {
    perspective: 1000px;
}

.flip-card-inner {
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.flip-card:hover .flip-card-inner {
    transform: rotateY(180deg);
}

/* Progress Bar Enhancement */
.progress-bar {
    position: relative;
    overflow: hidden;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.3),
        transparent
    );
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Tooltip Enhancement */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: 8px 12px;
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid rgba(102, 126, 234, 0.3);
    border-radius: 8px;
    color: white;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 1000;
}

[data-tooltip]:hover::before {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

/* Enhanced Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    transform: translateX(400px);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: auto;
    max-width: 380px;
    min-width: 300px;
}

.toast.active {
    transform: translateX(0);
    opacity: 1;
}

.toast.toast-exit {
    transform: translateX(400px);
    opacity: 0;
}

.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
    color: white;
}

.toast-message {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.4;
}

.toast-close {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    padding: 0;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-close:hover {
    color: white;
    transform: rotate(90deg);
}

.toast-success {
    border-left: 3px solid #10b981;
}

.toast-success .toast-icon {
    color: #10b981;
}

.toast-error {
    border-left: 3px solid #ef4444;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-warning {
    border-left: 3px solid #f59e0b;
}

.toast-warning .toast-icon {
    color: #f59e0b;
}

.toast-info {
    border-left: 3px solid #3b82f6;
}

.toast-info .toast-icon {
    color: #3b82f6;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .challenge-card:hover {
        transform: translateY(-4px) scale(1.01);
    }

    .modal {
        max-height: 95vh;
        margin: 10px;
    }

    .toast-container {
        right: 12px;
        left: 12px;
        max-width: calc(100% - 24px);
    }

    .toast {
        min-width: unset;
        max-width: 100%;
    }
}

/* Accessibility Improvements */
*:focus-visible {
    outline: 2px solid rgba(102, 126, 234, 0.6);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode contrast enhancement */
@media (prefers-contrast: high) {
    .glass-card {
        border-width: 2px;
        border-color: rgba(255, 255, 255, 0.3);
    }

    .btn-primary, .btn-secondary {
        border: 2px solid currentColor;
    }
}
