/* ==========================================================================
   BigiWorld · 顶部导航栏
   --------------------------------------------------------------------------
   - 桌面：品牌在左，链接靠右；吸顶 + 毛玻璃，滚动时一直贴在顶部
   - 窄屏：链接收进右侧汉堡菜单，纯 CSS 展开（勾选 checkbox），不需要 JS
   - 链接地址 / 文案都在 index.html 的 .navBar__menu 里改

   结构（index.html）：
     header.navBar
       a.navBar__brand       品牌，点回首页
       input.navBar__checkbox + label.navBar__toggle   汉堡开关
       nav.navBar__menu > a.navBar__link               链接
   ========================================================================== */

/* --------------------------------------------------------------------------
   页面基础
   导航栏是半透明的，总得有底色衬着。下面这段是整页的底色和字体，
   只想要导航栏的话可以整段删掉，但 body 的 margin: 0 建议留着，
   否则导航栏左右会各留 8px 白边、贴不到屏幕边。

   配色全部走变量：亮色写在这里，夜间模式在 [data-theme="dark"] 里覆盖。
   <html data-theme="dark"> 由 res/script/theme.js 切换、themeInit.js 提前定。
   -------------------------------------------------------------------------- */
:root,
[data-theme="light"] {
  color-scheme: light;

  --nav-h: 64px;          /* 导航栏高度，窄屏会覆盖 */

  /* ---- 亮色（默认） ---- */
  --ink: #0f172a;         /* 主文字色 */
  --muted: #475467;       /* 次要文字色 */
  --brand-a: #4f6bff;     /* 品牌渐变起点 */
  --brand-b: #1fc8a9;     /* 品牌渐变终点 */
  --line: rgba(15, 23, 42, 0.08);

  --page-a: rgba(79, 107, 255, 0.16);   /* 页面右上角蓝色光斑 */
  --page-b: rgba(31, 200, 169, 0.14);   /* 页面左侧青色光斑 */
  --page-base: #f7f9fc;                 /* 页面底色 */

  --nav-bg: #fff;                       /* 导航栏底色（吸顶，保持不透明） */
  --nav-menu-bg: rgba(255, 255, 255, 0.98);
  --nav-hover-bg: rgba(15, 23, 42, 0.05);

  --surface: rgba(255, 255, 255, 0.72);       /* 卡片底色 */
  --surface-soft: rgba(255, 255, 255, 0.6);   /* 卡片里的次级块 */
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.1);

}

/* ---- 夜间模式 ---- */
[data-theme="dark"] {
  color-scheme: dark;

  --ink: #e8ecf5;
  --muted: #9aa4b8;
  --line: rgba(255, 255, 255, 0.12);

  --page-a: rgba(79, 107, 255, 0.3);
  --page-b: rgba(31, 200, 169, 0.2);
  --page-base: #0b1020;

  --nav-bg: #0e1424;
  --nav-menu-bg: rgba(14, 20, 36, 0.98);
  --nav-hover-bg: rgba(255, 255, 255, 0.08);

  --surface: rgba(255, 255, 255, 0.06);
  --surface-soft: rgba(255, 255, 255, 0.05);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);

}

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

body,
.themeWipe {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 82% -8%, var(--page-a), transparent 62%),
    radial-gradient(900px 480px at -6% 8%, var(--page-b), transparent 58%),
    var(--page-base);
}

/* --------------------------------------------------------------------------
   栏体
   -------------------------------------------------------------------------- */
.navBar {
  position: sticky;
  top: 0;
  z-index: 100;

  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--nav-h);
  padding: 0 clamp(16px, 4vw, 48px);

  background: var(--nav-bg);
  border-bottom: 1px solid var(--line);

  /* 这里原本有一层 backdrop-filter，但 --nav-bg 是不透明的，模糊根本看不见，
     反而让导航栏单独成为一个合成层：换主题提交时这一层经常晚一帧重绘，
     顶部会闪一下旧颜色。去掉后观感完全一样，主题切换干净很多。 */
}

