/* --- VARIABLES GLOBALES --- */
:root {
    --parchment: #f5e6c8;
    --seal-red: #c62828;
    --text-dark: #3e2723;
    --gold-treasure: #ffb300;
}

/* --- BASE & TYPOGRAPHY --- */
body {
    font-family: 'Roboto', sans-serif;
    color: var(--text-dark);
    overflow-x: hidden;
    min-height: 100vh;
    background-color: var(--parchment) !important;
    position: relative;
    
    /* DEFINICIÓN DE LA IMAGEN (Común para todos) */
    background-image: url('../img/fondo_mapa.jpeg');
    background-position: center top; /* Anclamos arriba para estabilidad */

    /* ESTRATEGIA MÓVIL (Por defecto) */
    /* Usamos 'scroll' en lugar de 'fixed'. 
       La imagen se mueve con el texto. Cero saltos, rendimiento perfecto. */
    background-attachment: scroll;
}

/* ESTRATEGIA ESCRITORIO (Pantallas grandes) */
@media (min-width: 1024px) {
    body {
        /* En PC sí podemos usar fixed porque la ventana no cambia de tamaño sola */
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
    }
}

/* Aseguramos que los pseudo-elementos antiguos no molesten */
body::before,
body::after {
    display: none !important;
    content: none !important;
}

/* --- HEADER / BANNER GLOBAL --- */
header {
    text-align: center;
    padding-top: 0;
    position: relative;
    z-index: 10;
}

.banner-wrapper {
    width: 100%;
    height: 20vh;
    min-height: 240px;
    margin: 0 0 60px 0;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    background-image: url('../img/banner.jpg');
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
}

@media (min-width: 1024px) {
    .banner-wrapper {
        background-image: url('../img/banner_big.jpg');
    }
}

/* --- NAVEGACIÓN --- */
.nav-bar {
    display: flex;
    justify-content: flex-start;
    gap: 15px;
    position: absolute;
    bottom: -22px;
    left: 30px;
    z-index: 20;
    margin: 0;
}

