:root {
    --bg-color: #121212;
    --glass-bg: rgba(42, 42, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent: #7B5693;
    --accent-glow: rgba(123, 86, 147, 0.4);
    --text-main: #AAAAAA;
    --text-bright: #E1E1E1;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Background Animated Blobs */
.background-blobs {
    position: fixed;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    filter: blur(100px);
}

.blob {
    position: absolute;
    border-radius: 50%;
    animation: float 20s infinite ease-in-out alternate;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: #1E1E1E;
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 500px;
    height: 500px;
    background: rgba(123, 86, 147, 0.15);
    bottom: -150px;
    right: -100px;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(100px, 150px) scale(1.2); }
}

@keyframes subtle-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

@keyframes indeterminate-slide {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(0%); }
    100% { transform: translateX(100%); }
}

/* Glassmorphism Container */
.glass-container {
    box-sizing: border-box;
    width: 96%;
    max-width: 1800px; /* Massively expanded to allow large video */
    height: calc(100vh - 60px); /* Uniform top and bottom outer padding */
    max-height: calc(100vh - 60px);
    overflow-y: auto; /* Let internal elements scroll if screen is too small */
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 30px;
    transition: all 0.4s ease;
}

/* Custom Scrollbar for container */
.glass-container::-webkit-scrollbar {
    width: 8px;
}
.glass-container::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05); 
    border-radius: 4px;
}
.glass-container::-webkit-scrollbar-thumb {
    background: var(--glass-border); 
    border-radius: 4px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--accent);
    margin-bottom: 20px;
}

.avatar-picker-grid {
    display: grid;
    grid-template-columns: repeat(4, auto);
    gap: 16px;
    margin-bottom: 25px;
    justify-content: center;
}

.avatar-option {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    object-fit: cover;
}

.avatar-option:hover {
    transform: scale(1.1);
}

.avatar-option.selected {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
    transform: scale(1.1);
}

.btn-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

h1 {
    margin: 0;
    color: var(--text-bright);
    font-weight: 600;
    font-size: 2rem;
}

h1 span {
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent-glow);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px; /* Increased padding */
    border-radius: 20px;
    font-size: 0.95rem; /* Slightly larger text */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    background: rgba(255,255,255,0.1);
}

.status-badge .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
}

.status-badge.waiting { color: #FFA000; background: rgba(255, 160, 0, 0.1); border: 1px solid rgba(255, 160, 0, 0.3); }
.status-badge.connecting { color: #3498db; background: rgba(52, 152, 219, 0.1); border: 1px solid rgba(52, 152, 219, 0.3); }
.status-badge.playing { color: #4CAF50; background: rgba(76, 175, 80, 0.1); border: 1px solid #4CAF50; box-shadow: 0 0 10px rgba(76, 175, 80, 0.4); }
.status-badge.error { color: #e74c3c; background: rgba(231, 76, 60, 0.1); border: 1px solid rgba(231, 76, 60, 0.3); }

/* --- HEADER IDENTITY & DROPDOWN --- */
.header-separator {
    width: 2px;
    height: 30px;
    background: var(--glass-border);
    margin: 0 10px;
}

.user-profile-container {
    position: relative;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    border: 1px solid transparent;
    padding: 6px 16px 6px 6px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: none;
}

.user-profile-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--glass-border);
    transform: none;
    box-shadow: none;
}

.user-profile-btn:active {
    transform: scale(0.97);
}

.user-avatar-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--accent);
}

#user-display-name {
    color: var(--text-bright);
    font-size: 1.05rem;
    font-weight: 500;
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 220px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    transform-origin: top right;
    transition: opacity 0.2s, transform 0.2s;
}

.profile-dropdown.hidden {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
    display: flex !important; /* Override standard .hidden so transitions work */
}

.dropdown-item {
    padding: 16px 20px;
    color: var(--text-bright);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.dropdown-item.highlight {
    color: var(--accent);
    border-top: 1px solid var(--glass-border);
}

.dropdown-item.highlight:hover {
    background: rgba(123, 86, 147, 0.2);
}

/* --- EDIT NAME MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: flex !important; /* Keep it flex to transition out smoothly */
}

.modal-content {
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 30px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.9);
}

.modal-content h3 {
    margin: 0 0 10px 0;
    font-size: 1.5rem;
    color: var(--text-bright);
}

.modal-content p {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 20px;
}

.premium-input {
    width: 100%;
    box-sizing: border-box;
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-bright);
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    outline: none;
    text-align: left !important;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.premium-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 15px var(--accent-glow);
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 25px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--glass-border);
}

