/* ==========================================================================
   Sun Movie 同步观影 · Notion 风格
   ========================================================================== */

:root {
  --notion-text: #37352f;
  --notion-bg: #f7f6f3;
  --notion-card: #ffffff;
  --notion-border: #d1d5db;
  --notion-hover: #efedea;
  --notion-active: #e3e1db;
  --notion-muted: #6b7280;
  --notion-link: #2eaadc;
  --notion-accent: #2eaadc;
  --safe-b: env(safe-area-inset-bottom, 0px);
  
  /* 弹幕设置变量（字号与透明度由设置面板写入；速度在 JS 里换算成动画时长，不走 CSS 变量） */
  --danmaku-font-size: 20px;
  --danmaku-opacity: 1;
}

/* ─── 深色模式（跟随系统 / 手动切换）────────────────────── */
html.dark {
  --notion-text: #e0deda;
  --notion-bg: #1e1e1c;
  --notion-card: #2c2c29;
  --notion-border: #3d3d39;
  --notion-hover: #363632;
  --notion-active: #43433e;
  --notion-muted: #9f9b91;
  --notion-link: #6fbae6;
  --notion-accent: #6fbae6;
}

@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --notion-text: #e0deda;
    --notion-bg: #1e1e1c;
    --notion-card: #2c2c29;
    --notion-border: #3d3d39;
    --notion-hover: #363632;
    --notion-active: #43433e;
    --notion-muted: #9f9b91;
    --notion-link: #6fbae6;
    --notion-accent: #6fbae6;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--notion-text);
  background: var(--notion-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100dvh;
  padding-bottom: var(--safe-b);
  overscroll-behavior-y: none;
}

/* ─── 顶部导航 ───────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--notion-card);
  border-bottom: 1px solid var(--notion-border);
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 14px;
  color: var(--notion-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--notion-text);
}

.brand-text em {
  font-size: 11px;
  color: var(--notion-muted);
  font-style: normal;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.pill {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--notion-border);
  color: var(--notion-muted);
  white-space: nowrap;
}

.pill.master {
  color: #fff;
  border-color: transparent;
  background: var(--notion-accent);
}

.icon-btn {
  position: relative;
  height: 32px;
  min-width: 32px;
  padding: 0 8px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--notion-border);
  border-radius: 8px;
  background: var(--notion-card);
  cursor: pointer;
  font-size: 13px;
  color: var(--notion-text);
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--notion-hover);
}

.icon-btn:active {
  background: var(--notion-active);
}

.icon-btn .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

/* ─── 布局 ─────────────────────────────────────────────── */
.layout {
  display: flex;
  gap: 16px;
  padding: 16px;
  min-height: calc(100dvh - 52px);
}

.stage-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.side {
  width: 340px;
  flex-shrink: 0;
  height: calc(100dvh - 52px - 32px); /* 减去顶栏 + layout padding */
  max-height: calc(100dvh - 52px - 32px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--notion-border);
  border-radius: 12px;
  background: var(--notion-card);
  overflow: hidden;
}

/* ─── 播放器 ────────────────────────────────────────────── */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--notion-border);
}

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

/* 视频全屏模式（保留控制栏） */
.stage:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
}

.stage:fullscreen video {
  flex: 1;
  width: 100%;
  height: auto;
}

.stage:fullscreen .controls {
  position: relative;
  bottom: auto;
  left: auto;
  right: auto;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.8);
  opacity: 1;
  pointer-events: auto;
}

/* 控制条 */
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 40px 12px 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

/* 控制条显示条件：JS 在鼠标靠近底栏时加 .controls-visible，键盘焦点进入时也显示。
   注意：不要加 .stage:hover，否则鼠标在画面任意位置都会弹出控制条，
   与「鼠标靠近底栏才显示、离开即隐藏」的交互冲突。 */
.stage.controls-visible .controls,
.controls:focus-within {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* 进度条 */
.progress {
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
}

.progress::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 4px;
  background: rgba(255,255,255,0.25);
}

