/* Added for this piece. */
.piece-body h3 { max-width: 34rem; margin: 1.75rem 0 0.35rem; font-size: 1.3125rem; font-weight: 600; line-height: 1.3; }

.piece-body h2 + .loop-summary { margin-top: -0.25rem; }

.loop-summary, .tags, .refline { max-width: 34rem; margin: 0 0 0.75rem; font: 300 0.9375rem/1.4 var(--label); letter-spacing: 0.06em; }

.tags { font-size: 0.8125rem; margin-bottom: 0.6rem; }

.refline { font-size: 0.875rem; }

.aside .fig { max-width: 24rem; }

.fig .fig-caption { font-size: 13px; }

.fig .fig-big { font-size: 18px; }

/* The loops: one scene per loop, each drawn on the same diagram. A scene arrives showing the loop before it,
   then zooms out and brings its own loop in, so stepping through them reads as one figure growing. */
.loops-fig svg { display: block; width: 100%; height: auto; }

.loops-fig text { fill: var(--accent); font: 300 14px var(--label); letter-spacing: 0.02em; }

.loops-fig .ring-name { font-size: 13px; }

.loops-fig .center, .loops-fig .op { font-size: 11.5px; }

.loops-fig .pill { fill: var(--paper); stroke: var(--accent); stroke-width: 1.1; }

.loops-fig .ring { fill: none; stroke: var(--accent); stroke-width: 1.1; }

.loops-fig .ff { stroke-dasharray: 4 4; }

.loops-fig [data-st] { transition: opacity 0.6s ease; }

.loop-scene[data-show="1"] [data-st="2"] { opacity: 0; }

.loop-scene[data-show="1"] [data-st="3"] { opacity: 0; }

.loop-scene[data-show="1"] [data-st="4"] { opacity: 0; }

.loop-scene[data-show="1"] [data-st="5"] { opacity: 0; }

.loop-scene[data-show="2"] [data-st="1"] { opacity: 0.4; }

.loop-scene[data-show="2"] [data-st="3"] { opacity: 0; }

.loop-scene[data-show="2"] [data-st="4"] { opacity: 0; }

.loop-scene[data-show="2"] [data-st="5"] { opacity: 0; }

.loop-scene[data-show="3"] [data-st="1"] { opacity: 0.4; }

.loop-scene[data-show="3"] [data-st="2"] { opacity: 0.4; }

.loop-scene[data-show="3"] [data-st="4"] { opacity: 0; }

.loop-scene[data-show="3"] [data-st="5"] { opacity: 0; }

.loop-scene[data-show="4"] [data-st="1"] { opacity: 0.4; }

.loop-scene[data-show="4"] [data-st="2"] { opacity: 0.4; }

.loop-scene[data-show="4"] [data-st="3"] { opacity: 0.4; }

.loop-scene[data-show="4"] [data-st="5"] { opacity: 0; }

.loop-scene[data-show="5"] [data-st="1"] { opacity: 0.4; }

.loop-scene[data-show="5"] [data-st="2"] { opacity: 0.4; }

.loop-scene[data-show="5"] [data-st="3"] { opacity: 0.4; }

.loop-scene[data-show="5"] [data-st="4"] { opacity: 0.4; }

.loops-fig .act-out { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.5); transition: opacity 0.45s ease, transform 0.6s cubic-bezier(.4,0,.2,1); }

.loops-fig .act-in { transition: opacity 0.4s ease 0.25s; }

.loop-scene[data-show="1"] .act-out { opacity: 1; transform: none; }

.loop-scene[data-show="1"] .act-in { opacity: 0; transition-delay: 0s; }

.loops-fig { cursor: pointer; }

.scenes .loop-scene { display: grid; gap: 1rem; grid-template-areas: "lead" "fig" "text" "key"; }

.scenes .loop-scene > .loops-lead { grid-area: lead; }

.scenes .loop-scene > .fig-box { grid-area: fig; }

.scenes .loop-scene > .loop-text { grid-area: text; }

.scenes .loop-scene > .loops-key { grid-area: key; }

.scenes .loop-scene .loops-fig svg { width: 100%; max-height: calc(100svh - 22rem); }

