/* The Reader. 5 Dec 2026 (docs/design/DECISIONS.md, "The Reader: three sanctioned parts").

   templates/reader/. A stream of decks. A deck is one paper told on a few plates
   that lie side by side in a rail. The rail scrolls and snaps on its own, scripts
   or not; static/js/reader.js adds the keys and keeps the marks. Under 960px the
   five sections are a bar fixed to the foot of the screen; from 960px they are a
   column on the left, and from 1200px "Today on Pith" stands on the right. Flow
   (/reader/flow) gives each deck the whole screen and snaps from deck to deck.

   A plate is a sheet with a line round it and one 2px ink rule at its head. The
   cover of a reviewed paper is the dark sheet: the template sets data-theme="dark"
   on it and every colour below resolves again inside. All plates are one size, so
   nothing jumps from plate to plate or from deck to deck. Colours, sizes and
   widths come from tokens.css; nothing here moves. */

/* The measures. --top is what stands over the first deck (site head, tabs),
   --rest is the deck's own lines around a plate plus the bar, so the first cover,
   its progress line and its actions are whole on the first screen. --air is the
   room a tall screen adds inside a plate: none up to 800px of height, 12px from
   900px, so a short screen sets the same plate closer and a long title still fits. */
.page-reader {
  --reader-vh: 100vh;
  --bar: 57px;
  --lead: var(--space-1);
  --top: 110px;
  --rest: 141px;
  --edge: var(--space-2);
  --peek: var(--space-3);
  --pad: var(--space-3);
  --acts: var(--target);
  --arrows: none;
  --air: clamp(0px, calc((var(--reader-vh) - 800px) * 0.12), var(--space-3));
  --plate: clamp(464px, calc(var(--reader-vh) - var(--top) - var(--rest)), 720px);
  padding-block-end: calc(var(--bar) + env(safe-area-inset-bottom, 0px));
}

@supports (block-size: 100svh) {
  .page-reader {
    --reader-vh: 100svh;
  }
}

.page-reader .layout {
  padding-block: var(--lead) var(--space-6);
}

.reader-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

/* The five sections: a bar at the foot of a phone, each item 56px high. */
.reader-nav {
  position: fixed;
  inset: auto 0 0;
  z-index: 3;
  padding-block-end: env(safe-area-inset-bottom, 0px);
  border-top: var(--rule-hair);
  background: var(--sheet);
}

.reader-nav__list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.reader-nav__link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-block-size: calc(var(--bar) - 1px);
  border-top: 2px solid transparent;
  color: var(--ink-2);
  font: var(--type-small);
  font-size: var(--size-label);
  font-weight: 600;
  text-decoration: none;
}

.reader-nav__link:hover {
  color: var(--ink);
}

.reader-nav__link[aria-current] {
  border-top: var(--rule-inset);
  color: var(--ink);
  font-weight: 700;
}

.reader-nav__hint,
.reader-rail,
.flow-bar,
.plate-edge {
  display: none;
}

/* What Pith says back after a key or a press: one plain line, top of the screen. */
.reader-message {
  position: fixed;
  inset: var(--space-2) 0 auto;
  z-index: 4;
  inline-size: fit-content;
  max-inline-size: min(100% - 2 * var(--margin), 30rem);
  margin-inline: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--ink);
  color: var(--sheet);
  font: var(--type-small);
}

/* The streams: one row; on a phone it scrolls sideways under the thumb. */
.reader-top {
  margin-block-end: var(--lead);
}

.page-reader .tabs {
  flex-wrap: nowrap;
  column-gap: var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
}

.page-reader .tabs__tab {
  flex: none;
  justify-content: center;
  min-inline-size: var(--target);
}

.tabs__tab[aria-current] {
  scroll-initial-target: nearest;
}

.reader-view,
.reader-more a,
.reader-rule a,
.reader-carry__links a,
.deck__open,
.flow-bar__back {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-block-size: var(--target);
  min-inline-size: var(--target);
  font: var(--type-small);
}

