/*
 * 挂件按钮移入顶栏（2026-11-15）
 * ────────────────────────────────────────────────────────────────────────────
 * ## 服主的要求
 *
 *   「左下角这2个按钮现在可以换位置了」→ 选定「移到顶栏里」＋「沉浸态也要隐藏」。
 *
 * ## 涉及的元素
 *
 *   `#dock`      容器（⚙ 挂件开关 / ♪ 音乐 / →] 怎么进服 三个按钮）
 *   面板          #dockPanel（挂件开关）、#musicPanel（音乐）、#joinPanel（怎么进服）
 *
 * ## 做了什么
 *
 *   ① HTML 里把 `#dock` 从 body 直属搬到 `topnav-inner` 内（搜索按钮之前），
 *      并加上 `dock--topbar` 类；
 *   ② 本文件把 `.dock--topbar` 从"左下角固定定位"改成"顶栏内联排列"；
 *   ③ 三个面板从"贴左下角往上展开"改成"从顶栏右上角往下展开"。
 *
 * ## ⚠️ 关键取舍：为什么容器不能删
 *
 *   `dock.js` 第 12-13 行 `const dock = document.getElementById('dock'); if (!dock) return;`
 *   —— 容器不存在时整个脚本退出，挂件开关与音乐面板全部失效。
 *   所以这里**只改样式，不动 id、不动结构**。
 *
 * ## ⚠️ 沉浸态为什么不用额外写
 *
 *   服主要「沉浸态也要隐藏」。`#dock` 现在在 `.topnav` 内部，
 *   而沉浸态下 `.topnav` 整条 `translateY(-100%)` —— dock 会**自动跟着上移出屏**。
 *   单独再写一条隐藏规则反而会与顶栏的动画脱节（两边时长不同步就会看到"按钮先没、顶栏后走"）。
 *   这里只在窄屏（抽屉模式）另作处理，因为那时顶栏行为不同。
 * ────────────────────────────────────────────────────────────────────────────
 */

/* ==========================================================================
   一、容器：从"左下角固定"改成"顶栏内联"
   --------------------------------------------------------------------------
   style.css 里的原规则是：
     .dock { position: fixed; left: 16px; bottom: 16px; z-index: 85; display: flex; ... }
   rail.css 又把它推到 `left: calc(16px + var(--rail-w))` 给左栏让位。
   现在它在顶栏内部，这些全部要清掉 —— 用 `!important` 覆盖，
   因为 rail.css / immersive.css 里那几条都带 `!important`。
   ========================================================================== */
.dock--topbar {
  position: static !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
  /* 在顶栏这一行里靠右排（顶栏内层是 flex，账号卡之后就是它） */
  margin: 0 0 0 8px !important;
  gap: 6px !important;
  z-index: auto !important;
  /* 不再需要"浮在内容上方"的层级，也不再有底部留白 */
  align-items: center;
}

/* ==========================================================================
   二、按钮：从"圆形大按钮"改成"顶栏图标按钮"
   --------------------------------------------------------------------------
   原来底部那两个是 40px 圆钮（有阴影、有底色），放在顶栏会显得笨重。
   改成与搜索按钮同一套尺寸与观感：32px 方圆、悬停浅底、无阴影。
   ========================================================================== */
