:root {
  --nav-radius: 30px;
  --floating-side-gap: 30px;
}

:root {
  --nav-glass-bg: rgba(255, 255, 255, 0.8);
  --nav-glass-border: 2px solid rgba(255, 255, 255, 1);
  --nav-shadow: rgba(220, 220, 220, 0.2) 0px 0px 8px 0px inset, rgba(220, 220, 220, 0.82) 0px 0px 10px 0px;
  --nav-link-color: #444444; /* it is different from --link-color */
  --nav-link-border-bottom: 1px solid #eaeaea;
  --nav-hover-color: #007bff;
  --nav-filter: blur(1px) saturate(3.6)
}
@media (prefers-color-scheme: dark) {
  :root {
    --nav-glass-bg: rgba(62, 62, 62, 0.4);
    --nav-glass-border: 2px solid rgba(68, 68, 68, 0.6);
    --nav-shadow: none;
    --nav-link-color: #bbbbbb;
    --nav-link-border-bottom: 1px solid rgba(68, 68, 68, 0.6);
    --nav-hover-color: #4dabff;
    --nav-filter: blur(1px) saturate(0.8) brightness(1.0)
  }
}

nav {
  position: fixed;
  width: 100%;
  height: var(--nav-height);
  z-index: 1000;

  display: flex;
  top: 0;
  left: 0;
  right: 0;
}
nav::before {
  content: "";
  position: absolute;
  inset: 0; /* 撑满父容器 */
  z-index: -1; /* 躲在文字下面 */

  backdrop-filter: var(--nav-filter);
  background-color: var(--nav-glass-bg);
  border: var(--nav-glass-border);
  box-shadow: var(--nav-shadow);
  backface-visibility: hidden;
}
@media screen and (max-width: 768px) {
  nav {
    width: calc(100% - 2 * var(--floating-side-gap));
    height: auto;
    left: auto;
    right: var(--floating-side-gap);
    top: auto;
    bottom: var(--floating-bottom-gap);
    justify-items: right;

    transform: translateZ(0); 
    will-change: width; /* 提前告诉浏览器宽度会变 */
    transition: var(--width-transform);
  }
  nav::before {
    border-radius: var(--nav-radius);
    backface-visibility: hidden;
  }

  #nav-logo, 
  .nav-home-wrapper {
    display: flex;
    align-items: center;
    overflow: hidden; /* 极其重要：防止收缩时文字折行 */
    white-space: nowrap; /* 强制不换行 */
    will-change: width, opacity;
    transition: var(--appear-or-dis), var(--width-transform);
  }

  /* 下滑收缩nav */
  #menu-toggle:not(:checked) ~ nav.nav-compact {
    width: var(--nav-height); /* 变成正方形 */
    will-change: width;
    transform: translateZ(0);
    transition: var(--width-transform);
  }
  #menu-toggle:not(:checked) ~ .nav-compact :is(#nav-logo, .nav-home-wrapper) {
    opacity: 0;
    width: 0;
    margin: 0;
    pointer-events: none;
    will-change: width;
    transform: translateX(10px);
  }
}

#nav-content {
  width: 100%;
  max-width: var(--max-width);
  padding: 0 var(--padding-width);
  margin: 0 auto;

  display: flex;
  justify-content: flex-end;
  align-items: center;
}
@media screen and (max-width: 768px) {
  #nav-content {
    padding: 0px;
  }
}

#nav-logo {
  margin-left: 0px;
  font-size: 1.2rem;
  color: var(--text-color);
}

/* 4. 右侧组合区域 */
#nav-right {
  display: flex;
  flex-wrap: nowrap;
  margin-left: auto;
  gap: 25px;
  /* Home 与 菜单第一项 的间距 */
}
@media screen and (max-width: 768px) {
  #nav-logo {
    margin-left: 20px;
  }
  #nav-right {
    gap: 0px;
  }
}

