/* Deep-dive pages (/on/<slug>/) — fixed left contents rail + embedded film
   figures, inside the shared article system. Tokens come from site.css. */

.deep-dive .article-body h2[id],
.deep-dive .article-body h3[id] {
  scroll-margin-top: 24px;
}

.deep-dive .article-body {
  max-width: none;
}

/* contents */

.dd-toc-toggle {
  appearance: none;
  background: var(--chip);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
  text-align: left;
}

.dd-toc-list {
  display: none;
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.dd-toc.open .dd-toc-list {
  display: block;
}

.dd-toc-list > li {
  margin: 0 0 14px;
}

.dd-toc-list > li > a {
  font-family: var(--font-text);
  font-weight: 700;
  font-size: var(--size-body-ui);
  color: var(--text);
  text-decoration: none;
}

.dd-toc-list ol {
  list-style: none;
  margin: 6px 0 0;
  padding: 0 0 0 12px;
  border-left: 1px solid var(--line);
  display: grid;
  gap: 5px;
}

.dd-toc-list ol a {
  display: block;
  padding: 2px 0;
  font-size: var(--size-body-ui);
  line-height: 1.4;
  color: var(--muted);
  text-decoration: none;
}

.dd-toc-list a:hover {
  color: var(--text);
}

.dd-toc-list a[aria-current] {
  color: var(--accent);
}

@media (min-width: 960px) {
  .deep-dive .article-grid {
    grid-template-columns: 200px minmax(0, 1fr);
  }

  .dd-toc-toggle {
    display: none;
  }

  .dd-toc-list {
    display: block;
  }

  .dd-rail {
    max-height: calc(100vh - 48px);
    display: flex;
  }

  .dd-toc {
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
  }

  .dd-toc-title {
    flex: 0 0 auto;
    padding-bottom: 12px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
    font-family: var(--font-display);
    font-size: 20px;
    line-height: 1.15;
    letter-spacing: -0.01em;
  }

  .dd-toc-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
  }
}

/* the rail title would duplicate the h1 on mobile, where the rail stacks above it */
.dd-toc-title {
  display: none;
  color: var(--text);
  text-decoration: none;
}

@media (min-width: 960px) {
  .dd-toc-title {
    display: block;
  }
}

/* embedded films */

.dd-video {
  margin: 28px 0;
}

.dd-video .video-frame {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-media);
  background: #000;
}

.dd-video .video-frame iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.dd-video figcaption {
  margin-top: 10px;
  font-size: var(--size-body-ui);
  color: var(--muted);
}

@media (prefers-reduced-motion: no-preference) {
  html:has(.deep-dive) {
    scroll-behavior: smooth;
  }
}

/* citations — inline superscript markers and the reference list they point at */

.deep-dive .article-body [data-footnote-ref] {
  font-family: var(--font-text);
  font-size: 0.72em;
  font-weight: 700;
  padding: 0 1px 0 2px;
  color: var(--accent);
  text-decoration: none;
  scroll-margin-top: 24px;
}

.deep-dive .article-body [data-footnote-ref]::before {
  content: "[";
}

.deep-dive .article-body [data-footnote-ref]::after {
  content: "]";
}

.deep-dive .article-body [data-footnote-ref]:hover,
.deep-dive .article-body [data-footnote-ref]:target {
  text-decoration: underline;
}

.deep-dive .footnotes .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.deep-dive .footnotes ol {
  margin: 0;
  padding-left: 1.4em;
  display: grid;
  gap: 12px;
  counter-reset: none;
}

.deep-dive .footnotes li {
  font-size: var(--size-body-ui);
  line-height: 1.55;
  color: var(--muted);
  scroll-margin-top: 24px;
}

.deep-dive .footnotes li:target {
  color: var(--text);
}

.deep-dive .footnotes li p {
  margin: 0 0 6px;
}

.deep-dive .footnotes li p + p {
  padding-left: 12px;
  border-left: 1px solid var(--line);
  font-style: italic;
}

.deep-dive .footnotes a {
  color: var(--text);
}

.deep-dive .footnotes [data-footnote-backref] {
  color: var(--accent);
  text-decoration: none;
  padding-left: 4px;
}

/* figures — our diagrams and openly licensed images, always with a credit */

.dd-figure {
  margin: 32px 0;
}

.dd-figure svg {
  display: block;
  width: 100%;
  height: auto;
  color: var(--text);
}

.dd-figure img {
  display: block;
  /* never upscale a scan past its own resolution — an 1918 engraving blown up
     to the column width is worse than the same engraving at its real size */
  width: auto;
  max-width: 100%;
  height: auto;
  margin-inline: auto;
  border-radius: var(--radius-media);
}

