/**
 * JOGO DA VELHA - STYLES.CSS
 * Otimizado para Google PageSpeed 100/100
 * Mobile First, Acessível (WCAG 2.2), Dark Mode, PWA Ready
 */

/* ============================================
   VARIÁVEIS CSS - Fácil customização e manutenção
   ============================================ */
:root {
    /* Cores - Light Mode */
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-secondary: #64748b;
    --color-secondary-hover: #475569;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-border: #e2e8f0;
    
    /* Células do tabuleiro */
    --color-cell-bg: #ffffff;
    --color-cell-hover: #f1f5f9;
    --color-cell-border: #cbd5e1;
    
    /* Tamanhos */
    --cell-size: min(100px, 28vw);
    --gap: min(12px, 3vw);
    --border-radius: 12px;
    --border-radius-small: 8px;
    
    /* Tipografia */
    --font-size-base: 16px;
    --font-size-large: 1.25rem;
    --font-size-xlarge: 2rem;
    --font-size-small: 0.875rem;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    /* Transições */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
}

/* Dark Mode - Respeitando preferência do sistema */
@media (prefers-color-scheme: dark) {
    :root {
        --color-primary: #3b82f6;
        --color-primary-hover: #2563eb;
        --color-secondary: #94a3b8;
        --color-secondary-hover: #cbd5e1;
        
        --color-bg: #0f172a;
        --color-surface: #1e293b;
        --color-text: #e2e8f0;
        --color-text-secondary: #94a3b8;
        --color-border: #334155;
        
        --color-cell-bg: #1e293b;
        --color-cell-hover: #334155;
        --color-cell-border: #475569;
    }
}

/* ============================================
   RESET E BASE
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Previne layout shift */
    overflow-y: scroll;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color var(--transition-normal), color var(--transition-normal);
    
    /* Melhora renderização de texto */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* ============================================
   ACESSIBILIDADE
   ============================================ */

/* Skip link para navegação via teclado */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    border-radius: 0 0 var(--border-radius-small) 0;
    z-index: 1000;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid var(--color-warning);
    outline-offset: 2px;
}

/* Oculta visualmente mas mantém para screen readers */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Foco visível para navegação via teclado (WCAG 2.2) */
*:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--border-radius-small);
}

/* Remove foco visual para mouse, mantém para teclado */
*:focus:not(:focus-visible) {
    outline: none;
}

/* ============================================
   HEADER
   ============================================ */
header {
    text-align: center;
    padding: 2rem 1rem 1rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

header h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    color: var(--color-primary);
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: var(--font-size-large);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
main {
    flex: 1;
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* ============================================
   SCORE SECTION
   ============================================ */
.score-section {
    margin-bottom: 2rem;
}

.score-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    background: var(--color-surface);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

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

.score-value {
    font-size: var(--font-size-xlarge);
    font-weight: 700;
    color: var(--color-primary);
}

/* ============================================
   TURN INDICATOR
   ============================================ */
.turn-indicator {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-surface);
    border-radius: var(--border-radius);
    border: 2px solid var(--color-primary);
    box-shadow: var(--shadow-sm);
}

#turn-text {
    font-size: var(--font-size-large);
    color: var(--color-text);
}

#current-player {
    color: var(--color-primary);
    font-size: 1.5rem;
}

/* ============================================
   GAME BOARD
   ============================================ */
.game-container {
    margin-bottom: 2rem;
}

.board {
    display: grid;
    grid-template-columns: repeat(3, var(--cell-size));
    grid-template-rows: repeat(3, var(--cell-size));
    gap: var(--gap);
    justify-content: center;
    margin: 0 auto;
}

.cell {
    background: var(--color-cell-bg);
    border: 2px solid var(--color-cell-border);
    border-radius: var(--border-radius-small);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(2rem, 8vw, 3rem);
    font-weight: 700;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    
    /* Acessibilidade */
    position: relative;
}

