/* ==========================================================================
   LinkStream CSS - Premium Dark Glassmorphism Design
   ========================================================================== */

/* Design Tokens & Theme Variables */
:root {
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    /* Sleek Cyber/Indigo Palette */
    --bg-base: #090d16;
    --panel-bg: rgba(15, 23, 42, 0.55);
    --panel-border: rgba(255, 255, 255, 0.08);
    --panel-glow: rgba(99, 102, 241, 0.15);
    
    /* Primary Colors */
    --color-primary: #6366f1;         /* Indigo */
    --color-primary-hover: #4f46e5;
    --color-secondary: #a855f7;       /* Purple */
    --color-accent: #06b6d4;          /* Cyan */
    --color-accent-glow: rgba(6, 182, 212, 0.3);
    
    /* Functional Colors */
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dark: #64748b;
    
    /* UI Dimensions */
    --header-height: 70px;
    --footer-height: 80px;
    --sidebar-width: 360px;
    --border-radius-lg: 24px;
    --border-radius-md: 16px;
    --border-radius-sm: 8px;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Resets & Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-sans);
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    overflow: hidden;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 900px) {
    html,
    body {
        touch-action: pan-x pan-y;
    }
}

/* Ambient Background Lights */
.glow-bg {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    overflow: hidden;
}

.glow-bg .shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.4;
    animation: floatGlow 15s infinite alternate;
}

.glow-bg .shape-1 {
    top: -10%;
    left: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, var(--color-primary) 0%, transparent 70%);
}

.glow-bg .shape-2 {
    bottom: -15%;
    right: -10%;
    width: 55vw;
    height: 55vw;
    background: radial-gradient(circle, var(--color-secondary) 0%, transparent 70%);
    animation-delay: -5s;
}

@keyframes floatGlow {
    0% {
        transform: translate(0, 0) scale(1);
    }
    100% {
        transform: translate(8%, 5%) scale(1.15);
    }
}

/* Utility Styles & Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Glassmorphism Panel Template */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--panel-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border-radius: var(--border-radius-lg);
    display: none;
    transition: var(--transition-smooth);
}

.glass-panel.active {
    display: flex;
}

/* ==========================================================================
   Lobby Styling (Setup Screen)
   ========================================================================== */
#lobby-container {
    display: none;
    width: 100vw;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    position: fixed;
    top: 0;
    left: 0;
    background: #0a0e1a;
    z-index: 100;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.5s ease-out;
}

#lobby-container.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lobby-centered {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 380px;
    padding: 40px 28px;
}

/* Badge Logo */
.lobby-logo {
    margin-bottom: 24px;
}

.lobby-logo-img {
    width: 100px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 20px rgba(200, 170, 80, 0.25));
}

/* Title */
.lobby-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #f0f0f0;
    text-align: center;
    margin-bottom: 36px;
    letter-spacing: 2px;
}

/* Form */
.lobby-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
}

.lobby-form input[type="text"] {
    width: 100%;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: #f0f0f0;
    font-size: 1rem;
    font-family: var(--font-sans);
    outline: none;
    transition: var(--transition-smooth);
}

.lobby-form input[type="text"]::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.lobby-form input[type="text"]:focus {
    border-color: rgba(200, 170, 80, 0.5);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 3px rgba(200, 170, 80, 0.12);
}

/* Join Button */
.lobby-join-btn {
    width: 100%;
    padding: 15px 24px;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1rem;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-smooth);
    letter-spacing: 1px;
}

.lobby-join-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(200, 170, 80, 0.4);
}

.lobby-join-btn:active {
    transform: scale(0.98);
}

/* Responsive Lobby */
@media (max-width: 768px) {
    .lobby-centered {
        padding: 32px 24px;
        max-width: 340px;
    }
    .lobby-logo-img {
        width: 80px;
    }
    .lobby-title {
        font-size: 1.3rem;
    }
}

