/* "Как это работает" — стили только для страницы /ru/how-it-works/.
   Использует исключительно переменные, радиусы и тени из landing-shared.css.

   Архитектура: каждый шаг сценария — самостоятельный <li class="hiw-step">
   с собственным phone-frame + скриншотом и текстом. Без JS все 8 шагов
   видны как обычный список (прогрессивное улучшение). С JS добавляется
   класс .js-ready на корневую секцию — тогда виден только активный
   сценарий и активный шаг внутри него, появляются переключатель роли,
   рельс шагов, линия маршрута и кнопки Далее/Назад. */

.hiw-hero {
  max-width: 760px;
  margin: 0 auto;
  padding: 116px 24px 6px;
  text-align: center;
}
.hiw-hero .eyebrow {
  margin-bottom: 10px;
}
.hiw-hero h1 {
  margin-bottom: 10px;
}
.hiw-hero-sub {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  color: var(--text-muted);
  font-size: 17px;
  line-height: 1.6;
}

.hiw-interactive {
  max-width: 980px;
  margin: 16px auto 0;
  padding: 0 24px;
}

/* ROLE SWITCH */
.role-switch {
  max-width: 560px;
  margin: 0 auto 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.role-btn {
  text-align: left;
  background: var(--white);
  border: 1px solid var(--ivory-dark);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}
.role-btn:hover {
  border-color: var(--blue);
}
.role-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.role-btn-title {
  display: block;
  /* Every one of these small UI labels needs its own line-height:
     body sets 1.72 for long-form paragraph text, and inheriting that
     on a one-line button label or city name roughly doubles the
     vertical space it actually needs. */
  line-height: 1.25;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 2px;
}
.role-btn-sub {
  display: block;
  line-height: 1.25;
  font-size: 12px;
  color: var(--text-muted);
}
.role-btn[aria-pressed='true'] {
  border-color: var(--blue);
  background: color-mix(in srgb, var(--blue) 6%, var(--white));
  box-shadow: var(--shadow-soft);
}
.role-btn[aria-pressed='true'] .role-btn-title {
  color: var(--blue);
}

/* ROUTE LINE */
.hiw-route-line {
  max-width: 420px;
  margin: 0 auto 10px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}
.hiw-route-city {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  line-height: 1.25;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.hiw-route-track {
  position: relative;
  height: 2px;
  background: var(--ivory-dark);
  border-radius: 2px;
}
.hiw-route-marker {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent);
  transform: translate(-50%, -50%);
  transition: left 0.3s ease;
}

/* STEP RAIL */
.hiw-rail {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 420px;
  margin: 0 auto 6px;
}
.hiw-dot {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--ivory-dark);
  background: var(--white);
  color: var(--text-muted);
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease;
}
.hiw-dot:hover {
  border-color: var(--blue);
}
.hiw-dot:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.hiw-dot[aria-current='step'] {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--white);
}
.hiw-rail-line {
  flex: 1;
  height: 1px;
  background: var(--ivory-dark);
}

