/* ==========================================================================
   航海梦页头（注入到巴哈镜像静态站的样式）
   --------------------------------------------------------------------------
   用途：由 nginx etc/vhost/static.hanghaimeng.com.conf 里的 sub_filter 往
   /src/ 下的每个 .html 页的 </head> 前注入 <link rel="stylesheet" href="/__hm/header.css?v=1">，
   再在 </body> 前注入 header.js 渲染页头 DOM。设计值照抄 hanghaimeng-rails
   app/assets/stylesheets/pages.css「3. 导航」一节（不依赖 Bootstrap）。

   隔离：镜像站旧 CSS 对 div / a / input / p / ul / li 有全局 reset，会串到我们的
   页头上；所以本文件所有规则都在 .hm- 前缀（根容器 .hm-header）作用域内，
   不出现裸元素选择器（例外只有 .hm-brand__mark svg，已被 .hm-brand__mark 限定，
   不会外溢；以及文件开头唯一一条故意的全局规则 html { scroll-padding-top }）。
   同时下面显式重置 box-sizing / font-family / line-height / margin / padding，
   抵消镜像站 reset 的影响。

   镜像站还有全局 a { color:#464646; text-decoration:none } 与
   a:hover { color:#0055aa; text-decoration:underline }（见
   css/98a472329051695a75bed80d694b3a3a.css，优先级 0,1,1），压过我们单 class 的
   .hm-nav__link（0,1,0），悬停时导航链接会被加下划线。所以用
   .hm-header a:hover / .hm-header a:focus（0,2,1）压回 text-decoration；
   颜色由 .hm-nav__link:hover（0,2,1）与 .hm-brand:hover（0,2,0）决定，都高于
   镜像的 a:hover（0,1,1）。本文件注入在 </head> 之前、排在镜像站所有 CSS 后面，
   万一出现等优先级，也按来源顺序由我们胜出。

   字号单位：镜像页旧 CSS 里 :root { font-size: 15px }，若用 rem，页头文字会比
   www 站（根字号 16px）小一圈。所以本文件一律写 px 固定值（按 16px 基准换算：
   .9rem→14.4px、1.05rem→16.8px、.62rem→9.92px、.875rem→14px、.82rem→13.12px
   等），与 www 站实际渲染像素一致。

   可调项：
   - 页头内容宽度：改 --hm-max-width（默认 1250px，与镜像页 #BH-wrapper 的
     1250px 对齐）；也可在页面里 `:root { --hm-max-width: 1000px; }` 覆盖。
   - 是否吸顶：注释掉 .hm-header 里的 `position: sticky; top: 0;` 即变普通页头，
     此时开头那条 `html { scroll-padding-top: 78px; }` 一起删掉。
   - 缓存版本：改文件名上的 ?v= 参数（见 vhost 里的 sub_filter），别改这里。

   注意：镜像页 viewport 写死 width=1250，所以不做窄屏汉堡菜单/折叠逻辑；
   只在 ~1000px 宽度下靠 flex-wrap + 搜索框收缩保证不破版。
   ========================================================================== */

/* --- 给吸顶页头让位（全局规则，故意写在 .hm- 作用域之外） ---
   镜像正文里的目录锚点（<a name="guide">、#WIKIINDEX 里的 TOC 链接）跳转时，
   目标会被 70px 高的吸顶页头盖住，所以滚动定位预留 78px（页头 70 + 8 呼吸）。
   关掉吸顶（见上面可调项）时这行一起删。 */
html {
  scroll-padding-top: 78px;
}

/* --- 作用域内重置（对抗镜像站的全局 reset） --- */
.hm-header,
.hm-header *,
.hm-header *::before,
.hm-header *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Arial, sans-serif;
  line-height: 1.5;
}

/* --- 压住镜像站全局 a:hover / a:focus（下划线 + 变蓝） ---
   只处理 text-decoration；颜色交给下面的 .hm-* 规则（见文件头注释的优先级核对）。 */
.hm-header a:hover,
.hm-header a:focus {
  text-decoration: none;
}

/* --- 键盘焦点可见（与 www 站基础样式同值） ---
   写在导航/搜索规则之后，作为页头内所有可聚焦元素的统一焦点环；
   .hm-nav__link:focus-visible 只保留 color，不再改 outline-offset，避免与这条冲突。 */
.hm-header :focus-visible {
  outline: 3px solid rgba(217, 178, 95, .55);
  outline-offset: 2px;
}