/* Mobile participant visibility */
.member-count-badge {
    min-height: 32px;
    padding: 5px 10px;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    font: inherit;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.member-count-badge:hover,
.member-count-badge[aria-expanded="true"] {
    border-color: rgba(34, 211, 238, 0.42);
    background: rgba(34, 211, 238, 0.1);
    color: var(--text-main);
}

.member-count-badge i {
    width: 15px;
    height: 15px;
    color: var(--color-accent);
}

.member-count-badge .member-count-chevron {
    width: 13px;
    height: 13px;
    color: currentColor;
    transition: transform 0.2s ease;
}

.member-count-badge[aria-expanded="true"] .member-count-chevron {
    transform: rotate(180deg);
}

.room-header { position: relative; }

.member-panel[hidden] { display: none; }

.member-panel {
    position: absolute;
    top: calc(100% - 6px);
    right: 18px;
    z-index: 1200;
    display: flex;
    width: min(360px, calc(100vw - 32px));
    max-height: min(480px, calc(100vh - 150px));
    overflow: hidden;
    flex-direction: column;
    border-radius: 18px;
    background: rgba(8, 14, 24, 0.96);
    box-shadow: 0 20px 55px rgba(0, 0, 0, 0.48);
}

.member-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 16px 12px;
    border-bottom: 1px solid var(--panel-border);
}

.member-panel-header > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.member-panel-header strong { font-size: 0.95rem; }
.member-panel-header span { color: var(--text-muted); font-size: 0.72rem; }

.member-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    list-style: none;
}

.member-item {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    align-items: center;
    gap: 11px;
    min-height: 60px;
    padding: 8px 10px;
    border-radius: 12px;
}

.member-item:hover { background: rgba(255, 255, 255, 0.045); }

.member-avatar {
    width: 42px;
    height: 42px;
    border: 1px solid rgba(34, 211, 238, 0.3);
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.42), rgba(6, 182, 212, 0.25));
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 0.9rem;
    font-weight: 700;
}

.member-details { min-width: 0; }

.member-name-row {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.member-name {
    overflow: hidden;
    color: var(--text-main);
    font-size: 0.86rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-self-tag {
    flex-shrink: 0;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
    font-size: 0.62rem;
}

.member-connection {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 0.68rem;
}

.member-connection-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #f59e0b;
}

.member-connection.connected .member-connection-dot { background: var(--color-success); }
.member-connection.problem .member-connection-dot { background: var(--color-danger); }

.member-device-status {
    display: flex;
    gap: 6px;
}

.member-device-icon {
    width: 29px;
    height: 29px;
    border-radius: 9px;
    background: rgba(16, 185, 129, 0.1);
    color: #6ee7b7;
    display: grid;
    place-items: center;
}

.member-device-icon.off {
    background: rgba(239, 68, 68, 0.12);
    color: #fca5a5;
}

.member-device-icon svg { width: 14px; height: 14px; }

@media (max-width: 768px) {
    .member-count-badge {
        margin-left: auto;
        min-height: 30px;
        padding: 4px 9px;
        background: rgba(34, 211, 238, 0.08);
        color: #d8f8ff;
    }

    .member-panel {
        top: calc(100% - 2px);
        left: 8px;
        right: 8px;
        width: auto;
        max-height: min(380px, calc(100dvh - 150px));
    }

    .room-info {
        width: 100%;
        min-width: 0;
        gap: 8px;
    }

    .video-grid-container.multi-layout {
        align-items: flex-start;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    #video-grid.multi {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: minmax(165px, 34vh);
        align-content: start;
        height: auto;
        min-height: 100%;
        gap: 8px;
    }

    #video-grid.multi .video-card {
        width: 100%;
        height: 100%;
        min-height: 165px;
        aspect-ratio: auto;
        border-radius: 13px;
    }

    #video-grid.multi .video-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        max-height: 38vh;
    }

    #video-grid.multi .video-card video,
    #video-grid.double .video-card:not(.local) video {
        object-fit: cover;
    }

    #video-grid.multi .video-overlay {
        padding: 8px;
    }

    #video-grid.multi .username-tag {
        max-width: calc(100% - 4px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.72rem;
        background: rgba(0, 0, 0, 0.72);
    }

    #video-grid.multi .mic-status-icon {
        width: 25px;
        height: 25px;
    }
}

/* ========================================================================== 
   2026 Room UI refinement: video-first layout, touch and accessibility
   ========================================================================== */
:root {
    --bg-base: #070b12;
    --panel-bg: rgba(11, 18, 30, 0.9);
    --panel-border: rgba(148, 163, 184, 0.14);
    --color-primary: #3b82f6;
    --color-primary-hover: #2563eb;
    --color-accent: #22d3ee;
    --sidebar-width: 380px;
}

button,
input {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(34, 211, 238, 0.72);
    outline-offset: 3px;
}

