:root {
  --nav-height: 3rem;
  --nav-bg: rgb(255 255 255 / 88%);
  --nav-border: #e5e5e5;
  --nav-text: #043361;
  --nav-hover-bg: #e8eef5;
}

@media (prefers-color-scheme: dark) {
  :root {
    --nav-bg: rgb(32 33 43 / 88%);
    --nav-border: #33343f;
    --nav-text: rgb(62, 183, 240);
    --nav-hover-bg: #2c2e3b;
  }
}

.topnav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  height: var(--nav-height);
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(160%) blur(8px);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--nav-border);
}

.topnav-inner {
  max-width: 960px;
  height: 100%;
  margin: 0 auto;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.topnav-name {
  color: var(--nav-text) !important;
  font-weight: 600;
  white-space: nowrap;
  /* The sidebar already shows the name on wide screens */
  visibility: hidden;
}

.topnav-links {
  display: flex;
  gap: 0.15rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav-links::-webkit-scrollbar {
  display: none;
}

.topnav-links a {
  color: var(--nav-text) !important;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 0.95rem;
  transition: background-color .15s ease;
}

.topnav-links a:hover,
.topnav-links a:focus-visible,
.topnav-links a.active {
  background: var(--nav-hover-bg);
  text-decoration: none;
}

/* Keep content and anchor targets clear of the fixed bar */
body.has-nav header,
body.has-nav section {
  margin-top: var(--nav-height);
}

html {
  scroll-padding-top: calc(var(--nav-height) + 0.75rem);
}

@media (max-width: 960px) {
  .topnav-name {
    visibility: visible;
  }

  body.has-nav header {
    margin-top: calc(var(--nav-height) + 0.5rem);
  }

  body.has-nav section {
    margin-top: 0;
  }
}

@media (max-width: 600px) {
  .topnav-name {
    display: none;
  }

  .topnav-inner {
    justify-content: center;
    padding: 0;
  }

  .topnav-links {
    gap: 0;
  }

  .topnav-links a {
    padding: 0.3rem 0.4rem;
    font-size: 0.88rem;
  }
}
