:root {
  color-scheme: light;

  --red: #e51e36;
  --red-dark: #c9162c;
  --green: #1f9d55;

  --text: #191b20;
  --muted: #737780;
  --line: #e6e8ec;
  --field: #f5f6f8;

  /* Быстрый старт и мягкая остановка — для большинства движений. */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  /* С лёгким перелётом — для «пружинящих» элементов. */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f0f1f3;
  color: var(--text);

  font-family: -apple-system, BlinkMacSystemFont,
    "Segoe UI", Arial, sans-serif;

  -webkit-font-smoothing: antialiased;
}

button,
input,
a {
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.page {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 24px 24px 0;
  background: #ffffff;

  /* Экраны сдвигаются при смене шага — без горизонтальной прокрутки. */
  overflow-x: clip;
}

/* ---------- Появление при загрузке ---------- */

.reveal {
  animation: rise 520ms var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 60ms + 60ms);
}

/* После первого перехода не повторяем появление при возврате на шаг 1. */
.revealed .reveal {
  animation: none;
}

.stagger {
  animation: rise 420ms var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 50ms + 120ms);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}

/* ---------- Шапка и вступление ---------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 32px;
}

.brand {
  display: flex;
  align-items: center;
  width: 178px;
  min-height: 44px;
}

.brand img {
  display: block;
  width: 100%;
  height: auto;
}

.help {
  display: grid;
  place-items: center;

  width: 44px;
  height: 44px;
  flex-shrink: 0;

  border: 1px solid var(--line);
  border-radius: 50%;

  color: #626773;
  text-decoration: none;
  font-size: 23px;
  font-weight: 500;

  transition:
    background-color 160ms ease,
    transform 160ms ease;
}

.help:active {
  transform: scale(0.94);
  background: var(--field);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);

  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

h1 {
  margin: 0;

  font-size: clamp(32px, 8.8vw, 40px);
  font-weight: 750;
  line-height: 1.12;
  letter-spacing: -1.5px;
}

.description {
  max-width: 340px;
  margin: 16px 0 0;

  color: var(--muted);
  font-size: 16px;
  line-height: 1.5;
}

/* ---------- Индикатор шагов ---------- */

.steps {
  display: flex;
  margin: 30px 0 34px;
  padding: 0;
  list-style: none;
}

.step {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  gap: 9px;

  color: var(--muted);
  font-size: 13px;

  transition: color 250ms ease;
}

.step:not(:last-child)::before,
.step:not(:last-child)::after {
  position: absolute;
  top: 18px;
  left: calc(50% + 25px);

  width: calc(100% - 50px);
  height: 2px;

  border-radius: 1px;
  content: "";
}

/* Серая линия. */
.step:not(:last-child)::after {
  background: #e6e8ec;
}

/* Красная заливка поверх неё — растёт слева направо. */
.step:not(:last-child)::before {
  z-index: 1;
  background: var(--red);

  transform: scaleX(0);
  transform-origin: left;
  transition: transform 450ms var(--ease);
}

.step.done::before {
  transform: scaleX(1);
}

.step-number {
  position: relative;
  z-index: 2;

  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;

  border-radius: 50%;
  background: #f0f1f4;
  color: #727783;

  font-size: 16px;
  font-weight: 500;

  transition:
    background-color 250ms ease,
    color 250ms ease,
    box-shadow 250ms ease;
}

.step.active {
  color: var(--red);
  font-weight: 600;
}

.step.active .step-number {
  background: var(--red);
  color: #ffffff;
  box-shadow: 0 0 0 5px rgb(229 30 54 / 12%);

  animation: step-pop 450ms var(--ease) backwards;
}

/* При загрузке ждём, пока проявится сам индикатор. */
html:not(.revealed) .step.active .step-number {
  animation-delay: 350ms;
}

.step.done {
  color: var(--text);
}

.step.done .step-number {
  background: var(--red);
  color: transparent;
}

.step.done .step-number::after {
  position: absolute;
  inset: 0;

  display: grid;
  place-items: center;

  color: #ffffff;
  content: "✓";
  font-size: 17px;
  font-weight: 600;

  animation: check-in 300ms var(--ease-spring) 200ms backwards;
}

@keyframes step-pop {
  0% {
    transform: scale(0.85);
  }

  55% {
    transform: scale(1.12);
  }

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

@keyframes check-in {
  from {
    opacity: 0;
    transform: scale(0.4);
  }
}

/* ---------- Экраны шагов ---------- */

.section-heading {
  margin-bottom: 22px;
}

h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.7px;
}