.lobby-centered {
    background: linear-gradient(145deg, rgba(20, 30, 48, 0.88), rgba(9, 14, 24, 0.94));
    border: 1px solid var(--panel-border);
    border-radius: 28px;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45), inset 0 1px rgba(255, 255, 255, 0.04);
}

#room-container {
    max-width: 1680px;
    max-height: 960px;
}

.room-header,
.room-footer {
    flex-shrink: 0;
    background: rgba(7, 12, 21, 0.72);
}

.video-grid-container {
    padding: 18px;
    overflow: hidden;
    background: radial-gradient(circle at 50% 35%, rgba(59, 130, 246, 0.09), transparent 56%);
}

.video-card {
    background: #02050a;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
}

.video-overlay {
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.42), transparent 38%, transparent 62%, rgba(0, 0, 0, 0.64));
}

#sidebar {
    background: rgba(8, 14, 24, 0.88);
}

.sidebar-header {
    min-height: 58px;
}

#chat-messages {
    gap: 14px;
}

.msg-bubble {
    word-break: break-word;
    overflow-wrap: anywhere;
}

.chat-msg.sent .msg-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
}

.chat-input-area {
    background: rgba(7, 12, 21, 0.92);
}

.input-actions {
    min-height: 48px;
}

.control-toolbar {
    background: rgba(15, 23, 42, 0.92);
}

@media (max-width: 1100px) and (min-width: 769px) {
    :root {
        --sidebar-width: 320px;
    }

    #video-grid {
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    }

    .control-toolbar {
        gap: 10px;
        padding-inline: 18px;
    }
}

@media (max-width: 768px) {
    .room-header {
        height: calc(58px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 14px 0;
    }

    .room-header .logo h2,
    .room-info .divider,
    .room-id-badge > span,
    .room-meta {
        display: none;
    }

    .room-id-badge {
        max-width: calc(100vw - 80px);
    }

    #room-id-display {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #sidebar {
        background: rgba(7, 12, 21, 0.98);
    }

    .sidebar-header {
        padding-top: calc(14px + env(safe-area-inset-top));
    }

    .video-grid-container {
        padding: 8px;
    }

    #video-grid.double .video-card.local {
        top: 12px;
        right: 12px;
        width: clamp(92px, 27vw, 120px);
        height: clamp(132px, 38vw, 172px);
    }

    .room-footer {
        height: calc(68px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
    }

    .control-toolbar {
        width: calc(100% - 16px);
        justify-content: space-around;
        padding: 7px 8px;
        gap: 4px;
    }

    .control-btn {
        width: 44px;
        height: 44px;
    }

    .chat-input-area {
        padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
    }

    .toast {
        width: calc(100% - 32px);
        justify-content: center;
        text-align: center;
        bottom: calc(84px + env(safe-area-inset-bottom));
    }
}

@media (max-width: 768px) {
    .member-count-badge {
        margin-left: auto;
        min-height: 30px;
        padding: 4px 9px;
        background: rgba(34, 211, 238, 0.08);
        color: #d8f8ff;
    }
    .room-info { width: 100%; min-width: 0; gap: 8px; }
    .video-grid-container { overscroll-behavior: contain; }
    .video-grid-container.multi-layout { align-items: flex-start; overflow-y: auto; }
    #video-grid.multi {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: minmax(165px, 34vh);
        align-content: start;
        height: auto;
        min-height: 100%;
        gap: 8px;
    }
    #video-grid.multi .video-card {
        width: 100%;
        height: 100%;
        min-height: 165px;
        aspect-ratio: auto;
        border-radius: 13px;
    }
    #video-grid.multi .video-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        max-height: 38vh;
    }
    #video-grid.multi .video-card video,
    #video-grid.double .video-card:not(.local) video { object-fit: cover; }
    #video-grid.multi .video-overlay { padding: 8px; }
    #video-grid.multi .username-tag {
        max-width: calc(100% - 4px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.72rem;
        background: rgba(0, 0, 0, 0.72);
    }
    #video-grid.multi .mic-status-icon { width: 25px; height: 25px; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}

/* Logo (used in room header) */
.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.room-logo-img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.logo h1, .logo h2 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 1px;
    color: var(--text-main);
}

/* ==========================================================================
   Room Styling (Active Video Chat)
   ========================================================================== */
