/* Value Stacking Matching Game - Updated CSS with Creativity Color Fix */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');

/* Hide on mobile - Enhanced detection */
@media (max-width: 799px) {
    .vs-matching-game-section {
        display: none !important;
    }
}

/* Additional mobile detection for problematic devices */
@media (max-width: 900px) {
    .vs-matching-game-section {
        display: none !important;
    }
}

@media (max-device-width: 800px) {
    .vs-matching-game-section {
        display: none !important;
    }
}

/* JavaScript-based mobile detection */
.mobile-device .vs-matching-game-section {
    display: none !important;
}

/* Touch device detection */
@media (pointer: coarse) {
    .vs-matching-game-section {
        display: none !important;
    }
}

/* Matching Game Section - Updated Background */
.vs-matching-game-section {
    position: relative;
    min-height: 100vh;
    padding: 60px 0;
    background: linear-gradient(135deg, #E7243B 0%, #c41e32 50%, #a01827 100%);
    font-family: 'Kanit', sans-serif;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    touch-action: manipulation;
}

.vs-matching-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    position: relative;
    z-index: 2;
}

/* Game Header */
.vs-matching-header {
    text-align: center;
    margin-bottom: 40px;
}

.vs-matching-title {
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 15px;
    text-shadow: none;
}

@keyframes vs-matching-title-glow {
    from { text-shadow: 0 0 30px rgba(255, 255, 255, 0.5), 0 0 40px rgba(254, 214, 56, 0.3); }
    to { text-shadow: 0 0 40px rgba(255, 255, 255, 0.8), 0 0 60px rgba(254, 214, 56, 0.6); }
}

.vs-matching-subtitle {
    font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    color: rgba(255, 255, 255, 0.9);
    font-weight: 400;
}

/* Game HUD - Enhanced Glass Effect */
.vs-matching-hud {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.vs-hud-item {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 15px 25px;
    border-radius: 20px;
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #ffffff;
    font-size: 1.1rem;
    transition: all 0.3s ease;
    position: relative;
}

.vs-hud-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    border-radius: 20px;
    z-index: -1;
}

.vs-hud-item:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 12px 40px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.vs-hud-value {
    color: #FED638;
    font-size: 1.3em;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(254, 214, 56, 0.5);
}

.vs-timer-container .vs-timer {
    transition: all 0.3s ease;
}

.vs-timer-container.vs-timer-warning .vs-timer {
    color: #ff6b6b;
    animation: vs-timer-pulse 1s ease-in-out infinite;
}

.vs-timer-container.vs-timer-critical .vs-timer {
    color: #ff3838;
    animation: vs-timer-critical 0.5s ease-in-out infinite;
}

@keyframes vs-timer-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes vs-timer-critical {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); color: #ffffff; }
}

/* Game Instructions - Enhanced Glass Effect */
.vs-matching-instructions {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 50px;
    border-radius: 30px;
    text-align: center;
    max-width: 700px;
    margin: 0 auto 40px;
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    position: relative;
}

.vs-matching-instructions::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    border-radius: 30px;
    z-index: -1;
}

.vs-matching-instructions h3 {
    font-size: 2.2rem;
    color: #ffffff;
    margin-bottom: 30px;
    font-weight: 700;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.vs-instruction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.vs-instruction-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.vs-instruction-item:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-3px);
}

.vs-instruction-icon {
    font-size: 2.5rem;
    line-height: 1;
    filter: drop-shadow(0 0 10px rgba(254, 214, 56, 0.5));
}

.vs-instruction-item p {
    font-size: 1.1rem;
    color: #ffffff;
    margin: 0;
    font-weight: 500;
    text-align: center;
}

/* Enhanced Button Styles */
.vs-matching-start-btn,
.vs-matching-restart-btn {
    background: #E7243B;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 8px;
    padding: 15px 40px;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 5px 5px 0px 0px #FED638;
    font-family: inherit;
}

.vs-matching-start-btn:hover,
.vs-matching-restart-btn:hover {
    background: #408aee;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 7px 7px 0px 0px #FED638;
}

.vs-matching-start-btn:active,
.vs-matching-restart-btn:active {
    transform: translateY(0px);
    box-shadow: 3px 3px 0px 0px #FED638;
}

/* Game Board */
.vs-matching-board {
    display: none;
    gap: 30px;
    height: auto;
    min-height: 600px;
}

.vs-matching-board.active {
    display: block;
}

/* Category Boxes - Updated Colors with Creativity Fix */
.vs-category-boxes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 40px;
}

.vs-category-box {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 3px solid;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    height: 400px;
    display: flex;
    flex-direction: column;
}

.vs-category-box:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
}

/* Updated Category Colors - Leadership now uses #408aee */
.vs-category-leadership {
    border-color: #408aee;
    background: linear-gradient(135deg, rgba(64, 138, 238, 0.15), rgba(64, 138, 238, 0.05));
}

