/* ============================================================
   设计 token
   冷蓝黑背景，青绿=正向操作，红=挂断/关闭状态。
   刻意避开腾讯会议/钉钉的蓝色主调。
   ============================================================ */
:root {
  --bg: #0e1419;
  --surface: #161f28;
  --elevated: #1f2b36;
  --border: #2a3742;
  --text: #e8edf2;
  --muted: #8696a5;
  --accent: #34d399;
  --accent-dim: rgba(52, 211, 153, 0.14);
  --danger: #f0584e;
  --danger-dim: rgba(240, 88, 78, 0.16);
  --warn: #e0a458;
  --radius: 14px;
  --ctrl-size: 56px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Roboto Mono", Consolas, monospace;
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button,
input {
  font-family: inherit;
}
button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================================
   主页
   ============================================================ */
.home {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
}
.home-wrap {
  width: 100%;
  max-width: 420px;
}
.brand {
  text-align: center;
  margin-bottom: 36px;
}
.brand-mark {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 16px;
}
.brand-mark .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: pulse 1.8s ease-in-out infinite;
}
.brand-mark .dot:nth-child(2) {
  animation-delay: 0.3s;
}
.brand-mark .dot:nth-child(3) {
  animation-delay: 0.6s;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}
.brand-name {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0;
}
.brand-sub {
  color: var(--muted);
  font-size: 14px;
  margin: 6px 0 0;
  letter-spacing: 1px;
}

.field {
  margin-bottom: 18px;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
input[type="text"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 13px 14px;
  transition: border-color 0.15s;
}
input[type="text"]::placeholder {
  color: #566472;
}
input[type="text"]:focus {
  border-color: var(--accent);
  outline: none;
}

.card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  transition: transform 0.12s, border-color 0.15s, background 0.15s;
}
.card:active {
  transform: scale(0.985);
}
.card-icon {
  flex: none;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-size: 24px;
  font-weight: 600;
  background: var(--accent-dim);
  color: var(--accent);
}
.card-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.card-title {
  font-size: 17px;
  font-weight: 600;
}
.card-desc {
  font-size: 13px;
  color: var(--muted);
}
.card-primary:hover {
  border-color: var(--accent);
}
.card-join {
  cursor: default;
}
.join-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.join-row input {
  flex: 1;
  font-family: var(--mono);
  letter-spacing: 2px;
  padding: 10px 12px;
  font-size: 15px;
}
.join-row button {
  flex: none;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 20px;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s;
}
.join-row button:hover {
  background: #283744;
}

.hint {
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  margin: 4px 0 0;
}
.home-foot {
  margin-top: 28px;
  text-align: center;
}
.env-note {
  font-size: 12px;
  color: #5a6876;
  line-height: 1.5;
  margin: 0;
}

/* ============================================================
   会议室
   ============================================================ */
.room {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: rgba(14, 20, 25, 0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--accent-dim);
  animation: live 2s ease-out infinite;
}
@keyframes live {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.5);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(52, 211, 153, 0);
  }
}
.room-label {
  font-size: 13px;
  color: var(--muted);
}
.room-code {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text);
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--surface);
}
.room-code:active {
  background: var(--elevated);
}
.peer-count {
  font-size: 13px;
  color: var(--muted);
  background: var(--surface);
  padding: 5px 11px;
  border-radius: 20px;
}

/* 视频网格：根据人数自适应列数 */
.video-grid {
  flex: 1;
  display: grid;
  gap: 8px;
  padding: 8px;
  overflow: hidden;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
}
.video-grid[data-count="1"] {
  grid-template-columns: 1fr;
}
.video-grid[data-count="2"] {
  grid-template-columns: 1fr;
}
.video-grid[data-count="3"],
.video-grid[data-count="4"] {
  grid-template-columns: 1fr 1fr;
}
.video-grid[data-count="5"],
.video-grid[data-count="6"] {
  grid-template-columns: 1fr 1fr;
}
@media (min-width: 720px) {
  .video-grid[data-count="2"] {
    grid-template-columns: 1fr 1fr;
  }
  .video-grid[data-count="3"],
  .video-grid[data-count="4"] {
    grid-template-columns: 1fr 1fr;
  }
  .video-grid[data-count="5"],
  .video-grid[data-count="6"] {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.tile {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
}
.tile.speaking {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0a0e12;
}
/* 共享屏幕的画面用 contain，避免裁切 */
.tile.is-screen video {
  object-fit: contain;
  background: #000;
}
.tile-local video {
  transform: scaleX(-1); /* 本地摄像头镜像，符合直觉 */
}
.tile-local.is-screen video {
  transform: none; /* 共享屏幕时不镜像 */
}

/* 摄像头关闭时显示的头像占位 */
.tile-avatar {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--surface);
}
.tile.cam-off .tile-avatar {
  display: grid;
}
.tile.cam-off video {
  visibility: hidden;
}
.tile-avatar span {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--elevated);
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 600;
  color: var(--muted);
}

.tile-overlay {
  position: absolute;
  left: 0;
  bottom: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  z-index: 2;
}
.tile-name {
  font-size: 13px;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.tile-status {
  display: inline-flex;
  gap: 4px;
  margin-left: auto;
}
.tile-status .muted-badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  display: grid;
  place-items: center;
}
.tile-status .muted-badge svg {
  width: 13px;
  height: 13px;
  fill: #fff;
}

/* 控制栏 */
.controls {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  background: rgba(14, 20, 25, 0.85);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
}
.ctrl {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 60px;
}
.ctrl-icon {
  width: var(--ctrl-size);
  height: var(--ctrl-size);
  border-radius: 50%;
  background: var(--elevated);
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.1s;
}
.ctrl:active .ctrl-icon {
  transform: scale(0.92);
}
.ctrl-icon svg {
  width: 24px;
  height: 24px;
  fill: var(--text);
}
.ctrl-label {
  font-size: 11px;
  color: var(--muted);
}
/* 关闭状态（麦克风/摄像头被关）显示红底 */
.ctrl[data-on="false"][data-toggle] .ctrl-icon {
  background: var(--danger-dim);
}
.ctrl[data-on="false"][data-toggle] .ctrl-icon svg {
  fill: var(--danger);
}
/* 共享屏幕开启时显示青绿底 */
#btn-share[data-on="true"] .ctrl-icon {
  background: var(--accent-dim);
}
#btn-share[data-on="true"] .ctrl-icon svg {
  fill: var(--accent);
}
.ctrl-leave .ctrl-icon {
  background: var(--danger);
}
.ctrl-leave .ctrl-icon svg {
  fill: #fff;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 110px);
  transform: translateX(-50%) translateY(20px);
  background: var(--elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 24px;
  max-width: 88%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 20;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
