/*
 * Zoey Made — the layout of a guided Learn session (LRN-005).
 *
 * Spelling practice built this first; vocabulary practice needed the same page. So the column, the
 * step box and its focus ring, the sheet of paper, the room an answer reserves, the row of controls,
 * the motion and the print rules live here on `zoey-learn-session__*` classes, and both practices
 * carry them. `inc/learn/session.php` renders the markup; a practice's own stylesheet says only what
 * is genuinely its own — the typography of a spelling word is not the typography of a vocabulary
 * definition, and that is the whole of the difference.
 *
 * Nothing here restates a shared component. The paper, the controls, the callouts and the glyphs are
 * the library's, composed through supported options; this file places them.
 *
 * Loaded with either Learn practice block, so it reaches those two routes and no other.
 */

/*
 * Zoey Made — paper spelling practice (LRN-004).
 *
 * Layout and one piece of typography that is genuinely this page's own: the prompt. Everything else
 * — the callouts, the controls, the page introduction — belongs to a component that styles itself,
 * and this file places those rather than restating them.
 *
 * Loaded with the `zoey-made/learn-spelling` block, so it reaches the practice route and no other.
 */

/*
 * **The column is the shared template's now (SPL-001).**
 *
 * This file used to pin the page title and the feature block to 48rem itself, because
 * `page.html` sets its content size to `var(--wp--custom--measure)` — `56ch`, which resolves
 * against each element's own font size and so constrained the title to 1478px and the prose to
 * 470px. Three Learn stylesheets and two Make ones each corrected that for themselves.
 *
 * `templates/page-standard.html` carries `var(--wp--custom--layout--content)` instead, so core
 * generates the width rule for the title and for every default child of the content, and the two
 * share an edge without either of them asking. The correction is gone rather than kept beside its
 * replacement, because two owners of one width is how they drift apart.
 *
 * It is gone **only because these routes adopted that template**. A Learn block placed on a page
 * still using `page.html` would be back to the 56ch title, which is the thing to check first if
 * one ever looks wrong. `docs/COMPONENT-INVENTORY.md` records which pages have adopted.
 */

/*
 * The browser's own scroll compensation, turned off for this page — measured, not assumed.
 *
 * Scroll anchoring keeps a chosen node still when content above it changes size. On a page that
 * swaps one step for another it does the opposite of what it is for: leaving the word review for a
 * sentence shrinks the current step by 477px at 200% text, and the browser scrolled the window
 * 477px to keep its anchor in place. Measured: 512 → 35 in one frame, before any script of ours
 * ran. With this rule the same transition leaves the scroll position where the parent put it, and
 * the only movement left is the 54px the focused step genuinely needed to come into view.
 *
 * On `html`, because anchoring belongs to the scrolling box rather than to the content, and through
 * `:has()` so the rule cannot reach a page this block does not render on even if the stylesheet is
 * loaded somewhere unexpected. A browser without `:has()` drops the rule and gets the old
 * behaviour — no worse than before.
 */
html:has(.zoey-learn-session) {
	overflow-anchor: none;
}

/*
 * Anything this stylesheet gives a `display` to, it also takes away when `hidden` says so.
 *
 * `[hidden] { display: none }` is a **user agent** rule, and any class rule that sets a display
 * value beats it. LRN-004 shipped that defect once — four controls visible in every state while
 * every attribute check in sight reported them hidden — and the shared `action` component was fixed
 * for it. These are the session's own boxes, every one of them bound to a `hidden` directive, and
 * every one of them given a display below. One extra attribute of specificity, no `!important`.
 */
.zoey-learn-session__guided[hidden],
.zoey-learn-session__swap[hidden],
.zoey-learn-session__leaving[hidden],
.zoey-learn-session__prompt[hidden],
.zoey-learn-session__answer[hidden] {
	display: none;
}

.zoey-learn-session {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--50, 1.5rem);
}

