/* header and nav layout */
header .nav-wrapper {
  background-color: var(--text-color);
  width: 100%;
  z-index: 2;
  position: fixed;
}

/* race tune-in ticker strip (above the main nav bar).
   :where() keeps specificity flat so ticker rules never conflict with nav rules.
   Mobile-first: the race row scrolls horizontally with the CTA stacked below it;
   at tablet+ (R13 breakpoint) everything joins into a single centered row. */
header :where(.nav-ticker) {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background-color: var(--ticker-background-color);
  box-shadow: 0 5px 8px rgb(0 0 0 / 10%);
  padding: 5px 5px 10px;
}

header :where(.nav-ticker .default-content-wrapper) {
  width: 100%;
  overflow-x: auto;
}

header :where(.nav-ticker ul) {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  width: fit-content;
  min-width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

header :where(.nav-ticker ul li) {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 0 1 auto;
  padding: 10px;
  background-color: var(--background-color);
  border-radius: 8px;
  box-shadow: 0 2px 5px rgb(0 0 0 / 20%);
  font-size: var(--body-font-size-xs);
  line-height: 1.3;
}

/* keep the logo/watch-on images at their natural size; the info column is the
   one part that shrinks and truncates so the race row never overflows */
header :where(.nav-ticker .ticker-logo),
header :where(.nav-ticker .ticker-watch-on) {
  flex-shrink: 0;
}

header :where(.nav-ticker ul li p) {
  margin: 0;
}

header :where(.nav-ticker .ticker-info) {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

header :where(.nav-ticker .ticker-track-name),
header :where(.nav-ticker .ticker-race-date) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* race name is authored content but is not shown in the ticker card, matching source */
header :where(.nav-ticker .ticker-race-name) {
  display: none;
}

header :where(.nav-ticker .ticker-watch-on) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  white-space: nowrap;
}

header :where(.nav-ticker .ticker-logo img) {
  width: 65px;
  height: auto;
}

header :where(.nav-ticker .ticker-watch-on img) {
  height: 15px;
  width: auto;
}

/* not :where() — needs enough specificity to override the global a:any-link color (styles.css) */
header .nav-ticker a:any-link {
  color: var(--link-color);
  font-weight: 700;
  white-space: nowrap;
}

/* the "Weekend Schedule" CTA, pulled out of the race list to sit on its own
   line below the scrollable row on mobile (source: .schedule-button-container) */
header .nav-ticker a.ticker-cta {
  box-sizing: border-box;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 210px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background-color: var(--link-color);
  color: var(--background-color);
  font-size: var(--body-font-size-xs);
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
}

header .nav-ticker a.ticker-cta:hover {
  background-color: var(--background-color);
  border-color: var(--text-color);
  color: var(--text-color);
}

@media (width >= 768px) {
  header :where(.nav-ticker) {
    flex-direction: row;
    justify-content: center;
    gap: 25px;
  }

  header :where(.nav-ticker .default-content-wrapper) {
    width: auto;
  }

  header :where(.nav-ticker ul) {
    width: auto;
    min-width: 0;
  }

  header .nav-ticker a.ticker-cta {
    width: auto;
  }
}

/* between tablet and the point where the full row fits (1063px), there isn't room for
   full-size logos and a one-line CTA in the same row: shrink the logos out fluidly
   (no scrolling) and let the CTA's own label wrap to two lines, staying inline in the
   row, rather than adding another named breakpoint */
@media (width >= 768px) and (width < 1063px) {
  header :where(.nav-ticker .ticker-logo img) {
    width: clamp(0px, calc((100vw - 768px) * 65 / 295), 65px);
  }

  header :where(.nav-ticker ul li) {
    padding: 14px 10px;
  }

  header .nav-ticker a.ticker-cta {
    max-width: 90px;
    padding: 4px 8px;
    white-space: normal;
    text-align: center;
  }
}

header nav {
  box-sizing: border-box;
  display: grid;
  grid-template:
    'brand tools' var(--nav-height)
    'sections sections' 1fr / 1fr auto;
  align-items: center;
  gap: 0 24px;
  margin: auto;
  max-width: var(--content-max-width);
  height: var(--nav-height);
  padding: 0 16px;
  color: var(--background-color);
  font-family: var(--body-font-family);
}

header nav[aria-expanded='true'] {
  grid-template:
    'brand' var(--nav-height)
    'sections' 1fr
    'tools' var(--nav-height) / 1fr;
  overflow-y: auto;
  min-height: 100dvh;
}

@media (width >= 1024px) {
  header .nav-wrapper {
    position: relative;
  }

  header nav {
    display: flex;
    justify-content: flex-start;
    gap: 0 24px;
    padding: 0 32px;
  }

  header nav[aria-expanded='true'] {
    min-height: 0;
    overflow: visible;
  }
}

header nav p {
  margin: 0;
  line-height: 1;
}

header nav a:any-link {
  color: currentcolor;
  font-weight: 400;
}

/* hamburger — hidden for now; nav-sections is inaccessible on mobile until
   mobile navigation is revisited (kept in markup/JS to make that easy later) */
header nav .nav-hamburger {
  display: none;
  visibility: hidden;
}

header nav .nav-hamburger button {
  height: 22px;
  margin: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background-color: transparent;
  color: inherit;
  overflow: initial;
  text-overflow: initial;
  white-space: initial;
}

header nav .nav-hamburger-icon,
header nav .nav-hamburger-icon::before,
header nav .nav-hamburger-icon::after {
  box-sizing: border-box;
  display: block;
  position: relative;
  width: 20px;
}

header nav .nav-hamburger-icon::before,
header nav .nav-hamburger-icon::after {
  content: '';
  position: absolute;
  background: currentcolor;
}

header nav[aria-expanded='false'] .nav-hamburger-icon,
header nav[aria-expanded='false'] .nav-hamburger-icon::before,
header nav[aria-expanded='false'] .nav-hamburger-icon::after {
  height: 2px;
  border-radius: 2px;
  background: currentcolor;
}

header nav[aria-expanded='false'] .nav-hamburger-icon::before {
  top: -6px;
}

header nav[aria-expanded='false'] .nav-hamburger-icon::after {
  top: 6px;
}

header nav[aria-expanded='true'] .nav-hamburger-icon {
  height: 22px;
}

header nav[aria-expanded='true'] .nav-hamburger-icon::before,
header nav[aria-expanded='true'] .nav-hamburger-icon::after {
  top: 3px;
  left: 1px;
  transform: rotate(45deg);
  transform-origin: 2px 1px;
  width: 24px;
  height: 2px;
  border-radius: 2px;
}

header nav[aria-expanded='true'] .nav-hamburger-icon::after {
  top: unset;
  bottom: 3px;
  transform: rotate(-45deg);
}

/* brand */
header .nav-brand {
  grid-area: brand;
  line-height: 1;
}

header nav .nav-brand img {
  width: 150px;
  height: auto;
}

@media (width >= 1024px) {
  header .nav-brand {
    flex-basis: 160px;
  }

  header nav .nav-brand img {
    width: 150px;
  }
}

/* sections */
header nav .nav-sections {
  grid-area: sections;
  flex: 1 1 auto;
  display: none;
  visibility: hidden;
}

header nav[aria-expanded='true'] .nav-sections {
  display: block;
  visibility: visible;
  align-self: start;
}

header nav .nav-sections ul {
  list-style: none;
  padding-left: 0;
  font-size: var(--body-font-size-s);
}

header nav .nav-sections ul > li {
  font-weight: 400;
  text-transform: uppercase;
}

header nav .nav-sections ul > li > ul {
  margin-top: 0;
}

header nav .nav-sections ul > li > ul > li {
  font-weight: 400;
}

@media (width >= 1024px) {
  header nav .nav-sections {
    display: block;
    visibility: visible;
    white-space: nowrap;
  }

  header nav[aria-expanded='true'] .nav-sections {
    align-self: unset;
  }

  header nav .nav-sections .nav-drop {
    position: relative;
    padding-right: 16px;
    cursor: pointer;
  }

  header nav .nav-sections .nav-drop::after {
    content: '';
    display: inline-block;
    position: absolute;
    top: 50%;
    right: 2px;
    transform: translateY(-50%) rotate(135deg);
    width: 6px;
    height: 6px;
    border: 2px solid currentcolor;
    border-radius: 0 1px 0 0;
    border-width: 2px 2px 0 0;
  }

  header nav .nav-sections .nav-drop[aria-expanded='true']::after {
    transform: translateY(-50%) rotate(315deg);
  }

  header nav .nav-sections ul {
    display: flex;
    gap: 24px;
    margin: 0;
  }

  header nav .nav-sections .default-content-wrapper > ul > li {
    flex: 0 1 auto;
    position: relative;
  }

  header nav .nav-sections .default-content-wrapper > ul > li > ul {
    display: none;
    position: relative;
  }

  header nav .nav-sections .default-content-wrapper > ul > li[aria-expanded='true'] > ul {
    display: block;
    position: absolute;
    left: -16px;
    width: 220px;
    top: 200%;
    padding: 8px 0;
    background-color: var(--text-color);
    border-top: 3px solid var(--brand-primary);
    white-space: initial;
    z-index: 3;
  }

  header nav .nav-sections .default-content-wrapper > ul > li > ul > li {
    padding: 8px 16px;
    text-transform: none;
  }

  header nav .nav-sections .default-content-wrapper > ul > li > ul > li:hover {
    background-color: var(--dark-color);
  }
}

/* tools */
header nav .nav-tools {
  grid-area: tools;
}

header nav .nav-tools :where(ul) {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: var(--body-font-size-xs);
}

header nav .nav-tools a:any-link {
  font-weight: 400;
  text-transform: uppercase;
}

/* "Tickets" / "Shop" get a pill outline; the last tool ("My Profile") stays plain
   pending an author-side icon swap (see R5 — icons are authored, not hardcoded) */
header nav .nav-tools ul li:not(:last-child) a:any-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid currentcolor;
  border-radius: 999px;
  padding: 6px 12px;
}

@media (width >= 1024px) {
  header nav .nav-tools :where(ul) {
    gap: 16px;
    font-size: var(--body-font-size-s);
  }

  header nav .nav-tools ul li:not(:last-child) a:any-link {
    padding: 6px 16px;
  }
}