.progress-buffer,
.progress-played {
  position: absolute;
  left: 0;
  height: 4px;
  border-radius: 4px;
}

.progress-buffer {
  background: rgba(255,255,255,0.35);
}

.progress-played {
  background: #fff;
  width: 0;
}

.progress-knob {
  position: absolute;
  left: 0;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transform: translateX(-50%) scale(0.85);
  transition: transform 0.1s;
}

.progress:hover .progress-knob,
.progress.dragging .progress-knob {
  transform: translateX(-50%) scale(1.2);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  color: #fff;
  font-size: 13px;
}

.controls-row .icon-btn {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
  color: #fff;
  height: 30px;
  min-width: 30px;
}

.controls-row .icon-btn:hover {
  background: rgba(255,255,255,0.2);
}

.controls-row .icon-btn.lg {
  height: 36px;
  min-width: 36px;
  font-size: 15px;
}

.time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: rgba(255,255,255,0.85);
  white-space: nowrap;
  min-width: 90px;
}

.controls-row .spacer {
  flex: 1;
}

.volume-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.volume-range {
  width: 70px;
  accent-color: #fff;
}

.menu-wrap {
  position: relative;
}

.popover {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 96px;
  padding: 6px;
  border-radius: 10px;
  background: var(--notion-card);
  border: 1px solid var(--notion-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 30;
}

.popover[hidden] {
  display: none;
}

.popover button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: var(--notion-text);
  transition: background 0.15s;
}

.popover button:hover {
  background: var(--notion-hover);
}

/* ─── 状态栏 ────────────────────────────────────────────── */
.statusbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr) auto;
  gap: 6px;
  padding: 10px;
  border-radius: 10px;
  background: var(--notion-card);
  border: 1px solid var(--notion-border);
  font-size: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--notion-bg);
  min-width: 0;
}

.stat-ico {
  font-size: 11px;
  opacity: 0.65;
}

.stat b {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--notion-text);
}

.stat small {
  font-size: 10px;
  color: var(--notion-muted);
}

.stat b.drift-good { color: #10b981; }
.stat b.drift-ok   { color: #f59e0b; }
.stat b.drift-bad  { color: #ef4444; }

.stat-toggle {
  align-self: stretch;
  padding: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--notion-border);
  background: var(--notion-card);
  color: var(--notion-muted);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.stat-toggle:hover {
  background: var(--notion-hover);
}

.stat-toggle[aria-pressed="true"] {
  border-color: #10b981;
  color: #10b981;
}

/* ─── 卡片 / 片源 ───────────────────────────────────────── */
.card {
  padding: 14px;
  border-radius: 12px;
  background: var(--notion-card);
  border: 1px solid var(--notion-border);
  font-size: 13px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--notion-text);
}

.hint {
  font-size: 11.5px;
  color: var(--notion-muted);
}

.field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.field + .field {
  margin-top: 8px;
}

.field.subtle-row {
  flex-wrap: wrap;
}

input[type="text"],
input[type="url"],
input[type="number"] {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--notion-border);
  background: var(--notion-card);
  color: var(--notion-text);
  font-size: 14px;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
input[type="url"]:focus {
  outline: none;
  border-color: var(--notion-accent);
  box-shadow: 0 0 0 3px rgba(46,170,220,0.12);
}

.btn {
  height: 38px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid var(--notion-border);
  background: var(--notion-card);
  color: var(--notion-text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--notion-hover);
}

.btn:active {
  background: var(--notion-active);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  border-color: transparent;
  background: var(--notion-accent);
  color: #fff;
}

.btn.primary:hover {
  filter: brightness(0.95);
}

.btn.primary:active {
  filter: brightness(0.9);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
}

.btn.ghost:hover {
  background: var(--notion-hover);
  border-color: var(--notion-border);
}

.btn.danger {
  color: #ef4444;
  border-color: rgba(239,68,68,0.3);
}

.btn.danger:hover {
  border-color: #ef4444;
  background: rgba(239,68,68,0.04);
}

.note {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--notion-muted);
  line-height: 1.5;
  word-break: break-all;
}

.note.warn {
  color: #f59e0b;
}

.note code {
  background: var(--notion-bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.86em;
}

/* ─── 侧栏 tabs ───────────────────────────────────────── */
.tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--notion-border);
  flex-shrink: 0;
}