.nav-btn {
    background: linear-gradient(to bottom, #3e2723, #211512);
    color: #d7ccc8;
    text-decoration: none;
    padding: 8px 25px;
    border: 3px ridge #795548;
    border-radius: 4px;
    font-family: 'Pirata One', cursive;
    font-size: 1.3rem;
    transition: all 0.2s;
    box-shadow: 0 6px 8px rgba(0, 0, 0, 0.6);
    text-shadow: 1px 1px 0px #000;
}

.nav-btn:hover {
    background: linear-gradient(to bottom, #5d4037, #3e2723);
    border-color: #a1887f;
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.7);
    color: #fff;
}

/* --- MEDIA QUERIES (Banner/Nav Mobile) --- */
@media (max-width: 600px) {
    .banner-wrapper {
        height: 15vh;
        background-image: url('../img/banner_tlf.jpg');
        min-height: 150px;
        margin: 0;
        margin-bottom: 20px;
    }

    .nav-bar {
        left: 0;
        width: 100%;
        justify-content: center;
        bottom: -15px;
        gap: 8px;
    }

    .nav-btn {
        padding: 6px 15px;
        font-size: 1.1rem;
    }
}

/* --- SUBTITLE CONTAINER --- */
.subtitle-container {
    text-align: center;
    padding: 30px 20px 20px;
    position: relative;
    z-index: 10;
}

.page-subtitle {
    font-family: 'Pirata One', cursive;
    font-size: 2.5rem;
    color: var(--gold-treasure);
    text-shadow:
        2px 2px 0 #3e2723,
        -1px -1px 0 #3e2723,
        1px -1px 0 #3e2723,
        -1px 1px 0 #3e2723,
        1px 1px 0 #3e2723;
    margin: 0;
    line-height: 1.2;
}

@media (max-width: 600px) {
    .page-subtitle {
        font-size: 1.8rem;
    }
}


/* --- ESTILOS DEL TÍTULO MADERA Y ORO (CORREGIDO) --- */

.main-header-text {
    text-align: center;
    padding: 15px 0 20px 0;
    position: relative;
    z-index: 20;
}

/* 1. Reseteamos el h1 contenedor para que no pinte nada raro */
.app-title-wood {
    margin: 0;
    line-height: 1;
    text-shadow: none !important;
    /* Mata la sombra roja del h1 padre */
}

.app-title-wood a {
    font-family: 'Pirata One', cursive;
    font-size: 4rem;
    text-decoration: none !important;
    display: inline-block;
    transition: transform 0.2s ease;
    cursor: pointer;

    /* 2. EL RELLENO (Madera Marrón Oscuro) */
    color: #3e2723 !important;

    /* 3. EL BORDE (Marco Dorado) */
    -webkit-text-stroke: 2px var(--gold-treasure);

    /* 4. PAINT ORDER (Clave para que el borde no tape la letra) */
    paint-order: stroke fill;

    /* 5. ELIMINAR SOMBRA ROJA Y DAR PROFUNDIDAD NEGRA */
    /* El !important aquí borra la sombra roja global */
    text-shadow: none !important;

    /* Usamos filter: drop-shadow para la profundidad 3D externa */
    filter: drop-shadow(3px 3px 2px rgba(0, 0, 0, 0.8));
}

/* Efecto Hover */
.app-title-wood a:hover {
    transform: scale(1.05) rotate(-1deg);
    color: #4e342e !important;
    -webkit-text-stroke: 2px #ffd54f;
    /* Oro más brillante */
    /* Brillo dorado exterior */
    filter: drop-shadow(0 0 5px rgba(255, 179, 0, 0.6));
}

/* Ajustes Mobile */
@media (max-width: 600px) {
    .app-title-wood a {
        font-size: 3rem;
        -webkit-text-stroke: 1.5px var(--gold-treasure);
    }
}

/* --- NAVEGACIÓN TIPO "CARTAS" (Estilo Pergamino) --- */
.game-links {
    display: grid;
    /* Crea tantas columnas como quepan. Mínimo 140px de ancho por carta */
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 15px;
    width: 100%;
    max-width: 800px;
    margin: 30px auto;
    padding: 0 10px;
}

.btn-navegacion {
    /* Layout interno */
    display: flex;
    flex-direction: column;
    /* Icono arriba, texto abajo */
    align-items: center;
    justify-content: center;
    height: 130px;
    /* Altura fija para uniformidad */

    /* Estilo Visual: Fondo Pergamino */
    background-image: url('../img/card.png');
    background-size: 100% 100%;
    /* Estirar la imagen para cubrir el botón */
    background-repeat: no-repeat;
    background-color: #f4e7be;
    /* Color de respaldo (beige) */

    text-decoration: none;
    border-radius: 8px;
    /* Ligero redondeo para suavizar esquinas */

    /* Sombra de la carta flotando */
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.6);

    /* Transición suave */
    transition: transform 0.2s ease, filter 0.2s ease;

    /* Aseguramos que no tenga bordes extraños del intento anterior */
    border: none;
    overflow: visible;
}

/* IMÁGENES / ICONOS (Ahora se ven bien, centrados) */
.btn-character-img,
.btn-wordle-img {
    position: static;
    /* Reseteamos cualquier posición absoluta anterior */
    width: auto;
    height: 65px;
    /* Tamaño controlado del icono */
    margin-bottom: 8px;
    object-fit: contain;
    opacity: 1;
    /* Totalmente visible */
    filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.4));
    transition: transform 0.2s;
}

/* TEXTO DORADO (Legible sobre fondo claro) */
.btn-text {
    font-family: 'Pirata One', cursive;
    font-size: 1.6rem;
    line-height: 1;
    text-align: center;

    /* Color Dorado */
    color: #ffca28;

    /* Contorno oscuro FUERTE para contraste sobre el pergamino */
    text-shadow:
        2px 2px 0 #3e2723,
        -1px -1px 0 #3e2723,
        1px -1px 0 #3e2723,
        -1px 1px 0 #3e2723,
        1px 1px 0 #3e2723;

    z-index: 2;
    padding: 0 5px;
}

