:root {
  --bg: #141518;
  --panel: #1d1f24;
  --panel-2: #26282f;
  --line: #33363e;
  --text: #e8e9eb;
  --muted: #8b8f98;
  --accent: #3b82f6;
  --live: #22c55e;
  --off: #6b7280;
  --danger: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- 工具栏 ---------- */
.toolbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-weight: 700; font-size: 15px; }
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 16px; cursor: pointer; font-size: 13px;
}
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.tab-icon {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 10px;
}
.tab-icon svg { width: 16px; height: 16px; }
.toolbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.toolbar-menu {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: 0 0 auto;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 16px; cursor: pointer;
}
.status-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex: 0 0 auto;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  cursor: pointer;
}
.status-toggle:hover { border-color: var(--line); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.status-dot.on, .status-toggle.on .status-dot { background: var(--live); box-shadow: 0 0 6px var(--live); }

/* 账号菜单：刷新 / 退出收进头像下拉 */
.user-menu { position: relative; flex: 0 0 auto; }
.user-pop {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  display: none; min-width: 168px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.user-menu.open .user-pop { display: block; }
.menu-item {
  display: block; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--text); font-size: 13px; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--panel-2); }
.menu-item.danger { color: var(--danger); }

.btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
  transition: filter .15s;
}
.btn:hover { filter: brightness(1.2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.tiny { padding: 2px 8px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }
#addInput {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; width: 280px; font-size: 13px;
}
#addInput:focus { outline: none; border-color: var(--accent); }

/* ---------- 主体 ---------- */
.body { display: flex; flex: 1 1 auto; min-height: 0; position: relative; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  position: relative;
  width: 280px; flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: margin-left .2s;
}
/* 收起列表：贴在列表右侧边缘、垂直居中，不占底部空间 */
.sidebar-hide {
  position: absolute; right: -12px; top: 50%; transform: translateY(-50%);
  z-index: 20; padding: 0;
  width: 22px; height: 52px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-left: none;
  border-radius: 0 8px 8px 0;
  font-size: 12px; line-height: 1; cursor: pointer;
}
.sidebar-hide:hover { filter: brightness(1.3); color: var(--text); }
.sidebar.hidden { margin-left: -280px; }
/* 侧边栏收起后的展开触发条（一直可见，不会被带出屏幕） */
.sidebar-reveal {
  position: absolute; left: 0; top: 45%; z-index: 40;
  width: 18px; height: 72px;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-left: none; border-radius: 0 6px 6px 0;
  font-size: 11px; cursor: pointer; display: none;
  transition: filter .15s;
}
.sidebar-reveal:hover { filter: brightness(1.3); color: var(--text); }
.sidebar-mask {
  position: absolute; inset: 0; z-index: 25;
  background: rgba(0, 0, 0, .45);
  display: none;
}
.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 8px; }
.sidebar-footer {
  flex: 0 0 auto; padding: 8px 12px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: 12px;
}

.group-label {
  font-size: 11px; color: var(--muted); font-weight: 600;
  padding: 10px 6px 4px;
}
.room-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
  position: relative;
}
.room-row:hover { background: var(--panel-2); }
.room-row.selected { background: rgba(59,130,246,.18); outline: 1px solid rgba(59,130,246,.4); }
.room-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--panel-2); flex: 0 0 auto;
  object-fit: cover; border: 1px solid var(--line);
}
.room-avatar.fallback {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px;
}
.room-main { flex: 1 1 auto; min-width: 0; }
.room-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-meta { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.room-rid { font-size: 11px; color: var(--muted); font-family: monospace; }
.cat-select {
  font-size: 10px; color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 2px;
  max-width: 120px; margin-top: 3px; cursor: pointer;
}
.room-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-chip {
  font-size: 10px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 4px; padding: 0 5px; line-height: 16px;
}
.room-hot { font-size: 11px; color: var(--muted); white-space: nowrap; }
.room-hot .live { color: var(--live); }
.room-actions { display: none; gap: 4px; position: absolute; right: 6px; top: 4px; }
.room-row:hover .room-actions { display: flex; }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--muted); border-radius: 4px; width: 20px; height: 20px;
  cursor: pointer; font-size: 11px; line-height: 1;
}
.icon-btn:hover { color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.live-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.live-dot.on { background: var(--live); }
.live-dot.off { background: var(--off); }

/* ---------- 主区 / 播放 ---------- */
.main { flex: 1 1 auto; min-width: 0; position: relative; }
.view { display: none; width: 100%; height: 100%; }
.view.active { display: block; }

.player-wrap {
  position: relative; width: 100%; height: 100%;
  background: #000;
}
#player { width: 100%; height: 100%; object-fit: contain; }
.player-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--muted);
}
.ph-title { font-size: 20px; font-weight: 600; }
.ph-sub { font-size: 13px; }

