/* Cabinhub News — photographic direction. Owner: N3-DESIGN (photo lane).
   NEW file; no class is renamed and no other stylesheet is edited.

   This file is the single statement of how a photograph behaves in the
   product. media.css still owns the plate markup and the AI label; detail.css
   and cards.css still own their surfaces. photo.css sets the SLOT table, the
   crop anchor, the radius policy, the placeholder and the caption, and it must
   be the LAST stylesheet linked in index.html so these declarations win the
   equal-specificity tie against media.css/detail.css/cards.css.

   Sources behind the numbers (researched 2026-11-07, URLs in docs/bar/PHOTOS.md):
     Apple Newsroom  inline figure reserves padding-top:56.25% (16:9);
                     caption 12px/1.3333, #6e6e73, weight 600, margin 16px.
     FT (Origami)    o-teaser lazy placeholder height:0;padding-bottom:56.25%
                     (16:9); image styles have no radius; caption = sans scale -1
                     with the credit inside the figcaption.
     The Verge       ratio set found in its CSS: 16/9, 3/2, 4/5, 9/16, 1;
                     image radius token 2px; blur-up LQIP + background-position
                     50% 50%; thumbnails are server-cropped per slot.
     NYT             media container reserves 66.666% (3:2), 100%, 149.93%;
                     solid `--tpl-color-background-tertiary` behind the photo;
                     300ms transition from that ground; credit 0.6875rem (11px),
                     #727272, right-aligned serif.
   The slot table below is OUR decision, informed by those measurements. */

/* ============================================================ slot table ==
   One ratio per role, declared once and consumed below. A slot NEVER keeps
   the source ratio by accident: the 1664x928 plate (1.793) is cropped by the
   slot, not by the file. */
:root {
  --photo-hero: 16 / 9;      /* full-width article hero; lead card */
  --photo-secondary: 3 / 2;  /* the two-up pair under the lead */
  --photo-river: 1 / 1;      /* the dense river/rail thumb */
  --photo-body: 16 / 9;      /* in-prose figure and the article title plate */
  /* Faces sit in the upper two thirds of an editorial frame. Anchor the crop
     window slightly ABOVE the midline (42%, not 50%) so heads and eyes
     survive a tall crop; horizontal stays dead centre (50%) because the
     subject of a generated news plate is centred. This is inert for crops
     that trim only the sides (today's 1:1, 3:2 and 16:9 slots) and becomes
     load-bearing the first time a portrait or 4:5 slot is added. */
  --photo-anchor: 50% 42%;
}

/* One base for every photograph, whatever slot wraps it. `height: auto` plus
   an explicit ratio keeps the box reserved before bytes arrive; `cover`
   crops rather than letterboxes; there is never a border and never a shadow —
   the photograph is the frame. */
figure .thumb__img,
.plate .plate__img,
figure.story-figure img,
figure.story-figure .thumb__img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
  object-position: var(--photo-anchor);
  border: 0;
  box-shadow: none;
  /* The solid ground IS the loading state: painted from first layout, behind
     the pixels, so the box never flashes white and never reflows. */
  background: var(--paper-2);
}

/* ---- the four roles ----------------------------------------------------- */

/* Hero: full width above the headline. The largest radius in the newspaper,
   because it is the one image that behaves like a cover. */
figure.thumb--hero .thumb__img {
  aspect-ratio: var(--photo-hero);
  border-radius: var(--r-lg);
}

/* Secondary: the two-up pair under the lead. 3:2 is the classic second-tier
   crop — less panoramic than the lead, so the pair reads as its own shelf.
   (This intentionally supersedes cards.css's 16:9 for .card--secondary; the
   selector below carries one extra element so it wins even if link order is
   ever changed.) */
figure.thumb--secondary .thumb__img,
.card--secondary figure.thumb--card:has(.thumb__img) .thumb__img {
  aspect-ratio: var(--photo-secondary);
  border-radius: var(--r-md);
}

/* River / rail thumb: square, so a dense list has a rhythmic left edge. */
figure.thumb--card .thumb__img {
  aspect-ratio: var(--photo-river);
  border-radius: var(--r-md);
}

/* Lead card: the page's first voice, inside the card list, so --r-md. */
figure.thumb--lead .thumb__img {
  aspect-ratio: var(--photo-hero);
  border-radius: var(--r-md);
}

/* Article body: a photograph on a printed page, not a card. Prose gets the
   smaller radius (--r-md), which reads as a trimmed print rather than a UI
   panel. The aside title plate follows the same rule. */