/* --- 外层：吸顶 + 深蓝三段渐变 + 黄铜细边 --- */
.hm-header {
  position: sticky;
  top: 0;
  z-index: 1030;
  width: 100%;
  background-image: linear-gradient(135deg, #081528 0%, #0b1d36 55%, #103153 100%);
  border-bottom: 1px solid rgba(217, 178, 95, .16);
  box-shadow: 0 12px 30px rgba(6, 15, 28, .22);
  padding-block: 10px;
  color: #fff;
  text-align: left;
}

/* --- 内层：1250px 居中，与镜像页 #BH-wrapper 对齐 ---
   padding-inline 必须为 0：实测内层 x=15 与 #BH-wrapper 的 x=15 对齐，
   再加内边距会让品牌块比正文右移。
   整条页头高度 = 10 + 49 + 10 + 1(下边框) = 70px，与 www 站一致。 */
.hm-header__inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 20px;
  min-height: 49px;
  max-width: var(--hm-max-width, 1250px);
  margin: 0 auto;
  padding-inline: 0;
}

/* --- 品牌块 --- */
.hm-brand {
  display: flex;
  align-items: center;
  gap: 10.4px;
  flex: none;
  margin-right: 5.6px;
  color: #fff;
  text-decoration: none;
  min-width: 0;
}

.hm-brand__mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(217, 178, 95, .38);
  border-radius: 12px;
  background-image: linear-gradient(150deg, #0f2a49 0%, #081528 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .08),
    0 6px 16px rgba(6, 15, 28, .35);
  color: #e6c985;
}

.hm-brand__mark svg {
  display: block;
  width: 22px;
  height: 22px;
}

.hm-brand__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hm-brand__name {
  font-size: 16.8px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: .12em;
  color: #fff;
  white-space: nowrap;
}

.hm-brand__sub {
  margin-top: 2px;
  font-size: 9.92px;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: .2em;
  color: rgba(255, 255, 255, .48);
  white-space: nowrap;
}

/* 品牌块悬停：文字保持白色（镜像站 a:hover 会把链接染成 #0055aa），只有徽标提亮 */
.hm-brand:hover {
  color: #fff;
}

.hm-brand:hover .hm-brand__mark {
  border-color: rgba(217, 178, 95, .6);
  color: #d9b25f;
}

/* --- 导航链接 --- */
.hm-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
}

.hm-nav__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 8.8px 14.4px;
  border-radius: 10px;
  color: rgba(255, 255, 255, .72);
  font-size: 14.4px;
  text-decoration: none;
  white-space: nowrap;
  transition: color .18s ease, background-color .18s ease;
}

.hm-nav__link:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, .06);
}

/* 焦点环交给上面的 .hm-header :focus-visible，这里只保证文字提亮 */
.hm-nav__link:focus-visible {
  color: #fff;
}

.hm-nav__link.is-active {
  color: #fff;
}

/* 当前页：底部居中一条 18×2 的黄铜短线 */
.hm-nav__link.is-active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 4px;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  translate: -50% 0;
  background-color: #d9b25f;
}

/* --- 搜索胶囊（margin-left:auto 推到最右） --- */
.hm-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(340px, 100%);
  flex: 0 1 auto;
  margin-left: auto;
  padding: 4.48px 4.8px 4.48px 14.4px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
  background-color: rgba(255, 255, 255, .07);
  transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}

.hm-search:focus-within {
  border-color: rgba(217, 178, 95, .65);
  background-color: rgba(255, 255, 255, .1);
  box-shadow: 0 0 0 4px rgba(217, 178, 95, .12);
}

.hm-search__icon {
  flex: none;
  width: 17px;
  height: 17px;
  color: rgba(255, 255, 255, .5);
}

.hm-search__input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 5.6px 0;
  border: 0;
  background-color: transparent;
  background-image: none;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  appearance: none;
  -webkit-appearance: none;
}

.hm-search__input::placeholder {
  color: rgba(255, 255, 255, .45);
  opacity: 1;
}

.hm-search__input::-webkit-search-cancel-button,
.hm-search__input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.hm-search__submit {
  flex: none;
  padding: 8px 15.2px;
  border: 0;
  border-radius: 999px;
  background-image: linear-gradient(135deg, #e6c985, #d9b25f);
  background-color: #d9b25f;
  color: #081528;
  font-family: inherit;
  font-size: 13.12px;
  font-weight: 600;
  letter-spacing: .04em;
  cursor: pointer;
  transition: filter .18s ease, box-shadow .18s ease, transform .18s ease;
}

.hm-search__submit:hover {
  filter: brightness(1.06);
  box-shadow: 0 6px 16px rgba(217, 178, 95, .28);
}

.hm-search__submit:active {
  transform: translateY(1px);
  filter: brightness(.98);
}

/* --- 读屏可见、视觉隐藏 --- */
.hm-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  padding: 0;
  margin: -1px;
}