.cell:hover:not(.cell-taken) {
    background: var(--color-cell-hover);
    border-color: var(--color-primary);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

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

.cell-taken {
    cursor: not-allowed;
}

/* Símbolos X e O com cores distintas */
.cell[data-value="X"] {
    color: var(--color-primary);
}

.cell[data-value="O"] {
    color: var(--color-danger);
}

/* Animação de entrada do símbolo */
@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.cell.cell-animate {
    animation: popIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

/* Células vencedoras destacadas */
.cell.winner {
    background: var(--color-success);
    color: white !important;
    border-color: var(--color-success);
    animation: winPulse 0.6s ease-in-out;
}

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

/* Respeita preferência de movimento reduzido */
@media (prefers-reduced-motion: reduce) {
    .cell,
    .btn,
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .cell:hover:not(.cell-taken) {
        transform: none;
    }
}

/* ============================================
   RESULT MESSAGE
   ============================================ */
.result-message {
    text-align: center;
    min-height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.result-message.show {
    font-size: var(--font-size-large);
    font-weight: 700;
    padding: 1rem;
    border-radius: var(--border-radius);
    background: var(--color-surface);
    border: 2px solid currentColor;
    animation: slideDown 0.4s ease-out;
}

.result-message.winner-x {
    color: var(--color-primary);
}

.result-message.winner-o {
    color: var(--color-danger);
}

.result-message.draw {
    color: var(--color-warning);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   BUTTONS
   ============================================ */
.actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 2rem;
}

.btn {
    padding: 0.875rem 1.75rem;
    font-size: var(--font-size-base);
    font-weight: 600;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-md);
    font-family: inherit;
    
    /* Acessibilidade */
    min-height: 44px;
    min-width: 44px;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--color-secondary);
    color: white;
}

.btn-secondary:hover,
.btn-secondary:focus {
    background: var(--color-secondary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

/* ============================================
   GAME INFO (SEO Content)
   ============================================ */
.game-info {
    background: var(--color-surface);
    padding: 2rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    margin-bottom: 2rem;
}

.game-info h2 {
    font-size: 1.5rem;
    color: var(--color-primary);
    margin-bottom: 1rem;
}

.game-info h3 {
    font-size: 1.25rem;
    color: var(--color-text);
    margin: 1.5rem 0 0.75rem;
}

.game-info p {
    margin-bottom: 1rem;
    color: var(--color-text-secondary);
    line-height: 1.7;
}

.game-info ul {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.game-info li {
    margin-bottom: 0.5rem;
    color: var(--color-text-secondary);
}

/* ============================================
   AD CONTAINER - Sem Layout Shift
   ============================================ */
.ad-container {
    min-height: 250px;
    background: var(--color-surface);
    border: 1px dashed var(--color-border);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    padding: 1rem;
    
    /* Reserva espaço para prevenir CLS */
    contain: layout;
}

.ad-placeholder {
    color: var(--color-text-secondary);
    font-size: var(--font-size-small);
    text-align: center;
}

/* ============================================
   FOOTER
   ============================================ */
footer {
    text-align: center;
    padding: 2rem 1rem;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    margin-top: auto;
}

footer p {
    margin-bottom: 0.5rem;
}

.footer-links {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.footer-links a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-links a:hover,
.footer-links a:focus {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

/* ============================================
   RESPONSIVE - Mobile First
   ============================================ */

/* Small devices */
@media (max-width: 360px) {
    :root {
        --cell-size: 85px;
        --gap: 8px;
    }
    
    .score-container {
        gap: 0.5rem;
        padding: 1rem;
    }
    
    .score-value {
        font-size: 1.5rem;
    }
}

/* Medium devices and up */
@media (min-width: 768px) {
    :root {
        --cell-size: 120px;
        --gap: 16px;
    }
    
    main {
        padding: 2rem 1rem;
    }
    
    header {
        padding: 3rem 1rem 1.5rem;
    }
}

/* Large devices */
@media (min-width: 1024px) {
    .board {
        gap: 20px;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .skip-link,
    .actions,
    .ad-container,
    footer {
        display: none;
    }
    
    body {
        background: white;
        color: black;
    }
}

/* ============================================
   PWA - Standalone Mode
   ============================================ */
@media (display-mode: standalone) {
    header {
        padding-top: env(safe-area-inset-top);
    }
}