figure.story-figure img,
figure.story-figure .thumb__img,
.plate .plate__img {
  aspect-ratio: var(--photo-body);
  border-radius: var(--r-md);
}

/* detail.css draws a hairline around .plate__img; a news photograph is never
   boxed. State it here as well as in the base rule so a stale build cannot
   reintroduce the border. */
.plate__img {
  border: 0;
}

/* ====================================================== placeholder ======
   Loading: the img's own --paper-2 ground (base rule) with the slot's box
   already reserved. Failure and no-image: app.js emits .thumb__empty (or, in
   the article aside, .plate__note). Both become a plain solid ground — no
   icon, no glyph, no text. The string "Illustration pending" already exists
   in app.js; it must never be seen, so its children are hidden here even
   though media.css hides them too (a stale build must not be able to leak it).

   A 300ms fade-in was REJECTED, deliberately: CSS has no "image decoded"
   state. `[loading]` is a static scheduling attribute, not load progress, so
   any CSS animation keyed to it starts at element creation and finishes
   before the bytes arrive on a slow network — it would fade the empty ground
   in and then CUT to the photo, i.e. manufacture the flash it is meant to
   hide. A real fade needs img.decode()/complete in JS (app.js, not this
   lane). The reserved paper-2 box is the honest no-flash loading state. */

.thumb__empty,
.plate .thumb__empty {
  background: var(--paper-2);
  border: 0;
  box-shadow: none;
}
/* The plate carries no text at all (app.js mediaPlaceholder emits one empty element),
   so there is no label to hide here. A `.badge` inside the slot is still suppressed:
   that one is drawn by other code paths and is not part of this lane. */
.thumb__empty .badge {
  display: none;
}

/* The article aside keeps its frame when the image fails: a solid block where
   the photograph would be, and no error sentence inside a photographic slot
   (detail.css's .plate__note). The panel label above the block already says
   what the slot is; a sentence here reads as a broken product, not a status. */
.plate:has(> .plate__note) {
  aspect-ratio: var(--photo-body);
  border-radius: var(--r-md);
  background: var(--paper-2);
}
.plate__note { display: none; }

/* ========================================================= dark mode =====
   DECISION: images are NOT dimmed, desaturated, tinted or blended in dark
   mode. The surrounding ground changes; the photograph does not. A news
   photograph is evidence, and lowering its brightness or saturation to match
   a theme corrupts the evidence. No filter/opacity/mix-blend-mode rule for
   images exists in this file, and none may be added. */

/* ================================================== caption and credit ===
   The caption is metadata: --fs-label at --ink-faint, one quiet step below the
   body. The credit is its own run — a separate line, because a photographer's
   name is not a clause in the description. The AI label pill is defined once
   in media.css (.story-figure .badge / .ai-label) and is NOT restyled here. */

.story-figure figcaption,
.thumb--hero figcaption {
  margin-top: 0.6rem;
  font-size: var(--fs-label);
  line-height: 1.55;
  color: var(--ink-faint);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.5rem;
}

.story-figure figcaption .credit,
.story-figure figcaption .photo-credit,
.thumb--hero figcaption .credit,
.thumb--hero figcaption .photo-credit {
  display: block;
  flex-basis: 100%;
  margin-top: 0.15rem;
}

/* app.js bodyImageFigure (N2 BODYIMG, 5a3a475) emits these two spans: the
   description in the caption's own ink, then credit and licence on their own
   quieter line. An empty caption collapses so the credit sits first. */
.story-figure__caption { color: var(--ink-soft); }
.story-figure__caption:empty { display: none; }
.story-figure__credit {
  flex-basis: 100%;
  margin-top: 0.1rem;
  font-size: var(--fs-micro);
  color: var(--ink-faint);
}

/* The hero caption holds the credit line a licensed photograph requires AND the AI label a
   generated plate requires — either one alone is enough to draw it (app.js renderDetail).
   No new rule is needed for it: the `.thumb--hero figcaption .photo-credit` selector above
   already gives it its own line, and it inherits the caption's own type size and ink, so a
   photograph's credit reads at the same weight as the rest of the picture's metadata.
   The label reads as the same quiet pill the in-story figures use. */
.thumb--hero .ai-label {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-faint);
  font-size: var(--fs-micro);
  line-height: 1.5;
  white-space: nowrap;
}

