@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    outline: none;
}

:root {
    /* Colors - Light mode */
    --primary-color: #f6f7f9;
    --secondary-color: #ffffff;
    --surface-color: #ffffff;
    --surface-hover: #eef0f3;
    --surface-muted: #f1f3f6;
    --text-color: #18181b;
    --text-secondary: #63636e;
    --msg-title-color: #2563eb;
    --input-color: #52525b;
    --btn-color: #18181b;
    --hover-color: #2563eb;
    --accent-color: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.1);
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --danger-soft: rgba(220, 38, 38, 0.1);
    --live-color: #dc2626;
    --success-color: #16a34a;
    --tran-05: all 0.5s ease;
    --scrollbar-bg: #2563eb;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.25);
    --input-border-hover: rgba(128, 128, 128, 0.35);

    /* Layout */
    --form-width: 50%;
    --form-height: 80%;
    --control-size: 44px;
    --drawer-width: 400px;

    /* Spacing (8px grid) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border */
    --border: 1px solid rgba(0, 0, 0, 0.08);
    --border-radius-sm: 6px;
    --border-radius: 10px;
    --border-radius-md: 12px;
    --border-radius-lg: 14px;
    --border-radius-xl: 20px;
    --border-radius-full: 999px;

    /* Shadows */
    --box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.08);

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-xs: 0.75rem;
    --font-sm: 0.8125rem;
    --font-base: 0.9375rem;
    --font-lg: 1.125rem;
    --font-xl: 1.5rem;
}

* {
    font-family: var(--font-family);
}

body {
    min-height: 100vh;
    background-color: var(--primary-color);
    color: var(--text-color);
    overflow: auto;
    font-size: var(--font-base);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.dark {
    --primary-color: #0e0e10;
    --secondary-color: #18181b;
    --surface-color: #1f1f23;
    --surface-hover: #2a2a30;
    --surface-muted: #232328;
    --text-color: #efeff1;
    --text-secondary: #a1a1aa;
    --msg-title-color: #60a5fa;
    --input-color: #a1a1aa;
    --btn-color: #efeff1;
    --hover-color: #3b82f6;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --accent-soft: rgba(59, 130, 246, 0.16);
    --danger-color: #f05252;
    --danger-hover: #dc2626;
    --danger-soft: rgba(240, 82, 82, 0.16);
    --success-color: #4ade80;
    --scrollbar-bg: #3b82f6;
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.35);
    --border: 1px solid rgba(255, 255, 255, 0.07);
    --box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.24);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Keyboard focus indicator (pointer clicks keep a clean look) */
:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: none;
}

::selection {
    background: var(--accent-soft);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: var(--border-radius-full);
    transition: background var(--transition-normal);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-bg);
}

/* Buttons */
button {
    padding: var(--space-sm) var(--space-md);
    color: var(--text-color);
    background-color: var(--surface-color);
    cursor: pointer;
    border: var(--border);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    font-size: var(--font-sm);
    font-weight: 500;
    transition: all var(--transition-fast);
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

button:hover {
    background-color: var(--surface-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
    box-shadow: var(--box-shadow);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

.chat-compose button.emoji-picker-button {
    color: var(--text-secondary);
    background: var(--surface-muted);
    border: 1px solid transparent;
}

.chat-compose button.emoji-picker-button:hover,
.chat-compose button.emoji-picker-button[aria-expanded='true'] {
    color: var(--accent-color);
    background: var(--accent-soft);
}

.emoji-picker-popover {
    position: absolute;
    z-index: 1100;
    max-width: calc(100% - 16px);
    max-height: calc(100% - 16px);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    overflow: auto;
}

.emoji-picker-popover[hidden] {
    display: none;
}

/* Video container */
.container {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: var(--border-radius-lg);
    overflow: hidden;
}

.container video {
    z-index: 1;
    position: relative;
    width: 100%;
    height: 100%;
    cursor: pointer;
    border-radius: var(--border-radius-lg);
    transition: filter var(--transition-normal);
    object-fit: contain;
}

/* CSS loading spinner – replaces poster GIF */
.video-loading {
    background: var(--surface-color);
}

.video-loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border: 3px solid rgba(128, 128, 128, 0.25);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    z-index: 5;
    animation: spin 0.8s linear infinite;
    pointer-events: none;
}

.container video:hover {
    filter: brightness(1.03);
}

/* Video overlay gradient for readability */
.container::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
    z-index: 2;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.container:hover::after {
    opacity: 1;
}

.video-off {
    z-index: 3;
    position: absolute;
    visibility: hidden;
    top: 50%;
    left: 50%;
    width: 12vh;
    height: 12vh;
    transform: translate(-50%, -50%);
    opacity: 0.8;
}

video {
    background: #000;
}

video:fullscreen {
    object-fit: contain;
}

video::-webkit-media-controls {
    display: none !important;
}

.mirror {
    -webkit-transform: rotateY(180deg);
    -moz-transform: rotateY(180deg);
    transform: rotateY(180deg);
}

.not-selectable {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(128, 128, 128, 0.3);
    transition: var(--transition-normal);
}

.slider:before {
    position: absolute;
    content: '';
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-normal);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background-color: var(--accent-color);
}

input:focus + .slider {
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

.slider.round {
    border-radius: var(--border-radius-full);
}

.slider.round:before {
    border-radius: 50%;
}

/* Support */
.support {
    text-align: right;
}

.support button {
    padding: var(--space-xs) var(--space-sm);
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--text-secondary);
    font-size: var(--font-base);
}

.support button:hover {
    color: #ef4444;
    background: transparent;
    box-shadow: none;
    transform: scale(1.15);
}

/* Links */
a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-hover);
}

