:root {
  --bg: #ffffff;
  --bg-soft: #f4f2ee;
  --bg-sel: #e8eefc;
  --line: #e1ddd5;
  --text: #1d1d1f;
  --muted: #6b6760;
  --accent: #3b5bdb;
  --danger: #c92a2a;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --bg-soft: #2a2a2d;
    --bg-sel: #2b3550;
    --line: #3a3a3d;
    --text: #f2f2f2;
    --muted: #a3a09a;
    --accent: #8fa8ff;
    --danger: #ff8787;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  font: 14px/1.4 var(--font);
  color: var(--text);
  background: var(--bg);
}
button, input, select { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 6px;
  padding: 5px 10px;
}
button:hover { background: var(--bg-soft); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.icon { padding: 3px 7px; min-width: 28px; }
button.on { background: var(--bg-sel); border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type=text], select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  padding: 5px 8px;
  min-width: 0;
}
input[type=color] {
  width: 28px; height: 28px; padding: 0; border: 1px solid var(--line);
  border-radius: 6px; background: none; cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.side {
  width: 360px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--bg);
  min-height: 0;
}
.tabs { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: none; padding: 7px 4px; font-weight: 500; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--bg-sel); color: var(--accent); }
.panel { overflow-y: auto; padding: 12px; flex: 1; display: flex; flex-direction: column; gap: 12px; }
.panel > * { flex: none; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 6px 0 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--danger); font-size: 12px; }
label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.sel { border-color: var(--accent); background: color-mix(in srgb, var(--bg-sel) 40%, var(--bg)); }
.card .head { display: flex; align-items: center; gap: 8px; }
.card .head .swatch { width: 18px; height: 6px; border-radius: 3px; flex: none; }
.card .head .name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: none; border: none; text-align: left; padding: 2px 0; }
.stops { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; }
.stops li { display: flex; align-items: center; gap: 6px; background: var(--bg-soft); border-radius: 6px; padding: 4px 6px; }
.stops li .n { width: 20px; height: 20px; border-radius: 50%; background: var(--text); color: var(--bg); font-size: 11px; display: grid; place-items: center; flex: none; }
.stops li .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stops li button { border: none; background: none; padding: 0 4px; }

.streetlist { display: flex; flex-direction: column; }
.street { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.street:hover { background: var(--bg-soft); }
.street.sel { background: var(--bg-sel); }
.street .nm { flex: 1; min-width: 0; border: none; background: none; text-align: left; padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.street .nm em { color: var(--muted); font-style: normal; font-size: 12px; }
.street .hl { width: 22px; height: 22px; padding: 0; border-radius: 50%; }
.street .hl.none { background: repeating-linear-gradient(45deg, var(--bg) 0 3px, var(--line) 3px 5px); }

.stage { flex: 1; position: relative; min-width: 0; background: #efe9df; }
#map { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
#map.dragging { cursor: grabbing; }
#map.picking { cursor: crosshair; }
.zoom { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 40px; height: 36px; padding: 0; font-size: 18px; }
.zoom button#zfit { font-size: 12px; }
.banner {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: #1d1d1f; color: #fff; border-radius: 999px; padding: 8px 8px 8px 16px;
  display: flex; gap: 12px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.banner button { background: #fff; color: #1d1d1f; border: none; border-radius: 999px; padding: 4px 14px; font-weight: 600; }
.tools { position: absolute; top: 14px; right: 14px; display: flex; gap: 6px; }
.tools button, .zoom button { background: #fff; color: #1d1d1f; border-color: #d6d0c6; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.tools button { padding: 7px 14px; font-weight: 600; }
.tools button[aria-pressed=true] { background: #1d1d1f; color: #fff; border-color: #1d1d1f; }
.pop {
  position: absolute; width: 220px; background: #fff; color: #1d1d1f; border-radius: 10px; padding: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.22); display: flex; flex-direction: column; gap: 2px;
}
.pop-title { font-weight: 700; padding: 4px 8px 6px; }
.pop button { background: none; border: none; text-align: left; padding: 7px 8px; color: #1d1d1f; }
.pop button:hover { background: #f1efea; }
.styles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.styles button { display: flex; flex-direction: column; gap: 6px; padding: 6px; text-align: left; font-weight: 500; }
.styles button[aria-pressed=true] { background: var(--bg-sel); border-color: var(--accent); color: var(--accent); }
.styles svg { width: 100%; height: 64px; border-radius: 5px; display: block; }
.toast {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: #1d1d1f; color: #fff; border-radius: 8px; padding: 8px 14px; font-size: 13px;
}

@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  .side { width: 100%; height: 46%; border-right: none; border-top: 1px solid var(--line); }
  .stage { flex: 1; min-height: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
