:root {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1f2430;
  --border: #2a3040;
  --text: #eef1f7;
  --muted: #98a2b3;
  --primary: #5865f2;
  --primary-hover: #4752c4;
  --danger: #e5484d;
  --danger-hover: #cd2b31;
  --live: #22c55e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 999px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-pill {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
}

.room-pill strong {
  color: var(--text);
}

/* Lobby */
.lobby {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.lobby-card {
  width: 100%;
  max-width: 540px;
}

.lobby-card h2,
.host-panel h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.subtitle {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.input-row {
  display: flex;
  gap: 8px;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--primary);
}

.label-hint {
  color: var(--muted);
  opacity: 0.75;
  font-size: 12px;
}

.presets-box {
  margin: 20px 0;
}

.presets-header {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.preset-option {
  cursor: pointer;
}

.preset-option input {
  display: none;
}

.preset-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}

.preset-card strong {
  font-size: 13px;
}

.preset-card small {
  font-size: 11px;
  color: var(--muted);
}

.preset-option input:checked + .preset-card {
  border-color: var(--primary);
  background: rgba(88, 101, 242, 0.12);
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
  transition: background 0.12s, opacity 0.12s;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #282f3f;
}

.btn-danger {
  background: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
}

.btn-lg {
  padding: 12px 16px;
  font-size: 15px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
}

.status-msg {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: rgba(229, 72, 77, 0.14);
  border: 1px solid rgba(229, 72, 77, 0.4);
  color: #ffb3b5;
}

/* Host View */
.workspace {
  flex: 1;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.host-panel {
  width: 100%;
  max-width: 780px;
}

.host-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.live-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  margin-bottom: 8px;
}

.live-tag.is-live {
  background: rgba(34, 197, 94, 0.18);
  color: var(--live);
}

.viewer-counter {
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 18px;
  min-width: 86px;
}

.viewer-num {
  display: block;
  font-size: 26px;
  font-weight: 700;
}

.viewer-label {
  font-size: 12px;
  color: var(--muted);
}

.host-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.preview-wrap {
  margin-bottom: 20px;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-wrap video {
  width: 100%;
  max-height: 360px;
  display: block;
  background: #000;
}

.preview-note {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-2);
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.info-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  overflow: hidden;
}

.info-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.info-box strong {
  font-size: 13px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.info-box.wide {
  grid-column: 1 / -1;
}

.info-box.span-2 {
  grid-column: span 2;
}

.mono {
  font-family: Consolas, Menlo, monospace;
}

.viewers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.viewers-list li {
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.viewers-list li.empty {
  color: var(--muted);
}

/* Viewer Player */
.viewer-workspace {
  flex: 1;
  display: flex;
  padding: 16px;
  justify-content: center;
  align-items: center;
}

.player-shell {
  position: relative;
  width: 100%;
  max-width: 1440px;
  height: calc(100vh - 100px);
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-shell:fullscreen {
  max-width: none;
  height: 100vh;
  border-radius: 0;
  border: none;
}

#remoteVideo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.player-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 17, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.overlay-card h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.overlay-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.stats-hud {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 10px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 6px 10px;
  border-radius: 8px;
  font-family: Consolas, Menlo, monospace;
  font-size: 12px;
}

.player-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.controls-left,
.controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

#volumeSlider {
  width: 90px;
  accent-color: var(--primary);
}

.stream-meta {
  font-size: 13px;
  color: var(--muted);
}

[hidden] {
  display: none !important;
}

@media (max-width: 680px) {
  .preset-grid,
  .info-grid,
  .actions-row {
    grid-template-columns: 1fr;
  }

  .info-box.span-2 {
    grid-column: auto;
  }
}