/* 品牌：渐变方块 + 站名 */
.navBar__brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 6px 6px;
  margin-left: -6px;              /* 抵消内边距，让图标和栏的左边界对齐 */
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  transition: background 0.15s ease;
}

.navBar__brand:hover {
  background: var(--nav-hover-bg);
}

.navBar__brand:focus-visible {
  outline: 3px solid var(--brand-a);
  outline-offset: 2px;
}

.navBar__name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* 链接：靠右排；当前页用渐变胶囊标出来 */
.navBar__menu {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.navBar__link {
  padding: 9px 15px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}

.navBar__link:hover {
  color: var(--brand-a);
  background: rgba(79, 107, 255, 0.09);
}

/* 当前页：不再用渐变胶囊，改成文字下面的一条线（.navBar__line）。
   文字压深一点，没脚本、量不到线的时候也能一眼看出在哪一页。 */
.navBar__link[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
}

/* --------------------------------------------------------------------------
   当前页指示线
   --------------------------------------------------------------------------
   DOM：<body> 里、header 之后 > span.navBar__line（不在导航栏里，见各页面）

   为什么放在导航栏外面：切页时这条线要单独做 View Transition 组，才能
   在“整页快照”上面继续动。如果它嵌在导航栏里，导航栏的那张快照会把它
   盖住（或者留一个洞），没法单独动画。

   它是固定定位的，left / top / width 走下面三个变量，由
   res/script/pageTransition.js 在页面显示前（pagereveal）量好写进来；
   所以即使还没量，也不会先闪在左上角——量好之前整条线是透明的。
   -------------------------------------------------------------------------- */
.navBar__line {
  position: fixed;
  left: var(--line-new-x, 0px);
  top: var(--line-y, 0px);
  width: var(--line-new-w, 0px);
  height: 2px;
  border-radius: 1px;
  background: linear-gradient(90deg, var(--brand-a), var(--brand-b));
  opacity: 0;
  pointer-events: none;
  z-index: 120;                /* 导航栏是 100，线要盖在它上面 */
  will-change: left, width;
}

/* 脚本量好位置后才显示，避免第一帧闪一下 */
html[data-line-ready] .navBar__line {
  opacity: 1;
}

.navBar__link:focus-visible {
  outline: 3px solid var(--brand-a);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   夜间模式开关
   --------------------------------------------------------------------------
   DOM：header.navBar > ... > nav.navBar__menu > 之后接 button.navBar__theme
   两个图标（月亮 / 太阳）都放在按钮里，靠 [data-theme="dark"] 决定显示哪个，
   真正切主题和写 localStorage 的是 res/script/theme.js。
   -------------------------------------------------------------------------- */
.navBar__theme {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;

  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.navBar__theme:hover {
  color: var(--brand-a);
  background: rgba(79, 107, 255, 0.09);
  border-color: rgba(79, 107, 255, 0.28);
}

.navBar__theme:focus-visible {
  outline: 3px solid var(--brand-a);
  outline-offset: 2px;
}

.navBar__themeIcon {
  display: block;
  width: 20px;
  height: 20px;
}

/* 亮色显示月亮（点了进夜间），夜间显示太阳 */
.navBar__themeIcon--sun {
  display: none;
}

[data-theme="dark"] .navBar__themeIcon--sun {
  display: block;
}

[data-theme="dark"] .navBar__themeIcon--moon {
  display: none;
}

/* --------------------------------------------------------------------------
   主题切换时的圆形扩散层
   --------------------------------------------------------------------------
   View Transitions 同一时间只能跑一个，连点会让前一个圆直接跳过。所以这里
   自己造层：每次点击把页面克隆一份，套上目标主题盖在最上面，再用 clip-path
   画圆扩散。多层可以同时存在，最后一个播完时统一提交主题并清场。
   -------------------------------------------------------------------------- */

/* 单层：铺满视口，圆以外的部分不显示 */
.themeWipe {
  position: fixed;
  inset: 0;
  z-index: 200;
  overflow: hidden;
  pointer-events: none;      /* 下层真实页面（包括开关按钮）照样能点 */
}

/* 克隆内容放在自己的滚动容器里，滚动位置由 theme.js 对齐，
   这样 position: sticky 的导航在层里也贴得住 */
.themeWipe__scroll {
  height: 100%;
  overflow: auto;
  scrollbar-width: none;
}

.themeWipe__scroll::-webkit-scrollbar {
  display: none;
}

/* --------------------------------------------------------------------------
   克隆体里关掉毛玻璃
   --------------------------------------------------------------------------
   .themeWipe 是换主题时克隆出来的整页。克隆体里的 backdrop-filter 会让
   浏览器在 clip-path 动画期间额外建一层「背景根」：页面里卡片一多（首页、
   项目页、公告页），连点时容易出现半成品帧和卡片残影，看起来就是闪屏。
   克隆体只活半秒，底色又是一整片平滑渐变，关掉模糊几乎看不出区别。
   （「关于」页没有卡片，所以之前不闪。）
   -------------------------------------------------------------------------- */
.themeWipe .card,
.themeWipe .projectCard,
.themeWipe .annItem {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* --------------------------------------------------------------------------
   汉堡按钮（桌面隐藏）
   checkbox 只负责记状态，真正被看到、被点的是紧挨着它的 label。
   -------------------------------------------------------------------------- */
.navBar__checkbox {
  display: none;                 /* 桌面没有汉堡，不留看不见的 Tab 停留点 */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;                    /* 窄屏下视觉上不出现，但仍能用键盘聚焦 */
  pointer-events: none;
}

.navBar__toggle {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 42px;
  height: 42px;
  margin-left: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.navBar__bar {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--ink);
  transition: transform 0.2s ease, opacity 0.15s ease;
}

/* 键盘聚焦到 checkbox 时，把焦点框画在 label 上 */
.navBar__checkbox:focus-visible + .navBar__toggle {
  outline: 3px solid var(--brand-a);
  outline-offset: 2px;
}

/* 展开时三条杠收成叉 */
.navBar__checkbox:checked + .navBar__toggle .navBar__bar:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.navBar__checkbox:checked + .navBar__toggle .navBar__bar:nth-child(2) {
  opacity: 0;
}

.navBar__checkbox:checked + .navBar__toggle .navBar__bar:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* --------------------------------------------------------------------------
   窄屏：链接收进从栏底滑出的面板
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  :root {
    --nav-h: 60px;
  }

  /* 窄屏的导航是竖着展开的面板，切页后菜单会收起，线没有可以滑的位置，
     所以指示线不参与切页动画，只在展开的菜单里给当前项画一小段。 */
  .navBar__line {
    display: none;
  }

  .navBar__link[aria-current="page"] {
    position: relative;
  }

  /* 线绝对定位，不参与行高，菜单项高度不会被撑开 */
  .navBar__link[aria-current="page"]::after {
    content: "";
    position: absolute;
    left: 14px;                  /* 和文字左边缘对齐（= 左右内边距） */
    bottom: 7px;
    width: 2em;                  /* 导航项都是两个字，正好垫在文字下面 */
    height: 2px;
    border-radius: 1px;
    background: linear-gradient(90deg, var(--brand-a), var(--brand-b));
  }

  /* 窄屏才把开关放出来（视觉上仍是 1px 的透明元素，靠 label 当按钮） */
  .navBar__checkbox {
    display: block;
  }

  .navBar__toggle {
    display: inline-flex;
  }

  .navBar__menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 99;

    display: none;               /* 默认收起，勾选后展开 */
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    margin: 0;
    padding: 8px clamp(12px, 4vw, 24px) 16px;

    background: var(--nav-menu-bg);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);

    max-height: calc(100vh - var(--nav-h));
    overflow-y: auto;
  }

  .navBar__checkbox:checked ~ .navBar__menu {
    display: flex;
    animation: navDrop 0.2s ease-out;
  }

  .navBar__link {
    padding: 13px 14px;
    border-radius: 10px;
    font-size: 16px;
  }

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

/* 系统开了「减少动态效果」时，不做汉堡变叉和面板滑出的过渡 */
@media (prefers-reduced-motion: reduce) {
  .navBar__brand,
  .navBar__link,
  .navBar__bar {
    transition: none;
  }

  .navBar__checkbox:checked ~ .navBar__menu {
    animation: none;
  }
}

/* --------------------------------------------------------------------------
   登录入口 / 已登录用户菜单
   --------------------------------------------------------------------------
   DOM 由 include/pageRender.py 生成，放在 .navBar__menu 的最后一个位置：
     未登录：a.navBar__auth
     已登录：details.navBar__account > summary + .navBar__accountMenu
   用原生 <details> 做下拉，不需要 JS；窄屏时菜单本来就收在汉堡面板里，
   下拉改成展开在面板内部，不再绝对定位。
   -------------------------------------------------------------------------- */
.navBar__auth {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-left: 8px;
  padding: 9px 16px;

  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(79, 107, 255, 0.24);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: filter 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.navBar__auth:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
  box-shadow: 0 9px 20px rgba(79, 107, 255, 0.32);
}

.navBar__auth:focus-visible {
  outline: 3px solid var(--brand-a);
  outline-offset: 2px;
}

.navBar__authIcon {
  width: 17px;
  height: 17px;
}

.navBar__account {
  position: relative;
  margin-left: 8px;
}

.navBar__accountSummary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 5px;

  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
  list-style: none;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.navBar__accountSummary::-webkit-details-marker {
  display: none;
}

.navBar__accountSummary:hover {
  background: var(--nav-hover-bg);
  border-color: rgba(79, 107, 255, 0.28);
}

.navBar__accountSummary:focus-visible {
  outline: 3px solid var(--brand-a);
  outline-offset: 2px;
}

.navBar__avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;

  background: linear-gradient(135deg, var(--brand-a), var(--brand-b));
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

.navBar__accountName {
  max-width: 10em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.navBar__chevron {
  width: 14px;
  height: 14px;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.navBar__account[open] .navBar__chevron {
  transform: rotate(180deg);
}

.navBar__accountMenu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 110;

  display: grid;
  gap: 2px;
  min-width: 200px;
  padding: 6px;

  background: var(--nav-menu-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.navBar__accountMeta {
  margin: 0;
  padding: 6px 12px 8px;
  color: var(--muted);
  font-size: 12px;
}

.navBar__accountItem {
  display: block;
  width: 100%;
  padding: 9px 12px;

  background: none;
  border: 0;
  border-radius: 9px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.navBar__accountItem:hover {
  background: var(--nav-hover-bg);
  color: var(--brand-a);
}

.navBar__accountItem:focus-visible {
  outline: 3px solid var(--brand-a);
  outline-offset: -2px;
}

.navBar__accountItem--danger {
  color: #c62a2f;
}

.navBar__accountItem--danger:hover {
  background: rgba(198, 42, 47, 0.1);
  color: #c62a2f;
}

[data-theme="dark"] .navBar__accountItem--danger,
[data-theme="dark"] .navBar__accountItem--danger:hover {
  color: #ff9b9b;
}

/* 换主题的整页克隆里不要毛玻璃，避免动画期间多建一层合成层 */
.themeWipe .navBar__accountMenu {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* --------------------------------------------------------------------------
   窄屏：登录入口 / 用户菜单在汉堡面板里占满一行
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .navBar__auth {
    margin: 6px 0 0;
    padding: 13px 16px;
    border-radius: 10px;
  }

  .navBar__account {
    margin: 6px 0 0;
  }

  .navBar__accountSummary {
    width: 100%;
    justify-content: flex-start;
    padding: 8px 10px;
    border-radius: 10px;
  }

  .navBar__accountMenu {
    position: static;
    min-width: 0;
    margin-top: 6px;
    background: var(--surface-soft);
    box-shadow: none;
  }

  .navBar__accountMeta {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .navBar__auth,
  .navBar__accountSummary,
  .navBar__chevron,
  .navBar__accountItem {
    transition: none;
  }

  .navBar__auth:hover {
    transform: none;
  }
}
