/* ==========================================================================
   Metapsy Risk of Bias Handbook (rob/handbook/*.html, generated by
   _render/generate.js from _render/content/*.md and templates/layout.html).
   In the look of the RoB overview (/rob) and the RoB Assistant:
   light canvas, hairline borders, dark ink headings, muted rating colours.
   ========================================================================== */

.rob-handbook {
  --hb-heading: color-mix(in srgb, #0372b7 62%, #5f6f78); /* muted --bs-primary */
  --hb-canvas: #f6f9fb;
  --hb-surface: #ffffff;
  --hb-line: rgba(49, 63, 69, 0.12);
  --hb-ink: #24323a;
  --hb-text: #33424a;
  --hb-muted: #5f6f78;
  --hb-blue: #0372b7;
  --hb-low: #4f8a5a;
  --hb-some: #a5832a;
  --hb-high: #b4544c;
  --hb-nav-h: 7.3rem; /* height of the fixed site navbar */
  background-color: var(--hb-surface) !important;
  color: var(--hb-text);
}
html[data-theme="dark"] .rob-handbook {
  --hb-heading: color-mix(in srgb, #4f9fd6 68%, #9fb0b8);
  --hb-canvas: #1a2226;
  --hb-surface: #222d32;
  --hb-line: rgba(108, 117, 125, 0.3);
  --hb-ink: #e2e8eb;
  --hb-text: #cfd8dc;
  --hb-muted: #9fb0b8;
  --hb-blue: #4f9fd6;
  --hb-low: #7cbf88;
  --hb-some: #d6b45a;
  --hb-high: #e08279;
  background-color: var(--hb-surface) !important;
}

/* anchors land below the fixed navbar (--mnav-h: its height, set on <html>
   by js/nav-modern.js; + the gradient strip and some air) */
html {
  scroll-padding-top: calc(var(--mnav-h, 6.3rem) + 2rem);
}

/* one background for the whole page (the site's dark theme paints
   #main-body a shade darker than the sidebars otherwise) */
#main-body,
html[data-theme="dark"] #main-body {
  background-color: transparent !important;
}

/* ---- Fixed site navbar on top ------------------------------------------- */
.navigation {
  position: fixed;
  top: 0;
  z-index: 1030;
  width: 100%;
  background-color: #fff;
  box-shadow: 0 1px 0 var(--hb-line);
}

/* ---- Three columns: contents · article · on this page ------------------- */
@media (min-width: 992px) {
  /* full height under the fixed navbar (no gap whatever its exact height) */
  #sidebar-toc,
  .on-this-page {
    position: fixed;
    top: 0;
    z-index: 2;
    width: 16.666%;
    height: 100vh;
    padding-top: var(--hb-nav-h);
    overflow-y: auto;
  }
  #sidebar-toc {
    left: 0;
    background-color: transparent;
  }
  html[data-theme="dark"] #sidebar-toc {
    background-color: transparent;
  }
  .on-this-page {
    right: 0;
    padding-right: 1.5rem;
    padding-bottom: 2rem;
  }
  main {
    position: relative;
    z-index: 1;
    margin: 0 16.666%;
    padding: calc(var(--hb-nav-h) + 2.25rem) 2rem 6rem;
    overflow-x: hidden;
  }
}
@media (max-width: 991.98px) {
  /* below the fixed navbar: its height comes from js/nav-modern.js (--mnav-h)
     plus the thin gradient strip above it */
  #sidebar-toc {
    padding: calc(var(--mnav-h, 5.5rem) + 1.5rem) 1.25rem 0.5rem;
  }
  main {
    padding: 1.5rem 1.25rem 4rem;
  }
}

/* ---- Left: brand + contents --------------------------------------------- */
.hb-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.6rem 1.5rem 1.25rem;
  color: var(--hb-muted);
  text-decoration: none;
  user-select: none;
}
.hb-brand:hover {
  color: var(--hb-ink);
}
/* shield 1.9rem on a 16-unit grid (font-size 2rem: 1 unit = 0.95em / 16) */
.hb-brand__icon {
  position: relative;
  flex: none;
  width: 0.95em;
  height: 0.95em;
  font-size: 2rem;
}
.hb-brand__icon svg {
  display: block;
  width: 100%;
  height: 100%;
}
/* traffic-light dots (as on /rob): a steady conveyor through the shield,
   growing in at the top and shrinking away at the bottom; only transform
   is animated, on composited layers. Still at rest (green / amber / red in
   the three slots: the delays put them at 17 / 50 / 83 % of the cycle),
   flowing while the pointer is on the logo. */
