/*
 * Recorder styling.
 *
 * Colors come from Gravity Forms' CSS API custom properties, so the recorder
 * follows whichever Gravity Forms theme the form uses. Each one carries a
 * high-contrast fallback for forms rendered without the theme framework, and
 * the add-on's own color settings override them through inline custom
 * properties on .gfvr-ui.
 *
 * Sizing is deliberately absolute rather than inherited: respondents may be on
 * small, low-quality screens, and a site theme's own type scale would otherwise
 * make the controls either tiny or unwieldy.
 */

.gfvr-gfield,
.gfvr-gfield * {
	box-sizing: border-box;
}

.gfvr-gfield {
	min-width: 0;
}

/*
 * The administrator's Description is the story prompt, so it is moved above the
 * recorder. Gravity Forms marks its own placement on the field, and a field
 * explicitly set to show the description above is already in the right order.
 */
.gfvr-gfield.field_description_below {
	display: flex;
	flex-direction: column;
}

.gfvr-gfield.field_description_below > .gfield_label {
	order: -2;
}

.gfvr-gfield.field_description_below > .gfield_description:not(.gform_fileupload_rules):not(.gfield_validation_message) {
	order: -1;
}

.gfvr-gfield > .gfield_description:not(.gform_fileupload_rules):not(.gfield_validation_message) {
	max-height: 11rem;
	margin-block: 0.75rem;
	padding: 0.875rem 1rem;
	overflow-y: auto;
	border: 1px solid #d3d8de;
	border-left: 5px solid var(--gf-color-primary, #1d4ed8);
	border-radius: 0.5rem;
	background: #f6f7f8;
	color: #1d2327;
	font-size: 1.0625rem;
	line-height: 1.5;
}

.gfvr-field {
	width: 100%;
	max-width: 100%;
	min-width: 0;
}

.gfvr-field [hidden] {
	display: none !important;
}

.gfvr-field.gfvr-enhanced .gfvr-native {
	display: none;
}

/*
 * .gform-theme__disable is Gravity Forms' documented opt-out. It is required
 * rather than cosmetic: without it the theme reset strips this component's
 * buttons back to unstyled 22px-tall controls.
 */
.gfvr-ui {
	--gfvr-primary: var(--gf-color-primary, #1d4ed8);
	--gfvr-on-primary: var(--gf-color-primary-contrast, #fff);
	--gfvr-success: var(--gf-color-success, #1a7f37);
	--gfvr-danger: var(--gf-color-danger, #b32d2e);
	--gfvr-border: var(--gf-ctrl-border-color, #656b75);
	--gfvr-ink: #1d2327;
	--gfvr-ink-quiet: #4a5157;
	--gfvr-radius: 0.5rem;
	--gfvr-stage-max: 60vh;
	/* A red that stays legible on the dark stage and on filled buttons. */
	--gfvr-record: #ff5b5b;

	display: grid;
	gap: 1rem;
	width: 100%;
	max-width: 100%;
	font-family: inherit;
	line-height: 1.45;
}

.gfvr-ui p {
	margin: 0;
}

.gfvr-icon {
	flex: none;
	width: 1.15em;
	height: 1.15em;
	fill: currentcolor;
}

/* Status panel ------------------------------------------------------------ */

.gfvr-status {
	display: flex;
	gap: 0.75rem;
	align-items: flex-start;
	min-height: 1.75em;
}

.gfvr-status > .gfvr-icon {
	display: none;
}

.gfvr-status-title {
	color: var(--gfvr-ink);
	font-size: 1.1875rem;
	font-weight: 700;
}

/* Outranks the .gfvr-ui p margin reset above. */
.gfvr-ui .gfvr-status-note {
	margin-top: 0.25rem;
	color: var(--gfvr-ink-quiet);
	font-size: 1rem;
}

/* The recording is not kept until the respondent approves it, so the review
 * status reads as a pending step rather than a confirmation. */
.gfvr-field[data-gfvr-state="review"] .gfvr-status {
	padding: 1rem;
	border: 2px solid #bb7d00;
	border-left-width: 6px;
	border-radius: var(--gfvr-radius);
	background: #fdf6e6;
}

.gfvr-field[data-gfvr-state="uploaded"] .gfvr-status {
	padding: 1rem;
	border: 2px solid var(--gfvr-success);
	border-radius: var(--gfvr-radius);
	background: #f1faf3;
}

.gfvr-field[data-gfvr-state="uploaded"] .gfvr-status > .gfvr-icon {
	display: block;
	width: 1.75rem;
	height: 1.75rem;
	color: var(--gfvr-success);
}

/* A browser that cannot record gets the same weight as an error. */
.gfvr-field[data-gfvr-supported="false"][data-gfvr-state="idle"] .gfvr-status {
	padding: 1rem;
	border: 2px solid #bb7d00;
	border-left-width: 6px;
	border-radius: var(--gfvr-radius);
	background: #fdf6e6;
}

/* Errors ------------------------------------------------------------------ */

.gfvr-error {
	display: flex;
	gap: 0.75rem;
	align-items: flex-start;
	padding: 1rem;
	border: 2px solid var(--gfvr-danger);
	border-left-width: 6px;
	border-radius: var(--gfvr-radius);
	background: #fdf3f3;
	color: #7c1d1d;
}

.gfvr-error > .gfvr-icon {
	width: 1.75rem;
	height: 1.75rem;
	color: var(--gfvr-danger);
}

.gfvr-error-title {
	font-size: 1.125rem;
	font-weight: 800;
}

.gfvr-ui .gfvr-error-text {
	margin-top: 0.25rem;
	font-size: 1rem;
}

.gfvr-error:focus-visible {
	outline: 3px solid var(--gfvr-primary);
	outline-offset: 3px;
}

/* Video stage ------------------------------------------------------------ */

.gfvr-stage {
	position: relative;
	width: 100%;
	max-width: 100%;
	max-height: var(--gfvr-stage-max);
	overflow: hidden;
	aspect-ratio: 16 / 9;
	border-radius: var(--gfvr-radius);
	background: #000;
}

/*
 * Once there is a recording, the stage takes the recording's own shape so a
 * landscape clip is not padded into a portrait box, or the reverse.
 */
.gfvr-field[data-gfvr-state="review"] .gfvr-stage,
.gfvr-field[data-gfvr-state="uploading"] .gfvr-stage {
	aspect-ratio: auto;
}

/* Keeps the upload overlay usable when there is no local recording behind it,
 * as happens after an existing file is chosen. */
.gfvr-field[data-gfvr-state="uploading"][data-gfvr-has-video="false"] .gfvr-stage {
	min-height: 11rem;
}

.gfvr-live,
.gfvr-playback {
	display: block;
	width: 100%;
	background: #000;
}

/*
 * The live preview is a mirror for framing, so it fills the stage; cropping the
 * sides only ever includes more than the respondent can see. Playback keeps its
 * own proportions so the review shows exactly what was recorded.
 */
.gfvr-live {
	height: 100%;
	object-fit: cover;
}

.gfvr-playback {
	height: auto;
	max-height: var(--gfvr-stage-max);
	object-fit: contain;
}

.gfvr-rec-indicator,
.gfvr-timer {
	position: absolute;
	z-index: 2;
	top: 0.75rem;
	padding: 0.4rem 0.7rem;
	border-radius: 999px;
	background: rgb(0 0 0 / 78%);
	color: #fff;
	font-size: 1rem;
	font-weight: 700;
}

.gfvr-rec-indicator {
	left: 0.75rem;
	display: flex;
	align-items: center;
	gap: 0.45rem;
}

.gfvr-timer {
	right: 0.75rem;
	font-variant-numeric: tabular-nums;
}

.gfvr-rec-dot {
	width: 0.8rem;
	height: 0.8rem;
	border-radius: 50%;
	background: var(--gfvr-record);
	animation: gfvr-pulse 1.4s ease-in-out infinite;
}

.gfvr-timer-sr {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

/* Countdown -------------------------------------------------------------- */

.gfvr-countdown {
	position: absolute;
	z-index: 3;
	inset: 0;
	display: grid;
	place-items: center;
	background: rgb(0 0 0 / 55%);
}

.gfvr-countdown-ring {
	position: absolute;
	width: min(58%, 11rem);
	aspect-ratio: 1;
	border: 0.3rem solid rgb(255 255 255 / 80%);
	border-radius: 50%;
	opacity: 0;
}

.gfvr-countdown-number {
	color: #fff;
	font-size: clamp(4rem, 24vw, 8rem);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	line-height: 1;
	text-shadow: 0 2px 12px rgb(0 0 0 / 45%);
}

.gfvr-countdown--tick .gfvr-countdown-number {
	animation: gfvr-count-number 900ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.gfvr-countdown--tick .gfvr-countdown-ring {
	animation: gfvr-count-ring 900ms cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

/* Upload progress -------------------------------------------------------- */

.gfvr-progress {
	position: absolute;
	z-index: 3;
	inset: 0;
	display: grid;
	place-content: center;
	justify-items: center;
	gap: 0.85rem;
	padding: 1.25rem;
	background: rgb(0 0 0 / 62%);
	color: #fff;
}

.gfvr-progress-text {
	font-size: clamp(2.25rem, 11vw, 3.25rem);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	line-height: 1;
}

.gfvr-progress progress {
	appearance: none;
	width: min(100%, 22rem);
	height: 1rem;
	overflow: hidden;
	border: 0;
	border-radius: 999px;
	background: rgb(255 255 255 / 32%);
}

.gfvr-progress progress::-webkit-progress-bar {
	border-radius: 999px;
	background: rgb(255 255 255 / 32%);
}

.gfvr-progress progress::-webkit-progress-value {
	border-radius: 999px;
	background: #fff;
}

.gfvr-progress progress::-moz-progress-bar {
	border-radius: 999px;
	background: #fff;
}

/* Controls --------------------------------------------------------------- */

.gfvr-controls {
	display: flex;
	flex-wrap: wrap;
	gap: 0.75rem;
	max-width: 100%;
}

.gfvr-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	min-height: 3rem;
	min-width: 44px;
	padding: 0.625rem 1.25rem;
	border: 2px solid var(--gfvr-border);
	border-radius: var(--gfvr-radius);
	background: #fff;
	color: var(--gfvr-ink);
	cursor: pointer;
	font-family: inherit;
	font-size: 1.0625rem;
	font-weight: 700;
	line-height: 1.25;
	text-align: center;
}

/* Darkening with an inset layer keeps hover working for any configured color. */
.gfvr-btn:hover {
	box-shadow: inset 0 0 0 999px rgb(0 0 0 / 7%);
}

.gfvr-btn:focus-visible {
	outline: 3px solid var(--gfvr-primary);
	outline-offset: 3px;
}

.gfvr-btn:disabled {
	cursor: wait;
	opacity: 0.6;
}

.gfvr-btn-primary,
.gfvr-field[data-gfvr-supported="false"] .gfvr-btn[data-gfvr-action="fallback"] {
	border-color: transparent;
	background: var(--gfvr-primary);
	color: var(--gfvr-on-primary);
}

.gfvr-btn-stop {
	border-color: transparent;
	background: #1d2327;
	color: #fff;
}

.gfvr-btn-primary:hover,
.gfvr-btn-stop:hover,
.gfvr-field[data-gfvr-supported="false"] .gfvr-btn[data-gfvr-action="fallback"]:hover {
	box-shadow: inset 0 0 0 999px rgb(0 0 0 / 18%);
}

.gfvr-btn .gfvr-icon--record {
	color: var(--gfvr-record);
}

.gfvr-btn-stop .gfvr-icon--stop {
	color: var(--gfvr-record);
}

/* Form editor preview ---------------------------------------------------- */

/*
 * Scoped to the field container so it outranks the form editor's own reset of
 * elements inside a field preview.
 */
.gfvr-gfield .gfvr-editor-preview {
	display: flex;
	gap: 0.875rem;
	align-items: center;
	padding: 0.875rem;
	border: 1px dashed #8c8f94;
	border-radius: 0.5rem;
	background: #f6f7f8;
}

.gfvr-gfield .gfvr-editor-preview-stage {
	display: grid;
	place-items: center;
	width: 5.5rem;
	height: 3.5rem;
	border-radius: 0.375rem;
	background: #1d2327;
	color: #fff;
}

.gfvr-gfield .gfvr-editor-preview-stage .gfvr-icon {
	width: 1.75rem;
	height: 1.75rem;
}

.gfvr-gfield .gfvr-editor-preview-body {
	display: grid;
	gap: 0.4rem;
	justify-items: start;
}

.gfvr-gfield .gfvr-editor-preview-title {
	color: #50575e;
	font-size: 0.875rem;
}

.gfvr-gfield .gfvr-editor-preview-button {
	padding: 0.4rem 0.85rem;
	border-radius: 0.375rem;
	background: #1d4ed8;
	color: #fff;
	font-size: 0.875rem;
	font-weight: 600;
}

/* Recorder wording settings --------------------------------------------- */

.gfvr-text-setting + .gfvr-text-setting {
	margin-top: 0.75rem;
}

.gfvr-text-setting label {
	display: block;
	margin-bottom: 0.25rem;
}

.gfvr-text-setting-input {
	width: 100%;
}

/* Animation ------------------------------------------------------------- */

@keyframes gfvr-pulse {
	50% {
		opacity: 0.45;
	}
}

@keyframes gfvr-count-number {
	0% {
		opacity: 0;
		transform: scale(0.55);
	}

	28% {
		opacity: 1;
		transform: scale(1.06);
	}

	45% {
		transform: scale(1);
	}
}

@keyframes gfvr-count-ring {
	0% {
		opacity: 0.9;
		transform: scale(0.7);
	}

	100% {
		opacity: 0;
		transform: scale(1.45);
	}
}

/* Narrow screens ------------------------------------------------------- */

@media (max-width: 600px) {
	.gfvr-controls {
		display: grid;
		grid-template-columns: minmax(0, 1fr);
	}

	.gfvr-btn {
		width: 100%;
	}

	/*
	 * A taller stage on a phone: a 16:9 letterbox leaves a respondent's face too
	 * small to frame. The height cap and the shorter prompt panel together keep
	 * the current action on screen without scrolling.
	 */
	.gfvr-ui {
		--gfvr-stage-max: 40vh;
	}

	.gfvr-stage {
		aspect-ratio: 4 / 5;
	}

	.gfvr-gfield > .gfield_description:not(.gform_fileupload_rules):not(.gfield_validation_message) {
		max-height: 7.5rem;
	}

	.gfvr-rec-indicator,
	.gfvr-timer {
		top: 0.5rem;
		padding: 0.3rem 0.55rem;
		font-size: 0.875rem;
	}

	.gfvr-rec-indicator {
		left: 0.5rem;
	}

	.gfvr-timer {
		right: 0.5rem;
	}

	.gfvr-status-title {
		font-size: 1.125rem;
	}
}

@media (prefers-reduced-motion: reduce) {
	.gfvr-rec-dot {
		animation: none;
	}

	.gfvr-countdown--tick .gfvr-countdown-number,
	.gfvr-countdown--tick .gfvr-countdown-ring {
		animation: none;
	}

	/* Without the entrance animation the ring still needs to be visible. */
	.gfvr-countdown-ring {
		opacity: 0.55;
	}
}
