/*
 * Zoey Made — the shared control family (VS-005).
 *
 * `STYLE-GUIDE-v1.md` §8's two button roles, declared once each. `inc/content/action.php` is the
 * renderer and the allowlists; this file is the appearance, and it is the appearance of **both**
 * markups the family reaches the page in:
 *
 *   .zoey-action                      this component's own control, from zoey_made_action()
 *   .zoey-home-button--secondary …    a core Button block an editor placed, given the variant
 *
 * The second of those is the reason this file names one of core's classes, which `docs/CSS-AND-
 * ASSETS.md` allows for exactly this case — a component built out of a core block, where the
 * markup is core's and the design is ours. The rule is deliberately more specific than the
 * element style it replaces and restates its hover state, because block styles and component
 * styles can print in either order and a tie is decided by nothing we control.
 *
 * **The primary variant is not declared here for core's markup**, and that is the division worth
 * understanding: `theme.json`'s `elements.button` is the primary button for every core Button
 * block on the site, including WooCommerce's submit controls, and has been since FOUND-004. This
 * file restates the same values against `.zoey-action--primary` for controls that are not core
 * blocks. Two selectors, one set of tokens, and `scripts/dev/content.mjs` reads the computed
 * paint off one of each and fails if they drift.
 *
 * Loaded by whatever renders a control — `zoey_made_component_style( 'action' )` — and by the
 * homepage and Make stylesheets' own surfaces, so a cart or checkout document carries none of it
 * unless WooCommerce's own controls are on the page, which they style themselves.
 */

/*
 * The shape every control shares.
 *
 * `inline-flex` rather than `flex`, so a control is as wide as its label by default and a
 * surface that wants a full-width one asks for it. The 48px minimum is §8's target for a new
 * child-facing control, met by the control's own box rather than by a transparent tap target
 * drawn around it — which is what keeps the thing you can see and the thing you can hit the
 * same shape.
 */
/*
 * A control that is `hidden` is hidden.
 *
 * `display: inline-flex` below sets a display value, and a class rule beats the user agent's
 * `[hidden] { display: none }` — so without this, an `.zoey-action` carrying the attribute stays on
 * the screen **and in the tab order**, while every attribute check in sight reports it hidden. That
 * is exactly what happened on the spelling practice: the directives set `hidden` correctly on every
 * control that did not apply to the current step, the state was right, and all four buttons showed
 * anyway.
 *
 * It lives here rather than in the consumer because the next component to set a display value will
 * have the same problem, and because a shared control that cannot be hidden is a defect in the
 * control. One extra attribute of specificity, no `!important`.
 */
.zoey-action[hidden] {
  display: none;
}

.zoey-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--wp--preset--spacing--20);
  min-block-size: 48px;
  padding-inline: var(--wp--preset--spacing--50);
  border: 1px solid transparent;
  border-radius: var(--wp--custom--radius--pill);
  font-family: var(--wp--preset--font-family--primary);
  font-size: var(--wp--preset--font-size--body);
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  text-decoration: none;

  /* §8 allows a short border/shadow transition; base.css removes it under reduced motion. */
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

/*
 * A button element arrives with the browser's own chrome on it. An anchor does not, so these
 * four are stated here rather than relied on: without them the same variant renders as two
 * slightly different controls depending on which element the caller's arguments produced.
 */
.zoey-action {
  appearance: none;
  background-image: none;
  cursor: pointer;
  margin: 0;
}

/*
 * A control can never be wider than what it is in, and a long label wraps rather than pushing it
 * there.
 *
 * Both halves are needed and VS-005 shipped neither at first. `overflow-wrap: anywhere` on the
 * label lets a long word break *and* reduces the label's min-content width, which is what lets a
 * flex item shrink at all. `max-inline-size: 100%` on the control is the backstop for the case
 * the label cannot help with: a control whose padding alone exceeds its container.
 *
 * That case is real rather than theoretical. Measured at 320px with a reader's text at 200%, a
 * disabled secondary control rendered **162px wide inside a 23px container** — because the
 * padding is 1.5rem a side, which is 48px at that text size, and nothing capped the box. The
 * label had already shrunk to a single character; there was nothing left for it to give.
 */
.zoey-action {
  max-inline-size: 100%;
  min-inline-size: 0;
}

.zoey-action__label {
  min-inline-size: 0;
  overflow-wrap: anywhere;
}

/*
 * And at the narrow end the padding comes in, for the same reason `surface.css` brings its own in:
 * 1.5rem a side is right in a 390px column and is most of a 320px one once a reader has doubled
 * their text. 1rem keeps the control a pill rather than a circle around two letters.
 *
 * A media query rather than a container query, deliberately: a control is not a container, and
 * its own width is the thing being decided here rather than the thing being responded to.
 */
@media (max-width: 47.99rem) {
  .zoey-action {
    padding-inline: var(--wp--preset--spacing--40);
  }
}

