/* -----------------------------------------------
   PATTERNS: valencia/query-cards, valencia/query-cards-lead

   One card, two photo treatments, chosen by a modifier on the wrapper:
     .valencia-qcards--fade   photo fills the card, colour fades up
     .valencia-qcards--plate  solid colour, photo as a corner plate

   THE ARCHITECTURE. Core's post-featured-image block renders NOTHING
   when a post has no featured image. That is the entire conditional —
   no PHP, no has-image class, no fallback markup. So the card is always
   the colour field with its title, complete on its own, and the photo
   is a layer that simply is not there for the 19 of 51 posts without
   one. Nothing degrades, because the no-photo card IS the base state.

   THE ONE DEPARTURE FROM THE THEME'S RULE. Card colours are assigned
   here by :nth-child, not as block attributes, so they cannot be
   changed in the editor sidebar. Query Loop renders ONE template N
   times — there is no per-card markup to hang an attribute on, so a
   cycling palette is only expressible in CSS. The colours are exposed
   as custom properties on the wrapper (--qc-1 … --qc-4) so a page can
   override the set in one place without editing selectors.

   Why cycle by position rather than map to category: 23 of 51 posts
   are Uncategorized and there are 12 categories against ~5 usable
   colours, so a category map would paint nearly half the grid one
   colour and scatter singletons through the rest. Position claims no
   meaning and always balances.

   Everything else IS a block attribute: post counts, offset, order,
   columns, the grid gap, and the spacing on every element.
   ----------------------------------------------- */

.valencia-qcards {
  --qc-1: var(--wp--preset--color--ink-deep);
  --qc-2: var(--wp--preset--color--accent-strong);
  --qc-3: var(--wp--preset--color--sage);
  --qc-4: var(--wp--preset--color--ink-row);
}

/* ---------- the card, shared ---------- */

.valencia-qcard {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
  aspect-ratio: 4 / 3;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: var(--wp--preset--spacing--md);
  background: var(--qc-1);
  transition: transform 0.18s ease;
}

.valencia-qcard:hover {
  transform: translateY(-3px);
}

/* The colour cycle. Scoped to the grid loop so the lead keeps its own
   fixed colour below. */
.valencia-qcards-grid .valencia-qcard,
.valencia-qcards--plate .valencia-qcard {
  background: var(--qc-1);
}
.valencia-qcards-grid .wp-block-post:nth-child(4n + 2) .valencia-qcard,
.valencia-qcards--plate .wp-block-post:nth-child(4n + 2) .valencia-qcard {
  background: var(--qc-2);
}
.valencia-qcards-grid .wp-block-post:nth-child(4n + 3) .valencia-qcard,
.valencia-qcards--plate .wp-block-post:nth-child(4n + 3) .valencia-qcard {
  background: var(--qc-3);
}
.valencia-qcards-grid .wp-block-post:nth-child(4n + 4) .valencia-qcard,
.valencia-qcards--plate .wp-block-post:nth-child(4n + 4) .valencia-qcard {
  background: var(--qc-4);
}

/* Text sits above whatever the photo layer does. */
.valencia-qcard-text {
  position: relative;
  z-index: 3;
}

/* core-single-post.css puts a 2px accent underline on every link in
   entry content, and these cards are all links; on a coloured card that
   reads as damage. Traded for the whole card's hover lift. */
.valencia-qcard a,
.valencia-qcard a:hover,
.valencia-qcard a:focus {
  text-decoration: none;
  border-bottom: none;
  box-shadow: none;
}

