/* Header: a dark masthead (tools | logo | member actions) above a row of topic links,
   plus the menu drawer. Loaded after mews-base.css. */


/* Tokens */

/* Single source of truth for the header geometry. The body offset, .navbar-spacer (the sticky
   threshold in mews.js), post hero, split layout, sticky sidebars and scroll padding all read
   --navbar-height and --navbar-compact-height, and the rows below are sized from the same values. */
html {
  --navbar-bg: #1a1817;
  --navbar-fg: #fff;
  --navbar-rule: rgba(255, 255, 255, 0.14);
  --navbar-masthead-height: 5rem;
  --navbar-topics-height: 3rem;
  --navbar-masthead-compact-height: 3rem;
  --navbar-topics-compact-height: 2.5rem;
  --navbar-height: calc(var(--navbar-masthead-height) + var(--navbar-topics-height));
  --navbar-compact-height: calc(var(--navbar-masthead-compact-height) + var(--navbar-topics-compact-height));
  /* Logos fit half the masthead row AND this width, so wide wordmarks stay in proportion */
  --navbar-logo-max-width: 12rem;
}


/* Bar */

/* Sticky header: fixed from the first paint, shrinks to the compact height once scrolled (mews.js) */
.navbar {
  background-color: var(--navbar-bg);
  color: var(--navbar-fg);
  position: fixed;
  top: 0; left: 0;
  z-index: 97;
}

/* In dark mode the page shares the bar's tone, so a hairline marks its edge (a shadow adds no height) */
html.theme-dark .navbar {
  box-shadow: 0 1px 0 var(--navbar-rule);
}

.navbar-spacer {
  background-color: var(--color-body-bg);
  content: '';
  height: var(--navbar-height);
  position: fixed;
  top: 0; right: 0; left: 0;
  z-index: -3;
}


/* Masthead row */

/* The outer columns share the free space equally, so the logo sits at the true center */
.navbar-masthead {
  align-items: center;
  column-gap: 1rem;
  display: grid;
  grid-template-areas: "start logo end";
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  height: var(--navbar-masthead-height);
}

body.compact .navbar-masthead {
  height: var(--navbar-masthead-compact-height);
}

.navbar-start {
  align-items: center;
  display: flex;
  grid-area: start;
  justify-self: start;
}

.navbar-end {
  align-items: center;
  display: flex;
  gap: 1.25rem;
  grid-area: end;
  justify-self: end;
}

/* The width cap sits on the link so the grid column is sized to it, which keeps the logo centered */
.navbar-logo {
  align-items: center;
  display: flex;
  grid-area: logo;
  height: 50%;
  max-width: var(--navbar-logo-max-width);
  min-width: 0;
}

/* Scale down to whichever limit is hit first: the row height (tall or square logos),
   --navbar-logo-max-width (wide wordmarks) or the room left by the tools on narrow phones.
   Never scales up. */
