:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --fg: #1c1f24;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #ea580c;
  --accent-fg: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  --foot: #16a34a;
  --track: #a16207;
  --bike: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d;
    --bg-soft: #22252b;
    --fg: #e8eaed;
    --muted: #9aa0a8;
    --line: #2f333a;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  overflow: hidden;
}
#map { flex: 1; height: 100%; }
button, input, select { font: inherit; color: inherit; }

#panel {
  width: 340px;
  flex: 0 0 340px;
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 1000;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.panel-head h1 { font-size: 17px; margin: 0; letter-spacing: -.01em; flex: 1; }
.panel-head h1::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: 1px;
}
.panel-body { overflow-y: auto; padding: 12px 16px 24px; flex: 1; }
section { margin-bottom: 12px; }
.card { background: var(--bg-soft); border-radius: 12px; padding: 12px; }
.row-label { display: block; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }

button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: 7px 10px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.07); }
button.wide { width: 100%; padding: 9px; }
.icon-btn { padding: 6px 10px; line-height: 1; }
.mobile-only { display: none; }

.target-row { display: flex; align-items: center; gap: 10px; }
.target-row input[type=range] { flex: 1; accent-color: var(--accent); }
.num { display: flex; align-items: center; gap: 4px; }
.num input { width: 64px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); text-align: right; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chips button { padding: 3px 9px; font-size: 12px; border-radius: 999px; }
.chips button.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.two-col label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
select { padding: 7px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); width: 100%; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.hint:empty { display: none; }

.stats .big { font-size: 30px; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: baseline; gap: 4px; }
.stats .big small { font-size: 15px; font-weight: 600; color: var(--muted); }
.stats .of { margin-left: auto; font-size: 13px; font-weight: 500; color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.bar i.done { background: var(--ok); }
.bar i.over { background: var(--warn); }
.remaining { font-size: 13px; min-height: 18px; }
.remaining b.ok { color: var(--ok); }
.remaining b.warn { color: var(--warn); }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 0; }
.kv div { background: var(--bg); border-radius: 8px; padding: 6px 8px; }
.kv dt { font-size: 11px; color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.kv input { width: 100%; border: 0; padding: 0; background: transparent; font-weight: 600; }
.elev { margin-top: 10px; background: var(--bg); border-radius: 8px; padding: 4px; }
.elev svg { width: 100%; height: 56px; display: block; }
.elev .area { fill: var(--accent); opacity: .18; }
.elev .line { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

#suggestHome.nudge { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.suggestions { list-style: none; padding: 0; margin: 8px 0 0; }
.suggestions:empty { display: none; }
.suggestions li {
  display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px;
  background: var(--bg); margin-top: 6px; cursor: pointer; border: 2px solid transparent;
}
.suggestions li:hover, .suggestions li.hot { border-color: var(--c); }
.suggestions .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.suggestions .txt { flex: 1; font-size: 13px; }
.suggestions .txt small { display: block; color: var(--muted); }
.suggestions .badge { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 999px; background: var(--ok); color: #fff; }
.suggestions .note { cursor: default; color: var(--muted); font-size: 12.5px; }

.saved-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.saved-head .row-label { margin: 0; }
.saved-head button { font-size: 12px; padding: 4px 8px; }
.saved-list { list-style: none; padding: 0; margin: 0 0 12px; }
.saved-list:last-child { margin-bottom: 0; }
.saved-list:empty::before { content: attr(data-empty); color: var(--muted); font-size: 12.5px; }
.saved-list li { display: flex; align-items: center; gap: 6px; background: var(--bg); border-radius: 8px; margin-top: 4px; }
.saved-list .open { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 8px 10px; }
.saved-list .open small { display: block; color: var(--muted); font-size: 11.5px; }
.saved-list .open span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-list .del { border: 0; background: transparent; color: var(--muted); padding: 8px 10px; }
.saved-list .del:hover { color: #dc2626; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tools button { font-size: 13px; padding: 6px 9px; }

.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.check input { accent-color: var(--accent); }
.sw { width: 18px; height: 4px; border-radius: 2px; display: inline-block; }
.sw.foot { background: var(--foot); }
.sw.track { background: repeating-linear-gradient(90deg, var(--track) 0 6px, transparent 6px 9px); }
.sw.bike { background: var(--bike); }
.card .row-label + .check { margin-top: -2px; }

.help summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.help ul { padding-left: 18px; color: var(--muted); font-size: 13px; }
.credits { font-size: 11px; color: var(--muted); margin-top: 14px; }

.busy { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.busy[hidden] { display: none; }
.busy i { width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
.busy em { font-style: normal; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #1c1f24; color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; z-index: 2000; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* settings dialog */
.settings {
  border: 0; border-radius: 14px; padding: 0; width: min(360px, calc(100vw - 32px));
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow);
}
.settings::backdrop { background: rgba(0, 0, 0, .35); }
.settings header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.settings h2 { margin: 0; font-size: 16px; }
.settings section { padding: 14px 16px 16px; margin: 0; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.swatches button {
  width: 34px; height: 34px; border-radius: 50%; padding: 0;
  background: var(--c); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--line);
}
.swatches button[aria-checked="true"] { box-shadow: 0 0 0 2px var(--fg); }
.custom-color { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.custom-color input { width: 44px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }

/* map markers */
.wp span, .home-pin span {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); color: var(--fg);
  font-weight: 700; font-size: 11px; color: #1c1f24;
  box-shadow: 0 2px 6px rgba(0,0,0,.3); cursor: grab;
}
.wp.ghost span { background: var(--accent); color: #fff; opacity: .85; }
.home-pin span { width: 32px; height: 32px; background: var(--accent); color: #fff; border-color: #fff; font-size: 16px; }
.km span {
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: #1c1f24; color: #fff; font-size: 9.5px; font-weight: 700;
  border: 1.5px solid #fff;
}
.route-line { cursor: grab; }
.leaflet-container { cursor: crosshair; }
.leaflet-container.leaflet-drag-target, .leaflet-dragging .leaflet-container { cursor: grabbing; }
.wp-pop { display: flex; align-items: center; gap: 10px; }
.wp-pop button { padding: 4px 8px; }

/* phones: panel becomes a bottom sheet */
@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  .head-dist { font-weight: 700; font-size: 13px; color: var(--muted); }
  .panel-head { padding: 10px 16px 8px; cursor: pointer; }
  #panel { width: 100%; height: auto; flex: 0 0 auto; max-height: 46vh; max-height: 46dvh; border-right: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow); }
  #panel.collapsed .panel-body { display: none; }
  #panel.collapsed #togglePanel { transform: rotate(180deg); }
  .panel-body { padding: 10px 16px 20px; }
  .mobile-only { display: inline-block; }
  #map { flex: 1; min-height: 0; }
}
