/* Area "test" — see DESIGN.md («Онлайн-тест»). Pages page-exam.php / page-start.php and the markup of the plugin
   emytest (tpl/exam.php, tpl/start.php, js/scripts.js). */

/* ---------- page ---------- */
.e-test-page { padding: var(--e-s6) 0 var(--e-s12); background: var(--e-bg-soft); }
@media (min-width: 960px) { .e-test-page { padding: var(--e-s10) 0 var(--e-s16); } }

.e-test-page__head { margin-bottom: var(--e-s5); }
.e-test-page__title {
	color: var(--e-ink); font-size: clamp(26px, 4vw, 36px); line-height: 1.15; font-weight: 750;
	letter-spacing: -.02em; text-wrap: balance; overflow-wrap: break-word;
}
/* one line of description (two on phones), the rest is cut */
.e-test-page__desc {
	margin-top: var(--e-s2); color: var(--e-muted); font-size: 16px; line-height: 1.5;
	display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
@media (min-width: 640px) { .e-test-page__desc { -webkit-line-clamp: 1; line-clamp: 1; } }
.e-test-page__lead { margin-top: var(--e-s3); color: var(--e-text); font-size: clamp(17px, 2vw, 19px); line-height: 1.55; }

/* page text around the shortcode: its heading is a short caption above the test */
.e-test-page__body > h2 { margin: 0 0 var(--e-s3); color: var(--e-text); font-size: 17px; line-height: 1.4; font-weight: 650; }
.e-test-page__body > p:empty { display: none; }

/* ---------- test card ---------- */
.e-test {
	--e-test-pad: var(--e-s5);
	position: relative; /* no overflow here: the "Next" bar is sticky */
	padding: var(--e-test-pad);
	background: #fff; border: 1px solid var(--e-line); border-radius: var(--e-radius-xl); box-shadow: var(--e-shadow-sm);
}
.e-test [hidden], .e-test[hidden] { display: none !important; }
@media (max-width: 639.98px) {
	/* edge to edge on phones: more room for the picture and the answers */
	.e-test { margin-inline: calc(-1 * var(--e-s5)); border-radius: 0; border-inline: 0; }
}
@media (min-width: 640px) { .e-test { --e-test-pad: var(--e-s6); } }
@media (min-width: 960px) { .e-test { --e-test-pad: var(--e-s8); } }
.e-test--empty { text-align: center; }
.e-test__empty { padding: var(--e-s8) 0; color: var(--e-muted); font-size: 18px; }

/* progress */
.e-test__progress { margin-bottom: var(--e-s4); }
.e-test__count { margin-bottom: var(--e-s2); color: var(--e-muted); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.e-test__current, .e-test__total { color: var(--e-ink); font-weight: 750; }
.e-test__bar { height: 6px; border-radius: 999px; background: var(--e-line); overflow: hidden; }
.e-test__bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--e-primary); transition: width .3s ease; }

/* picture: always a 16:9 box (the size of the next pictures is unknown), tap to enlarge */
.e-test__figure { margin: 0 0 var(--e-s5); }
.e-test__zoom {
	position: relative; display: block; width: 100%; aspect-ratio: 16 / 9; padding: 0;
	border: 0; border-radius: var(--e-radius-lg); overflow: hidden; background: var(--e-bg-soft); cursor: zoom-in;
}
.e-test__img { width: 100%; height: 100%; object-fit: contain; transition: opacity .2s; }
.e-test__figure.is-loading .e-test__img { opacity: 0; }
.e-test__zoom-icon {
	position: absolute; right: 10px; bottom: 10px; display: grid; place-items: center; width: 40px; height: 40px;
	border-radius: 999px; background: rgba(15, 23, 42, .72); color: #fff; transition: background-color .15s;
}
.e-test__zoom:hover .e-test__zoom-icon { background: var(--e-ink); }
.e-test__zoom:focus-visible { border-radius: var(--e-radius-lg); outline-offset: 3px; }

/* question */
.e-test__question {
	margin: 0 0 var(--e-s4); color: var(--e-ink); font-size: clamp(19px, 2.4vw, 22px); line-height: 1.4;
	font-weight: 700; letter-spacing: -.01em; overflow-wrap: break-word;
}
.e-test__question:focus, .e-test__result-title:focus { outline: none; }

