:root {
  --bg: #050816;
  --bg-elevated: #0b1020;
  --accent: #6366f1;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --accent-strong: #4f46e5;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --danger: #ef4444;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: radial-gradient(circle at top, #1d243a 0, #050816 45%, #000 100%);
  color: var(--text);
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 1280px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 16px;
  background: linear-gradient(120deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.6));
  border: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(18px);
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: linear-gradient(120deg, #a855f7, #6366f1, #22d3ee);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.room-info {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.input {
  padding: 8px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 16px;
  min-width: 0;
}

.input::placeholder {
  color: var(--text-muted);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.7);
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 16px;
  cursor: pointer;
  background: rgba(148, 163, 184, 0.2);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.7);
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  filter: none;
}

.joined-tag {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(129, 140, 248, 0.6);
  color: #c7d2fe;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 2.2fr 1fr;
  gap: 12px;
  min-height: 0;
}

.video-panel,
.chat-panel {
  background: radial-gradient(circle at top left, #1e293b 0, #020617 60%);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.38);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.8);
}

.video-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.video-toolbar .input {
  flex: 1;
}

.file-label {
  position: relative;
  overflow: hidden;
  border-radius: 999px;
  border: 1px dashed rgba(148, 163, 184, 0.6);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.file-label:hover {
  border-color: var(--accent);
  color: #e5e7eb;
}

.file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.video-wrapper {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #020617;
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.95);
}

video {
  width: 100%;
  height: 100%;
  max-height: 480px;
  display: block;
  background: #000;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
}

.chat-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #cbd5f5;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(31, 41, 55, 0.9);
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth; /* 平滑滚动 */
  /* 优化滚动条样式 */
  scrollbar-width: thin;
  scrollbar-color: rgba(99, 102, 241, 0.5) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.5);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(99, 102, 241, 0.7);
}

.msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 6px 8px;
  border-radius: 10px;
  max-width: 100%;
}

.msg.me {
  align-self: flex-end;
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.7);
}

.msg.other {
  align-self: flex-start;
  background: rgba(79, 70, 229, 0.18);
  border: 1px solid rgba(129, 140, 248, 0.7);
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
}

.msg-name {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 2px;
  color: #e0f2fe;
}

.msg-text {
  word-wrap: break-word;
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.chat-form {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  align-items: center;
  position: relative; /* 为表情面板提供定位上下文 */
  flex-shrink: 0; /* 确保输入框不会被压缩 */
}

.chat-form .icon-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 20px;
}

.chat-form .input {
  flex: 1;
}

.chat-form .btn.primary {
  flex-shrink: 0;
  min-width: 86px;
}

/* PC端：固定聊天框高度，防止聊天记录挤压布局 */
@media (min-width: 901px) {
  .chat-panel {
    max-height: calc(100vh - 180px);
    min-height: 0; /* 确保flex子元素可以正确收缩 */
  }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    max-height: 320px;
  }
}

/* 视频控制 */
.video-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.speed-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.speed-select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

/* 播放列表 */
.playlist-panel {
  margin-top: 8px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  max-height: 200px;
  overflow-y: auto;
}

.playlist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.playlist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.playlist-item {
  padding: 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.1);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.playlist-item:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent);
}

.playlist-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.playlist-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.playlist-item-remove {
  padding: 4px 8px;
  font-size: 12px;
  opacity: 0.6;
}

.playlist-item-remove:hover {
  opacity: 1;
  color: var(--danger);
}

/* 用户列表 */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.users-panel {
  margin-bottom: 8px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.2);
  max-height: 150px;
  overflow-y: auto;
}

.users-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.users-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-item {
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-item.owner::before {
  content: '👑';
  font-size: 12px;
}

/* 分享模态框 */
.share-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.share-modal-content {
  background: var(--bg-elevated);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.share-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.share-modal-title {
  font-size: 18px;
  font-weight: 600;
}

.share-modal-close {
  background: none;
  border: none;
  color: var(--text);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.share-modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.share-link-container {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.share-link-input {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 14px;
}

.share-copy-btn {
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.share-copy-btn:hover {
  background: var(--accent-strong);
}

.share-qrcode {
  text-align: center;
  padding: 16px;
  background: white;
  border-radius: 8px;
  margin-top: 16px;
}

@media (max-width: 640px) {
  .app {
    padding: 10px;
  }

  .app-header {
    align-items: flex-start;
  }

  .room-info {
    width: 100%;
    justify-content: flex-start;
  }

  .video-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .video-controls {
    width: 100%;
    justify-content: space-between;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .chat-form {
    flex-direction: row;
  }

  .chat-form .btn.primary {
    width: auto;
    min-width: 88px;
    padding: 10px 14px;
  }
}