/*
 * The guided interface is a column with a gap, and the gap is what keeps the focus ring off the
 * buttons.
 *
 * A step takes focus when it becomes the current one, and the site's indicator is a 3px outline
 * drawn 4px outside the element — so it reaches 7px past the step's box without occupying a pixel
 * of layout. Measured before this rule: the step's bottom and the controls' top were at the same
 * y, and the ring crossed straight through the row of buttons.
 *
 * A gap rather than a margin on the step, because the hidden steps are `display: none` and
 * contribute no gap at all — so the spacing appears exactly once, between whichever step is current
 * and the controls below it.
 */
.zoey-learn-session__guided {
	display: flex;
	flex-direction: column;
	gap: var(--wp--preset--spacing--40, 1rem);
}

/*
 * A step takes focus when it becomes the current one, so it needs the site's focus ring — and it is
 * `tabindex="-1"`, so this is the only way it ever shows one. Without it a keyboard user is moved
 * somewhere with no indication that anything happened.
 */
.zoey-learn-session__step:focus-visible {
	outline: 3px solid var(--wp--preset--color--ink);
	outline-offset: 4px;
	border-radius: 0.5rem;
}

/*
 * The sheet of paper, placed and not restyled.
 *
 * Everything about how it looks — the cream, the grain, the padding, the tape, the print and
 * forced-colors fallbacks, the container query that tightens it below 26rem — belongs to
 * `surface.css` and arrives with `zoey_made_surface()`. The only thing Learn says here is where it
 * sits, which is the whole of the reuse contract: `docs/CSS-AND-ASSETS.md`, and the inventory's
 * Surface entry for the options this composes.
 *
 * It fills the step, because the step is the focus target and the ring is drawn 4px outside it —
 * so the ring is outside the paper rather than crossing it, and the tape, which straddles the top
 * edge, has the ring's clearance and the surface's own padding between it and anything to read.
 */
.zoey-learn-session__card {
	inline-size: 100%;
}

/*
 * Room above the paper for the tape to straddle its edge.
 *
 * Tape is half on the sheet and half off it — that is the placement's whole idea — and the focus
 * ring is drawn 4px outside the step. Measured without this rule: the tape reached **10px past the
 * ring**, which is the style guide's one hard rule about tape broken (it may not cover text,
 * controls or focus indicators). A spacing token of room at the top of the step puts the tape back
 * inside the box the ring encloses.
 *
 * On the step rather than the card, because it is the *ring* that needs the clearance, and the ring
 * traces the step. It is the same number in every state, so nothing the stability pass measured
 * moves. Every step that carries paper carries it — the two prompts and the two reviews.
 */
.zoey-learn-session__step--word,
.zoey-learn-session__step--sentence,
.zoey-learn-session__step--word-review,
.zoey-learn-session__step--sentence-review,
.zoey-learn-session__step--entry {
	padding-block-start: var(--wp--preset--spacing--40, 1rem);
}

/*
 * The answer area: one box with two states, and it does not change size between them.
 *
 * Measured before this rule, at 1440px: pressing *Reveal the word* moved the row of controls down
 * 71px — under the pointer that had just pressed one — because the concealed prompt was
 * `display: none` and reserved nothing, while the revealed one was 128px tall. At 200% text the same
 * press moved them 97px, and the two sentences of the fixture set disagreed with each other by 39px.
 *
 * So the prompt and the *"Hidden until you are ready"* line live in one wrapper, and the wrapper
 * holds the room the **tallest prompt of its kind** needs. That height cannot be written here: it
 * depends on the column width, the reader's text size, the font once it has loaded, and the words
 * themselves. `learn-practice.js` measures it and sets the two custom properties below; until it
 * does — or if it never does — `auto` is the old behaviour rather than a broken one.
 *
 * Reserving the *tallest of the kind* rather than each step's own height is deliberate: it is what
 * keeps *Back*, *Reveal* and *Next* in one place through all ten words and through every sentence,
 * not merely either side of a single reveal.
 */
.zoey-learn-session__answer {
	padding-block: var(--wp--preset--spacing--40, 1rem);
}

/*
 * The prompt, which is the one thing on this page a parent reads at arm's length.
 *
 * A word is set large because it is read aloud across a table; a sentence is set smaller than a word
 * and left ranged, because it is a line of prose rather than a single thing to look at. Both break
 * anywhere rather than widening the page — `anywhere` and not `break-word`, for the reason
 * base.css writes out.
 */

