/*
 * 右侧栏（2026-11-15）
 * ────────────────────────────────────────────────────────────────────────────
 * 只在首页与状态页出现，展示"此刻最该看的几件事"。
 *
 * ## 为什么用 fixed 浮动列，而不是把内容包成两栏
 *
 * 首页有 6 个 section（hero / modes / start / shortcuts / specs / news），
 * 其中 `start-layout`、`shortcut-grid` 自己已经是网格。如果在最外层包一层 flex 两栏，
 * 那些内部网格会被挤在更窄的容器里 —— 等于同时改了两层版式。
 * 浮动右栏只压一个变量：内容区多了一个右内边距。
 *
 * ## 出现条件
 *
 *   · 屏幕 ≥ 1240px（再窄就真的挤了：1240 − 244 左栏 − 320 右栏 = 676px 内容，已经是下限）
 *   · 页面是首页或状态页
 *   · 页面是首页或状态页 → 那段同步脚本给 `<html>` 加类 `fxside-page`，
 *     由 `html.fxside-page body` 决定内容区让出多少右边距；
 *   · 加在 `<html>` 上而不是 `<body>`：body 的 class 可能已被 `$bodyTag` 占用
 *     （子服页是 `class="srv-page"`），拼两个 class 会失效；
 *     而且那段脚本执行时 `document.body` 还不存在。
 *
 * ## 与其他层的边界
 *
 *   · 不改任何现有规则，只加；
 *   · 数据全部来自站上现成的函数（status_summary / dau_unique / content('news')）；
 *   · **签到那块只读**：网页签到的写入留到下一批（要新表 + 幂等键 + 金币通道）。
 * ────────────────────────────────────────────────────────────────────────────
 */

:root {
  /*
   * 右栏宽度（2026-11-15 服主：「把左右2边做成一样宽」）。
   *
   * ⚠️ 必须与 rail.css 的 `--rail-w` **完全一致**（现在是 264px）。
   *    改宽度时两处一起改，`上线/同步栏宽.mjs` 会核对。
   *    原来是 320px、左栏 244px —— 差 76px，两边明显不对称。
   */
  --fxside-w: 264px;
  --fxside-gap: 28px;

  /*
   * 折叠/滑动的三个尺寸（2026-11-15 服主：「右边我以后也打算让他能滑动和折叠隐藏」）
   *   --fxside-handle   收起时露在屏幕右边的那条"拉手"的宽度
   *   --fxside-mini     收起后宽度（只留拉手）
   */
  --fxside-handle: 28px;
  --fxside-mini: 28px;

  --fxside-bg: #ffffff;
  --fxside-line: #e4eaf3;
  --fxside-line-2: #d3dce9;
  --fxside-ink: #0f1115;
  --fxside-ink-2: #3c4453;
  --fxside-ink-3: #697386;
  --fxside-ink-4: #95a0b3;
  --fxside-brand: #4176e6;
  --fxside-brand-600: #3567d4;
  --fxside-brand-soft: #eef3ff;
  --fxside-ok: #14915a;
  --fxside-ok-soft: #e7f7ef;
}

html[data-theme="dark"] {
  --fxside-bg: #10161f;
  --fxside-line: #232b3a;
  --fxside-line-2: #2e3a4d;
  --fxside-ink: #e9edf7;
  --fxside-ink-2: #c6cddd;
  --fxside-ink-3: #94a1b8;
  --fxside-ink-4: #6e7b90;
  --fxside-brand: #7c9bf7;
  --fxside-brand-600: #a8bfff;
  --fxside-brand-soft: #172235;
  --fxside-ok: #5ccb8a;
  --fxside-ok-soft: #15301f;
}

