/* the reader: the posts read in a stream. what and when (squares, title, dates) sit in a gutter on
   the open page, the post reads down the card to its right, and next ↓ waits beside it. on a phone
   the gutter goes over the card, with arrows either side of the title for the previous and next.

   every hand-written line is trimmed to its caps and baseline (text-box), so the padding and gaps
   are the distances the eye sees */

[data-look="reader"] {
  /* the dates, a step under next and keep reading so they sit back from the title */
  --date: var(--h-xs);

  .grid {
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 62rem;
    margin: 0 auto;
  }

  /* gutter, card, and (where there's room) next as a third column */
  .grid-item {
    position: relative;
    display: grid;
    grid-template-columns: 13rem 1fr;
    gap: var(--s5);
    width: auto !important;
    transform: none !important;
  }

  /* with no picture, the gutter's line shares a baseline with the first line of words; a picture
     has no baseline, so the line hangs level with its top instead */
  .grid-item > * { align-self: start; }
  .grid-item:has(.no-image) > * { align-self: baseline; }

  /* the gutter, out of the card on the open page to its left, set right against the card as
     next is set left on its other side */

  .gutter {
    position: sticky;
    top: 0;
    padding-top: var(--s4);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--s4);
    text-align: right;
  }

  /* the squares run in the title's first line, so a title that wraps keeps them beside it; the
     squares are 16px to the title's 16px caps, so they sit flush on its baseline */
  .gutter .head {
    font-size: var(--h-m);
    line-height: 1.15;
    text-box: trim-both cap alphabetic;
  }

  .gutter .head .blocks { display: inline-flex; vertical-align: baseline; margin-right: var(--s2); }
  .gutter .head :is(.name, a) { display: inline; }

  /* the phone's arrows and one-line when; here next and the dates say it */
  .steps,
  .gutter .meta { display: none; }

  /* every date it was observed, newest first, joined by a dashed thread. set right, the bullets
     and thread sit on their right */
  .dates {
    list-style: none;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .dates li {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding-right: var(--s3);
    line-height: 1.2;
  }

  .dates li + li { margin-top: var(--s2); }

  .dates li::before {
    content: "";
    position: absolute;
    right: 0;
    top: calc(0.4 * var(--date) - 3.5px);
    width: 5px;
    height: 5px;
    border: 1px solid var(--ink);
    border-radius: 50%;
    background: var(--fill, var(--paper));
  }

  .dates li + li::after {
    content: "";
    position: absolute;
    right: 3px;
    bottom: calc(100% - 0.4 * var(--date));
    height: calc(var(--s2) + 0.6em);
    border-left: 1px dashed var(--pale);
  }

  .dates time { font-size: var(--date); line-height: 1.15; }
  .dates .delta { font-size: var(--tiny); color: var(--dim); }

  :is(.gutter .name, .dates time, .next, .more) { text-box: trim-both cap alphabetic; }

  /* the post */

  .column {
    display: flex;
    flex-direction: column;
    gap: var(--s4);
    min-width: 0;
  }

  /* long heads are capped and faded; keep reading shows only when something is cut. clipped, not
     hidden, with room under the last line for its descenders */
  .body {
    display: flex;
    flex-direction: column;
    gap: var(--s4);
    max-height: 28rem;
    overflow: clip;
    overflow-clip-margin: 0.4em;
    font-size: var(--size);
    line-height: 1.65;
  }

  .body.clipped {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 5rem), transparent);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 5rem), transparent);
  }

  /* each box trimmed to its first line's caps and last line's baseline, so the gap at the top and
     either side of the rules between boxes are what they say */
  .body .box { text-box: trim-both cap alphabetic; }
  .body .box > * + * { margin-top: var(--s3); }
  .body .box + .box { padding-top: var(--s4); border-top: 1px dashed var(--faint); }

  .body blockquote {
    padding-left: var(--s3);
    border-left: 1px dashed var(--pale);
    color: var(--text);
  }

  .body :is(ul, ol) { padding-left: 1.25rem; }

  /* pictures take the column's width, uncropped */
  :is(.column > img, .body img) {
    width: 100%;
    height: auto;
    max-width: 100%;
  }

  /* next and keep reading, in the lightest greys that still read: on the grey page for next,
     on white for keep reading */

  :is(.next, .more) { font-family: var(--hand); font-size: var(--h-s); }
  .next { line-height: 1.15; color: var(--dim-page); }
  .more { color: var(--dim); display: none; align-self: flex-start; }
  :is(.more.cut, .body.clipped ~ .more) { display: inline; }

  .next:hover,
  .more:hover,
  .gutter a:hover .name { text-shadow: var(--glow); }

  /* next sits outside the card: under it, set right */
  .beside {
    display: flex;
    justify-content: flex-end;
    padding-top: var(--s3);
  }

  .grid-item > .beside { grid-column: 2; font-size: var(--h-s); }

  /* the last card showing has nothing to go on to */
  .grid-item.last-shown .beside { visibility: hidden; }

  /* where there's a pointer, next shows faintly, and fully while it's in the card's band: the card
     and the open page either side of it, as far as the window goes */
  @media (hover: hover) {
    .grid-item::before {
      content: "";
      position: absolute;
      top: 0;
      bottom: 0;
      left: calc(50% - 50vw);
      width: 100vw;
    }
    body { overflow-x: clip; }
    .next { opacity: 0.45; transition: opacity 0.15s; }
    :is(.grid-item:hover .next, .next:focus-visible) { opacity: 1; }
  }

  /* where there's room, next sits to the card's right as a third column with no width of its own,
     so it mirrors the gutter across the card: on the title's line, or hung level with the picture's
     top, and it follows the card down. its whole line is trimmed to the caps, not just next in it,
     or the line's own leading sets it low */
  @media (min-width: 1280px) {
    .grid-item { grid-template-columns: 13rem 1fr 0; }
    .grid-item > .beside {
      grid-column: 3;
      position: sticky;
      top: 0;
      display: block;
      padding: var(--s4) 0 0;
      white-space: nowrap;
      line-height: 1.15;
      text-box: trim-both cap alphabetic;
    }
  }

  /* phones: the squares and title centred over the card, with one line saying when, not every
     date, 16px of open page over and under them; the card and its pictures the screen's full
     width. arrows either side of the title step to the previous and next post in next's place */
  @media (max-width: 700px) {
    .grid { gap: var(--s4); }

    /* an arrow lands the post a rem under the top of the screen, not flush against it */
    .grid-item { display: flex; flex-direction: column; gap: 0; scroll-margin-top: 1rem; }
    .grid-item > .card { align-self: stretch; }
    .grid-item > .beside { display: none; }

    .gutter {
      position: relative;
      /* kept clear of the arrows, so a long title wraps before it runs under them */
      padding: 0 2rem var(--s4);
      align-self: stretch;
      align-items: center;
      gap: var(--s2);
      text-align: center;
    }

    .gutter .dates { display: none; }

    .gutter .meta {
      display: block;
      font-family: var(--hand);
      font-size: var(--date);
      line-height: 1.3;
      /* trimmed like next, so the gaps either side of it are the ones the eye sees */
      text-box: trim-both cap alphabetic;
    }

    /* up at the card's left edge, down at its right, centred on the squares, title and when (the
       gutter less its padding under them); none past either end */
    .steps {
      position: absolute;
      top: 0;
      bottom: var(--s4);
      left: 0;
      right: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      pointer-events: none;
    }

    .steps a {
      pointer-events: auto;
      /* a finger's worth to tap, without moving the drawing off the card's edge */
      padding: 14px;
      margin: -14px;
      font-size: var(--h-m);
      color: var(--dim-page);
    }

    /* small, a step under the dates' capitals, so they sit back from the title */
    .steps .glyph { width: auto; height: 9px; stroke-width: 1.8; }
    .steps a:hover { text-shadow: var(--glow); }

    :is(.first-shown .steps .up, .last-shown .steps .down) { visibility: hidden; }
  }
}
