:root {
    --bg-0: #0f1117;
    --bg-1: #111318;
    --bg-2: #161922;
    --bg-3: #1e2230;
    --panel: #1a1f2b;
    --brand: #5865f2; /* Discord-ish indigo */
    --text: #e7e9ee;
    --text-dim: #a9afc3;
    --danger: #ed4245;
    --success: #3ba55d;
    --warning: #f0b232;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    --radius-xl: 16px;
    --radius-2xl: 22px;
    --gap: 12px;
}
* {
    box-sizing: border-box;
}
html,
body {
    height: 100%;
}
body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
        "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
    color: var(--text);
    background: radial-gradient(
            1200px 800px at 85% -10%,
            #20263b 0%,
            var(--bg-0) 45%
        )
        no-repeat fixed;
    background-color: var(--bg-0);
}

/* ===== App Layout ===== */
.app {
    grid-template-rows: auto 1fr;
    gap: 0;
    height: 100dvh;
    width: 100%;
}

/* Call Header */
.call-header {
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 18px;
    backdrop-filter: blur(6px);
}
.call-header .left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.call-title {
    font-weight: 700;
    letter-spacing: 0.2px;
}
.pill {
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 12px;
    color: var(--text);
    background: rgba(88, 101, 242, 0.18);
    border: 1px solid rgba(88, 101, 242, 0.35);
}
.call-header .right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.btn-sm {
    height: 34px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    cursor: pointer;
}
.btn-sm:hover {
    background: rgba(255, 255, 255, 0.07);
}

/* Main content */
.main {
    display: grid;
    grid-template-rows: 1fr auto;
    gap: 0;
    min-height: 0; /* ensure children can shrink */
    height: 100%;
}

/* Screen share area */
.screen-area {
    display: none; /* hidden by default */
    gap: var(--gap);
    grid-auto-rows: 1fr;
    grid-template-columns: 1fr;
    padding: 16px 16px 8px 16px;
    min-height: 0;
}
.screen-tile {
    position: relative;
    background: linear-gradient(135deg, #10131b, #0c0f16);
    border-radius: var(--radius-2xl);
    border: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: grid;
    place-items: center;
    isolation: isolate;
}
.screen-feed {
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        #1e2436,
        #1e2436 10px,
        #1a2030 10px,
        #1a2030 20px
    );
    filter: saturate(1.1);
    position: absolute;
}

.screen-feed video {
    object-fit: contain;
    width: 100%;
    height: 100%;
}


.screen-tile .label {
    position: absolute;
    left: 12px;
    bottom: 12px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 13px;
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Video grid */
.video-grid {
    display: grid;
    gap: var(--gap);
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    padding: 16px;
    align-content: start;
    min-height: 0;
    height: 100%;
}

/* Video grid when screen sharing is active */
.screen-sharing .screen-area {
    display: grid;
}
.screen-sharing .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    padding: 8px 16px 96px; /* extra bottom for controls bar */
    max-height: 200px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-direction: row;
    display: flex;
}
.screen-sharing .video-grid .tile {
    flex: 0 0 auto;
    width: 180px;
    height: 120px;
}

.tile {
    position: relative;
    background: #0d1016;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    aspect-ratio: 16/10;
    display: block;
    place-items: center;
    box-shadow: var(--shadow);
}
.tile[data-speaking="true"] {
    outline: 2px solid rgba(88, 101, 242, 0.9);
    box-shadow: 0 0 0 4px rgba(88, 101, 242, 0.2), var(--shadow);
}

.tile[data-muted="true"] .badge.mic .icon::after  {
    content: "mic_off";
}

.tile[data-muted="false"] .badge.mic .icon::after  {
    content: "mic";
}

.tile[data-video="on"] .badge.video .icon::after  {
    content: "videocam";
}

.tile[data-video="off"] .badge.video .icon::after  {
    content: "videocam_off";
}

.tile[data-video="off"] .video-feed video {
    display: none;
}

.video-feed {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.video-feed video {
    object-fit: fill;
    width: 100%;
}

.overlay {
    position: absolute;
    inset: auto 8px 8px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.name {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 13px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.badges {
    display: flex;
    gap: 6px;
}
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 1px 10px;
    border-radius: 999px;
    font-size: 16px !important;
    color: var(--text);
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.icon {
    font-size: 16px !important;
}

/* Controls bar (bottom center) */
.controls {
    background: rgba(17, 19, 24, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    box-shadow: var(--shadow);
    justify-content: center;
}
.ctl {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.5);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
.ctl:hover {
    background: rgba(255, 255, 255, 0.9);
}
.ctl.red {
    background: rgba(237, 66, 69, 0.9);
    border-color: rgba(237, 66, 69, 1);
}
.ctl.red:hover {
    filter: brightness(1.05);
}


/* Settings Panel */
.settings-panel {
    position: fixed;
    width: 380px;
    height: 90%;
    background: var(--panel);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: var(--shadow);
    transition: left 0.3s ease;
    z-index: 100;
    display: flex;
    flex-direction: column;
    left: -50%;
    transform: translate(-50%, -50%);
    top: 50%;
    border-radius: 10px;
}

.settings-panel[aria-hidden="false"] {
    left: 50%;
}

.settings-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-header h2 {
    margin: 0;
    font-size: 18px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

.settings-content {
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-item {
    margin-bottom: 16px;
}

.setting-item label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
}

.setting-select, .setting-item input[type="range"] {
    width: 100%;
    padding: 10px;
    background: var(--bg-2);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
}

.setting-select:focus, .setting-item input[type="range"]:focus {
    outline: none;
    border-color: var(--brand);
}

.setting-item input[type="range"] {
    -webkit-appearance: none;
    height: 6px;
    background: var(--bg-2);
    border-radius: 3px;
    padding: 0;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--brand);
    border-radius: 50%;
    cursor: pointer;
}

/* Overlay when settings are open */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.settings-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.stats{
    position: absolute;
    top: 0;
    left: 0;
    font-size: x-small;
}