/* The sources page (sources.html). */

  /* Sources page only. The inverse of corpus.html: that page is
     word-primary (a grid of words, each pointing back to its sources);
     this one is source-primary (a card per reference image, listing the
     words read off it). Everything structural is in style.css/blocks.css. */
  .backlink { font-weight: bold; font-size: 0.95rem; }
  .corpus-controls {
    display: flex; gap: 10px 14px; flex-wrap: wrap; align-items: center;
    margin: 18px 0 2px;
  }
  .corpus-controls input[type="search"] {
    font: inherit; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
    min-width: 12rem; flex: 1 1 12rem;
  }
  .corpus-count { color: var(--muted); font-size: 0.9rem; }
  .legend { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0; }

  /* Tiling: cards pack into as many columns as fit. The words shown per card
     are capped (below), so cards stay a fairly uniform height and the grid
     rows don't leave the dead space a 50-word card used to. Category headers
     span every column, starting each group on its own row. */
  .source-list {
    display: grid; gap: 16px; margin-top: 20px; align-items: start;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
    container-type: inline-size;
  }
  /* A category groups the slides of one post / signs of one episode
     (instagram-1.1, .2, …) under a header. Lone sources have no header. */
  .cat-head {
    grid-column: 1 / -1;
    display: flex; align-items: baseline; gap: 8px 12px; flex-wrap: wrap;
    font-size: 1.05rem; font-weight: 700; color: var(--ink);
    margin: 16px 0 14px; padding-bottom: 5px; border-bottom: 1px solid var(--line);
    scroll-margin-top: 16px;
  }
  .cat-head:first-child { margin-top: 0; }
  .cat-head[hidden] { display: none; }
  .cat-head a.cat-link { color: inherit; text-decoration: none; }
  .cat-head a.cat-link:hover, .cat-head a.cat-link:focus-visible { color: var(--accent); }
  .cat-head a.cat-link::after { content: " #"; color: var(--muted-2); font-weight: 400; opacity: 0; }
  .cat-head a.cat-link:hover::after, .cat-head a.cat-link:focus-visible::after { opacity: 1; }
  .cat-head .cat-count { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
  .cat-collapse {
    margin-left: auto; font: inherit; font-size: 0.78rem; font-weight: 400;
    background: none; border: 1px solid var(--line); color: var(--muted);
    border-radius: 6px; padding: 2px 9px; cursor: pointer;
  }
  .cat-collapse:hover { border-color: var(--accent); color: var(--ink); }
  .source-card:target { scroll-margin-top: 16px; }

  /* Per-source collapse: fold the image + words away, leaving the head row. */
  .source-collapse {
    margin-left: 8px; flex: 0 0 auto; font: inherit; font-size: 0.8rem; line-height: 1;
    background: none; border: 1px solid var(--line); color: var(--muted);
    border-radius: 6px; padding: 3px 7px; cursor: pointer;
  }
  .source-collapse:hover { border-color: var(--accent); color: var(--ink); }
  .source-card.is-collapsed { padding: 10px 16px; align-items: center; }
  .source-card.is-collapsed { grid-column: auto; }
  .source-card.is-collapsed .source-thumb,
  .source-card.is-collapsed .source-noimg,
  .source-card.is-collapsed .source-what,
  .source-card.is-collapsed .source-words,
  .source-card.is-collapsed .source-empty { display: none; }

  /* A word-heavy source takes up more width instead of towering: it spans
     extra grid columns, so its words tile wide and all of them show. The
     grid does NOT clamp a span to the columns that fit (it adds columns off
     the edge instead), so cap it here: 3 columns need 3×360 + 2×16 px of
     list, 2 need 2×360 + 16. */
  .source-card.span2 { grid-column: span 2; }
  .source-card.span3 { grid-column: span 3; }
  @container (max-width: 1111.98px) { .source-card.span3 { grid-column: span 2; } }
  @container (max-width: 735.98px) {
    .source-card.span2, .source-card.span3 { grid-column: auto; }
  }
  /* Phone width: a thumbnail beside the words leaves them a sliver, so put
     the image above them and give the words the card's full width. */
  @container (max-width: 479.98px) {
    .source-card { flex-direction: column; gap: 12px; }
    .source-body { width: 100%; }
  }
  .source-card {
    background: var(--card); border: 1px solid var(--line);
    border-radius: 12px; padding: 16px; display: flex; gap: 16px;
    align-items: flex-start;
    /* room above when scrolled to via its link, so it isn't jammed to the top */
    scroll-margin-top: 16px;
  }
  .source-card[hidden] { display: none; }
  /* Landed on via its own link (sources.html#source-<id>): ring it so it's
     obvious which card the link pointed at. */
  .source-card:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
  /* The reference image. Links to the original post, or to the full image
     if there is no post URL. */
  .source-thumb {
    flex: 0 0 auto; display: block; line-height: 0;
    width: 132px; height: 132px;
  }
  .source-thumb img {
    width: 132px; height: 132px; object-fit: cover;
    border-radius: 8px; border: 1px solid var(--line); background: var(--hover);
  }
  .source-thumb:hover img { border-color: var(--accent); }
  .source-noimg {
    width: 132px; height: 132px; border-radius: 8px;
    border: 1px dashed var(--line); background: var(--hover);
    display: flex; align-items: center; justify-content: center;
    color: var(--muted-2); font-size: 0.78rem; text-align: center; padding: 8px;
  }
  .source-body { flex: 1 1 auto; min-width: 0; }
  /* Two parts: the info (id, links, credit) wraps as it needs to; the meta
     (word count + collapse) stays pinned top-right, so a narrow card never
     strands it on a line of its own. */
  .source-head { display: flex; align-items: baseline; gap: 12px; }
  .source-info { flex: 1 1 auto; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
  .source-meta { flex: 0 0 auto; display: flex; align-items: baseline; }
  .source-id { font-weight: 700; font-size: 1.02rem; color: inherit; text-decoration: none; }
  .source-id:hover, .source-id:focus-visible { color: var(--accent); }
  /* A faint ¶-style anchor mark, so it reads as "click to link here". */
  .source-id::after { content: " #"; color: var(--muted-2); font-weight: 400; opacity: 0; }
  .source-id:hover::after, .source-id:focus-visible::after { opacity: 1; }
  .source-where a { color: var(--accent); font-size: 0.85rem; }
  .source-where span { color: var(--muted-2); font-size: 0.85rem; }
  /* Who translated / transcribed this source, when the source records it.
     Kept out of the way: a credited source's `where` label gets a faint
     dotted underline, and hovering it (or tapping it, on a phone) shows the
     credit in a small popup. It's in the page all along, so screen readers
     get it too. */
  .has-credit { position: relative; cursor: help; }
  .has-credit > span, .has-credit > a {
    text-decoration: underline dotted var(--muted-2); text-underline-offset: 3px;
  }
  .has-credit:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
  .source-author {
    position: absolute; left: 0; top: calc(100% + 6px); z-index: 5;
    white-space: nowrap; color: var(--ink); font-size: 0.82rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
    padding: 4px 8px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    opacity: 0; visibility: hidden; transition: opacity 0.12s;
  }
  .has-credit:hover .source-author,
  .has-credit:focus-within .source-author { opacity: 1; visibility: visible; }
  .source-author a { color: var(--accent); text-decoration: none; }
  .source-author a:hover, .source-author a:focus-visible { text-decoration: underline; }
  .source-count { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
  /* The transcription the corpus was read off. Italic so it reads as a
     quotation of the image rather than as the page's own prose. */
  .source-what {
    color: var(--muted); font-size: 0.82rem; font-style: italic;
    margin: 6px 0 12px; line-height: 1.5;
    /* Clamp a long transcription so it doesn't make the card a tower; the
       full text is in the title, and the words are listed below anyway. */
    display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  /* The words themselves, each drawn in the spelling THIS source used —
     which is the thing the corpus page hides except in the contested
     hover. A chip links to that word on the corpus page. */
  .source-words { display: flex; flex-wrap: wrap; gap: 10px; }
  .source-word {
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    text-decoration: none; color: inherit;
    border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px 7px;
    background: var(--surface); transition: border-color 0.12s, box-shadow 0.12s;
  }
  .source-word:hover, .source-word:focus-visible {
    border-color: var(--accent); box-shadow: 0 3px 10px rgba(0,0,0,0.12);
    outline: none;
  }
  .source-word .avatarian-word { --av-size: 26px; margin: 0; }
  .source-word .sw-en { font-size: 0.8rem; color: var(--ink); }
  /* A word this source only contributed a losing spelling of — the corpus
     draws a different, more-attested one. Flagged so the drawn glyph isn't
     mistaken for the canonical spelling. */
  .source-word .sw-en.is-alt { color: var(--accent); }
  .source-word .sw-en.is-alt::after { content: " ∗"; }
  .source-empty { color: var(--muted-2); font-size: 0.82rem; font-style: italic; }
  .empty { color: var(--muted); margin-top: 24px; }

  /* References & credits. The corpus cards above are the in-world specimens;
     this is the community decipherment work those readings rest on — write-ups
     rather than images, so a plain linked list rather than a card grid. */
  .references {
    margin-top: 40px; padding-top: 20px; border-top: 1px solid var(--line);
  }
  .references h2 { font-size: 1.1rem; margin: 0 0 4px; }
  .ref-intro { color: var(--muted); font-size: 0.88rem; margin: 0 0 14px; }
  .ref-list { list-style: none; padding: 0; margin: 0; display: flex;
    flex-direction: column; gap: 9px; }
  .ref-list a { color: var(--accent); text-decoration: none; }
  .ref-list a:hover, .ref-list a:focus-visible { text-decoration: underline; }
  .ref-where { color: var(--muted-2); font-size: 0.85rem; margin-left: 6px; }
  .ref-credit { color: var(--muted); font-size: 0.88rem; margin: 16px 0 0; }
  .ref-credit a { color: var(--accent); }
