/* Articles: symmetric. The text block is 65 cells wide (odd) and centred on the window; figures are the same width.
   Centred lines must have an odd number of cells, or they fall half a cell off the grid.
   On tablets the block narrows to leave room for the contents rail; on wide screens the right margin holds the notes. */
body.article{
  --col-w:min(calc(65*var(--cell)),calc(100vw - 26*var(--cell)));
  --col-x:calc((100vw - var(--col-w))/2)}
/* tablets: rail on the left, nothing on the right, so rail and text are centred as one group */
@media (min-width:47.5em) and (max-width:72em){body.article{--col-x:calc((100vw - var(--col-w))/2 + 4*var(--cell))}}
@media (max-width:47.5em){body.article{--col-w:calc(100vw - 4*var(--cell));--col-x:calc(2*var(--cell))}}

.page{width:var(--col-w);margin-left:var(--col-x);padding:calc(3*var(--l)) 0 calc(5*var(--l));position:relative}

/* ---- title page ---- */
header.title{text-align:center}
header.title .dek,header.title .by,header.title .when{font-family:var(--mono)}
header.title .dek{margin-top:calc(2*var(--l))}
header.title .by,header.title .when{margin-top:var(--l)}
.abstract{width:min(calc(47*var(--cell)),100%);margin:calc(3*var(--l)) auto 0;padding:var(--l) calc(2*var(--cell));text-align:left;border:1px solid var(--ink)}
.abstract h2{font-size:var(--b);line-height:var(--l);margin-top:0;box-shadow:none}
@media (max-width:47.5em){header.title,header.title p{text-align:left}header.title br.c{display:none}h1{font-size:calc(2*var(--b))}}

/* ---- text ---- */
article h2{position:relative;margin-top:calc(2.5*var(--l));box-shadow:inset 0 -1px 0 var(--ink)}
article h3{position:relative;margin-top:calc(1.5*var(--l))}
article p{margin-top:var(--l)}
article h3+p{margin-top:calc(.5*var(--l))}
article p,.fig figcaption,.abstract p{text-align:justify;-webkit-hyphens:auto;hyphens:auto}
header.title p{text-align:center;-webkit-hyphens:manual;hyphens:manual}
header.title .abstract p{text-align:justify;-webkit-hyphens:auto;hyphens:auto}
.abstract p{margin-top:0}
article ol.refs{margin-top:var(--l);list-style:none;counter-reset:r}
article ol.refs li{counter-increment:r;padding-left:calc(5*var(--cell));text-indent:calc(-5*var(--cell));margin-top:var(--l)}
article ol.refs li::before{content:"[" counter(r) "] ";font-family:var(--mono)}

/* ---- figures: same width as the text, full outline ---- */
.fig{border:1px solid var(--ink);margin-top:calc(2*var(--l));transition:box-shadow .2s}
.fig.flash{box-shadow:0 0 0 3px var(--ink)}
.fig .stage{padding:var(--l) calc(2*var(--cell))}
.fig .controls{display:flex;flex-wrap:wrap;gap:0 calc(2*var(--cell));align-items:center;padding:0 calc(2*var(--cell)) var(--l);font-family:var(--mono)}
.fig .controls label{display:inline-flex;gap:var(--cell);align-items:center}
.fig input[type=number]{font:inherit;width:6ch;border:1px solid var(--ink);border-radius:0;padding:0 .5ch;background:var(--paper);color:var(--ink);height:var(--l)}
.fig select{font:inherit;border:1px solid var(--ink);border-radius:0;background:var(--paper);color:var(--ink);height:var(--l)}
.fig input:focus-visible,.fig select:focus-visible{outline:2px solid var(--ink);outline-offset:1px}
.fig figcaption{border-top:1px solid var(--ink);padding:var(--l) calc(2*var(--cell));display:block}
.fig figcaption b{font-family:var(--mono);font-weight:600}

/* ---- citations: a click on [n] opens the full reference in a small window ---- */
button.cite{font-family:var(--mono);font-size:.9em;min-height:0;padding:0}
button.cite[aria-expanded="true"]{background:var(--ink);color:var(--paper)}
.refpop{position:absolute;z-index:20;width:min(calc(44*var(--cell)),calc(100vw - 4*var(--cell)));background:var(--paper);border:1px solid var(--ink);padding:calc(.5*var(--l)) calc(2*var(--cell)) calc(.75*var(--l))}
.refpop[hidden]{display:none}
.refpop .rp-head{display:flex;justify-content:space-between;font-family:var(--mono);font-weight:600}
.refpop .rp-text{margin-top:calc(.5*var(--l))}
.refpop .rp-links{margin-top:calc(.5*var(--l));display:flex;flex-direction:column;font-family:var(--mono);font-size:.9em}
@media (max-width:47.5em){.refpop{position:fixed;left:calc(2*var(--cell))!important;right:calc(2*var(--cell));bottom:calc(var(--l) + 48px);top:auto!important;width:auto}}

