:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #d6dae1;
  --accent: #1f7a4d;
  --error: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --panel: #1b2129;
    --text: #e6e9ee;
    --muted: #98a2b3;
    --line: #2f3844;
    --accent: #3fb27f;
    --error: #f97066;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, sans-serif; display: flex; flex-direction: column; }
header, .toolbar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; flex-wrap: wrap; }
header { border-bottom: 1px solid var(--line); background: var(--panel); }
main { flex: 1; display: flex; min-height: 0; }
#stage { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.canvas-wrap { flex: 1; position: relative; min-height: 300px; background: var(--panel); }
.canvas-wrap > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#canvas { cursor: crosshair; }
#canvas.pick { cursor: default; }
.steps { display: flex; gap: 6px; align-items: center; }
.step { display: inline-flex; gap: 6px; align-items: center; padding: 5px 12px; font-weight: 600; }
.step .num { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--line); color: var(--text); font-size: 12px; }
.step.active .num, .step.primary .num { background: rgba(255, 255, 255, 0.25); color: #fff; }
button.danger { background: var(--error); border-color: var(--error); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
.lang { font-size: 12px; min-width: 40px; }
.tooltip { position: absolute; left: 0; top: 0; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; line-height: 1.5; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); min-width: 180px; z-index: 2; }
.tooltip strong { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px 12px; max-width: calc(100% - 16px); background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; }
.legend:empty { display: none; }
.legend .item { display: inline-flex; gap: 5px; align-items: center; }
.swatch { width: 14px; height: 14px; vertical-align: middle; flex: none; }
.zone-swatch { width: 14px; height: 10px; background: rgba(31, 122, 77, 0.12); border: 1px solid rgba(31, 122, 77, 0.6); }
.route-swatch { width: 16px; height: 0; border-top: 2px solid #1f7a4d; }
.stop-swatch { width: 9px; height: 9px; border-radius: 50%; background: #f79009; }
.stop-swatch.wait { background: #f04438; }
details#advanced { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 8px; }
details#advanced > summary { cursor: pointer; font-weight: 600; padding: 4px 0; margin-bottom: 8px; }
#panel-main h3 { display: flex; gap: 6px; align-items: center; }
#panel-main p { margin: 4px 0; }
#panel-main label, #panel-main .row { display: flex; justify-content: space-between; margin: 6px 0; gap: 8px; }
#panel-main input:not([type="checkbox"]), #panel-main select { width: 180px; }
aside { width: 360px; max-width: 45vw; border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 8px 12px; }
button, input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; }
button { cursor: pointer; }
button.primary, button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
input[type="number"] { width: 80px; }
label { display: inline-flex; gap: 6px; align-items: center; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tab label, .tab .row { display: flex; justify-content: space-between; margin: 6px 0; gap: 8px; }
.tab input:not([type="checkbox"]), .tab select { width: 180px; }
.tab h3 { margin: 12px 0 4px; font-size: 14px; }
.hidden { display: none !important; }
.grow { flex: 1; }
.sep { width: 1px; height: 20px; background: var(--line); }
.status, .hint { color: var(--muted); font-size: 12px; }
.error { color: var(--error); white-space: pre-wrap; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; z-index: 10; }
.card { background: var(--panel); padding: 24px; border-radius: 10px; display: flex; flex-direction: column; gap: 12px; min-width: 280px; }
.card h1 { margin: 0; font-size: 20px; }
textarea { width: 100%; height: 50vh; font-family: ui-monospace, monospace; font-size: 12px; }
footer { padding: 4px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); min-height: 24px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { border-bottom: 1px solid var(--line); padding: 6px 0; display: flex; gap: 6px; align-items: center; cursor: pointer; }
.list li.selected { font-weight: 600; }
.file input { display: none; }
.file { border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; cursor: pointer; }
pre { white-space: pre-wrap; margin: 4px 0; font-size: 12px; }
@media (max-width: 800px) {
  .steps { order: 10; width: 100%; }
  .step { flex: 1; justify-content: center; }
  main { flex-direction: column; }
  aside { width: 100%; max-width: none; border-left: 0; border-top: 1px solid var(--line); }
}
.eink { display: block; max-width: 100%; height: auto; margin: 4px 0; }