/* SweetAlert overrides */
.swal2-title,
.swal2-content {
    background-color: transparent !important;
    color: var(--text-color) !important;
    text-align: center;
}

.swal2-title {
    font-weight: 600 !important;
    letter-spacing: -0.01em;
}

.swal2-html-container {
    background-color: transparent !important;
    color: var(--text-secondary) !important;
    font-size: var(--font-base) !important;
    line-height: 1.6 !important;
}

.swal2-popup {
    border-radius: var(--border-radius-xl) !important;
    background-color: var(--secondary-color) !important;
    color: var(--text-color) !important;
    border: var(--border) !important;
    box-shadow: var(--shadow-xl) !important;
}

.swal2-popup.swal2-toast {
    border-radius: var(--border-radius-lg) !important;
}

.swal2-actions {
    gap: var(--space-sm);
}

.swal2-actions button {
    min-height: 42px;
    margin: 0 !important;
    padding: 10px 20px !important;
    color: var(--text-color) !important;
    background: var(--surface-hover) !important;
    border: var(--border) !important;
    box-shadow: none !important;
    border-radius: var(--border-radius) !important;
    font-weight: 600 !important;
}

.swal2-actions .swal2-confirm {
    color: #fff !important;
    background: var(--accent-color) !important;
    border-color: var(--accent-color) !important;
}

.swal2-actions .swal2-confirm:hover {
    background: var(--accent-hover) !important;
}

.swal2-actions button:focus-visible {
    box-shadow: var(--focus-ring) !important;
}

.swal2-input,
.swal2-select {
    color: var(--text-color) !important;
    background: var(--surface-muted) !important;
    border: var(--border) !important;
    border-radius: var(--border-radius) !important;
}

.swal2-timer-progress-bar-container {
    background: var(--accent-color);
}

/* Table */
table {
    font-family: var(--font-family);
    border-collapse: separate;
    border-spacing: 0 var(--space-xs);
    width: 100%;
}

td,
th {
    text-align: center;
    padding: var(--space-sm) var(--space-md);
}

th {
    width: calc(100% / 3);
    font-weight: 600;
    font-size: var(--font-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    padding: var(--space-sm) var(--space-md);
    border-bottom: var(--border);
}

tr:not(:first-child) {
    background: var(--surface-color);
    border-radius: var(--border-radius);
}

tr:not(:first-child) td:first-child {
    border-radius: var(--border-radius) 0 0 var(--border-radius);
}

tr:not(:first-child) td:last-child {
    border-radius: 0 var(--border-radius) var(--border-radius) 0;
}

tr:not(:first-child):hover td {
    background-color: var(--surface-hover);
}

td {
    width: calc(100% / 3);
    font-size: var(--font-sm);
    border-bottom: none;
}

td button {
    width: auto;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-sm);
    background-color: transparent;
    color: var(--text-secondary);
    border: none;
    border-radius: var(--border-radius-sm);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
}