.tab {
  padding: 8px 12px;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--notion-muted);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}

.tab:hover {
  color: var(--notion-text);
  background: var(--notion-hover);
}

.tab.active {
  color: var(--notion-text);
  border-bottom-color: var(--notion-accent);
  font-weight: 600;
}

.tab-close {
  margin-left: auto;
  margin-bottom: 4px;
  height: 28px;
  min-width: 28px;
  font-size: 12px;
}

/* ─── 聊天 / 弹幕 / 片单 / 房间信息 ───────────────────── */
.tabpanel {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tabpanel.active {
  display: flex;
}

/* 除「聊天」外的面板内容通常比容器高（片源/房间/设置），必须允许纵向滚动。
   否则在手机横屏、窄窗口或桌面全屏下，下半部分会被 overflow:hidden 裁掉，
   而且用户怎么滑都出不来（overflow:hidden 仍然可以脚本设 scrollTop，容易被误判）。
   聊天面板不在此列：它由内部的 .chat-log 自己滚动，外层再滚会出现双滚动条。 */
.tabpanel[data-panel="source"],
.tabpanel[data-panel="room-status"],
.tabpanel[data-panel="settings"] {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.chat-log {
  flex: 1;
  min-height: 0; /* critical: without this, flex children won't shrink below content height */
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.chat-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--notion-border);
  flex-shrink: 0;
}

.msg {
  max-width: 86%;
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.msg .who {
  display: block;
  font-size: 10.5px;
  color: var(--notion-muted);
  margin-bottom: 2px;
}

.msg.other {
  align-self: flex-start;
  background: var(--notion-bg);
  border: 1px solid var(--notion-border);
}

.msg.mine {
  align-self: flex-end;
  background: var(--notion-accent);
  color: #fff;
  border: none;
}

.msg.mine .who {
  color: rgba(255,255,255,0.75);
}

.msg.system {
  align-self: center;
  max-width: 100%;
  background: transparent;
  border: 1px dashed var(--notion-border);
  color: var(--notion-muted);
  font-size: 11.5px;
  text-align: center;
}

.msg .ts {
  font-size: 10px;
  opacity: 0.55;
  margin-left: 6px;
}

/* 播放列表 */
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--notion-muted);
  cursor: pointer;
}

.switch input {
  accent-color: var(--notion-accent);
}

.qitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--notion-bg);
  font-size: 12.5px;
  border-left: 3px solid transparent;
}

/* 正在播放：左侧强调条 + 高亮，取代原来的 outline（outline 会把相邻条目挤在一起） */
.qitem.current {
  border-left-color: var(--notion-accent);
  background: var(--notion-active);
}

.qitem.current .q-idx {
  color: var(--notion-accent);
}

/* 下一个待播：淡一点，说明自动连播接下来会放它 */
.qitem.next {
  border-left-color: var(--notion-border);
}

.q-badge {
  flex-shrink: 0;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
}

.q-badge.playing {
  color: #fff;
  background: var(--notion-accent);
}

.q-badge.up-next {
  color: var(--notion-muted);
  border: 1px solid var(--notion-border);
}

.q-idx {
  color: var(--notion-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.q-url {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--notion-text);
}

.q-act {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.q-act button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--notion-muted);
  font-size: 12px;
  padding: 3px 5px;
  border-radius: 4px;
  transition: background 0.15s;
}

.q-act button:hover {
  background: var(--notion-hover);
  color: var(--notion-text);
}

.queue-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.queue-actions {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--notion-border);
  flex-shrink: 0;
}

.queue-actions .btn {
  flex: 1;
}

/* 房间 + 状态面板（面板名从 info 改为 room-status，这里的 padding 曾因此失效） */
.tabpanel[data-panel="room-status"] {
  padding: 12px;
}

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.qr-canvas {
  padding: 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--notion-border);
  line-height: 0;
}

