:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1f242c;
  --text: #e8ecf1;
  --sub: #97a1ad;
  --accent: #4f8cff;
  --danger: #ff5f6d;
}
* { box-sizing: border-box; }
/* 修复：带 display 的类会覆盖 hidden 属性，导致遮罩/区块无法真正隐藏 */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: inherit; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 20px; background: var(--panel);
  border-bottom: 1px solid #242a33; position: sticky; top: 0; z-index: 5;
  flex-wrap: wrap;
}
.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.brand span { color: var(--accent); }
/* 平台标签栏 */
.site-tabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid #2b323c; border-radius: 10px; padding: 3px;
}
.site-tab {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: transparent; color: var(--sub); border: 0; border-radius: 7px;
  padding: 8px 14px; font-size: 14px; line-height: 1; white-space: nowrap;
  transition: background .15s, color .15s;
}
.site-tab img { width: 18px; height: 18px; border-radius: 5px; display: block; }
.site-tab:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.site-tab.is-active { background: var(--accent); color: #fff; font-weight: 600; }
@media (max-width: 720px) {
  .site-tab { padding: 7px 10px; font-size: 13px; }
}

.loader { display: flex; gap: 8px; flex: 1; min-width: 320px; }
.loader select, .loader input, .loader button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid #2b323c; border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.loader input { flex: 1; min-width: 200px; }
.loader button {
  background: var(--accent); border-color: var(--accent); color: #fff;
  cursor: pointer; font-weight: 600;
}
.loader button:hover { filter: brightness(1.08); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }

.player-section { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; }
@media (max-width: 900px) { .player-section { grid-template-columns: 1fr; } }

.video-wrap {
  position: relative; background: #000; border-radius: 12px; overflow: hidden;
  aspect-ratio: 16 / 9; width: 100%;
}
.video-wrap video { width: 100%; height: 100%; display: block; background: #000; object-fit: contain; }
.player-status {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.55); color: #fff; font-size: 15px; text-align: center; padding: 20px;
  pointer-events: none; /* 不要挡住原生播放控件的全屏/设置按钮 */
}

.side { background: var(--panel); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.room-head { display: flex; gap: 12px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; background: var(--panel-2); }
.room-title { font-weight: 600; line-height: 1.3; }
.room-sub { color: var(--sub); font-size: 13px; margin-top: 3px; }
.control-row { display: flex; align-items: center; gap: 10px; }
.control-row label { width: 52px; color: var(--sub); font-size: 13px; }
.control-row select {
  flex: 1; background: var(--panel-2); color: var(--text);
  border: 1px solid #2b323c; border-radius: 8px; padding: 8px 10px;
}
.url-info { color: var(--sub); font-size: 12px; word-break: break-all; }
.tip-warn { color: #ffb400; font-size: 12px; line-height: 1.5; }
.hint { color: #6b7684; font-size: 12px; line-height: 1.5; margin-top: auto; }

.home h2 { font-size: 18px; margin: 8px 0 16px; }

/* 分类栏 */
.cate-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.cate-chip {
  background: var(--panel); color: var(--sub); border: 1px solid #232a33;
  border-radius: 999px; padding: 7px 16px; font-size: 13px; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.cate-chip:hover { border-color: var(--accent); color: var(--text); }
.cate-chip.is-active { background: rgba(79, 140, 255, .16); border-color: var(--accent); color: var(--text); font-weight: 600; }

.cate-sub-bar {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px;
  padding-bottom: 14px; border-bottom: 1px solid #20262e;
}
.cate-sub {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  background: transparent; color: var(--sub); border: 1px solid transparent;
  border-radius: 8px; padding: 5px 10px; font-size: 13px;
}
.cate-sub img { width: 20px; height: 20px; border-radius: 4px; object-fit: cover; background: var(--panel-2); }
.cate-sub:hover { color: var(--text); background: var(--panel); }
.cate-sub.is-active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.more-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid #2b323c;
  border-radius: 8px; padding: 9px 22px; font-size: 13px; cursor: pointer;
}
.more-btn:hover { border-color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border-radius: 10px; overflow: hidden; cursor: pointer;
  border: 1px solid #20262e; transition: transform .12s, border-color .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: var(--panel-2); }
.card .info { padding: 8px 10px; }
.card .title { font-size: 13px; line-height: 1.35; height: 2.7em; overflow: hidden; }
.card .sub { color: var(--sub); font-size: 12px; margin-top: 4px; display: flex; justify-content: space-between; }
.home-tip { color: var(--sub); font-size: 13px; }

/* ===== 搜索 ===== */
.search { display: flex; gap: 8px; min-width: 260px; }
.search input {
  flex: 1; background: var(--panel-2); color: var(--text);
  border: 1px solid #2b323c; border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.search button {
  background: var(--panel-2); color: var(--text); border: 1px solid #2b323c;
  border-radius: 8px; padding: 10px 14px; cursor: pointer;
}
.search button:hover { border-color: var(--accent); }

.search-panel {
  position: fixed; inset: 64px 20px auto 20px; z-index: 20;
  background: var(--panel); border: 1px solid #262d37; border-radius: 12px;
  padding: 14px 16px; max-height: 68vh; overflow: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.search-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.search-head button {
  background: transparent; color: var(--sub); border: 1px solid #2b323c;
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}

/* ===== 弹幕 ===== */
.danmaku-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.player-status { z-index: 3; }
.viewer-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.viewer-badge[hidden] { display: none; }
.vb-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ff4d4f;
  animation: vb-pulse 1.8s ease-out infinite;
}
@keyframes vb-pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.65); }
  70% { box-shadow: 0 0 0 6px rgba(255, 77, 79, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); }
}
.switch { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.control-row input[type="range"] { flex: 1; }

/* ===== 播放器内浮层（底部控制条 / 弹幕设置 / 全屏） ===== */
.player-overlay {
  position: absolute; inset: 0; z-index: 4; pointer-events: none;
  display: flex; flex-direction: column;
  opacity: 0; transition: opacity .18s ease;
}
/* 底部区域：弹幕面板 + 控制条，始终紧贴控制条上方 */
.overlay-bottom {
  margin-top: auto; display: flex; flex-direction: column; align-items: flex-end;
  gap: 10px; min-width: 0;
}
.video-wrap:hover .player-overlay,
.video-wrap:focus-within .player-overlay,
.video-wrap.is-paused .player-overlay,
.player-overlay.is-pinned { opacity: 1; }
@media (hover: none) { .player-overlay { opacity: 1; } }

.icon-btn {
  pointer-events: auto; cursor: pointer; min-width: 34px; height: 34px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(20, 24, 30, .68); color: #e8ecf1; font-size: 15px; line-height: 1;
  border: 1px solid rgba(255, 255, 255, .16); border-radius: 8px;
  backdrop-filter: blur(6px); transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: rgba(32, 38, 48, .9); border-color: var(--accent); }
.icon-btn.is-on { background: rgba(79, 140, 255, .85); border-color: var(--accent); color: #fff; }
.icon-btn.is-off { opacity: .55; }

/* 底部控制条：播放 / 音量 / 清晰度 / 线路 / 弹幕 / 刷新 / 全屏 */
.player-controls {
  pointer-events: auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  flex-wrap: wrap; row-gap: 6px; width: 100%;
  padding: 26px 12px 10px;
  background: linear-gradient(to top, rgba(0,0,0,.78), rgba(0,0,0,.32) 58%, transparent);
  color: #e8ecf1; font-size: 13px;
}
.pc-left, .pc-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.pc-left { flex: 0 0 auto; }
/* 换行时右侧按钮组保持右对齐，不再挤到左边 */
.pc-right { flex: 0 1 auto; margin-left: auto; flex-wrap: wrap; row-gap: 6px; justify-content: flex-end; }
.pc-volume { display: flex; align-items: center; gap: 6px; }
.pc-volume input[type="range"] { width: 84px; accent-color: var(--accent); }
.pc-live {
  display: inline-flex; align-items: center; gap: 5px; color: #ff6b6b;
  font-weight: 600; letter-spacing: .5px;
}
.pc-live i {
  width: 7px; height: 7px; border-radius: 50%; background: #ff4d4f;
  animation: pc-live-pulse 1.4s ease-in-out infinite;
}
@keyframes pc-live-pulse { 50% { opacity: .25; } }
.pc-time { color: #cfd6e0; font-variant-numeric: tabular-nums; }
.pc-select {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  height: 34px; padding: 0 4px 0 10px;
  background: rgba(20, 24, 30, .68); border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 8px; backdrop-filter: blur(6px); transition: border-color .15s;
}
.pc-select:hover { border-color: var(--accent); }
.pc-select span { color: #b9c2ce; font-size: 12px; white-space: nowrap; }
.pc-select select {
  background: transparent; color: #e8ecf1; border: 0; outline: none; cursor: pointer;
  font-size: 13px; min-width: 0; max-width: 150px; padding: 0 4px;
  text-overflow: ellipsis;
}
.pc-select select option { background: #1f242c; color: #e8ecf1; }

/* 窄屏：压缩左侧信息与下拉宽度，避免换行后溢出 */
@media (max-width: 820px) {
  .pc-select { flex: 0 1 auto; min-width: 0; }
  .pc-select span { display: none; }
  .pc-select select { max-width: 130px; }
}
@media (max-width: 620px) {
  .player-controls { padding: 22px 10px 8px; gap: 6px; }
  .pc-left, .pc-right { gap: 6px; }
  .pc-volume input[type="range"] { width: 56px; }
  .pc-select select { max-width: 104px; }
}
@media (max-width: 480px) {
  .pc-live, .pc-time { display: none; }
  .pc-volume input[type="range"] { display: none; }
  .pc-select select { max-width: 88px; }
  .icon-btn { min-width: 30px; height: 30px; padding: 0 6px; }
  .pc-select { height: 30px; padding: 0 4px; }
}

/* 弹幕设置面板：贴在底栏上方 */
.danmaku-panel {
  pointer-events: auto; position: relative; margin-right: 10px; width: 292px; max-width: calc(100% - 20px);
  max-height: min(72vh, 540px); overflow-y: auto;
  background: rgba(18, 22, 28, .94); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 12px; padding: 12px 14px 14px; backdrop-filter: blur(10px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55); color: var(--text);
}
.dm-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.dm-row { display: grid; grid-template-columns: 62px 1fr 52px; align-items: center; gap: 8px; margin: 9px 0; }
.dm-row label { font-size: 13px; color: #c6ced9; }
.dm-val { font-size: 12px; color: #c6ced9; text-align: right; font-variant-numeric: tabular-nums; }
.dm-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #c6ced9; margin-top: 10px; }
.dm-block { margin-top: 10px; }
.dm-block label { display: block; font-size: 13px; color: #c6ced9; margin-bottom: 5px; }
.dm-block textarea {
  width: 100%; resize: vertical; min-height: 44px;
  background: rgba(0, 0, 0, .35); color: var(--text);
  border: 1px solid rgba(255, 255, 255, .16); border-radius: 8px;
  padding: 7px 9px; font-size: 12px; line-height: 1.5; font-family: inherit;
}
.dm-block textarea:focus { outline: none; border-color: var(--accent); }
.dm-check { align-items: flex-start; line-height: 1.45; }
.dm-check input[type="checkbox"] { margin-top: 1px; flex: 0 0 auto; }
.danmaku-panel input[type="range"] { width: 100%; accent-color: var(--accent); }
.danmaku-panel input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

/* 全屏时容器铺满，去掉圆角与固定比例 */
.video-wrap:fullscreen, .video-wrap:-webkit-full-screen { aspect-ratio: auto; border-radius: 0; width: 100%; height: 100%; }
/* 网页全屏：铺满浏览器视口，页面其它内容留在下方 */
.video-wrap.is-web-full {
  position: fixed; inset: 0; z-index: 50; width: 100%; height: 100%;
  aspect-ratio: auto; border-radius: 0;
}

/* ===== 关注 / 历史 区块 ===== */
.home-block { margin-bottom: 24px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 12px; }
.block-head h2 { margin: 0; }
.block-head .count { color: var(--sub); font-size: 13px; font-weight: 400; }
.block-tools { display: flex; gap: 8px; }
.ghost-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid #2b323c;
  border-radius: 8px; padding: 7px 12px; font-size: 12px; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: border-color .15s, color .15s;
}
.ghost-btn:hover { border-color: var(--accent); }
.ghost-btn[disabled] { opacity: .55; cursor: default; }
.card .thumb { position: relative; line-height: 0; background: var(--panel-2); }
.card .thumb img.is-icon { object-fit: contain; padding: 26%; opacity: .45; }
.card .badge {
  position: absolute; left: 8px; top: 8px; padding: 3px 7px; border-radius: 6px;
  font-size: 11px; line-height: 1; backdrop-filter: blur(4px);
}
.card .badge.is-live { background: #ff4d4f; color: #fff; }
.card .badge.is-off { background: rgba(0, 0, 0, .6); color: #c6ced9; }
.card-x {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 15px; line-height: 1;
}
.card-x:hover { background: var(--danger); }

/* ===== 侧栏基础信息 ===== */
.room-actions { display: flex; gap: 8px; }
.follow-btn {
  flex: 1; padding: 9px 12px; font-size: 13px; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  border: 1px solid #2b323c; border-radius: 8px; transition: background .15s, border-color .15s;
}
.follow-btn:hover { border-color: var(--accent); }
.follow-btn.is-on { background: rgba(79, 140, 255, .16); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.follow-btn[disabled] { opacity: .55; cursor: default; }
.room-facts {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px;
  margin: 0; padding: 10px 12px; background: var(--panel-2); border-radius: 10px;
}
.room-facts div { min-width: 0; }
.room-facts dt { color: var(--sub); font-size: 11px; margin-bottom: 3px; }
.room-facts dd { margin: 0; font-size: 13px; word-break: break-all; }

/* ===== 轻提示 ===== */
#toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); z-index: 90;
  padding: 9px 16px; border-radius: 999px;
  background: rgba(20, 24, 30, .94); color: #fff; font-size: 13px;
  border: 1px solid rgba(255, 255, 255, .14);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ===== 移动端适配 ===== */
html { -webkit-text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
button, .card, select, .ghost-btn { touch-action: manipulation; }
.topbar-toggle { display: none; }

/* 触屏：加大点击热区，去掉 hover 位移 */
@media (hover: none) {
  .icon-btn { min-width: 38px; height: 38px; font-size: 16px; }
  .pc-select { height: 38px; }
  .follow-btn, .ghost-btn { padding-top: 10px; padding-bottom: 10px; }
  .card:hover { transform: none; }
  .card-x { width: 28px; height: 28px; }
}

@media (max-width: 720px) {
  main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); }
  /* 窄屏顶栏不再吸顶：四行高度会吃掉大片可视区，滚动时让它自然离开 */
  .topbar {
    position: static;
    gap: 8px 10px;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .brand { font-size: 17px; }
  .topbar-toggle { display: inline-flex; margin-left: auto; }
  /* 平台标签一行横向滚动，不再换行把顶栏撑高 */
  .site-tabs {
    order: 10; width: 100%; flex-wrap: nowrap; justify-content: flex-start;
    overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .site-tabs::-webkit-scrollbar { display: none; }
  .site-tab { flex: 0 0 auto; }
  .loader { order: 20; width: 100%; min-width: 0; }
  .loader input { min-width: 0; }
  /* 搜索默认收进 🔍，点开才占一行 */
  .search { order: 30; width: 100%; min-width: 0; display: none; }
  body.search-open .search { display: flex; }
  .search-panel {
    inset: auto 8px max(8px, env(safe-area-inset-bottom)) 8px;
    max-height: 74vh; border-radius: 14px; padding: 12px 14px;
  }
  .player-section { gap: 12px; }
  .side { padding: 12px; gap: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }
  .card .title { height: auto; max-height: 2.7em; }
  /* 关注/历史在窄屏改为横向滑动，省纵向空间 */
  .grid.hscroll {
    display: flex; flex-wrap: nowrap; gap: 10px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
    padding-bottom: 4px;
  }
  .grid.hscroll::-webkit-scrollbar { display: none; }
  .grid.hscroll .card { flex: 0 0 58%; max-width: 240px; }
  .danmaku-panel { width: min(292px, calc(100vw - 24px)); max-height: 62vh; }
  .search-head button { padding: 7px 12px; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .grid.hscroll .card { flex: 0 0 66%; }
  .room-facts { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 9px 10px; }
  .search-panel { max-height: 78vh; }
}

/* 网页全屏在移动端要用 dvh，避免地址栏伸缩导致高度跳变 */
.video-wrap.is-web-full { height: 100vh; height: 100dvh; }
