/* ==========================
   FUENTE
========================== */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;700&display=swap');

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
    font-family:'Poppins',sans-serif;
}


/* ==========================
   FONDO
========================== */

body{

    min-height:100vh;

    display:flex;
    justify-content:center;
    align-items:center;

    /* Foto real de bosque de fondo + capa verde para mantener el tema
       y que la tarjeta blanca y los textos se lean bien */
    background:
        linear-gradient(135deg, rgba(27,94,32,.72), rgba(46,125,50,.55), rgba(102,187,106,.5)),
        url('../assets/forest.jpg') center center / cover no-repeat fixed;

    overflow:hidden;
}


/* ==========================
   CONTENEDOR GENERAL
========================== */

.pantalla{

    position:relative;
    z-index:1;

    width:90%;
    max-width:1000px;

    background:white;

    border-radius:25px;

    padding:40px;

    box-shadow:0px 15px 45px rgba(0,0,0,.30);

    animation:aparecer .5s ease;

}


/* ==========================
   OCULTAR
========================== */

.oculto{

    display:none;

}


/* ==========================
   TITULOS
========================== */

h1{

    text-align:center;

    color:#2E7D32;

    font-size:42px;

    margin-bottom:20px;

}

h2{

    text-align:center;

    font-size:30px;

    color:#333;

}


/* ==========================
   TEXTO
========================== */

p{

    text-align:center;

    font-size:20px;

    margin-bottom:30px;

    color:#555;

}


/* ==========================
   BOTONES
========================== */

button{

    cursor:pointer;

    border:none;

    transition:.25s;

    /* Sin destello gris al tocar en celular */
    -webkit-tap-highlight-color:transparent;

}


/* ==========================
   BOTON PRINCIPAL
========================== */

#btnComenzar,
#btnReiniciar{

    display:block;

    margin:auto;

    width:280px;

    padding:18px;

    font-size:22px;

    color:white;

    background:linear-gradient(135deg,#43A047,#2E7D32);

    border-radius:15px;

    font-weight:bold;

    letter-spacing:.3px;

    box-shadow:0 8px 20px rgba(46,125,50,.35);

    transition:transform .2s cubic-bezier(.34,1.56,.64,1),
               box-shadow .2s ease,
               background .2s ease;

}

#btnComenzar:hover,
#btnReiniciar:hover{

    transform:translateY(-3px) scale(1.05);

    background:linear-gradient(135deg,#2E7D32,#1B5E20);

    box-shadow:0 14px 28px rgba(46,125,50,.45);

}

#btnComenzar:active,
#btnReiniciar:active{

    transform:translateY(0) scale(.97);

    box-shadow:0 5px 14px rgba(46,125,50,.35);

}

/* Latido sutil para invitar a empezar */
#btnComenzar{

    animation:respira 2.4s ease-in-out infinite;

}

#btnComenzar:hover,
#btnComenzar:active{

    animation:none;

}


/* ==========================
   CAMPO DE NOMBRE
========================== */

#nombreJugador{

    display:block;

    margin:0 auto 25px auto;

    width:280px;

    max-width:100%;

    padding:15px 18px;

    font-size:18px;

    text-align:center;

    color:#2E7D32;

    border:3px solid #A5D6A7;

    border-radius:15px;

    outline:none;

    transition:.25s;

}

#nombreJugador:focus{

    border-color:#2E7D32;

    box-shadow:0 0 0 4px rgba(46,125,50,.15);

}


/* ==========================
   BARRA SUPERIOR
========================== */

.barraSuperior{

    display:flex;

    justify-content:space-between;

    align-items:center;

    margin-bottom:40px;

}


#progreso,
#puntaje{

    background:#E8F5E9;

    padding:12px 18px;

    border-radius:12px;

    font-size:18px;

    font-weight:bold;

    color:#2E7D32;

}


/* ==========================
   TEMPORIZADOR ANIMADO (ANILLO)
========================== */

#temporizador{

    position:relative;

    width:64px;

    height:64px;

    flex-shrink:0;

}

.anilloTiempo{

    width:100%;

    height:100%;

    transform:rotate(-90deg);   /* empieza arriba */

}

.anilloFondo{

    fill:none;

    stroke:#E8F5E9;

    stroke-width:9;

}

