/*
 * Zoey Made — product card.
 *
 * The canonical presentation of a WooCommerce product, wherever products are offered:
 * Featured Creations on the homepage, the shop archive, product-category archives, and
 * whatever discovery surfaces come after them. There is one implementation of it —
 * zoey_made_product_card() in functions.php builds the markup, this file gives it its
 * appearance — because the thing that goes wrong with product cards is that a second
 * near-identical one appears and the two drift.
 *
 * The rule the design is written against is STORE-004 §2:
 *
 *   The product should be the star. The card should make it easier to understand, not
 *   compete with it.
 *
 * So the card is a quiet frame: a stage for the photograph, a name, a price, and at most
 * one badge when the product's real state calls for one. There is no wishlist heart, no
 * quick add, no rating row and no category chip, because none of those is a feature this
 * store has — a control that does nothing is a lie about what the site can do, and empty
 * stars are a lie about a product.
 *
 * The card owns no grid. Whatever renders it decides how many fit across, which is why
 * every measurement here is relative and there is not a single width in the file. See
 * docs/CSS-AND-ASSETS.md.
 */

.zoey-product-card {
  /*
   * The image region's shape, as a knob rather than a constant.
   *
   * 1:1 is the starting direction STORE-004 §6 asks for and the ratio WooCommerce already
   * crops catalogue thumbnails to, so the delivered image fills the region exactly and
   * nothing is cropped a second time. It is a custom property because §6 also says the
   * final choice should follow the real product photography, and there is none yet: when
   * there is, this is the one line that changes.
   */
  --zoey-product-card-media-ratio: 1;

  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--wp--preset--color--border-soft);
  border-radius: var(--wp--custom--radius--medium);
  background-color: var(--wp--preset--color--surface);
  box-shadow: var(--wp--preset--shadow--soft);
  transition:
    transform 150ms ease,
    box-shadow 150ms ease,
    border-color 150ms ease;
}

/*
 * The image region.
 *
 * An aspect ratio rather than a height, so the space is reserved before the image arrives
 * and the grid does not move as the row loads.
 *
 * The ground behind the image is Surface Soft, and it is a ground rather than a design
 * element: the image covers the region, so what shows through is a product with no
 * photograph, artwork with transparency, and the moment before an image paints. STORE-004
 * §18 asks whether the homepage's pale washes belong here too, and the answer measured on
 * this page is no — a wash nothing can see is not framing, and the story rules out mixing
 * a second implementation of one to find out. See the implementation report.
 */
.zoey-product-card__media {
  position: relative;
  aspect-ratio: var(--zoey-product-card-media-ratio);
  background-color: var(--wp--preset--color--surface-soft);
}

/*
 * The image fills the region and is cropped rather than letterboxed, so a product shot at
 * an unexpected ratio still leaves the grid orderly. With WooCommerce's own square
 * catalogue crop this does nothing at all, which is the intended normal case, and it is
 * what keeps real photography — which arrives with its own staging — looking like a
 * photograph rather than a picture mounted on a mat.
 *
 * **The image is taken out of flow, and that is load-bearing rather than stylistic.** The
 * media region owns the card's geometry: its `aspect-ratio` is what reserves the square
 * before anything loads, and nothing inside it may be allowed to change that. An in-flow
 * image can, because `aspect-ratio` sets a preferred size and does not cap the box — a
 * child taller than the ratio grows the region, and the region grows the card, and in a
 * grid the card grows the whole row.
 *
 * That is not hypothetical. It was measured on `/shop/`: with an image whose file was
 * missing, and WordPress's `sizes="auto"` on the one lazy-loaded image in the grid, the
 * image resolved to 1500px tall inside a 290px square, and the row it sat in went from
 * 381px to 1591px, dragging three healthy cards to full-browser height with it. Removing
 * `sizes`, removing `srcset`, or fixing the file each made it go away, which is what makes
 * it a layout contract and not a bug in any one of them: an image with nothing usable to
 * measure must not be able to resize the region it is painted into.
 *
 * `inset: 0` plus `inline-size`/`block-size` — belt and braces on purpose, so the fill is
 * correct whether or not a future rule reintroduces a definite height. The card's own
 * `overflow: hidden` and radius still clip it, and the badge still paints above it because
 * it comes after the image in the markup.
 */
