/* Native research article: continuous page scrolling below the explorer. */
.research-detail .native-writeup {
  max-width: 900px;
  margin: 56px auto 0;
  padding-top: 40px;
}

.writeup-heading { max-width: 820px; margin: 0 auto 40px; }
.writeup-heading h2 {
  margin: 12px 0;
  font-size: clamp(1.65rem, 3vw, 2.2rem);
  line-height: 1.25;
  font-weight: 500;
}
.writeup-byline { color: var(--muted); margin: 0; }
.writeup-prose {
  --paragraph-gap: 20px;
  --figure-gap: 32px;
  --section-gap: 40px;
  display: flex;
  flex-direction: column;
  font-size: 1rem;
  line-height: 1.8;
}
.writeup-prose > p, .writeup-prose > h3 {
  width: 100%;
  max-width: 820px;
  margin-inline: auto;
}
.writeup-prose > p { margin-block: 0; }
.writeup-prose > p + p { margin-top: var(--paragraph-gap); }
.writeup-prose > h3 {
  margin-block: var(--section-gap) 16px;
  font-size: 1.4rem;
  line-height: 1.3;
  font-weight: 500;
}
.writeup-prose > h3:first-child { margin-top: 0; }
.writeup-prose a { color: var(--accent); text-underline-offset: 4px; overflow-wrap: anywhere; }
.writeup-prose > .writeup-figure {
  width: 100%;
  margin: var(--figure-gap) 0 0;
}
.writeup-prose > .writeup-figure + p,
.writeup-prose > .writeup-figure + .writeup-figure {
  margin-top: var(--figure-gap);
}
.writeup-figure a { display: block; cursor: zoom-in; }
.writeup-figure img { display: block; width: 100%; height: auto; }
.writeup-figure figcaption {
  max-width: 820px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.65;
}
.native-writeup .document-actions { max-width: 820px; margin: 32px auto 0; }
@media (max-width: 700px) {
  .research-detail .native-writeup { margin-top: 32px; padding-top: 28px; }
  .writeup-heading { margin-bottom: 28px; }
  .writeup-prose {
    --paragraph-gap: 16px;
    --figure-gap: 24px;
    --section-gap: 32px;
  }
}

/* Figure 1 has transparent export padding; show only the chart in the article. */
.population-figure > a {
  aspect-ratio: 1066 / 669;
  overflow: hidden;
}

.population-figure > a > img {
  margin-top: -13.0394%;
}

/* Keep project contents available throughout the graph and write-up. */
.research-detail .detail-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.research-detail .detail-section {
  scroll-margin-top: 88px;
}

@media (max-width: 700px) {
  .research-detail .detail-section {
    scroll-margin-top: 132px;
  }
}

/* Persistent contents navigation, independent of page scroll position. */
.research-detail .detail-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  box-sizing: border-box;
}

.research-detail .detail-shell {
  padding-top: 100px;
}

@media (max-width: 700px) {
  .research-detail .detail-shell {
    padding-top: 140px;
  }
}

/* A quiet left contents rail, with no full-width header. */
.project-contents {
  position: fixed;
  top: 48px;
  left: max(24px, calc((100vw - 1400px) / 2));
  width: 180px;
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  padding-right: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  scrollbar-width: thin;
}
.contents-back { color: var(--muted); text-decoration: none; }
.contents-label {
  margin: 32px 0 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.7rem;
}
.project-contents nav { display: grid; gap: 10px; }
.project-contents nav a {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  text-decoration: none;
}
.project-contents nav a:hover,
.project-contents nav a[aria-current="location"] {
  color: var(--accent-dark);
  border-left-color: var(--accent);
}
.research-detail .detail-shell {
  width: min(1120px, calc(100% - 280px));
  margin-left: max(240px, calc((100vw - 1400px) / 2 + 240px));
  margin-right: 40px;
  padding-top: 48px;
}
.research-detail .detail-section,
.research-detail .writeup-prose h3,
.research-detail #project-title { scroll-margin-top: 32px; }
.research-detail .site-footer {
  width: auto;
  margin-left: max(240px, calc((100vw - 1400px) / 2 + 240px));
}
@media (max-width: 900px) {
  .project-contents { width: 140px; left: 16px; font-size: 0.8rem; }
  .research-detail .detail-shell {
    width: calc(100% - 200px);
    margin-left: 176px;
    margin-right: 24px;
  }
  .research-detail .site-footer { margin-left: 176px; }
}
@media (max-width: 600px) {
  .project-contents {
    top: 0;
    left: 0;
    width: 100%;
    max-height: 90px;
    padding: 10px 16px;
    box-sizing: border-box;
    background: var(--surface);
    z-index: 20;
    border-bottom: 1px solid var(--line);
  }
  .contents-label { display: none; }
  .project-contents nav {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    margin-top: 8px;
    padding-bottom: 4px;
  }
  .project-contents nav a { white-space: nowrap; padding-left: 0; border-left: 0; }
  .research-detail .detail-shell {
    width: calc(100% - 32px);
    margin-inline: auto;
    padding-top: 112px;
  }
  .research-detail .detail-section,
  .research-detail .writeup-prose h3,
  .research-detail #project-title { scroll-margin-top: 112px; }
  .research-detail .site-footer { margin-inline: 16px; }
}

