/* ==========================================================================
   VARIABLES Y CONFIGURACIÓN DE COLORES
   ========================================================================== */
:root {
    --bg-color: #0d1117;
    --card-color: #161b22;
    --text-color: #c9d1d9;
    --accent-color: #58a6ff;
    --correct-color: #3fb950;
    --error-color: #f85149;
    
    /* Colores por Dedo */
    --color-pinky: #ff7eb9;
    --color-ring: #ffae81;
    --color-middle: #e0afff;
    --color-index: #7efff5;
    --color-thumb: #b4f481;
}

/* ==========================================================================
   BASE Y LAYOUT
   ========================================================================== */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Contenedor Principal Optimizado (Escalado para Macbook Air) */
.container {
    width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
    transform: scale(min(1, min(85vw / 1200, 85vh / 880)));
    transform-origin: center center;
}

/* ==========================================================================
   BARRA DE ESTADÍSTICAS (SUPERIOR)
   ========================================================================== */
.stats-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 30px;
    background: var(--card-color);
    padding: 15px 30px;
    border-radius: 15px;
    border: 1px solid #30363d;
}

.stat-item { 
    font-size: 1.3rem; 
    text-transform: uppercase; 
    color: #8b949e; 
}

.stat-item span { 
    color: var(--accent-color); 
    font-weight: bold; 
    font-size: 1.3rem; 
    display: inline-flex; 
    min-width: 45px; 
    text-align: center; 
}

/* MODIFICACIÓN: Color rojo para el contador de errores en la barra superior */
.stat-item:nth-child(3) span {
    color: var(--error-color);
}

/* Switch de Bloqueo de Borrado */
.toggle-container { 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    padding: 0 20px; 
    border-left: 1px solid #30363d; 
    border-right: 1px solid #30363d; 
    font-size: 0.8rem; 
    color: #8b949e; 
}

.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: #30363d; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--error-color); }
input:checked + .slider:before { transform: translateX(18px); }

/* ==========================================================================
   ÁREA DE TEXTO PRINCIPAL
   ========================================================================== */
.text-display {
    background-color: var(--card-color);
    padding: 30px;
    border-radius: 15px;
    font-size: 28px;
    font-family: 'Courier New', monospace;
    width: 1000px;
    min-height: 140px;
    text-align: left;
    border: 1px solid #30363d;
    margin-bottom: 40px;
    line-height: 1.6;
    box-sizing: border-box;
    color: var(--text-color);
}

.char-correct { color: var(--correct-color); }
.char-error { color: var(--error-color); background: rgba(248, 81, 73, 0.15); border-radius: 4px; }
.char-current { border-bottom: 4px solid var(--accent-color); }

/* ==========================================================================
   TECLADO VIRTUAL
   ========================================================================== */
.keyboard {
    background: #21262d;
    padding: 25px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid #30363d;
    margin-bottom: 40px;
}

.row { display: flex; justify-content: center; gap: 8px; }

.key {
    width: 55px; height: 55px;
    background: var(--card-color);
    border: 1px solid #444c56;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #8b949e;
    transition: all 0.1s ease;
    position: relative; /* Necesario para las rayitas F y J */
}

.row:first-child .key { justify-content: space-around; padding: 6px 0; font-size: 0.8rem; }
.key.space { width: 380px; }
.key.shift-left { width: 100px; }

/* NUEVO: Guías táctiles para F y J */
#key-f::after, #key-j::after {
    content: "";
    position: absolute;
    bottom: 8px;
    left: 25%;
    right: 25%;
    height: 3px;
    background-color: rgba(139, 148, 158, 0.4);
    border-radius: 2px;
}

/* NUEVO: Tecla pulsada por error */
.key.key-wrong {
    background-color: var(--error-color) !important;
    color: white !important;
    border-color: #ff8e89 !important;
    box-shadow: 0 0 20px rgba(248, 81, 73, 0.6);
    transform: translateY(2px);
}

/* ==========================================================================
   VISUALIZACIÓN DE DEDOS (HIGHLIGHTS)
   ========================================================================== */
