:root {
  --bg-deep: #0b1210;
  --bg-panel: rgba(18, 28, 24, 0.88);
  --ink: #e8f0ec;
  --ink-muted: #8aa396;
  --accent: #3ecf8e;
  --accent-dim: #1f6b4a;
  --danger: #e5484d;
  --line: rgba(232, 240, 236, 0.12);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font-display: "Outfit", system-ui, sans-serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg-deep);
}

.hidden { display: none !important; }

/* 已添加到主屏幕：整屏运行，禁掉橡皮筋回弹 */
@media (display-mode: standalone), (display-mode: fullscreen) {
  html, body {
    height: 100%;
    overscroll-behavior: none;
  }
}

.view {
  min-height: 100vh;
  min-height: 100dvh;
}

.banner {
  position: fixed;
  inset: 0 0 auto;
  z-index: 40;
  padding: 12px 16px;
  background: #3a1d12;
  color: #ffd7c8;
  text-align: center;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 50;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 14px;
  white-space: nowrap;
}

/* iOS「添加到主屏幕」引导 */
.ios-install-tip {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(18, 20, 34, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  color: #e9ecff;
}

.ios-install-text {
  margin: 0;
  flex: 1;
  font-size: 13px;
  line-height: 1.5;
}

.ios-share-glyph {
  display: inline-block;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(91, 108, 255, 0.28);
}

.ios-install-close {
  flex: none;
  padding: 7px 12px;
  border: 0;
  border-radius: 999px;
  background: #5b6cff;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

/* iOS 系统全屏用的临时 video 副本：留在文档流之外，不参与页面渲染 */
.ios-fs-video {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Lobby */
.view-lobby {
  position: relative;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
}

.lobby-bg {
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(ellipse 50% 40% at 20% 20%, rgba(62, 207, 142, 0.18), transparent 60%),
    radial-gradient(ellipse 45% 35% at 80% 70%, rgba(40, 90, 120, 0.25), transparent 55%),
    linear-gradient(160deg, #0b1210 0%, #122019 50%, #0b1210 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1.02); }
  to { transform: translate3d(2%, 1%, 0) scale(1.06); }
}

.lobby-panel {
  position: relative;
  width: min(420px, 100%);
  padding: 36px 28px 28px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 8vw, 3.2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.tagline {
  margin: 10px 0 28px;
  color: var(--ink-muted);
  font-size: 1rem;
}

.profile {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  object-fit: cover;
  background: #1a2a22;
}

.profile-meta { flex: 1; min-width: 0; }

.nickname-input {
  width: 100%;
  margin-bottom: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: 600 1rem var(--font-display);
}

.link-btn {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font: 600 0.85rem var(--font-body);
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font: 600 1rem var(--font-body);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  width: 100%;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--accent), #2aa86f);
  color: #052015;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
}

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

.text-input {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  font: 600 1rem/1 var(--font-display);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hint {
  margin: 18px 0 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
  text-align: center;
}

/* Waiting */
.view-waiting {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 30%, rgba(62, 207, 142, 0.12), transparent 45%),
    var(--bg-deep);
}

.waiting-panel {
  text-align: center;
  width: min(380px, 100%);
}

.pulse {
  width: 64px;
  height: 64px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.6s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0.5); transform: scale(0.92); }
  70% { box-shadow: 0 0 0 28px rgba(62, 207, 142, 0); transform: scale(1); }
  100% { box-shadow: 0 0 0 0 rgba(62, 207, 142, 0); transform: scale(0.92); }
}

.waiting-label { margin: 0; color: var(--ink-muted); }

.waiting-status {
  min-height: 1.4em;
  margin: 0 0 16px;
  color: #f0a090;
  font-size: 0.95rem;
}

.invite-qr-wrap {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin: 0 auto 22px;
}

.invite-qr {
  width: 176px;
  height: 176px;
  padding: 12px;
  border-radius: 16px;
  background: #f4f7f5;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.invite-qr img,
.invite-qr canvas {
  display: block;
  width: 152px !important;
  height: 152px !important;
}

.invite-qr-hint {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.room-code {
  margin: 12px 0 24px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 700;
  letter-spacing: 0.18em;
}

.waiting-panel .btn { width: 100%; margin-bottom: 10px; }

/* Call — 微信式主从布局 */
.view-call { background: #000; }

.call-stage {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #000;
  /* 全屏时铺满 */
  color: #fff;
  /* 关掉双击缩放与双击选中，双击手势完全交给我们自己处理 */
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.call-stage.is-immersive {
  position: fixed;
  inset: 0;
  z-index: 80;
  width: 100%;
  height: 100%;
  height: 100dvh;
  /* iOS 视觉视口，尽量贴满可用区域 */
  height: 100svh;
  background: #000;
}

body.is-call-fullscreen,
body.is-call-cinema {
  background: #000;
  overscroll-behavior: none;
}

body.is-call-fullscreen .debug-fab,
body.is-call-cinema .debug-fab {
  display: none !important;
}

/* 沉浸模式：隐藏所有控件与小窗，只留主画面 */
.call-stage.is-cinema .controls,
.call-stage.is-cinema .video-tile.is-pip {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.call-stage.is-cinema .controls {
  transform: translate(-50%, 12px);
}

.call-stage.is-cinema .video-tile.is-pip {
  transform: scale(0.92);
}

/* call-top 整体不能设 opacity:0，否则退出按钮无法单独保留 */
.call-stage.is-cinema .call-top {
  background: none;
}

.call-stage.is-cinema .call-top-left,
.call-stage.is-cinema .call-status,
.call-stage.is-cinema #btn-swap-video {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

/* 退出口必须常驻可点：沉浸模式下只淡化，不隐藏 */
.call-stage.is-cinema #btn-fullscreen {
  opacity: 0.4;
  pointer-events: auto;
  transition: opacity 0.2s ease;
}

/* 单击主画面临时唤出全部控件 */
.call-stage.is-cinema.is-peek .call-top {
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
}

.call-stage.is-cinema.is-peek .call-top-left,
.call-stage.is-cinema.is-peek .call-status,
.call-stage.is-cinema.is-peek #btn-swap-video,
.call-stage.is-cinema.is-peek #btn-fullscreen,
.call-stage.is-cinema.is-peek .controls,
.call-stage.is-cinema.is-peek .video-tile.is-pip {
  opacity: 1;
  pointer-events: auto;
}

.call-stage.is-cinema.is-peek .controls {
  transform: translateX(-50%);
}

.call-stage.is-cinema.is-peek .video-tile.is-pip {
  transform: none;
}

.call-stage:not(.is-cinema) .call-top,
.call-stage:not(.is-cinema) .controls {
  transition: opacity 0.2s ease, transform 0.2s ease;
}

body.is-call-cinema .debug-fab {
  display: none !important;
}

.cinema-hint {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 0.85rem;
  pointer-events: none;
  letter-spacing: 0.04em;
}

.cinema-hint.hidden { display: none !important; }

.video-tile {
  overflow: hidden;
  background: #0a0a0a;
  -webkit-tap-highlight-color: transparent;
}

.video-tile.is-main {
  position: absolute;
  inset: 0;
  z-index: 1;
  border-radius: 0;
  border: 0;
  box-shadow: none;
  cursor: default;
}

.video-tile.is-pip {
  position: absolute;
  z-index: 6;
  top: calc(12px + env(safe-area-inset-top) + 44px);
  right: max(12px, env(safe-area-inset-right));
  left: auto;
  bottom: auto;
  width: min(30vw, 132px);
  aspect-ratio: 9 / 16;
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  background: #111;
  cursor: pointer;
  touch-action: none;
  transition: box-shadow 0.15s ease;
}

.video-tile.is-pip:active {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}

.video-tile.is-pip.is-dragging {
  transition: none;
  opacity: 0.95;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.call-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0a0a0a;
  /* 避免 iOS 全屏手势误触 */
  pointer-events: none;
}

.call-video.is-mirrored {
  transform: scaleX(-1);
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 12px;
  background: radial-gradient(circle at center, #1c2430, #07080a);
}

.video-placeholder img { border-radius: 28px; }

.pip-placeholder img {
  width: 48px;
  height: 48px;
  border-radius: 14px;
}

.mute-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 12px;
}

.call-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 28px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.55), transparent);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.call-top-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.call-timer {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.call-room {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.65);
  text-transform: uppercase;
}

.call-status {
  flex: 1;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.82rem;
  text-align: center;
  padding-top: 4px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-status.is-error { color: #f0a090; }

.call-top-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
  flex-shrink: 0;
}

.call-chip {
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(0, 0, 0, 0.4);
  color: #fff;
  font: 600 0.78rem var(--font-display);
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.call-chip[aria-pressed="true"] {
  background: rgba(62, 207, 142, 0.35);
  border-color: rgba(62, 207, 142, 0.55);
}

.btn-info {
  margin-left: 10px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--ink);
  font: 600 0.8rem var(--font-display);
  cursor: pointer;
}

.debug-fab {
  position: fixed;
  z-index: 60;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(88px, calc(72px + env(safe-area-inset-bottom)));
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(12, 18, 16, 0.88);
  color: var(--accent);
  font: 700 0.95rem var(--font-display);
  box-shadow: var(--shadow);
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.conn-info-panel {
  position: fixed;
  z-index: 70;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(10, 16, 14, 0.96);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.conn-info-panel.hidden { display: none !important; }

.conn-info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.conn-info-title {
  margin: 0;
  font: 600 1rem var(--font-display);
}

.conn-info-close {
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.conn-info-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 12px 0;
  flex-shrink: 0;
}

.conn-tab {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: transparent;
  color: var(--ink-muted);
  font: 600 0.9rem var(--font-body);
  cursor: pointer;
}

.conn-tab.active {
  color: #052015;
  background: linear-gradient(135deg, var(--accent), #2aa86f);
  border-color: transparent;
}

.conn-info-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 14px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.conn-log-body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.conn-log-line {
  padding: 4px 0;
  border-bottom: 1px solid rgba(232, 240, 236, 0.06);
  color: #c9d8cf;
}

.conn-log-line.is-warn { color: #f0c090; }
.conn-log-line.is-error { color: #f0a090; }

.conn-info-empty { margin: 8px 0; color: var(--ink-muted); }

.conn-info-section {
  margin: 0 0 14px;
}

.conn-info-section h3 {
  margin: 0 0 6px;
  font: 600 0.78rem var(--font-display);
  letter-spacing: 0.04em;
  color: var(--accent);
  text-transform: uppercase;
}

.conn-info-row {
  display: grid;
  grid-template-columns: 108px 1fr;
  gap: 6px 10px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(232, 240, 236, 0.06);
}

.conn-info-row dt {
  margin: 0;
  color: var(--ink-muted);
}

.conn-info-row dd {
  margin: 0;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

.conn-info-highlight dd {
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}

.conn-info-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.conn-info-actions .btn {
  flex: 1;
  min-height: 40px;
  min-width: 88px;
  font-size: 0.9rem;
}

.controls {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  border-radius: 22px;
  background: rgba(10, 16, 14, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  max-width: calc(100% - 12px);
  flex-wrap: wrap;
  justify-content: center;
}

.ctrl {
  min-width: 52px;
  height: auto;
  min-height: 52px;
  padding: 6px 8px 5px;
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-display);
  line-height: 1.1;
}

.ctrl-icon { font-size: 1.15rem; line-height: 1; }
.ctrl-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.92;
  white-space: nowrap;
}

/* 开启：绿色描边；关闭：红色实底，状态一目了然 */
.ctrl-toggle.is-on {
  background: rgba(62, 207, 142, 0.22);
  border-color: rgba(62, 207, 142, 0.85);
  color: #dff9ec;
  box-shadow: 0 0 0 1px rgba(62, 207, 142, 0.2);
}

.ctrl-toggle.is-off {
  background: rgba(229, 72, 77, 0.92);
  border-color: #ff6b6f;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(229, 72, 77, 0.35);
}

.ctrl-toggle.is-off .ctrl-label {
  opacity: 1;
}

.ctrl-hangup {
  background: var(--danger);
  border-color: #ff6b6f;
  color: #fff;
}

.quality-wrap { position: relative; }

.quality-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 96px;
  padding: 6px;
  border-radius: 12px;
  background: rgba(12, 18, 16, 0.95);
  border: 1px solid var(--line);
  display: grid;
  gap: 4px;
}

.quality-menu button {
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: 600 0.9rem var(--font-body);
}

.quality-menu button.active,
.quality-menu button:hover {
  background: rgba(62, 207, 142, 0.18);
}

@media (max-width: 767px) {
  .ctrl {
    min-width: 46px;
    min-height: 48px;
    padding: 5px 6px 4px;
    border-radius: 12px;
  }
  .ctrl-icon { font-size: 1.05rem; }
  .ctrl-label { font-size: 0.58rem; }
  .video-tile.is-pip {
    width: min(28vw, 118px);
    aspect-ratio: 9 / 16;
  }
  .controls {
    gap: 6px;
    padding: 8px 8px;
  }
  .call-status { max-width: 34%; font-size: 0.75rem; }
}

/* 横屏手机：小窗改横向比例，避免遮挡 */
@media (max-width: 900px) and (orientation: landscape) {
  .video-tile.is-pip {
    width: min(22vw, 168px);
    aspect-ratio: 16 / 9;
    top: calc(8px + env(safe-area-inset-top));
  }
  .controls {
    bottom: calc(10px + env(safe-area-inset-bottom));
    padding: 6px 10px;
  }
  .ctrl { width: 40px; height: 40px; min-width: 40px; min-height: 40px; padding: 4px; }
  .ctrl-label { display: none; }
}

@media (min-width: 768px) {
  .video-tile.is-pip {
    width: 160px;
    aspect-ratio: 9 / 16;
    top: calc(16px + env(safe-area-inset-top) + 48px);
    right: 24px;
  }
  .controls { gap: 12px; }
  #btn-flip.desktop-hidden { display: none; }
}

/* 桌面宽屏主画面可读性：仍 cover，小窗略大 */
@media (min-width: 1024px) {
  .video-tile.is-pip {
    width: 180px;
  }
}