#room-container {
    width: 98vw;
    height: 96vh;
    max-width: 1600px;
    max-height: 900px;
    flex-direction: column;
    overflow: hidden;
}

/* Room Header */
.room-header {
    height: var(--header-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--panel-border);
}

.room-info {
    display: flex;
    align-items: center;
    gap: 16px;
}

.room-info h2 {
    font-size: 1.3rem;
}

.room-info .divider {
    width: 1px;
    height: 24px;
    background: var(--panel-border);
}

.room-id-badge {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--panel-border);
    padding: 6px 12px;
    border-radius: 30px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-id-badge span {
    color: var(--text-muted);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    transition: var(--transition-smooth);
}

.icon-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn i {
    width: 16px;
    height: 16px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

#connection-status[data-state="connected"] { color: var(--color-success); }
#connection-status[data-state="error"] { color: #fca5a5; }

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--color-success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 1.6s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Room Main Area */
.room-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Video Grid Area */
.video-grid-container {
    flex: 1;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow-y: auto;
}

#video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 20px;
    width: 100%;
    height: 100%;
    max-height: 100%;
    align-content: center;
}

/* Grid state variations based on number of children */
#video-grid.single {
    grid-template-columns: 1fr;
    max-width: 800px;
    aspect-ratio: 16/10;
}

#video-grid.double {
    grid-template-columns: repeat(2, 1fr);
    max-width: 1200px;
}

#video-grid.multi {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Video Card */
.video-card {
    position: relative;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    background: #0a0d14;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    aspect-ratio: 16/10;
    transition: var(--transition-smooth);
}

.video-card:hover {
    border-color: rgba(99, 102, 241, 0.3);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

/* Pinned theater fullscreen mode */
.video-card.pinned {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 20000 !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
    aspect-ratio: auto !important;
}

.video-card.pinned video {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    object-position: center center !important;
    background: #000 !important;
}

.video-card.pinned::after {
    content: 'クリックして縮小';
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 30px;
    color: #f8fafc;
    font-size: 0.9rem;
    pointer-events: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 10000;
}

.video-card.speaking {
    border-color: var(--color-accent);
    box-shadow: 0 0 16px var(--color-accent-glow);
}

.video-card video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.video-card.video-unavailable video {
    visibility: hidden !important;
}

.video-card.local video {
    transform: rotateY(180deg);
}

.video-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 12px 16px;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.3) 0%, transparent 60%, rgba(0,0,0,0.5) 100%);
    pointer-events: none;
}

.username-tag {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    padding: 4px 10px;
    border-radius: 30px;
    font-size: 0.75rem;
    font-weight: 500;
    align-self: flex-start;
}

.device-status {
    display: flex;
    gap: 8px;
    align-self: flex-end;
}

.mic-status-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.mic-status-icon i {
    width: 14px;
    height: 14px;
}

.mic-status-icon.muted {
    background: var(--color-danger);
}

/* Remote Placeholder when Camera is OFF */
.remote-placeholder {
    position: absolute;
    inset: 0;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
}

.remote-avatar {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.remote-camera-placeholder {
    z-index: 9;
    background: radial-gradient(circle at 50% 35%, #172554 0%, #0b1220 68%);
}

.remote-placeholder-name {
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-main);
    font-size: 0.9rem;
}

.remote-placeholder-status {
    color: var(--text-muted);
    font-size: 0.72rem;
}

/* ==========================================================================
   Sidebar: Chat & File Transfer
   ========================================================================== */
#sidebar {
    width: var(--sidebar-width);
    border-left: 1px solid var(--panel-border);
    display: none;
    flex-direction: column;
    background: rgba(10, 15, 30, 0.4);
    transition: var(--transition-smooth);
}

#sidebar.active {
    display: flex;
}

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--panel-border);
}

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h3 i {
    width: 18px;
    height: 18px;
    color: var(--color-accent);
}

/* Chat drag and drop file zone */
.chat-scroll-region {
    position: relative;
    flex: 1;
    min-height: 0;
}

.chat-messages-wrapper {
    height: 100%;
    overflow-y: auto;
    position: relative;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

/* Drag overlay */
.drag-overlay {
    position: absolute;
    inset: 0;
    background: rgba(9, 13, 22, 0.9);
    border: 2px dashed var(--color-accent);
    margin: 10px;
    border-radius: var(--border-radius-md);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: none; /* Let events propagate to zone */
}

.chat-messages-wrapper.dragover .drag-overlay {
    display: flex;
}

.drag-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--color-accent);
}

