/* Site header and primary nav, one copy for every page. index.html and doc.css
   no longer carry header rules. Reads the color tokens from the page's :root and
   --display from fonts.css. Behavior (click, tap, Escape, outside click) is nav.js;
   hover opening is CSS only, and only for fine pointers. Breakpoint: 820px. */

/* Solid bone, no blur: content never shows through it, and nothing re-renders
   over the flood every scroll frame. */
header { position: sticky; top: 0; z-index: 60; background: var(--bone);
  border-bottom: 1px solid transparent; transition: border-color .35s ease; }
header.scrolled { border-bottom-color: var(--line); }
/* At the very top nothing sits under the bar yet, so it lets the page tint show
   through instead of ending in a hard bone edge. Every page's script sets
   .scrolled past 8px, which brings the solid bone back before content slides under. */
/* Solid again while the phone menu is open, so the bar and its panel read as one sheet. */
html.js header:not(.scrolled):not(.on-cobalt):not(:has(.nav-menu[aria-expanded=true])) { background: transparent; }

.nav { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.brand { position: relative; display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand .tile { width: 28px; height: 28px; display: block; flex: none; }
.brand .name { font-weight: 700; letter-spacing: -0.01em; font-size: 15.5px; white-space: nowrap; }
/* Narrow phones: the icon carries the brand (the link keeps its aria-label). */
@media (max-width: 440px) { .brand .name { display: none; } }

.nav-links { display: flex; align-items: center; gap: 26px; }
.nav-links > .btn { position: relative; white-space: nowrap; color: var(--bone); }
.nav-list, .nav-drop-menu { list-style: none; margin: 0; padding: 0; }
.nav-list { display: flex; align-items: center; gap: 26px; }
.nav-list > li { position: relative; }

/* Top-level items. The Legal button is styled as a link so the row reads as one. */
.nav-list > li > a, .nav-drop-toggle {
  position: relative; display: flex; align-items: center; gap: 6px;
  font: inherit; font-size: 15px; font-weight: 500; color: var(--muted); text-decoration: none;
  background: none; border: 0; padding: 0; cursor: pointer; }
.nav-list > li > a:hover, .nav-drop-toggle:hover { color: var(--ink); }
.nav-list > li > a[aria-current=page], .nav-drop:has([aria-current=page]) > .nav-drop-toggle { color: var(--ink); }
.nav-drop-toggle svg { flex: none; transition: transform .2s ease; }

/* 44px tap targets without growing the 64px header (E12, E22). */
.brand::after, .nav-links > .btn::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 44px; transform: translateY(-50%); }
.nav-list > li > a::after, .nav-drop-toggle::after { content: ""; position: absolute; left: -8px; right: -8px; top: 50%; height: 44px; transform: translateY(-50%); }
/* The brand link is 44px wide too, so the icon-only home link on narrow phones is 44x44. */
.brand::after { left: -8px; right: -8px; }

/* Label swap, ported from the portfolio nav: the Satoshi label rolls up and out,
   the same word in Instrument Serif rolls in from below. One custom
   property drives both halves, so each trigger below only sets --swap: 1. */
.nav-swap { position: relative; display: block; height: 1.4em; line-height: 1.4;
  overflow: hidden; overflow: visible clip; } /* clip rows only: italic tails may run a hair wide */
.nav-label, .nav-label-alt { display: block; white-space: nowrap;
  transition: transform .22s cubic-bezier(.23, 1, .32, 1), opacity .18s ease; }
.nav-label { transform: translateY(calc(var(--swap, 0) * -100%)); opacity: calc(1 - var(--swap, 0)); }
.nav-label-alt { position: absolute; left: 0; top: 0;
  font-family: var(--display); font-weight: 400; font-size: 1.2em; line-height: calc(1.4 / 1.2);
  color: var(--cobalt); transform: translateY(calc((1 - var(--swap, 0)) * 100%)); opacity: var(--swap, 0); }
/* The legal pages are one-font documents: the hover label stays Satoshi there. */
body:has(.legal-doc) .nav-label-alt { font-family: inherit; font-style: normal; font-size: 1em; line-height: 1.4; }

/* Phone menu button, hidden on desktop. */
.nav-menu { display: none; }
/* Without JS the button can't open anything; the footer carries every link. */
html:not(.js) .nav-menu { display: none; }

@media (min-width: 821px) {
  /* Keyboard focus and an open Legal menu swap the label too, not only the mouse. */
  .nav-list > li > a:focus-visible, .nav-drop-toggle:is(:focus-visible, [aria-expanded=true]) { --swap: 1; }
  /* Tabbing across the row should land instantly, not replay the roll on every stop. */
  .nav-list > li > a:focus-visible .nav-swap > *, .nav-drop-toggle:focus-visible .nav-swap > * { transition: none; }
  .nav-drop-toggle[aria-expanded=true] svg { transform: rotate(180deg); }

  /* The Legal card. visibility (not display) so it can fade, and so closed links
     drop out of the tab order. The delay on visibility lets the fade-out finish. */
  .nav-drop-menu { position: absolute; top: 100%; left: 50%; z-index: 70; margin-top: 28px; min-width: 196px; padding: 6px;
    background: var(--bone-2); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 10px 28px rgba(26, 26, 26, 0.08);
    opacity: 0; visibility: hidden; transform: translate(-50%, -4px);
    transition: opacity .16s ease, transform .16s ease, visibility 0s linear .16s; }
  /* Invisible bridge over the gap, so the pointer can travel from Legal to the card. */
  .nav-drop-menu::before { content: ""; position: absolute; left: 0; right: 0; bottom: 100%; height: 30px; }
  .nav-drop-toggle[aria-expanded=true] + .nav-drop-menu { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }
  .nav-drop-menu a { display: block; padding: 11px 12px; border-radius: 8px; white-space: nowrap;
    font-size: 14.5px; font-weight: 500; color: var(--ink); text-decoration: none; }
  .nav-drop-menu a:hover { background: rgba(27, 58, 140, 0.06); color: var(--cobalt); }
  .nav-drop-menu a[aria-current=page] { color: var(--cobalt); }
}
.nav-drop-menu a:focus-visible { outline-offset: 0; }

/* Hover only where hover is real: on touch screens a tap would leave it stuck. */
/* .is-dismissed: Escape pressed while hovering (nav.js); cleared when the pointer leaves. */
@media (min-width: 821px) and (hover: hover) {
  .nav-list > li > a:hover, .nav-drop:not(.is-dismissed):hover > .nav-drop-toggle { --swap: 1; }
  .nav-drop:not(.is-dismissed):hover > .nav-drop-toggle svg { transform: rotate(180deg); }
  .nav-drop:not(.is-dismissed):hover > .nav-drop-menu { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition-delay: 0s; }
}

/* Phones and small tablets: the bar keeps the brand, the waitlist button and a
   menu button. The list drops below the bar as a panel; Legal is a disclosure
   row inside it. The menu button comes first in the DOM so Tab goes button,
   panel, waitlist; order: 1 still draws it at the far right. */
@media (max-width: 820px) {
  .nav-links { gap: 6px; }
  .nav-menu { order: 1; display: grid; place-items: center; width: 44px; height: 44px; margin-right: -10px;
    background: none; border: 0; padding: 0; color: var(--ink); cursor: pointer; }
  .nav-menu-icon { position: relative; width: 18px; height: 8px; }
  .nav-menu-icon::before, .nav-menu-icon::after { content: ""; position: absolute; left: 0; right: 0; height: 1.5px;
    border-radius: 1px; background: currentColor; transition: transform .2s ease; }
  .nav-menu-icon::before { top: 0; }
  .nav-menu-icon::after { bottom: 0; }
  .nav-menu[aria-expanded=true] .nav-menu-icon::before { transform: translateY(3.25px) rotate(45deg); }
  .nav-menu[aria-expanded=true] .nav-menu-icon::after { transform: translateY(-3.25px) rotate(-45deg); }

  .nav-list { display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: 0;
    padding: 4px max(clamp(18px, 4vw, 34px), env(safe-area-inset-right)) 14px max(clamp(18px, 4vw, 34px), env(safe-area-inset-left));
    max-height: calc(100dvh - 64px); overflow-y: auto; overscroll-behavior: contain;
    background: var(--bone); border-bottom: 1px solid var(--line); box-shadow: 0 12px 24px rgba(26, 26, 26, 0.06);
    /* On .nav-list itself, not the open selector, so the reduced-motion rule below
       wins on equal specificity. Closing stays instant (display: none). */
    transition: opacity .18s cubic-bezier(.23, 1, .32, 1), transform .18s cubic-bezier(.23, 1, .32, 1); }
  .nav-menu[aria-expanded=true] ~ .nav-list { display: flex; }
  /* Opening fades and drops in from just above instead of appearing in one frame. */
  @starting-style { .nav-menu[aria-expanded=true] ~ .nav-list { opacity: 0; transform: translateY(-6px); } }
  .nav-list > li + li { border-top: 1px solid var(--line); }
  .nav-list > li > a, .nav-drop-toggle { width: 100%; min-height: 52px; justify-content: space-between; font-size: 17px; color: var(--ink); }
  .nav-list > li > a::after, .nav-drop-toggle::after { content: none; }
  .nav-swap { height: auto; overflow: visible; }
  .nav-label-alt { display: none; }

  .nav-drop-menu { display: none; padding: 0 0 8px 14px; }
  .nav-drop-toggle[aria-expanded=true] + .nav-drop-menu { display: block; }
  .nav-drop-toggle[aria-expanded=true] svg { transform: rotate(180deg); }
  .nav-drop-menu a { display: flex; align-items: center; min-height: 44px; font-size: 16px; color: var(--muted); text-decoration: none; }
  .nav-drop-menu a:hover, .nav-drop-menu a[aria-current=page] { color: var(--cobalt); }
  /* Current page cue in the panel, as desktop has with ink against muted. */
  .nav-list > li > a[aria-current=page], .nav-drop:has([aria-current=page]) > .nav-drop-toggle { color: var(--cobalt); }
}

/* index.html only: over cobalt (the flood, the showcase, the closing band) the bar
   turns cobalt, flipped in one frame, no fade. Only bar-level items flip to bone; the Legal card and the phone
   panel are bone surfaces and keep ink text and the cobalt focus ring. */
header.on-cobalt { background: var(--cobalt); border-bottom-color: transparent; transition: none; }
/* The tile is the bar's own cobalt here; a bone ring keeps the home mark visible. */
header.on-cobalt .brand .tile { box-shadow: 0 0 0 1.5px rgba(245,240,232,0.5); border-radius: 6px; }
header.on-cobalt .brand, header.on-cobalt .nav-menu { color: var(--bone); }
header.on-cobalt .nav-links > .btn { background: var(--bone); color: var(--cobalt); }
header.on-cobalt :is(.brand, .nav-menu, .nav-links > .btn):focus-visible { outline-color: var(--bone); }
@media (min-width: 821px) {
  header.on-cobalt .nav-list > li > :is(a, button) { color: var(--bone); }
  header.on-cobalt .nav-list > li > :focus-visible { outline-color: var(--bone); }
  header.on-cobalt .nav-label-alt { color: var(--bone); }
}

@media (prefers-reduced-motion: reduce) {
  header, .nav-label, .nav-label-alt, .nav-drop-toggle svg, .nav-drop-menu, .nav-list,
  .nav-menu-icon::before, .nav-menu-icon::after { transition: none; }
}

/* Page transitions between pages (cross-document View Transitions, built into the browser).
   The old page fades out and the new one settles in the same place, so a click reads as moving
   within one site instead of a white flash. Both pages must opt in, which is why this lives here,
   in the one stylesheet every page loads. The header keeps its own name and no animation, so it
   holds still while the page under it changes. Reduce Motion never opts in: a plain page load.
   Browsers without View Transitions (Firefox today) ignore all of this and load pages as before.
   The easing is written out because the compound and legal pages take :root from doc.css. */
header { view-transition-name: site-header; }
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: page-out 140ms ease-in both; }
  ::view-transition-new(root) { animation: page-in 280ms cubic-bezier(0.22, 1, 0.36, 1) both; }
  ::view-transition-group(site-header) { animation-duration: 0s; }
}
@keyframes page-out { to { opacity: 0; } }
@keyframes page-in { from { opacity: 0; transform: translateY(10px); } }