.hb-brand__dot {
  position: absolute;
  left: calc(50% - 0.07125em);
  top: calc(2.9 * 0.059375em - 0.07125em);
  width: 0.1425em;
  height: 0.1425em;
  border-radius: 50%;
  background: #6aa874;
  animation: hb-dot-flow 2.7s linear infinite;
  animation-delay: -0.459s;
  animation-play-state: paused;
}
.hb-brand__dot:nth-of-type(2) {
  background: #d2ad4c;
  animation-delay: -1.35s;
}
.hb-brand__dot:nth-of-type(3) {
  background: #cf6d64;
  animation-delay: -2.241s;
}
.hb-brand:hover .hb-brand__dot,
.hb-brand:focus-visible .hb-brand__dot {
  animation-play-state: running;
}
@keyframes hb-dot-flow {
  0% {
    transform: translateY(0) scale(0);
  }
  15% {
    transform: translateY(0.0775em) scale(1);
  }
  85% {
    transform: translateY(0.4391em) scale(1);
  }
  100% {
    transform: translateY(0.5166em) scale(0);
  }
}
/* reduced motion: still, in the three slots */
@media (prefers-reduced-motion: reduce) {
  .hb-brand__dot {
    animation: none;
    transform: translateY(0.0861em);
  }
  .hb-brand__dot:nth-of-type(2) {
    transform: translateY(0.2583em);
  }
  .hb-brand__dot:nth-of-type(3) {
    transform: translateY(0.4305em);
  }
}
.hb-brand__title {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.hb-brand__version {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: var(--hb-muted);
}
#burger-toc {
  padding: 0.75rem 1rem 1rem;
  background-color: var(--hb-surface);
  border: 1px solid var(--hb-line);
  border-bottom-width: 3px;
  border-radius: 0 0.5rem 0.5rem 0;
  border-left: none;
  box-shadow: 0 1px 2px rgba(36, 50, 58, 0.06);
}
.hb-label {
  margin: 0 0 0.6rem 0.5rem;
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--hb-muted);
  user-select: none;
}
#sidebar-toc .nav-item,
.on-this-page .nav-item {
  padding: 0 !important;
  margin: 0;
}
#sidebar-toc .nav-link {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem !important;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--hb-muted) !important;
  border-radius: 0;
  transition: background-color 160ms ease, color 160ms ease;
}
/* read by screen readers only (e.g. "Domain 1:" before the chapter name) */
.hb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
/* chapter number badge (Domain 1–5; blank for Welcome / Algorithms) */
.hb-toc-num {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.02rem;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1;
  color: var(--hb-muted);
  background-color: color-mix(in srgb, var(--hb-ink) 7%, transparent);
  border-radius: 3px;
}
.hb-toc-num--blank {
  background: none;
}
#sidebar-toc .nav-link.active .hb-toc-num:not(.hb-toc-num--blank) {
  color: #fff;
  background-color: var(--hb-blue);
}
#sidebar-toc .nav-link:hover {
  color: var(--hb-ink) !important;
  background-color: color-mix(in srgb, var(--hb-ink) 4%, transparent);
}
#sidebar-toc .nav-link.active {
  color: var(--hb-blue) !important;
  font-weight: 600;
  background-color: color-mix(in srgb, var(--hb-blue) 10%, transparent);
}
html[data-theme="dark"] #sidebar-toc .nav-link.active {
  color: #cfe3ee !important;
  background-color: color-mix(in srgb, var(--hb-blue) 18%, transparent);
}
/* phones: a full-width "Contents" toggle */
.hb-toc-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  min-height: 2.75rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--hb-ink);
  background-color: var(--hb-surface);
  border: 1px solid var(--hb-line);
  border-radius: 6px;
}
@media (max-width: 991.98px) {
  /* phones / tablets: just the "Contents" toggle under the navbar */
  .hb-brand {
    display: none;
  }
  #burger-toc {
    padding: 0;
  }
  #toc-collapse .nav {
    margin-top: 0.5rem;
  }
}

