* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, #0c0c0c 0%, #1a1a2e 50%, #16213e 100%);
    color: #ffffff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow-x: hidden;
    /* Added vertical padding as requested and some horizontal for small screens */
    padding: 50px 15px;
}

/* Animated background particles */
.particles {
    position: absolute;
    width: 100%;
    /* Changed height to 100% to fill the new padded body */
    height: 100%;
    overflow: hidden;
    z-index: -1;
    top: 0;
    left: 0;
}

.particle {
    position: absolute;
    background: rgba(74, 144, 226, 0.3);
    border-radius: 50%;
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px) rotate(0deg); opacity: 1; }
    50% { transform: translateY(-20px) rotate(180deg); opacity: 0.8; }
}

.game-container {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    max-width: 500px;
    width: 100%;
    text-align: center;
    position: relative;
}

.header {
    /* Adjusted margin for better spacing */
    margin-bottom: 20px;
}

.title {
    /* Replaced fixed font-size with clamp() for fluid typography */
    font-size: clamp(2.2em, 8vw, 3em);
    font-weight: 700;
    background: linear-gradient(135deg, #4a90e2, #7b68ee);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 30px;
    /* Removed fragile positioning for a more robust layout */
}

.controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: center;
    /* Removed fragile positioning */
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    font-size: 0.9em;
    color: #b0b0b0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

select, button {
    padding: 8px 15px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

select:hover, button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.scoreboard {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 15px;
}

.score-item {
    text-align: center;
}

.score-label {
    font-size: 0.8em;
    color: #b0b0b0;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-value {
    font-size: 1.5em;
    font-weight: bold;
}

.player-x { color: #4a90e2; }
.player-o { color: #e74c3c; }
.draws { color: #f39c12; }

.status {
    font-size: 1.3em;
    font-weight: 600;
    margin: 20px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border-left: 4px solid #4a90e2;
    transition: all 0.3s ease;
}

.status.winner {
    animation: pulse 2s ease-in-out infinite;
    border-left-color: #2ecc71;
    background: rgba(46, 204, 113, 0.1);
}

.status.draw {
    border-left-color: #f39c12;
    background: rgba(243, 156, 18, 0.1);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin: 25px auto;
    /* Using width 100% to make the board scale within the container */
    width: 100%;
    max-width: 350px;
    perspective: 1000px;
}

.cell {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Replaced fixed font-size with clamp() for fluid 'X' and 'O' marks */
    font-size: clamp(2.5em, 12vw, 3.5em);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
}

.cell::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;
}

.cell:hover::before {
    left: 100%;
}

.cell:hover {
    transform: translateY(-5px) rotateX(5deg);
    box-shadow: 0 15px 30px rgba(74, 144, 226, 0.3);
    border-color: rgba(74, 144, 226, 0.5);
}

.cell:active {
    transform: translateY(-2px) scale(0.95);
}

.cell.x {
    color: #4a90e2;
    text-shadow: 0 0 20px rgba(74, 144, 226, 0.5);
}

.cell.o {
    color: #e74c3c;
    text-shadow: 0 0 20px rgba(231, 76, 60, 0.5);
}

.cell.winning {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.3), rgba(46, 204, 113, 0.1));
    animation: winning-glow 2s ease-in-out infinite;
    border-color: #2ecc71;
}

@keyframes winning-glow {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(46, 204, 113, 0.5);
        transform: scale(1);
    }
    50% { 
        box-shadow: 0 0 30px rgba(46, 204, 113, 0.8);
        transform: scale(1.05);
    }
}

.actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

.btn {
    padding: 12px 25px;
    font-size: 1em;
    font-weight: 600;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, #4a90e2, #357abd);
    color: white;
    box-shadow: 0 5px 15px rgba(74, 144, 226, 0.3);
}

.btn-secondary {
    background: linear-gradient(135deg, #6c757d, #545b62);
    color: white;
    box-shadow: 0 5px 15px rgba(108, 117, 125, 0.3);
}

.btn-danger {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    box-shadow: 0 5px 15px rgba(231, 76, 60, 0.3);
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(-1px);
}

.game-stats {
    margin-top: 20px;
    display: flex;
    justify-content: space-around;
    font-size: 0.9em;
    color: #b0b0b0;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 1.2em;
    font-weight: bold;
    color: white;
}

/* Sound toggle */
.sound-toggle {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.3s ease;
}

.sound-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.sound-off {
    opacity: 0.5;
}

/* Responsive design for smaller devices */
@media (max-width: 600px) {
    body {
        /* Reduce padding on smaller screens */
        padding: 20px 15px;
        /* Ensure content aligns to the top on small screens if it overflows */
        align-items: flex-start;
    }

    .game-container {
        padding: 20px;
    }
    
    .controls {
        flex-direction: column;
        gap: 10px;
    }
    
    .actions {
        flex-direction: column;
    }

    .board {
        gap: 10px;
    }
}