.qr-canvas svg {
  width: min(180px, 45vw);
  height: auto;
  display: block;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  margin: 14px 0 0;
  font-size: 12.5px;
}

.kv dt {
  color: var(--notion-muted);
}

.kv dd {
  margin: 0;
  text-align: right;
  word-break: break-all;
  color: var(--notion-text);
}

/* ─── 弹幕 ──────────────────────────────────────────────── */
.danmaku-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.danmaku-item {
  position: absolute;
  top: var(--lane-y, 4px);
  left: 0;
  white-space: nowrap;
  font-size: var(--danmaku-font-size, 20px);
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.85), 0 0 6px rgba(0,0,0,0.4);
  animation: dm-move linear forwards;
  animation-duration: var(--dm-dur, 10s);
  opacity: var(--danmaku-opacity, 1);
  will-change: transform;
}

/* 入场点 = 弹幕层宽度（左边缘刚好贴住右缘），出场点 = 左边缘完全离开左缘。
   两端位移之差恰好等于「层宽 + 自身宽度」，与 JS 计算的 duration 严格对应，
   这样速度设置才是准确的（此前用 100vw，比实际层宽大得多，速度会偏快且随窗口变化）。 */
@keyframes dm-move {
  from {
    transform: translateX(var(--dm-layer-w, 100vw));
  }
  to {
    transform: translateX(calc(var(--dm-layer-w, 100vw) - var(--dm-travel, 100vw)));
  }
}

.danmaku-item.mine {
  outline: 1px solid rgba(255,255,255,0.45);
  border-radius: 4px;
  padding: 0 3px;
}

.danmaku-layer.off {
  display: none;
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast-stack {
  position: absolute;
  left: 12px;
  bottom: calc(60px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 25;
  pointer-events: none;
  max-width: min(340px, 80%);
}

.toast {
  padding: 8px 13px;
  border-radius: 10px;
  font-size: 12.5px;
  background: rgba(55,53,47,0.92);
  border-left: 3px solid var(--notion-accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.14);
  animation: toast-in 0.2s ease;
}

.toast.success {
  border-left-color: #10b981;
}

.toast.warning {
  border-left-color: #f59e0b;
}

.toast.error {
  border-left-color: #ef4444;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ─── 覆盖层 ────────────────────────────────────────────── */
.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.72);
  text-align: center;
  color: #fff;
  padding: 24px;
  z-index: 15;
}

.stage-overlay[hidden] {
  display: none;
}

/* ─── 视频加载中提示 ─────────────────────────────────────── */
/* 盖在画面上但不挡操作：pointer-events:none，播放/暂停等仍可点击。
   z-index 低于 .stage-overlay(15)，因为「还没有内容 / 等房主」这类提示优先级更高。 */
.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 14;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* 必须有这条：上面的 display:flex 会覆盖 hidden 属性的默认 display:none */
.stage-loading[hidden] {
  display: none;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: rgba(255, 255, 255, 0.95);
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

/* 尊重系统的「减少动态效果」设置：改为呼吸效果，避免旋转动画 */
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: spinner-pulse 1.4s ease-in-out infinite;
    border-top-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.55);
  }

  @keyframes spinner-pulse {
    50% {
      opacity: 0.35;
    }
  }
}

.overlay-card {
  padding: 22px;
  max-width: 420px;
}

.overlay-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  font-size: 20px;
}

.overlay-card h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
}

.overlay-card p {
  margin: 0 0 14px;
  font-size: 13px;
  color: rgba(255,255,255,0.7);
}

.overlay-card .btn {
  margin: 0 auto;
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
  color: #fff;
}

.overlay-card .btn:hover {
  background: rgba(255,255,255,0.2);
}