.anilloProgreso{

    fill:none;

    stroke:#2E7D32;

    stroke-width:9;

    stroke-linecap:round;

    /* La animación real se controla desde JavaScript */
    transition:stroke-dashoffset 1s linear, stroke .4s;

}

/* Colores según el tiempo restante */
.anilloProgreso.medio{

    stroke:#F9A825;

}

.anilloProgreso.bajo{

    stroke:#E53935;

}

#tiempoTexto{

    position:absolute;

    top:50%;
    left:50%;
    transform:translate(-50%,-50%);

    font-size:22px;

    font-weight:bold;

    color:#2E7D32;

}

/* Latido cuando queda poco tiempo */
#temporizador.alerta #tiempoTexto{

    color:#E53935;

    animation:latido .6s infinite;

}

@keyframes latido{

    0%   { transform:translate(-50%,-50%) scale(1);    }
    50%  { transform:translate(-50%,-50%) scale(1.25); }
    100% { transform:translate(-50%,-50%) scale(1);    }

}


/* ==========================
   PREGUNTA
========================== */

.contenedorPregunta{

    margin-bottom:40px;

    background:#F5F5F5;

    border-radius:20px;

    padding:35px;

    /* Barra de acento verde a la izquierda */
    border-left:6px solid #66BB6A;

}

/* La pregunta "entra" cada vez que aparece una nueva */
.contenedorPregunta.entra{

    animation:entraPregunta .5s cubic-bezier(.2,.7,.3,1);

}


/* ==========================
   OPCIONES
========================== */

.contenedorOpciones{

    display:flex;

    flex-wrap:wrap;

    gap:20px;

}


.opcion{

    width:calc(50% - 10px);

    flex-grow:0;
    flex-shrink:0;

    min-height:90px;

    font-size:20px;

    font-weight:600;

    color:white;

    border-radius:18px;

    overflow:hidden;

    box-shadow:0 4px 10px rgba(0,0,0,.12);

    /* El tamaño/aparición son algo lentos (efecto de revelado),
       pero terminan antes de la pausa total de 5s antes de avanzar;
       hover y color siguen siendo rápidos */
    transition:
        width 1.5s ease,
        opacity 1.5s ease,
        transform .2s cubic-bezier(.34,1.56,.64,1),
        box-shadow .2s ease,
        filter .25s;

}

/* Entrada escalonada de las opciones al aparecer cada pregunta.
   Se usa fill 'backwards' (no 'both'): el estado inicial se aplica durante
   el retardo del escalonado, pero NO se fija el estado final, para no pisar
   luego el desvanecido del revelado (.oculto / .expandida). */
.opcion.entra{

    animation:entraOpcion .45s cubic-bezier(.2,.7,.3,1) backwards;

}

/* Al revelar la respuesta, las opciones no elegidas se desvanecen y encogen */
.opcion.oculto{

    width:0;
    min-width:0;
    min-height:0;
    padding:0;

    opacity:0;

    pointer-events:none;

}

/* La opción correcta pasa a ocupar todo el ancho */
.opcion.expandida{

    width:100%;

    min-height:110px;

    font-size:24px;

}


/* COLORES */

#opcion0{

    background:#E53935;

}

#opcion1{

    background:#1E88E5;

}

#opcion2{

    background:#FDD835;

    color:#222;

}

#opcion3{

    background:#43A047;

}


/* HOVER */

.opcion:hover{

    transform:translateY(-6px) scale(1.02);

    filter:brightness(1.08);

    box-shadow:0 14px 24px rgba(0,0,0,.25);

}

.opcion:active{

    transform:translateY(-2px) scale(.99);

    box-shadow:0 6px 14px rgba(0,0,0,.20);

}


/* ==========================
   RESPUESTA CORRECTA
========================== */

.correcta{

    background:#2ECC71 !important;

    box-shadow:0 0 0 4px rgba(46,204,113,.35), 0 10px 26px rgba(46,204,113,.45) !important;

    animation:correcto .6s cubic-bezier(.34,1.56,.64,1);

}


/* ==========================
   RESPUESTA INCORRECTA
========================== */

.incorrecta{

    background:#C62828 !important;

    animation:error .5s;

}


