@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #8b5cf6;
    --primary-light: #a78bfa;
    --primary-dark: #7c3aed;
    --primary-glow: rgba(139, 92, 246, 0.4);
    --secondary: #06b6d4;
    --secondary-light: #22d3ee;
    --accent: #f472b6;
    --accent-light: #f9a8d4;
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.4);
    --error: #ef4444;
    --error-glow: rgba(239, 68, 68, 0.4);
    --warning: #f59e0b;

    --bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4c1d95 100%);
    --card-bg: rgba(255, 255, 255, 0.1);
    --card-bg-solid: rgba(255, 255, 255, 0.95);
    --card-border: rgba(255, 255, 255, 0.2);
    --glass-bg: rgba(255, 255, 255, 0.08);
    --glass-border: rgba(255, 255, 255, 0.15);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-dark: #1f2937;
    --text-muted: #6b7280;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--primary-glow);

    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-xl: 32px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

/* Animated background particles */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(139, 92, 246, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(6, 182, 212, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(244, 114, 182, 0.2) 0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
}

/* Floating orbs animation */
.orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(40px);
    opacity: 0.5;
    animation: float 20s infinite ease-in-out;
    pointer-events: none;
    z-index: 0;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: var(--primary);
    top: -100px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 200px;
    height: 200px;
    background: var(--secondary);
    bottom: -50px;
    left: -50px;
    animation-delay: -5s;
}

.orb-3 {
    width: 150px;
    height: 150px;
    background: var(--accent);
    top: 50%;
    right: 10%;
    animation-delay: -10s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.1); }
    50% { transform: translate(-20px, 20px) scale(0.9); }
    75% { transform: translate(20px, 30px) scale(1.05); }
}

/* Screen container */
.screen {
    width: 100%;
    max-width: 440px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

.screen.hidden {
    display: none;
}

/* ========== START SCREEN ========== */
.start-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
}

.title-emoji {
    font-size: 4rem;
    margin-bottom: 3rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    animation: titleEntrance 1s ease-out;
}

.title-emoji span {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    width: 4.5rem;
    text-align: center;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    animation: pulse-subtle 3s infinite ease-in-out;
}

.title-emoji span:nth-child(1) { animation-delay: 0s; }
.title-emoji span:nth-child(2) { animation-delay: 0.5s; }
.title-emoji span:nth-child(3) { animation-delay: 1s; }

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

@keyframes pulse-subtle {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.difficulty-select {
    margin-bottom: 2.5rem;
    width: 100%;
    animation: fadeInUp 0.8s ease-out 0.3s backwards;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.difficulty-btn {
    padding: 1rem 1.5rem;
    border: 2px solid var(--glass-border);
    border-radius: var(--radius-md);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.25rem;
    width: 200px;
    margin: 0 auto;
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
}

.difficulty-btn::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.5s ease;
}

.difficulty-btn:hover::before {
    left: 100%;
}

.difficulty-btn:hover {
    border-color: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.difficulty-btn.active {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.2);
    box-shadow: 0 0 30px var(--primary-glow), inset 0 0 20px rgba(139, 92, 246, 0.1);
}

.diff-pairs,
.diff-time {
    white-space: nowrap;
    font-size: 1.1rem;
}

.diff-time {
    opacity: 0.8;
}

/* Primary button - Play */
.primary-btn {
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md), 0 0 30px var(--primary-glow);
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    animation: fadeInUp 0.8s ease-out 0.6s backwards;
}

.primary-btn::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary), var(--accent));
    z-index: -1;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.primary-btn:hover::before {
    opacity: 1;
}

.primary-btn:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg), 0 0 50px var(--primary-glow);
}

.primary-btn:active {
    transform: scale(0.95);
}

/* Secondary button */
.secondary-btn {
    padding: 1rem;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text-primary);
    border: 2px solid var(--glass-border);
    border-radius: 50%;
    font-size: 1.75rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--primary-light);
    transform: scale(1.1);
    box-shadow: var(--shadow-glow);
}