/* The lead belongs to the first loop. Stepping on to the second, it fades and folds away; later loops start without it. */
.scenes .seq-cell > .loop-scene > p.loops-lead { opacity: 1; visibility: visible;
  transition: opacity 0.4s ease, visibility 0.4s, max-height 0.6s cubic-bezier(.4,0,.2,1), margin 0.6s cubic-bezier(.4,0,.2,1); }

.scenes .seq-cell > .loop-scene.cont:not(.lead-in) > p.loops-lead { opacity: 0; visibility: hidden; }

@media (min-width: 66rem) {
  .scenes .seq-cell > .loop-scene > p.loops-lead { max-height: 8em; overflow: hidden; }
  .scenes .seq-cell > .loop-scene.cont:not(.lead-in) > p.loops-lead { max-height: 0; margin-bottom: -1rem; }
}

@media (min-width: 66rem) {
  .scenes .seq-stage:has(.loop-scene) { max-width: 76rem; }
  .scenes .loop-scene { grid-template-columns: minmax(0, 17rem) minmax(0, 1fr); grid-template-rows: auto 1fr auto; column-gap: 2.5rem;
    grid-template-areas: "lead lead" "text fig" "key key"; align-items: start; }
  /* the caption sits level with the diagram's middle; a footnote, if any, centered at the foot like the lead */
  .scenes .loop-scene > .loop-text { align-self: center; }
  .scenes .loop-scene > .loops-key { align-self: end; justify-self: center; text-align: center; max-width: 36rem; }
  .scenes .loop-scene > .fig-box { align-self: center; }
  /* the lead heads the whole first loop, text and diagram both; when it folds away the diagram takes its room */
  .scenes .loop-scene > .loops-lead { justify-self: center; text-align: center; max-width: 36rem; }
  /* the loops stage reads from the top: lead at the top edge, the diagram filling the room below */
  .scenes .seq-stage:has(.loop-scene) { justify-content: flex-start; padding-top: 1.25rem; }
  .scenes .seq-stage:has(.loop-scene) .seq-cell { flex: 1 1 auto; min-height: 0; }
  .scenes .seq-cell > .loop-scene { height: 100%; align-content: start; }
  .scenes .loop-scene .loops-fig svg { max-height: calc(100svh - 2.25rem - 4rem); transition: max-height 0.6s cubic-bezier(.4,0,.2,1); }
  .scenes .loop-scene:not(.cont) .loops-fig svg, .scenes .loop-scene.lead-in .loops-fig svg { max-height: calc(100svh - 2.25rem - 4rem - 5.5rem); }
  /* the footnote row under the first loop takes its height from the diagram */
  .scenes .loop-scene:has(> .loops-key) .loops-fig svg { max-height: calc(100svh - 2.25rem - 4rem - 5.5rem - 4rem); }
}

.essay .loop-scene.cont > .loops-lead { display: none; }

.loop-scene.snap, .loop-scene.snap * { transition: none !important; }

.essay .fig-box .loops-fig { max-width: 30rem; margin: 0.5rem 0 0; }

.loops-lead { color: var(--quiet); max-width: 34rem; }

.loops-key { max-width: 34rem; font: 300 0.8125rem/1.45 var(--label); letter-spacing: 0.04em; }

/* A sequence: continuing scenes share one pinned stage. Each step is its own stop; stepping swaps the paragraph
   and the figure carries on from where the last step's figure ended. */
.scenes .slide.seq { display: block; padding: 0; min-height: 0; scroll-snap-align: none; }

.scenes .seq-stage { position: sticky; top: 2.25rem; height: calc(100svh - 2.25rem); display: flex; flex-direction: column;
  justify-content: center; padding: 2rem 0; box-sizing: border-box; }

.scenes .seq-stage > h2:first-child, .scenes .seq-stage > h3:first-child { margin-top: 0; }

.scenes .seq-cell { display: grid; }

.scenes .seq-cell > .scene { grid-area: 1 / 1; }

.scenes .seq-cell > .scene:not(.cur) { visibility: hidden; }

.scenes .seq-cell > .scene > p { transition: opacity 0.35s ease 0.1s; }

.scenes .seq-cell > .scene:not(.cur) > p { opacity: 0; transition: none; }

.scenes .seq-stops { margin-top: calc(-100svh + 2.25rem); }