.navbar-logo img {
  height: auto;
  width: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* Fallback when there is no alternate logo: the main logo is drawn for light backgrounds */
.navbar-logo .logo-inverted {
  filter: invert(1);
}

.navbar-site-title {
  color: inherit;
  font-family: var(--gh-font-heading, var(--font-heading));
  font-size: 1.75rem;
  grid-area: logo;
  line-height: 1.1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


/* Tools: menu, search and colour scheme toggle */

.navbar-tools {
  align-items: center;
  display: flex;
}

.navbar-search, .color-scheme-toggle {
  align-items: center;
  background-color: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  height: 44px;
  justify-content: center;
  padding: 0;
  position: relative;
  width: 44px;
}

.navbar-search svg {
  min-width: 16px;
}

.color-scheme-toggle {
  perspective: 1000px;
  transform-style: preserve-3d;
}

.color-scheme-toggle > span {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  transition: transform 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  top: 0; left: 0;
}

.color-scheme-toggle > span:first-child {
  transform: rotateY(0deg);
}

.color-scheme-toggle > span:last-child {
  transform: rotateY(180deg);
}

/* Keyed on the html class, which is set before first paint, so the icon starts in the right state without flipping on load */
html.theme-dark .color-scheme-toggle > span:first-child {
  transform: rotateY(-180deg);
}

html.theme-dark .color-scheme-toggle > span:last-child {
  transform: rotateY(0deg);
}

/* The bars sit 11px inside the button, so the negative margin lines them up with the container edge */
.hamburger {
  background-color: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  height: 48px;
  margin: 0 0 0 -11px;
  min-width: 48px;
  padding: 0;
  position: relative;
  width: 48px;
}

.hamburger span {
  background-color: currentColor;
  display: block;
  height: 2px;
  position: absolute;
  right: 11px; left: 11px;
}

.hamburger span:nth-child(1) {
  top: 16px;
}

.hamburger span:nth-child(2) {
  top: 23px;
}

.hamburger span:nth-child(3) {
  top: 30px;
}


/* Member actions */

.navbar-signin, .navbar-subscribe {
  font-family: var(--font-accent);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.25;
  white-space: nowrap;
}

.navbar-signin {
  color: inherit;
  padding: 0.5rem 0;
}

.navbar .navbar-subscribe {
  background-color: #fff;
  border-radius: 0.25rem;
  color: var(--navbar-bg);
  padding: 0.625rem 1.125rem;
  text-decoration: none;
}

/* No underline: the hover rule must outrank the global a:not(.btn, .navbar-menu-item):hover
   underline in mews-base.css, which scores higher than two classes */
.navbar .navbar-subscribe:hover {
  background-color: #e8e6e3;
  text-decoration: none;
}


/* Topic row (header-tags page, or all tags as fallback) */

/* Full width so the rule between the rows runs edge to edge; the list inside is a .container */
.navbar-tags {
  box-shadow: inset 0 1px 0 var(--navbar-rule);
  height: var(--navbar-topics-height);
}

body.compact .navbar-tags {
  height: var(--navbar-topics-compact-height);
}

/* No scrollbar (it would steal row height): the edge fade signals overflow, mews.js maps the
   mouse wheel to horizontal scroll, and focused links scroll into view */
.navbar-tags-list {
  display: flex;
  gap: 2rem;
  height: 100%;
  list-style: none;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 2rem), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 2rem), transparent);
  overflow-x: auto;
  overflow-y: hidden;
  scroll-padding-inline: 2rem;
  scrollbar-width: none;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

.navbar-tags-list::-webkit-scrollbar {
  display: none;
}

/* Two classes so it outranks the global li spacing in mews-article.css, which loads later */
.navbar-tags .navbar-tags-list > li {
  display: flex;
  flex-shrink: 0;
  margin: 0;
}

/* Centered while the links fit; auto margins collapse to zero once the row overflows, so the
   first link never ends up cut off (unlike justify-content: center) */
.navbar-tags .navbar-tags-list > li:first-child {
  margin-inline-start: auto;
}

.navbar-tags .navbar-tags-list > li:last-child {
  margin-inline-end: auto;
}

.navbar-tags-link {
  align-items: center;
  color: inherit;
  display: flex;
  font-family: var(--font-accent);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.2;
  position: relative;
}

/* The bar replaces the global underline; it also marks the current topic, so state never relies on colour alone */
.navbar .navbar-tags-link:hover {
  text-decoration: none;
}

.navbar-tags-link::after {
  background-color: currentColor;
  content: '';
  height: 2px;
  position: absolute;
  right: 0; bottom: 0; left: 0;
  transform: scaleX(0);
}

.navbar-tags-link:hover::after,
.navbar-tags-link[aria-current="page"]::after {
  transform: scaleX(1);
}


/* Keyboard focus */

.navbar :is(a, button):focus-visible {
  outline: 2px solid var(--navbar-fg);
  outline-offset: 2px;
}

/* Inset rings: the topic row clips anything outside it, and icon buttons are larger than their icons */
.navbar .navbar-tags-link:focus-visible {
  outline-offset: -2px;
}

.hamburger:focus-visible,
.navbar-menu-close:focus-visible {
  outline-offset: -6px;
}


/* Motion */

@media (prefers-reduced-motion: no-preference) {
  .navbar-masthead, .navbar-tags {transition: height 0.3s ease-out;}
  .navbar-tags-link::after {transition: transform 0.2s ease-out;}
  .navbar .navbar-subscribe {transition: background-color 0.15s ease-out;}
}


/* Menu drawer: slides in from the left, beside the menu button */

.navbar-menu {
  background-color: var(--color-body-bg);
  opacity: 0;
  padding: 3rem;
  pointer-events: none;
  position: fixed;
  max-width: 20rem;
  top: 0; bottom: 0; left: 0;
  transform: translateX(calc(-100% - 2px));
  transition: 0.3s ease-out;
  width: 100%;
  z-index: 99;
}