/* Фокус на заголовок ставится скриптом при смене шага. */
h2:focus {
  outline: none;
}

.section-heading p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Поля ---------- */

.form-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.form-group + .form-group {
  margin-top: 30px;
}

.form-group legend {
  margin-bottom: 14px;
  padding: 0;

  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

.field {
  margin-bottom: 20px;
}

/* Поле, которое снова показали (фактический адрес). */
.field.is-appearing {
  animation: rise 320ms var(--ease);
}

.field label {
  display: block;
  margin-bottom: 8px;

  font-size: 14px;
  font-weight: 500;
}

.input-wrap {
  position: relative;
}

.field input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 54px;
  padding: 15px 44px 15px 14px;

  border: 1px solid var(--line);
  border-radius: 11px;

  background: var(--field);
  color: var(--text);

  /* 16px предотвращает увеличение поля на iPhone. */
  font-size: 16px;
  line-height: 1.4;

  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

/* У дат нет галочки, а на iPhone значение по умолчанию стоит по центру. */
.field input[type="date"] {
  padding-right: 14px;
  -webkit-appearance: none;
  appearance: none;
}

.field input[type="date"]::-webkit-date-and-time-value {
  text-align: left;
}

/* Пустая дата — серым, как подсказка в других полях. */
.field input[type="date"]:not(:focus):invalid {
  color: #9297a0;
}

.field input::placeholder {
  color: #9297a0;
  opacity: 1;
}

.field input:focus {
  outline: none;
  border-color: var(--red);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgb(229 30 54 / 9%);
}

.field.has-error input {
  border-color: var(--red);
  background: #fff7f8;
}

.field-check {
  position: absolute;
  top: 50%;
  right: 14px;

  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: -10px;

  border-radius: 50%;
  background: var(--green);
  pointer-events: none;

  opacity: 0;
  transform: scale(0.4);
  transition:
    opacity 200ms ease,
    transform 300ms var(--ease-spring);
}

.field-check svg {
  width: 20px;
  height: 20px;

  fill: none;
  stroke: #ffffff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.field.is-valid .field-check {
  opacity: 1;
  transform: scale(1);
}

.field-hint {
  display: block;
  margin-top: 7px;

  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.field.has-error .field-hint {
  display: none;
}

.field-error {
  display: none;
  margin-top: 7px;

  color: var(--red-dark);
  font-size: 12px;
  line-height: 1.5;
}

.has-error .field-error {
  display: block;
  animation: error-in 220ms var(--ease) backwards;
}

@keyframes error-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: -8px 0 12px;

  font-size: 14px;
  cursor: pointer;
}

.check-row input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--red);
}

/* ---------- Кнопки ---------- */

.actions {
  display: flex;
  gap: 10px;
  margin-top: 28px;
}

.primary-button {
  position: relative;

  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 16px;

  min-height: 56px;
  padding: 15px 19px;

  border: 0;
  border-radius: 12px;

  background: var(--red);
  color: #ffffff;

  font-size: 16px;
  font-weight: 600;
  cursor: pointer;

  transition:
    background-color 160ms ease,
    opacity 200ms ease,
    transform 160ms ease;
}

.button-label {
  padding-left: 24px;
  flex: 1;
  text-align: center;

  transition: opacity 160ms ease;
}

.button-arrow {
  font-size: 24px;
  font-weight: 400;
  line-height: 1;

  transition:
    opacity 160ms ease,
    transform 200ms var(--ease);
}

.primary-button:active {
  transform: scale(0.985);
  background: var(--red-dark);
}

.primary-button:active .button-arrow {
  transform: translateX(4px);
}

@media (hover: hover) {
  .primary-button:hover {
    background: var(--red-dark);
  }

  .primary-button:hover .button-arrow {
    transform: translateX(3px);
  }
}

/* Форма ещё не заполнена: кнопка приглушена, но нажимается и показывает ошибки. */
.primary-button.is-idle {
  opacity: 0.5;
}

.button-spinner {
  position: absolute;
  top: 50%;
  left: 50%;

  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;

  border: 2.5px solid rgb(255 255 255 / 35%);
  border-top-color: #ffffff;
  border-radius: 50%;

  opacity: 0;
  transition: opacity 160ms ease;
}

.primary-button.is-loading {
  cursor: default;
}

.primary-button.is-loading .button-label,
.primary-button.is-loading .button-arrow {
  opacity: 0;
}

