* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Georgia', serif;
    background: linear-gradient(135deg, #1a1a2e, #16213e, #0f0f23);
    color: #e0e0e0;
    min-height: 100vh;
    overflow-x: hidden;
}

#game-container {
    position: relative;
    width: 100%;
}

.screen {
    display: none;
    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;
    padding-bottom: 4rem;
}

.screen.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
    z-index: 10;
    pointer-events: auto;
    position: relative;
}

/* Pantalla de inicio */
#start-screen.active {
    align-items: center;
    justify-content: center;
    background: 
        radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.3), transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3), transparent 50%),
        linear-gradient(135deg, #0c0c0c, #1a1a2e, #16213e);
}

.mansion-bg {
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    padding: 3rem;
    border-radius: 20px;
    border: 2px solid #444;
    box-shadow: 
        0 0 50px rgba(138, 43, 226, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.5);
    /* backdrop-filter: blur(10px); */ /* Esta línea fue eliminada por ser muy costosa en móviles */
    position: relative;
    max-width: 600px;
    margin: 2rem;
    animation: ghostlyGlow 3s ease-in-out infinite alternate;
}

@keyframes ghostlyGlow {
    0% { box-shadow: 0 0 50px rgba(138, 43, 226, 0.3), inset 0 0 20px rgba(0, 0, 0, 0.5); }
    100% { box-shadow: 0 0 80px rgba(138, 43, 226, 0.5), inset 0 0 30px rgba(0, 0, 0, 0.3); }
}

.fog {
    position: absolute;
    top: -50px;
    left: -50px;
    right: -50px;
    bottom: -50px;
    background: 
        radial-gradient(ellipse at center, transparent 40%, rgba(255, 255, 255, 0.1) 70%);
    animation: fogMove 6s ease-in-out infinite;
    pointer-events: none;
}

@keyframes fogMove {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.1) rotate(2deg); }
}

.game-title {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    background: linear-gradient(45deg, #ff6b6b, #ffd93d, #6bcf7f, #4ecdc4);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
    animation: titlePulse 2s ease-in-out infinite alternate;
}

@keyframes titlePulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.05); }
}

.game-subtitle {
    font-size: 1.2rem;
    color: #bbb;
    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 #8a2be2;
    line-height: 1.6;
}

.warning {
    color: #ff4757;
    font-weight: bold;
    margin-top: 1rem;
    animation: warningBlink 2s infinite;
}

@keyframes warningBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.7; }
}

/* Botones */
.btn-primary, .btn-submit, .btn-secondary {
    color: white;
    padding: 12px 30px;
    border: none;
    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;
    display: inline-block;
}

