/* ============================================================
   Alufit quiz — стилизация в духе Marquiz
   фирменный цвет: #f03f51
   ============================================================ */

:root {
    --q-primary: #f03f51;
    --q-primary-dark: #d61c2f;
    --q-primary-light: #f89ba5;
    --q-primary-soft: rgba(240, 63, 81, 0.08);
    --q-primary-alpha-20: rgba(240, 63, 81, 0.2);
    --q-text: #363636;
    --q-text-soft: #737373;
    --q-text-mute: #b3b3b3;
    --q-bg: #ffffff;
    --q-bg-soft: #f7f7f7;
    --q-bg-mute: #ededed;
    --q-border: #e6e6e6;
    --q-shadow: 0 12px 32px rgba(54, 54, 54, 0.08);
    --q-shadow-lg: 0 24px 60px rgba(54, 54, 54, 0.15);
    --q-radius: 0.5rem;
    --q-radius-lg: 0.75rem;
    --q-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --q-anim: 280ms cubic-bezier(.61, .3, .8, .97);
}

/* ---- база ---- */
.quiz-body {
    margin: 0;
    min-height: 100vh;
    background: linear-gradient(135deg, #fafafa 0%, #f0f0f0 100%);
    color: var(--q-text);
    font-family: var(--q-font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    /* демо-страница: центрируем триггерную кнопку */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

/* ---- триггерная кнопка ---- */
.quiz-launcher-wrap {
    display: inline-block;
    text-align: center;
}

.quiz-launcher-demo {
    max-width: 560px;
}

.quiz-launcher-demo__title {
    margin: 0 0 12px;
    font-size: 32px;
    font-weight: 700;
    color: var(--q-text);
    letter-spacing: -0.01em;
}

.quiz-launcher-demo__lead {
    margin: 0 0 28px;
    font-size: 17px;
    color: var(--q-text-soft);
    line-height: 1.5;
}

.quiz-launcher--lg {
    padding: 18px 36px;
    font-size: 17px;
}

.quiz-launcher--lg svg {
    width: 24px;
    height: 24px;
}

.quiz-launcher {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    border: 0;
    border-radius: var(--q-radius);
    background: var(--q-primary);
    color: #fff;
    font-family: var(--q-font);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(240, 63, 81, 0.3);
    transition: all var(--q-anim);
}

.quiz-launcher:hover {
    background: var(--q-primary-dark);
    box-shadow: 0 8px 24px rgba(240, 63, 81, 0.4);
    transform: translateY(-1px);
}

.quiz-launcher svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* ---- бэкдроп ---- */
.quiz-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 9998;
    animation: q-fade-in 240ms ease-out;
}

@keyframes q-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ---- модалка ---- */
.quiz-app {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 32px);
    max-width: 1180px;
    max-height: calc(100vh - 32px);
    background: var(--q-bg);
    border-radius: var(--q-radius-lg);
    box-shadow: var(--q-shadow-lg);
    overflow: hidden;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    animation: q-pop-in 280ms cubic-bezier(.16, 1, .3, 1);
}

/* атрибут hidden должен перебивать display:flex/block */
.quiz-app[hidden],
.quiz-backdrop[hidden] {
    display: none !important;
}

@keyframes q-pop-in {
    from { opacity: 0; transform: translate(-50%, -48%) scale(.96); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* блокируем прокрутку body, когда модалка открыта */
body.quiz-is-open {
    overflow: hidden;
}

/* ---- крестик закрытия ---- */
.quiz-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: var(--q-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all var(--q-anim);
}

.quiz-close:hover {
    background: var(--q-primary);
    color: #fff;
    transform: rotate(90deg);
}

.quiz-close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.quiz-app * {
    box-sizing: border-box;
}

/* ---- шаги ---- */
.quiz-step {
    display: none;
    width: 100%;
    min-height: 0;
    animation: q-fade var(--q-anim) both;
}

.quiz-step.is-active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

/* стартовая страница скроллится внутри, если не влезает */
.quiz-start.is-active {
    overflow-y: auto;
}

/* тело вопросов: title/progress сверху, контент скроллится, nav снизу */
.quiz-questions.is-active .quiz__body {
    overflow-y: auto;
    min-height: 0;
}

@keyframes q-fade {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   СТАРТОВАЯ СТРАНИЦА
   ============================================================ */
.quiz-start {
    flex-direction: row !important;
    align-items: stretch;
    padding: 0;
}

.quiz-start__bg {
    flex: 0 0 58%;
    min-height: 600px;
    background-size: cover;
    background-position: center;
}

.quiz-start__content {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    padding: 48px 40px;
}

.quiz-start__body {
    width: 100%;
}

.quiz-start__title {
    margin: 0 0 16px;
    font-size: 28px;
    line-height: 1.2;
    font-weight: 700;
    color: var(--q-text);
}

.quiz-start__subtitle {
    margin: 0 0 28px;
    font-size: 16px;
    color: var(--q-text-soft);
}

.quiz-start__note {
    margin: 18px 0 0;
    font-size: 13px;
    color: var(--q-text-mute);
}

/* ============================================================
   КАРКАС ВОПРОСОВ
   ============================================================ */
.quiz-questions {
    padding: 32px 40px 24px;
}

.quiz__title h3 {
    margin: 0 0 12px;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--q-text-mute);
    font-weight: 700;
}

.quiz__progress {
    margin-bottom: 20px;
}

.quiz__progress-label {
    font-size: 13px;
    color: var(--q-text-soft);
    margin-bottom: 6px;
}

.quiz__progress-label span {
    color: var(--q-primary);
    font-weight: 700;
}

.quiz__progress-bar {
    position: relative;
    width: 100%;
    height: 6px;
    background: var(--q-bg-mute);
    border-radius: 999px;
    overflow: hidden;
}

.quiz__progress-bar span {
    display: block;
    height: 100%;
    background: var(--q-primary);
    border-radius: inherit;
    transition: width var(--q-anim);
}

.quiz__body {
    flex: 1 1 auto;
    position: relative;
}

/* ---- вопросы ---- */
.q {
    display: none;
    animation: q-fade var(--q-anim) both;
    padding-bottom: 16px;
}

.q.is-active {
    display: block;
}

.q__sep {
    margin: 0 0 16px;
    border: 0;
    border-top: 1px solid var(--q-border);
}

.q__title {
    margin: 0 0 6px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1.3;
}

.q__hint {
    margin: 0 0 18px;
    font-size: 14px;
    color: var(--q-text-soft);
}

.q__tag {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 10px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--q-text-soft);
    background: var(--q-bg-mute);
    border-radius: 999px;
    vertical-align: middle;
}

/* ---- ответы: сетка картинок ---- */
.answers--grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    max-height: 640px;
    overflow-x: hidden;
    overflow-y: auto;
    /* лёгкий внутренний отступ, чтобы карточки не упирались в скроллбар */
    padding-right: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--q-primary-light) transparent;
}