.primary-button.is-loading .button-spinner {
  opacity: 1;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.back-button {
  display: grid;
  place-items: center;

  width: 56px;
  min-height: 56px;
  flex-shrink: 0;

  border: 1px solid var(--line);
  border-radius: 12px;

  background: #ffffff;
  color: var(--text);

  font-size: 22px;
  cursor: pointer;

  transition:
    background-color 160ms ease,
    transform 160ms ease;
}

.back-button:active {
  transform: scale(0.96);
  background: var(--field);
}

.primary-button:focus-visible,
.back-button:focus-visible,
.contract:focus-visible,
a:focus-visible {
  outline: 3px solid #f3939f;
  outline-offset: 4px;
}

.step-caption {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- Шаг 2: договор ---------- */

.summary-list {
  margin-bottom: 16px;
}

.summary-title {
  margin: 0 0 8px;

  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.6px;
  text-transform: uppercase;
}

.summary + .summary-title {
  margin-top: 18px;
}

.summary {
  margin: 0;
  padding: 0 16px;

  border: 1px solid var(--line);
  border-radius: 14px;
}

.summary div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 0;
}

.summary div:not(:last-child) {
  border-bottom: 1px solid var(--line);
}

/* Длинная подпись переносится сама, а не сжимает значение. */
.summary dt {
  flex: 0 1 auto;
  max-width: 48%;
  color: var(--muted);
  font-size: 13px;
}

.summary dd {
  min-width: 0;
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
  overflow-wrap: break-word;
}

.contract {
  max-height: 220px;
  overflow: auto;
  padding: 16px;

  border-radius: 14px;
  background: var(--field);

  font-size: 14px;
  line-height: 1.6;
}

.contract p {
  margin: 0;
}

.contract p + p {
  margin-top: 10px;
}

.contract-muted {
  color: var(--muted);
  font-size: 13px;
}

/* ---------- Шаг 3: подпись ---------- */

.agree-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;

  border: 1px solid var(--line);
  border-radius: 14px;

  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;

  transition:
    border-color 160ms ease,
    background-color 160ms ease;
}

.agree-label input {
  width: 22px;
  height: 22px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--red);
}

.agree-label:has(input:checked) {
  border-color: var(--red);
  background: #fff5f6;
}

.agree.has-error .agree-label {
  border-color: var(--red);
}

/* ---------- Финал ---------- */

.done-screen {
  padding: 8px 0 4px;
  text-align: center;
}

.done-icon {
  display: block;
  width: 76px;
  height: 76px;
  margin: 0 auto 20px;

  fill: none;
  stroke: var(--red);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;

  animation: done-pop 500ms var(--ease-spring) backwards;
}

.done-icon circle {
  fill: #fff5f6;
  stroke-dasharray: 1;
  animation: draw 650ms var(--ease) 150ms backwards;
}

.done-icon path {
  stroke-width: 4;
  stroke-dasharray: 1;
  animation: draw 350ms var(--ease) 700ms backwards;
}

@keyframes done-pop {
  from {
    transform: scale(0.6);
  }
}

@keyframes draw {
  0% {
    opacity: 0;
    stroke-dashoffset: 1;
  }

  10% {
    opacity: 1;
  }

  100% {
    stroke-dashoffset: 0;
  }
}

.done-screen h2,
.done-screen p {
  animation: rise 420ms var(--ease) backwards;
}

.done-screen h2 {
  animation-delay: 750ms;
}

.done-screen p {
  max-width: 300px;
  margin: 8px auto 0;

  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;

  animation-delay: 830ms;
}

.done-email {
  color: var(--text);
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* ---------- Низ страницы ---------- */

.preview-label {
  margin: 26px 0 22px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;

  padding: 22px 0;
  padding-bottom: max(24px, env(safe-area-inset-bottom));

  border-top: 1px solid var(--line);
  color: var(--muted);

  font-size: 11px;
  line-height: 1.6;
}

.company,
.contact {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.footer-brand {
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
}

.contact a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;

  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

@media (max-width: 360px) {
  .page {
    padding-right: 18px;
    padding-left: 18px;
  }

  .brand {
    width: 156px;
  }

  .step {
    font-size: 12px;
  }
}

@media (min-width: 600px) {
  .page {
    margin-top: 32px;
    margin-bottom: 32px;
    padding: 28px 32px 0;

    border: 1px solid var(--line);
    border-radius: 24px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
