/* Shared site header — the single source of truth.
 *
 * It lives in `public/`, so Astro keeps its name and it stays at `/site-header.css`. Both the
 * website and the explorer (Go, separate repository and build) link it — two copies would
 * drift apart after the first change.
 *
 * Only what is identical on every page belongs here: the navigation bar, the theme switch
 * and the tab strip under the hero.
 *
 * Colour tokens do not belong here — each page defines them (global.css on the website,
 * style.css in the explorer), so the header follows their theme.
 */

/* The header must not inherit anything from the page. When it inherited margins and line
 * height, the logo and navigation sat a few pixels apart on different pages and jumped when
 * navigating. Everything that decides position is fixed here. */
.site-header {
  --site-gutter: clamp(1.25rem, 5vw, 5rem);
  border-bottom: 1px solid var(--rule-strong);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Long pages have a scrollbar and short ones don't, which shifts centred content by its
 * width. `stable` always reserves the space. */
html { scrollbar-gutter: stable; }

/* The page keeps its proportions on every screen size.
 *
 * All sizes on the website and in the explorer are in rem — page width, type, icons, spacing
 * and this header. As rem grows with the window, the whole page scales in one ratio, as if
 * the Full HD layout were zoomed in. The reference is a Full HD browser window: 1920 px wide
 * and ~940 px tall (without toolbars), where rem = 16 px.
 *
 * - min(width, height): on ultrawide screens (3440×1440) width alone would blow the page past
 *   the screen edge — the smaller dimension decides.
 * - max(100 %, …): it never shrinks below Full HD, where type would get too small; the layout
 *   adapts with clamp() in vw/vh instead. 100 % rather than 16px keeps the font size the
 *   visitor set in the browser.
 *
 * It is here, in the shared file, not in the website's global.css — if only the website scaled,
 * the header would jump when moving to the explorer on a large screen. */
html { font-size: max(100%, min(100vw / 120, 100vh / 59)); }
.site-header-in {
  max-width: 78rem;
  margin: 0 auto;
  padding-inline: var(--site-gutter);
  padding-block: 1.1rem;
  /* Three columns: brand | navigation | theme. The outer ones are equal 1fr, so the navigation
   * is always exactly centred and grows symmetrically when an item is added.
   * minmax(max-content, …) keeps the brand and the switch from being squeezed. */
  display: grid;
  grid-template-columns: minmax(max-content, 1fr) auto minmax(max-content, 1fr);
  align-items: center;
  gap: 0.75rem 2rem;
}
.site-brand { justify-self: start; }
.site-theme { justify-self: end; }

.site-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--ink);
}
.site-brand-mark { display: block; width: 1.65rem; flex: none; }
.site-brand-mark svg { display: block; width: 100%; height: auto; fill: currentColor; }
.site-brand-name {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.35rem 1.75rem;
  font-size: 0.9375rem;
}
.site-nav a { color: var(--ink-2); text-decoration: none; }
.site-nav a:hover { color: var(--ink); }
/* The active item must not turn bold — bold text is wider and the other items would shift.
 * Underline and colour don't change the width. */
.site-nav a[aria-current="page"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.45em;
}

/* An item that doesn't exist yet: visible, but not clickable — a link to a 404 is worse than
 * no link. */
.site-nav .soon {
  color: var(--ink-3);
  cursor: default;
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
}
.site-nav .soon i {
  font-style: normal;
  font-family: var(--mono);
  font-size: 0.625rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid var(--rule);
  padding: 0.05rem 0.3rem;
}

/* Theme switch. The active option is the theme the page is using — data-theme when set,
 * otherwise the system setting. */
.site-theme { display: flex; border: 1px solid var(--rule); flex: none; }
.site-theme > * {
  text-decoration: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  color: var(--ink-3);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.site-theme > * + * { border-left: 1px solid var(--rule); }
.site-theme > *:hover { color: var(--ink); }
/* Icon size in rem, not from width="17" — otherwise icons wouldn't scale on large screens. */
.site-theme svg { width: 1.0625rem; height: 1.0625rem; }
:root[data-theme="light"] .site-theme .t-light,
:root[data-theme="dark"] .site-theme .t-dark {
  background: var(--ink);
  color: var(--paper);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .site-theme .t-dark { background: var(--ink); color: var(--paper); }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .site-theme .t-light { background: var(--ink); color: var(--paper); }
}

/* Tab strip under the hero — the second level of navigation: the header says which part of
 * the site you are in, the tabs say where within it. */
.site-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.75rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2rem;
  font-size: 0.9375rem;
}
.site-tabs a {
  color: var(--ink-3);
  text-decoration: none;
  padding: 0.6rem 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.site-tabs a:hover { color: var(--ink); }
.site-tabs a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--rule-strong);
}

/* When brand, navigation and switch don't fit on one line, the navigation moves to a second
 * line, still centred. The breakpoint is the width they need on one line (~1080 px with six
 * items) plus a margin; move it when adding an item, or the navigation wraps inside the
 * middle column. */
@media (max-width: 70rem) {
  .site-header-in { grid-template-columns: 1fr auto; gap: 0.6rem 1rem; padding-block: 0.9rem; }
  .site-nav { grid-column: 1 / -1; grid-row: 2; gap: 0.35rem 1.25rem; }
}
@media (max-width: 40rem) {
  .site-nav { font-size: 0.875rem; }
  .site-tabs { gap: 0 1.25rem; font-size: 0.875rem; }
}
