/* Floating navigation; retain the captured controls and mobile rail. */
:root:root body > header:has(> .wrap) {
  top: 18px;
  width: max-content;
  max-width: calc(100% - 48px);
  margin: 18px auto 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--lighting-header, var(--bg));
  color: var(--fg);
  box-shadow: inset 0 1px 0 var(--lighting-panel-edge, transparent),
    0 8px 28px -16px rgb(0 0 0 / .3);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  overflow: visible;
}

:root:root body > header > .wrap {
  width: max-content;
  max-width: none;
  height: auto;
  min-height: 50px;
  padding: 7px 10px 7px 18px;
  gap: 20px;
}

:root:root body > header > .wrap > a:first-child {
  gap: 8px;
  border-radius: 16px;
}

:root:root body > header > .wrap > a:first-child img {
  width: 27px;
  height: 27px;
}

:root:root body > header > .wrap > a:first-child > span {
  font-size: 17px;
  letter-spacing: -.035em;
}

:root:root body > header .grokit-registered {
  display: inline-block;
  position: relative;
  top: -.45em;
  margin-inline-start: 2px;
  font: 500 .53em/1 Arial, sans-serif;
  letter-spacing: 0;
  vertical-align: baseline;
}

:root:root body > header > .wrap > div:has(> nav) {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr;
  min-width: 0;
  opacity: 1;
  visibility: visible;
  margin-inline-end: 0;
  transition: grid-template-columns .55s cubic-bezier(.22, 1, .36, 1),
    margin-inline-end .55s cubic-bezier(.22, 1, .36, 1),
    opacity .22s ease-out, visibility 0s;
}

:root:root body > header > .wrap nav {
  justify-content: center;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}

:root:root body > header[data-nav-compact="true"] > .wrap > div:has(> nav) {
  grid-template-columns: 0fr;
  margin-inline-end: -20px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: grid-template-columns .55s cubic-bezier(.22, 1, .36, 1),
    margin-inline-end .55s cubic-bezier(.22, 1, .36, 1),
    opacity .18s ease-out, visibility 0s .55s;
}

:root:root body > header nav > a {
  border-radius: 999px;
  white-space: nowrap;
}

:root:root body > header > .wrap nav > a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 9px;
  font-size: 13px;
}

/* Documentation stays in the footer, outside both header navigation layouts. */
:root:root body > header nav > a:is([href="docs.html"], [href="/docs.html"], [href="../docs.html"], [href="/docs"], [href="docs"]) {
  display: none;
}

:root:root body > header > .wrap > .ml-auto {
  flex: 0 0 auto;
  gap: 6px;
}

:root:root body > header > .wrap > .ml-auto :is(button, a) {
  border-radius: 999px;
}

/* The existing accessible Search name and keyboard shortcut stay functional. */
:root:root body > header button[aria-label="Search"] {
  width: 36px;
  height: 36px;
  padding: 0;
  gap: 0;
  justify-content: center;
  border-color: transparent;
  background: transparent;
  color: var(--fg-2);
}

:root:root body > header button[aria-label="Search"] > :is(span, kbd) {
  display: none;
}

:root:root body > header :is(#grokit-theme-toggle, a[aria-label*="on X"]) {
  border-color: transparent;
  background: transparent;
  color: var(--fg-2);
}

:root:root body > header .btn-accent {
  border-style: solid;
  border-color: var(--line);
  background: transparent;
  color: var(--fg-2);
}

:root:root body > header .btn-primary {
  box-shadow: inset 0 1px 0 var(--lighting-action-edge, transparent),
    0 3px 12px -8px var(--fg);
}

:root:root body > header nav > a[aria-current="page"] {
  background: var(--fg);
  color: var(--bg);
}

:root:root body > header :is(a, button):focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

:root:root body > header nav > a:focus-visible {
  outline-offset: -2px;
}

html:has(body > header > .wrap) {
  scroll-padding-top: 96px;
}

@media (hover: hover) {
  :root:root body > header nav > a:not([aria-current="page"]):hover,
  :root:root body > header :is(button[aria-label="Search"], #grokit-theme-toggle, a[aria-label*="on X"]):hover {
    background: var(--bg-3);
    color: var(--fg);
  }
}

/* Keep the native horizontal menu until there is room for every desktop action. */
@media (max-width: 1099px) {
  :root:root body > header:has(> .wrap) {
    width: var(--nav-expanded-width, calc(100% - 48px));
    max-width: 760px;
    border-radius: 28px;
    transition: width .55s cubic-bezier(.22, 1, .36, 1);
  }

  :root:root body > header[data-nav-compact="true"]:has(> .wrap) {
    width: var(--nav-compact-width, calc(100% - 48px));
  }

  :root:root body > header > .wrap {
    width: 100%;
  }

  :root:root body > header > .wrap > div:has(> nav) {
    display: none;
  }

  :root:root body > header > div:not(.wrap):has(> nav) {
    display: block;
    margin: 0 9px 5px;
    border-top: 0;
  }

  :root:root body > header > div:not(.wrap) > nav {
    gap: 3px;
    padding: 4px 5px 7px;
    overflow-x: auto;
    scroll-padding-inline: 6px;
    overscroll-behavior-x: contain;
  }

  :root:root body > header > div:not(.wrap) > nav > a {
    min-height: 32px;
    padding: 5px 12px;
    font-size: 12px;
  }

  :root:root body > header > div:not(.wrap) > nav > a[data-nav-foldable] {
    max-width: 120px;
    opacity: 1;
    overflow: hidden;
    transition: max-width .55s cubic-bezier(.22, 1, .36, 1), padding .55s cubic-bezier(.22, 1, .36, 1),
      opacity .22s ease-out, visibility 0s;
  }

  :root:root body > header[data-nav-compact="true"] > div:not(.wrap) > nav > a[data-nav-foldable] {
    max-width: 0;
    padding-inline: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: max-width .55s cubic-bezier(.22, 1, .36, 1), padding .55s cubic-bezier(.22, 1, .36, 1),
      opacity .18s ease-out, visibility 0s .55s;
  }

  html:has(body > header > .wrap) {
    scroll-padding-top: 132px;
  }
}

@media (max-width: 639px) {
  :root:root body > header:has(> .wrap) {
    top: 8px;
    width: var(--nav-expanded-width, calc(100% - 24px));
    margin-top: 8px;
    border-radius: 24px;
  }

  :root:root body > header > .wrap {
    gap: 8px;
    padding-inline: 10px;
  }

  :root:root body > header > .wrap > .ml-auto {
    gap: 4px;
  }

  :root:root body > header > .wrap > a:first-child img {
    width: 24px;
    height: 24px;
  }

  :root:root body > header > .wrap > a:first-child > span {
    font-size: 16px;
  }

  /* Leave room for the full text-chat label beside the compact header controls. */
  :root:root body > header .btn-primary {
    padding-inline: 10px !important;
  }

  html:has(body > header > .wrap) {
    scroll-padding-top: 116px;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root:root body > header:has(> .wrap),
  :root:root body > header > .wrap > div:has(> nav),
  :root:root body > header > div:not(.wrap) > nav > a[data-nav-foldable] {
    transition: opacity .12s linear !important;
  }
}

@media (forced-colors: active) {
  :root:root body > header:has(> .wrap) {
    background: Canvas;
    border-color: CanvasText;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