.answers--grid::-webkit-scrollbar {
    width: 6px;
}
.answers--grid::-webkit-scrollbar-track {
    background: transparent;
}
.answers--grid::-webkit-scrollbar-thumb {
    background: var(--q-primary-light);
    border-radius: 3px;
}
.answers--grid::-webkit-scrollbar-thumb:hover {
    background: var(--q-primary);
}

.answers--grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.answers--grid-2 {
    grid-template-columns: repeat(2, 1fr);
    max-width: 720px;
}

.ans {
    position: relative;
    display: block;
    cursor: pointer;
    user-select: none;
}

.ans input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.ans--img {
    border: 2px solid var(--q-border);
    border-radius: var(--q-radius);
    overflow: hidden;
    background: var(--q-bg);
    transition: all var(--q-anim);
}

.ans--img:hover {
    border-color: var(--q-primary-light);
    box-shadow: var(--q-shadow);
    transform: translateY(-2px);
}

.ans--img:has(input:checked) {
    border-color: var(--q-primary);
    box-shadow: 0 0 0 4px var(--q-primary-alpha-20), var(--q-shadow);
}

.ans__img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    background-size: cover;
    background-position: center;
    background-color: var(--q-bg-soft);
}

.ans__title {
    display: block;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
    color: var(--q-text);
    line-height: 1.3;
}

.ans__title small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    font-weight: 400;
    color: var(--q-text-soft);
}

/* ---- ответы: варианты текстом + картинка ---- */
.answers--variants {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: center;
}

.answers__variants {
    display: grid;
    gap: 10px;
}

.answers__hero img {
    max-width: 100%;
    height: auto;
    border-radius: var(--q-radius);
    background: var(--q-bg-soft);
}

.ans--var {
    display: block;
    padding: 18px 22px;
    border: 2px solid var(--q-border);
    border-radius: var(--q-radius);
    transition: all var(--q-anim);
    font-weight: 600;
    background: var(--q-bg);
}

.ans--var:hover {
    border-color: var(--q-primary-light);
}

.ans--var:has(input:checked) {
    border-color: var(--q-primary);
    background: var(--q-primary-soft);
    color: var(--q-primary-dark);
}

/* ---- дата ---- */
.answers--date {
    max-width: 460px;
}

