/* ... existing imports and root ... */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Modern Dark Palette */
    --primary: #6366f1;       /* Indigo 500 */
    --primary-hover: #4f46e5; /* Indigo 600 */
    --secondary: #a855f7;     /* Purple 500 */
    --accent: #ec4899;        /* Pink 500 */
    
    --bg-dark: #030712;       /* Gray 950 */
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e1b4b;

    --text-main: #f8fafc;     /* Slate 50 */
    --text-muted: #94a3b8;    /* Slate 400 */
    
    /* Glassmorphism Variables */
    --glass-bg: rgba(15, 23, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.03);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.36);
    --backdrop-blur: 12px;

    --danger: #ef4444;
    --success: #22c55e;
    --gold: #eab308;
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-dark);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.15), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(236, 72, 153, 0.15), transparent 25%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    font-size: 15px;
    line-height: 1.5;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* --- Glass Panel Mixin --- */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--backdrop-blur));
    -webkit-backdrop-filter: blur(var(--backdrop-blur));
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: var(--radius-lg);
}

/* --- Buttons --- */
.btn {
    padding: 0.6rem 1.2rem;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    font-size: 0.95rem;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn:active:not(:disabled) {
    transform: translateY(0);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.start-btn, .submit-btn, .confirm-btn {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    color: white;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.start-btn:hover, .submit-btn:hover, .confirm-btn:hover {
    background: linear-gradient(135deg, var(--primary-hover), var(--secondary));
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
    transform: translateY(-2px);
}

/* --- Inputs --- */
input[type="text"], 
input[type="email"], 
input[type="password"], 
textarea {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s ease;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* --- Auth & Header --- */
.auth-buttons {
    position: absolute;
    top: 1rem;
    display: flex;
    gap: 1rem;
    align-items: center;
    z-index: 100;
}

.user-info {
    color: var(--text-muted);
    font-weight: 500;
}

/* --- Mobile Menu Logic --- */
.mobile-menu-container {
    position: relative;
    display: flex;
    align-items: center;
}

/* Default: Hamburger Hidden */
.hamburger-btn {
    display: none; /* Hidden on desktop */
    flex-direction: column;
    justify-content: space-around;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.6rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    z-index: 101;
}

.hamburger-btn span {
    width: 100%;
    height: 2px;
    background-color: var(--text-main);
    border-radius: 2px;
    transition: all 0.3s linear;
    transform-origin: 1px;
}

.hamburger-btn.active span:nth-child(1) { transform: rotate(45deg); }
.hamburger-btn.active span:nth-child(2) { opacity: 0; transform: translateX(20px); }
.hamburger-btn.active span:nth-child(3) { transform: rotate(-45deg); }

/* Default: Menu Visible (Desktop) */
.mobile-menu {
    display: flex;
    gap: 1rem;
    position: static; /* Normal flow on desktop */
    background: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
}

/* --- Hero Section --- */
.hero {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeIn 0.8s ease-out;
}

.title {
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
    background: linear-gradient(to right, #fff, #a5b4fc);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.participant-count {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
    display: inline-flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    backdrop-filter: blur(4px);
}

.start-btn {
    padding: 1rem 3rem;
    font-size: 1.2rem;
    border-radius: var(--radius-full);
}

/* --- Main Question --- */
.question-container {
    max-width: 800px;
    width: 100%;
    margin-top: 2rem;
    padding: 2.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    box-shadow: var(--glass-shadow);
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.question-text {
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 2rem;
    line-height: 1.4;
}

.answers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.answer-btn {
    text-align: left;
    padding: 1.2rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-main);
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.answer-btn:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--primary);
}

.answer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;
    position: relative;
}

/* Hide results by default */
.vote-count, .percentage-display {
    display: none;
    margin-left: 1rem;
    font-size: 0.9em;
    color: var(--text-muted);
}

/* Show results when container has .show-results class */
.show-results .vote-count, 
.show-results .percentage-display {
    display: inline-block;
}

.vote-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    width: 100%;
    background: rgba(0,0,0,0.2);
}

.vote-bar {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 1s cubic-bezier(0.22, 1, 0.36, 1);
}

.selected-answer {
    border-color: var(--accent);
    background: rgba(236, 72, 153, 0.1);
    box-shadow: 0 0 0 1px var(--accent);
}

.checkmark {
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
}
.selected-answer .checkmark {
    opacity: 1;
    transform: scale(1);
}

.continue-btn {
    margin-top: 2rem;
    width: 100%;
    justify-content: center;
    padding: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    background: linear-gradient(135deg, var(--success), var(--primary));
    border: none;
    border-radius: var(--radius-full);
    color: white;
    cursor: pointer;
    display: flex;
    animation: fadeIn 0.5s ease;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.3);
}
.continue-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
}

