/* ==========================================================================
   Strand art and the strand graph (js/views/strand.js, js/strand-controls.js).
   Supersedes the "Strand art" and "Strand graph" rules in styles.css and uses
   that file's tokens. Colour is the publication's (--pub) and nothing else.

   One coordinate runs through everything here: --x, a tweet's place in posting
   order from 0 to 1. The axis marks, the dots and the hairline all sit at
   --pad + --x * (width - 2 * --pad), so they line up at any width.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Strand art: cover and thumbnail. The svg stretches to its box; strokes do
   not scale, so dots stay round and lines stay hairlines at any aspect ratio.
   -------------------------------------------------------------------------- */
.strand-art .st-wire,
.strand-art .st-dots,
.strand-art .st-time { fill: none; vector-effect: non-scaling-stroke; }
.strand-art .st-wire { stroke: color-mix(in oklab, var(--pub) 58%, var(--paper)); stroke-width: 1px; stroke-linejoin: round; }
.strand-art .st-dots { stroke: var(--pub-ink); stroke-width: 4px; stroke-linecap: round; }
.strand-art .st-time { stroke: var(--pub-ink); stroke-width: 1px; opacity: 0.75; }
.strand-art .st-time--out { stroke: var(--ink-4); }
.strand-art--cover .st-wire { stroke-width: 1.25px; }
.strand-art--cover .st-dots { stroke-width: 6.5px; }
.strand-art--cover .st-time { stroke-width: 1.5px; }

/* --------------------------------------------------------------------------
   Strand graph
   -------------------------------------------------------------------------- */
.strand {
  --pad: 14px;
  --row: 28px;
  --dot: 11px;
  --wire: color-mix(in oklab, var(--pub) 52%, var(--paper));
  position: relative;
  margin-top: 24px;
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: var(--fs-sm);
  line-height: 1.4;
}
.strand[data-density="mid"] { --row: 24px; --dot: 10px; }
.strand[data-density="hi"] { --row: 20px; --dot: 9px; }
.strand .strand__none { margin: 0; color: var(--ink-3); font-size: var(--fs-ui); }

/* Time axis. It stays under the toolbar while the rows scroll, and moves with it. */
.strand__axis {
  position: sticky;
  top: var(--header-h);
  z-index: var(--z-sticky);
  padding-top: 8px;
  background: var(--paper);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: top 260ms var(--ease-out);
}
@media (min-width: 1024px) {
  :root:not([data-scroll="down"]) .strand__axis { top: calc(var(--header-h) + var(--toolbar-h)); }
}
.strand__scale { position: relative; height: 18px; }
.strand__tick {
  position: absolute;
  top: 0;
  left: calc(var(--pad) + var(--x) * (100% - 2 * var(--pad)));
  padding-left: 5px;
  border-left: 1px solid var(--line-2);
  color: var(--ink-3);
  font-size: var(--fs-micro);
  line-height: 18px;
  white-space: nowrap;
}
.strand__tick--end { transform: translateX(-100%); padding: 0 5px 0 0; border-left: 0; border-right: 1px solid var(--line-2); }
.strand__tick.is-under { visibility: hidden; }
.strand__now {
  position: absolute;
  top: 0;
  left: 0;
  color: var(--ink);
  font-size: var(--fs-micro);
  font-weight: 650;
  line-height: 18px;
  white-space: nowrap;
}

.strand__track { position: relative; height: 16px; border-bottom: 1px solid var(--line-2); }
.strand__span {
  position: absolute;
  bottom: -1px;
  left: calc(var(--pad) + var(--x0) * (100% - 2 * var(--pad)) - 3px);
  width: calc((var(--x1) - var(--x0)) * (100% - 2 * var(--pad)) + 6px);
  height: 3px;
  border-radius: 2px;
  background: color-mix(in oklab, var(--pub) 42%, var(--paper));
}
.strand__mark {
  position: absolute;
  bottom: 3px;
  left: calc(var(--pad) + var(--x) * (100% - 2 * var(--pad)));
  width: 2px;
  height: 12px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--pub-ink);
  transform: scaleY(0.58);
  transform-origin: bottom;
  transition: transform 160ms var(--ease-out), opacity 160ms;
}
.strand__mark--out { background: var(--ink-4); transform: scaleY(0.34); }
.strand__mark.is-twin { transform: none; }
.strand__mark.is-selected,
.strand__mark.is-active { z-index: 1; background: var(--ink); transform: none; }

