/* ==========================================================================
   Writing. The same paper, ink and two working colours as the front page,
   set for reading: one measured column, figures that break out of it, and
   controls that look like instruments rather than app chrome.
   ========================================================================== */

:root {
  --pm: 34em;                         /* the reading measure */
  --pw: 1100px;                       /* how wide a figure may go */
}

.post-page main { padding-bottom: clamp(64px, 9vw, 120px); }

/* masthead on article pages */
.mast__links {
  display: flex;
  gap: 18px;
  margin-left: 22px;
  font: 400 12.5px/1 var(--mono);
}
.mast__links a { color: var(--ink-2); text-decoration: none; }
.mast__links a:hover { color: var(--ink); }
.mast__links a[aria-current="page"] { color: var(--ink); }
@media (max-width: 560px) { .mast__links { display: none; } }

/* the column grid: text in the middle, figures allowed out to --pw */
.article {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gutter), 1fr)
    [wide-start] minmax(0, calc((var(--pw) - min(var(--pm), 100%)) / 2))
    [main-start] min(var(--pm), calc(100% - 2 * var(--gutter)))
    [main-end] minmax(0, calc((var(--pw) - min(var(--pm), 100%)) / 2))
    [wide-end] minmax(var(--gutter), 1fr) [full-end];
}
.article > * { grid-column: main; }
.article > .wide, .article > .pfig { grid-column: wide; }

/* header */
.post__head { padding: clamp(48px, 9vw, 112px) 0 clamp(28px, 4vw, 44px); grid-column: wide; }
.post__head > * { max-width: 46rem; }
.post__kicker {
  font: 400 12.5px/1.5 var(--mono);
  font-variant-numeric: lining-nums;
  color: var(--ink-3);
}
.post__kicker a { color: inherit; }
.post__title {
  margin: 18px 0 20px;
  font-size: clamp(40px, 26px + 4.4vw, 88px);
  font-weight: 400;
  line-height: .98;
  letter-spacing: -.03em;
  font-variation-settings: "opsz" 72;
}
.post__title em { font-style: italic; }
.post__dek {
  max-width: 34em;
  font-size: clamp(19px, 16px + .8vw, 25px);
  font-style: italic;
  line-height: 1.42;
  color: var(--ink-2);
}
.post__byline {
  margin-top: 26px;
  font: 400 12.5px/1.5 var(--mono);
  color: var(--ink-3);
  font-variant-numeric: lining-nums;
}
.post__byline b { color: var(--ink); font-weight: 500; }
.post__head .post__title { animation: raster .8s .05s var(--ease) both; }

/* body text */
.article > p, .article > ul > li, .article > ol > li { font-size: clamp(18px, 15.6px + .45vw, 20.5px); line-height: 1.62; }
.article > p { margin: 0 0 1.05em; }
.article > p:first-of-type::first-letter {
  float: left;
  margin: .06em .09em 0 -.02em;
  font-size: 3.4em;
  line-height: .78;
  font-weight: 400;
  color: var(--hot-ink);
}
.article h2 {
  margin: 1.9em 0 .55em;
  font-size: clamp(28px, 20px + 1.6vw, 40px);
  line-height: 1.08;
  letter-spacing: -.018em;
}
.article h2 .h-no { margin-right: .45em; font: 500 .38em var(--mono); color: var(--hot-ink); vertical-align: .55em; letter-spacing: 0; }
.article h3 { margin: 1.6em 0 .45em; font-size: clamp(21px, 18px + .5vw, 25px); font-style: italic; }
.article strong { font-weight: 600; }
.article a { text-decoration-color: color-mix(in srgb, currentColor 38%, transparent); }

.article > ul, .article > ol { margin: 0 0 1.2em; }
.article > ul > li, .article > ol > li { position: relative; padding-left: 1.3em; }
.article > ul > li + li, .article > ol > li + li { margin-top: .45em; }
.article > ul > li::before { content: "–"; position: absolute; left: 0; color: var(--ink-3); }
.article > ol { counter-reset: n; }
.article > ol > li { counter-increment: n; }
.article > ol > li::before {
  content: counter(n);
  position: absolute;
  left: 0; top: .42em;
  font: 500 .62em var(--mono);
  color: var(--hot-ink);
}

.article code {
  padding: .08em .32em;
  border-radius: 3px;
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  font-size: .82em;
}