.zoey-learn-session__answer--word {
	min-block-size: var(--zoey-learn-answer-word, auto);
}

.zoey-learn-session__answer--sentence {
	min-block-size: var(--zoey-learn-answer-sentence, auto);
}

.zoey-learn-session__answer--entry {
	min-block-size: var(--zoey-learn-answer-entry, auto);
}

/*
 * A prompt arrives rather than appears.
 *
 * `docs/INTERACTIVITY.md` puts UI feedback at 120–200ms and asks that nothing have to finish
 * animating before a visitor can carry on. This is 170ms of fade with a 5px settle, on the
 * **incoming content only** — no crossfade, because the previous answer is concealed the instant a
 * parent moves rather than lingering through a dissolve where a child could still read it.
 *
 * The animation is on the wrapper inside the step, not on the step: the box, its focus ring and the
 * controls below it hold the positions the stability pass measured, and `transform` takes no part in
 * layout, so the reserved answer height is the same throughout.
 *
 * **And since `D9` it is not on that wrapper either — it is on the changing text inside it.**
 * Product reviewed the shipped practices on 2026-10-10: the wrapper holds Bubble as well as the
 * words, so *Next* and *Back* faded her in again on every step and she read as arriving each time
 * rather than staying with the child. She is a guide, so she stops moving. The targets below are
 * the step's heading, its instruction and the message region beside her; **she, the paper and its
 * tape are outside all of them** and hold their opacity and position throughout.
 *
 * The selectors say that by exclusion rather than by naming each practice's own classes, which is
 * what keeps one rule true for both: everything directly inside the wrapper animates **except**
 * the answer region and the character composition, and inside those two, the composition's
 * message column animates and its media column — Bubble — does not. Spelling nests the
 * composition inside the answer region and vocabulary puts it directly in the wrapper, and this
 * covers both without either shape being mentioned.
 *
 * It is keyed to nothing but `display`. A step that is not current is `hidden`, which is
 * `display: none`, and an element coming back into display starts its animations again from the
 * beginning — so *Next* and *Back* run it, and nothing else does. There is no class to add, no timer
 * to clear, and a second press part-way through simply hides that step, which cancels its animation
 * outright: no queue, no stale frame, no half-faded word left on the screen.
 *
 * Only words and sentences. The ready step, the reviews and the finish are arrivals of a different
 * kind and are left alone — and it means nothing animates when the page first loads.
 */
