:root {
  --bg: #0a0c13;
  --panel: rgba(255, 255, 255, 0.045);
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef0f7;
  --muted: #8b91a7;
  --accent: #7c7cf5;
  --accent2: #a855f7;
  --danger: #f05a6a;
  --ok: #34d399;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(124, 124, 245, 0.16), transparent 60%),
    radial-gradient(900px 500px at 100% 110%, rgba(168, 85, 247, 0.13), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 22px 28px 26px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; }

.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 650; letter-spacing: .2px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(124, 124, 245, .35);
}
.brand-mark span { width: 10px; height: 10px; border-radius: 50%; background: #fff; }
.brand-tag {
  font-size: 11px; font-weight: 500; color: #b9bcf6;
  background: rgba(124, 124, 245, .14); border: 1px solid rgba(124, 124, 245, .22);
  padding: 3px 8px; border-radius: 999px;
}

.top-actions { display: flex; align-items: center; gap: 10px; }
.badge {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 13px; border-radius: 999px;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: #6b7085; transition: .25s; }
.badge.connected .dot { background: var(--ok); box-shadow: 0 0 0 4px rgba(52, 211, 153, .14); }
.badge.connecting .dot { background: #fbbf24; animation: pulse 1.2s infinite; }
.badge.connected { color: #c7f5e2; }

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 11px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted); cursor: pointer; transition: .2s;
}
.icon-btn:hover { color: #fff; background: rgba(255, 255, 255, .09); }
.icon-btn svg { width: 18px; height: 18px; }

.stage { flex: 1; min-height: 0; display: flex; }

.video-wrap {
  position: relative; flex: 1; min-height: 0;
  border-radius: 22px; overflow: hidden;
  background: linear-gradient(160deg, #151826, #0e1019 70%);
  border: 1px solid var(--border);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .45);
}
.video-wrap::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: radial-gradient(70% 50% at 50% 0%, rgba(124, 124, 245, .07), transparent 70%);
}

#remoteVideo { width: 100%; height: 100%; object-fit: cover; display: block; background: #0d0f18; }

.placeholder {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 30px; gap: 10px;
}
.placeholder[hidden], .name-tag[hidden], .local-pip[hidden], .stats-panel[hidden] { display: none; }
.placeholder-icon {
  width: 66px; height: 66px; border-radius: 20px; display: grid; place-items: center;
  background: rgba(124, 124, 245, .13); border: 1px solid rgba(124, 124, 245, .25);
  color: #a9a9ff; margin-bottom: 6px;
}
.placeholder-icon svg { width: 32px; height: 32px; }
.placeholder h2 { margin: 0; font-size: 22px; font-weight: 620; }
.placeholder p { margin: 0; max-width: 420px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.room-chip {
  margin-top: 10px; font-size: 12px; color: #b9bcf6;
  background: rgba(124, 124, 245, .12); border: 1px solid rgba(124, 124, 245, .22);
  padding: 7px 14px; border-radius: 999px;
}
.room-chip b { color: #fff; margin-left: 5px; letter-spacing: .5px; }

.name-tag {
  position: absolute; z-index: 3; font-size: 11px; color: #e8eaf2;
  background: rgba(10, 12, 19, .65); backdrop-filter: blur(8px);
  border: 1px solid var(--border); padding: 5px 10px; border-radius: 8px;
}
.remote-tag { top: 16px; left: 16px; }

.local-pip {
  position: absolute; z-index: 4; right: 18px; bottom: 18px;
  width: clamp(150px, 20vw, 250px); aspect-ratio: 16 / 9;
  border-radius: 14px; overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .18);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
  background: #11131d;
}
.local-pip video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.local-pip .name-tag { left: 8px; bottom: 8px; padding: 3px 8px; }

.stats-panel {
  position: absolute; z-index: 5; top: 16px; right: 16px; width: 246px;
  background: rgba(14, 16, 25, .88); backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 14px; padding: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
.stats-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 10px; letter-spacing: .5px; }
.stats-head button { background: none; border: 0; color: var(--muted); font-size: 19px; cursor: pointer; line-height: 1; }
.stat-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 6px 0; border-top: 1px solid rgba(255, 255, 255, .05); }
.stat-row span { color: var(--muted); }
.stat-row b { font-weight: 550; font-variant-numeric: tabular-nums; }

.controls { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.ctrl {
  min-width: 104px; height: 58px; padding: 0 18px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 15px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer;
  font-size: 11px; transition: .2s; backdrop-filter: blur(10px);
}
.ctrl svg { width: 21px; height: 21px; }
.ctrl .off { display: none; }
.ctrl.muted .on { display: none; }
.ctrl.muted .off { display: block; }
.ctrl.muted { color: var(--danger); border-color: rgba(240, 90, 106, .3); }
.ctrl:hover:not(:disabled) { background: rgba(255, 255, 255, .1); transform: translateY(-2px); }
.ctrl:disabled { opacity: .38; cursor: not-allowed; }
.ctrl.hangup { background: rgba(240, 90, 106, .14); border-color: rgba(240, 90, 106, .32); color: #ff9aa5; }
.ctrl.hangup:hover:not(:disabled) { background: rgba(240, 90, 106, .24); }

.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 20px;
  background: rgba(5, 6, 11, .74); backdrop-filter: blur(12px);
}
.modal[hidden] { display: none; }
.card {
  width: min(430px, 100%); padding: 34px;
  border-radius: 22px; background: linear-gradient(160deg, #1a1d2b, #12141e);
  border: 1px solid var(--border); box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
}
.card-icon {
  width: 52px; height: 52px; border-radius: 15px; display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(124, 124, 245, .22), rgba(168, 85, 247, .18));
  border: 1px solid rgba(124, 124, 245, .3); color: #b9b9ff; margin-bottom: 18px;
}
.card-icon svg { width: 27px; height: 27px; }
.card h1 { margin: 0 0 8px; font-size: 24px; font-weight: 650; }
.subtitle { margin: 0 0 26px; color: var(--muted); font-size: 13px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 9px; }
.text-input {
  width: 100%; height: 46px; padding: 0 15px; margin-bottom: 22px;
  border-radius: 11px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04); color: #fff; font-size: 14px; outline: none;
  transition: .2s;
}
.text-input:focus { border-color: rgba(124, 124, 245, .6); box-shadow: 0 0 0 3px rgba(124, 124, 245, .12); }
.text-input::placeholder { color: #5d6279; }

.quality { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 24px; }
.quality button {
  padding: 11px 6px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--border); background: rgba(255, 255, 255, .03); color: var(--muted);
  display: flex; flex-direction: column; gap: 4px; transition: .2s;
}
.quality button b { font-size: 13px; font-weight: 600; }
.quality button small { font-size: 10px; opacity: .75; }
.quality button:hover { background: rgba(255, 255, 255, .07); }
.quality button.active {
  color: #fff; border-color: rgba(124, 124, 245, .6);
  background: linear-gradient(135deg, rgba(124, 124, 245, .28), rgba(168, 85, 247, .2));
  box-shadow: 0 6px 18px rgba(124, 124, 245, .18);
}

.demo-toggle {
  display: flex; align-items: center; gap: 9px;
  font-size: 12px; color: var(--muted); cursor: pointer;
  margin: -8px 0 22px; user-select: none;
}
.demo-toggle input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.primary-btn {
  width: 100%; height: 48px; border: 0; border-radius: 12px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 10px 26px rgba(124, 124, 245, .3); transition: .2s;
}
.primary-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.primary-btn:disabled { opacity: .6; cursor: wait; transform: none; }
.hint { margin: 14px 0 0; text-align: center; font-size: 11px; color: #6b7089; line-height: 1.6; }
.error { margin: 12px 0 0; text-align: center; font-size: 12px; color: #ff9aa5; }

.toast {
  position: fixed; z-index: 30; bottom: 104px; left: 50%; transform: translateX(-50%);
  padding: 11px 18px; border-radius: 11px; font-size: 13px;
  background: rgba(24, 27, 40, .96); border: 1px solid var(--border);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .5);
}
.toast[hidden] { display: none; }

@keyframes pulse { 50% { opacity: .35; } }

@media (max-width: 720px) {
  .app { padding: 14px; gap: 12px; }
  .brand-tag { display: none; }
  .ctrl { min-width: 72px; padding: 0 10px; }
  .local-pip { width: 130px; right: 10px; bottom: 10px; }
  .stats-panel { width: 210px; }
  .card { padding: 26px; }
}
