/* ==========================================================================
   blog.css: the rules only the blog pages use. Loaded after styles.css, which
   supplies the grid, the palette, the cabinet, the prompt lines and the keys.

   The index is a directory listing and a post is a text file. Both scroll
   down the page; neither may ever scroll sideways.
   ========================================================================== */

/* 70 columns of text. 70ch is a whole number of pixels on both grids (560px
   and 672px); the 12 --px on top are the screen's borders and the body's
   padding, left and right. */
.screen { max-width: calc(70ch + var(--px) * 12); }

/* ---------- run: a prompt and its keys ---------------------------------- */

.run {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: calc(var(--px) * 2) 1ch;
}

/* A one-word key can be narrower than a fingertip ("Home" is 40px wide on the
   1px grid), so it is held to the touch floor with its word centred. */
.run .key { min-width: 44px; justify-content: center; }

/* Two keys travel together: a narrow screen moves both under the prompt and
   never strands one on a row of its own. */
.keys {
  display: flex;
  gap: 1ch;
}

/* ---------- ls: one row per entry --------------------------------------- */

/* Shared by the list of posts and a post's press timeline. The whole row is
   the link. Its text sits on the prompt's column, so the fill under the
   pointer reaches 3 --px into the gutter on either side. */
.ls {
  display: grid;
  gap: calc(var(--px) * 2);
}

.ls a {
  display: block;
  min-height: 44px;                        /* touch target floor */
  margin-inline: calc(var(--px) * -3);
  padding: calc(var(--px) * 2) calc(var(--px) * 3);
  color: var(--dim);
  text-decoration: none;
}

/* Drawn inside the row, so the ring stays clear of the screen's border. */
.ls a:focus-visible { outline-offset: calc(var(--px) * -2); }

.ls cite { font-style: normal; color: var(--fg); }
.ls .t   { display: block; text-wrap: balance; }   /* no one-word last line */

/* ---------- links in running text --------------------------------------- */

/* Underlined as well as bright, so colour is never the only cue. */
.ls .t,
.post p a {
  color: var(--bright);
  text-decoration-line: underline;
  text-decoration-thickness: var(--px);
  text-underline-offset: calc(var(--px) * 2);
}

:is(.ls, .post p) a        { transition: background-color 120ms steps(2); }
:is(.ls, .post p) a:hover  { background: var(--hover); }
:is(.ls, .post p) a:active { background: var(--press); }

/* ---------- post -------------------------------------------------------- */

/* One blank row between blocks, as in a text file: 1.25em is the body's line
   height. A word too long for its line, a URL on a narrow phone or a table
   heading in a wide fallback font, breaks sooner than push the page sideways. */
.post {
  display: grid;
  gap: 1.25em;
  margin-block: 1.25em;
  overflow-wrap: anywhere;
}

/* The double rule stands in for the row of ==== under a text file's title. */
.post h1 {
  padding-bottom: calc(var(--px) * 2);
  border-bottom: calc(var(--px) * 3) double var(--rule);
  font-size: inherit;
  font-weight: 400;
  color: var(--bright);
  text-wrap: balance;                      /* no one-word last line */
}

.meta { color: var(--dim); }               /* the dateline, a footnote */

/* VT323 has one weight, and a synthesised bold smears its stems off the grid.
   What the source sets in bold is bright instead, a terminal's own bold. */
.post :is(th, strong) { font-weight: 400; color: var(--bright); }

/* ---------- quotes and lists: a mark in the gutter ----------------------- */

/* A quote keeps its ">" and a list item its "-", as in the text file, in a
   gutter two cells wide with the text hanging beside it: the mark floats back
   into the padding. The empty string after the slash keeps the mark out of
   what a screen reader says; the plain declaration before it is for engines
   without that syntax. */
.post :is(blockquote, ul:not(.ls) > li) { padding-inline-start: 2ch; }

.post :is(blockquote, ul:not(.ls) > li)::before {
  float: left;
  width: 2ch;
  margin-inline-start: -2ch;
}

.post blockquote::before       { content: ">"; content: ">" / ""; }
.post ul:not(.ls) > li::before { content: "-"; content: "-" / ""; }

.post blockquote { color: var(--dim); }    /* an aside */

/* ---------- card: a screen inside the post ------------------------------- */

/* A titled, set-apart block is the cabinet in miniature: the same 1 --px
   frame around the same .bar and .body from styles.css. Only the gap differs,
   because a card holds blocks of text, a blank row apart like the post's. */
.card { border: var(--px) solid var(--rule); }
.card .body { gap: 1.25em; }

/* ---------- table ------------------------------------------------------- */

/* A row of seven cells does not fit a phone's 35 columns, so there a row is a
   record of three lines: its name, its five short cells under the head's five,
   and its last cell. Every row is a subgrid of the table, which is what lines
   the short cells up from row to row. Safari drops a table's semantics once
   its display changes, so the markup restates each one as an ARIA role. */
.post table {
  display: grid;
  grid-template-columns: repeat(5, auto);
  column-gap: 1ch;
}

.post :is(thead, tbody, tr) {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: subgrid;
}

.post tr       { padding-block: calc(var(--px) * 2); }
.post tbody tr { border-top: var(--px) solid var(--rule); }

.post :is(th, td) { padding: 0; text-align: start; }

/* The name and the last cell take a line each. Size containment keeps their
   long text out of the column widths, which the short cells alone decide. */
.post tr > :is(:first-child, :last-child) {
  grid-column: 1 / -1;
  contain: inline-size;
}

/* ---------- the full 70 columns ----------------------------------------- */

/* The screen reaches its full width at 716px on the 2px grid; 736px leaves
   room for a scrollbar. The title goes double height, each line two rows tall
   exactly because the line height stays 1.25, and a table row has room to be
   one line of seven cells. The last column never falls below 16 cells, or a
   wide fallback font would squeeze it to one letter per line. */
@media (min-width: 736px) {
  .post h1 { font-size: calc(var(--fs) * 2); }
  .post table { grid-template-columns: repeat(6, auto) minmax(16ch, 1fr); }
  .post tr > :is(:first-child, :last-child) { grid-column: auto; contain: none; }
}