.drag-icon {
    width: 48px;
    height: 48px;
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

#chat-messages {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message styling */
.system-message {
    align-self: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--panel-border);
    padding: 8px 14px;
    border-radius: 12px;
    max-width: 90%;
    text-align: center;
}

.system-message p {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
}

.chat-msg.sent {
    align-self: flex-end;
}

.chat-msg.received {
    align-self: flex-start;
}

.msg-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    padding: 0 4px;
}

.chat-msg.sent .msg-meta {
    text-align: right;
}

.msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-all;
    white-space: pre-wrap;
}

.chat-jump-btn {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    z-index: 20;
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 0;
    padding: 8px 13px;
    border: 1px solid rgba(99, 102, 241, 0.55);
    border-radius: 999px;
    background: rgba(30, 41, 59, 0.96);
    color: var(--text-main);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

.chat-jump-btn:not([hidden]) { display: flex; }
.chat-jump-btn:hover { background: rgba(79, 70, 229, 0.96); }
.chat-jump-btn svg { width: 16px; height: 16px; }

.chat-msg.sent .msg-bubble {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    color: white;
    border-top-right-radius: 4px;
}

.chat-msg.received .msg-bubble {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    border-top-left-radius: 4px;
}

/* Premium P2P File message cards */
.file-card {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--panel-border);
    border-radius: var(--border-radius-md);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 250px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.file-card.image-file-card {
    width: min(300px, 78vw);
    padding: 7px;
    gap: 9px;
}

.chat-image-preview-link {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 11px;
    overflow: hidden;
    background: #02050a;
    cursor: zoom-in;
}

.chat-image-preview-link:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

.chat-image-preview {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    background: #02050a;
}

.image-file-card .file-info {
    padding: 2px 5px;
}

.image-download-btn {
    margin-top: 2px;
}

body.image-lightbox-open {
    overflow: hidden;
}

.image-lightbox[hidden] {
    display: none;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 76px 24px 24px;
    background: rgba(0, 0, 0, 0.94);
    backdrop-filter: blur(14px);
}

.image-lightbox-toolbar {
    position: absolute;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    display: flex;
    gap: 10px;
}

.image-lightbox-action {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.88);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.image-lightbox-action:hover,
.image-lightbox-action:focus-visible {
    background: rgba(79, 70, 229, 0.95);
    outline: none;
}

.image-lightbox-action svg {
    width: 20px;
    height: 20px;
}

.image-lightbox-image {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - 100px);
    object-fit: contain;
    user-select: none;
}

@media (max-width: 600px) {
    .image-lightbox {
        padding: 70px 8px max(8px, env(safe-area-inset-bottom));
    }

    .image-lightbox-toolbar {
        left: max(8px, env(safe-area-inset-left));
        right: max(8px, env(safe-area-inset-right));
        justify-content: flex-end;
    }

    .image-lightbox-action span {
        display: none;
    }
}

.file-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-icon-box {
    width: 38px;
    height: 38px;
    border-radius: var(--border-radius-sm);
    background: rgba(99, 102, 241, 0.1);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-icon-box i {
    width: 20px;
    height: 20px;
}

.file-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.file-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.file-size.file-status-complete { color: var(--color-success); }
.file-size.file-status-failed { color: var(--color-danger); }

/* File download link button */
.file-download-btn {
    width: 100%;
    padding: 8px;
    background: var(--color-primary);
    border: none;
    border-radius: var(--border-radius-sm);
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    transition: var(--transition-smooth);
}

.file-download-btn:hover {
    background: var(--color-primary-hover);
}

/* Send file progress indicator */
.file-progress-wrapper {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--panel-border);
    padding: 8px 12px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 8px;
}

.file-progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 6px;
}

.file-progress-bar-bg {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.file-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-accent), var(--color-primary));
    transition: width 0.1s linear;
}

/* Active transfers panel at bottom of sidebar */
#file-transfers-container {
    padding: 0 10px;
}

/* Chat Input Field Area */
.chat-input-area {
    padding: 16px;
    border-top: 1px solid var(--panel-border);
    background: rgba(9, 13, 22, 0.5);
}

.input-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--panel-border);
    border-radius: 30px;
    padding: 6px 12px;
    transition: var(--transition-smooth);
}

