/* CSS Custom Properties for Theming */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #dc2626;
    --secondary-hover: #b91c1c;
    --bg-color: #ffffff;
    --text-color: #1f2937;
    --border-color: #e5e7eb;
    --cell-size: 80px;
    --cell-gap: 8px;
    --border-radius: 8px;
    --transition: all 0.2s ease-in-out;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 0.5rem;
    padding: 1.5rem 0;
    position: relative;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

/* Language Switcher - Discrete Dropdown */
.language-switcher {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    z-index: 100;
}

.language-switcher:hover {
    opacity: 1;
}

.lang-btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.35rem 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: 40px;
    min-height: 32px;
    opacity: 0.7;
}

.lang-btn:hover {
    opacity: 1;
    border-color: var(--primary-color);
    background-color: rgba(37, 99, 235, 0.05);
}

.lang-btn:focus {
    outline: 1px solid var(--primary-color);
    outline-offset: 1px;
    opacity: 1;
}

.lang-arrow {
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    opacity: 0.7;
}

.lang-btn[aria-expanded="true"] .lang-arrow {
    transform: rotate(180deg);
}

.lang-dropdown {
    position: absolute;
    top: calc(100% + 0.25rem);
    right: 0;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    min-width: 140px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    overflow: hidden;
}

.lang-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.lang-item {
    width: 100%;
    background-color: transparent;
    border: none;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-align: left;
    color: var(--text-color);
    min-height: 40px;
}

.lang-item:hover {
    background-color: rgba(37, 99, 235, 0.05);
}

.lang-item:focus {
    outline: 1px solid var(--primary-color);
    outline-offset: -1px;
}

.lang-item.active {
    background-color: rgba(37, 99, 235, 0.1);
    font-weight: 600;
}

.lang-item span {
    flex: 1;
}

.subtitle {
    font-size: 1rem;
    color: #6b7280;
    font-weight: 400;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.game-container {
    width: 100%;
    max-width: 100%;
}

/* Game Info */
.game-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

/* Game Mode Selector */
.game-mode-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    width: 100%;
}

.game-mode-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #6b7280;
    text-align: center;
}

.game-mode-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.game-mode-btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-color);
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    touch-action: manipulation;
    min-height: 40px;
    min-width: 120px;
}

.game-mode-btn:hover {
    border-color: var(--primary-color);
    background-color: rgba(37, 99, 235, 0.05);
    transform: translateY(-1px);
}

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

.game-mode-btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.game-mode-btn.active {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    font-weight: 600;
}

.game-mode-btn.active:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.status {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
    text-align: center;
    min-height: 1.5rem;
}

.reset-btn {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    background-color: var(--primary-color);
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    touch-action: manipulation;
    min-height: 44px;
    min-width: 120px;
}

.reset-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

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

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

/* Game Board */
.board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--cell-gap);
    width: 100%;
    max-width: calc(var(--cell-size) * 3 + var(--cell-gap) * 2);
    margin: 0 auto;
    aspect-ratio: 1;
}

.cell {
    width: 100%;
    aspect-ratio: 1;
    min-height: 44px;
    background-color: var(--bg-color);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-color);
    cursor: pointer;
    transition: var(--transition);
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    -webkit-user-select: none;
    user-select: none;
}

.cell:hover:not(:disabled) {
    background-color: #f9fafb;
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.cell:active:not(:disabled) {
    transform: scale(0.95);
}

.cell:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

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

.cell.x::before {
    content: 'X';
    color: var(--primary-color);
}

.cell.o::before {
    content: 'O';
    color: var(--secondary-color);
}

.cell.winning {
    background-color: #dbeafe;
    border-color: var(--primary-color);
    animation: pulse 0.5s ease-in-out;
}

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

/* Score */
.score {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: #6b7280;
}

.score span:first-child {
    color: var(--primary-color);
    font-weight: 600;
}

.score span:last-child {
    color: var(--secondary-color);
    font-weight: 600;
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem 0;
    margin-top: 2rem;
    color: #6b7280;
    font-size: 0.875rem;
}

/* Tablet Styles (768px and up) */
@media (min-width: 768px) {
    :root {
        --cell-size: 120px;
        --cell-gap: 12px;
    }
    
    h1 {
        font-size: 3rem;
    }
    
    .subtitle {
        font-size: 1.125rem;
    }
    
    .status {
        font-size: 1.5rem;
    }
    
    .cell {
        font-size: 3.5rem;
    }
    
    body {
        padding: 2rem;
    }
    
    .language-switcher {
        top: 1rem;
        right: 1rem;
    }
    
    .lang-dropdown {
        min-width: 160px;
    }
}

/* Desktop Styles (1024px and up) */
@media (min-width: 1024px) {
    :root {
        --cell-size: 150px;
        --cell-gap: 16px;
    }
    
    h1 {
        font-size: 3.5rem;
    }
    
    .cell {
        font-size: 4.5rem;
    }
    
    .cell:hover:not(:disabled) {
        transform: scale(1.08);
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --text-color: #000000;
    }
    
    .cell {
        border-width: 3px;
    }
}

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

/* Dark Mode Support (Optional) */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #111827;
        --text-color: #f9fafb;
        --border-color: #374151;
    }
    
    .cell:hover:not(:disabled) {
        background-color: #1f2937;
    }
    
    .cell.winning {
        background-color: #1e3a8a;
    }
    
    footer {
        color: #9ca3af;
    }
    
    .lang-btn:hover {
        background-color: rgba(37, 99, 235, 0.1);
    }
    
    .lang-dropdown {
        background-color: #1f2937;
        border-color: #374151;
    }
    
    .lang-item {
        color: #f9fafb;
    }
    
    .lang-item:hover {
        background-color: rgba(37, 99, 235, 0.15);
    }
    
    .lang-item.active {
        background-color: rgba(37, 99, 235, 0.25);
    }
    
    .game-mode-label {
        color: #9ca3af;
    }
    
    .game-mode-btn {
        background-color: #1f2937;
        border-color: #374151;
        color: #f9fafb;
    }
    
    .game-mode-btn:hover {
        background-color: rgba(37, 99, 235, 0.1);
    }
}