/* answers */
.e-test__answers { display: flex; flex-direction: column; gap: var(--e-s3); }
.e-test__answer {
	display: flex; align-items: center; gap: var(--e-s3); width: 100%; min-height: 56px; padding: 10px 14px 10px 10px;
	border: 2px solid var(--e-line); border-radius: var(--e-radius-md); background: #fff; color: var(--e-ink);
	font-size: 17px; line-height: 1.4; font-weight: 500; text-align: left;
	transition: border-color .15s, background-color .15s, color .15s;
	-webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.e-test__answer:focus-visible { border-radius: var(--e-radius-md); }
.e-test__letter {
	flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
	background: var(--e-primary-50); color: var(--e-primary-700); font-size: 16px; font-weight: 750; line-height: 1;
	transition: background-color .15s, color .15s;
}
.e-test__text { flex: 1 1 auto; min-width: 0; overflow-wrap: break-word; }
.e-test__mark { flex: none; display: none; }
@media (hover: hover) {
	.e-test__answer:not([aria-disabled="true"]):hover { border-color: var(--e-primary); background: var(--e-primary-50); }
	.e-test__answer:not([aria-disabled="true"]):hover .e-test__letter { background: var(--e-primary); color: #fff; }
}
.e-test__answer:not([aria-disabled="true"]):active { transform: translateY(1px); }
.e-test__answer[aria-disabled="true"] { cursor: default; }
.e-test[aria-busy="true"] .e-test__answer, .e-test[aria-busy="true"] .e-test__next { cursor: progress; }
.e-test__answer.is-pending { border-color: var(--e-primary); background: var(--e-primary-50); }
.e-test__answer.is-pending .e-test__letter { background: var(--e-primary); color: #fff; }

.e-test__answer.is-correct { border-color: var(--e-success); background: var(--e-success-50); }
.e-test__answer.is-correct .e-test__letter { background: #15803d; color: #fff; }
.e-test__answer.is-wrong { border-color: var(--e-danger); background: var(--e-danger-50); }
.e-test__answer.is-wrong .e-test__letter { background: var(--e-danger); color: #fff; }
.e-test__answer.is-correct .e-test__mark, .e-test__answer.is-wrong .e-test__mark { display: grid; }
.e-test__answer.is-correct .e-test__mark { color: #15803d; }
.e-test__answer.is-wrong .e-test__mark { color: #b91c1c; }
.e-test__answer.is-correct .e-test__mark-no, .e-test__answer.is-wrong .e-test__mark-ok { display: none; }
.e-test__answer.is-dim { color: var(--e-muted); }
.e-test__answer.is-dim .e-test__letter { background: var(--e-bg-soft); color: var(--e-muted); }

/* waiting for the server: a spinner on the chosen answer / on "Next" (shown only if it takes a moment) */
@keyframes e-test-spin { to { transform: rotate(360deg); } }
@keyframes e-test-appear { from { opacity: 0; } to { opacity: 1; } }
.e-test__answer.is-pending .e-test__mark { display: grid; color: var(--e-primary); }
.e-test__answer.is-pending .e-test__mark svg, .e-test[aria-busy="true"] .e-test__next svg { display: none; }
.e-test__answer.is-pending .e-test__mark::before, .e-test[aria-busy="true"] .e-test__next::after {
	content: ""; width: 20px; height: 20px; border: 2.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
	animation: e-test-spin .7s linear infinite, e-test-appear .2s .25s both;
}

/* after the answer: verdict and explanation */
.e-test__feedback { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.4; }
.e-test__feedback.is-shown { margin-top: var(--e-s4); padding: 10px 14px; border-radius: var(--e-radius-md); }
.e-test__feedback.is-correct { background: var(--e-success-50); color: #15803d; }
.e-test__feedback.is-wrong { background: var(--e-danger-50); color: #b91c1c; }

.e-test__explain { margin-top: var(--e-s3); padding: var(--e-s4) var(--e-s5); border: 1px solid var(--e-line); border-radius: var(--e-radius-md); background: var(--e-bg-soft); }
.e-test__explain-title { display: flex; align-items: center; gap: var(--e-s2); margin-bottom: var(--e-s2); color: var(--e-ink); font-size: 16px; font-weight: 700; }
.e-test__explain-title svg { color: var(--e-primary); }
.e-test__explain-body { color: var(--e-text); font-size: 16px; line-height: 1.6; overflow-wrap: break-word; }
.e-test__explain-body > * + * { margin-top: .6em; }
.e-test__explain-body a { text-decoration: underline; text-underline-offset: 2px; }
.e-test__explain-body b, .e-test__explain-body strong { color: var(--e-ink); }
.e-test__explain-body ul { padding-left: 1.2em; list-style: disc; }
.e-test__explain-body ol { padding-left: 1.2em; list-style: decimal; }
.e-test__explain-body img { max-width: 100%; height: auto; border-radius: var(--e-radius-sm); }
.e-test__explain-body hr { margin: var(--e-s3) 0; border: 0; border-top: 1px solid var(--e-line); }

.e-test__hint { display: none; margin-top: var(--e-s4); color: var(--e-muted); font-size: 14px; }
@media (hover: hover) and (pointer: fine) { .e-test__hint { display: block; } }
.e-test__error { margin-top: var(--e-s4); padding: 10px 14px; border-radius: var(--e-radius-md); background: var(--e-danger-50); color: #b91c1c; font-size: 15px; font-weight: 600; }

/* "Next": right-aligned under the explanation; on phones and small tablets a bar stuck to the bottom of the screen */
.e-test__next-bar { display: flex; justify-content: flex-end; margin-top: var(--e-s5); }
.e-test__next { min-width: 220px; }
.e-test__next[aria-disabled="true"] { opacity: .75; }
.e-test .e-btn:focus-visible { border-radius: var(--e-radius-lg); }
@media (max-width: 959.98px) {
	.e-test__next-bar {
		position: sticky; bottom: 0; z-index: 5;
		margin: var(--e-s5) calc(-1 * var(--e-test-pad)) calc(-1 * var(--e-test-pad));
		padding: var(--e-s3) var(--e-test-pad) max(var(--e-s3), env(safe-area-inset-bottom));
		background: rgba(255, 255, 255, .97); border-top: 1px solid var(--e-line); box-shadow: 0 -6px 16px rgba(15, 23, 42, .06);
	}
	.e-test__next { width: 100%; min-width: 0; }
}
@media (min-width: 640px) and (max-width: 959.98px) {
	.e-test__next-bar { border-radius: 0 0 var(--e-radius-xl) var(--e-radius-xl); }
}

/* desktop: picture on the left (stays in view), question and answers on the right — everything fits one screen */
@media (min-width: 960px) {
	.e-test-page--exam .e-container--narrow { max-width: calc(1080px + 2 * var(--e-s5)); }
	.e-test__layout { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: var(--e-s8); align-items: start; }
	.e-test__figure { position: sticky; top: calc(var(--e-header-h) + var(--e-s4)); margin: 0; }
	.e-test__layout:has(> .e-test__figure[hidden]) { grid-template-columns: minmax(0, 1fr); max-width: 720px; margin-inline: auto; }
	/* long explanations: "Next" stays at the bottom of the screen here too */
	.e-test__next-bar {
		position: sticky; bottom: 0; z-index: 2; margin-top: var(--e-s2); padding: var(--e-s4) 0;
		background: linear-gradient(rgba(255, 255, 255, 0), #fff var(--e-s4));
	}
}

/* ---------- result ---------- */
.e-test__result { padding: var(--e-s4) 0; text-align: center; }
.e-test__trophy {
	display: inline-grid; place-items: center; width: 64px; height: 64px; margin-bottom: var(--e-s3);
	border-radius: 20px; background: var(--e-primary-50); color: var(--e-primary);
}
.e-test__result-title { color: var(--e-ink); font-size: 22px; line-height: 1.3; font-weight: 750; }
.e-test__score {
	margin-top: var(--e-s2); color: var(--e-ink); font-size: clamp(56px, 14vw, 80px); line-height: 1.05; font-weight: 800;
	letter-spacing: -.03em; font-variant-numeric: tabular-nums;
}
.e-test__score-sep { margin: 0 .12em; color: #cbd5e1; font-weight: 600; }
.e-test__score-total { color: var(--e-muted); }
.e-test__percent { margin-top: var(--e-s2); color: var(--e-primary-700); font-size: 18px; font-weight: 700; }
.e-test__meter { max-width: 320px; height: 10px; margin: var(--e-s3) auto 0; border-radius: 999px; background: var(--e-line); overflow: hidden; }
.e-test__meter-fill { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--e-primary); }
.e-test__result[data-tier="great"] .e-test__trophy { background: var(--e-success-50); color: #15803d; }
.e-test__result[data-tier="great"] .e-test__percent { color: #15803d; }
.e-test__result[data-tier="great"] .e-test__meter-fill { background: var(--e-success); }
.e-test__result[data-tier="low"] .e-test__trophy { background: #fff7ed; color: #b45309; }
.e-test__result[data-tier="low"] .e-test__percent { color: #b45309; }
.e-test__result[data-tier="low"] .e-test__meter-fill { background: var(--e-star); }
.e-test__message { max-width: 42ch; margin: var(--e-s4) auto 0; color: var(--e-text); font-size: 17px; line-height: 1.55; }
.e-test__result .e-test__error { max-width: 420px; margin: var(--e-s5) auto 0; }
.e-test__restart { margin-top: var(--e-s6); }
@media (max-width: 639.98px) { .e-test__restart { width: 100%; } }
.e-test__app { margin-top: var(--e-s8); padding-top: var(--e-s6); border-top: 1px solid var(--e-line); }
.e-test__app-title { color: var(--e-ink); font-size: 20px; line-height: 1.3; font-weight: 700; }
.e-test__app-text { max-width: 46ch; margin: var(--e-s1) auto 0; color: var(--e-muted); font-size: 16px; line-height: 1.5; }
.e-test__app .e-stores { justify-content: center; margin-top: var(--e-s4); }

/* ---------- enlarged picture ---------- */
.e-test__dialog {
	width: min(100vw - 24px, 1100px); max-width: none; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
	padding: 0; border: 0; border-radius: var(--e-radius-lg); background: var(--e-dark); color: #fff; overflow: hidden;
}
.e-test__dialog::backdrop { background: rgba(11, 21, 48, .85); }
.e-test__dialog-scroll { max-height: inherit; overflow: auto; overscroll-behavior: contain; }
.e-test__dialog-img { width: 100%; height: auto; }
.e-test__dialog-close {
	position: absolute; top: 8px; right: 8px; z-index: 1; display: grid; place-items: center; width: 44px; height: 44px;
	padding: 0; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .95); color: var(--e-ink); box-shadow: var(--e-shadow-sm);
}
.e-test__dialog-close:hover { background: #fff; }
.e-test__dialog-close:focus-visible { border-radius: 999px; }
@media (max-width: 639.98px) and (orientation: portrait) {
	/* a phone screen is as wide as the card: show the picture taller and let it pan sideways */
	.e-test__dialog { width: 100vw; border-radius: 0; }
	.e-test__dialog-img { width: auto; max-width: none; height: min(60vh, 576px); }
}

/* ---------- start page ---------- */
.e-test-page__start {
	padding: var(--e-s6) var(--e-s5); background: #fff; border: 1px solid var(--e-line); border-radius: var(--e-radius-xl);
	box-shadow: var(--e-shadow-sm);
}
@media (min-width: 640px) { .e-test-page__start { padding: var(--e-s8); } }
.e-test-page__start > h2 { margin-bottom: var(--e-s5); color: var(--e-ink); font-size: 18px; }
.e-test-start__facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--e-s3); margin-bottom: var(--e-s6); }
.e-test-start__fact {
	display: flex; align-items: center; gap: var(--e-s3); padding: var(--e-s4); border-radius: var(--e-radius-lg);
	background: var(--e-bg-soft); color: var(--e-ink); font-size: 16px; font-weight: 600; line-height: 1.35;
}
.e-test-start__fact svg { flex: none; color: var(--e-primary); }
.e-test-start__fact--num { flex-direction: row-reverse; justify-content: flex-end; }
.e-test-start__value { min-width: 24px; color: var(--e-primary-700); font-size: 26px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
@media (min-width: 640px) {
	.e-test-start__facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.e-test-start__fact { flex-direction: column; align-items: flex-start; justify-content: flex-start; }
	.e-test-start__fact--num { flex-direction: column-reverse; justify-content: flex-end; }
}
.e-test-start__btn { width: 100%; }
@media (min-width: 640px) { .e-test-start__btn { width: auto; min-width: 280px; } }

/* ---------- "Continue in the app" under the test ---------- */
.e-test-apps { padding-top: var(--e-s8); }
.e-test-apps__card {
	display: flex; flex-direction: column; align-items: flex-start; gap: var(--e-s4); padding: var(--e-s6) var(--e-s4);
	border-radius: var(--e-radius-xl); background: var(--e-primary-50);
}
.e-test-apps__icon { display: none; place-items: center; width: 48px; height: 48px; flex: none; border-radius: 14px; background: #fff; color: var(--e-primary); }
@media (min-width: 640px) { .e-test-apps__icon { display: grid; } }
.e-test-apps__title { color: var(--e-ink); font-size: 22px; line-height: 1.25; font-weight: 750; letter-spacing: -.01em; }
.e-test-apps__lead { margin-top: var(--e-s1); color: var(--e-text); font-size: 16px; line-height: 1.5; }
@media (min-width: 640px) {
	/* one row when there is room (wide exam page), otherwise the badges go under the text */
	.e-test-apps__card { flex-direction: row; flex-wrap: wrap; align-items: center; padding: var(--e-s6) var(--e-s8); }
	.e-test-apps__text { flex: 1 1 300px; min-width: 0; }
	.e-test-apps__card .e-stores { flex: none; }
}
/* the result screen has its own store buttons */
.e-test-page:has(.e-test__result:not([hidden])) .e-test-apps { display: none; }