/* ==========================
   RESULTADO FINAL
========================== */

#resultadoFinal{

    margin-top:20px;

    margin-bottom:15px;

}

#mensajeFinal{

    font-size:24px;

    font-weight:bold;

}


/* ==========================
   TABLA DE POSICIONES / RANKING
========================== */

.tituloRanking{

    text-align:center;

    color:#2E7D32;

    margin-top:30px;

    margin-bottom:15px;

    font-size:24px;

}

.creditos{

    text-align:center;

    font-size:12px;

    color:#9E9E9E;

    margin-top:25px;

    margin-bottom:0;

}

.creditos a{

    color:#66BB6A;

    text-decoration:none;

}

.creditos a:hover{

    text-decoration:underline;

}

.ranking{

    max-width:500px;

    margin:0 auto 25px auto;

}

/* Ranking en la pantalla de inicio */
#rankingInicio{

    margin-top:30px;

}

.filaRanking{

    display:flex;

    align-items:center;

    justify-content:space-between;

    gap:12px;

    background:#F5F5F5;

    border-radius:12px;

    padding:12px 18px;

    margin-bottom:10px;

    font-size:18px;

    animation:aparecer .4s ease;

}

/* Podio: oro, plata y bronce */
.filaRanking.oro{    background:#FFF3C4; }
.filaRanking.plata{  background:#ECEFF1; }
.filaRanking.bronce{ background:#F3E0D0; }

.filaRanking .posicion{

    font-weight:bold;

    color:#2E7D32;

    min-width:40px;

}

.filaRanking .nombre{

    flex:1;

    text-align:left;

    font-weight:600;

    color:#333;

    overflow:hidden;

    text-overflow:ellipsis;

    white-space:nowrap;

}

.filaRanking .puntos{

    font-weight:bold;

    color:#2E7D32;

}

/* Resalta la fila del jugador actual */
.filaRanking.actual{

    outline:3px solid #2E7D32;

}

.rankingVacio{

    text-align:center;

    color:#777;

    font-style:italic;

}

/* Indicador: ¿el ranking viene del servidor compartido o es local de esta PC? */
.estadoConexion{

    display:flex;
    align-items:center;
    justify-content:center;
    gap:8px;

    margin:0 auto 6px auto;

    font-size:14px;
    font-weight:600;

}

.estadoConexion::before{

    content:"";

    width:10px;
    height:10px;

    border-radius:50%;

    flex-shrink:0;

}

/* Conectado al servidor: ranking compartido por todas las PCs */
.estadoConexion[data-estado="servidor"]{

    color:#2E7D32;

}

.estadoConexion[data-estado="servidor"]::before{

    background:#2ECC71;

    box-shadow:0 0 0 4px rgba(46,204,113,.20);

}

/* Sin servidor: cada PC ve solo lo suyo (localStorage) */
.estadoConexion[data-estado="local"]{

    color:#C62828;

}

.estadoConexion[data-estado="local"]::before{

    background:#E53935;

    box-shadow:0 0 0 4px rgba(229,57,53,.18);

}


/* ==========================
   BOTÓN SECUNDARIO
========================== */

.btnSecundario{

    display:block;

    margin:15px auto 0 auto;

    padding:10px 20px;

    font-size:15px;

    color:#2E7D32;

    background:transparent;

    border:2px solid #A5D6A7;

    border-radius:12px;

    font-weight:600;

}

.btnSecundario:hover{

    background:#E8F5E9;

}

/* Estado cuando el temporizador está desactivado para la partida actual */
.btnSecundario.timerDesactivado{

    color:#C62828;

    border-color:#E57373;

    background:#FBE9E7;

}

.btnSecundario.timerDesactivado:hover{

    background:#FFCDD2;

}


/* ==========================
   PESTAÑA + PANEL DE PUNTAJES
========================== */

/* Pestaña que asoma en el borde derecho */
.tabPuntajes{

    position:fixed;

    top:50%;
    right:0;

    transform:translateY(-50%);

    z-index:900;

    writing-mode:vertical-rl;

    padding:20px 10px;

    font-size:17px;
    font-weight:700;
    letter-spacing:1px;

    color:white;
    background:#2E7D32;

    border-radius:14px 0 0 14px;

    box-shadow:-3px 3px 12px rgba(0,0,0,.30);

    transition:background .25s, padding .25s;

}

.tabPuntajes:hover{

    background:#1B5E20;

    padding-right:16px;

}

/* Fondo oscuro detrás del panel */
.drawerBackdrop{

    position:fixed;

    inset:0;

    z-index:940;

    background:rgba(0,0,0,.45);

}

/* Panel lateral deslizante */
.drawerPuntajes{

    position:fixed;

    top:0;
    right:0;

    z-index:950;

    width:min(380px, 88vw);
    height:100%;

    background:white;

    box-shadow:-8px 0 30px rgba(0,0,0,.30);

    transform:translateX(100%);

    transition:transform .35s ease;

    display:flex;
    flex-direction:column;

}

.drawerPuntajes.abierto{

    transform:translateX(0);

}

.drawerCabecera{

    display:flex;
    align-items:center;
    justify-content:space-between;

    padding:22px 24px;

    border-bottom:2px solid #E8F5E9;

    flex-shrink:0;

}

.drawerCabecera h2{

    color:#2E7D32;
    font-size:26px;

}

.btnCerrarDrawer{

    width:40px;
    height:40px;

    font-size:26px;
    line-height:1;

    color:#2E7D32;
    background:#E8F5E9;

    border-radius:12px;

    transition:.2s;

}

.btnCerrarDrawer:hover{

    background:#C8E6C9;

}

.drawerContenido{

    padding:10px 24px 30px 24px;

    overflow-y:auto;

    flex:1;

}

/* En el panel los títulos y el botón no necesitan tanto margen superior */
.drawerContenido .tituloRanking:first-child{

    margin-top:15px;

}

.drawerContenido #btnBorrarRanking{

    margin-top:25px;

}

/* Pestaña y panel ocultos mientras se juega */
.tabPuntajes.oculto,
.drawerBackdrop.oculto{

    display:none;

}

@media(max-width:600px){

    /* En el celular el contenido (sobre todo la pantalla final con los dos
       rankings) puede ser más alto que la pantalla: se habilita el scroll
       vertical y se ancla arriba para que no se recorte el encabezado.
       'scroll' en el fondo evita el bug del 'fixed' en iOS. */
    body{

        overflow-y:auto;
        overflow-x:hidden;

        align-items:flex-start;

        padding:14px 0;

        background-attachment:scroll;

    }

    .pantalla{

        width:94%;

        padding:24px 18px;

        border-radius:18px;

    }

    h1{

        font-size:26px;
        margin-bottom:14px;

    }

    h2{

        font-size:20px;

    }

    p{

        font-size:16px;
        margin-bottom:22px;

    }

    /* Barra superior (progreso / puntaje / temporizador) más compacta */
    .barraSuperior{

        margin-bottom:24px;
        gap:10px;

    }

    #progreso,
    #puntaje{

        padding:9px 12px;
        font-size:14px;

    }

    #temporizador{

        width:52px;
        height:52px;

    }

    #tiempoTexto{

        font-size:18px;

    }

    .contenedorPregunta{

        padding:22px 18px;
        margin-bottom:24px;

    }

    .contenedorOpciones{

        gap:12px;

    }

    .opcion{

        min-height:70px;
        font-size:17px;
        border-radius:14px;

    }

    .opcion.expandida{

        min-height:80px;
        font-size:19px;

    }

    .tabPuntajes{

        font-size:15px;
        padding:16px 8px;

    }

    /* Rankings más chicos para que entren mejor */
    .tituloRanking{

        font-size:20px;
        margin-top:22px;

    }

    .filaRanking{

        font-size:16px;
        padding:10px 14px;

    }

    #btnComenzar,
    #btnReiniciar{

        font-size:20px;
        padding:16px;

    }

    /* Panel lateral: un poco más de aire en pantallas chicas */
    .drawerContenido{

        padding:10px 18px 24px 18px;

    }

}


