:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1f2733;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: radial-gradient(1200px 600px at 50% -10%, #1a2332 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── 顶栏 ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, 0.7);
  backdrop-filter: blur(8px);
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
}

.brand strong {
  display: block;
  font-size: 16px;
}

.brand span {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.connection-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #484f58;
  flex: none;
}

.status-dot.online {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.status-dot.connecting {
  background: var(--warn);
  box-shadow: 0 0 8px var(--warn);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

/* ── 主布局 ───────────────────────────────────────────── */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr);
  gap: 20px;
  padding: 20px 22px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

/* ── 舞台 ─────────────────────────────────────────────── */
.stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.video-frame {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.video-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-dim);
  background: radial-gradient(400px 240px at 50% 50%, #1a2230 0%, #0b0f14 100%);
  pointer-events: none;
}

.video-placeholder .placeholder-mark {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 40px;
  color: #fff;
  background: linear-gradient(135deg, #2f81f7, #7c3aed);
  opacity: 0.9;
}

.video-placeholder p {
  margin: 0;
  font-size: 14px;
}

.video-frame.has-video .video-placeholder {
  display: none;
}

.speaking-badge {
  position: absolute;
  left: 14px;
  bottom: 14px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(31, 111, 235, 0.85);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.speaking-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 0.9s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

.stage-controls {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.select-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.select-label select {
  appearance: none;
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.primary-button,
.secondary-button {
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
}

.primary-button {
  background: var(--accent-2);
  color: #fff;
  font-weight: 600;
}

.primary-button:hover {
  background: var(--accent);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.primary-button.connected {
  background: var(--danger);
}

.secondary-button {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--text);
}

.error-text {
  margin: 0;
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.4);
  color: #ff9b94;
  font-size: 13px;
}

/* ── 侧栏 ─────────────────────────────────────────────── */
.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.agent-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.agent-state {
  font-size: 18px;
  font-weight: 600;
}

.state-badge,
.small-state {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

.voice-meter {
  display: flex;
  gap: 4px;
  height: 40px;
  align-items: center;
  justify-content: center;
}

.voice-meter span {
  width: 5px;
  height: 8px;
  border-radius: 3px;
  background: #30363d;
  transition: height 0.12s ease, background 0.12s ease;
}

.voice-meter[data-state="speaking"] span,
.voice-meter.user-speaking span {
  background: var(--accent);
  animation: bar 0.6s ease-in-out infinite alternate;
}

.voice-meter[data-state="listening"] span {
  background: var(--ok);
  animation: bar 0.8s ease-in-out infinite alternate;
}

.voice-meter[data-state="thinking"] span {
  background: var(--warn);
  animation: bar 1s ease-in-out infinite alternate;
}

@keyframes bar {
  from { height: 6px; }
  to { height: 36px; }
}

.mic-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.transcript {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.transcript-head {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.transcript-body {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  min-height: 40px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.transcript.assistant .transcript-body {
  color: #9ecbff;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.meta-item {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.meta-item dt {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.meta-item dd {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
}

/* ── 手机端适配 ─────────────────────────────────────────── */
@media (max-width: 720px) {
  .topbar {
    padding: 10px 14px;
  }
  .brand span {
    display: none;
  }
  .brand strong {
    font-size: 15px;
  }
  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }
  .layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }
  .video-frame {
    aspect-ratio: 4 / 3;
    border-radius: 10px;
  }
  .stage-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .select-label {
    width: 100%;
  }
  .select-label select {
    width: 100%;
    min-width: 0;
    padding: 12px;
    font-size: 15px;
  }
  .primary-button {
    width: 100%;
    padding: 14px;
    font-size: 16px;
    border-radius: 10px;
  }
  .panel {
    padding: 14px;
    gap: 12px;
    border-radius: 10px;
  }
  .agent-state {
    font-size: 17px;
  }
  .transcript-body {
    font-size: 14px;
    min-height: 32px;
  }
  .meta-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .meta-item {
    padding: 8px 10px;
  }
  .voice-meter {
    height: 32px;
  }
  .voice-meter span {
    width: 4px;
  }
}
