/* ===============================================
   CSS Variables for Consistent Theming
   =============================================== */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --success-color: #27ae60;
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --cell-bg: #ffffff;
    --cell-hover: #ecf0f1;
    --cell-active: #d5dbdb;
    --text-primary: #2c3e50;
    --text-secondary: #7f8c8d;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.15);
    --border-radius: 12px;
    --transition-speed: 0.3s;
}

/* ===============================================
   Base Styles & Reset
   =============================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    color: var(--text-primary);
}

/* ===============================================
   Container & Layout
   =============================================== */
.container {
    max-width: 600px;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: 40px 30px;
    backdrop-filter: blur(10px);
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    font-weight: 700;
    letter-spacing: 1px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===============================================
   Game Status Display
   =============================================== */
.game-status {
    text-align: center;
    margin-bottom: 25px;
}

.status-text {
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--primary-color);
    padding: 12px 24px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
}

.status-text.winner {
    animation: celebration 0.6s ease-in-out;
}

@keyframes celebration {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ===============================================
   Game Board
   =============================================== */
.game-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-gap: 12px;
    margin: 0 auto 30px;
    max-width: 450px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
}

.cell {
    aspect-ratio: 1;
    background: var(--cell-bg);
    border: 3px solid transparent;
    border-radius: 10px;
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary-color);
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.cell:hover:not(:disabled) {
    background: var(--cell-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--secondary-color);
}

.cell:active:not(:disabled) {
    transform: translateY(0);
    background: var(--cell-active);
}

.cell:disabled {
    cursor: not-allowed;
    opacity: 0.9;
}

/* Player Marks Styling */
.cell.x {
    color: var(--secondary-color);
    animation: markAppear 0.3s ease-in-out;
}

.cell.o {
    color: var(--accent-color);
    animation: markAppear 0.3s ease-in-out;
}

@keyframes markAppear {
    0% {
        transform: scale(0) rotate(180deg);
        opacity: 0;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Winning Line Highlight */
.cell.winner {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    animation: winnerPulse 0.8s ease-in-out infinite;
}

@keyframes winnerPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(245, 87, 108, 0.5);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 20px rgba(245, 87, 108, 0.8);
    }
}

/* ===============================================
   Controls & Buttons
   =============================================== */
.controls {
    text-align: center;
    margin-bottom: 30px;
}

.btn-reset {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #2980b9 100%);
    color: white;
    border: none;
    padding: 14px 40px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
    box-shadow: var(--shadow-md);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-reset:hover {
    background: linear-gradient(135deg, #2980b9 0%, var(--secondary-color) 100%);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-reset:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}

/* ===============================================
   Scoreboard
   =============================================== */
.scoreboard {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(255, 255, 255, 0.6);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.score-item {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.score-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.score-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--accent-color) 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ===============================================
   Footer
   =============================================== */
footer {
    text-align: center;
    margin-top: 20px;
}

footer p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ===============================================
   Responsive Design
   =============================================== */
@media (max-width: 600px) {
    .container {
        padding: 30px 20px;
    }

    header h1 {
        font-size: 2rem;
    }

    .status-text {
        font-size: 1.2rem;
        padding: 10px 20px;
    }

    .game-board {
        padding: 15px;
        grid-gap: 10px;
    }

    .cell {
        font-size: 2.5rem;
    }

    .btn-reset {
        padding: 12px 32px;
        font-size: 1rem;
    }

    .score-label {
        font-size: 0.8rem;
    }

    .score-value {
        font-size: 1.6rem;
    }
}

@media (max-width: 400px) {
    header h1 {
        font-size: 1.6rem;
    }

    .cell {
        font-size: 2rem;
    }

    .scoreboard {
        flex-direction: column;
        gap: 15px;
    }

    .score-item {
        flex-direction: row;
        gap: 12px;
        width: 100%;
        justify-content: center;
    }
}

/* ===============================================
   Accessibility Improvements
   =============================================== */
.cell:focus-visible {
    outline: 3px solid var(--secondary-color);
    outline-offset: 2px;
}

.btn-reset:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