/* ---- Article --------------------------------------------------------------- */
.hb-article {
  max-width: 46rem;
  margin: 0 auto;
  font-size: 1.02rem;
  line-height: 1.7;
}
.hb-article h1 {
  margin: 0 0 1.25rem;
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--hb-heading) !important; /* page title only; the site's dark theme recolours headings */
}
/* domain pages: "Domain N" as a small label above the title */
.hb-eyebrow {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
  color: var(--hb-muted);
}
.hb-article h2,
.hb-article h3,
.hb-article h4 {
  position: relative;
  margin: 2.5rem 0 0.75rem;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.01em;
  /* muted: between the ink and the grey of secondary text */
  color: color-mix(in srgb, var(--hb-ink) 55%, var(--hb-muted)) !important;
}
html[data-theme="dark"] .hb-article h2,
html[data-theme="dark"] .hb-article h3,
html[data-theme="dark"] .hb-article h4 {
  color: var(--hb-text) !important;
}
.hb-article h2 {
  font-size: 1.45rem;
}
/* text under a question lines up with the question, not the number badge
   (badge 1.45rem + gap 0.6rem) */
.hb-article h3.hb-q ~ :not(h1):not(h2):not(h3):not(hr):not(img) {
  margin-left: 2.05rem;
}
@media (max-width: 575.98px) {
  .hb-article h3.hb-q ~ :not(h1):not(h2):not(h3):not(hr):not(img) {
    margin-left: 0;
  }
}
/* question headings: the number in a small square (as in the RoB Assistant) */
.hb-article h3.hb-q {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.hb-qnum {
  flex: none;
  display: inline-grid;
  place-items: center;
  min-width: 1.45rem;
  height: 1.45rem;
  margin-top: 0.08em;
  padding: 0 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  color: var(--hb-blue);
  background-color: color-mix(in srgb, var(--hb-blue) 12%, transparent);
  border-radius: 3px;
}
.hb-article h3 {
  font-size: 1.2rem;
}
.hb-article h4 {
  font-size: 1.05rem;
}
.hb-article hr {
  margin: 0 0 1.25rem;
  color: var(--hb-line);
  opacity: 1;
}
.hb-article h1 + hr {
  display: none; /* the header image follows directly */
}
.hb-article p,
.hb-article li {
  color: var(--hb-text);
}
.hb-article strong,
.hb-article b {
  color: var(--hb-ink);
}
.hb-article a {
  color: var(--hb-blue);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--hb-blue) 35%, transparent);
  text-underline-offset: 0.15em;
  transition: text-decoration-color 160ms ease;
}
.hb-article a:hover {
  text-decoration-color: var(--hb-blue);
}
.hb-article code {
  padding: 0.1em 0.35em;
  font-size: 0.88em;
  color: var(--hb-ink) !important;
  background-color: color-mix(in srgb, var(--hb-ink) 6%, transparent);
  border-radius: 3px;
}
.hb-article a code {
  color: var(--hb-blue) !important;
  background-color: color-mix(in srgb, var(--hb-blue) 9%, transparent);
}

/* references to other questions ("#17"): a quiet link, also inside headings */
.hb-article a.hb-qref {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: color-mix(in srgb, var(--hb-blue) 55%, transparent);
  text-underline-offset: 0.18em;
}
.hb-article a.hb-qref:hover,
.hb-article a.hb-qref:focus-visible {
  color: var(--hb-blue);
  text-decoration-style: solid;
}
/* header images: square top, rounded bottom (as elsewhere on the site) */
.hb-article img {
  display: block;
  width: 100%;
  height: 11rem;
  margin: 0 0 1.75rem;
  object-fit: cover;
  object-position: center;
  border-radius: 0 0 0.5rem 0.5rem !important;
}

/* heading permalinks: a quiet # icon in front, on hover */
.heading-permalink {
  position: absolute;
  left: -1.6rem;
  top: 0.05em;
  color: var(--hb-muted) !important;
  text-decoration: none !important;
  opacity: 0;
  transition: opacity 160ms ease;
}
.hb-article h2:hover .heading-permalink,
.hb-article h3:hover .heading-permalink,
.hb-article h4:hover .heading-permalink,
.heading-permalink:focus-visible {
  opacity: 1;
}
@media (max-width: 991.98px) {
  .heading-permalink {
    display: none;
  }
}

