.site-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  padding: 14px 20px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(250, 250, 250, 0.08);
}

.logo img {
  height: 35px;
  display: block;
}

.main-nav {
  justify-self: center;
  display: flex;
  gap: 24px;
}

.main-nav a {
  color: #bebebe;
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  border-radius: 10px;
  transition: color 0.2s ease, background-color 0.2s ease;
}

.main-nav a:hover,
.main-nav a:focus-visible {
  color: #ffffff;
}

.nav-toggle {
  display: none;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #0b0d1a;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  transition: none;
}

.nav-toggle .icon {
  position: relative;
  width: 18px;
  height: 18px;
  display: block;
}

.nav-toggle .base {
  position: absolute;
  inset: 0;
  background: transparent;
  border: 4px solid #f5f5f5;
  box-sizing: border-box;
  clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
  transition: none;
}

.nav-toggle .base::after {
  content: "";
  position: absolute;
  top: -4px;
  right: 0px;
  width: 3px;
  height: 4px;
  background: #0b0d1a;
}

.nav-toggle .bar {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 24px;
  background: linear-gradient(
    to bottom,
    #ffffff 100%,
    #ffffff 38%,
    transparent 38%,
    transparent 62%,
    #ffffff 62%,
    #ffffff 100%
  );
  /* border-radius: 999px; */
  opacity: 0;
  transform-origin: center;
}

.nav-toggle .bar-1 {
  transform: translate(-50%, -50%) rotate(45deg) ;
  outline: 2px solid black;
  z-index: 2;
}

.nav-toggle .bar-2 {
  transform: translate(-50%, -50%) rotate(-45deg) ;
  z-index: 1; /* 右側斜線在上方 */
}

.site-header.is-open .nav-toggle .bar {
  opacity: 1;
  animation: barIn 400ms ease forwards;
}

.site-header.is-open .nav-toggle .base {
  animation: squareToX 420ms ease forwards;
}

.site-header:not(.is-open) .nav-toggle .base {
  animation: xToSquare 420ms ease forwards;
}

.site-header:not(.is-open) .nav-toggle .bar {
  animation: barOut 300ms ease forwards;
}

.site-header.is-open .nav-toggle .base::after {
  animation: notchToTriangle 420ms ease forwards;
}

.site-header:not(.is-open) .nav-toggle .base::after {
  animation: notchToSquare 420ms ease forwards;
}

@media (max-width: 820px) {
  .site-header {
    grid-template-columns: auto auto;
    column-gap: 12px;
    align-items: center;
  }

  .main-nav {
    position: absolute;
    top: calc(100% + 12px);
    right: 20px;
    left: auto;
    width: min(280px, calc(100% - 32px));
    flex-direction: column;
    gap: 8px;
    padding: 14px;
    background: rgba(10, 12, 22, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55), 0 0 18px rgba(250, 149, 55, 0.25);
    backdrop-filter: blur(30px);
    display: none;
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
    filter: blur(30px);
    transform-origin: top right;
  }

  .site-header.is-open .main-nav {
    display: flex;
    animation: menuEnter 260ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
  }

  .nav-toggle {
    display: inline-flex;
    justify-self: end;
  }

  .main-nav a {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
  }
}

@keyframes squareToX {
  0% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
    transform: translateY(0) scale(1);
  }
  45% {
    clip-path: polygon(50% 0%, 100% 100%, 25% 100%, 0% 82%, 0% 100%);
    transform: translateY(2px) scale(1.05);
  }
  100% {
    clip-path: polygon(50% 0%, 100% 100%, 25% 100%, 0% 82%, 0% 100%);
    transform: translateY(2px) scale(0.8);
    opacity: 0;
  }
}

@keyframes xToSquare {
  0% {
    clip-path: polygon(50% 0%, 100% 100%, 25% 100%, 0% 82%, 0% 100%);
    transform: translateY(2px) scale(0.8);
    opacity: 0;
  }
  55% {
    clip-path: polygon(50% 0%, 100% 100%, 25% 100%, 0% 82%, 0% 100%);
    transform: translateY(1px) scale(1.05);
    opacity: 1;
  }
  100% {
    clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%);
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes barIn {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(0deg) scale(0.4);
  }
  50% {
    opacity: 1;
    transform: translate(-50%, -40%) rotate(25deg) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--rot)) scale(1);
  }
}

@keyframes barOut {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(var(--rot)) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) rotate(0deg) scale(0.6);
  }
}

@keyframes notchToTriangle {
  0% {
    top: -4px;
    right: 0px;
    left: auto;
    width: 3px;
    height: 4px;
    opacity: 1;
  }
  50% {
    top: 38%;
    right: auto;
    left: -2px;
    width: 10px;
    height: 10px;
    opacity: 1;
  }
  100% {
    top: 38%;
    right: auto;
    left: -2px;
    width: 10px;
    height: 10px;
    opacity: 0.85;
  }
}

@keyframes notchToSquare {
  0% {
    top: 38%;
    right: auto;
    left: -2px;
    width: 10px;
    height: 10px;
    opacity: 0.85;
  }
  55% {
    top: 20%;
    right: auto;
    left: 2px;
    width: 9px;
    height: 9px;
    opacity: 1;
  }
  100% {
    top: -4px;
    right: 0px;
    left: auto;
    width: 3px;
    height: 4px;
    opacity: 1;
  }
}

.nav-toggle .bar-1 {
  --rot: 45deg;
}
.nav-toggle .bar-2 {
  --rot: -45deg;
}
@keyframes menuEnter {
  0% {
    opacity: 0;
    transform: translateY(-10px) scale(0.94) skewY(-2deg);
    filter: blur(10px);
  }
  70% {
    opacity: 1;
    transform: translateY(4px) scale(1.01) skewY(0deg);
    filter: blur(2px);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) skewY(0deg);
    filter: blur(0);
  }
}