.btn-primary, .btn-submit {
    background: linear-gradient(45deg, #667eea, #764ba2);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover, .btn-submit:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
    background: linear-gradient(45deg, #764ba2, #667eea);
}

/* Estilo para el botón secundario (Salir/Escapar) */
.btn-secondary {
    background: transparent;
    border: 2px solid #667eea;
    box-shadow: none;
    padding: 10px 28px;
    color: #c0c0e0;
}

.btn-secondary:hover {
    background: rgba(102, 126, 234, 0.2);
    transform: translateY(-2px);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.btn-submit {
    background: linear-gradient(45deg, #11998e, #38ef7d);
    box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
}

.btn-submit:hover {
    background: linear-gradient(45deg, #38ef7d, #11998e);
    box-shadow: 0 6px 20px rgba(17, 153, 142, 0.6);
}

/* Pantalla de juego */
.game-header {
    background: rgba(0, 0, 0, 0.9);
    padding: 1rem;
    border-bottom: 2px solid #444;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.level-info {
    display: flex;
    gap: 2rem;
    font-size: 1.1rem;
}

.ghost-counter {
    color: #ff4757;
    animation: ghostFloat 2s ease-in-out infinite alternate;
}

@keyframes ghostFloat {
    0% { transform: translateY(0px); }
    100% { transform: translateY(-3px); }
}

/* Contenedor para vidas y botón de escapar */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.lives {
    font-size: 1.2rem;
}

.game-main {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    padding: 2rem;
    max-width: 1200px;
    margin: 0 auto;
}

.room-container {
    background: rgba(0, 0, 0, 0.6);
    border-radius: 15px;
    padding: 2rem;
    border: 1px solid #444;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.room-desc {
    margin-bottom: 2rem;
    text-align: center;
}

.room-desc h2 {
    color: #ffd93d;
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    text-shadow: 0 0 10px rgba(255, 217, 61, 0.5);
}

.problem-container {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 1.5rem;
    border: 1px solid #555;
}

.problem-box {
    margin-bottom: 2rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border-left: 4px solid #4ecdc4;
}

.math-content {
    font-size: 1.2rem;
    line-height: 1.8;
    color: #e8e8e8;
    margin: 1rem 0;
    text-align: center;
    overflow-x: auto;
    padding-bottom: 10px;
}

.answer-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: bold;
    color: #bbb;
}

.input-field {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid #555;
    border-radius: 5px;
    padding: 10px;
    color: #e0e0e0;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.input-field:focus {
    outline: none;
    border-color: #4ecdc4;
    box-shadow: 0 0 10px rgba(78, 205, 196, 0.3);
    background: rgba(255, 255, 255, 0.15);
}

.input-field option {
    background: #1a1a2e;
    color: #e0e0e0;
}

/* Panel de ayuda */
.help-panel {
    background: rgba(0, 0, 0, 0.8);
    border-radius: 15px;
    padding: 1.5rem;
    border: 1px solid #444;
    height: fit-content;
    position: sticky;
    top: 2rem;
}

.help-panel h3 {
    color: #ffd93d;
    margin-bottom: 1rem;
    text-align: center;
}

.help-content {
    line-height: 1.6;
    color: #ccc;
}

.help-topics-list {
    list-style: none;
    padding: 0;
    margin-top: 1rem;
}

.tooltip-topic {
    background: rgba(78, 205, 196, 0.1);
    border: 1px solid rgba(78, 205, 196, 0.3);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    cursor: help;
    transition: all 0.2s ease-in-out;
    text-align: center;
    font-weight: bold;
    color: #4ecdc4;
}

.tooltip-topic:hover {
    background-color: rgba(78, 205, 196, 0.3);
    border-color: #4ecdc4;
    transform: translateY(-2px);
    box-shadow: 0 2px 10px rgba(78, 205, 196, 0.4);
}

/* Tooltip */
.tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.95);
    color: #e0e0e0;
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid #4ecdc4;
    box-shadow: 0 0 20px rgba(78, 205, 196, 0.5);
    max-width: 300px;
    z-index: 1000;
    display: none;
    font-size: 0.9rem;
    line-height: 1.4;
}

.tooltip.show {
    display: block;
    animation: tooltipFadeIn 0.3s ease-out;
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Pantallas de fin */
#game-over-screen.active, #victory-screen.active {
    align-items: center;
    justify-content: center;
    text-align: center;
}

.game-over-bg, .victory-bg {
    background: rgba(139, 0, 0, 0.9);
    padding: 3rem;
    border-radius: 20px;
    border: 2px solid #8b0000;
    box-shadow: 0 0 50px rgba(139, 0, 0, 0.5);
    margin: 2rem;
}

.game-over-title {
    font-size: 2.5rem;
    color: #ff4757;
    margin-bottom: 1rem;
    animation: shake 0.5s ease-in-out infinite alternate;
}

@keyframes shake {
    0% { transform: translateX(-2px); }
    100% { transform: translateX(2px); }
}

.ghost-animation {
    font-size: 3rem;
    margin: 1rem 0;
    animation: ghostDance 1s ease-in-out infinite;
}

@keyframes ghostDance {
    0%, 100% { transform: scale(1) rotate(-5deg); }
    50% { transform: scale(1.2) rotate(5deg); }
}

.victory-bg {
    background: rgba(0, 100, 0, 0.9);
    border: 2px solid #4ecdc4;
    box-shadow: 0 0 50px rgba(78, 205, 196, 0.5);
}

.victory-title {
    font-size: 2.5rem;
    color: #4ecdc4;
    margin-bottom: 1rem;
    animation: victoryPulse 1s ease-in-out infinite alternate;
}

@keyframes victoryPulse {
    0% { transform: scale(1); text-shadow: 0 0 20px rgba(78, 205, 196, 0.5); }
    100% { transform: scale(1.05); text-shadow: 0 0 30px rgba(78, 205, 196, 0.8); }
}

.sparkles {
    font-size: 2rem;
    margin: 1rem 0;
    animation: sparkle 1.5s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.3) rotate(180deg); }
}

.score-display {
    background: rgba(0, 0, 0, 0.5);
    padding: 1rem;
    border-radius: 10px;
    margin: 1rem 0;
    font-size: 1.2rem;
    border: 1px solid #4ecdc4;
}

/* Contenedor para botones de fin de juego */
.end-game-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    margin-top: 2rem;
    flex-wrap: wrap;
}

/* Efectos de error */
.error-shake {
    animation: errorShake 0.5s ease-in-out;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    75% { transform: translateX(10px); }
}

.error-flash {
    animation: errorFlash 0.5s ease-in-out;
}

@keyframes errorFlash {
    0%, 100% { background-color: rgba(255, 255, 255, 0.1); }
    50% { background-color: rgba(255, 71, 87, 0.3); }
}

/* Media Queries para Responsividad */
@media (max-width: 900px) {
    .game-main {
        grid-template-columns: 1fr;
        padding: 1rem;
    }
    
    .help-panel {
        position: static;
        top: auto;
        margin-top: 2rem;
    }

    .tooltip {
        max-width: 90vw;
    }
}

@media (max-width: 768px) {
    .status-bar {
        flex-direction: column;
        gap: 1rem;
        justify-content: center;
    }
    
    .game-title {
        font-size: 2rem;
    }
    
    .mansion-bg, .game-over-bg, .victory-bg {
        padding: 2rem 1rem;
        margin: 1rem;
    }

    .room-container {
        padding: 1.5rem;
    }

    /* Asegurar que los botones de acción del header no se vean mal en móvil */
    .header-actions {
        justify-content: center;
    }
}