@keyframes fadeInUp {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ========== GAME SCREEN ========== */
.game-header {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    gap: 1rem;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    font-size: 1.25rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.progress-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: 0%;
    position: relative;
    box-shadow: 0 0 10px var(--primary-glow);
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 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%); }
}

.round-display {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.round-indicator {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.round-total {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.timer-container {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
}

.timer {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
}

.timer.warning {
    color: var(--error);
    animation: pulse-warning 0.5s infinite;
    text-shadow: 0 0 10px var(--error-glow);
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Game Main */
.game-main {
    flex: 1;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
}

.instruction {
    text-align: center;
    font-size: 1.75rem;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.game-board {
    display: flex;
    gap: 0.75rem;
    flex: 1;
}

.column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

/* Game Cards */
.card {
    padding: 0.875rem;
    background: var(--card-bg-solid);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-dark);
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    animation: cardEntrance 0.4s ease-out both;
}

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

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

/* Ensure cards stay visible after entrance */
.card.selected,
.card.matched,
.card.wrong {
    opacity: 1;
}

.card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, rgba(255, 255, 255, 0.8) 50%, transparent 60%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}

.card:hover:not(.matched):not(.disabled) {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.card:hover:not(.matched):not(.disabled)::before {
    transform: translateX(100%);
}

.card.selected {
    border-color: var(--primary);
    background: linear-gradient(135deg, #f5f3ff 0%, #ede9fe 100%);
    box-shadow: 0 0 20px var(--primary-glow), var(--shadow-md);
    transform: scale(1.02);
    color: #5b21b6;
    font-weight: 600;
}

.card.matched {
    border-color: var(--success);
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
    box-shadow: 0 0 15px var(--success-glow);
    cursor: default;
    animation: matchPop 0.4s ease-out;
    color: #065f46;
    font-weight: 600;
}

@keyframes matchPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.card.wrong {
    border-color: var(--error);
    background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
    box-shadow: 0 0 15px var(--error-glow);
    color: #991b1b;
    font-weight: 600;
}

/* After entrance animation completes, disable it */
.card.entered {
    animation: none;
}

.card.shake {
    animation: shake 0.4s ease !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

.card.disabled {
    cursor: default;
    opacity: 0.5;
}

.emoji-card {
    font-size: 1.4rem;
}

/* Score Display */
.score-display {
    padding: 1rem 1.25rem;
    text-align: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

#current-score {
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.5rem;
    font-weight: 800;
    min-width: 60px;
    display: inline-block;
}

/* ========== RESULTS SCREEN ========== */
.results-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
}

.results-content h1 {
    font-size: 5rem;
    margin-bottom: 2rem;
    animation: bounceIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.results-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 3rem;
    animation: fadeInUp 0.6s ease-out 0.2s backwards;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.25rem;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    min-width: 90px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

.stat-label {
    font-size: 1.5rem;
}

.results-buttons {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 1.5rem;
    animation: fadeInUp 0.6s ease-out 0.4s backwards;
}

/* ========== CONFETTI ========== */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 480px) {
    .game-main {
        padding: 1rem;
    }

    .card {
        padding: 0.75rem;
        font-size: 0.875rem;
        height: 56px;
    }

    .emoji-card {
        font-size: 1.25rem;
    }

    .results-stats {
        gap: 1rem;
    }

    .stat {
        padding: 1rem;
        min-width: 80px;
    }

    .stat-value {
        font-size: 1.75rem;
    }

    .title-emoji {
        font-size: 3rem;
    }

    .title-emoji span {
        width: 3.5rem;
    }
}

/* ========== SCORE ANIMATION ========== */
.score-pop {
    animation: scorePop 0.3s ease-out;
}

@keyframes scorePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Negative score flash */
.score-negative {
    animation: scoreNegative 0.3s ease-out;
}

@keyframes scoreNegative {
    0%, 100% { filter: none; }
    50% { filter: brightness(0.5) sepia(1) hue-rotate(-50deg) saturate(5); }
}
