* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #dc2626;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --x-color: #3b82f6;
    --o-color: #ec4899;
    --border-color: #334155;
    --hover-color: #475569;
    --win-color: #10b981;
}

[data-theme="light"] {
    --primary-color: #2563eb;
    --secondary-color: #dc2626;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-secondary: #64748b;
    --x-color: #3b82f6;
    --o-color: #ec4899;
    --border-color: #e2e8f0;
    --hover-color: #f1f5f9;
    --win-color: #10b981;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    padding: 0;
    margin: 0;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.main-header {
    width: 100%;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.1);
    position: fixed;
    top: 0;
    z-index: 100;
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 80px 20px 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 100px);
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 30px;
    max-width: 1200px;
    margin: 0 auto;
}


h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0;
}

.theme-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-color);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.theme-btn:hover {
    background: var(--hover-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.2);
}

.theme-icon {
    font-size: 1.1rem;
}

.theme-text {
    font-size: 0.85rem;
}

.game-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    justify-content: center;
    margin-bottom: 20px;
}

.game-settings {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.size-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.size-selector label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.size-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.size-btn {
    padding: 10px 20px;
    border: 2px solid var(--border-color);
    background: transparent;
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
    min-width: 100px;
}

.size-btn:hover {
    background: var(--hover-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.size-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

[data-theme="light"] .size-btn.active {
    color: white;
}

.player-turn-container {
    text-align: center;
    margin-bottom: 20px;
}

.player-turn {
    text-align: center;
    background: var(--card-bg);
    padding: 15px 30px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: inline-block;
    width: auto;
}

.game-center {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-score {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.current-player {
    font-size: 1.2rem;
    font-weight: 600;
}

.player-symbol {
    display: inline-block;
    padding: 5px 15px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 1.3rem;
    margin-left: 8px;
}

.player-symbol.x {
    color: var(--x-color);
    background: rgba(59, 130, 246, 0.1);
}

.player-symbol.o {
    color: var(--o-color);
    background: rgba(236, 72, 153, 0.1);
}

.score-board {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.score-item {
    text-align: center;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    min-width: 120px;
}

.score-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.score-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
}

.game-board {
    display: grid;
    gap: 10px;
    width: 500px;
    height: 500px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    grid-template-rows: repeat(var(--grid-size, 3), 1fr);
}

.game-board.size-3 {
    grid-template-columns: repeat(3, 1fr);
    --grid-size: 3;
}

.game-board.size-4 {
    grid-template-columns: repeat(4, 1fr);
    --grid-size: 4;
}

.game-board.size-5 {
    grid-template-columns: repeat(5, 1fr);
    --grid-size: 5;
}

.cell {
    background: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    line-height: 1;
    height: 100%;
    width: 100%;
}

.game-board.size-4 .cell {
    font-size: 2.5rem;
}

.game-board.size-5 .cell {
    font-size: 2rem;
}

.cell:hover:not(.taken) {
    background: var(--hover-color);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.cell.taken {
    cursor: not-allowed;
}

.cell.x {
    color: var(--x-color);
    animation: markX 0.4s ease;
}

.cell.o {
    color: var(--o-color);
    animation: markO 0.4s ease;
}

.cell::before {
    content: '';
    display: inline-block;
    height: 0;
    width: 0;
    vertical-align: middle;
}

.cell.taken {
    display: flex;
    align-items: center;
    justify-content: center;
}

.cell.winner {
    background: var(--win-color) !important;
    color: white !important;
    animation: winPulse 0.6s ease;
}

@keyframes markX {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

@keyframes markO {
    0% {
        transform: scale(0) rotate(180deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0);
        opacity: 1;
    }
}

@keyframes winPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.game-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.btn-secondary {
    background: transparent;
    color: var(--text-color);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--hover-color);
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.4s ease;
    max-width: 90%;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--primary-color);
}

@media (max-width: 1000px) {
    .header-content {
        padding: 15px 20px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .game-container {
        flex-direction: column;
        align-items: center;
    }

    .size-buttons {
        flex-direction: row;
    }

    .score-board {
        flex-direction: row;
    }

    .score-item {
        min-width: auto;
        flex: 1;
    }
}

@media (max-width: 600px) {
    .header-content {
        padding: 12px 15px;
    }

    h1 {
        font-size: 1.3rem;
    }

    .container {
        padding: 70px 15px 15px;
    }

    .game-board {
        padding: 15px;
        width: 90vw;
        height: 90vw;
        max-width: 400px;
        max-height: 400px;
    }

    .cell {
        font-size: 2rem;
        line-height: 1;
    }

    .game-board.size-4 .cell {
        font-size: 1.5rem;
    }

    .game-board.size-5 .cell {
        font-size: 1.2rem;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    .game-settings,
    .game-score {
        padding: 15px;
        width: 100%;
    }

    .theme-btn {
        padding: 8px 16px;
        font-size: 0.8rem;
    }

    .theme-text {
        font-size: 0.75rem;
    }

    .modal-content {
        padding: 30px 20px;
    }

    .modal-content h2 {
        font-size: 1.5rem;
    }
}

@media (max-width: 400px) {
    .size-buttons {
        flex-direction: column;
    }

    .size-btn {
        width: 100%;
    }

    .score-board {
        flex-direction: column;
        gap: 10px;
    }
}