/* Keep the rail brief until the reader opens the write-up contents. */
.writeup-contents summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.writeup-contents summary::-webkit-details-marker { display: none; }
.writeup-contents summary::after { content: "+"; }
.writeup-contents[open] summary::after { content: "−"; }
.writeup-contents summary:hover,
.writeup-contents[open] summary { color: var(--accent-dark); }
.writeup-contents summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}
.writeup-contents-links {
  display: grid;
  gap: 10px;
  padding: 14px 0 0 12px;
  font-size: 0.8rem;
}
@media (max-width: 600px) {
  .project-contents:has(.writeup-contents[open]) {
    max-height: min(55dvh, 380px);
    overflow-y: auto;
  }
  .project-contents nav { align-items: flex-start; }
  .writeup-contents summary { padding-left: 0; border: 0; }
  .writeup-contents-links { padding-left: 0; }
}

/* Separate the return link from the contents rail. */
.project-back-link {
  position: fixed;
  top: 24px;
  left: max(24px, calc((100vw - 1400px) / 2));
  z-index: 25;
  color: var(--accent);
  font-size: 0.9rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}
.project-contents { top: 88px; max-height: calc(100dvh - 120px); }
.contents-label { margin-top: 0; }
@media (max-width: 900px) {
  .project-back-link { left: 16px; }
}
@media (max-width: 600px) {
  .project-back-link { top: 12px; }
  .project-contents { top: 40px; max-height: 50px; }
  .project-contents nav { margin-top: 0; }
  .project-contents:has(.writeup-contents[open]) { max-height: min(50dvh, 340px); }
  .project-back-link { background: var(--surface); }
}

/* Research scope reads as a quiet summary rather than a row of callouts. */
.scope-heading { max-width: 820px; margin-bottom: 24px; }
.scope-heading h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  line-height: 1.3;
  font-weight: 500;
}
.scope-heading p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.research-detail .project-scope .project-metrics {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
  gap: 24px;
}
.research-detail .project-scope .project-metric {
  border: 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.research-detail .project-scope .project-metric strong {
  font-size: 1.8rem;
  font-weight: 500;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.research-detail .project-scope .project-metric span {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
  line-height: 1.6;
}

/* A shared outer measure aligns every major project section. */
.research-detail .detail-hero,
.research-detail .detail-section {
  width: 100%;
  max-width: 900px;
  box-sizing: border-box;
  margin-inline: auto;
}

.research-detail .detail-hero h1 {
  max-width: none;
}

/* Compact overview and explorer preserve the article's scrolling rhythm. */
.research-detail .detail-hero { container-type: inline-size; }
.research-detail .detail-hero h1 {
  font-size: clamp(1.2rem, 3.25cqi, 1.85rem);
  line-height: 1.3;
  letter-spacing: -0.025em;
}
.research-detail #network .tall-frame iframe {
  height: clamp(440px, 66vh, 600px);
  min-height: 0;
}
.research-detail #network .section-heading { margin-bottom: 20px; }
.network-open-link {
  margin: 12px 0 0;
  font-size: 0.85rem;
}
.network-open-link a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
@media (max-width: 600px) {
  .research-detail .detail-hero h1 { font-size: 1.75rem; }
  .research-detail #network .tall-frame iframe { height: 500px; }
}

/* Let the overview and scope flow without stacked separators. */
.research-detail .detail-shell { padding-top: 32px; }
.research-detail .detail-hero { margin-bottom: 0; }
.research-detail .detail-hero .eyebrow { margin: 0 0 8px; }
.research-detail .detail-hero h1 { margin: 0; }
.research-detail .detail-hero > p:not(.eyebrow) { margin: 12px 0; }
.research-detail .detail-hero .detail-tags { margin: 12px 0 0; }
.research-detail .project-scope {
  margin-top: 28px;
  padding-top: 0;
  padding-bottom: 0;
  border-top: 0;
}
.research-detail .project-scope .project-metric { border-top: 0; padding-top: 0; }
.research-detail .scope-heading { margin-bottom: 16px; }
.research-detail #network { margin-top: 28px; padding-top: 24px; }
@media (max-width: 600px) {
  .research-detail .detail-shell { padding-top: 112px; }
}

/* An academic opening: title, research question context, and the essential scale. */
.research-detail .detail-hero .project-summary {
  max-width: none;
  margin: 12px 0 0;
  font-size: 1rem;
  line-height: 1.65;
  color: var(--muted);
}
.scope-accessible-title {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.research-detail .project-scope { margin-top: 24px; }
.research-detail .project-scope .project-metrics { gap: 20px; }
.research-detail .project-scope .project-metric strong {
  font-size: 1.6rem;
  line-height: 1.2;
}
.research-detail .project-scope .project-metric span {
  margin-top: 5px;
  font-size: 0.8rem;
  line-height: 1.45;
}
.research-detail #network {
  margin-top: 28px;
  padding-top: 0;
  border-top: 0;
}

/* Equal columns keep all five scope figures on a consistent baseline. */
.research-detail .project-scope .project-metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.research-detail .project-scope .project-metric {
  min-width: 0;
  padding: 0;
}
.research-detail .project-scope .project-metric strong {
  display: block;
  white-space: nowrap;
  font-size: clamp(1.25rem, 2vw, 1.6rem);
}
@media (max-width: 900px) {
  .research-detail .project-scope .project-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px 16px;
  }
}
@media (max-width: 420px) {
  .research-detail .project-scope .project-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Center each scope statistic in an identical cell for even visual spacing. */
.research-detail .project-scope .project-metrics {
  gap: 24px 12px;
}
.research-detail .project-scope .project-metric {
  display: grid;
  grid-template-rows: auto 1fr;
  justify-items: center;
  align-content: start;
  row-gap: 8px;
  text-align: center;
}
.research-detail .project-scope .project-metric strong {
  margin: 0;
  line-height: 1.2;
}
.research-detail .project-scope .project-metric span {
  display: block;
  width: 100%;
  max-width: 145px;
  margin: 0;
  line-height: 1.5;
  font-size: 0.8rem;
}

.writeup-prose > ul, .writeup-prose > ol { width: 100%; max-width: 820px; box-sizing: border-box; margin: 0 auto 20px; padding-left: 24px; }
.writeup-prose li p { margin: 0 0 8px; }

.plot-instructions { margin: 0 0 12px; font-size: 0.8rem; color: var(--muted); }

/* Identical, borderless framing on both research pages. */
.research-detail .detail-section { border: 0; border-radius: 0; background: transparent; }

/* Clear inherited section padding so both pages share the title's outer edges. */
.research-detail .detail-section {
  padding-left: 0;
  padding-right: 0;
}
.research-detail #network .interactive-frame {
  width: 100%;
  box-sizing: border-box;
}

