:root {
  --bg: #fbfbfd;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --soft: #8e8e93;
  --fill: rgba(120, 120, 128, 0.1);
  --blue: #007aff;
  --blue-press: #0062cc;
  --blue-tint: #e8f1ff;
  --amber: #ff9500;
  --amber-ink: #b36200;
  --green: #34c759;
  --green-ink: #1f8a3c;
  --red: #ff3b30;
  --focus: 0 0 0 3px #fff, 0 0 0 6px rgba(0, 122, 255, 0.55);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 19px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); }
p { margin: 0; }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 12px; }

/* ---------- Scenes ---------- */

/* Каждая сцена — не меньше экрана: следующий блок начинается за его краем. */
.scene {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 100vh;
  min-height: 100svh;
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(80px, 13vh, 150px) 24px;
  text-align: center;
}
.scene-body { width: 100%; }
/* Карта не центрируется, чтобы смена состояний не сдвигала её; снизу — отступ до итога. */
.scene-map { justify-content: flex-start; margin-top: 20vh; padding-top: clamp(64px, 10vh, 120px); padding-bottom: clamp(140px, 24vh, 260px); }

.display {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: clamp(2rem, 1.1rem + 3.6vw, 4.5rem);
  line-height: 1.06;
  letter-spacing: -0.028em;
  font-weight: 700;
  margin: 0 auto;
  max-width: 18ch;
  text-wrap: balance;
}

.lead {
  font-size: clamp(1.15rem, 1rem + 0.55vw, 1.45rem);
  color: var(--muted);
  max-width: 34ch;
  margin: 28px auto 0;
  text-wrap: pretty;
}

.hero-mark { display: block; width: 180px; height: auto; margin: 0 auto 36px; overflow: visible; }
.hero-path { fill: none; stroke: var(--blue); stroke-width: 3.5; stroke-linecap: round; stroke-dasharray: 0.1 9; }
.hero-dot { fill: var(--blue); stroke: #fff; stroke-width: 2; }
.hero-dot-halo { fill: rgba(0, 122, 255, 0.16); }
.hero-pin { fill: var(--red); }
.hero-actions { margin-top: 44px; display: flex; flex-direction: column; align-items: center; gap: 18px; }

.link { font-size: 17px; text-decoration: none; padding: 6px 10px; border-radius: 10px; }
.link:hover { text-decoration: underline; }

/* ---------- Buttons ---------- */

.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease), transform 0.12s var(--ease), opacity 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible { border-radius: 999px; }
.btn[disabled],
.btn[aria-disabled="true"] { cursor: default; opacity: 0.45; transform: none; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not([disabled]):not([aria-disabled="true"]) { background: var(--blue-press); }
.btn-tint { background: var(--blue-tint); color: var(--blue); }
.btn-tint:hover:not([disabled]) { background: #d9e8ff; }
.btn-lg { min-height: 58px; padding: 0 36px; font-size: 18px; }
.btn-sm { min-height: 44px; padding: 0 20px; font-size: 16px; }

/* ---------- Choices ---------- */

.choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  max-width: 960px;
  margin: 44px auto 0;
}
.choices:empty { display: none; }

.choice {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  min-height: 76px;
  padding: 18px 48px 18px 24px;
  border: 2px solid transparent;
  border-radius: 22px;
  background: var(--fill);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease), color 0.18s;
}
.choice:hover { background: rgba(120, 120, 128, 0.16); }
.choice:focus-visible { border-radius: 22px; }
.choice::after {
  content: "";
  position: absolute;
  right: 18px;
  top: 50%;
  width: 22px;
  height: 22px;
  margin-top: -11px;
  border-radius: 50%;
  border: 2px solid rgba(60, 60, 67, 0.25);
  box-sizing: border-box;
}
.choice[aria-pressed="true"] {
  background: var(--blue-tint);
  border-color: var(--blue);
  color: #00449e;
}
.choice[aria-pressed="true"]::after {
  border: 0;
  background: var(--blue) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 22'%3E%3Cpath d='M6.5 11.3l3 3 6-6.4' fill='none' stroke='%23fff' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 22px no-repeat;
}