/* --- INTERACCIONES (Hover) --- */
.btn-navegacion:hover {
    transform: scale(1.08) translateY(-5px);
    /* Crece un poco y sube */
    filter: brightness(1.1);
    /* Se ilumina ligeramente */
    z-index: 10;
}

.btn-navegacion:hover .btn-character-img,
.btn-navegacion:hover .btn-wordle-img {
    transform: rotate(-5deg) scale(1.1);
    /* El icono se mueve un poco */
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 500px) {
    .game-links {
        gap: 10px;
        /* En móviles pequeños, aseguramos 2 columnas */
        grid-template-columns: repeat(2, 1fr);
    }

    .btn-navegacion {
        height: 110px;
        /* Un poco más compactas en móvil */
    }

    .btn-text {
        font-size: 1rem;
        /* Ajuste de fuente */
    }

    .btn-character-img,
    .btn-wordle-img {
        height: 70px;
        /* Iconos más pequeños */
    }

    .btn-navegacion:hover {
        transform: none;
        /* Crece un poco y sube */
        filter: none;
        /* Se ilumina ligeramente */
    }

    .btn-navegacion:hover .btn-character-img,
    .btn-navegacion:hover .btn-wordle-img {
        transform: none;
    }

}

/* --- BOTÓN VOLVER --- */

.back-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 10px auto 10px;
    width: 100%;
}

.btn-back {
    /* Estética de madera oscura (similar a tu nav-bar) */
    background: linear-gradient(to bottom, #3e2723, #211512);
    color: #ffca28;
    /* Dorado */
    font-family: 'Pirata One', cursive;
    font-size: 1.5rem;
    text-decoration: none;
    padding: 10px 40px;
    border: 2px solid #795548;
    border-radius: 4px;

    /* Sombras para dar profundidad */
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5);
    text-shadow: 1px 1px 0 #000;

    transition: all 0.3s ease;
    cursor: pointer;
    display: inline-block;
}

.btn-back:hover {
    background: linear-gradient(to bottom, #5d4037, #3e2723);
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.7);
    color: #fff;
    border-color: var(--gold-treasure);
    /* Borde dorado al pasar el ratón */
}

/* =========================================
   1. CONTENEDOR GENÉRICO DE JUEGO
   ========================================= */
.game-container {
    background: rgba(255, 248, 225, 0.6);
    border: 3px double #5d4037;
    border-radius: 12px;
    padding: 30px;
    box-shadow:
        0 10px 25px rgba(0, 0, 0, 0.3),
        inset 0 0 50px rgba(161, 136, 127, 0.2);
    margin-bottom: 40px;
    backdrop-filter: blur(5px);
}

/* =========================================
   2. SISTEMA DE PISTAS (HINTS)
   ========================================= */
