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

body {
    background: linear-gradient(135deg, #2c3e50 0%, #34495e 50%, #2c3e50 100%);
    text-align: center;
    font-family: 'Arial', sans-serif;
    min-height: 100vh;
    color: #ecf0f1;
    padding: 20px;
}

.container {
    height: 100vh;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
}

.game-title {
    font-size: 2.5rem;
    font-weight: bold;
    color: #ecf0f1;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.game-subtitle {
    font-size: 1.1rem;
    color: #d5dbdb; /* Changed from #bdc3c7 for better contrast */
    margin-top: 0.5rem;
    font-weight: 300;
}

.scoreboard {
    display: flex;
    gap: 30px;
    background: #2c3e50;
    padding: 15px 25px;
    border-radius: 10px;
    border: 2px solid #7f8c8d;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.score-item {
    text-align: center;
}

.score-label {
    font-size: 0.9rem;
    color: #d5dbdb; /* Changed from #bdc3c7 for better contrast */
    margin-bottom: 5px;
}

.score-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ecf0f1;
}

.score-item.wins .score-value {
    color: #27ae60;
}

.score-item.losses .score-value {
    color: #e74c3c;
}

.score-item.draws .score-value {
    color: #f39c12;
}

.game {
    display: grid;
    gap: 0.3rem;
    padding: 1rem;
    background: #34495e;
    border-radius: 12px;
    border: 3px solid #7f8c8d;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    max-width: min(90vw, 500px);
    max-height: min(90vw, 500px);
}

.game.size-3 {
    grid-template-columns: repeat(3, 1fr);
    height: min(400px, 80vw);
    width: min(400px, 80vw);
}

.game.size-3 .box {
    font-size: min(60px, 12vw);
    min-height: 80px;
}

.game.size-5 {
    grid-template-columns: repeat(5, 1fr);
    height: min(450px, 85vw);
    width: min(450px, 85vw);
    gap: 0.2rem;
}

.game.size-5 .box {
    font-size: min(40px, 8vw);
    min-height: 60px;
    border-radius: 6px;
}

.game.size-7 {
    grid-template-columns: repeat(7, 1fr);
    height: min(480px, 90vw);
    width: min(480px, 90vw);
    gap: 0.15rem;
}

.game.size-7 .box {
    font-size: min(30px, 6vw);
    min-height: 45px;
    border-radius: 4px;
}

.game.size-9 {
    grid-template-columns: repeat(9, 1fr);
    height: min(500px, 95vw);
    width: min(500px, 95vw);
    gap: 0.1rem;
}

.game.size-9 .box {
    font-size: min(24px, 5vw);
    min-height: 35px;
    border-radius: 3px;
}

.box {
    background: #ffffff; /* Pure white for maximum contrast */
    border: 2px solid #7f8c8d; /* Darker border for better visibility */
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    color: #2c3e50;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    font-family: 'Georgia', serif;
    aspect-ratio: 1;
}

.box:focus {
    outline: 3px solid #f39c12;
    outline-offset: 2px;
    border-color: #f39c12;
}

.box:hover, .box:focus-visible {
    background: #f8f9fa; /* Slightly off-white for hover state */
    border-color: #2980b9; /* Darker blue for better contrast */
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(41, 128, 185, 0.4);
}

.box:active {
    transform: translateY(0) scale(0.98);
    transition: all 0.1s ease;
}

.box.x {
    color: #a93226; /* Darker red for better contrast */
    text-shadow: 1px 1px 2px rgba(169, 50, 38, 0.3);
}

.box.o {
    color: #1f618d; /* Darker blue for better contrast */
    text-shadow: 1px 1px 2px rgba(31, 97, 141, 0.3);
}

#reset {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 8px;
    border: 2px solid #e74c3c;
    background: #e74c3c;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: none;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
    touch-action: manipulation;
    font-family: 'Arial', sans-serif;
}

#reset:focus {
    outline: 3px solid #f39c12;
    outline-offset: 2px;
}

#reset:hover {
    background: #c0392b;
    border-color: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(231, 76, 60, 0.4);
}

#reset:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.3);
}

.game-setup {
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    padding: 2rem;
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.game-setup h2, .game-setup h3 {
    color: #ecf0f1;
    margin-bottom: 1.5rem;
}

.mode-buttons, .difficulty-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.mode-btn, .difficulty-btn {
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 8px;
    border: 2px solid #2980b9; /* Darker blue for better contrast */
    background: transparent;
    color: #2980b9; /* Darker blue for better contrast */
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 120px;
}

.mode-btn:hover, .difficulty-btn:hover {
    background: #2980b9; /* Darker blue */
    color: white;
    transform: translateY(-2px);
}

.mode-btn.selected, .difficulty-btn.selected {
    background: #2980b9; /* Darker blue */
    color: white;
}

#start-game {
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 10px;
    border: 2px solid #27ae60;
    background: #27ae60;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

#start-game:hover {
    background: #229954;
    transform: translateY(-2px);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin-bottom: 1rem;
}

.current-player {
    font-size: 1.5rem;
    font-weight: bold;
    color: #ecf0f1;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    flex: 1;
    text-align: left;
}

.sound-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    backdrop-filter: blur(10px);
}

.sound-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

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

.sound-btn.muted {
    background: rgba(231, 76, 60, 0.2);
    border-color: rgba(231, 76, 60, 0.5);
}