.reader-view {
  margin-inline-start: auto;
}

/* The stream. On a phone it runs to the edges of the screen. */
.reader-stream {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: var(--space-6);
  margin-inline: calc(0px - var(--margin));
}

.deck-item {
  min-block-size: calc(var(--reader-vh) - var(--top));
}

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

/* The apparatus face is for what a program filed: an id, a place in a deck or
   a row. It stays under an eighth of the text; the other lines are Pith's. */
.deck-plate__foot,
.deck__row-kind,
.deck__row-standing {
  color: var(--apparatus);
  font: var(--type-line);
  font-size: var(--size-label);
}

.deck__why,
.deck__head,
.deck__facts,
.deck__place,
.reader-row__line {
  color: var(--ink-2);
  font: var(--type-small);
  font-size: var(--size-label);
}

.deck__why,
.deck__head,
.deck__facts,
.deck-plate__foot,
.reader-row__line {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  column-gap: var(--space-4);
}

/* The line over a deck keeps its height when empty, so the mark "Read" moves nothing. */
.deck__why {
  min-block-size: 1.45em;
  margin-block-end: var(--space-1);
  padding-inline: var(--edge);
}

.deck__read {
  color: var(--ink);
  font-weight: 700;
}

/* The progress line: one segment a plate, ink up to the plate in view. A segment
   is 2px of line in a 44px place to press, which takes no room of its own. */
.deck__bar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  column-gap: var(--space-1);
  margin-block-end: var(--lead);
  padding-inline: var(--edge) calc(var(--edge) + var(--peek));
}

.deck__seg {
  display: block;
  margin-block: -21px;
  padding-block: 21px;
}

.deck__seg::before {
  content: "";
  display: block;
  block-size: 2px;
  border-bottom: var(--rule-control);
}

.deck__bar li:has(~ li [aria-current]) .deck__seg::before,
.deck__seg[aria-current]::before {
  border-bottom: var(--rule-inset);
}

/* The rail. Plates lie side by side; the rail snaps one plate at a time and the
   edge of the next plate shows (--peek). */