/* SCENARIOS + STEPS (also the no-JS readable list) */
.hiw-scenario-hdr {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--blue);
  text-align: center;
  margin: 0 0 10px;
}
.hiw-step-list {
  list-style: none;
}
.hiw-step {
  display: grid;
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
  gap: 32px;
  /* stretch (the grid default would be stretch anyway, but spelled
     out since it matters here): makes the text column exactly as
     tall as the phone — the tallest cell in the row — so its own
     flex-column layout below can pin the pay-demo card to the
     bottom, flush with the phone's bottom edge. */
  align-items: stretch;
  border-top: 1px solid var(--ivory-dark);
  padding: 28px 0;
}
.hiw-step:first-child {
  border-top: 0;
}
.hiw-step-media {
  display: flex;
  justify-content: center;
}
.hiw-step-media .phone-frame {
  margin: 0;
}
.hiw-step-text {
  /* Stretched (by .hiw-step's align-items) to the phone's full
     height. A flex column so the badge/heading/description/buttons
     stay grouped at the top while .hiw-pay-demo, pushed down by its
     own margin-top: auto once JS moves it in here, lands flush with
     the bottom — matching the phone's bottom edge. */
  display: flex;
  flex-direction: column;
  /* flex-start, not the flex default (stretch): without it the badge
     pill and nav buttons — block-level once they're flex items —
     would stretch to the column's full width instead of staying
     their natural content size. .hiw-pay-demo opts back into
     stretching on its own (align-self) since that one should fill
     the column. */
  align-items: flex-start;
  /* Same height the phone itself resolves to (duplicated algebra, not
     a custom property — this is a sibling of the phone, not a
     descendant). .phone-frame--shot's width is
     min(314px, (76vh - 2B)/ratio + 2B); working that back into a
     height gives min((314-2B)*ratio + 2B, 76vh) — with B=9px and
     ratio=2532/1170, the capped case is (314-18)*2.164103+18≈658.6px.
     Nudges the text down from the very top of the column so it
     roughly lines up with where a centred block used to start. */
  padding-top: calc(min(658.6px, 76vh) * 0.17);
}
.hiw-step-badge {
  display: inline-block;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--blue);
  background: color-mix(in srgb, var(--blue) 10%, transparent);
  border-radius: 999px;
  padding: 4px 10px;
  margin-bottom: 10px;
}
.hiw-step-text h3 {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 19px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.hiw-step-text p {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* CHIP-NOTE — small "where's the money right now" line added after
   each step's existing <p>. Tinted per track: blue for "Я
   путешествую", accent for "Мне нужно…" — same color-mix(...)
   convention already used throughout landing-shared.css for tinted
   chips/badges. */
.hiw-chip-note {
  display: inline-flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 100%;
}
.hiw-chip-note svg {
  flex-shrink: 0;
  margin-top: 2px;
}
.hiw-chip-note a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}
.hiw-scenario[data-role='traveler'] .hiw-chip-note {
  background: color-mix(in srgb, var(--blue) 8%, transparent);
  color: var(--blue);
}
.hiw-scenario[data-role='requester'] .hiw-chip-note {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  color: var(--accent);
}

/* Fallback placeholder shown inside the phone when a real screenshot
   file is not present yet at the given path (see onerror in the HTML). */
.hiw-phone-frame .phone-shot-fallback {
  flex-direction: column;
  gap: 6px;
}
.hiw-fallback-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ivory-dark);
  border: 1px solid var(--gold);
  color: var(--blue);
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* JS moves this block to sit right under the active step's own text
   (see how-it-works.js setActiveStep) instead of below the whole
   phone, so Назад/Далее stay next to the description they act on and
   in view together with it without scrolling. */
.hiw-step-nav {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  margin-top: 28px;
}
.hiw-nav-btn {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  background: var(--white);
  border: 1.5px solid color-mix(in srgb, var(--primary) 32%, transparent);
  border-radius: 28px;
  padding: 9px 20px;
  cursor: pointer;
  transition:
    opacity 0.2s ease,
    border-color 0.2s ease;
}
.hiw-nav-btn:hover {
  border-color: var(--primary);
}
.hiw-nav-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.hiw-nav-btn--primary {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}
.hiw-nav-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.hiw-nav-btn:disabled:hover {
  border-color: color-mix(in srgb, var(--primary) 32%, transparent);
}

/* JS-ENHANCED STATE */
.hiw-interactive:not(.js-ready) .role-switch,
.hiw-interactive:not(.js-ready) .hiw-route-line,
.hiw-interactive:not(.js-ready) .hiw-rail,
.hiw-interactive:not(.js-ready) .hiw-step-nav,
.hiw-interactive:not(.js-ready) .hiw-pay-demo {
  display: none;
}
.hiw-interactive.js-ready .hiw-scenario {
  display: none;
}
.hiw-interactive.js-ready .hiw-scenario.is-active {
  display: block;
}
/* The role-switch buttons already say "Я путешествую" / "Мне нужно…" —
   this heading repeating it above the active step is redundant once
   JS is driving things, and costs height the phone needs. */
.hiw-interactive.js-ready .hiw-scenario-hdr {
  display: none;
}
.hiw-interactive.js-ready .hiw-step {
  display: none;
  border-top: 0;
  padding: 6px 0;
}
.hiw-interactive.js-ready .hiw-step.is-active {
  display: grid;
}
.hiw-interactive.js-ready .hiw-step-media,
.hiw-interactive.js-ready .hiw-step-text {
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
}
.hiw-interactive.js-ready .hiw-step.hiw-step-switching .hiw-step-media,
.hiw-interactive.js-ready .hiw-step.hiw-step-switching .hiw-step-text {
  opacity: 0;
  transform: translateY(6px);
}
@media (prefers-reduced-motion: reduce) {
  .hiw-route-marker,
  .hiw-interactive.js-ready .hiw-step-media,
  .hiw-interactive.js-ready .hiw-step-text {
    transition: none;
  }
}

