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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.top-right-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    z-index: 1000;
}

.language-selector {
    display: flex;
    gap: 10px;
}

.flag {
    font-size: 32px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.3s, transform 0.2s;
}

.flag:hover {
    transform: scale(1.1);
}

.flag.active {
    opacity: 1;
}

.auth-button {
    display: flex;
    gap: 10px;
}

.auth-button button {
    padding: 8px 16px;
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

.auth-button button:hover {
    background: #667eea;
    color: white;
}

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal.active {
    display: block;
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 40px;
    border-radius: 10px;
    width: 90%;
    max-width: 400px;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.close {
    position: absolute;
    right: 20px;
    top: 10px;
    font-size: 28px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
}

.close:hover {
    color: #000;
}

.form-section h2 {
    margin-bottom: 20px;
    color: #333;
}

.form-section input {
    width: 100%;
    padding: 12px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.forgot-password-link {
    margin: 5px 0;
    font-size: 13px;
}

.forgot-password-link a {
    color: #667eea;
    text-decoration: none;
}

.forgot-password-link a:hover {
    text-decoration: underline;
}

.form-section button {
    width: 100%;
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
}

.form-section button:hover {
    background: #5568d3;
}

.form-section p {
    text-align: center;
    margin-top: 15px;
    color: #666;
}

.form-section a {
    color: #667eea;
    text-decoration: none;
    font-weight: bold;
}

#main-container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    padding: 40px;
    border-radius: 10px;
    margin-top: 20px;
}

#game-title {
    text-align: center;
    color: #667eea;
    margin-bottom: 30px;
}

#menu-screen h2 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    margin: 0 auto;
}

.menu-options label {
    font-weight: bold;
    color: #333;
}

.menu-options select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
}

.game-mode-container {
    display: flex;
    gap: 20px;
    align-items: center;
    width: 100%;
}

.game-mode-select {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.game-mode-select select {
    width: 100%;
}

.round-trip-checkbox {
    display: flex;
    align-items: center;
    padding-top: 20px;
}

.round-trip-checkbox label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}

.round-trip-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.menu-options button {
    padding: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
}

.menu-options button:hover {
    background: #5568d3;
}

.game-info {
    text-align: center;
    margin-bottom: 5px;
}

.score-panel {
    display: flex;
    justify-content: center;
    gap: 50px;
    margin-bottom: 5px;
}

.score {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 3px 20px;
    border-radius: 8px;
    transition: all 0.3s;
}

.score.active-turn {
    background: rgba(102, 126, 234, 0.15);
    transform: scale(1.05);
}

.player-name {
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 5px;
    padding: 5px 10px;
    border-radius: 5px;
    transition: all 0.3s;
}

.player1-color {
    color: #dc3545;
    font-weight: bold;
}

.player2-color {
    color: #007bff;
    font-weight: bold;
}

.player-name.player1-color {
    color: #dc3545;
}

.player-name.player2-color {
    color: #007bff;
}

.score.active-turn .player-name.player1-color {
    background: rgba(220, 53, 69, 0.2);
}

.score.active-turn .player-name.player2-color {
    background: rgba(0, 123, 255, 0.2);
}

.score span:last-child {
    font-size: 24px;
    color: #667eea;
}

#message {
    color: #000501;
    font-weight: bold;
    min-height: 20px;
}

#continue-btn {
    margin: 15px auto 0;
    padding: 10px 30px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

#continue-btn:hover {
    background: #5568d3;
    transform: scale(1.05);
}

#game-end-continue-btn {
    margin: 15px auto 0;
    padding: 10px 30px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    display: block;
}

#game-end-continue-btn:hover {
    background: #5568d3;
    transform: scale(1.05);
}

#letter-popup {
    position: fixed;
    display: none;
    background: transparent;
    border: none;
    padding: 5px;
    z-index: 1000;
    gap: 5px;
}

#letter-popup.show {
    display: flex;
}