td button:hover {
    background-color: var(--surface-hover);
    color: var(--text-color);
    box-shadow: none;
}

/* Utility Classes */
.color-red {
    color: var(--danger-color) !important;
}

.color-green {
    color: var(--success-color);
}

/* Quiet feedback for local microphone and camera changes */
.media-status {
    position: fixed;
    left: 50%;
    bottom: calc(76px + env(safe-area-inset-bottom));
    z-index: 850;
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    min-height: 36px;
    padding: 7px 12px;
    color: var(--success-color);
    background: color-mix(in srgb, var(--surface-color) 94%, transparent);
    border: var(--border);
    border-radius: var(--border-radius-full);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    font-size: var(--font-sm);
    font-weight: 600;
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.98);
    transition:
        opacity var(--transition-normal),
        transform var(--transition-normal);
    pointer-events: none;
}

.media-status.media-status-off {
    color: var(--danger-color);
}

.media-status.media-status-visible {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
}

@media (max-width: 768px) {
    .media-status {
        bottom: calc(62px + env(safe-area-inset-bottom));
    }
}

@media (prefers-reduced-motion: reduce) {
    .media-status {
        transition: opacity var(--transition-fast);
    }
}

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.full-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--primary-color);
    z-index: 10;
}

/* Awaiting Broadcaster */
.awaiting-broadcaster {
    z-index: 3;
    position: absolute;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--border-radius-full);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    font-size: var(--font-sm);
    font-weight: 500;
    pointer-events: none;
    text-align: center;
    width: max-content;
}

.awaiting-broadcaster::before {
    content: '';
    flex: 0 0 auto;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

/* Animations */
.fadeIn {
    animation: fadeIn ease-in 0.5s forwards;
}

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

.pulse {
    animation: pulse 2.5s ease-in-out infinite;
}

.pulse-bg {
    background-color: var(--accent-color) !important;
    color: white !important;
    animation: pulse 2.5s ease-in-out infinite;
}

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

/* LIVE badge */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 10px;
    background: var(--live-color);
    color: #fff;
    font-size: var(--font-xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-radius: var(--border-radius-full);
    line-height: 1;
    flex: 0 0 auto;
}

.live-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    animation: livePulse 1.5s ease-in-out infinite;
}

/* Marks a broadcast fed by an external RTMP publisher instead of a browser */
.source-badge {
    align-items: center;
    gap: var(--space-xs);
    padding: 2px var(--space-sm);
    background: var(--accent-color);
    color: white;
    font-size: var(--font-xs);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-radius: var(--border-radius-sm);
    line-height: 1.6;
}

/* Two classes so page-level layout rules such as `.role-copy span` cannot win */
.source-badge:not(.active) {
    display: none;
}

.source-badge.active {
    display: inline-flex;
}

@keyframes livePulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.8);
    }
}

/* Reconnecting overlay */
.reconnecting-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: fadeIn 0.3s ease-out;
}

.reconnecting-overlay.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
}

.reconnecting-overlay .spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.reconnecting-overlay span {
    color: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

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

/* QR container */
.qrRoomContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-md);
}

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

/* =====================================================
   Room UI — shared by broadcaster and viewer pages
   ===================================================== */

.room {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: var(--space-sm) var(--space-md) var(--space-md);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: var(--space-sm);
    color: var(--text-color);
    background: var(--primary-color);
    overflow: hidden;
}

/* Header */
.room-header {
    min-width: 0;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    z-index: 20;
}

.room-meta {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    overflow: hidden;
}

.room-meta .source-badge {
    height: 28px;
    padding: 0 10px;
    border-radius: var(--border-radius-full);
    flex: 0 0 auto;
}

.meta-item {
    min-width: 0;
    height: 28px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    color: var(--text-color);
    background: var(--surface-color);
    border: var(--border);
    border-radius: var(--border-radius-full);
    font-size: var(--font-sm);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex: 0 0 auto;
}

.meta-item i {
    color: var(--text-secondary);
    font-size: 0.7rem;
}