/* --- Chat Interface --- */
#chatroomContainer {
    width: 100%;
    max-width: 1000px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--glass-shadow);
    animation: fadeIn 0.5s ease;
}

#chatroomHeader {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatroom-header-info {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 1rem;
}
.chatroom-header-info span { color: var(--text-main); }

#chatView {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Crucial for flex scrolling */
    position: relative;
}

#chatMessages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

/* Chat Bubbles */
.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    animation: messagePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.message-wrapper.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message-wrapper.other-user {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content-container {
    display: flex;
    flex-direction: column;
    position: relative;
}

.message {
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    gap: 0.8rem;
}

.message-bubble-content {
    display: flex;
    flex-direction: column;
}

/* My Messages */
.message-wrapper.user .message {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-bottom-right-radius: 4px;
}

/* Others Messages */
.message-wrapper.other-user .message {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

/* System Messages */
.message-wrapper.system {
    align-self: center;
    max-width: 90%;
    opacity: 0.8;
}
.message-wrapper.system .message {
    background: transparent;
    box-shadow: none;
    font-style: italic;
    color: var(--text-muted);
    border: 1px dashed var(--glass-border);
    padding: 0.4rem 1rem;
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 700;
    margin-bottom: 0.2rem;
    opacity: 0.9;
}

.message-wrapper.other-user .message-sender a {
    color: var(--accent);
    text-decoration: none;
}
.message-wrapper.other-user .message-sender a:hover {
    text-decoration: underline;
}

/* --- FIX: Link Styling in Messages --- */
.message-text a {
    color: var(--accent); /* Use accent color for visibility */
    text-decoration: underline;
    text-underline-offset: 2px; /* Better readability */
    font-weight: 500;
    transition: color 0.2s, text-decoration-color 0.2s;
}

.message-text a:hover {
    color: var(--primary); /* Shift to primary on hover */
    text-decoration-color: var(--primary);
    cursor: pointer;
}

/* Ensure links in own messages (which have dark backgrounds) are readable */
.message-wrapper.user .message-text a {
    color: #fff;
    text-decoration-color: rgba(255,255,255,0.6);
}

.message-wrapper.user .message-text a:hover {
    color: rgba(255,255,255,0.9);
    text-decoration-color: #fff;
}

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.1);
}

/* Chat Input Area */
#chatInputContainer {
    padding: 1.2rem;
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid var(--glass-border);
    display: flex;
    gap: 0.8rem;
    align-items: center;
}

#chatInput {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-full);
    padding: 0.8rem 1.5rem;
    border: 1px solid transparent;
    color: white;
}
#chatInput:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
    box-shadow: none;
}

#sendChatBtn {
    border-radius: var(--radius-full);
    padding: 0.8rem 1.5rem;
}

/* --- Reply Bar --- */
#replyingToContainer {
    background: rgba(15, 23, 42, 0.9);
    border-top: 1px solid var(--glass-border);
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    border-left: 3px solid var(--accent);
}

.reply-quote {
    background: rgba(0,0,0,0.2);
    border-left: 3px solid var(--text-muted);
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    border-radius: 0 8px 8px 0;
    color: var(--text-muted);
}

/* --- Message Actions (Hover) --- */
.message-actions {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 5px;
    
    /* Interaction Logic: */
    /* Default: Invisible to eyes and mouse */
    opacity: 0;
    visibility: hidden;
    
    /* Transition:
       - Opacity: Fades in/out smoothly (0.2s)
       - Visibility: Delays switching to 'hidden' by 0.3s. 
         This allows the element to remain interactive (clickable) 
         while it fades out, preventing it from disappearing mid-hover.
    */
    transition: opacity 0.2s ease-in-out, visibility 0s linear 0.3s;
    
    z-index: 100; /* Ensure above message bubble */
}

/* Show Actions */
.message-wrapper:hover .message-actions,
.message-actions:hover {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s; /* Show immediately, no delay */
}

/* Invisible Bridge: Fills gap between message and buttons so hover isn't lost */
.message-actions::after {
    content: '';
    position: absolute;
    top: -20px;
    bottom: -20px;
    width: 40px; /* Wide enough to span the gap */
    z-index: -1;
}

