/* ========== 基础 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* 防止 display 规则覆盖 hidden 属性 */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  background: #0e1116;
  color: #e8ecf1;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ========== 首页 ========== */
.join-card {
  max-width: 360px;
  margin: 0 auto;
  padding: 48px 24px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.join-title {
  font-size: 26px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 36px;
  letter-spacing: 2px;
}

.field-label {
  display: block;
  font-size: 14px;
  color: #9aa4b2;
  margin: 18px 0 8px;
}

.field-input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  font-size: 16px;
  color: #e8ecf1;
  background: #171c24;
  border: 1px solid #2a3240;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s;
}

.field-input:focus {
  border-color: #4a90d9;
}

.join-btn {
  width: 100%;
  height: 48px;
  margin-top: 32px;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  background: #2f7fe0;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.join-btn:hover:not(:disabled) {
  background: #3b8ce8;
}

.join-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-msg {
  margin-top: 16px;
  font-size: 14px;
  color: #ff7676;
  text-align: center;
}

/* ========== 房间页布局 ========== */
body.role-broadcaster,
body.role-viewer {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  font-size: 14px;
  color: #9aa4b2;
  flex-shrink: 0;
}

.viewer-badge {
  background: #1d242e;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
}

.video-stage {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* 视图切换：默认都隐藏，由 body 角色类控制显示 */
.viewer-grid,
.broadcaster-stage,
.broadcaster-controls,
.viewer-controls {
  display: none;
}

body.role-broadcaster .broadcaster-stage {
  display: block;
}

body.role-viewer .viewer-grid {
  display: flex;
}

body.role-broadcaster .broadcaster-controls {
  display: flex;
}

body.role-viewer .viewer-controls {
  display: flex;
}

/* ========== 视频窗口 ========== */
video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

/* 观众视图：竖屏上下排列，横屏左右 */
.viewer-grid {
  height: 100%;
  gap: 8px;
  padding: 8px;
  flex-direction: column;
}

@media (orientation: landscape) and (min-width: 700px) {
  .viewer-grid {
    flex-direction: row;
  }
}

.video-tile {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #161b22;
  border-radius: 12px;
  overflow: hidden;
}

.video-tile video {
  position: absolute;
  inset: 0;
}

.tile-label {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  font-size: 12px;
  color: #cfd6df;
  background: rgba(0, 0, 0, 0.45);
  padding: 3px 10px;
  border-radius: 999px;
}

.tile-placeholder,
.tile-error {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #6b7686;
  text-align: center;
  padding: 12px;
}

.tile-error {
  color: #ff7676;
  z-index: 3;
}

.video-tile.has-stream .tile-placeholder {
  display: none;
}

.tap-play {
  position: absolute;
  z-index: 4;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  font-size: 13px;
  color: #fff;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  cursor: pointer;
}

/* 视频用户视图：对方大窗 + 本地小窗 */
.broadcaster-stage {
  height: 100%;
}

.remote-wrap {
  position: absolute;
  inset: 0;
}

.remote-wrap .tile-placeholder,
.remote-wrap .tile-error {
  border-radius: 12px;
}

.local-wrap {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  width: 26%;
  max-width: 170px;
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: #000;
}

.local-off-hint {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #6b7686;
  background: #000;
}

/* ========== 控制栏（固定底部） ========== */
.controls {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 12px 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.broadcaster-controls {
  gap: 14px;
}

.viewer-controls {
  align-items: center;
  gap: 18px;
}

.listening-hint {
  font-size: 14px;
  color: #9aa4b2;
}

.ctrl-btn {
  min-width: 96px;
  height: 48px;
  padding: 0 20px;
  font-size: 15px;
  color: #e8ecf1;
  background: #1d242e;
  border: 1px solid #2a3240;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.ctrl-btn:hover:not(:disabled) {
  background: #262f3c;
}

.ctrl-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ctrl-btn.off {
  color: #ff9d9d;
  border-color: #5a3434;
  background: #2b1d1d;
}

.ctrl-hangup {
  background: #d64545;
  border-color: #d64545;
  color: #fff;
}

.ctrl-hangup:hover {
  background: #e05555;
}

/* ========== 提示 ========== */
.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  font-size: 14px;
  text-align: center;
  color: #ffd9a8;
  background: rgba(52, 39, 20, 0.95);
  border-bottom: 1px solid rgba(255, 200, 120, 0.25);
}

.toast-area {
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 86%;
  padding: 10px 20px;
  font-size: 14px;
  color: #e8ecf1;
  background: rgba(29, 36, 46, 0.96);
  border: 1px solid #2a3240;
  border-radius: 999px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.25s ease, toast-out 0.3s ease 2.7s forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
  }
}