.deck__track {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  outline-offset: -2px;
  overscroll-behavior-x: contain;
  scroll-padding-inline-start: var(--edge);
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.deck__track::after {
  content: "";
  flex: none;
  inline-size: calc(var(--edge) + var(--peek));
}

.plate-slot {
  position: relative;
  display: flex;
  flex: none;
  inline-size: calc(100% - 2 * var(--edge) - var(--peek));
  margin-inline-start: var(--edge);
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.plate-slot--start {
  scroll-initial-target: nearest;
}

.plate-slot:focus {
  outline: none;
}

/* The plate. */
.deck-plate {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-inline-size: 0;
  min-block-size: var(--plate);
  border: var(--rule-control);
  background: var(--sheet);
  color: var(--ink);
}

.deck-plate__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  row-gap: calc(var(--space-2) - (var(--space-3) - var(--air)) / 6);
  padding: var(--space-3) var(--pad) var(--space-2);
  overflow-wrap: anywhere;
}

.deck-plate__body::before {
  content: "";
  flex: none;
  block-size: 2px;
  background: var(--ink);
}

.deck-plate__foot {
  margin-inline: var(--pad);
  padding-block: calc(var(--space-1) + var(--air) / 3) var(--space-2);
  border-top: var(--rule-hair);
}

/* Type on a plate: four sizes at most. The paper's own words are in the paper
   face; what Pith says is in Pith's. A phone sets the cover close, so a title of
   six lines and the claim under it still end above the actions. */
.deck__title {
  font: var(--type-verdict);
  font-size: var(--size-number);
  letter-spacing: var(--track-verdict);
}

.deck-plate [data-paper-words] {
  font-family: var(--face-paper);
  font-weight: 400;
}

.deck__title[data-paper-words] {
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: var(--track-title);
}

.deck__claim {
  font-size: var(--size-small);
  line-height: 1.45;
}

.deck__title--inner,
.deck__count {
  font-size: var(--size-title);
}

.deck__count {
  font-weight: 780;
  line-height: 1.08;
}

.deck__by,
.deck__note,
.deck__machine,
.deck__row,
.deck__caption {
  color: var(--ink-2);
  font: var(--type-small);
}

/* A line of text holds 45 to 68 characters: the small step and the paper face
   run narrower than the body, so on a wide plate they stop short of its edge. */
.deck__by,
.deck__note,
.deck__machine,
.deck__row {
  max-inline-size: 30em;
}

.deck-plate [data-paper-words]:not(.deck__title) {
  max-inline-size: 26em;
}

.deck__standing {
  font-weight: 680;
  line-height: 1.3;
}

.deck__label {
  margin-block-end: calc(0px - var(--space-1));
}

.deck__paper {
  padding-inline-start: var(--space-3);
  border-inline-start: var(--rule-control);
}

.deck__facts,
.deck__doors {
  margin-block-start: auto;
}

.deck__row {
  padding-block: var(--space-1);
  border-top: var(--rule-hair);
}

/* A title in a row may hold mathematics, so its link stays one run of text. */
.deck__row-kind,
.deck__row a {
  display: block;
}

.deck__row a {
  align-content: center;
  min-block-size: var(--target);
}

.deck__doors {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Under a plate: the actions, then the paper's name once the cover is out of view.
   The two marks stand left, the links right; a link that does not fit the row
   (Flow on a narrow phone) goes under the links, not under the marks. */
.deck__acts,
.reader-row__acts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  column-gap: var(--space-2);
  min-block-size: var(--acts);
}

.deck__acts {
  margin-block-start: var(--space-2);
  padding-inline: var(--edge);
}

.deck__acts > form:last-of-type {
  margin-inline-end: auto;
}

.deck__open + .deck__open {
  margin-inline-start: var(--space-1);
}

.deck__act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-block-size: var(--target);
  min-inline-size: 4.8em;
  padding: 0 var(--space-3);
  border: var(--rule-control);
  background: var(--sheet);
  color: var(--ink);
  font: var(--type-small);
  font-weight: 600;
  cursor: pointer;
}

.deck__act[data-action="read"],
.deck__act[data-action="follow"] {
  min-inline-size: 7em;
}

.deck__act:hover {
  border-color: var(--ink);
}

.deck__act[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--sheet);
}

.deck__caption {
  margin-block-start: var(--space-2);
  padding-inline: var(--edge);
}

.deck__caption strong,
.reader-row__title {
  color: var(--ink);
  font-weight: 600;
}

/* With scripts on, the plate in view is known: its cover needs no caption, and
   from 720px the two arrows beside it are drawn. */
@media (scripting: enabled) {
  .deck:has(.plate-slot:first-child[aria-current]) .deck__caption {
    visibility: hidden;
  }

  .plate-slot[aria-current] > .plate-edge {
    display: var(--arrows);
  }
}

.plate-edge {
  position: absolute;
  inset-block: 0;
  align-items: center;
  justify-content: center;
  inline-size: var(--edge);
  color: var(--apparatus);
  font: var(--type-verdict);
  text-decoration: none;
}

.plate-edge--back {
  inset-inline-end: 100%;
}

.plate-edge--on {
  inset-inline-start: 100%;
}

.plate-edge:hover {
  color: var(--ink);
}

/* The lines round the stream, and the rows of the list view, Explore, Library
   and Following. */
.reader-more,
.reader-rule,
.reader-none,
.reader-scope {
  padding-block: var(--space-3);
  color: var(--ink-2);
  font: var(--type-small);
}

.reader-more {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: var(--space-3);
}

.reader-shelf {
  margin-block: var(--space-5) var(--space-2);
  font: var(--type-body);
  font-weight: 700;
}

.reader-row,
.reader-stream-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  column-gap: var(--space-4);
  padding-block: var(--space-2);
  border-top: var(--rule-hair);
}

/* The row the j and k keys are on. */
.reader-row[data-active] {
  border-top-color: var(--ink);
}

