:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --card: #ffffff;
  --text: #16181d;
  --muted: #646b78;
  --line: #e3e6eb;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --verified: #1d4ed8;
  --inferred: #60a5fa;
  --uncertain: #f59e0b;
  --unpaved: #dc2626;
  --ok-bg: #dcfce7; --ok-fg: #166534;
  --mid-bg: #fef3c7; --mid-fg: #92400e;
  --low-bg: #fee2e2; --low-fg: #991b1b;
  --err-bg: #fef2f2; --err-line: #fecaca;
  --radius: 12px;
  --like: #ef4444;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #15181e; --card: #1b1f27; --text: #e8eaee; --muted: #9aa3b2; --line: #2a303b;
    --accent: #3b82f6; --inferred: #93c5fd;
    --ok-bg: #12351f; --ok-fg: #86efac; --mid-bg: #3a2c0b; --mid-fg: #fcd34d; --low-bg: #3b1212; --low-fg: #fca5a5;
    --err-bg: #2a1414; --err-line: #5b2121;
    --like: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
}
#app { display: flex; height: 100%; }
#panel {
  width: 400px; flex: none; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
#map-area { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; }

/* Индикатор генерации поверх карты: видно, что идёт работа, а не зависание. Карта под ним остаётся рабочей. */
.busy-overlay {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(15, 17, 21, .14); pointer-events: none;
}
.busy-overlay[hidden] { display: none; }
.busy-card {
  display: flex; align-items: center; gap: 14px; max-width: 420px; padding: 14px 18px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .2);
}
.busy-card strong { font-size: 15px; }
.busy-card p { margin: 3px 0 0; font-size: 13px; }
.busy-card p:empty { display: none; }

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 4px 0; }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.logo { width: 34px; height: 34px; border-radius: 50%; border: 5px solid var(--accent); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; top: -9px; left: 8px; width: 10px; height: 10px; border-radius: 50%; background: #16a34a; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.card h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.row h2 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
#start-text { margin: 6px 0 0; font-variant-numeric: tabular-nums; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input[type="number"], select {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 9px; width: 100%;
}
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); margin: 8px 0; }
.check input { margin-top: 2px; }

fieldset.modes { border: 0; padding: 0; margin: 14px 0 0; }
fieldset.modes legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--bg); border-radius: 9px; padding: 3px; gap: 3px; }
.segmented button {
  font: inherit; font-size: 12.5px; border: 0; border-radius: 7px; padding: 7px 4px; background: transparent; color: var(--text);
  cursor: pointer; line-height: 1.2;
}
.segmented button[aria-checked="true"] { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 600; }
#mode-desc { margin: 6px 0 0; min-height: 2.6em; }

fieldset.direction { border: 0; padding: 0; margin: 14px 0 0; }
fieldset.direction legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; }
.dir-row { display: flex; align-items: center; gap: 12px; }
.dir-row p { margin: 0; }
.compass { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 30px); gap: 3px;
  background: var(--bg); border-radius: 9px; padding: 3px; flex: none; }
.compass button { font: inherit; font-size: 12px; border: 0; border-radius: 6px; background: transparent; color: var(--text);
  cursor: pointer; padding: 0; }
.compass button[aria-checked="true"] { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.12); font-weight: 650; color: var(--accent); }
details { margin-top: 12px; }
details summary { cursor: pointer; color: var(--accent); font-size: 13px; }
details[open] summary { margin-bottom: 6px; }
.surfaces { margin: 8px 0 10px; }
#surfaces { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 4px; }
#surfaces .check { margin: 0; }