.f-pinky  { background: var(--color-pinky) !important; color: #000 !important; box-shadow: 0 0 20px var(--color-pinky); transform: translateY(-4px); border-color: white; }
.f-ring   { background: var(--color-ring) !important; color: #000 !important; box-shadow: 0 0 20px var(--color-ring); transform: translateY(-4px); border-color: white; }
.f-middle { background: var(--color-middle) !important; color: #000 !important; box-shadow: 0 0 20px var(--color-middle); transform: translateY(-4px); border-color: white; }
.f-index  { background: var(--color-index) !important; color: #000 !important; box-shadow: 0 0 20px var(--color-index); transform: translateY(-4px); border-color: white; }
.f-thumb  { background: var(--color-thumb) !important; color: #000 !important; box-shadow: 0 0 20px var(--color-thumb); transform: translateY(-4px); border-color: white; }

/* ==========================================================================
   MANOS Y DEDOS
   ========================================================================== */
.hands-container { display: flex; justify-content: center; gap: 180px; margin-top: 10px; }
.hand { display: flex; align-items: flex-end; gap: 14px; height: 160px; }
.finger { width: 34px; background: #1c2128; border: 1px solid #30363d; border-radius: 14px 14px 4px 4px; display: flex; justify-content: center; align-items: flex-start; padding-top: 10px; font-weight: bold; font-size: 0.9rem; color: #8b949e; }

#finger-1, #finger-10 { border-bottom: 8px solid var(--color-pinky); }
#finger-2, #finger-9  { border-bottom: 8px solid var(--color-ring); }
#finger-3, #finger-8  { border-bottom: 8px solid var(--color-middle); }
#finger-4, #finger-7  { border-bottom: 8px solid var(--color-index); }
#finger-5, #finger-6  { border-bottom: 8px solid var(--color-thumb); }

.f1, .f10 { height: 80px; } 
.f2, .f9 { height: 120px; } 
.f3, .f8 { height: 155px; } 
.f4, .f7 { height: 135px; } 
.f5, .f6 { height: 60px; width: 50px; }

/* ==========================================================================
   MODALES (RESULTADOS Y AYUDA)
   ========================================================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 5000;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    justify-content: center;
    align-items: center;
    color: white; 
}

.modal-content {
    background-color: var(--card-color);
    padding: 40px;
    border-radius: 25px;
    border: 1px solid rgba(88, 166, 255, 0.3);
    text-align: center;
    max-width: 550px;
    width: 90%;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.modal-content h2 { color: var(--accent-color); font-size: 2.2rem; margin: 0 0 20px 0; }

.modal-results-container { margin-bottom: 25px; }

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.result-row:last-child { border-bottom: none; }

.modal-label { color: var(--text-color); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; }
.modal-value { color: white; font-size: 1.6rem; font-weight: bold; font-family: 'Courier New', monospace; }

/* Área de revisión de texto en modal */
.modal-review-text {
    background: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    margin: 15px 0 25px 0;
    max-height: 120px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    line-height: 1.5;
    text-align: left;
}

.review-correct { color: var(--correct-color); }
.review-error { color: var(--error-color); text-decoration: underline; background: rgba(248, 81, 73, 0.1); }

/* Ayuda Steps */
.help-step { 
    display: flex; 
    align-items: center; 
    gap: 15px; 
    background: rgba(255,255,255,0.03); 
    padding: 12px; 
    border-radius: 12px; 
    border: 1px solid #30363d; 
    margin-bottom: 10px; 
    text-align: left; 
}

.step-num { 
    background: var(--accent-color); 
    width: 28px; 
    height: 28px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    border-radius: 50%; 
    font-weight: bold; 
    flex-shrink: 0;
}

/* ==========================================================================
   BOTONES Y ELEMENTOS DE INTERFAZ
   ========================================================================== */
#reset-btn { 
    padding: 12px 24px; 
    cursor: pointer; 
    background: #21262d; 
    border: 1px solid #444c56; 
    color: var(--text-color); 
    border-radius: 10px; 
    font-weight: bold; 
    text-transform: uppercase; 
    transition: 0.2s;
}

#reset-btn:hover { border-color: var(--accent-color); background: #30363d; }

#help-btn { 
    width: 40px; 
    height: 40px; 
    border-radius: 50%; 
    border: 1px solid #444c56; 
    background: #21262d; 
    color: var(--accent-color); 
    font-weight: bold; 
    font-size: 1.2rem; 
    cursor: pointer; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
}

.modal-btn-alt, #close-modal-btn {
    padding: 16px;
    width: 100%;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    font-size: 1.1rem;
    text-transform: uppercase;
    border: none;
    transition: 0.2s;
    margin-top: 10px;
}

.modal-btn-alt { background: var(--correct-color); color: white; }
#close-modal-btn { background: var(--accent-color); color: white; }

/* Utilitarios */
#hidden-input { position: absolute; top: -100px; opacity: 0; pointer-events: none; }

.shake {
    animation: shake 0.2s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}