:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1f262f;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4f8cff;
  --danger: #ff5d5d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  height: 100%;
}

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

button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
button:hover { filter: brightness(1.1); }
button[disabled] { opacity: 0.5; cursor: not-allowed; }

input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--muted);
}

hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }

/* ---- Landing ---- */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
}
.card h1 { margin: 0 0 4px; }
.tagline { color: var(--muted); margin-top: 0; }
#join-form button { width: 100%; padding: 10px; font-weight: 600; }

/* ---- Room layout ---- */
.room {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.room-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.room-header h1 { font-size: 16px; margin: 0; flex: 1; }
.room-header .controls { display: flex; gap: 8px; }
.leave {
  text-decoration: none;
  color: var(--muted);
}

.room-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}

.video-grid {
  display: grid;
  gap: 8px;
  padding: 12px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-content: start;
  overflow-y: auto;
}
.video-tile {
  position: relative;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.video-tile video {
  width: 100%; height: 100%; object-fit: cover; background: #000;
}
.video-tile .label {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0,0,0,0.55);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}
.video-tile.is-owner {
  outline: 2px solid gold;
  outline-offset: -2px;
}
.video-tile .mute-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(255, 93, 93, 0.85);
  color: #fff;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

/* ---- Sidebar ---- */
.sidebar {
  border-left: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 12px 16px 6px;
}
.peer-list {
  border-bottom: 1px solid var(--border);
  max-height: 30%;
  overflow-y: auto;
}
.peer-list ul { list-style: none; margin: 0; padding: 0 8px 12px; }
.peer-list li.peer-row {
  padding: 6px 8px;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
}
.peer-list li.peer-row.self {
  cursor: default;
  color: var(--muted);
}
.peer-list li.peer-row:not(.self):hover {
  background: rgba(79, 140, 255, 0.08);
}
.peer-list li.peer-row.expanded {
  background: rgba(79, 140, 255, 0.12);
}
.peer-list .peer-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.peer-list .peer-actions {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.peer-list .peer-actions button {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.peer-list .peer-actions button:hover {
  background: var(--accent);
  border-color: var(--accent);
}
.peer-list .peer-actions button.danger:hover {
  background: var(--danger);
  border-color: var(--danger);
}

.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#chat-log {
  list-style: none;
  margin: 0;
  padding: 0 16px;
  flex: 1;
  overflow-y: auto;
}
#chat-log li {
  margin: 6px 0;
  font-size: 14px;
  line-height: 1.35;
  word-wrap: break-word;
  position: relative;
  padding-right: 18px;
}
#chat-log .nick { font-weight: 600; color: var(--accent); margin-right: 6px; }
#chat-log .msg-del {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0 4px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
#chat-log li:hover .msg-del { opacity: 1; }
#chat-log .msg-del:hover { color: var(--danger); }
#chat-form {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
#chat-form input { flex: 1; }
#chat-form button { padding: 8px 12px; }

/* ---- Room directory (landing) ---- */
#directory .dir-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
#directory h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0;
}
.muted { color: var(--muted); font-size: 12px; }

.rooms-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}
.rooms-list li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
}
.rooms-list li:last-child { border-bottom: 0; }
.rooms-list li:hover { background: rgba(79, 140, 255, 0.08); }
.rooms-list li.empty { cursor: default; color: var(--muted); justify-content: center; }
.rooms-list li.empty:hover { background: transparent; }
.rooms-list .room-name {
  flex: 1;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rooms-list .badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border);
  color: var(--muted);
}
.rooms-list .badge.cf { background: #f38020; color: #1c1c1c; }
.rooms-list .badge.ms { background: #1f6feb; color: #fff; }
.rooms-list .counts {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.rooms-list .counts strong { color: var(--text); }

/* ---- Account page ---- */
.account {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 16px;
}
.account-card {
  max-width: 560px;
}
.account-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 8px;
}
.account-header h1 { margin: 0; font-size: 22px; }
.account-card h2 { font-size: 16px; margin: 16px 0 4px; }
.account-card h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 24px 0 8px;
}
.small { font-size: 12px; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 12px;
}
.checkbox input { width: auto; }

.room-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.room-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.room-card-head h3 {
  margin: 0;
  font-size: 16px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}
.btn-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}
.btn-danger {
  background: var(--danger);
  margin-top: 16px;
}
.btn-danger:hover { filter: brightness(1.1); }

.bans-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.bans-list li {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.bans-list li:last-child { border-bottom: 0; }
.bans-list li.empty { color: var(--muted); justify-content: center; }
.bans-list li button {
  margin-left: auto;
  padding: 4px 10px;
  font-size: 12px;
}
.bans-list li span:first-child {
  font-weight: 600;
}
.bans-list li .role-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border);
  color: var(--text);
  margin-left: 6px;
}
.bans-list li .role-badge.admin { background: #f78166; color: #1c1c1c; }
.bans-list li .role-badge.mod { background: #1f6feb; color: #fff; }
.bans-list li .role-badge.member { background: #56d364; color: #1c1c1c; }

.add-role {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.add-role input { flex: 1; min-width: 120px; }
.add-role select { width: auto; }
.add-role button { flex-shrink: 0; }
.add-role .err { flex-basis: 100%; margin: 0; }

textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}

.ok { color: #56d364; min-height: 1.2em; font-size: 13px; }

#toggle-lock { background: var(--panel-2); border: 1px solid var(--border); }
#toggle-lock:hover { background: var(--panel); }

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
}
.modal-card h2 { margin: 0 0 16px; font-size: 18px; }
.modal-card select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}
.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#open-settings {
  padding: 8px 10px;
  font-size: 16px;
  line-height: 1;
}

@media (max-width: 720px) {
  .room-main { grid-template-columns: 1fr; }
  .sidebar { border-left: 0; border-top: 1px solid var(--border); height: 45%; }
}
