:root {
  --bg: #14161a;
  --bg-elevated: #1c1f25;
  --bg-panel: #20242b;
  --border: #2c313a;
  --text: #e8eaed;
  --text-dim: #9aa2ad;
  --accent: #5b9bd5;
  --accent-hover: #79b0e0;
  --danger: #d16969;
  --danger-hover: #e08585;
  --ok: #6fbf8f;
  --pending: #d3b15c;
  --radius: 14px;
  --radius-sm: 8px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

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

.hidden { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Landing ---------- */
.view { min-height: 100vh; }

#view-gate, #view-landing, #view-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#view-gate .landing-card {
  text-align: center;
}
#view-gate .actions {
  display: flex;
  justify-content: center;
}
#view-gate input {
  text-align: center;
}

.landing-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.brand {
  margin: 0 0 4px;
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tagline {
  color: var(--text-dim);
  margin: 0 0 24px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.stack { display: flex; flex-direction: column; gap: 8px; }

label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 12px;
}

input[type="text"], input[type="number"], input[type="password"], select {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
}

input:focus, select:focus, button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(91, 155, 213, 0.3);
}

.actions { margin-top: 20px; }

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  background: var(--bg-panel);
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--bg-panel); }

.btn-ghost { background: transparent; margin-top: 16px; }

.btn-danger-outline { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: rgba(209, 105, 105, 0.12); }

.join-alt { margin-top: 20px; color: var(--text-dim); font-size: 0.9rem; }
.join-alt summary { cursor: pointer; }
.join-alt form { margin-top: 12px; }

.joining-note { color: var(--accent); font-size: 0.9rem; margin: 0 0 4px; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 9, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.overlay .landing-card { width: 100%; max-width: 420px; }
.overlay .actions { display: flex; gap: 8px; }

.room-list-section {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.room-list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.room-list-header h2 {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-dim);
  font-weight: 600;
}

.room-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
}
.room-row-label { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row button { flex-shrink: 0; padding: 6px 12px; font-size: 0.8rem; }

.privacy-note {
  margin-top: 24px;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.invite-row { display: flex; gap: 8px; margin: 16px 0; }
.invite-row input { flex: 1; min-width: 0; }

.status-line { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 0.9rem; }

.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pending);
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.status-pending { background: var(--pending); }
.status-dot.status-connected { background: var(--ok); }
.status-dot.status-error { background: var(--danger); }

/* ---------- Room ---------- */
#view-room {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.room-status { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-dim); }

.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 0.85rem; padding: 0; margin-left: 8px;
  text-decoration: underline;
}

.diagnostics-panel {
  padding: 6px 16px;
  font-size: 0.78rem;
  color: var(--text-dim);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #0b0c0e;
  overflow: hidden;
}

.video-wrap.remote {
  position: absolute;
  inset: 0;
}
.video-wrap.remote video {
  width: 100%; height: 100%; object-fit: contain; background: #000;
}

.video-wrap.local {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: min(220px, 32vw);
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.video-wrap.local video {
  width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1);
}

.video-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  background: #0b0c0e;
}
.video-placeholder.small { font-size: 0.75rem; }

.badge {
  position: absolute;
  top: 12px; left: 12px;
  background: rgba(91, 155, 213, 0.9);
  color: #0d1117;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.error-banner {
  background: rgba(209, 105, 105, 0.15);
  border-top: 1px solid var(--danger);
  color: #f2c2c2;
  padding: 10px 16px;
  font-size: 0.88rem;
  flex-shrink: 0;
}

.control-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 1.1rem;
  min-width: 64px;
}
.ctrl-btn span { font-size: 0.68rem; color: var(--text-dim); }
.ctrl-btn:hover { border-color: var(--accent); }
.ctrl-btn[aria-pressed="true"] { border-color: var(--danger); background: rgba(209,105,105,0.15); }
.ctrl-btn.ctrl-danger { border-color: var(--danger); }
.ctrl-btn.ctrl-danger:hover { background: rgba(209, 105, 105, 0.15); }

/* ---------- Side panels ---------- */
.side-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(360px, 100vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.side-panel-header h2 { margin: 0; font-size: 1rem; }

.icon-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 1rem; cursor: pointer; padding: 4px;
}

.tabs { display: flex; gap: 4px; }
.tab {
  background: none; border: none; color: var(--text-dim);
  padding: 6px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.tab.active { background: var(--bg-panel); color: var(--text); }

.panel-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 12px 16px; overflow-y: auto; }

.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.chat-msg { font-size: 0.9rem; line-height: 1.4; word-break: break-word; }
.chat-meta { display: block; font-size: 0.72rem; color: var(--text-dim); margin-bottom: 2px; }
.chat-name { font-weight: 600; }

.chat-input-row { display: flex; gap: 8px; flex-shrink: 0; }
.chat-input-row input { flex: 1; min-width: 0; }

.settings-body { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.custom-quality { display: flex; flex-direction: column; gap: 4px; border-top: 1px dashed var(--border); margin-top: 8px; padding-top: 8px; }

.hint { color: var(--text-dim); font-size: 0.78rem; line-height: 1.5; margin: 8px 0; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 24px 12px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.9rem;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); color: var(--text); }

.file-queue { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.file-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.85rem;
}
.file-item-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { color: var(--text-dim); flex-shrink: 0; }
.file-progress { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.file-progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width 0.15s; }
.file-item-meta { display: flex; justify-content: space-between; color: var(--text-dim); font-size: 0.75rem; margin-top: 4px; }
.file-item-actions { display: flex; gap: 6px; margin-top: 8px; }
.file-item-actions button {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 10px; font-size: 0.78rem; cursor: pointer;
}
.file-item-actions button:hover { border-color: var(--accent); }

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed;
  bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 100;
}
.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.toast.toast-error { border-color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .video-wrap.local { width: 30vw; right: 10px; bottom: 10px; }
  .ctrl-btn { min-width: 52px; padding: 8px; }
  .ctrl-btn span { display: none; }
  .side-panel { width: 100vw; }
}