/* Teléfonos muy angostos */
@media(max-width:380px){

    .pantalla{

        padding:20px 14px;

    }

    h1{

        font-size:23px;

    }

    .opcion{

        min-height:62px;
        font-size:16px;

    }

    #nombreJugador,
    #btnComenzar,
    #btnReiniciar,
    #btnToggleTimer{

        width:100%;

    }

}


/* ==========================
   MODAL DE CONTRASEÑA
========================== */

.modalOverlay{

    position:fixed;

    inset:0;

    display:flex;

    align-items:center;

    justify-content:center;

    padding:20px;

    background:rgba(0,0,0,.55);

    z-index:1000;

}

/* Mayor especificidad que .oculto para poder mostrar/ocultar el modal */
.modalOverlay.oculto{

    display:none;

}

.modalCaja{

    width:100%;

    max-width:360px;

    background:white;

    border-radius:20px;

    padding:30px;

    box-shadow:0 15px 45px rgba(0,0,0,.30);

    animation:aparecer .3s ease;

}

.modalCaja h3{

    text-align:center;

    color:#2E7D32;

    margin-bottom:20px;

}

.modalCaja input{

    display:block;

    margin:0 auto 12px auto;

    width:100%;

    padding:15px 18px;

    font-size:18px;

    text-align:center;

    color:#2E7D32;

    border:3px solid #A5D6A7;

    border-radius:15px;

    outline:none;

    transition:.25s;

}