.sound-btn.muted:hover {
    background: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.7);
}

.game-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

#new-game {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 8px;
    border: 2px solid #3498db;
    background: #3498db;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Arial', sans-serif;
}

#new-game:hover {
    background: #2980b9;
    transform: translateY(-2px);
}

/* Screen reader support */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    body {
        padding: 15px;
    }
    
    .container {
        gap: 25px;
    }
    
    .game {
        gap: 6px;
        padding: 12px;
        height: min(350px, 85vw);
        width: min(350px, 85vw);
    }
    
    .box {
        font-size: min(50px, 10vw);
        min-height: 70px;
        border-radius: 6px;
    }
    
    #reset {
        font-size: 15px;
        padding: 10px 20px;
    }
    
    .game-title {
        font-size: 2rem;
    }
    
    .game-subtitle {
        font-size: 1rem;
        color: #d5dbdb; /* Maintain better contrast on mobile */
    }
    
    .scoreboard {
        gap: 20px;
        padding: 12px 20px;
    }
    
    .score-label {
        font-size: 0.8rem;
        color: #d5dbdb; /* Maintain better contrast on mobile */
    }
    
    .score-value {
        font-size: 1.3rem;
    }
    
    .mode-buttons, .difficulty-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .mode-btn, .difficulty-btn {
        min-width: 200px;
    }
    
    .game-controls {
        flex-direction: column;
        align-items: center;
    }
    
    .size-buttons {
        gap: 0.5rem;
    }
    
    .size-btn {
        padding: 8px 16px;
        font-size: 0.8rem;
        min-width: 50px;
    }
    
    .game.size-3 .box {
        font-size: min(50px, 10vw);
        min-height: 70px;
    }
    
    .game.size-5 .box {
        font-size: min(35px, 7vw);
        min-height: 50px;
    }
    
    .game.size-7 .box {
        font-size: min(25px, 5vw);
        min-height: 40px;
    }
    
    .game.size-9 .box {
        font-size: min(20px, 4vw);
        min-height: 30px;
    }
    
    .game-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .current-player {
        text-align: center;
        font-size: 1.3rem;
    }
    
    .sound-btn {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }
    
    footer {
        font-size: 0.8rem;
        padding: 0.8rem;
        color: #bdc3c7; /* Maintain readable contrast */
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 1.5rem;
    }
    
    .scoreboard {
        gap: 15px;
        padding: 10px 15px;
    }
    
    .score-label {
        font-size: 0.7rem;
    }
    
    .score-value {
        font-size: 1.1rem;
    }
    
    .current-player {
        font-size: 1.1rem;
    }
    
    .sound-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }
    
    .game.size-3 .box {
        font-size: min(45px, 9vw);
        min-height: 60px;
    }
    
    .game.size-5 .box {
        font-size: min(30px, 6vw);
        min-height: 45px;
    }
    
    .game.size-7 .box {
        font-size: min(22px, 4.5vw);
        min-height: 35px;
    }
    
    .game.size-9 .box {
        font-size: min(18px, 3.5vw);
        min-height: 25px;
    }
    
    .game-subtitle {
        font-size: 0.9rem;
        color: #d5dbdb; /* Maintain better contrast on small screens */
    }
}

.board-size-selection {
    margin: 1.5rem 0;
}

.board-size-selection h3 {
    color: #ecf0f1;
    margin-bottom: 1rem;
}

.size-buttons {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
    flex-wrap: wrap;
}

.size-btn {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 6px;
    border: 2px solid #d68910; /* Darker orange for better contrast */
    background: transparent;
    color: #d68910; /* Darker orange for better contrast */
    cursor: pointer;
    transition: all 0.3s ease;
    min-width: 60px;
}

.size-btn:hover {
    background: #d68910; /* Darker orange */
    color: white;
    transform: translateY(-1px);
}

.size-btn.selected {
    background: #d68910; /* Darker orange */
    color: white;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

footer {
    margin-top: 2rem;
    padding: 1rem;
    text-align: center;
    color: #bdc3c7; /* Improved contrast against dark background */
    font-size: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2); /* Increased opacity for visibility */
}

.game-message {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.message-content {
    background: linear-gradient(145deg, #2c3e50, #34495e);
    border-radius: 20px;
    padding: 2rem;
    text-align: center;
    border: 3px solid #3498db;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: 90%;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#message-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #ecf0f1;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

#message-text {
    font-size: 1.2rem;
    margin-bottom: 1.5rem;
    color: #d5dbdb;
    line-height: 1.4;
}

.message-btn {
    padding: 12px 30px;
    font-size: 1rem;
    font-weight: bold;
    border-radius: 10px;
    border: 2px solid #27ae60;
    background: #27ae60;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Arial', sans-serif;
}

.message-btn:hover {
    background: #229954;
    border-color: #229954;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(39, 174, 96, 0.4);
}

.message-btn:active {
    transform: translateY(0);
}

@media (max-width: 768px) {
    .message-content {
        padding: 1.5rem;
        margin: 1rem;
    }
    
    #message-title {
        font-size: 1.5rem;
    }
    
    #message-text {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .message-content {
        padding: 1rem;
    }
    
    #message-title {
        font-size: 1.3rem;
    }
    
    #message-text {
        font-size: 0.9rem;
    }
}