.reader-row__text {
  flex: 1 1 16rem;
  min-inline-size: 0;
}

.reader-row__title {
  display: block;
  align-content: center;
  min-block-size: var(--target);
}

.reader-row__line {
  justify-content: flex-start;
}

.reader-sub,
.reader-find,
.reader-carry {
  margin-block: var(--space-4);
}

.reader-carry__links {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--space-5);
}

/* The browser's own button inside the file field, drawn as the page's buttons are. */
.reader-opml .field__input--file {
  padding-inline-start: 0;
  font: var(--type-small);
}

.reader-opml .field__input--file::file-selector-button {
  height: 100%;
  margin-inline-end: var(--space-3);
  padding: 0 var(--space-3);
  border: 0;
  border-inline-end: var(--rule-control);
  background: var(--sheet);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

/* The sheet of keys. */
.reader-keys {
  max-inline-size: min(100% - 2 * var(--margin), 30rem);
  padding: var(--space-5);
  border: var(--rule);
  background: var(--sheet);
  color: var(--ink);
}

.reader-keys::backdrop {
  background: var(--sheet);
  opacity: 0.85;
}

.reader-keys__list {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-2) var(--space-4);
  margin-block: var(--space-4);
  font: var(--type-small);
}

.page-reader kbd {
  padding: 0 var(--space-1);
  border: var(--rule-control);
  font-size: var(--size-label);
}

@media (min-width: 720px) {
  .page-reader {
    --lead: var(--space-2);
    --top: 126px;
    --rest: 155px;
    --edge: var(--target);
    --peek: var(--space-4);
    --pad: var(--space-5);
    --acts: var(--control);
    --arrows: flex;
  }

  .page-reader .tabs {
    flex-wrap: wrap;
    overflow: visible;
  }

  .tabs__tab[aria-current] {
    scroll-initial-target: none;
  }

  .deck-plate__body {
    padding-block: calc(var(--space-3) + var(--air)) calc(var(--space-2) + var(--air) / 3);
  }

  .deck__title[data-paper-words] {
    line-height: 1.1;
  }

  .deck__claim {
    font-size: var(--size-body);
    line-height: 1.5;
  }

  .deck__title--inner,
  .deck__count {
    font-size: var(--size-verdict);
  }

  .deck__label {
    margin-block-start: calc(var(--air) * 2 / 3);
  }

  /* A plate that says little says it large: the objection or the test stands at
     the size of a plate's headline, so the plate is not half empty. */
  .deck-plate--large .deck__said,
  .deck-plate--large .deck__test {
    font-size: var(--size-verdict);
    line-height: 1.25;
  }

  .reader-stream {
    max-inline-size: 644px;
    margin-inline: auto;
  }
}

/* From 960px the sections are a column on the left that stays in view. */
@media (min-width: 960px) {
  .page-reader {
    --bar: 0px;
    --rest: 96px;
  }

  .reader-shell {
    grid-template-columns: 208px minmax(0, 1fr);
    align-items: start;
    column-gap: var(--gutter);
  }

  .reader-nav {
    position: sticky;
    inset: var(--space-4) auto auto;
    z-index: auto;
    border: 0;
  }

  .reader-nav__list {
    grid-template-columns: minmax(0, 1fr);
  }

  .reader-nav__link,
  .reader-nav__link[aria-current] {
    justify-content: flex-start;
    min-block-size: var(--target);
    border: 0;
    font-size: var(--size-body);
  }

  .reader-nav__hint {
    display: block;
    margin-block-start: var(--space-4);
    padding-block-start: var(--space-3);
    border-top: var(--rule-hair);
    color: var(--ink-2);
    font: var(--type-small);
  }

  h2.deck__title {
    font-size: var(--size-title);
  }
}

