/* Cabinhub News — card variants and the home information architecture.
   Owner: N3-DESIGN (cards + home IA). New file; nothing here renames a class
   that frontend/app.js already emits.

   The rule this file is built on (TEAM.md §8, Han 2026-11-06): a card is TEXT
   separated by a hairline. No border around a card, no shadow, no background
   fill, no pill, no radius on a card. Hierarchy is carried by type size and
   space alone. A hairline appears only where a list needs separation.

   Variant contract — each variant declares its hierarchy as a small block of
   custom properties, and the shared consumers below apply them. app.js can
   adopt a variant by adding ONE class to the element it already renders:
     .card--lead      the lead story          headline --fs-lead
     .card--secondary two-up under the lead   headline --fs-sub
     .card--river     the dense list          headline --fs-title, 1-line deck
     .card--rail      the right column index  headline --fs-title, no deck
     .card--compact   category/headline/time  headline --fs-small, no deck, no image

   The home grid puts four areas on .feed: lead, secondary, river, rail. It
   works with today's markup (lead + rail) and with the wrappers app.js adds
   later (.feed__secondary, .feed__river); everything collapses to one column
   under 900px. */

/* ================================================== home architecture ==== */

.feed {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "lead"
    "secondary"
    "river"
    "compact"
    "rail"
    "digest";
  row-gap: clamp(1.1rem, 2.2vw, 1.8rem);
  column-gap: 0;
  align-items: start;
}

/* Existing children keep their names; the grid only places them. */
.feed > .feed__lead      { grid-area: lead; }
.feed > .feed__secondary { grid-area: secondary; }
.feed > .feed__river     { grid-area: river; }
.feed > .feed__compact   { grid-area: compact; }
.feed > .feed__side      { grid-area: rail; }
.feed > .feed__digest    { grid-area: digest; }

/* A variant placed directly in .feed (no wrapper) still lands in its area. */
.feed > :is(.card--lead, .article--lead) { grid-area: lead; }

@media (min-width: 900px) {
  .feed {
    grid-template-columns: minmax(0, 1.9fr) minmax(0, 1.1fr) minmax(17rem, 21rem);
    grid-template-areas:
      "lead lead rail"
      "secondary secondary rail"
      "river river rail"
      "compact compact rail"
      "digest digest digest";
    column-gap: clamp(1.4rem, 2.2vw, 2.2rem);
  }
  .feed--single {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "lead"
      "secondary"
      "river"
      "compact"
      "rail"
      "digest";
  }
  /* The rail keeps the one hairline that separates it from the main column.
     It stretches to the bottom of the lead it sits beside: an index of three
     items is shorter than the lead, and a rule that stopped at the last item
     left the right column looking abandoned halfway down the page. */
  .feed > .feed__side {
    align-self: stretch;
    border-left: 1px solid var(--rule-soft);
    padding-left: clamp(1rem, 1.8vw, 1.6rem);
    border-top: 0;
    padding-top: 0;
  }
}

/* -------------------------------------------- secondary pair + river ---- */

.feed__secondary {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  row-gap: var(--sp-4);
  min-width: 0;
}
@media (min-width: 640px) {
  .feed__secondary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: clamp(1rem, 2.4vw, 2rem);
    row-gap: 0;
  }
  .feed__secondary > .card--secondary + .card--secondary {
    border-left: 1px solid var(--rule-soft);
    padding-left: clamp(1rem, 2vw, 1.6rem);
  }
}

.feed__river {
  border-top: 1px solid var(--rule);
  padding-top: var(--sp-2);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}
@media (min-width: 1080px) {
  .feed__river {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: clamp(1rem, 2.4vw, 2rem);
  }
  /* In two columns the first pair sits under the container rule, so only the
     items below it carry their own hairline. */
  .feed__river > .card--river:nth-child(-n + 2) { border-top: 0; }
}

/* ==================================================== the variant system ==
   Each block is the whole hierarchy statement for that variant: headline size,
   leading, measure, deck size/clamp, meta gap and the space the card occupies.
   The consumers that follow read these properties. */

/* The lead: the page's first voice. 28 -> 40px (--fs-lead), a 20ch measure so
   the headline breaks like a printed page, a 3-line deck at most. */