/* ============================ 栏本体 ============================ */
/*
 * 2026-11-15 改造（服主：「右边我以后也打算让他能滑动和折叠隐藏」）：
 *
 * ① **滑动**：`.fxside` 自己 `overflow-y: auto`，内容高了在栏内滚。
 *    滚动条样式与左栏统一（6px、轨道透明、悬停加深）。
 * ② **折叠隐藏**：点顶部拉手上的按钮 → 整栏向右滑出、只留一条 28px 拉手。
 *    状态存 localStorage；用 `html[data-fxside="hidden"]` 表达。
 * ③ **宽度与左栏一致**（264px）。
 *
 * ⚠️ 折叠时内容区要让出来（padding-right 从 264+28+20 降到 28+20），
 *    见下面的 `html[data-fxside="hidden"]` 规则。这一条不能漏，否则
 *    收起后右边会留一大片空白。
 */
.fxside {
  position: fixed;
  top: calc(var(--fxside-top, 72px) + 16px);
  right: 20px;
  width: var(--fxside-w);
  display: flex;
  flex-direction: column;
  gap: 14px;
  z-index: 30;                       /* 低于顶栏（60）、低于左栏（95） */
  max-height: calc(100vh - var(--fxside-top, 72px) - 40px);
  /* 滑动：内容高了在栏内滚（原来就是 auto，这里把滚动条样式补齐） */
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--fxside-line-2) transparent;
  overscroll-behavior: contain;
  /* 折叠动画：宽度与位移一起走，时长与左栏折叠一致（.24s） */
  transition: width var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1)),
              transform var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1)),
              opacity .18s ease;
  pointer-events: auto;
}

/* 滚动条：与左栏同一套（细、透明轨道、悬停加深） */
.fxside::-webkit-scrollbar { width: 6px; }
.fxside::-webkit-scrollbar-track { background: transparent; }
.fxside::-webkit-scrollbar-thumb {
  background: var(--fxside-line-2);
  border-radius: 3px;
  transition: background .15s;
}
.fxside:hover::-webkit-scrollbar-thumb { background: var(--fxside-ink-4); }
.fxside::-webkit-scrollbar-thumb:hover { background: var(--fxside-ink-3); }

/* ============================ 折叠拉手 ============================ */
/*
 * 拉手固定在栏顶（`position: sticky` 让它跟着滚动留在视野里），
 * 收起后它是唯一的可见部分。
 */
.fxside-tog {
  position: sticky;
  top: 0;
  z-index: 3;
  align-self: flex-end;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0 0 -14px auto;      /* 负边距抵掉 flex gap，贴在第一张卡右上 */
  border: 1px solid var(--fxside-line);
  border-radius: 8px;
  background: var(--fxside-bg);
  color: var(--fxside-ink-4);
  cursor: pointer;
  transition: background .13s, color .13s, border-color .13s;
}
.fxside-tog:hover {
  background: var(--fxside-brand-soft);
  border-color: var(--fxside-brand);
  color: var(--fxside-brand-600);
}
/*
 * 2026-11-15 换图标：右栏用与左栏相同的「方框 + 竖线」图标，
 * 这里做**水平镜像**，让竖线落在右侧（对应右栏方位）。
 *
 * ⚠️ 用 scaleX(-1) 而不是 rotate(180deg)：
 *    rotate 是上下左右都翻，会把外框圆角与竖线一起倒置，一眼就看出不对。
 *    scaleX(-1) 只左右镜像，上下方向保持正常。
 */
.fxside-tog svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: scaleX(-1);
  transition: transform var(--bar-dur, .36s) var(--bar-ease, cubic-bezier(.4,0,.2,1));
}

/* ---------- 收起态 ---------- */
/*
 * 🔴 2026-11-15 修 bug：第一版收起后**展不开**。
 *
 * 原因：`.fxside` 用 `translateX` 滑出屏幕，同时 `overflow: hidden` ——
 *   而折叠按钮是 `.fxside` 的**子元素**，于是它跟着一起被滑出、又被 overflow 裁掉，
 *   屏幕上什么都没有，自然点不到"展开"。
 *
 * 改法：收起时**不给 .fxside 加 transform**，改成只把"内容卡片"逐个淡出，
 *   并把 .fxside 自身收窄到只剩拉手宽度。这样按钮始终留在视口内。
 *   具体：
 *     · .fxside 宽度 264 → 28（保留在屏幕右缘）
 *     · 卡片 `display: none`（不是 opacity:0 —— 后者仍占宽度，会把栏撑开）
 *     · 按钮脱离文档流（position: fixed 到屏幕右缘），成为唯一可点元素
 */
