:root {
  --bg: #0a0c10;
  --panel: #12161c;
  --panel-2: #171c24;
  --line: #242b36;
  --text: #e9edf3;
  --muted: #8b95a5;
  --brand: #3ddc97;
  --brand-dark: #0b3b28;
  --radius: 12px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

button:hover:not(:disabled) {
  background: #1e242d;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #04231a;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #4deea7;
}

button.ghost {
  background: transparent;
}

button.small {
  padding: 6px 12px;
  font-size: 12px;
}

button.on {
  background: var(--brand-dark);
  border-color: var(--brand);
  color: var(--brand);
}

input {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px;
  outline: none;
}

input:focus {
  border-color: #3b4757;
}

input::placeholder {
  color: #64707f;
}

.hidden {
  display: none !important;
}

/* ---------- 大厅 ---------- */

.lobby {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lobby-card {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 16px;
  justify-items: stretch;
  text-align: center;
  padding: 32px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.lobby-card h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: 0.06em;
}

.lobby-sub {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.join {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.join input {
  min-width: 0;
  text-align: center;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.lobby-error {
  margin: 0;
  min-height: 18px;
  color: #ff7b72;
  font-size: 12px;
}

/* ---------- 房间 ---------- */

.room {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}

.room-id {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-id .label {
  color: var(--muted);
  font-size: 12px;
}

.room-id strong {
  font: 600 15px/1.2 "JetBrains Mono", ui-monospace, Consolas, monospace;
  letter-spacing: 0.12em;
  color: var(--brand);
}

.presence {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  margin-right: auto;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #4a5563;
  transition: background 0.2s ease;
}

.dot.live {
  background: var(--brand);
  box-shadow: 0 0 0 3px rgba(61, 220, 151, 0.16);
}

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.voice-state {
  font-size: 11px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.voice-state[data-state="ok"] {
  color: var(--brand);
  border-color: rgba(61, 220, 151, 0.4);
}

.voice-state[data-state="bad"] {
  color: #ff8a80;
  border-color: rgba(255, 138, 128, 0.4);
}

.voice-state[data-state="warn"] {
  color: #ffcf6b;
  border-color: rgba(255, 207, 107, 0.4);
}

.cache-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.cache-hint[data-state="ok"] {
  color: var(--brand);
}

.remote-audio {
  display: none;
}

.stage {
  position: relative;
  background: #000;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}

.stage video {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #000;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(2px);
}

.overlay-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
  padding: 28px 24px;
  background: var(--panel);
  border: 1px dashed #2d3644;
  border-radius: var(--radius);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

.overlay-card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.overlay-card .hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: #5f6b7a;
}

.overlay.dragover {
  background: rgba(61, 220, 151, 0.12);
  border: 2px dashed var(--brand);
}

.upload-panel {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 48px));
  padding: 14px 16px;
  background: rgba(18, 22, 28, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.upload-name {
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-row button {
  flex: 0 0 auto;
}

.bar {
  height: 6px;
  border-radius: 999px;
  background: #232b36;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  background: var(--brand);
  transition: width 0.2s ease;
}

.upload-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.gesture-hint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 18px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- 侧栏 ---------- */

.side {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.video-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.chat-log {
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.msg {
  max-width: 90%;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--panel-2);
  font-size: 13px;
  line-height: 1.45;
  word-break: break-word;
}

.msg.mine {
  align-self: flex-end;
  background: var(--brand-dark);
  border: 1px solid rgba(61, 220, 151, 0.28);
}

.msg .who {
  display: block;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--muted);
}

.msg.sys {
  align-self: center;
  background: transparent;
  color: #5f6b7a;
  font-size: 11px;
  padding: 2px 0;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  min-width: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  padding: 10px 18px;
  background: #202833;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  z-index: 20;
  max-width: calc(100vw - 48px);
}

.library-entry {
  width: 100%;
}

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

.small {
  font-size: 12px;
}

/* ---------- 片源库 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 7, 10, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(640px, 100%);
  max-height: min(80dvh, 720px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow-y: auto;
}

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

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-head .muted {
  margin-right: auto;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.modal-section {
  display: grid;
  gap: 8px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.section-head h3 {
  margin: 0;
  font-size: 13px;
}

.lib-list {
  display: grid;
  gap: 8px;
}

.lib-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.lib-info {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.lib-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-meta {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.lib-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.lib-empty {
  padding: 14px;
  text-align: center;
  font-size: 12px;
  color: #5f6b7a;
  border: 1px dashed var(--line);
  border-radius: 10px;
}

@media (max-width: 560px) {
  .lib-item {
    flex-wrap: wrap;
  }

  .lib-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 860px) {
  .room {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100dvh;
  }

  .stage {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
  }

  .side {
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .presence {
    margin-right: 0;
  }

  .topbar {
    gap: 10px;
  }
}
