/* Centrado del Contenedor Principal (Aplicable a todo móvil) */
body {
    display: flex;
    justify-content: center; /* Centrado Horizontal */
    align-items: center; /* Centrado Vertical */
    min-height: 100vh; /* Ocupa el 100% del alto visible */
    margin: 0;
    padding: 0;
}

/* Configuración básica del contenedor del juego */
.game-container {
    max-width: 450px; /* Límite para que no sea muy ancho en tabletas */
    width: 95%; /* Usa la mayoría del ancho disponible */
}
/*
  Juego Gato (Tic-Tac-Toe) - Hoja de Estilos
  Diseño por: JonaDev
  Versión: 2.2 (Mobile & UX Polish)
*/

/* --- 1. Importación de Fuentes y Reseteo Básico --- */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');

html, body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

* {
    box-sizing: border-box;
}

/* --- 2. Definición de la Paleta de Colores y Variables Globales --- */
:root {
    --bg-gradient-start: #FDF8F0;
    --bg-gradient-end: #E8F5E9;
    --card-bg: rgba(255, 255, 255, 0.7);
    --header-bg: rgba(255, 255, 255, 0.5);
    --text-primary: #263238;
    --text-secondary: #546E7A;
    --accent-primary: #FF7043;
    --accent-primary-darker: #F4511E;
    --accent-secondary: #26A69A;
    --input-bg: rgba(255, 255, 255, 0.8);
    --input-border: #B0BEC5;
    --shadow-color: rgba(38, 50, 56, 0.1);
    --symbol-x-color: var(--accent-primary);
    --symbol-o-color: var(--accent-secondary);
    --success-color: #66BB6A;
    --error-color: #757575; /* Gris para desconectado */
    --reconnecting-color: #FFA726; /* Naranja/Amarillo para reconectando */
    --accent-primary-rgb: 255, 112, 67;
    --symbol-x-rgb: 255, 112, 67;
    --symbol-o-rgb: 38, 166, 154;
    --border-radius: 16px;
    --card-padding: 32px;
    --shadow-sm: 0 2px 8px var(--shadow-color);
    --shadow-md: 0 4px 16px var(--shadow-color);
    --shadow-lg: 0 8px 32px var(--shadow-color);
}

html[data-theme='dark'] {
    --bg-gradient-start: #1A2035;
    --bg-gradient-end: #121826;
    --card-bg: rgba(42, 51, 79, 0.7);
    --header-bg: rgba(26, 32, 53, 0.5);
    --text-primary: #ECEFF1;
    --text-secondary: #90A4AE;
    --accent-primary: #FFA726;
    --accent-primary-darker: #FB8C00;
    --accent-secondary: #4DD0E1;
    --input-bg: rgba(26, 32, 53, 0.8);
    --input-border: #455A64;
    --shadow-color: rgba(0, 0, 0, 0.2);
    --error-color: #616161;
    --accent-primary-rgb: 255, 167, 38;
    --symbol-x-rgb: 255, 167, 38;
    --symbol-o-rgb: 77, 208, 225;
}

/* --- 3. Estructura Principal y Cabecera --- */
body {
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-primary);
    transition: background 0.5s, color 0.5s;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 25px 25px;
    animation: move-background 90s linear infinite;
    z-index: -1;
}

@keyframes move-background {
    from { transform: translate(0, 0); }
    to { transform: translate(25px, 25px); }
}

.app-header {
    width: 100%;
    padding: 16px 24px;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-title h1 {
    font-size: 1.5rem;
    margin-bottom: 0;
}

#header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%; /* Make it a circle */
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#header-logo:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.main-content {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 100%;
    padding: 80px 20px 20px 20px; /* Espacio para el header fijo */
}

h2, h3 {
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
}

h2 { font-size: 1.5rem; margin-bottom: 1.5rem; color: var(--text-secondary); }
.lobby-container h3 { font-size: 1.2rem; margin-bottom: 1rem; }

