/* Shared navigation for the academic homepage, archive, and reading pages. */
/* Colors and type come from site-theme.css. */
:root {
  --site-header-height: 64px;
  --site-header-offset: var(--site-header-height);
  --site-header-motion: 280ms cubic-bezier(.22, 1, .36, 1);
}

html { scroll-padding-top: calc(var(--site-header-offset) + 20px); }
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  flex: none;
  width: 100%;
  background: transparent;
  color: var(--site-ink);
  font-family: var(--site-font);
  -webkit-font-smoothing: antialiased;
  /* Only the visible controls intercept clicks over the reading area. */
  pointer-events: none;
}
.site-header:not(.has-scroll-effect) {
  background: #fafafa;
  box-shadow: 0 1px var(--site-line);
}
.site-header, .site-header * { box-sizing: border-box; }
.site-header-inner {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  grid-template-areas: "name nav tools";
  align-items: center;
  column-gap: 20px;
  width: min(var(--site-width), calc(100% - 80px));
  height: var(--site-header-height);
  margin-inline: auto;
}
/* A separate surface contracts without scaling the text or moving the document. */
.site-header-inner::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 8px 0;
  width: var(--header-compact-width, 100%);
  margin-inline: auto;
  border: 1px solid var(--site-line);
  border-radius: 999px;
  background: #fafafaf5;
  box-shadow: 0 2px 6px #25262b05, 0 8px 24px #25262b08;
  opacity: 0;
  transform: scaleX(var(--header-surface-scale, 1));
  transition: transform var(--site-header-motion), opacity var(--site-header-motion);
  pointer-events: none;
}
.site-header.is-compact .site-header-inner::before { opacity: 1; transform: scaleX(1); }
.site-header.is-compact .site-name { transform: translateX(var(--header-shift, 0px)); }
.site-header.is-compact .site-tools { transform: translateX(calc(-1 * var(--header-shift, 0px))); }
.site-name, .site-nav, .site-tools { pointer-events: auto; }
.site-tools { transition: transform var(--site-header-motion); }
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .site-header-inner::before {
    background: #fafafae6;
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
  }
}
.site-header a { border: 0; color: inherit; text-decoration: none; }
.site-name {
  grid-area: name;
  justify-self: start;
  padding: 6px 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.4;
  white-space: nowrap;
  transition: transform var(--site-header-motion), color .2s ease;
}
.site-name:hover { color: var(--site-accent); }
.site-nav { grid-area: nav; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  color: var(--site-muted);
  font-size: 13.5px;
  font-weight: 520;
  line-height: 1;
  transition: color .2s ease, background .2s ease;
}
.site-nav a:hover { color: var(--site-ink); background: var(--site-accent-soft); }
.site-nav a.is-active { color: var(--site-accent); background: var(--site-accent-soft); font-weight: 600; }
.site-tools { grid-area: tools; justify-self: end; display: flex; align-items: center; }

/* One button switches language; the filled half shows the language in use. */
.site-language {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 34px;
  padding: 3px;
  border: 1px solid var(--site-line-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--site-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: border-color .2s ease;
}
.site-language[hidden] { display: none; }
.site-language span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 100%;
  padding: 0 8px;
  border-radius: 999px;
  transition: color .2s ease, background .2s ease;
}
.site-language:hover { border-color: var(--site-accent); }
html:not([lang^="zh"]) .site-language [data-language="en"],
html[lang^="zh"] .site-language [data-language="zh"] { color: var(--site-accent); background: var(--site-accent-soft); }
.site-header a:focus-visible, .site-language:focus-visible { outline: 2px solid var(--site-accent); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 60; left: 20px; top: -100px; padding: 12px 18px; background: #fff; }
.skip-link:focus { top: 12px; }

@media (max-width: 900px) {
  .site-nav a { padding-inline: 11px; }
}
@media (max-width: 840px) {
  .site-header-inner { width: min(720px, calc(100% - 48px)); }
}
/* Keep every link on phones: two rows gather into one rounded, floating surface. */
@media (max-width: 760px) {
  :root { --site-header-height: 97px; }
  .site-header-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 54px 42px;
    grid-template-areas: "name tools" "nav nav";
    column-gap: 12px;
  }
  .site-header-inner::before {
    inset: 4px -12px 0;
    border-radius: 24px;
  }
  .site-nav {
    align-self: start;
    gap: 2px;
    margin-inline: -10px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 14px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 14px), transparent);
  }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a { flex: none; min-height: 34px; padding-inline: 10px; font-size: 13px; }
}
@media (max-width: 480px) {
  .site-header-inner { width: calc(100% - 40px); }
}
@media (prefers-reduced-motion: reduce) {
  .site-header-inner::before, .site-name, .site-tools,
  .site-nav a, .site-language, .site-language span { transition: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .site-header-inner::before {
    background: #fafafa;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
@media print {
  html { scroll-padding-top: 0; }
  .site-header { display: none; }
}