.muted-note { color: var(--soft); margin-top: 28px; font-size: 17px; }

/* Место под фразу занято заранее: после выбора желания сцена не прыгает. */
.phrase-wrap { margin-top: 48px; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.phrase-wrap.is-pending { visibility: hidden; }
.phrase-wrap:not(.is-pending) { animation: fadeUp 0.45s var(--ease) both; }
.phrase {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3.75em;
  font-size: clamp(1.35rem, 1rem + 1.3vw, 2.1rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  max-width: 26ch;
  text-wrap: balance;
}

/* ---------- Map scene ---------- */

#mapTitle { max-width: none; font-size: clamp(2rem, 1.1rem + 2.8vw, 3.6rem); }

.intent {
  position: sticky;
  top: 12px;
  z-index: 5;
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 10px;
  max-width: min(100%, 760px);
  margin: 26px auto 0;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  backdrop-filter: blur(16px) saturate(180%);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 6px 20px rgba(0, 0, 0, 0.07);
  font-size: 17px;
}
.intent-label { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--soft); }
.intent-text { font-weight: 600; }

.map-app {
  position: relative;
  width: min(960px, 100%);
  margin: 22px auto 0;
  border-radius: 28px;
  overflow: hidden;
  background: #f3f1ec;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 22px 60px rgba(0, 0, 0, 0.09);
  text-align: left;
}

.map-svg { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; }

.panel,
.route-card {
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-radius: 20px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 8px 26px rgba(0, 0, 0, 0.11);
}

.panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
  display: flex;
  align-items: center;
  padding: 12px 20px;
}
.od { display: flex; align-items: center; gap: 7px; font-size: 16px; font-weight: 600; white-space: nowrap; }
.od-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 3px #fff, 0 0 0 4px rgba(0,0,0,0.08); margin-right: 2px; }
.od-pin { width: 12px; height: 12px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--red); margin: 0 2px 0 4px; }
.od-arrow { color: var(--soft); font-weight: 400; margin: 0 2px; }

