:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a5;
  --accent: #4c8dff;
  --danger: #e5484d;
  --ok: #46c07a;
  --warn: #e8a33d;
  --radius: 12px;
}

* { box-sizing: border-box; }

/*
 * 必须有这条,而且必须带 !important。
 *
 * 浏览器内置样式表里的 [hidden] { display: none } 属于 UA origin,
 * 优先级低于作者样式。下面任何一条 .lobby { display: grid } 之类的规则
 * 都会把它盖掉,结果就是 element.hidden = true 完全不起作用 ——
 * 表现为进了房间大厅还赖在屏幕上、按钮一直停在「正在连接…」。
 */
[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

button { font: inherit; cursor: pointer; }

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

/* ───────────────────────── 加入界面 ───────────────────────── */

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

.join-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.join-card h1 {
  margin: 0;
  font-size: 22px;
}

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

.join-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.join-card input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  outline: none;
}

.join-card input:focus { border-color: var(--accent); }

.join-card button[type=submit] {
  margin-top: 6px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 11px;
  font-weight: 600;
}

.join-card button[type=submit]:disabled { opacity: .5; cursor: default; }

.error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

/* ───────────────────────── 通话界面 ───────────────────────── */

.room {
  height: 100%;
  display: grid;
  grid-template-columns: 1fr 320px;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px;
  gap: 14px;
}

.videos {
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-content: center;
}

.tile {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}

.tile.self video { transform: scaleX(-1); }
.tile.self.sharing video { transform: none; }

.tile .name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(6px);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.tile .dot.connected { background: var(--ok); }
.tile .dot.connecting { background: var(--warn); }
.tile .dot.failed { background: var(--danger); }

.tile .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  color: var(--text);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 1px;
}
.tile .placeholder[hidden] { display: none; }

/* 头像底下那个圆 */
.tile .placeholder::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 86px;
  height: 86px;
  margin: -43px 0 0 -43px;
  border-radius: 50%;
  background: rgba(140, 150, 170, .16);
}

.tile .muted-ico {
  font-size: 11px;
  opacity: .9;
}
.tile .muted-ico[hidden] { display: none; }

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.ctl {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.ctl:hover { background: var(--panel-2); }
.ctl .lbl { font-size: 13px; }
.ctl.off { color: var(--muted); border-color: var(--danger); }
.ctl.off .ico { opacity: .45; }

/* 正在等权限弹窗 */
.ctl.pending { opacity: .6; pointer-events: none; }
.ctl.pending .ico { animation: blink 1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .25; } }
.ctl.active { border-color: var(--accent); color: var(--accent); }
.ctl.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ctl.danger .ico { transform: rotate(135deg); }

/* ───────────────────────── 聊天 ───────────────────────── */

.chat {
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-head .muted { font-size: 12px; margin-left: 8px; }

.icon-btn {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 16px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { max-width: 90%; }
.msg .who { font-size: 11px; color: var(--muted); margin-bottom: 3px; }

.msg .body {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 11px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}

.msg.self { align-self: flex-end; }
.msg.self .who { text-align: right; }
.msg.self .body { background: var(--accent); border-color: var(--accent); color: #fff; }

.msg.system {
  align-self: center;
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
}
.msg.system .body {
  background: none;
  border: 0;
  padding: 2px 0;
  text-align: center;
}

.chat-form {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-form textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--text);
  font: inherit;
  outline: none;
}

.chat-form textarea:focus { border-color: var(--accent); }

.chat-form button[type=submit] {
  background: var(--accent);
  border: 0;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 17px;
  flex: 0 0 auto;
}

.attach-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 16px;
  flex: 0 0 auto;
  line-height: 1;
}

.attach-btn:hover { background: var(--panel-2); }

/* ───────────────────── 消息里的图片 / 文件 ───────────────────── */

.msg .body.attach {
  padding: 4px;
  overflow: hidden;
}

.msg .thumb {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: 7px;
  cursor: zoom-in;
  background: var(--panel-2);
}

.filecard {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  min-width: 190px;
}

.filecard .fico { font-size: 22px; flex: 0 0 auto; }
.filecard .fmeta { min-width: 0; flex: 1; }

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

.filecard .fsize { font-size: 11px; opacity: .65; }

.filecard .fdl {
  flex: 0 0 auto;
  color: inherit;
  text-decoration: none;
  font-size: 17px;
  opacity: .75;
}
.filecard .fdl:hover { opacity: 1; }

.xfer {
  height: 3px;
  border-radius: 2px;
  background: rgba(127, 127, 127, .3);
  margin: 5px 3px 2px;
  overflow: hidden;
}

.xfer > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s linear;
}

.msg.self .xfer > i { background: #fff; }
.xfer.done { display: none; }

.msg .body a {
  color: var(--accent);
  word-break: break-all;
}
.msg.self .body a { color: #fff; text-decoration: underline; }

/* ───────────────────── 拖拽 / 放大 ───────────────────── */

.dropzone {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 17, 21, .82);
  backdrop-filter: blur(3px);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.dropzone[hidden] { display: none; }

.dropzone-inner {
  border: 2px dashed var(--accent);
  border-radius: 16px;
  padding: 40px 60px;
  text-align: center;
  color: var(--text);
  font-size: 15px;
}

.dropzone-ico { font-size: 40px; margin-bottom: 8px; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, .9);
  display: grid;
  place-items: center;
  cursor: zoom-out;
  padding: 32px;
}
.lightbox[hidden] { display: none; }

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}

.lightbox-download {
  position: absolute;
  right: 20px;
  top: 18px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}
.lightbox-download:hover { background: rgba(255, 255, 255, .22); }

/* ───────────────────────── 连接信息 ───────────────────────── */

.stats-panel {
  position: absolute;
  left: 14px;
  top: 14px;
  background: rgba(15, 17, 21, .92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 13px;
  font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted);
  max-width: 300px;
  pointer-events: none;
}

.stats-panel b { color: var(--text); font-weight: 600; }
.stats-panel .relay { color: var(--warn); }
.stats-panel .direct { color: var(--ok); }

/* ───────────────────────── 窄屏 ───────────────────────── */

.only-narrow { display: none; }

@media (max-width: 820px) {
  .room { grid-template-columns: 1fr; }

  .chat {
    position: fixed;
    inset: 0;
    z-index: 20;
    border-left: 0;
  }
  .chat[hidden] { display: none; }

  .only-narrow { display: flex; }
  .ctl .lbl { display: none; }
  .ctl { padding: 10px 13px; }
  .videos { grid-template-columns: 1fr; }
}