.valencia-qcard-cat a,
.valencia-qcard-cat {
  font-family: var(--wp--preset--font-family--mono);
  font-size: var(--wp--preset--font-size--caption);
  color: var(--wp--preset--color--base);
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* The title is the card. Doubled class beats core's own
   .wp-block-post-title margins, which print after the theme sheet. */
.valencia-qcard-title.valencia-qcard-title {
  margin: var(--wp--preset--spacing--xs) 0 0;
  font-size: var(--wp--preset--font-size--large);
  line-height: 1.05;
}

.valencia-qcard-title a {
  color: var(--wp--preset--color--base);
  text-decoration: none;
}

.valencia-qcard-date {
  margin: var(--wp--preset--spacing--xs) 0 0;
  font-size: var(--wp--preset--font-size--caption);
  color: var(--wp--preset--color--base);
  opacity: 0.7;
}

/* ---------- treatment: bottom fade ---------- */

.valencia-qcards--fade .valencia-qcard-photo {
  position: absolute;
  inset: 0;
  z-index: 1;
  margin: 0;
}

.valencia-qcards--fade .valencia-qcard-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* The gradient is the card's OWN colour rising from the base, so the
   photo and no-photo cards share a ground and the transition is
   invisible. currentColor is not usable here — the fill has to match
   the background, so each cycle position repeats it. */
.valencia-qcards--fade .valencia-qcard::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(to top, var(--qc-1) 0%, var(--qc-1) 28%, transparent 78%);
}
.valencia-qcards-grid .wp-block-post:nth-child(4n + 2) .valencia-qcard::after {
  background: linear-gradient(to top, var(--qc-2) 0%, var(--qc-2) 28%, transparent 78%);
}
.valencia-qcards-grid .wp-block-post:nth-child(4n + 3) .valencia-qcard::after {
  background: linear-gradient(to top, var(--qc-3) 0%, var(--qc-3) 28%, transparent 78%);
}
.valencia-qcards-grid .wp-block-post:nth-child(4n + 4) .valencia-qcard::after {
  background: linear-gradient(to top, var(--qc-4) 0%, var(--qc-4) 28%, transparent 78%);
}

/* The lead spans the full width in a cinematic band and keeps ink-deep,
   so it anchors the section while the grid below carries the rhythm. */
.valencia-qcards-lead .valencia-qcard {
  aspect-ratio: 21 / 9;
  background: var(--qc-1);
  padding: var(--wp--preset--spacing--lg);
}

.valencia-qcards-lead .valencia-qcard-title.valencia-qcard-title {
  font-size: var(--wp--preset--font-size--x-large);
}

/* A 21:9 band is too short for its own text on a phone; let it grow. */
@media (max-width: 600px) {
  .valencia-qcards-lead .valencia-qcard {
    aspect-ratio: 4 / 3;
    padding: var(--wp--preset--spacing--md);
  }
}

/* ---------- treatment: corner plate ---------- */

/* The photo is jewellery pinned over an untouched card: no added
   height, nothing to lay out around, and it disappears cleanly when a
   post has no image. Grown from the notes-feed badge — bigger, squarer,
   a real border and shadow at this scale. */
.valencia-qcards--plate .valencia-qcard-photo {
  position: absolute;
  top: -10px;
  right: -10px;
  /* 38%, not 44%: at 44 the plate reaches far enough down the card that
     a two-line title runs under it. The text is bottom-aligned, so the
     collision is with the plate's lower edge, not its width alone. */
  width: 38%;
  aspect-ratio: 1;
  z-index: 3;
  margin: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 4px solid var(--wp--preset--color--base);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  transform: rotate(3deg);
  transition: transform 0.18s ease;
}

.valencia-qcards--plate .valencia-qcard:hover .valencia-qcard-photo {
  transform: rotate(3deg) scale(1.05);
}

/* Keep the title clear of the plate. The text is bottom-aligned and the
   plate is top-pinned, so they only meet when a title runs to three
   lines — but a long title is common enough that this cannot rely on
   luck. The reserve is only applied on cards that actually have a
   plate: :has() means a post with no featured image keeps the full
   width for its title. */
.valencia-qcards--plate .valencia-qcard:has(.valencia-qcard-photo) .valencia-qcard-title {
  padding-right: 22%;
}

.valencia-qcards--plate .valencia-qcard-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---------- editor ---------- */

/* The editor wraps every block in .wp-block, whose default vertical
   margin opens gaps the frontend never has. Inert on the frontend. */
.valencia-qcard .block-editor-block-list__layout > .wp-block {
  margin-top: 0;
  margin-bottom: 0;
}