.dock--topbar .dock-btn {
  width: 32px !important;
  height: 32px !important;
  min-width: 32px;
  border-radius: 9px !important;
  background: transparent !important;
  border: 1px solid transparent !important;
  box-shadow: none !important;
  color: var(--ink-3, #697386) !important;
  font-size: 15px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .14s ease, color .14s ease, border-color .14s ease;
}
.dock--topbar .dock-btn:hover {
  background: var(--brand-soft, #eef3ff) !important;
  color: var(--brand-600, #3567d4) !important;
  border-color: transparent !important;
}
.dock--topbar .dock-btn:focus-visible {
  outline: 2px solid var(--brand-btn, #4a6ee2);
  outline-offset: 2px;
}
/* 激活态（面板正开着）：与搜索按钮的 active 同一套 */
.dock--topbar .dock-btn.is-on,
.dock--topbar .dock-btn[aria-expanded="true"] {
  background: var(--brand-soft, #eef3ff) !important;
  color: var(--brand-600, #3567d4) !important;
}
/* 音乐按钮开着时的脉冲点（原来底部按钮有，这里保留但缩小） */
.dock--topbar .dock-btn.dock-music.is-on::after {
  content: "";
  position: absolute;
  top: 6px; right: 6px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--brand-btn, #4a6ee2);
}
.dock--topbar .dock-btn { position: relative; }

/* 深色模式 */
html[data-theme="dark"] .dock--topbar .dock-btn {
  color: var(--ink-3, #94a1b8) !important;
}
html[data-theme="dark"] .dock--topbar .dock-btn:hover {
  background: #1b2537 !important;
  color: #a8bfff !important;
}

/* ==========================================================================
   三、面板：从"左下角往上"改成"顶栏下方往下"
   --------------------------------------------------------------------------
   原来（style.css）：
     .dock-panel, .music-panel { left: 16px; bottom: 84px; top: auto; right: auto; }
     （rail.css 又把 left 推到 16+264）
   现在按钮在顶栏右端，面板应该：
     · 水平：右对齐到按钮附近（right: 距屏幕右缘约 16px，避开账号区）
     · 垂直：从顶栏底边往下展开（top: 顶栏高度 + 8px）
     · 动画原点：右上角（transform-origin: 100% 0）
   ========================================================================== */
/*
 * ⚠️ 面板**不在** `.topnav` 内部：
 *    DOM 顺序是  <header class="topnav">…</header>  →  #joinPanel / #musicPanel / #dockPanel
 *    所以不能用 `.dock--topbar ~ .dock-panel` 这种兄弟选择器（永远匹配不到）。
 *    直接按类名与 id 定位即可 —— 它们是全站唯一的。
 */
.dock-panel,
.music-panel,
#joinPanel {
  left: auto !important;
  right: 16px !important;
  bottom: auto !important;
  top: calc(var(--topbar-height, 56px) + 10px) !important;
  transform-origin: 100% 0 !important;
  /*
   * ⚠️ 动画方向要跟着改。
   *    `.wpanel` 原本（style.css:2116）是：
   *        opacity: 0; transform: translateY(8px) scale(.96);
   *        transform-origin: 100% 100%;
   *    那是"从下往上弹出"—— 因为面板在屏幕左下角、按钮在它下方。
   *    现在按钮在顶栏、面板在按钮**下方**，应该"从上往下落"才对。
   *    所以初态位移取负值（往上 8px 起步，落到原位）。
   */
  transform: translateY(-8px) scale(.96) !important;
}
/* 展示态：落回原位（覆盖 .wpanel.show 的 transform:none） */
.dock-panel.show,
.music-panel.show,
#joinPanel.show {
  transform: none !important;
}
/*
 * 右边要避开右栏：≥1400px 时右栏占 264 + 间距，面板右缘对齐到右栏左侧。
 * ⚠️ 用变量算，不写死 —— 右栏宽度在 1400 以下是 240。
 */
@media (min-width: 1400px) {
  .dock-panel,
  .music-panel,
  #joinPanel {
    right: calc(var(--fxside-w, 264px) + var(--fxside-gap, 28px) + 32px) !important;
  }
}
/* 顶栏同样通栏，但面板要躲开右栏；窄屏（无右栏）就用常规 16px */
@media (max-width: 1399px) {
  .dock-panel,
  .music-panel,
  #joinPanel {
    right: 16px !important;
  }
}

/*
 * 「怎么进服」面板比挂件面板宽（要放地址与群号），横屏下别顶到屏幕左缘。
 */
#joinPanel {
  width: min(360px, calc(100vw - 40px)) !important;
  max-height: min(70vh, 520px);
  overflow-y: auto;
}

/* ==========================================================================
   四、窄屏（≤900）：顶栏变胶囊形态，按钮另作处理
   --------------------------------------------------------------------------
   900px 以下顶栏是手机布局（`.topnav-inner` 变成满宽胶囊），
   原来 dock 是"贴屏幕左下角、不跟左栏走"（rail.css 第 499 行）。
   现在它在顶栏内，跟着顶栏走即可；这里只把尺寸再缩小一点，免得挤爆手机顶栏。
   ========================================================================== */
@media (max-width: 900px) {
  .dock--topbar {
    margin-left: 4px !important;
    gap: 2px !important;
  }
  .dock--topbar .dock-btn {
    width: 30px !important;
    height: 30px !important;
    min-width: 30px;
  }
  /* 手机上音乐按钮通常不出现（后台开关），但真出现时也别挤 */
  .dock--topbar .dock-btn.dock-music { display: none; }

  /* 手机上面板改全宽 */
  .dock-panel,
  .music-panel,
  #joinPanel {
    left: 8px !important;
    right: 8px !important;
    top: calc(var(--topbar-height, 56px) + 8px) !important;
    width: auto !important;
  }
}

/* ==========================================================================
   五、沉浸态：按钮跟着顶栏走，但**面板要单独处理**
   --------------------------------------------------------------------------
   `#dock` 在 `.topnav` 内部，顶栏沉浸态 `translateY(-100%)` 会带着它一起上移出屏 ✓
   
   🔴 但三个面板**不在顶栏内部**：
      DOM 顺序是  <header class="topnav">…</header> → #joinPanel / #musicPanel / #dockPanel
      所以顶栏上移时，面板会**留在原地** —— 如果此刻面板正开着，
      就会出现"按钮没了、面板还飘在屏幕上方"的错位。
   
   修法：让面板跟着顶栏一起上移（同一个时长与曲线），而不是 `display:none`
   （后者会在收起的瞬间"啪"地消失，比跟着滑动更突兀）。

   ⚠️ **只作用于 `.show` 状态**：
      `.wpanel` 的展开/收起完全靠 `.show` 类（`opacity: 1; transform: none`），
      `[hidden]` 属性只是语义标记、**没有对应的 display 规则**。
      所以这里的沉浸态规则必须写成 `html[data-immersive="1"] .wpanel.show`，
      写成不带 `.show` 的会连"展开"状态一起压掉 —— 面板就永远显示不出来了。
   ========================================================================== */
html[data-immersive="1"] .dock-panel.show,
html[data-immersive="1"] .music-panel.show,
html[data-immersive="1"] #joinPanel.show {
  transform: translateY(calc(-100% - var(--topbar-height, 56px) - 20px)) !important;
  opacity: 0 !important;
  pointer-events: none !important;
  transition:
    transform var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1)),
    opacity var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1)) !important;
}

/*
 * 归位态（非沉浸）：面板展开时回到原位。
 * 这里只补 transition 的时长，**不改 opacity / transform** ——
 * 那两个交给 `.wpanel` 与 `.wpanel.show` 自己管（它们本来就有正确的值与动画）。
 * 单独写 `!important` 会把 `.show` 的展开效果压掉。
 */
.dock-panel,
.music-panel,
#joinPanel {
  transition:
    transform var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1)),
    opacity var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1));
}

/* ==========================================================================
   六、打印：不显示
   ========================================================================== */
@media print {
  .dock--topbar { display: none !important; }
}

/* ==========================================================================
   七、动画时长：跟随顶栏
   --------------------------------------------------------------------------
   dock 现在在顶栏里，它的任何位移都该与顶栏同步。
   （虽然它本身不位移，但"悬停底色"这类过渡要跟得上）
   ========================================================================== */
.dock--topbar {
  transition: none;
}
