/* Shared navigation geometry; each topic supplies its own type and colours. */
#pages[data-current-topic] {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: baseline;
  column-gap: clamp(16px, 2.4vw, 32px);
  row-gap: 10px;
  min-width: 0;
}

#pages[data-current-topic] > .nav-brand {
  justify-self: start;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
}

#pages .nav-destinations {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: baseline;
  column-gap: clamp(12px, 2vw, 26px);
  justify-self: end;
  width: 100%;
  max-width: 680px;
  min-width: 0;
}

#pages .popular-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: baseline;
  column-gap: clamp(12px, 2vw, 26px);
  min-width: 0;
}

#pages .nav-topic {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

#pages .nav-all {
  justify-self: end;
  white-space: nowrap;
}

/* Reserve the expanded timer's corner from the outset. Its opening never
   changes the navigation geometry or obscures a destination. */
#pages[data-current-topic="us-china-ai"] {
  padding-right: 208px;
}

@media (max-width: 1100px) {
  #pages[data-current-topic="us-china-ai"] {
    grid-template-columns: minmax(0, 1fr);
    padding-right: 0;
  }

  #pages[data-current-topic="us-china-ai"] > .nav-brand {
    min-height: 48px;
  }

  #pages[data-current-topic="us-china-ai"] .nav-destinations {
    max-width: none;
  }

  #pages[data-current-topic="us-china-ai"] .nav-topic {
    text-align: left;
  }
}

@media (max-width: 760px) {
  #pages[data-current-topic] {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 10px;
  }

  #pages[data-current-topic] > .nav-brand {
    min-height: 48px;
  }

  #pages .nav-destinations {
    max-width: none;
    column-gap: 12px;
  }

  #pages .popular-links {
    column-gap: 12px;
  }

  #pages .nav-topic {
    text-align: left;
  }

  /* Give narrow layouts the complete destination names. US–China keeps its
     second-row All charts link because the timer occupies the upper corner. */
  #pages[data-current-topic]:not([data-current-topic="us-china-ai"]) {
    grid-template-columns: minmax(0, 1fr) max-content;
    row-gap: 14px;
  }

  #pages[data-current-topic]:not([data-current-topic="us-china-ai"]) > .nav-brand {
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
  }

  #pages[data-current-topic]:not([data-current-topic="us-china-ai"]) .nav-destinations {
    display: contents;
  }

  #pages[data-current-topic]:not([data-current-topic="us-china-ai"]) .popular-links {
    grid-column: 1 / -1;
    grid-row: 2;
    align-items: start;
  }

  #pages[data-current-topic]:not([data-current-topic="us-china-ai"]) .nav-all {
    grid-column: 2;
    grid-row: 1;
  }

  #pages[data-current-topic]:not([data-current-topic="us-china-ai"]) .nav-topic {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.6;
  }
}