.scenes .seq-stop { height: calc(100svh - 2.25rem); scroll-snap-align: start; scroll-snap-stop: always; }

.essay .seq-stage, .essay .seq-cell { display: contents; }

.essay .seq-stops { display: none; }

@media (prefers-reduced-motion: reduce) { .loops-fig [data-st], .loops-fig .act-out, .loops-fig .act-in, .seq-cell > .scene > p { transition: none; } }

/* Scenes: the essay as slides. One scroll, swipe or key moves one slide; each slide's content rises in as it arrives.
   Essay: the same text read straight through, each figure folded away below its paragraph. */
html.scenes { scroll-snap-type: y mandatory; scroll-padding-top: 2.25rem; }

.scene { display: flex; flex-direction: column; }

.scenes .slide { min-height: calc(100svh - 2.25rem); display: flex; flex-direction: column; justify-content: center;
  padding: 2rem 0; scroll-snap-align: start; scroll-snap-stop: always; }

.scenes .slide > h2:first-child, .scenes .slide > h3:first-child { margin-top: 0; }

html.scenes body > .top { scroll-snap-align: start; }

.scenes .foot { scroll-snap-align: end; }

.scenes .scene { gap: 1.25rem; margin: 0 0 1rem; }

.scenes .scene > p { max-width: 34rem; margin: 0; }

.scenes .fig-box > summary { display: none; }

.scenes .fig-box .viz { max-width: 30rem; margin: 0; }

.scenes.focus .slide > * { opacity: 0; transform: translateY(18px); transition: opacity 0.5s ease, transform 0.6s cubic-bezier(.2,.7,.2,1); }

.scenes.focus .slide.here > * { opacity: 1; transform: none; }

.scenes.focus .slide.here > *:nth-child(2) { transition-delay: 0.06s; }

.scenes.focus .slide.here > *:nth-child(3) { transition-delay: 0.12s; }

.scenes.focus .slide.here > *:nth-child(4) { transition-delay: 0.18s; }

.scenes.focus .slide.here > *:nth-child(n+5) { transition-delay: 0.24s; }

.fig-box { margin: 0; }

.fig-box > summary { cursor: pointer; list-style: none; color: var(--accent); font: 300 0.875rem/1.4 var(--label); letter-spacing: 0.06em; }

.fig-box > summary::-webkit-details-marker { display: none; }

.fig-box > summary::before { content: "+ "; }

.fig-box[open] > summary::before { content: "− "; }

.essay .slide { display: contents; }

.essay .scene > .fig-box { order: 2; margin: -0.25rem 0 1.25rem; }

.essay .fig-box .viz { max-width: 24rem; margin: 0.5rem 0 0; }

@media (prefers-reduced-motion: reduce) {
  html.scenes { scroll-snap-type: y proximity; }
  .scenes.focus .slide > * { transition: none; transform: none; opacity: 1; }
}

/* Continuing scenes: the figure picks up where the last one stopped, so it arrives without rising or fading in. */
.scenes.focus .slide > .scene.cont { opacity: 1; transform: none; transition: none; }

.scenes.focus .slide > .scene.cont > p { opacity: 0; transform: translateY(18px); transition: opacity 0.5s ease 0.1s, transform 0.6s cubic-bezier(.2,.7,.2,1) 0.1s; }

.scenes.focus .slide.here > .scene.cont > p { opacity: 1; transform: none; }

.scene.cont .viz svg { transition: none; }

.pull { font-size: clamp(1.45rem, 2.6vw, 1.85rem); line-height: 1.35; max-width: 30rem; }

.essay .pull { font-size: inherit; line-height: inherit; max-width: 34rem; }

/* Contents: a rail to the right of the text. The introduction, the loops (with each loop under them, and the
   current loop's practices under it) and the closing each get a stretch of rail with a tick per slide or step.
   The rail fills as you read; the current tick is longer and blue. Where there is no room for a column, the
   section name in the bar opens the same list. */
.toc { font: 300 0.8125rem/1.35 var(--label); letter-spacing: 0.04em; }

.toc ol { list-style: none; margin: 0; padding: 0; }

.toc a { color: var(--quiet); text-decoration: none; }

.toc a:hover { color: var(--accent); }

