/*
 * The newsletter signup panel.
 *
 * Composition and the one control family this feature had to bring with it. The paper, the
 * tape, the doodles and the button are all drawn by their own stylesheets — surface.css,
 * decoration.css and action.css — and nothing here reaches into any of them.
 *
 * ## No page-level anything
 *
 * The component-library contract: *"a feature stylesheet never establishes a page width, gutter
 * or page-level spacing of its own."* There is no max-width, no margin-inline, no gutter and no
 * container query against the viewport in this file. The panel fills whatever its caller gives
 * it, and the caller is the shared page layout.
 *
 * ## The breakpoint is the content's, not the device's
 *
 * Expressed against the panel rather than the window, because the panel on the proof surface and
 * the panel on a homepage are different widths at the same viewport. DESIGN-CONTRACT:
 * *"Field/action row stacks when content requires it; do not force a breakpoint that fragments
 * words."*
 *
 * **The container is `zoey-surface`, and this file does not open a second one.** `.zoey-email-signup`
 * *is* the surface element — the class is merged into the surface's own list — and `surface.css`
 * already declares `container-type: inline-size` and `container-name: zoey-surface` on it. Naming
 * it again here won the cascade in neither direction reliably and left these queries addressing a
 * container that did not exist, so they silently never fired. That is the defect `surface.css`'s
 * own comment records SL-007 shipping, caught here by a capture that showed one column at 1280px.
 */

.zoey-email-signup {
  position: relative;
}

/*
 * The surface's own content box is the grid. One column by default — the phone column
 * DESIGN-CONTRACT describes: small illustration, heading, copy, label, field, action, helper.
 */
.zoey-email-signup .zoey-surface__content {
  display: grid;
  gap: var(--wp--preset--spacing--40);
  justify-items: center;
  text-align: center;
}

/*
 * Roughly one-third illustration, two-thirds content, as the contract asks, and only once
 * there is width for it. `minmax(0, …)` on both tracks so a long address cannot push the grid
 * wider than the paper.
 */
@container zoey-surface (min-width: 44rem) {
  .zoey-email-signup .zoey-surface__content {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    /*
     * `start`, not `center`, and it is a stability fix rather than a taste one.
     *
     * The illustration column has a fixed 4:5 ratio while the content column grows when feedback
     * appears. Centred, that growth re-centres the whole column and **moved the field and the
     * action up by 8px** the moment an error or a confirmation was shown — measured at 1280 and
     * nowhere else, because only here is the content column shorter than the illustration.
     * Aligning to the start means feedback can only ever extend downward, so the controls hold
     * still. The 768 and phone layouts never had the problem and are unaffected.
     */
    align-items: start;
    gap: var(--wp--preset--spacing--50);
    justify-items: start;
    text-align: start;
  }
}

/*
 * The illustration slot.
 *
 * A defined box with its own ratio, not a flex box that happens to contain an image. Two reasons,
 * and both are about the artwork that has not arrived yet: the panel's height stops moving when
 * the master lands, and the art has a bottom edge to stand on.
 *
 * `align-items: end` is the "integrated rather than floating" requirement, expressed in one
 * line. Centred art in a tall column reads as a sticker dropped onto the paper; art whose optical
 * baseline sits on the slot's bottom edge reads as standing on it. `ASSET-PLAN.md` asks the
 * master to be drawn to that baseline for the same reason.
 */
.zoey-email-signup__art {
  position: relative;
  display: grid;
  place-items: end center;
  min-inline-size: 0;
  /*
   * Full width even on a phone, where `.zoey-surface__content` centres its items. Without this
   * the slot shrinks to the cameo's own width and the accent layer inside it has nowhere to put
   * a corner mark except on top of the character.
   */
  inline-size: 100%;
  /*
   * Room for the corner marks, in the same unit the marks are sized in.
   *
   * Both the accents and the character scale with the root font size, so at 200% text they grew
   * into each other and a star landed on Bubbles' head — measured, after the first version of
   * this slot shipped without it. Padding in `rem` scales with both, so the clearance holds at
   * every text size instead of only at the one that was looked at.
   *
   * Only in the stacked layout. At desktop the slot is a narrow column where a centred character
   * already clears the corners, and this padding would push it into them instead.
   *
   * **3rem, chosen by measurement rather than taste.** At 2.5rem the marks still crossed the
   * character by 3px at 200% text; at 3.5rem the 200% cameo was crushed to 60px wide. 3rem
   * clears at both sizes and leaves the character untouched at normal text — 144px — while
   * letting it fall to a 92px cameo at 200%, which is the illustration declining to dominate
   * rather than a defect.
   */
  padding-inline: 3rem;
}