/* One shared content measure for research titles, figures, and prose. */
.research-detail {
  --research-content-width: 900px;
}
.research-detail .detail-hero,
.research-detail .detail-section,
.research-detail .native-writeup {
  width: 100%;
  max-width: var(--research-content-width);
  margin-inline: auto;
}
.research-detail .writeup-heading,
.research-detail .writeup-prose,
.research-detail .writeup-prose > p,
.research-detail .writeup-prose > h3,
.research-detail .writeup-prose > ul,
.research-detail .writeup-prose > ol,
.research-detail .writeup-figure figcaption,
.research-detail .native-writeup .document-actions {
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  margin-left: 0;
  margin-right: 0;
}
.research-detail .native-writeup {
  margin-top: 40px;
  padding-top: 24px;
}
.research-detail .writeup-heading { margin-bottom: 32px; }
@media (max-width: 700px) {
  .research-detail .native-writeup { margin-top: 28px; padding-top: 16px; }
  .research-detail .writeup-heading { margin-bottom: 24px; }
}

/* A quiet next read at the end of each research page. */
.research-detail .related-project {
  width: 100%;
  max-width: var(--research-content-width);
  box-sizing: border-box;
  margin: 40px auto 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
}
.related-project > span {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.related-project a {
  justify-self: start;
  color: var(--accent);
  font-size: 1rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}
.related-project a:hover { color: var(--ink); }

/* Make the related research link a clear, restrained call to action. */
.related-project a {
  display: inline-flex;
  align-items: center;
  gap: 20px;
  padding: 12px 16px;
  border: 1px solid #bfc9b9;
  border-radius: 3px;
  background: #f0f2ea;
  color: var(--accent-dark);
  font-size: 1.05rem;
  text-decoration: none;
}
.related-project a > span { font-size: 1.35rem; }
.related-project a:hover { background: #e7ecdf; border-color: var(--accent); }

/* The same editorial measure extends to every portfolio project. */
.research-detail .detail-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 40px;
}
.research-detail .detail-grid article > h2 {
  margin: 0 0 16px;
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1.3;
}
.research-detail .detail-grid article > p {
  font-size: 1rem;
  line-height: 1.8;
}
.research-detail .detail-grid article > p + p { margin-top: 20px; }
.research-detail .project-scope .four-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.credit-source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
}
@media (max-width: 700px) {
  .research-detail .project-scope .four-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Credit access has one title and a continuous opening into the article. */
.credit-detail .detail-hero > .writeup-byline {
  margin: 12px 0 0;
  font-size: 0.875rem;
  line-height: 1.6;
}
.credit-detail #writeup.native-writeup {
  margin-top: 32px;
  padding-top: 0;
}
@media (max-width: 700px) {
  .credit-detail #writeup.native-writeup { margin-top: 24px; }
}