.route-card {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  width: 330px;
  padding: 16px 18px;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
}
.route-card.is-empty { opacity: 0; transform: translateY(8px); pointer-events: none; }
.rc-empty { display: none; color: var(--soft); font-size: 16px; }
.route-card.is-empty .rc-empty { display: block; }
.route-card.is-empty .rc-body { display: none; }
.rc-title { font-size: 19px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.25; }
.rc-meta { margin-top: 4px; font-size: 15px; color: var(--muted); line-height: 1.35; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin-top: 14px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(118, 118, 128, 0.14);
}
.seg[hidden] { display: none; }
.seg-btn {
  -webkit-appearance: none;
  appearance: none;
  min-height: 40px;
  padding: 4px 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.15;
  cursor: pointer;
  transition: background-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.seg-btn[aria-checked="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 3px 8px rgba(0, 0, 0, 0.06); }
.seg-btn:focus-visible { border-radius: 9px; }
.seg-btn[disabled] { cursor: default; opacity: 0.5; }

/* Одна ячейка под картой: кнопка постройки и пояснение сменяют друг друга без сдвига. */
.below-map { display: grid; margin-top: 30px; }
.below-map > * { grid-area: 1 / 1; }
.build-cta { display: flex; align-items: center; justify-content: center; }
.build-cta.is-hidden { visibility: hidden; }
.build-cta .btn { min-width: min(320px, 100%); }

.explain {
  min-height: 2.7em;
  max-width: 32ch;
  margin: 0 auto;
  font-size: clamp(1.2rem, 1rem + 0.7vw, 1.6rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.3;
  text-wrap: balance;
}
.question { min-height: 1.5em; margin-top: 14px; color: var(--muted); font-size: 18px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  width: min(960px, 100%);
  min-height: 52px;
  margin: 18px auto 0;
}
.actions .btn { flex: 1 1 0; max-width: 320px; }
.actions .note { flex-basis: 100%; color: var(--muted); font-size: 17px; margin-bottom: 4px; }

.fade-in { animation: fadeUp 0.45s var(--ease) both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Final ---------- */

.scene-final { padding-bottom: clamp(80px, 12vh, 140px); }

.story {
  max-width: 30ch;
  margin: 40px auto 0;
  font-size: clamp(1.3rem, 1rem + 1vw, 1.95rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.4;
  text-wrap: balance;
}
.story .arr { color: var(--blue); font-weight: 500; padding: 0 0.15em; }
.story-meta { margin-top: 16px; color: var(--muted); font-size: 17px; }
.general { max-width: 36ch; margin: 36px auto 0; color: var(--muted); font-size: clamp(1.1rem, 1rem + 0.4vw, 1.3rem); text-wrap: pretty; }
.general + .general { margin-top: 14px; }

.triad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 32px;
  max-width: 960px;
  margin: 64px auto 0;
  text-align: left;
}
.triad div { padding-top: 16px; border-top: 1px solid rgba(60, 60, 67, 0.14); }
.triad dt { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--soft); }
.triad dd { margin: 8px 0 0; font-size: 19px; font-weight: 600; line-height: 1.35; letter-spacing: -0.01em; }
.triad .t-crit dd { color: var(--blue); }

.closing {
  max-width: 28ch;
  margin: 72px auto 36px;
  font-size: clamp(1.4rem, 1rem + 1.4vw, 2.3rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  text-wrap: balance;
}

.foot { text-align: center; color: var(--soft); font-size: 14px; padding: 0 24px 40px; }

/* ---------- Reveal ---------- */

/* Сцена проявляется, когда поднимается выше ~60% высоты экрана (см. app.js). */
.js [data-reveal] { opacity: 0; transform: translateY(14px); transition: opacity 0.7s var(--ease), transform 0.7s var(--ease); }
.js [data-reveal]:not(.in) { pointer-events: none; }
.js [data-reveal].in { opacity: 1; transform: none; }

/* Заголовок итога получает фокус программно — без кольца. */
[tabindex="-1"]:focus { box-shadow: none; }

/* ---------- SVG map ---------- */

.st-lbl { font-size: 13px; font-weight: 600; fill: #85827c; letter-spacing: 0.02em; paint-order: stroke; stroke: #fff; stroke-width: 3.5px; stroke-linejoin: round; }
.st-lbl.major { font-size: 14px; fill: #6f6b63; }
.st-lbl.alley { font-size: 11px; font-weight: 500; }
.area-lbl { font-size: 14px; font-weight: 600; fill: #3f8a3a; paint-order: stroke; stroke: rgba(255,255,255,0.85); stroke-width: 3px; stroke-linejoin: round; }
.water-lbl { font-size: 14px; font-style: italic; font-weight: 500; fill: #4a8ac0; letter-spacing: 0.06em; }
.poi-lbl { font-size: 13px; font-weight: 600; paint-order: stroke; stroke: #fff; stroke-width: 3.5px; stroke-linejoin: round; }
.mk-lbl { font-size: 15px; font-weight: 700; fill: #1d1d1f; paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }

.route path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.route .r-case { stroke: #0058d6; stroke-width: 12; }
.route .r-main { stroke: #1b84ff; stroke-width: 8; }
.route.is-alt .r-case { stroke: transparent; }
.route.is-alt .r-main { stroke: #8fa9cc; stroke-width: 4.5; stroke-dasharray: 1 10; }
.route .r-main, .route .r-case { transition: stroke 0.35s var(--ease), stroke-width 0.35s var(--ease); }

.bub rect { fill: #fff; stroke: rgba(0,0,0,0.06); }
.bub path { fill: #fff; }
.bub text { font-size: 14px; font-weight: 700; fill: #1d1d1f; }
.bub .bub-sub { font-size: 11px; font-weight: 600; fill: #6e6e73; }
.bub.is-active rect, .bub.is-active path { fill: #1b84ff; stroke: none; }
.bub.is-active text { fill: #fff; }
.bub.is-active .bub-sub { fill: rgba(255,255,255,0.85); }
.bub-i { filter: drop-shadow(0 2px 4px rgba(0,0,0,0.16)); }

.hl-seg { fill: none; stroke: rgba(255, 149, 0, 0.42); stroke-width: 30; stroke-linecap: round; }
.hl-ring { fill: rgba(255, 149, 0, 0.1); stroke: var(--amber); stroke-width: 2.5; stroke-dasharray: 6 5; }
.hl.ok .hl-ring { fill: rgba(52, 199, 89, 0.12); stroke: var(--green); stroke-dasharray: none; }
.hl-pulse { fill: none; stroke: var(--amber); stroke-width: 2; opacity: 0; transform-box: fill-box; transform-origin: center; }
.hl.miss.first .hl-pulse { animation: ring 1.8s ease-out 0.1s 3; }
@keyframes ring { 0% { opacity: 0.8; transform: scale(1); } 100% { opacity: 0; transform: scale(1.45); } }
.tag rect { fill: var(--amber); }
.tag text { font-size: 13px; font-weight: 700; fill: #fff; }
.hl.ok .tag rect { fill: var(--green-ink); }
.hl-in { animation: fadeIn 0.4s var(--ease) both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Mobile ---------- */

@media (max-width: 720px) {
  body { font-size: 17px; }
  .scene { padding: 64px 16px; }
  .scene-map { padding-top: 56px; padding-bottom: max(140px, 22vh); }
  .display { font-size: clamp(1.75rem, 1.2rem + 2.6vw, 2.25rem); }
  .choices { grid-template-columns: 1fr; gap: 10px; margin-top: 30px; }
  .choice { min-height: 62px; font-size: 17px; }
  .intent { position: relative; top: 0; font-size: 15px; padding: 8px 16px; border-radius: 20px; }
  .hide-m { display: none; }
  .map-app { width: calc(100% + 16px); margin-left: -8px; margin-right: -8px; border-radius: 22px; }
  .panel {
    position: static;
    border-radius: 0;
    box-shadow: 0 1px 0 rgba(0,0,0,0.06);
    padding: 12px 16px;
  }
  .od { font-size: 15px; gap: 6px; }
  .route-card {
    position: relative;
    right: auto;
    bottom: auto;
    width: auto;
    border-radius: 0;
    box-shadow: 0 -1px 0 rgba(0,0,0,0.06);
    padding: 14px 16px 16px;
  }
  /* Пустая карточка занимает ту же высоту, что и заполненная: после постройки ничего не сдвигается. */
  .route-card.is-empty { opacity: 1; transform: none; }
  .route-card.is-empty .rc-body { display: block; visibility: hidden; }
  .route-card.is-empty .rc-empty { position: absolute; top: 14px; left: 16px; right: 16px; }
  .rc-title { font-size: 17px; min-height: 1.25em; }
  .seg[hidden] { display: grid; visibility: hidden; }
  .rc-meta { min-height: 2.7em; }
  #mapTitle { font-size: clamp(1.75rem, 1.2rem + 2.6vw, 2.25rem); min-height: 2.12em; display: flex; align-items: center; justify-content: center; }
  .below-map { margin-top: 22px; }
  .explain { min-height: 3.9em; }
  .build-cta .btn { width: 100%; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions .btn { max-width: none; flex: 0 0 auto; }
  .triad { grid-template-columns: 1fr; gap: 20px; margin-top: 44px; }
  .closing { margin-top: 52px; }

  .st-lbl { font-size: 22px; stroke-width: 5px; }
  .st-lbl.major { font-size: 23px; }
  .st-lbl.alley { display: none; }
  .area-lbl { font-size: 22px; }
  .water-lbl { font-size: 20px; }
  .route .r-case { stroke-width: 19; }
  .route .r-main { stroke-width: 13; }
  .route.is-alt .r-main { stroke-width: 7; stroke-dasharray: 1 15; }
  .hl-seg { stroke-width: 44; }
  .scale-m { transform: scale(1.6); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js [data-reveal] { transform: none; transition: none; }
  .fade-in, .hl-in, .phrase-wrap:not(.is-pending) { animation: none; }
  .hl.miss.first .hl-pulse { animation: none; }
  .route-card, .btn, .choice, .seg-btn, .route .r-main, .route .r-case { transition: none; }
}
