/* Shared site header (home + how-it-works, EN + ZH). Markup contract: see
   scripts/tests/website_download_entry.test.js "shared header". Fallback values
   below equal the tokens both pages define, so the header computes the same on each:
   --ink #23272e, --muted #5f6674, --line #dfe3ea, --body (how-it-works: --muted-strong) #4c5361,
   page bg (--page / --bg) #eef0f4. */
.sp-header,
.sp-header * { box-sizing: border-box; }

.sp-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(238, 240, 244, .82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line, #dfe3ea);
  font-family: 'Manrope', 'Noto Sans SC', sans-serif;
  line-height: 1.4;
}

.sp-header__row {
  max-width: 1160px;
  margin: 0 auto;
  padding: 12px 32px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.sp-header .sp-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  color: var(--ink, #23272e);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
  text-decoration: none;
}
.sp-header .sp-header__brand:hover { color: var(--ink, #23272e); }
.sp-header__brand img { display: block; border-radius: 8px; box-shadow: 0 3px 9px rgba(15, 23, 42, .16); }

.sp-header__nav {
  display: flex;
  gap: 24px;
  font-size: 15px;
  font-weight: 500;
}
.sp-header .sp-header__nav a {
  color: var(--muted, #5f6674);
  text-decoration: none;
  transition: color .18s;
}
.sp-header .sp-header__nav a:hover,
.sp-header .sp-header__nav a[aria-current="page"] { color: var(--ink, #23272e); }

.sp-header__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sp-header .sp-header__lang {
  padding: 5px 14px;
  color: var(--body, var(--muted-strong, #4c5361));
  background: rgba(75, 123, 236, .06);
  border: 1px solid rgba(28, 34, 46, .07);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background .18s, color .18s;
}
.sp-header .sp-header__lang:hover { background: rgba(75, 123, 236, .12); color: var(--ink, #23272e); }

.sp-header .sp-header__download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 14px;
  color: #fff;
  background: linear-gradient(180deg, #5b87f0, #3a68dd);
  box-shadow: 0 4px 12px rgba(59, 104, 221, .28), inset 0 1px 0 rgba(255, 255, 255, .45);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background .18s;
}
.sp-header .sp-header__download:hover { color: #fff; background: linear-gradient(180deg, #6b95f3, #4a78e6); }

.sp-header .sp-header__menu {
  display: none;
  width: 40px;
  height: 34px;
  padding: 0;
  align-items: center;
  justify-content: center;
  color: var(--ink, #23272e);
  background: transparent;
  border: 1px solid var(--line, #dfe3ea);
  border-radius: 8px;
  cursor: pointer;
}
.sp-header__menu span,
.sp-header__menu span::before,
.sp-header__menu span::after {
  display: block;
  width: 16px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transition: transform .18s, background .18s;
}
.sp-header__menu span { position: relative; }
.sp-header__menu span::before,
.sp-header__menu span::after { position: absolute; left: 0; }
.sp-header__menu span::before { transform: translateY(-5px); }
.sp-header__menu span::after { transform: translateY(5px); }
.sp-header-open .sp-header__menu span { background: transparent; }
.sp-header-open .sp-header__menu span::before { transform: rotate(45deg); }
.sp-header-open .sp-header__menu span::after { transform: rotate(-45deg); }

.sp-header a:focus-visible,
.sp-header button:focus-visible { outline: 2px solid #5b87f0; outline-offset: 3px; }

.sp-header__progress {
  height: 2px;
  background: linear-gradient(90deg, #8fb3ff, #3a68dd);
  transform-origin: 0 50%;
  animation: spPageProgress linear both;
  animation-timeline: scroll(root);
}
@keyframes spPageProgress { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .sp-header__progress { animation: none; transform: scaleX(1); }
  .sp-header * { transition: none !important; }
}

/* No-JS fallback (html never gets .sp-js): nav wraps onto a second row, no menu button. */
@media (max-width: 820px) {
  .sp-header__row { flex-wrap: wrap; row-gap: 12px; padding: 10px 16px; gap: 12px; }
  .sp-header__nav { order: 2; flex: 1 0 100%; min-width: 0; flex-wrap: wrap; gap: 12px 18px; }

  /* Enhanced (script sets .sp-js on <html>): one row = brand, language, menu button. */
  .sp-js .sp-header__row { flex-wrap: nowrap; }
  .sp-js .sp-header__menu { display: inline-flex; }
  .sp-js .sp-header__nav,
  .sp-js .sp-header__download { display: none; }

  /* Open (script sets .sp-header-open on <html>): the header grows in flow:
     row 1 brand / language / menu, then the three links, then the download button. */
  .sp-js.sp-header-open .sp-header__row { flex-wrap: wrap; row-gap: 4px; }
  .sp-js.sp-header-open .sp-header__actions { display: contents; }
  .sp-js.sp-header-open .sp-header__lang { order: 1; margin-left: auto; }
  .sp-js.sp-header-open .sp-header__menu { order: 2; }
  .sp-js.sp-header-open .sp-header__nav {
    display: flex;
    flex-direction: column;
    flex: 1 0 100%;
    gap: 0;
    order: 3;
  }
  .sp-js.sp-header-open .sp-header__nav a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 8px;
    border-radius: 10px;
  }
  .sp-js.sp-header-open .sp-header__nav a:hover,
  .sp-js.sp-header-open .sp-header__nav a[aria-current="page"] { background: rgba(75, 123, 236, .08); }
  .sp-js.sp-header-open .sp-header__download {
    display: flex;
    order: 4;
    flex: 1 0 100%;
    min-height: 44px;
    margin: 4px 0 4px;
  }
}

@media (max-width: 460px) {
  .sp-header__row { padding-left: 12px; padding-right: 12px; }
}
