* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body { 
    font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif; 
    background: linear-gradient(135deg, #0d0d0d, #120e1a, #0d1a1a); 
    color: #f5f5f5; 
    min-height: 100vh; 
    overflow-x: hidden;
}
h1, h2, h3 { font-family: 'Georgia', serif; }

#game-container { min-height: 100vh; width: 100%; height: 100vh; }
.screen { display: none; flex-direction: column; min-height: 100vh; position: absolute; top: 0; left: 0; width: 100%; z-index: 1; transition: opacity 0.5s ease-in-out; opacity: 0; pointer-events: none; }
.screen.active { display: flex; opacity: 1; z-index: 10; pointer-events: auto; }

/* --- PANTALLA DE INICIO --- */
#start-screen { align-items: center; justify-content: center; background: radial-gradient(circle at 20% 80%, rgba(240, 0, 255, 0.1), transparent 60%), linear-gradient(135deg, #0d0d0d, #120e1a); }
.mansion-bg { text-align: center; background: rgba(10, 10, 20, 0.8); padding: 3rem; border-radius: 20px; border: 1px solid #F000FF; box-shadow: 0 0 30px rgba(240, 0, 255, 0.4), inset 0 0 20px rgba(0, 0, 0, 0.5); backdrop-filter: blur(10px); position: relative; max-width: 650px; }
.game-title { font-size: 2.8rem; margin-bottom: 1rem; color: #f5f5f5; text-shadow: 0 0 8px #fff, 0 0 15px #fff, 0 0 25px #F000FF; }
.game-subtitle { font-size: 1.2rem; color: #a3a3a3; margin-bottom: 2rem; font-style: italic; }
.story-box { background: rgba(0, 0, 0, 0.6); padding: 1.5rem; border-radius: 10px; margin: 2rem 0; border-left: 4px solid #F000FF; line-height: 1.6; }
.warning { color: #F000FF; font-weight: bold; margin-top: 1rem; animation: warningBlink 1.5s infinite; text-shadow: 0 0 10px #F000FF; }
@keyframes warningBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* --- BOTÓN DE EMERGENCIA --- */
#emergency-button-container { position: relative; width: 280px; height: 100px; background: #222; border-radius: 10px; border: 3px solid #444; box-shadow: inset 0 2px 4px rgba(0,0,0,0.6), 0 5px 10px rgba(0,0,0,0.5); margin: 2rem auto 0 auto; cursor: pointer; overflow: hidden; -webkit-tap-highlight-color: transparent; }
.emergency-cover { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: #1a1a1a; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath fill='%23F000FF' d='M50 10a8 8 0 100 16 8 8 0 000-16zm0 8a2 2 0 110-4 2 2 0 010 4z'/%3E%3Cpath fill='%23F000FF' d='M50 10a40 40 0 00-34.64 20H30a20 20 0 0134.64-20zM15.36 30A40 40 0 0010 50v15h15a25 25 0 01-1.96-9.8l-3.54-3.54zM84.64 30A40 40 0 0090 50v15h-15a25 25 0 011.96-9.8l3.54-3.54z' transform='rotate(60 50 50)'/%3E%3Cpath fill='%23F000FF' d='M50 10a40 40 0 00-34.64 20H30a20 20 0 0134.64-20zM15.36 30A40 40 0 0010 50v15h15a25 25 0 01-1.96-9.8l-3.54-3.54zM84.64 30A40 40 0 0090 50v15h-15a25 25 0 011.96-9.8l3.54-3.54z' transform='rotate(180 50 50)'/%3E%3Cpath fill='%23F000FF' d='M50 10a40 40 0 00-34.64 20H30a20 20 0 0134.64-20zM15.36 30A40 40 0 0010 50v15h15a25 25 0 01-1.96-9.8l-3.54-3.54zM84.64 30A40 40 0 0090 50v15h-15a25 25 0 011.96-9.8l3.54-3.54z' transform='rotate(300 50 50)'/%3E%3C/svg%3E"); background-size: 60px 60px; background-position: center 10px; background-repeat: no-repeat; z-index: 2; transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px; }
.emergency-cover span { color: white; font-size: 0.9rem; font-weight: bold; letter-spacing: 1px; text-shadow: 0 0 5px black; text-transform: uppercase; }
#emergency-button-container.cover-lifted .emergency-cover { transform: translateY(-110%); }
#start-btn.btn-emergency-actual { position: relative; width: 80px; height: 80px; background: radial-gradient(#ff55ff, #c500c5); border-radius: 50%; border: 3px solid #8b008b; color: white; font-weight: bold; font-size: 1rem; cursor: pointer; box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.4), 0 0 20px #F000FF; display: flex; align-items: center; justify-content: center; margin: 8px auto; z-index: 1; animation: pulse-magenta 1.5s infinite ease-in-out; outline: none; }
#start-btn.btn-emergency-actual .btn-gloss { position: absolute; top: 5px; left: 15px; width: 50px; height: 25px; background: linear-gradient(to bottom, rgba(255,255,255,0.5), rgba(255,255,255,0.1)); border-radius: 50% / 100%; transform: rotate(-15deg); }
#start-btn.btn-emergency-actual:hover { animation-play-state: paused; box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.5), 0 0 35px #ff11ff, 0 0 50px #ff55ff; }
#start-btn.btn-emergency-actual:active { transform: scale(0.95); box-shadow: inset 0 3px 5px rgba(0,0,0,0.5); }
@keyframes pulse-magenta { 0% { box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.4), 0 0 15px #F000FF; } 50% { box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.4), 0 0 30px #ff48ff; } 100% { box-shadow: inset 0 3px 5px rgba(255, 255, 255, 0.4), 0 0 15px #F000FF; } }

/* --- PANTALLA DE JUEGO --- */
.game-header { background: rgba(10, 10, 20, 0.9); padding: 1rem 2rem; border-bottom: 1px solid #61FFD4; backdrop-filter: blur(5px); z-index: 10; position: sticky; top: 0; }
.status-bar { display: flex; justify-content: space-between; align-items: center; max-width: 1400px; margin: 0 auto; }
.level-info { font-size: 1.3rem; letter-spacing: 1px; }
.ghost-counter { color: #F000FF; text-shadow: 0 0 5px #F000FF; }
/* === CAMBIO: Se ajusta el contenedor de vidas para alinear el nuevo botón === */
.lives { font-size: 1.3rem; letter-spacing: 1px; display: flex; align-items: center; gap: 1rem; }
.lives span#lives { font-size: 1.5rem; vertical-align: middle; margin-left: 0.5rem; }
.game-main { display: grid; grid-template-columns: 1fr 350px; gap: 2rem; padding: 2rem; max-width: 1400px; margin: 0 auto; flex-grow: 1; overflow-y: auto; }
.room-container { background: rgba(10, 10, 20, 0.6); border-radius: 15px; padding: 2.5rem; border: 1px solid #334155; }
.room-desc h2 { color: #f5f5f5; font-size: 2rem; text-align: center; margin-bottom: 0.5rem; text-shadow: 0 0 5px #fff, 0 0 10px #61FFD4; }
#room-story { text-align: center; margin-bottom: 2.5rem; font-size: 1.25rem; color: #61FFD4; text-shadow: 0 0 7px rgba(97, 255, 212, 0.7); font-style: normal; font-weight: 500; line-height: 1.6; }
.problem-container { background: #1e293b; border-radius: 10px; padding: 2rem; border: 1px solid #334155; }
.problem-box { margin-bottom: 2rem; padding: 1rem 1.5rem; background: #10141f; border-radius: 8px; border-left: 4px solid #61FFD4; }
.math-content { font-size: 1.5rem; line-height: 1.8; color: #e8e8e8; margin: 1rem 0; text-align: center; }
.input-field { background: #334155; border: 1px solid #475569; border-radius: 5px; padding: 12px; color: #f5f5f5; font-size: 1rem; transition: all 0.3s ease; }
.input-field:focus { outline: none; border-color: #61FFD4; box-shadow: 0 0 10px rgba(97, 255, 212, 0.5); background: #475569; }
.btn-submit { background: linear-gradient(45deg, #00c6ff, #0072ff); color: white; padding: 12px 30px; border: none; border-radius: 25px; font-size: 1.1rem; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(0, 198, 255, 0.4); text-transform: uppercase; letter-spacing: 1px; font-weight: bold; align-self: center; margin-top: 1rem; }
.btn-submit:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0, 198, 255, 0.6); }
.help-panel { background: rgba(10, 10, 20, 0.8); border-radius: 15px; padding: 1.5rem; border: 1px solid #334155; height: fit-content; position: sticky; top: 2rem; backdrop-filter: blur(5px); }
.help-panel h3 { color: #f5f5f5; margin-bottom: 1rem; text-align: center; font-size: 1.4rem; text-shadow: 0 0 8px #61FFD4; }
.help-topics-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.tooltip-topic { background: rgba(30, 41, 59, 0.5); border: 1px solid #475569; border-radius: 8px; padding: 0.75rem 1rem; cursor: help; transition: all 0.2s ease-in-out; text-align: center; font-weight: bold; color: #cbd5e1; font-size: 1.1rem; }
.tooltip-topic:hover { background-color: rgba(97, 255, 212, 0.1); border-color: #61FFD4; color: #61FFD4; }
#game-over-screen, #victory-screen { align-items: center; justify-content: center; text-align: center; flex-direction: column; padding: 1rem; }
.game-over-bg, .victory-bg { padding: 3rem; border-radius: 20px; width: 100%; max-width: 600px; }
.game-over-bg { background: rgba(139, 0, 139, 0.9); border: 2px solid #F000FF; box-shadow: 0 0 50px rgba(240, 0, 255, 0.5); }
.game-over-title { font-size: 2.5rem; color: #ff6bff; margin-bottom: 1rem; animation: shake 0.5s ease-in-out infinite alternate; text-shadow: 0 0 15px #F000FF; }
.victory-bg { background: rgba(0, 100, 100, 0.9); border: 2px solid #61FFD4; box-shadow: 0 0 50px rgba(97, 255, 212, 0.5); }
.victory-title { font-size: 2.5rem; color: #a2ffee; margin-bottom: 1rem; text-shadow: 0 0 15px #61FFD4; }
.score-display { background: rgba(0, 0, 0, 0.5); padding: 1.5rem; border-radius: 10px; margin: 2rem 0; font-size: 1.1rem; border: 1px solid #61FFD4; text-align: left; }
.btn-primary { background: linear-gradient(45deg, #da22ff, #9733ee); color: white; padding: 12px 30px; border: none; border-radius: 25px; font-size: 1.1rem; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 15px rgba(218, 34, 255, 0.4); text-transform: uppercase; letter-spacing: 1px; font-weight: bold; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(218, 34, 255, 0.6); }

/* === CAMBIO: Estilos para los nuevos botones de salida y secundarios === */
.btn-exit {
    background: rgba(45, 55, 72, 0.7);
    border: 1px solid #64748b;
    color: #e2e8f0;
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.3s ease;
    cursor: pointer;
}
.btn-exit:hover {
    background: #475569;
    border-color: #94a3b8;
    color: #fff;
}
.end-screen-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
    flex-wrap: wrap; /* Permite que los botones se ajusten en pantallas pequeñas */
}
.btn-secondary {
    background: transparent;
    border: 2px solid #9733ee;
    color: #f5f5f5;
    padding: 12px 30px;
    border-radius: 25px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
    text-decoration: none;
}
.btn-secondary:hover {
    background: #9733ee;
    color: white;
    box-shadow: 0 4px 15px rgba(151, 51, 238, 0.5);
}
/* === FIN DE CAMBIOS PARA BOTONES === */

@keyframes shake { 0% { transform: translateX(-2px); } 100% { transform: translateX(2px); } }
.ghost-animation, .sparkles { font-size: 3rem; margin: 1rem 0; }
.ghost-animation { animation: meltdown 1s ease-in-out infinite; text-shadow: 0 0 20px #F000FF;}
.sparkles { text-shadow: 0 0 20px #61FFD4; }
.feedback-modal { display: none; position: fixed; z-index: 1001; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(5px); align-items: center; justify-content: center; }
.feedback-modal.active { display: flex; animation: fadeIn 0.3s ease; }
.feedback-content { background: #1e293b; border-radius: 15px; padding: 2rem; border: 1px solid #334155; width: 90%; max-width: 550px; text-align: center; box-shadow: 0 0 50px rgba(0,0,0,0.5); }
.feedback-content.correct { border-color: #61FFD4; box-shadow: 0 0 30px rgba(97, 255, 212, 0.4); }
.feedback-content.incorrect { border-color: #F000FF; box-shadow: 0 0 30px rgba(240, 0, 255, 0.4); }
.feedback-content h4 { font-size: 2.8rem; margin-bottom: 1.5rem; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; }
.feedback-content.correct h4 { color: #61FFD4; text-shadow: 0 0 8px #61FFD4; }
.feedback-content.incorrect h4 { color: #ff6bff; text-shadow: 0 0 8px #F000FF; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.tooltip { position: fixed; background: rgba(15, 23, 42, 0.95); color: #e0e0e0; padding: 1rem; border-radius: 10px; border: 1px solid #61FFD4; box-shadow: 0 0 20px rgba(97, 255, 212, 0.5); max-width: 320px; z-index: 1002; display: none; backdrop-filter: blur(5px); }
.tooltip.show { display: block; animation: fadeIn 0.2s ease-out; }
.tooltip-content h4 { color: #61FFD4; margin-bottom: 0.75rem; }
@media (max-width: 900px) { .game-main { grid-template-columns: 1fr; padding: 1rem; } .help-panel { position: static; margin-top: 1.5rem; top: 0; } .status-bar { flex-direction: column; gap: 0.75rem; text-align: center; } }
@media (max-width: 600px) { 
    html { font-size: 14px; } 
    .mansion-bg, .game-over-bg, .victory-bg { padding: 1.5rem; margin: 1rem; max-width: 95vw; } 
    .game-title { font-size: 2.2rem; } 
    .room-container, .problem-container { padding: 1.5rem; } 
    .feedback-content { padding: 1.5rem; } 
    .feedback-content h4 { font-size: 2rem; } 
    /* === CAMBIO: Se apilan los botones de las pantallas finales en móviles === */
    .end-screen-buttons {
        flex-direction: column;
        align-items: center;
    }
}