/* From 1200px "Today on Pith" stands on the right. */
@media (min-width: 1200px) {
  .reader-shell {
    grid-template-columns: 208px minmax(0, 1fr) 300px;
  }

  /* The rail is as tall as the first screen under the site's head and no taller.
     Its rows stand in one column that wraps: a row that does not fit whole goes to
     a second column, and that column is outside the rail and is not drawn. So no
     line of the rail is ever cut by the screen's edge, at any height. */
  .reader-rail {
    position: sticky;
    inset-block-start: var(--space-4);
    display: flex;
    flex-flow: column wrap;
    align-content: flex-start;
    column-gap: var(--gutter);
    max-block-size: calc(var(--reader-vh) - var(--top) + var(--space-6));
    overflow: hidden;
    padding-inline-start: var(--gutter);
    border-inline-start: var(--rule-hair);
  }

  .reader-rail > *,
  .reader-rail__links > li {
    inline-size: 100%;
  }

  .reader-rail__links {
    display: contents;
  }

  .reader-rail a {
    display: block;
    padding-block: var(--space-1);
  }

  .reader-rail__counts a {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    text-decoration: none;
  }

  .reader-rail .counter__number {
    flex: none;
    min-inline-size: 1.6em;
    font: var(--type-verdict);
  }

  .reader-rail .counter__unit {
    margin: 0;
    color: var(--ink-2);
  }

  .reader-rail__rule {
    margin-block-start: var(--space-3);
    padding-block-start: var(--space-3);
    border-top: var(--rule-hair);
  }

  .reader-rail__rule a {
    text-decoration: none;
    color: var(--ink-2);
  }

  /* A heading keeps room under it for its first row, so it never stands alone
     at the foot of the rail. */
  .reader-rail__head {
    margin-block: var(--space-5) var(--space-8);
    padding-block-start: var(--space-3);
    border-top: var(--rule-hair);
    color: var(--ink-2);
  }

  .reader-rail__head + .reader-rail__links > li:first-child {
    margin-block-start: calc(var(--space-1) - var(--space-8));
  }

  .reader-rail__links a {
    font: var(--type-small);
    text-decoration: none;
  }

  .reader-rail__and {
    color: var(--ink-2);
  }

  .reader-rail__side {
    display: block;
  }

  .reader-rule {
    display: none;
  }
}

/* Flow: one deck a screen. The page itself does not scroll; main does, and snaps.
   The site's head and foot, the tabs and the side columns are not drawn; a quiet
   bar at the top leads back to the Feed. */
.page-flow {
  --lead: var(--space-1);
  --acts: var(--target);
  --plate: 0px;
  padding-block-end: 0;
  overflow: hidden;
}

.page-flow .site-head,
.page-flow .site-foot,
.page-flow .reader-top,
.page-flow .reader-rail,
.page-flow .reader-rule,
.page-flow .reader-follow,
.page-flow .reader-scope,
.page-flow .deck__caption {
  display: none;
}

.page-flow .layout {
  flex: none;
  block-size: 100dvh;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}

.page-flow .flow-bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  block-size: var(--target);
  padding-inline: var(--margin);
  border-bottom: var(--rule-hair);
  background: var(--sheet);
  color: var(--ink-2);
  font: var(--type-small);
}

.page-flow .reader-stream {
  row-gap: 0;
}

.page-flow .deck-item,
.page-flow .reader-more {
  display: flex;
  flex-direction: column;
  min-block-size: 100dvh;
  padding-block: var(--target) calc(var(--bar) + env(safe-area-inset-bottom, 0px));
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

.page-flow .reader-more {
  align-items: center;
  justify-content: center;
}

.page-flow .deck {
  flex: 1;
  padding-block: var(--space-1);
}

.page-flow .deck__frame {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.page-flow .deck__track {
  flex: 1;
}

@media (min-width: 960px) {
  .page-flow .reader-shell {
    display: block;
  }

  .page-flow .reader-nav {
    display: none;
  }
}

@media print {
  .reader-nav,
  .reader-top,
  .deck__bar,
  .deck__acts {
    display: none;
  }

  .deck__track {
    display: block;
  }

  .plate-slot {
    inline-size: auto;
    margin: 0 0 var(--space-4);
  }
}