/* --- 4. Contenedores de Contenido --- */
.lobby-container,
.game-container {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: var(--card-padding);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
    max-width: 420px;
    animation: fade-in 0.5s ease-out;
}

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

/* --- 5. Estilos de Componentes (Botones, Inputs) --- */
.form-group { margin-bottom: 1.5rem; }
label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-secondary); }

input[type="text"] {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid var(--input-border);
    background-color: var(--input-bg);
    color: var(--text-primary);
    border-radius: 12px;
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    transition: border-color 0.3s, box-shadow 0.3s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(var(--accent-primary-rgb), 0.3);
}

.primary-btn, .symbol-btn, .secondary-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.primary-btn { background: linear-gradient(45deg, var(--accent-primary), var(--accent-primary-darker)); color: #fff; box-shadow: var(--shadow-sm); }
.primary-btn:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.primary-btn:active { transform: translateY(-1px); box-shadow: none; }

.secondary-btn { background: transparent; color: var(--accent-primary); font-weight: 600; }
.secondary-btn:hover { background: rgba(var(--accent-primary-rgb), 0.1); }

/* --- 6. Estilos del Lobby (index.html) --- */
.new-game-section, .join-game-section { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--input-border); }
.symbol-picker { display: flex; justify-content: center; align-items: center; margin-bottom: 1.5rem; gap: 1rem; color: var(--text-secondary); font-weight: 600; }
.symbol-options { display: flex; border-radius: 12px; overflow: hidden; background: var(--input-bg); padding: 4px; }
.symbol-btn { padding: 8px 24px; background: transparent; color: var(--text-secondary); font-size: 1.75rem; font-weight: 700; border-radius: 8px; }
.symbol-btn.active { background: var(--accent-primary); color: #fff; box-shadow: var(--shadow-sm); }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(5px); display: flex; justify-content: center; align-items: center; z-index: 1000; animation: fade-in 0.3s; }
.modal-content { background: var(--card-bg); padding: var(--card-padding); border-radius: var(--border-radius); max-width: 400px; width: 90%; text-align: center; position: relative; box-shadow: var(--shadow-lg); border: 1px solid rgba(255, 255, 255, 0.1); }
.close-modal { position: absolute; top: 16px; right: 16px; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); transition: color 0.2s; }
.close-modal:hover { color: var(--text-primary); }

/* --- 7. Estilos de la Pantalla de Juego (game.html) --- */
.game-wrapper { width: 100%; max-width: 500px; position: relative; }
.game-container { max-width: 500px; gap: 1rem; }

.back-to-lobby {
    position: absolute;
    top: -40px;
    left: 0;
    text-decoration: none;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.back-to-lobby img {
    width: 28px;
    height: 28px;
    transition: filter 0.2s;
}

.back-to-lobby:hover {
    transform: scale(1.1);
}

html[data-theme='dark'] .back-to-lobby img {
    filter: invert(1) opacity(0.8);
}

.back-to-lobby:hover img {
    filter: none;
}

#game-info { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.player-info { display: flex; flex-direction: column; align-items: center; padding: 12px 16px; border-radius: 12px; width: 120px; background: var(--input-bg); border: 2px solid transparent; transition: all 0.3s ease; }
.player-info.active-turn { border-color: var(--accent-primary); box-shadow: 0 0 24px rgba(var(--accent-primary-rgb), 0.6); transform: scale(1.08); }

.player-name-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.player-symbol {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 1rem;
    background-color: var(--input-border);
    color: var(--text-primary);
}

#player-info-X .player-symbol { color: var(--symbol-x-color); }
#player-info-O .player-symbol { color: var(--symbol-o-color); }

.player-info .score { font-size: 1.75rem; font-weight: 700; color: var(--text-secondary); margin-top: 4px; }

#turn-indicator { font-size: 1.2rem; font-weight: 600; color: var(--text-secondary); text-align: center; padding: 8px 16px; background: var(--input-bg); border-radius: 12px; }

#board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; background: var(--input-border); padding: 12px; border-radius: 12px; }
.cell { aspect-ratio: 1 / 1; background-color: var(--bg-gradient-start); border-radius: 12px; display: flex; justify-content: center; align-items: center; font-size: 4.5rem; font-weight: 700; cursor: pointer; transition: all 0.2s ease-out; box-shadow: var(--shadow-sm); border: 1px solid transparent; }
.cell:hover { transform: scale(1.05); box-shadow: var(--shadow-md); border-color: var(--accent-primary); }
.cell.X { color: var(--symbol-x-color); text-shadow: 0 0 15px rgba(var(--symbol-x-rgb), 0.5); }
.cell.O { color: var(--symbol-o-color); text-shadow: 0 0 15px rgba(var(--symbol-o-rgb), 0.5); }

#status-bar { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--text-secondary); }

#room-id-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

#copy-room-id-btn {
    padding: 4px 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 6px;
    background-color: var(--input-border);
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

#copy-room-id-btn:hover {
    background-color: var(--text-secondary);
    color: var(--card-bg);
    transform: scale(1.05);
}