/* 返回Home */
.nav-home-wrapper {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
}
.menu-toggle-label {display: none;}
@media screen and (max-width: 768px) {
  .menu-toggle-label {
    /* 固定尺寸，不允许被内容撑开 */
    width: var(--nav-height); 
    height: var(--nav-height);
    cursor: pointer;
    
    position: relative; 
    display: flex;
    align-items: center;
    justify-content: center;

    -webkit-tap-highlight-color: transparent;
  }

  /* 汉堡图标三条杠 */
  #menu-icon {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    width: 24px;
  }
  #menu-icon .line {
    width: 100%;
    height: 2px;
    background-color: var(--text-color);
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.2);
  }
  #menu-icon .bottom-lines {
    position: relative;
    width: 24px;
    height: 2px;
  }
  #menu-icon .bottom-lines .line {
    position: absolute; /* 绝对定位，它们会默认重叠在左上角 */
    top: 0; left: 0;
  }
  
  #menu-toggle:checked ~ nav {
    & #menu-icon {
      & > :nth-child(1) { transform: translate(0px, 5px) scaleX(0); }
      & > :nth-child(2) { transform: scaleX(0); }
    }
    & #bottom-l-line {
      transform: rotate(-45deg) translate(0px, -5px) scaleX(0.5);
    }
    & #bottom-r-line {
      transform: rotate( 45deg) translate(0px, -5px) scaleX(0.5);
    }
  }
}

/* 菜单内部容器 */
.nav-menu {
  display: flex;
  flex-direction: row;
  gap: 25px;
  /* 这里是 菜单内部各项目 的间距 */
  margin: 0;
  padding: 0;
}
@media screen and (max-width: 768px) {
  /* 上拉菜单 */
  .nav-menu {
    /* 初始隐藏 */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(15px);
    transition:
      var(--appear-or-dis),
      transform 0.2s ease,
      visibility 0.2s;

    flex-direction: column;
    gap: 0;

    position: absolute;
    top: auto;
    bottom: var(--nav-height-space);
    left: auto;
    right: 0;
    width: auto;
  }
  .nav-menu::before {
    content: "";
    position: absolute;
    inset: 0; /* 撑满父容器 */
    z-index: -1; /* 躲在文字下面 */
  
    backdrop-filter: var(--nav-filter);
    background-color: var(--nav-glass-bg);
    border: var(--nav-glass-border);
    box-shadow: var(--nav-shadow);
    backface-visibility: hidden;

    border-radius: 8px
  }

  /* 展开 */
  #menu-toggle:checked ~ nav .nav-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    transition:
      var(--appear-or-dis),
      transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* 增加一点点回弹效果 */
  }
  
  #menu-overlay {
    /* background-color: rgba(255, 0, 0); */
    z-index: 999;
  }
}

/* 基础状态链接颜色 */
.nav-link {
  color: var(--nav-link-color);
  border-bottom: var(--nav-link-border-bottom);
  -webkit-tap-highlight-color: transparent;
}

/* 当用户鼠标悬停时，显示高亮色 */
.nav-link:hover {
  color: var(--nav-hover-color);
}

/* 增强： active 项加粗，显示高亮色，视觉引导更强 */
.nav-link.is-active {
  color: var(--nav-hover-color);
  font-weight: bolder;
}
.nav-link::after {
  display: block;
  content: "Research"; /* 读取 HTML 里的 data-text 内容 */
  font-weight: bolder;        /* 强行让它变成粗体 */
  
  height: 0;                /* 高度设为 0，不影响垂直布局 */
  visibility: hidden;       /* 隐形，看不见它 */
  overflow: hidden;         /* 彻底隐藏溢出 */
}

@media screen and (max-width: 768px) {
  .nav-link {
    text-align: left;
    padding: 12px 10px;
  }

  .nav-menu .nav-link:last-child {
    border-bottom: 0px;
  }
}