/* All header links use the same text alignment and hit area, including Books
   links added by navigation.js. No page content or navigation target changes. */
body > header > nav > a {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-size: inherit;
  line-height: 1.4;
}

/* The boarding page has one generated Books link and no main site menu. */
body > header:not(:has(> .brand)) > nav { font-size: 14px; }

/* Keep the existing mobile menu's larger touch targets. */
@media (max-width: 640px) {
  body > header:has(> .brand) > nav > a { min-height: 48px; }
}

@media (min-width: 641px) {
  body > header:has(> .brand) {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px 24px;
    height: auto;
    min-height: 112px;
    padding-top: 12px;
    padding-bottom: 12px;
  }
  body > header:has(> .brand) > nav {
    display: flex;
    flex-wrap: nowrap;
    flex-basis: auto;
    align-items: center;
    justify-content: center;
    order: initial;
    min-width: 0;
    width: auto;
    margin: 0;
    padding: 0;
    gap: 8px clamp(12px, 1.25vw, 20px);
    font-size: 14px;
  }
  body > header:has(> .brand) > nav > a {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

/* Give the complete menu its own row before the logo/selector could squeeze
   translated labels. The affected screenshot width keeps one aligned row. */
@media (min-width: 641px) and (max-width: 1440px) {
  body > header:has(> .brand) { grid-template-columns: minmax(0, 1fr) auto; }
  body > header:has(> .brand) > .brand { grid-column: 1; grid-row: 1; }
  body > header:has(> .brand) > #language { grid-column: 2; grid-row: 1; }
  body > header:has(> .brand) > nav { grid-column: 1 / -1; grid-row: 2; }
}

/* Deliberately balanced rows on small tablets: seven links become 4 + 3,
   five become 3 + 2. Never leave the final Books link alone on a new row.
   Six/four-link no-JavaScript navigation remains balanced as 3 + 3 / 2 + 2. */
@media (min-width: 641px) and (max-width: 999px) {
  body > header:has(> .brand) > nav {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    align-items: stretch;
    gap: 8px 12px;
  }
  body > header:has(> .brand) > nav > a {
    grid-column: span 4;
    min-width: 0;
    justify-content: center;
    padding: 8px;
    white-space: normal;
    text-align: center;
    overflow-wrap: anywhere;
  }
  body > header:has(> .brand) > nav > a:first-child:nth-last-child(7),
  body > header:has(> .brand) > nav > a:first-child:nth-last-child(7) ~ a:nth-child(-n+4) { grid-column: span 3; }
  body > header:has(> .brand) > nav > a:first-child:nth-last-child(5) ~ a:nth-child(n+4),
  body > header:has(> .brand) > nav > a:first-child:nth-last-child(4),
  body > header:has(> .brand) > nav > a:first-child:nth-last-child(4) ~ a { grid-column: span 6; }
}