.letter-popup-btn {
    padding: 12px 20px;
    font-size: 20px;
    font-weight: bold;
    border: none;
    background: #667eea;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 50px;
    opacity: 0.6;
}

.letter-popup-btn:hover {
    background: #5568d3;
    transform: scale(1.1);
    opacity: 0.8;
}

#board-container {
    display: grid;
    gap: 3px;
    width: 100%;
    max-width: 90vw;
    margin: 0 auto 20px;
    background: #ddd;
    padding: 3px;
    border-radius: 5px;
}

@media (min-width: 768px) {
    #board-container {
        max-width: 600px;
    }
}

#board-container.size-5 {
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    padding: 5px;
}

#board-container.size-6 {
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
    padding: 4px;
}

#board-container.size-7 {
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    padding: 4px;
}

#board-container.size-8 {
    grid-template-columns: repeat(8, 1fr);
    gap: 3px;
}

#board-container.size-9 {
    grid-template-columns: repeat(9, 1fr);
    gap: 3px;
}

#board-container.size-10 {
    grid-template-columns: repeat(10, 1fr);
    gap: 3px;
}

#board-container.size-11 {
    grid-template-columns: repeat(11, 1fr);
    gap: 2px;
}

#board-container.size-12 {
    grid-template-columns: repeat(12, 1fr);
    gap: 2px;
}


.board-cell {
    aspect-ratio: 1;
    background: white;
    border: 2px solid #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    line-height: 1;
}

.size-5 .board-cell {
    font-size: 8vw;
    border-width: 2px;
}

.size-6 .board-cell {
    font-size: 7vw;
    border-width: 2px;
}

.size-7 .board-cell {
    font-size: 6.5vw;
    border-width: 2px;
}

.size-8 .board-cell {
    font-size: 6vw;
    border-width: 1px;
}

.size-9 .board-cell {
    font-size: 5vw;
    border-width: 1px;
}

.size-10 .board-cell {
    font-size: 4.5vw;
    border-width: 1px;
}

.size-11 .board-cell {
    font-size: 4vw;
    border-width: 1px;
}

.size-12 .board-cell {
    font-size: 3.5vw;
    border-width: 1px;
}

@media (min-width: 768px) {
    .size-5 .board-cell {
        font-size: 48px;
        border-width: 3px;
    }

    .size-6 .board-cell {
        font-size: 42px;
        border-width: 3px;
    }

    .size-7 .board-cell {
        font-size: 38px;
        border-width: 2px;
    }

    .size-8 .board-cell {
        font-size: 34px;
        border-width: 2px;
    }

    .size-9 .board-cell {
        font-size: 30px;
        border-width: 2px;
    }

    .size-10 .board-cell {
        font-size: 27px;
        border-width: 2px;
    }

    .size-11 .board-cell {
        font-size: 25px;
        border-width: 2px;
    }

    .size-12 .board-cell {
        font-size: 22px;
        border-width: 2px;
    }
}

.board-cell:hover:not(.filled) {
    background: #f0f0f0;
}

.board-cell.filled {
    cursor: default;
    background: #e8e8e8;
}

/* --- MODIFICACIÓN: CLASES PARA RESALTAR --- */
.board-cell.last-move {
    border-color: #ff0000 !important;
    /* Rojo intenso */
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.6) inset;
    /* Resplandor interior */
    z-index: 5;
}

.board-cell.popup-target {
    background-color: #999 !important;
    /* Fondo gris oscuro al seleccionar */
    border-color: #333 !important;
    transform: scale(0.95);
    /* Efecto de "presionado" */
}

/* --- FIN MODIFICACIÓN --- */

.debug-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #666;
    font-size: 0.8em;
    background: #f0f0f0;
    border: 1px solid #ddd;
}

.board-cell.player1-color {
    color: #dc3545;
}

.board-cell.player2-color {
    color: #007bff;
}

.board-cell.manual-selected {
    background: #fff3cd !important;
    border-color: #ffc107 !important;
}

