/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px;
    overflow-x: hidden;
    user-select: none;
}

.game-container {
    max-width: 800px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    min-height: calc(100vh - 20px);
    position: relative;
}

/* Header Styles */
.game-header {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    color: white;
    padding: 20px;
    text-align: center;
}

.game-header h1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    margin-bottom: 5px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.current-category {
    font-size: clamp(0.8rem, 2vw, 1rem);
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 15px;
    border-radius: 15px;
    display: inline-block;
    backdrop-filter: blur(10px);
}

.score-display {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: clamp(0.9rem, 2.5vw, 1.2rem);
    font-weight: bold;
    flex-wrap: wrap;
}

.stat {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

/* Progress Bar */
.progress-container {
    padding: 20px;
    text-align: center;
}

.progress-bar {
    background: #e9ecef;
    border-radius: 10px;
    height: 20px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    height: 100%;
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 10px;
}

.progress-text {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    color: #666;
    font-weight: bold;
}

/* Instructions */
.instructions {
    background: #fff3cd;
    border: 2px solid #ffeaa7;
    border-radius: 15px;
    padding: 20px;
    margin: 20px;
    text-align: center;
}

.instruction-title {
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: #856404;
    margin-bottom: 10px;
    font-weight: bold;
}

.instruction-text {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    color: #856404;
    line-height: 1.5;
    margin-bottom: 20px;
}

.instruction-features {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
    text-align: left;
}

.feature {
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    color: #856404;
    padding: 8px 12px;
    background: rgba(255, 234, 167, 0.3);
    border-radius: 8px;
}

/* Category Selection */
.category-selection {
    padding: 20px;
    margin: 20px;
    background: linear-gradient(145deg, #f8f9fa, #e9ecef);
    border-radius: 15px;
}

.category-title {
    text-align: center;
    font-size: clamp(1.2rem, 4vw, 1.8rem);
    color: #333;
    margin-bottom: 10px;
    font-weight: bold;
}

.category-subtitle {
    text-align: center;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    color: #666;
    margin-bottom: 25px;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.category-card {
    background: white;
    border: 3px solid #e9ecef;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.category-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    border-color: #4ecdc4;
}

.category-card.selected {
    border-color: #4ecdc4;
    background: rgba(78, 205, 196, 0.05);
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(78, 205, 196, 0.3);
}

.category-icon {
    font-size: clamp(2.5rem, 6vw, 4rem);
    margin-bottom: 10px;
}

.category-name {
    font-size: clamp(1rem, 3vw, 1.2rem);
    font-weight: bold;
    color: #333;
    margin-bottom: 8px;
}

.category-description {
    font-size: clamp(0.8rem, 2vw, 0.9rem);
    color: #666;
    margin-bottom: 15px;
    line-height: 1.4;
}

.category-preview {
    font-size: clamp(1.5rem, 4vw, 2rem);
    letter-spacing: 8px;
    opacity: 0.7;
}

/* Selected Category Info */
.selected-category-info {
    background: white;
    border: 2px solid #4ecdc4;
    border-radius: 15px;
    padding: 20px;
    text-align: center;
    animation: slideIn 0.3s ease-out;
}

.selected-title {
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: #4ecdc4;
    font-weight: bold;
    margin-bottom: 10px;
}

.selected-name {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    color: #333;
    font-weight: bold;
    margin-bottom: 8px;
}

.selected-description {
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    color: #666;
    margin-bottom: 15px;
}

.category-preview .preview-item {
    display: inline-block;
    font-size: clamp(2rem, 5vw, 2.5rem);
    margin: 0 8px;
    padding: 8px;
    background: rgba(78, 205, 196, 0.1);
    border-radius: 12px;
    animation: bounce 0.5s ease-in-out infinite alternate;
}

.category-preview .preview-item:nth-child(2) { animation-delay: 0.1s; }
.category-preview .preview-item:nth-child(3) { animation-delay: 0.2s; }
.category-preview .preview-item:nth-child(4) { animation-delay: 0.3s; }

.category-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
    flex-wrap: wrap;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-5px); }
}