/* ─── 进房向导 ───────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(420px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px;
  border-radius: 14px;
  background: var(--notion-card);
  border: 1px solid var(--notion-border);
  box-shadow: 0 8px 30px rgba(0,0,0,0.14);
  animation: modal-in 0.22s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
  color: var(--notion-text);
}

.modal-sub {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--notion-muted);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.field-block {
  display: block;
  margin-bottom: 14px;
}

.field-block span {
  display: block;
  font-size: 12px;
  color: var(--notion-muted);
  margin-bottom: 5px;
}

.field-block input {
  width: 100%;
  height: 42px;
}

.modal-actions {
  display: flex;
  gap: 9px;
  margin-top: 8px;
}

.modal-actions .btn {
  flex: 1;
  height: 42px;
}

.modal-msg {
  margin: 0 0 12px;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  background: rgba(245,158,11,0.1);
  color: #f59e0b;
}

.modal-msg[hidden] {
  display: none;
}

.modal-foot {
  margin: 16px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--notion-muted);
}

.recent {
  margin-top: 14px;
  font-size: 12px;
  color: var(--notion-muted);
}

.recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.recent-list button {
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--notion-border);
  background: var(--notion-card);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.recent-list button:hover {
  background: var(--notion-hover);
}

/* ─── 响应式 ────────────────────────────────────────────── */
@media (max-width: 1020px) {
  .layout {
    flex-direction: column;
  }

  .side {
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 75dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    z-index: 50;
    transform: translateY(100%);
    transition: transform 0.26s cubic-bezier(0.2, 0, 0, 1);
  }

  body.panel-open .side {
    transform: translateY(0);
  }

  .tab-close {
    display: inline-grid;
  }
}

@media (min-width: 1021px) {
  .tab-close {
    display: none;
  }
}

@media (max-width: 720px) {
  .layout {
    padding: 10px;
    gap: 10px;
  }

  .brand-text em {
    display: none;
  }

  .field {
    flex-wrap: wrap;
  }

  .field input[type="url"] {
    flex: 1 1 100%;
  }

  .field .btn {
    flex: 1;
  }

  .controls-row .icon-btn {
    height: 28px;
    min-width: 28px;
    font-size: 12px;
    padding: 0 4px;
  }

  .controls-row .icon-btn.lg {
    height: 34px;
    min-width: 34px;
  }
}

/* 手机竖屏：侧栏直接显示在视频下方，填满剩余空间 */
@media (max-width: 720px) and (orientation: portrait) {
  html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    padding-bottom: 0;
  }

  .topbar {
    position: relative;
    flex-shrink: 0;
    height: 48px;
    padding: 0 12px;
    z-index: auto;
  }

  .layout {
    flex-direction: column;
    height: calc(100dvh - 48px);
    padding: 0 12px;
    gap: 0;
    overflow: hidden;
    box-sizing: border-box;
  }

  .stage-col {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
    padding-top: 8px;
  }

  .stage {
    flex: 0 0 auto;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: 10px;
    border: 1px solid var(--notion-border);
  }

  .side {
    position: static;
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    max-height: none;
    margin-top: 8px;
    margin-bottom: 8px;
    border-radius: 10px;
    border: 1px solid var(--notion-border);
    background: var(--notion-card);
    transform: none;
    transition: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.panel-open .side {
    transform: none;
  }

  .tabpanel {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
  }

  .tabs {
    flex-shrink: 0;
  }

  .tab-close {
    display: none;
  }

  .danmaku-chat {
    display: none;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar {
    position: static;
  }

  /* 这里必须减去顶栏的真实高度（52px）。原来写 40px，导致
     顶栏(52) + 视频(100dvh-40) = 100dvh + 12，页面多出 12px 纵向滚动。 */
  .stage {
    aspect-ratio: auto;
    height: calc(100dvh - 52px);
    border-radius: 0;
  }

  .layout {
    padding: 0;
    gap: 0;
  }
}

/* ─── 全屏聊天侧栏 ─────────────────────────────────────── */
/* 浏览器原生全屏模式下的样式（全屏元素是 body） */
:fullscreen .topbar {
  /* 全屏时顶栏改为浮层：既能在鼠标移上去时滑出，又不占布局高度。
     若保持 sticky 会占掉 52px，把 100dvh 的播放器顶出屏幕、页面出现滚动条。 */
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

:fullscreen .topbar:hover,
:fullscreen .topbar:focus-within {
  opacity: 1;
  pointer-events: auto;
}

:fullscreen .layout {
  padding: 0;
  gap: 0;
  min-height: 100dvh;
  position: relative;
}

:fullscreen .stage-col {
  gap: 0;
}

:fullscreen .stage {
  border-radius: 0;
  border: none;
  aspect-ratio: auto;
  height: 100dvh;
  width: 100%;
}

:fullscreen .danmaku-chat {
  display: none;
}

/* 侧栏：全屏时隐藏，右侧浮层展开 */
:fullscreen .side {
  position: fixed;
  top: 0;
  /* 必须显式 left: auto！@media (max-width: 1020px) 给 .side 设了 left: 0，
     而 :fullscreen .side 只设了 right: 0。position: fixed 下 left/width/right
     同时非 auto 时，LTR 会忽略 right —— 结果侧栏贴左边弹出，
     而 lll 按钮在右边，抽屉从反方向出来，右边还留一条黑边。 */
  left: auto;
  right: 0;
  bottom: 0;
  /* 同理清掉竖屏规则里的 margin: 8px 0，否则整体下移 8px、底部被裁掉 8px */
  margin: 0;
  width: 360px;
  max-width: 90vw;
  height: 100dvh;
  max-height: 100dvh;
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--notion-border);
  z-index: 80;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.2, 0, 0, 1);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.25);
}