/* rating words in the text ("Yes/PY", "High risk", …): the muted RoB colours */
.hb-article [style*="forestgreen"] {
  color: var(--hb-low) !important;
}
.hb-article [style*="firebrick"],
.hb-article [style*="#dc3545"],
.hb-article [style*="color: red"] {
  color: var(--hb-high) !important;
}
.hb-article [style*="#8B8000"],
.hb-article [style*="#8b8000"],
.hb-article [style*="darkgoldenrod"] {
  color: var(--hb-some) !important;
}

/* algorithm boxes (Algorithms page) */
.hb-article .bg-light.border {
  padding: 1rem 1.25rem !important;
  background-color: var(--hb-canvas) !important;
  border: 1px solid var(--hb-line) !important;
  border-radius: 0 !important;
  font-size: 0.95rem;
  line-height: 1.75;
}
.hb-article .bg-light.border p {
  margin: 0;
}
/* long rules (Domains 3–5): one line each, the box scrolls sideways */
.hb-article .scrollable-div {
  max-width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  overscroll-behavior-x: contain;
}

/* ---- Previous / next ------------------------------------------------------ */
.hb-pager {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  max-width: 46rem;
  margin: 3.5rem auto 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hb-line);
}
.hb-pager__link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  max-width: 48%;
  padding: 0.85rem 1.15rem;
  color: var(--hb-ink);
  text-decoration: none;
  background-color: var(--hb-surface);
  border: 1px solid var(--hb-line);
  border-bottom-width: 3px;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(36, 50, 58, 0.06);
  transition: border-color 160ms ease, transform 90ms ease;
}
.hb-pager__link--next {
  margin-left: auto;
  align-items: flex-end;
  text-align: right;
}
.hb-pager__link:hover,
.hb-pager__link:focus-visible {
  color: var(--hb-ink);
  border-color: color-mix(in srgb, var(--hb-blue) 40%, var(--hb-line));
}
.hb-pager__link:active {
  transform: translateY(2px);
}
.hb-pager__dir {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hb-muted);
}
.hb-pager__title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--hb-blue);
}

/* ---- Right: on this page ---------------------------------------------------- */
.on-this-page .hb-label {
  margin: 2.25rem 0 0.6rem;
}
.on-this-page .nav-link {
  padding: 0.35rem 0 0.35rem 0.75rem !important;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--hb-muted) !important;
  border-left: 2px solid var(--hb-line);
  transition: color 160ms ease, border-color 160ms ease;
}
.on-this-page .nav-link:hover {
  color: var(--hb-ink) !important;
}
/* current section (set by highlight-sidebar.js) */
.on-this-page .nav-link.active-otp {
  color: var(--hb-blue) !important;
  border-left-color: var(--hb-blue);
  background: none;
}
.handbook-theme-switch {
  padding: 1.5rem 0 0.5rem;
}
html[data-theme="dark"] .on-this-page #metapsy-theme-toggle {
  color: #e2e8eb !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
}

/* ---- Corner buttons: back (bottom left), expand (bottom right) ------------- */
.hb-corner-btn {
  position: fixed;
  bottom: 0.75rem;
  z-index: 1031;
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--hb-muted);
  text-decoration: none;
  background-color: var(--hb-surface);
  border: 1px solid var(--hb-line);
  border-radius: 0;
  transition: border-color 160ms ease, color 160ms ease;
}
#back-btn {
  left: 0.75rem;
}
#expand-btn {
  right: 0.75rem;
}
.hb-corner-btn:hover,
.hb-corner-btn:focus-visible {
  color: var(--hb-blue);
  border-color: color-mix(in srgb, var(--hb-muted) 40%, var(--hb-line));
}

/* ---- Expanded: the site navbar is hidden ------------------------------------- */
html.hb-expanded .navigation {
  display: none;
}
html.hb-expanded .rob-handbook {
  --hb-nav-h: 0px;
}
html.hb-expanded {
  scroll-padding-top: 1.5rem;
}
@media (max-width: 991.98px) {
  html.hb-expanded #sidebar-toc {
    padding-top: 1.25rem;
  }
}