.input-actions:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.input-actions input,
.input-actions textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    outline: none;
    font-size: 0.85rem;
    padding: 6px 0;
    min-width: 0;
}

.input-actions textarea {
    display: block;
    min-height: 30px;
    max-height: 120px;
    line-height: 1.45;
    resize: none;
    overflow-y: auto;
}

.chat-input-help {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 12px 0;
    color: var(--text-dark);
    font-size: 0.68rem;
}

.chat-input-help .near-limit { color: #fbbf24; }

.send-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    transform: none;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    transition: var(--transition-smooth);
}

.action-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.08);
}

.action-btn i {
    width: 16px;
    height: 16px;
}

.send-btn {
    background: var(--color-primary);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.send-btn:hover {
    background: var(--color-primary-hover);
    transform: scale(1.05);
}

.send-btn i {
    width: 14px;
    height: 14px;
}

/* ==========================================================================
   Control Bar / Room Toolbar
   ========================================================================== */
.room-footer {
    height: var(--footer-height);
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--panel-border);
}

.control-toolbar {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    padding: 10px 24px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.06);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
    position: relative;
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border: 2px solid #0f172a;
    border-radius: 999px;
    background: var(--color-danger);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

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

.control-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.control-btn.active:hover {
    background: var(--color-primary-hover);
}

.control-btn.disabled {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: white;
}

.control-btn.disabled:hover {
    background: var(--color-danger-hover);
}

.control-btn.danger {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: white;
}

.control-btn.danger:hover {
    background: var(--color-danger-hover);
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

.control-btn i {
    width: 20px;
    height: 20px;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   Toast Notification Styling
   ========================================================================== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--color-primary);
    box-shadow: 0 0 15px var(--panel-glow);
    backdrop-filter: blur(10px);
    padding: 12px 24px;
    border-radius: 30px;
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 9999;
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.remote-audio {
    display: none;
}

.audio-unlock-btn {
    position: fixed;
    left: 50%;
    bottom: 104px;
    transform: translate(-50%, 20px);
    z-index: 10020;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 18px;
    border: 1px solid rgba(34, 211, 238, 0.45);
    border-radius: 999px;
    background: #0e7490;
    color: white;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    transition: opacity .2s ease, transform .2s ease;
}

.audio-unlock-btn.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}

.audio-unlock-btn i {
    width: 18px;
    height: 18px;
}

@media (max-width: 768px) {
    .audio-unlock-btn {
        bottom: calc(78px + env(safe-area-inset-bottom));
    }
}

/* Screen Sharing Video Card overlay badge */
.screenshare-badge {
    background: var(--color-secondary);
    color: white;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
    text-transform: uppercase;
}