/*
 * The ratio applies only once there is a column to hold it. On a phone the slot is a cameo in a
 * stacked column — DESIGN-CONTRACT's *"small illustration"*, and its amended *Scenery* section is
 * explicit that the mobile composition is a compact crop and **not** the desktop scene shrunk to
 * an illegible thumbnail. Forcing 4:5 at 320px would do exactly that.
 */
@container zoey-surface (min-width: 44rem) {
  .zoey-email-signup__art {
    aspect-ratio: 4 / 5;
    inline-size: 100%;
    padding-inline: 0;
  }

  /*
   * The slot is the scenery's frame, so it clips.
   *
   * The scenery is deliberately drawn wider than the lane — its shelf has to be legible — and
   * without this it would reach past the slot and put paper props behind the heading and the
   * field, which the artwork package forbids in as many words: "no props behind copy or fields".
   * `clip` rather than `hidden` because it creates no scroll container.
   */
  .zoey-email-signup__art {
    overflow: clip;
  }
}

/*
 * ## The two canvases, composed rather than stretched
 *
 * The scenery is a 3:2 landscape (1536x1024) and Bubbles is a 1254px square. `ASSET-PLAN.md` and
 * the artwork package both insist these are independent canvases: *"establish their scale and
 * baseline visually rather than stretching them to fill matching boxes"*. So neither is given a
 * box to fill. Each keeps its intrinsic ratio, and they are related to each other by a **shared
 * baseline** — both sit on the bottom of the slot — and by size chosen against what is actually
 * painted inside each canvas, not against the canvas edges.
 *
 * Bubbles' size is the character component's own `panel` cap, unchanged. The scenery is sized
 * relative to the slot and placed behind her.
 */

/*
 * The scenery, behind. Desktop only.
 *
 * `position: absolute` so it reserves no height — the slot's own ratio decides the panel's
 * height, and the scenery cannot push the form down. Anchored to the slot's bottom-left because
 * that is where its shelf is drawn; its own README says it "intentionally reaches the left/right
 * canvas boundaries" and should be used "as a framed illustration layer", so the frame is the
 * slot and the sparse right-hand props fall outside it rather than being scaled down to fit.
 *
 * 140% of the slot width is the figure that makes the shelf legible — at 100% it painted about
 * 92px wide and read as clutter. The overflow is all on the *trailing* side, where the slot clips
 * it, so the sparse scattered props fall outside the frame and the shelf keeps its own left edge.
 * An earlier revision pulled it 12% to the leading side and cut the shelf in half.
 */
.zoey-email-signup__scenery {
  display: none;
  position: absolute;
  z-index: 0;
  inset-block-end: 0;
  inset-inline-start: 0;
  inline-size: 140%;
  /*
   * `base.css` caps every image at `max-width: 100%`, which silently clamped this back to the
   * lane width and made the 140% above do nothing — the shelf painted at 231px and read as
   * clutter. The slot clips the overflow, so opting out here cannot spill onto the page.
   */
  max-inline-size: none;
  block-size: auto;
  /* Intrinsic ratio preserved: width is set, height follows the artwork. */
  pointer-events: none;
}

@container zoey-surface (min-width: 44rem) {
  .zoey-email-signup__scenery {
    display: block;
  }
}

/*
 * Bubbles, in front of the scenery and on the same baseline.
 *
 * `position: relative` only to lift her above the scenery's stacking order; her size is still
 * the character component's `panel` cap, which this file does not override. An earlier revision
 * tried to and the rule never applied — `character.css` wins — which is recorded in the
 * implementation report as a dead rule removed rather than escalated.
 */
.zoey-email-signup__character {
  position: relative;
  z-index: 1;
  inline-size: auto;
  max-inline-size: 100%;
}

.zoey-email-signup__content {
  display: grid;
  gap: var(--wp--preset--spacing--30);
  inline-size: 100%;
  /* The reading measure, which is not a page width — it is the prose's own comfort. */
  max-inline-size: var(--wp--custom--measure);
}

/*
 * The accent layer sits over the illustration slot, and nothing else.
 *
 * `decoration.css` gives the group `inset: 0` and says that is "a default a consuming surface is
 * expected to replace". The replacement here is structural rather than numeric: the group is a
 * child of the art slot, so `inset: 0` already means "the illustration region" and the corner
 * placements resolve inside it.
 *
 * That is not a tidiness preference, it is what the measurements forced. The panel's padding
 * ring is 24px at desktop and 16px on a phone, and the text runs to within 25px and 17px of the
 * panel edges — so a 48px mark at a *panel* corner overlaps the eyebrow at the top and the
 * helper line at the bottom, which is exactly what the first attempt measured. The art slot is
 * the only region with real space at every width.
 *
 * `position: relative` for it is declared with the slot above.
 *
 * The group is raised above the scenery. `decoration.css` gives it `z-index: 0`, and the scenery
 * is a later sibling at the same level — so without this the shelf paints straight over the heart
 * and the stars that the previous round existed to make visible.
 *
 * The accent layer is raised above the scenery; see the group rule below.
 */