#copy-room-id-btn.copied {
    background-color: var(--success-color);
    color: #fff;
}

#opponent-status-container { display: none; } /* Oculto, reemplazado por indicadores */

#new-round-btn { margin-top: 1rem; }

/* --- 8. Theme Switcher y Marca de Agua --- */
.theme-switcher-container { position: relative; }
.theme-switcher-checkbox { display: none; }
.theme-switcher-label { display: block; width: 60px; height: 30px; background-color: var(--input-bg); border-radius: 15px; position: relative; cursor: pointer; transition: background-color 0.3s ease; box-shadow: inset 0 1px 3px rgba(0,0,0,0.2); }
.theme-switcher-label:active { transform: scale(0.95); }
.theme-switcher-thumb { position: absolute; top: 3px; left: 4px; width: 24px; height: 24px; background-color: #fff; border-radius: 50%; transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94); box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.theme-switcher-thumb::before { content: ''; position: absolute; top: 5px; left: 5px; width: 14px; height: 14px; background-color: transparent; border-radius: 50%; box-shadow: -3px -3px 0 3px var(--accent-secondary); transition: all 0.3s ease; transform: scale(1); }
.theme-switcher-thumb::after { content: ''; position: absolute; top: 50%; left: 50%; width: 16px; height: 16px; margin: -8px; background-color: var(--accent-primary); border-radius: 50%; transform: scale(0); transition: all 0.3s ease; box-shadow: 0 -10px 0 -3px #fff, 0 10px 0 -3px #fff, 10px 0 0 -3px #fff, -10px 0 0 -3px #fff, 7px -7px 0 -3px #fff, -7px 7px 0 -3px #fff, 7px 7px 0 -3px #fff, -7px -7px 0 -3px #fff; }

.theme-switcher-checkbox:checked + .theme-switcher-label .theme-switcher-thumb { transform: translateX(29px); }
.theme-switcher-checkbox:checked + .theme-switcher-label .theme-switcher-thumb::before { transform: scale(0); }
.theme-switcher-checkbox:checked + .theme-switcher-label .theme-switcher-thumb::after { transform: scale(1) rotate(360deg); background-color: var(--accent-primary); box-shadow: 0 -10px 0 -3px var(--accent-primary), 0 10px 0 -3px var(--accent-primary), 10px 0 0 -3px var(--accent-primary), -10px 0 0 -3px var(--accent-primary), 7px -7px 0 -3px var(--accent-primary), -7px 7px 0 -3px var(--accent-primary), 7px 7px 0 -3px var(--accent-primary), -7px -7px 0 -3px var(--accent-primary); }
html[data-theme='light'] .theme-switcher-label { background-color: var(--accent-secondary); }

.watermark { position: fixed; bottom: 10px; right: 15px; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); opacity: 0.7; z-index: 1001; transition: color 0.3s; }

/* --- 9. Estilos Responsivos --- */
@media (max-width: 520px) {
    .app-header { padding: 12px 16px; }
    .header-title h1 { font-size: 1.2rem; }
    .main-content { padding: 80px 15px 15px 15px; }
    :root { --card-padding: 15px; }

    .game-container {
        padding: var(--card-padding);
    }

    #game-info {
        flex-wrap: wrap;
        justify-content: center;
        gap: 1rem;
    }

    .player-info {
        width: calc(50% - 8px);
        padding: 8px;
        flex-direction: column;
        align-items: center;
        min-height: 80px;
    }

    .player-name-wrapper {
        font-size: 0.8rem;
    }

    .player-info .score {
        font-size: 1.5rem;
    }

    #turn-indicator-container {
        width: 100%;
        order: -1; /* Mueve el indicador de turno arriba */
        margin-bottom: 0.5rem;
    }

    #turn-indicator {
        font-size: 1.1rem;
    }

    .cell {
        font-size: 16vw;
        border-radius: 8px;
    }

    #board {
        gap: 8px;
        padding: 8px;
    }
}