.zoey-product-card__image {
  position: absolute;
  inset: 0;
  display: block;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
}

/*
 * The badge.
 *
 * At most one, and only when WooCommerce says something true: Sold Out beats Sale,
 * because a product that cannot be bought is the more important fact. It is a word rather
 * than a colour — the state survives being read aloud, printed, or seen by someone who
 * cannot tell the two fills apart.
 */
.zoey-product-card__badge {
  position: absolute;
  inset-block-start: var(--wp--preset--spacing--30);
  inset-inline-start: var(--wp--preset--spacing--30);
  padding: var(--wp--preset--spacing--10) var(--wp--preset--spacing--30);
  border-radius: var(--wp--custom--radius--pill);
  font-size: var(--wp--preset--font-size--body-small);
  font-weight: 700;
  line-height: 1.4;
}

/* Ink on Surface, 13.0:1. The strongest pairing the palette has, for the one state that
   says a visitor cannot have the thing they are looking at. */
.zoey-product-card__badge--sold-out {
  background-color: var(--wp--preset--color--ink);
  color: var(--wp--preset--color--surface);
}

/* Ink on Zoey Yellow, 9.5:1. Yellow is the palette's small-positive-emphasis colour and
   this is the one place on a product card it is spent. */
.zoey-product-card__badge--sale {
  background-color: var(--wp--preset--color--zoey-yellow);
  color: var(--wp--preset--color--ink);
}

.zoey-product-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--wp--preset--spacing--20);
  padding: var(--wp--preset--spacing--40);
}

/*
 * The product name.
 *
 * card-title is the type scale's step for exactly this and is 18px, which does not shrink
 * on a narrower card: STORE-004 §38 and the global type floor both rule that out. It
 * wraps as far as it needs to rather than being truncated — a name a visitor cannot read
 * to the end is worse than a card a line taller.
 *
 * `anywhere` rather than `break-word`, and the difference between them is the whole reason
 * this line has a paragraph. Both break a word that does not fit on a line; only `anywhere`
 * reduces the element's **minimum** width, and minimum width is what sizes a grid track.
 * With `break-word` a product named `...Supercalifragilisticexpialidocious` asked for a
 * 615px column inside a 280px one and scrolled `/shop/` sideways — 9px at 320px with normal
 * text and 315px at 200% text, in all three engines. STORE-013 recorded it and left it open
 * with "whoever next touches the product card" named as the owner; PRODUCT-009 §65 is that
 * story. Related Creations and Featured Creations never overflowed under the same input
 * because their grids are `minmax(0, 1fr)`; `/shop/` is WooCommerce's `product-template`
 * grid, which sizes its tracks from content.
 *
 * Nothing about an ordinary title changes: a word that fits is not broken either way, and
 * the accepted homepage, shop and product pages are byte-identical across the change.
 *
 * The heading level is the caller's, because the card does not know what it sits under.
 * The font size is stated here so that h2 on an archive and h3 on the homepage look
 * identical, which is the point of one card.
 */
