/* ==========================================================================
   MASTHEAD (U10): the one site masthead, src/_includes/masthead.njk.
   Loaded by every page (base.njk, after style.css) and by the map (src/map/index.njk, before app.css), so its rules
   live here once. It reads style.css's tokens; the map aliases them to its own in app.css. app.css only positions it.
   ========================================================================== */

.masthead {
  position: sticky;
  top: 0;
  z-index: 100;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  view-transition-name: masthead;
}

::view-transition-old(masthead),
::view-transition-new(masthead) {
  animation: none;
  mix-blend-mode: normal;
}

.masthead__inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  max-width: 1800px;
  margin: 0 auto;
  padding: 0 var(--space-md);
}

/* brand: title + byline, the same on every page */
.masthead__brand {
  min-width: 0;
  text-align: left;
  opacity: 0.45; /* child pages: subtle */
  transition: opacity 0.4s ease;
}

.masthead__brand:hover,
.masthead__brand:focus-within {
  opacity: 0.85;
}

.masthead--home .masthead__brand,
.masthead--map .masthead__brand {
  opacity: 1;
}

.masthead__title {
  display: block;
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  color: var(--color-text);
}

.masthead__byline {
  display: block;
  margin-top: 0.125rem;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  line-height: 1.2;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-text-muted);
}

.masthead__byline a {
  color: inherit;
  text-decoration: none;
  transition: color 0.3s ease;
}

.masthead__title:hover,
.masthead__byline a:hover {
  color: var(--color-accent);
}

/* centred like a magazine wordmark only where the controls (about 40rem) leave it room */
@media (min-width: 1680px) {
  .masthead__brand {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
  }
}

/* homepage entrance */
@keyframes masthead-scale-down {
  0% { transform: scale(2.5); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes masthead-slide-up {
  0% { transform: translateY(10px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}

.masthead--home .masthead__title {
  animation: masthead-scale-down 1s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.masthead--home .masthead__byline {
  opacity: 0;
  animation: masthead-slide-up 0.6s cubic-bezier(0.16, 1, 0.3, 1) 0.4s forwards;
}

/* controls: "Use in your agent" · Search · Map|Posts · About · Mode · RSS */
.masthead__controls {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: none;
  margin-left: auto;
}

.masthead__menu {
  display: contents;
}

.masthead__control {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: var(--hit, 2.25rem);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  color: var(--color-text-muted);
  transition: color 0.3s ease;
}

.masthead__control:hover {
  color: var(--color-text);
}

.masthead__control-icon {
  font-size: 1.1em;
  opacity: 0.7;
}

.masthead__menu-btn,
.masthead__control--agent {
  display: none;
}

/* "Use in your agent": the one pill (the map's second copy, in its control row, shares it) */
.agent-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  min-height: var(--hit, 2.25rem);
  padding: 0 0.95em;
  border-radius: 999px;
  border: 1px solid var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-ui);
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.agent-btn:hover,
.agent-btn:focus-visible {
  background: var(--color-accent);
  color: var(--color-bg);
}

.agent-btn .arr {
  color: var(--color-accent);
  transition: transform 0.15s ease;
}

.agent-btn:hover .arr,
.agent-btn:focus-visible .arr {
  color: inherit;
  transform: translateX(0.15em);
}

@media (prefers-color-scheme: dark) {
  :root:not(.light-mode) .agent-btn {
    border-color: color-mix(in srgb, var(--color-accent) 70%, transparent);
  }
}

:root.dark-mode .agent-btn {
  border-color: color-mix(in srgb, var(--color-accent) 70%, transparent);
}

/* the map's "How it works" sits on its rail; the menu carries it where the rail has no room */
.masthead__control--how { display: none; }

/* below 960: the controls fold into a labelled menu under the masthead; brand and byline stay */
@media (max-width: 959px) {
  .masthead__control--how { display: inline-flex; }
  .masthead__controls {
    gap: var(--space-sm);
  }

  .masthead__menu-btn {
    display: inline-flex;
  }

  .masthead__menu {
    display: none;
    position: absolute;
    top: calc(100% + var(--space-xs));
    right: var(--space-sm);
    z-index: 20;
    min-width: 13rem;
    padding: var(--space-xs);
    flex-direction: column;
    align-items: stretch;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0.875rem;
    box-shadow: 0 1.125rem 3rem -1.5rem color-mix(in srgb, var(--color-text) 35%, transparent);
  }

  body.menu-open .masthead__menu {
    display: flex;
  }

  .masthead__menu .masthead__control {
    justify-content: flex-start;
    gap: var(--space-sm);
    min-height: 2.75rem;
    padding: 0 var(--space-sm);
    border-radius: 0.625rem;
  }

  .masthead__menu .masthead__control:hover,
  .masthead__menu .masthead__control:focus-visible {
    background: color-mix(in srgb, var(--color-accent) 10%, transparent);
  }

  .masthead__menu .masthead__control-icon {
    width: 1.2em;
    text-align: center;
  }
}

/* phones: the pill leaves the bar (the menu lists it; the map keeps its own copy in the control row) */
@media (max-width: 759px) {
  .masthead__agent {
    display: none;
  }

  .masthead__control--agent {
    display: inline-flex;
  }
}

@media (max-width: 600px) {
  .masthead__title {
    font-size: var(--text-sm);
  }
}

@media (pointer: coarse) {
  .masthead__control {
    min-height: 2.75rem;
  }
}

/* scrolled (main.js): a tighter bar */
.masthead--condensed {
  padding: var(--space-xs) 0;
}