.modalCaja input:focus{

    border-color:#2E7D32;

    box-shadow:0 0 0 4px rgba(46,125,50,.15);

}

.errorAuth{

    min-height:20px;

    margin:-4px 0 10px 0;

    font-size:15px;

    color:#C62828;

    text-align:center;

}

.modalTexto{

    text-align:center;

    font-size:15px;

    color:#555;

    margin:-10px 0 20px 0;

}

.modalBotones{

    display:flex;

    flex-direction:column;

    gap:10px;

}

.modalBotones #btnConfirmarClave{

    display:block;

    width:100%;

    padding:15px;

    font-size:18px;

    color:white;

    background:#2E7D32;

    border-radius:15px;

    font-weight:bold;

}

.modalBotones #btnConfirmarClave:hover{

    background:#1B5E20;

}

.modalBotones .btnSecundario{

    margin:0 auto;

}

.btnPeligro{

    display:block;

    width:100%;

    padding:15px;

    font-size:18px;

    color:white;

    background:#C62828;

    border-radius:15px;

    font-weight:bold;

}

.btnPeligro:hover{

    background:#8E0000;

}


/* ==========================
   ANIMACIONES
========================== */

@keyframes aparecer{

    from{

        opacity:0;

        transform:translateY(30px);

    }

    to{

        opacity:1;

        transform:translateY(0);

    }

}

@keyframes correcto{

    0%{

        transform:scale(1);

    }

    45%{

        transform:scale(1.1);

    }

    70%{

        transform:scale(.97);

    }

    100%{

        transform:scale(1);

    }

}

/* Latido suave del botón "Comenzar" en la pantalla de inicio */
@keyframes respira{

    0%,100%{

        transform:scale(1);

        box-shadow:0 8px 20px rgba(46,125,50,.35);

    }

    50%{

        transform:scale(1.035);

        box-shadow:0 12px 26px rgba(46,125,50,.45);

    }

}

/* Entrada de cada opción (con retardo escalonado puesto desde JS) */
@keyframes entraOpcion{

    from{

        opacity:0;

        transform:translateY(20px) scale(.96);

    }

    to{

        opacity:1;

        transform:translateY(0) scale(1);

    }

}

/* Entrada de la tarjeta de pregunta */
@keyframes entraPregunta{

    from{

        opacity:0;

        transform:translateY(-16px) scale(.98);

    }

    to{

        opacity:1;

        transform:translateY(0) scale(1);

    }

}

@keyframes error{

    0%{

        transform:translateX(0);

    }

    25%{

        transform:translateX(-10px);

    }

    50%{

        transform:translateX(10px);

    }

    75%{

        transform:translateX(-10px);

    }

    100%{

        transform:translateX(0);

    }

}


/* ==========================
   RESPONSIVE
========================== */

@media(max-width:800px){

    .opcion{

        width:100%;

    }

    h1{

        font-size:30px;

    }

    h2{

        font-size:22px;

    }

    #btnComenzar,
    #btnReiniciar{

        width:100%;

    }

}