:root {
  --bg: #0b0f1a;
  --panel: #141a2b;
  --panel-2: #1a2136;
  --line: #232b44;
  --accent: #6c63ff;
  --text: #eef1f7;
  --muted: #8b93a7;
  --danger: #ff5a5f;
  --ok: #34d17f;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; }
body { display: flex; justify-content: center; }
#app { width: 100%; max-width: 480px; padding: max(16px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }

.brand { text-align: center; margin: 24px 0 20px; }
.brand .logo { width: 56px; height: 56px; border-radius: 16px; display: inline-grid; place-items: center;
  background: linear-gradient(160deg, #7b73ff, #4b41d8); color: #fff; font-weight: 800; font-size: 26px; }
.brand h1 { font-size: 24px; margin: 12px 0 2px; }
.brand p { color: var(--muted); margin: 0; font-size: 14px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
label.field { display: block; margin-bottom: 12px; }
label.field .k { color: var(--muted); font-size: 12px; margin-bottom: 6px; display: block; }
.input { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 16px; }
.input:focus { outline: none; border-color: var(--accent); }
.input.warn { border-color: var(--danger); }

.btn { width: 100%; padding: 15px; border-radius: 14px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700; cursor: pointer; }
.btn.secondary { background: var(--panel-2); border-color: var(--line); color: var(--text); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }

/* Origin↔destination swap. On the main input a small centered ⇅ button sits
   between the "Откуда" and "Куда" rows; on the result screen it's a labelled
   "⇅ Обратно" secondary button in the route head. */
.swap-row { display: flex; justify-content: center; margin: -2px 0 2px; }
.swap-btn { width: 40px; height: 40px; flex: 0 0 40px; aspect-ratio: 1 / 1; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--accent); font-size: 18px;
  display: grid; place-items: center; cursor: pointer; transition: transform .12s ease, border-color .12s ease; }
.swap-btn:hover { border-color: var(--accent); transform: rotate(180deg); }

/* Recent + saved routes (local history). Compact tappable rows under the card. */
.hist-sec { margin: 0 0 12px; }
.hist-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; margin: 2px 4px 6px; }
.hist-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.hist-open { flex: 1; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 15px; cursor: pointer; }
.hist-open:hover { border-color: var(--accent); }
.hist-rm { flex: 0 0 auto; }

.mic-row { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.mic { width: 52px; height: 52px; flex: 0 0 52px; aspect-ratio: 1 / 1; border-radius: 50%; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--muted); font-size: 22px; display: grid; place-items: center; }
/* flex:0 0 52px keeps the button from being compressed by the hint text on a
   narrow viewport (it would otherwise shrink to an oval); aspect-ratio 1/1 is a
   belt-and-suspenders square guarantee so border-radius:50% is always a circle. */
.mic-row .note { color: var(--muted); font-size: 12px; }

.msg { border-radius: 12px; padding: 12px 14px; font-size: 14px; margin-bottom: 12px; }
.msg.err { background: rgba(255,90,95,.12); border: 1px solid rgba(255,90,95,.35); color: #ffb3b5; }
.msg.info { background: rgba(108,99,255,.12); border: 1px solid rgba(108,99,255,.35); color: #c8c4ff; }

.foot { color: var(--muted); font-size: 12px; text-align: center; margin-top: 14px; display: flex; gap: 8px; justify-content: center; }
.foot .dot { color: var(--ok); }

/* route result — responsive header: the action buttons share the top row (wrapping
   if a very narrow width can't hold all three), and the «Origin → Destination» title
   takes its OWN full-width line below, wrapping to 2 lines for long names instead of
   being clipped on the right. */
.route-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 14px; }
.route-head h2 { font-size: 20px; margin: 2px 0 0; flex-basis: 100%; min-width: 0;
  line-height: 1.25; overflow-wrap: anywhere; }
.chips { display: flex; gap: 18px; margin-bottom: 6px; }
.chip { display: flex; flex-direction: column; }
.chip b { font-size: 18px; }
.chip span { color: var(--muted); font-size: 12px; }

/* route map (self-contained schematic — Phase 1 metro-only, no tiles) */
.route-map { border-radius: 16px; overflow: hidden; border: 1px solid var(--line);
  background: #070a12; margin-bottom: -14px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.route-map .metro-map { display: block; width: 100%; height: auto; }
/* bottom sheet lifts over the map's lower edge, iOS-like */
.card.sheet { position: relative; z-index: 1; border-top-left-radius: 20px; border-top-right-radius: 20px; }
.card.sheet::before { content: ""; display: block; width: 36px; height: 4px; border-radius: 2px;
  background: var(--line); margin: -4px auto 12px; }

.timeline { margin: 6px 0; }
.step { display: grid; grid-template-columns: 40px 1fr; gap: 10px; padding: 2px 0; }
.rail { display: grid; justify-items: center; }
.badge { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 13px; }
.badge.walk { background: var(--panel-2); color: var(--muted); }
.badge.dest { background: #fff; color: #000; }
.connector { width: 4px; flex: 1; min-height: 26px; margin: 2px 0; border-radius: 2px; background: var(--line); }
.step .body { padding-bottom: 12px; }
.step .body .t { font-weight: 700; }
.step .body .s { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* disambiguation */
.disamb h2 { font-size: 20px; margin: 6px 0 2px; text-align: center; }
.disamb .sub { color: var(--muted); text-align: center; margin: 0 0 16px; font-size: 14px; }
.cand { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; }
.cand .names { flex: 1; }
.cand .names .t { font-weight: 700; }
.cand .names .s { color: var(--muted); font-size: 13px; }
.cand .lines { display: flex; gap: 6px; }

/* mic button (enabled) */
.mic.live { background: linear-gradient(160deg, #7b73ff, #4b41d8); color: #fff; border-color: transparent; cursor: pointer; }

/* listening screen */
.listen { text-align: center; padding-top: 8px; }
.listen-top { display: flex; justify-content: flex-end; }
.pulse { position: relative; width: 200px; height: 200px; margin: 30px auto 10px; display: grid; place-items: center; }
.pulse .ring { position: absolute; border-radius: 50%; border: 1px solid rgba(124,116,255,.35); inset: 50% auto auto 50%; transform: translate(-50%,-50%); }
.pulse .r1 { width: 120px; height: 120px; } .pulse .r2 { width: 160px; height: 160px; } .pulse .r3 { width: 200px; height: 200px; }
.pulse.on .ring { animation: ripple 2.4s ease-out infinite; }
.pulse.on .r2 { animation-delay: .5s; } .pulse.on .r3 { animation-delay: 1s; }
@keyframes ripple { 0% { opacity: .7; } 70% { opacity: .15; } 100% { opacity: .7; } }
.mic-orb { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center; font-size: 34px;
  background: radial-gradient(circle at 35% 30%, #8f88ff, #4b41d8); box-shadow: 0 0 40px rgba(108,99,255,.5); z-index: 1; }
.listen h2 { font-size: 32px; margin: 10px 0 2px; }
.listen .sub { color: var(--muted); margin: 0 0 16px; }
.wave { display: flex; gap: 4px; justify-content: center; align-items: center; height: 34px; margin: 8px 0 18px; }
.wave .bar { width: 4px; height: 8px; border-radius: 2px; background: var(--accent); }
.wave.on .bar { animation: eq .9s ease-in-out infinite; }
@keyframes eq { 0%,100% { height: 8px; } 50% { height: 28px; } }
.hint-chip { display: inline-flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 16px; text-align: left; }
.hint-chip b { display: block; font-size: 15px; } .hint-chip span { color: var(--muted); font-size: 12px; }
.listen .tip { color: var(--muted); font-size: 13px; margin-top: 28px; }

/* Phase-2: fallback foot-leg text (azimuth+distance, no drawn line). */
.timeline .s.warn { color: #d98a2b; }

/* Phase-2 GPS (spec §5.8): live-origin chip, location button, underground screen. */
.btn.secondary.loc { margin-top: 8px; }
.origin-live { display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  background: rgba(108,99,255,.12); border: 1px solid rgba(108,99,255,.35); border-radius: 12px; color: #c8c4ff; font-weight: 600; }
.origin-live .acc { color: var(--muted); font-weight: 400; font-size: 12px; }
.origin-live .loc-dot { filter: drop-shadow(0 0 4px rgba(108,99,255,.6)); }
.linkbtn { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 15px; cursor: pointer; padding: 4px 8px; }
.live-pos { margin: 10px 2px 0; padding: 10px 14px; border-radius: 12px; font-weight: 600;
  background: rgba(76,141,255,.12); border: 1px solid rgba(76,141,255,.35); color: #bcd4ff; }
.live-pos .acc { color: var(--muted); font-weight: 400; }

/* Underground / no-GPS screen (no_gps.png) */
.ug { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 8px 4px 24px; }
.ug-top { align-self: flex-start; }
.ug-icon { margin: 12px 0 4px; }
.pulse.nogps .ring { border-color: rgba(239,43,45,.5); }
.pulse.nogps .mic-orb { font-size: 30px; }
.ug-title { font-size: 26px; margin: 8px 0 2px; }
.ug-sub.err-txt { color: #ef5350; font-weight: 700; margin: 0 0 10px; }
.ug-hint { color: var(--muted); max-width: 320px; margin: 0 0 18px; }
.ug-voice { display: flex; align-items: center; gap: 14px; width: 100%; max-width: 420px; text-align: left;
  padding: 14px 16px; border-radius: 16px; background: var(--card, #131a2b); border: 1px solid rgba(255,255,255,.08); cursor: pointer; color: #fff; }
.ug-voice .mic-mini { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #6c63ff, #3a34a8); font-size: 20px; }
.ug-voice b { display: block; font-size: 17px; } .ug-voice span span { color: var(--muted); font-size: 13px; }
.ug-or { color: var(--muted); margin: 16px 0 12px; }
.ug-pick { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px; }
.ug-pick .k { color: var(--muted); font-size: 13px; text-align: left; }
.ug-note { display: flex; gap: 8px; align-items: flex-start; text-align: left; margin-top: 20px; padding: 12px 14px;
  border-radius: 12px; background: rgba(108,99,255,.1); border: 1px solid rgba(108,99,255,.25); color: var(--muted); max-width: 440px; }

/* Phase-2 foot geographic map (self-drawn from the foot graph — no tiles). */
.view-toggle { display: flex; gap: 6px; margin: 4px 2px 8px; }
.view-toggle .vtab { flex: 1; padding: 8px 10px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--card, #131a2b); border: 1px solid rgba(255,255,255,.08); color: var(--muted); cursor: pointer; }
.view-toggle .vtab.on { color: #fff; background: rgba(108,99,255,.18); border-color: rgba(108,99,255,.5); }
.foot-map { display: block; width: 100%; height: auto; border-radius: 14px; background: #0c1220; }
.fm-loading { display: grid; place-items: center; min-height: 180px; color: var(--muted);
  border-radius: 14px; background: #0c1220; gap: 6px; }
.fm-bg { fill: #0c1220; }
.fm-street { fill: none; stroke: #33405e; stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.fm-walk { fill: none; stroke: #4c8dff; stroke-width: 4.5; stroke-linecap: round; stroke-linejoin: round;
  filter: drop-shadow(0 0 4px rgba(76,141,255,.5)); }
.fm-dir { stroke: #d98a2b; stroke-width: 3; stroke-dasharray: 6 5; fill: none; stroke-linecap: round; }
.fm-dir-txt { fill: #e6b980; font-size: 11px; font-weight: 600; text-anchor: middle; }
.fm-origin { fill: #9aa7c7; stroke: #0c1220; stroke-width: 2; }
.fm-pin-halo { fill: rgba(239,43,45,.22); }
.fm-pin-dot { fill: #ef2b2d; stroke: #fff; stroke-width: 2; }
.fm-pin-num { fill: #fff; font-size: 11px; font-weight: 700; text-anchor: middle; }
.fm-live-halo { fill: rgba(76,141,255,.25); }
.fm-live-dot { fill: #4c8dff; stroke: #fff; stroke-width: 2.5; }
.fm-odbl { fill: #6b7690; font-size: 9px; text-anchor: end; }

/* Phase-2 perf: dev stage-timer overlay (visible with ?perf=1). */
.perf-overlay { position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 9999;
  background: rgba(8,12,20,.92); border: 1px solid rgba(108,99,255,.5); border-radius: 10px;
  color: #cdd6f4; font: 11px/1.4 ui-monospace, Menlo, monospace; padding: 8px 10px; text-align: center; }
.perf-overlay b { color: #8be9fd; }