.card--lead,
.article--lead {
  --v-title-size: var(--fs-lead);
  --v-title-line: 1.12;
  --v-title-track: -0.022em;
  --v-title-weight: 700;
  --v-title-measure: 20ch;
  --v-title-gap: var(--sp-2);
  --v-deck-size: var(--fs-small);
  --v-deck-line: 1.7;
  --v-deck-measure: 56ch;
  --v-deck-clamp: 3;
  --v-meta-gap: var(--sp-2);
  --v-pad: 0 0 var(--sp-5);
}

/* The secondary pair: the two stories that stand beside the lead. One size
   step down, 19 -> 23px (--fs-sub), two-line deck. */
.card--secondary {
  --v-title-size: var(--fs-sub);
  --v-title-line: 1.22;
  --v-title-track: -0.014em;
  --v-title-weight: 700;
  --v-title-measure: 26ch;
  --v-title-gap: var(--sp-1);
  --v-deck-size: var(--fs-small);
  --v-deck-line: 1.6;
  --v-deck-measure: 44ch;
  --v-deck-clamp: 2;
  --v-meta-gap: var(--sp-1);
  --v-pad: 0 0 var(--sp-4);
}

/* The river: the dense list that carries the rest of the edition. Same size as
   the rail (17 -> 18px, --fs-title) but it keeps exactly one line of deck, so
   the two read differently without a second size step. */
.card--river {
  --v-title-size: var(--fs-title);
  --v-title-line: 1.32;
  --v-title-track: -0.006em;
  --v-title-weight: 700;
  --v-title-measure: 44ch;
  --v-title-gap: 0;
  --v-deck-size: var(--fs-label);
  --v-deck-line: 1.5;
  --v-deck-measure: 60ch;
  --v-deck-clamp: 1;
  --v-meta-gap: var(--sp-1);
  --v-pad: 0.55rem 0 0.6rem;
}

/* The rail: a narrow index. Headline only — no deck, no promise of more. */
.card--rail {
  --v-title-size: var(--fs-title);
  --v-title-line: 1.32;
  --v-title-track: -0.006em;
  --v-title-weight: 600;
  --v-title-measure: 32ch;
  --v-title-gap: 0;
  --v-meta-gap: var(--sp-1);
  --v-pad: 0.6rem 0 0.65rem;
}

/* The compact index: category, headline, time. No deck, no image, no source. */
.card--compact {
  --v-title-size: var(--fs-small);
  --v-title-line: 1.38;
  --v-title-track: 0;
  --v-title-weight: 600;
  --v-title-measure: 40ch;
  --v-title-gap: 0;
  --v-meta-gap: 0.15rem;
  --v-pad: 0.4rem 0 0.45rem;
}

/* ------------------------------------------------------------ consumers -- */

/* Headline. One rule for every variant; the per-variant blocks above decide
   the number, this decides how it is set. */
:is(.card--lead, .article--lead, .card--secondary, .card--river, .card--rail, .card--compact)
  :is(.card__title, .article__title) {
  font-size: var(--v-title-size, var(--fs-title));
  line-height: var(--v-title-line, 1.3);
  letter-spacing: var(--v-title-track, -0.008em);
  font-weight: var(--v-title-weight, 700);
  max-width: var(--v-title-measure, none);
  margin: 0 0 var(--v-title-gap, 0);
  text-wrap: pretty;
}

/* Deck. Clamped to the variant's line count, so a long summary never pushes a
   dense list out of its rhythm. */
:is(.card--lead, .article--lead, .card--secondary, .card--river)
  :is(.card__deck, .article__deck) {
  font-size: var(--v-deck-size, var(--fs-small));
  line-height: var(--v-deck-line, 1.65);
  max-width: var(--v-deck-measure, var(--measure-deck));
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--v-deck-clamp, 2);
  overflow: hidden;
  text-wrap: pretty;
}

/* Meta line sits closer to the headline as the step gets smaller. */
:is(.card--lead, .article--lead, .card--secondary, .card--river, .card--rail, .card--compact)
  :is(.card__meta, .article__meta) {
  margin-bottom: var(--v-meta-gap, var(--sp-1));
}

/* Space and the one hairline each variant is allowed. A variant never draws a
   frame: border-top is a list separator, border-bottom separates the lead from
   the pair beneath it. */
