/*
 * Reader forms: the tip form on author pages, the support and contact forms
 * on their pages. Each form is a sheet of the letters' stationery; the stamp
 * that sends it and the postmark after are in forms-post.css. Enqueued on
 * author archives and pages only. No script of ours: the donate amount and
 * the volunteer hint reveal with :has() (Baseline); the contact form's only
 * script is Cloudflare's Turnstile. Focus is a calm ink ring; a refused field
 * is red, thicker and flagged with "!", so an error never reads as focus.
 */
@layer components {

	.vt-form {
		--sheet: var(--wp--custom--letter--paper);
		--sheet-ink: var(--wp--custom--letter--ink);
		--sheet-muted: var(--wp--custom--letter--paper-muted);
		--sheet-rule: var(--wp--custom--letter--paper-rule);
		--field: var(--wp--custom--letter--envelope-light);
		--field-edge: var(--wp--custom--letter--muted);
		--focus: var(--wp--preset--color--ink);
		--error: var(--wp--custom--color--mark-on-light);
		--gap: clamp(1.25rem, 3vw, 1.75rem);

		box-sizing: border-box;
		position: relative;
		container-type: inline-size;
		display: grid;
		gap: var(--gap);
		max-inline-size: 640px;
		margin-block: 2rem 0;
		padding:
			clamp(2rem, 5vw, 3rem) clamp(1.25rem, 5vw, 3rem)
			clamp(1.5rem, 4vw, 2.5rem);
		border: 1px solid var(--sheet-rule);
		background:
			radial-gradient(ellipse at 100% 0, var(--wp--custom--letter--paper-wash), transparent 60%),
			repeating-linear-gradient(4deg, var(--wp--custom--letter--paper-texture) 0 1px, transparent 1px 4px),
			var(--sheet);
		color: var(--sheet-ink);
		font-family: var(--wp--preset--font-family--text);
		box-shadow:
			0 18px 40px -22px var(--wp--custom--letter--paper-shadow),
			0 1px 4px var(--wp--custom--letter--paper-edge);
	}

	/* The airmail edge along the top of the sheet. */
	.vt-form::before {
		content: "";
		position: absolute;
		inset: -1px -1px auto;
		block-size: 6px;
		background: repeating-linear-gradient(-45deg, var(--wp--custom--color--mark) 0 10px, transparent 10px 16px, var(--wp--preset--color--ink) 16px 26px, transparent 26px 32px);
	}

	.vt-form__key {
		justify-self: end;
		margin: calc(var(--gap) * -0.5) 0 calc(var(--gap) * -0.5);
		font-family: var(--wp--preset--font-family--mono);
		font-size: var(--wp--preset--font-size--micro);
		color: var(--sheet-muted);
	}

	.vt-form__req {
		color: var(--error);
	}

	.vt-form__field {
		display: grid;
		gap: 0.5rem;
		align-content: start;
		min-inline-size: 0;
	}

	.vt-form__field > label {
		font-size: var(--wp--preset--font-size--note);
		font-weight: 500;
		line-height: 1.35;
	}

	.vt-form__hint {
		margin: 0;
		font-size: var(--wp--preset--font-size--note);
		line-height: var(--wp--custom--lead--caption);
		color: var(--sheet-muted);
	}

	.vt-form :where(input:not([type="radio"]), textarea, select) {
		box-sizing: border-box;
		inline-size: 100%;
		min-block-size: 3rem;
		margin: 0;
		padding: 0.6875rem 0.875rem;
		border: 1px solid var(--field-edge);
		border-radius: 0;
		background-color: var(--field);
		font: inherit;
		font-size: var(--wp--preset--font-size--body-sm);
		line-height: 1.5;
		color: var(--sheet-ink);
	}

	/* One height for text inputs and selects, so a row's fields line up. */
	.vt-form :where(input:not([type="radio"]), select) {
		block-size: 3rem;
	}

	.vt-form :where(input, textarea)::placeholder {
		color: var(--sheet-muted);
		opacity: 1;
	}

	/* Writing paper: the rules scroll with the text. */
	.vt-form textarea {
		--line: 1.75rem;

		min-block-size: calc(var(--line) * 4 + 1.5rem);
		padding-block: 0.75rem;
		background-image: repeating-linear-gradient(transparent 0 calc(var(--line) - 1px), var(--sheet-rule) calc(var(--line) - 1px) var(--line));
		background-attachment: local;
		background-position: 0 0.75rem;
		line-height: var(--line);
		resize: vertical;
	}

	.vt-form select {
		appearance: none;
		padding-inline-end: 2.5rem;
		background-image:
			linear-gradient(45deg, transparent 50%, var(--sheet-ink) 50%),
			linear-gradient(135deg, var(--sheet-ink) 50%, transparent 50%);
		background-position:
			calc(100% - 1.25rem) 50%,
			calc(100% - 0.9375rem) 50%;
		background-size: 0.3125rem 0.3125rem;
		background-repeat: no-repeat;
		cursor: pointer;
	}

	.vt-form :where(input:not([type="radio"]), textarea, select):hover {
		border-color: var(--sheet-ink);
	}

	/* Focus: a calm ink ring, never the error red. */
	.vt-form
	:where(
		input:not([type="radio"]),
		textarea,
		select,
		a,
		button
	):focus-visible {
		outline: 2px solid var(--focus);
		outline-offset: 2px;
	}

	.vt-form :where(input:not([type="radio"]), textarea, select):focus-visible {
		border-color: var(--focus);
	}

	.vt-form fieldset {
		display: grid;
		gap: 0.75rem;
		min-inline-size: 0;
		margin: 0;
		padding: 0;
		border: 0;
	}

	.vt-form legend {
		padding: 0;
		margin-block-end: 0.75rem;
		font-family: var(--wp--preset--font-family--display);
		font-size: clamp(1.375rem, 2.6vw, 1.75rem);
		line-height: 1.15;
		text-wrap: balance;
	}

	/* The help choice: two cards, side by side, each a real radio. */
	.vt-form__choice legend {
		font-size: clamp(1.625rem, 3.4vw, 2.125rem);
	}

	.vt-form__options {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 0.75rem;
	}

	.vt-form__option {
		display: flex;
		gap: 0.75rem;
		align-items: center;
		min-block-size: 3.75rem;
		padding: 0.75rem 1rem;
		border: 1px solid var(--field-edge);
		background: var(--field);
		font-size: var(--wp--preset--font-size--body);
		cursor: pointer;
	}

	.vt-form__option:hover {
		border-color: var(--sheet-ink);
	}

	.vt-form__option input {
		flex: none;
		inline-size: 1.25rem;
		block-size: 1.25rem;
		margin: 0;
		accent-color: var(--focus);
	}

	/* The card carries the radio's focus ring. */
	.vt-form__option input:focus-visible {
		outline: 0;
	}

	.vt-form__option:has(:focus-visible) {
		outline: 2px solid var(--focus);
		outline-offset: 2px;
	}

	.vt-form__option:has(:checked) {
		border-color: var(--focus);
		background: var(--wp--custom--letter--shine);
		box-shadow: inset 0 0 0 1px var(--focus);
		color: var(--focus);
	}

	/* Shown once its choice is checked; without CSS it stays visible. */
	.vt-form:not(:has(.vt-form__reveals:checked)) .vt-form__reveal {
		display: none;
	}

	.vt-form:not(:has(.vt-support__volunteers:checked))
	.vt-support__if-volunteer {
		display: none;
	}

	.vt-form__row {
		display: grid;
		grid-template-columns: minmax(0, 1fr) minmax(0, 1.7fr) minmax(0, 0.9fr);
		gap: 1rem;
		align-items: end;
	}

	.vt-form__pair {
		display: grid;
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: var(--gap) 1rem;
	}

	.vt-form__note {
		margin: 0;
		font-size: var(--wp--preset--font-size--note);
		color: var(--sheet-muted);
	}

	/* The answer after a send, at the top of the sheet. */
	.vt-form__status {
		display: grid;
		grid-template-columns: auto minmax(0, 1fr);
		gap: 0.75rem;
		align-items: start;
		max-inline-size: 640px;
		margin: 0;
		font-size: var(--wp--preset--font-size--body-sm);
		line-height: 1.45;
	}

	.vt-form__status:focus {
		outline: 0;
	}

	/* A refusal: boxed, flagged "!" and worded as an error, not only red. */
	.vt-form__status.is-error {
		padding: 0.875rem 1rem;
		border: 2px solid var(--error);
		background: color-mix(in oklab, var(--error) 7%, var(--sheet));
		font-weight: 500;
	}

	.vt-form__status.is-error::before,
	.vt-form__field:has([aria-invalid="true"]) > label::before,
	.vt-form__choice:has([aria-invalid="true"]) > legend::before {
		content: "!" / "";
		display: inline-grid;
		place-items: center;
		inline-size: 1.375rem;
		block-size: 1.375rem;
		margin-inline-end: 0.5rem;
		border-radius: var(--wp--custom--radius--pill);
		background: var(--error);
		color: var(--sheet);
		font-family: var(--wp--preset--font-family--text);
		font-size: 0.875rem;
		font-weight: 700;
		line-height: 1;
		vertical-align: 0.1em;
	}

	.vt-form__status.is-error::before {
		margin: 0.0625rem 0 0;
	}

	.vt-form [aria-invalid="true"]:not([type="radio"]) {
		border: 2px solid var(--error);
		background-color: color-mix(in oklab, var(--error) 5%, var(--field));
	}

	.vt-form__choice:has([aria-invalid="true"]) .vt-form__option {
		border: 2px solid var(--error);
	}

	/* The contact page's unconfigured notice, outside any sheet. */
	.vt-contact > .vt-form__status {
		display: block;
		padding-inline-start: 0.75rem;
		border-inline-start: 3px solid var(--ink);
	}

	@container (width < 30rem) {

		.vt-form__pair {
			grid-template-columns: minmax(0, 1fr);
		}

		.vt-form__row {
			grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
		}

		.vt-support__currency {
			grid-column: 1 / -1;
			grid-row: 2;
		}
	}

	@container (width < 15rem) {

		.vt-form__options {
			grid-template-columns: minmax(0, 1fr);
		}
	}

	@media (prefers-reduced-motion: no-preference) {

		.vt-form :where(input:not([type="radio"]), textarea, select),
		.vt-form__option {
			transition:
				border-color var(--wp--custom--motion--hover)
				var(--wp--custom--motion--ease-out),
				background-color var(--wp--custom--motion--hover)
				var(--wp--custom--motion--ease-out);
		}
	}
}
