:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --accent-2: #3b74e0;
  --danger: #e5484d;
  --ok: #30a46c;
  color-scheme: dark;
}

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

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;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  padding: 8px 14px;
}
button:hover { border-color: #3a4150; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-2); }
button.primary.stop { background: var(--danger); border-color: var(--danger); }
button.primary:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; }

input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 0; }

/* Startseite */
.join { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.card h1 { margin: 0; font-size: 24px; }
.card p { margin: 0; }

/* Raum */
.room {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 220px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "bar bar" "stage people";
}

.toolbar {
  grid-area: bar;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.room-info, .controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pill {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.settings { position: relative; }
.settings summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
}
.settings summary::-webkit-details-marker { display: none; }
.settings-body {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: 280px;
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.settings-body p { margin: 0; }

.stage { grid-area: stage; position: relative; overflow: hidden; padding: 12px; }
.grid {
  height: 100%;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
}
.grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="3"], .grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="3"] .tile:first-child { grid-column: 1 / -1; }

.empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
}
.empty p { margin: 4px 0; }

.tile {
  position: relative;
  margin: 0;
  min-height: 0;
  min-width: 0;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.tile.local { border-color: var(--accent); }
.tile video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}
.tile figcaption {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.tile-name, .tile-stats {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0,0,0,.65);
}
.tile-stats { color: #b9c0cc; font-variant-numeric: tabular-nums; }
.tile-stats:empty { display: none; }
.tile-fs {
  margin-left: auto;
  pointer-events: auto;
  padding: 2px 8px;
  background: rgba(0,0,0,.65);
  border-color: transparent;
}
.tile:fullscreen { border: 0; border-radius: 0; }

.people {
  grid-area: people;
  border-left: 1px solid var(--border);
  background: var(--panel);
  padding: 12px 16px;
  overflow: auto;
}
.people h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 4px 0 10px; }
.people ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.people li { display: flex; align-items: center; gap: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people li .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--border); }
.people li.sharing .dot { background: var(--ok); }
.people li .you { color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  z-index: 50;
}

@media (max-width: 760px) {
  .room {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "bar" "stage" "people";
  }
  .people { border-left: 0; border-top: 1px solid var(--border); max-height: 25vh; }
  .grid[data-count] { grid-template-columns: 1fr; }
  .grid[data-count="3"] .tile:first-child { grid-column: auto; }
  .settings-body { right: auto; left: 0; }
}
