:root {
  --ink: #1a1a1a;
  --ink-2: #6b6b6b;
  --line: #e4e4e4;
  --bg: #fff;
  --accent: #2563eb;
  --on-accent: #fff;
  --hover: #f0f0f0;
  --hover-accent: #f1f5ff;
  --shadow: rgba(0, 0, 0, 0.1);
  color-scheme: light;

  /* map palette (read by app.js) */
  --map-water: #f4f6f8;
  --map-neighbor: #ececec;
  --map-land: #fff;
  --map-border: #d4d4d4;
  --map-road: #e2e2e2;
  --map-interstate: #c8c8c8;
  --map-label: #333;
  --map-state: #8c8c8c;
  --map-halo: #fff;
  --map-route: #2563eb;
  --map-route-ink: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #ececec;
    --ink-2: #9a9a9a;
    --line: #2e2e2e;
    --bg: #161616;
    --accent: #5b9cff;
    --on-accent: #0b0b0b;
    --hover: #262626;
    --hover-accent: #1e2a40;
    --shadow: rgba(0, 0, 0, 0.5);
    --map-water: #0f0f10;
    --map-neighbor: #1a1a1a;
    --map-land: #1f1f1f;
    --map-border: #3a3a3a;
    --map-road: #2a2a2a;
    --map-interstate: #484848;
    --map-label: #d6d6d6;
  --map-state: #7d7d7d;
    --map-halo: #1f1f1f;
    --map-route: #5b9cff;
    --map-route-ink: #0b0b0b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #ececec;
  --ink-2: #9a9a9a;
  --line: #2e2e2e;
  --bg: #161616;
  --accent: #5b9cff;
  --on-accent: #0b0b0b;
  --hover: #262626;
  --hover-accent: #1e2a40;
  --shadow: rgba(0, 0, 0, 0.5);
  --map-water: #0f0f10;
  --map-neighbor: #1a1a1a;
  --map-land: #1f1f1f;
  --map-border: #3a3a3a;
  --map-road: #2a2a2a;
  --map-interstate: #484848;
  --map-label: #d6d6d6;
  --map-state: #7d7d7d;
  --map-halo: #1f1f1f;
  --map-route: #5b9cff;
  --map-route-ink: #0b0b0b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.app { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.panel { padding: 20px; border-right: 1px solid var(--line); overflow-y: auto; }
h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 600; }

.search { position: relative; }
#q { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
#q:focus { outline: none; border-color: var(--accent); }
.suggest {
  position: absolute; left: 0; right: 0; top: 44px; z-index: 5; margin: 0; padding: 4px; list-style: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px var(--shadow);
}
.suggest li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--hover-accent); }
.suggest .s-meta, .s-none { color: var(--ink-2); }
.suggest .s-meta { flex: none; max-width: 50%; text-align: right; font-size: 13px; }
.suggest .s-credit { display: block; padding: 4px 8px 2px; font-size: 11px; color: var(--ink-2); cursor: default; }
.suggest .s-credit:hover { background: none; }

.summary { margin: 16px 0 8px; color: var(--ink-2); }
.cost { margin: -4px 0 10px; color: var(--ink-2); font-size: 13.5px; }
.stops { margin: 0; padding: 0; list-style: none; }
.stop { display: flex; align-items: center; gap: 4px; padding: 4px 0; border-radius: 6px; cursor: grab; user-select: none; position: relative; }
.stop .num { touch-action: none; }
.stop.dragging { z-index: 2; cursor: grabbing; background: var(--bg); box-shadow: 0 4px 14px var(--shadow); }
.stop.drop-above::before, .stop.drop-below::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--accent); }
.stop.drop-above::before { top: -2px; }
.stop.drop-below::after { bottom: -2px; }
.stop.flash { animation: flash 1s ease-out; }
@keyframes flash { from { background: var(--hover-accent); } }
.num {
  flex: none; width: 22px; height: 22px; margin-right: 6px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 600;
}
.stop-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.icon-btn { width: 26px; height: 26px; border: 0; border-radius: 6px; background: none; color: var(--ink-2); }
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.icon-btn:disabled { opacity: 0.25; cursor: default; }
.leg { margin: 0 0 0 10px; padding: 2px 0 2px 19px; border-left: 2px solid var(--accent); color: var(--ink-2); font-size: 13.5px; }
.empty { color: var(--ink-2); }

.actions { display: flex; gap: 8px; margin-top: 16px; }
.btn { height: 34px; padding: 0 14px; border: 1px solid var(--ink); border-radius: 8px; background: var(--ink); color: var(--bg); }
.btn.quiet { background: none; border-color: var(--line); color: var(--ink); }

.map-wrap { position: relative; min-width: 0; overflow: hidden; background: var(--map-water); }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map:active { cursor: grabbing; }
.zoom { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.zoom button { width: 36px; height: 36px; border: 0; background: none; font-size: 18px; }
.zoom button + button { border-top: 1px solid var(--line); }
.zoom button:hover { background: var(--hover); }

@media (max-width: 760px) {
  html, body { height: auto; }
  .app { display: block; height: auto; }
  .panel { border: 0; overflow: visible; }
  .map-wrap { height: 60vh; order: -1; }
  .app { display: flex; flex-direction: column; }
}

.chip { margin-top: 12px; height: 30px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: none; color: var(--ink-2); font-size: 13px; }
.chip:hover { color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.head { display: flex; align-items: center; margin-bottom: 16px; }
#theme { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: none; color: var(--ink-2); font-size: 15px; }
#theme:hover { color: var(--ink); }

.saved-wrap h2 { margin: 24px 0 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
.saved { margin: 0; padding: 0; list-style: none; }
.saved li { display: flex; align-items: center; border-radius: 6px; }
.saved li:hover, .saved li.current { background: var(--hover); }
.saved-open { flex: 1; min-width: 0; display: flex; justify-content: space-between; gap: 12px; padding: 6px 8px; border: 0; background: none; text-align: left; }
.saved-name { min-width: 0; overflow-wrap: anywhere; }
.saved li.current .saved-name { font-weight: 600; }
.saved-meta { flex: none; color: var(--ink-2); font-size: 13px; }
.sync { margin: 20px 0 0; font-size: 12.5px; color: var(--ink-2); }
.link { padding: 0; border: 0; background: none; color: var(--accent); font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; text-decoration: underline; text-underline-offset: 2px; }
#sync-status:not(:empty)::before { content: "\00b7  "; }
