/* ==========================================================================
   A tweet's photos, video stills, link card and loose links (js/media.js).
   Uses the tokens in styles.css.

   Every picture sits in a frame whose size is known before the picture loads:
   the frame's shape comes from the width and height in the payload, so nothing
   moves when the image arrives. The image only fills its frame.
   ========================================================================== */

/* --------------------------------------------------------------------------
   The frame, shared by the thread and the popover
   -------------------------------------------------------------------------- */
.tm__item {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: var(--r);
  background: var(--paper-2);
}
/* A hairline over the picture, so a white screenshot still has an edge on white paper. */
.tm__item::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 1px solid rgb(29 27 24 / 0.1);
  border-radius: inherit;
  pointer-events: none;
  transition: border-color 120ms;
}
.tm__item:hover::after { border-color: rgb(29 27 24 / 0.32); }
.tm__item:focus-visible { z-index: 1; border-radius: var(--r); }
.tm__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Alt text, for the moment between a failed load and the line that replaces it. */
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: var(--fs-xs);
}

/* A video or GIF is its still frame. The mark says it plays, the link goes to the tweet. */
.tm__play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  /* Ink on a still of any colour: a white mark would vanish on a screen recording. */
  background: rgb(29 27 24 / 0.72);
  color: var(--paper);
}
.tm__play .icon { width: 20px; height: 20px; fill: currentColor; }

.tm__gone {
  margin-top: 10px;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: var(--fs-sm);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   In the thread
   -------------------------------------------------------------------------- */
.tm {
  --tm-max-h: 520px;
  display: grid;
  gap: 4px;
  margin-top: 12px;
}
.tm:first-child { margin-top: 4px; }

/* One picture: its own shape, as wide as the column allows, never taller than --tm-max-h and
   never wider than the picture itself. */
.tm[data-n="1"] .tm__item {
  width: min(100%, var(--w, 100%), calc(var(--tm-max-h) * var(--ar, 1.5)));
  aspect-ratio: var(--ar, 1.5);
}
/* Size unknown: a 3:2 frame, and the picture shown whole inside it. */
.tm[data-n="1"] .tm__item--unsized .tm__img { object-fit: contain; }

/* Two side by side; three or four in a two-by-two grid. Cropped to fill. */
.tm[data-n="2"], .tm[data-n="3"], .tm[data-n="4"] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  aspect-ratio: 16 / 9;
}
.tm[data-n="3"], .tm[data-n="4"] { grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
.tm[data-n="3"] .tm__item:first-child { grid-row: span 2; }

/* What follows a picture inside one tweet. */
.tm + .tw__text { margin-top: 8px; }
.tm + .tw__text .tw__meta { margin-left: 0; }
/* A tweet that opens with a picture has no first line of text for its number to sit on. */
.tw:has(> .tw__body > .tm:first-child) { align-items: start; }

/* A card for a page the tweet links to. A reference, not a feature: one border, no shadow.
   Its height comes from its text alone. The thumbnail fills a box of fixed width that stretches
   to that height, so nothing moves when the picture loads or fails. */
.lc {
  display: flex;
  max-width: 560px;
  min-height: 72px;
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: inherit;
  font-family: var(--sans);
  text-decoration: none;
  transition: border-color 120ms;
}
.lc:hover { border-color: var(--line-2); }
.lc:focus-visible { border-radius: var(--r); }
.lc__body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
}
.lc__site { color: var(--ink-3); font-size: var(--fs-micro); font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc__title, .lc__desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.lc__title { color: var(--ink); font-size: var(--fs-ui); font-weight: 600; line-height: 1.3; }
.lc__desc { color: var(--ink-3); font-size: var(--fs-sm); line-height: 1.35; }
.lc:hover .lc__title { color: var(--pub-ink); }
/* On a phone the thumbnail narrows. It never drops under the text. */
.lc__thumb {
  position: relative;
  flex: none;
  width: clamp(72px, 22%, 128px);
  border-left: 1px solid var(--line);
  background: var(--paper-2);
}
.lc__img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.lc + .tw__text { margin-top: 8px; }
.lc + .tw__text .tw__meta { margin-left: 0; }
.tw:has(> .tw__body > .lc:first-child) { align-items: start; }

/* Links the text has no place for. */
.tw-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 8px;
  font-family: var(--sans);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.tw-links .ext-link { min-width: 0; white-space: normal; overflow-wrap: anywhere; }

/* --------------------------------------------------------------------------
   In the source-tweet popover: a row of small squares
   -------------------------------------------------------------------------- */
.tm-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tm-thumbs .tm__item { width: 72px; height: 72px; border-radius: var(--r-sm); }
.tm-thumbs .tm__play { width: 28px; height: 28px; margin: -14px 0 0 -14px; }
.tm-thumbs .tm__play .icon { width: 14px; height: 14px; }
.popover .tw-links { margin-top: 10px; }
.popover .tm__gone { font-size: var(--fs-xs); }

@media (max-width: 600px) {
  .lc__body { padding-inline: 10px; }
  .lc__thumb { width: clamp(56px, 20%, 92px); }
  .tm-thumbs { display: grid; grid-template-columns: repeat(4, minmax(0, 72px)); }
  .tm-thumbs .tm__item { width: 100%; height: auto; aspect-ratio: 1; }
}