/* The glyph keeps its own size and never shrinks to make room for the label. */
.zoey-action__icon {
  flex: none;
}

/* --- The two variants -------------------------------------------------------------------- */

/*
 * Primary. §8: pink fill, Ink label, pill shape — the one obvious thing to do on a surface.
 *
 * Ink on Zoey Pink measures **5.54:1**, which clears AA for body text, and the hover state inverts
 * to Surface on Ink at 13.0:1. The same two pairings `theme.json` sets for `elements.button`, read
 * from the same tokens.
 *
 * The first number is worth a note. `make-landing.css` carried this pairing as **8.9:1** from
 * MAKE-005, and VS-005 moved the rule and the claim together — then `scripts/dev/content.mjs`
 * measured the painted control and returned 5.54. Checking it by hand against the palette agrees:
 * Ink `#332F3D` has a relative luminance of 0.0307 and Zoey Pink `#FF7FB3` 0.3987, which is
 * 5.56:1 before rounding. The old figure was simply wrong. Nothing changes as a result — 5.54
 * clears the 4.5:1 AA asks of body text, and comfortably clears the 3:1 for large text — but a
 * number that has been measured is worth more than one that has been copied, and the copying is
 * how it survived three stories.
 */
.zoey-action--primary {
  background-color: var(--wp--preset--color--zoey-pink);
  color: var(--wp--preset--color--ink);
}

.zoey-action--primary:hover,
.zoey-action--primary:active {
  background-color: var(--wp--preset--color--ink);
  color: var(--wp--preset--color--surface);
}

/*
 * Secondary. §8: plain fill and a **visible** outline.
 *
 * Ink Soft, not Border Soft, and the difference is the whole of the word "visible": Border Soft
 * against Surface measures 1.1:1, which is a hairline you cannot quite see and does not read as
 * an outline at all. Ink Soft measures 4.5:1 and does. Both approved references draw this border
 * in Ink Soft, and `.zoey-home-button--secondary` drew it in Border Soft — so adopting the
 * family is a visible change on the homepage, recorded in the VS-005 report with before and
 * after rather than slipped in.
 *
 * The hover state is the one the homepage already had, which is also the one the component board
 * shows: the outline fills with Ink. So the two controls now agree on hover as well as at rest.
 */
.zoey-action--secondary {
  border-color: var(--wp--preset--color--ink-soft);
  background-color: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--ink);
}

.zoey-action--secondary:hover,
.zoey-action--secondary:active {
  border-color: var(--wp--preset--color--ink);
  background-color: var(--wp--preset--color--ink);
  color: var(--wp--preset--color--surface);
}

/*
 * The same variant, over a core Button block.
 *
 * `.zoey-home-button--secondary` is a className on a core Buttons block, so the markup is
 * core's and the only thing this theme can do is name the class core puts on the control. Two
 * components of specificity against `elements.button`'s one, and the hover state restated for
 * the ordering reason in the file header. This is the single declaration of the variant for both
 * markups — the values are the same custom properties the rules above read.
 */
.zoey-home-button--secondary .wp-element-button {
  border: 1px solid var(--wp--preset--color--ink-soft);
  background-color: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--ink);
}

.zoey-home-button--secondary .wp-element-button:hover,
.zoey-home-button--secondary .wp-element-button:focus {
  border-color: var(--wp--preset--color--ink);
  background-color: var(--wp--preset--color--ink);
  color: var(--wp--preset--color--surface);
}

/* --- Size ------------------------------------------------------------------------------- */

/*
 * §8 again, and both of its numbers: 48px for a new child-facing control, and *"preserving at
 * least the existing 44px utility targets"*. `compact` is that 44px, and it exists so an
 * existing control the guide explicitly allows to stay at 44 can adopt this family without
 * growing — which matters on the Make card, whose call to action is measured against a phone's
 * usable height to the pixel.
 *
 * Only the box is shorter. The label stays Body, the way a compact icon is a smaller box and not
 * a lighter drawing.
 */
.zoey-action--compact {
  min-block-size: 44px;
  padding-inline: var(--wp--preset--spacing--40);
}

/* --- Fill ------------------------------------------------------------------------------- */

.zoey-action--fill-always {
  display: flex;
  inline-size: 100%;
}

/*
 * The full width of its container on a phone and content-sized from 48rem, which is what both
 * approved references show and what `MAKE-LANDING-PROD-001` §6 asks for by name. Written as a
 * max-width query so the content-sized form is the unprefixed default and a browser that drops
 * the query gets the desktop control rather than a full-width one.
 */
@media (max-width: 47.99rem) {
  .zoey-action--fill-narrow {
    display: flex;
    inline-size: 100%;
  }
}

/* --- Disabled --------------------------------------------------------------------------- */

