:root {
  --bg0: #0b1220;
  --bg1: #121a2b;
  --panel: rgba(18, 28, 46, 0.88);
  --line: rgba(148, 178, 220, 0.18);
  --text: #eef3fb;
  --muted: #8fa0b8;
  --accent: #3ecf8e;
  --accent-2: #f0b429;
  --danger: #ff6b6b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --font-display: "Syne", "Segoe UI", sans-serif;
  --font-body: "DM Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(1000px 500px at 10% -10%, rgba(62, 207, 142, 0.18), transparent 55%),
    radial-gradient(800px 420px at 100% 0%, rgba(240, 180, 41, 0.12), transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1));
}

[hidden] { display: none !important; }

.auth-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.auth-glow {
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(62, 207, 142, 0.22), transparent 70%);
  filter: blur(8px);
  animation: drift 10s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate(-30%, -20%); }
  to { transform: translate(40%, 25%); }
}

.auth-card {
  width: min(420px, 100%);
  padding: 36px 32px 28px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 1;
}

.brand, .brand-mark {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--accent);
}

.auth-card .brand {
  margin: 0 0 10px;
  font-size: 42px;
  line-height: 1;
}

.auth-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.auth-sub {
  margin: 8px 0 22px;
  color: var(--muted);
  font-size: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  font: inherit;
  cursor: pointer;
}

.tab.active {
  color: var(--text);
  border-color: rgba(62, 207, 142, 0.55);
  background: rgba(62, 207, 142, 0.1);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.auth-form input,
.composer input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(8, 14, 24, 0.7);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  outline: none;
}

.auth-form input:focus,
.composer input:focus {
  border-color: rgba(62, 207, 142, 0.65);
}

.btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 11px 16px;
  font: inherit;
  cursor: pointer;
}

.btn.primary {
  border-color: rgba(62, 207, 142, 0.5);
  background: linear-gradient(135deg, #2db87a, #3ecf8e);
  color: #04140c;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
}

.btn.mic {
  width: 100%;
  font-weight: 700;
}

.btn.mic.off {
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.12);
  color: #ffb4b4;
}

.btn.mic.on {
  border-color: rgba(62, 207, 142, 0.5);
  background: rgba(62, 207, 142, 0.18);
  color: #9df0c5;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.room-view {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 12, 20, 0.55);
  backdrop-filter: blur(10px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.brand-mark { font-size: 22px; }
.self-name {
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 方形自适应头像 */
.avatar {
  display: inline-grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  width: clamp(28px, 7vw, 40px);
  height: auto;
  flex-shrink: 0;
  object-fit: cover;
  object-position: center;
  border: 1px solid var(--line);
  background: rgba(62, 207, 142, 0.16);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.72em;
  overflow: hidden;
  vertical-align: middle;
}
.avatar-lg {
  width: clamp(36px, 8vw, 48px);
}
.avatar-sm {
  width: clamp(24px, 6vw, 32px);
  font-size: 0.65em;
}
.avatar-fallback {
  text-transform: uppercase;
}
img.avatar {
  display: block;
  background: #0d1522;
}

.self-avatar-wrap {
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}
.self-avatar-wrap:hover .avatar {
  outline: 2px solid rgba(62, 207, 142, 0.55);
  outline-offset: 2px;
}

.room {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.peers-panel,
.chat-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.peers-panel {
  border-right: 1px solid var(--line);
  background: rgba(10, 16, 28, 0.55);
  padding: 14px;
}

.panel-head {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.peer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 80px;
}

.peer-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  font-size: 14px;
}

.peer-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.peer-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.peer-identity .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.peer-item.self {
  border-color: rgba(62, 207, 142, 0.35);
}

.peer-item .tag {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.peer-item .tag.live { color: var(--accent); }
.peer-item .tag.warn { color: var(--accent-2); }
.peer-item .tag.bad { color: var(--danger); }

.peer-item .peer-meter {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.peer-item .peer-retry {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
}

.voice-controls {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.status-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.status-pill.off { color: #ffb4b4; border-color: rgba(255, 107, 107, 0.35); background: rgba(255, 107, 107, 0.1); }
.status-pill.live { color: #9df0c5; border-color: rgba(62, 207, 142, 0.45); background: rgba(62, 207, 142, 0.12); }
.status-pill.test { color: #ffe08a; border-color: rgba(240, 180, 41, 0.45); background: rgba(240, 180, 41, 0.12); }
.status-pill.idle { color: var(--muted); }
.status-pill.playing { color: #9df0c5; border-color: rgba(62, 207, 142, 0.45); background: rgba(62, 207, 142, 0.12); }
.status-pill.warn { color: #ffe08a; border-color: rgba(240, 180, 41, 0.45); background: rgba(240, 180, 41, 0.12); }

.meter { display: flex; flex-direction: column; gap: 4px; }
.meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
}
.meter-track {
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  transition: width 50ms linear;
}
.meter-fill.mic { background: linear-gradient(90deg, #2db87a, #3ecf8e 55%, #f0b429 85%, #ff6b6b); }
.meter-fill.speaker { background: linear-gradient(90deg, #3a7bd5, #3ecf8e 70%, #f0b429); }

.slider-row {
  display: grid;
  grid-template-columns: 72px 1fr 42px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.slider-row input[type="range"] {
  width: 100%;
  accent-color: #3ecf8e;
}
.slider-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.voice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.hint.device {
  font-size: 11px;
  opacity: 0.85;
  word-break: break-all;
}

.chat-panel {
  padding: 0;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: min(680px, 92%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}

.msg .msg-main { min-width: 0; }

.msg .meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
}

.msg .meta .name {
  color: var(--accent-2);
  font-weight: 700;
}

.msg .body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  font-size: 15px;
}

.msg.system {
  align-self: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 4px;
  display: block;
  max-width: none;
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: rgba(8, 12, 20, 0.55);
}

.composer input { flex: 1; }

.audio-stage { position: absolute; width: 0; height: 0; overflow: hidden; }

@media (max-width: 720px) {
  .room {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .peers-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }
  .peer-list { max-height: 120px; }
  .auth-card { padding: 28px 20px 22px; }
  .auth-card .brand { font-size: 36px; }
}
