:root {
    --bg-base: #0f172a; /* Slate oscuro, igual que configurar-sesion */
    --bg-panel: #1e293b;
    --bg-darker: #000000;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #b72a1e;
    --border: rgba(255,255,255,0.1);
}

body.tv-mode-dark { margin: 0; font-family: 'Inter', sans-serif; background: var(--bg-base); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
* { box-sizing: border-box; }
.hidden { display: none !important; }

/* HEADER */
.room-header { height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; background: var(--bg-panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.header-left, .header-right { display: flex; align-items: center; gap: 15px; }
.btn-back { color: var(--text-muted); text-decoration: none; font-weight: 600; display: flex; align-items: center; gap: 8px; transition: 0.2s; }
.btn-back:hover { color: white; }
.divider { width: 1px; height: 20px; background: var(--border); }
.room-branding { display: flex; align-items: center; gap: 8px; font-weight: 700; color: #38bdf8; }
.room-branding img { height: 24px; }
.btn-icon { background: transparent; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; transition: 0.2s; }
.btn-icon:hover { color: white; }

/* LAYOUT PRINCIPAL (Twitch Style) */
.room-layout { display: flex; flex-grow: 1; overflow: hidden; }
.video-column { flex-grow: 1; display: flex; flex-direction: column; overflow-y: auto; background: var(--bg-base); }
.chat-column { width: 380px; flex-shrink: 0; background: var(--bg-panel); border-left: 1px solid var(--border); display: flex; flex-direction: column; }

/* REPRODUCTOR GIGANTE */
.theater-stage { width: 100%; aspect-ratio: 16/9; background: var(--bg-darker); position: relative; flex-shrink: 0; display: flex; justify-content: center; align-items: center; }
.theater-stage iframe { width: 100%; height: 100%; border: none; position: absolute; top: 0; left: 0; }

.theater-badges { position: absolute; top: 20px; left: 20px; z-index: 10; display: flex; gap: 10px; }
.badge { padding: 6px 12px; border-radius: 6px; font-weight: 700; font-size: 0.85rem; letter-spacing: 0.5px; backdrop-filter: blur(5px); }
.badge.live { background: #e50914; color: white; animation: pulse 2s infinite; }
.badge.upcoming { background: rgba(255,255,255,0.2); color: white; }
.badge.vod { background: rgba(71, 85, 105, 0.8); color: white; }
.badge.viewers { background: rgba(0,0,0,0.6); color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }

/* COUNTDOWN */
.countdown-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; background: rgba(0,0,0,0.85); z-index: 5; text-align: center;}
.countdown-overlay h3 { color: var(--text-muted); letter-spacing: 2px; text-transform: uppercase; margin-bottom: 10px; }
.timer { font-size: 5rem; font-weight: 900; color: white; font-variant-numeric: tabular-nums; line-height: 1; text-shadow: 0 0 30px var(--accent); margin-bottom: 10px; }

/* PANEL DE CONTEXTO */
.context-panel { padding: 2rem; max-width: 1400px; margin: 0 auto; width: 100%; }
.context-header { border-bottom: 1px solid var(--border); padding-bottom: 1.5rem; margin-bottom: 1.5rem; }
.context-header h1 { margin: 0 0 10px 0; font-size: 2rem; }
.context-meta { display: flex; flex-wrap: wrap; gap: 15px; color: var(--text-muted); font-size: 0.95rem; align-items: center; }
.project-tag { color: #38bdf8; font-weight: 600; }
.doi-tag { background: rgba(255,255,255,0.05); padding: 4px 8px; border-radius: 4px; font-family: monospace; border: 1px solid var(--border);}

.context-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 2rem; }
.info-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 1.5rem; }
.info-card h3 { margin: 0 0 1rem 0; font-size: 1.1rem; color: var(--text-muted); border-bottom: 1px solid var(--border); padding-bottom: 10px; }

.speakers-list { display: flex; flex-direction: column; gap: 15px; }
.speaker-item { display: flex; align-items: center; gap: 12px; }
.speaker-item img { width: 45px; height: 45px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); }
.speaker-info strong { display: block; font-size: 1rem; color: white; }
.speaker-info span { font-size: 0.85rem; color: var(--text-muted); }

.description-card p { 
    line-height: 1.6; 
    color: rgba(255,255,255,0.9); 
    margin-top: 0; 
    white-space: pre-wrap; /* Esta línea mágica respeta los saltos de línea automáticos */
}
/* --- LÓGICA DE DESCRIPCIÓN TIPO YOUTUBE --- */
.desc-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.desc-collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 4; /* Cortará el texto exactamente a las 4 líneas */
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.btn-toggle-desc {
    background: transparent;
    border: none;
    color: white;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 5px 0 0 0;
    margin-top: 5px;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-toggle-desc:hover {
    color: #38bdf8; /* Azul característico al pasar el mouse */
}
.btn-primary { background: var(--accent); color: white; border: none; padding: 10px 20px; border-radius: 8px; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; transition: 0.2s; }
.btn-primary:hover { background: #962218; transform: translateY(-2px); }

/* CHAT COLUMN */
.chat-container { display: flex; flex-direction: column; height: 100%; }
.chat-tabs { display: flex; background: var(--bg-base); }
.chat-tab { flex: 1; padding: 15px; background: none; border: none; color: var(--text-muted); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
.chat-tab.active { color: white; border-bottom-color: var(--accent); background: var(--bg-panel); }
/* --- TRUCO ANTI-BLOQUEO PARA TWITCH --- */
.chat-panels { flex-grow: 1; position: relative; overflow: hidden; display: flex; flex-direction: column; }
.chat-panel { position: absolute; left: -9999px; visibility: hidden; width: 100%; height: 100%; flex-direction: column; }
.chat-panel.active { position: relative; left: 0; visibility: visible; display: flex; flex-grow: 1; }
.chat-feed { flex-grow: 1; overflow-y: auto; padding: 15px; }
.chat-input-area { padding: 15px; background: var(--bg-base); border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.chat-input-area input { flex-grow: 1; background: var(--bg-panel); border: 1px solid var(--border); padding: 12px 15px; border-radius: 50px; color: white; outline: none; }
.chat-input-area button#btn-send-bsky { background: var(--accent); color: white; border: none; width: 42px; height: 42px; border-radius: 50%; cursor: pointer; flex-shrink: 0;}
.chat-input-area button#btn-send-bsky:disabled { opacity: 0.5; cursor: not-allowed; }

/* NUEVO: Botón de Emojis */
.btn-emoji { background: transparent; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; transition: 0.2s; padding: 0; display: flex; justify-content: center; align-items: center; }
.btn-emoji:hover:not(:disabled) { color: #facc15; transform: scale(1.1); }
.btn-emoji:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-overlay { position: absolute; inset: 0; background: rgba(15,23,42,0.95); z-index: 10; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 20px; }
.chat-overlay i { font-size: 3rem; color: #0085ff; margin-bottom: 15px; }

@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }

/* --- ACCIONES INFERIORES Y COMPARTIR --- */
.room-footer-actions { margin-top: 2rem; border-top: 1px solid var(--border); padding-top: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; }
.live-room-share-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.share-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--border); color: var(--text-muted); display: flex; align-items: center; justify-content: center; background: var(--bg-panel); cursor: pointer; transition: 0.2s; font-size: 1.1rem; }
.share-btn:hover { background: var(--accent); color: white; border-color: var(--accent); transform: translateY(-2px); }
.footer-meta-actions { display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem; }
.disclaimer-text { font-size: 0.85rem; color: var(--text-muted); margin: 0; line-height: 1.5; flex-grow: 1; }
.btn-report { background: none; border: none; color: var(--text-muted); font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 6px; transition: 0.2s; white-space: nowrap; }
.btn-report:hover { color: #ef4444; }

/* Enlaces dentro de ponentes y DOI */
.speaker-handle { color: #38bdf8; text-decoration: none; transition: 0.2s; }
.speaker-handle:hover { text-decoration: underline; }
.avatar-modal-trigger { cursor: pointer; transition: transform 0.2s; }
.avatar-modal-trigger:hover { transform: scale(1.1); border-color: var(--accent) !important; }
.doi-tag a { color: inherit; text-decoration: none; transition: 0.2s; }
.doi-tag a:hover { color: white; }

/* --- MODAL DE INVESTIGADOR --- */
.investigator-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; z-index: 4000; backdrop-filter: blur(5px); opacity: 0; visibility: hidden; transition: 0.3s; }
.investigator-modal-overlay.is-visible { opacity: 1; visibility: visible; }
.investigator-modal { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 16px; width: 90%; max-width: 450px; max-height: 85vh; display: flex; flex-direction: column; position: relative; }
.investigator-modal-header { padding: 1rem; display: flex; justify-content: flex-end; border-bottom: 1px solid var(--border); }
.investigator-modal-close-btn { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
.investigator-modal-close-btn:hover { color: white; }
.investigator-modal-content { padding: 2rem; overflow-y: auto; text-align: center; }
.investigator-modal-content img.avatar { width: 90px; height: 90px; border-radius: 50%; border: 3px solid var(--accent); margin-bottom: 1rem; object-fit: cover; }
.investigator-modal-content h3 { margin: 0 0 0.5rem; color: white; font-size: 1.3rem; }
.profile-card__socials { display: flex; justify-content: center; gap: 15px; margin: 1.5rem 0; font-size: 1.3rem; }
.profile-card__socials a { color: var(--text-muted); transition: 0.2s; }
.profile-card__socials a:hover { color: white; transform: scale(1.1); }
.investigator-bio { font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; margin-bottom: 1.5rem; }
.project-info { background: var(--bg-base); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; text-align: left; }
.project-info h4 { margin: 0 0 10px 0; font-size: 0.95rem; color: white; }
.project-info ul { margin: 0; padding-left: 20px; font-size: 0.85rem; color: var(--text-muted); }
.project-info li { margin-bottom: 5px; }

/* --- LÓGICA DE YOUTUBE MOBILE (HOJA DESLIZANTE) --- */
.hidden-desktop { display: none !important; }

@media (max-width: 992px) {
    .hidden-desktop { display: flex !important; }

    /* 1. Hacemos que la página entera haga scroll (no columnas separadas) */
    .room-layout { flex-direction: column; overflow-y: auto; height: calc(100vh - 60px); display: block; }
    .video-column { display: block; overflow: visible; }

    /* 2. REPRODUCTOR PEGAJOSO (Sticky): Nunca se pierde de vista */
    .theater-stage {
        position: sticky;
        top: 0;
        z-index: 100;
        box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    }

    /* 3. Botón para abrir el chat debajo del video */
    .mobile-chat-toggle {
        padding: 15px 20px;
        background: var(--bg-panel);
        border-bottom: 1px solid var(--border);
        justify-content: center;
    }
    .mobile-chat-toggle button {
        width: 100%; padding: 12px; border-radius: 50px; background: var(--bg-card); border: 1px solid var(--border); color: white; font-weight: 600; font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: 0.2s;
    }

    /* 4. CHAT DESLIZANTE (Bottom Sheet) */
    .chat-column {
        position: fixed;
        bottom: -100%; /* Oculto debajo de la pantalla por defecto */
        left: 0;
        width: 100%;
        /* Altura dinámica: Pantalla total - alto del header - alto del video(16:9) */
        height: calc(100dvh - 60px - 56.25vw); 
        border-left: none;
        border-top: 1px solid var(--border);
        box-shadow: 0 -10px 30px rgba(0,0,0,0.6);
        z-index: 90; /* Se desliza por DEBAJO del video que tiene z-index 100 */
        transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 20px 20px 0 0;
        overflow: hidden;
    }
    
    /* Clase activa que inyecta JS para mostrarlo */
    .chat-column.mobile-open { bottom: 0; }

    /* Botón de flecha hacia abajo en el chat */
    .btn-close-chat-mobile {
        background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; margin-left: auto; padding: 0 15px;
    }
    
    .context-grid { grid-template-columns: 1fr; }
}

/* =================================================================
   SECCIÓN DE COMENTARIOS (ÁGORA)
   ================================================================= */
.agora-comments-section {
    margin: 2rem 0;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}
.comments-title {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}
.comments-auth-prompt {
    background: rgba(255, 255, 255, 0.03);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 2rem;
    border: 1px solid var(--border);
}
.comments-auth-prompt p { margin: 0; color: var(--text-muted); }

/* Formulario */
.comments-form {
    display: flex;
    gap: 15px;
    margin-bottom: 3rem;
    align-items: flex-start;
}
.comment-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
}
.comment-input-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#comment-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--text-muted);
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    padding: 8px 0;
    resize: none;
    outline: none;
    overflow: hidden;
    min-height: 35px;
    transition: border-color 0.2s;
}
#comment-input:focus {
    border-bottom: 2px solid var(--accent);
    padding-bottom: 7px;
}
.comment-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
}
.char-counter { font-size: 0.8rem; color: var(--text-muted); }
.btn-sm { padding: 8px 18px; font-size: 0.9rem; border-radius: 20px; }

/* Lista de Comentarios */
.comments-feed {
    display: flex;
    flex-direction: column;
    gap: 1.8rem;
}
.comment-item {
    display: flex;
    gap: 15px;
    animation: fadeIn 0.4s ease;
}
.comment-item-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}
/* ¡NUEVO! Forzamos a la caja de texto a respetar el ancho de la pantalla */
.comment-item-content {
    min-width: 0; 
    flex-grow: 1;
}

.comment-item-header {
    display: flex;
    align-items: center; /* 'center' alinea mejor la etiqueta dorada si salta de línea */
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap; /* CRÍTICO: Permite que el @handle o la etiqueta bajen a la siguiente línea si no caben */
}

/* Opcional: Aseguramos que los nombres larguísimos se corten con puntos suspensivos */
.comment-author-name { 
    font-weight: 600; 
    font-size: 0.95rem; 
    color: var(--text-main); 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    max-width: 100%; 
}
.comment-author-handle { font-size: 0.8rem; color: var(--text-muted); }
.comment-text {
    font-size: 0.95rem;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.9);
    margin: 0;
    word-break: break-word;
}

/* --- SISTEMA DE VOTACIÓN (ÁGORA) --- */
.live-poll-container {
    position: absolute;
    bottom: 30px;
    right: 30px;
    z-index: 50;
    display: flex;
    gap: 12px;
    background: rgba(15, 23, 42, 0.7);
    padding: 10px 15px;
    border-radius: 50px;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.15);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    animation: slideUpFade 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.poll-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 50px;
    padding: 6px 16px;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: white;
    font-weight: 700;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.poll-btn:hover { background: rgba(255,255,255,0.25); transform: scale(1.08) translateY(-3px); border-color: var(--accent); }
.poll-btn:active { transform: scale(0.95); }
.poll-count { font-size: 1rem; color: #38bdf8; text-shadow: 0 2px 4px rgba(0,0,0,0.8);}

@keyframes slideUpFade { from { opacity: 0; transform: translateY(20px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }

@media (max-width: 992px) {
    .live-poll-container { bottom: 15px; right: 15px; gap: 8px; padding: 8px 12px; }
    .poll-btn { font-size: 1.2rem; padding: 4px 12px; }
    .poll-count { font-size: 0.9rem; }
}
/* =================================================================
   CORRECCIONES MÓVILES (Cuenta regresiva, Títulos y Tarjetas)
   ================================================================= */
@media (max-width: 768px) {
    /* 1. Evitar que el título del video asfixie la pantalla */
    .countdown-overlay h3 {
        font-size: 0.9rem;
        margin-bottom: 5px;
        padding: 0 15px;
        /* Forzar a máximo 2 líneas si es muy largo */
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        line-height: 1.3;
    }

    /* 2. Achicar drásticamente la cuenta regresiva en celular */
    .timer {
        font-size: 2.5rem !important; /* Mitad de tamaño para que encaje perfecto */
        margin-bottom: 5px;
    }

    /* 3. Ajustar el título principal de la sala */
    .context-header h1 {
        font-size: 1.5rem;
        line-height: 1.3;
    }

    /* 4. Evitar que las tarjetas de contexto se desborden con palabras/enlaces largos */
    .info-card {
        padding: 1.2rem 1rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .context-meta {
        gap: 8px;
        font-size: 0.85rem;
    }
    
    /* 1. Reducimos el padding lateral del panel para que las tarjetas tengan más espacio */
    .context-panel {
        padding: 1.5rem 1rem; 
        width: 100%;
        overflow: hidden; /* Corta cualquier desbordamiento invisible */
    }

    /* 2. Forzamos a las tarjetas y su contenido a romperse si son más anchas que la pantalla */
    .info-card {
        padding: 1.2rem 1rem;
        width: 100%;
        max-width: 100%;
        word-wrap: break-word;
        overflow-wrap: break-word;
        word-break: break-word; /* CRÍTICO: Obliga a romper enlaces o correos largos */
    }
}
/* --- ESTILOS PARA EL POST ANCLA DEL HILO --- */
.anchor-comment {
    background: rgba(56, 189, 248, 0.05); /* Fondo sutil celeste/Epistecnología */
    border: 1px solid rgba(56, 189, 248, 0.2);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.anchor-badge {
    background: #38bdf8;
    color: #0f172a;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}