.auth-divider span {
    padding: 0 10px;
}

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: #fff;
    color: #3c4043;
    border: none;
    padding: 15px 20px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn-google:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-bright);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: none;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--accent);
    border: none;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(123, 86, 147, 0.4);
}

.btn-primary:hover {
    background: #8b64a4;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(123, 86, 147, 0.6);
}

.btn-danger {
    background: #E63946;
    border: none;
    color: #fff;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 1rem;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(230, 57, 70, 0.4);
}

.btn-danger:hover {
    background: #f04753;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(230, 57, 70, 0.6);
}

/* --- HERO & DUAL-ACTION HOMEPAGE --- */
.hero-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 60px 20px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
    position: relative;
}

.hero-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, rgba(123, 86, 147, 0.15) 0%, rgba(102, 252, 241, 0.05) 40%, transparent 70%);
    z-index: -1;
    pointer-events: none;
}

.hero-hook {
    text-align: center;
    margin-bottom: 50px;
}

.hero-hook h2 {
    font-size: 3.5rem;
    font-weight: 700;
    margin: 0 0 10px 0;
    color: var(--text-bright);
    letter-spacing: -1px;
}

.hero-hook p {
    font-size: 1.25rem;
    color: var(--text-muted);
    margin: 0;
}

.action-cards-wrapper {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 30px;
    width: 100%;
}

.action-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 40px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.action-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(255,255,255,0.1);
}

.card-icon {
    font-size: 3rem;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 15px rgba(255,255,255,0.2));
}

.action-card h3 {
    font-size: 1.75rem;
    color: var(--text-bright);
    margin: 0 0 15px 0;
}

.action-card p {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin: 0 0 30px 0;
    line-height: 1.5;
    flex-grow: 1;
}

.input-group {
    display: flex;
    flex-direction: column; /* Stack input and button vertically in card */
    gap: 15px;
    width: 100%;
}

input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.3);
    color: var(--text-bright);
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    outline: none;
    transition: border-color 0.3s;
    text-align: center;
}

input[type="text"]:focus {
    border-color: var(--accent);
}

.btn-solid {
    width: 100%;
    padding: 15px 30px;
    border-radius: 12px;
    border: none;
    background: rgba(255,255,255,0.1);
    color: var(--text-bright);
    font-size: 1.1rem;
    font-weight: 600;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    border: 1px solid rgba(255,255,255,0.1);
}

.btn-solid:hover {
    background: rgba(255,255,255,0.15);
    transform: translateY(-2px);
}

.btn-solid:active {
    transform: translateY(0);
}

.btn-gradient {
    width: 100%;
    padding: 15px 30px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--accent) 0%, #a881c2 100%);
    color: #000;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 0 20px rgba(123, 86, 147, 0.5);
    margin-top: auto;
}

.btn-gradient:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(123, 86, 147, 0.8);
}

.btn-gradient:active {
    transform: translateY(0);
}

.hidden {
    display: none !important;
}

main {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#room-content {
    display: flex;
    gap: 20px;
    width: 100%;
    align-items: stretch;
    flex: 1; /* Allow content area to fill vertical space */
    min-height: 0;
}

/* Fullscreen mode for room-content (Wraps Video + Chat) */
#room-content:fullscreen {
    background-color: #000;
    padding: 0;
    margin: 0;
    width: 100vw;
    height: 100vh;
    gap: 0;
}

#room-content:fullscreen #video-wrapper {
    margin: 0;
    padding: 0;
    height: 100vh;
    justify-content: center;
    background: #000;
    flex: 1;
    position: relative; /* Required for absolute positioning of overlays */
}

/* Make the video info an elegant overlay instead of pushing the video down */
#room-content:fullscreen .video-info {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    pointer-events: none; /* Let clicks pass through empty space to the video */
}

#room-content:fullscreen #video-title {
    pointer-events: auto; /* Re-enable clicks for the element itself */
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#room-content:fullscreen .stats {
    pointer-events: auto; /* Re-enable clicks for the element itself */
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    margin-right: 60px; /* Safely push it to the left of the fullscreen button to prevent overlap */
}

#room-content:fullscreen #video-container {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#room-content:fullscreen #player {
    max-height: 100vh;
    max-width: 100%;
    border-radius: 0;
}

#room-content:fullscreen #chat-sidebar {
    height: 100vh;
    border-radius: 0;
    border: none;
    border-left: 1px solid rgba(255,255,255,0.1);
    background: #0f0f14; /* Darker background to not distract from video */
    margin: 0;
    max-height: 100vh;
}