.zoey-product-card__title {
  margin: 0;
  font-size: var(--wp--preset--font-size--card-title);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/*
 * The one link.
 *
 * WooCommerce's own card links twice to the same product, from the image and again from
 * the title, which is the redundant focus stop FOUND-011 recorded and STORE-004 §47 owns.
 * Here there is one anchor, and its ::after covers the card — so the whole card is the
 * target for a finger, while the accessible name stays exactly the product's name.
 *
 * No underline at rest: the card is the affordance, and twenty underlined titles in a
 * catalogue is noise rather than clarity. Hover and focus put it back, so the text itself
 * still confirms what it is the moment anyone interacts with it.
 */
.zoey-product-card__link {
  color: var(--wp--preset--color--ink);
  text-decoration: none;
}

.zoey-product-card__link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.zoey-product-card__link:hover,
.zoey-product-card__link:focus-visible {
  text-decoration: underline;
}

/*
 * The price, straight from WooCommerce and never rebuilt: whatever get_price_html()
 * returns is what a visitor sees, including a range for a product that has one and
 * nothing at all for a product with no price. Inventing a display value here is how a
 * storefront ends up quoting a figure the checkout disagrees with.
 *
 * Quieter than the name, because the hierarchy is image, then name, then price — but at
 * body size and in Ink at 13.0:1, which is not the same as obscure.
 */
.zoey-product-card__price {
  margin: 0;
  font-size: var(--wp--preset--font-size--body);
  color: var(--wp--preset--color--ink);
}

/*
 * A sale price is <del> and <ins> — WooCommerce's markup, and semantic rather than a pair
 * of colours. Two things need correcting for it: <ins> is underlined by default and reads
 * as a link, and the two prices need separating. The old price also takes Ink Soft, which
 * is a Surface colour and is on one here.
 */
.zoey-product-card__price ins {
  text-decoration: none;
}

.zoey-product-card__price del {
  margin-inline-end: var(--wp--preset--spacing--20);
  color: var(--wp--preset--color--ink-soft);
}

/*
 * Hover: a small lift and a warmer edge, and nothing that reveals information. Everything
 * the card has to say is already on it.
 *
 * Behind a hover query so a touch device does not hold the lifted state after a tap. The
 * reduced-motion preference is honoured site-wide in base.css, which collapses the
 * transition rather than the state — the card still lifts, it just stops travelling.
 */
@media (hover: hover) {
  .zoey-product-card:hover {
    transform: translateY(-2px);
    border-color: var(--wp--preset--color--zoey-lavender);
    box-shadow: var(--wp--preset--shadow--lifted);
  }
}

/*
 * Focus.
 *
 * The site's one ring, moved from the anchor to the card, because the card is what the
 * anchor covers: a ring around three words of title would be describing a target much
 * smaller than the one that responds. This is the same 3px Ink outline base.css defines
 * for everything else — not a component inventing its own treatment.
 *
 * The @supports guard is why the outline: none is safe. Without :has() neither rule
 * applies and the anchor keeps the site ring, so no engine can end up with no ring at
 * all. See docs/ACCESSIBILITY.md.
 *
 * The second selector is long on purpose. base.css writes the site ring through an :is()
 * list, which carries the specificity of its longest branch — deliberately more than a
 * class, so that a component cannot casually weaken the ring. Restating the :has()
 * condition beats it, and says what it means: the link stops drawing its own ring exactly
 * when the card is drawing one for it.
 *
 * Order cannot be relied on here. A stylesheet registered against a block prints *before*
 * base.css and before global styles, and the same file enqueued on wp_enqueue_scripts
 * prints after both — so a rule that wins by source order would behave differently
 * depending on which surface loaded it. Measured, with both rings drawing at once.
 */
@supports selector(:has(*)) {
  .zoey-product-card:has(.zoey-product-card__link:focus-visible) {
    outline: 3px solid var(--wp--preset--color--ink);
    outline-offset: 2px;
  }

  .zoey-product-card:has(.zoey-product-card__link:focus-visible) .zoey-product-card__link:focus-visible {
    outline: none;
  }
}

/* --- The Shop variant (SL-006, D1 / D3) -------------------------------------------- */

/*
 * The catalogue's card. Three differences from the card above, and the rules below are only those
 * three — everything else about a product card is declared once, further up this file, and the
 * variant wears it.
 *
 *   the ground    the approved soft-paper surface, at its own grain 0.5
 *   the title     non-linked text
 *   the action    a visible secondary-outline control, which is the card's one anchor
 *
 * **What is deliberately absent is a second card.** `zoey_made_product_card()` has one
 * implementation and this is an option on it; the homepage's Featured Creations, Related Creations
 * on a product page, the product-taxonomy archives and the proof surface all render the `standard`
 * card and none of them sees a single rule in this section. That boundary is tested, not assumed —
 * see the SL-006 report.
 *
 * ## The surface brings its own box, which is why the base rules are turned off rather than tuned
 *
 * A `standard` card draws its own white ground, hairline, radius and shadow. The Shop variant's
 * ground is `zoey_made_surface()`'s, so those four would be a second card painted underneath the
 * paper — a hairline inside a sheet, and two shadows. They are removed here rather than made
 * conditional up there, so that the accepted card's declarations are untouched and a reader of the
 * base rules sees exactly what the accepted surfaces get.
 *
 * `overflow: hidden` goes too, and that one matters: the surface clips its own decorative layers,
 * and the base card's `overflow: hidden` on top of `position: relative` would clip the focus ring
 * this variant draws **outside** the card's box.
 */
.zoey-product-card--shop {
  border: 0;
  border-radius: 0;
  background-color: transparent;
  box-shadow: none;
  overflow: visible;
}

/*
 * The surface's content wrapper is the flex column the base card's root normally is.
 *
 * The media, the body and the action stack inside the paper's padding rather than against the
 * card's edge, which is the same composition the accepted `collection` activity card uses for a
 * picture on paper — inset, with its own radius — and is what the approved board shows.
 */
.zoey-product-card--shop > .zoey-surface__content {
  display: flex;
  flex-direction: column;
  gap: var(--wp--preset--spacing--40);
}

/*
 * The media keeps the base variant's square and its ground, and gains a radius of its own because
 * it is no longer clipped by the card's.
 *
 * `overflow: hidden` here rather than on the card: the image is absolutely positioned and
 * `object-fit: cover`, so without a clipping ancestor its corners would square off over the paper.
 */
/*
 * The media keeps the base variant's square and its ground, and the **image** is what carries the
 * radius — not the region around it.
 *
 * It was the region, with `overflow: hidden`, which rounded the picture correctly and **clipped the
 * badge**. Measured at 390px with a 32px root: the *Sold Out* badge laid out 70 x 290px inside an
 * 85 x 85px media box, so a reader at that text size saw a dark square containing the letter *S*.
 * A badge is the one thing on this card that states a fact WooCommerce reports, and it is the last
 * thing that may be cut off.
 *
 * Rounding the image directly gives the same picture with no clipping ancestor, so the badge is
 * free to be as large as its text needs. The image is absolutely positioned and `object-fit: cover`,
 * so its own border-radius is what a viewer sees.
 */
.zoey-product-card--shop .zoey-product-card__media {
  border-radius: var(--wp--custom--radius--medium);
}

.zoey-product-card--shop .zoey-product-card__image {
  border-radius: var(--wp--custom--radius--medium);
}

/*
 * The body stops being a padded region — the paper's own padding is the card's padding now — and
 * becomes the column the title, price and action sit in.
 */
.zoey-product-card--shop .zoey-product-card__body {
  padding: 0;
  gap: var(--wp--preset--spacing--20);
}

/*
 * The action sits at the bottom of the card, and the cards in a row end up the same height with
 * their controls on one line.
 *
 * `margin-block-start: auto` rather than a fixed height anywhere: the design contract rules out a
 * fixed card height that clips content, and a long title must be free to take a third line. This
 * aligns the controls **without** constraining what is above them — a taller card simply has more
 * space between its price and its button.
 */
.zoey-product-card--shop .zoey-product-card__action {
  margin-block-start: auto;
}

/*
 * **The control stays statically positioned, and that is load-bearing rather than an omission.**
 *
 * An absolutely positioned pseudo-element resolves against the padding box of its nearest
 * *positioned* ancestor. Giving the control `position: relative` — which the first version of this
 * rule did — made the overlay resolve against the control itself, so the "whole card" target was a
 * 44px-tall strip at the bottom of the card. Measured before it shipped.
 *
 * Left static, the chain is control -> body -> `.zoey-surface__content`, which the surface already
 * positions with `z-index: 1` to lift content above its tint and grain layers. `__content` is the
 * surface's only in-flow child and the surface has no padding of its own, so `__content`'s padding
 * box **is** the card — which is why `inset: 0` covers the paper's own padding ring too and needs
 * no negative offsets to reach the card's edge.
 */

/*
 * The one anchor, stretched over the whole card — `D1`.
 *
 * This is the accepted card's own mechanism, moved: it was `.zoey-product-card__link::after` on the
 * title anchor, and it is now on the action. Everything the contract protects is unchanged — one
 * anchor, one focus stop, the whole card as the click target — and what changed is which element
 * carries it.
 *
 * **`z-index` is why this works over paper where the original needed none.** The surface paints its
 * tint and grain in two pseudo-elements and lifts `__content` above them with `z-index: 1`; an
 * overlay at the default `auto` would sit inside that stacking context and still cover the card,
 * but the control itself has to stay above its own overlay or the label would be unclickable.
 * Stated rather than left to painting order, because the surface's layers make the order a real
 * question here rather than an academic one.
 */
.zoey-product-card--shop .zoey-product-card__action::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

/*
 * The title is text, so it takes the link colour the anchor used to give it and nothing else. No
 * hover underline, because there is nothing here to activate: the affordance is the control below
 * it and the whole card around it.
 */
.zoey-product-card--shop .zoey-product-card__title {
  color: var(--wp--preset--color--ink);
}

/*
 * **The control's label and the price break at spaces, never inside a word or a number.**
 *
 * `.zoey-surface__content` sets `overflow-wrap: anywhere` — correctly, because an unbreakable token
 * inside a surface would otherwise push past the card, which is the defect VS-006 and PRODUCT-009
 * each measured. Everything inside the paper inherits it, and on a narrow card at a reader's
 * doubled text that produced, measured at 390px with a 32px root:
 *
 *     View details   a 19px box holding a 100px word -> one letter per line, ten lines
 *     $12.50         fragmented across lines mid-number
 *
 * A title may still break anywhere and **must** keep that: it is what reduces the element's
 * min-content width, which is what sizes a grid track, and `/shop/` scrolled sideways without it.
 * A control's label and a price are different — neither is ever the thing that sizes a track, and
 * both become unreadable when broken. So the inheritance is undone for exactly those two.
 *
 * This is a readability fix and not the whole answer: the card also has to stop being 85px wide at
 * that text size, which is `components/shop-archive.css`'s single-column fallback.
 */
.zoey-product-card--shop .zoey-product-card__action .zoey-action__label,
.zoey-product-card--shop .zoey-product-card__price {
  overflow-wrap: normal;
  word-break: normal;
}

/*
 * The whole-card focus ring, following the anchor.
 *
 * Same shape, same reasoning and the same `@supports` guard as the base card's: the ring goes on
 * the card because the card is what the anchor covers, and without `:has()` neither rule applies so
 * the control keeps the site ring and no engine ends up with no ring at all. The second selector is
 * long for the reason the base rule records — `base.css` writes the site ring through an `:is()`
 * list whose specificity a single class cannot beat.
 *
 * `action.css` draws its own focus ring on `.zoey-action`, which is why the inner rule turns it off
 * here specifically: two rings, one inside the other, on one tab stop.
 */
@supports selector(:has(*)) {
  .zoey-product-card--shop:has(.zoey-product-card__action:focus-visible) {
    outline: 3px solid var(--wp--preset--color--ink);
    outline-offset: 2px;
  }

  .zoey-product-card--shop:has(.zoey-product-card__action:focus-visible) .zoey-product-card__action:focus-visible {
    outline: none;
  }
}

/*
 * Hover: the same small lift the accepted card has, on the paper rather than on the white box.
 * Behind the same `hover: hover` query, so a touch device does not hold the lifted state after a
 * tap, and the border-colour change the base rule makes is dropped — there is no border to warm.
 */
@media (hover: hover) {
  .zoey-product-card--shop:hover {
    transform: translateY(-2px);
    box-shadow: var(--wp--preset--shadow--lifted);
  }
}