/* ==========================================================================
   Mobile Responsive Media Queries (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
    /* Lock html and body to the actual visible height to prevent dynamic bar scrolling */
    html, body {
        height: 100%;
        height: calc(var(--vh, 1vh) * 100);
        width: 100vw;
        overflow: hidden;
        position: fixed;
        top: 0;
        left: 0;
    }

    /* Fullscreen layout on mobile using fixed positioning to subtract browser toolbars */
    #room-container {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100%;
        height: calc(var(--vh, 1vh) * 100);
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .room-header {
        padding: 0 16px;
        height: 60px;
    }

    .room-info h2 span {
        display: none; /* Hide 'Stream' in LinkStream logo to save space */
    }

    .room-id-badge {
        font-size: 0.8rem;
        padding: 4px 10px;
    }

    .room-main {
        position: relative; /* Setup positioning for absolute sidebar overlay */
    }

    /* Sidebar Overlay mode on mobile */
    #sidebar {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%; /* Take full width on mobile chat */
        z-index: 1000;
        background: rgba(10, 15, 25, 0.96);
        backdrop-filter: blur(25px);
        -webkit-backdrop-filter: blur(25px);
        border-left: none;
        box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
        animation: slideIn 0.3s ease-out;
    }

    @keyframes slideIn {
        from { transform: translateX(100%); }
        to { transform: translateX(0); }
    }

    /* Adjust Video Grid for portrait views */
    .video-grid-container {
        padding: 12px;
        height: 100%;
        width: 100%;
    }

    #video-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        height: 100%;
        width: 100%;
    }

    /* Single user mode: Full viewport portrait video card */
    #video-grid.single {
        height: 100%;
        width: 100%;
        max-width: 100%;
        aspect-ratio: auto;
    }

    #video-grid.single .video-card {
        width: 100%;
        height: 100%;
        aspect-ratio: auto;
    }

    /* Double user mode: equal participant grid */
    #video-grid.double {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: repeat(2, minmax(0, 1fr));
        gap: 8px;
        height: 100%;
        width: 100%;
    }

    #video-grid.double .video-card,
    #video-grid.double .video-card.local,
    #video-grid.double .video-card:not(.local) {
        position: relative;
        inset: auto;
        width: 100%;
        height: 100%;
        min-height: 0;
        z-index: auto;
        border-radius: 13px;
        border: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
        aspect-ratio: auto;
    }

    /* Multi-user mode (3+ users): clear two-column participant grid */
    #video-grid.multi {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: minmax(165px, 34vh);
        align-content: start;
        height: auto;
        min-height: 100%;
        gap: 8px;
    }

    #video-grid.multi .video-card {
        width: 100%;
        height: 100%;
        min-height: 165px;
        aspect-ratio: auto;
        border-radius: 13px;
    }

    #video-grid.multi .video-card:last-child:nth-child(odd) {
        grid-column: 1 / -1;
        max-height: 38vh;
    }

    /* Scale controls and toolbar downwards */
    .room-footer {
        height: 70px;
    }

    .control-toolbar {
        padding: 8px 16px;
        gap: 10px;
        border-radius: 30px;
    }

    .control-btn {
        width: 40px;
        height: 40px;
    }

    .control-btn i {
        width: 16px;
        height: 16px;
    }

    .toolbar-divider {
        display: none; /* Hide dividers to fit buttons */
    }

    /* Chat components adjustments */
    .file-card {
        width: 100%; /* Take full bubble width */
        max-width: 280px;
    }
}

/* Final cascade overrides for the active room components declared above. */
#room-container { max-width: 1680px; max-height: 960px; }
.room-header, .room-footer { flex-shrink: 0; background: rgba(7, 12, 21, 0.72); }
.video-grid-container {
    padding: 18px;
    overflow: hidden;
    background: radial-gradient(circle at 50% 35%, rgba(59, 130, 246, 0.09), transparent 56%);
}
.video-card { background: #02050a; box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3); }
.video-overlay {
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.42), transparent 38%, transparent 62%, rgba(0, 0, 0, 0.64));
}
#sidebar { background: rgba(8, 14, 24, 0.88); }
.sidebar-header { min-height: 58px; }
#chat-messages { gap: 14px; }
.msg-bubble { word-break: break-word; overflow-wrap: anywhere; }
.chat-msg.sent .msg-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
}
.chat-input-area { background: rgba(7, 12, 21, 0.92); }
.input-actions { min-height: 48px; }
.control-toolbar { background: rgba(15, 23, 42, 0.92); }

@media (max-width: 1100px) and (min-width: 769px) {
    :root { --sidebar-width: 320px; }
    #video-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
    .control-toolbar { gap: 10px; padding-inline: 18px; }
}

@media (max-width: 768px) {
    .room-header {
        height: calc(58px + env(safe-area-inset-top));
        padding: env(safe-area-inset-top) 14px 0;
    }
    .room-header .logo h2,
    .room-info .divider,
    .room-id-badge > span,
    .room-meta { display: none; }
    .room-id-badge { max-width: calc(100vw - 80px); }
    #room-id-display {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    #sidebar { background: rgba(7, 12, 21, 0.98); }
    .sidebar-header { padding-top: calc(14px + env(safe-area-inset-top)); }
    .video-grid-container { padding: 8px; }
    #video-grid.double .video-card.local {
        position: relative;
        inset: auto;
        width: 100%;
        height: 100%;
        z-index: auto;
    }
    .room-footer {
        height: calc(68px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
    }
    .control-toolbar {
        width: calc(100% - 16px);
        justify-content: space-around;
        padding: 7px 8px;
        gap: 4px;
    }
    .control-btn { width: 44px; height: 44px; }
    .chat-input-area { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
    .chat-input-help > span:first-child { display: none; }
    .chat-input-help { justify-content: flex-end; }
    .toast {
        width: calc(100% - 32px);
        justify-content: center;
        text-align: center;
        bottom: calc(84px + env(safe-area-inset-bottom));
    }
}