#video-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-height: 0;
}

.video-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px; /* Increased gap from 10px to create visual zones */
    margin-bottom: 5px;
}

#video-title {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text-bright);
}

.stats {
    display: flex;
    gap: 15px;
    font-size: 0.95rem;
    background: rgba(0,0,0,0.4);
    padding: 10px 20px; /* Increased padding to let badges breathe */
    border-radius: 12px;
}

#video-container {
    width: 100%;
    flex: 1; /* Fill remaining vertical space in wrapper */
    min-height: 0; /* Let it shrink indefinitely so it never overflows the container */
    border-radius: 16px;
    overflow: hidden;
    background: #000;
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center; /* Keep video perfectly centered vertically */
}

#video-container video {
    width: 100%;
    height: 100%; /* perfectly fill the container */
    object-fit: contain; /* Keep aspect ratio perfectly */
    display: block;
    outline: none;
    accent-color: var(--accent); /* Brand the HTML5 native progress bar and playhead! */
}

/* --- FULLSCREEN FIXES --- */
/* When the container goes fullscreen, override constraints to fill the screen */
#video-container:-webkit-full-screen {
    border-radius: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}
#video-container:-webkit-full-screen video {
    max-height: 100vh !important;
    height: 100vh !important;
}
#video-container:fullscreen {
    border-radius: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
}
#video-container:fullscreen video {
    max-height: 100vh !important;
    height: 100vh !important;
}

/* Hide native fullscreen buttons so they don't break our overlay */
video::-webkit-media-controls-fullscreen-button {
    display: none !important;
}
video::-moz-full-screen-button {
    display: none !important;
}

/* Premium Custom Fullscreen Button */
#custom-fs-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 100;
    transition: background 0.2s, transform 0.2s;
    opacity: 0; /* Hidden by default */
}

#video-container:hover #custom-fs-btn {
    opacity: 1; /* Fade in on hover */
}

#custom-fs-btn:hover {
    background: rgba(102, 252, 241, 0.3);
    transform: scale(1.1);
}

@media (max-width: 600px) {
    .input-group {
        flex-direction: column;
    }
    header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    .video-info {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* Premium Pill Gesture Overlay (iOS Style) */
#gesture-overlay {
    position: absolute; /* Confined to the video container */
    top: 30px; /* Top padding inside the video player */
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: auto;
    height: auto;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 9999;
    display: flex;
    flex-direction: row; /* Horizontal layout */
    justify-content: center;
    align-items: center;
    padding: 12px 24px;
    border-radius: 50px; /* Pill shape */
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#gesture-overlay.active {
    opacity: 1;
    transform: translateX(-50%) translateY(0); /* Slide down smoothly */
}

.gesture-icon {
    font-size: 1.5rem;
    margin-bottom: 0;
    margin-right: 15px;
    filter: drop-shadow(0 0 10px var(--accent-glow));
    transition: transform 0.1s;
    line-height: 1;
}

.gesture-bar-container {
    width: 150px;
    height: 6px;
    background: rgba(255,255,255,0.15);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0;
    margin-right: 15px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

.gesture-bar-fill {
    height: 100%;
    width: 100%;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    transition: width 0.1s ease;
}

.gesture-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-bright);
    letter-spacing: 0.5px;
    min-width: 45px; /* Prevent pill width jittering */
    text-align: right;
}

/* =========================================
   CHAT UI STYLES
   ========================================= */

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s, box-shadow 0.3s;
    position: relative;
    color: var(--text-bright);
}

.unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #e74c3c;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
    z-index: 10;
    box-sizing: border-box;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
}

.chat-sidebar {
    width: 350px;
    background: #0B0C10;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255,255,255,0.05);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    overflow: hidden;
    transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease, margin 0.5s cubic-bezier(0.2, 0.8, 0.2, 1), border-width 0.4s ease;
}

.chat-sidebar.hidden {
    display: flex !important; /* Override global display: none */
    width: 0;
    opacity: 0;
    border-width: 0;
    margin-left: -20px; /* Instantly negate the gap from #room-content so video player slides flush right */
}

.chat-header {
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(26,26,26,1) 0%, rgba(10,10,10,1) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.chat-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #fff;
    font-weight: 600;
}

#chat-close-btn {
    cursor: pointer;
    color: rgba(255,255,255,0.5);
    transition: color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
}

#chat-close-btn:hover {
    color: #fff;
    transform: scale(1.1);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    /* gap: 15px; REMOVED FOR CLUSTERING */
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}