.danmaku-layer {
  position: absolute; left: 12px; right: 12px;
  bottom: calc(64px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column-reverse; gap: 5px;
  pointer-events: none; z-index: 5;
}
.danmaku-item {
  display: flex; gap: 8px; align-items: baseline;
  background: rgba(0,0,0,.45); border-radius: 6px;
  padding: 4px 10px; max-width: 60%;
  font-size: 15px; line-height: 1.4;
}
.danmaku-item .dn { color: #fff; font-weight: 600; white-space: nowrap; }
.danmaku-item .dc { color: rgba(255,255,255,.95); word-break: break-word; }

.player-controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  z-index: 6;
}
.ctrl-left, .ctrl-right { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 11px; color: #ffd166;
  background: rgba(0,0,0,.5); border: 1px solid rgba(255,209,102,.4);
  border-radius: 4px; padding: 1px 6px;
}
.stats { font-size: 12px; color: var(--muted); }

/* ---------- 电视墙 ---------- */
.wall-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.wall-title { font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.wall-tags { display: flex; gap: 6px; min-width: 0; }
.wall-tag {
  flex: 0 0 auto;
  font-size: 12px; color: var(--muted); cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; padding: 2px 10px;
}
.wall-tag.active { color: #fff; border-color: var(--accent); background: rgba(59,130,246,.2); }
.sound-toggle { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px;
}
.hint { font-size: 11px; }

#wallView.active { display: flex; flex-direction: column; }
.wall-grid {
  display: grid; gap: 6px; padding: 8px;
  width: 100%; flex: 1 1 auto; min-height: 0;
}
.wall-grid.layout-4 { grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr); }
.wall-grid.layout-9 { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.wall-cell {
  position: relative; background: #000; border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line); min-height: 0;
}
.wall-cell.sounding { outline: 2px solid var(--accent); }
.wall-cell.playing { border-color: rgba(34,197,94,.5); }
.wall-cell video { width: 100%; height: 100%; object-fit: contain; }
.wall-cell .wc-cover {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #0c0d0f; color: var(--muted); font-size: 13px;
}
.wall-cell .wc-cover img { width: 100%; height: 100%; object-fit: cover; opacity: .5; filter: blur(2px); }
.wall-cell .wc-cover .wc-cname {
  position: absolute; font-weight: 600; color: #fff; text-shadow: 0 1px 4px #000;
  max-width: 80%; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wall-cell .wc-cover .wc-coff { position: absolute; bottom: 8px; font-size: 11px; color: var(--muted); }
.wall-cell .wc-tag {
  position: absolute; top: 6px; right: 6px;
  font-size: 10px; color: #ffd166; background: rgba(0,0,0,.55);
  border-radius: 4px; padding: 1px 5px; z-index: 3;
}
.wall-cell .wc-online {
  position: absolute; left: 6px; bottom: 6px; z-index: 3;
  font-size: 11px; color: var(--live); background: rgba(0,0,0,.55);
  border-radius: 4px; padding: 1px 5px;
}
.wall-cell .wc-sound {
  position: absolute; right: 6px; bottom: 6px; z-index: 3;
  font-size: 11px; color: var(--accent); background: rgba(0,0,0,.55);
  border-radius: 4px; padding: 1px 5px; display: none;
}
.wall-cell.sounding .wc-sound { display: block; }
.wall-cell .wc-danmaku {
  position: absolute; left: 6px; right: 6px; bottom: 22px; z-index: 4;
  display: flex; flex-direction: column-reverse; gap: 2px; pointer-events: none;
}
.wall-cell .wc-danmaku .di {
  font-size: 11px; color: rgba(255,255,255,.92);
  background: rgba(0,0,0,.45); border-radius: 4px; padding: 1px 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- 沉浸模式 ---------- */
.immersive {
  position: fixed; inset: 0; background: #000; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.immersive.hidden { display: none; }
#imPlayer { width: 100%; height: 100%; object-fit: contain; }
.im-danmaku {
  position: absolute; left: 200px; right: 40px; bottom: 70px; z-index: 10;
  display: flex; flex-direction: column-reverse; gap: 6px; pointer-events: none;
}
.im-danmaku .danmaku-item { max-width: 55%; }
.im-topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 12;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: linear-gradient(rgba(0,0,0,.7), transparent);
}
.im-topbar span { color: #fff; font-weight: 600; text-shadow: 0 1px 3px #000; }
#imTitle {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.im-topbar .stats { font-weight: 400; font-size: 12px; color: rgba(255,255,255,.75); white-space: nowrap; }
.im-actions {
  margin-left: auto; flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
}
.kbd { margin-left: 4px; font-size: 11px; font-weight: 400; color: var(--muted); }
.im-roomlist {
  position: absolute; left: 12px; top: 52px; bottom: 12px; z-index: 11;
  width: 220px; background: rgba(255,255,255,.92); color: #111;
  border-radius: 10px; padding: 10px; overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  transition: transform .18s;
}
.im-roomlist.collapsed { transform: translateX(-235px); }
/* 收起列表：贴在列表右侧边缘、垂直居中（不跟随内容滚动） */
.im-list-toggle {
  position: absolute; left: 226px; top: 50%; transform: translateY(-50%);
  z-index: 12; padding: 0;
  width: 24px; height: 52px;
  background: rgba(255,255,255,.9); color: #444;
  border: 1px solid rgba(0,0,0,.12); border-left: none;
  border-radius: 0 8px 8px 0; cursor: pointer; font-size: 12px; line-height: 1;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.im-list-toggle:hover { background: #fff; color: #111; }
.immersive.list-collapsed .im-list-toggle { display: none; }
.im-roomlist .gl { font-size: 11px; color: #666; font-weight: 600; padding: 6px 4px 3px; }
.im-room {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 7px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.im-room:hover { background: rgba(0,0,0,.06); }
.im-room.sel { background: rgba(59,130,246,.16); }
.im-room img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.im-room .rn { font-weight: 500; color: #111; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-room .ld { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; }
.im-room .ld.on { background: var(--live); }
.im-room .ld.off { background: #bbb; }
.im-hover-zone {
  position: absolute; left: 0; top: 52px; bottom: 12px; width: 14px; z-index: 11; cursor: pointer;
  display: none;
}
.im-hover-zone.show { display: block; }
.im-handle {
  position: absolute; left: 4px; top: 50%; width: 4px; height: 44px;
  background: rgba(255,255,255,.35); border-radius: 3px; z-index: 11;
  display: none;
}
.im-hover-zone.show + .im-handle, .im-handle.show { display: block; }
/* 列表收起时弹幕左移，铺满画面 */
.immersive.list-collapsed .im-danmaku { left: 16px; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(40px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(20,22,25,.92); color: #fff;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 18px; z-index: 200; display: none;
  max-width: 70%; font-size: 13px;
}
.toast.show { display: block; animation: toastIn .2s; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 登录层 ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: rgba(15, 17, 22, .88); backdrop-filter: blur(6px);
}
.login-mask.hidden { display: none; }
.login-card {
  width: 360px; padding: 40px 36px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line);
  text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 14px; }
.login-title { font-size: 22px; font-weight: 700; color: var(--text); }
.login-sub { font-size: 13px; color: var(--muted); margin: 8px 0 26px; }
.login-btn {
  width: 100%; height: 44px; border: 0; border-radius: 8px; cursor: pointer;
  background: #3370ff; color: #fff; font-size: 15px; font-weight: 600;
}
.login-btn:hover { background: #2861e8; }
.login-tip { margin-top: 16px; font-size: 11px; color: var(--muted); line-height: 1.6; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text); padding: 2px 8px;
  background: transparent; border: 0; border-radius: 6px; cursor: pointer;
  max-width: 160px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.user-chip:hover { background: var(--panel-2); }
.chip-avatar { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 移动端 / 触屏适配 ---------- */
@media (max-width: 768px), (max-height: 520px) and (orientation: landscape) {
  body { font-size: 13px; }

  /* 顶栏：两行（导航行 + 添加行），次要按钮收进头像菜单 */
  .toolbar {
    flex-wrap: wrap; gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
  }
  .toolbar-menu { display: inline-flex; order: 1; }
  .brand { font-size: 14px; order: 2; }
  .tabs { order: 3; }
  .toolbar-actions { display: contents; }
  .status-toggle { order: 4; margin-left: auto; width: 36px; height: 36px; }
  .user-menu { order: 5; }
  #monitorBtn { display: none; }
  #addInput {
    order: 6; width: auto; flex: 1 1 120px; min-width: 0;
    height: 40px; padding: 0 12px; font-size: 16px;
  }
  #addBtn { order: 7; flex: 0 0 auto; min-height: 40px; padding: 0 14px; font-size: 14px; }
  .tab { padding: 6px 10px; }
  .user-chip { max-width: 40px; padding: 2px 6px; overflow: hidden; }
  .chip-name { display: none; }
  .menu-item { min-height: 40px; font-size: 14px; }

  /* 侧栏：覆盖式抽屉（从顶栏下方开始）+ 遮罩 */
  .sidebar {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 30;
    width: min(300px, 86vw); margin-left: 0;
    padding-bottom: env(safe-area-inset-bottom);
    transition: transform .2s;
  }
  .sidebar.hidden { margin-left: 0; transform: translateX(-100%); }
  .sidebar-mask.show { display: block; }
  .sidebar-reveal { top: 40%; width: 22px; height: 72px; }

  /* 主播列表：分类选择与操作按钮同一行，触屏常显且不挤压主播名 */
  .room-row {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px; row-gap: 4px;
  }
  .room-main { display: contents; }
  .live-dot { grid-column: 1; grid-row: 1 / span 3; }
  .room-avatar { grid-column: 2; grid-row: 1 / span 3; }
  .room-name { grid-column: 3; grid-row: 1; min-width: 0; }
  .room-meta {
    grid-column: 3; grid-row: 2;
    margin-top: 0; min-width: 0; overflow: hidden;
  }
  .room-hot { grid-column: 4; grid-row: 1 / span 2; justify-self: end; }
  .cat-select {
    grid-column: 3; grid-row: 3;
    width: 100%; max-width: none; min-width: 0; height: 32px;
    margin-top: 0; padding: 0 6px; border-radius: 6px; font-size: 16px;
  }
  .room-actions {
    grid-column: 4; grid-row: 3;
    display: flex; position: static; justify-self: end;
    gap: 6px; margin: 0;
  }
  .icon-btn { width: 30px; height: 30px; font-size: 13px; }
  .sidebar-footer .btn.tiny { min-height: 32px; }

  /* 播放控制条：单行 + 安全区，标题截断 */
  .player-controls {
    flex-wrap: nowrap; gap: 6px;
    padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  }
  .ctrl-left { flex: 1 1 auto; min-width: 0; gap: 6px; }
  #nowTitle { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .player-controls .badge, .stats { display: none; }
  .ctrl-right { flex: 0 0 auto; flex-wrap: nowrap; gap: 4px; }
  .ctrl-right .btn.small { min-height: 34px; padding: 4px 8px; }
  .danmaku-item { font-size: 13px; max-width: 82%; }

  /* 电视墙：工具条两行（翻页 / 标签横滚 + 声音 + 布局） */
  .wall-toolbar {
    flex-wrap: wrap; gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
  }
  .wall-title { order: 1; }
  #wallCount { order: 2; }
  .spacer { order: 3; }
  #wallPrev { order: 4; }
  #wallPage { order: 5; }
  #wallNext { order: 6; }
  .wall-tags { order: 7; flex: 1 1 120px; overflow-x: auto; padding-bottom: 2px; }
  .sound-toggle { order: 8; }
  #wallLayout { order: 9; }
  .hint { display: none; }
  .wall-grid { gap: 4px; padding: 6px; }

  /* 沉浸：顶栏紧凑、按钮可点、边缘热区加宽 */
  .im-roomlist { width: 180px; top: 60px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .im-roomlist.collapsed { transform: translateX(-195px); }
  .im-topbar {
    padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
    gap: 8px;
  }
  #imTitle { flex: 1 1 auto; max-width: none; font-size: 13px; }
  .im-topbar .badge, .im-topbar .stats, .kbd { display: none; }
  .im-actions { gap: 6px; }
  .im-topbar .btn { min-height: 36px; padding: 0 9px; }
  .im-danmaku { left: 12px; right: 12px; bottom: calc(56px + env(safe-area-inset-bottom)); }
  .im-danmaku .danmaku-item { max-width: 84%; font-size: 13px; }
  .immersive.list-collapsed .im-danmaku { left: 12px; }
  .im-hover-zone { top: 60px; width: 24px; }
  .im-handle { top: 46%; }
  .im-list-toggle { left: 186px; width: 26px; height: 44px; }

  /* 登录卡片 / 提示 */
  .login-card { width: min(340px, 88vw); padding: 32px 24px; }
  .toast { max-width: calc(100vw - 32px); }
}

/* ---------- 直播数据看板 ---------- */
.analytics {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  overflow: auto;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom));
  background: rgba(10, 11, 13, .94);
  backdrop-filter: blur(6px);
}
.analytics.hidden { display: none; }
.an-head {
  display: flex; align-items: center; gap: 14px;
  flex: 0 0 auto; margin-bottom: 16px;
}
.an-brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.an-brand svg { width: 20px; height: 20px; color: var(--accent); }
.an-ranges { display: flex; gap: 6px; }
.an-range {
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.an-range.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.an-head .btn { margin-left: auto; }
.an-body {
  display: flex; flex-direction: column; gap: 14px;
  width: 100%; max-width: 1400px; margin: 0 auto;
}
.an-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.an-kpi {
  padding: 12px 14px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line);
}
.an-kpi .k { margin-bottom: 6px; font-size: 12px; color: var(--muted); }
.an-kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-kpi .s { margin-top: 2px; font-size: 11px; color: var(--muted); }
.an-card {
  min-width: 0; padding: 14px 16px 10px;
  border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
}
.an-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 8px; font-size: 13px; font-weight: 600;
}
.an-card-head .muted { font-weight: 400; font-size: 11px; }
.an-chart-wrap { position: relative; }
.an-chart { display: block; width: 100%; height: 220px; }
.an-chart-wrap.short { margin-top: 6px; }
.an-chart-wrap.short .an-chart { height: 180px; }
.an-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; pointer-events: none;
}
.an-cols {
  display: grid;
  grid-template-columns: minmax(260px, .9fr) minmax(230px, .7fr) 1.4fr;
  gap: 14px;
}
@media (max-width: 1100px) {
  .an-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .an-detail-card { grid-column: 1 / -1; }
}
.an-ranking { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow: auto; }
.an-row {
  display: grid; grid-template-columns: 26px minmax(0, 1fr) auto auto;
  align-items: center; gap: 8px;
  padding: 8px; border-radius: 8px; cursor: pointer; border: 1px solid transparent;
}
.an-row:hover { background: var(--panel-2); }
.an-row.active { background: rgba(59, 130, 246, .12); border-color: var(--accent); }
.an-ava {
  position: relative;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--panel-2); font-size: 12px;
}
.an-ava img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
}
.an-pie-wrap { display: flex; align-items: center; gap: 10px; }
.an-pie { flex: 0 0 auto; width: 148px; height: 148px; }
.an-legend {
  display: flex; flex-direction: column; gap: 4px;
  min-width: 0; overflow: hidden;
  font-size: 11px; color: var(--muted);
}
.an-legend-item { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.an-legend-item > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; }
.an-legend-item .dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 2px; }
.an-legend-item b { color: var(--text); font-weight: 600; }
.an-name {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.an-name-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.an-name-main > span,
.an-nick { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-sub { font-size: 10px; color: var(--muted); }
.an-live { flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; background: var(--live); }
.an-num {
  font-size: 12px; color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.an-num b { color: var(--text); font-weight: 600; }
.an-room-kpis { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12px; color: var(--muted); }
.an-room-kpis b { margin-left: 4px; font-size: 15px; color: var(--text); }

@media (max-width: 820px) {
  .analytics {
    padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  }
  .an-head { flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
  .an-brand { flex: 1 1 auto; font-size: 15px; }
  .an-head .btn { margin-left: 0; min-height: 34px; }
  .an-ranges { order: 3; width: 100%; }
  .an-range { flex: 1 1 0; text-align: center; min-height: 36px; }
  .an-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .an-kpi { padding: 10px 12px; }
  .an-kpi .v { font-size: 18px; }
  .an-cols { grid-template-columns: 1fr; }
  .an-chart { height: 170px; }
  .an-pie { width: 130px; height: 130px; }
  .an-ranking { max-height: 240px; }
  .an-row { padding: 9px 6px; }
}