@keyframes zoey-learn-session-settle {
	from {
		opacity: 0;
		transform: translateY(5px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

/* ----------------------------------------------------------------------------------- motion */

@keyframes zoey-learn-session-fade {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}

.zoey-learn-session__step--word .zoey-learn-session__content > :not(.zoey-learn-session__answer):not(.zoey-character-message),
.zoey-learn-session__step--sentence .zoey-learn-session__content > :not(.zoey-learn-session__answer):not(.zoey-character-message),
.zoey-learn-session__step--entry .zoey-learn-session__content > :not(.zoey-learn-session__answer):not(.zoey-character-message),
.zoey-learn-session__step--word .zoey-learn-session__content .zoey-character-message__body,
.zoey-learn-session__step--sentence .zoey-learn-session__content .zoey-character-message__body,
.zoey-learn-session__step--entry .zoey-learn-session__content .zoey-character-message__body {
	animation: zoey-learn-session-settle 170ms ease-out both;
}

/*
 * And the other half of `D9`, stated rather than left to inference.
 *
 * A rule that only *omits* Bubble is one inherited `animation` shorthand away from including her
 * again, and the failure would be silent — she would simply start fading once more and nothing
 * would report it. So the media column says no outright, and `wb3:test` reads her opacity
 * mid-transition rather than trusting this line.
 */
.zoey-learn-session__content .zoey-character-message__media,
.zoey-learn-session__content .zoey-character-message__media .zoey-character {
	animation: none;
}

/*
 * The reveal is a fade and nothing else — the word must not move, because it has already been given
 * its room and because a word that slides is a word that is harder to read.
 */
.zoey-learn-session__prompt {
	animation: zoey-learn-session-fade 180ms ease-out both;
}

/*
 * Measuring is not animating.
 *
 * `learn-practice.js` clones an answer area into a hidden probe to measure how much room the longest
 * prompt needs. A clone that started at `opacity: 0` and a 5px offset would still measure the same
 * height — `transform` is not layout — but relying on that is a trap for whoever changes the
 * keyframes next. The probe switches motion off outright, on specificity rather than `!important`.
 */
.zoey-learn-session__probe .zoey-learn-session__content,
.zoey-learn-session__probe .zoey-learn-session__content > *,
.zoey-learn-session__probe .zoey-character-message__body,
.zoey-learn-session__probe .zoey-learn-session__prompt {
	animation: none;
}

/*
 * Reduced motion removes the movement and keeps everything else: the step still changes, the word
 * still appears, the announcement still happens. The selectors repeat the ones above so the cascade
 * decides this on source order rather than on specificity, which is what `docs/INTERACTIVITY.md`
 * asks for. `base.css` would collapse the durations site-wide anyway; saying it here is the
 * component meaning it.
 *
 * **"Repeat the ones above" is literal, and `D9` briefly broke it.** The first version of this
 * block wrote the new targets in a shorter form — `.zoey-learn-session__content
 * .zoey-character-message__body`, two classes against the three above it — so the rule it was
 * meant to cancel simply out-specified it and `animation-name` stayed `zoey-learn-session-settle`
 * under reduced motion. Nothing looked wrong, because `base.css` collapses every duration
 * site-wide and the movement went away anyway; the component had just stopped meaning it on its
 * own. Measured and corrected before closeout: the selectors below are now character-for-character
 * the ones above.
 */
@media (prefers-reduced-motion: reduce) {
	.zoey-learn-session__step--word .zoey-learn-session__content > :not(.zoey-learn-session__answer):not(.zoey-character-message),
	.zoey-learn-session__step--sentence .zoey-learn-session__content > :not(.zoey-learn-session__answer):not(.zoey-character-message),
	.zoey-learn-session__step--entry .zoey-learn-session__content > :not(.zoey-learn-session__answer):not(.zoey-character-message),
	.zoey-learn-session__step--word .zoey-learn-session__content .zoey-character-message__body,
	.zoey-learn-session__step--sentence .zoey-learn-session__content .zoey-character-message__body,
	.zoey-learn-session__step--entry .zoey-learn-session__content .zoey-character-message__body,
	.zoey-learn-session__prompt {
		animation: none;
	}
}

/*
 * A reveal that has been used keeps its slot and gives up everything else.
 *
 * `visibility: hidden` rather than the `hidden` attribute, deliberately and only here: the control
 * is not perceivable, cannot be focused, cannot be clicked and is not in the accessibility tree —
 * it simply still occupies its box, so *Next* does not slide left on a wide screen or jump up a row
 * at 320px the moment a word is revealed. On a review or the finish, where there is nothing to
 * reveal at all, the attribute takes it out of the layout completely.
 */
/*
 * Two controls, one slot.
 *
 * A 1×1 grid: both children sit in the same cell, so the slot is as wide and as tall as the wider
 * and taller of them, whichever is showing. That is what lets a practice swap *reveal* for *try
 * again* without the row reflowing and the control beside it moving under a parent's hand.
 */
.zoey-learn-session__swap {
	display: grid;
	align-items: center;
	justify-items: start;
}

.zoey-learn-session__swap > * {
	grid-area: 1 / 1;
}

.zoey-learn-session__controls .zoey-action.is-spent {
	visibility: hidden;
}

/*
 * The controls wrap rather than scroll, which is the call `action.css` and the guide's section links
 * both make. Below 48rem each member takes a floor of its own so two can share a phone row at
 * ordinary text sizes and they stack when a reader has enlarged their text.
 */
.zoey-learn-session__controls {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	align-items: center;
}

.zoey-learn-session__finish-actions,
.zoey-learn-session__leaving-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	margin: 1rem 0 0;
}

@media (max-width: 48rem) {
	.zoey-learn-session__controls > * {
		flex: 1 1 auto;
		min-inline-size: min(100%, 9rem);
	}
}