.toc a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toc-row { position: relative; padding-left: 0.9rem; min-height: calc(var(--n, 1) * 0.4rem + 0.5rem); margin-bottom: 0.55rem; }

.toc-row > a { display: block; }

.toc-item.cur > .toc-row > a, .toc-item.read > .toc-row > a { color: var(--ink); }

.toc-ticks { position: absolute; left: 0; top: 0.2rem; bottom: 0; display: flex; flex-direction: column; justify-content: space-between;
  border-left: 1px solid var(--quiet); }

.toc-ticks i { display: block; width: 0.25rem; height: 1px; background: var(--quiet); transition: width 0.3s ease, background 0.3s ease; }

.toc-ticks i.read { background: var(--ink); }

.toc-ticks i.here { width: 0.55rem; background: var(--accent); }

.toc-item.read > .toc-row > .toc-ticks, .toc-item.cur > .toc-row > .toc-ticks { border-left-color: var(--ink); }

.toc-kids { padding-left: 0.9rem !important; }

.toc-sub { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.4s ease; margin: -0.25rem 0 0 0.9rem; }

.toc-sub > ol { overflow: hidden; }

.toc-item.cur > .toc-sub { grid-template-rows: 1fr; }

.toc-sub li { margin-bottom: 0.35rem; font-size: 0.75rem; }

.toc-sub li:last-child { margin-bottom: 0.6rem; }

.toc-sub a.here { color: var(--accent); }

.fn-ref { font: 300 0.7em var(--label); line-height: 0; margin-left: 0.1em; }

.fn-ref a { text-decoration: none; }

.footnote { color: var(--quiet); }

.footnote a { color: var(--quiet); }

.loop-summary { color: var(--quiet); font: 300 0.9375rem/1.4 var(--label); letter-spacing: 0.04em; }

.viz-bar .where { all: unset; cursor: default; color: var(--ink); }

@media (min-width: 54rem) {
  .piece-body { position: relative; }
  .piece-body h2, .piece-body h3 { max-width: 34rem; }
  /* the column sits at the page's right edge; anything wide stops short of it */
  .toc { position: absolute; top: 3.75rem; bottom: 0; right: 0; width: 10rem; }
  .toc > ol { position: sticky; top: 3.75rem; max-height: calc(100svh - 4.75rem); overflow: auto; }
  .seq-stage, .slide:not(.seq) { margin-right: 12rem; }
}

@media (max-width: 53.99rem) {
  .viz-bar button.where { cursor: pointer; }
  .viz-bar button.where::after { content: " ▾"; color: var(--accent); }
  .toc { display: none; }
  .toc.open { display: block; position: fixed; z-index: 4; top: 2.3rem; left: 0; right: 0; max-height: 75svh; overflow: auto;
    padding: 1rem var(--gutter); background: var(--paper); box-shadow: 0 1px var(--quiet); }
}

@media (prefers-reduced-motion: reduce) { .toc-ticks i, .toc-sub { transition: none; } }

/* One control for every figure, in a bar that also names the loop being read. */
.piece { --head: 3rem; }

.viz-bar { position: sticky; top: 0; z-index: 3; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  margin: 0 calc(-1 * var(--gutter)) 1.25rem; padding: 0.5rem var(--gutter); background: var(--paper); box-shadow: 0 1px var(--quiet);
  font: 300 0.8125rem/1.4 var(--label); letter-spacing: 0.06em; }

.viz-bar .where { color: var(--ink); }

.viz-bar button { all: unset; cursor: pointer; color: var(--accent); white-space: nowrap; }

.viz-bar button:hover { text-decoration: underline; text-underline-offset: 0.3em; }

.viz-bar button:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }

.viz { cursor: pointer; }

.viz:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

@media (prefers-reduced-motion: reduce) { .viz { cursor: default; } }

.viz svg { transition: opacity 0.4s ease; }

.jsv .viz:not(.on) svg { opacity: 0; }

.viz.paused * { animation-play-state: paused !important; }

/* The bar names the section only once the page title has scrolled up behind it. */
.viz-bar .where { transition: opacity 0.25s ease, visibility 0.25s; }

.viz-bar.title-watch:not(.past-title) .where { opacity: 0; visibility: hidden; }

@media (prefers-reduced-motion: reduce) { .viz-bar .where { transition: none; } }