/* Position: Own Messages (Buttons on Left) */
.message-wrapper.user .message-actions { 
    right: 100%; 
    margin-right: 10px; 
}
.message-wrapper.user .message-actions::after {
    left: 100%; /* Extend bridge to the right towards message */
}

/* Position: Other Messages (Buttons on Right) */
.message-wrapper.other-user .message-actions { 
    left: 100%; 
    margin-left: 10px; 
}
.message-wrapper.other-user .message-actions::after {
    right: 100%; /* Extend bridge to the left towards message */
}

/* Action Buttons */
.message-action-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;  /* Enforce circle shape */
    min-height: 32px; /* Enforce circle shape */
    border-radius: 50%;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;      /* Remove padding that causes skewing */
    flex-shrink: 0;  /* Prevent squeezing in flex containers */
    line-height: 1;
}

.message-action-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
    border-color: var(--primary);
}

/* --- NEW: Reaction Picker (Hidden by default) --- */
.reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 5px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    padding: 0.3rem 0.5rem;
    display: flex;
    gap: 0.25rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    opacity: 0;
    visibility: hidden;
    transform: translateY(5px);
    transition: all 0.2s ease;
    z-index: 10;
}

/* Show on hover */
.message-content-container:hover .reaction-picker {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Style the emoji buttons inside picker */
.reaction-picker button {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.1s;
    padding: 0.2rem;
    border-radius: 50%;
}
.reaction-picker button:hover {
    transform: scale(1.3);
    background: rgba(255,255,255,0.1);
}

.reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.8rem;
    margin-top: 4px;
    cursor: pointer;
}
.reaction-chip.user-reacted {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--primary);
}

/* --- Toast Notifications --- */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: white;
    padding: 0.8rem 2rem;
    border-radius: var(--radius-full);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 2000;
    font-weight: 500;
    translate: 0 20px; /* Slide up effect */
}

.toast.show {
    opacity: 1;
    translate: 0 0;
}

.toast.level-up {
    background: linear-gradient(135deg, var(--gold), var(--primary));
    box-shadow: 0 10px 30px rgba(234, 179, 8, 0.4);
}


/* --- Modals --- */
.confirmation-modal, 
#emailLoginModal, 
#accountModal, 
#profileModal, 
#inboxModal, 
#adminPollModal, 
#summariesModal,
#dmModal,
#adminMessageModal {
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    color: var(--text-main);
    padding: 20px; /* Reset padding for flex layout */
    overflow: hidden;
    
    /* CRITICAL FIX: Ensure modals are hidden by default but properly positioned */
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000; /* Ensure they are above everything */
}

/* SHOW Modals when active */
.confirmation-modal.active, 
#emailLoginModal.active, 
#accountModal.active, 
#profileModal.active, 
#inboxModal.active, 
#adminPollModal.active, 
#summariesModal.active,
#dmModal.active,
#adminMessageModal.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

#accountModal, #profileModal, #inboxModal {
    width: 800px;
    max-width: 95vw;
    max-height: 85vh;
}

.modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2);
}

.modal-tab-btn {
    flex: 1;
    padding: 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.modal-tab-btn:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.02);
}

.modal-tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

/* --- CRITICAL FIX: Display content correctly --- */
.modal-tab-content {
    display: none; /* Hidden by default */
}

.modal-tab-content.active {
    display: block; /* Shown when active */
}

.modal-scrollable-content {
    padding: 2rem;
    overflow-y: auto;
    flex: 1;
}

.modal-buttons {
    padding: 1rem 2rem;
    border-top: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* --- Lists (Inbox, Social, Leaderboard) --- */
.inbox-item, .social-list-item, .leaderboard-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s;
}

/* --- FIX: Add style for read inbox items --- */
.inbox-item.read {
    opacity: 0.6;
    background: rgba(255, 255, 255, 0.01);
}

.inbox-item:hover, .social-list-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255,255,255,0.1);
}

/* --- Badges --- */
.badges-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
}
.badge {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1rem;
    text-align: center;
    position: relative;
    cursor: help;
    transition: transform 0.2s;
}
.badge:hover {
    transform: translateY(-3px);
    border-color: var(--secondary);
}
.badge-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.badge-name { font-size: 0.8rem; font-weight: 600; }

/* --- Tree Visualization --- */
#treePageContainer {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--bg-dark);
    z-index: 500;
    display: none; /* Controlled by JS */
    flex-direction: column;
}
#tree-content-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.tree-explorer-header {
    padding: 1rem 2rem;
    background: var(--glass-bg);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    gap: 1rem;
    align-items: center;
}
.tree-explorer-body {
    flex: 1;
    position: relative;
    display: flex;
}
/*
#tree-container {
    flex: 1;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
}
#tree-info-panel {
    width: 450px;
    background: var(--glass-bg);
    border-left: 1px solid var(--glass-border);
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    overflow-y: auto;
}
*/