html[data-fxside="hidden"] .fxside {
  /* 宽度收窄到拉手宽度：栏仍然存在、按钮仍然可点，只是内容没了 */
  width: var(--fxside-mini);
  overflow: visible;               /* 按钮收起时要能"探出"栏外一点 */
  background: transparent;
  border: 0;
  box-shadow: none;
}
html[data-fxside="hidden"] .fxside > *:not(.fxside-tog) {
  /*
   * ⚠️ 必须 display:none，不能只 opacity:0：
   *    opacity:0 的元素仍然占宽度与高度，会把 .fxside 撑回 264px，
   *    看着就像"没收起"，只是内容透明了。
   */
  display: none !important;
}
html[data-fxside="hidden"] .fxside-tog {
  /* 收起时按钮钉在屏幕右缘，是唯一可见可点的东西 */
  position: fixed;
  right: 8px;
  top: calc(var(--fxside-top, 72px) + 16px);
  margin: 0;
  z-index: 31;
  /* 收起态给一点提示：按钮底色与描边更明显，让人知道能点开 */
  background: var(--fxside-bg);
  border-color: var(--fxside-line-2);
  color: var(--fxside-brand-600);
  box-shadow: 0 2px 8px rgba(16, 24, 40, .12);
}
html[data-fxside="hidden"] .fxside-tog:hover {
  background: var(--fxside-brand-soft);
  border-color: var(--fxside-brand);
}
/* 收起态：镜像翻回去（scaleX(1)），竖线从右侧跑到左侧 —— 语义变成「展开」 */
html[data-fxside="hidden"] .fxside-tog svg { transform: scaleX(1); }

/* 收起时内容区让位减少（否则右边留一大片空白） */
@media (min-width: 1100px) {
  html[data-fxside="hidden"].fxside-page body {
    padding-right: calc(var(--fxside-mini) + 16px);
  }
}

/* ==========================================================================
   内容区让位 —— 三档自适应（2026-11-15 服主：「屏幕要适配所有用户」）
   --------------------------------------------------------------------------
   🔴 之前是"1400px 以下整栏不出现"，这不符合"适配所有用户"：
      常见笔记本 1280/1366、平板横屏 1024~1200 都会看不到右栏。
      但两栏并存确实要占宽度（264 + 28 + 20 = 312px），硬塞会把内容挤扁。

   所以改成**三档渐进**，而不是"要么全有、要么全无"：

     档位           屏幕宽度        右栏宽度   做法
     ---------------------------------------------------------------
     宽屏           ≥ 1400px       264px      完整显示（三张卡全展开）
     中等           1100~1399px    240px      显示，但卡片内容更紧凑
                                               （统计块改单列、公告只显示 2 条）
     窄（笔记本竖/竖屏平板）
                    1100px 以下    默认**收起**（只留拉手）
                                    用户点一下就展开（占用宽度仍 240）

   为什么 1100px 以下默认收起：那段宽度内容区只剩 836px 左右，
   再刨 312px 给右栏就只剩 520px，正文会窄到读不下去。
   但**不是不给**——用户想用随时点开，展开后内容区会被压窄，那是他的选择。
   ========================================================================== */
