.study-nav {
  --nav-bg: #fbfbfb;
  --nav-ink: #40576a;
  --nav-active: #003b65;
  --nav-border: #d5dfe5;
  --nav-focus: #005f90;
  background: var(--nav-bg);
  color: var(--nav-ink);
  z-index: 40;
}

.study-nav-rail, .study-nav-mobile {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  border-block-start: 1px solid var(--nav-border);
  padding-bottom: env(safe-area-inset-bottom);
}

.study-nav-items, .study-nav-group {
  display: flex;
  align-items: stretch;
}

.study-nav-items {
  gap: 2px;
  overflow-x: auto;
  padding: 3px 6px;
  scrollbar-width: thin;
}

.study-nav-group { gap: 2px; }
.study-nav-link {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 66px;
  min-height: 52px;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--nav-ink);
  font-size: 0.8125rem;
  font-weight: 400;
  line-height: 1.25;
  text-decoration: none;
  white-space: nowrap;
}

.study-nav-icon {
  flex: none;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.study-nav-link[aria-current="page"] {
  color: var(--nav-active);
  font-weight: 600;
}

.study-nav-link[aria-current="page"] .study-nav-icon { stroke-width: 2.1; }

@media (hover: hover) {
  .study-nav-link:hover { color: var(--nav-focus); }
}
.study-nav-link:focus-visible { outline: 2px solid var(--nav-focus); outline-offset: -2px; }

@media (min-width: 768px) {
  .study-nav-mobile { display: none; }
}
@media (min-width: 1024px) {
  .study-nav-rail {
    inset-block: 0;
    inset-inline: 0 auto;
    width: min(20%, 230px);
    border-block-start: 0;
    border-inline-end: 1px solid var(--nav-border);
    padding: 0;
  }
  .study-nav-items, .study-nav-group { flex-direction: column; }
  .study-nav-items { height: 100%; padding: 12px 8px; overflow: auto; gap: 6px; }
  .study-nav-link {
    flex-direction: row;
    justify-content: flex-start;
    min-height: 44px;
    padding-inline: 12px;
    gap: 12px;
    font-size: 0.9375rem;
  }
  .study-nav-items > a:first-child { margin: 0 4px 10px; }
  .study-nav-group:last-child { margin-top: auto; }
}

@media (max-width: 1023px) {
  body:has(.study-nav-rail) > main {
    padding-block-end: calc(60px + env(safe-area-inset-bottom));
  }
}

/*
 * Pages with the study sidebar have no site footer, so the "Cookie settings"
 * link (cookie_banner.html) is the last thing on the page. On wide screens,
 * centre it under the content rather than the whole window, and keep it at
 * the bottom of the screen when the page is shorter than the screen: sticky
 * pushes it down into the empty end of the body, never over content.
 */
@media (min-width: 1024px) {
  body:has(.study-nav-rail):not(:has(#site-footer)) { min-height: 100vh; }
  body:has(.study-nav-rail):not(:has(#site-footer)) > #cookie-preferences {
    position: sticky;
    top: calc(100vh - 2.5rem);
    margin-inline-start: min(20%, 230px);
  }
}