/* ====================================================== in-story rhythm ==
   app.js renderProse appends each assets.body_images entry as a .story-figure
   right after its paragraph, so pictures that share an after_paragraph index
   arrive as adjacent siblings: a RUN. The layout is read from the run length,
   never from a class (app.js emits none) and never from the picture's ratio:
     run of 1   one picture across the measure, whatever its shape;
     run of 2   a pair, side by side from 600px up;
     run of 3   one picture across the measure, then the pair under it;
     run of 4+  stacked, one per row (no layout is invented for it).
   A story without pictures keeps the plain block flow: the grid below only
   switches on when the body holds a figure (docs/API.md §11 compatibility). */
.prose:has(> .story-figure) {
  --fig-space: clamp(1.6rem, 3.5vw, 2.4rem); /* paragraph to picture, both ways */
  --fig-run: var(--sp-5);                     /* picture to picture in one run */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: var(--sp-4);
  align-items: start;
}
.prose:has(> .story-figure) > * { grid-column: 1 / -1; }

.prose > .story-figure { margin: var(--fig-space) 0 0; max-width: none; }
.prose > .story-figure + .story-figure { margin-top: var(--fig-run); }
.prose > .story-figure + p { margin-top: var(--fig-space); }

/* A picture on its own takes the ratio app.js reserves from `aspect`, capped
   so a portrait never runs past the screen. It stays `cover`, not `contain`:
   the pipeline falls back to aspect "16:9" when it has no dimensions
   (image_sources.as_body_image), and `contain` would then draw paper-2 bars
   inside the frame. Only a capped portrait is cropped, around --photo-anchor
   (eyes sit above the midline); on a phone a 2:3 frame is under the cap and
   shows whole. */
.prose > .story-figure img {
  max-height: min(36rem, 75svh);
}

@media (min-width: 600px) {
  .prose:has(> .story-figure) { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

  /* Pair members are the last two pictures of a run of two or three.
     A2 = start of a run of exactly two; A3 = start of a run of exactly three. */
  .prose > :is(
    :not(.story-figure) + .story-figure:has(+ .story-figure):not(:has(+ .story-figure + .story-figure)),
    :not(.story-figure) + .story-figure:has(+ .story-figure + .story-figure):not(:has(+ .story-figure + .story-figure + .story-figure)) + .story-figure
  ) { grid-column: 1; }
  .prose > :is(
    :not(.story-figure) + .story-figure:has(+ .story-figure):not(:has(+ .story-figure + .story-figure)) + .story-figure,
    :not(.story-figure) + .story-figure:has(+ .story-figure + .story-figure):not(:has(+ .story-figure + .story-figure + .story-figure)) + .story-figure + .story-figure
  ) { grid-column: 2; }

  /* The second of a lone pair starts level with the first. */
  .prose > :not(.story-figure) + .story-figure:has(+ .story-figure):not(:has(+ .story-figure + .story-figure)) + .story-figure {
    margin-top: var(--fig-space);
  }

  /* A pair is a designed shelf: both pictures share one 3:2 crop so their
     edges and captions line up. !important outranks the inline aspect-ratio
     app.js sets from `aspect`; the box is still reserved before bytes arrive. */
  .prose > :is(
    :not(.story-figure) + .story-figure:has(+ .story-figure):not(:has(+ .story-figure + .story-figure)),
    :not(.story-figure) + .story-figure:has(+ .story-figure):not(:has(+ .story-figure + .story-figure)) + .story-figure,
    :not(.story-figure) + .story-figure:has(+ .story-figure + .story-figure):not(:has(+ .story-figure + .story-figure + .story-figure)) + .story-figure,
    :not(.story-figure) + .story-figure:has(+ .story-figure + .story-figure):not(:has(+ .story-figure + .story-figure + .story-figure)) + .story-figure + .story-figure
  ) img {
    aspect-ratio: var(--photo-secondary) !important;
    max-height: none;
    object-fit: cover;
  }
}

/* ---- house graphics in small slots ------------------------------------------
   A house graphic is a typeset card whose figure sits left-aligned in the left
   two thirds of a 16:9 frame. The square river/rail/shelf crop above keeps only
   the middle 56% and cut "0.7%" to ".7%" on the live home page (2026-11-09).
   These slots show the card whole at 16:9 and a little wider, so the figure is
   legible; photographs keep the square. app.js adds .thumb--house.
   Lead and secondary cards are already full-width; they only lose the 3:2 crop. */
.card:not(.card--lead):not(.card--secondary) figure.thumb--card.thumb--house:has(.thumb__img) {
  width: 128px;
}
.card figure.thumb--card.thumb--house:has(.thumb__img) .thumb__img {
  aspect-ratio: 16 / 9;
  object-position: 0% 50%;
}
