* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Arial', sans-serif;
}

body {
    background-color: #f0f4f8;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    user-select: none;
}

.container {
    max-width: 95%;
    width: 100%;
    max-width: 1200px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin: 0 auto;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

h1 {
    color: #2d3748;
    font-size: 1.8rem;
    margin: 0;
}

.difficulty-selector {
    display: flex;
    gap: 1rem;
    padding: 0.8rem;
    background-color: #f5f5f5;
    border-radius: 8px;
}

.difficulty-btn {
    padding: 0.6rem 1.5rem;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    background-color: white;
    color: #4a5568;
    font-weight: 500;
}

.difficulty-btn.active {
    background-color: #4299e1;
    color: white;
    border-color: #4299e1;
    box-shadow: 0 2px 6px rgba(66, 153, 225, 0.3);
}

.difficulty-btn:hover:not(.active) {
    border-color: #4299e1;
    color: #4299e1;
}

.rules {
    background-color: #f8f9fa;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    color: #4a5568;
    line-height: 1.5;
    font-size: 1rem;
}

.rules h3 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.stone-piles {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1.5rem 0;
    width: 100%;
}

.pile-count-3 .pile {
    max-width: 32%;
    min-width: 200px;
}

.pile-count-5 .pile {
    max-width: 18%;
    min-width: 150px;
}

.pile {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #fafafa;
    padding: 1.2rem;
    border-radius: 12px;
    flex: 1;
    min-width: 0;
    min-height: auto;
    border: 1px solid #eee;
}

.pile-title {
    font-size: 0.9rem;
    color: #2d3748;
    margin-bottom: 1rem;
    font-weight: 600;
    text-align: center;
    width: 100%;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #eee;
}

.stones {
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
    justify-content: center;
    align-content: flex-start;
    margin-bottom: 1rem;
    width: 100%;
    padding: 0.8rem;
    background-color: #f5f5f5;
    border-radius: 10px;
    cursor: pointer;
    position: relative;
}

.stones.dragging {
    cursor: grabbing;
    background-color: #e8f4f8;
}

.stone {
    width: 22px;
    height: 22px;
    background-color: #f0e6d2;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    box-shadow: 0 2px 3px rgba(0,0,0,0.1), 
                inset 0 -2px 3px rgba(0,0,0,0.05),
                inset 2px 0 3px rgba(255,255,255,0.15);
    color: #8b5a2b;
    transition: all 0.2s;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    touch-action: none;
}

.stone:nth-child(5n+1) { transform: translate(1px, 1px) rotate(2deg); }
.stone:nth-child(5n+2) { transform: translate(-1px, 0) rotate(-1deg); }
.stone:nth-child(5n+3) { transform: translate(0, -1px) rotate(1deg); }
.stone:nth-child(5n+4) { transform: translate(1px, -1px) rotate(-2deg); }
.stone:nth-child(5n) { transform: translate(-1px, 1px) rotate(1deg); }

.stone:hover {
    transform: scale(1.2) rotate(0deg);
    background-color: #e8d8b8;
    z-index: 10;
    box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}

.stone.selected {
    background-color: #4299e1;
    color: white;
    box-shadow: 0 2px 6px rgba(66, 153, 225, 0.4);
    transform: scale(1.1) rotate(0deg);
    z-index: 5;
}

.selection-box {
    position: absolute;
    border: 2px solid #4299e1;
    background-color: rgba(66, 153, 225, 0.1);
    pointer-events: none;
    z-index: 20;
    display: none;
}

.pile-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eee;
}

.selected-count {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    color: #4a5568;
    font-weight: 500;
}

.take-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    background-color: #48bb78;
    color: white;
    width: 100%;
    min-width: 80px;
}

.take-btn:hover {
    background-color: #38a169;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(56, 161, 105, 0.2);
}

.take-btn:disabled {
    background-color: #cbd5e0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.global-controls {
    display: flex;
    justify-content: center;
    margin: 1.2rem 0;
}

#reset-btn {
    padding: 0.6rem 1.8rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    background-color: #e53e3e;
    color: white;
    box-shadow: 0 4px 8px rgba(229, 62, 62, 0.15);
}

#reset-btn:hover {
    background-color: #c53030;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(229, 62, 62, 0.2);
}

.status {
    font-size: 1.1rem;
    font-weight: bold;
    text-align: center;
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 10px;
    width: 100%;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e8f4f8;
    color: #2d3748;
}

.computer-turn {
    background-color: #f5fafe;
    color: #4299e1;
}

.game-over {
    background-color: #fdf2f8;
    color: #e53e3e;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.8; }
    100% { opacity: 1; }
}

@media (max-width: 1024px) {
    .pile-count-5 .pile {
        max-width: 30%;
    }
}

@media (max-width: 768px) {
    .pile-count-3 .pile,
    .pile-count-5 .pile {
        max-width: 48%;
    }
}

@media (max-width: 480px) {
    .pile-count-3 .pile,
    .pile-count-5 .pile {
        max-width: 100%;
    }
    
    .stone {
        width: 20px;
        height: 20px;
        font-size: 11px;
    }
    
    .difficulty-selector {
        flex-direction: column;
        width: 100%;
    }
    
    .difficulty-btn {
        width: 100%;
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    h1 {
        font-size: 1.5rem;
    }
}