#tree-container {
    flex: 1;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    position: relative;
    min-width: 0; /* Allow shrinking in flex container */
    min-height: 0; /* Allow shrinking in flex container */
}

#tree-info-panel {
    width: 450px;
    background: var(--glass-bg);
    border-left: 1px solid var(--glass-border);
    padding: 1.5rem;
    backdrop-filter: blur(20px);
    overflow-y: auto;
    /* Ensure it fills height on desktop but doesn't overflow parent */
    height: 100%; 
    flex-shrink: 0;
}

/* --- NEW: Tree Status Styles --- */
.tree-status-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-left: 1rem;
    margin-right: auto;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.tree-status-text {
    font-size: 0.85rem;
    opacity: 0.8;
}

.icon-btn {
    padding: 0.4rem;
    width: 32px;
    height: 32px;
    font-size: 1.2rem;
    line-height: 1;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.refreshing {
    animation: spin 1s linear infinite;
    pointer-events: none;
    opacity: 0.7;
}

@keyframes spin { 
    100% { transform: rotate(360deg); } 
}

/* --- NEW: Tree Visualization Enhancements --- */

/* 1. Improved Link Styling */
.tree-link {
    stroke: rgba(255, 255, 255, 0.15); /* Slightly brighter for better visibility */
    stroke-width: 1.5px;
    transition: stroke 0.3s, stroke-width 0.3s;
    pointer-events: none; /* Let clicks pass through to background/nodes */
}
.tree-link.active-path {
    stroke: var(--accent);
    stroke-width: 2.5px;
    stroke-opacity: 0.8;
    filter: drop-shadow(0 0 3px var(--accent));
    z-index: 10; /* Keep above other links */
}

/* 2. Improved Node Groups */
.tree-node-group {
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); /* Smooth pop effect */
}

/* 3. Node Circle Styling */
.tree-node-group circle {
    stroke: rgba(255, 255, 255, 0.5);
    stroke-width: 1.5px;
    transition: all 0.3s ease;
    transform-box: fill-box;
    transform-origin: center;
}

/* Hover Effect: Pop, glow, brighten */
.tree-node-group:hover circle {
    transform: scale(1.2);
    stroke: #fff;
    stroke-width: 2px;
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.6));
    fill-opacity: 1;
}

/* Selected Node Styling */
.tree-node-group circle.selected-node {
    stroke: var(--accent);
    stroke-width: 3px;
    filter: drop-shadow(0 0 15px var(--accent));
    fill: var(--primary) !important; /* Override D3 fill if needed for emphasis */
    transform: scale(1.25);
}

/* 4. Text Styling */
.tree-node-group text {
    font-family: 'Inter', sans-serif;
    font-weight: 500;
    fill: #e2e8f0 !important; /* Ensure readable light text */
    text-shadow: 
        -1px -1px 0 rgba(0,0,0,0.8),  
         1px -1px 0 rgba(0,0,0,0.8),
        -1px  1px 0 rgba(0,0,0,0.8),
         1px  1px 0 rgba(0,0,0,0.8), /* Strong dark outline for contrast */
         0 2px 4px rgba(0,0,0,0.5);
    pointer-events: none;
    transition: font-weight 0.2s, fill 0.2s;
}

.tree-node-group:hover text {
    font-weight: 700;
    fill: #fff !important;
}

/* 5. Search Highlighting */
.tree-node-group.search-match circle {
    stroke: var(--success);
    stroke-width: 3px;
    animation: pulseSearch 1.5s infinite;
}
.tree-node-group.search-no-match {
    opacity: 0.15;
}

@keyframes pulseSearch {
    0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* --- Glows --- */
.glow {
    position: fixed;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--primary), transparent 70%);
    filter: blur(80px);
    opacity: 0.15;
    pointer-events: none;
    z-index: -1;
}