@media (min-width: 1400px) {
  html.fxside-page body { padding-right: calc(var(--fxside-w) + var(--fxside-gap) + 20px); }

  /*
   * 🔴 首页首屏不需要额外处理（2026-11-15 自查后删掉了原来的那段覆盖）。
   *
   * 原来我在这里写了一条：
   *     html.fxside-page body.fxrail-home .hero {
   *       width: calc(100% + var(--rail-w) - var(--fxside-w) - var(--fxside-gap) - 20px);
   *     }
   * 这是**重复扣减**，算错了。原因：
   *   · `.hero` 的 `width: calc(100% + var(--rail-w))` 里的 `100%`，
   *     解析的是**父级内容盒宽度**，而 body 的 padding-right 已经把右栏那段空间扣掉了；
   *   · 所以 `100%` 本身就已经少了 (右栏宽 + 间距 + 20)，
   *     我再去减一遍，首屏会缩到远早于右栏的位置、右边留一大块空白。
   *
   * 结论：`.hero` 的破格宽度**自动随 padding-right 收缩**，这里一条都不用写。
   * ⚠️ 以后若改 body 的 padding 方案，务必先按上面的算法验一遍再动。
   */
}

/* 中等宽度：右栏默认**收起**（只留拉手），用户可自行点开
   --------------------------------------------------------------------------
   🔴 2026-11-15 修正（按新增的"屏幕差异会误判"规矩重新核算）：
      原来这一档是"右栏显示但紧凑（240px）"。但把各档排在一起看就发现冲突：

        1100px 屏：左栏展开 264 + 右栏 272 = 536，中间内容只剩 696px
        1280px 屏：左边 264 + 右边 272 = 536，中间只剩 744px

      而站点 `.wrap` 的设计宽度是 1120px —— 700 出头时首页玩法卡会掉成单列、
      三栏步骤折成竖排。也就是说这一档"两栏都在"会把内容挤扁。

      改成与窄屏一致：**默认收起，只留 28px 拉手**。用户想用点一下即可展开，
      展开后内容区被压窄是他自己的选择（不再是默认行为）。

   ⚠️ 与 ≤1099px 那档的差别只剩"展开后宽度"（240 vs 240）与间距，可以合并思考；
      保留独立媒体查询是因为这段还挂了"统计块单列 / 公告 2 条"的紧凑规则。
   ========================================================================== */
@media (max-width: 1399px) and (min-width: 1100px) {
  :root { --fxside-w: 240px; --fxside-gap: 20px; }

  /* 默认收起（用户没选过时）：只留拉手，不占内容区 */
  html:not([data-fxside]) .fxside {
    width: var(--fxside-mini);
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  html:not([data-fxside]) .fxside > *:not(.fxside-tog) { display: none !important; }
  html:not([data-fxside]) .fxside-tog {
    position: fixed;
    right: 8px;
    top: calc(var(--fxside-top, 72px) + 16px);
    margin: 0;
    z-index: 31;
    background: var(--fxside-bg);
    border-color: var(--fxside-line-2);
    color: var(--fxside-brand-600);
    box-shadow: 0 2px 8px rgba(16, 24, 40, .12);
  }

  /* 用户点开后：显示并让位 */
  html[data-fxside="open"].fxside-page body {
    padding-right: calc(var(--fxside-w) + var(--fxside-gap) + 16px);
  }
  /* 用户收起后：只让出拉手宽度 */
  html[data-fxside="hidden"].fxside-page body {
    padding-right: calc(var(--fxside-mini) + 16px);
  }

  /* 展开时内容更紧凑：统计块改单列、公告只留 2 条 */
  .fxside-stats { grid-template-columns: 1fr !important; }
  .fxside-stats div { border-left: 0 !important; border-top: 1px solid var(--fxside-line); }
  .fxside-stats div:first-child { border-top: 0; }
  .fxside-row:nth-child(n + 3) { display: none; }
}

/* 窄屏（≤1099px）：右栏**默认收起**，只留拉手；用户点开就展开 */
@media (max-width: 1099px) {
  :root { --fxside-w: 240px; --fxside-gap: 16px; }

  /*
   * 默认收起：靠这段同步脚本之外的方式做不到"默认"，所以这里用 CSS 兜底
   * （脚本会在 <html> 上加 data-fxside，用户点开后这个属性会变）。
   * ⚠️ 用 :not([data-fxside]) 表示"用户还没选过"，此时强制收起。
   */
  html:not([data-fxside]) .fxside {
    width: var(--fxside-mini);
    overflow: visible;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  html:not([data-fxside]) .fxside > *:not(.fxside-tog) { display: none !important; }
  html:not([data-fxside]) .fxside-tog {
    position: fixed;
    right: 8px;
    top: calc(var(--fxside-top, 72px) + 16px);
    margin: 0;
    z-index: 31;
    background: var(--fxside-bg);
    border-color: var(--fxside-line-2);
    color: var(--fxside-brand-600);
    box-shadow: 0 2px 8px rgba(16, 24, 40, .12);
  }
  /* 用户手动展开后：正常显示，内容区让位 */
  html[data-fxside="open"].fxside-page body { padding-right: calc(var(--fxside-w) + var(--fxside-gap) + 16px); }
  html[data-fxside="open"] .fxside { padding-right: 0; }
}

/* ============================ 卡片 ============================ */
.fxside-card {
  border: 1px solid var(--fxside-line);
  border-radius: 14px;
  background: var(--fxside-bg);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .04);
  overflow: hidden;
  flex: none;
}

.fxside-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 15px;
  border-bottom: 1px solid var(--fxside-line);
}
.fxside-h b {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--fxside-ink);
  letter-spacing: -.005em;
}
.fxside-h a {
  font-size: 12px;
  color: var(--fxside-ink-3);
  text-decoration: none;
  white-space: nowrap;
}
.fxside-h a:hover { color: var(--fxside-brand-600); }

