/* ============================================
   Variables & Reset
   ============================================ */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-cell: #232733;
    --bg-cell-hover: #2a2f3d;
    --border-color: #2e3345;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0ab;
    --text-muted: #6b7280;
    --accent-x: #6c8cff;
    --accent-o: #ff6b9d;
    --accent-draw: #ffd166;
    --accent-win: #06d6a0;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1.5rem;
    line-height: 1.5;
}

/* ============================================
   App Container
   ============================================ */
.app {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

/* ============================================
   Header
   ============================================ */
.header {
    text-align: center;
    margin-bottom: 0.25rem;
}

.title {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-x), var(--accent-o));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-top: 0.15rem;
}

/* ============================================
   Mode Selector
   ============================================ */
.mode-selector {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mode-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
    gap: 4px;
}

.mode-tab {
    flex: 1;
    padding: 0.6rem 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
}

.mode-tab:hover {
    color: var(--text-primary);
}

.mode-tab.active {
    background: var(--bg-cell);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* Side selector */
.side-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.5rem;
}

.side-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.side-buttons {
    display: flex;
    gap: 6px;
}

.side-btn {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
}

.side-btn:hover {
    border-color: var(--text-muted);
}

.side-btn.active {
    border-color: var(--accent-x);
    background: rgba(108, 140, 255, 0.12);
    color: var(--accent-x);
    box-shadow: 0 0 12px rgba(108, 140, 255, 0.2);
}

/* Difficulty selector */
.difficulty-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
}

.diff-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.diff-buttons {
    display: flex;
    gap: 6px;
}

.diff-btn {
    padding: 0.45rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
}

.diff-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.diff-btn.active {
    border-color: var(--accent-o);
    background: rgba(255, 107, 157, 0.12);
    color: var(--accent-o);
    box-shadow: 0 0 12px rgba(255, 107, 157, 0.2);
}

/* ============================================
   Scoreboard
   ============================================ */
.scoreboard {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.score-card {
    flex: 1;
    max-width: 120px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.5rem;
    text-align: center;
    border: 2px solid transparent;
    transition: all var(--transition-normal);
}

.score-card.score-x {
    border-color: rgba(108, 140, 255, 0.15);
}

.score-card.score-o {
    border-color: rgba(255, 107, 157, 0.15);
}

.score-card.score-draw {
    border-color: rgba(255, 209, 102, 0.15);
}

.score-symbol {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
}

.score-x .score-symbol {
    color: var(--accent-x);
}

.score-o .score-symbol {
    color: var(--accent-o);
}

.score-draw .score-symbol {
    color: var(--accent-draw);
}

.score-value {
    display: block;
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
}

.score-label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 0.1rem;
}

/* ============================================
   Status Bar
   ============================================ */
.status-bar {
    width: 100%;
    text-align: center;
    padding: 0.7rem 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 2px solid var(--border-color);
    transition: all var(--transition-normal);
}

.status-bar.status-x {
    border-color: rgba(108, 140, 255, 0.3);
    box-shadow: 0 0 20px rgba(108, 140, 255, 0.08);
}

.status-bar.status-o {
    border-color: rgba(255, 107, 157, 0.3);
    box-shadow: 0 0 20px rgba(255, 107, 157, 0.08);
}

.status-bar.status-win {
    border-color: var(--accent-win);
    box-shadow: 0 0 24px rgba(6, 214, 160, 0.15);
    animation: statusPulse 1.5s ease-in-out infinite;
}

.status-bar.status-draw {
    border-color: var(--accent-draw);
    box-shadow: 0 0 20px rgba(255, 209, 102, 0.1);
}

.status-text {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 20px rgba(6, 214, 160, 0.1); }
    50% { box-shadow: 0 0 28px rgba(6, 214, 160, 0.2); }
}

/* ============================================
   Board
   ============================================ */
.board-container {
    width: 100%;
    aspect-ratio: 1;
}

.board {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 6px;
}

.cell {
    background: var(--bg-cell);
    border: none;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255,255,255,0.04) 0%, transparent 70%);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.cell:hover:not(.taken):not(.disabled)::before {
    opacity: 1;
}

.cell:hover:not(.taken):not(.disabled) {
    background: var(--bg-cell-hover);
    transform: scale(1.02);
}

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

.cell.taken,
.cell.disabled {
    cursor: default;
}

/* Symboles X et O */
.cell .symbol {
    font-size: clamp(2rem, 8vw, 3.5rem);
    font-weight: 800;
    line-height: 1;
    opacity: 0;
    transform: scale(0.5) rotate(-15deg);
    transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell .symbol.show {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

.cell .symbol.x {
    color: var(--accent-x);
    text-shadow: 0 0 20px rgba(108, 140, 255, 0.3);
}

.cell .symbol.o {
    color: var(--accent-o);
    text-shadow: 0 0 20px rgba(255, 107, 157, 0.3);
}

/* Case gagnante */
.cell.winner {
    background: rgba(6, 214, 160, 0.12);
    animation: winGlow 1.2s ease-in-out infinite alternate;
}

.cell.winner .symbol {
    color: var(--accent-win) !important;
    text-shadow: 0 0 24px rgba(6, 214, 160, 0.4) !important;
}

@keyframes winGlow {
    0% { box-shadow: inset 0 0 12px rgba(6, 214, 160, 0.1); }
    100% { box-shadow: inset 0 0 24px rgba(6, 214, 160, 0.2); }
}

/* ============================================
   Boutons d'action
   ============================================ */
.actions {
    width: 100%;
    display: flex;
    gap: 0.75rem;
}

.btn {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-normal);
    font-family: inherit;
    letter-spacing: 0.02em;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-x), #8b5cf6);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-cell);
    color: var(--text-primary);
    border-color: var(--text-muted);
}

.btn-secondary:active {
    background: var(--bg-cell-hover);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 400px) {
    body {
        padding: 1rem;
        align-items: flex-start;
    }

    .app {
        gap: 1rem;
    }

    .title {
        font-size: 2rem;
    }

    .scoreboard {
        gap: 0.5rem;
    }

    .score-card {
        padding: 0.6rem 0.4rem;
    }

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

    .actions {
        flex-direction: column;
    }

    .diff-buttons {
        gap: 4px;
    }

    .diff-btn {
        padding: 0.4rem 0.7rem;
        font-size: 0.75rem;
    }
}

@media (min-width: 600px) {
    .app {
        max-width: 440px;
    }
}

/* ============================================
   Accessibilité : focus visible
   ============================================ */
.cell:focus-visible,
.btn:focus-visible,
.mode-tab:focus-visible,
.side-btn:focus-visible,
.diff-btn:focus-visible {
    outline: 2px solid var(--accent-x);
    outline-offset: 2px;
}

/* ============================================
   Préférence : réduction de mouvement
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
