/* Bento grid — per-project image/text grid.

   Below the desktop breakpoint (<75rem — phones and tablets, 2 columns)
   rows size to their content: image/video cells carry an explicit square
   height (one column wide, via container query units — see below), while
   text cells simply take the height of their own copy. This keeps every
   image a true square while letting a text block be exactly as tall as
   its content + skills — no wasted vertical space, and no clipping when
   the copy runs long (the failure the old uniform fixed-row grid hit on
   narrow tablet columns, where a long text block was cut off).

   At >=75rem (desktop, 3 columns) rows switch to a fixed square height
   computed to exactly equal one column's width, so every cell aligns on
   a strict grid and a wide text block is exactly one row tall — there,
   fitting the copy to that square is the author's job (per Liam), not
   the layout's.

   The query container for cqw is `.project` (see layout.css), not this
   element — cqw can't resolve against the same element whose own layout
   it helps determine, so container-type lives one level up (.project__grid
   fills 100% of .project's content width, so the widths are identical). */
.project__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-flow: dense;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

/* Image/video cells are square (one column wide) on the 2-column layout
   via an explicit height rather than a fixed grid-row track, so text
   cells in other rows can size to their own content. A wide (2x1) image
   keeps this same height and just spans two columns. */
.project__grid-item:not(.project__grid-item--text) {
  height: calc((100cqw - var(--space-3)) / 2);
}

@media (min-width: 75rem) {
  .project__grid {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: calc((100cqw - 2 * var(--space-4)) / 3);
    gap: var(--space-4);
  }

  /* Back to strict fixed square rows — the media cell fills its row
     (its img/video is absolute inset:0) rather than carrying a height. */
  .project__grid-item:not(.project__grid-item--text) {
    height: auto;
  }
}

.project__grid-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-block);
  background: var(--color-border);
}

/* Each image/video stays invisible until it's ready to show, then
   soft-fades in, rather than popping in the instant its network
   request completes. The whole <main> is itself held back until the
   header's name has faded in (see layout.css), so this fade only
   really shows for media that finishes loading after that reveal.
   js/render-projects.js adds .is-loaded once the media is ready (an
   image's `load` event, a video's `loadeddata` event, or immediately
   if already cached/complete). */
.project__grid-item img,
.project__grid-item video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.6s ease-in-out;
}

.project__grid-item img.is-loaded,
.project__grid-item video.is-loaded {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .project__grid-item img,
  .project__grid-item video {
    transition: none;
  }
}

/* span: "2x1" — spans two columns, one row */
.project__grid-item--wide {
  grid-column: span 2;
}

/* A wide (2x1) text block spans both columns. Below 75rem it takes its
   natural content height (the grid's auto rows); at >=75rem it locks to
   a single fixed square row like every other cell. */
@media (min-width: 75rem) {
  .project__grid-item--text.project__grid-item--wide {
    grid-row: span 1;
  }
}

/* Caption overlay, positioned inside the block — same 16px padding as
   the text blocks (--space-3). */
.project__grid-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: var(--space-3);
  font-size: var(--font-size-sm);
  line-height: 1.3;
}

.project__grid-caption a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.project__grid-caption--white {
  color: #ffffff;
}

.project__grid-caption--black {
  color: #111111;
}

/* Phones only (<=40rem): captions overlap the image content awkwardly at
   these small sizes, so they're hidden. They stay on tablet and up. */
@media (max-width: 40rem) {
  .project__grid-caption {
    display: none;
  }
}

/* Text-only block — no image, background colour + heading/body copy.
   16px padding on all sides (--space-3), content top/left-aligned.
   32px (2rem) between the badge pill and the copy that follows it. */
.project__grid-item--text {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  text-align: left;
  gap: 2rem;
  padding: var(--space-3);
  background: var(--block-bg, #222222);
  color: var(--block-text, #ffffff);
}

.project__block-badge {
  display: inline-block;
  align-self: flex-start;
  /* 2px less below the text than above, to optically center it. */
  padding: 10px var(--space-3) 8px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--color-text);
  font-size: var(--font-size-xs);
  letter-spacing: 0;
  line-height: 1;
}

.project__block-heading,
.project__block-body p,
.project__block-credit-role,
.project__block-credit-name {
  font-size: var(--font-size-base);
  letter-spacing: 0;
  line-height: var(--line-height-heading);
}

/* Prevent single-word last lines (widows) in the card heading and body
   copy. Deliberately not applied to credits or skills — those are short
   label-like lines where widow-balancing isn't wanted. */
.project__block-heading,
.project__block-body p {
  text-wrap: pretty;
}

.project__block-body {
  display: flex;
  flex-direction: column;
}

/* Credits — grouped responsibility + contributors (e.g. "Design" →
   "Liam Kennedy" / "Elias Lemke"). Groups stack with a gap between
   them; within a group the role sits directly above its names. The role
   is dimmed to 70% of the block's text color (opacity, since the label
   is text-only); names inherit the full-strength text color. */
.project__block-credits {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.project__block-credit {
  display: flex;
  flex-direction: column;
}

.project__block-credit-role {
  opacity: 0.7;
}

/* A 1x1 credits list (multiple role groups, each with several names) can
   run long — on mobile, where text cells hug their own content height
   instead of a fixed square, that pushes the card noticeably taller
   than the 1x1 image cells beside it. Dropping to --font-size-sm (14px)
   for just this case brings the card back down without touching wide
   (2x1) cards, which have the width to carry the copy at the normal
   size, or credits on tablet/desktop. */
@media (max-width: 40rem) {
  .project__grid-item--text:not(.project__grid-item--wide) .project__block-credit-role,
  .project__grid-item--text:not(.project__grid-item--wide) .project__block-credit-name {
    font-size: var(--font-size-sm);
  }
}

/* 16px between paragraphs of body copy. The block's own flex gap (2rem,
   on .project__grid-item--text) still separates the body group as a
   whole from the badge/heading above and the skill pills below. */
.project__block-body {
  gap: var(--space-3);
}

/* Skill pills — a wrapped row pinned to the bottom of the text block
   (margin-top: auto absorbs the free space in the flex column so the
   row sits at the bottom regardless of copy length). Same padding and
   shape as the date badge above; background/text color are editable
   per-block and shared across all of that block's pills. */
.project__block-skills {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.project__block-skill {
  display: inline-block;
  /* 2px less below the text than above, to optically center it —
     matches .project__block-badge. */
  padding: 10px var(--space-3) 8px;
  border-radius: 999px;
  background: var(--skill-bg, #ffffff);
  color: var(--skill-text, var(--color-text));
  font-size: var(--font-size-xs);
  letter-spacing: 0;
  line-height: 1;
}