/* MINI PAYMENT DEMO — JS moves this into the active step's
   .hiw-step-text, right after the Назад/Далее buttons (see
   how-it-works.js setActiveStep). margin-top: auto there pushes it to
   the bottom of that (now phone-height-tall) column, so it lines up
   with the phone's bottom edge instead of sitting centred under the
   whole section with a big empty gap above it. */
.hiw-pay-demo {
  align-self: stretch;
  margin-top: auto;
  width: 100%;
  background: var(--white);
  border: 1px solid var(--ivory-dark);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-align: center;
}
.hiw-pay-demo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.hiw-pay-demo-label {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  transition: color 0.2s ease;
}
.hiw-pay-btn {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--white);
  background: var(--blue);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
}
.hiw-pay-btn:hover {
  opacity: 0.88;
}
.hiw-pay-btn:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}
.hiw-pay-btn:disabled {
  opacity: 0.45;
  cursor: default;
}
.hiw-pay-demo-row.is-paid .hiw-pay-demo-label {
  color: #4a8c74;
}
.hiw-pay-note {
  margin-top: 10px;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
}

/* BOTTOM LINK + DOWNLOAD BLOCK */
.hiw-help-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: -apple-system, 'Segoe UI', sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--white);
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 760px) {
  /* The shared frame is capped at 76vh, which on a phone fills the
     screen and pushes the step numbers or Назад/Далее off it. Keep
     this override on the how-it-works mockup only: reserve the fixed
     header, the step rail, the short description, the two buttons and
     the sticky store bar. */
  .hiw-interactive .phone-frame.phone-frame--shot {
    --phone-w: calc(
      (clamp(280px, 100vh - 470px, 400px) - 2 * var(--phone-border)) / 2.164103 +
        2 * var(--phone-border)
    );
    --phone-w: calc(
      (clamp(280px, 100svh - 470px, 400px) - 2 * var(--phone-border)) / 2.164103 +
        2 * var(--phone-border)
    );
    /* The height cap lands on a half pixel (182.5px in a 390px column).
       A screenshot resampled off the pixel grid looks soft. Snap the
       width to a whole pixel that shares the column's parity, so the
       centered frame starts on a whole pixel too. */
    width: calc(
      round(down, var(--phone-w), 1px) -
        mod(round(down, var(--phone-w), 1px) - 100%, 2px)
    );
  }
  .hiw-interactive .phone-screen--shot img {
    /* One scale into the screen box. cover on a box that is a fraction
       off the bitmap's ratio resamples the screenshot a second time. */
    height: auto;
    object-fit: unset;
  }
  .hiw-step {
    grid-template-columns: 1fr;
    text-align: center;
    justify-items: center;
  }
  .hiw-step-nav {
    justify-content: center;
    margin-top: 12px;
  }
  .hiw-step-text {
    /* flex-start was only needed to stop the badge/buttons stretching
       full-width next to the phone on desktop; stacked on mobile
       (phone above, text below, both already full-width) centring
       everything matches .hiw-step's own centred text-align here. */
    align-items: center;
    /* The viewport-height-based padding-top exists to line the text
       up with the top of the phone in the side-by-side desktop
       layout; stacked on mobile (phone above, text below) it would
       just be a large dead gap, so use a small fixed one instead. */
    padding-top: 16px;
  }
  .hiw-pay-demo {
    /* On the stacked mobile layout .hiw-step-text isn't stretched to
       the phone's height (each grid item gets its own auto-height
       row), so margin-top: auto has no spare space to push against
       and collapses to 0 — use a real gap instead, same as it always
       had under the phone and buttons. */
    margin-top: 16px;
  }
}

@media (max-width: 400px) {
  .role-switch {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .hiw-hero {
    padding-top: 92px;
  }
  .hiw-interactive {
    padding: 0 16px;
  }
}

/* Short laptop windows (e.g. 1366x768 minus browser chrome): the mini
   payment demo is a nice-to-have, not part of the core step-by-step
   demo, so it's the first thing to go to keep role switch -> phone ->
   Далее/Назад visible in one screen without scrolling. */
@media (max-height: 760px) and (min-width: 761px) {
  .hiw-pay-demo {
    display: none;
  }
  .hiw-interactive {
    margin-top: 10px;
  }
  .role-switch {
    margin-bottom: 8px;
  }
  .hiw-route-line {
    margin-bottom: 8px;
  }
  .hiw-rail {
    margin-bottom: 4px;
  }
}