/* Rows: one per paragraph, in reading order */
.strand__rows { position: relative; padding-bottom: 4px; }
.strand__grid,
.strand__guide,
.strand__jog {
  position: absolute;
  top: 0;
  left: calc(var(--pad) + var(--x) * (100% - 2 * var(--pad)));
  width: 1px;
  pointer-events: none;
}
.strand__grid { bottom: 0; background: var(--line); }
.strand__guide { z-index: 1; margin-left: -0.5px; background: var(--ink-3); }
.strand__jog { bottom: 0; background: var(--wire); }

.strand .strand__act {
  position: relative;
  display: flex;
  margin: 0;
  padding: 18px var(--pad) 7px;
  font: inherit;
}
.strand .strand__act:first-of-type { padding-top: 14px; }
.strand__act-name {
  position: relative;
  z-index: 1;
  max-width: 100%;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 0.9375rem;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.006em;
  text-align: left;
  text-wrap: balance;
}
/* Paper behind the words only, line by line, so the strand and the year rules pass beside them */
.strand__act-text {
  padding: 1px 8px 1px 0;
  background: var(--paper);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
button.strand__act-name:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.18em; text-decoration-color: var(--line-2); }
.strand__act-num { color: var(--pub-ink); font-weight: 600; font-variant-numeric: lining-nums; }
.strand__act--out .strand__act-name { color: var(--ink-3); font-family: var(--sans); font-size: var(--fs-sm); font-weight: 600; letter-spacing: 0; }

