:root {
    --bg-color: #f3f4f6;
    --text-color: #333;
    --primary: #0b5394;
    --primary-light: #4a90e2;
    --error: #f44336;
    --key-bg: #ffffff;
    --key-shadow: #9ca3af;
    --key-guide: #fbbf24; 
    --font-main: 'Nunito', sans-serif;
}

body { font-family: var(--font-main); background-color: var(--bg-color); color: var(--text-color); margin: 0; padding: 0; display: flex; flex-direction: column; min-height: 100vh; }

.top-bar { background: #ffffff; height: 50px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); font-size: 0.9rem; color: #555; font-weight: 700; }
.close-btn { cursor: pointer; font-size: 1.2rem; color: #999; }

.screen { display: none; flex: 1; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.screen.active { display: flex; }
.container { background: #fff; padding: 2rem 3rem; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); width: 90%; max-width: 1000px; text-align: center; }

/* FORMULARIO */
.form-group { display: flex; flex-direction: column; gap: 15px; max-width: 400px; margin: 0 auto; }
input { padding: 15px; font-size: 1.1rem; border: 2px solid #e5e7eb; border-radius: 10px; font-family: var(--font-main); outline: none; transition: border 0.3s; }
input:focus { border-color: var(--primary-light); }

/* BOTONES */
button { padding: 12px 24px; font-size: 1rem; font-weight: 700; border: none; border-radius: 10px; cursor: pointer; font-family: var(--font-main); transition: all 0.2s; }
button:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #083b6b; }
.btn-secondary { background: #e5e7eb; color: #333; }
.btn-secondary:hover { background: #d1d5db; }
.btn-outline { background: #fff; border: 2px solid #e5e7eb; color: #4b5563; padding: 8px 16px; font-size: 0.9rem; }
.btn-outline:hover { background: #f3f4f6; }

/* SELECCIÓN */
.seccion-titulo { font-size: 1.5rem; text-align: left; margin: 20px 0 10px 0; color: #4b5563; border-bottom: 2px solid #e5e7eb; padding-bottom: 10px; font-weight: 800; }
.lecciones-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
.btn-leccion { background: #f8fafc; border: 2px solid #e2e8f0; padding: 20px; font-size: 1.1rem; color: #333; border-radius: 12px; text-align: left; }
.btn-leccion:hover { border-color: var(--primary); background: white; box-shadow: 0 4px 12px rgba(11, 83, 148, 0.1); }

/* PANTALLA DE LECCIÓN */
.lesson-container { width: 100%; max-width: 1200px; display: flex; flex-direction: column; gap: 15px; }

/* BARRA DE ACCIONES (Volver, Progreso, Reiniciar) */
.lesson-actions { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.progress-bar-container { flex: 1; height: 12px; background-color: #e5e7eb; border-radius: 10px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); }
.progress-bar-fill { height: 100%; width: 0%; background-color: var(--primary-light); border-radius: 10px; transition: width 0.1s ease-out; }

/* CAJA DE TEXTO CON EFECTO DE SCROLL */
.text-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 2rem;
    line-height: 1.6;
    letter-spacing: 2px;
    padding: 30px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    outline: none;
    border: 2px solid transparent;
    word-wrap: break-word;
    
    /* NUEVAS REGLAS PARA CENTRADO ABSOLUTO */
    height: 220px; /* Altura fija */
    position: relative; /* Para posicionar el texto adentro */
    overflow: hidden;
}

/* El contenedor de la línea actual */
.linea-texto {
    position: absolute; /* Lo saca del flujo normal y evita que empuje hacia abajo */
    top: 50%; /* Lo baja a la mitad */
    left: 30px; /* Margen izquierdo */
    right: 30px;
    transform: translateY(-50%); /* Lo sube exactamente la mitad de su altura para centrarlo */
    width: calc(100% - 60px);
    text-align: left;
}

.text-display:focus { border-color: var(--primary-light); }
.char { color: #9ca3af; transition: color 0.1s; }
.char.correct { color: #10b981; }
.char.incorrect { color: var(--error); background: #fee2e2; border-radius: 4px; }
.char.current { border-left: 3px solid var(--primary-light); animation: blink 1s infinite; margin-left: -3px; }
@keyframes blink { 50% { border-color: transparent; } }

/* TECLADO COMPLETO ESTILO 104 TECLAS */
.keyboard-scroll-wrapper {
    width: 100%;
    overflow-x: auto; /* Permite hacer scroll horizontal en pantallas pequeñas */
    padding-bottom: 10px;
}

.keyboard-full {
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    background: #e5e7eb;
    padding: 15px;
    border-radius: 12px;
    box-shadow: inset 0 -6px 0 #d1d5db;
    margin: 0 auto;
}

.keyboard-row { 
    display: flex; 
    gap: 6px; 
    justify-content: flex-start; 
}
.key {
    background: var(--key-bg);
    height: 42px;
    display: flex; justify-content: center; align-items: center;
    font-weight: 700; font-size: 0.8rem; color: #4b5563;
    box-shadow: 0 3px 0 var(--key-shadow);
    box-sizing: border-box;
    user-select: none;
    transition: transform 0.05s, box-shadow 0.05s, background-color 0.05s;
    border-radius: 5px;
}

.key.active { 
    transform: translateY(3px); 
    box-shadow: 0 0 0 var(--key-shadow); 
    background: var(--primary-light); 
    color: white; 
}

.key.next-key { 
    background-color: var(--key-guide); 
    color: #fff; 
    box-shadow: inset 0 0 0 3px #d97706, 0 3px 0 #d97706; 
}

/* Texto de Enter en la lección */
.char.enter-char {
    display: inline-block;
    width: 100%;
    color: #0b5394;
    font-size: 1.2rem;
    font-weight: bold;
    line-height: 1;
    margin-top: 10px;
}
/* Tamaños de teclas */
.key.std { width: 45px; }
.key.w-1-25 { width: 60px; }
.key.w-1-5 { width: 70px; }
.key.w-1-75 { width: 85px; }
.key.w-2 { width: 95px; }
.key.w-2-25 { width: 110px; }
.key.w-2-75 { width: 130px; }
.key.w-6-25 { width: 290px; } /* Barra espaciadora */

.key.active { transform: translateY(3px); box-shadow: 0 0 0 var(--key-shadow); background: var(--primary-light); color: white; }
.key.next-key { background-color: var(--key-guide); color: #fff; box-shadow: inset 0 0 0 3px #d97706, 0 3px 0 #d97706; }

/* Separadores visuales en el teclado */
.key-gap { width: 15px; } 

/* RESULTADOS */
/* ... (Los estilos de resultados y constancia se mantienen igual que la vez pasada) ... */
.results-container { width: 100%; max-width: 800px; display: flex; flex-direction: column; align-items: center; gap: 30px; }
.results-card { position: relative; background: white; padding: 40px; border-radius: 24px; box-shadow: 0 10px 40px rgba(0,0,0,0.08); display: flex; align-items: flex-start; gap: 30px; width: 100%; box-sizing: border-box; }
.mascot { font-size: 6rem; }
.speech-bubble { background: #f8fafc; border: 2px solid #e2e8f0; padding: 20px 40px; border-radius: 20px; flex: 1; text-align: center; position: relative; }
.speech-bubble::before { content: ''; position: absolute; left: -20px; top: 40px; border: 10px solid transparent; border-right-color: #e2e8f0; }
.stars-container { font-size: 3.5rem; color: #d1d5db; margin: 10px 0; letter-spacing: 5px; }
.star.filled { color: #fbbf24; text-shadow: 0 4px 10px rgba(251, 191, 36, 0.4); }
.score-summary { text-align: center; }
.score-summary h3 { font-size: 1.8rem; color: #4b5563; font-weight: 400;}
.highlight { color: #10b981; font-weight: 800; font-size: 2.5rem; }
.botones-accion { display: flex; gap: 20px; margin-top: 20px; }

#certificado { border: 12px solid var(--primary); padding: 50px; text-align: center; border-radius: 10px; background: #fff; width: 100%; box-sizing: border-box; }
.cert-header h2 { color: var(--primary); font-size: 2rem; margin-bottom: 5px;}
.cert-header h3 { font-size: 3rem; margin-top: 0; letter-spacing: 2px;}
.cert-body h1 { font-size: 2.5rem; color: #333; border-bottom: 2px solid #ccc; display: inline-block; padding: 0 20px 10px; margin: 20px 0;}
.cert-body h2 { color: var(--primary); }
.cert-datos { margin-top: 30px; font-size: 1.2rem; display: flex; justify-content: space-around; background: #f3f4f6; padding: 20px; border-radius: 8px;}

@media print {
    body * { visibility: hidden; }
    #certificado, #certificado * { visibility: visible; }
    #certificado { position: absolute; left: 0; top: 0; width: 100%; border: 10px solid #0b5394; display: block !important; }
    .botones-accion, .results-card, .score-summary, .top-bar { display: none !important; }
}

/* NUEVOS ESTILOS PARA LA SELECCIÓN DE GRADO */
.grados-grid {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.btn-grado {
    background: #f8fafc;
    border: 3px solid #e2e8f0;
    padding: 30px 20px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 180px;
}

.btn-grado:hover {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 10px 20px rgba(11, 83, 148, 0.1);
    transform: translateY(-5px);
}

.grado-icon {
    font-size: 3rem;
    margin-bottom: 15px;
}

.grado-titulo {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
}

/* NUEVOS ESTILOS PARA EL RESUMEN DE PUNTUACIÓN */
.score-summary {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.05);
    width: 100%;
    box-sizing: border-box;
}

.score-big {
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 10px;
    text-align: center;
}
.score-big .score-max {
    font-size: 2rem;
    color: #9ca3af;
    font-weight: 400;
}
.score-big p {
    font-size: 1rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
    margin-top: 5px;
}

.score-details {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    justify-content: center;
    width: 100%;
}

.detail-box {
    background: #f3f4f6;
    padding: 15px 25px;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}

.detail-val {
    font-size: 1.8rem;
    font-weight: 800;
    color: #1f2937;
}

.detail-label {
    font-size: 0.8rem;
    color: #6b7280;
    text-transform: uppercase;
    font-weight: 700;
    margin-top: 5px;
}

/* Estilos para la lista de datos dentro de la constancia */
.cert-lista-datos {
    margin: 25px 0;
    font-size: 1.1rem;
    line-height: 1.6;
    color: #333;
}

.cert-lista-datos p {
    margin: 5px 0;
}

.cert-lista-datos span {
    font-weight: 800;
    color: #0b5394;
}

/* Estilos para la nota final */
.cert-nota-final {
    font-size: 2rem;
    font-weight: 800;
    color: #0b5394;
    margin-top: 20px;
    padding: 10px;
    background: #f3f4f6;
    border-radius: 8px;
    display: inline-block;
}

/* Contenedor de la barra y contador */
.progress-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
}

.progress-info {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 600px; /* Para que no sea gigante */
}

.line-counter {
    font-size: 0.85rem;
    font-weight: 700;
    color: #6b7280;
    white-space: nowrap;
}

/* Ajustamos la barra para que ocupe el resto del espacio */
.progress-bar-container {
    flex: 1;
    height: 12px;
    background-color: #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

/* CAJA DE TEXTO CENTRADA */
.text-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: 2rem;
    line-height: 1.6;
    letter-spacing: 2px;
    padding: 30px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    outline: none;
    border: 2px solid transparent;
    word-wrap: break-word;
    
    /* NUEVAS REGLAS PARA CENTRAR */
    height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: center; /* ¡Aquí está la magia! Centra el texto verticalmente */
    align-items: flex-start;
    overflow: hidden;
}

/* Ocultar las líneas que no son la actual */
.linea-texto {
    display: block;
    width: 100%;
    transition: opacity 0.2s ease;
}
.linea-oculta {
    opacity: 0;
    visibility: hidden; /* Mantiene el espacio pero invisible */
    pointer-events: none;
}