body.nav-menu-open .navbar-menu {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.navbar-menu-links {
  opacity: 0;
  overflow-y: auto;
  padding-bottom: 3rem;
  transform: translateX(-25%);
  transition: 0.3s ease-out 0.125s;
}

body.nav-menu-open .navbar-menu-links {
  opacity: 1;
  transform: translateX(0);
}

/* Navigation is UI type (Inter), like the header links */
.navbar-menu-item {
  font-family: var(--font-accent);
  font-size: 1.25rem;
  font-weight: 500;
  position: relative;
}

.navbar-menu-item span,
.navbar-menu-collapse a {
  transition: 0.15s ease-out;
}

.navbar-menu-item:hover span,
.navbar-menu-collapse a:hover {
  opacity: 0.85;
}

.navbar-menu-item:not(:first-child),
.navbar-menu-item:not(:first-child) .navbar-menu-collapse-toggle {
  padding-top: 0.5rem;
}

.navbar-menu-item:not(:last-child) {
  border-bottom: 1px solid  var(--color-lightest);
  padding-bottom: 0.5rem;
}

.navbar-menu-item.collapse {
  padding: 0;
}

.navbar-menu-collapse-toggle {
  background-color: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0 0 0.5rem;
  text-align: left;
  width: 100%;
}

.navbar-menu-collapse-toggle svg {
  min-width: 0.75rem;
  width: 0.75rem;
  transition: 0.15s ease-out;
}

.navbar-menu-collapse-toggle.active svg {
  transform: scaleY(-1);
}

.navbar-menu-collapse {
  font-family: var(--font-accent);
  font-size: 0.625rem;
  height: auto;
  letter-spacing: 0.1em;
  opacity: 0;
  pointer-events: none;
  text-transform: uppercase;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}

.navbar-menu-collapse:not(.show) {
  max-height: 0!important;
}

.navbar-menu-collapse.show {
  opacity: 1;
  pointer-events: auto;
}

.navbar-menu-collapse > div {
  padding: 0 0 0.5rem 0.15rem;
}

.navbar-menu-collapse a {
  display: inline-block;
  margin-bottom: 0.75rem;
}

.navbar-menu-collapse > div > div:last-child a {
  margin-bottom: 0.5rem;
}

.navbar-menu-btns {
  padding-top: 1.5rem;
}

.navbar-menu-btns .btn:not(:last-child) {
  margin-right: 1.5rem;
}

.navbar-menu-btns:before {
  background: linear-gradient(0deg, var(--color-body-bg) 0%, transparent 100%);
  content: '';
  height: 5rem;
  position: absolute;
  top: -5rem; right: 0; left: 0;
}

/* Phones only: the header hands its colour toggle to the drawer under 480px */
.navbar-menu-btns .color-scheme-toggle {
  display: none;
}

/* Shared close button styles (size and the X) live in mews-base.css */
.navbar-menu-close {
  margin: 0;
  position: absolute;
  top: 0; right: 0;
}

.navbar-menu :is(a, button):focus-visible {
  outline: 2px solid var(--color-titles);
  outline-offset: 2px;
}


/* Media Queries */

/* 960px: Forbes-style compact masthead. The logo moves left beside the tools and nothing shrinks on scroll. */
@media (max-width: 959.98px) {
  html {--navbar-masthead-height: 3.5rem; --navbar-topics-height: 2.75rem; --navbar-masthead-compact-height: var(--navbar-masthead-height); --navbar-topics-compact-height: var(--navbar-topics-height); --navbar-logo-max-width: 7.5rem;}
  .navbar-masthead {grid-template-columns: auto minmax(0, 1fr) auto;}
  .navbar-logo, .navbar-site-title {justify-self: start;}
  .navbar-site-title {font-size: 1.5rem;}
  .navbar-tags .navbar-tags-list > li:first-child {margin-inline-start: 0;}
  .navbar-tags .navbar-tags-list > li:last-child {margin-inline-end: 0;}
  .navbar-tags-list {gap: 1.5rem;}
}

/* 720px */
@media (max-width: 719.98px) {
  .navbar-menu {padding: 3rem 2rem 2rem;}
}

/* 480px: Sign in and the colour toggle move into the drawer (only when there is one) */
@media (max-width: 479.98px) {
  .navbar.has-menu .navbar-signin, .navbar.has-menu .navbar-tools .color-scheme-toggle {display: none;}
  .navbar-menu-btns .color-scheme-toggle {display: inline-flex;}
  .navbar-end {gap: 1rem;}
  .navbar .navbar-subscribe {font-size: 0.8125rem; padding: 0.5rem 0.875rem;}
}