.strand__row { position: relative; scroll-margin-top: calc(var(--toolbar-h) + 72px); scroll-margin-bottom: 24px; }
.strand__strip {
  position: relative;
  height: var(--row);
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.strand__row--bare > .strand__strip { cursor: default; }
.strand__row.is-probed > .strand__strip { background: color-mix(in oklab, var(--pub) 8%, transparent); }
.strand__row.is-arrived > .strand__strip { animation: strand-flash 1.5s var(--ease-out); }
@keyframes strand-flash { from, 30% { background: var(--pub-tint); } }

/* The strand: each row draws its own piece, entering from the row above and leaving for the next */
.strand__wire {
  position: absolute;
  top: 0;
  left: var(--pad);
  width: calc(100% - 2 * var(--pad));
  max-width: none;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.strand__wire polyline {
  fill: none;
  stroke: var(--wire);
  stroke-width: 1px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: stroke 160ms;
}
.strand__row.is-probed .strand__wire polyline,
.strand__row.is-open .strand__wire polyline { stroke: var(--pub-ink); }

/* A source. The row is the pointer target and picks the nearest dot, so the dot itself
   only has to be seen; it is still a button for the keyboard and for assistive tech. */
.strand__dot {
  position: absolute;
  top: 50%;
  left: calc(var(--pad) + var(--x) * (100% - 2 * var(--pad)));
  z-index: 2;
  width: var(--dot);
  height: var(--dot);
  margin: calc(var(--dot) / -2) 0 0 calc(var(--dot) / -2);
  border-radius: 50%;
  background: var(--pub-ink);
  box-shadow: 0 0 0 1.5px var(--paper);
  pointer-events: none;
  transition: transform 160ms var(--ease-out), opacity 160ms, background-color 160ms, box-shadow 160ms;
}
.strand__dot--out { background: var(--paper); box-shadow: inset 0 0 0 1.5px var(--ink-4), 0 0 0 1.5px var(--paper); }
.strand__dot.is-twin { box-shadow: 0 0 0 2px var(--paper), 0 0 0 3.5px var(--pub-ink); }
.strand__dot.is-active { z-index: 3; transform: scale(1.45); background: var(--ink); }
.strand__dot--out.is-active { background: var(--paper); box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 1.5px var(--paper); }
.strand__dot.is-selected { z-index: 3; background: var(--ink); box-shadow: 0 0 0 2px var(--pub-wash), 0 0 0 3.5px var(--pub-ink); }
.strand__dot--out.is-selected { background: var(--paper); box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 2px var(--pub-wash), 0 0 0 3.5px var(--pub-ink); }
.strand__dot:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 50%; }

/* Pointing at a tweet quiets every other thread */
.strand[data-threads="many"].is-probing .strand__dot:not(.is-kin),
.strand[data-threads="many"].is-probing .strand__mark:not(.is-kin) { opacity: 0.28; }

/* The open row: its paragraph and its tweet, in place */
.strand__row.is-open { border-radius: var(--r-lg); background: var(--pub-wash); }
.strand__detail { display: grid; grid-template-rows: 1fr; }
.strand__row.is-opening > .strand__detail { animation: strand-open 280ms var(--ease-out); }
@keyframes strand-open { from { grid-template-rows: 0fr; opacity: 0; } }
.strand__detail-in { min-height: 0; overflow: hidden; padding: 2px 16px 10px; }
.strand .strand__para {
  max-width: 68ch;
  margin: 0;
  padding-top: 4px;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.62;
  text-wrap: pretty;
  overflow-wrap: break-word;
}
.strand .strand__para--bare { line-height: 2.1; }
.strand .strand__para--bare .cites { white-space: normal; }
.strand .strand__para--bare .cite { margin-left: 0; margin-right: 0.3em; vertical-align: baseline; line-height: 1; font-size: 0.72em; }
.strand__cite[aria-pressed="true"],
.strand__cite[aria-pressed="true"]:hover { background: var(--pub-ink); color: #fff; }
.strand .tweet-embed { margin-top: 12px; }
.strand__foot { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-top: 8px; }
.strand__step { display: inline-flex; align-items: center; gap: 2px; margin-left: -6px; color: var(--ink-3); font-size: var(--fs-xs); }
.strand__step-at { min-width: 5.5em; text-align: center; white-space: nowrap; }
.strand__step-btn--back svg { transform: scaleX(-1); }
.strand__foot .icon-btn:hover:not(:disabled) { background: var(--pub-tint); }
.strand__read { margin-left: auto; }
.strand__read .icon { width: 1.05em; height: 1.05em; }
.strand__close { margin-right: -6px; }
.strand__step + .strand__close { margin-left: auto; }

/* Preview of the tweet under the pointer or the focus */
.strand__tip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: calc(var(--z-sticky) + 1);
  width: min(304px, 100%);
  padding: 9px 12px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--paper);
  box-shadow: var(--shadow-2);
  pointer-events: none;
}
.strand .strand__tip-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--ink-3);
  font-size: var(--fs-micro);
  line-height: 1.4;
}
.strand__tip-meta > span { display: inline-flex; align-items: center; gap: 3px; }
.strand__tip-meta .icon { width: 12px; height: 12px; }
.strand__tip-num { margin-left: auto; color: var(--pub-ink); font-weight: 600; }
.strand .strand__tip-text {
  display: -webkit-box;
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--ink);
  font-size: var(--fs-sm);
  line-height: 1.45;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
}

/* Where the reader lands in the essay after "Read in essay" or the toolbar */
.strand-landed { border-radius: 3px; animation: strand-landed 1.6s ease-out; }
[data-strand-landed]:focus-visible { outline: none; }
@keyframes strand-landed {
  from, 35% { background: var(--pub-tint); box-shadow: 0 0 0 6px var(--pub-tint); }
  to { background: transparent; box-shadow: 0 0 0 6px transparent; }
}

@media (pointer: coarse) {
  .strand, .strand[data-density] { --row: 32px; }
  .strand__foot .icon-btn--sm { width: 40px; height: 40px; }
  .strand__read { min-height: 40px; }
}
@media (max-width: 599px) {
  .strand { --pad: 10px; }
  .strand__detail-in { padding-inline: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .strand__axis { transition: none; }
  .strand__row.is-arrived > .strand__strip { animation: none; background: var(--pub-tint); }
  .strand-landed { animation: none; background: var(--pub-tint); box-shadow: 0 0 0 6px var(--pub-tint); }
}
@media print {
  .strand__axis { position: static; }
  .strand__tip, .strand__guide, .strand__foot { display: none; }
}
