/*
 * Zoey Made — base layer.
 *
 * Theme-wide CSS for the few things theme.json cannot express. Design values live in
 * theme.json and are read back from it; nothing here defines a colour, size, or spacing
 * value of its own. See docs/CSS-AND-ASSETS.md.
 */

/*
 * Media never outgrows its container and keeps its intrinsic ratio. WordPress constrains
 * images inside its own blocks but not in theme markup, and a bare <img> computes
 * max-width: none. :where() holds specificity at zero so any component rule wins.
 */
:where(img, svg, video, canvas) {
  max-width: 100%;
  height: auto;
}

/*
 * A code span never widens the page.
 *
 * `<code>` holds things with no spaces in them — a function name, a file path, a command — and
 * `overflow-wrap: normal` has no break opportunity inside one, so a single token sets the
 * element's minimum width and every ancestor inherits it. Measured on the component showcase at
 * 320px with a reader's text at 200%: `zoey_made_page_intro()` rendered 424px wide in a 320px
 * viewport, and the page scrolled sideways because of it.
 *
 * `anywhere` rather than `break-word`, for the reason STORE-013 wrote out: both break a token
 * that cannot fit on a line, and only `anywhere` also reduces the element's *minimum* width,
 * which is what a shrink-to-fit ancestor actually asks for. A token that already fits is
 * unaffected, so this changes nothing at ordinary text sizes.
 *
 * Here rather than in a component stylesheet because WCAG 1.4.10 reflow applies to every route,
 * and because a `<code>` an editor writes into a page should get the same guarantee the
 * development surfaces do. `:where()` holds specificity at zero so any component rule wins.
 */
:where(code) {
  overflow-wrap: anywhere;
}

/*
 * ...and neither does a heading.
 *
 * The same guarantee for the same reason, and this one has been arrived at three times already:
 * STORE-013 added it to the homepage's headings after measuring 69px of sideways scroll at 200%
 * text on a 320px screen, PRODUCT-009 added it to the shop archive's after a category name
 * overflowed by 106px, and VS-005 added it to the shared page introduction and the activity card.
 * Each time it was the same defect on a surface the previous sweep had not reached. VS-006 found
 * it once more on the showcase's own section headings, which belong to no component at all.
 *
 * Three surfaces needing the identical rule is the signal that it belongs to the base layer
 * rather than to any of them. `anywhere` rather than `break-word`, for the reason STORE-013 wrote
 * out: only `anywhere` also reduces the element's *minimum* width, which is what a shrink-to-fit
 * ancestor actually asks for. A heading whose words already fit is unaffected, so this changes
 * nothing at ordinary text sizes.
 *
 * The per-surface rules are left where they are. They are accepted work, they agree with this,
 * and removing them would be churn in files this story has no other reason to touch.
 */
:where(h1, h2, h3, h4, h5, h6) {
  overflow-wrap: anywhere;
}

/*
 * Project-owned components size by their border box, which is the model component CSS is
 * written against. Scoped to .zoey-* rather than applied globally: WordPress and
 * WooCommerce ship no reset and are laid out against the browser default, so a site-wide
 * change would move their geometry for no gain here.
 */
:where([class^="zoey-"], [class*=" zoey-"]) {
  box-sizing: border-box;
}

/*
 * Motion on this site is decorative, so honouring the preference is a site-wide guarantee
 * rather than something every component has to remember. The !important is deliberate and
 * is the documented exception: it has to beat component, inline, and plugin styles,
 * including animation shipped by WordPress and WooCommerce.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-delay: -1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-delay: 0s !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/*
 * The focus ring.
 *
 * One treatment for the whole site, including everything WordPress and WooCommerce render:
 * the shop, a product, the cart, checkout, the account forms and the editor canvas all
 * show the same ring, so "where am I" never depends on which engine drew the control or
 * which plugin owns the markup. Before this existed each component carried its own rule
 * and the rest of the site fell back to the browser default — 1px, and a different colour
 * in every browser.
 *
 * Ink, because the ring has to stay obvious on white and on every pastel. Measured against
 * the palette it is 12.5:1 on the page background and 3.9:1 at its worst, on Zoey Purple,
 * which still clears the 3:1 that WCAG asks of a non-text indicator. A pastel ring does
 * not: purple on white is 3.4:1 and pink is 2.4:1.
 *
 * :focus-visible, so a mouse click does not leave a ring behind, and the offset is what
 * keeps the ring readable against a control that has just turned Ink itself — the gap
 * shows the page through it. :is() carries the specificity of its longest branch, which is
 * enough to beat the single-class focus styles WooCommerce ships without reaching for
 * !important.
 *
 * Nothing anywhere may set outline: none without putting an equally visible treatment in
 * its place. See docs/ACCESSIBILITY.md.
 */
:is(
  a[href],
  area[href],
  button,
  input,
  select,
  textarea,
  summary,
  iframe,
  [tabindex]:not([tabindex^="-"]),
  [contenteditable="true"]
):focus-visible {
  outline: 3px solid var(--wp--preset--color--ink);
  outline-offset: 2px;
}

/*
 * Visually hidden.
 *
 * The project's one screen-reader helper. Use it for text that exists to be read aloud —
 * the cart's item count, a control's real name behind an icon, a page heading the visual
 * design carries some other way.
 *
 * The theme used to borrow core's .screen-reader-text, which is defined by the block
 * library and by WooCommerce but by nothing this repository owns: deactivating WooCommerce
 * or trimming block CSS would have turned every hidden label into visible text. One class,
 * defined here, ends that. Core and WooCommerce keep using their own in their own markup —
 * that is theirs, and there is no second Zoey Made implementation competing with it.
 *
 * clip-path over the older clip, and the word-wrap pair, because several screen readers
 * announce a 1px-wide box as broken words without them.
 */
.zoey-visually-hidden:not(:focus):not(:active) {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip-path: inset(50%);
  white-space: nowrap;
  word-wrap: normal;
  word-break: normal;
}