/* Mobile Responsive Adjustments - Medium Mobile */
@media (max-width: 600px) and (min-width: 481px) {
    .btn {
        min-width: 130px;
        padding: 14px 24px;
        font-size: clamp(1rem, 3vw, 1.2rem);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        min-height: 48px;
    }
    
    .game-controls {
        padding: 20px 15px;
        gap: 15px;
        flex-wrap: wrap;
    }
    
    .magic-item {
        width: 85px;
        height: 85px;
        font-size: clamp(2.2rem, 5.2vw, 2.8rem);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .magic-tray {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
        gap: 15px;
        padding: 20px;
        min-height: 200px;
    }
    
    .items-grid {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
        gap: 15px;
    }
    
    .category-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .category-card {
        min-height: 130px;
        padding: 25px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .selection-controls {
        display: flex;
        gap: 15px;
        justify-content: center;
        margin-top: 20px;
        flex-wrap: wrap;
    }
}

/* Mobile Responsive Adjustments - Medium Mobile */
@media (max-width: 600px) {
    .btn {
        min-width: 110px;
        padding: 12px 20px;
        font-size: clamp(0.9rem, 3vw, 1.1rem);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .game-controls {
        padding: 20px 15px;
        gap: 12px;
    }
    
    .magic-item {
        width: 80px;
        height: 80px;
        font-size: clamp(2rem, 5vw, 2.5rem);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .magic-tray {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 12px;
        padding: 18px;
        min-height: 180px;
    }
    
    .items-grid {
        grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
        gap: 12px;
    }
    
    .category-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .category-card {
        min-height: 120px;
        padding: 20px;
    }
}

/* Mobile Responsive Adjustments - Small Mobile */
@media (max-width: 480px) {
    .magic-item {
        width: 90px;
        height: 90px;
        font-size: clamp(2.2rem, 5.5vw, 3rem);
    }
    
    .magic-tray {
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
        gap: 15px;
        padding: 20px;
        min-height: 220px;
    }
    
    .items-grid {
        grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
        gap: 15px;
    }
    
    .btn {
        min-width: 120px;
        padding: 14px 22px;
        font-size: clamp(1rem, 3.5vw, 1.2rem);
    }
    
    .category-preview .preview-item {
        font-size: clamp(1.5rem, 4vw, 2rem);
        margin: 0 5px;
        padding: 5px;
    }
}

@media (max-width: 320px) {
    .magic-item {
        width: 85px;
        height: 85px;
        font-size: clamp(2rem, 5vw, 3rem);
    }
    
    .magic-tray {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
        gap: 12px;
        padding: 15px;
        min-height: 200px;
    }
    
    .items-grid {
        grid-template-columns: repeat(auto-fit, minmax(85px, 1fr));
        gap: 12px;
    }
}

/* Magic Tray */
.magic-tray-container {
    margin: 20px;
    padding: 20px;
    background: linear-gradient(145deg, #f0f0f0, #e0e0e0);
    border-radius: 15px;
    box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.1);
}

.tray-title {
    text-align: center;
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: #333;
    margin-bottom: 15px;
    font-weight: bold;
}

.magic-tray {
    background: white;
    border: 3px dashed #ccc;
    border-radius: 15px;
    min-height: 280px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 20px;
    padding: 25px;
    position: relative;
}

.magic-tray.active {
    border-color: #4ecdc4;
    background: rgba(78, 205, 196, 0.05);
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
}

.tray-status {
    text-align: center;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    color: #666;
    margin-top: 10px;
    font-weight: bold;
}

/* Magic Items */
.magic-item {
    width: 120px;
    height: 120px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(3rem, 7vw, 4.5rem);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    margin: 0 auto;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-width: 44px; /* Minimum touch target */
    min-height: 44px; /* Minimum touch target */
}

.magic-item.appear {
    animation: itemAppear 0.5s ease-out;
}

.magic-item.disappear {
    animation: itemDisappear 0.3s ease-in;
}

.magic-item.selected {
    transform: scale(1.15);
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.8);
    border: 4px solid #4ecdc4;
}

.magic-item.correct {
    animation: correctPulse 0.6s ease-in-out;
}

.magic-item.incorrect {
    animation: incorrectShake 0.5s ease-in-out;
}

/* Item Colors */
.item-red { background: linear-gradient(145deg, #ff6b6b, #ee5a52); }
.item-blue { background: linear-gradient(145deg, #4ecdc4, #45b7aa); }
.item-green { background: linear-gradient(145deg, #95e1d3, #7dd3c0); }
.item-yellow { background: linear-gradient(145deg, #fce38a, #f9ca24); }
.item-purple { background: linear-gradient(145deg, #a8e6cf, #88d8c0); }
.item-orange { background: linear-gradient(145deg, #ffb347, #ff9500); }
.item-pink { background: linear-gradient(145deg, #ff8a95, #ff6b7a); }
.item-cyan { background: linear-gradient(145deg, #74b9ff, #0984e3); }

/* Selection Area */
.selection-area {
    background: #f8f9fa;
    padding: 20px;
    margin: 20px;
    border-radius: 15px;
}

.selection-title {
    text-align: center;
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: #555;
    margin-bottom: 15px;
    font-weight: bold;
}

.items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
    justify-items: center;
}

.selection-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-size: clamp(0.9rem, 2.5vw, 1rem);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
    min-height: 44px; /* Minimum touch target size */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
    color: white;
}

.btn-secondary {
    background: linear-gradient(45deg, #a8e6cf, #88d8c0);
    color: #333;
}

.btn:hover, .btn:active {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

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

/* Game Controls */
.game-controls {
    display: flex;
    gap: 10px;
    padding: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Result Overlay */
.result-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.result-overlay.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.result-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.result-icon {
    font-size: clamp(3rem, 8vw, 5rem);
    margin-bottom: 20px;
}

.result-title {
    font-size: clamp(1.5rem, 4vw, 2rem);
    color: #333;
    margin-bottom: 10px;
    font-weight: bold;
}

.result-message {
    font-size: clamp(1rem, 3vw, 1.2rem);
    color: #666;
    margin-bottom: 30px;
    line-height: 1.5;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.settings-panel.show {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.settings-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    max-width: 90%;
    width: 400px;
}

.settings-content h3 {
    text-align: center;
    margin-bottom: 20px;
    color: #333;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    flex-wrap: wrap;
}

.setting-item small {
    width: 100%;
    color: #666;
    font-size: 0.8rem;
    margin-top: 5px;
    font-style: italic;
}

.setting-item label {
    font-weight: bold;
    color: #555;
}

.setting-item select,
.setting-item input {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

/* Animations */
@keyframes itemAppear {
    from {
        opacity: 0;
        transform: scale(0.3) rotate(180deg);
    }
    50% {
        opacity: 0.8;
        transform: scale(1.1) rotate(90deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes itemDisappear {
    from {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.5;
        transform: scale(1.1);
    }
    to {
        opacity: 0;
        transform: scale(0.3);
    }
}

@keyframes correctPulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
    }
    50% { 
        transform: scale(1.3);
        box-shadow: 0 0 25px rgba(76, 175, 80, 0.8);
    }
}

@keyframes incorrectShake {
    0%, 100% { 
        transform: translateX(0);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.25);
    }
    25% { 
        transform: translateX(-15px);
        box-shadow: 0 0 20px rgba(244, 67, 54, 0.6);
    }
    75% { 
        transform: translateX(15px);
        box-shadow: 0 0 20px rgba(244, 67, 54, 0.6);
    }
}
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .game-container {
        margin: 5px;
        border-radius: 15px;
        min-height: calc(100vh - 10px);
    }

    .magic-tray-container,
    .selection-area,
    .instructions {
        margin: 15px;
        padding: 15px;
    }

    .magic-tray {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        gap: 10px;
        padding: 15px;
        min-height: 150px;
    }

    .magic-item {
        width: 70px;
        height: 70px;
        font-size: clamp(1.5rem, 4vw, 2rem);
    }

    .items-grid {
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
        gap: 10px;
    }

    .game-controls {
        padding: 15px;
        gap: 8px;
    }

    .btn {
        min-width: 100px;
        padding: 10px 20px;
    }

    .score-display {
        gap: 15px;
    }
}

/* Touch Feedback - Enhanced for mobile */
@media (hover: none) and (pointer: coarse) {
    .magic-item:active,
    .btn:active,
    .category-card:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
    
    .btn:active {
        background: linear-gradient(45deg, #ff5252, #26c6da);
    }
    
    .btn-secondary:active {
        background: linear-gradient(45deg, #81c784, #4db6ac);
    }
    
    /* Ensure buttons are always clickable */
    .btn {
        pointer-events: auto !important;
        position: relative;
        z-index: 10;
    }
    
    .magic-item {
        pointer-events: auto !important;
        position: relative;
        z-index: 5;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .magic-item {
        border: 2px solid #000;
    }
    
    .btn {
        border: 2px solid #000;
    }
}