.date-field {
    display: block;
}

.date-field__label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--q-text-soft);
}

.date-field__control {
    position: relative;
    display: flex;
    align-items: center;
    border: 2px solid var(--q-border);
    border-radius: var(--q-radius);
    background: var(--q-bg);
    padding: 0 16px;
    transition: border-color var(--q-anim);
}

.date-field__control:focus-within {
    border-color: var(--q-primary);
}

.date-field__control svg {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    fill: var(--q-text-mute);
    flex-shrink: 0;
}

.date-field input {
    flex: 1 1 auto;
    height: 56px;
    border: 0;
    background: transparent;
    font-family: var(--q-font);
    font-size: 16px;
    color: var(--q-text);
    outline: none;
}

.date-field__note {
    margin: 12px 0 0;
    font-size: 13px;
    color: var(--q-text-soft);
}

/* ---- финальная форма ---- */
.q--final .q__title {
    font-size: 24px;
}

.lead-form {
    display: grid;
    gap: 18px;
    max-width: 520px;
}

.field {
    display: block;
}

.field__label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--q-text-soft);
}

.field__control {
    position: relative;
    display: flex;
    align-items: center;
    border: 2px solid var(--q-border);
    border-radius: var(--q-radius);
    background: var(--q-bg);
    padding: 0 16px;
    transition: border-color var(--q-anim);
}

.field__control:focus-within {
    border-color: var(--q-primary);
}

.field__control svg {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    fill: var(--q-text-mute);
    flex-shrink: 0;
}

.field input {
    flex: 1 1 auto;
    height: 56px;
    border: 0;
    background: transparent;
    font-family: var(--q-font);
    font-size: 16px;
    color: var(--q-text);
    outline: none;
}

.field__err {
    display: none;
    margin-top: 6px;
    font-size: 12px;
    color: var(--q-primary);
}

.field.is-invalid .field__control {
    border-color: var(--q-primary);
}

.field.is-invalid .field__err {
    display: block;
}

.agree {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
    color: var(--q-text-soft);
    cursor: pointer;
}

.agree input {
    margin-top: 3px;
    accent-color: var(--q-primary);
    flex-shrink: 0;
}

.agree a {
    color: var(--q-primary);
    text-decoration: none;
}

.agree a:hover {
    text-decoration: underline;
}

/* ---- итог ---- */
.q__done {
    text-align: center;
    padding: 32px 16px 16px;
}

.q__done-ico {
    width: 72px;
    height: 72px;
    margin: 0 auto 18px;
    background: var(--q-primary);
    color: #fff;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.q__done-ico svg {
    width: 40px;
    height: 40px;
    fill: #fff;
}

.q__done-ico--fail {
    background: var(--q-bg-mute);
    color: var(--q-primary);
}

.q__done-ico--fail svg {
    fill: var(--q-primary);
}

.q__done h2 {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 700;
}

.q__done p {
    margin: 0 0 22px;
    color: var(--q-text-soft);
}

.q__done a {
    color: var(--q-primary);
}

/* ============================================================
   НАВИГАЦИЯ
   ============================================================ */
.quiz__nav {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-top: 18px;
    border-top: 1px solid var(--q-border);
    margin-top: 8px;
}

.quiz__nav-next {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

/* ============================================================
   КНОПКИ
   ============================================================ */
.quiz-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: var(--q-radius);
    background: var(--q-bg-mute);
    color: var(--q-text);
    padding: 0 22px;
    height: 48px;
    font-family: var(--q-font);
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: all var(--q-anim);
    text-decoration: none;
}

.quiz-app [hidden] {
    display: none !important;
}

.quiz-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.quiz-btn--primary {
    background: var(--q-primary);
    color: #fff;
    box-shadow: 0 4px 16px rgba(240, 63, 81, 0.25);
}

.quiz-btn--primary:hover {
    background: var(--q-primary-dark);
    box-shadow: 0 6px 20px rgba(240, 63, 81, 0.35);
}

.quiz-btn--lg {
    height: 56px;
    padding: 0 32px;
    font-size: 16px;
}

.quiz-btn--sm {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
}

.quiz-btn--ghost {
    background: transparent;
    color: var(--q-text-soft);
    box-shadow: none;
}

.quiz-btn--ghost:hover:not(:disabled) {
    background: var(--q-bg-mute);
    color: var(--q-text);
}

.quiz-btn:disabled,
.quiz-btn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: not-allowed;
    box-shadow: none;
}

.quiz-btn--primary:disabled {
    background: var(--q-primary-light);
}