:is(.card--lead, .card--secondary, .card--river, .card--rail, .card--compact) {
  padding: var(--v-pad, 0);
  border: 0;
  background: transparent;
  box-shadow: none;
}
.card--lead { border-bottom: 1px solid var(--rule); }
.feed__lead > .card--lead:last-child { border-bottom: 0; }
.card--river,
.card--rail,
.card--compact { border-top: 1px solid var(--rule-soft); }
.feed__river > .card--river:first-child { border-top: 0; }
.feed__side > .card--rail:first-of-type,
.feed__compact > .card--compact:first-child { border-top: 0; }

/* Secondary pair: the lead's own rule separates it; the pair draws none. */
.card--secondary { border-top: 0; }
.feed__secondary > .card--secondary { border-top: 0; }
@media (max-width: 639px) {
  .feed__secondary > .card--secondary + .card--secondary { border-top: 1px solid var(--rule-soft); padding-top: var(--sp-3); }
}

/* --------------------------------------------------------------- decks ---
   The rail and the compact index carry no deck; their headline is the whole
   item. The river carries one line, enforced above by --v-deck-clamp. */
.card--rail .card__deck,
.card--compact .card__deck { display: none; }

/* Compact drops the source name and its dangling separator; category and time
   are the identification. */
.card--compact .card__source,
.card--compact .card__meta > .article__dot { display: none; }

/* -------------------------------------------------------------- images ---
   An image is shown only when one exists (media.css hides the empty plate), and
   its slot is set by the variant's density:
     lead / secondary  full-width 16:9 above the headline
     river             a 72px square, floated, so the list stays dense
     rail              a 72px square, floated
     compact           never
   No frame, no shadow, no caption chrome: the photograph is the only thing. */

.card--lead .thumb--card:has(.thumb__img),
.card--secondary .thumb--card:has(.thumb__img) {
  display: block;
  float: none;
  width: 100%;
  margin: 0 0 var(--sp-3);
}
.card--lead .thumb--card:has(.thumb__img) .thumb__img,
.card--secondary .thumb--card:has(.thumb__img) .thumb__img { aspect-ratio: 16 / 9; }

.card--river .thumb--card:has(.thumb__img),
.card--rail .thumb--card:has(.thumb__img) {
  display: block;
  float: right;
  width: 72px;
  margin: 0.1rem 0 0.3rem 0.7rem;
}
.card--river .thumb--card:has(.thumb__img) .thumb__img,
.card--rail .thumb--card:has(.thumb__img) .thumb__img { aspect-ratio: 1 / 1; }
.card.card--compact .thumb,
.card.card--compact .thumb--card:has(.thumb__img) { display: none; }

/* The lead's own media block (article--lead uses the 'lead' variant, not
   'card') already draws a full-width 16:9 plate in media.css; keep it
   full-width even when the lead spans two grid columns. */
.article--lead .thumb--lead { float: none; width: 100%; }

/* ================================================== single-column home ====
   Under 900px the areas stack in reading order: lead, pair, river, rail. The
   rail's left hairline becomes a top hairline, because a vertical separator
   has no meaning in one column. */

@media (max-width: 899px) {
  .feed > .feed__side {
    border-left: 0;
    border-top: 1px solid var(--rule);
    padding-left: 0;
    padding-top: var(--sp-2);
    margin-top: var(--sp-1);
  }
  .card--lead { padding-bottom: var(--sp-4); }
  .card--lead .card__title,
  .article--lead .article__title { max-width: 26ch; }
}

