/* 全局样式：CSS 变量 + 类名（原生 CSS，无框架）。 */

:root {
  --color-bg: #0e1116;
  --color-surface: #171b22;
  --color-fg: #e8ecf2;
  --color-muted: #9aa4b2;
  --color-accent: #2f80ed;
  --color-warn: #f2c94c;
  --color-ok: #27ae60;
  --color-danger: #eb5757;
  --radius: 10px;
  --gap: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  padding: var(--gap);
  gap: var(--gap);
}

/* ---------- 顶部状态条 ---------- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding: 10px 14px;
  background: var(--color-surface);
  border-radius: var(--radius);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-muted);
  flex: 0 0 auto;
}
.state-idle { background: var(--color-muted); }
.state-init,
.state-creating,
.state-waiting,
.state-negotiating,
.state-connecting,
.state-reconnecting {
  background: var(--color-warn);
  animation: pulse 1.2s ease-in-out infinite;
}
.state-connected { background: var(--color-ok); }
.state-ended { background: var(--color-muted); }
.state-error { background: var(--color-danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.status-text {
  font-weight: 600;
}

.spacer {
  flex: 1 1 auto;
}

.status-preset {
  color: var(--color-muted);
}

.link-badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.badge-direct {
  background: rgba(39, 174, 96, 0.18);
  color: var(--color-ok);
  border: 1px solid var(--color-ok);
}
.badge-relay {
  background: rgba(242, 201, 76, 0.18);
  color: var(--color-warn);
  border: 1px solid var(--color-warn);
}

/* ---------- 提示条 ---------- */
.notice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}
.notice-warn {
  background: rgba(242, 201, 76, 0.15);
  border: 1px solid var(--color-warn);
  color: var(--color-warn);
}
.notice-ok {
  background: rgba(39, 174, 96, 0.15);
  border: 1px solid var(--color-ok);
  color: var(--color-ok);
}
.notice-danger {
  background: rgba(235, 87, 87, 0.15);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
}
.notice-text {
  flex: 1 1 auto;
}
.notice-close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- 舞台 / 视频 ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  flex: 1 1 auto;
  min-height: 0;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #000;
}
.video-local {
  /* 摄像头自拍预览默认镜像（符合自拍直觉）；屏幕分享时由 JS 移除 is-mirror 类，不镜像 */
}
.video-local.is-mirror {
  transform: scaleX(-1);
}

/* ---------- 覆盖层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(6, 8, 12, 0.72);
  backdrop-filter: blur(2px);
}
.overlay-text {
  margin: 0;
  font-size: 16px;
  max-width: 32em;
  line-height: 1.5;
}
.overlay-actions {
  display: flex;
  gap: 10px;
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 1px solid #2b323d;
  background: #232a34;
  color: var(--color-fg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:hover {
  background: #2b333f;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
}
.btn-primary:hover {
  background: #1f6fd6;
}
.btn-danger {
  background: var(--color-danger);
  border-color: var(--color-danger);
}
.btn-danger:hover {
  background: #d34747;
}

/* ---------- 控制区 ---------- */
.controls-bar {
  display: flex;
  flex-direction: column;
  flex: none;
  gap: 10px;
  padding: 12px 14px;
  background: var(--color-surface);
  border-radius: var(--radius);
}
.room-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.room-label,
.passcode-label {
  color: var(--color-muted);
  font-size: 13px;
}
.room-id {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}
.passcode-value {
  font-weight: 600;
  color: var(--color-warn);
}
.controls-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- 档位分段控件 ---------- */
.preset-seg {
  display: inline-flex;
  border: 1px solid #2b323d;
  border-radius: 8px;
  overflow: hidden;
}
.preset-btn {
  appearance: none;
  border: none;
  background: #232a34;
  color: var(--color-fg);
  padding: 8px 16px;
  cursor: pointer;
  border-right: 1px solid #2b323d;
}
.preset-btn:last-child {
  border-right: none;
}
.preset-btn.active {
  background: var(--color-accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- 输入源 / 自定义画质 ---------- */
.source-label,
.custom-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-muted);
  font-size: 13px;
}
.source-select,
.custom-input,
.custom-panel select {
  background: #1a2029;
  color: var(--color-fg);
  border: 1px solid #2b323d;
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  max-width: 240px;
}
.custom-input {
  width: 90px;
}
.custom-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px dashed #2b323d;
  border-radius: 8px;
}

/* ---------- 入房表单 ---------- */
.join-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: none;
  gap: 14px;
  padding: 28px;
  background: var(--color-surface);
  border-radius: var(--radius);
  max-width: 420px;
  margin: 24px auto;
}
.join-room {
  font-size: 16px;
}
.join-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  color: var(--color-muted);
  width: 100%;
}
.join-input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #2b323d;
  background: #10141a;
  color: var(--color-fg);
  font-size: 18px;
  letter-spacing: 4px;
  text-align: center;
}
.join-error {
  color: var(--color-danger);
  font-size: 14px;
  margin: 0;
}

/* ---------- 指标条 ---------- */
.metrics-bar {
  display: flex;
  flex-wrap: wrap;
  flex: none;
  gap: 6px 18px;
  padding: 10px 14px;
  background: var(--color-surface);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--color-muted);
}
.metrics-item b {
  color: var(--color-fg);
  font-variant-numeric: tabular-nums;
}
/* 音画不同步警示（复用 warn 配色变量） */
.metrics-item b.metric-warn {
  color: var(--color-warn);
}

/* ---------- toast ---------- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: 999px;
  background: #232a34;
  color: var(--color-fg);
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-out {
  opacity: 0;
  transform: translateY(8px);
}
.toast-ok { border: 1px solid var(--color-ok); }
.toast-warn { border: 1px solid var(--color-warn); }
.toast-danger { border: 1px solid var(--color-danger); }
.toast-info { border: 1px solid #2b323d; }

@media (max-width: 640px) {
  .room-id { font-size: 18px; }
  .preset-btn { padding: 8px 10px; }
}

/* 小屏 / 矮视口适配：压缩纵向留白，保证指标条留在首屏底部 */
@media (max-height: 760px) {
  .app {
    --gap: 6px;
  }
  .controls-bar,
  .metrics-bar {
    padding-top: 6px;
    padding-bottom: 6px;
  }
}