/* --- Direct Messages Styling --- */
.dm-message {
    padding: 0.8rem 1.2rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 75%;
    word-wrap: break-word;
    margin-bottom: 0.5rem;
    animation: messagePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dm-message.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.dm-message.received {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes messagePop {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .title { font-size: 3rem; }
    #chatroomContainer { height: 100vh; border-radius: 0; border: none; }
    .container { padding: 0; }
    #accountModal, #profileModal, #inboxModal { width: 100%; height: 100%; border-radius: 0; }
    .message-wrapper { max-width: 85%; }
    .auth-buttons { top: 1rem; right: 1rem; }
    #tree-info-panel { position: absolute; bottom: 0; left: 0; width: 100%; height: 40%; border-top: 1px solid var(--glass-border); border-left: none; }

    /* --- Tree Explorer Mobile Fixes --- */
    .tree-explorer-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.8rem;
    }
    .tree-explorer-header h2 {
        font-size: 1rem;
        margin-right: auto;
    }
    .tree-status-group {
        display: none; /* Hide 'Just now' text on very small screens to save space */
    }
    #tree-search-input {
        width: 100%;
        margin-top: 0.5rem;
        order: 5; /* Push search to new line */
    }
    
    .tree-explorer-body {
        flex-direction: column; /* Stack map on top of info panel */
    }

    #tree-container {
        flex: 1 1 auto; /* Map takes all available remaining space */
        width: 100%;
        min-height: 0;
        position: relative;
        order: 1; /* Ensure Map is visual first */
    }

    #tree-info-panel {
        width: 100%;
        height: auto;
        flex: 0 0 70%; /* Fixed height at bottom */
        position: relative; 
        border-left: none;
        border-top: 1px solid var(--glass-border);
        padding: 1rem;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
        z-index: 10;
        border-radius: 20px 20px 0 0;
        background: rgba(15, 23, 42, 0.98);
        order: 2; /* Panel below map */
    }
    
    .hamburger-btn {
        display: flex; /* Show hamburger on mobile */
    }
    
    .mobile-menu {
        display: none; /* Hide menu by default on mobile */
        position: absolute;
        top: 100%;
        right: 0;
        background: rgba(15, 23, 42, 0.95);
        border: 1px solid var(--glass-border);
        padding: 1rem;
        flex-direction: column; /* Stack items vertically */
        width: 200px; /* Optional: fix width or let it content-size */
        align-items: stretch; /* Stretch buttons to full width */
        border-radius: var(--radius-md);
    }
    .mobile-menu.active {
        display: flex;
    }
    
    .mobile-menu .btn {
        justify-content: flex-start; /* Align button text to left */
    }

    /* Hide Room Name, Status and adjacent separators on mobile */
    #roomIdDisplay,
    #roomIdDisplay + span,
    #roomStatusText,
    #roomStatusText + span {
        display: none;
    }

    /* Force hide simulate join button on mobile */
    #simulateJoinBtn {
        display: none !important;
    }

    /* ADDED: Spacing for mobile header elements to avoid overlap and align vertically */
    .participant-count {
        margin-top: 4rem;
    }

    /* Fix alignment in chatroom header */
    #chatroomHeader {
        align-items: flex-start;
    }

    /* Align Chatroom User Count and Summaries Button */
    .chatroom-header-info,
    #summariesBtn {
        margin-top: 4rem;
    }
    
    /* Ensure Toggle button aligns if visible */
    #toggleChatInquiryBtn {
        margin-top: 4rem;
    }

    /* --- NEW: Shorten Tree Header Text on Mobile --- */
    .tree-explorer-header h2 {
        font-size: 0 !important; /* Hide 'Discussion Map' */
        margin-right: auto;
        display: flex;
        align-items: center;
    }
    .tree-explorer-header h2::after {
        content: 'Map'; /* Replace with 'Map' */
        font-size: 1rem;
    }
}

/* --- FIX: Add styles for inbox indicator --- */
#inboxBtn {
    position: relative;
}

#inbox-indicator {
    display: none; /* Toggled by JS */
    position: absolute;
    top: 5px;
    right: 5px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--danger);
    box-shadow: 0 0 5px var(--danger);
    z-index: 10;
}

/* --- NEW: Inquiry View Styles --- */
.suggested-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.suggested-item:hover {
    background: rgba(255, 255, 255, 0.06);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.suggested-item.user-suggestion {
    border-color: var(--primary);
    background: linear-gradient(to bottom right, rgba(99, 102, 241, 0.05), rgba(255, 255, 255, 0.02));
}

.suggestion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.own-tag {
    background: var(--primary);
    color: white;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
}

.suggestion-question {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-main);
    line-height: 1.4;
}

.suggested-answers {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.suggested-answers li {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    padding: 0.3rem 0.8rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.suggestion-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.vote-count-badge {
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.vote-suggestion-btn {
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
}

.vote-suggestion-btn.voted {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.pop-pref-vote-btn.selected-pop-vote {
    background-color: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.4);
    transform: translateY(-2px);
}