:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --accent: #7c6cff;
  --accent-2: #5b4ee0;
  --ok: #3ccf8e;
  --warn: #f5b84b;
  --bad: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); margin: 0; }

button, input {
  font: inherit;
  color: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  padding: 8px 12px;
}
button { cursor: pointer; white-space: nowrap; }
button:hover { border-color: #3a4150; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.ghost { background: transparent; }
button.danger { background: var(--bad); border-color: var(--bad); color: #111; }
button.active { background: var(--ok); border-color: var(--ok); color: #111; }
input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Join */
.join { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 14px;
}
.card h1 { margin: 0; font-size: 26px; }
.card p { margin: 0; }
.card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.card input { color: var(--text); font-size: 15px; }

.button-link, .ghost-link {
  display: inline-block;
  text-decoration: none;
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
}
.button-link { background: var(--accent); color: #fff; }
.button-link:hover { background: var(--accent-2); }
.ghost-link { color: var(--muted); border: 1px solid var(--line); }
.ghost-link:hover { color: var(--text); border-color: #3a4150; }

/* Room layout */
.room {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "stage side";
}
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { font-size: 17px; }
.room-name { color: var(--muted); }
.url-form { display: flex; gap: 6px; flex: 1; min-width: 220px; }
.url-form input { flex: 1; min-width: 0; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.conn.ok { background: var(--ok); }
.conn.bad { background: var(--bad); }

.stage { grid-area: stage; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 14px; gap: 8px; }
.player-wrap {
  position: relative;
  flex: 1;
  min-height: 240px;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  place-items: center;
}
.player-wrap video, #yt-host, #yt-host iframe { width: 100%; height: 100%; border: 0; }
.player-wrap video { object-fit: contain; background: #000; }
#yt-host { position: absolute; inset: 0; }
#screen { position: absolute; inset: 0; z-index: 2; }
.empty { text-align: center; padding: 20px; }
.empty p { margin: 4px 0; }
.unblock {
  position: absolute;
  z-index: 3;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 17px;
  padding: 14px 22px;
}
.player-note {
  position: absolute;
  z-index: 3;
  max-width: min(460px, calc(100% - 32px));
  margin: 0;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: rgba(23, 26, 33, .92);
  border: 1px solid var(--line);
  text-align: center;
}
.player-note a { color: var(--accent); display: inline-block; margin-top: 8px; }
.now-playing { display: flex; gap: 10px; align-items: center; min-height: 24px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--ok); }

/* Sidebar */
.side {
  grid-area: side;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.call-bar { display: flex; gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.call-bar button { flex: 1; }
.members { list-style: none; margin: 0; padding: 8px 12px; border-bottom: 1px solid var(--line); max-height: 30%; overflow: auto; }
.members li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.members .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.members .dot.call { background: var(--ok); }
.members .dot.muted { background: var(--warn); }
.members .dot.speaking { box-shadow: 0 0 0 3px rgba(60, 207, 142, .45); }
.members .tag { font-size: 11px; color: var(--muted); }
.chat-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.msg { word-wrap: break-word; }
.msg .who { font-weight: 600; margin-right: 6px; }
.msg .time { color: var(--muted); font-size: 11px; margin-left: 6px; }
.msg.system { color: var(--muted); font-size: 13px; font-style: italic; }
.chat-form { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; min-width: 0; }

/* Library */
.library {
  width: min(640px, calc(100% - 32px));
  max-height: 80vh;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.library::backdrop { background: rgba(0, 0, 0, .6); }
.library-head { display: flex; justify-content: space-between; align-items: center; }
.library-head h2 { margin: 0; }
.upload {
  display: block;
  margin: 14px 0 6px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  cursor: pointer;
}
.upload:hover { border-color: var(--accent); }
.upload input { display: none; }
.progress { margin: 6px 0; font-size: 13px; }
.progress .bar { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.progress .bar div { height: 100%; background: var(--accent); width: 0; }
.media-list { list-style: none; padding: 0; margin: 10px 0 0; display: grid; gap: 6px; }
.media-list li {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
}
.media-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 860px) {
  .room {
    height: auto;
    min-height: 100%;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    grid-template-areas: "top" "stage" "side";
  }
  .player-wrap { aspect-ratio: 16 / 9; flex: none; min-height: 0; }
  .side { border-left: 0; border-top: 1px solid var(--line); min-height: 420px; }
}

/* Host dashboard */
.dash { min-height: 100%; }
.dash-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.dash-head .me { margin-left: auto; }
.dash-main { width: min(860px, 100%); margin: 0 auto; padding: 20px 16px 40px; }
.dash-main h2 { font-size: 17px; margin: 0 0 12px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.create-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; align-items: end; }
.create-row label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.create-row input { color: var(--text); min-width: 0; }
.pw-field { display: flex; gap: 6px; }
.pw-field input { flex: 1; }
.create .error { margin-top: 10px; }
.rooms-head { margin-top: 28px !important; }
.rooms { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.room-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: grid;
  gap: 10px;
}
.room-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.room-top strong { font-size: 16px; }
.online { font-size: 12px; color: var(--muted); }
.online.live { color: var(--ok); }
.room-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.room-facts dt { color: var(--muted); }
.room-facts dd { margin: 0; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.room-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.room-actions .danger-ghost { color: var(--bad); background: transparent; margin-left: auto; }

@media (max-width: 640px) {
  .create-row { grid-template-columns: 1fr; }
  .room-actions .danger-ghost { margin-left: 0; }
}