button.primary {
  margin-top: 14px; width: 100%; font: inherit; font-weight: 600; font-size: 15px; border: 0; border-radius: 10px;
  padding: 11px; background: var(--accent); color: var(--accent-text); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
button.primary:disabled { opacity: .55; cursor: not-allowed; }
button.link { font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 0; }
.spinner { display: none; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
.busy .spinner { display: inline-block; }
.spinner.big {
  display: inline-block; flex: none; width: 34px; height: 34px; border-width: 4px;
  border-color: var(--line); border-top-color: var(--accent);
}
button.primary.busy:disabled { opacity: 1; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }

#message:empty { display: none; }
#message { margin-top: 10px; padding: 10px 12px; border-radius: 9px; background: var(--err-bg); border: 1px solid var(--err-line); font-size: 13px; }
#message ul { margin: 6px 0 0; padding-left: 18px; }

.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.badge.high { background: var(--ok-bg); color: var(--ok-fg); }
.badge.medium { background: var(--mid-bg); color: var(--mid-fg); }
.badge.low { background: var(--low-bg); color: var(--low-fg); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.stats > div { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 4px; }
.stats .value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stats .unit { color: var(--muted); font-size: 13px; }
.stats .cap { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }

.export { display: flex; align-items: center; gap: 10px; margin: 12px 0 2px; }
.export .small { line-height: 1.3; }
.export code { font-size: 11px; }
a.button {
  flex: none; font-weight: 600; font-size: 13px; text-decoration: none; color: var(--accent); border: 1.5px solid var(--accent);
  border-radius: 9px; padding: 7px 12px; white-space: nowrap;
}
a.button:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.profile { height: 120px; margin-top: 10px; position: relative; }
.profile svg { width: 100%; height: 100%; display: block; overflow: visible; }
.profile .area { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 1.5; }
.profile .axis { stroke: var(--line); }
.profile text { fill: var(--muted); font-size: 10px; }
.profile .cursor { stroke: var(--text); stroke-width: 1; opacity: .5; }
.profile .tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--text); color: var(--panel); font-size: 11px; padding: 2px 6px; border-radius: 5px; pointer-events: none; white-space: nowrap; }

.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line); }
.bar span { display: block; height: 100%; }
.legend, .kv { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.legend li, .kv li { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.legend li > span:first-child { display: flex; align-items: center; gap: 7px; }
.sw { width: 18px; height: 4px; border-radius: 2px; display: inline-block; flex: none; }
.sw.dashed { background: repeating-linear-gradient(90deg, currentColor 0 5px, transparent 5px 8px) !important; }

/* Сердечко «нравится»: контур → красное, с «пульсом» при лайке */
.like {
  display: inline-flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--text); cursor: pointer;
}
.like svg {
  width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round;
  stroke-linecap: round; transition: transform .12s ease;
}
.like:hover svg { transform: scale(1.1); }
.like[aria-pressed="true"] { color: var(--like); }
.like[aria-pressed="true"] svg { fill: currentColor; }
.like:disabled { cursor: progress; }
.like.pop svg { animation: like-pop .36s ease-out; }
@keyframes like-pop { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }
.like-map {
  position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 4; width: 56px; height: 56px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
}
.like-map svg { width: 30px; height: 30px; }
.like-map[hidden] { display: none; }
#favorites-card h2 { margin: 0 0 8px; }
.favorites { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.favorites li { display: flex; align-items: center; gap: 6px; }
.favorites .open {
  flex: 1; min-width: 0; font: inherit; background: none; border: 0; padding: 4px 0; color: var(--text); cursor: pointer;
  text-align: left; font-variant-numeric: tabular-nums;
}
.favorites .open[aria-current="true"] { font-weight: 650; color: var(--accent); }
.favorites .when { color: var(--muted); font-size: 12px; margin-left: 6px; }
.favorites .like { width: 30px; height: 30px; }
.favorites .like svg { width: 18px; height: 18px; }
.favorites .empty { color: var(--muted); font-size: 13px; }
.fav-mark { color: var(--like); margin-left: 6px; }
#history { margin: 0; padding-left: 20px; display: grid; gap: 4px; }
#history button { font: inherit; background: none; border: 0; padding: 0; color: var(--text); cursor: pointer; text-align: left; font-variant-numeric: tabular-nums; }
#history button[aria-current="true"] { font-weight: 650; color: var(--accent); }

#attribution { padding: 0 4px 8px; display: grid; gap: 4px; }
#attribution p { margin: 0; }
#attribution a { color: inherit; }

.start-source { margin: 4px 0 0; font-size: 12px; }
.start-source:empty { display: none; }
.start-marker { width: 22px; height: 22px; border-radius: 50%; background: #16a34a; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: grab; }
.hover-marker { width: 14px; height: 14px; border-radius: 50%; background: #111827; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45); }
.maplibregl-ctrl-attrib { font-size: 11px; }

@media (max-width: 767px) {
  #app { flex-direction: column-reverse; height: auto; }
  #map-area { height: 55vh; min-height: 320px; flex: none; }
  #panel { width: 100%; border-right: 0; padding: 12px 16px 24px; overflow: visible; }
  .stats .value { font-size: 20px; }
}