.hint-container {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.hint-box {
    background: linear-gradient(to bottom, #4e342e, #3e2723);
    border: 2px solid #8d6e63;
    border-radius: 8px;
    padding: 15px 20px;
    color: #d7ccc8;
    min-width: 250px;
    flex: 1;
    max-width: 450px;
    display: flex;
    flex-direction: row;
    /* Escritorio: En línea */
    align-items: center;
    justify-content: center;
    gap: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.hint-box.disabled {
    opacity: 0.8;
    background: #2d201c;
    border-color: #4e342e;
    cursor: not-allowed;
}

.hint-box.enabled {
    cursor: pointer;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.hint-box.active,
.hint-box.revealed {
    background: #ffecb3;
    color: #3e2723;
    border-color: #ffb300;
}

.hint-title {
    font-family: 'Pirata One', cursive;
    font-size: 1.4rem;
    letter-spacing: 1px;
    white-space: nowrap;
}

.hint-lock {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #ffb300;
    background: rgba(0, 0, 0, 0.3);
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 179, 0, 0.3);
    white-space: nowrap;
}

/* Pistas Reveladas (Texto) */
.revealed-hints-container {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.revealed-hint-line {
    background: rgba(255, 253, 231, 0.95);
    padding: 12px 20px;
    margin: 8px 0;
    border-radius: 6px;
    border-left: 5px solid #ffb300;
    font-weight: 500;
    color: #3e2723;
    font-family: 'Roboto', sans-serif;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
    animation: fadeIn 0.5s ease;
    width: fit-content;
    min-width: 60%;
    max-width: 90%;
    text-align: center;
}

/* =========================================
   3. INPUT Y BÚSQUEDA (SEARCH WRAP)
   ========================================= */
.searchWrap {
    position: relative;
    max-width: 600px;
    margin: 0 auto 30px;
}

.input-group {
    display: flex;
    gap: 10px;
    border-radius: 50px;
}

#guessInput {
    flex: 1;
    padding: 15px 25px;
    font-size: 1.1rem;
    font-family: 'Roboto', sans-serif;
    color: #3e2723;
    background-color: #fffbf0;
    border: 2px solid #8d6e63;
    border-radius: 50px;
    outline: none;
    transition: border-color 0.3s;
}

#guessInput:focus {
    border-color: #8d6e63;
    box-shadow: 0 0 0 3px rgba(255, 179, 0, 0.2);
}

#guessBtn {
    background: linear-gradient(to bottom, #c62828, #b71c1c);
    color: #fff;
    border: 2px solid #8d0000;
    padding: 0 30px;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Pirata One', cursive;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

#guessBtn:active {
    transform: translateY(2px);
}

#guessBtn svg {
    stroke: #8d6e63;
}

/* =========================================
   4. AUTOCOMPLETE
   ========================================= */
#autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: #4e342e;
    border: none;
    border-radius: 8px;
    margin-top: 5px;
    max-height: 300px;
    overflow-y: auto;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
    text-align: left !important;
}

#autocomplete::-webkit-scrollbar {
    width: 8px;
}

#autocomplete::-webkit-scrollbar-track {
    background: #3e2723;
}

#autocomplete::-webkit-scrollbar-thumb {
    background: #8d6e63;
    border-radius: 4px;
}

.ac-item {
    padding: 10px 15px;
    border-bottom: 1px solid #5d4037;
    color: #d7ccc8;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    display: block;
}

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

.ac-item:hover,
.ac-item.highlighted {
    background: #5d4037;
}

/* Flexbox para la fila interna */
.ac-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100%;
}

.ac-avatar {
    display: block;
    width: 50px !important;
    height: 50px !important;
    object-fit: cover;
    object-position: top center;
    border-radius: 4px;
    border: 1px solid #8d6e63;
    flex: 0 0 50px !important;
    margin-right: 15px !important;
}

.ac-texts {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: flex-start !important;
    flex: 1 1 auto !important;
    min-width: 0;
    line-height: 1.2;
}

.ac-name {
    font-size: 1.2rem;
    font-weight: bold;
    color: #ffecb3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: block;
}

.ac-alias {
    font-size: 0.9rem;
    color: #a1887f;
    font-style: italic;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    display: block;
}

.ac-item:hover .ac-name,
.ac-item.highlighted .ac-name {
    color: #ffca28;
}

.ac-item:hover .ac-alias,
.ac-item.highlighted .ac-alias {
    color: #d7ccc8;
}

/* =========================================
   5. MENSAJE DE VICTORIA
   ========================================= */
#winMsg {
    margin: 10px;
    margin-top: 20px;
    animation: bounceIn 0.8s;
}