/* A plate is line art on paper. It gets its own paper rather than being
   inverted or dropped onto the page background, which would misreport a
   public-domain engraving in dark mode. */
.dd-figure-plate img {
  background: #fdfcfa;
  padding: 20px;
}

.dd-figure figcaption {
  margin-top: 12px;
  font-size: var(--size-body-ui);
  line-height: 1.5;
  color: var(--muted);
}

.dd-figure .figure-credit {
  display: block;
  margin-top: 4px;
  font-size: var(--size-caps);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dd-figure .figure-credit a {
  color: inherit;
}

/* a diagram is drawn to the full column, not the reading measure */
@media (min-width: 960px) {
  .dd-figure-diagram {
    margin-left: -40px;
    margin-right: -40px;
  }
}

.deep-dive-wide .article-body {
  max-width: none;
}

.hl-bar {
  position: fixed;
  z-index: 20;
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.hl-bar[hidden] { display: none; }
.hl-bar button,
.hl-menu a {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-decoration: none;
}
.hl-bar button:hover,
.hl-menu a:hover { background: var(--chip); }
.hl-bar svg { width: 16px; height: 16px; }
.hl-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  min-width: 112px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.hl-menu[hidden] { display: none; }
.hl-menu a {
  width: auto;
  justify-content: start;
  padding: 0 10px;
  font: 13px/1 var(--font-sans);
}
.dd-home-toc {
  width: 100%;
  max-width: 660px;
  margin-top: 40px;
  border-top: 1px solid var(--line);
}
.dd-home-list {
  display: grid;
}
.deep-dive-home .dd-home-part h2 {
  margin: 0;
  padding: 28px 0 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 1.25rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.deep-dive-home .dd-home-part h2 a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}
.deep-dive-home .dd-home-part h2 a:hover {
  color: var(--accent);
}
.deep-dive-home .dd-home-part h2 span {
  display: inline-block;
  min-width: 2rem;
  color: var(--accent);
  font-size: var(--size-caps);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.dd-home-entry {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) 5rem;
  align-items: center;
  gap: 12px;
  min-height: 6.5rem;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}
.dd-home-entry-nested {
  margin-left: 3rem;
  width: calc(100% - 3rem);
}
.dd-home-entry:hover,
.dd-home-entry:focus-visible {
  background: var(--featured);
}
.dd-home-entry:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.dd-home-number {
  align-self: start;
  padding-top: 2px;
  color: var(--accent);
  font-family: var(--font-text);
  font-size: var(--size-caps);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dd-home-thumb {
  display: grid;
  width: 5rem;
  height: 3.75rem;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.dd-home-thumb-empty {
  border-color: transparent;
  background: transparent;
}
.dd-home-thumb img,
.dd-home-thumb svg {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  object-fit: contain;
  color: var(--text);
}
.dd-home-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.dd-home-copy strong {
  font-family: var(--font-text);
  font-size: 0.95rem;
  line-height: 1.2;
}
.dd-home-copy > span {
  color: var(--muted);
  font-family: var(--font-text);
  font-size: 0.9rem;
  line-height: 1.3;
}
.dd-toc-number {
  flex: 0 0 2.8rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.dd-toc-list a,
.dd-toc-list ol a {
  display: flex;
  gap: 4px;
}
.dd-toc-list ol ol {
  margin-top: 5px;
}
.dd-group-list {
  display: grid;
  border-top: 1px solid var(--line);
}
.dd-reference-section + .dd-reference-section {
  margin-top: 48px;
}
.dd-reference-section h2 {
  margin-bottom: 18px;
  font-size: 1.1rem;
}
.dd-reference-section h2 a {
  color: var(--text);
  text-decoration: none;
}
.dd-reference-section h2 a:hover {
  color: var(--accent);
}
@media (max-width: 600px) {
  .deep-dive-home .dd-home-part h2 {
    padding-top: 24px;
  }
  .dd-home-entry {
    grid-template-columns: 2.7rem minmax(0, 1fr) 4.25rem;
    gap: 10px;
    padding: 12px 0;
  }
  .dd-home-entry-nested {
    margin-left: 2.7rem;
    width: calc(100% - 2.7rem);
  }
  .dd-home-thumb {
    width: 4.25rem;
    height: 3.25rem;
  }
}
.dd-pager {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 48px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-family: var(--font-text);
  font-size: var(--size-body-ui);
}
.dd-pager a {
  color: var(--text);
  text-decoration: none;
}
.dd-pager a:hover {
  color: var(--accent);
}