:fullscreen.panel-open .side {
  transform: translateX(0);
}

/* 全屏模式下 tab-close 始终可见 */
:fullscreen .tab-close {
  display: inline-grid;
}

/* 全屏模式下的右侧贴边聊天条 */
.fullscreen-chat-toggle {
  display: none;
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 70;
  width: 36px;
  height: 96px;
  border-radius: 10px 0 0 10px;
  border: none;
  border-right: none;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s, width 0.2s, opacity 0.3s;
  place-items: center;
  /* writing-mode: vertical-rl 会把拉丁字母旋转 90°，于是按钮文字 "lll"
     正好显示成三条横线 "≡"。 */
  writing-mode: vertical-rl;
  letter-spacing: 2px;
  padding: 12px 0;
  gap: 6px;
  opacity: 0.6;
}

.fullscreen-chat-toggle:hover {
  background: rgba(0,0,0,0.7);
  width: 42px;
  opacity: 1;
}

.fullscreen-chat-toggle:active {
  background: rgba(0,0,0,0.85);
}

:fullscreen .fullscreen-chat-toggle {
  display: grid;
}

/* 侧栏打开时，点击遮罩关闭 */
.fullscreen-side-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 75;
}

:fullscreen.panel-open .fullscreen-side-backdrop {
  display: block;
}

/* 全屏聊天按钮上的未读 badge */
.fullscreen-chat-toggle .badge {
  position: absolute;
  top: 8px;
  left: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  display: none;
  writing-mode: horizontal-tb;
  letter-spacing: 0;
}

:fullscreen .fullscreen-chat-toggle .badge.has-unread {
  display: block;
}

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

/* ─── 辅助 ──────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 7px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

[hidden] {
  display: none !important;
}

/* ─── 设置面板样式 ─────────────────────────────────────── */
.settings-section {
  padding: 16px;
}

.settings-section h4 {
  margin: 0 0 16px 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--notion-text);
  border-bottom: 1px solid var(--notion-border);
  padding-bottom: 8px;
}

.setting-item {
  margin-bottom: 16px;
}

.setting-item label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--notion-text);
  margin-bottom: 6px;
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 10px;
}

.setting-control select,
.setting-control input[type="range"] {
  flex: 1;
}

.setting-control select {
  padding: 6px 10px;
  border: 1px solid var(--notion-border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--notion-card);
  color: var(--notion-text);
  outline: none;
}

.setting-control select:focus {
  border-color: var(--notion-accent);
}

.setting-control input[type="range"] {
  -webkit-appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--notion-border);
  outline: none;
}