.vs-category-creativity {
    border-color: #FED638;
    background: linear-gradient(135deg, rgba(254, 214, 56, 0.15), rgba(254, 214, 56, 0.05));
}

.vs-category-technical {
    border-color: #ff7fa5;
    background: linear-gradient(135deg, rgba(255, 127, 165, 0.15), rgba(255, 127, 165, 0.05));
}

.vs-category-communication {
    border-color: #ff6d4d;
    background: linear-gradient(135deg, rgba(255, 109, 77, 0.15), rgba(255, 109, 77, 0.05));
}

.vs-category-header {
    padding: 20px;
    text-align: center;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    background: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
}

.vs-category-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 10px;
}

.vs-category-name {
    font-size: 1.2rem;
    font-weight: 700;
    color: #1C1C1E;
}

/* Category Display Zone */
.vs-category-display-zone {
    flex: 1;
    padding: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.3);
    min-height: 200px;
    align-content: flex-start;
}

/* Category Drop Zone */
.vs-category-drop-zone {
    height: 120px;
    padding: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    background: rgba(0, 0, 0, 0.05);
    border-top: 3px dashed rgba(0, 0, 0, 0.2);
    border-radius: 0 0 20px 20px;
}

.vs-category-drop-zone:empty::before {
    content: 'ลากการ์ดมาวางที่นี่';
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    pointer-events: none;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.vs-category-drop-zone.vs-drag-over {
    background: rgba(254, 214, 56, 0.4);
    transform: scale(1.02);
    border-color: #FED638;
    border-style: solid;
}

.vs-category-drop-zone.vs-drag-over::before {
    content: '✨ วางที่นี่เลย!';
    color: #E6243B;
    font-weight: 700;
    animation: vs-drop-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes vs-drop-pulse {
    from { transform: scale(1); }
    to { transform: scale(1.1); }
}

/* Cards Deck */
.vs-cards-deck {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 3px solid #FED638;
    padding: 30px;
    min-height: 200px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    align-content: flex-start;
    overflow-y: auto;
    max-height: 300px;
}

/* Cards */
.vs-card {
    background: linear-gradient(135deg, #ffffff, #F9F9F9);
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 15px 20px;
    font-size: 1rem;
    font-weight: 600;
    color: #1C1C1E;
    cursor: grab;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    user-select: none;
    position: relative;
    min-width: 120px;
    text-align: center;
    line-height: 1.2;
    will-change: transform;
}

.vs-card:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    border-color: #FED638;
    background: linear-gradient(135deg, #FED638, #fef3cd);
    color: #1C1C1E;
}

.vs-card:active {
    cursor: grabbing;
    transform: rotate(3deg) scale(1.08);
}

.vs-card.vs-dragging {
    opacity: 0.8;
    transform: rotate(8deg) scale(1.1);
    z-index: 1000;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    background: linear-gradient(135deg, #FED638, #fef3cd);
}

.vs-card.vs-matched {
    opacity: 0.3;
    pointer-events: none;
    transform: scale(0.9);
    filter: grayscale(0.7);
}

/* Placed Cards in Categories - Updated Colors with Creativity Fix */
.vs-placed-card {
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #ffffff;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    animation: vs-card-place 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    flex-shrink: 0;
    max-width: fit-content;
    line-height: 1.2;
    white-space: nowrap;
    display: inline-block;
}

.vs-category-leadership .vs-placed-card {
    background: linear-gradient(135deg, #408aee, #3671d9);
    border: 2px solid #2563eb;
    color: #ffffff;
}

.vs-category-creativity .vs-placed-card {
    background: linear-gradient(135deg, #FED638, #e6c042);
    border: 2px solid #d4ac00;
}

.vs-category-technical .vs-placed-card {
    background: linear-gradient(135deg, #ff7fa5, #e85a8a);
    border: 2px solid #d4456f;
}

.vs-category-communication .vs-placed-card {
    background: linear-gradient(135deg, #ff6d4d, #e8583a);
    border: 2px solid #d14327;
}

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

/* Score Animation */
.vs-score-popup {
    position: fixed;
    font-size: 2rem;
    font-weight: 700;
    color: #FED638;
    text-shadow: 0 0 10px rgba(254, 214, 56, 0.8), 2px 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    z-index: 1000;
    animation: vs-score-float 1.5s ease-out forwards;
}

.vs-score-popup.vs-double-score {
    color: #E6243B;
    text-shadow: 0 0 15px rgba(230, 36, 59, 1), 2px 2px 4px rgba(0, 0, 0, 0.8);
    font-size: 2.5rem;
}

@keyframes vs-score-float {
    0% {
        opacity: 1;
        transform: translateY(0) scale(0.5);
    }
    30% {
        transform: translateY(-50px) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translateY(-100px) scale(1);
    }
}

/* Show Wrong Placement - CSS Animation */
@keyframes vs-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

/* Game Over Screen */
.vs-matching-game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.vs-matching-game-over.active {
    display: flex;
}

.vs-game-over-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 50px;
    border-radius: 25px;
    border: 3px solid #FED638;
    text-align: center;
    max-width: 600px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    animation: vs-game-over-appear 0.5s ease-out;
    position: relative;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes vs-game-over-appear {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

.vs-game-over-content h3 {
    font-size: 2.5rem;
    color: #E6243B;
    margin-bottom: 30px;
    font-weight: 700;
}

.vs-final-results {
    margin-bottom: 30px;
}

.vs-result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 12px 0;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
}

.vs-result-label {
    font-size: 1.2rem;
    color: #1C1C1E;
    font-weight: 500;
}

.vs-result-value {
    font-size: 1.5rem;
    color: #E6243B;
    font-weight: 700;
}

.vs-performance-badge {
    margin: 25px 0;
    padding: 20px;
    border-radius: 15px;
    background: linear-gradient(45deg, rgba(254, 214, 56, 0.2), rgba(230, 36, 59, 0.2));
    border: 2px solid #FED638;
}

.vs-performance-text {
    font-size: 1.4rem;
    font-weight: 600;
    color: #E6243B;
}

/* Enhanced Action Buttons */
.vs-save-screenshot-btn {
    background: #408aee;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 8px;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 0px 0px #FED638;
    font-family: inherit;
    margin: 8px 5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.vs-save-screenshot-btn:hover {
    background: #FED638;
    color: #000000;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0px 0px #408aee;
}

.vs-view-results-btn {
    background: #E7243B;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 8px;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 0px 0px #FED638;
    font-family: inherit;
    margin: 8px 5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.vs-view-results-btn:hover {
    background: #408aee;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0px 0px #FED638;
}

/* Gray Close Button */
.vs-close-results-btn {
    background: #6b7280;
    color: #ffffff;
    border: 2px solid #ffffff;
    border-radius: 8px;
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 3px 3px 0px 0px #FED638;
    font-family: inherit;
    margin: 8px 5px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.vs-close-results-btn:hover {
    background: #4b5563;
    color: #ffffff;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0px 0px #FED638;
}

.vs-save-screenshot-btn:active,
.vs-view-results-btn:active,
.vs-close-results-btn:active {
    transform: translateY(0px);
    box-shadow: 2px 2px 0px 0px #FED638;
}

.vs-save-screenshot-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Double Score Effect */
.vs-double-score-effect {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    font-weight: 700;
    color: #E6243B;
    text-shadow: 0 0 20px rgba(230, 36, 59, 1);
    pointer-events: none;
    z-index: 1500;
    animation: vs-double-score-announce 2s ease-out forwards;
}

@keyframes vs-double-score-announce {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
}

/* Particles Effect */
.vs-particle {
    position: fixed;
    width: 8px;
    height: 8px;
    background: #FED638;
    border-radius: 50%;
    pointer-events: none;
    z-index: 999;
    animation: vs-particle-float 2s ease-out forwards;
}

@keyframes vs-particle-float {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-200px) scale(0.3);
    }
}

/* Quote Section */
.vs-quote-section {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 3px solid #FED638;
    padding: 30px;
    margin-top: 30px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.vs-quote-section h3 {
    color: #E6243B;
    font-size: 1.5rem;
    margin-bottom: 20px;
    font-weight: 600;
}

.vs-quote-text {
    color: #1C1C1E;
    font-size: 1.1rem;
    line-height: 1.6;
    font-style: italic;
    font-weight: 500;
}

/* Result Mode */
.vs-game-result-mode .vs-cards-deck {
    display: none !important;
}

.vs-game-result-mode .vs-card,
.vs-game-result-mode .vs-category-drop-zone {
    pointer-events: none !important;
    cursor: default !important;
}

.vs-game-result-mode .vs-category-drop-zone::before {
    display: none !important;
}

/* Screenshot Mode */
.vs-screenshot-mode {
    position: relative;
    background: #E7243B;
    padding: 40px;
    border-radius: 20px;
    min-height: 600px;
    font-family: 'Kanit', sans-serif;
}

.vs-screenshot-mode .vs-matching-board {
    display: grid !important;
    height: auto;
    min-height: auto;
    grid-template-rows: 1fr;
}

.vs-screenshot-mode .vs-cards-deck {
    display: none !important;
}

.vs-screenshot-mode .vs-category-drop-zone::before {
    display: none !important;
}

.vs-screenshot-watermark {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 100px;
    height: auto;
    opacity: 0.9;
    z-index: 10;
}

/* Tablet adjustments */
@media (min-width: 800px) and (max-width: 1024px) {
    .vs-category-boxes {
        gap: 15px;
    }
    
    .vs-category-box {
        height: 350px;
    }
    
    .vs-cards-deck {
        max-height: 250px;
    }
}