/* --- BLOQUE 0: CSS (RANKING 6 COLS + CHAT BUTTON FIX + NOTIFICACIÓN) --- */

    /* --- ESTILOS GLOBALES --- */
    body { 
        box-sizing: border-box;
        margin: 0; padding: 0;
        font-family: 'Cinzel', 'Georgia', serif; 
        background-color: #000000; color: #f4e4d7; 
        
        /* FIX IOS: Usar dvh asegura que ocupamos la pantalla REAL descontando barras */
        height: 100vh; 
        height: 100dvh; 
        
        width: 100vw; overflow: hidden; display: flex;
        justify-content: center; align-items: center;
        
        /* FIX IOS: Evita el efecto rebote gris al arrastrar bordes */
        overscroll-behavior: none;
    }
    * { box-sizing: border-box; }

    /* --- FIX ANTI-FRUSTRACIÓN: CLICS INMEDIATOS Y PRECISOS --- */
    button, input, select, textarea, a, .professor-item, .avatar-container, .medal, .nav-arrow {
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: transparent !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }

    /* --- BLOQUEO DE FONDO AZUL AUTOFILL NAVEGADOR --- */
    input:-webkit-autofill,
    input:-webkit-autofill:hover, 
    input:-webkit-autofill:focus,
    input:-webkit-autofill:active {
        -webkit-box-shadow: 0 0 0 1000px #1a0802 inset !important;
        -webkit-text-fill-color: #f4e4d7 !important;
        border-color: #5b3a2a !important;
        transition: background-color 5000s ease-in-out 0s;
    }

    /* --- EL ESCENARIO (GAME STAGE) --- */
    #game-stage { 
        position: relative;
        width: 100%; max-width: 1600px; aspect-ratio: 16/9; max-height: 100vh; 
        background-color: #000000; background-position: center center; background-repeat: no-repeat;
        box-shadow: 0 0 50px 20px rgba(0, 0, 0, 0.9); border: 2px solid #3e2723; overflow: hidden; 
        display: flex; flex-direction: column;
        transition: background-image 0.5s ease-in-out; 
    }

    ::-webkit-scrollbar { width: 6px; }
    ::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.3); }
    ::-webkit-scrollbar-thumb { background: #a85f36; border-radius: 4px; }

    .container { 
        width: 100%; height: 100%; display: flex; flex-direction: column; padding: 10px; 
        position: relative; overflow-y: auto; 
    }

    /* --- LOADING --- */
    #loading-overlay, #transition-overlay { 
        position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
        background-color: #000000; z-index: 9999; display: flex; flex-direction: column; 
        justify-content: center; align-items: center; transition: opacity 0.3s ease-out; 
    }
    #transition-overlay { 
        z-index: 9998; opacity: 0; pointer-events: none; transition: opacity 0.5s ease-in-out;
    }
    
    /* --- MODAL PERSONALIZADO --- */
    #customModal { 
        position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
        background-color: rgba(0,0,0,0.85); z-index: 10000; display: none !important; 
        flex-direction: column; justify-content: center; align-items: center; opacity: 0; 
        transition: opacity 0.3s ease-out; 
    }
    #customModal.active { display: flex !important; opacity: 1; }

    .modal-box { 
        background: linear-gradient(180deg, #1a1a1a 0%, #0d0d0d 100%); 
        border: 2px solid #ffcc66; border-radius: 10px; padding: 22px 24px;
        width: 92%; max-width: 500px; text-align: center; box-shadow: 0 0 30px rgba(255, 204, 102, 0.2);
        max-height: 85vh; overflow-y: auto;
    }
    .modal-title { 
        font-size: 1.4rem; color: #ffcc66; margin-bottom: 15px; border-bottom: 1px solid #a85f36; padding-bottom: 10px;
    }
    .modal-msg { 
        font-size: 1.2rem; color: #e0e0e0; margin-bottom: 20px; font-family: 'Crimson Text', serif; 
        white-space: pre-wrap; text-align: justify; line-height: 1.4; 
    }
    .modal-input { 
        width: 100%; padding: 10px; margin-bottom: 20px; background: rgba(0,0,0,0.5); 
        border: 1px solid #a85f36; color: #fff; font-family: 'Crimson Text', serif; display: none; 
    }
    .modal-buttons { display: flex; justify-content: center; gap: 15px; }
    .modal-btn { 
        padding: 8px 20px; border-radius: 4px; cursor: pointer; font-family: 'Cinzel', serif; font-weight: bold;
        border: 1px solid #ffcc66; background: #5b3a2a; color: #f5f5dc; transition: all 0.2s; 
        user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    .modal-btn:hover { background: #7a4f3b; color: #fff; }
    .modal-btn.confirm { background: linear-gradient(180deg, #ffcc66 0%, #d4a045 100%); color: #1e0e0a; border-color: #fff; }
    .modal-btn.confirm:hover { background: linear-gradient(180deg, #ffeeb0 0%, #eac065 100%); }

    /* LOADER */
    .loader-spinner { 
        border: 4px solid rgba(255, 204, 102, 0.3); border-top: 4px solid #ffcc66; 
        border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; margin-bottom: 20px;
    }
    .loader-text { color: #ffcc66; font-size: 1.2rem; animation: pulse 2s infinite; }
    @keyframes spin { 100% { transform: rotate(360deg); } }
    @keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

    /* --- ANIMACIONES --- */
    @keyframes golden-glow-pulse { 
        0%, 100% { filter: drop-shadow(0 0 30px rgba(255, 204, 102, 0.6)); } 
        50% { filter: drop-shadow(0 0 60px rgba(255, 204, 102, 1.0)); } 
    }
    @keyframes orange-glow-pulse { 
        0%, 100% { box-shadow: 0 0 15px rgba(204, 85, 0, 0.6); border-color: #cc5500; } 
        50% { box-shadow: 0 0 30px rgba(255, 140, 0, 0.9); border-color: #ff8c00; } 
    }
    @keyframes red-orange-pulse { 
        0% { background: #5b3a2a; border-color: #ffcc66; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); } 
        50% { background: #b33c00; border-color: #ffaa00; box-shadow: 0 0 25px rgba(255, 100, 0, 0.9); color: #fff; transform: scale(1.05); } 
        100% { background: #5b3a2a; border-color: #ffcc66; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); } 
    }
    .urgent-call { animation: red-orange-pulse 1.5s infinite ease-in-out !important; z-index: 100; position: relative; }

    /* ANIMACIÓN DE DESBLOQUEO */
    @keyframes unlock-flash {
        0% { box-shadow: 0 0 0 rgba(134, 239, 172, 0); transform: scale(1); filter: brightness(1); }
        50% { box-shadow: 0 0 60px 30px rgba(134, 239, 172, 0.8); transform: scale(1.15); filter: brightness(1.5); border-color: #fff; }
        100% { box-shadow: 0 0 0 rgba(134, 239, 172, 0); transform: scale(1); filter: brightness(1); }
    }
    .just-unlocked { animation: unlock-flash 2s ease-in-out 3; z-index: 100; }

    /* --- ELEMENTOS COMUNES --- */
    .university-insignia { margin: 0 auto; flex-shrink: 0; transition: all 0.3s ease; }
    .university-insignia img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 5px 10px rgba(0, 0, 0, 0.8)); }
    #insignia-login { width: clamp(250px, 40vh, 600px); height: clamp(250px, 40vh, 600px); max-width: 100%; max-height: 50vh; margin-bottom: 2vh; }
    #insignia-login img { animation: golden-glow-pulse 4s ease-in-out infinite; }
    #insignia-menu { width: 50px !important; height: 50px !important; min-width: 50px; margin: 0; margin-right: 15px; }

    /* ESTILO BOTONES GENERAL */
    .game-button { 
        color: #1e0e0a; border: 2px solid #ffcc66; border-radius: 6px; padding: 10px; cursor: pointer; 
        font-size: 1rem; font-weight: bold; transition: all 0.2s; box-shadow: 0 3px 0 #8c4c2d, 0 4px 8px rgba(0,0,0,0.8); 
        text-shadow: 0 1px 0 rgba(255,255,255,0.3); width: 100%; margin-bottom: 8px; font-family: 'Cinzel', serif; 
        background: linear-gradient(180deg, #ffcc66 0%, #d4a045 100%); 
        user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    .game-button:active { transform: translateY(3px); box-shadow: 0 0 0 #8c4c2d; }
    .game-button:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(100%); box-shadow: none; transform: none; }
    .game-button:hover:not(:disabled) { background: linear-gradient(180deg, #ffeeb0 0%, #eac065 100%); }

    /* PIANO BLACK */
    .piano-btn { 
        background: linear-gradient(180deg, #1a1a1a 0%, #000000 100%); border: 1px solid #cd7f32; color: #cd7f32; 
        padding: 12px; border-radius: 6px; width: 100%; font-family: 'Cinzel', serif; font-weight: bold; font-size: 1.1rem;
        cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.9); text-shadow: 0 1px 2px rgba(0,0,0,0.8); margin-bottom: 10px;
        transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s; text-transform: uppercase; letter-spacing: 1px; 
        user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    .piano-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 15px rgba(205, 127, 50, 0.3); border-color: #e69b45; color: #e69b45; }
    .piano-btn:active { transform: translateY(2px); box-shadow: inset 0 2px 5px rgba(0,0,0,0.9); }

    /* CONTROLES DE TEST */
    .test-controls { 
        position: absolute; bottom: 0; left: 0; width: 100%; display: flex; justify-content: space-around; 
        padding: 10px; background: rgba(0,0,0,0.9); border-top: 2px solid #a85f36; gap: 5px; z-index: 500; 
        height: 60px; box-sizing: border-box; 
    }
    .small-btn { 
        font-size: 0.8rem; padding: 8px 5px; width: 100%; max-width: 120px; margin-bottom: 0; 
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis; 
    }

    .screen { 
        display: none; width: 100%; height: 100%; flex-direction: column; align-items: center; 
        padding: 0; overflow: hidden; position: relative; 
    }
    h2 { 
        color: #ffcc66; text-align: center; margin: 1vh 0; font-size: clamp(1.4rem, 4vh, 3rem); 
        text-shadow: 0 0 10px rgba(255, 204, 102, 0.5); flex-shrink: 0;
    }

    /* --- REFECTORIO --- */
    .refectorio-nav-container { 
        position: absolute; top: 15px; left: 0; width: 100%; display: flex; align-items: center; 
        justify-content: center; background: rgba(0, 0, 0, 0.7); border-top: 2px solid #5b3a2a;
        border-bottom: 2px solid #5b3a2a; padding: 5px 0; z-index: 100; height: 80px; 
    }
    .nav-arrow { 
        background: rgba(0,0,0,0.5); border: 1px solid #ffcc66; color: #ffcc66; width: 30px; height: 40px; 
        font-size: 1.2rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
        z-index: 101; margin: 0 5px; transition: all 0.2s; 
        user-select: none; -webkit-user-select: none;
    }
    .nav-arrow:active { transform: scale(0.9); background: #a85f36; }
    #refectorioTopBar { 
        flex: 1; display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 15px; padding: 0 15px;
        height: 100%; align-items: center; scroll-behavior: smooth; -ms-overflow-style: none; scrollbar-width: none; 
    }
    #refectorioTopBar::-webkit-scrollbar { display: none; }
    .megaphone-btn { 
        position: relative; width: 60px; height: 45px; background: transparent; border: none; 
        cursor: pointer; flex-shrink: 0; transition: transform 0.2s; display: flex; align-items: center; justify-content: center; 
        user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    .megaphone-btn:hover { transform: scale(1.1); }
    .megaphone-btn svg { width: 100%; height: 100%; fill: #424242; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.8)); }
    .megaphone-num { 
        position: absolute; left: 42%; top: 50%; transform: translate(-50%, -50%); color: #ffffff; 
        font-weight: bold; font-family: 'Cinzel', serif; font-size: 1.1rem; z-index: 2; text-shadow: 0 0 3px rgba(0,0,0,0.8);
    }

    /* --- PANTALLAS ESPECÍFICAS --- */
    .login-screen { 
        display: flex; flex-direction: column; align-items: center; justify-content: flex-end; 
        height: 100%; width: 100%; padding-bottom: 5vh;
    }
    .login-box { 
        background: rgba(15, 8, 5, 0.9); border: 2px solid #a85f36; border-radius: 12px; padding: 25px 30px;
        text-align: center; width: 90%; max-width: 400px; height: auto; max-height: 50vh; overflow-y: auto; 
        display: flex; flex-direction: column; backdrop-filter: blur(8px); box-shadow: 0 0 50px rgba(0, 0, 0, 0.95); margin-top: 1vh;
    }
    .login-box p { margin: 0 0 20px 0; font-size: 1.1rem; color: #ffcc66; font-weight: bold; letter-spacing: 1px; }
    .login-box input { 
        width: 100%; padding: 12px; margin-bottom: 15px; border: 1px solid #5b3a2a; border-radius: 4px;
        background: rgba(0, 0, 0, 0.7); color: #f4e4d7; font-size: 1rem; font-family: 'Crimson Text', serif;
    }
    .login-box input:focus { border-color: #ffcc66; background: rgba(0, 0, 0, 0.9); outline: none; }
    .director-portrait { 
        width: clamp(150px, 20vh, 280px); height: clamp(150px, 20vh, 280px); border-radius: 50%; border: 4px solid #cc5500;
        object-fit: cover; margin-bottom: 20px; animation: orange-glow-pulse 3s infinite; flex-shrink: 0; z-index: 10;
    }
    .welcome-content { 
        background: rgba(10, 10, 10, 0.95); border: 2px solid #a85f36; border-radius: 10px; padding: 25px;
        max-width: 100%; width: 100%; flex: 1; min-height: 0; display: flex; flex-direction: column; text-align: center;
        box-shadow: 0 0 40px rgba(0, 0, 0, 1); 
    }
    .narrative-scroll { flex: 1; overflow-y: auto; margin-bottom: 20px; padding-right: 10px; }
    .narrative-text { 
        font-family: 'Crimson Text', serif; font-size: clamp(1.25rem, 2.2vw, 1.6rem); line-height: 1.5; 
        color: #e0e0e0; text-align: left; text-shadow: 0 1px 2px rgba(0,0,0,0.8); 
    }
    .narrative-text p { margin-top: 0; margin-bottom: 12px; text-align: left; }
    .narrative-text p:last-child { margin-bottom: 0; }
    .narrative-text strong { color: #ffcc66; }
    #chronicleBody { text-align: left !important; line-height: 1.5 !important; }
    #chronicleBody p { margin-top: 0; margin-bottom: 12px; text-align: left; }
    #chronicleBody p:last-child { margin-bottom: 0; }
    #startAdventureBtn { flex-shrink: 0; margin: 0 auto; max-width: 300px; }
    #mainGame h2 { 
        margin-top: 15px; margin-bottom: 10px; font-size: clamp(1.5rem, 4vw, 2.5rem); text-transform: uppercase;
        letter-spacing: 2px; z-index: 10; padding: 0 100px; 
    }
    .menu-info { 
        width: auto; max-width: 90%; text-align: center; margin-bottom: 10px; margin-left: auto; margin-right: auto; 
        background: rgba(0, 0, 0, 0.7); border: 1px solid #a85f36; border-radius: 8px; padding: 5px 20px;
        font-size: 0.9rem; flex-shrink: 0; display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 15px;
    }
    .user-stats-text { display: flex; flex-direction: row; gap: 15px; align-items: center; color: #f4e4d7; }
    .user-stats-text p { margin: 0; white-space: nowrap; }
    .menu-header { 
        width: 100%; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; 
        background: rgba(10, 5, 3, 0.8); padding: 10px; border-radius: 8px; border: 1px solid #5b3a2a; flex-shrink: 0; 
    }
    .menu-header button { flex: 0 0 auto; width: auto; font-size: 0.75rem; padding: 8px 12px; } 
    .silver-bronze-border { 
        border: none !important; border-radius: 6px; background: linear-gradient(145deg, #5b3a2a, #4a2c1a); color: #f5f5dc; 
        box-shadow: inset 0 0 0 1px #8c4c2d, 0 0 0 2px #c0c0c0, 0 0 0 4px #cd7f32, 0 4px 8px rgba(0, 0, 0, 0.6);
        transition: all 0.3s ease; 
    }
    .silver-bronze-border:hover { 
        background: linear-gradient(145deg, #7a4f3b, #5b3a2a); color: #fff;
        box-shadow: inset 0 0 0 1px #a85f36, 0 0 0 2px #e8e8e8, 0 0 0 4px #e69b45, 0 6px 12px rgba(0, 0, 0, 0.8), 0 0 15px rgba(205, 127, 50, 0.5);
        transform: translateY(-2px) scale(1.02); 
    }
    .back-btn-container button { 
        background: #5b3a2a; color: #f5f5dc; border: 1px solid #ffcc66; border-radius: 4px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5); transition: all 0.2s; 
    }
    .back-btn-container button:hover { 
        background: #7a4f3b; color: #fff; transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0, 0, 0, 0.6); 
    }
    .corner-btn { position: absolute; z-index: 50; min-width: 80px; }
    .top-left { top: 10px; left: 10px; }
    .top-right { top: 10px; right: 10px; }
    .bottom-right { bottom: 130px; right: 5px; } 
    .professor-list { 
        display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(15px, 4vw, 40px); width: 100%;
        max-width: 100%; flex: 1; overflow-y: auto; padding: 20px; 
    }
    .professor-container { display: flex; flex-direction: column; align-items: center; margin-bottom: 10px; }
    .professor-item { 
        width: clamp(120px, 15vw, 180px); height: clamp(120px, 15vw, 180px); border-radius: 50%;
        border: 3px solid #cc5500; overflow: hidden; cursor: pointer; transition: transform 0.3s, box-shadow 0.3s; background-color: #000;
        user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    .professor-item:hover { transform: scale(1.1); box-shadow: 0 0 25px rgba(204, 85, 0, 0.8); }
    .professor-item img { width: 100%; height: 100%; object-fit: cover; }
    .professor-name { margin-top: 10px; color: #ffcc66; font-size: clamp(0.9rem, 1.5vw, 1.2rem); font-weight: bold; text-align: center; }

    /* --- PUERTAS INVISIBLES Y SIN TEXTO --- */
    .professor-item.wood-texture {
        opacity: 0; pointer-events: none; border: none; box-shadow: none; background: none;
    }
    .professor-item.wood-texture img { display: none; }
    .professor-name.hidden-text { display: none; }

    /* --- ROOM LAYOUT --- */
    .room-layout { 
        display: flex; flex-direction: row; width: 100%; max-width: 100%; flex: 1; justify-content: flex-end; 
        align-items: flex-start; gap: 30px; padding: 20px 50px; overflow-y: hidden; height: 100%;
    }
    .room-left { flex: 1; display: none; }
    .room-right { 
        display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 12px; 
        width: auto; max-width: 160px; margin-right: 5%; margin-top: 50px;
    }
    .room-buttons { width: 100%; display: flex; flex-direction: column; gap: 12px; align-items: flex-end; }
    #inquisitorThemesList { 
        max-height: 75vh; overflow-y: auto; padding: 15px; background: rgba(0, 0, 0, 0.8);
        border: 2px solid #ffcc66; border-radius: 8px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.9); width: auto; min-width: 120px; max-width: 220px;
        display: flex; flex-direction: column; align-items: center; margin-right: 0; 
    }
    #inquisitorThemesList .theme-btn { width: fit-content !important; white-space: nowrap; }
    #inquisitorScreen .room-right { max-width: 250px; align-items: flex-end; margin-right: 0 !important; margin-top: 10px !important; justify-content: flex-start; }
    #inquisitorScreen .room-layout { padding-right: 5px !important; padding-top: 10px !important; }
    .theme-btn.has-notes { border-color: #00bcd4 !important; background: linear-gradient(180deg, #006064 0%, #00363a 100%) !important; box-shadow: 0 0 10px #00bcd4 !important; color: #e0f7fa !important; }
    .theme-btn.has-notes::after { content: " 📜"; margin-left: 5px; }
    .theme-btn { 
        padding: 10px; border: 2px solid #ffcc66; background: linear-gradient(180deg, #5b3a2a 0%, #2d1810 100%); color: #f4e4d7;
        font-family: 'Cinzel', serif; font-size: 0.85rem; font-weight: bold; cursor: pointer; border-radius: 8px; transition: all 0.3s; text-align: center;
        box-shadow: 0 4px 8px rgba(0,0,0,0.5); width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
        min-height: 50px; user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    .theme-btn:hover:not(.locked-btn) { background: linear-gradient(180deg, #7a4f3b 0%, #4a2c1a 100%); transform: scale(1.02); }
    .theme-btn.locked-btn { background: #1e0e0a; border-color: #444; color: #666; cursor: not-allowed; filter: grayscale(100%); }
    .theme-btn .req-score { font-size: 0.7rem; color: #e69b45; margin-top: 3px; font-weight: normal; }
    .back-btn-container { position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%); width: auto; z-index: 100; }
    
    /* FIX: CENTRADO PERFECTO DEL DIRECTOR MEDIANTE PRIORIDAD ESTRICTA */
    #directionScreen .room-layout { 
        display: flex !important; 
        justify-content: center !important; 
        align-items: center !important; 
        padding: 20px !important; 
        flex-direction: column !important; 
        width: 100% !important; 
        height: 100% !important;
    }
    #directionScreen .room-right { 
        max-width: 800px !important; 
        width: 100% !important; 
        align-items: center !important; 
        justify-content: center !important; 
        margin: 0 auto !important; 
        height: auto !important; 
        padding-top: 0 !important; 
    }
    #directionScreen .room-buttons { 
        align-items: center !important; 
        width: 100% !important; 
    }

    /* CHAT, RANKING, ETC */
    #chatScreen .game-content, #libraryScreen .game-content { 
        display: flex; flex-direction: column; height: 100%; padding: 10px; overflow: hidden; 
        width: 90%; max-width: 900px; box-sizing: border-box; 
    }
    #chatMessages, #libraryMessages { 
        flex: 1; overflow-y: auto; padding: 10px; background: rgba(0,0,0,0.3); border-radius: 8px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px;
    }
    
    .chat-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 8px; width: 100%; }
    .chat-row.mine { justify-content: flex-end; }
    .chat-row.theirs { justify-content: flex-start; }
    .chat-avatar { width: 35px; height: 35px; border-radius: 50%; border: 1px solid #ffcc66; object-fit: cover; flex-shrink: 0; background: #000; }
    .chat-row.mine .chat-avatar { order: 2; } 
    
    /* FASE 1: REDISEÑO DEL CHAT TIPO CÓMIC CON COLORES DINÁMICOS */
    .chat-msg {
        position: relative;
        padding: 12px 18px;
        border-radius: 12px;
        font-family: 'Crimson Text', serif;
        font-size: 1.1rem;
        line-height: 1.4;
        max-width: 75%;
        word-wrap: break-word;
        box-shadow: 2px 2px 8px rgba(0,0,0,0.6);
        color: #fff;
    }
    .chat-msg.mine {
        background: var(--chat-bg, #333);
        border: 2px solid var(--chat-border, #ffcc66);
        border-bottom-right-radius: 0;
    }
    .chat-msg.theirs {
        background: var(--chat-bg, #1a1a1a); 
        border: 2px solid var(--chat-border, #00bcd4); 
        border-bottom-left-radius: 0;
    }
    
    .chat-msg::before, .chat-msg::after { content: ''; position: absolute; border-style: solid; }
    
    .chat-msg.mine::after { bottom: -2px; right: -12px; border-width: 12px 0 0 12px; border-color: var(--chat-border, #ffcc66) transparent transparent transparent; }
    .chat-msg.mine::before { bottom: 0; right: -8px; border-width: 10px 0 0 10px; border-color: var(--chat-bg, #333) transparent transparent transparent; z-index: 1; }
    
    .chat-msg.theirs::after { bottom: -2px; left: -12px; border-width: 12px 12px 0 0; border-color: var(--chat-border, #00bcd4) transparent transparent transparent; }
    .chat-msg.theirs::before { bottom: 0; left: -8px; border-width: 10px 10px 0 0; border-color: var(--chat-bg, #1a1a1a) transparent transparent transparent; z-index: 1; }
    
    .chat-user { font-family: 'Cinzel', serif; font-size: 0.75rem; color: var(--chat-border, #a85f36); margin-bottom: 4px; display: block; font-weight: bold; text-transform: uppercase; border-bottom: 1px solid rgba(255, 255, 255, 0.2); padding-bottom: 2px; }
    
    .chat-input-area { display: flex; gap: 10px; }
    #chatInput, #libraryInput { flex: 1; padding: 10px; background: rgba(0,0,0,0.7); border: 1px solid #a85f36; color: white; border-radius: 4px; }
    #sendChatBtn, #sendLibraryBtn { width: auto; padding: 10px 20px; }
    
    #rankingList { display: flex; flex-direction: column; gap: 5px; }
    
    /* --- REDISEÑO GRID RANKING: 6 COLUMNAS --- */
    /* --- REDISEÑO GRID RANKING: 6 COLUMNAS CON LETRERO DE RANGO --- */
    .ranking-header { 
        display: grid; grid-template-columns: 42px 35px 2fr 1.6fr 1.2fr 1fr; gap: 10px; padding: 10px 12px;
        border-bottom: 2px solid #ffcc66; font-weight: bold; color: #ffcc66; margin-bottom: 10px; text-transform: uppercase; font-size: 0.88rem;
    }
    .ranking-item { 
        display: grid; grid-template-columns: 42px 35px 2fr 1.6fr 1.2fr 1fr; gap: 10px; padding: 10px 12px;
        background: rgba(0,0,0,0.4); border-radius: 6px; align-items: center; border-bottom: 1px solid #5b3a2a; 
        transition: background 0.2s;
    }
    .ranking-item:hover { background: rgba(255, 204, 102, 0.08); }
    .ranking-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 1.5px solid #ffcc66; display: block; }
    .ranking-item:nth-child(even) { background: rgba(255,255,255,0.03); }
    .ranking-item.self { border: 1.5px solid #ffcc66; background: rgba(255, 204, 102, 0.12); box-shadow: 0 0 10px rgba(255, 204, 102, 0.2); }
    .rank-pos { font-weight: bold; color: #aaa; text-align: center; }
    .rank-1 .rank-pos { color: #ffd700; text-shadow: 0 0 10px #ffd700; font-size: 1.25rem; }
    .rank-2 .rank-pos { color: #e0e0e0; text-shadow: 0 0 8px #ffffff; font-size: 1.15rem; }
    .rank-3 .rank-pos { color: #cd7f32; text-shadow: 0 0 8px #cd7f32; font-size: 1.15rem; }

    /* --- LETREROS DE RANGO ESTILO AVATAR MIRROR PARA EL RANKING --- */
    .ranking-rank-badge {
        display: inline-block;
        font-family: 'Cinzel', serif;
        font-size: 0.65rem;
        font-weight: bold;
        padding: 2px 8px;
        border-radius: 10px;
        white-space: nowrap;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        text-align: center;
        box-shadow: 0 2px 5px rgba(0,0,0,0.8);
        user-select: none;
        box-sizing: border-box;
    }

    /* 1º PUESTO: ORO PURO Y RESPLANDOR CELESTIAL */
    .rank-badge-gold {
        background: linear-gradient(180deg, #ffe082 0%, #ffd700 40%, #ffb300 70%, #b78103 100%);
        border: 1px solid #fff9c4;
        color: #1a0c00 !important;
        font-weight: 800;
        text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
        box-shadow: 0 0 12px rgba(255, 215, 0, 0.75), 0 2px 5px rgba(0, 0, 0, 0.8);
    }

    /* 2º PUESTO: PLATA BRUGIDA */
    .rank-badge-silver {
        background: linear-gradient(180deg, #ffffff 0%, #eeeeee 35%, #e0e0e0 70%, #9e9e9e 100%);
        border: 1px solid #ffffff;
        color: #1a1a1a !important;
        font-weight: 800;
        text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
        box-shadow: 0 0 10px rgba(238, 238, 238, 0.65), 0 2px 5px rgba(0, 0, 0, 0.8);
    }

    /* 3º PUESTO: BRONCE NOBLE */
    .rank-badge-bronze {
        background: linear-gradient(180deg, #ffcc80 0%, #f0a36b 35%, #cd7f32 70%, #794017 100%);
        border: 1px solid #ffe0b2;
        color: #ffffff !important;
        font-weight: 800;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
        box-shadow: 0 0 10px rgba(205, 127, 50, 0.65), 0 2px 5px rgba(0, 0, 0, 0.8);
    }

    /* 4º PUESTO EN ADELANTE: HOJALATA / HIERRO ARCANO FORJADO */
    .rank-badge-tin {
        background: linear-gradient(180deg, #90a4ae 0%, #607d8b 45%, #455a64 80%, #263238 100%);
        border: 1px solid #b0bec5;
        color: #f5f5f5 !important;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
        box-shadow: 0 1px 5px rgba(0, 0, 0, 0.7);
    }

    /* GRAN CANCILLER / SUPERVISIÓN ADMIN: AMATISTA IMPERIAL Y ORO */
    .rank-badge-canciller {
        background: linear-gradient(180deg, #ab47bc 0%, #7b1fa2 40%, #4a148c 80%, #1e053a 100%);
        border: 1.5px solid #ffd700;
        color: #ffd700 !important;
        font-weight: 800;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
        box-shadow: 0 0 14px rgba(186, 104, 200, 0.8), 0 2px 5px rgba(0, 0, 0, 0.8);
    }
    
    /* TEST SCREEN */
    #gameScreen .game-content { 
        background: transparent !important; border: none !important; box-shadow: none !important; background-image: none !important; padding: 10px 20px; color: #f4e4d7; display: flex; flex-direction: column;
        height: calc(100% - 60px); overflow-y: auto; justify-content: flex-start; border-bottom: 2px solid #a85f36 !important; margin-bottom: 0;
    }
    #questionContainer { display: flex; flex-direction: column; min-height: 100%; width: 100%; justify-content: flex-start; align-items: center; padding-bottom: 20px;}
    #gameScreen #questionText { 
        color: #2d1b12; text-shadow: none; font-family: 'Crimson Text', serif; font-weight: bold; font-size: 1.3rem;
        margin-bottom: 20px; text-align: center; background-color: rgba(255, 224, 178, 0.8); border: 2px solid #e65100; border-radius: 8px; padding: 15px 30px; width: fit-content;
        max-width: 80%; max-height: 40%; overflow-y: auto; margin-left: auto; margin-right: auto; box-shadow: 0 4px 10px rgba(0,0,0,0.15); flex-shrink: 0;
    }
    #gameScreen #qNumberDisplay { color: #ffcc66; text-shadow: 0 1px 2px rgba(0,0,0,0.8); font-weight: bold; width: 100%; text-align: right; margin-bottom: 10px; }
    #options { width: 100%; display: flex; flex-direction: column; flex: 1; justify-content: center; gap: 12px; max-width: 800px; margin: 0 auto; padding-bottom: 10px; }
    #gameScreen .option-btn { 
        background: rgba(255, 253, 208, 0.9); border: 1px solid #8d6e63; border-radius: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.5); color: #3e2723; font-family: 'Crimson Text', serif; font-size: 1.1rem;
        font-weight: bold; padding: 15px 20px; text-align: left; transition: all 0.2s; text-shadow: none; width: 100%; cursor: pointer; display: flex; align-items: center;
        margin-bottom: 0; white-space: normal !important; height: auto !important; min-height: 60px; line-height: 1.2;
        user-select: none; -webkit-user-select: none; touch-action: manipulation;
    }
    #gameScreen .option-btn:hover { background: #fff9c4; transform: translateX(5px); border-color: #5d4037; }
    #gameScreen .option-btn.selected { background: #fff59d !important; border: 2px solid #5d4037; color: #000; transform: translateX(5px); }
    #gameScreen .option-btn.selected::before { content: "✒️ "; margin-right: 10px; }
    #gameScreen .option-btn.correct, #reviewScreen .option-btn.correct { background: #c8e6c9 !important; border: 2px solid #2e7d32 !important; color: #1b5e20 !important; }
    #gameScreen .option-btn.correct::before, #reviewScreen .option-btn.correct::before { content: "✅ "; margin-right: 10px; }
    #gameScreen .option-btn.incorrect, #reviewScreen .option-btn.incorrect { background: #ffcdd2 !important; border: 2px solid #c62828 !important; color: #b71c1c !important; text-decoration: line-through; }
    #gameScreen .option-btn.incorrect::before, #reviewScreen .option-btn.incorrect::before { content: "❌ "; margin-right: 10px; }
    #gameScreen .option-btn:disabled, #reviewScreen .option-btn:disabled { filter: none; opacity: 1; cursor: default; color: #3e2723; }
    #gameScreen .option-btn.correct:disabled, #reviewScreen .option-btn.correct:disabled { background: #c8e6c9 !important; border-color: #2e7d32 !important; color: #1b5e20 !important; }
    #gameScreen .option-btn.incorrect:disabled, #reviewScreen .option-btn.incorrect:disabled { background: #ffcdd2 !important; border-color: #c62828 !important; color: #b71c1c !important; }

    /* ESTILO OSCURO PARA RESULTADOS */
    .result-content {
        background: linear-gradient(180deg, #1a1a1a 0%, #0d0d0d 100%);
        border: 2px solid #ffcc66; border-radius: 12px; padding: 30px; width: 90%; max-width: 500px; text-align: center;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.9); display: flex; flex-direction: column; align-items: center; gap: 15px;
    }
    .result-content h3 { color: #ffcc66; font-size: 2rem; margin: 0; text-transform: uppercase; border-bottom: 1px solid #a85f36; width: 100%; padding-bottom: 10px; }
    .result-content p { color: #e0e0e0; font-size: 1.4rem; font-family: 'Crimson Text', serif; margin: 0; }
    #professorFeedbackContainer { 
        width: 100%; background: rgba(255, 255, 255, 0.05); padding: 15px; border-radius: 8px; border-left: 4px solid #ffcc66; text-align: left; font-size: 1.3rem;
    }
    
    /* DEV BOX VISIBLE */
    #developerBox { 
        position: absolute; top: 50px; left: 10px; background: rgba(50, 0, 0, 0.9); border: 2px dashed red; padding: 10px; border-radius: 8px; z-index: 9999;
        display: flex; flex-direction: column; gap: 5px;
    }

    /* BOTÓN CAMPANITA DE CRISPÍN */
    #guideBellBtn {
        position: absolute; top: 60px; left: 10px; width: 48px; height: 48px; border-radius: 50%;
        background: radial-gradient(circle, #4e342e 30%, #1a0f0a 100%); border: 2px solid #ffd700; color: #ffd700; font-size: 1.55rem; cursor: pointer;
        z-index: 900; display: none; justify-content: center; align-items: center; box-shadow: 0 4px 12px rgba(0,0,0,0.8), 0 0 10px rgba(255,215,0,0.4); transition: transform 0.2s, box-shadow 0.2s; text-shadow: 0 0 8px #ffb74d;
        animation: bellPulseGlow 3s infinite ease-in-out;
    }
    @keyframes bellPulseGlow {
        0%, 100% { box-shadow: 0 4px 12px rgba(0,0,0,0.8), 0 0 8px rgba(255,215,0,0.3); transform: scale(1); }
        50% { box-shadow: 0 4px 18px rgba(255,215,0,0.7), 0 0 20px rgba(255,215,0,0.6); transform: scale(1.08) rotate(5deg); }
    }
    #guideBellBtn:hover { transform: scale(1.1) rotate(15deg); box-shadow: 0 0 15px rgba(255, 204, 102, 0.4); }
    #guideBellBtn:active { transform: scale(0.9); }

    @media (max-width: 1024px) { 
        body { background: #000; display: block; overflow: visible; } 
        #game-stage { max-width: 100%; height: 100vh; max-height: none; aspect-ratio: unset; border: none; box-shadow: none; border-radius: 0; background-repeat: no-repeat; background-position: center; } 
        #options { width: 95%; } 
    }
    
    @media (max-width: 768px) { 
        h2 { font-size: 1.4rem; padding: 0 10px; margin: 15px 0; } .container { padding: 0; } .corner-btn { padding: 6px 10px; font-size: 0.7rem; } 
        .top-left { toppadding: 5px; left: 5px; } .top-right { top: 5px; right: 5px; } .bottom-right { bottom: 130px; right: 5px; } 
        .menu-header { padding: 5px; gap: 8px; justify-content: center; display: flex; flex-wrap: wrap; } 
        .menu-header button { flex: 0 0 auto; width: auto; font-size: 0.75rem; padding: 8px 12px; } 
        .user-stats-text { font-size: 0.8rem; flex-direction: column; gap: 2px; } 
        #insignia-menu { display: block !important; width: 40px !important; height: 40px !important; margin-right: 5px; } 
        #gameScreen .game-content { display: block; position: relative; height: 100vh; width: 100%; margin: 0; margin-top: 50px; padding: 10px 15px !important; padding-bottom: 160px !important; border: none !important; overflow-y: auto; box-sizing: border-box; } 
        #questionContainer { display: flex; flex-direction: column; gap: 15px; width: 100%; justify-content: flex-start; min-height: auto; } 
        #gameScreen #questionText { font-size: 1.1rem; margin-bottom: 10px; padding: 15px; width: 100%; max-width: 100%; } 
        #options { width: 100%; display: flex; flex-direction: column; gap: 12px; flex: 0 0 auto !important; height: auto !important; justify-content: flex-start !important; } 
        #gameScreen .option-btn { width: 100%; font-size: 1rem; padding: 15px 15px; height: auto !important; min-height: 60px; flex: none; margin-bottom: 0; white-space: normal !important; line-height: 1.3; text-align: left; } 
        .test-controls { position: fixed !important; bottom: 0 !important; left: 0 !important; width: 100% !important; height: auto !important; min-height: 100px; padding: 10px 10px 20px 10px; gap: 8px; background: #000; border-top: 2px solid #a85f36; z-index: 9999; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; box-shadow: 0 -5px 20px rgba(0,0,0,0.9); } 
        .small-btn { font-size: 0.85rem; padding: 5px 5px; height: 45px; flex: 1 1 48%; max-width: 49%; margin-bottom: 5px; display: flex; align-items: center; justify-content: center; } 
        #gameThemeTitle { position: absolute; top: 5px; left: 0; width: 100%; text-align: center; font-size: 1.1rem; z-index: 10; pointer-events: none; } 
        #testScoreDisplay { position: absolute; top: 30px; width: 100%; text-align: center; font-size: 0.8rem; } 
    }
    
    @media (max-width: 480px) { 
        #mainGame h2 { padding: 0 5px; margin-top: 40px; font-size: 1.3rem; } 
        .ranking-header, .ranking-item { grid-template-columns: 36px 30px 1.8fr 1.6fr 1fr; gap: 6px; padding: 8px 6px; font-size: 0.75rem; }
        .ranking-header span:nth-child(5), .ranking-item span:nth-child(5) { display: none; }
        .modal-box { width: 95%; padding: 15px; } .modal-buttons { flex-direction: column; gap: 10px; } .modal-btn { width: 100%; } 
    }
    #btnIndexCronicas:hover, #btnIndexGrimorio:hover { color: #b71c1c !important; transform: scale(1.1); text-shadow: 0 0 10px rgba(183, 28, 28, 0.5) !important; }

    /* --- VIDEO INTRO OVERLAY --- */
    #video-overlay { 
        position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: #000; z-index: 11000;
        display: none; justify-content: center; align-items: center; flex-direction: column;
    }

    #intro-video { 
        width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity 0.5s ease-in;
    }
    #intro-video.se-mueve { opacity: 1; }

    #skip-video-btn {
        position: absolute; bottom: 30px; right: 30px; z-index: 11001; background: rgba(0, 0, 0, 0.5); border: 1px solid #ffcc66; color: #ffcc66;
        padding: 10px 20px; cursor: pointer; font-family: 'Cinzel', serif; border-radius: 4px; transition: all 0.3s;
    }
    #skip-video-btn:hover { background: #ffcc66; color: #000; }

    /* --- NUEVOS ESTILOS PERFIL --- */
    #profileScreen { overflow-y: auto !important; padding-bottom: 45px !important; box-sizing: border-box; }
    .profile-layout { display: flex; width: 100%; height: auto; min-height: calc(100% - 100px); gap: 20px; padding: 10px; box-sizing: border-box; }
    .profile-col { background: rgba(0,0,0,0.6); border: 1px solid #5b3a2a; border-radius: 8px; padding: 20px; display: flex; flex-direction: column; gap: 20px; backdrop-filter: blur(5px); }
    .col-left { width: 25%; min-width: 200px; align-items: center; text-align: center; }
    .col-center { flex: 1; }
    .col-right { width: 25%; min-width: 200px; }

    /* Avatar */
    .avatar-container { position: relative; width: 150px; height: 150px; cursor: pointer; transition: transform 0.3s; }
    .avatar-container:hover { transform: scale(1.05); }
    .avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 4px solid #ffcc66; box-shadow: 0 0 20px rgba(255, 204, 102, 0.3); background: #000; }
    .avatar-edit-icon { position: absolute; bottom: 5px; right: 5px; background: #5b3a2a; color: #fff; border-radius: 50%; width: 35px; height: 35px; display: flex; align-items: center; justify-content: center; border: 2px solid #ffcc66; font-size: 1.2rem; }
    
    /* Stats Cards */
    .stats-row { display: flex; gap: 15px; margin-bottom: 20px; }
    .stat-card { flex: 1; background: linear-gradient(145deg, #2d1b12, #1a0f0a); padding: 15px; border-radius: 8px; text-align: center; border: 1px solid #8d6e63; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
    .stat-val { display: block; font-size: 1.8rem; color: #ffcc66; font-weight: bold; margin-bottom: 5px; text-shadow: 0 0 5px #ffcc66; }
    .stat-lbl { font-size: 0.8rem; color: #aaa; text-transform: uppercase; letter-spacing: 1px; }

    /* Medallas Mejoradas */
    .medals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 15px; margin-top: 20px; }
    .medal { aspect-ratio: 1/1; border-radius: 50%; background: #111; border: 2px solid #333; position: relative; display: flex; align-items: center; justify-content: center; opacity: 0.5; filter: grayscale(100%); transition: all 0.3s; cursor: help; }
    .medal img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
    
    /* Tiers de Medallas */
    .medal.unlocked { opacity: 1; filter: grayscale(0%); }
    .medal.bronze { border-color: #cd7f32; box-shadow: 0 0 15px rgba(205, 127, 50, 0.4); }
    .medal.silver { border-color: #c0c0c0; box-shadow: 0 0 20px rgba(192, 192, 192, 0.6); }
    .medal.gold { border-color: #ffd700; box-shadow: 0 0 25px rgba(255, 215, 0, 0.8), inset 0 0 10px rgba(255, 215, 0, 0.5); animation: golden-glow-pulse 3s infinite; }

    /* Settings */
    .setting-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: rgba(255,255,255,0.05); margin-bottom: 10px; border-radius: 6px; }
    .danger-zone { margin-top: auto; border-top: 1px solid #b71c1c; padding-top: 20px; }
    .danger-btn { width: 100%; background: #5a0000; color: #ff9999; border: 1px solid #b71c1c; padding: 10px; cursor: pointer; border-radius: 4px; font-weight: bold; transition: all 0.2s; }
    .danger-btn:hover { background: #8a0000; color: #fff; }

    /* Switch */
    .switch { position: relative; display: inline-block; width: 50px; height: 24px; }
    .switch input { opacity: 0; width: 0; height: 0; }
    .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #3e2723; transition: .4s; border-radius: 24px; border: 1px solid #5b3a2a; }
    .slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 3px; background-color: #aaa; transition: .4s; border-radius: 50%; }
    input:checked + .slider { background-color: #ffcc66; }
    input:checked + .slider:before { transform: translateX(26px); background-color: #fff; }

    /* Modal Avatar Inicial */
    .avatar-selection-grid { display: flex; gap: 15px; justify-content: center; margin: 20px 0; }
    .premade-avatar { width: 70px; height: 70px; border-radius: 50%; border: 2px solid #555; cursor: pointer; transition: transform 0.2s; }
    .premade-avatar:hover { transform: scale(1.1); border-color: #ffcc66; }
    .premade-avatar.selected { border-color: #00bcd4; box-shadow: 0 0 15px #00bcd4; transform: scale(1.1); }

    /* =========================================================================
       🔮 EL ESPEJO DE LAS ALMAS — SELECTOR Y FORJA DE AVATARES
       ========================================================================= */
    .avatar-mirror-container {
        display: flex;
        flex-direction: column;
        gap: 12px;
        max-width: 580px;
        margin: 0 auto;
    }
    
    .avatar-mirror-header {
        display: flex;
        align-items: center;
        gap: 16px;
        background: rgba(26, 15, 10, 0.75);
        border: 1px solid #8d6e63;
        border-radius: 10px;
        padding: 12px 16px;
        box-shadow: inset 0 0 15px rgba(0,0,0,0.6);
    }
    
    .avatar-mirror-preview-wrap {
        position: relative;
        width: 84px;
        height: 84px;
        flex-shrink: 0;
    }
    
    .avatar-mirror-preview-img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        object-fit: cover;
        border: 3px solid #ffcc66;
        box-shadow: 0 0 20px rgba(255, 204, 102, 0.4);
        background: #000;
        transition: transform 0.2s, box-shadow 0.2s;
    }
    
    .avatar-mirror-rank-badge {
        position: absolute;
        bottom: -4px;
        left: 50%;
        transform: translateX(-50%);
        background: linear-gradient(180deg, #d4a017, #795548);
        border: 1px solid #ffe082;
        color: #000;
        font-size: 0.65rem;
        font-weight: bold;
        padding: 1px 6px;
        border-radius: 10px;
        white-space: nowrap;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }
    
    .avatar-mirror-info {
        flex: 1;
        text-align: left;
    }
    
    .avatar-mirror-title {
        color: #ffcc66;
        font-family: 'Cinzel', serif;
        font-size: 1.1rem;
        margin: 0 0 4px 0;
        text-shadow: 0 0 8px rgba(255, 204, 102, 0.4);
    }
    
    .avatar-mirror-subtitle {
        color: #d7ccc8;
        font-size: 0.85rem;
        margin: 0;
        line-height: 1.3;
    }
    
    .avatar-filter-bar {
        display: flex;
        gap: 6px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .avatar-filter-chip {
        background: #1a0f0a;
        border: 1px solid #5b3a2a;
        color: #d7ccc8;
        padding: 6px 12px;
        border-radius: 20px;
        font-size: 0.82rem;
        cursor: pointer;
        transition: all 0.2s;
        display: inline-flex;
        align-items: center;
        gap: 4px;
    }
    
    .avatar-filter-chip:hover {
        background: #3e2723;
        border-color: #ffcc66;
        color: #fff;
        transform: translateY(-1px);
    }
    
    .avatar-filter-chip.active {
        background: linear-gradient(180deg, #5b3a2a, #2d1b12);
        border-color: #ffcc66;
        color: #ffcc66;
        font-weight: bold;
        box-shadow: 0 0 10px rgba(255, 204, 102, 0.3);
    }
    
    .avatar-mosaic-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
        gap: 10px;
        max-height: 250px;
        overflow-y: auto;
        padding: 10px;
        background: rgba(10, 5, 2, 0.75);
        border: 1px solid #4a2c1b;
        border-radius: 8px;
        box-shadow: inset 0 0 20px rgba(0,0,0,0.8);
    }
    
    .avatar-mosaic-item {
        position: relative;
        aspect-ratio: 1 / 1;
        border-radius: 50%;
        border: 2px solid #5b3a2a;
        overflow: hidden;
        cursor: pointer;
        transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        background: #000;
    }
    
    .avatar-mosaic-item img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
        transition: transform 0.25s;
    }
    
    .avatar-mosaic-item:hover {
        border-color: #ffcc66;
        transform: scale(1.12);
        box-shadow: 0 0 15px rgba(255, 204, 102, 0.5);
        z-index: 2;
    }
    
    .avatar-mosaic-item:hover img {
        transform: scale(1.08);
    }
    
    .avatar-mosaic-item.selected {
        border-color: #00e5ff !important;
        box-shadow: 0 0 20px #00e5ff, inset 0 0 10px rgba(0, 229, 255, 0.4) !important;
        transform: scale(1.15) !important;
        z-index: 3;
    }
    
    .avatar-mosaic-item.selected::after {
        content: "✓";
        position: absolute;
        bottom: 2px;
        right: 2px;
        background: #00e5ff;
        color: #000;
        width: 18px;
        height: 18px;
        border-radius: 50%;
        font-size: 0.7rem;
        font-weight: bold;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 4px rgba(0,0,0,0.8);
    }

    @media (max-width: 900px) { .profile-layout { flex-direction: column; } .col-left, .col-right { width: 100%; } .col-center { overflow: visible; } }

    /* --- PANTALLA DE REPASAR FALLOS --- */
    #failedQuestionsScreen {
        padding: 20px 20px 0 20px !important;
        box-sizing: border-box !important;
    }
    #failedQuestionsList {
        width: 100%;
        max-width: 650px;
        flex: 1;
        overflow-y: auto;
        margin-top: 15px;
        margin-bottom: 90px; /* Margen inferior para no solapar con el botón de Volver */
        padding: 15px;
        box-sizing: border-box;
        background: rgba(0, 0, 0, 0.45);
        border: 1px solid #5d4037;
        border-radius: 8px;
        box-shadow: inset 0 0 15px rgba(0,0,0,0.6);
    }

    /* ANIMACIÓN NOTIFICACIÓN CHAT */
    @keyframes golden-pulse-soft {
        0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.4); border-color: #ffcc66; transform: scale(1); }
        50% { box-shadow: 0 0 20px 10px rgba(255, 215, 0, 0.2); border-color: #ffeeb0; transform: scale(1.02); }
        100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); border-color: #ffcc66; transform: scale(1); }
    }

    .notification-glow {
        animation: golden-pulse-soft 2s infinite !important; border-color: #ffd700 !important; color: #ffd700 !important;
        text-shadow: 0 0 8px rgba(255, 215, 0, 0.8); background: linear-gradient(180deg, #5b3a2a 0%, #3e2723 100%);
        position: relative; z-index: 100;
    }
    
    .notification-glow::after {
        content: "!"; position: absolute; top: -5px; right: -5px; background: #ffd700; color: #000; width: 20px; height: 20px;
        border-radius: 50%; font-size: 0.8rem; display: flex; align-items: center; justify-content: center; font-weight: bold; box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    }

    #chatScreen .back-btn-container { bottom: auto; left: auto; transform: none; top: 10px; right: 10px; }
    #chatScreen .back-btn-container button { width: auto; padding: 8px 15px; font-size: 0.8rem; }

/* --- EL CÓDICE: MULTICAPA Y THEMES GRID --- */
.codice-prof-img { 
    position: absolute; 
    width: clamp(150px, 25vw, 300px); 
    height: auto; 
    filter: drop-shadow(0 0 15px rgba(0,0,0,0.8)); 
    z-index: 5; 
    pointer-events: none;
}
.codice-bubble { 
    position: absolute; 
    background: #fff; 
    color: #000; 
    padding: 15px 20px; 
    border-radius: 15px; 
    font-family: 'Comic Sans MS', cursive, sans-serif; 
    font-size: 1.1rem; 
    line-height: 1.4; 
    box-shadow: 2px 2px 10px rgba(0,0,0,0.8); 
    z-index: 10; 
    pointer-events: auto; 
    max-width: 400px;
    border: 2px solid #333;
}
.codice-bubble::before, .codice-bubble::after { 
    content: ''; 
    position: absolute; 
    border-style: solid; 
}

/* Colas del Bocadillo (Configurables) */
.tail-bottom-left { border-bottom-left-radius: 0; }
.tail-bottom-left::after { bottom: -15px; left: 15px; border-width: 15px 15px 0 0; border-color: #333 transparent transparent transparent; }
.tail-bottom-left::before { bottom: -10px; left: 17px; border-width: 10px 10px 0 0; border-color: #fff transparent transparent transparent; z-index: 11; }

.tail-bottom-right { border-bottom-right-radius: 0; }
.tail-bottom-right::after { bottom: -15px; right: 15px; border-width: 15px 0 0 15px; border-color: #333 transparent transparent transparent; }
.tail-bottom-right::before { bottom: -10px; right: 17px; border-width: 10px 0 0 10px; border-color: #fff transparent transparent transparent; z-index: 11; }

.tail-top-left { border-top-left-radius: 0; }
.tail-top-left::after { top: -15px; left: 15px; border-width: 0 15px 15px 0; border-color: transparent transparent #333 transparent; }
.tail-top-left::before { top: -10px; left: 17px; border-width: 0 10px 10px 0; border-color: transparent transparent #fff transparent; z-index: 11; }

.tail-top-right { border-top-right-radius: 0; }
.tail-top-right::after { top: -15px; right: 15px; border-width: 0 0 15px 15px; border-color: transparent transparent #333 transparent; }
.tail-top-right::before { top: -10px; right: 17px; border-width: 0 0 10px 10px; border-color: transparent transparent #fff transparent; z-index: 11; }

/* Botón Continuar Diálogo */
.codice-next-btn {
    position: absolute;
    bottom: -15px;
    right: -15px;
    background: #ffcc66;
    color: #000;
    border: 2px solid #fff;
    border-radius: 50%;
    width: 35px; height: 35px;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(255,204,102,1);
    animation: pulse-next 1.5s infinite;
    z-index: 12;
    display: flex; justify-content: center; align-items: center;
    user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
@keyframes pulse-next { 
    0%, 100% { transform: scale(1); } 
    50% { transform: scale(1.15); box-shadow: 0 0 25px rgba(255,204,102,1); } 
}

/* Botón Especial de Volver en el Códice */
#codiceScreen .back-btn-container {
    left: 20px;
    bottom: 20px;
    transform: none;
    width: auto;
}
#backFromCodiceBtn {
    background: rgba(0, 20, 20, 0.9);
    border: 2px solid #00bcd4;
    color: #00bcd4;
    box-shadow: 0 0 15px rgba(0,188,212,0.4);
    font-family: 'Cinzel', serif;
}
#backFromCodiceBtn:hover {
    background: #00bcd4;
    color: #000;
    box-shadow: 0 0 25px rgba(0,188,212,0.8);
}

/* Botón Especial de Volver en el Sanctum */
#sanctumScreen .back-btn-container {
    left: 20px;
    bottom: 20px;
    transform: none;
    width: auto;
}

.codice-themes-grid { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 15px; 
    justify-content: center; 
    margin-top: 20px;
    width: 100%;
    max-height: 50vh; 
    overflow-y: auto; 
    padding-right: 10px;
    align-content: flex-start;
}
.codice-theme-btn { 
    background: rgba(0, 0, 0, 0.6); 
    border: 2px solid #00bcd4; 
    color: #fff; 
    padding: 12px 25px; 
    border-radius: 8px; 
    cursor: pointer; 
    transition: all 0.3s; 
    font-family: 'Cinzel', serif; 
    font-size: 1.1rem; 
    font-weight: bold;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.codice-theme-btn:hover { 
    background: rgba(0, 188, 212, 0.4); 
    transform: scale(1.05); 
    box-shadow: 0 0 15px #00bcd4; 
}
.codice-theme-btn.selected { 
    background: #00bcd4; 
    color: #000; 
    box-shadow: 0 0 20px #00bcd4; 
    transform: scale(1.1);
}

/* FIX CENTRADO PERFECTO */
.codice-ui-layer { 
    width: 100%; 
    height: 100%; 
    display: flex; 
    flex-direction: row; 
    align-items: center; 
    justify-content: center; 
    pointer-events: auto; 
    z-index: 5; 
    gap: 30px; 
    box-sizing: border-box; 
}
.codice-answers-grid {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    box-sizing: border-box;
}
.codice-board { 
    width: 60%; 
    max-width: 800px; 
    background: rgba(0,0,0,0.8); 
    border: 2px solid #00bcd4; 
    border-radius: 12px; 
    padding: 40px; 
    box-shadow: 0 0 30px rgba(0, 188, 212, 0.3); 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    justify-content: center;
    backdrop-filter: blur(5px); 
    z-index: 3; 
    position: relative; 
    margin: auto;
}
.codice-question { font-family:'Cinzel', serif; font-size:1.5rem; color:#ffcc66; text-align:center; margin-bottom:30px; text-shadow:0 0 10px rgba(255,204,102,0.5);}
.codice-btn { background:linear-gradient(180deg, #004d40 0%, #00251a 100%); border:2px solid #00bcd4; color:#e0f7fa; padding:15px 20px; width:100%; border-radius:8px; font-family:'Crimson Text', serif; font-size:1.2rem; font-weight:bold; cursor:pointer; margin-bottom:15px; transition:all 0.3s; box-shadow:0 5px 15px rgba(0,188,212,0.4); display:flex; align-items:center; justify-content:center; white-space:normal; min-height: 80px; user-select: none; -webkit-user-select: none; touch-action: manipulation;}
.codice-btn:hover { background:linear-gradient(180deg, #00838f 0%, #004d40 100%); transform:translateY(-3px) scale(1.02); box-shadow:0 8px 25px rgba(0,188,212,0.6);}
.codice-btn:active { transform:translateY(2px); box-shadow:0 2px 10px rgba(0,188,212,0.4);}
.codice-btn.correct { background:linear-gradient(180deg, #2e7d32 0%, #1b5e20 100%); border-color:#69f0ae; color:#fff; box-shadow:0 0 20px rgba(105,240,174,0.6); pointer-events:none;}
.codice-btn.incorrect { background:linear-gradient(180deg, #c62828 0%, #b71c1c 100%); border-color:#ff5252; color:#fff; box-shadow:0 0 20px rgba(255,82,82,0.6); pointer-events:none;}

/* --- BARRA PROGRESO CÓDICE LUMINOSA --- */
.codice-progress-container {
    position: absolute; 
    left: 30px; 
    top: 50%; 
    transform: translateY(-50%);
    display: flex; 
    flex-direction: column-reverse;
    gap: 8px; 
    padding: 15px; 
    background: rgba(0,0,0,0.7);
    border: 2px solid #a85f36; 
    border-radius: 12px; 
    z-index: 20;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
}
.codice-square {
    width: 30px; 
    height: 30px; 
    background: #1a1a1a;
    border: 2px solid #444; 
    border-radius: 4px; 
    transition: all 0.3s ease;
}
.codice-square.active {
    background: #ffcc66; 
    border-color: #fff;
    box-shadow: 0 0 15px #ffcc66, inset 0 0 10px #fff;
}
.codice-progress-glow {
    position: absolute; 
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 12px; 
    box-shadow: 0 0 30px rgba(255, 204, 102, 0);
    pointer-events: none; 
    transition: all 0.5s;
}
.codice-progress-container.pulsing .codice-progress-glow {
    animation: golden-glow-pulse 2s infinite;
}

/* --- ANIMACIÓN ATRIL SANCTUM --- */
@keyframes arcane-blue-pulse {
    0%, 100% { filter: drop-shadow(0 0 15px rgba(0, 188, 212, 0.4)) brightness(1); }
    50% { filter: drop-shadow(0 0 40px rgba(0, 188, 212, 1)) brightness(1.2); }
}
.atril-pulsing {
    animation: arcane-blue-pulse 4s infinite ease-in-out !important;
}

/* --- DIARIO DE ERUDITO (SANCTUM) --- */
.diario-container {
    display: flex;
    width: 100%;
    height: 100%;
    padding: 5% 8%;
    gap: 8%;
    box-sizing: border-box;
}
.diario-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    color: #3e2723;
    font-family: 'Crimson Text', serif;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
}
.diario-page h3 {
    font-family: 'Cinzel', serif;
    color: #5b3a2a;
    text-align: center;
    border-bottom: 2px solid #8d6e63;
    padding-bottom: 10px;
    margin-top: 0;
}
.diario-page::-webkit-scrollbar { width: 4px; }
.diario-page::-webkit-scrollbar-track { background: transparent; }
.diario-page::-webkit-scrollbar-thumb { background: #8d6e63; border-radius: 4px; }

.diario-avatar-box {
    width: 120px;
    height: 120px;
    margin: 0 auto 15px auto;
    border-radius: 50%;
    border: 4px solid #8d6e63;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    overflow: hidden;
}
.diario-avatar-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.diario-stat {
    display: flex;
    justify-content: space-between;
    background: rgba(141, 110, 99, 0.1);
    padding: 8px 15px;
    margin-bottom: 8px;
    border-radius: 4px;
    border: 1px dashed #8d6e63;
    font-weight: bold;
}
.diario-logro {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    background: rgba(255,255,255,0.5);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #bcaaa4;
}
.diario-logro-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

/* =====================================================
   LIBRO DEL ATRIL — Estilos del Expediente Arcano 
   ===================================================== */

.libro-doble-pagina {
    position: relative;
    width: 100%;
    height: 100%;
    font-size: calc(1rem * var(--libro-scale, 1));
}

.libro-pagina {
    position: absolute;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    font-family: 'Crimson Text', serif;
    color: #3e2723;
    padding: 2% 4%;
    z-index: 5;
    display: flex;
    flex-direction: column;
}

.libro-pagina::-webkit-scrollbar { width: 0; display: none; }
.libro-pagina { -ms-overflow-style: none; scrollbar-width: none; }

.libro-titulo {
    font-family: 'Cinzel', serif;
    font-size: calc(1.05rem * var(--libro-scale, 1));
    color: #5d3a1a;
    text-align: center;
    margin: 0 0 6px;
    border-bottom: 1px solid #c9a22755;
    padding-bottom: 3px;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.libro-subtitulo {
    font-family: 'Cinzel', serif;
    font-size: calc(0.72rem * var(--libro-scale, 1));
    color: #8d6e63;
    text-align: center;
    margin-bottom: 4px;
    flex-shrink: 0;
}

.libro-separador {
    height: 1px;
    background: linear-gradient(to right, transparent, #c9a22788, transparent);
    margin: 4px 0;
    flex-shrink: 0;
}

.libro-stats-tabla {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
}

.libro-stats-tabla tr:nth-child(even) td {
    background: rgba(139,90,43,0.06);
}

.libro-stat-label {
    font-size: calc(0.82rem * var(--libro-scale, 1));
    padding: 3px 2px;
    color: #5d3a1a;
    font-family: 'Crimson Text', serif;
}

.libro-stat-val {
    font-size: calc(0.95rem * var(--libro-scale, 1));
    font-family: 'Cinzel', serif;
    font-weight: bold;
    color: #3e2723;
    text-align: right;
    padding: 3px 2px;
}

.libro-medallas-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 4px;
    width: 100%;
    flex-shrink: 0;
}

.libro-medalla {
    position: relative;
    aspect-ratio: 1;
    border-radius: 50%;
    overflow: visible;
    border: 2px solid transparent;
    transition: transform 0.2s;
    max-width: 48px;
    max-height: 48px;
    margin: 0 auto;
    width: 100%;
}

.libro-medalla:hover { transform: scale(1.1); }

.medalla-bloqueada { opacity: 0.45; border-color: #9e9e9e44; }
.medalla-bronce    { border-color: #cd7f32; }
.medalla-plata     { border-color: #aaaaaa; }
.medalla-oro       { border-color: #ffd700; }

.medalla-badge {
    position: absolute;
    bottom: -3px;
    right: -3px;
    font-size: calc(0.75rem * var(--libro-scale, 1));
    line-height: 1;
    filter: drop-shadow(0 0 3px rgba(0,0,0,0.7));
}

.libro-titulos-lista {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.libro-titulo-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: calc(0.68rem * var(--libro-scale, 1));
    border: 1px solid transparent;
    line-height: 1.2;
}

.titulo-ganado { background: rgba(201,162,39,0.12); border-color: #c9a22755; color: #3e2723; }
.titulo-pendiente { background: rgba(62,39,35,0.05); border-color: #9e9e9e33; color: #795548; font-style: italic; }

/* =====================================================
   LIBRO DEL ATRIL — Forzar orientación horizontal
   ===================================================== */

#libroOrientacionAviso {
    display: none;
}

@media (max-width: 1024px) and (orientation: portrait) {
    #libroAtrilInner,
    #libroAtrilBtnPrev,
    #libroAtrilBtnNext {
        display: none !important;
    }
    #libroOrientacionAviso {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        gap: 20px;
        color: #c9a227;
        font-family: 'Cinzel', serif;
        text-align: center;
        padding: 30px;
    }
    #libroOrientacionAviso .aviso-icono {
        font-size: 3.5rem;
        animation: girarIcono 2s ease-in-out infinite;
    }
    #libroOrientacionAviso .aviso-texto {
        font-size: 1.1rem;
        line-height: 1.6;
        color: #f4e4d7;
        text-shadow: 0 0 10px rgba(201,162,39,0.5);
    }
    #libroOrientacionAviso .aviso-subtexto {
        font-size: 0.8rem;
        color: #8d6e63;
        font-family: 'Crimson Text', serif;
    }
}

body.is-portrait #libroAtrilInner,
body.is-portrait #libroAtrilBtnPrev,
body.is-portrait #libroAtrilBtnNext {
    display: none !important;
}
body.is-portrait #libroOrientacionAviso {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 20px;
    color: #c9a227;
    font-family: 'Cinzel', serif;
    text-align: center;
    padding: 30px;
}
body.is-portrait #libroOrientacionAviso .aviso-icono {
    font-size: 3.5rem;
    animation: girarIcono 2s ease-in-out infinite;
}
body.is-portrait #libroOrientacionAviso .aviso-texto {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #f4e4d7;
    text-shadow: 0 0 10px rgba(201,162,39,0.5);
}
body.is-portrait #libroOrientacionAviso .aviso-subtexto {
    font-size: 0.8rem;
    color: #8d6e63;
    font-family: 'Crimson Text', serif;
}

@keyframes girarIcono {
    0%   { transform: rotate(0deg); }
    30%  { transform: rotate(90deg); }
    70%  { transform: rotate(90deg); }
    100% { transform: rotate(0deg); }
}

/* =====================================================
   PARCHE MAESTRO V2: SINCRONIZACIÓN 1:1 SUBIDOR ARCANO (BOCADILLOS)
   ===================================================== */

@media (max-width: 1024px) {
    
    /* --- CÓDICE MÓVIL: MODO VERTICAL (PORTRAIT) --- */
    @media (orientation: portrait), (max-width: 650px) {
        #codiceScreen .back-btn-container {
            top: 10px !important;
            left: 10px !important;
            bottom: auto !important;
            transform: none !important;
            width: auto !important;
            z-index: 100 !important;
        }
        #backFromCodiceBtn {
            padding: 5px 12px !important;
            font-size: 0.78rem !important;
        }
        .codice-ui-layer, #codiceUILayer {
            flex-direction: column !important;
            justify-content: flex-start !important;
            align-items: center !important;
            padding: 46px 8px 20px 8px !important;
            gap: 8px !important;
            overflow-y: auto !important;
            -webkit-overflow-scrolling: touch !important;
            width: 100% !important;
            height: 100% !important;
            box-sizing: border-box !important;
        }
        .codice-progress-container {
            position: relative !important;
            left: auto !important;
            top: auto !important;
            transform: none !important;
            flex-direction: row !important;
            order: 1 !important;
            width: auto !important;
            max-width: 95% !important;
            justify-content: center !important;
            margin: 0 auto 4px auto !important;
            padding: 6px 12px !important;
            gap: 6px !important;
            flex-shrink: 0 !important;
            z-index: 10 !important;
        }
        .codice-square {
            width: clamp(16px, 5vw, 22px) !important;
            height: clamp(16px, 5vw, 22px) !important;
        }
        .codice-board, #codiceBoardInner {
            order: 2 !important;
            width: 100% !important;
            max-width: 480px !important;
            margin: 0 auto !important;
            flex: none !important;
            padding: 14px 10px !important;
            border-radius: 10px !important;
            box-shadow: 0 0 15px rgba(0, 188, 212, 0.3) !important;
            box-sizing: border-box !important;
        }
        .codice-question {
            font-size: 1.05rem !important;
            margin-bottom: 12px !important;
            line-height: 1.35 !important;
            padding: 0 4px !important;
        }
        .codice-answers-grid {
            display: grid !important;
            grid-template-columns: 1fr 1fr !important;
            gap: 8px !important;
            width: 100% !important;
        }
        .codice-btn {
            padding: 8px 10px !important;
            font-size: 0.88rem !important;
            min-height: 56px !important;
            line-height: 1.25 !important;
            margin-bottom: 0 !important;
            border-radius: 6px !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            text-align: center !important;
        }
    }

    body.is-portrait #codiceScreen .back-btn-container { top: 10px !important; left: 10px !important; bottom: auto !important; transform: none !important; width: auto !important; z-index: 100 !important; }
    body.is-portrait #backFromCodiceBtn { padding: 5px 12px !important; font-size: 0.78rem !important; }
    body.is-portrait .codice-ui-layer, body.is-portrait #codiceUILayer { flex-direction: column !important; justify-content: flex-start !important; align-items: center !important; padding: 46px 8px 20px 8px !important; gap: 8px !important; overflow-y: auto !important; -webkit-overflow-scrolling: touch !important; width: 100% !important; height: 100% !important; box-sizing: border-box !important; }
    body.is-portrait .codice-progress-container { position: relative !important; left: auto !important; top: auto !important; transform: none !important; flex-direction: row !important; order: 1 !important; width: auto !important; max-width: 95% !important; justify-content: center !important; margin: 0 auto 4px auto !important; padding: 6px 12px !important; gap: 6px !important; flex-shrink: 0 !important; z-index: 10 !important; }
    body.is-portrait .codice-square { width: clamp(16px, 5vw, 22px) !important; height: clamp(16px, 5vw, 22px) !important; }
    body.is-portrait .codice-board, body.is-portrait #codiceBoardInner { order: 2 !important; width: 100% !important; max-width: 480px !important; margin: 0 auto !important; flex: none !important; padding: 14px 10px !important; border-radius: 10px !important; box-sizing: border-box !important; }
    body.is-portrait .codice-question { font-size: 1.05rem !important; margin-bottom: 12px !important; line-height: 1.35 !important; }
    body.is-portrait .codice-answers-grid { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 8px !important; width: 100% !important; }
    body.is-portrait .codice-btn { padding: 8px 10px !important; font-size: 0.88rem !important; min-height: 56px !important; line-height: 1.25 !important; margin-bottom: 0 !important; border-radius: 6px !important; }

    /* --- CÓDICE MÓVIL: MODO HORIZONTAL (LANDSCAPE) --- */
    @media (orientation: landscape) and (max-height: 520px), (orientation: landscape) and (max-width: 950px) {
        #codiceScreen .back-btn-container {
            top: 6px !important;
            left: 8px !important;
            bottom: auto !important;
            transform: none !important;
            width: auto !important;
            z-index: 100 !important;
        }
        #backFromCodiceBtn {
            padding: 4px 8px !important;
            font-size: 0.7rem !important;
        }
        .codice-ui-layer, #codiceUILayer {
            flex-direction: row !important;
            justify-content: center !important;
            align-items: center !important;
            padding: 6px 10px 6px 45px !important;
            gap: 10px !important;
            overflow-y: auto !important;
            -webkit-overflow-scrolling: touch !important;
            width: 100% !important;
            height: 100% !important;
            box-sizing: border-box !important;
        }
        .codice-progress-container {
            position: relative !important;
            left: auto !important;
            top: auto !important;
            transform: none !important;
            flex-direction: column-reverse !important;
            width: auto !important;
            flex-shrink: 0 !important;
            padding: 4px 5px !important;
            margin: 0 !important;
            gap: 3px !important;
            z-index: 10 !important;
        }
        .codice-square {
            width: 15px !important;
            height: 15px !important;
            border-radius: 2px !important;
        }
        .codice-board, #codiceBoardInner {
            flex: 1 !important;
            width: auto !important;
            max-width: 840px !important;
            max-height: 96vh !important;
            overflow-y: auto !important;
            padding: 8px 12px !important;
            margin: 0 !important;
            border-radius: 8px !important;
            box-shadow: 0 0 15px rgba(0, 188, 212, 0.3) !important;
            box-sizing: border-box !important;
        }
        .codice-question {
            font-size: 0.95rem !important;
            margin-bottom: 6px !important;
            line-height: 1.2 !important;
            padding: 0 4px !important;
        }
        .codice-answers-grid {
            display: grid !important;
            grid-template-columns: 1fr 1fr !important;
            gap: 6px !important;
            width: 100% !important;
        }
        .codice-btn {
            padding: 6px 8px !important;
            font-size: 0.8rem !important;
            min-height: 42px !important;
            line-height: 1.2 !important;
            margin-bottom: 0 !important;
            border-radius: 5px !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
            text-align: center !important;
        }
    }

    @media (max-width: 599px) and (orientation: portrait), (max-width: 599px) {
        body.is-portrait .codice-prof-img, .codice-prof-img { width: 82vw !important; max-width: none !important; }
        body.is-portrait .codice-bubble, .codice-bubble { 
            max-width: 102.5vw !important; 
            font-size: 6.15vw !important; 
            padding: 5.12vw 7.69vw !important;
            border-radius: 6.15vw !important;
            line-height: 1.3 !important;
        }
    }

    @media (max-width: 850px) and (orientation: landscape) {
        .codice-prof-img { width: 33.3vw !important; max-width: none !important; }
        .codice-bubble { 
            max-width: 41.6vw !important; 
            font-size: 2.5vw !important; 
            padding: 2.08vw 3.12vw !important;
            border-radius: 2.5vw !important;
            line-height: 1.3 !important;
        }
    }

    @media (min-width: 600px) and (max-width: 1024px) and (orientation: portrait) {
        body.is-portrait .codice-prof-img, .codice-prof-img { width: 57.1vw !important; max-width: none !important; }
        body.is-portrait .codice-bubble, .codice-bubble { 
            max-width: 71.4vw !important; 
            font-size: 4.28vw !important; 
            padding: 3.57vw 5.35vw !important;
            border-radius: 4.28vw !important;
            line-height: 1.3 !important;
        }
    }
    @media (min-width: 600px) and (max-width: 1024px) {
        body.is-portrait .codice-prof-img { width: 57.1vw !important; max-width: none !important; }
        body.is-portrait .codice-bubble { 
            max-width: 71.4vw !important; 
            font-size: 4.28vw !important; 
            padding: 3.57vw 5.35vw !important;
            border-radius: 4.28vw !important;
            line-height: 1.3 !important;
        }
    }

    @media (min-width: 851px) and (max-width: 1024px) and (orientation: landscape) {
        .codice-prof-img { width: 28.5vw !important; max-width: none !important; }
        .codice-bubble { 
            max-width: 35.7vw !important; 
            font-size: 2.14vw !important; 
            padding: 1.78vw 2.67vw !important;
            border-radius: 2.14vw !important;
            line-height: 1.3 !important;
        }
    }
}

/* =====================================================
   CHAT — Footer de mensaje (hora + borrar)
   ===================================================== */
.chat-msg-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
    opacity: 0.65;
}

.chat-msg-time {
    font-size: 0.68rem;
    font-style: italic;
}

.chat-msg-delete {
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0.6;
    transition: opacity 0.2s, transform 0.2s;
}

.chat-msg-delete:hover {
    opacity: 1;
    transform: scale(1.15);
}

/* =====================================================
   BURBUJA Y PANEL DE CHAT FLOTANTE DEL SANCTUM
   ===================================================== */
@media (max-width: 600px) {
    #sanctumChatPanel {
        width: 92vw !important;
        height: 50vh !important;
        bottom: 80px !important;
    }
    #sanctumChatBubble {
        bottom: 14px !important;
    }
}

#sanctumChatMessages .chat-row {
    margin-bottom: 8px;
}

/* FIX SCROLL MÓVIL: Pantalla de Evaluación (Resultados) */
#resultScreen {
    overflow-y: auto !important;
    justify-content: flex-start !important; 
    padding: 20px 10px !important;
}

#resultScreen > div {
    margin: auto;
}

/* =====================================================
   BLOQUEO DE ROTACIÓN EN MÓVILES (Fuerza Vertical)
   Usa #orientacion-aviso-global (div real en index.html)
   en lugar de ::before/::after para evitar el bug de
   que el aviso queda incrustado al volver a vertical.
   ===================================================== */

#orientacion-aviso-global {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: linear-gradient(180deg, #1a1a1a 0%, #000 100%);
    border: 10px solid #5b3a2a;
    box-sizing: border-box;
    z-index: 100000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: 'Cinzel', serif;
    color: #ffcc66;
    font-size: 1.2rem;
    line-height: 1.8;
    padding: 30px;
    pointer-events: all;
}

#orientacion-aviso-global .aviso-phone-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    display: block;
    animation: rotatePhone 2s infinite ease-in-out;
}

/* Activado por clase JS solo si se requiere forzar aviso */
body.forzar-aviso-orientacion #orientacion-aviso-global {
    display: flex !important;
}
body.forzar-aviso-orientacion .screen {
    display: none !important;
}

@keyframes rotatePhone {
    0%   { transform: rotate(-90deg); }
    50%  { transform: rotate(0deg); }
    100% { transform: rotate(0deg); }
}

/* =====================================================
   BIBLIOTECA (ÍNDICE DEL LIBRO) — Forzar orientación horizontal
   ===================================================== */

#libraryOrientacionAviso {
    display: none;
    z-index: 1000;
}

@media (max-width: 1024px) and (orientation: portrait) {
    #libraryBackground,
    #chronicleReader,
    #grimoireReader {
        display: none !important;
    }
    #libraryOrientacionAviso {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        height: 100%;
        gap: 20px;
        color: #c9a227;
        font-family: 'Cinzel', serif;
        text-align: center;
        padding: 30px;
    }
}

body.is-portrait #libraryBackground,
body.is-portrait #chronicleReader,
body.is-portrait #grimoireReader {
    display: none !important;
}
body.is-portrait #libraryOrientacionAviso {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 20px;
    color: #c9a227;
    font-family: 'Cinzel', serif;
    text-align: center;
    padding: 30px;
}

/* =====================================================
   GRIMORIO — Forzar orientación horizontal (Clon Sanctum)
   ===================================================== */
#grimoireOrientacionAviso {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 20px;
    text-align: center;
    padding: 30px;
}

@media (max-width: 1024px) and (orientation: portrait) {
    #grimoireInnerContainer,
    #grimoireControlsContainer {
        display: none !important;
    }
    #grimoireOrientacionAviso {
        display: flex !important;
    }
}

body.is-portrait #grimoireInnerContainer,
body.is-portrait #grimoireControlsContainer {
    display: none !important;
}

body.is-portrait #grimoireOrientacionAviso {
    display: flex !important;
}

@media (max-width: 1366px) {
    #exitAppBtn {
        display: none !important;
    }
}

/* --- ACCESIBILIDAD: TIPOGRAFÍA LIMPIA --- */
body.clean-font-active, 
body.clean-font-active * { 
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif !important; 
}

/* --- GESTIÓN ADAPTATIVA DE BOTONES DE PERFIL (WEB vs NATIVO) --- */
/* En la Web (iPhone y navegadores de PC): Por defecto, sin botón cian y con botón morado */
#checkUpdatesBtn {
    display: none !important;
}
#purgeCacheBtn {
    display: block !important;
}

/* En Apps Nativas Instaladas (Android APK y PC EXE): Se activa el botón cian y se oculta el morado */
body.is-native-app #checkUpdatesBtn {
    display: block !important;
}
body.is-native-app #purgeCacheBtn {
    display: none !important;
}

/* --- CÓDICE: BOTONES DE TEMAS SUPERADOS (ÁMBAR MÍSTICO) --- */
.codice-theme-btn.completed-amber {
    background: linear-gradient(180deg, rgba(255, 179, 0, 0.25) 0%, rgba(183, 110, 0, 0.35) 100%) !important;
    border: 2px solid #ffb300 !important;
    color: #fff8e1 !important;
    box-shadow: 0 0 15px rgba(255, 179, 0, 0.45), inset 0 0 10px rgba(255, 179, 0, 0.2) !important;
    text-shadow: 0 0 8px rgba(255, 179, 0, 0.8) !important;
}
.codice-theme-btn.completed-amber:hover {
    background: linear-gradient(180deg, rgba(255, 193, 7, 0.45) 0%, rgba(255, 143, 0, 0.55) 100%) !important;
    border-color: #ffd54f !important;
    box-shadow: 0 0 25px rgba(255, 213, 79, 0.8) !important;
    transform: scale(1.08) !important;
}
.codice-theme-btn.completed-amber.selected {
    background: #ffb300 !important;
    color: #000 !important;
    box-shadow: 0 0 25px #ffb300 !important;
    transform: scale(1.1) !important;
}

/* ==========================================================================
   LA TORRE DE LOS ENIGMAS (ZHYREL) - PANEL DERECHO NORTE A SUR
   ========================================================================== */

#torreEnigmasScreen {
    display: none;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    box-sizing: border-box;
    overflow: hidden !important;
    padding: 0 !important;
    z-index: 50;
    pointer-events: none;
}

/* En PC y Tablets (pantallas anchas >= 701px): Panel lateral derecho Norte a Sur */
@media (min-width: 701px) {
    .torre-content-wrapper {
        position: absolute !important;
        top: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        width: clamp(420px, 44vw, 540px) !important;
        height: 100% !important;
        max-height: 100% !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        background: rgba(14, 7, 24, 0.88) !important;
        backdrop-filter: blur(10px) !important;
        -webkit-backdrop-filter: blur(10px) !important;
        border-left: 1.5px solid rgba(186, 104, 200, 0.6) !important;
        border-top: none !important;
        border-right: none !important;
        border-bottom: none !important;
        border-radius: 0 !important;
        box-shadow: -5px 0 35px rgba(0, 0, 0, 0.9), inset 0 0 20px rgba(186, 104, 200, 0.15) !important;
        padding: 12px 16px !important;
        box-sizing: border-box !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        pointer-events: auto;
    }
}

/* En móviles en vertical (<= 700px): pantalla completa scrollable */
@media (max-width: 700px) {
    #torreEnigmasScreen {
        position: relative !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding: 8px 8px 80px 8px !important;
        pointer-events: auto;
    }
    .torre-content-wrapper {
        position: relative !important;
        top: auto !important;
        bottom: auto !important;
        right: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 auto !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        background: rgba(14, 7, 24, 0.88) !important;
        border: 1px solid rgba(186, 104, 200, 0.6) !important;
        border-radius: 10px !important;
        padding: 10px !important;
        box-sizing: border-box !important;
        overflow-y: visible !important;
        pointer-events: auto;
    }
}

/* Scrollbar estilizada para el panel de la Torre */
.torre-content-wrapper::-webkit-scrollbar {
    width: 6px;
}
.torre-content-wrapper::-webkit-scrollbar-track {
    background: rgba(10, 5, 20, 0.4);
    border-radius: 6px;
}
.torre-content-wrapper::-webkit-scrollbar-thumb {
    background: rgba(186, 104, 200, 0.5);
    border-radius: 6px;
}
.torre-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: #ba68c8;
}

/* Botones Píldora de la Torre (Anti-truncamiento absoluto) */
.torre-pill-btn {
    width: auto !important;
    max-width: none !important;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
    font-family: 'Cinzel', serif !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px;
    margin-bottom: 0 !important;
    transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease !important;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
}
.torre-pill-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.15);
}
.torre-pill-btn:active {
    transform: translateY(1px);
}

/* Tarjeta Cabecera */
.torre-header-card {
    text-align: center;
    background: rgba(12, 6, 22, 0.88);
    border: 1px solid #ba68c8;
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}
.torre-header-btns {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
@media (max-width: 480px) {
    .torre-header-btns {
        gap: 6px;
    }
    .torre-header-btns .torre-pill-btn {
        flex: 1 1 135px;
        font-size: 0.74rem !important;
        padding: 6px 10px !important;
    }
}

/* Barra de Récords */
.torre-records-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(18, 10, 30, 0.9);
    border: 1px solid #ffd700;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.85rem;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
    flex-wrap: wrap;
    gap: 8px;
    backdrop-filter: blur(4px);
}
.torre-records-scores {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}
@media (max-width: 600px) {
    .torre-records-box {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 8px 12px;
    }
    .torre-records-scores {
        justify-content: space-around;
        width: 100%;
        gap: 8px;
    }
    .torre-records-btn {
        width: 100% !important;
        text-align: center;
    }
}

/* Tarjetas Generales de Torre */
.torre-card {
    background: rgba(18, 10, 28, 0.9);
    border: 1px solid #7b1fa2;
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}
@media (max-width: 480px) {
    .torre-card {
        padding: 10px;
    }
}

/* Rejilla de Disciplinas del Taller */
.torre-disciplinas-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 6px !important;
}
.torre-disciplina-btn {
    padding: 8px 4px !important;
    font-size: 0.78rem !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 2px !important;
    border-radius: 6px !important;
    text-transform: none !important;
    width: 100% !important;
    max-width: none !important;
    margin-bottom: 0 !important;
    box-sizing: border-box !important;
    cursor: pointer;
}
.torre-disciplina-btn strong {
    font-size: 0.78rem !important;
}
.torre-disciplina-btn span {
    line-height: 1.1;
}
.torre-disciplina-btn:hover {
    filter: brightness(1.15);
    transform: translateY(-2px);
}
.torre-disciplina-btn:active {
    transform: translateY(1px);
}

/* Badges del Gran Desafío */
.torre-badges-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 5px !important;
    background: rgba(0, 0, 0, 0.45);
    border-radius: 6px;
    padding: 6px 8px !important;
    margin-bottom: 8px !important;
    font-size: 0.75rem !important;
    color: #eee;
    text-align: center;
}

/* Botones de Pestañas de Diálogo de Zhyrel */
.zhyrel-tab-btn {
    width: 100% !important;
    max-width: none !important;
    white-space: nowrap !important;
    overflow: visible !important;
    text-overflow: clip !important;
    margin-bottom: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.75rem !important;
    padding: 6px 4px !important;
    cursor: pointer;
    touch-action: manipulation;
}
@media (max-width: 520px) {
    .zhyrel-tabs-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 5px !important;
    }
    .zhyrel-tab-btn {
        font-size: 0.7rem !important;
        padding: 5px 2px !important;
    }
}