.word-line {
    position: absolute;
    pointer-events: none;
    z-index: 10;
}

.game-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.game-controls button {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

.game-controls button:hover {
    background: #5568d3;
}

.stats-container,
.history-container {
    margin-top: 30px;
}

#dashboard-screen h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
}

#dashboard-screen>button {
    display: block;
    margin: 0 auto 20px;
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#stats-display {
    background: #f5f5f5;
    padding: 20px;
    border-radius: 5px;
}

#stats-display p {
    margin: 10px 0;
    color: #333;
}

#history-display table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#history-display th {
    background: #667eea;
    color: white;
    padding: 10px;
    text-align: left;
}

#history-display td {
    padding: 10px;
    border-bottom: 1px solid #ddd;
}

#history-display tr:hover {
    background: #f5f5f5;
}

.notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 15px 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    display: none;
    animation: slideDown 0.3s ease;
    max-width: 80%;
    text-align: center;
}

.notification.show {
    display: block;
}

.notification.error {
    background: #dc3545;
}

.notification.success {
    background: #28a745;
}

.notification.info {
    background: #17a2b8;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.confirm-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.confirm-dialog.show {
    display: flex;
}

.confirm-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.confirm-content p {
    margin: 0 0 20px;
    font-size: 16px;
    color: #333;
    text-align: center;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.confirm-btn {
    padding: 10px 24px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.2s;
}

.confirm-yes {
    background: #667eea;
    color: white;
}

.confirm-yes:hover {
    background: #5568d3;
}

.confirm-no {
    background: #e0e0e0;
    color: #333;
}

.confirm-no:hover {
    background: #d0d0d0;
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .language-selector {
        top: 10px;
        right: 10px;
    }

    .auth-button {
        top: 60px;
        right: 10px;
        flex-direction: column;
    }

    #main-container {
        padding: 20px;
        margin-top: 80px;
    }

    .flag {
        font-size: 24px;
    }
}

/* --- ESTILOS ESPECÍFICOS PARA LA VENTANA DE AYUDA --- */

/* Hacemos la ventana más ancha y permitimos scroll si es muy alta */
.help-modal-content {
    max-width: 700px;
    /* Mucho más ancha que el login (era 400px) */
    width: 95%;
    /* Ocupa casi todo el ancho en móviles */
    max-height: 90vh;
    /* Nunca superará el 90% de la altura de la pantalla */
    overflow-y: auto;
    /* Activa barra de scroll si el texto es muy largo */
    margin: 20px auto;
    /* Margen más pequeño arriba/abajo para aprovechar espacio */
    padding: 30px;
    /* Un poco más de aire interior */
}

/* Mejoramos la tipografía para que no se vea "apretujada" */
.help-section {
    margin-bottom: 25px;
    /* Separación entre secciones */
}

.help-section h3 {
    color: #667eea;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
    /* Línea separadora elegante */
    font-size: 1.2rem;
}

.help-section p {
    line-height: 1.6;
    /* Aumenta el espacio entre líneas de texto */
    margin-bottom: 15px;
    color: #444;
    font-size: 16px;
    /* Texto base un poco más grande y legible */
}

.help-section ul,
.help-section ol {
    padding-left: 25px;
    margin-bottom: 20px;
}

.help-section li {
    line-height: 1.6;
    /* Espaciado también en las listas */
    margin-bottom: 8px;
    /* Separación entre puntos de la lista */
    color: #444;
}

/* Botón de cerrar inferior más visible */
.close-help-btn {
    display: block;
    width: 100%;
    padding: 15px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 20px;
    transition: background 0.3s;
}

.close-help-btn:hover {
    background: #5568d3;
}

/* Ajuste de la barra de scroll para que sea más bonita (opcional, funciona en Chrome/Edge/Safari) */
.help-modal-content::-webkit-scrollbar {
    width: 8px;
}

.help-modal-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.help-modal-content::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.help-modal-content::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.help-modal-content h2 {
    color: #667eea;
    margin-bottom: 20px;
}