.meta-user {
    flex-shrink: 1;
}

.meta-user span {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-leave {
    flex: 0 0 auto;
    height: 36px;
    padding: 0 14px;
    color: var(--danger-color);
    background: var(--danger-soft);
    border: 1px solid transparent;
    border-radius: var(--border-radius-full);
    box-shadow: none;
    font-size: var(--font-sm);
    font-weight: 600;
    white-space: nowrap;
}

.room-leave:hover {
    color: #fff;
    background: var(--danger-hover);
    box-shadow: none;
    transform: none;
}

/* JS toggles these buttons with display: block, so spacing can't rely on flex gap */
.room-leave span {
    margin-left: 6px;
}

/* Recording indicator */
.rec-indicator {
    justify-self: center;
    align-self: center;
    padding: 4px 12px;
    color: var(--danger-color);
    background: var(--danger-soft);
    border-radius: var(--border-radius-full);
    font-size: var(--font-xs);
    font-weight: 700;
    letter-spacing: 0.06em;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.rec-indicator::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    vertical-align: 1px;
    background: currentColor;
    border-radius: 50%;
}

/* Floating control dock */
.control-dock {
    justify-self: center;
    max-width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: 6px;
    background: color-mix(in srgb, var(--surface-color) 92%, transparent);
    border: var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 20;
}

.control-dock button {
    position: relative;
    width: var(--control-size);
    height: var(--control-size);
    padding: 0;
    color: var(--text-color);
    background: transparent;
    border: none;
    border-radius: var(--border-radius-md);
    box-shadow: none;
    font-size: 1rem;
}

.control-dock button i {
    font-size: 1rem;
}

.control-dock button:hover {
    background: var(--surface-hover);
    box-shadow: none;
    transform: none;
}

/* Off / recording states (class from JS, or inline color for the camera toggle) */
.control-dock button.color-red,
.control-dock button[style*='color: red'] {
    color: var(--danger-color) !important;
    background: var(--danger-soft);
}

.control-dock button.color-red:hover,
.control-dock button[style*='color: red']:hover {
    background: color-mix(in srgb, var(--danger-color) 24%, transparent);
}

/* The panel this button controls is open */
.control-dock button[aria-expanded='true'] {
    color: var(--accent-color);
    background: var(--accent-soft);
}

/* Side drawers */
.panel-drawer {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 900;
    width: min(var(--drawer-width), 100vw);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    color: var(--text-color);
    background: var(--secondary-color);
    border-left: var(--border);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    transform: translateX(100%);
    visibility: hidden;
    pointer-events: none;
    transition:
        transform var(--transition-slow),
        visibility 0s 300ms;
}

.panel-drawer.panel-open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
}

.panel-header {
    flex: 0 0 auto;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md) var(--space-sm) 20px;
    border-bottom: var(--border);
}

.panel-title {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

.panel-title i {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--accent-color);
    background: var(--accent-soft);
    border-radius: var(--border-radius);
    font-size: var(--font-sm);
}

.panel-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
}

.panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Compact icon-only buttons used inside panels */
.icon-btn,
.panel-close-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--border-radius);
    box-shadow: none;
    font-size: var(--font-sm);
}

.icon-btn:hover,
.panel-close-btn:hover {
    color: var(--text-color);
    background: var(--surface-hover);
    box-shadow: none;
    transform: none;
}

.panel-close-btn {
    margin-left: 2px;
    font-size: var(--font-base);
}

/* Forms inside panels */
.form-section {
    display: grid;
    gap: var(--space-sm);
    padding: var(--space-md) 20px;
    border-bottom: var(--border);
}

.form-section:last-child {
    border-bottom: none;
}

.form-section[hidden] {
    display: none;
}

.form-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-color);
    font-size: var(--font-sm);
    font-weight: 600;
}

.form-label i {
    width: 16px;
    color: var(--accent-color);
    font-size: var(--font-sm);
    text-align: center;
}

