:root {
  --bg: #0b1220;
  --card: #0f172a;
  --border: #22304a;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #3b82f6;
  --primary2: #2563eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 20% 0%, #142045 0%, var(--bg) 55%);
  background-attachment: fixed;
  background-size: cover;
  background-position: center;
  color: var(--text);
  transition: background 0.3s ease;
}
body.page-bg-image {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.top {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

h1 { margin: 0; font-size: 28px; }
h2 { margin: 0; font-size: 18px; }

.sub, .hint {
  color: var(--muted);
  margin: 6px 0 0;
  font-size: 14px;
}

.card {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  backdrop-filter: blur(8px);
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.row.space {
  justify-content: space-between;
}

.actions button {
  min-width: 100px;
}

.field { flex: 1; min-width: 220px; }
label { display:block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1020;
  color: var(--text);
  outline: none;
}

input:focus {
  border-color: rgba(59,130,246,0.8);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.2);
}

button {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0b1020;
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: rgba(255,255,255,0.18);
}

button.primary {
  background: var(--primary);
  border-color: rgba(255,255,255,0.18);
}

button.primary:hover {
  background: var(--primary2);
}

.grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 14px;
}

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr; }
  .top { align-items: flex-start; flex-direction: column; }
}

.pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(59,130,246,0.12);
  color: var(--text);
  font-size: 12px;
}

.videos {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  /* 정사각형 n×n 균등 분할: 빈 타일로 채워도 항상 정사각형 */
  grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr));
  align-content: stretch;
  align-items: stretch;
  transition: grid-template-columns 0.2s ease, grid-template-rows 0.2s ease;
  min-height: 520px;
  aspect-ratio: 1 / 1;
  max-height: min(78vh, 900px);
  padding: 12px;
  background-color: rgba(0,0,0,0.18);
  background-image:
    linear-gradient(rgba(255,255,255,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 24px 24px;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  overflow: auto;
}

.grid-info {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.grid-info .pill {
  font-size: 11px;
  padding: 2px 8px;
}

.layout-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.layout-controls button {
  padding: 6px 10px;
  font-size: 12px;
  min-width: auto;
  border-radius: 8px;
}
.layout-controls button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* 상단 고정 타일 시각적 구분 */
.tile.pinned {
  border-color: rgba(59,130,246,0.45);
  box-shadow: 0 0 0 1px rgba(59,130,246,0.25);
}
.tile.pinned.sharing {
  border-color: rgba(245,158,11,0.55);
  box-shadow: 0 0 0 1px rgba(245,158,11,0.35);
}

.tile {
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 1 / 1;
  width: 100%;
  height: 100%;
  align-self: stretch;
  justify-self: stretch;
}

.tile.empty {
  background:
    linear-gradient(rgba(255,255,255,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px),
    rgba(255,255,255,0.04);
  background-size: 20px 20px, 20px 20px, auto;
  border-style: dashed;
  border-color: rgba(255,255,255,0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 1 / 1;
  width: 100%;
  height: 100%;
  align-self: stretch;
  justify-self: stretch;
}
.tile.empty .empty-icon {
  font-size: 22px;
  opacity: 0.5;
}
.tile.empty .empty-label {
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cap {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cap-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.cap-hint {
  font-size: 10px;
  color: var(--muted);
  opacity: 0.7;
  flex-shrink: 0;
}

video {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: block;
  background: #000;
  cursor: pointer;
  object-fit: cover;
}

/* sharing tile highlight */
.tile.sharing {
  border-color: rgba(245,158,11,0.45);
  box-shadow: 0 0 0 1px rgba(245,158,11,0.25);
}
.tile.sharing .cap {
  background: rgba(245,158,11,0.10);
}

/* fullscreen */
.tile:fullscreen {
  width: 100vw;
  height: 100vh;
  background: #000;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  border: none;
}
.tile:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  background: #000;
}
.tile:fullscreen video,
.tile:-webkit-full-screen video {
  flex: 1;
  width: 100%;
  height: calc(100vh - 36px);
  object-fit: contain;
  background: #000;
}
.tile:fullscreen .cap {
  background: rgba(0,0,0,0.85);
  color: #fff;
  border-bottom-color: rgba(255,255,255,0.15);
}

.chatlog {
  margin: 10px 0;
  height: 420px;
  overflow: auto;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  padding: 10px;
  background: rgba(0,0,0,0.18);
}

.msg { margin: 6px 0; font-size: 14px; }
.msg.sys { color: var(--muted); }
.msg.me { font-weight: 700; }

.diag {
  margin: 8px 0 12px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  background: rgba(0,0,0,0.12);
}

.diaglog {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  max-height: 120px;
  overflow: auto;
  border-top: 1px solid rgba(255,255,255,0.10);
  padding-top: 10px;
}

.diagline { margin: 4px 0; }

.meter {
  margin-top: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.10);
  overflow: hidden;
}

.micbar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, rgba(16,185,129,0.8), rgba(245,158,11,0.8), rgba(239,68,68,0.8));
  transition: width 80ms linear;
}

.roster {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.roster-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  background: rgba(0,0,0,0.15);
}

.roster-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.roster-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--text);
}

.badge.good { background: rgba(16,185,129,0.18); }
.badge.bad { background: rgba(239,68,68,0.18); }
.badge.warn { background: rgba(245,158,11,0.18); }
.badge.muted { background: rgba(156,163,175,0.12); color: var(--muted); }

/* ===== Background settings panel ===== */
.bg-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
}
.bg-panel h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text);
}
.bg-section {
  margin-bottom: 14px;
}
.bg-section:last-child { margin-bottom: 0; }
.bg-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bg-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.bg-row label {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
  min-width: 60px;
}
.bg-row input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 2px;
  border-radius: 8px;
  cursor: pointer;
}
.bg-row input[type="file"] {
  font-size: 12px;
  max-width: 200px;
}
.bg-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.bg-preset {
  width: 48px;
  height: 32px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  background-size: cover;
  background-position: center;
  transition: border-color 0.15s, transform 0.15s;
}
.bg-preset:hover { transform: scale(1.08); }
.bg-preset.active { border-color: var(--primary); }
.bg-preset.none {
  background: repeating-conic-gradient(#1e293b 0% 25%, #334155 0% 50%) 50% / 12px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--muted);
}
.vbg-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.vbg-controls button {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  min-width: auto;
}
.vbg-controls button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.vbg-preview {
  width: 100%;
  height: 80px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.10);
  background: #000;
  object-fit: cover;
  display: none;
}
.vbg-preview.show { display: block; }

/* virtual bg canvas overlay */
.tile.vbg-active {
  position: relative;
}
.tile.vbg-active canvas.vbg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
}