.win-content {
    background: linear-gradient(135deg, #2e7d32, #1b5e20);
    border: 3px solid #ffb300;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    color: white;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

.jolly-roger img {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #fff;
    object-fit: cover;
    object-position: top center;
}

#winMsg h2 {
    font-family: 'Pirata One', cursive;
    color: #ffca28;
    font-size: 2rem;
    margin: 0 0 10px 0;
}

#winMsg p {
    margin: 0;
    font-size: 1.1rem;
}

.hidden {
    display: none !important;
}

/* =========================================
   6. MENSAJES DE ERROR
   ========================================= */
.error-message {
    background-color: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
    padding: 10px 20px;
    border-radius: 8px;
    margin-bottom: 15px;
    text-align: center;
    font-weight: bold;
    animation: fadeIn 0.3s ease;
}

.error-message.fade-out {
    opacity: 0;
    transition: opacity 0.5s ease;
}

/* =========================================
   7. ANIMACIONES COMUNES
   ========================================= */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }

    50% {
        opacity: 1;
        transform: scale(1.05);
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-5px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(5px);
    }
}

/* =========================================
   8. RESPONSIVE COMÚN (MÓVIL)
   ========================================= */
@media (max-width: 600px) {
    .game-container {
        padding: 15px 10px;
    }

    /* Input y Botón apilados */
    .searchWrap {
        max-width: 100%;
        position: relative;
    }

    .input-group {
        flex-direction: column;
        gap: 10px;
    }

    #guessInput {
        width: 100%;
        font-size: 1.2rem;
    }

    #guessBtn {
        width: 100%;
        justify-content: center;
        padding: 12px 0;
        font-size: 1.4rem;
    }

    /* Autocomplete posicionado bajo el input */
    #autocomplete {
        top: 60px;
        z-index: 200;
        width: 100%;
    }

    /* Pistas apiladas verticalmente */
    .hint-container {
        flex-direction: column;
        gap: 10px;
        margin-bottom: 10px;
    }

    .hint-box {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        justify-content: space-between;
        padding: 15px 10px;
        gap: 8px;
        height: auto;
    }

    .hint-title {
        white-space: normal;
        text-align: left;
    }

    .hint-lock {
        flex-shrink: 0;
    }

    .revealed-hint-line {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Win modal apilado */
    .win-content {
        flex-direction: column;
        text-align: center;
    }
}

/* =========================================
   9. SECCIÓN DE INFORMACIÓN / TUTORIAL
   ========================================= */
.info-game {
    background: linear-gradient(135deg, #3e2723, #281b18);
    border: 3px solid #ffb300;
    border-radius: 12px;
    padding: 30px;
    margin: 10px;
    margin-top: 40px;
    margin-bottom: 40px;
    color: #d7ccc8;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.info-game h3 {
    font-family: 'Pirata One', cursive;
    font-size: 2rem;
    color: #ffca28;
    margin-top: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 202, 40, 0.3);
    padding-bottom: 10px;
}

.info-game p {
    line-height: 1.6;
    font-size: 1.1rem;
    margin-bottom: 20px;
}

.color-legend {
    list-style: none;
    padding: 0;
    margin: 20px 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}

.color-legend li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.color-legend strong {
    display: block;
    color: #ffecb3;
    margin-bottom: 4px;
}

.color-legend span {
    font-size: 0.9rem;
    color: #bcaaa4;
}

.color-legend .color-box {
    width: 30px;
    height: 30px;
    margin-top: 2px;
}

.game-legend-container .color-box {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}

.color-box {
    display: inline-block;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    margin-top: 2px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.color-box.green {
    background: linear-gradient(145deg, rgba(46, 139, 87, 0.9), rgba(34, 102, 68, 0.9));
}

.color-box.yellow {
    background: linear-gradient(145deg, rgba(230, 126, 34, 0.85), rgba(211, 84, 0, 0.85));
}

.color-box.gray {
    background: linear-gradient(145deg, #757575, #505050);
}

.color-box.red {
    background: linear-gradient(145deg, #da1616, #8d1616);
}