/* --- 10. UI Polish & Animations --- */
#turn-indicator .dot { display: inline-block; animation: blink 1.4s infinite; }
#turn-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
#turn-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0; } 40% { opacity: 1; } }

#board.board-inactive .cell { cursor: not-allowed; opacity: 0.7; }
#board.board-inactive .cell:hover { transform: none; box-shadow: var(--shadow-sm); border-color: transparent; }

.cell:active { transform: scale(0.97); background-color: var(--input-bg); }
.cell .symbol { display: inline-block; opacity: 0; transform: scale(0.5); animation: symbol-enter 0.3s forwards cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes symbol-enter { to { opacity: 1; transform: scale(1); } }

.cell.winning-cell { background-color: var(--accent-primary); animation: pulse-winner 0.8s infinite; }
.cell.winning-cell .symbol { color: #fff; text-shadow: 0 0 10px rgba(0,0,0,0.3); }
@keyframes pulse-winner { 0% { transform: scale(1); box-shadow: var(--shadow-md); } 50% { transform: scale(1.05); box-shadow: var(--shadow-lg); } 100% { transform: scale(1); box-shadow: var(--shadow-md); } }

.toast { position: fixed; bottom: -100px; left: 50%; transform: translateX(-50%); padding: 12px 24px; border-radius: 10px; background: var(--text-primary); color: var(--bg-gradient-start); box-shadow: var(--shadow-lg); font-weight: 600; z-index: 2000; transition: bottom 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55); }
.toast.show { bottom: 40px; }

/* Indicador de Conexión */
.connection-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--error-color);
    transition: background-color 0.5s ease;
}

.connection-indicator.connected {
    background-color: var(--success-color);
}

.connection-indicator.reconnecting {
    background-color: var(--reconnecting-color);
    animation: pulse-reconnecting 1.5s infinite;
}

@keyframes pulse-reconnecting {
    0% { opacity: 1; }
    50% { opacity: 0.4; }
    100% { opacity: 1; }
}

/* MEDIA QUERY para Teléfonos con Pantalla Larga (Long/Tall Screens) */
 @media screen and (min-aspect-ratio: 2/1) {
    
    /* 1. Limitar el alto del contenedor del juego (Clave para evitar estiramiento) */
    .game-container {
        /* Limita el contenedor principal del juego al 80% del alto visible */
        max-height: 80vh; 
        height: auto;
    }

    /* 2. Ajustar el tamaño del tablero (Opcional, si es muy grande) */
    #board {
        max-width: 350px; 
        margin-top: 20px;
    }
    
    /* 3. Ajustar el padding superior (para barras de URL del navegador) */
    /* Asegura que el contenido se separe del borde superior e inferior */
    body {
        padding-top: 2vh; 
        padding-bottom: 2vh;
    }
}