/*
 * A control that cannot be used, and the reason beside it.
 *
 * The fade is not the state — it is the hint that there is one. §9: *"Never communicate state by
 * color alone."* The state is carried by the `disabled` attribute, which takes the control out of
 * the tab order and out of the set of things that can be activated, and by the sentence the
 * renderer puts next to it. A reader who cannot tell 55% ink from 100% still gets both.
 *
 * `:hover` is restated to nothing, because a disabled control that lights up under the pointer
 * is telling the reader it is available.
 */
.zoey-action:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.zoey-action--primary:disabled:hover {
  background-color: var(--wp--preset--color--zoey-pink);
  color: var(--wp--preset--color--ink);
}

.zoey-action--secondary:disabled:hover {
  border-color: var(--wp--preset--color--ink-soft);
  background-color: var(--wp--preset--color--surface);
  color: var(--wp--preset--color--ink);
}

/*
 * A control and its reason are one thing to lay out, and the wrapper must be able to shrink to
 * whatever it is given — otherwise it hands its children a width it does not have, which is the
 * 23px container the control above overflowed.
 */
.zoey-action-state {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wp--preset--spacing--20) var(--wp--preset--spacing--30);
  min-inline-size: 0;
  max-inline-size: 100%;
}

/*
 * The reason, which is prose and therefore the thing most likely to be too wide for the box it is
 * in. All three declarations are needed and the last two were added after measuring: a flex item
 * will not shrink below its own min-content width without `min-inline-size: 0`, and `anywhere` is
 * what makes that min-content width a character rather than the longest word. Measured inside a
 * study card at 320px with a reader's text at 200%: *"Not implemented."* rendered 164px wide in a
 * 148px card.
 *
 * The measure is a *cap*, for the long reasons — a sentence explaining why a control is
 * unavailable should not run the full width of a desktop page.
 */
.zoey-action-state__reason {
  min-inline-size: 0;
  max-inline-size: var(--wp--custom--measure);
  overflow-wrap: anywhere;
  color: var(--wp--preset--color--ink-soft);
  font-size: var(--wp--preset--font-size--body-small);
}

/* --- The utility action group ------------------------------------------------------------ */

/*
 * A wrapping row of controls — the Learn reference's `.utilities`.
 *
 * Wrapping rather than scrolling, which is the same call `make-activity.css` makes for the
 * guide's section links: a horizontally scrolling row of controls hides half of itself on the
 * width where it matters most. So the row wraps, and nothing in it is ever off-screen.
 */
.zoey-action-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wp--preset--spacing--30);
}

/*
 * On a phone the members share the width instead of each being as wide as its own label, which is
 * what the Learn reference's `.utilities button{flex:1}` does and what stops a row of two
 * utilities reading as one long control and one short one.
 *
 * `min-inline-size: min(100%, 9rem)` is the part that took measuring, and `flex: 1 1 auto` rather
 * than `flex: 1 1 0` is the part that follows from it. With a zero basis three members divide
 * whatever the row has, however little that is — and at 320px with a reader's text at 200% that
 * was about 60px each, against a control that needs its padding before it needs anything else.
 * Measured: the row's content ran to 354px inside a 214px box.
 *
 * A floor expressed as `min(100%, 9rem)` resolves both ways correctly without a second
 * breakpoint. At ordinary text sizes 9rem is 144px, so two or three members still share a phone
 * row, which is the reference's look. At 200% text 9rem is 288px — wider than the row — so the
 * floor becomes 100% and the members stack one per line and wrap, which is the only arrangement
 * that fits. `flex-wrap: wrap` on the group was always there; this is what gives it something to
 * wrap on.
 */
@media (max-width: 47.99rem) {
  .zoey-action-group > .zoey-action,
  .zoey-action-group > .zoey-action-state {
    flex: 1 1 auto;
    min-inline-size: min( 100%, 9rem );
  }

  .zoey-action-group > .zoey-action-state {
    flex-direction: column;
    align-items: stretch;
  }
}

/* --- Forced colors ---------------------------------------------------------------------- */

/*
 * A fill is decoration, and decoration is replaced by the system's own colours in forced-colors
 * mode. Every control keeps a border in `ButtonText` so it is still a control there, and the
 * disabled one keeps `GrayText` — the system's own word for unavailable, which is the right
 * answer precisely because the opacity above is gone.
 */
@media (forced-colors: active) {
  .zoey-action {
    border: 1px solid ButtonText;
  }

  .zoey-action:disabled {
    border-color: GrayText;
    color: GrayText;
    opacity: 1;
  }
}

/* --- Print ------------------------------------------------------------------------------ */

/*
 * §11's economical ink. A control is not useful on paper, and a pink pill is the most expensive
 * thing on the page to print — so a printed control is its label in a thin outline. It is not
 * hidden: the Learn reference prints a study set, and a reader holding that paper should still
 * be able to see what the page offered.
 */
@media print {
  .zoey-action {
    border: 1px solid #000;
    background-color: transparent;
    color: #000;
  }
}