/* ============================================================
   ОТЗЫВЧИВОСТЬ
   ============================================================ */

/* ----- планшеты (≤ 900 px) ----- */
@media (max-width: 900px) {
    .quiz-launcher-demo__title {
        font-size: 26px;
    }
    .quiz-launcher-demo__lead {
        font-size: 15px;
    }

    .quiz-start {
        flex-direction: column !important;
    }
    .quiz-start__bg {
        flex: 0 0 220px;
        min-height: 220px;
    }
    .quiz-start__content {
        padding: 24px 20px 32px;
    }
    .quiz-start__title {
        font-size: 22px;
    }
    .quiz-start__subtitle {
        font-size: 15px;
    }
    .quiz-questions {
        padding: 20px 18px 16px;
    }
    .quiz__title h3 {
        font-size: 12px;
    }
    .q__title {
        font-size: 18px;
    }
    .answers--grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
        max-height: none;
    }
    .answers--grid-3,
    .answers--grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }
    .answers--variants {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    .answers__hero {
        order: -1;
    }
    .answers__hero img {
        max-height: 180px;
        width: auto;
        margin: 0 auto;
        display: block;
    }
    .quiz-btn--lg {
        width: 100%;
    }
}

/* ----- мобильные (≤ 600 px): модалка во весь экран ----- */
@media (max-width: 600px) {
    .quiz-app {
        width: 100%;
        max-width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        top: 0;
        left: 0;
        transform: none;
        border-radius: 0;
        box-shadow: none;
        /* учёт безопасной зоны iOS (notch / home-indicator) */
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    @keyframes q-pop-in {
        from { opacity: 0; transform: translateY(12px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .quiz-close {
        top: calc(env(safe-area-inset-top, 0) + 10px);
        right: 10px;
        width: 32px;
        height: 32px;
    }
    .quiz-close svg {
        width: 18px;
        height: 18px;
    }
}

/* ----- маленькие телефоны (≤ 480 px) ----- */
@media (max-width: 480px) {
    .quiz-launcher-demo__title {
        font-size: 22px;
    }
    .quiz-launcher-demo__lead {
        font-size: 14px;
        margin-bottom: 22px;
    }
    .quiz-launcher--lg {
        padding: 16px 24px;
        font-size: 15px;
        width: 100%;
        justify-content: center;
    }

    .quiz-start__title {
        font-size: 20px;
    }
    .quiz-start__subtitle {
        font-size: 14px;
        margin-bottom: 20px;
    }
    .quiz-questions {
        padding: 18px 14px 14px;
    }
    .q__title {
        font-size: 17px;
    }
    .q__hint {
        font-size: 13px;
    }
    .answers--grid,
    .answers--grid-2,
    .answers--grid-3 {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .ans__title {
        padding: 10px;
        font-size: 12.5px;
        line-height: 1.25;
    }
    .ans__title small {
        font-size: 11px;
    }
    /* финальная форма — поля плотнее */
    .field input,
    .date-field input {
        height: 52px;
        font-size: 15px;
    }
    .q--final .q__title {
        font-size: 20px;
    }
    /* итоги */
    .q__done h2 {
        font-size: 20px;
    }
    .q__done {
        padding: 16px 8px 8px;
    }

    /* нижняя навигация: prev — иконкой, next занимает всё, skip компактный */
    .quiz__nav {
        gap: 10px;
        padding-top: 14px;
    }
    .quiz__nav-next {
        gap: 8px;
        flex: 1 1 auto;
    }
    .quiz__nav-next .quiz-btn[data-action="next"] {
        flex: 1 1 auto;
        padding: 0 16px;
    }
    .quiz-btn {
        height: 46px;
        font-size: 14px;
        padding: 0 16px;
    }
    .quiz-btn--lg {
        height: 52px;
        font-size: 15px;
    }
    .quiz-btn[data-action="prev"] {
        padding: 0 12px;
    }
}

/* ----- очень узкие экраны (≤ 360 px) ----- */
@media (max-width: 360px) {
    .answers--grid,
    .answers--grid-2,
    .answers--grid-3 {
        grid-template-columns: 1fr;
    }
    .ans--img .ans__img {
        aspect-ratio: 16 / 10;
    }
}

/* ----- ландшафт телефонов (низкий вьюпорт) ----- */
@media (max-height: 480px) and (max-width: 900px) {
    .quiz-start__bg {
        display: none;
    }
    .quiz-start__content {
        padding: 18px 20px;
    }
    .quiz-start__title {
        font-size: 18px;
        margin-bottom: 10px;
    }
    .quiz-start__subtitle {
        margin-bottom: 16px;
    }
}