/* --- FIN ESTILOS AYUDA --- */

/* --- ESTILOS PARA CONTROLES DE REPRODUCCIÓN --- */

#playback-controls {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    padding: 20px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 12px;
    border: 2px solid rgba(102, 126, 234, 0.3);
}

.playback-btn {
    width: 55px;
    height: 55px;
    font-size: 26px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.playback-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 15px rgba(102, 126, 234, 0.5);
}

.playback-btn:active {
    transform: scale(0.95);
}

.playback-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.2);
}

.playback-btn:disabled:hover {
    transform: none;
    box-shadow: 0 2px 5px rgba(102, 126, 234, 0.2);
}

#move-counter {
    font-size: 16px;
    font-weight: bold;
    color: #667eea;
    margin-left: 10px;
    padding: 8px 16px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Indicador visual cuando está navegando en el historial */
#board-container.navigating {
    border: 3px solid #ff9800;
    box-shadow: 0 0 15px rgba(255, 152, 0, 0.5);
}

/* --- FIN ESTILOS REPRODUCCIÓN --- */

/* --- MAIN MENU STYLES --- */
.main-menu-container {
    position: relative;
}

.menu-btn {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s;
    padding: 0 10px;
}

.menu-btn:hover {
    transform: scale(1.1);
}

.main-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    min-width: 220px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    overflow: hidden;
    z-index: 1001;
    margin-top: 10px;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 12px 20px;
    text-align: left;
    background: none;
    border: none;
    font-size: 16px;
    color: #333;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid #f0f0f0;
}

.menu-item:last-child {
    border-bottom: none;
}

.menu-item:hover {
    background: #f5f5f5;
    color: #667eea;
}

/* --- LEGAL & COOKIES MODAL STYLES --- */
.legal-content {
    margin-top: 20px;
    line-height: 1.6;
    color: #444;
}

.legal-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: #667eea;
}

.legal-content p {
    margin-bottom: 15px;
}

.legal-content a {
    color: #667eea;
    text-decoration: none;
    font-weight: bold;
}

.legal-content a:hover {
    text-decoration: underline;
}

@media (max-width: 480px) {
    #playback-controls {
        gap: 5px;
        padding: 10px;
        margin: 10px 0;
    }

    .playback-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    #move-counter {
        font-size: 14px;
        align-items: right;
        justify-content: right;
        padding: 6px 10px;
        margin-left: 5px;
        white-space: nowrap;
    }
}

/* --- LOBBY Y MULTIJUGADOR REMOTO --- */

#lobby-container {
    max-width: 500px;
    margin: 20px auto;
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: none;
}

#lobby-container h2 {
    color: #667eea;
    margin-bottom: 5px;
    text-align: center;
}

#lobby-container p {
    text-align: center;
    color: #666;
    margin-bottom: 20px;
}

.user-list {
    max-height: 300px;
    overflow-y: auto;
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 20px;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    background: white;
    border-radius: 6px;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.user-item:hover {
    transform: translateY(-2px);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 12px;
    background: #ccc;
}

.status-dot.online {
    background: #28a745;
}

.status-dot.busy {
    background: #ffc107;
}

.status-dot.away {
    background: #dc3545;
}

.user-item .username {
    flex: 1;
    font-weight: 600;
    color: #333;
}

.btn-small {
    padding: 5px 12px;
    font-size: 13px;
    margin: 0;
}

.empty-msg {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
}

/* Modales personalizados para invitaciones */
#invitation-modal {
    z-index: 11000;
}

#invitation-modal .modal-content {
    text-align: center;
}

#invitation-modal h3 {
    color: #667eea;
    margin-bottom: 15px;
}

#invitation-modal .modal-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 25px;
}

.btn-success {
    background: #28a745;
    color: white;
    border: none;
}

.btn-danger {
    background: #dc3545;
    color: white;
    border: none;
}

.btn-success:hover {
    background: #218838;
}

.btn-danger:hover {
    background: #c82333;
}