.chat-bubble-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 90%;
    margin-bottom: 15px; /* Default spacing between different senders */
}

.chat-bubble-container.clustered {
    margin-bottom: 4px; /* Tighter grouping for the same person */
}

.chat-bubble-container.mine {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-sender {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 3px;
    margin-left: 5px;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    background: #2A2D34;
    color: #fff;
    font-size: 0.95rem;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

.chat-bubble-container.mine .chat-bubble {
    background: linear-gradient(135deg, var(--accent), #5a3d6d); /* Brand gradient */
    color: #fff;
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.chat-bubble-container.mine.clustered .chat-bubble {
    border-top-right-radius: 4px;
}

.chat-bubble-container:not(.mine) .chat-bubble {
    border-bottom-left-radius: 4px;
}

.chat-bubble-container:not(.mine).clustered .chat-bubble {
    border-top-left-radius: 4px;
}

.chat-input-area {
    padding: 15px;
    background: #1A1A24;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    min-height: 80px; /* Ensure space for overlay */
}


.chat-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.emoji-dock {
    display: flex;
    gap: 15px;
    justify-content: space-around;
    background: rgba(255,255,255,0.05);
    padding: 8px 12px;
    border-radius: 20px;
    margin-bottom: 5px;
}

.emoji-reaction {
    font-size: 1.3rem;
    cursor: pointer;
    transition: transform 0.2s;
    user-select: none;
}

.emoji-reaction:hover {
    transform: scale(1.3);
}

.chat-input-wrapper {
    width: 100%;
}

#chat-input {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    padding: 12px 16px;
    border-radius: 20px;
    outline: none;
    font-size: 0.95rem;
    font-family: inherit;
    text-align: left; /* Overrides global input center alignment */
    transition: border-color 0.3s, box-shadow 0.3s;
}

#chat-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.chat-anchor-pill {
    position: sticky;
    bottom: 10px;
    margin: 0 auto;
    background: var(--accent);
    color: var(--bg-deep);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 10;
    width: max-content;
}

/* =========================================
   FULL SCREEN GHOST OVERLAY STYLES
   ========================================= */

#video-container:fullscreen #chat-sidebar,
#video-container:-webkit-full-screen #chat-sidebar {
    position: absolute;
    top: 20px;
    right: 20px;
    bottom: 20px;
    height: calc(100% - 100px); /* Leave room for video controls */
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 50;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#video-container:fullscreen #chat-sidebar.idle-fade,
#video-container:-webkit-full-screen #chat-sidebar.idle-fade {
    opacity: 0 !important;
    pointer-events: none;
}

/* Wake Up Trigger for messages when chat is faded out */
.chat-wake-up {
    opacity: 1 !important;
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-color: transparent !important;
}

.chat-wake-up .chat-header,
.chat-wake-up .chat-input-area {
    opacity: 0 !important;
    pointer-events: none;
}

.chat-wake-up .chat-bubble-container {
    opacity: 0;
}

.chat-wake-up .chat-bubble-container:last-child {
    animation: wake-up-flash 5s ease forwards;
}

@keyframes wake-up-flash {
    0% { opacity: 0; transform: translateY(10px); }
    10% { opacity: 1; transform: translateY(0); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

/* =========================================
   EMOJI PARTICLE SYSTEM
   ========================================= */

.emoji-particle {
    position: absolute;
    bottom: 80px; /* start above native controls */
    right: 50px;
    font-size: 2rem;
    pointer-events: none;
    z-index: 100;
    animation: float-up 3s ease-out forwards;
    filter: drop-shadow(0 0 5px rgba(0,0,0,0.5));
    will-change: transform, opacity;
}

@keyframes float-up {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(-200px) scale(1.5) rotate(var(--rot, 0deg));
    }
}

/* =========================================
   SHORTCUTS MODAL
   ========================================= */

.shortcuts-grid {
    display: flex;
    flex-direction: column;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.05);
    overflow: hidden;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    color: var(--text-bright);
    font-size: 0.95rem;
}

kbd {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 6px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--premium-accent);
    box-shadow: 0 2px 0 rgba(0,0,0,0.3);
    min-width: 24px;
    display: inline-block;
    text-align: center;
}

/* =========================================
   FLOATING STATUS PILL
   ========================================= */

.floating-pill {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
    font-size: 0.95rem;
    font-weight: 500;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.floating-pill.hidden {
    display: none;
}

.floating-pill.pill-fade-in {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.floating-pill.pill-fade-out {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
}

.pill-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--premium-accent);
}

.pill-spinner {
    animation: spin 1.5s linear infinite;
}