.control-row {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.control-row > select {
    flex: 1 1 0;
}

.panel-drawer select {
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 0 36px 0 14px;
    color: var(--text-color);
    background-color: var(--surface-muted);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23808089' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    border: 1px solid transparent;
    border-radius: var(--border-radius-md);
    font-size: var(--font-sm);
    text-overflow: ellipsis;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.panel-drawer select:hover {
    border-color: var(--input-border-hover);
}

.panel-drawer select:focus {
    border-color: var(--accent-color);
    box-shadow: var(--focus-ring);
}

.panel-drawer select:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.text-input {
    width: 100%;
    min-width: 0;
    height: 44px;
    padding: 0 14px;
    color: var(--text-color);
    background: var(--surface-muted);
    border: 1px solid transparent;
    border-radius: var(--border-radius-md);
    font-size: var(--font-sm);
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.text-input::placeholder {
    color: var(--text-secondary);
}

.text-input:hover {
    border-color: var(--input-border-hover);
}

.text-input:focus {
    border-color: var(--accent-color);
    box-shadow: var(--focus-ring);
}

.square-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    flex: 0 0 auto;
    color: var(--text-color);
    background: var(--surface-muted);
    border: 1px solid transparent;
    border-radius: var(--border-radius-md);
    box-shadow: none;
    font-size: var(--font-sm);
}

.square-btn:hover {
    color: #fff;
    background: var(--accent-color);
    box-shadow: none;
    transform: none;
}

/* Chat */
.chat-feed {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: var(--space-md) 20px;
    scroll-behavior: smooth;
}

.chat-feed:empty::before {
    content: 'No messages yet. Start the conversation below.';
    margin: auto;
    max-width: 220px;
    color: var(--text-secondary);
    font-size: var(--font-sm);
    text-align: center;
}

.chat-compose {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 12px var(--space-md) calc(12px + env(safe-area-inset-bottom));
    border-top: var(--border);
    background: var(--secondary-color);
}

.chat-compose .text-input {
    flex: 1 1 auto;
}

.chat-compose button {
    width: 44px;
    height: 44px;
    padding: 0;
    flex: 0 0 auto;
    color: #fff;
    background: var(--accent-color);
    border: none;
    border-radius: var(--border-radius-md);
    box-shadow: none;
    font-size: var(--font-sm);
}

.chat-compose button:hover {
    background: var(--accent-hover);
    box-shadow: none;
    transform: none;
}

/* On wide screens, keep the stage and dock fully visible beside an open drawer */
@media (min-width: 1024px) {
    .room {
        transition: padding-right var(--transition-slow);
    }

    body:has(.panel-drawer.panel-open) .room {
        padding-right: calc(var(--drawer-width) + var(--space-md));
    }
}

/* Responsive room layout */
@media (max-width: 768px) {
    .room {
        --control-size: 40px;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
        gap: 6px;
    }

    .room-header {
        min-height: 40px;
        gap: var(--space-sm);
    }

    .room-meta {
        gap: 6px;
    }

    .meta-item {
        height: 26px;
        padding: 0 8px;
        font-size: var(--font-xs);
    }

    .live-badge,
    .room-meta .source-badge {
        height: 26px;
        padding: 0 8px;
    }

    .meta-user span {
        max-width: 90px;
    }

    .control-dock {
        gap: 2px;
        padding: 4px;
        border-radius: 16px;
    }

    .control-dock button {
        border-radius: var(--border-radius);
    }

    .panel-drawer {
        width: 100vw;
        border-left: none;
        box-shadow: none;
        transform: translateY(100%);
    }

    .panel-drawer.panel-open {
        transform: translateY(0);
    }

    .panel-header {
        padding-top: calc(var(--space-sm) + env(safe-area-inset-top));
    }
}

@media (max-width: 480px) {
    .room-leave {
        width: 36px;
        padding: 0;
    }

    .room-leave span {
        display: none;
    }

    /* Keep every control on a single row; buttons share the available width */
    .control-dock {
        width: 100%;
        flex-wrap: nowrap;
        justify-content: space-evenly;
    }

    .control-dock button {
        flex: 0 1 var(--control-size);
        min-width: 30px;
    }
}

@media (max-height: 480px) and (orientation: landscape) {
    .room {
        --control-size: 36px;
        padding-top: 4px;
        padding-bottom: 4px;
        gap: 4px;
    }

    .room-header {
        min-height: 34px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .room {
        transition: none;
    }

    .panel-drawer {
        transition: visibility 0s;
    }
}
