/* the wall: a pinboard you scan. masonry cards, each with the opening lines of its post; pointing
   at one plays its edits back to its first version and forward again in those lines, the head's
   marble sliding with them (js/looks/wall.js) */

/* registered, so the glide to a change further down can animate it (an unregistered custom
   property only jumps) */
@property --lift {
  syntax: "<length>";
  inherits: true;
  initial-value: 0px;
}

/* the same, so the marble can slide back to an older version and on again */
@property --end {
  syntax: "<percentage>";
  inherits: true;
  initial-value: 0%;
}

[data-look="wall"] {

  /* the head is the post's span on the whole site's; on hover the "since" note slides in at its
     end and the line gives way, so the card's height never changes */

  .card-head {
    display: flex;
    align-items: center;
    min-height: 11px;
    margin-bottom: calc(-1 * var(--s1));
  }

  /* a dashed line for the site's whole life, solid for this post's, a spot at each observation in
     the colours it had then. lines and outlines are the card's border colour, darkening with it */
  .span-line {
    position: relative;
    flex: 1;
    border-bottom: 1px dashed var(--rule);
    transition: --end 0.6s ease;
  }

  /* the solid line runs to the marble, the newest observation or, mid-replay, the version on show */
  .span-line b {
    position: absolute;
    bottom: -1px;
    left: var(--start);
    width: calc(var(--end) - var(--start));
    min-width: 1px;
    border-bottom: 1px solid var(--rule);
  }

  .span-line .marble { left: var(--end); }

  .span-line .block {
    position: absolute;
    bottom: -5.5px;
    width: 10px;
    height: 10px;
    margin-left: -5px;
    border-radius: 50%;
    border-color: var(--rule);
    transition: opacity 0.4s ease;
  }

  /* the spots for versions after the one on show */
  .span-line .block.ahead { opacity: 0; }

  .card:hover :is(.span-line, .span-line b, .span-line .block) { border-color: var(--pale); }

  .as-of {
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
    font-size: var(--tiny);
    line-height: 1;
    color: var(--dim);
    opacity: 0;
    transition: opacity 0.3s ease, max-width 0.4s ease, margin-left 0.4s ease;
  }

  .as-of time { font: inherit; color: var(--text); }

  .card.then .as-of {
    max-width: 12em;
    margin-left: var(--s2);
    opacity: 1;
  }

  /* the foot: when it was observed, with the post's squares in the corner. while the card shows
     its previous version, the squares are that version's, when they differ */

  .history {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--s2);
  }

  .history .blocks.was { display: none; }
  .card.then .history .blocks.was { display: flex; }
  .card.then .history .blocks.now:has(+ .was) { display: none; }

  /* the replay: every edit's lines share one cell, the newest on show and the rest faded out, each
     with its live lines and an invisible copy holding old and new together, so the card is already
     as tall as any of them needs and the masonry never shifts */

  .swaps { display: grid; }

  .swap {
    display: grid;
    grid-area: 1 / 1;
    transition: opacity 0.3s ease;
  }

  .swap.off { opacity: 0; }

  .swap > div {
    grid-area: 1 / 1;
    display: flex;
    flex-direction: column;
  }

  .swap > .sizer { visibility: hidden; }

  /* the live lines fill the cell, so the fade stays at the card's foot, not over the newest words */
  .swap .excerpt { flex: 1; }
  .card img + .swaps .excerpt { max-height: calc(1.6em * 3); }

  /* the copy is marked up as a diff: words added get a wash, words cut are struck */
  .marked del {
    color: var(--pale);
    text-decoration: line-through;
  }

  .marked ins {
    text-decoration: none;
    background: var(--wash);
    box-shadow: inset 0 -1px 0 var(--ink);
  }

  /* glides to a change further down, and back. one value moves the lines and grows the fade under
     the head with them, so nothing slides up past a hard edge; the fade never runs deeper than the
     lines have gone, so at rest the first line is untouched */
  .live .excerpt {
    --lift: 0px;
    transition: color 0.4s ease, --lift 0.5s ease;
  }

  /* put somewhere all at once, an edit's lines move nothing on the way */
  .live .excerpt.still,
  .live .excerpt.still :is(p.fold, del, ins) { transition: none; animation: none; }

  .scroll { transform: translateY(calc(var(--lift) * -1)); }

  .live .excerpt::before {
    content: "";
    position: absolute;
    z-index: 1;
    left: 0;
    right: 0;
    top: 0;
    height: min(2.4em, var(--lift));
    background: linear-gradient(var(--paper), transparent);
    pointer-events: none;
  }

  /* lifted to the end of the lines, the fade at the foot would sit over the last of them */
  .live .excerpt::after { transition: opacity 0.5s ease; }
  .live .excerpt.end::after { opacity: 0; }

  /* at rest the added words are just words; they come in light purple while being typed and
     fade back into the text once their spot has played */
  .live ins {
    background: transparent;
    box-shadow: none;
    transition: color 1.2s ease;
  }

  :is(.card:hover, a:focus-visible) .live ins { color: var(--arriving); }
  :is(.card:hover, a:focus-visible) .live .done ins { color: inherit; }

  /* while a card shows its older version the lines go lighter; whatever is typed back in arrives
     in purple, so the new words stand out from the old */
  .card.then .live .excerpt { color: var(--dim); }
  .card.then .live ins { color: var(--arriving); }

  /* a long added or cut paragraph folds by its height, its gap and rule going with it */
  .live p.fold {
    overflow: hidden;
    transition: height 0.45s ease, opacity 0.35s ease, margin 0.45s ease, padding 0.45s ease;
  }

  /* cut words come back as plain text, are struck, then fade */
  .live del {
    color: inherit;
    text-decoration: line-through transparent;
    transition: color 0.25s ease, text-decoration-color 0.25s ease, opacity 0.3s ease;
  }

  .live del.back { animation: back-in 0.3s ease; }
  .live del.gone { color: var(--pale); text-decoration-color: currentColor; }
  .live del.out { opacity: 0; }

  @media (prefers-reduced-motion: reduce) {
    :is(.span-line, .span-line .block, .swap, .live .excerpt, .as-of, .live p.fold, .live del, .live ins) { transition: none; animation: none; }
  }
}

@keyframes back-in { from { opacity: 0; } }
