* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

/* Bloqueamos el scroll del body para que la página sea 100% estable */
body { 
    background: #0f172a; color: white; 
    height: 100vh;
    display: flex; flex-direction: column; 
    overflow: hidden; 
}

/* ======== HEADER Y NAV ======== */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 30px; background: #1e293b; border-bottom: 2px solid #334155; }
.logo { display: flex; align-items: center; gap: 15px; }
.icono { font-size: 30px; color: #3b82f6; }
.topbar h1 { font-size: 20px; margin: 0; }
.topbar small { color: #94a3b8; font-size: 13px; }
.busqueda input { padding: 8px 15px; border-radius: 20px; border: none; outline: none; width: 300px; font-size: 14px; background: white; color: black; }
.busqueda input:focus { box-shadow: 0 0 15px #3b82f6; }
.menu { display: flex; justify-content: center; gap: 15px; padding: 10px; background: #0f172a; }
.menu button { padding: 8px 18px; background: #1e293b; color: white; border: none; border-radius: 8px; font-size: 15px; cursor: pointer; transition: .2s; font-weight: bold; }
.menu button:hover { background: #3b82f6; }

main { 
    display: flex; 
    flex: 1; 
    padding: 15px; 
    gap: 40px; 
    max-width: 1800px; 
    margin: 0 auto; 
    width: 100%; 
    justify-content: center; 
    align-items: center; 
}
footer { text-align: center; padding: 10px; background: #1e293b; color: #94a3b8; font-size: 13px; }

/* ======== COLORES DE ELEMENTOS ======== */
.alcalino       { background: #1f2136; color: white; }
.alcalinoterreo { background: #eab464; color: black; }
.transicion     { background: #0077c0; color: white; }
.post           { background: #7e1fa1; color: white; }
.metaloide      { background: #e9154a; color: white; }
.nometal        { background: #f17100; color: white; }
.halogeno       { background: #90b341; color: black; }
.noble          { background: #1a4321; color: white; }
.lantanido      { background: #ccea87; color: black; }
.actinido       { background: #24aa99; color: black; }
.desconocido    { background: #475569; color: white; }

/* ======== ESTRUCTURA TABLA Y LEYENDA ======== */
.contenedor-principal {
    position: relative;
    width: max-content;
    display: flex;
    flex-direction: column;
}

#leyenda-central {
    position: absolute;
    /* CÁLCULO EXACTO DEL HUECO PARA QUE ENCAJE COMO LEGO */
    left: 157px;   /* Empieza exactamente donde arranca el grupo 3 */
    top: 29px;     /* Empieza exactamente debajo de los números de los grupos */
    width: 636px;  /* Ocupa el ancho exacto de los 10 grupos vacíos */
    height: 188px; /* Ocupa el alto exacto de los 3 periodos vacíos */
    
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 40px; /* Espacio perfecto entre las familias y el ejemplo */
    pointer-events: none; 
}

.familias-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.item-leyenda { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 500; color: #e2e8f0; }
.color-box { width: 14px; height: 14px; border-radius: 3px; display: inline-block; box-shadow: 0 0 5px rgba(0,0,0,0.3); }

/* ======== ESTILOS DEL EJEMPLO VISUAL ======== */
.ejemplo-container {
    display: flex; align-items: center;
    background: rgba(255,255,255,0.05);
    padding: 10px 15px; border-radius: 12px;
}
.ejemplo-etiquetas-izq, .ejemplo-etiquetas-der {
    display: flex; flex-direction: column; justify-content: space-between;
    height: 52px; font-size: 10px; color: #94a3b8; font-weight: bold;
}
.ejemplo-etiquetas-izq { text-align: right; }
.ejemplo-etiquetas-der { text-align: left; }
.elemento-ejemplo {
    width: 60px; height: 60px; border-radius: 6px;
    position: relative; display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    color: white; box-shadow: 0 0 10px rgba(0,0,0,0.4);
    margin: 0 10px;
}
.elemento-ejemplo .top-info { position: absolute; top: 3px; left: 3px; right: 3px; display: flex; justify-content: space-between; font-size: 10px; font-weight: bold; opacity:0.9; }
.elemento-ejemplo .simbolo { font-size: 23px; font-weight: bold; margin-top: 8px; }
.elemento-ejemplo .nombre { font-size: 8.5px; margin-top: 1px; }

/* ======== TABLA Y TARJETAS ======== */
#tabla {
    display: grid;
    gap: 4px;
    grid-template-columns: 25px repeat(18, 60px);
    grid-template-rows: 25px repeat(10, 60px);
}

.grupo-label, .periodo-label {
    display: flex; justify-content: center; align-items: center;
    color: #94a3b8; font-size: 13px; font-weight: bold;
}

.elemento {
    position: relative;
    overflow: hidden;
    animation: zoom .3s;
    cursor: pointer;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s;
}
.elemento::before { content: ""; position: absolute; top: 0; left: -100%; width: 100%; height: 100%; background: rgba(255,255,255,.15); transition: .3s; }
.elemento:hover::before { left: 100%; }
.elemento:hover { transform: scale(1.15); z-index: 100 !important; }

.top-info {
    position: absolute;
    top: 3px; left: 3px; right: 3px;
    display: flex; justify-content: space-between;
    font-size: 10px; font-weight: bold; opacity: 0.85;
}
.simbolo { font-size: 23px; font-weight: bold; margin-top: 8px; }
.nombre { font-size: 8.5px; margin-top: 1px; text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 95%; }

/* ======== PANEL LATERAL ======== */
#panel { height: max-content; width: 320px; } 
.card { animation: aparecer .4s; background: #1e293b; padding: 20px; border-radius: 12px; }
.card h2 { font-size: 26px; margin-bottom: 15px; text-align: center; }
.info { display: flex; flex-direction: column; gap: 8px; }
.info div { background: #0f172a; padding: 12px; border-radius: 8px; border-left: 5px solid #3b82f6; font-size: 14px; transition: .2s; }
.info div:hover { transform: translateX(5px); background: #1e3a8a; }
.info span { font-weight: bold; font-size: 11px; color: #60a5fa; text-transform: uppercase; }

/* ======== MODALES Y JUEGOS ======== */
.ventana { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.8); display: flex; justify-content: center; align-items: center; z-index: 999; }
.ventanaContenido { background: #1e293b; padding: 30px; border-radius: 20px; width: 500px; max-width: 90%; text-align: center; box-shadow: 0 0 25px rgba(0,0,0,.5); animation: abrir .3s; }
.ventanaContenido h2 { margin-bottom: 20px; font-size: 28px; }
.ventanaContenido h1 { margin: 20px 0; font-size: 24px; color: #60a5fa; }
.ventanaContenido button { width: 100%; padding: 14px; margin: 8px 0; border: none; border-radius: 10px; background: #2563eb; color: white; font-size: 17px; cursor: pointer; transition: .25s; font-weight: bold; }
.ventanaContenido button:hover { background: #3b82f6; transform: scale(1.03); }
.ventanaContenido input { width: 100%; padding: 15px; font-size: 22px; text-align: center; border: none; border-radius: 10px; outline: none; margin-top: 10px; }
#resultadoJuego { margin-top: 18px; font-size: 22px; font-weight: bold; min-height: 35px; }

@keyframes aparecer { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes zoom { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes abrir { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }