.topbar {
  position: sticky;
  top: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(var(--page-width), 100%);
  margin: 0 auto 48px;
  padding: 14px 18px;
  background: var(--surface-bg);
  border: 2px solid var(--surface-border);
  border-radius: var(--radius);
  box-shadow: var(--inner-shadow);
  backdrop-filter: blur(12px);
}

.brand,
.nav-links,
.nav-cta {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 800;
}

.nav-links {
  margin-left: auto;
  gap: clamp(14px, 2vw, 28px);
}

.nav-links a {
  position: relative;
  color: var(--muted);
  font-size: 0.86rem;
  transition: color 160ms ease;
}

.nav-links a::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -8px;
  left: 0;
  height: 1px;
  background: var(--theme);
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 160ms ease;
}

.nav-links a:hover,
.nav-links a.is-active,
.nav-links a[aria-current="true"] {
  color: var(--text);
}

.nav-links a:hover::after,
.nav-links a.is-active::after,
.nav-links a[aria-current="true"]::after {
  transform: scaleX(1);
}
.nav-cta {
  justify-content: center;
  min-height: 34px;
  margin-left: 22px;
  padding: 0 14px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 850;
  background: var(--text);
  border: 2px solid var(--text);
  box-shadow: 4px 4px 0 rgba(6, 199, 186, 0.28);
  white-space: nowrap;
}

.scroll-progress { position: fixed; top: 0; left: 0; z-index: 40; width: 100%; height: 3px; background: transparent; }
.scroll-progress span { display: block; width: 0%; height: 100%; background: linear-gradient(90deg, var(--theme), rgba(255,255,255,.58)); }

.scroll-progress span {
  box-shadow: none;
  transition: width 120ms linear;
}

.chapter-rail { position: fixed; right: clamp(12px, 2vw, 28px); top: 50%; z-index: 18; display: grid; gap: 10px; transform: translateY(-50%); }
.chapter-rail a { display: grid; grid-template-columns: 26px 1fr; gap: 8px; align-items: center; color: var(--muted); font-size: .78rem; }
.chapter-rail a.is-active { color: var(--text); }

.chapter-rail a {
  min-width: 88px;
  padding: 4px 0;
  transition: color 160ms ease, transform 160ms ease;
}

.chapter-rail a:hover,
.chapter-rail a[aria-current="true"] {
  color: var(--text);
  transform: translateX(-2px);
}

.chapter-rail a span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--muted-2);
  font-size: 0.68rem;
  font-weight: 850;
  background: var(--inner-bg);
  border: 1px solid var(--inner-border);
  border-radius: var(--radius);
}

.chapter-rail a strong {
  font-size: 0.78rem;
  font-weight: 800;
}

.chapter-rail a.is-active span,
.chapter-rail a[aria-current="true"] span {
  color: #08080a;
  background: var(--theme);
  border-color: var(--theme);
  box-shadow: var(--inner-shadow);
}

@media (max-width: 1480px) {
  .chapter-rail {
    display: none;
  }
}
