:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #242833;
  --text: #e8eaf0;
  --muted: #8b91a1;
  --accent: #4f7cff;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Malgun Gothic", system-ui, sans-serif;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; }
.muted { color: var(--muted); font-size: 0.9em; margin-left: 8px; }
.error { color: var(--danger); margin: 0; font-size: 0.9em; }

.primary {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.1); }
.primary:disabled { opacity: 0.5; cursor: default; }
.ghost {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 14px;
  white-space: nowrap;
}

input, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid #333846;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
select { min-width: 0; }

/* ---------- 로비 ---------- */
.lobby {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.lobby-card {
  width: min(460px, 100%);
  background: var(--panel);
  border-radius: 20px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.lobby-card h1 { margin: 0; font-size: 1.8rem; }
.sub { margin: 4px 0 0; color: var(--muted); }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.install {
  background: var(--ok);
  color: #fff;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
  white-space: nowrap;
}
.install:hover { filter: brightness(1.1); }
.install-hint {
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}
.lobby-card label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9em; color: var(--muted); }
.lobby-card label .opt { font-size: 0.8em; opacity: 0.8; }
.room-lock { margin-right: 4px; }
.radios { border: 1px solid #333846; border-radius: 10px; padding: 8px 12px 10px; margin: 0; display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.9em; color: var(--muted); }
.radios legend { padding: 0 4px; }
.radio { display: flex; align-items: center; gap: 4px; color: var(--text); cursor: pointer; }
.radio input { width: auto; }
.room-rec { color: var(--danger); }

/* 녹화 표시 */
.rec-badge {
  color: #fff;
  background: var(--danger);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
  animation: rec-blink 1.4s infinite;
}
@keyframes rec-blink { 50% { opacity: 0.55; } }
.ctrl.rec-on { background: var(--danger); }
.ctrl.rec-on .lb { color: #fff; }
.msg.system a { color: var(--accent); }
.row { display: flex; gap: 8px; }

.preview-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.preview-wrap video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.preview-off { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
.preview-controls {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}
.round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--danger);
  font-size: 1.1rem;
}
.round.on { background: rgba(255, 255, 255, 0.2); backdrop-filter: blur(6px); }

/* 방 목록 */
.rooms { border-top: 1px solid #2c303b; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.rooms-head { display: flex; justify-content: space-between; align-items: center; }
.room-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.room-btn {
  width: 100%;
  text-align: left;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid transparent;
}
.room-btn:hover { border-color: var(--accent); }
.room-item.full .room-btn { opacity: 0.55; cursor: default; }
.room-main { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-id { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-count { font-size: 0.8rem; color: var(--ok); white-space: nowrap; }
.room-item.full .room-count { color: var(--danger); }
.room-sub { display: flex; justify-content: space-between; gap: 8px; font-size: 0.8rem; color: var(--muted); }
.room-names { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-since { white-space: nowrap; }
.rooms-empty { margin: 0; font-size: 0.85rem; color: var(--muted); }

/* ---------- 회의실 ---------- */
.meeting { height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
}
.stage { flex: 1; display: flex; min-height: 0; gap: 10px; padding: 0 10px; }

.grid {
  flex: 1;
  display: grid;
  gap: 10px;
  align-content: center;
  min-height: 0;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: var(--row-h, 1fr);
}

.tile {
  position: relative;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  outline: 3px solid transparent;
  transition: outline-color 0.15s;
}
.tile.speaking { outline-color: var(--ok); }
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.local video { transform: scaleX(-1); }
.tile.local.screen video, .tile.screen video { transform: none; object-fit: contain; }
.tile.video-off video { visibility: hidden; }
.tile .avatar {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: none;
  place-items: center;
  font-size: 2.2rem;
  font-weight: 700;
  color: #fff;
}
.tile.video-off .avatar { display: grid; }
.tile .label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.55);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  display: flex;
  gap: 6px;
  max-width: calc(100% - 20px);
}
.tile .label .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile.pinned { grid-column: 1 / -1; grid-row: span 2; }
.tile .label .net { font-size: 0.8em; }
.tile .label .net.good { color: var(--ok); }
.tile .label .net.weak { color: #f5a524; }
.tile .label .net.bad { color: var(--danger); }
.tile .hint {
  position: absolute;
  left: 50%;
  bottom: 44px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: #f5a524;
  font-size: 0.78rem;
  padding: 3px 10px;
  border-radius: 8px;
  white-space: nowrap;
}

/* 네트워크 자동 조절 */
.topbar-right { display: flex; align-items: center; gap: 12px; }
.chip {
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
}
.chip.on { color: var(--ok); }
.banner {
  margin: 0 10px 8px;
  padding: 8px 14px;
  background: #3a2f12;
  color: #ffd580;
  border-radius: 10px;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.ghost.small { padding: 5px 10px; font-size: 0.8rem; }

/* 채팅 */
.chat {
  width: 320px;
  background: var(--panel);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid #2c303b; }
.icon { background: none; font-size: 1rem; color: var(--muted); }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg .meta { font-size: 0.78rem; color: var(--muted); margin-bottom: 2px; }
.msg .body { background: var(--panel-2); padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; display: inline-block; max-width: 100%; }
.msg.mine { text-align: right; }
.msg.mine .body { background: var(--accent); color: #fff; text-align: left; }
.msg.system { text-align: center; font-size: 0.8rem; color: var(--muted); }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #2c303b; }
.chat-form button { white-space: nowrap; }

/* 컨트롤 */
.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  flex-wrap: wrap;
}
.ctrl {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 76px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--panel-2);
}
.ctrl:hover { filter: brightness(1.2); }
.ctrl .ic { font-size: 1.25rem; }
.ctrl .lb { font-size: 0.75rem; color: var(--muted); }
.ctrl.off { background: var(--danger); }
.ctrl.off .lb, .ctrl.active .lb, .ctrl.danger .lb { color: #fff; }
.ctrl.active { background: var(--accent); }
.ctrl.danger { background: var(--danger); }
.badge {
  position: absolute;
  top: 4px;
  right: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  border-radius: 999px;
  padding: 0 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  background: #000c;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 10;
}

@media (max-width: 720px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar > div:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .muted { display: none; }
  .chip { padding: 3px 8px; font-size: 0.72rem; white-space: nowrap; }
  .banner { margin: 0 8px 6px; font-size: 0.8rem; }
  .chat { position: fixed; inset: 0 0 80px 0; width: auto; z-index: 5; border-radius: 0; }
  .ctrl { min-width: 0; padding: 8px; }
  .ctrl .lb { display: none; }
  .lobby-card { padding: 20px; }
}