.article pre {
  margin: .4em 0 1.6em;
  padding: 16px 20px;
  overflow-x: auto;
  border-left: 2px solid var(--rule-2);
  background: var(--paper-2);
  font: 400 13.5px/1.65 var(--mono);
  font-variant-numeric: lining-nums;
  tab-size: 2;
}
.article pre code { padding: 0; background: none; font-size: 1em; }
.tk-k { color: var(--cool-ink); }
.tk-s { color: var(--hot-ink); }
.tk-c { color: var(--ink-3); font-style: italic; }
.tk-n { color: var(--ink); font-weight: 500; }
.tk-f { color: var(--ink); }

.article blockquote {
  margin: 1.4em 0 1.6em;
  padding-left: 22px;
  border-left: 2px solid var(--hot);
  font-size: clamp(21px, 17px + .9vw, 27px);
  font-style: italic;
  line-height: 1.4;
}
.article blockquote p { font-size: inherit; line-height: inherit; }

.article .aside {
  margin: 0 0 1.4em;
  padding: 2px 0 2px 16px;
  border-left: 1px solid var(--rule-2);
  font-size: .9em;
  color: var(--ink-2);
}

.article hr {
  width: 100%;
  margin: 2.6em 0;
  border: 0;
  text-align: center;
}
.article hr::after { content: "§"; font: 500 14px var(--mono); color: var(--ink-3); }

/* --------------------------------------------------------------- figures */

.pfig {
  margin: 1.8em 0 2.4em;
  padding-top: 14px;
  border-top: 1px solid var(--ink);
}
.pfig__stage {
  position: relative;
  width: 100%;
  height: var(--h, 380px);
  overflow: hidden;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.pfig__stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pfig__stage.is-grab { cursor: grab; touch-action: none; }
.pfig__stage.is-grab:active { cursor: grabbing; }

.pfig__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 26px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--rule);
  font: 400 12.5px/1.3 var(--mono);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--ink-2);
}
.pfig__ctrl { display: inline-flex; align-items: center; gap: 10px; }
.pfig__ctrl > span:first-child { color: var(--ink-3); }
.pfig__ctrl output { min-width: 4.5em; color: var(--ink); }
.pfig__readouts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin-left: auto; }
.pfig__readouts span { color: var(--ink-3); }
.pfig__readouts b { color: var(--ink); font-weight: 500; }
.pfig__readouts .is-hot { color: var(--hot-ink); }
.pfig__readouts .is-cool { color: var(--cool-ink); }

.pfig figcaption { margin-top: 12px; max-width: 54em; }

.pfig input[type="range"] {
  width: 140px;
  height: 20px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.pfig input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--rule-2); }
.pfig input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  margin-top: -6px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}
.pfig input[type="range"]::-moz-range-track { height: 2px; background: var(--rule-2); }
.pfig input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}
.pfig input[type="range"]:focus-visible { outline: 2px solid var(--hot); outline-offset: 2px; }

.pfig .seg button { padding: 5px 10px; }

/* DOM-built figures share one row style */
.drow { display: grid; align-items: center; gap: 14px; }

@media (max-width: 640px) {
  .pfig__readouts { margin-left: 0; }
  .pfig input[type="range"] { width: 120px; }
}

/* --------------------------------------------------------------- footer */

.post__foot {
  grid-column: main;
  margin-top: 2.4em;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
  font-size: .95em;
  color: var(--ink-2);
}
.post__foot p { font-size: 17px; }
.post__foot p + p { margin-top: .7em; }
.post__more { grid-column: wide; margin-top: clamp(48px, 7vw, 80px); }
.post__more h2 { margin: 0 0 14px; font: 500 12.5px var(--mono); color: var(--ink-3); letter-spacing: 0; }

/* figures need a script; without one the prose stands alone */
.no-js .pfig { display: none; }

@media print {
  .pfig__controls, .post__more { display: none !important; }
  .article > p:first-of-type::first-letter { float: none; font-size: inherit; color: inherit; margin: 0; }
}

/* ------------------------------------------------- figure-specific pieces */

