/* =============================================================================
   global-scroll-controls.css — 全站悬浮页面滚动组件的唯一样式来源（手工维护，2026-12-02）

   四个按钮（返回顶部 / 向上滚动一屏 / 向下滚动一屏 / 直达底部）由 global-scroll-controls.js 生成：
     div#back-to-top.back-to-top[role=group] > button.scroll-nav-button[data-scroll-action] > svg
   love8.me 与 game.love8.me 两站各存一份、逐字节相同。规则原样迁自主站 navigation.css 与游戏站
   nav-floating-tools.css 的「悬浮工具」一节，数值未改；导航页的「显示描述」按钮仍在各站导航样式表里。

   站主已确认的设计（未经站主明确授权不得修改，也不要以触控面积、无障碍或品牌色为由放大按钮或换色）：
     按钮 32×32px、图标 18×18px、间距 4px、圆角 6px、内边距 6px、1px currentColor 边框、底色 #eff6ff、
     阴影两层；常态 #3d3eff（≤640px 为真机定的 #6769ff）、悬停 / 焦点 / 按下 #0000ff；
     距视口右下角 20px，窄屏与横放触屏手机按安全区计算；≥1500px 贴在内容列外侧 8px；RTL 镜像到左侧。
   到达边界的按钮保留槽位但隐藏、不接收点击；整组不可滚动时隐藏，空白区域不拦截页面点击。

   页脚让位（--footer-controls-clearance）不在这里：滚动按钮在页面底部时下面两格已隐藏，
   不需要让位；只有导航页的「显示描述」按钮需要，由各站导航样式表设置。
   ============================================================================= */

.back-to-top {
  position: fixed;
  z-index: 40;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 32px;
  color: #3d3eff;
  opacity: 0;
  visibility: hidden;
  /* Empty slots must let pointer events pass through to the page. */
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
}

.back-to-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-nav-button {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  padding: 6px;
  appearance: none;
  color: inherit;
  border: 1px solid currentColor;
  border-radius: 6px;
  background: #eff6ff;
  box-shadow:
    0 1px 2px rgba(23, 33, 43, .10),
    0 10px 24px rgba(29, 78, 216, .22);
  cursor: pointer;
  pointer-events: auto;
  touch-action: manipulation;
  transition: color .15s ease, opacity .15s ease;
}

.scroll-nav-button svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#back-to-top .scroll-nav-button[aria-disabled="true"] {
  /* Keep all four slots in the fixed group, including the lower empty slots. */
  visibility: hidden;
  pointer-events: none;
}

/* Touch screens use focus feedback to avoid sticky hover. */
@media (hover: hover) {
  .scroll-nav-button:not([aria-disabled="true"]):hover {
    color: #0000ff;
  }
}

.scroll-nav-button:focus,
.scroll-nav-button:active {
  color: #0000ff;
  text-decoration: none;
}

.scroll-nav-button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* 宽屏：按钮组跟着内容列走，外缘贴住内容列外边缘、留 8px 间隙，落在两侧空白里。
   用 left 定位（不用 translateX：显隐动画占着 transform），用 100% 而不是 100vw（fixed 元素的百分比
   不含滚动条）。内容列宽度取全站 Token --max（1160px，页头、导航页与页脚的内容宽度；主站内容页正文
   main.page 最宽 1180px、左右各 20px 内边距，文字区 1140px，同样落在 --max 之内），缺省时按 1160px。
   阈值 1500px 沿用导航页：两侧还要放下导航页的「显示描述」按钮。 */
@media (min-width: 1500px) {
  .back-to-top {
    left: calc(50% + min(var(--max, 1160px), 100% - 40px) / 2 + 8px);
    right: auto;
  }
}

@media (max-width: 640px) {
  /* 窄屏常态色 #6769ff 是站主看过真机后定的（压在 #eff6ff 上 3.83:1，仍高于 UI 组件的 3:1）；
     模拟器观感比真机淡，调这类值以真机为准。字、图标、边框都绑在同一个 color 上。
     窄屏按钮尺寸一律继承基础层，不要以「触摸目标太小」为由放大（26–32px 不违反 WCAG 2.5.8 的 24×24）。 */
  .back-to-top {
    color: #6769ff;
  }
}

/* RTL：物理左右对调，「返回顶部」组在行末一侧。 */
html[dir="rtl"] .back-to-top {
  left: 20px;
  right: auto;
}

@media (min-width: 1500px) {
  html[dir="rtl"] .back-to-top {
    right: calc(50% + min(var(--max, 1160px), 100% - 40px) / 2 + 8px);
    left: auto;
  }
}

/* 窄屏及横放后超过 640px 的触屏手机：底距与左右边距按安全区计算（iPhone 圆角与 Home Indicator）。
   --nav-floating-bottom 也供导航页的「显示描述」按钮与页脚让位使用。 */
@media (max-width: 640px),
       (max-width: 1499px) and (max-height: 500px) and (orientation: landscape) and (hover: none) and (pointer: coarse) {
  body {
    --nav-floating-bottom: max(25px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  }

  .back-to-top {
    bottom: var(--nav-floating-bottom);
  }

  html[dir="rtl"] .back-to-top {
    left: max(16px, calc(env(safe-area-inset-left, 0px) + 8px));
  }

  html:not([dir="rtl"]) .back-to-top {
    right: max(16px, calc(env(safe-area-inset-right, 0px) + 8px));
  }
}

/* 系统设置了减少动态效果时，显隐与颜色不做过渡；滚动本身由脚本改为直接跳到目标位置。 */
@media (prefers-reduced-motion: reduce) {
  .back-to-top,
  .scroll-nav-button {
    transition: none;
  }
}
