/* Site navigation: a sticky bar with the name, the links and the theme
   button. */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}

.site-nav .nav-inner {
  max-width: var(--w-content);
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.nav-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.nav-brand .tick { color: var(--accent); }

.nav-links {
  display: flex;
  gap: 1.4rem;
  margin-left: auto;
  align-items: center;
}

.nav-links a {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--muted);
  transition: color 140ms ease;
}

.nav-links a:hover, .nav-links a:focus-visible { color: var(--accent-strong); }

/* The mark for the current page. */
.nav-links a[aria-current="page"] { color: var(--accent-strong); }

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.theme-toggle, .nav-toggle {
  position: relative;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 140ms ease, border-color 140ms ease;
}

.theme-toggle svg, .nav-toggle svg { width: 0.95rem; height: 0.95rem; }

/* A finger needs 44px, and the circle is 32px. A transparent box adds the
   rest, and the gap of 0.75rem keeps two boxes apart. */
@media (pointer: coarse) {
  .nav-actions { gap: 0.75rem; }

  .theme-toggle::after, .nav-toggle::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2.75rem;
    height: 2.75rem;
    transform: translate(-50%, -50%);
  }
}

/* The two buttons need a script. The menu button also shows only on a small
   screen. */
.theme-toggle, .nav-toggle { display: none; }

.js .theme-toggle { display: inline-flex; }

.nav-toggle .icon-close { display: none; }
.nav-toggle[aria-expanded="true"] .icon-menu { display: none; }
.nav-toggle[aria-expanded="true"] .icon-close { display: block; }

/* The theme button shows one icon: system, light or dark. Not light and not
   dark is the system mode. */
.theme-toggle svg { display: none; }

:root:not([data-theme="light"]):not([data-theme="dark"]) .theme-toggle .icon-system { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* Below 840px the bar does not hold one line. The links move to their own
   row, which the menu button hides if a script runs. */
@media (max-width: 840px) {
  .site-nav .nav-inner {
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 0.7rem 1.15rem;
  }

  .nav-actions { margin-left: auto; }

  .nav-links {
    order: 3;
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    gap: 0.35rem 1.1rem;
  }

  .js .nav-toggle { display: inline-flex; }

  .js .nav-links {
    display: none;
    flex-direction: column;
    /* A full-width row, so a touch hits more than the label. */
    align-items: stretch;
    gap: 0;
    margin-top: 0.1rem;
    padding-top: 0.2rem;
    border-top: 1px solid var(--hairline);
  }

  .js .nav-links.is-open {
    display: flex;
    animation: nav-reveal 180ms ease;
  }

  /* The touch areas for the links in a column. */
  .js .nav-links a {
    padding: 0.72rem 0.15rem;
    font-size: 0.78rem;
  }
}

@keyframes nav-reveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