.zoey-email-signup__eyebrow {
  margin: 0;
  font-size: var(--wp--preset--font-size--body-small);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wp--preset--color--ink-soft);
}

.zoey-email-signup__heading {
  margin: 0;
  color: var(--wp--preset--color--ink);
}

.zoey-email-signup__body {
  margin: 0;
  color: var(--wp--preset--color--ink-soft);
}

.zoey-email-signup__form {
  display: grid;
  gap: var(--wp--preset--spacing--20);
  inline-size: 100%;
  margin-block-start: var(--wp--preset--spacing--20);
}

.zoey-email-signup__row {
  display: grid;
  gap: var(--wp--preset--spacing--20);
  align-items: end;
}

@container zoey-surface (min-width: 30rem) {
  .zoey-email-signup__row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

.zoey-email-signup__field {
  display: grid;
  gap: 0.375rem;
  min-inline-size: 0;
}

.zoey-email-signup__label {
  font-size: var(--wp--preset--font-size--body-small);
  font-weight: 700;
  color: var(--wp--preset--color--ink);
}

/*
 * Near-white with a quiet lavender border, soft radius and generous interior spacing, per
 * DESIGN-CONTRACT. The block size matches the action's 48px target so the row reads as one
 * control pair rather than two things that nearly line up.
 */
.zoey-email-signup__input {
  min-block-size: 48px;
  inline-size: 100%;
  padding: 0.625rem 0.875rem;
  font-family: inherit;
  font-size: var(--wp--preset--font-size--body);
  color: var(--wp--preset--color--ink);
  background-color: var(--wp--preset--color--surface);
  border: 2px solid color-mix(in srgb, var(--wp--preset--color--zoey-lavender) 55%, var(--wp--preset--color--surface));
  border-radius: var(--wp--custom--radius--medium);
}

.zoey-email-signup__input::placeholder {
  color: var(--wp--preset--color--ink-soft);
  opacity: 0.7;
}

/*
 * The accepted visible focus ring, matched to the one base.css draws rather than invented here.
 * Two pixels of outline and a two-pixel offset, so the ring sits clear of the border it is
 * drawn outside.
 */
.zoey-email-signup__input:focus-visible {
  outline: 2px solid var(--wp--preset--color--ink);
  outline-offset: 2px;
}

/*
 * Error is carried by the border weight *and* the message below, never by colour alone —
 * FORM-STATES: *"Error feedback must be associated with the relevant control and not rely on
 * color."* The association is the permanent aria-describedby in the markup.
 */
.zoey-email-signup__input[aria-invalid='true'] {
  border-color: var(--wp--preset--color--ink);
  border-style: dashed;
}

/*
 * The honeypot. Taken out of flow and out of sight without `display: none`, which some bots
 * check for, and already out of the accessibility tree via aria-hidden in the markup.
 */
.zoey-email-signup__trap {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/*
 * ## The feedback regions reserve nothing, and the reason they used to is worth recording
 *
 * Both regions carried `min-block-size: 1.5em` "so that a result appearing does not shift the
 * button out from under a finger already moving toward it". **That premise was false.** Both
 * regions sit *below* the field and the action, so content appearing in them can never move
 * either control — it only moves the helper line underneath. The reservation protected nothing
 * and cost two blank lines.
 *
 * Measured, which is what Product's "the gap is too large" turned out to be: the idle distance
 * from the action row to the helper was **70px**, and it decomposed exactly as
 * `8 + 21 + 8 + 21 + 12` — two 8px form gaps, two empty 21px reserved lines, and the 12px
 * content gap.
 *
 * The two were also reserving the same line twice over. They are **mutually exclusive by
 * construction**: `showError()` clears the status region and `showStatus()` clears the error, so
 * at most one of them ever has text. One of the two reservations was pure waste even on its own
 * terms.
 *
 * What replaces it: the error collapses out of the grid entirely when empty, and the status —
 * which permanently holds the envelope image and so can never be `:empty` — simply has no
 * minimum and measures zero while its image is hidden. Idle becomes `8 + 0 + 12` = **20px**,
 * inside the 16-24px Product asked for.
 *
 * Nothing is hidden or clipped to achieve it. Neither region has a fixed height, so a long
 * message, a two-line error and enlarged text all expand the panel naturally, and the field and
 * the action do not move when they do.
 */
.zoey-email-signup__error,
.zoey-email-signup__status {
  margin: 0;
  font-size: var(--wp--preset--font-size--body-small);
}

/*
 * `:empty` rather than a zero height, so the grid gap above it collapses too — a zero-height
 * child still takes its gap, which would have left 28px rather than 20px. The element is
 * rendered with no whitespace inside it precisely so this matches.
 */
.zoey-email-signup__error:empty {
  display: none;
}

.zoey-email-signup__error {
  font-weight: 700;
  color: var(--wp--preset--color--ink);
}

.zoey-email-signup__status {
  color: var(--wp--preset--color--ink-soft);
}

/*
 * The envelope, on the pending-confirmation outcome and on no other.
 *
 * Hidden by default and revealed only when the server's own outcome was `pending`. That is the
 * one state in which MailPoet both accepted the address as unconfirmed *and* reported sending a
 * confirmation request — so it is the one state where a picture of an envelope is not a claim
 * about something that did not happen. `unconfirmable` (added, send failed) deliberately does not
 * get it, which is why the reveal keys on the outcome rather than on "a status appeared".
 *
 * It is still decoration: the status text carries the meaning, and the image is `alt=""` and
 * `aria-hidden`.
 */
.zoey-email-signup__envelope {
  display: none;
  inline-size: 8rem;
  block-size: auto;
  margin-inline: auto;
}

.zoey-email-signup__status[data-outcome='pending'] .zoey-email-signup__envelope {
  display: block;
}

.zoey-email-signup__status-heading {
  margin: 0;
  font-family: var(--wp--preset--font-family--accent);
  font-size: var(--wp--preset--font-size--section-small);
  color: var(--wp--preset--color--ink);
}

/*
 * ## The pending response, which replaces the controls
 *
 * FORM-STATES v0.6. `pending` is the one outcome that ends the form's job — the address is with
 * MailPoet and there is nothing left to retype — so it is the one outcome that takes the field
 * and the button away and puts a response in their place. Every other outcome leaves the controls
 * and the typing alone.
 *
 * The row is hidden rather than removed, so the element the script already holds references to
 * stays valid and nothing has to be rebuilt if the panel is ever re-used.
 */
.zoey-email-signup__form[data-state='pending'] .zoey-email-signup__row {
  display: none;
}

/*
 * The response, given the weight a state the visitor must notice deserves. It is deliberately
 * taller than the controls it replaced — envelope, heading and message — so the panel grows
 * slightly rather than collapsing, which is what the amendment asks for.
 */
.zoey-email-signup__form[data-state='pending'] .zoey-email-signup__status {
  display: grid;
  gap: var(--wp--preset--spacing--20);
  justify-items: center;
  text-align: center;
  padding-block: var(--wp--preset--spacing--20);
}

.zoey-email-signup__form[data-state='pending'] .zoey-email-signup__status-heading {
  font-size: var(--wp--preset--font-size--section-title);
  line-height: 1.15;
}

.zoey-email-signup__form[data-state='pending'] .zoey-email-signup__status p:not(.zoey-email-signup__status-heading) {
  margin: 0;
  max-inline-size: var(--wp--custom--measure);
  font-size: var(--wp--preset--font-size--body);
  color: var(--wp--preset--color--ink);
}

/*
 * Focus lands here when the controls are replaced, so the ring has to be visible — a focused
 * element with no ring is the keyboard equivalent of the focus having gone nowhere.
 */
.zoey-email-signup__status:focus-visible {
  outline: 2px solid var(--wp--preset--color--ink);
  outline-offset: 4px;
  border-radius: var(--wp--custom--radius--medium);
}

.zoey-email-signup__helper {
  margin: 0;
  font-size: var(--wp--preset--font-size--body-small);
  color: var(--wp--preset--color--ink-soft);
}

.zoey-email-signup__privacy {
  color: inherit;
}

/*
 * Busy. The label swap is done in script; this is only the pointer and the dimming, and the
 * control keeps its own focus ring because a disabled-looking button that still has focus is
 * still where the keyboard is.
 */
.zoey-email-signup__action[aria-disabled='true'] {
  cursor: progress;
  opacity: 0.75;
}

/*
 * Forced colours. The paper, the tint and the doodles all step aside on their own; what must
 * survive here is the field reading as a field and the error reading as an error, which means
 * a border the system draws and a style difference that is not a colour.
 */
@media (forced-colors: active) {
  .zoey-email-signup__input {
    border: 2px solid CanvasText;
  }

  .zoey-email-signup__input[aria-invalid='true'] {
    border-style: dashed;
  }

  .zoey-email-signup__input:focus-visible {
    outline: 2px solid Highlight;
  }
}