.fxside-b { padding: 14px 15px; }

/* ---------- 签到 ---------- */
.fxside-sign {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 11px;
}
.fxside-sign b {
  font-size: 27px;
  font-weight: 780;
  line-height: 1;
  color: var(--fxside-brand-600);
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.fxside-sign span {
  font-size: 12px;
  color: var(--fxside-ink-4);
}
.fxside-note {
  margin: 0 0 12px;
  font-size: 11.5px;
  line-height: 1.72;
  color: var(--fxside-ink-4);
}
.fxside-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background .14s, border-color .14s, color .14s;
}
.fxside-btn--ghost {
  border-color: var(--fxside-line-2);
  color: var(--fxside-ink-2);
  background: transparent;
}
.fxside-btn--ghost:hover {
  border-color: var(--fxside-brand);
  color: var(--fxside-brand-600);
  background: var(--fxside-brand-soft);
}
.fxside-btn--pri {
  color: #fff;
  background: linear-gradient(150deg, #5b8af0, #3567d4);
  box-shadow: 0 2px 8px rgba(65, 118, 230, .26);
}
.fxside-btn--pri:hover { box-shadow: 0 4px 14px rgba(65, 118, 230, .32); }

/* ---------- 数据块 ---------- */
.fxside-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.fxside-stats div {
  padding: 12px 15px;
  border-top: 1px solid var(--fxside-line);
}
.fxside-stats div:nth-child(-n+2) { border-top: 0; }
.fxside-stats div:nth-child(even) { border-left: 1px solid var(--fxside-line); }
.fxside-stats b {
  display: block;
  font-size: 20px;
  font-weight: 760;
  line-height: 1.2;
  letter-spacing: -.02em;
  color: var(--fxside-ink);
  font-variant-numeric: tabular-nums;
}
.fxside-stats span {
  font-size: 11.5px;
  color: var(--fxside-ink-4);
}

/* ---------- 公告列表 ---------- */
.fxside-list { display: flex; flex-direction: column; }
.fxside-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  border-top: 1px solid var(--fxside-line);
  text-decoration: none;
  color: inherit;
  transition: background .12s;
}
.fxside-row:first-child { border-top: 0; }
.fxside-row:hover { background: var(--fxside-brand-soft); }
.fxside-row-t {
  flex: 1;
  min-width: 0;
  font-size: 12.8px;
  line-height: 1.55;
  color: var(--fxside-ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.fxside-row-d {
  flex: none;
  font-size: 11px;
  color: var(--fxside-ink-4);
  font-variant-numeric: tabular-nums;
}

/* 打印时不显示 */
@media print {
  .fxside { display: none !important; }
  html.fxside-page body { padding-right: 0 !important; }
}