/* ====================================================== tablet band =====
   Between the phone stack and the 900px three-column desktop there was NO
   layout: the feed stayed one column from 560 to 899, so an iPad portrait at
   768-834 read a 719-781px lead followed by an index whose every entry ran the
   full page width. MEASURED 2026-11-16 (tools/n3_tablet.mjs, chromium 149,
   fixture feed): feed columns 1 at 600/700/768/834 and 3 at 900; the index's
   .card__title measured 75ch at 700 and 88ch at 834 in EN -- past WCAG 1.4.8's
   80-character ceiling and well past the 75ch this product's own tokens.css
   names as the comfortable range. That is the "desktop squeezed" reading Han
   reported: the width is there, the columns are not.

   At 760 the two-column feed returns, with the index beside the lead exactly
   as it sits on desktop -- the same grid-template-areas, one track fewer than
   the >=900 rule, so the 900 breakpoint only has to widen the rail, not
   re-learn the layout. 760 is the first width where the lead and a >=14rem
   index both clear their measures (711px content box - 224px rail - 17px gap
   = a 470px lead). Below 760 the rail is already a stacked shelf (feed.css),
   so the band edge changes the feed and nothing else.

   This block sits AFTER the single-column block on purpose: it must win the
   rail's border/padding at 760-899, which is a cascade fact, not taste.

   The digest spans BOTH tracks ("digest digest"), never the rail's. With
   "digest rail" the list was pinned to the lead track -- 427.7px and one
   column -- while the rail's left hairline ran to the page foot, a 4241px box
   whose three cards end at 330px (measured 768, 2026-11-23). That empty right
   half is the "shell" reading. No JS masonry dependency: native CSS Grid areas
   already carry this layout (masonry-layout MIT and packery MIT were checked
   and declined; isotope-layout is GPL-3.0, a hard gate; see the tablet_band
   test). */
@media (min-width: 760px) and (max-width: 899px) {
  .feed {
    grid-template-columns: minmax(0, 1fr) minmax(14rem, 17rem);
    grid-template-areas:
      "lead rail"
      "secondary rail"
      "river rail"
      "compact rail"
      "digest digest";
    column-gap: clamp(1.2rem, 2.2vw, 2rem);
  }
  .feed > .feed__side {
    align-self: stretch;
    border-left: 1px solid var(--rule-soft);
    border-top: 0;
    padding-left: clamp(1rem, 1.8vw, 1.6rem);
    padding-top: 0;
    margin-top: 0;
  }
}

/* ========================================================== zh-Hans ======
   Chinese headlines carry their own word breaks; balance/pretty and negative
   tracking are Latin devices. Sizes and spacing are inherited unchanged.

   Leading is NOT inherited unchanged. A Han glyph fills its em box, so the
   ink of a Songti line runs to 1.43-1.46x the font size — measured on
   Chromium's Noto Songti at 360/390/768/1440 (tools/n3_zhlead.mjs, 2026-11-09) —
   while a Latin serif's ink rarely passes 1.0. A leading that is comfortable
   for Latin therefore packs Chinese lines so tightly that consecutive lines'
   ink overlaps: at 1.35 the shelf and rail headlines (184 of 184 rows) and
   at 1.28 the lead (every phone) were cramped, and the lead block's
   scrollHeight ran past its clientHeight, which reads as a clipped headline.
   W3C CLReq asks 1.5-2.0 for Chinese body; display type may sit under that,
   never under the ink box. 1.5 is the smallest step that clears the measured
   1.471 ink ratio at the CARD size (17-18px), and the card headline keeps it.

   The LEAD headline is a different size and was being led at 1.46. At 360-390
   it is 28px and 1.46 clears the ink; at 768 it is 34.5px and at 1440 it is
   40px, where 1.46 leaves only 0.4px (768) to 1.4px (1440) of clear space
   between baselines (e.g. 1.425 * 40 = 57px ink against 58.4px leading,
   measured 2026-11-17 with probe6 on the fixture feed). That is the packing the
   1.5 floor exists to prevent, and it is a SIZE problem, not a ratio problem: a
   fixed ratio of a bigger glyph leaves proportionally less air. So the lead is
   led at 1.5 too,
   which is cjk.css's own floor; the 1.46 exception is kept for the small
   `.card--lead` headline where 1.5 left a single stray line on a phone.

   This selector was silently taking the lead BELOW cjk.css (which also sets
   1.5): cards.css loads after cjk.css, so at equal specificity on
   `html[lang="zh-Hans"] .article__title` the later sheet won. */
html[lang="zh-Hans"] :is(.card__title, .article__title) {
  letter-spacing: 0;
  text-wrap: wrap;
  line-height: 1.5;
}
html[lang="zh-Hans"] .card--lead .card__title { line-height: 1.46; }

/* ================================================== reduced motion ======= */
@media (prefers-reduced-motion: reduce) {
  :is(.card__title, .article__title) { transition: none; }
}