/* a table of tests whose rows re-sort themselves */
.ranker { font: 400 12.5px/1.2 var(--mono); font-variant-numeric: lining-nums tabular-nums; }
.rk-row {
  display: grid;
  grid-template-columns: 11.5em minmax(0, 1fr) 4.5em 5.5em 13.5em;
  align-items: center;
  gap: 14px;
  height: 46px;
  padding: 0 4px;
  border-bottom: 1px solid var(--rule);
}
.rk-head { height: 34px; color: var(--ink-3); font-size: 11.5px; border-bottom-color: var(--rule-2); }
.rk-body { position: relative; }
.rk-body .rk-row { position: absolute; left: 0; right: 0; top: 0; background: var(--paper); transition: transform .75s var(--ease-out); }
.rk-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk-runs { display: flex; gap: 3px; min-width: 0; overflow: hidden; }
.mk { position: relative; flex: none; width: 11px; height: 11px; }
.mk-p::before { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--ink-2); }
.mk-f::before, .mk-f::after { content: ""; position: absolute; left: 1px; right: 1px; top: 4.5px; height: 2px; background: var(--hot); transform: rotate(45deg); }
.mk-f::after { transform: rotate(-45deg); }
.rk-num { position: relative; text-align: right; color: var(--ink-3); transition: color .3s var(--ease); }
.rk-bar { position: absolute; right: 0; bottom: -8px; height: 2px; width: calc(var(--v) * 100%); background: var(--ink-3); opacity: 0; transition: opacity .3s var(--ease); }
.ranker[data-by="fail"] .rk-num[data-col="fail"],
.ranker[data-by="flip"] .rk-num[data-col="flip"] { color: var(--ink); font-weight: 600; }
.ranker[data-by="fail"] [data-col="fail"] .rk-bar { opacity: 1; background: var(--hot); }
.ranker[data-by="flip"] [data-col="flip"] .rk-bar { opacity: 1; background: var(--ink); }
.rk-v i, .v-suspect i { font-style: normal; padding: 3px 6px; border-radius: 2px; font-weight: 500; white-space: nowrap; }
.v-suspect i { color: var(--ink); box-shadow: inset 0 0 0 1px var(--rule-2); }
@media (max-width: 720px) {
  .rk-row { grid-template-columns: minmax(0, 1fr) 3.6em 4.6em; grid-template-rows: auto auto; row-gap: 6px; height: 64px; align-content: center; }
  .rk-head { height: 34px; grid-template-rows: auto; }
  .rk-head span:nth-child(2), .rk-head span:nth-child(5) { display: none; }
  .rk-runs { grid-column: 1 / -1; grid-row: 2; gap: 2px; }
  .mk { width: 9px; height: 9px; }
  .mk-f::before, .mk-f::after { top: 3.5px; }
  .mk-p::before { inset: 2.5px; }
  .rk-v { display: none; }
}

/* the writing index */
.writing-older { margin-top: clamp(48px, 6vw, 72px); }
.writing-older .writing__list li { padding: 10px 0; border-bottom: 1px solid var(--rule); }
.writing-older .writing__list li:first-child { border-top: 1px solid var(--rule); }
.writing-older .writing__list a { text-decoration-color: transparent; }
.writing-older .writing__list a:hover { text-decoration-color: var(--hot); }
.writing-papers { margin-top: 18px; font-size: 17px; color: var(--ink-2); }

/* a plain data table, set like the rest of the report */
.dtable { margin: .2em 0 1.8em; overflow-x: auto; }
.dtable table { width: 100%; min-width: 560px; border-collapse: collapse; font: 400 13px/1.45 var(--mono); font-variant-numeric: lining-nums tabular-nums; }
.dtable th { padding: 0 14px 8px 0; border-bottom: 1px solid var(--rule-2); color: var(--ink-3); font-size: 11.5px; font-weight: 500; text-align: left; vertical-align: bottom; }
.dtable td { padding: 9px 14px 9px 0; border-bottom: 1px solid var(--rule); color: var(--ink-2); vertical-align: top; }
.dtable tbody th { padding: 9px 14px 9px 0; border-bottom-color: var(--rule); color: var(--ink); font-size: 12px; font-weight: 600; vertical-align: top; }
.dtable td.is-hot { color: var(--hot-ink); font-weight: 600; }
.dtable td.is-cool { color: var(--cool-ink); }
.dtable p { max-width: 54em; margin-top: 12px; font-size: 15px; line-height: 1.5; color: var(--ink-2); }

/* a figure can ask for a different height on phones: style="--h: 300px; --h-sm: 380px" */
@media (max-width: 640px) {
  .pfig__stage[style*="--h-sm"] { height: var(--h-sm); }
}
.writing-group { margin-top: clamp(40px, 5vw, 60px); }
.post__byline a { color: inherit; text-decoration: none; }
.post__byline a:hover b { text-decoration: underline; text-decoration-color: var(--hot); }

/* a figure whose body is a table rather than a canvas */
.pfig__html { margin: 0 0 4px; }
.pfig__html table { min-width: 0; }
@media (max-width: 640px) { .pfig__html table { font-size: 11.5px; } .pfig__html th, .pfig__html td { padding-right: 8px; } }