/* ---- sidenotes: same black, no box; the annotation face (Plex Mono Light), smaller, so they read as notes and weigh less ---- */
article{counter-reset:sn}
.sn-ref{counter-increment:sn;cursor:pointer;font-family:var(--mono);font-size:.7em;vertical-align:.6em;line-height:0;padding:0 .2ch}
.sn-ref::after{content:counter(sn)}
.sn-tg{position:absolute;opacity:0;width:1px;height:1px;pointer-events:none}
.sn-ref:has(+.sn-tg:focus-visible){outline:2px solid var(--ink);outline-offset:1px}
.sidenote{display:none;margin:calc(.5*var(--l)) 0;padding-left:calc(2*var(--cell));position:relative;text-align:left;-webkit-hyphens:manual;hyphens:manual}
.sn-t{font-family:var(--mono);font-weight:300;font-size:.8em;line-height:1.6}
.sidenote::before{content:counter(sn);font-size:.8em;font-family:var(--mono);position:absolute;left:0;top:.1em}
.sn-tg:checked+.sidenote{display:block}
.sn-ref:hover,.sn-ref:has(+.sn-tg+.sidenote:hover){background:var(--ink);color:var(--paper)}
.sn-ref:hover+.sn-tg+.sidenote::before,.sidenote:hover::before{background:var(--ink);color:var(--paper)}
@media (pointer:coarse){.sn-ref{padding:.4em}}
@media (min-width:72em){
  .page{--nw:min(calc(30*var(--cell)),calc((100vw - var(--col-w))/2 - 9*var(--cell)))}
  .sn-ref{cursor:default}
  .sidenote,.sn-tg:checked+.sidenote{display:block;float:right;clear:right;width:var(--nw);margin:0 calc(-1*var(--nw) - 4*var(--cell)) calc(.5*var(--l)) 0;padding:0 0 0 calc(2.5*var(--cell))}
}

/* ---- contents rail: ticks only to the right, H2 twice as long as H3; a green square marks where you are ---- */
.toc{position:fixed;z-index:3;top:20vh;left:calc(var(--col-x) - 12*var(--cell));width:calc(6*var(--cell));height:60vh;font-family:var(--mono)}
.toc .rail{position:absolute;left:calc(2*var(--cell));top:0;bottom:0;width:1px;background:var(--ink)}
.toc .tick{position:absolute;left:calc(2*var(--cell));height:1px;background:var(--ink)}
.toc .tick.h2{width:calc(3*var(--cell))}.toc .tick.h3{width:calc(1.5*var(--cell))}
.toc .here{position:absolute;top:0;left:calc(2*var(--cell) - 3px);width:7px;height:7px;background:var(--core);will-change:transform}
.toc button.open{position:absolute;inset:0;width:100%}
.toc button.open:hover,.toc button.open:focus-visible{background:transparent}
.toc .panel{display:none;position:absolute;left:calc(5*var(--cell));top:0;width:calc(34*var(--cell));max-height:60vh;overflow:auto;background:var(--paper);border:1px solid var(--ink);padding:var(--l) calc(2*var(--cell))}
.toc:hover .panel,.toc:focus-within .panel,.toc.pinned .panel{display:block}
.toc .panel ol{list-style:none}
.toc .panel li.h3{padding-left:calc(2*var(--cell))}
.toc .panel a{text-decoration:none}
.toc .panel a[aria-current]{background:var(--ink);color:var(--paper)}
.toc .panel p{font-weight:600;margin-bottom:var(--l)}
@media (max-width:47.5em){
  .toc{top:auto;bottom:var(--l);left:calc(2*var(--cell));width:auto;height:auto;transition:transform .25s cubic-bezier(.2,.7,.2,1)}
  body.nav-hidden .toc,body:not(.toc-ready) .toc{transform:translateY(calc(100% + 2*var(--l)))}
  .toc .rail,.toc .tick,.toc .here{display:none}
  .toc button.open{position:static;background:var(--paper);border:1px solid var(--ink);padding:0 var(--cell);min-height:44px}
  .toc button.open::after{content:"[contents]"}
  .toc button.open:hover,.toc button.open:focus-visible{background:var(--ink);color:var(--paper)}
  .toc .panel{left:0;top:auto;bottom:calc(44px + 4px);width:min(calc(40*var(--cell)),calc(100vw - 4*var(--cell)));max-height:60vh}
  .toc:hover .panel,.toc:focus-within .panel{display:none}
  .toc.pinned .panel{display:block}
}
@media (prefers-reduced-motion:reduce){.fig,.toc{transition:none}}
@media print{
  .sidenote,.sn-tg:checked+.sidenote{display:block!important;float:none!important;width:auto!important;margin:calc(.5*var(--l)) 0!important;padding-left:calc(2*var(--cell))!important}
  .fig{border:1px solid #000}
  button.cite{background:none!important;color:#000!important}
}
/* phones: the whole title page is set flush left (after the centring rules above, so it wins) */
@media (max-width:47.5em){header.title p{text-align:left}}