.setting-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--notion-accent);
  cursor: pointer;
}

.setting-control span {
  min-width: 40px;
  text-align: right;
  font-size: 13px;
  color: var(--notion-muted);
}

.setting-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--notion-border);
}

/* 关于面板：主站链接用 .btn 外观，需要补上 a 元素的排版属性 */
.about-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

/* ─── 侧栏内状态面板 ────────────────────────────────────── */
.status-panel {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.status-panel .stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--notion-bg);
  font-size: 13px;
}

.status-panel .stat-ico {
  font-size: 14px;
  flex-shrink: 0;
}

.status-panel .stat-row b {
  font-weight: 600;
  color: var(--notion-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-panel .stat-row small {
  font-size: 11px;
  color: var(--notion-muted);
  flex-shrink: 0;
}

.status-panel .stat-toggle {
  margin-top: 4px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--notion-border);
  background: var(--notion-card);
  color: var(--notion-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.status-panel .stat-toggle:hover {
  background: var(--notion-hover);
}

.status-panel .stat-toggle[aria-pressed="true"] {
  border-color: #10b981;
  color: #10b981;
}

/* 房主不允许使用自动跟随：置灰并禁用悬停反馈 */
.status-panel .stat-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  color: var(--notion-muted);
  border-color: var(--notion-border);
  border-style: dashed;
  background: transparent;
}

.status-panel .stat-toggle:disabled:hover {
  background: transparent;
}

/* ─── 侧栏内片源面板（重新设计） ─────────────────────────── */
.tabpanel[data-panel="source"] {
  padding: 12px;
  gap: 14px;
}

/* 每个功能块一张卡片，靠留白分组，不再用分隔线 */
.src-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--notion-border);
  border-radius: 10px;
  background: var(--notion-card);
}

.src-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.src-title {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--notion-text);
  display: flex;
  align-items: center;
  gap: 7px;
}

.src-block .field {
  margin-top: 0;
}

.src-block .note {
  margin-top: 0;
}

/* 当前片源卡片：一眼看到「现在播的是什么」+ 三个就地操作 */
.now-playing {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: var(--notion-bg);
}

.np-ico {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
}

.np-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.np-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--notion-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* 未载入时由 JS 加上 .is-empty，弱化显示 */
}

.now-playing.is-empty .np-name {
  color: var(--notion-muted);
  font-weight: 500;
}

.np-sub {
  font-size: 11px;
  color: var(--notion-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.np-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn.sm {
  height: 26px;
  min-width: 26px;
  padding: 0 6px;
  font-size: 12px;
  border-radius: 6px;
}

.icon-btn.sm.danger {
  color: #ef4444;
}

.icon-btn.sm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* 播放列表条目数 */
.pl-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--notion-muted);
  background: var(--notion-bg);
  border-radius: 999px;
  padding: 1px 7px;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 播放列表区块在片源 tab 内，空列表占位不再撑出多余间距 */
.queue-list > .note {
  margin: 0;
  padding: 10px 2px;
}

.src-block .queue-actions {
  padding: 0;
  border-top: none;
}

/* ─── 房间与状态合并选项卡 ─────────────────────────────── */
.room-status-section {
  margin-bottom: 16px;
}

.room-status-section h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--notion-text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--notion-border);
}

.room-status-section:last-child {
  margin-bottom: 0;
}

/* 二维码盒子样式 */
.qr-box {
  text-align: center;
  padding: 12px;
  background: var(--notion-bg);
  border-radius: 8px;
  margin-bottom: 12px;
}

.qr-canvas {
  margin: 0 auto 8px;
}

.qr-box .note {
  margin: 0;
  font-size: 12px;
  color: var(--notion-muted);
}

/* 键值对样式 */
.room-status-section .kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  padding: 12px;
  background: var(--notion-bg);
  border-radius: 8px;
  font-size: 13px;
}

.room-status-section .kv dt {
  font-weight: 500;
  color: var(--notion-muted);
}

.room-status-section .kv dd {
  margin: 0;
  color: var(--notion-text);
  font-weight: 500;
}
